tsdom
Version:
Fast, lightweight JavaScript DOM manipulation utility
3 lines (2 loc) • 6.13 kB
JavaScript
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).tsdom=t()}}(function(){return function o(s,u,f){function a(e,t){if(!u[e]){if(!s[e]){var n="function"==typeof require&&require;if(!t&&n)return n(e,!0);if(c)return c(e,!0);var r=new Error("Cannot find module '"+e+"'");throw r.code="MODULE_NOT_FOUND",r}var i=u[e]={exports:{}};s[e][0].call(i.exports,function(t){return a(s[e][1][t]||t)},i,i.exports,o,s,u,f)}return u[e].exports}for(var c="function"==typeof require&&require,t=0;t<f.length;t++)a(f[t]);return a}({1:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var u=t("../index");n.delegate=function(o,e,s){return function(n){var t=new u.Instance(e,o),r=null,i=!1;t.each(function(t){var e=n.target;if(e===t)return i=!0,void(r=e);for(;e&&e!==o;)(e=e.parentNode)===t&&(i=!0,r=e)}),i&&s(n,r)}}},{"../index":6}],2:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.direct=function(n){return function(t){var e=t.currentTarget;n(t,e)}}},{}],3:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=t("./registry");n.registry=r.registry;var i=t("./direct");n.direct=i.direct;var o=t("./delegate");n.delegate=o.delegate},{"./delegate":1,"./direct":2,"./registry":4}],4:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var r=function(){function t(){this.list=[]}return t.prototype.find=function(e){return this.list.filter(function(t){return t.type===e})},t.prototype.add=function(t){this.list.push(t)},t.prototype.remove=function(e){var t=this.list;this.list=t.filter(function(t){return t.type!==e})},t}();n.Registry=r,n.registry=function(){return new r}},{}],5:[function(t,e,n){e.exports=t("./index").default},{"./index":6}],6:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var o=t("./utility"),f=t("./event"),r=function(){function i(t,e,n){var r;if(this.meta=n||{},this.events=f.registry(),!(r="string"==typeof t?o.query(t,e||document):t))return this;if(1===r.nodeType||r===window)this[0]=r,this.length=1;else for(var i=this.length=r.length;i--;this[i]=r[i]);}return i.prototype.get=function(t){return this[t]},i.prototype.first=function(){return new i(this[0])},i.prototype.find=function(t){return new i(t,this[0],{owner:this})},i.prototype.closest=function(t){var e,n=document.querySelectorAll(t),r=this[0];do{for(e=n.length;0<=--e&&n.item(e)!==r;);}while(e<0&&(r=r.parentElement));return new i(r)},i.prototype.each=function(t){for(var e=0,n=this.length;e<n&&!1!==t.call(this,this[e],e++););return this},i.prototype.css=function(o){return this.each(function(t){for(var e=0,n=Object.keys(o);e<n.length;e++){var r=n[e],i=o[r];t.style.setProperty(r,i)}}),this},i.prototype.attr=function(o){if("string"==typeof o)return this[0].getAttribute(o);this.each(function(t){for(var e=0,n=Object.keys(o);e<n.length;e++){var r=n[e],i=o[r];t.setAttribute(r,i)}})},i.prototype.hasClass=function(e){var n=!1;return this.each(function(t){n=o.hasClass(t,e)}),n},i.prototype.addClass=function(e){return this.each(function(t){o.hasClass(t,e)||(t.className+=" "+e)}),this},i.prototype.removeClass=function(r){return this.each(function(t){if(o.hasClass(t,r)){var e=new RegExp("(\\s|^)"+r+"(\\s|$)"),n=t.className.replace(e," ").trim();t.className=n.replace(/\s{2,}/g," ")}}),this},i.prototype.toggleClass=function(t){return this.hasClass(t)?this.removeClass(t):this.addClass(t),this},i.prototype.on=function(n,r,i){var o=this.events,s="function"==typeof r&&void 0===i,u="string"==typeof r&&"function"==typeof i;return this.each(function(t){var e=null;if(s&&(e=f.direct(r)),u&&(e=f.delegate(t,r,i)),!e)throw new Error("TSDom.on: Invalid Arguments");t.addEventListener(n,e,!0),o.add({type:n,handler:e})}),this},i.prototype.off=function(n){var t=this.events;return this.each(function(e){t.find(n).forEach(function(t){void 0!==t&&e.removeEventListener(n,t.handler,!0)})}),t.remove(n),this},i.prototype.val=function(t){var e=this.get(0);return void 0===e.value?null:void 0===t?e.value:e.value=t},i.prototype.text=function(e){var t=this.get(0);return t?void 0===e?t.innerText:(this.each(function(t){t.innerHTML=e}),e):null},i.prototype.data=function(e,n){var t=this.get(0);return t?void 0===n?t.getAttribute("data-"+e):(this.each(function(t){t.setAttribute("data-"+e,n)}),n):null},i.prototype.html=function(e){var t=this.get(0);return t?void 0===e?t.innerHTML:(this.each(function(t){t.innerHTML=e}),e):null},i.prototype.append=function(e){return this.each(function(t){if("string"==typeof e)return t.insertAdjacentHTML("beforeend",e);t.appendChild(e)}),this},i.prototype.prepend=function(e){return this.each(function(t){if("string"==typeof e)return t.insertAdjacentHTML("afterbegin",e);t.insertBefore(e,t.firstChild)}),this},i.prototype.empty=function(){return this.each(function(t){for(;t.firstChild;)t.removeChild(t.firstChild)}),this},i.prototype.remove=function(){this.each(function(t){t.parentNode.removeChild(t)})},i.prototype.toArray=function(){var e=[];return this.each(function(t){e.push(t)}),e},i}();n.Instance=r,n.default=function(t,e){return new r(t,e)}},{"./event":3,"./utility":8}],7:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0}),n.hasClass=function(t,e){var n=!1,r=" "+e+" ";return-1<(" "+t.className+" ").replace(/[\n\t]/g," ").indexOf(r)&&(n=!0),n}},{}],8:[function(t,e,n){"use strict";function r(t){for(var e in t)n.hasOwnProperty(e)||(n[e]=t[e])}Object.defineProperty(n,"__esModule",{value:!0}),r(t("./query")),r(t("./hasClass"))},{"./hasClass":7,"./query":9}],9:[function(t,e,n){"use strict";Object.defineProperty(n,"__esModule",{value:!0});var i=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/;n.query=function(t,e){var n,r;if(n=i.exec(t)){if(r=n[3])return e.getElementsByClassName(r);if(r=n[2])return e.getElementsByTagName(r);if(r=n[1])return document.getElementById(r)}return e.querySelectorAll(t)}},{}]},{},[5])(5)});
//# sourceMappingURL=tsdom.inc.js.map