From 2c2668ca0275758fd0ded1fc2add1e5921dfea9f Mon Sep 17 00:00:00 2001 From: David Baumgold Date: Fri, 6 Sep 2013 09:21:55 -0400 Subject: [PATCH] Removed template loader JS library --- cms/static/js/template_loader.js | 79 -------------------------------- 1 file changed, 79 deletions(-) delete mode 100644 cms/static/js/template_loader.js diff --git a/cms/static/js/template_loader.js b/cms/static/js/template_loader.js deleted file mode 100644 index 45161b3c28..0000000000 --- a/cms/static/js/template_loader.js +++ /dev/null @@ -1,79 +0,0 @@ -// -// TODO Figure out how to initialize w/ static views from server (don't call .load but instead inject in django as strings) -// so this only loads the lazily loaded ones. -(function () { - if (typeof window.templateLoader == 'function') return; - - var templateLoader = { - templateVersion: "0.0.15", - templates: {}, - // Control whether template caching in local memory occurs. Caching screws up development but may - // be a good optimization in production (it works fairly well). - cacheTemplates: false, - loadRemoteTemplate: function (templateName, filename, callback) { - if (!this.templates[templateName]) { - var self = this; - jQuery.ajax({url: filename, - success: function (data) { - self.addTemplate(templateName, data); - self.saveLocalTemplates(); - callback(data); - }, - error: function (xhdr, textStatus, errorThrown) { - console.log(textStatus); - }, - dataType: "html" - }) - } - else { - callback(this.templates[templateName]); - } - }, - - addTemplate: function (templateName, data) { - // is there a reason this doesn't go ahead and compile the template? _.template(data) - // I suppose localstorage use would still req raw string rather than compiled version, but that sd work - // if it maintains a separate cache of uncompiled ones - this.templates[templateName] = data; - }, - - localStorageAvailable: function () { - try { - return this.cacheTemplates && 'localStorage' in window && window['localStorage'] !== null; - } catch (e) { - return false; - } - }, - - saveLocalTemplates: function () { - if (this.localStorageAvailable()) { - localStorage.setItem("templates", JSON.stringify(this.templates)); - localStorage.setItem("templateVersion", this.templateVersion); - } - }, - - loadLocalTemplates: function () { - if (this.localStorageAvailable()) { - var templateVersion = localStorage.getItem("templateVersion"); - if (templateVersion && templateVersion == this.templateVersion) { - var templates = localStorage.getItem("templates"); - if (templates) { - templates = JSON.parse(templates); - for (var x in templates) { - if (!this.templates[x]) { - this.addTemplate(x, templates[x]); - } - } - } - } - else { - localStorage.removeItem("templates"); - localStorage.removeItem("templateVersion"); - } - } - } - - }; - templateLoader.loadLocalTemplates(); - window.templateLoader = templateLoader; -})();