This file contains hidden or 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 __in__ = function(elem, array){ | |
array.forEach(function(item) { | |
if (item === elem) return true; | |
}); | |
return false; | |
}; | |
var __filter_keys = function(obj, filter) { | |
var result = {}; | |
var extraKeys = $.grep(Object.keys(obj), function(el, i) { |
This file contains hidden or 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
(function(CollectionPrototype, ModelPrototype, slice) { | |
var monkeyPatch = function(prototype, name) { | |
var method = prototype[name]; | |
prototype[name] = function() { | |
var | |
args = slice.call(arguments) | |
,length = args.length | |
,options = length && length >= method.length && args[args.length - 1] | |
; |
This file contains hidden or 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
(function() { | |
Backbone.Model.prototype._save = Backbone.Model.prototype.save; | |
Backbone.Model.prototype.save = function(attrs, options) { | |
var that = this; | |
if (!options) { options = {}; } | |
if (this.savingNewRecord) { | |
// store or replace last PUT request with the latest version, we can safely replace old PUT requests with new ones | |
// but if there are callbacks from a previous PUT request, we need to make sure they are all called as well | |
_(['success','error']).each(function(event) { | |
// convert all callbacks to a single array of callbacks) |
This file contains hidden or 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
(function() { | |
var A, | |
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; | |
A = (function() { | |
function A(msg) { | |
this.msg = msg; | |
this.fat = __bind(this.fat, this); |
This file contains hidden or 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
# Override `Backbone.ajax` to queue all requests. | |
# Cache Backbone ajax function, by default, just $.ajax | |
_ajax = Backbone.ajax | |
# Override Backbone.ajax to queue all requests to prevent | |
# lost updates. | |
Backbone.ajax = (options) -> | |
@ajax.queue options |
This file contains hidden or 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
isEmptyObject: function( obj ) { | |
var name; | |
for ( name in obj ) { | |
return false; | |
} | |
return true; | |
}, |
This file contains hidden or 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
Show hidden characters
[ | |
{ "keys": ["ctrl+shift+x"], "command": "tidy_xml" }, | |
{ "keys": ["ctrl+shift+j"], "command": "prettify_json" } | |
] |
This file contains hidden or 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 make = function() { | |
var v = {}; | |
elems = ["a", "div", "span", "form", "h1", "h2", "h3", "h4"]; | |
for (var i in elems) { | |
v[elems[i]] = make_handler(elems[i]); | |
} | |
return v; | |
}(); | |
function make_handler(el) { |
This file contains hidden or 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
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind. | |
// Hat tip Paul Irish | |
var o = $( {} ); | |
$.subscribe = o.on.bind(o); | |
$.unsubscribe = o.off.bind(o); | |
$.publish = o.trigger.bind(o); | |
// Usage | |
$(document.body).on( 'click', function() { |
This file contains hidden or 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
/* jQuery Tiny Pub/Sub - v0.7 - 10/27/2011 | |
* http://benalman.com/ | |
* Copyright (c) 2011 "Cowboy" Ben Alman; Licensed MIT, GPL */ | |
(function($) { | |
var o = $({}); | |
$.subscribe = function() { | |
o.on.apply(o, arguments); |