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) { | |
| var proto = Backbone.Model.prototype; | |
| // Add a model, or list of models to the set. | |
| proto.add = function(models, options) { | |
| options = _.extend({ | |
| add: true, | |
| merge: false, | |
| remove: false |
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 CustomModel = Backbone.Model.extend({ | |
| constructor: function () { | |
| this.yourOtherModel = new YourOtherModel(); | |
| Backbone.Model.apply(this, arguments) | |
| }, | |
| parse: function () { | |
| // your parse. | |
| } |
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 Flower = Backbone.Model.extend({ | |
| parse: function (attrs, options) { | |
| // return parsed attrs | |
| } | |
| }); | |
| var Tree = Flower.extend({ | |
| parse: function (attrs, options) { | |
| attrs = Flower.prototype.parse.apply(this, arguments); | |
| // Do something with the parsed attrs here and |
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
| // Overriding sync | |
| var Sync = Backbone.sync; | |
| Backbone.sync = function (method, model, options) { | |
| var success = options.success; | |
| var error = options.error; | |
| // Your custom code goes here, you should be able to access | |
| // the xhr via options.xhr, or in the second argument from the ajax call. | |
| options.success = function (resp, status, xhr) { | |
| success.apply(this, arguments); |
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
| // Bookshelf.js 0.1.0 | |
| // (c) 2013 Tim Griesser | |
| // Bookshelf may be freely distributed under the MIT license. | |
| // For all details and documentation: | |
| // http://bookshelfjs.org | |
| (function() { | |
| // Initial Setup |
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
| class Footer extends ItemView | |
| events: | |
| "click .test": "test" | |
| class AppFooter extends Footer | |
| events: -> | |
| _.extend {}, Footer::events, | |
| # Anyway to mixin the parent events? So it isn't duplicated. | |
| # "click .test": "test" | |
| "click .test2": "test2" |
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
| $.fn.toJSON = -> | |
| # Serialize the array. | |
| data = this.serializeArray() | |
| data = _.reduce data, (memo, item) -> | |
| if memo[item.name] and not _.isArray(memo[item.name]) | |
| memo[item.name] = [memo[item.name], item.value] | |
| else if _.isArray(memo[item.name]) | |
| memo[item.name].push(item.value) | |
| 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
| Bookshelf.Model.prototype.format = function(attrs) { | |
| return _.reduce(attrs, function(memo, val, key) { | |
| memo[_.str.underscored(key)] = val; | |
| return memo; | |
| }, {}); | |
| }; | |
| Bookshelf.Model.prototype.parse = function(attrs) { | |
| return _.reduce(attrs, function(memo, val, key) { |
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
| // CheckIt.js 0.1.0 | |
| // http://tgriesser.com/checkit | |
| // (c) 2013 Tim Griesser | |
| // CheckIt may be freely distributed under the MIT license. | |
| (function() { | |
| "use strict"; |
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 Knex = require('knex'); | |
| Knex.Initialize({ | |
| client: 'mysql', | |
| connection: { | |
| user : 'root', | |
| password : 'password', | |
| database : 'dbname' | |
| } | |
| }); |