-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchildtab.php
More file actions
159 lines (138 loc) · 3.38 KB
/
childtab.php
File metadata and controls
159 lines (138 loc) · 3.38 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tab</title>
<script src="3p/jquery-3.7.1.min.js"></script>
</head>
<body>
<script>
var m_CHILDTABPINGFREQUENCY = 10000;
this.createTimer = function (fnTimer_a, intFrequency_a, blnAutoStart_a)
{
var strTimerID = 'timer_' + getGUID();
var strHTML = '<div id="' + strTimerID + '" class="gb-hidden"></div>';
m_objThis.element('#ge-timer-container').append(strHTML);
var objTimer = null;
try
{
objTimer = $.timer(onTimer, intFrequency_a, blnAutoStart_a);
registerTimer(strTimerID, objTimer);
}
catch(err)
{
m_objThis.dialogAlert('Timer Error: ' + err, doNothing);
}
function onTimer()
{
if (($.isFunction(fnTimer_a)) && (intFrequency_a > 0))
{
objTimer.pause();
fnTimer_a();
objTimer.play();
}
}
return strTimerID;
};
function getGUID()
{
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c)
{
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function childTabHandler(objOptions_a)
{
var m_objThis = this;
var m_objOptions = objOptions_a;
var m_strHandlerID = getGUID();
var m_objTab =
{
"id" : m_objOptions.id,
"caption" : 'Child (' + m_objOptions.id + ')',
"window" : m_objOptions.window,
"opener" : m_objOptions.window.opener
};
$(m_objOptions.window).bind('message', function (objEvent_a)
{
if ($.isFunction(m_objOptions.cbOnBroadcast))
{
var objJSON = null;
//console.log('before:childTabHandler');
try
{
objJSON = JSON.parse(objEvent_a.originalEvent.data);
}
catch (err)
{
// do nothing
}
//console.log('after1:childTabHandler');
if (objJSON !== null)
{
if (!(objJSON.queue == undefined))
{
m_objOptions.cbOnBroadcast(objJSON.queue, objJSON.message, objJSON.messagedata);
}
}
//console.log('after2:childTabHandler');
}
}
);
// ====================================================================================
// PUBLICS ============================================================================
m_objThis.broadcast = function (strQueue_a, strMessage_a, objMessageData_a)
{
var objJSON =
{
"tabid" : m_objTab.id,
"originid" : m_objTab.id,
"origindescription" : m_objTab.caption,
"queue" : strQueue_a,
"message" : strMessage_a,
"messagedata" : objMessageData_a
};
//alert('child broadcast:' + JSON.stringify(objJSON));
m_objTab.opener.postMessage(JSON.stringify(objJSON), '*');
};
m_objThis.canCreateTab = function ()
{
return false;
};
m_objThis.getHandlerID = function ()
{
return m_strHandlerID;
};
m_objThis.getTabInfo = function ()
{
return m_objTab;
};
m_objThis.getTabs = function ()
{
return [
{
"id" : m_objTab.id,
"caption" : m_objTab.caption
}
];
};
m_objThis.ping = function ()
{
//logDebug('child ping: ' + m_objTab.id);
m_objThis.broadcast('system', 'ping', 'ping');
};
}
var strTabID = urlParams.get('tabid');
var g_objTabHandler = new childTabHandler(
{
"id" : strTabID,
"cbOnBroadcast" : function() {},
"window" : window
}
);
var g_strChildTabPingTimerID = createTimer(g_objTabHandler.ping, m_CHILDTABPINGFREQUENCY, true);
</script>
</body>
</html>