From 36dddfbe06606df5a78ebaf62c3f452efd501916 Mon Sep 17 00:00:00 2001 From: Jeremy Ashkenas Date: Tue, 5 Jul 2011 09:59:15 -0400 Subject: [PATCH] Backbone.js 0.5.1 --- backbone.js | 4 ++-- docs/backbone.html | 40 ++++++++++++++++++++-------------------- index.html | 17 +++++++++++++---- package.json | 2 +- 4 files changed, 36 insertions(+), 27 deletions(-) diff --git a/backbone.js b/backbone.js index 5e690b0ca..18d484386 100644 --- a/backbone.js +++ b/backbone.js @@ -1,4 +1,4 @@ -// Backbone.js 0.5.0 +// Backbone.js 0.5.1 // (c) 2010 Jeremy Ashkenas, DocumentCloud Inc. // Backbone may be freely distributed under the MIT license. // For all details and documentation: @@ -25,7 +25,7 @@ } // Current version of the library. Keep in sync with `package.json`. - Backbone.VERSION = '0.5.0'; + Backbone.VERSION = '0.5.1'; // Require Underscore, if we're on the server, and it's not already present. var _ = root._; diff --git a/docs/backbone.html b/docs/backbone.html index 93581cdcb..3ee0e99a8 100644 --- a/docs/backbone.html +++ b/docs/backbone.html @@ -1,4 +1,4 @@ - backbone.js

backbone.js

Backbone.js 0.5.0
+      backbone.js           

backbone.js

Backbone.js 0.5.1
 (c) 2010 Jeremy Ashkenas, DocumentCloud Inc.
 Backbone may be freely distributed under the MIT license.
 For all details and documentation:
@@ -9,7 +9,7 @@
     Backbone = exports;
   } else {
     Backbone = root.Backbone = {};
-  }

Current version of the library. Keep in sync with package.json.

  Backbone.VERSION = '0.5.0';

Require Underscore, if we're on the server, and it's not already present.

  var _ = root._;
+  }

Current version of the library. Keep in sync with package.json.

  Backbone.VERSION = '0.5.1';

Require Underscore, if we're on the server, and it's not already present.

  var _ = root._;
   if (!_ && (typeof require !== 'undefined')) _ = require('underscore')._;

For Backbone's purposes, jQuery or Zepto owns the $ variable.

  var $ = root.jQuery || root.Zepto;

Runs Backbone.js in noConflict mode, returning the Backbone variable to its previous owner. Returns a reference to this Backbone object.

  Backbone.noConflict = function() {
     root.Backbone = previousBackbone;
@@ -91,7 +91,7 @@
     this._changed = false;
     this._previousAttributes = _.clone(this.attributes);
     if (options && options.collection) this.collection = options.collection;
-    this.initialize.apply(this, arguments);
+    this.initialize(attributes, options);
   };

Attach all inheritable methods to the Model prototype.

  _.extend(Backbone.Model.prototype, Backbone.Events, {

A snapshot of the model's previous attributes, taken immediately after the last "change" event was fired.

    _previousAttributes : null,

Has the item been changed since the last "change" event?

    _changed : false,

The default name for the JSON id attribute is "id". MongoDB and CouchDB users may want to set this to "_id".

    idAttribute : 'id',

Initialize is an empty function by default. Override it with your own @@ -411,7 +411,7 @@ });

Underscore methods that we want to implement on the Collection.

  var methods = ['forEach', 'each', 'map', 'reduce', 'reduceRight', 'find', 'detect',
     'filter', 'select', 'reject', 'every', 'all', 'some', 'any', 'include',
-    'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
+    'contains', 'invoke', 'max', 'min', 'sortBy', 'sortedIndex', 'toArray', 'size',
     'first', 'rest', 'last', 'without', 'indexOf', 'lastIndexOf', 'isEmpty'];

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

  _.each(methods, function(method) {
     Backbone.Collection.prototype[method] = function() {
       return _[method].apply(_, [this.models].concat(_.toArray(arguments)));
@@ -467,7 +467,7 @@
 browser does not support onhashchange, falls back to polling.

  Backbone.History = function() {
     this.handlers = [];
     _.bindAll(this, 'checkUrl');
-  };

Cached regex for cleaning hashes.

  var hashStrip = /^#*!?/;

Cached regex for detecting MSIE.

  var isExplorer = /msie [\w.]+/;

Has the history handling already been started?

  var historyStarted = false;

Set up all inheritable Backbone.History properties and methods.

  _.extend(Backbone.History.prototype, {

The default interval to poll for hash changes, if necessary, is + };

Cached regex for cleaning hashes.

  var hashStrip = /^#*/;

Cached regex for detecting MSIE.

  var isExplorer = /msie [\w.]+/;

Has the history handling already been started?

  var historyStarted = false;

Set up all inheritable Backbone.History properties and methods.

  _.extend(Backbone.History.prototype, {

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

    interval: 50,

Get the cross-browser normalized URL fragment, either from the URL, the hash, or the override.

    getFragment : function(fragment, forcePushState) {
       if (fragment == null) {
@@ -503,16 +503,16 @@
       }

Determine if we need to change the base url, for a pushState link opened by a non-pushState browser.

      this.fragment = fragment;
       historyStarted = true;
-      var started = this.loadUrl() || this.loadUrl(window.location.hash);
-      var atRoot  = window.location.pathname == this.options.root;
+      var loc = window.location;
+      var atRoot  = loc.pathname == this.options.root;
       if (this._wantsPushState && !this._hasPushState && !atRoot) {
         this.fragment = this.getFragment(null, true);
-        window.location = this.options.root + '#' + this.fragment;
-      } else if (this._wantsPushState && this._hasPushState && atRoot && window.location.hash) {
-        this.navigate(window.location.hash);
-      } else {
-        return started;
+        window.location.replace(this.options.root + '#' + this.fragment);
+      } else if (this._wantsPushState && this._hasPushState && atRoot && loc.hash) {
+        this.fragment = loc.hash.replace(hashStrip, '');
+        window.history.replaceState({}, document.title, loc.protocol + '//' + loc.host + this.options.root + this.fragment);
       }
+      return this.loadUrl();
     },

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

    route : function(route, callback) {
       this.handlers.unshift({route : route, callback : callback});
@@ -537,18 +537,18 @@
     },

Save a fragment into the hash history. You are responsible for properly URL-encoding the fragment in advance. This does not trigger a hashchange event.

    navigate : function(fragment, triggerRoute) {
-      fragment = (fragment || '').replace(hashStrip, '');
-      if (this.fragment == fragment || this.fragment == decodeURIComponent(fragment)) return;
+      var frag = (fragment || '').replace(hashStrip, '');
+      if (this.fragment == frag || this.fragment == decodeURIComponent(frag)) return;
       if (this._hasPushState) {
         var loc = window.location;
-        if (fragment.indexOf(this.options.root) != 0) fragment = this.options.root + fragment;
-        this.fragment = fragment;
-        window.history.pushState({}, document.title, loc.protocol + '//' + loc.host + fragment);
+        if (frag.indexOf(this.options.root) != 0) frag = this.options.root + frag;
+        this.fragment = frag;
+        window.history.pushState({}, document.title, loc.protocol + '//' + loc.host + frag);
       } else {
-        window.location.hash = this.fragment = fragment;
-        if (this.iframe && (fragment != this.getFragment(this.iframe.location.hash))) {
+        window.location.hash = this.fragment = frag;
+        if (this.iframe && (frag != this.getFragment(this.iframe.location.hash))) {
           this.iframe.document.open().close();
-          this.iframe.location.hash = fragment;
+          this.iframe.location.hash = frag;
         }
       }
       if (triggerRoute) this.loadUrl(fragment);
diff --git a/index.html b/index.html
index 92f483fd8..ea11de364 100644
--- a/index.html
+++ b/index.html
@@ -149,7 +149,7 @@
   

Change Log

+ +

+ 0.5.1July 5, 2011
+ Cleanups from the 0.5.0 release, to wit: improved transparent upgrades from + hash-based URLs to pushState, and vice-versa. Fixed inconsistency with + non-modified attributes being passed to Model#initialize. Reverted + a 0.5.0 change that would strip leading hashbangs from routes. + Added contains as an alias for includes. +

0.5.0July 1, 2011
diff --git a/package.json b/package.json index cba96e22e..9a7bb6be7 100644 --- a/package.json +++ b/package.json @@ -10,5 +10,5 @@ }, "lib" : ".", "main" : "backbone.js", - "version" : "0.5.0" + "version" : "0.5.1" }