Skip to content

Instantly share code, notes, and snippets.

View isochronous's full-sized avatar

Jeremy McLeod isochronous

  • DataScan
  • Atlanta, GA
View GitHub Profile
@isochronous
isochronous / gulpfile.js
Last active May 2, 2016 10:13
The gulpfile we use for our webapp-in-android-app project
var gulp = require('gulp'),
// Used to process `include` statements in source files
includer = require('gulp-includer'),
// Compiles SASS files using LibSass
sass = require('gulp-sass'),
// Renames files in the file stream
rename = require('gulp-rename'),
// JavaScript minifier
uglify = require('gulp-uglify'),
// Filter files out of the vinyl stream
@isochronous
isochronous / comparatorGenerator.js
Created May 22, 2015 22:25
A client-side comparator generating function for Backbone collections
/**
* This method creates a new comparator function that should correctly sort by the right field in the correct order
* assuming the sorting is specified by a single field with a "attributeName-asc/desc" format. Add as a change handler
* for your sortBy field, add `this.on('sync', this.sort)` to the collection, and you're ready to go.
* @param {Backbone.Model} model
* @param {string} newSortBy
* @deprecated
*/
updateCollectionComparator: function(model, newSortBy) {
var theCollection = this.someCollection, // change this line
@isochronous
isochronous / chosen.jquery.js
Created April 29, 2015 17:52
Chosen with fix to update classNames and title from select on update. Prototype version is a separate file below the jQuery version.
/*!
Chosen, a Select Box Enhancer for jQuery and Prototype
by Patrick Filler for Harvest, http://getharvest.com
Version 1.4.2
Full source at https://github.com/harvesthq/chosen
Copyright (c) 2011-2015 Harvest http://getharvest.com
MIT License, https://github.com/harvesthq/chosen/blob/master/LICENSE.md
This file is generated by `grunt build`, do not edit it by hand.
@isochronous
isochronous / jQueryUI Widget Skeleton.js
Created April 27, 2015 23:48
jQueryUI Widget Skeleton (basic comments only)
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(root.jQuery);
}
}(this, function ($) {
@isochronous
isochronous / jQueryUI-Widget-Skeleton-Integrated-Docs.js
Last active August 29, 2015 14:20
jQueryUI Widget Skeleton (integrated documentation)
// Use AMD loader if present, if not use global jQuery
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['jquery'], factory);
} else {
// Browser globals
factory(root.jQuery);
}
}(this, function ($) {
@isochronous
isochronous / Example widget code
Created September 13, 2013 18:49
This is just a widget I wrote (won't have any meaning outside of the project I'm working on) that I put up to show an example of how I write jQuery widgets, and contains some optimizations to make it as performant as possible by minimizing DOM operations.
define([
'jquery',
'underscore',
'text!./skeletonMarkup.html',
'jqueryui/widget',
'jqueryui/sortable',
'jqueryui/spinner'
], function ($, _, markup) {
'use strict';
@isochronous
isochronous / paths2object
Last active December 20, 2015 12:59
convert a flat object with namespaced keys to a heirarchical object
/**
* Converts a "flat" object with namespaced keys into a hierarchical object
* @param {object} flat - A "flat" object with namespaced keys to turn into a hierarchical object
* @returns object - the hierarchical object
*/
var _paths2obj = function (flat) {
var root = {},
keys = _.keys(flat),
parts, entry, currentPart, pointer, i, il;
@isochronous
isochronous / jquery.ui.toggle-switch.js
Last active December 12, 2015 06:49
taitems toggleswitch converted to AMD-compliant widget
/**
* jQuery UI Toggle Switch
*
* http://taitems.tumblr.com/post/17853682273/jquery-ui-toggleswitch-ux-lab-005
*
* Depends:
* jquery.ui.slider.js
*/
(function (factory) {
if (typeof exports === 'object') {
@isochronous
isochronous / gist:4439430
Last active December 10, 2015 13:08
register a region with a marionette sub-app after root app instantiation
// This code assumes you start all your sub-apps during the root-app's init
// phase. If not, this same logic can be bound to a different event (ex. start).
rootApp.on("initialize:after", function () {
vent.trigger("system:default:region:set", rootApp.body);
});
// Then in some other sub-application
define([
'marionette',
'mysupervent'
@isochronous
isochronous / Backbone.PickySitter Example
Created December 21, 2012 16:07
PickSitter + Backbone.BabySitter + Marionette Layouts = easy wizard pattern
var SelectView = Marionette.ItemView.extend({
initialize: function(options) {
this.bindTo(this, "selected", onSelect);
this.bindTo(this, "deselected", onDeselect);
},
onSelect: function() {
this.model.fetch();
},