/
dollardom.min.js
11 lines (11 loc) · 5.31 KB
/
dollardom.min.js
1
2
3
4
5
6
7
8
9
10
11
/**
* $dom library (v0.9.2b) copyright 2009, 2010, 2011 Keith Clark
* Licensed under the MIT License.
* http://www.keithclark.co.uk/
*
* Copyright 2011, 2012 Julien Wajsberg
* Licensed under the MIT License
* https://github.com/julienw/dollardom
* @preserve
*/
!function(t){function e(t,e,r){var i=n(e),o=P[i];return o&&o.set?o.set(t,r):t.style[i]=r}function n(t){return O[t]||(O[t]=t.replace($,function(t,e){return e.toUpperCase()}))}function r(t,n,r){if(r===A){if("string"==typeof n)return R(t,n)||0;for(var i in n)e(t,i,n[i])}else e(t,n,r)}function i(t){var e,n=[];if("string"==typeof t)for(;t&&(e=t.match(I),""!==e[0]);)n.push({rel:e[1],uTag:(e[2]||"").toUpperCase(),id:e[3],classes:e[4]?e[4].split("."):A}),t=t.substring(e[0].length);return n}function o(t,e){for(;(t=t.parentNode)&&t!==e;);return null!==t}function u(t,e){function n(t,e){var n,i=e.id?(n=(t&&t.ownerDocument||W).getElementById(e.id))&&o(n,t)?[n]:[]:r(t.getElementsByTagName(e.uTag||"*"));if(n=i.length,n>0&&(e.id||e.classes))for(;n--;)a(i[n],e)||i.splice(n,1);return i}function r(t){try{return Array.prototype.slice.call(t)}catch(e){for(var n=[],r=0,i=t.length;i>r;r++)n.push(t[r]);return n}}function u(t){for(var e=m.length;e--;)if(m[e]===t)return F;return H}var l,c,f,s,d,g,h,v,p,m=[],y=[t],E=i(e);for(E.length||(E=[{}]),l=0,c=E.length;c>l;l++){for(h=E[l],f=0,s=y.length;s>f;f++)switch(v=y[f],h.rel){case">":var b=v.childNodes;for(d=0,g=b.length;g>d;d++)a(b[d],h)&&m.push(b[d]);break;case"~":for(;v=v.nextSibling;)if(a(v,h)){if(u(v))break;m.push(v)}break;case"+":for(;(v=v.nextSibling)&&1!==v.nodeType;);v&&a(v,h)&&m.push(v);break;default:if(p=n(v,h),l>0)for(d=0,g=p.length;g>d;d++)u(p[d])||m.push(p[d]);else m=m.concat(p)}if(!m.length)return[];y=m.splice(0,m.length)}return y}function a(t,e){if(!e)return!0;var n=e.uTag,r=e.id,i=e.classes;return!(1!==t.nodeType||n&&n!==t.tagName||r&&r!==t.id||i&&!s(t,i))}function l(t,e,n){for(n=i(n)[0];t&&!a(t,n)&&(t=t[e]););return t}function c(t,e){return e=i(e)[0],t&&a(t,e)}function f(t,e,n){return l(t[e],e,n)}function s(t,e){if(""===t.className)return H;for(var n=0;n<e.length;n++)if(!C(t,e[n]))return H;return F}function d(){function e(){if(!r){r=!0,i&&(i=t.clearTimeout(i));for(var e=0,n=j.length;n>e;e++)j[e]()}}function n(){try{B.doScroll("left")}catch(r){return void t.setTimeout(n,20)}e()}var r,i;if(W.addEventListener)W.addEventListener("DOMContentLoaded",e,H),W.addEventListener("load",e,H);else if(W.attachEvent){W.attachEvent("onload",e);var o=!1;try{o=null===t.frameElement}catch(u){}o&&B.doScroll&&n()}}function g(t,e){var n=i(t)[0],r=n.uTag;if(!r)return null;var o=(e||W).createElement(r),u=n.id,a=n.classes;return u&&(o.id=u),a&&(o.className=a.join(" ")),o}function h(e){/loaded|complete|interactive/.test(W.readyState)?t.setTimeout(e,0):j.push(e)}function v(t,e){return u(e||B,t)}function p(t,e){return f(t,"parentNode",e)}function m(t,e){return f(t,"nextSibling",e)}function y(t,e){return f(t,"previousSibling",e)}function E(t,e){return t=t.parentNode.firstChild,l(t,"nextSibling",e)}function b(t,e){return t=t.parentNode.lastChild,l(t,"previousSibling",e)}function C(t,e){return(" "+t.className+" ").indexOf(" "+e+" ")>-1}function N(t,e){C(t,e)||(t.className+=" "+e)}function w(t,e){C(t,e)&&(t.className=t.className.replace(RegExp("(^|\\s)"+e+"(\\s|$)")," ").replace(/\s$/,""))}function S(t,e,n){(n?N:w)(t,e)}function T(t){return W.createTextNode(t)}function x(t,e,n){t.setAttribute(e,""+n)}function L(t,e){return t.getAttribute(e)||null}function D(t,e,n){if("object"!=typeof e)return n===A?L(t,e):void x(t,e,n);for(var r in e)x(t,r,e[r])}function V(t){for(;t.firstChild;)t.removeChild(t.firstChild)}function k(t,e){e||(e=t,t=this);for(var n in e)t[n]=e[n]}var A,W=t.document,B=W.documentElement,F=!0,H=!1,I=/^\s*([>+~])?\s*([*\w-]+)?(?:#([\w-]+))?(?:\.([\w.-]+))?\s*/,$=/-(\w)/g,j=[],q=[],O={"float":"cssFloat"in B.style?"cssFloat":"styleFloat"},P={borderWidth:{get:function(t){return R(t,"border-left-width")}},padding:{get:function(t){return R(t,"padding-left")}},margin:{get:function(t){return R(t,"margin-left")}}};!("opacity"in B.style)&&"filters"in B&&(P.opacity={set:function(t,e){var n=t.filters.alpha;n?n.opacity=100*e:t.style.filter+=" Alpha(opacity="+100*e+")"},get:function(t){var e=t.filters.alpha;return e?e.opacity/100:1}}),"clientWidth"in B&&(P.width={get:function(t){return t.style.width||t.clientWidth||t.offsetWidth}}),"clientHeight"in B&&(P.height={get:function(t){return t.style.height||t.clientHeight||t.offsetHeight}});var U=t.addEventListener?function(t,e,n){t.addEventListener(e,n,!1)}:function(e,n,r){var i=e.uniqueID+n+r;q[i]=function(){var n=t.event;return n.target=n.srcElement||W,n.currentTarget=e,n.preventDefault=function(){n.returnValue=!1},n.stopPropagation=function(){n.cancelBubble=!0},r.call(e,n)},e.attachEvent("on"+n,q[i])},M=t.removeEventListener?function(t,e,n){t.removeEventListener(e,n,!1)}:function(t,e,n){var r=t.uniqueID+e+n;t.detachEvent("on"+e,q[r]),delete q[r]},R=W.defaultView&&W.defaultView.getComputedStyle?function(t,e){var r=n(e),i=P[r];return i&&i.get?i.get(t):t.ownerDocument.defaultView.getComputedStyle(t,null).getPropertyValue(e)}:function(t,e){var r=n(e),i=P[r];return i&&i.get?i.get(t):t.currentStyle[r]},z={create:g,onready:h,addEvent:U,removeEvent:M,get:v,descendants:u,ancestor:p,next:m,previous:y,first:E,last:b,empty:V,is:c,text:T,attr:D,hasClass:C,addClass:N,removeClass:w,toggleClass:S,style:r,extend:k};t.$dom=z,d()}(this);