[Pkg-javascript-commits] [backbone] 68/74: light refactor for History#getFragment

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 16:59:10 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.3.0
in repository backbone.

commit b638e31cd761a6b8ee396749dd0f5522a9abf59b
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Tue Nov 9 11:14:48 2010 -0500

    light refactor for History#getFragment
---
 backbone.js | 33 ++++++++++++++-------------------
 1 file changed, 14 insertions(+), 19 deletions(-)

diff --git a/backbone.js b/backbone.js
index cf8239a..fe07c2f 100644
--- a/backbone.js
+++ b/backbone.js
@@ -574,7 +574,7 @@
   Backbone.Controller = function(options) {
     options || (options = {});
     if (options.routes) this.routes = options.routes;
-    this.bindRoutes();
+    this._bindRoutes();
     if (this.initialize) this.initialize(options);
   };
 
@@ -586,15 +586,6 @@
   // Set up all inheritable **Backbone.Controller** properties and methods.
   _.extend(Backbone.Controller.prototype, Backbone.Events, {
 
-    // Bind all defined routes to `Backbone.history`.
-    bindRoutes : function() {
-      if (!this.routes) return;
-      for (var route in this.routes) {
-        var name = this.routes[route];
-        this.route(route, name, this[name]);
-      }
-    },
-
     // Manually bind a single named route to a callback. For example:
     //
     //     this.route('search/:query/p:page', 'search', function(query, page) {
@@ -616,6 +607,15 @@
       Backbone.history.save(fragment);
     },
 
+    // Bind all defined routes to `Backbone.history`.
+    _bindRoutes : function() {
+      if (!this.routes) return;
+      for (var route in this.routes) {
+        var name = this.routes[route];
+        this.route(route, name, this[name]);
+      }
+    },
+
     // Convert a route string into a regular expression, suitable for matching
     // against the current hash state.
     _routeToRegExp : function(route) {
@@ -652,13 +652,8 @@
     interval: 50,
 
     // Get the cross-browser normalized URL fragment.
-    getFragment : function() {
-      return window.location.hash.replace(hashStrip, '');
-    },
-
-    // Get the cross-browser normalized URL fragment from the iframe.
-    getIframeFragment : function() {
-      return this.iframe.location.hash.replace(hashStrip, '');
+    getFragment : function(loc) {
+      return (loc || window.location).hash.replace(hashStrip, '');
     },
 
     // Start the hash change handling, returning true if the current URL matches
@@ -688,7 +683,7 @@
     checkUrl : function() {
       var current = this.getFragment();
       if (current == this.fragment && this.iframe) {
-        current = this.getIframeFragment();
+        current = this.getFragment(this.iframe.location);
       }
       if (!current ||
           current == this.fragment ||
@@ -719,7 +714,7 @@
       fragment = (fragment || '').replace(hashStrip, '');
       if (this.fragment == fragment) return;
       window.location.hash = this.fragment = fragment;
-      if (this.iframe && (fragment != this.getIframeFragment())) {
+      if (this.iframe && (fragment != this.getFragment(this.iframe.location))) {
         this.iframe.document.open().close();
         this.iframe.location.hash = fragment;
       }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list