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
| // Change underscore's templating from ERB-style to Mustache-style | |
| _.templateSettings = { | |
| interpolate : /\{\{(.+?)\}\}/g | |
| }; |
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 (root, factory) { | |
| if (typeof define === 'function' && define.amd) { | |
| // AMD. Register as an anonymous module. | |
| define(['bean', 'underscore'], function (bean, _) { | |
| // Also create a global in case some scripts | |
| // that are loaded still are looking for | |
| // a global even when an AMD loader is in use. | |
| return (root.Flotr2 = factory(bean, _)); | |
| }); | |
| } else { |
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
| return _.reduce($el.serializeArray(), function (hash, pair) { | |
| hash[pair.name] = pair.value; | |
| return hash; | |
| }, {}); |
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 parseQueryParams = function(params) { | |
| if(!params) { return {}; } | |
| return _.reduce(params.split('&'), function (hash, param) { | |
| var p = param.split('='); | |
| hash[p[0]] = p[1]; | |
| return hash; | |
| }, {}); | |
| }; |
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 EMAIL_REGEX = /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,253}[a-zA-Z0-9])?)*$/; | |
| var isValidEmailAddress = function(email) { | |
| return EMAIL_REGEX.test(email); | |
| }; |
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
| define(function(require, exports, module) { | |
| var _ = require('lodash'); | |
| var Validator = require('backbone.validator'); | |
| // Duck-punch so that we get the errors in the right format: | |
| // Instead of | |
| // { | |
| // field1: [ "errormsg1", "errormsg2" ], | |
| // field2: [ "errormsg3" ] |
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
| // Store a copy of the original Backbone.sync | |
| var originalSync = Backbone.sync; | |
| // Override Backbone.sync for all future requests. | |
| Backbone.sync = function(method, model, options) { | |
| // Do something special here | |
| // And then call the original sync | |
| return originalSync.call(model, method, model, 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
| Backbone.View.extend({ | |
| constructor: function (options) { | |
| // Do stuff before the View has been setup | |
| Backbone.View.apply(this, arguments); | |
| // Do stuff after the View has been setup, | |
| // particularly after `initialize()` has been called | |
| return 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
| var UserModel = Backbone.Model.extend({ | |
| defaults: { | |
| username: "", | |
| password: { | |
| old: "", | |
| new: "", | |
| confirm: "" | |
| } | |
| }, |
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
| exports.promise = function(work) { | |
| var dfd = $.Deferred(); | |
| work(dfd.resolve, dfd.reject); | |
| return dfd.promise(); | |
| }; | |
| exports.promiseResolved = function() { | |
| return $.Deferred().resolve().promise(); | |
| }; |
OlderNewer