forked from humhub/humhub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
132 lines (113 loc) · 2.63 KB
/
app.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
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/**
* Holds all already loaded javascript libaries
*
* @type HashTable
*/
var currentLoadedJavaScripts = new HashTable();
/**
* Looks for script tags inside the given string and checks if the files
* are already loaded.
*
* When already loaded, the scripts will ignored.
*
* @returns {undefined}
*/
function parseHtml(htmlString) {
var re = /<script type="text\/javascript" src="([\s\S]*?)"><\/script>/gm;
var match;
while (match = re.exec(htmlString)) {
js = match[1];
if (currentLoadedJavaScripts.hasItem(js)) {
// Remove Script Tag
//console.log("Ignore load of : "+js);
htmlString = htmlString.replace(match[0], "");
} else {
// Let Script Tag
//console.log("First load of: "+js);
currentLoadedJavaScripts.setItem(js, 1);
}
}
return htmlString;
}
/**
* Hashtable
*
* Javscript Class which represents a hashtable.
*
* @param {type} obj
* @returns {HashTable}
*/
function HashTable(obj)
{
this.length = 0;
this.items = {};
for (var p in obj) {
if (obj.hasOwnProperty(p)) {
this.items[p] = obj[p];
this.length++;
}
}
this.setItem = function(key, value)
{
var previous = undefined;
if (this.hasItem(key)) {
previous = this.items[key];
}
else {
this.length++;
}
this.items[key] = value;
return previous;
}
this.getItem = function(key) {
return this.hasItem(key) ? this.items[key] : undefined;
}
this.hasItem = function(key)
{
return this.items.hasOwnProperty(key);
}
this.removeItem = function(key)
{
if (this.hasItem(key)) {
previous = this.items[key];
this.length--;
delete this.items[key];
return previous;
}
else {
return undefined;
}
}
this.keys = function()
{
var keys = [];
for (var k in this.items) {
if (this.hasItem(k)) {
keys.push(k);
}
}
return keys;
}
this.values = function()
{
var values = [];
for (var k in this.items) {
if (this.hasItem(k)) {
values.push(this.items[k]);
}
}
return values;
}
this.each = function(fn) {
for (var k in this.items) {
if (this.hasItem(k)) {
fn(k, this.items[k]);
}
}
}
this.clear = function()
{
this.items = {}
this.length = 0;
}
}