UNPKG

ignite-ui

Version:

Ignite UI for jQuery by Infragistics

1 lines 5.98 kB
(function(factory){if(typeof define==="function"&&define.amd){define(["jquery"],factory)}else{return factory(jQuery)}})(function($){$.ig=$.ig||{};$.ig.locale=$.ig.locale||{};$.ig.locale.en=$.ig.locale.en||{};$.ig.Templating=$.ig.Templating||{};$.ig.locale.en.Templating={undefinedArgument:"An error has occurred while trying to retrieve data source property: ",noAdvancedTemplating:'The advanced templating engine is not loaded in order to handle {{if}} or {{each}}. Please include the "infragistics.templating.advanced.js" module in order to use advanced templating features.'};$.ig.Templating.locale=$.ig.Templating.locale||$.ig.locale.en.Templating;return $.ig.locale.en.Templating});"use strict";(function(factory){if(typeof define==="function"&&define.amd){define(["jquery","./infragistics.util","./infragistics.util.jquery"],factory)}else{factory(jQuery)}})(function($){$.ig=$.ig||{};$.extend($.ig,{tmpl:function(template,data,args){var tmpl=template,cacheConst;if(tmpl){tmpl=tmpl.replace($.ig.regExp.lineBreak,"");tmpl=tmpl.replace($.ig.regExp.comment,"");if(typeof data==="function"){if(args){data=data.apply(this,args)}else{data=data.call()}}if($.ig._internalTmplCache&&$.ig._internalTmplCache.hasOwnProperty(tmpl)){$.ig.tokens=$.ig._internalTmplCache[tmpl].tokens;$.ig.args=$.ig._internalTmplCache[tmpl].args;$.ig.i=$.ig._internalTmplCache[tmpl].i;$.ig._hasBlock=$.ig._internalTmplCache[tmpl]._hasBlock;tmpl=$.ig._internalTmplCache[tmpl].tmpl}else{$.ig.tokens=[];$.ig.args=[];$.ig.i=0;$.ig._tokenizeTemplate(tmpl);cacheConst=tmpl;$.ig._internalTmplCache[cacheConst]={};$.ig._internalTmplCache[cacheConst].tokens=$.ig.tokens;if($.ig.regExp.block.test(tmpl)){$.ig._hasBlock=true;if(typeof $.ig._tokenizeDirectives==="function"){tmpl=$.ig._tokenizeDirectives(tmpl)}else{console.warn($.ig._getLocaleString("noAdvancedTemplating"))}}else{$.ig._hasBlock=false}$.ig._internalTmplCache[cacheConst].args=$.ig.args;$.ig._internalTmplCache[cacheConst].i=$.ig.i;$.ig._internalTmplCache[cacheConst]._hasBlock=$.ig._hasBlock;$.ig._internalTmplCache[cacheConst].tmpl=tmpl}if(!$.ig.tokens.length){return tmpl}if($.ig._hasBlock){if(typeof $.ig._compileTemplate==="function"){tmpl=$.ig._compileTemplate(tmpl,data)}else{console.warn($.ig._getLocaleString("noAdvancedTemplating"))}}else{tmpl=$.ig._populateTemplate(tmpl,data)}delete $.ig.args;delete $.ig.tokens;delete $.ig._hasBlock;delete $.ig.i}return tmpl},clearTmplCache:function(){delete $.ig._internalTmplCache;$.ig._internalTmplCache={}},regExp:{comment:/\s#[^#]*#/g,sub:/\$\{([\w\$\-]+(?:\.[\w\$\-]+|\s[\w\$\-]+)*)\}/,nonEncodeSub:/\{\{html\s+((?:[\w\$-]+)(?:\.(?:[\w\$-]+)|\s(?:[\w\$-]+))*)\}\}/,forSub:/\$\{([\w\$]+\.[\w\$]+(?:\.[\w\$]+)*)\}/,arg:/args\[\d+\](?!.*\+)/,block:/\{\{(\w+).*?\}\}+(.*)(\{\{\/\1\}\})/,blockCont:/\{\{(?!\/)(\S+)(.*)\}\}(.*)/,blockDirective:/\{\{\S+.*?\}\}/,index:/\$i/g,lineBreak:/(\r\n|\n|\r)/gm,lt:/</g,gt:/>/g,ap:/'/g,ic:/"/g,amp:/&/g},_directives:{if:{start:"if (",close:") {",end:" }"},elseif:{start:" } else if (",close:") {",end:""},else:{start:" } else {",close:"",end:""},each:{start:"for (var i = 0; i < $data.length; i++) {",close:"",end:" }"}},_internalTmplCache:{},_tokenizeTemplate:function(template){var tempToken,splitName;if($.ig.regExp.sub.test(template)){tempToken=$.ig.regExp.sub.exec(template);while(tempToken!==null){splitName=tempToken[1].split(".");tempToken[1]=tempToken[1].replace(/\\/g,"\\\\").replace(/\$/g,"\\$");template=template.replace(new RegExp("\\$\\{"+tempToken[1]+"\\}","g"),"");tempToken[3]=new RegExp("\\$\\{"+tempToken[1]+"\\}","g");tempToken[1]=splitName;tempToken[2]=true;$.ig.tokens.push(tempToken);tempToken=$.ig.regExp.sub.exec(template)}}if($.ig.regExp.nonEncodeSub.test(template)){tempToken=$.ig.regExp.nonEncodeSub.exec(template);while(tempToken!==null){splitName=tempToken[1].split(".");tempToken[1]=tempToken[1].replace(/\\/g,"\\\\").replace(/\$/g,"\\$");template=template.replace(new RegExp("\\{\\{html\\s+"+tempToken[1]+"\\}\\}","g"),"");tempToken[3]=new RegExp("\\{\\{html\\s+"+tempToken[1]+"\\}\\}","g");tempToken[1]=splitName;tempToken[2]=false;$.ig.tokens.push(tempToken);tempToken=$.ig.regExp.nonEncodeSub.exec(template)}}},_populateTemplate:function(template,data){var i,j,result="",temp;if($.ig.util.getType(data)!=="array"){for(i=0;i<$.ig.tokens.length;i++){template=$.ig._populateArgumentValue(data,$.ig.tokens[i],template)}result=template}else{for(j=0;j<data.length;j++){temp=template;for(i=0;i<$.ig.tokens.length;i++){temp=$.ig._populateArgumentValue(data[j],$.ig.tokens[i],temp)}temp=temp.replace($.ig.regExp.index,j);result+=temp}}return result},_getLocaleString:function(key){return $.ig.util?$.ig.util.getLocaleValue("Templating",key):$.ig.Templating.locale[key]},_getArgumentValue:function(data,token,arg){var tempData,l;if(token[1].length&&token[1].length>1){tempData=data;for(l=0;l<token[1].length;l++){if(tempData&&tempData.hasOwnProperty(token[1][l])){tempData=tempData[token[1][l]]}else{tempData="";break}}if(token[2]&&typeof tempData==="string"){arg=$.ig.encode(tempData)}else{arg=tempData}}else{if(token[2]&&typeof data[token[1]]==="string"){arg=$.ig.encode(data[token[1]])}else{arg=data[token[1]]}}return arg},_populateArgumentValue:function(data,token,arg){var tempData,l,self=this;if(token[1].length&&token[1].length>1){tempData=data;for(l=0;l<token[1].length;l++){if(tempData&&tempData.hasOwnProperty(token[1][l])){tempData=typeof tempData[token[1][l]]==="function"?tempData[token[1][l]]():tempData[token[1][l]]}else{tempData="";break}}if(token[2]&&typeof tempData==="string"){arg=arg.replace(token[3],function(){return self.encode(tempData)})}else{arg=arg.replace(token[3],function(){return tempData===null?"":tempData})}}else{if(token[2]){arg=arg.replace(token[3],function(){return self.encode(typeof data[token[1]]==="function"?data[token[1]]():data[token[1]])})}else{arg=arg.replace(token[3],function(){return data[token[1]]===null?"":typeof data[token[1]]==="function"?data[token[1]]():data[token[1]]})}}return arg}})});