Skip to content

Instantly share code, notes, and snippets.

View kaspermeyer's full-sized avatar

Kasper Meyer kaspermeyer

View GitHub Profile
@kaspermeyer
kaspermeyer / jquery_event_delegator.coffee
Created December 13, 2018 14:06
Dispatch jQuery events as regular DOM events
# ~ Dispatch jQuery events as regular DOM events ~
#
# Delegated events are given a new name in the format `jquery:<original event name>`.
# If you delegate `ajax:send` you will be able to listen for `jquery:ajax:send`
# on native event listeners such as Stimulus actions and `EventTarget.addEventListener`.
#
# Notes:
# * The first parameter must be called "event".
# * The parameters can be accessed as members on the `event.detail` object.
#
@kaspermeyer
kaspermeyer / alias_controller.js
Created January 19, 2019 18:33
Stimulus controller to alias other Stimulus controllers
import { Controller } from "stimulus";
export default class extends Controller {
initialize() {
this.registerAliasedControllers()
}
registerAliasedControllers() {
for (let [alias, original] of this.controllerIdentifiersByAlias) {
if (!this.moduleForIdentifier(alias)) {
getHexColor = (color) ->
return "" unless color
return color if /^#/.test(color)
rgbValues = getRGBValues(color)
hexValues = rgbValues.map(numberToHex)
"#" + hexValues.join("")
numberToHex = (number) ->
"0#{number.toString(16)}".slice(-2).toUpperCase()