PageSourceSearch

https://angelo-san.com/assets/www.angelo-san.com/wp-content/plugins/smooth-scrolling-links-ssl/smoothscroll.js

js angelo-san.com collected 2026-10-02 18:23:39 UTC 5,914 bytes, 177 lines download raw bytes

1var _____WB$wombat$assign$function_____=function(name){return (globalThis._wb_wombat && globalThis._wb_wombat.local_init && globalThis._wb_wombat.local_init(name))||globalThis[name];};if(!globalThis.__WB_pmw){globalThis.__WB_pmw=function(obj){this.__WB_source=obj;return this;}}{
2let window = _____WB$wombat$assign$function_____("window");
3let self = _____WB$wombat$assign$function_____("self");
4let document = _____WB$wombat$assign$function_____("document");
5let location = _____WB$wombat$assign$function_____("location");
6let top = _____WB$wombat$assign$function_____("top");
7let parent = _____WB$wombat$assign$function_____("parent");
8let frames = _____WB$wombat$assign$function_____("frames");
9let opener = _____WB$wombat$assign$function_____("opener");
10/* Smooth scrolling
11   Changes links that link to other parts of this page to scroll
12   smoothly to those links rather than jump to them directly, which
13   can be a little disorienting.
14   
15   sil, http://www.kryogenix.org/
16   
17   Wordpress Plug-in Smooth Scroll Links [SSL] by Chetan Gole [http://chetangole.com/]
18   
19*/
20
21var ss = {
22  fixAllLinks: function() {
23    // Get a list of all links in the page
24    var allLinks = document.getElementsByTagName('a');
25    // Walk through the list
26    for (var i=0;i<allLinks.length;i++) {
27      var lnk = allLinks[i];
28      if ((lnk.href && lnk.href.indexOf('#') != -1) && 
29          ( (lnk.pathname == location.pathname) ||
30	    ('/'+lnk.pathname == location.pathname) ) && 
31          (lnk.search == location.search)) {
32        // If the link is internal to the page (begins in #)
33        // then attach the smoothScroll function as an onclick
34        // event handler
35        ss.addEvent(lnk,'click',ss.smoothScroll);
36      }
37    }
38  },
39
40  smoothScroll: function(e) {
41    // This is an event handler; get the clicked on element,
42    // in a cross-browser fashion
43    if (window.event) {
44      target = window.event.srcElement;
45    } else if (e) {
46      target = e.target;
47    } else return;
48
49    // Make sure that the target is an element, not a text node
50    // within an element
51    if (target.nodeName.toLowerCase() != 'a') {
52      target = target.parentNode;
53    }
54  
55    // Paranoia; check this is an A tag
56    if (target.nodeName.toLowerCase() != 'a') return;
57  
58    // Find the <a name> tag corresponding to this href
59    // First strip off the hash (first character)
60    anchor = target.hash.substr(1);
61    // Now loop all A tags until we find one with that name
62    var allLinks = document.getElementsByTagName('a');
63    var destinationLink = null;
64    for (var i=0;i<allLinks.length;i++) {
65      var lnk = allLinks[i];
66      if (lnk.name && (lnk.name == anchor)) {
67        destinationLink = lnk;
68        break;
69      }
70    }
71    if (!destinationLink) destinationLink = document.getElementById(anchor);
72
73    // If we didn't find a destination, give up and let the browser do
74    // its thing
75    if (!destinationLink) return true;
76  
77    // Find the destination's position
78    var destx = destinationLink.offsetLeft; 
79    var desty = destinationLink.offsetTop;
80    var thisNode = destinationLink;
81    while (thisNode.offsetParent && 
82          (thisNode.offsetParent != document.body)) {
83      thisNode = thisNode.offsetParent;
84      destx += thisNode.offsetLeft;
85      desty += thisNode.offsetTop;
86    }
87  
88    // Stop any current scrolling
89    clearInterval(ss.INTERVAL);
90  
91    cypos = ss.getCurrentYPos();
92  
93    ss_stepsize = parseInt((desty-cypos)/ss.STEPS);
94    ss.INTERVAL =
95setInterval('ss.scrollWindow('+ss_stepsize+','+desty+',"'+anchor+'")',10);
96  
97    // And stop the actual click happening
98    if (window.event) {
99      window.event.cancelBubble = true;
100      window.event.returnValue = false;
101    }
102    if (e && e.preventDefault && e.stopPropagation) {
103      e.preventDefault();
104      e.stopPropagation();
105    }
106  },
107
108  scrollWindow: function(scramount,dest,anchor) {
109    wascypos = ss.getCurrentYPos();
110    isAbove = (wascypos < dest);
111    window.scrollTo(0,wascypos + scramount);
112    iscypos = ss.getCurrentYPos();
113    isAboveNow = (iscypos < dest);
114    if ((isAbove != isAboveNow) || (wascypos == iscypos)) {
115      // if we've just scrolled past the destination, or
116      // we haven't moved from the last scroll (i.e., we're at the
117      // bottom of the page) then scroll exactly to the link
118      window.scrollTo(0,dest);
119      // cancel the repeating timer
120      clearInterval(ss.INTERVAL);
121      // and jump to the link directly so the URL's right
122      location.hash = anchor;
123    }
124  },
125
126  getCurrentYPos: function() {
127    if (document.body && document.body.scrollTop)
128      return document.body.scrollTop;
129    if (document.documentElement && document.documentElement.scrollTop)
130      return document.documentElement.scrollTop;
131    if (window.pageYOffset)
132      return window.pageYOffset;
133    return 0;
134  },
135
136  addEvent: function(elm, evType, fn, useCapture) {
137    // addEvent and removeEvent
138    // cross-browser event handling for IE5+,  NS6 and Mozilla
139    // By Scott Andrew
140    if (elm.addEventListener){
141      elm.addEventListener(evType, fn, useCapture);
142      return true;
143    } else if (elm.attachEvent){
144      var r = elm.attachEvent("on"+evType, fn);
145      return r;
146    } else {
147      alert("Handler could not be removed");
148    }
149  } 
150}
151
152ss.STEPS = 25;
153
154ss.addEvent(window,"load",ss.fixAllLinks);
155
156}
157
158/*
159     FILE ARCHIVED ON 12:43:50 Aug 12, 2025 AND RETRIEVED FROM THE
160     INTERNET ARCHIVE ON 11:41:44 Sep 12, 2026.
161     JAVASCRIPT APPENDED BY WAYBACK MACHINE, COPYRIGHT INTERNET ARCHIVE.
162
163     ALL OTHER CONTENT MAY ALSO BE PROTECTED BY COPYRIGHT (17 U.S.C.
164     SECTION 108(a)(3)).
165*/
166/*
167playback timings (ms):
168  captures_list: 0.615
169  exclusion.robots: 0.106
170  exclusion.robots.policy: 0.092
171  esindex: 0.009
172  cdx.remote: 3.046
173  LoadShardBlock: 80.051 (3)
174  PetaboxLoader3.datanode: 57.254 (4)
175  PetaboxLoader3.resolve: 71.116 (2)
176  load_resource: 113.591
177*/

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.