Skip to content

Instantly share code, notes, and snippets.

View pwfisher's full-sized avatar

Patrick Fisher pwfisher

View GitHub Profile
@pwfisher
pwfisher / jquery.nodoubletapzoom.js
Created July 27, 2012 08:39 — forked from johan/jquery.nodoubletapzoom.js
A jQuery plugin to selectively disable the iOS double-tap-to-zoom action on specific page elements (and have that generate two click events instead).
// jQuery no-double-tap-zoom plugin
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy!
(function($) {
var IS_IOS = /iphone|ipad/i.test(navigator.userAgent);
$.fn.nodoubletapzoom = function() {
if (IS_IOS)
$(this).bind('touchstart', function preventZoom(e) {
var now = (new Date().getTime()),
Ember.Handlebars.helper 'currency', (value) ->
'$' + parseFloat(value).toFixed(2)#.replace(/\d{1,3}(?=(\d{3})+(?!\d))/g , '$&,')
Ember.Handlebars.helper 'date', (date, format) ->
moment(date).format(if typeof format is 'string' then format else 'MMMM D')
Ember.Handlebars.helper 'from-now', (date) ->
moment(date).fromNow()
Ember.Handlebars.helper 'or', (args...) ->
return arg for arg in args when !!arg
Ember.Handlebars.helper 'image', (path, options) ->
attrs = for key, value of options.hash when typeof value is 'string' then "#{key}=\"#{value}\""
attrs.unshift 'src="//example.com/assets/' + path + '"'
new Handlebars.SafeString '<img ' + (attrs.join ' ') + '>'
@pwfisher
pwfisher / gtm-util.js
Last active April 20, 2021 19:32
Ember.js Google Tag Manager utility
// Google Tag Manager
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s);j.async=true;j.src=
'//www.googletagmanager.com/gtm.js?id='+i;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-ABCDEF');
// End Google Tag Manager
App.GtmUtil = {
@pwfisher
pwfisher / radio-button-component.js
Last active August 29, 2015 14:07 — forked from courajs/helpers-radio-button.js
radio-button-component.js
// {{ radio-button name='dish' value='spam' groupValue=selectedDish }} Spam
// {{ radio-button name='dish' value='eggs' groupValue=selectedDish }} Eggs
//
App.RadioButtonComponent = Ember.Component.extend({
tagName: 'input',
type: 'radio',
attributeBindings: [ 'checked', 'name', 'type', 'value' ],
checked: function () {
@pwfisher
pwfisher / jquery-xsrf.js
Created October 23, 2014 22:56
Set XSRF token header for POST, PUT and DELETE requests to relative URLs
//
// Set XSRF token header for POST, PUT and DELETE requests to relative URLs
//
$.ajaxSetup({
beforeSend: function (xhr, settings) {
if (/^https?:/.test(settings.url)) return;
if (!/(POST|PUT|DELETE)/.test(settings.type)) return;
xhr.setRequestHeader('X-XSRF-TOKEN', $.cookie('XSRF-TOKEN'));
}
});
@pwfisher
pwfisher / build-svg-icon-sprite.js
Last active August 29, 2015 14:11
SVG Sprite Icons in Ember.js
gulp.task('build-svg-icon-sprite', function () {
return gulp.src(conf.get('build:svg-sprite-icons:source'))
.pipe(svgo({
full: false,
plugins: [
{ cleanupIDs: true },
{ removeUnknownsAndDefaults: false }
]
}))
.pipe(fc2json('svg-icon-sprite.json'))
@pwfisher
pwfisher / ember-component-bubble-action.js
Created December 16, 2014 01:21
"bubble" action for all Ember components which sends the given action
Ember.Component.reopen({
actions: {
bubble: function (action) {
console.log('[Component action.bubble]', arguments);
var temp = this.get(action);
this.set(action, action);
this.sendAction(action);
this.set(action, temp);