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 / Marionette.SubAppRouter.js
Created December 1, 2012 21:46
Backbone.SubRoute functionality for Marionette.AppRouter
// This is heavily based on Backbone.SubRoute (https://github.com/ModelN/backbone.subroute) by Dave Cadwallader, who
// helped me out in this discussion thread:
// https://groups.google.com/forum/?fromgroups=#!topic/backbone-marionette/KTw7USoA6Gs
;define([
'underscore',
'marionette'
],
/**
* A module that defines and adds Marionette.SubAppRouter to the Marionette object
@isochronous
isochronous / Application.root.js
Last active November 17, 2018 10:13
Root app for drop-in multi-app Marionette framework using requireJS and the subapprouter it works with
define([
"underscore",
"backbone",
"marionette",
"vent"
],
/**
* Creates the primary `Marionette.Application` object that runs the admin framework. Provides a central point
* from which all other sub-applications are started, shown, hidden, and stopped.
@isochronous
isochronous / gist:4261718
Created December 11, 2012 20:10
marionette layout fix
var result = Marionette.ItemView.prototype.render.apply(this, arguments);
// FIX: Issue 351 - https://github.com/marionettejs/backbone.marionette/pull/351
// inject regions into template
var that = this;
_.each(this.regionManagers, function(region){
if (region.currentView) {
that.$el.find(region.el).html(region.currentView.$el);
}
});
@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();
},
@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 / 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 / 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 / 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 / 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 / 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 ($) {