1var today = new Date(); 2var nyr = today.getFullYear(); 3/* Smooth scrolling 4 Changes links that link to other parts of this page to scroll 5 smoothly to those links rather than jump to them directly, which 6 can be a little disorienting. 7 8 sil, http://www.kryogenix.org/ 9 10 Wordpress Plug-in Smooth Scroll Links [SSL] by Chetan Gole [http://chetangole.com/] 11 12*/ 13 14var ss = { 15 fixAllLinks: function() { 16 // Get a list of all links in the page 17 var allLinks = document.getElementsByTagName('a'); 18 // Walk through the list 19 for (var i=0;i<allLinks.length;i++) { 20 var lnk = allLinks[i]; 21 if ((lnk.href && lnk.href.indexOf('#') != -1) && 22 ( (lnk.pathname == location.pathname) || 23 ('/'+lnk.pathname == location.pathname) ) && 24 (lnk.search == location.search)) { 25 // If the link is internal to the page (begins in #) 26 // then attach the smoothScroll function as an onclick 27 // event handler 28 ss.addEvent(lnk,'click',ss.smoothScroll); 29 } 30 } 31 }, 32 33 smoothScroll: function(e) { 34 // This is an event handler; get the clicked on element, 35 // in a cross-browser fashion 36 if (window.event) { 37 target = window.event.srcElement; 38 } else if (e) { 39 target = e.target; 40 } else return; 41 42 // Make sure that the target is an element, not a text node 43 // within an element 44 if (target.nodeName.toLowerCase() != 'a') { 45 target = target.parentNode; 46 } 47 48 // Paranoia; check this is an A tag 49 if (target.nodeName.toLowerCase() != 'a') return; 50 51 // Find the <a name> tag corresponding to this href 52 // First strip off the hash (first character) 53 anchor = target.hash.substr(1); 54 // Now loop all A tags until we find one with that name 55 var allLinks = document.getElementsByTagName('a'); 56 var destinationLink = null; 57 for (var i=0;i<allLinks.length;i++) { 58 var lnk = allLinks[i]; 59 if (lnk.name && (lnk.name == anchor)) { 60 destinationLink = lnk; 61 break; 62 } 63 } 64 if (!destinationLink) destinationLink = document.getElementById(anchor); 65 66 // If we didn't find a destination, give up and let the browser do 67 // its thing 68 if (!destinationLink) return true; 69 70 // Find the destination's position 71 var destx = destinationLink.offsetLeft; 72 var desty = destinationLink.offsetTop; 73 var thisNode = destinationLink; 74 while (thisNode.offsetParent && 75 (thisNode.offsetParent != document.body)) { 76 thisNode = thisNode.offsetParent; 77 destx += thisNode.offsetLeft; 78 desty += thisNode.offsetTop; 79 } 80 81 // Stop any current scrolling 82 clearInterval(ss.INTERVAL); 83 84 cypos = ss.getCurrentYPos(); 85 86 ss_stepsize = parseInt((desty-cypos)/ss.STEPS); 87 ss.INTERVAL = 88setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10); 89 90 // And stop the actual click happening 91 if (window.event) { 92 window.event.cancelBubble = true; 93 window.event.returnValue = false; 94 } 95 if (e && e.preventDefault && e.stopPropagation) { 96 e.preventDefault(); 97 e.stopPropagation(); 98 } 99 }, 100 101 scrollWindow: function(scramount,dest,anchor) { 102 wascypos = ss.getCurrentYPos(); 103 isAbove = (wascypos < dest); 104 window.scrollTo(0,wascypos + scramount); 105 iscypos = ss.getCurrentYPos(); 106 isAboveNow = (iscypos < dest); 107 if ((isAbove != isAboveNow) || (wascypos == iscypos)) { 108 // if we've just scrolled past the destination, or 109 // we haven't moved from the last scroll (i.e., we're at the 110 // bottom of the page) then scroll exactly to the link 111 window.scrollTo(0,dest); 112 // cancel the repeating timer 113 clearInterval(ss.INTERVAL); 114 // and jump to the link directly so the URL's right 115 location.hash = anchor; 116 } 117 }, 118 119 getCurrentYPos: function() { 120 if (document.body && document.body.scrollTop) 121 return document.body.scrollTop; 122 if (document.documentElement && document.documentElement.scrollTop) 123 return document.documentElement.scrollTop; 124 if (window.pageYOffset) 125 return window.pageYOffset; 126 return 0; 127 }, 128 129 addEvent: function(elm, evType, fn, useCapture) { 130 // addEvent and removeEvent 131 // cross-browser event handling for IE5+, NS6 and Mozilla 132 // By Scott Andrew 133 if (elm.addEventListener){ 134 elm.addEventListener(evType, fn, useCapture); 135 return true; 136 } else if (elm.attachEvent){
137 var r = elm.attachEvent("on"+evType, fn); 138 return r; 139 } else { 140 alert("Handler could not be removed"); 141 } 142 } 143} 144 145ss.STEPS = 25; 146 147ss.addEvent(window,"load",ss.fixAllLinks);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.