| OLD | NEW |
| (Empty) |
| 1 <!-- Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
| 2 Use of this source code is governed by a BSD-style license that can be | |
| 3 found in the LICENSE file. --> | |
| 4 | |
| 5 <!-- | |
| 6 Use to observe to dynamically observe changes to the hash in the url. | |
| 7 | |
| 8 ex. | |
| 9 <cr-hash-observer on-hash-changed="{{ handleHashChange }}"></cr-hash-obs
erver> | |
| 10 --> | |
| 11 <polymer-element name="cr-hash-observer"> | |
| 12 <template> | |
| 13 <style> | |
| 14 :host { display: none; } | |
| 15 </style> | |
| 16 </template> | |
| 17 <script> | |
| 18 (function() { | |
| 19 var instances = []; | |
| 20 | |
| 21 Polymer("cr-hash-observer", { | |
| 22 attached: function() { | |
| 23 instances.push(this); | |
| 24 }, | |
| 25 detached: function() { | |
| 26 var i = instances.indexOf(this); | |
| 27 if (i >= 0) | |
| 28 instances.splice(i, 1); | |
| 29 }, | |
| 30 }); | |
| 31 | |
| 32 var currentHash = ""; | |
| 33 function notifyInstancesIfNeeded() { | |
| 34 if (window.location.hash == currentHash) | |
| 35 return; | |
| 36 currentHash = window.location.hash; | |
| 37 instances.forEach(function(instance) { | |
| 38 instance.asyncFire("hash-changed"); | |
| 39 }); | |
| 40 } | |
| 41 | |
| 42 function handleHashChange() { | |
| 43 setTimeout(notifyInstancesIfNeeded); | |
| 44 } | |
| 45 | |
| 46 document.addEventListener("navigate", handleHashChange); | |
| 47 window.addEventListener("hashchange", handleHashChange); | |
| 48 })(); | |
| 49 </script> | |
| 50 </polymer-element> | |
| OLD | NEW |