blob: c086e29e31ef993615d0dc7f44d10975d7385dad [file] [log] [blame]
Pankaj Berdec4ae4b82013-01-12 09:56:47 -08001// template loader from Christophe Coenraets
2tpl = {
3
4 // Hash of preloaded templates for the app
5 templates:{},
6
7 // Recursively pre-load all the templates for the app.
8 // This implementation should be changed in a production environment. All the template files should be
9 // concatenated in a single file.
10 loadTemplates:function (names, callback) {
11
12 var that = this;
13
14 var loadTemplate = function (index) {
15 var name = names[index];
16 console.log('Loading template: ' + name);
17 $.get('tpl/' + name + '.html', function (data) {
18 that.templates[name] = data;
19 index++;
20 if (index < names.length) {
21 loadTemplate(index);
22 } else {
23 callback();
24 }
25 });
26 }
27
28 loadTemplate(0);
29 },
30
31 // Get template by name from hash of preloaded templates
32 get:function (name) {
33 return this.templates[name];
34 }
35
36};