标签:style blog color os io ar art cti
;(function(global ,undefined){ var cache = {} var sn = ‘_ret_‘ + new Date().toString(36) function etic(tplNode , data){ var tplId = tplNode.id || (tplNode.id = uuid()) function cbk(){ return data ? cache[tplId].call(data) : cache[tplId] } if (cache[tplId]) return cbk() var tpl = tplNode.innerHTML var con = ‘var ‘ + sn + ‘ ="" ;‘ function tLine(str ){ return str.replace(/[\r\t\n]/g, " ").replace(/‘/g , "\\‘") } while (true){ var sPos = tpl.indexOf(‘<?‘) if (-1 == sPos) break var ePos = tpl.indexOf(‘?>‘ , sPos + 2) var part1 = tpl.slice(0,sPos) , f = tpl.slice(sPos + 2 , ePos) ,tpl = tpl.slice(ePos + 2) var op = f.charAt(0) if (part1.length) con += sn + " += ‘" + tLine(part1) + "‘;" switch (op){ case ‘=‘ : f = f.slice(1) con += sn + " += " + f + ";" break default: con += f } } tpl.length && (con += sn + " += ‘" + tLine(tpl) + "‘;") con += ‘return ‘ + sn try{ cache[tplId] = new Function("" , con) return cbk() }catch(e){ console && console.log(e , tpl) } } global.etic = etic })(this)
标签:style blog color os io ar art cti
原文地址:http://www.cnblogs.com/vaal-water/p/3925124.html