Skip to content

Instantly share code, notes, and snippets.

@askehansen
askehansen / on.js
Last active December 7, 2016 10:16
jQuery style event handler that attaches to the document so it works on dynamically added elements
function on (eventName, selector, callback) {
document.addEventListener(eventName, function (event) {
var elem = event.srcElement
var matches = elem.matches || elem.matchesSelector
if (matches.call(elem, selector)) {
callback.call(elem)
}
})
}
$(document).on('click', '@stepper-up, @stepper-down', function() {
var sender = $(this);
var parent = sender.parents('@stepper');
var target = parent.find('@stepper-input');
var val = parseInt(target.val());
if (sender.is('@stepper-up')) {
val++;
}
else {
def image_2x_tag(img, opts={})
x2_img = img.gsub(/(.+)(\.\w+)/, '\1@2x\2')
x2_path = image_path(x2_img)
opts[:srcset] = "#{x2_path} 2x"
image_tag(img, opts)
end
@askehansen
askehansen / fontawesome-states.css
Created December 2, 2015 09:40
States for fontawesome
.fa-state-warning {
color: #f0ad4e;
}
.fa-state-danger {
color: #d9534f;
}
.fa-state-primary {
color: #286090;
---
da:
clearance_mailer:
change_password:
closing: Ignorer denne email hvis du ikke har bedt om dette. Dit password er ikke blevet ændret.
link_text: Skift mit password
opening: "Du har bedt om et link til at skifte dit password:"
flashes:
failure_after_create: Ugyldig email eller password.
failure_after_update: Password skal udfyldes
@askehansen
askehansen / confirm.js
Created October 21, 2014 14:03
override rails_ujs confirm with bootbox.confirm
$.rails.allowAction = function(element) {
var message = element.data('confirm');
if (!message) {
return true;
}
bootbox.confirm(message, function(result) {
if (result) {
$.rails.handleMethod(element);
}
@askehansen
askehansen / gist:2cc2d149cde52141c1c2
Created June 2, 2014 10:04
Generate random password
function generatePassword(length) {
var charset = "abcdefghijklnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789",
retVal = "";
for (var i = 0, n = charset.length; i < length; ++i) {
retVal += charset.charAt(Math.floor(Math.random() * n));
}
return retVal;
}
document.activeElement.value = prompt('Password:', generatePassword(16));
.inner {
position: relative;
top: 50%;
transform: translateY(-50%);
}
@askehansen
askehansen / gist:11253752
Created April 24, 2014 12:59
parsley 2.x config for twitter bootstrap 3.x
window.ParsleyConfig = {
errorClass: 'has-error',
successClass: 'has-success',
classHandler: function (ParsleyField) {
return ParsleyField.$element.parents('.form-group');
},
errorsContainer: function (ParsleyField) {
return ParsleyField.$element.parents('.form-group');
},
errorsWrapper: '<span class="help-block">',
before_action :set_order
def set_order
if session[:order_id]
@order = Order.find(session[:order_id])
else
@order = Order.new
end
end