wp/wp-includes/js/backbone.js
changeset 22 8c2e4d02f4ef
parent 21 48c4eec2b7e6
equal deleted inserted replaced
21:48c4eec2b7e6 22:8c2e4d02f4ef
     1 //     Backbone.js 1.5.0
     1 //     Backbone.js 1.6.0
     2 
     2 
     3 //     (c) 2010-2022 Jeremy Ashkenas and DocumentCloud
     3 //     (c) 2010-2024 Jeremy Ashkenas and DocumentCloud
     4 //     Backbone may be freely distributed under the MIT license.
     4 //     Backbone may be freely distributed under the MIT license.
     5 //     For all details and documentation:
     5 //     For all details and documentation:
     6 //     http://backbonejs.org
     6 //     http://backbonejs.org
     7 
     7 
     8 (function(factory) {
     8 (function(factory) {
    42 
    42 
    43   // Create a local reference to a common array method we'll want to use later.
    43   // Create a local reference to a common array method we'll want to use later.
    44   var slice = Array.prototype.slice;
    44   var slice = Array.prototype.slice;
    45 
    45 
    46   // Current version of the library. Keep in sync with `package.json`.
    46   // Current version of the library. Keep in sync with `package.json`.
    47   Backbone.VERSION = '1.5.0';
    47   Backbone.VERSION = '1.6.0';
    48 
    48 
    49   // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
    49   // For Backbone's purposes, jQuery, Zepto, Ender, or My Library (kidding) owns
    50   // the `$` variable.
    50   // the `$` variable.
    51   Backbone.$ = $;
    51   Backbone.$ = $;
    52 
    52 
  1083       if (!wait) this.add(model, options);
  1083       if (!wait) this.add(model, options);
  1084       var collection = this;
  1084       var collection = this;
  1085       var success = options.success;
  1085       var success = options.success;
  1086       options.success = function(m, resp, callbackOpts) {
  1086       options.success = function(m, resp, callbackOpts) {
  1087         if (wait) {
  1087         if (wait) {
  1088           m.off('error', this._forwardPristineError, this);
  1088           m.off('error', collection._forwardPristineError, collection);
  1089           collection.add(m, callbackOpts);
  1089           collection.add(m, callbackOpts);
  1090         }
  1090         }
  1091         if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
  1091         if (success) success.call(callbackOpts.context, m, resp, callbackOpts);
  1092       };
  1092       };
  1093       // In case of wait:true, our collection is not listening to any
  1093       // In case of wait:true, our collection is not listening to any
  1983       // changed and we should use that for comparison.
  1983       // changed and we should use that for comparison.
  1984       if (current === this.fragment && this.iframe) {
  1984       if (current === this.fragment && this.iframe) {
  1985         current = this.getHash(this.iframe.contentWindow);
  1985         current = this.getHash(this.iframe.contentWindow);
  1986       }
  1986       }
  1987 
  1987 
  1988       if (current === this.fragment) return false;
  1988       if (current === this.fragment) {
       
  1989         if (!this.matchRoot()) return this.notfound();
       
  1990         return false;
       
  1991       }
  1989       if (this.iframe) this.navigate(current);
  1992       if (this.iframe) this.navigate(current);
  1990       this.loadUrl();
  1993       this.loadUrl();
  1991     },
  1994     },
  1992 
  1995 
  1993     // Attempt to load the current URL fragment. If a route succeeds with a
  1996     // Attempt to load the current URL fragment. If a route succeeds with a
  1994     // match, returns `true`. If no defined routes matches the fragment,
  1997     // match, returns `true`. If no defined routes matches the fragment,
  1995     // returns `false`.
  1998     // returns `false`.
  1996     loadUrl: function(fragment) {
  1999     loadUrl: function(fragment) {
  1997       // If the root doesn't match, no routes can match either.
  2000       // If the root doesn't match, no routes can match either.
  1998       if (!this.matchRoot()) return false;
  2001       if (!this.matchRoot()) return this.notfound();
  1999       fragment = this.fragment = this.getFragment(fragment);
  2002       fragment = this.fragment = this.getFragment(fragment);
  2000       return _.some(this.handlers, function(handler) {
  2003       return _.some(this.handlers, function(handler) {
  2001         if (handler.route.test(fragment)) {
  2004         if (handler.route.test(fragment)) {
  2002           handler.callback(fragment);
  2005           handler.callback(fragment);
  2003           return true;
  2006           return true;
  2004         }
  2007         }
  2005       });
  2008       }) || this.notfound();
       
  2009     },
       
  2010 
       
  2011     // When no route could be matched, this method is called internally to
       
  2012     // trigger the `'notfound'` event. It returns `false` so that it can be used
       
  2013     // in tail position.
       
  2014     notfound: function() {
       
  2015       this.trigger('notfound');
       
  2016       return false;
  2006     },
  2017     },
  2007 
  2018 
  2008     // Save a fragment into the hash history, or replace the URL state if the
  2019     // Save a fragment into the hash history, or replace the URL state if the
  2009     // 'replace' option is passed. You are responsible for properly URL-encoding
  2020     // 'replace' option is passed. You are responsible for properly URL-encoding
  2010     // the fragment in advance.
  2021     // the fragment in advance.
  2131       if (error) error.call(options.context, model, resp, options);
  2142       if (error) error.call(options.context, model, resp, options);
  2132       model.trigger('error', model, resp, options);
  2143       model.trigger('error', model, resp, options);
  2133     };
  2144     };
  2134   };
  2145   };
  2135 
  2146 
       
  2147   // Provide useful information when things go wrong. This method is not meant
       
  2148   // to be used directly; it merely provides the necessary introspection for the
       
  2149   // external `debugInfo` function.
       
  2150   Backbone._debug = function() {
       
  2151     return {root: root, _: _};
       
  2152   };
       
  2153 
  2136   return Backbone;
  2154   return Backbone;
  2137 });
  2155 });