[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 /** 2 * @provides javelin-behavior-phabricator-watch-anchor 3 * @requires javelin-behavior 4 * javelin-stratcom 5 * javelin-dom 6 * javelin-vector 7 */ 8 9 JX.behavior('phabricator-watch-anchor', function() { 10 11 var highlighted; 12 13 function highlight() { 14 highlighted && JX.DOM.alterClass(highlighted, 'anchor-target', false); 15 try { 16 highlighted = JX.$('anchor-' + window.location.hash.replace('#', '')); 17 } catch (ex) { 18 highlighted = null; 19 } 20 highlighted && JX.DOM.alterClass(highlighted, 'anchor-target', true); 21 } 22 23 // Defer invocation so other listeners can update the document. 24 function defer_highlight() { 25 setTimeout(highlight, 0); 26 } 27 28 // In some cases, we link to an anchor but the anchor target ajaxes in 29 // later. If it pops in within the first few seconds, jump to it. 30 function try_anchor() { 31 var anchor = window.location.hash.replace('#', ''); 32 try { 33 // If the anchor exists, assume the browser handled the jump. 34 if (anchor) { 35 JX.$(anchor); 36 } 37 defer_highlight(); 38 } catch (e) { 39 var n = 50; 40 var try_anchor_again = function () { 41 try { 42 window.scrollTo(0, JX.$V(JX.$(anchor)).y - 60); 43 defer_highlight(); 44 } catch (e) { 45 if (n--) { 46 setTimeout(try_anchor_again, 100); 47 } 48 } 49 }; 50 try_anchor_again(); 51 } 52 } 53 54 JX.Stratcom.listen('hashchange', null, try_anchor); 55 try_anchor(); 56 57 });
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |