Advertisement
Anon6k

kkk.bz Theme JavaScript

Jan 25th, 2016
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* begin Page */
  2.  
  3.  
  4.  
  5. var artEventHelper = {
  6.     'bind': function(obj, evt, fn) {
  7.         if (obj.addEventListener)
  8.             obj.addEventListener(evt, fn, false);
  9.         else if (obj.attachEvent)
  10.             obj.attachEvent('on' + evt, fn);
  11.         else
  12.             obj['on' + evt] = fn;
  13.     }
  14. };
  15.  
  16. var userAgent = navigator.userAgent.toLowerCase();
  17. var browser = {
  18.     version: (userAgent.match(/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/) || [])[1],
  19.     safari: /webkit/.test(userAgent) && !/chrome/.test(userAgent),
  20.     chrome: /chrome/.test(userAgent),
  21.     opera: /opera/.test(userAgent),
  22.     msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
  23.     mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
  24. };
  25.  
  26. var artLoadEvent = (function() {
  27.    
  28.  
  29.     var list = [];
  30.  
  31.     var done = false;
  32.     var ready = function() {
  33.         if (done) return;
  34.         done = true;
  35.         for (var i = 0; i < list.length; i++)
  36.             list[i]();
  37.     };
  38.  
  39.     if (document.addEventListener && !browser.opera)
  40.         document.addEventListener('DOMContentLoaded', ready, false);
  41.  
  42.     if (browser.msie && window == top) {
  43.         (function() {
  44.             try {
  45.                 document.documentElement.doScroll('left');
  46.             } catch (e) {
  47.                 setTimeout(arguments.callee, 10);
  48.                 return;
  49.             }
  50.             ready();
  51.         })();
  52.     }
  53.  
  54.     if (browser.opera) {
  55.         document.addEventListener('DOMContentLoaded', function() {
  56.             for (var i = 0; i < document.styleSheets.length; i++) {
  57.                 if (document.styleSheets[i].disabled) {
  58.                     setTimeout(arguments.callee, 10);
  59.                     return;
  60.                 }
  61.             }
  62.             ready();
  63.         }, false);
  64.     }
  65.  
  66.     if (browser.safari) {
  67.         var numStyles;
  68.         (function() {
  69.             if (document.readyState != 'loaded' && document.readyState != 'complete') {
  70.                 setTimeout(arguments.callee, 10);
  71.                 return;
  72.             }
  73.             if ('undefined' == typeof numStyles) {
  74.                 numStyles = document.getElementsByTagName('style').length;
  75.                 var links = document.getElementsByTagName('link');
  76.                 for (var i = 0; i < links.length; i++) {
  77.                     numStyles += (links[i].getAttribute('rel') == 'stylesheet') ? 1 : 0;
  78.                 }
  79.                 if (document.styleSheets.length != numStyles) {
  80.                     setTimeout(arguments.callee, 0);
  81.                     return;
  82.                 }
  83.             }
  84.             ready();
  85.         })();
  86.     }
  87.  
  88.     artEventHelper.bind(window, 'load', ready);
  89.  
  90.     return ({
  91.         add: function(f) {
  92.             list.push(f);
  93.         }
  94.     })
  95. })();
  96.  
  97. (function() {
  98.     // fix ie blinking
  99.     var m = document.uniqueID && document.compatMode && !window.XMLHttpRequest && document.execCommand;
  100.     try { if (!!m) { m('BackgroundImageCache', false, true); } }
  101.     catch (oh) { };
  102. })();
  103.  
  104. function xGetElementsByClassName(clsName, parentEle, tagName) {
  105.     var elements = null;
  106.     var found = [];
  107.     var s = String.fromCharCode(92);
  108.     var re = new RegExp('(?:^|' + s + 's+)' + clsName + '(?:$|' + s + 's+)');
  109.     if (!parentEle) parentEle = document;
  110.     if (!tagName) tagName = '*';
  111.     elements = parentEle.getElementsByTagName(tagName);
  112.     if (elements) {
  113.         for (var i = 0; i < elements.length; ++i) {
  114.             if (elements[i].className.search(re) != -1) {
  115.                 found[found.length] = elements[i];
  116.             }
  117.         }
  118.     }
  119.     return found;
  120. }
  121.  
  122. var styleUrlCached = null;
  123. function GetStyleUrl() {
  124.     if (null == styleUrlCached) {
  125.         var ns;
  126.         styleUrlCached = '';
  127.         ns = document.getElementsByTagName('link');
  128.         for (var i = 0; i < ns.length; i++) {
  129.             var l = ns[i];
  130.             if (l.href && /style\.css(\?.*)?$/.test(l.href)) {
  131.                 return styleUrlCached = l.href.replace(/style\.css(\?.*)?$/, '');
  132.             }
  133.         }
  134.  
  135.         ns = document.getElementsByTagName('style');
  136.         for (var i = 0; i < ns.length; i++) {
  137.             var matches = new RegExp('import\\s+"([^"]+\\/)style\\.css"').exec(ns[i].innerHTML);
  138.             if (null != matches && matches.length > 0)
  139.                 return styleUrlCached = matches[1];
  140.         }
  141.     }
  142.     return styleUrlCached;
  143. }
  144.  
  145. function fixPNG(element) {
  146.     if (/MSIE (5\.5|6).+Win/.test(navigator.userAgent)) {
  147.         var src;
  148.         if (element.tagName == 'IMG') {
  149.             if (/\.png$/.test(element.src)) {
  150.                 src = element.src;
  151.                 element.src = GetStyleUrl() + 'images/spacer.gif';
  152.             }
  153.         }
  154.         else {
  155.             src = element.currentStyle.backgroundImage.match(/url\("(.+\.png)"\)/i);
  156.             if (src) {
  157.                 src = src[1];
  158.                 element.runtimeStyle.backgroundImage = 'none';
  159.             }
  160.         }
  161.         if (src) element.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + src + "')";
  162.     }
  163. }
  164.  
  165. function artHasClass(el, cls) {
  166.     return (el && el.className && (' ' + el.className + ' ').indexOf(' ' + cls + ' ') != -1);
  167. }/* end Page */
  168.  
  169. /* begin Menu */
  170. function Insert_Separators() {
  171.     var menus = xGetElementsByClassName("art-menu", document);
  172.     for (var i = 0; i < menus.length; i++) {
  173.         var menu = menus[i];
  174.         var childs = menu.childNodes;
  175.         var listItems = [];
  176.         for (var j = 0; j < childs.length; j++) {
  177.             var el = childs[j];
  178.             if (String(el.tagName).toLowerCase() == "li") listItems.push(el);
  179.         }
  180.         for (var j = 0; j < listItems.length - 1; j++) {
  181.             var span = document.createElement('span');
  182.             span.className = 'art-menu-separator';
  183.             var li = document.createElement('li');
  184.             li.appendChild(span);
  185.             listItems[j].parentNode.insertBefore(li, listItems[j].nextSibling);
  186.         }
  187.     }
  188. }
  189. artLoadEvent.add(Insert_Separators);
  190.  
  191. function Menu_IE6Setup() {
  192.     var isIE6 = navigator.userAgent.toLowerCase().indexOf("msie") != -1
  193.     && navigator.userAgent.toLowerCase().indexOf("msie 7") == -1;
  194.     if (!isIE6) return;
  195.     var aTmp2, i, j, oLI, aUL, aA;
  196.     var aTmp = xGetElementsByClassName("art-menu", document, "ul");
  197.     for (i = 0; i < aTmp.length; i++) {
  198.         aTmp2 = aTmp[i].getElementsByTagName("li");
  199.         for (j = 0; j < aTmp2.length; j++) {
  200.             oLI = aTmp2[j];
  201.             aUL = oLI.getElementsByTagName("ul");
  202.             if (aUL && aUL.length) {
  203.                 oLI.UL = aUL[0];
  204.                 aA = oLI.getElementsByTagName("a");
  205.                 if (aA && aA.length)
  206.                     oLI.A = aA[0];
  207.                 oLI.onmouseenter = function() {
  208.                     this.className += " art-menuhover";
  209.                     this.UL.className += " art-menuhoverUL";
  210.                     if (this.A) this.A.className += " art-menuhoverA";
  211.                 };
  212.                 oLI.onmouseleave = function() {
  213.                     this.className = this.className.replace(/art-menuhover/, "");
  214.                     this.UL.className = this.UL.className.replace(/art-menuhoverUL/, "");
  215.                     if (this.A) this.A.className = this.A.className.replace(/art-menuhoverA/, "");
  216.                 };
  217.             }
  218.         }
  219.     }
  220. }
  221. artLoadEvent.add(Menu_IE6Setup);
  222. /* end Menu */
  223.  
  224. /* begin Button */
  225. function artButtonsSetupJsHover(className) {
  226.     var tags = ["input", "a", "button"];
  227.     for (var j = 0; j < tags.length; j++){
  228.         var buttons = xGetElementsByClassName(className, document, tags[j]);
  229.         for (var i = 0; i < buttons.length; i++) {
  230.             var button = buttons[i];
  231.             if (!button.tagName || !button.parentNode) return;
  232.             if (!artHasClass(button.parentNode, 'art-button-wrapper')) {
  233.                 if (!artHasClass(button, 'art-button')) button.className += ' art-button';
  234.                 var wrapper = document.createElement('span');
  235.                 wrapper.className = "art-button-wrapper";
  236.                 if (artHasClass(button, 'active')) wrapper.className += ' active';
  237.                 var spanL = document.createElement('span');
  238.                 spanL.className = "l";
  239.                 spanL.innerHTML = " ";
  240.                 wrapper.appendChild(spanL);
  241.                 var spanR = document.createElement('span');
  242.                 spanR.className = "r";
  243.                 spanR.innerHTML = " ";
  244.                 wrapper.appendChild(spanR);
  245.                 button.parentNode.insertBefore(wrapper, button);
  246.                 wrapper.appendChild(button);
  247.             }
  248.             artEventHelper.bind(button, 'mouseover', function(e) {
  249.                 e = e || window.event;
  250.                 wrapper = (e.target || e.srcElement).parentNode;
  251.                 wrapper.className += " hover";
  252.             });
  253.             artEventHelper.bind(button, 'mouseout', function(e) {
  254.                 e = e || window.event;
  255.                 button = e.target || e.srcElement;
  256.                 wrapper = button.parentNode;
  257.                 wrapper.className = wrapper.className.replace(/hover/, "");
  258.                 if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
  259.             });
  260.             artEventHelper.bind(button, 'mousedown', function(e) {
  261.                 e = e || window.event;
  262.                 button = e.target || e.srcElement;
  263.                 wrapper = button.parentNode;
  264.                 if (!artHasClass(button, 'active')) wrapper.className += " active";
  265.             });
  266.             artEventHelper.bind(button, 'mouseup', function(e) {
  267.                 e = e || window.event;
  268.                 button = e.target || e.srcElement;
  269.                 wrapper = button.parentNode;
  270.                 if (!artHasClass(button, 'active')) wrapper.className = wrapper.className.replace(/active/, "");
  271.             });
  272.         }
  273.     }
  274. }
  275. artLoadEvent.add(function() { artButtonsSetupJsHover("art-button"); });
  276. /* end Button */
  277.  
  278.  
  279.  
  280. artLoadEvent.add(function() { artButtonsSetupJsHover("button"); });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement