Skip to content

Instantly share code, notes, and snippets.

@zulfajuniadi
Created August 23, 2013 16:18
Show Gist options
  • Save zulfajuniadi/6321180 to your computer and use it in GitHub Desktop.
Save zulfajuniadi/6321180 to your computer and use it in GitHub Desktop.
!function(a,b,c,d){function e(d){if(!c[d]){if(!b[d]){if(a)return a(d);throw new Error("Cannot find module '"+d+"'")}var f=c[d]={exports:{}};b[d][0](function(a){var c=b[d][1][a];return e(c?c:a)},f,f.exports)}return c[d].exports}for(var f=0;f<d.length;f++)e(d[f]);return e}("undefined"!=typeof require&&require,{1:[function(a,b){var d,e,f,g,h,i=[].indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(b in this&&this[b]===a)return b;return-1};h=a("../lib/lodash.js"),g=a("./helpers"),e=a("./context"),f={},f.render=function(a,b,c,d){var i,j;return null==b&&(b=[]),null==c&&(c={}),null==d&&(d={}),i=d.debug&&console?g.consoleLogger:g.nullLogger,i("Transparency.render:",a,b,c,d),a?(h.isArray(b)||(b=[b]),a=(j=g.data(a)).context||(j.context=new e(a,f)),a.render(b,c,d).el):void 0},f.matcher=function(a,b){return a.el.id===b||i.call(a.classNames,b)>=0||a.el.name===b||a.el.getAttribute("data-bind")===b},f.clone=function(a){return d(a).clone()[0]},f.jQueryPlugin=g.chainable(function(a,b,c){var d,e,g,h;for(h=[],e=0,g=this.length;g>e;e++)d=this[e],h.push(f.render(d,a,b,c));return h}),("undefined"!=typeof jQuery&&null!==jQuery||"undefined"!=typeof Zepto&&null!==Zepto)&&(d="undefined"!=typeof jQuery?jQuery:Zepto,null!=d&&(d.fn.render=f.jQueryPlugin)),("undefined"!=typeof b&&null!==b?b.exports:void 0)&&(b.exports=f),"undefined"!=typeof window&&null!==window&&(window.Transparency=f),("undefined"!=typeof define&&null!==define?define.amd:void 0)&&define(function(){return f})},{"../lib/lodash.js":2,"./helpers":3,"./context":4}],2:[function(a,b,c){var d={};d.toString=Object.prototype.toString,d.toArray=function(a){for(var b=new Array(a.length),c=0;c<a.length;c++)b[c]=a[c];return b},d.isString=function(a){return"[object String]"==d.toString.call(a)},d.isNumber=function(a){return"[object Number]"==d.toString.call(a)},d.isArray=Array.isArray||function(a){return"[object Array]"===d.toString.call(a)},d.isDate=function(a){return"[object Date]"===d.toString.call(a)},d.isElement=function(a){return!(!a||1!==a.nodeType)},d.isPlainValue=function(a){var b;return b=typeof a,"object"!==b&&"function"!==b||c.isDate(a)},d.isBoolean=function(a){return a===!0||a===!1},b.exports=d},{}],3:[function(a,b,c){var d,e,f,g;d=a("./elementFactory"),c.before=function(a){return function(b){return function(){return a.apply(this,arguments),b.apply(this,arguments)}}},c.after=function(a){return function(b){return function(){return b.apply(this,arguments),a.apply(this,arguments)}}},c.chainable=c.after(function(){return this}),c.onlyWith$=function(a){return"undefined"!=typeof jQuery&&null!==jQuery||"undefined"!=typeof Zepto&&null!==Zepto?function(){return a(arguments)}(jQuery||Zepto):void 0},c.getElements=function(a){var b;return b=[],g(a,b),b},g=function(a,b){var e,f;for(e=a.firstChild,f=[];e;)e.nodeType===c.ELEMENT_NODE&&(b.push(new d.createElement(e)),g(e,b)),f.push(e=e.nextSibling);return f},c.ELEMENT_NODE=1,c.TEXT_NODE=3,f=function(){return"<:nav></:nav>"!==document.createElement("nav").cloneNode(!0).outerHTML},c.cloneNode="undefined"==typeof document||null===document||f()?function(a){return a.cloneNode(!0)}:function(a){var b,d,f,g,h;if(b=Transparency.clone(a),b.nodeType===c.ELEMENT_NODE)for(b.removeAttribute(e),h=b.getElementsByTagName("*"),f=0,g=h.length;g>f;f++)d=h[f],d.removeAttribute(e);return b},e="transparency",c.data=function(a){return a[e]||(a[e]={})},c.nullLogger=function(){},c.consoleLogger=function(){return console.log(arguments)},c.log=c.nullLogger},{"./elementFactory":5}],4:[function(a,b){var d,e,f,g,h,i,j;j=a("./helpers"),g=j.before,f=j.after,h=j.chainable,i=j.cloneNode,e=a("./instance"),b.exports=d=function(){function c(a,b){this.el=a,this.Transparency=b,this.template=i(this.el),this.instances=[new e(this.el,this.Transparency)],this.instanceCache=[]}var a,b;return b=h(function(){return this.parent=this.el.parentNode,this.parent?(this.nextSibling=this.el.nextSibling,this.parent.removeChild(this.el)):void 0}),a=h(function(){return this.parent?this.nextSibling?this.parent.insertBefore(this.el,this.nextSibling):this.parent.appendChild(this.el):void 0}),c.prototype.render=g(b)(f(a)(h(function(a,b,c){for(var d,f,g,h,j,k,l;a.length<this.instances.length;)this.instanceCache.push(this.instances.pop().remove());for(;a.length>this.instances.length;)g=this.instanceCache.pop()||new e(i(this.template),this.Transparency),this.instances.push(g.appendTo(this.el));for(l=[],f=j=0,k=a.length;k>j;f=++j)h=a[f],g=this.instances[f],d=[],l.push(g.prepare(h,d).renderValues(h,d).renderDirectives(h,f,b).renderChildren(h,d,b,c));return l}))),c}()},{"./helpers":3,"./instance":6}],5:[function(a,b){var d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t={}.hasOwnProperty,u=function(a,b){function d(){this.constructor=a}for(var c in b)t.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};n=a("../lib/lodash.js"),m=a("./helpers"),d=a("./attributeFactory"),b.exports=g={Elements:{input:{}},createElement:function(a){var b,c;return b="input"===(c=a.nodeName.toLowerCase())?g.Elements[c][a.type.toLowerCase()]||h:g.Elements[c]||f,new b(a)}},f=function(){function a(a){this.el=a,this.attributes={},this.childNodes=n.toArray(this.el.childNodes),this.nodeName=this.el.nodeName.toLowerCase(),this.classNames=this.el.className.split(" "),this.originalAttributes={}}return a.prototype.empty=function(){for(var a;a=this.el.firstChild;)this.el.removeChild(a);return this},a.prototype.reset=function(){var a,b,c,d;c=this.attributes,d=[];for(b in c)a=c[b],d.push(a.set(a.templateValue));return d},a.prototype.render=function(a){return this.attr("text",a)},a.prototype.attr=function(a,b){var c,e;return c=(e=this.attributes)[a]||(e[a]=d.createAttribute(this.el,a,b)),null!=b&&c.set(b),c},a.prototype.renderDirectives=function(a,b,c){var d,e,f,g;g=[];for(e in c)t.call(c,e)&&(d=c[e],"function"==typeof d&&(f=d.call(a,{element:this.el,index:b,value:this.attr(e).templateValue}),null!=f?g.push(this.attr(e,f)):g.push(void 0)));return g},a}(),j=function(a){function b(a){b.__super__.constructor.call(this,a),this.elements=m.getElements(a)}return u(b,a),g.Elements.select=b,b.prototype.render=function(a){var b,c,d,e,f;for(a=a.toString(),e=this.elements,f=[],c=0,d=e.length;d>c;c++)b=e[c],"option"===b.nodeName&&f.push(b.attr("selected",b.el.value===a));return f},b}(f),l=function(a){function f(){return o=f.__super__.constructor.apply(this,arguments)}var b,c,d,e;for(u(f,a),b=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],d=0,e=b.length;e>d;d++)c=b[d],g.Elements[c]=f;return f.prototype.attr=function(a,b){return"text"!==a&&"html"!==a?f.__super__.attr.call(this,a,b):void 0},f}(f),h=function(a){function b(){return p=b.__super__.constructor.apply(this,arguments)}return u(b,a),b.prototype.render=function(a){return this.attr("value",a)},b}(l),k=function(a){function b(){return q=b.__super__.constructor.apply(this,arguments)}return u(b,a),g.Elements.textarea=b,b}(h),e=function(a){function b(){return r=b.__super__.constructor.apply(this,arguments)}return u(b,a),g.Elements.input.checkbox=b,b.prototype.render=function(a){return this.attr("checked",Boolean(a))},b}(h),i=function(a){function b(){return s=b.__super__.constructor.apply(this,arguments)}return u(b,a),g.Elements.input.radio=b,b}(e)},{"../lib/lodash.js":2,"./helpers":3,"./attributeFactory":7}],6:[function(a,b){var d,e,f,g,h={}.hasOwnProperty;g=a("../lib/lodash.js"),e=(f=a("./helpers")).chainable,b.exports=d=function(){function a(a,b){this.Transparency=b,this.queryCache={},this.childNodes=g.toArray(a.childNodes),this.elements=f.getElements(a)}return a.prototype.remove=e(function(){var a,b,c,d,e;for(d=this.childNodes,e=[],b=0,c=d.length;c>b;b++)a=d[b],e.push(a.parentNode.removeChild(a));return e}),a.prototype.appendTo=e(function(a){var b,c,d,e,f;for(e=this.childNodes,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(a.appendChild(b));return f}),a.prototype.prepare=e(function(a){var b,c,d,e,g;for(e=this.elements,g=[],c=0,d=e.length;d>c;c++)b=e[c],b.reset(),g.push(f.data(b.el).model=a);return g}),a.prototype.renderValues=e(function(a,b){var c,d,e,f;if(g.isElement(a)&&(c=this.elements[0]))return c.empty().el.appendChild(a);if("object"==typeof a){f=[];for(d in a)h.call(a,d)&&(e=a[d],null!=e&&(g.isString(e)||g.isNumber(e)||g.isBoolean(e)||g.isDate(e)?f.push(function(){var a,b,f,g;for(f=this.matchingElements(d),g=[],a=0,b=f.length;b>a;a++)c=f[a],g.push(c.render(e));return g}.call(this)):"object"==typeof e?f.push(b.push(d)):f.push(void 0)));return f}}),a.prototype.renderDirectives=e(function(a,b,c){var d,e,f,g;g=[];for(f in c)h.call(c,f)&&(d=c[f],"object"==typeof d&&("object"!=typeof a&&(a={value:a}),g.push(function(){var c,g,h,i;for(h=this.matchingElements(f),i=[],c=0,g=h.length;g>c;c++)e=h[c],i.push(e.renderDirectives(a,b,d));return i}.call(this))));return g}),a.prototype.renderChildren=e(function(a,b,c,d){var e,f,g,h,i;for(i=[],g=0,h=b.length;h>g;g++)f=b[g],i.push(function(){var b,g,h,i;for(h=this.matchingElements(f),i=[],b=0,g=h.length;g>b;b++)e=h[b],i.push(this.Transparency.render(e.el,a[f],c[f],d));return i}.call(this));return i}),a.prototype.matchingElements=function(a){var b,c,d;return c=(d=this.queryCache)[a]||(d[a]=function(){var c,d,e,f;for(e=this.elements,f=[],c=0,d=e.length;d>c;c++)b=e[c],this.Transparency.matcher(b,a)&&f.push(b);return f}.call(this)),f.log("Matching elements for '"+a+"':",c),c},a}()},{"../lib/lodash.js":2,"./helpers":3}],7:[function(a,b){var d,e,f,g,h,i,j,k,l={}.hasOwnProperty,m=function(a,b){function d(){this.constructor=a}for(var c in b)l.call(b,c)&&(a[c]=b[c]);return d.prototype=b.prototype,a.prototype=new d,a.__super__=b.prototype,a};k=a("../lib/lodash"),j=a("./helpers"),b.exports=e={Attributes:{},createAttribute:function(a,b){var c;return c=e.Attributes[b]||d,new c(a,b)}},d=function(){function a(a,b){this.el=a,this.name=b,this.templateValue=this.el.getAttribute(this.name)||""}return a.prototype.set=function(a){return this.el[this.name]=a,this.el.setAttribute(this.name,a.toString())},a}(),f=function(a){function g(a,b){this.el=a,this.name=b,this.templateValue=this.el.getAttribute(this.name)||!1}var b,c,d,f;for(m(g,a),b=["hidden","async","defer","autofocus","formnovalidate","disabled","autofocus","formnovalidate","multiple","readonly","required","checked","scoped","reversed","selected","loop","muted","autoplay","controls","seamless","default","ismap","novalidate","open","typemustmatch","truespeed"],d=0,f=b.length;f>d;d++)c=b[d],e.Attributes[c]=g;return g.prototype.set=function(a){return this.el[this.name]=a,a?this.el.setAttribute(this.name,this.name):this.el.removeAttribute(this.name)},g}(d),i=function(a){function b(a,b){var c;this.el=a,this.name=b,this.templateValue=function(){var a,b,d,e;for(d=this.el.childNodes,e=[],a=0,b=d.length;b>a;a++)c=d[a],c.nodeType===j.TEXT_NODE&&e.push(c.nodeValue);return e}.call(this).join(""),this.children=k.toArray(this.el.children),(this.textNode=this.el.firstChild)?this.textNode.nodeType!==j.TEXT_NODE&&(this.textNode=this.el.insertBefore(this.el.ownerDocument.createTextNode(""),this.textNode)):this.el.appendChild(this.textNode=this.el.ownerDocument.createTextNode(""))}return m(b,a),e.Attributes.text=b,b.prototype.set=function(a){for(var b,c,d,e,f;b=this.el.firstChild;)this.el.removeChild(b);for(this.textNode.nodeValue=a,this.el.appendChild(this.textNode),e=this.children,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(this.el.appendChild(b));return f},b}(d),h=function(a){function b(a){this.el=a,this.templateValue="",this.children=k.toArray(this.el.children)}return m(b,a),e.Attributes.html=b,b.prototype.set=function(a){for(var b,c,d,e,f;b=this.el.firstChild;)this.el.removeChild(b);for(this.el.innerHTML=a+this.templateValue,e=this.children,f=[],c=0,d=e.length;d>c;c++)b=e[c],f.push(this.el.appendChild(b));return f},b}(d),g=function(a){function b(a){b.__super__.constructor.call(this,a,"class")}return m(b,a),e.Attributes["class"]=b,b}(d)},{"../lib/lodash":2,"./helpers":3}]},{},[1]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment