forked from adriancooney/voyeur.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Voyeur.min.js
1 lines (1 loc) · 3.02 KB
/
Voyeur.min.js
1
/* Voyeur v0.4.0 (c) 2013 Adrian Cooney http://dunxrion.github.io/voyeur.js/ */!function(){"use strict";var a=function(b){return b instanceof HTMLElement&&a.extendChildren(b),b.create=a.extendTags({},function(c){return a.create.bind({tag:c,parents:b})()}),b.use=function(c){return c&&(b instanceof Array?b.forEach(function(b,d){b=a(b),c.call(b,b,d)}):c.call(b,b)),b.root},b.find=function(c){var d;return b instanceof Array?(d=[],b.forEach(function(a){d=d.concat(Array.prototype.slice.call(a.querySelectorAll(c)))})):d=Array.prototype.slice.call(b.querySelectorAll(c)),d.length?a(1===d.length?d[0]:d):void 0},b.eq=function(c,d){if(b instanceof Array){var e=b.slice(c,d||c+1);return a(1===e.length?e[0]:e)}return b},b};a.extendChildren=function(b,c){c=Array.prototype.slice.call(c||b.children);for(var d={},e=0,f=c.length;f>e;e++){var g=c[e],h=g.tagName.toLowerCase();d[h]||(d[h]=[]),d[h].push(g)}for(var i in d)!function(c){Object.defineProperty(b,c,{get:function(){return a(1===d[c].length?d[c][0]:d[c])},configurable:!0})}(i)},a.create=function(b){var c=b||a.createElement(this.parents,this.tag);return c.root=this.root||c,c.parents=this.parents,a.extendTags(c,function(b){return a.unextendTags(c),a.create.bind({root:c.root,parents:c,tag:b})()}),c.use=function(b){if(b)if(c instanceof Array)c.forEach(function(c,d){c=a(c),b.call(c,c,d)});else{var d=a(c);b.call(d,d)}return a.unextendTags(c.root),a(c.root)},c.mult=function(b){c.parentNode.removeChild(c);for(var d=[],e=0;b>e;e++){var f=a.createElement(c.parents,c.tagName.toLowerCase());d.push(f)}return a.create.bind({root:c.root})(d)},c.special=function(b){return a.create.bind({root:c.root,parents:c,tag:b})()},c},a.createElement=function(a,b){function c(){return document.createElement(b)}if(a){if(a instanceof Array){var d=[];return a.forEach(function(a){var b=c();a.appendChild(b),d.push(b)}),d}var e=c();return a.appendChild(e),e}return c()},a.nodes="a,abbr,acronym,address,applet,area,article,aside,audio,b,base,basefont,bdi,bdo,bgsound,big,blink,blockquote,br,button,canvas,caption,center,cite,code,col,colgroup,data,datalist,dd,del,details,dfn,dir,div,dl,dt,em,embed,fieldset,figcaption,figure,font,footer,form,frame,frameset,h1,h2,h3,h4,h5,h6,header,hgroup,hr,i,iframe,img,input,ins,isindex,kbd,keygen,label,legend,li,link,listing,main,map,mark,marquee,menu,menuitem,meta,meter,nav,nobr,noframes,noscript,object,ol,optgroup,option,output,p,param,plaintext,pre,progress,q,rp,rt,ruby,s,samp,section,select,small,source,spacer,span,strike,strong,sub,summary,sup,table,tbody,td,textarea,tfoot,th,thead,time,tr,track,tt,u,ul,var,video,wbr,xmp".split(","),a.extendTags=function(b,c){return a.nodes.forEach(function(a){Object.defineProperty(b,a,{get:function(){return c.call(b,a)},configurable:!0})}),b},a.unextendTags=function(b){return a.nodes.forEach(function(a){delete b[a]}),b},document.addEventListener("DOMContentLoaded",function(){window.Voyeur=a(document.body),window.Voyeur.create=a.extendTags({},function(b){return a.create.bind({tag:b})()}),window.Voyeur.create.special=function(b){return a.create.bind({tag:b})()}})}();