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
set: function(attrs, options) { | |
_.each(attrs, function(val, key) { | |
if(!!this.validations[key]) | |
attrs[key] = this.filters[ this.validations[key].filter ](val); | |
}, this); | |
Backbone.Model.prototype.set.call(this, attrs, options); | |
return this; | |
}, |
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
animate : function(director, time) { | |
// General idea: | |
// try to touch the DOM as little as possible, | |
// extra JS calculations much cheaper than extra DOM-settings | |
if ( !this.isInAnimationFrame(time) ) { | |
this.inFrame= false; | |
this.dirty= true; | |
this.style( 'display', 'none'); |
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
// Since Posterous don't support javascript: | |
// Just add whatever link as bookmark, and paste this as the link instead | |
javascript:(function() { editors.javascript.setOption("lineNumbers", true); editors.html.setOption("lineNumbers", true); })(); |
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
(function(m) { | |
m.OnceBehavior = function() { | |
m.OnceBehavior.superclass.constructor.call(this); | |
}; | |
m.OnceBehavior.prototype = { | |
setForTime : function(time, actor) { | |
if(this.oldtime && this.oldtime > time) | |
this.callback(); |
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
Are you also having problems installing jshint (or other module) on Lion: | |
this is what i saw: | |
npm ERR! Error: ENOENT, chmod | |
... and loads of other stuff | |
This worked for me: | |
1. Clone the node-jshint repo |
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 partial = function(func) { | |
return Function.prototype.bind.apply(func, arguments); | |
}; | |
function add() { | |
var x = 0; | |
[].forEach.call(arguments, function(el) { | |
x += el; |
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
/* | |
* Example of using nested collections/models with backbone.js and backbone.js localStorage | |
* | |
* Read the complete blog post at karlwestin.posterous.com | |
* | |
* 1. run populate() from command line first time | |
* 2. reload the page (or open in another browser tab), and check the following: | |
* | |
* premier.at(0).get("name") => "Tottenham" | |
* premier.at(0).players.length => 3 |
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
/* | |
* Karl Westin | |
* Part of the "refactoring javascript for unit testing" blog post | |
*/ | |
$(document).ready(function() { | |
$("#boxlink").bind("click", function(e) { | |
var content = "<div class='js-overlay'></div>" + | |
"<div class='js-dialog'>" + |
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
/* | |
* Karl Westin | |
* Part of the "refactoring javascript for unit testing" blog post | |
*/ | |
function Lightbox(boxcontent) { | |
var content = "<div class='js-overlay'></div>" + | |
"<div class='js-dialog'>" + | |
"<a href='#' class='js-close'>Close</a>" + | |
"<div class='js-content'>" + |
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
describe("Lightbox tests", function() { | |
beforeEach(function() { | |
var content = "<div style='width: 100px; height: 110px; position: relative; display: inline-block; background-color: #fff;'>My test-content</div>" | |
// for unit-testing purposes, we turn jQuery.fx off | |
$.fx.off = true; | |
setFixtures(sandbox()); | |
this.$sandbox = $("#sandbox"); |