diff --git a/backbone-min.js b/backbone-min.js index d2e95b434..f29903b1a 100644 --- a/backbone-min.js +++ b/backbone-min.js @@ -1,2 +1,2 @@ -(function(t){var e=typeof self=="object"&&self.self==self&&self||typeof global=="object"&&global.global==global&&global;if(typeof define==="function"&&define.amd){define(["underscore","jquery","exports"],function(i,r,s){e.Backbone=t(e,s,i,r)})}else if(typeof exports!=="undefined"){var i=require("underscore"),r;try{r=require("jquery")}catch(s){}t(e,exports,i,r)}else{e.Backbone=t(e,{},e._,e.jQuery||e.Zepto||e.ender||e.$)}})(function(t,e,i,r){var s=t.Backbone;var n=[];var a=n.slice;e.VERSION="1.2.0";e.$=r;e.noConflict=function(){t.Backbone=s;return this};e.emulateHTTP=false;e.emulateJSON=false;var o=e.Events={};var h=/\s+/;var u=function(t,e,r,s,n){var a=0,o;if(r&&typeof r==="object"){for(o=i.keys(r);a=1.7.0" diff --git a/component.json b/component.json index 9fb9099ed..3418c4be4 100644 --- a/component.json +++ b/component.json @@ -1,6 +1,6 @@ { "name" : "backbone", - "version" : "1.2.0", + "version" : "1.2.1", "description" : "Give your JS App some Backbone with Models, Views, Collections, and Events.", "keywords" : ["model", "view", "controller", "router", "server", "client", "browser"], "repo" : "jashkenas/backbone", diff --git a/docs/backbone.html b/docs/backbone.html index 5d0e46994..7b536b1d6 100644 --- a/docs/backbone.html +++ b/docs/backbone.html @@ -27,7 +27,7 @@

backbone.js

-
Backbone.js 1.2.0
+              
Backbone.js 1.2.1
 
@@ -187,12 +187,11 @@

Initial Setup

-

Create local references to array methods we’ll want to use later.

+

Create a local reference to a common array method we’ll want to use later.

-
  var array = [];
-  var slice = array.slice;
+
  var slice = [].slice;
@@ -207,7 +206,7 @@

Initial Setup

-
  Backbone.VERSION = '1.2.0';
+
  Backbone.VERSION = '1.2.1';
@@ -288,10 +287,38 @@

Initial Setup

-

Backbone.Events

+

Proxy Underscore methods to a Backbone class’ prototype using a +particular attribute as the data argument

+
  var addMethod = function(length, method, attribute) {
+    switch (length) {
+      case 1: return function() {
+        return _[method](this[attribute]);
+      };
+      case 2: return function(value) {
+        return _[method](this[attribute], value);
+      };
+      case 3: return function(iteratee, context) {
+        return _[method](this[attribute], iteratee, context);
+      };
+      case 4: return function(iteratee, defaultVal, context) {
+        return _[method](this[attribute], iteratee, defaultVal, context);
+      };
+      default: return function() {
+        var args = slice.call(arguments);
+        args.unshift(this[attribute]);
+        return _[method].apply(_, args);
+      };
+    }
+  };
+  var addUnderscoreMethods = function(Class, methods, attribute) {
+    _.each(methods, function(length, method) {
+      if (_[method]) Class.prototype[method] = addMethod(length, method, attribute);
+    });
+  };
+ @@ -301,7 +328,8 @@

Backbone.Events

- +

Backbone.Events

+ @@ -313,6 +341,18 @@

Backbone.Events

+ + + + + + +
  • +
    + +
    + +

    A module that can be mixed in to any object in order to provide it with custom events. You may bind with on or remove with off callback functions to an event; trigger-ing an event fires all callbacks in @@ -329,11 +369,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Regular expression used to split event strings.

    @@ -344,11 +384,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Iterates over the standard event, callback (as well as the fancy multiple space-separated events "change blur", callback and jQuery-style event @@ -365,17 +405,18 @@

    Backbone.Events

  • -
  • +
  • - +

    Handle event maps.

    -
          for (names = _.keys(name); i < names.length ; i++) {
    +            
          if (callback !== void 0 && 'context' in opts && opts.context === void 0) opts.context = callback;
    +      for (names = _.keys(name); i < names.length ; i++) {
             memo = iteratee(memo, names[i], name[names[i]], opts);
           }
         } else if (name && eventSplitter.test(name)) {
    @@ -383,11 +424,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Handle space separated event names.

    @@ -405,11 +446,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Bind an event to a callback function. Passing "all" will bind the callback to all events fired.

    @@ -423,11 +464,11 @@

    Backbone.Events

  • -
  • +
  • - +

    An internal use on function, used to guard the listening argument from the public API.

    @@ -452,11 +493,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Inversion-of-control versions of on. Tell this object to listen to an event in another object… keeping track of what it’s listening to.

    @@ -472,11 +513,11 @@

    Backbone.Events

  • -
  • +
  • - +

    This object is not listening to any other events on obj yet. Setup the necessary references to track the listening callbacks.

    @@ -491,11 +532,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Bind callbacks on obj, and keep track of them on listening.

    @@ -508,11 +549,11 @@

    Backbone.Events

  • -
  • +
  • - +

    The reducing API that adds a callback to the events object.

    @@ -532,11 +573,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Remove one or many callbacks. If context is null, removes all callbacks with that function. If callback is null, removes all @@ -557,11 +598,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Tell this object to stop listening to either specific events … or to every object it’s currently listening to.

    @@ -580,11 +621,11 @@

    Backbone.Events

  • -
  • +
  • - +

    If listening doesn’t exist, this object is not currently listening to obj. Break out early.

    @@ -603,11 +644,11 @@

    Backbone.Events

  • -
  • +
  • - +

    The reducing API that removes a callback from the events object.

    @@ -618,11 +659,11 @@

    Backbone.Events

  • -
  • +
  • - +

    No events to consider.

    @@ -630,17 +671,17 @@

    Backbone.Events

        if (!events) return;
     
    -    var i = 0, length, listening;
    +    var i = 0, listening;
         var context = options.context, listeners = options.listeners;
  • -
  • +
  • - +

    Delete all events listeners and “drop” events.

    @@ -664,11 +705,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Bail out if there are no events stored.

    @@ -679,11 +720,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Replace events if there are any remaining. Otherwise, clean up.

    @@ -710,11 +751,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Update tail event if the list has any events. Otherwise, clean up.

    @@ -732,11 +773,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Bind an event to only be triggered a single time. After the first time the callback is invoked, it will be removed. When multiple events are @@ -750,11 +791,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Map the event into a {event: once} object.

    @@ -767,11 +808,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Inversion-of-control versions of once.

    @@ -782,11 +823,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Map the event into a {event: once} object.

    @@ -799,14 +840,14 @@

    Backbone.Events

  • -
  • +
  • - +

    Reduces the event callbacks into a map of {event: onceWrapper}. -offer unbinds the onceWrapper after it as been called.

    +offer unbinds the onceWrapper after it has been called.

    @@ -824,11 +865,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Trigger one or many events, firing all bound callbacks. Callbacks are passed the same arguments as trigger is, apart from the event name @@ -851,11 +892,11 @@

    Backbone.Events

  • -
  • +
  • - +

    Handles triggering the appropriate event callbacks.

    @@ -875,11 +916,11 @@

    Backbone.Events

  • -
  • +
  • - +

    A difficult-to-believe, but optimized internal dispatch function for triggering events. Tries to keep the usual cases speedy (most internal @@ -901,47 +942,6 @@

    Backbone.Events

  • -
  • -
    - -
    - -
    -

    Proxy Underscore methods to a Backbone class’ prototype using a -particular attribute as the data argument

    - -
    - -
      var addMethod = function(length, method, attribute) {
    -    switch (length) {
    -      case 1: return function() {
    -        return _[method](this[attribute]);
    -      };
    -      case 2: return function(value) {
    -        return _[method](this[attribute], value);
    -      };
    -      case 3: return function(iteratee, context) {
    -        return _[method](this[attribute], iteratee, context);
    -      };
    -      case 4: return function(iteratee, defaultVal, context) {
    -        return _[method](this[attribute], iteratee, defaultVal, context);
    -      };
    -      default: return function() {
    -        var args = slice.call(arguments);
    -        args.unshift(this[attribute]);
    -        return _[method].apply(_, args);
    -      };
    -    }
    -  };
    -  var addUnderscoreMethods = function(Class, methods, attribute) {
    -    _.each(methods, function(length, method) {
    -      if (_[method]) Class.prototype[method] = addMethod(length, method, attribute);
    -    });
    -  };
    - -
  • - -
  • @@ -1252,7 +1252,6 @@

    Backbone.Model

        set: function(key, val, options) {
    -      var attr, attrs, unset, changes, silent, changing, prev, current;
           if (key == null) return this;
  • @@ -1268,7 +1267,8 @@

    Backbone.Model

    -
          if (typeof key === 'object') {
    +            
          var attrs;
    +      if (typeof key === 'object') {
             attrs = key;
             options = val;
           } else {
    @@ -1305,17 +1305,20 @@ 

    Backbone.Model

    -
          unset           = options.unset;
    -      silent          = options.silent;
    -      changes         = [];
    -      changing        = this._changing;
    -      this._changing  = true;
    +            
          var unset      = options.unset;
    +      var silent     = options.silent;
    +      var changes    = [];
    +      var changing   = this._changing;
    +      this._changing = true;
     
           if (!changing) {
             this._previousAttributes = _.clone(this.attributes);
             this.changed = {};
           }
    -      current = this.attributes, prev = this._previousAttributes;
    + + var current = this.attributes; + var changed = this.changed; + var prev = this._previousAttributes;
    @@ -1345,13 +1348,13 @@

    Backbone.Model

    -
          for (attr in attrs) {
    +            
          for (var attr in attrs) {
             val = attrs[attr];
             if (!_.isEqual(current[attr], val)) changes.push(attr);
             if (!_.isEqual(prev[attr], val)) {
    -          this.changed[attr] = val;
    +          changed[attr] = val;
             } else {
    -          delete this.changed[attr];
    +          delete changed[attr];
             }
             unset ? delete current[attr] : current[attr] = val;
           }
    @@ -1479,13 +1482,14 @@

    Backbone.Model

        changedAttributes: function(diff) {
           if (!diff) return this.hasChanged() ? _.clone(this.changed) : false;
    -      var val, changed = false;
           var old = this._changing ? this._previousAttributes : this.attributes;
    +      var changed = {};
           for (var attr in diff) {
    -        if (_.isEqual(old[attr], (val = diff[attr]))) continue;
    -        (changed || (changed = {}))[attr] = val;
    +        var val = diff[attr];
    +        if (_.isEqual(old[attr], val)) continue;
    +        changed[attr] = val;
           }
    -      return changed;
    +      return _.size(changed) ? changed : false;
         },
    @@ -1540,12 +1544,12 @@

    Backbone.Model

        fetch: function(options) {
    -      options = options ? _.clone(options) : {};
    -      if (options.parse === void 0) options.parse = true;
    +      options = _.extend({parse: true}, options);
           var model = this;
           var success = options.success;
           options.success = function(resp) {
    -        if (!model.set(model.parse(resp, options), options)) return false;
    +        var serverAttrs = options.parse ? model.parse(resp, options) : resp;
    +        if (!model.set(serverAttrs, options)) return false;
             if (success) success.call(options.context, model, resp, options);
             model.trigger('sync', model, resp, options);
           };
    @@ -1568,8 +1572,7 @@ 

    Backbone.Model

    -
        save: function(key, val, options) {
    -      var attrs, method, xhr, attributes = this.attributes, wait;
    +
        save: function(key, val, options) {
    @@ -1584,15 +1587,16 @@

    Backbone.Model

    -
          if (key == null || typeof key === 'object') {
    +            
          var attrs;
    +      if (key == null || typeof key === 'object') {
             attrs = key;
             options = val;
           } else {
             (attrs = {})[key] = val;
           }
     
    -      options = _.extend({validate: true}, options);
    -      wait = options.wait;
    + options = _.extend({validate: true, parse: true}, options); + var wait = options.wait;
    @@ -1624,13 +1628,15 @@

    Backbone.Model

    -

    Set temporary attributes if {wait: true}.

    +

    After a successful server-side save, the client is (optionally) +updated with the server-side state.

    -
          if (attrs && wait) {
    -        this.attributes = _.extend({}, attributes, attrs);
    -      }
    +
          var model = this;
    +      var success = options.success;
    +      var attributes = this.attributes;
    +      options.success = function(resp) {
    @@ -1641,15 +1647,18 @@

    Backbone.Model

    -

    After a successful server-side save, the client is (optionally) -updated with the server-side state.

    +

    Ensure attributes are restored during synchronous saves.

    -
          if (options.parse === void 0) options.parse = true;
    -      var model = this;
    -      var success = options.success;
    -      options.success = function(resp) {
    +
            model.attributes = attributes;
    +        var serverAttrs = options.parse ? model.parse(resp, options) : resp;
    +        if (wait) serverAttrs = _.extend({}, attrs, serverAttrs);
    +        if (serverAttrs && !model.set(serverAttrs, options)) return false;
    +        if (success) success.call(options.context, model, resp, options);
    +        model.trigger('sync', model, resp, options);
    +      };
    +      wrapError(this, options);
    @@ -1660,24 +1669,15 @@

    Backbone.Model

    -

    Ensure attributes are restored during synchronous saves.

    +

    Set temporary attributes if {wait: true} to properly find new ids.

    -
            model.attributes = attributes;
    -        var serverAttrs = options.parse ? model.parse(resp, options) : resp;
    -        if (wait) serverAttrs = _.extend(attrs || {}, serverAttrs);
    -        if (_.isObject(serverAttrs) && !model.set(serverAttrs, options)) {
    -          return false;
    -        }
    -        if (success) success.call(options.context, model, resp, options);
    -        model.trigger('sync', model, resp, options);
    -      };
    -      wrapError(this, options);
    +            
          if (attrs && wait) this.attributes = _.extend({}, attributes, attrs);
     
    -      method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
    +      var method = this.isNew() ? 'create' : (options.patch ? 'patch' : 'update');
           if (method === 'patch' && !options.attrs) options.attrs = attrs;
    -      xhr = this.sync(method, this, options);
    + var xhr = this.sync(method, this, options);
    @@ -1692,7 +1692,7 @@

    Backbone.Model

    -
          if (attrs && wait) this.attributes = attributes;
    +            
          this.attributes = attributes;
     
           return xhr;
         },
    @@ -1761,8 +1761,8 @@

    Backbone.Model

    _.result(this.collection, 'url') || urlError(); if (this.isNew()) return base; - var id = this.id || this.attributes[this.idAttribute]; - return base.replace(/([^\/])$/, '$1/') + encodeURIComponent(id); + var id = this.get(this.idAttribute); + return base.replace(/[^\/]$/, '$&/') + encodeURIComponent(id); },
    @@ -1831,7 +1831,7 @@

    Backbone.Model

        isValid: function(options) {
    -      return this._validate({}, _.extend(options || {}, { validate: true }));
    +      return this._validate({}, _.defaults({validate: true}, options));
         },
    @@ -2035,7 +2035,7 @@

    Backbone.Collection

        toJSON: function(options) {
    -      return this.map(function(model){ return model.toJSON(options); });
    +      return this.map(function(model) { return model.toJSON(options); });
         },
    @@ -2086,12 +2086,12 @@

    Backbone.Collection

        remove: function(models, options) {
    -      var singular = !_.isArray(models), removed;
    +      options = _.extend({}, options);
    +      var singular = !_.isArray(models);
           models = singular ? [models] : _.clone(models);
    -      options || (options = {});
    -      removed = this._removeModels(models, options);
    +      var removed = this._removeModels(models, options);
           if (!options.silent && removed) this.trigger('update', this, options);
    -      return singular ? models[0] : models;
    +      return singular ? removed[0] : removed;
         },
    @@ -2112,7 +2112,7 @@

    Backbone.Collection

        set: function(models, options) {
           options = _.defaults({}, options, setOptions);
    -      if (options.parse) models = this.parse(models, options);
    +      if (options.parse && !this._isModel(models)) models = this.parse(models, options);
           var singular = !_.isArray(models);
           models = singular ? (models ? [models] : []) : models.slice();
           var id, model, attrs, existing, sort;
    @@ -2388,8 +2388,7 @@ 

    Backbone.Collection

        pop: function(options) {
           var model = this.at(this.length - 1);
    -      this.remove(model, options);
    -      return model;
    +      return this.remove(model, options);
         },
    @@ -2424,8 +2423,7 @@

    Backbone.Collection

        shift: function(options) {
           var model = this.at(0);
    -      this.remove(model, options);
    -      return model;
    +      return this.remove(model, options);
         },
    @@ -2596,8 +2594,7 @@

    Backbone.Collection

        fetch: function(options) {
    -      options = options ? _.clone(options) : {};
    -      if (options.parse === void 0) options.parse = true;
    +      options = _.extend({parse: true}, options);
           var success = options.success;
           var collection = this;
           options.success = function(resp) {
    @@ -2628,7 +2625,8 @@ 

    Backbone.Collection

        create: function(model, options) {
           options = options ? _.clone(options) : {};
           var wait = options.wait;
    -      if (!(model = this._prepareModel(model, options))) return false;
    +      model = this._prepareModel(model, options);
    +      if (!model) return false;
           if (!wait) this.add(model, options);
           var collection = this;
           var success = options.success;
    @@ -2751,30 +2749,31 @@ 

    Backbone.Collection

    -

    Internal method called by both remove and set. Does not trigger any -additional events. Returns true if anything was actually removed.

    +

    Internal method called by both remove and set. +Returns removed models, or false if nothing is removed.

        _removeModels: function(models, options) {
    -      var i, l, index, model, removed = false;
    -      for (var i = 0, j = 0; i < models.length; i++) {
    -        var model = models[i] = this.get(models[i]);
    +      var removed = [];
    +      for (var i = 0; i < models.length; i++) {
    +        var model = this.get(models[i]);
             if (!model) continue;
    -        var id = this.modelId(model.attributes);
    -        if (id != null) delete this._byId[id];
    -        delete this._byId[model.cid];
    +
             var index = this.indexOf(model);
             this.models.splice(index, 1);
             this.length--;
    +
             if (!options.silent) {
               options.index = index;
               model.trigger('remove', model, this, options);
             }
    -        models[j++] = model;
    +
    +        removed.push(model);
             this._removeReference(model, options);
    -        removed = true;
    -      }
    + } + return removed.length ? removed : false; + },
    @@ -2785,24 +2784,6 @@

    Backbone.Collection

    -

    We only need to slice if models array should be smaller, which is -caused by some models not actually getting removed.

    - -
    - -
          if (models.length !== j) models = models.slice(0, j);
    -      return removed;
    -    },
    - - - - -
  • -
    - -
    - -

    Method for checking whether an object should be considered a model for the purposes of adding to the collection.

    @@ -2815,11 +2796,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Internal method to create a model’s ties to a collection.

    @@ -2835,17 +2816,20 @@

    Backbone.Collection

  • -
  • +
  • - +

    Internal method to sever a model’s ties to a collection.

        _removeReference: function(model, options) {
    +      delete this._byId[model.cid];
    +      var id = this.modelId(model.attributes);
    +      if (id != null) delete this._byId[id];
           if (this === model.collection) delete model.collection;
           model.off('all', this._onModelEvent, this);
         },
    @@ -2853,11 +2837,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Internal method called every time a model in the set fires an event. Sets need to update their indexes when models change ids. All other @@ -2885,11 +2869,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Underscore methods that we want to implement on the Collection. 90% of the core usefulness of Backbone Collections is actually implemented @@ -2900,7 +2884,7 @@

    Backbone.Collection

      var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 4,
           foldl: 4, inject: 4, reduceRight: 4, foldr: 4, find: 3, detect: 3, filter: 3,
           select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 2,
    -      contains: 2, invoke: 2, max: 3, min: 3, toArray: 1, size: 1, first: 3,
    +      contains: 2, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
           head: 3, take: 3, initial: 3, rest: 3, tail: 3, drop: 3, last: 3,
           without: 0, difference: 0, indexOf: 3, shuffle: 1, lastIndexOf: 3,
           isEmpty: 1, chain: 1, sample: 3, partition: 3 };
    @@ -2908,11 +2892,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Mix in each Underscore method as a proxy to Collection#models.

    @@ -2923,11 +2907,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Underscore methods that take a property name as an argument.

    @@ -2938,11 +2922,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Use attributes instead of properties.

    @@ -2961,11 +2945,11 @@

    Backbone.Collection

  • -
  • +
  • - +

    Backbone.View

    @@ -2974,11 +2958,11 @@

    Backbone.View

  • -
  • +
  • - +
    @@ -2986,11 +2970,11 @@

    Backbone.View

  • -
  • +
  • - +

    Backbone Views are almost more convention than they are actual code. A View is simply a JavaScript object that represents a logical chunk of UI in the @@ -3005,11 +2989,11 @@

    Backbone.View

  • -
  • +
  • - +

    Creating a Backbone.View creates its initial element outside of the DOM, if an existing element is not provided…

    @@ -3018,7 +3002,6 @@

    Backbone.View

      var View = Backbone.View = function(options) {
         this.cid = _.uniqueId('view');
    -    options || (options = {});
         _.extend(this, _.pick(options, viewOptions));
         this._ensureElement();
         this.initialize.apply(this, arguments);
    @@ -3027,11 +3010,11 @@ 

    Backbone.View

  • -
  • +
  • - +

    Cached regex to split keys for delegate.

    @@ -3042,11 +3025,11 @@

    Backbone.View

  • -
  • +
  • - +

    List of view options to be merged as properties.

    @@ -3057,11 +3040,11 @@

    Backbone.View

  • -
  • +
  • - +

    Set up all inheritable Backbone.View properties and methods.

    @@ -3072,11 +3055,11 @@

    Backbone.View

  • -
  • +
  • - +

    The default tagName of a View’s element is "div".

    @@ -3087,11 +3070,11 @@

    Backbone.View

  • -
  • +
  • - +

    jQuery delegate for element lookup, scoped to DOM elements within the current view. This should be preferred to global lookups where possible.

    @@ -3105,11 +3088,11 @@

    Backbone.View

  • -
  • +
  • - +

    Initialize is an empty function by default. Override it with your own initialization logic.

    @@ -3121,11 +3104,11 @@

    Backbone.View

  • -
  • +
  • - +

    render is the core function that your view should override, in order to populate its element (this.el), with the appropriate HTML. The @@ -3140,11 +3123,11 @@

    Backbone.View

  • -
  • +
  • - +

    Remove this view by taking the element out of the DOM, and removing any applicable Backbone.Events listeners.

    @@ -3160,11 +3143,11 @@

    Backbone.View

  • -
  • +
  • - +

    Remove this view’s element from the document and all event listeners attached to it. Exposed for subclasses using an alternative DOM @@ -3179,11 +3162,11 @@

    Backbone.View

  • -
  • +
  • - +

    Change the view’s element (this.el property) and re-delegate the view’s events on the new element.

    @@ -3200,11 +3183,11 @@

    Backbone.View

  • -
  • +
  • - +

    Creates the this.el and this.$el references for this view using the given el. el can be a CSS selector or an HTML string, a jQuery @@ -3222,11 +3205,11 @@

    Backbone.View

  • -
  • +
  • - +

    Set callbacks, where this.events is a hash of

    {“event selector”: “callback”}

    @@ -3242,11 +3225,12 @@

    Backbone.View

        delegateEvents: function(events) {
    -      if (!(events || (events = _.result(this, 'events')))) return this;
    +      events || (events = _.result(this, 'events'));
    +      if (!events) return this;
           this.undelegateEvents();
           for (var key in events) {
             var method = events[key];
    -        if (!_.isFunction(method)) method = this[events[key]];
    +        if (!_.isFunction(method)) method = this[method];
             if (!method) continue;
             var match = key.match(delegateEventSplitter);
             this.delegate(match[1], match[2], _.bind(method, this));
    @@ -3257,11 +3241,11 @@ 

    Backbone.View

  • -
  • +
  • - +

    Add a single event listener to the view’s element (or a child element using selector). This only works for delegate-able events: not focus, @@ -3271,16 +3255,17 @@

    Backbone.View

        delegate: function(eventName, selector, listener) {
           this.$el.on(eventName + '.delegateEvents' + this.cid, selector, listener);
    +      return this;
         },
  • -
  • +
  • - +

    Clears all callbacks previously bound to the view by delegateEvents. You usually don’t need to use this, but may wish to if you have multiple @@ -3296,11 +3281,11 @@

    Backbone.View

  • -
  • +
  • - +

    A finer-grained undelegateEvents for removing a single delegated event. selector and listener are both optional.

    @@ -3309,16 +3294,17 @@

    Backbone.View

        undelegate: function(eventName, selector, listener) {
           this.$el.off(eventName + '.delegateEvents' + this.cid, selector, listener);
    +      return this;
         },
  • -
  • +
  • - +

    Produces a DOM element to be assigned to your view. Exposed for subclasses using an alternative DOM manipulation API.

    @@ -3332,11 +3318,11 @@

    Backbone.View

  • -
  • +
  • - +

    Ensure that the View has a DOM element to render into. If this.el is a string, pass it through $(), take the first @@ -3360,11 +3346,11 @@

    Backbone.View

  • -
  • +
  • - +

    Set attributes from a hash on this view’s element. Exposed for subclasses using an alternative DOM manipulation API.

    @@ -3380,11 +3366,11 @@

    Backbone.View

  • -
  • +
  • - +

    Backbone.sync

    @@ -3393,11 +3379,11 @@

    Backbone.sync

  • -
  • +
  • - +
    @@ -3405,11 +3391,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Override this function to change the manner in which Backbone persists models to the server. You will be passed the type of request, and the @@ -3435,11 +3421,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Default options, unless specified.

    @@ -3453,11 +3439,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Default JSON-request options.

    @@ -3468,11 +3454,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Ensure that we have a URL.

    @@ -3485,11 +3471,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Ensure that we have the appropriate request data.

    @@ -3503,11 +3489,11 @@

    Backbone.sync

  • -
  • +
  • - +

    For older servers, emulate JSON by encoding the request into an HTML-form.

    @@ -3521,11 +3507,11 @@

    Backbone.sync

  • -
  • +
  • - +

    For older servers, emulate HTTP by mimicking the HTTP method with _method And an X-HTTP-Method-Override header.

    @@ -3545,11 +3531,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Don’t process data on a non-GET request.

    @@ -3562,11 +3548,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Pass along textStatus and errorThrown from jQuery.

    @@ -3582,11 +3568,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Make the request, allowing the user to override any Ajax options.

    @@ -3600,11 +3586,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Map from CRUD to HTTP for our default Backbone.sync implementation.

    @@ -3621,11 +3607,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Set the default implementation of Backbone.ajax to proxy through to $. Override this if you’d like to use a different library.

    @@ -3639,11 +3625,11 @@

    Backbone.sync

  • -
  • +
  • - +

    Backbone.Router

    @@ -3652,11 +3638,11 @@

    Backbone.Router

  • -
  • +
  • - +
    @@ -3664,11 +3650,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Routers map faux-URLs to actions, and fire events when routes are matched. Creating a new one sets its routes hash, if not set statically.

    @@ -3685,11 +3671,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Cached regular expressions for matching named param parts and splatted parts of route strings.

    @@ -3704,11 +3690,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Set up all inheritable Backbone.Router properties and methods.

    @@ -3719,11 +3705,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Initialize is an empty function by default. Override it with your own initialization logic.

    @@ -3735,11 +3721,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Manually bind a single named route to a callback. For example:

    this.route('search/:query/p:num', 'search', function(query, num) {
    @@ -3770,11 +3756,11 @@ 

    Backbone.Router

  • -
  • +
  • - +

    Execute a route handler with the provided parameters. This is an excellent place to do pre-route setup or post-route cleanup.

    @@ -3788,11 +3774,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Simple proxy to Backbone.history to save a fragment into the history.

    @@ -3806,11 +3792,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Bind all defined routes to Backbone.history. We have to reverse the order of the routes here to support behavior where the most general @@ -3830,11 +3816,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Convert a route string into a regular expression, suitable for matching against the current location hash.

    @@ -3854,11 +3840,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Given a route, and a URL fragment that it matches, return the array of extracted decoded parameters. Empty or unmatched parameters will be @@ -3873,11 +3859,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Don’t decode the search params.

    @@ -3893,11 +3879,11 @@

    Backbone.Router

  • -
  • +
  • - +

    Backbone.History

    @@ -3906,11 +3892,11 @@

    Backbone.History

  • -
  • +
  • - +
    @@ -3918,11 +3904,11 @@

    Backbone.History

  • -
  • +
  • - +

    Handles cross-browser history management, based on either pushState and real URLs, or @@ -3939,11 +3925,11 @@

    Backbone.History

  • -
  • +
  • - +

    Ensure that History can be used outside of the browser.

    @@ -3958,11 +3944,11 @@

    Backbone.History

  • -
  • +
  • - +

    Cached regex for stripping a leading hash/slash and trailing space.

    @@ -3973,11 +3959,11 @@

    Backbone.History

  • -
  • +
  • - +

    Cached regex for stripping leading and trailing slashes.

    @@ -3988,11 +3974,11 @@

    Backbone.History

  • -
  • +
  • - +

    Cached regex for stripping urls of hash.

    @@ -4003,11 +3989,11 @@

    Backbone.History

  • -
  • +
  • - +

    Has the history handling already been started?

    @@ -4018,11 +4004,11 @@

    Backbone.History

  • -
  • +
  • - +

    Set up all inheritable Backbone.History properties and methods.

    @@ -4033,11 +4019,11 @@

    Backbone.History

  • -
  • +
  • - +

    The default interval to poll for hash changes, if necessary, is twenty times a second.

    @@ -4049,11 +4035,11 @@

    Backbone.History

  • -
  • +
  • - +

    Are we at the app root?

    @@ -4067,11 +4053,11 @@

    Backbone.History

  • -
  • +
  • - +

    Does the pathname match the root?

    @@ -4086,11 +4072,11 @@

    Backbone.History

  • -
  • +
  • - +

    Unicode characters in location.pathname are percent encoded so they’re decoded for comparison. %25 should not be decoded since it may be part @@ -4105,11 +4091,11 @@

    Backbone.History

  • -
  • +
  • - +

    In IE6, the hash fragment and search params are incorrect if the fragment contains ?.

    @@ -4124,11 +4110,11 @@

    Backbone.History

  • -
  • +
  • - +

    Gets the true hash value. Cannot use location.hash directly due to bug in Firefox where location.hash will always be decoded.

    @@ -4143,11 +4129,11 @@

    Backbone.History

  • -
  • +
  • - +

    Get the pathname and search params, without the root.

    @@ -4163,11 +4149,11 @@

    Backbone.History

  • -
  • +
  • - +

    Get the cross-browser normalized URL fragment from the path or hash.

    @@ -4187,11 +4173,11 @@

    Backbone.History

  • -
  • +
  • - +

    Start the hash change handling, returning true if the current URL matches an existing route, and false otherwise.

    @@ -4205,11 +4191,11 @@

    Backbone.History

  • -
  • +
  • - +

    Figure out the initial configuration. Do we need an iframe? Is pushState desired … is it available?

    @@ -4229,11 +4215,11 @@

    Backbone.History

  • -
  • +
  • - +

    Normalize root to always include a leading and trailing slash.

    @@ -4244,11 +4230,11 @@

    Backbone.History

  • -
  • +
  • - +

    Transition from hashChange to pushState or vice versa if both are requested.

    @@ -4260,11 +4246,11 @@

    Backbone.History

  • -
  • +
  • - +

    If we’ve started off with a route from a pushState-enabled browser, but we’re currently in a browser that doesn’t support it…

    @@ -4278,11 +4264,11 @@

    Backbone.History

  • -
  • +
  • - +

    Return immediately as browser will do redirect to new url

    @@ -4293,11 +4279,11 @@

    Backbone.History

  • -
  • +
  • - +

    Or if we’ve started out with a hash-based route, but we’re currently in a browser where it could be pushState-based instead…

    @@ -4313,11 +4299,11 @@

    Backbone.History

  • -
  • +
  • - +

    Proxy an iframe to handle location events if the browser doesn’t support the hashchange event, HTML5 history, or the user wants @@ -4326,38 +4312,39 @@

    Backbone.History

          if (!this._hasHashChange && this._wantsHashChange && !this._usePushState) {
    -        var iframe = document.createElement('iframe');
    -        iframe.src = 'javascript:0';
    -        iframe.style.display = 'none';
    -        iframe.tabIndex = -1;
    +        this.iframe = document.createElement('iframe');
    +        this.iframe.src = 'javascript:0';
    +        this.iframe.style.display = 'none';
    +        this.iframe.tabIndex = -1;
             var body = document.body;
  • -
  • +
  • - +

    Using appendChild will throw on IE < 9 if the document is not ready.

    -
            this.iframe = body.insertBefore(iframe, body.firstChild).contentWindow;
    -        this.iframe.document.open().close();
    -        this.iframe.location.hash = '#' + this.fragment;
    +            
            var iWindow = body.insertBefore(this.iframe, body.firstChild).contentWindow;
    +        iWindow.document.open();
    +        iWindow.document.close();
    +        iWindow.location.hash = '#' + this.fragment;
           }
  • -
  • +
  • - +

    Add a cross-platform addEventListener shim for older browsers.

    @@ -4370,11 +4357,11 @@

    Backbone.History

  • -
  • +
  • - +

    Depending on whether we’re using pushState or hashes, and whether ‘onhashchange’ is supported, determine how we check the URL state.

    @@ -4395,11 +4382,11 @@

    Backbone.History

  • -
  • +
  • - +

    Disable Backbone.history, perhaps temporarily. Not useful in a real app, but possibly useful for unit testing Routers.

    @@ -4411,11 +4398,11 @@

    Backbone.History

  • -
  • +
  • - +

    Add a cross-platform removeEventListener shim for older browsers.

    @@ -4428,11 +4415,11 @@

    Backbone.History

  • -
  • +
  • - +

    Remove window listeners.

    @@ -4447,29 +4434,29 @@

    Backbone.History

  • -
  • +
  • - +

    Clean up the iframe if necessary.

          if (this.iframe) {
    -        document.body.removeChild(this.iframe.frameElement);
    +        document.body.removeChild(this.iframe);
             this.iframe = null;
           }
  • -
  • +
  • - +

    Some environments will throw when clearing an undefined interval.

    @@ -4482,11 +4469,11 @@

    Backbone.History

  • -
  • +
  • - +

    Add a route to be tested when the fragment changes. Routes added later may override previous routes.

    @@ -4500,11 +4487,11 @@

    Backbone.History

  • -
  • +
  • - +

    Checks the current URL to see if it has changed, and if it has, calls loadUrl, normalizing across the hidden iframe.

    @@ -4517,11 +4504,11 @@

    Backbone.History

  • -
  • +
  • - +

    If the user pressed the back button, the iframe’s hash will have changed and we should use that for comparison.

    @@ -4529,7 +4516,7 @@

    Backbone.History

          if (current === this.fragment && this.iframe) {
    -        current = this.getHash(this.iframe);
    +        current = this.getHash(this.iframe.contentWindow);
           }
     
           if (current === this.fragment) return false;
    @@ -4540,11 +4527,11 @@ 

    Backbone.History

  • -
  • +
  • - +

    Attempt to load the current URL fragment. If a route succeeds with a match, returns true. If no defined routes matches the fragment, @@ -4557,11 +4544,11 @@

    Backbone.History

  • -
  • +
  • - +

    If the root doesn’t match, no routes can match either.

    @@ -4580,11 +4567,11 @@

    Backbone.History

  • -
  • +
  • - +

    Save a fragment into the hash history, or replace the URL state if the ‘replace’ option is passed. You are responsible for properly URL-encoding @@ -4602,11 +4589,11 @@

    Backbone.History

  • -
  • +
  • - +

    Normalize the fragment.

    @@ -4617,11 +4604,11 @@

    Backbone.History

  • -
  • +
  • - +

    Don’t include a trailing slash on the root.

    @@ -4636,11 +4623,11 @@

    Backbone.History

  • -
  • +
  • - +

    Strip the hash and decode for matching.

    @@ -4654,11 +4641,11 @@

    Backbone.History

  • -
  • +
  • - +

    If pushState is available, we use it to set the fragment as a real URL.

    @@ -4670,11 +4657,11 @@

    Backbone.History

  • -
  • +
  • - +

    If hash changes haven’t been explicitly disabled, update the hash fragment to store history.

    @@ -4683,16 +4670,17 @@

    Backbone.History

          } else if (this._wantsHashChange) {
             this._updateHash(this.location, fragment, options.replace);
    -        if (this.iframe && (fragment !== this.getHash(this.iframe))) {
    + if (this.iframe && (fragment !== this.getHash(this.iframe.contentWindow))) { + var iWindow = this.iframe.contentWindow;
  • -
  • +
  • - +

    Opening and closing the iframe tricks IE7 and earlier to push a history entry on hash-tag change. When replace is true, we don’t @@ -4700,18 +4688,22 @@

    Backbone.History

    -
              if (!options.replace) this.iframe.document.open().close();
    -          this._updateHash(this.iframe.location, fragment, options.replace);
    +            
              if (!options.replace) {
    +            iWindow.document.open();
    +            iWindow.document.close();
    +          }
    +
    +          this._updateHash(iWindow.location, fragment, options.replace);
             }
  • -
  • +
  • - +

    If you’ve told us that you explicitly don’t want fallback hashchange- based history, then navigate becomes a page refresh.

    @@ -4727,11 +4719,11 @@

    Backbone.History

  • -
  • +
  • - +

    Update the hash location, either replacing the current entry, or adding a new one to the browser history.

    @@ -4747,11 +4739,11 @@

    Backbone.History

  • -
  • +
  • - +

    Some browsers require that hash contains a leading #.

    @@ -4766,11 +4758,11 @@

    Backbone.History

  • -
  • +
  • - +

    Create the default Backbone.history.

    @@ -4781,11 +4773,11 @@

    Backbone.History

  • -
  • +
  • - +

    Helpers

    @@ -4794,11 +4786,11 @@

    Helpers

  • -
  • +
  • - +
    @@ -4806,11 +4798,11 @@

    Helpers

  • -
  • +
  • - +

    Helper function to correctly set up the prototype chain for subclasses. Similar to goog.inherits, but uses a hash of prototype properties and @@ -4825,11 +4817,11 @@

    Helpers

  • -
  • +
  • - +

    The constructor function for the new subclass is either defined by you (the “constructor” property in your extend definition), or defaulted @@ -4846,11 +4838,11 @@

    Helpers

  • -
  • +
  • - +

    Add static properties to the constructor function, if supplied.

    @@ -4861,11 +4853,11 @@

    Helpers

  • -
  • +
  • - +

    Set the prototype chain to inherit from parent, without calling parent constructor function.

    @@ -4879,11 +4871,11 @@

    Helpers

  • -
  • +
  • - +

    Add prototype properties (instance properties) to the subclass, if supplied.

    @@ -4895,11 +4887,11 @@

    Helpers

  • -
  • +
  • - +

    Set a convenience property in case the parent’s prototype is needed later.

    @@ -4914,11 +4906,11 @@

    Helpers

  • -
  • +
  • - +

    Set up inheritance for the model, collection, router, view and history.

    @@ -4929,11 +4921,11 @@

    Helpers

  • -
  • +
  • - +

    Throw an error when a URL is needed, and none is supplied.

    @@ -4946,11 +4938,11 @@

    Helpers

  • -
  • +
  • - +

    Wrap an optional error callback with a fallback error event.

    diff --git a/index.html b/index.html index 4683b99bc..e0375563e 100644 --- a/index.html +++ b/index.html @@ -300,7 +300,7 @@