Difference between revisions of "Template:Team:NUS Singapore/JS"

(Undo revision 162752 by Chloroplast (talk))
(Undo revision 162736 by Chloroplast (talk))
Line 1: Line 1:
 
<html>
 
<html>
 +
<!--lunar.js-->
 +
<script>
 +
(function (root, factory) {
 +
  if (typeof define === 'function' ) {
 +
        if(define.amd){
 +
          define(factory);
 +
      }else if (typeof exports === 'object') {
 +
        module.exports = factory;
 +
      } else {
 +
        root.lunar = factory();
 +
      }
 +
  } else if (typeof exports === 'object') {
 +
    module.exports = factory;
 +
  } else {
 +
    root.lunar = factory();
 +
  }
 +
})(this, function () {
 +
 +
  'use strict';
 +
 +
  var lunar = {};
 +
 +
  lunar.hasClass = function (elem, name) {
 +
    return new RegExp('(\\s|^)' + name + '(\\s|$)').test(elem.getAttribute('class'));
 +
  };
 +
 +
  lunar.addClass = function (elem, name) {
 +
    if(!lunar.hasClass(elem, name)){
 +
      if(elem.setAttribute('class', (!!elem.getAttribute('class') ? elem.getAttribute('class') + ' ' : '') + name)){
 +
        true;
 +
      }else{
 +
        false;
 +
      }
 +
    }else{
 +
      false;
 +
    }
 +
  };
 +
 +
  lunar.removeClass = function (elem, name) {
 +
    var remove = elem.getAttribute('class').replace(new RegExp('(\\s|^)' + name + '(\\s|$)', 'g'), '$2');
 +
    if(lunar.hasClass(elem, name)){
 +
      if(elem.setAttribute('class', remove)){
 +
        true;
 +
      }else{
 +
        false;
 +
      }
 +
    }else{
 +
      false;
 +
    }
 +
  };
 +
 +
  lunar.toggleClass = function (elem, name) {
 +
    lunar[lunar.hasClass(elem, name) ? 'removeClass' : 'addClass'](elem, name);
 +
  };
 +
 +
  return lunar;
 +
 +
});
 +
 +
</script>
  
 
<!--imagesloaded.pkgd.min.js-->
 
<!--imagesloaded.pkgd.min.js-->
Line 685: Line 745:
 
  */
 
  */
 
  var SidebarMenuEffects = (function() {
 
  var SidebarMenuEffects = (function() {
 
 
  function hasParentClass( e, classname ) {
 
  function hasParentClass( e, classname ) {
 
if(e === document) return false;
 
if(e === document) return false;
Line 691: Line 750:
 
return true;
 
return true;
 
}
 
}
return e.parentNode && hasParentClass( e.parentNode, classname );
+
                if(e.parentNode){
 +
                    if(hasParentClass( e.parentNode, classname )){
 +
                        return true;
 +
                    }else{
 +
                        return false;
 +
                    }
 +
                }else{
 +
                    return false;
 +
                }
 
}
 
}
  

Revision as of 04:49, 4 October 2016