| | 384 | |
| | 385 | // Backbone.History.prototype |
| | 386 | // -------------------------- |
| | 387 | // |
| | 388 | // Extends Backbone.History to support urls with GET queries in WordPress |
| | 389 | // Supports basic form ?param=value passing 'paramvalue' as the fragment |
| | 390 | _.extend( Backbone.History.prototype, { |
| | 391 | |
| | 392 | // Keep original fragment resolver available |
| | 393 | originalFragment: Backbone.History.prototype.getFragment, |
| | 394 | |
| | 395 | // ### Get the fragment |
| | 396 | // |
| | 397 | // If history constructor includes 'queryUri' param |
| | 398 | // Use our own getFragment resolver to handle the location changes |
| | 399 | // |
| | 400 | // Appends 'location.search' to pathname in order to deal with |
| | 401 | // query variables present in URI |
| | 402 | // |
| | 403 | // Returns fragment '?paramvalue' |
| | 404 | getFragment: function( fragment, forcePushState ) { |
| | 405 | var root; |
| | 406 | |
| | 407 | // If queryUri is not set via Backbone.history.start |
| | 408 | // return the original fragment handler |
| | 409 | if ( ! Backbone.history.options.queryUri ) { |
| | 410 | return this.originalFragment.apply( this, arguments ); |
| | 411 | } |
| | 412 | |
| | 413 | // If we got this far, parse this.location.search |
| | 414 | // since we have a URL with query vars |
| | 415 | if ( fragment == null ) { |
| | 416 | if ( this._hasPushState || ! this._wantsHashChange || forcePushState ) { |
| | 417 | |
| | 418 | // Constructs fragment attaching the query parameters |
| | 419 | fragment = this.location.pathname + this.location.search; |
| | 420 | root = this.root.replace( /\/$/, '' ); |
| | 421 | |
| | 422 | if ( ! fragment.indexOf( root ) ) { |
| | 423 | fragment = fragment.slice( root.length ); |
| | 424 | } |
| | 425 | |
| | 426 | } else { |
| | 427 | fragment = this.getHash(); |
| | 428 | } |
| | 429 | } |
| | 430 | |
| | 431 | return fragment.replace(/^\/+|\/+$/g, ''); |
| | 432 | } |
| | 433 | }); |
| | 434 | |