You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

get.js 686 B

4 years ago
1234567891011121314151617181920212223242526272829
  1. /**
  2. * 获取编译缓存(可由外部重写此方法)
  3. * @param {String} 模板名
  4. * @param {Function} 编译好的函数
  5. */
  6. template.get = function (filename) {
  7. var cache;
  8. if (cacheStore[filename]) {
  9. // 使用内存缓存
  10. cache = cacheStore[filename];
  11. } else if (typeof document === 'object') {
  12. // 加载模板并编译
  13. var elem = document.getElementById(filename);
  14. if (elem) {
  15. var source = (elem.value || elem.innerHTML)
  16. .replace(/^\s*|\s*$/g, '');
  17. cache = compile(source, {
  18. filename: filename
  19. });
  20. }
  21. }
  22. return cache;
  23. };