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
|
// JavaScript Document
function callJSON(){
// json.clean();
json.createScript('dashboard.php?output=json');
json.buildAll();
json.addAll();
}
var json = {
scripts: new Array(), // array of existing scripts id's
nextId: 1, // id of next script tag
head: '', // DOM Head obj
initialize: function(){
this.head = document.getElementsByTagName("head").item(0);
},
callBack: function(){
if(this.callBack.arguments.length > 0)
alert(this.callBack.arguments[0])
else
alert('callBack!');
},
onetime: function(url){
var onetimeid;
onetimeid = this.createScript(url);
this.buildScript(onetimeid);
this.addScript(onetimeid);
},
createScript: function(url){
this.scripts[this.nextId] = {
'id': this.nextId,
'fullurl': url+'&jsscriptid='+this.nextId,
'noCacheIE': '&noCacheIE=' + (new Date()).getTime(),
'scriptId': 'JscriptId' + this.nextId,
'status': 1
};
//SDI('create:' + this.nextId);
this.nextId++;
return (this.nextId-1);
},
buildScript: function(id){
if((typeof(id) != 'undefined')){
if((typeof(this.scripts[id]) != 'undefined') && !empty(this.scripts[id]) && (this.scripts[id].status == 1)){
var scriptObj = document.createElement("script");
// Add script object attributes
scriptObj.setAttribute("type", "text/javascript");
scriptObj.setAttribute("charset", "utf-8");
scriptObj.setAttribute("src", this.scripts[id].fullurl+this.scripts[id].noCacheIE);
scriptObj.setAttribute("id", this.scripts[id].scriptId);
this.scripts[id].scriptObj = scriptObj;
this.scripts[id].status = 2;
}
}
},
buildAll: function() {
for(var i=1; i < this.nextId; i++){
this.buildScript(i);
}
},
addScript: function(id){
if((typeof(id) != 'undefined')){
if((typeof(this.scripts[id]) != 'undefined') && !empty(this.scripts[id]) && (this.scripts[id].status == 2)){
this.head.appendChild(this.scripts[id].scriptObj);
this.scripts[id].status = 3;
}
}
},
addAll: function(){
for(var i=1; i < this.nextId; i++){
this.addScript(i);
}
},
removeScript: function(id){
if((typeof(id) != 'undefined')){
if((typeof(this.scripts[id]) != 'undefined') && !empty(this.scripts[id]) && (this.scripts[id].status == 3)){
//SDI('remove:'+this.scripts[id].scriptId);
this.head.removeChild(this.scripts[id].scriptObj);
this.scripts[id] = null;
}
}
},
clean: function(){
for(var i=1; i < this.nextId; i++){
this.removeScript(i);
}
this.scripts = new Array();
this.nextId = 1;
}
}
json.initialize();
|