Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

35 строки
1.4 KiB

  1. // Simple JavaScript Templating
  2. // John Resig - http://ejohn.org/ - MIT Licensed
  3. (function(){
  4. var cache = {};
  5. this.tmpl = function tmpl(str, data){
  6. // Figure out if we're getting a template, or if we need to
  7. // load the template - and be sure to cache the result.
  8. var fn = !/\W/.test(str) ?
  9. cache[str] = cache[str] ||
  10. tmpl(document.getElementById(str).innerHTML) :
  11. // Generate a reusable function that will serve as a template
  12. // generator (and which will be cached).
  13. new Function("obj",
  14. "var p=[],print=function(){p.push.apply(p,arguments);};" +
  15. // Introduce the data as local variables using with(){}
  16. "with(obj){p.push('" +
  17. // Convert the template into pure JavaScript
  18. str
  19. .replace(/[\r\t\n]/g, " ")
  20. .split("<%").join("\t")
  21. .replace(/((^|%>)[^\t]*)'/g, "$1\r")
  22. .replace(/\t=(.*?)%>/g, "',$1,'")
  23. .split("\t").join("');")
  24. .split("%>").join("p.push('")
  25. .split("\r").join("\\'")
  26. + "');}return p.join('');");
  27. // Provide some basic currying to the user
  28. return data ? fn( data ) : fn;
  29. };
  30. })();