-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.buildr.min.js
1 lines (1 loc) · 4.02 KB
/
jquery.buildr.min.js
1
(function(a,b){function p(a){this.name="NestingProhibitedError";this.tag=a}function o(a){this.name="UnknownArgumentError";this.arg=a}var c=b.Buildr=function(){this.stack=[];this.elements=[];this.tags=c.prototype.tags.concat()};var d=function(a){if(Object.prototype.toString.call(a)!=="[object Object]")return false;var b;for(b in a){}return!b||Object.prototype.hasOwnProperty.call(a,b)};var e=function(a){return toString.call(a)=="[object String]"};var f={};var g=["append","prepend"];a.each(g,function(b,c){f[c]=a.fn[c];a.fn[c]=function(){var b=a.makeArray(arguments);var d=j.apply(this,b);return f[c].apply(this,d)}});var h=true;var i=function(){a.each(g,function(b,c){a.fn[c]=f[c]});h=false};var j=function(){var b=a.makeArray(arguments);return a.map(b,function(a){return a instanceof c?a.root():a})};var k=function(b){var c=a.map(b,function(a){return a});var d=a.map(c,function(b){return b instanceof a?b.get():b});return d};var l=function(b){var c=k(b);return c&&c.length>0?a(c):null};var m=function(a){this.elements.splice(0,this.elements.length);return a?l(a.call(this,this)||this.root()):this};a.extend(c.prototype,{buildr:m,build:m,tags:[],defineTag:function(){var b=a.makeArray(arguments),c=this;a.each(b,function(b,d){c.tags.push(d);d=d.replace("/","");c[d]=function(){var b=a.makeArray(arguments);b.unshift(d);return this.tag.apply(this,b)}});return this},isSelfClosing:function(a){return this.tags.indexOf(a+"/")>-1},tag:function(){var b=a.makeArray(arguments),c=this,d=b.shift(),e=function(){return c},f=this.$=a.extend(a("<"+d+">"),{buildr:e,build:e}),g=this.stack[0];if(h)a.extend(f,n);this.isSelfClosing(d)&&delete f.nest&&delete f.contain;g&&g.append(f);this.elements.push(f);n.nest.apply(f,b);return f},root:function(){return a.grep(this.elements,function(a){return a.parent().length===0})},each:function(b,c){a.each(b,c.bind(this));return this},extend:function(){var b=a.makeArray(arguments),c=this;a.each(b,function(b,d){a.each(d,function(a,b){c[a]=b.bind(c)})});return c}});c.prototype.defineTag("a","abbr","acronym","address","article","aside","audio","b","bdi","bdo","big","blockquote","body","button","caption","canvas","command","cite","code","colgroup","datalist","dd","del","details","dfn","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","frameset","h1","h2","h3","h4","h5","h6","head","header","hgroup","html","i","iframe","ins","keygen","kbd","label","legend","li","map","mark","meter","nav","noframes","noscript","object","ol","optgroup","option","output","p","pre","progress","q","rp","rt","ruby","samp","section","script","select","small","source","span","strong","style","sub","summary","sup","table","tbody","td","textarea","tfoot","thead","time","title","tr","track","tt","ul","var","video","wbr","area/","base/","br/","col/","frame/","hr/","img/","input/","link/","meta/","param/");var n={id:function(a){this.attr({id:a});return this},"class":function(a){this.removeClass();this.addClass(a);return this},nest:function(){var b=this,c=this.buildr(),f=a.makeArray(arguments);var g=function(h){if(h instanceof a){var i=b.get(0).tagName.toLowerCase();if(c.isSelfClosing(i))throw new p(i);b.append(h)}else if(a.isArray(h)&&a.isFunction(f[0])){items=h,iterator=f.shift();n.nest.call(b,function(){c.each(items,iterator)})}else if(a.isFunction(h)){var j=h.call(c,c);j&&g(j)}else if(e(h)){b.text(h)}else if(d(h)){b.attr(h)}else{throw new o(h)}};c.stack.unshift(b);while(f.length>0)g(f.shift());c.stack.shift();return this}};n.contain=n.nest;o.prototype=Error.prototype;p.prototype=Error.prototype;a.extend(c,{untouch:i,UnknownArgumentError:o,NestingProhibitedError:p});a.buildr=function(){var b=new c;var f=a.makeArray(arguments);var g=[];while(f.length>0){var h=f.shift();if(d(h))b.extend(h);else if(e(h))b.defineTag(h);else if(a.isFunction(h))g.push(b.buildr(h))}return l(g)||b};a.buildr.defineTag=c.prototype.defineTag.bind(c.prototype);a.buildr.tags=c.prototype.tags;a.fn.buildr=function(){var b=a.makeArray(arguments);var c=a.buildr.apply(a.buildr,b);return this.append(c)};a.build||(a.build=a.buildr);a.fn.build||(a.fn.build=a.fn.buildr)})(jQuery,this)