forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplates.js
More file actions
107 lines (94 loc) · 2.76 KB
/
templates.js
File metadata and controls
107 lines (94 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
*
* @author: Malishev Dmitry <dima.malishev@gmail.com>
*/
App.Templates.html = {
WEB: {
hint: [''],
notification: [
'<li class="~!:UNSEEN~!"><span class="unselectable mark-seen" id="notification-~!:ID~!"> </span>\
<span class="title"><span class="unselectable icon ~!:TYPE~!"> </span>~!:TOPIC~!</span>\
~!:NOTICE~!\
<b><span class="time">~!:TIME~! ~!:DATE~!</span></b>\
</li>'
],
notification_empty: [
'<li class="empty"><span><i class="fas fa-bell-slash status-icon" style="font-size: 4rem;"></i><br><br>\
'+App.Constants.NOTIFICATIONS_EMPTY+'\</span></li>'
]
},
};
// Internals
var Tpl = App.Templates;
var Templator = function()
{
var init = function()
{
fb.info('Templator work');
Templator.splitThemAll();
Templator.freezeTplIndexes();
};
/**
* Split the tpl strings into arrays
*/
Templator.splitThemAll = function(){
fb.info('splitting tpls');
jQuery.each(App.Templates.html, function(o){
//try{
var tpls = App.Templates.html[o];
jQuery.each(tpls, function(t){
tpls[t] = tpls[t][0].split('~!');
});
//}catch(e){fb.error('%o %o', o, e);}
});
},
/**
* Iterates tpls
*/
Templator.freezeTplIndexes = function(){
fb.info('freezing tpl keys');
jQuery.each(App.Templates.html, Templator.cacheTplIndexes);
},
/**
* Grab the tpl group key and process it
*/
Templator.cacheTplIndexes = function(key)
{
var tpls = App.Templates.html[key];
jQuery.each(tpls, function(o)
{
var tpl = tpls[o];
Templator.catchIndex(key, o, tpl);
});
},
/**
* Set the indexes
*/
Templator.catchIndex = function(key, ref_key, tpl)
{
'undefined' == typeof App.Templates._indexes[key] ? App.Templates._indexes[key] = {} : false;
'undefined' == typeof App.Templates._indexes[key][ref_key] ?
App.Templates._indexes[key][ref_key] = {} : false;
jQuery(tpl).each(function(index, o) {
if (':' == o.charAt(0)) {
App.Templates._indexes[key][ref_key][o.toString()] = index;
}
});
}
/**
* Get concrete templates
*/
init();
return Templator;
};
Templator.getTemplate = function(ns, key){
return [
App.Templates._indexes[ns][key],
App.Templates.html[ns][key].slice(0)
];
}
// init templator
Tpl.Templator = Templator();
Tpl.get = function(key, group){
return Tpl.Templator.getTemplate(group, key);
}