This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is just an extension of https://github.com/gruntjs/grunt-contrib-connect#middleware | |
grunt.initConfig({ | |
connect: { | |
server: { | |
options: { | |
middleware: function(connect, options) { | |
var middlewares = []; | |
if (!Array.isArray(options.base)) { | |
options.base = [options.base]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// All navigation that is relative should be passed through the navigate | |
// method, to be processed by the router. If the link has a `data-bypass` | |
// attribute, bypass the delegation completely. | |
$(document).on('click', 'a[href]:not([data-bypass])', function(ev) { | |
// Get the absolute anchor href. | |
var $link = $(ev.currentTarget); | |
var href = { prop: $link.prop("href"), attr: $link.attr("href") }; | |
// Get the absolute root. | |
var root = location.protocol + "//" + location.host + app.root; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// polyfill window.getMatchedCSSRules() in FireFox 6+ | |
if ( typeof window.getMatchedCSSRules !== 'function' ) { | |
var ELEMENT_RE = /[\w-]+/g, | |
ID_RE = /#[\w-]+/g, | |
CLASS_RE = /\.[\w-]+/g, | |
ATTR_RE = /\[[^\]]+\]/g, | |
// :not() pseudo-class does not add to specificity, but its content does as if it was outside it | |
PSEUDO_CLASSES_RE = /\:(?!not)[\w-]+(\(.*\))?/g, | |
PSEUDO_ELEMENTS_RE = /\:\:?(after|before|first-letter|first-line|selection)/g; | |
// convert an array-like object to array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var net = require('net'); | |
var es = require('event-stream'); | |
var util = require('util'); | |
var _ = require('lodash'); | |
var stream = require('stream'); | |
/** | |
* A socketWrapper wraps a net.Socket object with any number | |
* of readableTransforms and writableTransforms, specified in the options object. | |
* @param {Object} options Options. Options not listed below are forwarded to net.Socket. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*global Backbone: true, _:true */ | |
(function() { | |
"use strict"; | |
/** | |
* Backbone.eventSafety | |
* | |
* Simple plugin that throws an error when Backbone.Events.on & Backbone.Events.once are called | |
* without a callback. Because you might be counting on that and accidentally pass it undefined | |
* because of a scoping error. | |
* Why Backbone doesn't do that, only God and @jashkenas knows. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* View mixin - allows parent views to have their own events objects & initialize methods. | |
* | |
* Usage: On your parent view only: | |
* var MyView = Backbone.View.extend(ExtendableMixin).extend({ // ... }) | |
* | |
* NOTICE: This completely breaks when using the Backbone-tools chrome extension. It modifies View.constructor. | |
*/ | |
var ExtendableMixin = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var oldLoadUrl = Backbone.History.prototype.loadUrl; | |
_.extend(Backbone.History.prototype, { | |
/** | |
* Override loadUrl & watch return value. Trigger event if no route was matched. | |
* @return {Boolean} True if a route was matched | |
*/ | |
loadUrl : function() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require([ | |
'app', | |
'backbone', | |
// Application Router | |
'routers/ApplicationRouter' | |
], | |
function(app, Backbone, ApplicationRouter) { | |
// Define your master router on the application namespace and trigger all |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define([ | |
'jquery', | |
'lodash', | |
'backbone', | |
'backbone-forms' | |
], function($, _, Backbone, BackboneForms) { | |
'use strict'; | |
/** | |
* This class contains overrides & patches for the Backbone.Form class. |