PageSourceSearch

https://www.asia-pacificresearch.com/wp-content/themes/globalresearch/js/jquery.main.js

js asia-pacificresearch.com collected 2026-09-26 03:54:35 UTC 14,829 bytes, 468 lines download raw bytes

1// page init
2jQuery(function() {
3  initAccordion();
4  initDropDown();
5  initOpenClose();
6});
7
8// open-close init
9function initOpenClose() {
10  jQuery('div.filter-wrap').openClose({
11    addClassBeforeAnimation : false,
12    activeClass : 'expanded',
13    opener : 'a.opener',
14    slider : 'div.slide',
15    effect : 'slide',
16    animSpeed : 500
17  });
18
19}
20
21/*
22 * jQuery Open/Close plugin
23 */
24;
25(function($) {
26  jQuery.fn.openClose = function(o) {
27    // default options
28    var options = $.extend({
29      addClassBeforeAnimation : true,
30      activeClass : 'active',
31      opener : '.opener',
32      slider : '.slide',
33      animSpeed : 400,
34      animStart : false,
35      animEnd : false,
36      effect : 'fade',
37      event : 'click'
38    }, o);
39
40    return this.each(function() {
41      // options
42      var holder = jQuery(this), animating;
43      var opener = jQuery(options.opener, holder);
44      var slider = jQuery(options.slider, holder);
45      if (slider.length) {
46        opener.bind(options.event, function() {
47          if (!animating) {
48            animating = true;
49            if (typeof options.animStart === 'function')
50              options.animStart();
51            if (holder.hasClass(options.activeClass)) {
52              toggleEffects[options.effect].hide({
53                speed : options.animSpeed,
54                box : slider,
55                complete : function() {
56                  animating = false;
57                  if (!options.addClassBeforeAnimation) {
58                    holder.removeClass(options.activeClass);
59                  }
60                  if (typeof options.animEnd === 'function')
61                    options.animEnd();
62                }
63              });
64              if (options.addClassBeforeAnimation) {
65                holder.removeClass(options.activeClass);
66              }
67            } else {
68              if (options.addClassBeforeAnimation) {
69                holder.addClass(options.activeClass);
70              }
71              toggleEffects[options.effect].show({
72                speed : options.animSpeed,
73                box : slider,
74                complete : function() {
75                  animating = false;
76                  if (!options.addClassBeforeAnimation) {
77                    holder.addClass(options.activeClass);
78                  }
79                  if (typeof options.animEnd === 'function')
80                    options.animEnd();
81                }
82              })
83            }
84          }
85          return false;
86        });
87        if (holder.hasClass(options.activeClass)) {
88          slider.show();
89        } else {
90          slider.hide();
91        }
92      }
93    });
94  }
95
96  // animation effects
97  var toggleEffects = {
98    slide : {
99      show : function(o) {
100        o.box.slideDown(o.speed, o.complete);
101      },
102      hide : function(o) {
103        o.box.slideUp(o.speed, o.complete);
104      }
105    },
106    fade : {
107      show : function(o) {
108        o.box.fadeIn(o.speed, o.complete);
109      },
110      hide : function(o) {
111        o.box.fadeOut(o.speed, o.complete);
112      }
113    },
114    none : {
115      show : function(o) {
116        o.box.show(0, o.complete);
117      },
118      hide : function(o) {
119        o.box.hide(0, o.complete);
120      }
121    }
122  }
123}(jQuery));
124
125// clear inputs on focus
126function initInputs() {
127  PlaceholderInput.replaceByOptions({
128    // filter options
129    clearInputs : true,
130    clearTextareas : true,
131    clearPasswords : true,
132    skipClass : 'default',
133
134    // input options
135    wrapWithElement : false,
136    showUntilTyping : false,
137    getParentByClass : false,
138    placeholderAttr : 'value'
139  });
140}
141
142// placeholder class
143;
144(function() {
145  var placeholderCollection = [];
146  PlaceholderInput = function() {
147    this.options = {
148      element : null,
149      showUntilTyping : false,
150      wrapWithElement : false,
151      getParentByClass : false,
152      placeholderAttr : 'value',
153      inputFocusClass : 'focus',
154      inputActiveClass : 'text-active',
155      parentFocusClass : 'parent-focus',
156      parentActiveClass : 'parent-active',
157      labelFocusClass : 'label-focus',
158      labelActiveClass : 'label-active',
159      fakeElementClass : 'input-placeholder-text'
160    }
161    placeholderCollection.push(this);
162    this.init.apply(this, arguments);
163  }
164  PlaceholderInput.refreshAllInputs = function(except) {
165    for ( var i = 0; i < placeholderCollection.length; i++) {
166      if (except !== placeholderCollection[i]) {
167        placeholderCollection[i].refreshState();
168      }
169    }
170  }
171  PlaceholderInput.replaceByOptions = function(opt) {
172    var inputs = [].concat(convertToArray(document.getElementsByTagName('input')), convertToArray(document.getElementsByTagName('textarea')));
173    for ( var i = 0; i < inputs.length; i++) {
174      if (inputs[i].className.indexOf(opt.skipClass) < 0) {
175        var inputType = getInputType(inputs[i]);
176        if ((opt.clearInputs && (inputType === 'text' || inputType === 'email')) || (opt.clearTextareas && inputType === 'textarea')
177            || (opt.clearPasswords && inputType === 'password')) {
178          new PlaceholderInput({
179            element : inputs[i],
180            wrapWithElement : opt.wrapWithElement,
181            showUntilTyping : opt.showUntilTyping,
182            getParentByClass : opt.getParentByClass,
183            placeholderAttr : inputs[i].getAttribute('placeholder') ? 'placeholder' : opt.placeholderAttr
184          });
185        }
186      }
187    }
188  }
189  PlaceholderInput.prototype = {
190    init : function(opt) {
191      this.setOptions(opt);
192      if (this.element && this.element.PlaceholderInst) {
193        this.element.PlaceholderInst.refreshClasses();
194      } else {
195        this.element.PlaceholderInst = this;
196        if (this.elementType !== 'radio' || this.elementType !== 'checkbox' || this.elementType !== 'file') {
197          this.initElements();
198          this.attachEvents();
199          this.refreshClasses();
200        }
201      }
202    },
203    setOptions : function(opt) {
204      for ( var p in opt) {
205        if (opt.hasOwnProperty(p)) {
206          this.options[p] = opt[p];
207        }
208      }
209      if (this.options.element) {
210        this.element = this.options.element;
211        this.elementType = getInputType(this.element);
212        this.wrapWithElement = (this.elementType === 'password' || this.options.showUntilTyping ? true : this.options.wrapWithElement
213            || this.options.placeholderAttr === 'placeholder');
214        this.setOrigValue(this.options.placeholderAttr == 'value' ? this.element.defaultValue : this.element.getAttribute(this.options.placeholderAttr));
215      }
216    },
217    setOrigValue : function(value) {
218      this.origValue = value;
219    },
220    initElements : function() {
221      // create fake element if needed
222      if (this.wrapWithElement) {
223        this.element.value = '';
224        this.element.removeAttribute(this.options.placeholderAttr);
225        this.fakeElement = document.createElement('span');
226        this.fakeElement.className = this.options.fakeElementClass;
227        this.fakeElement.innerHTML += this.origValue;
228        this.fakeElement.style.color = getStyle(this.element, 'color');
229        this.fakeElement.style.position = 'absolute';
230        this.element.parentNode.insertBefore(this.fakeElement, this.element);
231      }
232      // get input label
233      if (this.element.id) {
234        this.labels = document.getElementsByTagName('label');
235        for ( var i = 0; i < this.labels.length; i++) {
236          if (this.labels[i].htmlFor === this.element.id) {
237            this.labelFor = this.labels[i];
238            break;
239          }
240        }
241      }
242      // get parent node (or parentNode by className)
243      this.elementParent = this.element.parentNode;
244      if (typeof this.options.getParentByClass === 'string') {
245        var el = this.element;
246        while (el.parentNode) {
247          if (hasClass(el.parentNode, this.options.getParentByClass)) {
248            this.elementParent = el.parentNode;
249            break;
250          } else {
251            el = el.parentNode;
252          }
253        }
254      }
255    },
256    attachEvents : function() {
257      this.element.onfocus = bindScope(this.focusHandler, this);
258      this.element.onblur = bindScope(this.blurHandler, this);
259      if (this.options.showUntilTyping) {
260        this.element.onkeydown = bindScope(this.typingHandler, this);
261        this.element.onpaste = bindScope(this.typingHandler, this);
262      }
263      if (this.wrapWithElement)
264        this.fakeElement.onclick = bindScope(this.focusSetter, this);
265    },
266    togglePlaceholderText : function(state) {
267      if (this.wrapWithElement) {
268        this.fakeElement.style.display = state ? '' : 'none';
269      } else {
270        this.element.value = state ? this.origValue : '';
271      }
272    },
273    focusSetter : function() {
274      this.element.focus();
275    },
276    focusHandler : function() {
277      clearInterval(this.checkerInterval);
278      this.checkerInterval = setInterval(bindScope(this.intervalHandler, this), 1);
279      this.focused = true;
280      if (!this.element.value.length || this.element.value === this.origValue) {
281        if (!this.options.showUntilTyping) {
282          this.togglePlaceholderText(false);
283        }
284      }
285      this.refreshClasses();
286    },
287    blurHandler : function() {
288      clearInterval(this.checkerInterval);
289      this.focused = false;
290      if (!this.element.value.length || this.element.value === this.origValue) {
291        this.togglePlaceholderText(true);
292      }
293      this.refreshClasses();
294      PlaceholderInput.refreshAllInputs(this);
295    },
296    typingHandler : function() {
297      setTimeout(bindScope(function() {
298        if (this.element.value.length) {
299          this.togglePlaceholderText(false);
300          this.refreshClasses();
301        }
302      }, this), 10);
303    },
304    intervalHandler : function() {
305      if (typeof this.tmpValue === 'undefined') {
306        this.tmpValue = this.element.value;
307      }
308      if (this.tmpValue != this.element.value) {
309        PlaceholderInput.refreshAllInputs(this);
310      }
311    },
312    refreshState : function() {
313      if (this.wrapWithElement) {
314        if (this.element.value.length && this.element.value !== this.origValue) {
315          this.togglePlaceholderText(false);
316        } else if (!this.element.value.length) {
317          this.togglePlaceholderText(true);
318        }
319      }
320      this.refreshClasses();
321    },
322    refreshClasses : function() {
323      this.textActive = this.focused || (this.element.value.length && this.element.value !== this.origValue);
324      this.setStateClass(this.element, this.options.inputFocusClass, this.focused);
325      this.setStateClass(this.elementParent, this.options.parentFocusClass, this.focused);
326      this.setStateClass(this.labelFor, this.options.labelFocusClass, this.focused);
327      this.setStateClass(this.element, this.options.inputActiveClass, this.textActive);
328      this.setStateClass(this.elementParent, this.options.parentActiveClass, this.textActive);
329      this.setStateClass(this.labelFor, this.options.labelActiveClass, this.textActive);
330    },
331    setStateClass : function(el, cls, state) {
332      if (!el)
333        return;
334      else if (state)
335        addClass(el, cls);
336      else
337        removeClass(el, cls);
338    }
339  }
340
341  // utility functions
342  function convertToArray(collection) {
343    var arr = [];
344    for ( var i = 0, ref = arr.length = collection.length; i < ref; i++) {
345      arr[i] = collection[i];
346    }
347    return arr;
348  }
349  function getInputType(input) {
350    return (input.type ? input.type : input.tagName).toLowerCase();
351  }
352  function hasClass(el, cls) {
353    return el.className ? el.className.match(new RegExp('(\\s|^)' + cls + '(\\s|$)')) : false;
354  }
355  function addClass(el, cls) {
356    if (!hasClass(el, cls))
357      el.className += " " + cls;
358  }
359  function removeClass(el, cls) {
360    if (hasClass(el, cls)) {
361      el.className = el.className.replace(new RegExp('(\\s|^)' + cls + '(\\s|$)'), ' ');
362    }
363  }
364  function bindScope(f, scope) {
365    return function() {
366      return f.apply(scope, arguments)
367    }
368  }
369  function getStyle(el, prop) {
370    if (document.defaultView && document.defaultView.getComputedStyle) {
371      return document.defaultView.getComputedStyle(el, null)[prop];
372    } else if (el.currentStyle) {
373      return el.currentStyle[prop];
374    } else {
375      return el.style[prop];
376    }
377  }
378}());
379
380if (window.addEventListener)
381  window.addEventListener("load", initInputs, false);
382else if (window.attachEvent)
383  window.attachEvent("onload", initInputs);
384
385function initDropDown() {
386  var nav = document.getElementById("side-accordion");
387  if (nav) {
388    var lis = nav.getElementsByTagName("li");
389    for ( var i = 0; i < lis.length; i++) {
390      if (lis[i].getElementsByTagName("ul").length > 0) {
391        lis[i].className += " has-drop-down"
392        lis[i].getElementsByTagName("a")[0].className += " has-drop-down-a"
393      }
394      lis[i].onmouseover = function() {
395        this.className += " hover";
396      }
397      lis[i].onmouseout = function() {
398        this.className = this.className.replace(" hover", "");
399      }
400    }
401  }
402}
403
404// accordion init
405function initAccordion() {
406  jQuery('ul.accordion').slideAccordion({
407    opener : '>a.opener',
408    slider : '>div.slide',
409    collapsible : false,
410    animSpeed : 300
411  });
412}
413
414/*
415 * jQuery Accordion plugin
416 */
417;
418(function($) {
419  jQuery.fn.slideAccordion = function(o) {
420    // default options
421    var options = jQuery.extend({
422      addClassBeforeAnimation : false,
423      activeClass : 'active',
424      opener : '.opener',
425      slider : '.slide',
426      animSpeed : 300,
427      collapsible : true,
428      event : 'click'
429    }, o);
430
431    return this.each(function() {
432      // options
433      var accordion = jQuery(this);
434      var items = accordion.find(':has(' + options.slider + ')');
435      items.each(function() {
436        var item = jQuery(this);
437        var opener = item.find(options.opener);
438        var slider = item.find(options.slider);
439        opener.bind(options.event, function() {
440          if (!slider.is(':animated')) {
441            if (item.hasClass(options.activeClass)) {
442              if (options.collapsible) {
443                slider.slideUp(options.animSpeed, function() {
444                  item.removeClass(options.activeClass);
445                });
446              }
447            } else {
448              var _levelItems = item.siblings('.' + options.activeClass);
449              item.addClass(options.activeClass);
450              slider.slideDown(options.animSpeed);
451
452              // collapse others
453              _levelItems.find(options.slider).slideUp(options.animSpeed, function() {
454                _levelItems.removeClass(options.activeClass);
455              })
456            }
457          }
458          return false;
459        });
460        if (item.hasClass(options.activeClass)) {
461          slider.show();
462        } else {
463          slider.hide();
464        }
465      });
466    });
467  }
468}(jQuery));

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.