forked from isw-kudos/cc-customisations
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.js
81 lines (71 loc) · 2.35 KB
/
core.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
console.log("core loaded");
var iswExtensions = {
loadWhenReady: function(initFn, conditionalFns, ignoreHashChange){
if(typeof initFn !=='function' || !Array.isArray(conditionalFns)) {
return console.error('Invalid Params', arguments);
}
var MAX_ATTEMPTS = 30;
var numAttemptsForDojo = 0;
var mapLoadEvent = function(){
if(typeof dojo=="object"){
if(!ignoreHashChange) dojo.addOnLoad(mapHashChangeEvent);
dojo.addOnLoad(fnCallOnLoad);
}
else if(numAttemptsForDojo++ <= MAX_ATTEMPTS)
setTimeout(mapLoadEvent, 1000);
};
var currentHref = window.location.href;
var mapHashChangeEvent = function(){
//map method to onHashChange event
if (('onhashchange' in window) && (!dojo.isIE || dojo.isIE > 7)){
var hashFunc = window.onhashchange;
window.onhashchange = function() {
if(typeof hashFunc==='function')
hashFunc();
fnCallOnLoad();
};
} else { //if the event is not available then create a callback function to check if the url has changed
setInterval(function() {
var newHref = window.location.href;
if (currentHref !== newHref) {
currentHref = newHref;
fnCallOnLoad();
}
}, 1000);
}
};
var numAttempts = {};
var fnCallOnLoad = function(){
try{
var val;
for(var i=0; i<conditionalFns.length; i++) {
var fn = conditionalFns[i];
val = fn();
if(!val) {
numAttempts[i] = numAttempts[i] ? numAttempts[i]+1 : 1;
if(numAttempts[i] <=MAX_ATTEMPTS) setTimeout(fnCallOnLoad, 1000);
return;
}
}
initFn(val);
} catch(e) {
console.error('fnCallOnLoad: ', e);
}
};
mapLoadEvent();
},
fireClickEvent: function(el){
if(document.createEvent) {
var event = document.createEvent('MouseEvents');
event.initEvent( 'click', true, false );
el.dispatchEvent( event );
} else if(document.createEventObject && el.fireEvent) {
var event = document.createEventObject();
el.fireEvent( 'onclick', event );
}
},
addCssStyle:function(styleStr){
var head = document.head || document.getElementsByTagName('head')[0];
if(styleStr && head) dojo.create('style', {innerHTML:styleStr}, head);
}
};