-
Notifications
You must be signed in to change notification settings - Fork 19
/
00initialize.js
82 lines (72 loc) · 2.2 KB
/
00initialize.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
79
80
81
82
/* Initializer.
* Copyright (C) 2010-2014 shinGETsu Project.
*
* addScriptPath came from
* http://temping-amagramer.blogspot.jp/2012/02/jqueryjavascriptscript.html
*/
var shingetsu = (function () {
var _initializer = [];
var _recordsModifiers = [];
var shingetsu = {
debugMode: false,
plugins: {},
rootPath: '/',
dummyQuery: '',
uiLang: 'en'
};
shingetsu.log = function (arg) {
if (typeof console == 'object') {
console.log(arg);
} else if (shingetsu.debugMode) {
alert(arg);
}
};
shingetsu.initialize = function (func) {
_initializer[_initializer.length] = func;
};
shingetsu.addInitializer = shingetsu.initialize;
shingetsu.addRecordsModifiers = function (func) {
_recordsModifiers[_recordsModifiers.length] = func;
};
shingetsu.addScriptPath = function (path, onload) {
if (typeof onload != 'function') {
onload = function() {};
}
var sep = (path.indexOf('?') > 0) ? '&' : '?';
var realPath = shingetsu.rootPath + path + sep + shingetsu.dummyQuery;
var script = $('<script>');
script.attr('type', 'text/javascript')
.attr('src', realPath)
.on('load', function() { onload(); });
document.getElementsByTagName('head')[0].appendChild(script[0]);
};
shingetsu.modifyRecords = function ($container) {
for (var i = 0; i < _recordsModifiers.length; i++) {
if (shingetsu.debugMode) {
_recordsModifiers[i]($container);
continue;
}
try {
_recordsModifiers[i]($container);
} catch (e) {
shingetsu.log(e);
}
}
};
var _initialize = function () {
for (var i = 0; i < _initializer.length; i++) {
if (shingetsu.debugMode) {
_initializer[i]();
continue;
}
try {
_initializer[i]();
} catch (e) {
shingetsu.log(e);
}
}
shingetsu.modifyRecords($(document));
};
$(_initialize);
return shingetsu;
})();