-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.js
78 lines (69 loc) · 1.82 KB
/
utils.js
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
// global variables
var globals = {
// container of classes
class: {}
};
// defining class
function define(className, func) {
globals.class[className] = func
}
// create instance of class
function createClass(className, params) {
if (!globals.class[className]) {
console.error('class "' + className + '" not found');
return;
}
return new globals.class[className](params);
}
// compile template if it is not compiled already
function compileTemplate(template) {
if (!Template7.templates[template]) {
var tml = $$('script#' + template);
if (tml.length == 0) {
console.error('template "' + template + '" not found');
return;
}
var html = tml.html().replace(/\[\[/g, '{{').replace(/\]\]/g, '}}');
Template7.templates[template] = Template7.compile(html);
}
}
function compileTemplates(templates) {
templates.forEach(function(template) {
compileTemplate(template)
})
}
function removeTemplate(template) {
delete Template7.templates[template];
}
// ##### Dom7 addons
(function(jQuery) {
var class2type = {};
jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) {
class2type[ "[object " + name + "]" ] = name.toLowerCase();
});
jQuery.extend(jQuery, {
isFunction: function( obj ) {
return jQuery.type(obj) === "function";
},
isArray: Array.isArray || function( obj ) {
return jQuery.type(obj) === "array";
},
isNumeric: function( obj ) {
return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0;
},
isEmptyObject: function( obj ) {
var name;
for ( name in obj ) {
return false;
}
return true;
},
type: function (obj) {
if ( obj == null ) {
return obj + "";
}
return (typeof obj === "object" || typeof obj === "function") ?
class2type[toString.call(obj)] || "object" : typeof obj;
}
});
})(Dom7);