| OLD | NEW |
| (Empty) |
| 1 <!-- | |
| 2 Copyright (c) 2015 The Polymer Project Authors. All rights reserved. | |
| 3 This code may only be used under the BSD style license found at http://polymer.g
ithub.io/LICENSE.txt | |
| 4 The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt | |
| 5 The complete set of contributors may be found at http://polymer.github.io/CONTRI
BUTORS.txt | |
| 6 Code distributed by Google as part of the polymer project is also | |
| 7 subject to an additional IP rights grant found at http://polymer.github.io/PATEN
TS.txt | |
| 8 --> | |
| 9 <link rel="import" href="../driver.html"> | |
| 10 | |
| 11 <script> | |
| 12 (function(scope) { | |
| 13 var MoreRouting = scope.MoreRouting = scope.MoreRouting || {}; | |
| 14 MoreRouting.HashDriver = HashDriver; | |
| 15 | |
| 16 /** | |
| 17 * TODO(nevir): Docs. | |
| 18 */ | |
| 19 function HashDriver() { | |
| 20 MoreRouting.Driver.apply(this, arguments); | |
| 21 this._bindEvents(); | |
| 22 this._read(); | |
| 23 } | |
| 24 HashDriver.prototype = Object.create(MoreRouting.Driver.prototype); | |
| 25 | |
| 26 // By default, we prefer hashbang; but you can prefix with any string you wish. | |
| 27 HashDriver.prototype.prefix = '!/'; | |
| 28 | |
| 29 HashDriver.prototype.urlForParts = function urlForParts(parts) { | |
| 30 return '#' + MoreRouting.Driver.prototype.urlForParts.call(this, parts); | |
| 31 }; | |
| 32 | |
| 33 HashDriver.prototype.navigateToUrl = function navigateToUrl(url) { | |
| 34 window.location.hash = url; | |
| 35 }; | |
| 36 | |
| 37 HashDriver.prototype._bindEvents = function _bindEvents() { | |
| 38 window.addEventListener('hashchange', this._read.bind(this)); | |
| 39 }; | |
| 40 | |
| 41 HashDriver.prototype._read = function _read() { | |
| 42 this.setCurrentPath(window.location.hash.substr(1) || this.prefix); | |
| 43 }; | |
| 44 | |
| 45 })(window); | |
| 46 </script> | |
| OLD | NEW |