PageSourceSearch

https://bhea.upsi.edu.my/wp-content/themes/happenstance/js/selectnav.js?ver=0.1

js upsi.edu.my collected 2026-09-24 09:23:40 UTC 3,908 bytes, 151 lines download raw bytes

1/**
2 * @preserve SelectNav.js (v. 0.1)
3 * Converts your <ul>/<ol> navigation into a dropdown list for small screens
4 * https://github.com/lukaszfiszer/selectnav.js
5 */
6
7window.selectnav = (function(){
8
9"use strict";
10
11  var selectnav = function(element,options){
12
13    element = document.getElementById(element);
14
15    // return immediately if element doesn't exist
16    if( ! element){
17      return;
18    }
19
20    // return immediately if element is not a list
21    if( ! islist(element) ){
22      return;
23    }
24
25    // add a js class to <html> tag
26    document.documentElement.className += " js";
27
28    // retreive options and set defaults
29    var o = options || {},
30
31      activeclass = o.activeclass || 'active',
32      autoselect = typeof(o.autoselect) === "boolean" ? o.autoselect : true,
33      nested = typeof(o.nested) === "boolean" ? o.nested : true,
34      indent = o.indent || "→",
35      label = o.label || HappenStanceSiteParameters.message_menu,
36
37      // helper variables
38      level = 0,
39      selected = " selected ";
40
41    // insert the freshly created dropdown navigation after the existing navigation
42    element.insertAdjacentHTML('afterend', parselist(element) );
43
44    var nav = document.getElementById(id());
45
46    // autoforward on click
47    if (nav.addEventListener) {
48      nav.addEventListener('change',goTo);
49    }
50    if (nav.attachEvent) {
51      nav.attachEvent('onchange', goTo);
52    }
53
54    return nav;
55
56    function goTo(e){
57
58      // Crossbrowser issues - http://www.quirksmode.org/js/events_properties.html
59      var targ;
60      if (!e) e = window.event;
61      if (e.target) targ = e.target;
62      else if (e.srcElement) targ = e.srcElement;
63      if (targ.nodeType === 3) // defeat Safari bug
64        targ = targ.parentNode; 
65
66      if(targ.value) window.location.href = targ.value; 
67    }
68
69    function islist(list){
70      var n = list.nodeName.toLowerCase();
71      return (n === 'ul' || n === 'ol');
72    }
73
74    function id(nextId){
75      for(var j=1; document.getElementById('selectnav'+j);j++);
76      return (nextId) ? 'selectnav'+j : 'selectnav'+(j-1);
77    }
78
79    function parselist(list){
80
81      // go one level down
82      level++;
83
84      var length = list.children.length,
85        html = '',
86        prefix = '',
87        k = level-1
88        ;
89
90      // return immediately if has no children
91      if (!length) {
92        return;
93      }
94
95      if(k) {
96        while(k--){
97          prefix += indent;
98        }
99        prefix += " ";
100      }
101
102      for(var i=0; i < length; i++){
103
104        var link = list.children[i].children[0];
105        if(typeof(link) !== 'undefined'){
106          var text = link.innerText || link.textContent;
107          var isselected = '';
108
109          if(activeclass){
110            isselected = link.className.search(activeclass) !== -1 || link.parentElement.className.search(activeclass) !== -1 ? selected : '';
111          }
112
113          if(autoselect && !isselected){
114            isselected = link.href === document.URL ? selected : '';
115          }
116
117          html += '<option value="' + link.href + '" ' + isselected + '>' + prefix + text +'</option>';
118
119          if(nested){
120            var subElement = list.children[i].children[1];
121            if( subElement && islist(subElement) ){
122              html += parselist(subElement);
123            }
124          }
125        }
126      }
127
128      // adds label and home link
129      if(level === 1 && label) {    
130        html = '<option value="">' + label + '</option><option value="' + HappenStanceSiteParameters.link_home + '">' + HappenStanceSiteParameters.message_home + '</option>' + html;
131      }
132
133      // add <select> tag to the top level of the list
134      if(level === 1) {
135        html = '<select class="selectnav" id="'+id(true)+'">' + html + '</select>';
136      }
137
138      // go 1 level up
139      level--;
140
141      return html;
142    }
143
144  };
145
146  return function (element,options) {
147    selectnav(element,options);
148  };
149
150
151})();

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.