diff --git a/cash.min.js b/cash.min.js new file mode 100644 index 0000000..dfa927b --- /dev/null +++ b/cash.min.js @@ -0,0 +1,46 @@ +/* MIT https://github.com/fabiospampinato/cash */ +(function(){ +var aa={"class":"className",contenteditable:"contentEditable","for":"htmlFor",readonly:"readOnly",maxlength:"maxLength",tabindex:"tabIndex",colspan:"colSpan",rowspan:"rowSpan",usemap:"useMap"};function ba(a,b){try{return a(b)}catch(c){return b}} +var e=document,k=window,ca=e.documentElement,p=e.createElement.bind(e),da=p("div"),q=p("table"),ea=p("tbody"),ha=p("tr"),v=Array.isArray,x=Array.prototype,ia=x.concat,y=x.filter,ja=x.indexOf,ka=x.map,la=x.push,ma=x.slice,z=x.some,na=x.splice,oa=/^#(?:[\w-]|\\.|[^\x00-\xa0])*$/,pa=/^\.(?:[\w-]|\\.|[^\x00-\xa0])*$/,qa=/<.+>/,ra=/^\w+$/; +function A(a,b){var c=!!b&&11===b.nodeType;return a&&(c||B(b)||C(b))?!c&&pa.test(a)?b.getElementsByClassName(a.slice(1)):!c&&ra.test(a)?b.getElementsByTagName(a):b.querySelectorAll(a):[]} +var D=function(){function a(b,c){if(b){if(b instanceof D)return b;var d=b;if(G(b)){if(d=(c instanceof D?c[0]:c)||e,d=oa.test(b)&&"getElementById"in d?d.getElementById(b.slice(1)):qa.test(b)?sa(b):A(b,d),!d)return}else if(H(b))return this.ready(b);if(d.nodeType||d===k)d=[d];this.length=d.length;b=0;for(c=this.length;ba?a+this.length:a]};I.eq=function(a){return J(this.get(a))};I.first=function(){return this.eq(0)};I.last=function(){return this.eq(-1)};function M(a,b,c){if(c)for(c=a.length;c--&&!1!==b.call(a[c],c,a[c]););else if(wa(a)){var d=Object.keys(a);c=0;for(var f=d.length;carguments.length?this[0]&&this[0][a]:this.each(function(d,f){f[a]=b});for(var c in a)this.prop(c,a[c]);return this}};I.removeProp=function(a){return this.each(function(b,c){delete c[aa[a]||a]})}; +function N(){for(var a=[],b=0;barguments.length){if(!this[0]||!C(this[0]))return;var c=this[0].getAttribute(a);return null===c?void 0:c}return void 0===b?this:null===b?this.removeAttr(a):this.each(function(d,f){C(f)&&f.setAttribute(a,b)})}for(c in a)this.attr(c,a[c]);return this}}; +I.toggleClass=function(a,b){var c=Q(a),d=void 0!==b;return this.each(function(f,g){C(g)&&M(c,function(h,m){d?b?g.classList.add(m):g.classList.remove(m):g.classList.toggle(m)})})};I.addClass=function(a){return this.toggleClass(a,!0)};I.removeClass=function(a){return arguments.length?this.toggleClass(a,!1):this.attr("class","")}; +function R(a,b,c,d){for(var f=[],g=H(b),h=d&&O(d),m=0,l=a.length;marguments.length)return this[0]&&T(this[0],a,c);if(!a)return this;b=Ea(a,b,c);return this.each(function(f,g){C(g)&&(c?g.style.setProperty(a,b):g.style[a]=b)})}for(var d in a)this.css(d,a[d]);return this};var Fa=/^\s+|\s+$/;function Ga(a,b){a=a.dataset[b]||a.dataset[K(b)];return Fa.test(a)?a:ba(JSON.parse,a)} +I.data=function(a,b){if(!a){if(!this[0])return;var c={},d;for(d in this[0].dataset)c[d]=Ga(this[0],d);return c}if(G(a))return 2>arguments.length?this[0]&&Ga(this[0],a):void 0===b?this:this.each(function(f,g){f=b;f=ba(JSON.stringify,f);g.dataset[K(a)]=f});for(d in a)this.data(d,a[d]);return this};function Ha(a,b){var c=a.documentElement;return Math.max(a.body["scroll"+b],c["scroll"+b],a.body["offset"+b],c["offset"+b],c["client"+b])} +function Ia(a,b){return V(a,"border"+(b?"Left":"Top")+"Width")+V(a,"padding"+(b?"Left":"Top"))+V(a,"padding"+(b?"Right":"Bottom"))+V(a,"border"+(b?"Right":"Bottom")+"Width")} +M([!0,!1],function(a,b){M(["Width","Height"],function(c,d){I[(b?"outer":"inner")+d]=function(f){if(this[0])return L(this[0])?b?this[0]["inner"+d]:this[0].document.documentElement["client"+d]:B(this[0])?Ha(this[0],d):this[0][(b?"offset":"client")+d]+(f&&b?V(this[0],"margin"+(c?"Top":"Left"))+V(this[0],"margin"+(c?"Bottom":"Right")):0)}})}); +M(["Width","Height"],function(a,b){var c=b.toLowerCase();I[c]=function(d){if(!this[0])return void 0===d?void 0:this;if(!arguments.length)return L(this[0])?this[0].document.documentElement["client"+b]:B(this[0])?Ha(this[0],b):this[0].getBoundingClientRect()[c]-Ia(this[0],!a);var f=parseInt(d,10);return this.each(function(g,h){C(h)&&(g=T(h,"boxSizing"),h.style[c]=Ea(c,f+("border-box"===g?Ia(h,!a):0)))})}});var Ja={}; +I.toggle=function(a){return this.each(function(b,c){if(C(c))if(void 0===a?"none"===T(c,"display"):a){if(c.style.display=c.___cd||"","none"===T(c,"display")){b=c.style;c=c.tagName;if(Ja[c])c=Ja[c];else{var d=p(c);e.body.insertBefore(d,null);var f=T(d,"display");e.body.removeChild(d);c=Ja[c]="none"!==f?f:"block"}b.display=c}}else c.___cd=T(c,"display"),c.style.display="none"})};I.hide=function(){return this.toggle(!1)};I.show=function(){return this.toggle(!0)}; +function Ka(a,b){return!b||!z.call(b,function(c){return 0>a.indexOf(c)})}var W={focus:"focusin",blur:"focusout"},X={mouseenter:"mouseover",mouseleave:"mouseout"},La=/^(mouse|pointer|contextmenu|drag|drop|click|dblclick)/i;function Ma(a,b,c,d,f){var g=a.___ce=a.___ce||{};g[b]=g[b]||[];g[b].push([c,d,f]);a.addEventListener(b,f)}function Na(a){a=a.split(".");return[a[0],a.slice(1).sort()]} +function Y(a,b,c,d,f){var g=a.___ce=a.___ce||{};if(b)g[b]&&(g[b]=g[b].filter(function(h){var m=h[0],l=h[1];h=h[2];if(f&&h.guid!==f.guid||!Ka(m,c)||d&&d!==l)return!0;a.removeEventListener(b,h)}));else for(b in g)Y(a,b,c,d,f)} +I.off=function(a,b,c){var d=this;if(void 0===a)this.each(function(g,h){(C(h)||B(h)||L(h))&&Y(h)});else if(G(a))H(b)&&(c=b,b=""),M(Q(a),function(g,h){g=Na(h);h=g[0];var m=g[1],l=X[h]||W[h]||h;d.each(function(u,w){(C(w)||B(w)||L(w))&&Y(w,l,m,b,c)})});else for(var f in a)this.off(f,a[f]);return this}; +I.on=function(a,b,c,d,f){var g=this;if(!G(a)){for(var h in a)this.on(h,b,c,a[h],f);return this}G(b)||(void 0!==b&&null!==b&&(void 0!==c&&(d=c),c=b),b="");H(d)||(d=c,c=void 0);if(!d)return this;M(Q(a),function(m,l){m=Na(l);l=m[0];var u=m[1],w=X[l]||W[l]||l,U=l in X,E=l in W;w&&g.each(function(t,n){if(C(n)||B(n)||L(n))t=function Ra(r){if(r.target["___i"+r.type])return r.stopImmediatePropagation();if(!r.namespace||Ka(u,r.namespace.split(".")))if(b||!(E&&(r.target!==n||r.___ot===w)||U&&r.relatedTarget&& +n.contains(r.relatedTarget))){var fa=n;if(b){for(var F=r.target;!ua(F,b);){if(F===n)return;F=F.parentNode;if(!F)return}fa=F}Object.defineProperty(r,"currentTarget",{configurable:!0,get:function(){return fa}});Object.defineProperty(r,"delegateTarget",{configurable:!0,get:function(){return n}});Object.defineProperty(r,"data",{configurable:!0,get:function(){return c}});F=d.call(fa,r,r.___td);f&&Y(n,w,u,b,Ra);!1===F&&(r.preventDefault(),r.stopPropagation())}},t.guid=d.guid=d.guid||J.guid++,Ma(n,w,u,b, +t)})});return this};I.one=function(a,b,c,d){return this.on(a,b,c,d,!0)};I.ready=function(a){function b(){return setTimeout(a,0,J)}"loading"!==e.readyState?b():e.addEventListener("DOMContentLoaded",b);return this}; +I.trigger=function(a,b){if(G(a)){var c=Na(a),d=c[0];c=c[1];var f=X[d]||W[d]||d;if(!f)return this;var g=La.test(f)?"MouseEvents":"HTMLEvents";a=e.createEvent(g);a.initEvent(f,!0,!0);a.namespace=c.join(".");a.___ot=d}a.___td=b;var h=a.___ot in W;return this.each(function(m,l){h&&H(l[a.___ot])&&(l["___i"+a.type]=!0,l[a.___ot](),l["___i"+a.type]=!1);l.dispatchEvent(a)})}; +function Oa(a){return a.multiple&&a.options?R(y.call(a.options,function(b){return b.selected&&!b.disabled&&!b.parentNode.disabled}),"value"):a.value||""}var Pa=/%20/g,Qa=/\r?\n/g,Sa=/file|reset|submit|button|image/i,Ta=/radio|checkbox/i; +I.serialize=function(){var a="";this.each(function(b,c){M(c.elements||[c],function(d,f){f.disabled||!f.name||"FIELDSET"===f.tagName||Sa.test(f.type)||Ta.test(f.type)&&!f.checked||(d=Oa(f),void 0!==d&&(d=v(d)?d:[d],M(d,function(g,h){g=a;h="&"+encodeURIComponent(f.name)+"="+encodeURIComponent(h.replace(Qa,"\r\n")).replace(Pa,"+");a=g+h})))})});return a.slice(1)}; +I.val=function(a){return arguments.length?this.each(function(b,c){if((b=c.multiple&&c.options)||Ta.test(c.type)){var d=v(a)?ka.call(a,String):null===a?[]:[String(a)];b?M(c.options,function(f,g){g.selected=0<=d.indexOf(g.value)},!0):c.checked=0<=d.indexOf(c.value)}else c.value=void 0===a||null===a?"":a}):this[0]&&Oa(this[0])};I.clone=function(){return this.map(function(a,b){return b.cloneNode(!0)})};I.detach=function(a){P(this,a).each(function(b,c){c.parentNode&&c.parentNode.removeChild(c)});return this}; +var Ua=/^\s*<(\w+)[^>]*>/,Va=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,Wa={"*":da,tr:ea,td:ha,th:ha,thead:q,tbody:q,tfoot:q};function sa(a){if(!G(a))return[];if(Va.test(a))return[p(RegExp.$1)];var b=Ua.test(a)&&RegExp.$1;b=Wa[b]||Wa["*"];b.innerHTML=a;return J(b.childNodes).detach().get()}J.parseHTML=sa;I.empty=function(){return this.each(function(a,b){for(;b.firstChild;)b.removeChild(b.firstChild)})}; +I.html=function(a){return arguments.length?void 0===a?this:this.each(function(b,c){C(c)&&(c.innerHTML=a)}):this[0]&&this[0].innerHTML};I.remove=function(a){P(this,a).detach().off();return this};I.text=function(a){return void 0===a?this[0]?this[0].textContent:"":this.each(function(b,c){C(c)&&(c.textContent=a)})};I.unwrap=function(){this.parent().each(function(a,b){"BODY"!==b.tagName&&(a=J(b),a.replaceWith(a.children()))});return this}; +I.offset=function(){var a=this[0];if(a)return a=a.getBoundingClientRect(),{top:a.top+k.pageYOffset,left:a.left+k.pageXOffset}};I.offsetParent=function(){return this.map(function(a,b){for(a=b.offsetParent;a&&"static"===T(a,"position");)a=a.offsetParent;return a||ca})}; +I.position=function(){var a=this[0];if(a){var b="fixed"===T(a,"position"),c=b?a.getBoundingClientRect():this.offset();if(!b){var d=a.ownerDocument;for(b=a.offsetParent||d.documentElement;(b===d.body||b===d.documentElement)&&"static"===T(b,"position");)b=b.parentNode;b!==a&&C(b)&&(d=J(b).offset(),c.top-=d.top+V(b,"borderTopWidth"),c.left-=d.left+V(b,"borderLeftWidth"))}return{top:c.top-V(a,"marginTop"),left:c.left-V(a,"marginLeft")}}}; +I.children=function(a){return P(J(S(R(this,function(b){return b.children}))),a)};I.contents=function(){return J(S(R(this,function(a){return"IFRAME"===a.tagName?[a.contentDocument]:"TEMPLATE"===a.tagName?a.content.childNodes:a.childNodes})))};I.find=function(a){return J(S(R(this,function(b){return A(a,b)})))};var Xa=/^\s*\s*$/g,Ya=/^$|^module$|\/(java|ecma)script/i,Za=["type","src","nonce","noModule"]; +function $a(a,b){a=J(a);a.filter("script").add(a.find("script")).each(function(c,d){if(Ya.test(d.type)&&ca.contains(d)){var f=p("script");f.text=d.textContent.replace(Xa,"");M(Za,function(g,h){d[h]&&(f[h]=d[h])});b.head.insertBefore(f,null);b.head.removeChild(f)}})} +function Z(a,b,c,d,f,g,h,m){M(a,function(l,u){M(J(u),function(w,U){M(J(b),function(E,t){var n=c?t:U;E=c?w:E;t=c?U:t;n=E?n.cloneNode(!0):n;E=!E;f?t.insertBefore(n,d?t.firstChild:null):"HTML"===t.nodeName?t.parentNode.replaceChild(n,t):t.parentNode.insertBefore(n,d?t:t.nextSibling);E&&$a(n,t.ownerDocument)},m)},h)},g);return b}I.after=function(){return Z(arguments,this,!1,!1,!1,!0,!0)};I.append=function(){return Z(arguments,this,!1,!1,!0)};I.appendTo=function(a){return Z(arguments,this,!0,!1,!0)}; +I.before=function(){return Z(arguments,this,!1,!0)};I.insertAfter=function(a){return Z(arguments,this,!0,!1,!1,!1,!1,!0)};I.insertBefore=function(a){return Z(arguments,this,!0,!0)};I.prepend=function(){return Z(arguments,this,!1,!0,!0,!0,!0)};I.prependTo=function(a){return Z(arguments,this,!0,!0,!0,!1,!1,!0)};I.replaceWith=function(a){return this.before(a).remove()};I.replaceAll=function(a){J(a).replaceWith(this);return this}; +I.wrapAll=function(a){a=J(a);for(var b=a[0];b.children.length;)b=b.firstElementChild;this.first().before(a);return this.appendTo(b)};I.wrap=function(a){return this.each(function(b,c){var d=J(a)[0];J(c).wrapAll(b?d.cloneNode(!0):d)})};I.wrapInner=function(a){return this.each(function(b,c){b=J(c);c=b.contents();c.length?c.wrapAll(a):b.append(a)})};I.has=function(a){var b=G(a)?function(c,d){return A(a,d).length}:function(c,d){return d.contains(a)};return this.filter(b)}; +I.is=function(a){var b=O(a);return z.call(this,function(c,d){return b.call(c,d,c)})};I.next=function(a,b,c){return P(J(S(R(this,"nextElementSibling",b,c))),a)};I.nextAll=function(a){return this.next(a,!0)};I.nextUntil=function(a,b){return this.next(b,!0,a)};I.not=function(a){var b=O(a);return this.filter(function(c,d){return(!G(a)||C(d))&&!b.call(d,c,d)})};I.parent=function(a){return P(J(S(R(this,"parentNode"))),a)}; +I.index=function(a){var b=a?J(a)[0]:this[0];a=a?this:J(b).parent().children();return ja.call(a,b)};I.closest=function(a){var b=this.filter(a);if(b.length)return b;var c=this.parent();return c.length?c.closest(a):b};I.parents=function(a,b){return P(J(S(R(this,"parentElement",!0,b))),a)};I.parentsUntil=function(a,b){return this.parents(b,a)};I.prev=function(a,b,c){return P(J(S(R(this,"previousElementSibling",b,c))),a)};I.prevAll=function(a){return this.prev(a,!0)}; +I.prevUntil=function(a,b){return this.prev(b,!0,a)};I.siblings=function(a){return P(J(S(R(this,function(b){return J(b).parent().children().not(b)}))),a)};"undefined"!==typeof exports?module.exports=J:k.cash=k.$=J; +})(); \ No newline at end of file diff --git a/deploy/build_js.sh b/deploy/build_js.sh index 170d635..992e5a9 100755 --- a/deploy/build_js.sh +++ b/deploy/build_js.sh @@ -13,6 +13,8 @@ java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT5_STRICT --js java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT5_STRICT --js $ROOT/src_js/third_party/selectize.js >> $JSTARGET java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT5_STRICT --js $ROOT/src_js/third_party/selectize_preserve_on_blur.js >> $JSTARGET java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT_NEXT --js $ROOT/src_js/third_party/optimade_mpds_nlp.js >> $JSTARGET +java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT_NEXT --js $ROOT/src_js/wmgui$.js >> $JSTARGET +java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT_NEXT --js $ROOT/src_js/clean.js >> $JSTARGET java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT5_STRICT --js $ROOT/src_js/wmsettings.js >> $JSTARGET java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT_NEXT --js $ROOT/src_js/wmcore.js >> $JSTARGET java -jar $JSCOMP --jscomp_off checkTypes --language_in ECMASCRIPT5_STRICT --js $ROOT/src_js/sliders.js >> $JSTARGET diff --git a/example_dev.html b/example_dev.html index 5a6615e..caaf794 100755 --- a/example_dev.html +++ b/example_dev.html @@ -1,41 +1,51 @@ - - - - - - - + -var head = document.getElementsByTagName('head')[0]; -for (var i = 0; i < to_load.length; i++){ - var script = document.createElement('script'); - script.type = 'text/javascript'; - script.src = to_load[i]; - script.async = false; - head.appendChild(script); -} - - - + + + + + + \ No newline at end of file diff --git a/src_js/$.js b/src_js/$.js new file mode 100644 index 0000000..8179205 --- /dev/null +++ b/src_js/$.js @@ -0,0 +1,210 @@ +(function () { + $l = window.$l = function (object) { + if (typeof object === 'function') { + var functionsToInvokes = functionsToInvokes || []; + functionsToInvokes.push(object); + document.addEventListener('DOMContentLoaded', function () { + for (var i = 0; i < functionsToInvokes.length; i++) { + functionsToInvokes[i](); + } + }); + return; + } + + if (object instanceof HTMLElement) { + return new DOMNodeCollection([object]); // DOMNodeCollection + } + + var selector = object; // a string that represents a selector + + var HTMLElements = document.querySelectorAll(selector); // grab all HTMLElements on the page + HTMLElements = nodeCollectionToArray(HTMLElements); // convert from a NodeList to an Array + return new DOMNodeCollection(HTMLElements); // pass into constructor and return a DOMNodeCollection object; + }; + + $l.ajax = function (options) { // options is an object + var defaultFn = function () { }; + + var masterOptions = { + success: defaultFn, + error: defaultFn, + url: '', + method: 'GET', + data: null, + contentType: 'application/x-www-form-urlencoded; charset=UTF-8' + }; + + $l.extend(masterOptions, options); + + var success = masterOptions.success; + var error = masterOptions.error; + var url = masterOptions.url; + var method = masterOptions.method; + var data = masterOptions.data; + var contentType = masterOptions.contentType; + + var oReq = new XMLHttpRequest(); + oReq.addEventListener('load', success); + oReq.addEventListener('error', error); + oReq.open(method, url); + if (data === null) { + oReq.send(); + } else { + oReq.send(data); + } + + }; + + // helper function for use within $l.ajax() + $l.extend = function () { + if (arguments.length === 0) { + return new Error('No arguments passed'); + } + var master = arguments[0]; + for (var i = 1; i < arguments.length; i++) { + var object = arguments[i]; + for (prop in object) { + master[prop] = object[prop]; + } + } + }; + + function nodeCollectionToArray(nodeCollection) { + var convertedArr = []; + + for (var i = 0; i < nodeCollection.length; i++) { + var node = nodeCollection[i]; + convertedArr.push(node); + } + return convertedArr; + } + + DOMNodeCollection = window.DOMNodeCollection = function (HTMLElements) { + this.HTMLElements = nodeCollectionToArray(HTMLElements); + }; + + DOMNodeCollection.prototype.addClass = function (className) { + for (var i = 0; i < this.HTMLElements.length; i++) { + this.HTMLElements[i].classList.add(className); + } + }; + + DOMNodeCollection.prototype.append = function (object) { + // object is a DOMNodeCollection, HTMLElement, or string + if (object instanceof DOMNodeCollection) { + if (object.HTMLElements.length > 1) { + try { + throw new Error('DOMNodeCollection is greater than one'); + } catch (e) { + console.log(e.message); + return; + } + } + } + + if (object instanceof HTMLElement) { + this.HTMLElements.forEach(function (HTMLElement, idx, array) { + HTMLElement.appendChild(object); + }); + return; + } + + this.HTMLElements.forEach(function (HTMLElement, idx, array) { + HTMLElement.innerHTML = object; + }); + }; + + DOMNodeCollection.prototype.attr = function (attrName, value) { + var HTMLElement = this.HTMLElements[0]; + if (value === undefined) { + // gets the value of a given attribute for the first node within the DOMNodeCollection + return HTMLElement.getAttribute(attrName); + } else { + // sets the value of a given attribute for the first node within the DOMNodeCollection + return HTMLElement.setAttribute(attrName, value); + } + }; + + // returns DOMNodeCollection of all children of all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.children = function () { + var children = []; + for (var i = 0; i < this.HTMLElements.length; i++) { + children.push(this.HTMLElements[i].children); + } + return new DOMNodeCollection(children); + }; + + // returns a DOMNodeCollection of all nodes that match the selector + DOMNodeCollection.prototype.find = function (selector) { + var foundElements = []; + for (var i = 0; i < this.HTMLElements.length; i++) { + var HTMLElement = this.HTMLElements[i]; + var HTMLElements = HTMLElement.querySelectorAll(selector); + + // move HTMLElements from NodeList to an array. + for (var j = 0; j < HTMLElements.length; j++) { + foundElements.push(HTMLElements[i]); + } + } + + return new DOMNodeCollection(foundElements); + }; + + // clears all HTML from all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.empty = function () { + this.HTMLElements.forEach(function (HTMLElement, idx, array) { + HTMLElement.innerHTML = ''; + }); + }; + + // replaces the HTML property of all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.html = function (str) { + if (str === undefined) { + return this.HTMLElements[0].innerHTML; + } + + this.HTMLElements.forEach(function (HTMLElement, idx, array) { + HTMLElement.innerHTML = str; + }); + }; + + // removes the eventListener from all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.off = function (eventType, callback) { + for (var i = 0; i < this.HTMLElements.length; i++) { + this.HTMLElements[i].removeEventListener(eventType, callback); + } + }; + + // adds an eventListener to all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.on = function (eventType, callback) { + for (var i = 0; i < this.HTMLElements.length; i++) { + this.HTMLElements[i].addEventListener(eventType, callback); + } + }; + + // returns collection of all parents of all nodes within the DOMNodeCollection + DOMNodeCollection.prototype.parent = function () { + var parents = []; + for (var i = 0; i < this.HTMLElements.length; i++) { + var HTMLElement = this.HTMLElements[i]; + parents.push(HTMLElement.parentElement); + } + + return new DOMNodeCollection(parents); + }; + + // removes all nodes within the DOMNodeCollection from the DOM + DOMNodeCollection.prototype.remove = function () { + for (var i = 0; i < this.HTMLElements.length; i++) { + var HTMLElement = this.HTMLElements[i]; + HTMLElement.parentNode.removeChild(HTMLElement); + } + }; + + // removes a class from all of the nodes within the DOMNodeCollection + DOMNodeCollection.prototype.removeClass = function (className) { + for (var i = 0; i < this.HTMLElements.length; i++) { + this.HTMLElements[i].classList.remove(className); + } + }; +})(); \ No newline at end of file diff --git a/src_js/clean.js b/src_js/clean.js new file mode 100644 index 0000000..5e95259 --- /dev/null +++ b/src_js/clean.js @@ -0,0 +1,85 @@ +/*! + * Sanitize an HTML string + * (c) 2021 Chris Ferdinandi, MIT License, https://gomakethings.com + * @param {String} str The HTML string to sanitize + * @param {Boolean} nodes If true, returns HTML nodes instead of a string + * @return {String|NodeList} The sanitized string or nodes + */ +wmgui.clean = function (string, nodes) { + + /** + * Convert the string to an HTML document + * @return {Node} An HTML document + */ + function stringToHTML() { + let parser = new DOMParser(); + let doc = parser.parseFromString(string, 'text/html'); + return doc.body || document.createElement('body'); + } + + /** + * Remove