-
Notifications
You must be signed in to change notification settings - Fork 6
/
domplate-min.js
1 lines (1 loc) · 11 KB
/
domplate-min.js
1
void function(t,e,n,i,r,o,s,a,u,l,c,h,d,p,f,m,v){"use strict";function _(t){return i(t.querySelectorAll(".domplate-hide"),function(t){t.parentNode.removeChild(t)}),t}function y(t){var e=p("{{{ domplate.__tempValue__ = ( "+t+" ); }}}");return function(t){var n;return e(t),n=g.__tempValue__,delete g.__tempValue__,n}}function w(t){var e=new j;e.controller=t,e.rootElement=t.rootElement,t.scopes=e.compile()}function g(t){return"string"==typeof t&&(t=e.querySelector(t)),t.domplateController?t.domplateController:t.isDomplateElement?null:t.domplateController=new N(t)}function S(){t.domplate||(g.handle=l,t.domplate=g),"object"==typeof module&&"object"==typeof module.exports&&(module.exports=t.domplate)}var x=/^d-/,C=/^(d-)?on[a-z]+$/i,b=/\{\{[\s\S]+?\}\}|\\[\{\}]/,N=f(function U(t){this.rootElement=t,this.handleId=l(this),w(this),null!==this.initData&&this.load(this.initData)}).methods({scopes:null,initData:null,data:null,handleId:null,_updateInvoked:0,load:function(t){return this.data=t,this.update(),this},methods:function(){var t=function(t){return function(){return t.apply(this,arguments),this.update(),this}};return function(e){return o(e,function(e,n){this[n]=t(e)},this),this}}(),update:function(){this._updateInvoked++,this.scopes.update(this.data)}}),E=f(function B(t,e,n,i){this.node=t,this.ownCtrl=e,n&&(x.test(n)&&(d(t,n,null),n=n.replace(x,"")),this.name=n),i&&this.set(i)}).methods({parentScope:null,subScopes:null,lastValue:null,set:function(t){this.template=p(t)},get:function(t,e){var n=this.template(t);return this.lastValue!=n&&e.call(this,this.lastValue=n),n},update:function(t){this.get(t,this.change)}}),A=E.extend({type:"ExpressionContent",change:function(t){this.node.nodeValue=t}}),k=E.extend({type:"ExpressionAttribute",change:function(t){d(this.node,this.name,""===t?null:t)}}),V=E.extend({type:"EventAttribute",change:function(t){d(this.node,this.name,V.eventWrapper({controllerHandleId:this.ownCtrl.handleId,value:t}))}}).statics({eventWrapper:p(["return function(){ ","var __ctrl = domplate.handle({{ controllerHandleId }}); ","var __lastUpdateInvoked = __ctrl._updateInvoked; ","var __result = function( $this, __ctrl, __lastUpdateInvoked ){ ","{{ value }} ","}.call( this, __ctrl ); ","if( __lastUpdateInvoked === __ctrl._updateInvoked ) ","__ctrl.update(); ","return __result; ","}.call( this );"])}),I=E.extend(function M(t,e){this.attributes=[],this.parentNode=t.parentNode,this.setup()}).methods({placeholderNode:null,extractAttr:function(t){var e=d(this.node,t);return d(this.node,t,null),e},initPlaceholder:function(){var t,n;t=this.placeholderNode=e.createTextNode(""),n=this.node.parentNode,n.insertBefore(t,this.node),n.removeChild(this.node)},setup:function(){var t=this.node.attributes,e,n,i;r(t,function(t){e=t.name,n=t.value,C.test(e)?i=V:b.test(n)&&(i=k),i&&(this.attributes.push(new i(this.node,this.ownCtrl,e,n)),d(this.node,e,null),i=null)},this)},update:function(t){i(this.attributes,function(e){e.update(t)})},updateChilds:function(t){i(this.subScopes,function(t){t.update.apply(t,this)},arguments)}}),P=I.extend({type:"ShowScope",extract:null,lastValue:null,setup:function(){this.supr(),this.extract=y(this.extractAttr("show"))},update:function(t){var e=this.extract(t);this.supr(t),this.lastValue!==e&&(h[e?"remove":"add"](this.node,"domplate-hide"),this.lastValue=e),e&&this.updateChilds(t)}}),D=I.extend({type:"RepeatScope",itemName:null,extractCollection:null,setup:function(){var t,e,i;this.itemDatas=[],this.itemNodes=[],this.supr(),t=this.extractAttr("repeat").split(" in "),this.itemName=n(t[0]),this.extractCollection=y(n(t[1])),this.initPlaceholder()},update:function(t){var e=0,n,i,r,l=this.parentNode;if(l.insertBefore(this.node,this.placeholderNode),n=this.itemNodes,o(this.extractCollection(t),function(i,r){var o,c,h,d;e++,o=this.itemDatas[r],u(o,i)||(c=s(t),c[this.itemName]=i,c.$index=r,this.supr(c),this.updateChilds(c),d=_(this.node.cloneNode(!0)),h=n[r],l.insertBefore(d,h||this.node),h&&l.removeChild(h),n[r]=d,this.itemDatas[r]=a(i))},this),i=e,r=n.length,r>i){for(;r>i;i++)l.removeChild(n[i]);n.length=this.itemDatas.length=e}l.removeChild(this.node)}}),O=I.extend({type:"SwitchScope",extract:null,switchValue:null,caseMatch:0,setup:function(){this.supr(),this.extract=y(this.extractAttr("switch"))},update:function(t){this.supr(t),this.switchValue=this.extract(t).toString(),this.caseMatch=0,this.updateChilds(t)}}),T=I.extend({type:"CaseScope",parentSwitch:null,value:null,setup:function(){this.supr(),this.value=this.extractAttr("case")},update:function(t){var e=this.parentSwitch;this.value===e.switchValue?(this.supr(t),h.remove(this.node,"domplate-hide"),e.caseMatch++,this.updateChilds(t)):h.add(this.node,"domplate-hide")},onParentScopeSpecified:function(){for(var t=this.parentScope;t;){if("SwitchScope"==t.type){this.parentSwitch=t;break}t=t.parentScope}}}),z=T.extend({type:"DefaultScope",setup:function(){this.supr()},update:function(t){0===this.parentSwitch.caseMatch?(this.supr(t),h.remove(this.node,"domplate-hide"),this.updateChilds(t)):h.add(this.node,"domplate-hide")}}),L=I.extend({type:"SkipScope",setup:function(){this.supr()},update:function(t){this.supr(t),this.updateChilds(t)}}),j=f(function q(){}).statics({parseInit:function(t,e){var n=d(t,"init"),i;try{i=Function("return "+n+";")(),e.initData=i}catch(r){throw new Error("invalid data: "+n)}}}).methods({controller:null,compileNode:function(t,e){var n,r,o,s,a=this.controller;if(t.isDomplateElement)return null;switch(t.nodeType){case 1:t.isDomplateElement=!0,d(t,"init")&&j.parseInit(t,a),r=d(t,"show")?new P(t,a):d(t,"repeat")?new D(t,a):d(t,"switch")?new O(t,a):d(t,"case")?new T(t,a):null!==d(t,"default")?new z(t,a):new L(t,a);break;case 3:b.test(t.nodeValue)&&(r=new A(t,a,null,t.nodeValue));break;case 8:break;default:throw new Error("Unknow node type")}return n=t.childNodes,r&&(e&&(r.parentScope=e,r.onParentScopeSpecified&&r.onParentScopeSpecified()),n&&n.length&&(s=r.subScopes=[],i(n,function(t){o=this.compileNode(t,r),o&&s.push(o)},this))),r},compile:function(){return this.compileNode(this.rootElement,null)}});void function F(){return t.domplate?S():(c(v.initializeCss),void S())}()}("undefined"!=typeof window?window:this,document,function t(e){return e.trim?e.trim():e.replace(/^\s+|\s+$/g,"")},function e(t,n,i){if(t&&t.length)for(var r=0,o=t.length;o>r;r++)n.call(i,t[r],r)},function n(t,e,i){if(t&&t.length)for(var r=t.length-1;r>-1;r--)e.call(i,t[r],r)},function i(t,e,n){for(var i in t)t.hasOwnProperty(i)&&e.call(n,t[i],i)},function r(t){var e={};for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},function o(){var t=/num|str|boo|und/,e=/fun/,n=/date|rege/i;return function i(r){var o,s,a;if(o=typeof r,t.test(o)||!r)return r;if(e.test(o))return new Function("return "+r.toString())();if(n.test(r.constructor))return new r.constructor(r.valueOf());a="length"in r?[]:{};for(s in r)r.hasOwnProperty(s)&&(a[s]=i(r[s]));return a}}(),function s(){var t=/num|str|boo|fun/,e=/fun/,n=/regx|date/i;return function i(r,o){var s,a,u;if(s=typeof r,r===o)return!0;if(s!==typeof o)return!1;if(r!==r&&o!==o)return!0;if(t.test(s)||!r||!o)return r===o;if(e.test(s)||n.test(r.constructor))return r.toString()===o.toString();u={};for(a in r)if(r.hasOwnProperty(a)&&(u[a]=1,!i(r[a],o[a])))return!1;for(a in o)if(!u[a]&&o.hasOwnProperty(a)&&!i(r[a],o[a]))return!1;return!0}}(),function a(){var t={},e=0;return function(n){switch(typeof n){case"number":return t[n.toString()];break;case"object":case"function":return t[(++e).toString()]=n,e}}}(),function u(t,e){var n,i,r,o,s;if("object"==typeof t){n=t,t=[];for(i in n)if(n.hasOwnProperty(i)){r=n[i],t.push(i,"{");for(o in r)r.hasOwnProperty(o)&&t.push(o,":",r[o],";");t.push("}")}t=t.join("")}e||(e=document),e.createStyleSheet?(s=e.createStyleSheet(),s.cssText=t):(s=e.createElement("style"),s.type="text/css",s.appendChild(e.createTextNode(t)),e.getElementsByTagName("head")[0].appendChild(s))},function l(){function t(t){return new RegExp("(^|\\s+)"+t+"(\\s+|$)")}function e(t,e){(n(t,e)?r:i)(t,e)}var n,i,r;return"classList"in document.documentElement?(n=function(t,e){return t.classList.contains(e)},i=function(t,e){t.classList.add(e)},r=function(t,e){t.classList.remove(e)}):(n=function(e,n){return t(n).test(e.className)},i=function(t,e){n(t,e)||(t.className=t.className+" "+e)},r=function(e,n){e.className=e.className.replace(t(n)," ")}),{hasClass:n,addClass:i,removeClass:r,toggleClass:e,has:n,add:i,remove:r,toggle:e}}(),function c(){var t,e,n,i,r;for(i="checked,selected,async,autofocus,autoplay,controls,defer,disabled,hidden,ismap,loop,multiple,open,readonly,required,scoped",i=i.split(","),r=/^(0|NaN|false|undefined|null|\s*)$/,n={type:{set:function(t,e,n){return"radio"!=e||"input"!=t.nodeName.toLowerCase()?!1:(n=t.value,t.setAttribute("type",e),n?t.value=n:0,void 0)}},style:{get:function(t){return t.style.cssText||void 0},set:function(t,e){t.style.cssText=e+""}},value:{get:function(t){return"input"==t.nodeName.toLowerCase()?t.value:t.getAttribute("value")},set:function(t,e){return"input"!=t.nodeName.toLowerCase()?!1:void(t.value=e)}}},t=0;e=i[t];t++)n[e]={set:function(t,e,n){r.test(e)?(t.removeAttribute(n),t[n]=!1):(t.setAttribute(n,n),t[n]=!0)}};return function o(t,e,i,r){return t&&!/^[238]$/.test(t.nodeType)?null===i?t.removeAttribute(e):(r=n[e],"undefined"!=typeof i?r&&r.set&&r.set(t,i,e)!==!1?i:(t.setAttribute(e,i+""),i):r&&r.get?r.get(t):t.getAttribute(e)):void 0}}(),function h(){var t,e,n,i,r;return t=/\\([\{\}])|\u200c([^\u200d])\u200d/g,e={evaluate:/\{\{\{([\s\S]+?)\}\}\}/g,interpolate:/\{\{([\s\S]+?)\}\}/g},n=new RegExp(e.evaluate.source+"|"+e.interpolate.source+"|$","g"),i=/\\|"|\r|\n|\t|\u2028|\u2029/g,r={'"':'"',"\\":"\\","\r":"r","\n":"n"," ":"t","\u2028":"u2028","\u2029":"u2029"},function o(e,s){var a,u,l,c;u=0,l='_p_p_ = "',e instanceof Array&&(e=e.join("")),e=e.replace(t,"$1"),e.replace(n,function(t,n,o,s){return l+=e.slice(u,s).replace(i,function(t){return"\\"+r[t]}),n&&(l+='"; '+n+'; _p_p_ += "'),o&&(l+='" + ( ( _t_t_ = ( '+o+' ) ) == null ? "" : _t_t_ ) + "'),u=s+t.length,t}),l=l.replace(t,"$2"),l="var _t_t_, _p_p_; with( _d_d_ || {} ){ "+l+'"; } return _p_p_;';try{a=new Function("_d_d_",l)}catch(h){throw h.source=l,h}return s?a(s):(c=function(t){return a.call(this,t)},c.source="function( _d_d_ ){ "+l+" }",c)}}(),function d(){function d(e){return i.call(t(e)?e:function(){},e,1)}function t(t){return typeof t===o}function e(t,e,n){return function(){var i=this.supr,r={}.fabricatedUndefined,o=r;this.supr=n[a][t];try{o=e.apply(this,arguments)}finally{this.supr=i}return o}}function n(n,i,r){for(var o in i)i.hasOwnProperty(o)&&(n[o]=t(i[o])&&t(r[a][o])&&s.test(i[o])?e(o,i[o],r):i[o])}function i(e,r){function o(){}function s(){this.initialize?this.initialize.apply(this,arguments):(r||c&&u.apply(this,arguments),h.apply(this,arguments))}o[a]=this[a];var u=this,l=new o,c=t(e),h=c?e:this,d=c?{}:e;return s.methods=function(t){return n(l,t,u),s[a]=l,this},s.methods.call(s,d).prototype.constructor=s,s.extend=i,s[a].implement=s.statics=function(t,e){return t="string"==typeof t?function(){var n={};return n[t]=e,n}():t,n(this,t,u),this},s}var r=this,o="function",s=/xyz/.test(function(){xyz})?/\bsupr\b/:/.*/,a="prototype";return d}(),function p(){},{initializeCss:{".domplate-hide":{display:"none !important"}}});