helpcenter/Web/js/jquery/jquery.tmpl.min.js
alexandervnuchkov 71f171fb08 First commit
2016-08-29 16:51:20 +03:00

1 line
9.0 KiB
JavaScript

!function(jQuery,undefined){function newTmplItem(options,parentItem,fn,data){var newItem={data:data||(parentItem?parentItem.data:{}),_wrap:parentItem?parentItem._wrap:null,tmpl:null,parent:parentItem||null,nodes:[],calls:tiCalls,nest:tiNest,wrap:tiWrap,html:tiHtml,update:tiUpdate};return options&&jQuery.extend(newItem,options,{nodes:[],parent:parentItem}),fn&&(newItem.tmpl=fn,newItem._ctnt=newItem._ctnt||newItem.tmpl(jQuery,newItem),newItem.key=++itemKey,(stack.length?wrappedItems:newTmplItems)[itemKey]=newItem),newItem}function build(tmplItem,nested,content){var frag,ret=content?jQuery.map(content,function(item){return"string"==typeof item?tmplItem.key?item.replace(/(<\w+)(?=[\s>])(?![^>]*_tmplitem)([^>]*)/g,"$1 "+tmplItmAtt+'="'+tmplItem.key+'" $2'):item:build(item,tmplItem,item._ctnt)}):tmplItem;return nested?ret:(ret=ret.join(""),ret.replace(/^\s*([^<\s][^<]*)?(<[\w\W]+>)([^>]*[^>\s])?\s*$/,function(all,before,middle,after){frag=jQuery(middle).get(),storeTmplItems(frag),before&&(frag=unencode(before).concat(frag)),after&&(frag=frag.concat(unencode(after)))}),frag?frag:unencode(ret))}function unencode(text){var el=document.createElement("div");return el.innerHTML=text,jQuery.makeArray(el.childNodes)}function buildTmplFn(markup){return new Function("jQuery","$item","var $=jQuery,call,_=[],$data=$item.data;with($data){_.push('"+jQuery.trim(markup).replace(/([\\'])/g,"\\$1").replace(/[\r\t\n]/g," ").replace(/\$\{([^\}]*)\}/g,"{{= $1}}").replace(/\{\{(\/?)(\w+|.)(?:\(((?:[^\}]|\}(?!\}))*?)?\))?(?:\s+(.*?)?)?(\(((?:[^\}]|\}(?!\}))*?)\))?\s*\}\}/g,function(all,slash,type,fnargs,target,parens,args){var def,expr,exprAutoFnDetect,tag=jQuery.tmpl.tag[type];if(!tag)throw"Template command not found: "+type;return def=tag._default||[],parens&&!/\w$/.test(target)&&(target+=parens,parens=""),target?(target=unescape(target),args=args?","+unescape(args)+")":parens?")":"",expr=parens?target.indexOf(".")>-1?target+parens:"("+target+").call($item"+args:target,exprAutoFnDetect=parens?expr:"(typeof("+target+")==='function'?("+target+").call($item):("+target+"))"):exprAutoFnDetect=expr=def.$1||"null",fnargs=unescape(fnargs),"');"+tag[slash?"close":"open"].split("$notnull_1").join(target?"typeof("+target+")!=='undefined' && ("+target+")!=null":"true").split("$1a").join(exprAutoFnDetect).split("$1").join(expr).split("$2").join(fnargs?fnargs.replace(/\s*([^\(]+)\s*(\((.*?)\))?/g,function(all,name,parens,params){return params=params?","+params+")":parens?")":"",params?"("+name+").call($item"+params:all}):def.$2||"")+"_.push('"})+"');}return _;")}function updateWrapped(options,wrapped){options._wrap=build(options,!0,jQuery.isArray(wrapped)?wrapped:[htmlExpr.test(wrapped)?wrapped:jQuery(wrapped).html()]).join("")}function unescape(args){return args?args.replace(/\\'/g,"'").replace(/\\\\/g,"\\"):null}function outerHtml(elem){var div=document.createElement("div");return div.appendChild(elem.cloneNode(!0)),div.innerHTML}function storeTmplItems(content){function processItemKey(el){function cloneTmplItem(key){key+=keySuffix,tmplItem=newClonedItems[key]=newClonedItems[key]||newTmplItem(tmplItem,newTmplItems[tmplItem.parent.key+keySuffix]||tmplItem.parent,null,!0)}var pntKey,pntItem,tmplItem,key,pntNode=el;if(key=el.getAttribute(tmplItmAtt)){for(;pntNode.parentNode&&1===(pntNode=pntNode.parentNode).nodeType&&!(pntKey=pntNode.getAttribute(tmplItmAtt)););pntKey!==key&&(pntNode=pntNode.parentNode?11===pntNode.nodeType?0:pntNode.getAttribute(tmplItmAtt)||0:0,(tmplItem=newTmplItems[key])||(tmplItem=wrappedItems[key],tmplItem=newTmplItem(tmplItem,newTmplItems[pntNode]||wrappedItems[pntNode],null,!0),tmplItem.key=++itemKey,newTmplItems[itemKey]=tmplItem),cloneIndex&&cloneTmplItem(key)),el.removeAttribute(tmplItmAtt)}else cloneIndex&&(tmplItem=jQuery.data(el,"tmplItem"))&&(cloneTmplItem(tmplItem.key),newTmplItems[tmplItem.key]=tmplItem,pntNode=jQuery.data(el.parentNode,"tmplItem"),pntNode=pntNode?pntNode.key:0);if(tmplItem){for(pntItem=tmplItem;pntItem&&pntItem.key!=pntNode;)pntItem.nodes.push(el),pntItem=pntItem.parent;delete tmplItem._ctnt,delete tmplItem._wrap,jQuery.data(el,"tmplItem",tmplItem)}}var elem,elems,i,l,m,keySuffix="_"+cloneIndex,newClonedItems={};for(i=0,l=content.length;l>i;i++)if(1===(elem=content[i]).nodeType){for(elems=elem.getElementsByTagName("*"),m=elems.length-1;m>=0;m--)processItemKey(elems[m]);processItemKey(elem)}}function tiCalls(content,tmpl,data,options){return content?void stack.push({_:content,tmpl:tmpl,item:this,data:data,options:options}):stack.pop()}function tiNest(tmpl,data,options){return jQuery.tmpl(jQuery.template(tmpl),data,options,this)}function tiWrap(call,wrapped){var options=call.options||{};return options.wrapped=wrapped,jQuery.tmpl(jQuery.template(call.tmpl),call.data,options,call.item)}function tiHtml(filter,textOnly){var wrapped=this._wrap;return jQuery.map(jQuery(jQuery.isArray(wrapped)?wrapped.join(""):wrapped).filter(filter||"*"),function(e){return textOnly?e.innerText||e.textContent:e.outerHTML||outerHtml(e)})}function tiUpdate(){var coll=this.nodes;jQuery.tmpl(null,null,null,this).insertBefore(coll[0]),jQuery(coll).remove()}var appendToTmplItems,oldManip=jQuery.fn.domManip,tmplItmAtt="_tmplitem",htmlExpr=/^[^<]*(<[\w\W]+>)[^>]*$|\{\{\! /,newTmplItems={},wrappedItems={},topTmplItem={key:0,data:{}},itemKey=0,cloneIndex=0,stack=[];jQuery.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(name,original){jQuery.fn[name]=function(selector){var elems,i,l,tmplItems,ret=[],insert=jQuery(selector),parent=1===this.length&&this[0].parentNode;if(appendToTmplItems=newTmplItems||{},parent&&11===parent.nodeType&&1===parent.childNodes.length&&1===insert.length)insert[original](this[0]),ret=this;else{for(i=0,l=insert.length;l>i;i++)cloneIndex=i,elems=(i>0?this.clone(!0):this).get(),jQuery.fn[original].apply(jQuery(insert[i]),elems),ret=ret.concat(elems);cloneIndex=0,ret=this.pushStack(ret,name,insert.selector)}return tmplItems=appendToTmplItems,appendToTmplItems=null,jQuery.tmpl.complete(tmplItems),ret}}),jQuery.fn.extend({tmpl:function(data,options,parentItem){return jQuery.tmpl(this[0],data,options,parentItem)},tmplItem:function(){return jQuery.tmplItem(this[0])},template:function(name){return jQuery.template(name,this[0])},domManip:function(args,table,callback,options){if(args[0]&&args[0].nodeType){for(var tmplItem,dmArgs=jQuery.makeArray(arguments),argsLength=args.length,i=0;argsLength>i&&!(tmplItem=jQuery.data(args[i++],"tmplItem")););argsLength>1&&(dmArgs[0]=[jQuery.makeArray(args)]),tmplItem&&cloneIndex&&(dmArgs[2]=function(fragClone){jQuery.tmpl.afterManip(this,fragClone,callback)}),oldManip.apply(this,dmArgs)}else oldManip.apply(this,arguments);return cloneIndex=0,appendToTmplItems||jQuery.tmpl.complete(newTmplItems),this}}),jQuery.extend({tmpl:function(tmpl,data,options,parentItem){var ret,topLevel=!parentItem;if(topLevel)parentItem=topTmplItem,tmpl=jQuery.template[tmpl]||jQuery.template(null,tmpl),wrappedItems={};else if(!tmpl)return tmpl=parentItem.tmpl,newTmplItems[parentItem.key]=parentItem,parentItem.nodes=[],parentItem.wrapped&&updateWrapped(parentItem,parentItem.wrapped),jQuery(build(parentItem,null,parentItem.tmpl(jQuery,parentItem)));return tmpl?("function"==typeof data&&(data=data.call(parentItem||{})),options&&options.wrapped&&updateWrapped(options,options.wrapped),ret=jQuery.isArray(data)?jQuery.map(data,function(dataItem){return dataItem?newTmplItem(options,parentItem,tmpl,dataItem):null}):[newTmplItem(options,parentItem,tmpl,data)],topLevel?jQuery(build(parentItem,null,ret)):ret):[]},tmplItem:function(elem){var tmplItem;for(elem instanceof jQuery&&(elem=elem[0]);elem&&1===elem.nodeType&&!(tmplItem=jQuery.data(elem,"tmplItem"))&&(elem=elem.parentNode););return tmplItem||topTmplItem},template:function(name,tmpl){return tmpl?("string"==typeof tmpl?tmpl=buildTmplFn(tmpl):tmpl instanceof jQuery&&(tmpl=tmpl[0]||{}),tmpl.nodeType&&(tmpl=jQuery.data(tmpl,"tmpl")||jQuery.data(tmpl,"tmpl",buildTmplFn(tmpl.innerHTML))),"string"==typeof name?jQuery.template[name]=tmpl:tmpl):name?"string"!=typeof name?jQuery.template(null,name):jQuery.template[name]||jQuery.template(null,htmlExpr.test(name)?name:jQuery(name)):null},encode:function(text){return(""+text).split("<").join("&lt;").split(">").join("&gt;").split('"').join("&#34;").split("'").join("&#39;")}}),jQuery.extend(jQuery.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(items){newTmplItems={}},afterManip:function(elem,fragClone,callback){var content=11===fragClone.nodeType?jQuery.makeArray(fragClone.childNodes):1===fragClone.nodeType?[fragClone]:[];callback.call(elem,fragClone),storeTmplItems(content),cloneIndex++}})}(jQuery);