-
Notifications
You must be signed in to change notification settings - Fork 0
/
thin.min.js
1 lines (1 loc) · 4.34 KB
/
thin.min.js
1
!function(t,e){"use strict";function r(r,n){return n===!0?void t.addEventListener("load",r):void e.addEventListener("DOMContentLoaded",r)}function n(e,r,n){t.Array.prototype.forEach.call(e,r,n)}function o(t){var e=[],r=Object.getPrototypeOf(t);return null!==r&&(e=e.concat(o(r)),e.push((h?r:r.constructor).toString().match("(?:function|\\[object) ([A-Za-z0-9]+)")[1].replace("Prototype",""))),e}function i(){var t;do t="thin-rcn-"+Math.random().toString(36).substring(7);while(e.querySelector("."+t));return t}function s(){var t,r=i();return n(arguments,function(t){var e=o(t);(e.indexOf("NodeList")>=0||e.indexOf("Element")>=0)&&t.addClass(r)}),t=e.querySelectorAll("."+r),t.removeClass(r),t}function u(t,e,r){var n=[];return t.forEach(function(t){n.push(t[e].apply(t,r))}),n}function a(t){var e=typeof t;return"object"!==e?e:e+":{"+o(t).join("}{")+"}"}function c(t){var e=[];return n(t,function(t){e.push(a(t))}),e.join(", ")}function p(t){var e=t.split(new RegExp(", ?"));return e=e.map(function(t,e){return t=(e>0?", ":"")+t,t=t.replace(new RegExp("^(, )?(.*)\\?$"),"($1$2)?"),t=t.replace(new RegExp("^(, )?(.*)\\+$"),"($1$2(, )?)+"),t=t.replace(new RegExp("^(\\(?(?:, )?)object:((?:[^\\|\\(\\)]+\\|?)+)(\\)\\?|\\(, \\)\\?\\)\\+)?$"),"$1object:({[^}]+})*{($2)}({[^}]+})*$3")}),new RegExp("^"+e.join("")+"$")}function l(t){var e,r=c(t);for(e in y)if(null!==r.match(p(e)))return y[e]}var h="Object"===Object.getPrototypeOf(e.querySelectorAll("html")).constructor.name,f={Element:{setAttribute:t.Element.prototype.setAttribute,removeAttribute:t.Element.prototype.removeAttribute,addEventListener:t.Element.prototype.addEventListener,removeEventListener:t.Element.prototype.removeEventListener}},y={string:{thisArg:e,callback:e.querySelectorAll},"function, boolean?":{thisArg:this,callback:r},"object:Element|NodeList+":{thisArg:this,callback:s}};t.Thin=function(){var t=l(arguments);return t.callback.apply(t.thisArg,arguments)},t.Element.prototype.addClass=function(){return n(arguments,function(t){this.classList.add(t)},this),this},t.Element.prototype.removeClass=function(){return n(arguments,function(t){this.classList.remove(t)},this),this},t.Element.prototype.hasClass=function(t){return this.classList.contains(t)},t.Element.prototype.setAttribute=function(t,e){var r=t;"string"==typeof r&&(r={},r[t]=e);for(t in r)f.Element.setAttribute.call(this,t,r[t]);return this},t.Element.prototype.removeAttribute=function(){return n(arguments,function(t){f.Element.removeAttribute.call(this,t)},this),this},t.Element.prototype.setProperty=function(t,e){var r=t;"string"==typeof r&&(r={},r[t]=e);for(t in r)this.hasProperty(t)&&(this[t]=r[t]);return this},t.Element.prototype.getProperty=function(t){return this[t]},t.Element.prototype.hasProperty=function(t){return t in this},t.Element.prototype.addEventListener=function(t,e,r){return f.Element.addEventListener.call(this,t,e,r),this},t.Element.prototype.removeEventListener=function(t,e,r){return f.Element.removeEventListener.call(this,t,e,r),this},t.NodeList.prototype.forEach=function(t,e){return n(this,t,e),this},t.NodeList.prototype.addClass=function(){return u(this,"addClass",arguments),this},t.NodeList.prototype.removeClass=function(){return u(this,"removeClass",arguments),this},t.NodeList.prototype.hasClass=function(t){var e=u(this,"hasClass",[t]);return e.indexOf(!0)>=0},t.NodeList.prototype.getAttribute=function(t){return this[0].getAttribute(t)},t.NodeList.prototype.setAttribute=function(t,e){return u(this,"setAttribute",[t,e]),this},t.NodeList.prototype.removeAttribute=function(){return u(this,"removeAttribute",arguments),this},t.NodeList.prototype.hasAttribute=function(t){var e=u(this,"hasAttribute",[t]);return e.indexOf(!0)>=0},t.NodeList.prototype.setProperty=function(t,e){return u(this,"setProperty",[t,e]),this},t.NodeList.prototype.getProperty=function(t){return this[0].getProperty(t)},t.NodeList.prototype.hasProperty=function(t){var e=u(this,"hasProperty",[t]);return e.indexOf(!0)>=0},t.NodeList.prototype.addEventListener=function(t,e,r){return u(this,"addEventListener",[t,e,r]),this},t.NodeList.prototype.removeEventListener=function(t,e,r){return u(this,"removeEventListener",[t,e,r]),this},t.NodeList.prototype.querySelector=function(t){var e=u(this,"querySelector",[t]);return e.filter(function(t){return null!==t})[0]||[]},t.NodeList.prototype.querySelectorAll=function(t){var e=u(this,"querySelectorAll",[t]);return s.apply(null,e)}}(window,document);