Files
mifi-tools/webs/uz901/web1/js/3rd/jquery.tmpl.js
2025-11-03 15:27:16 +08:00

1 line
5.8 KiB
JavaScript

(function(V){var E=V.fn.domManip,S="_tmplitem",F=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,U={},Q={},R,G={key:0,data:{}},N=0,T=0,K=[];function P(b,i,a,f){var j={data:f||(f===0||f===false)?f:i?i.data:{},_wrap:i?i._wrap:null,tmpl:null,parent:i||null,nodes:[],calls:B,nest:z,wrap:y,html:A,update:C};b&&V.extend(j,b,{nodes:[],parent:i});if(a){j.tmpl=a;j._ctnt=j._ctnt||j.tmpl(V,j);j.key=++N;(K.length?Q:U)[N]=j}return j}V.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){V.fn[a]=function(r){var q=[],o=V(r),e,p,c,d,f=this.length===1&&this[0].parentNode;R=U||{};if(f&&f.nodeType===11&&f.childNodes.length===1&&o.length===1){o[b](this[0]);q=this}else{for(p=0,c=o.length;p<c;p++){T=p;e=(p>0?this.clone(true):this).get();V(o[p])[b](e);q=q.concat(e)}T=0;q=this.pushStack(q,a,o.selector)}d=R;R=null;V.tmpl.complete(d);return q}});V.fn.extend({tmpl:function(e,f,a){return V.tmpl(this[0],e,f,a)},tmplItem:function(){return V.tmplItem(this[0])},template:function(a){return V.template(a,this[0])},domManip:function(p,a,b){if(p[0]&&V.isArray(p[0])){var n=V.makeArray(arguments),l=p[0],c=l.length,e=0,o;while(e<c&&!(o=V.data(l[e++],"tmplItem"))){}if(o&&T){n[2]=function(d){V.tmpl.afterManip(this,d,b)}}E.apply(this,n)}else{E.apply(this,arguments)}T=0;!R&&V.tmpl.complete(U);return this}});V.extend({tmpl:function(j,f,g,l){var b,a=!l;if(a){l=G;j=V.template[j]||V.template(null,j);Q={}}else{if(!j){j=l.tmpl;U[l.key]=l;l.nodes=[];l.wrapped&&I(l,l.wrapped);return V(M(l,null,l.tmpl(V,l)))}}if(!j){return[]}if(typeof f==="function"){f=f.call(l||{})}g&&g.wrapped&&I(g,g.wrapped);b=V.isArray(f)?V.map(f,function(c){return c?P(g,l,j,c):null}):[P(g,l,j,f)];return a?V(M(l,null,b)):b},tmplItem:function(a){var d;if(a instanceof V){a=a[0]}while(a&&a.nodeType===1&&!(d=V.data(a,"tmplItem"))&&(a=a.parentNode)){}return d||G},template:function(d,a){if(a){if(typeof a==="string"){a=H(a)}else{if(a instanceof V){a=a[0]||{}}}if(a.nodeType){a=V.data(a,"tmpl")||V.data(a,"tmpl",H(a.innerHTML))}return typeof d==="string"?(V.template[d]=a):a}return d?typeof d!=="string"?V.template(null,d):V.template[d]||V.template(null,F.test(d)?d:V(d)):null},encode:function(b){return(""+b).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}});V.extend(V.tmpl,{tag:{tmpl:{_default:{$2:"null"},open:"if($notnull_1){__=__.concat($item.nest($1,$2));}"},wrap:{_default:{$2:"null"},open:"$item.calls(__,$1,$2);__=[];",close:"call=$item.calls();__=call._.concat($item.wrap(call,__));"},each:{_default:{$2:"$index, $value"},open:"if($notnull_1){$.each($1a,function($2){with(this){",close:"}});}"},"if":{open:"if(($notnull_1) && $1a){",close:"}"},"else":{_default:{$1:"true"},open:"}else if(($notnull_1) && $1a){"},html:{open:"if($notnull_1){__.push($1a);}"},"=":{_default:{$1:"$data"},open:"if($notnull_1){__.push($.encode($1a));}"},"!":{open:""}},complete:function(){U={}},afterManip:function(c,a,h){var g=a.nodeType===11?V.makeArray(a.childNodes):a.nodeType===1?[a]:[];h.call(c,a);J(g);T++}});function M(i,d,h){var a,j=h?V.map(h,function(b){return typeof b==="string"?i.key?b.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+S+'="'+i.key+'" $2'):b:M(b,i,b._ctnt)}):i;if(d){return j}j=j.join("");j.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(b,l,g,k){a=V(g).get();J(a);if(l){a=L(l).concat(a)}if(k){a=a.concat(L(k))}});return a?a:L(j)}function L(d){var a=document.createElement("div");a.innerHTML=d;return V.makeArray(a.childNodes)}function H(a){return new Function("jQuery","$item","var $=jQuery,call,__=[],$data=$item.data;with($data){__.push('"+V.trim(a).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(h,n,o,r,w,v,u){var p=V.tmpl.tag[o],q,t,s;if(!p){throw"Unknown template tag: "+o}q=p._default||[];if(v&&!/\w$/.test(w)){w+=v;v=""}if(w){w=O(w);u=u?","+O(u)+")":v?")":"";t=v?w.indexOf(".")>-1?w+O(v):"("+w+").call($item"+u:w;s=v?t:"(typeof("+w+")==='function'?("+w+").call($item):("+w+"))"}else{s=t=q.$1||"null"}r=O(r);return"');"+p[n?"close":"open"].split("$notnull_1").join(w?"typeof("+w+")!=='undefined' && ("+w+")!=null":"true").split("$1a").join(s).split("$1").join(t).split("$2").join(r||q.$2||"")+"__.push('"})+"');}return __;")}function I(d,a){d._wrap=M(d,true,V.isArray(a)?a:[F.test(a)?a:V(a).html()]).join("")}function O(b){return b?b.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function D(c){var d=document.createElement("div");d.appendChild(c.cloneNode(true));return d.innerHTML}function J(b){var c="_"+T,g,i,f={},r,a,q;for(r=0,a=b.length;r<a;r++){if((g=b[r]).nodeType!==1){continue}i=g.getElementsByTagName("*");for(q=i.length-1;q>=0;q--){d(i[q])}d(g)}function d(s){var v,t=s,n,u,l;if(l=s.getAttribute(S)){while(t.parentNode&&(t=t.parentNode).nodeType===1&&!(v=t.getAttribute(S))){}if(v!==l){t=t.parentNode?t.nodeType===11?0:t.getAttribute(S)||0:0;if(!(u=U[l])){u=Q[l];u=P(u,U[t]||Q[t]);u.key=++N;U[N]=u}T&&w(l)}s.removeAttribute(S)}else{if(T&&(u=V.data(s,"tmplItem"))){w(u.key);U[u.key]=u;t=V.data(s.parentNode,"tmplItem");t=t?t.key:0}}if(u){n=u;while(n&&n.key!=t){n.nodes.push(s);n=n.parent}delete u._ctnt;delete u._wrap;V.data(s,"tmplItem",u)}function w(e){e=e+c;u=f[e]=f[e]||P(u,U[u.parent.key+c]||u.parent)}}}function B(f,g,h,e){if(!f){return K.pop()}K.push({_:f,tmpl:g,item:this,data:h,options:e})}function z(e,f,a){return V.tmpl(V.template(e),f,a,this)}function y(a,e){var f=a.options||{};f.wrapped=e;return V.tmpl(V.template(a.tmpl),a.data,f,a.item)}function A(e,f){var a=this._wrap;return V.map(V(V.isArray(a)?a.join(""):a).filter(e||"*"),function(b){return f?b.innerText||b.textContent:b.outerHTML||D(b)})}function C(){var a=this.nodes;V.tmpl(null,null,null,this).insertBefore(a[0]);V(a).remove()}})(jQuery);