-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHorizon.js
More file actions
1411 lines (1115 loc) · 43.1 KB
/
Copy pathHorizon.js
File metadata and controls
1411 lines (1115 loc) · 43.1 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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if(!javaxt) var javaxt={};
if(!javaxt.express) javaxt.express={};
if(!javaxt.express.app) javaxt.express.app={};
//******************************************************************************
//** Horizon App
//******************************************************************************
/**
* User interface with a fixed header and horizontal tabs. The user interface
* is initialized via the update() method. Websockets are used to relay
* events between the client and the server.
*
******************************************************************************/
javaxt.express.app.Horizon = function(parent, config) {
this.className = "javaxt.express.app.Horizon"; //used by popstateListener
var me = this;
var defaultConfig = {
/** Name of the application. By default, the name will be used as the
* document title. As a user switches tabs, the tab name will be
* appended to the title.
*/
name: "Express",
/** Style for individual elements within the component. In addition,
* there is a general "javaxt" config for javaxt-components. This is a
* complex, nested config. See "default.js" in the javaxt-webcontrols.
* Note that you can provide CSS class names or an inline set of css
* style definitions for each components and javaxt subcomponents.
*/
style: {
javaxt: javaxt.dhtml.style.default,
header: {
/** Style for the header that appears at the top of the app.
*/
div: "app-header",
/** Style for the app icon/logo that appears on the left side of
* the header.
*/
icon: "app-header-icon noselect",
/** Style for the user profile button that appears on the right
* side of the header.
*/
profileButton: "app-header-profile noselect",
/** Style for the menu button that appears on the right side of
* the header. The menu button consists of an icon and label.
* The CSS class should include definitions for "icon" and
* "label".
*/
menuButton: "app-header-menu noselect",
menuPopup: "app-menu",
menuItem: "app-menu-item noselect"
},
navbar: {
div: "app-nav-bar",
tabs: "app-tab-container"
},
body: {
div: "app-body"
},
footer: {
div: "app-footer"
},
/** Style for the communication error popup that is rendered when the
* connection to the server is lost. The popup consists of an icon,
* title, message, and a close button. Note that the nested style
* properties can be replaced with a string representing a CSS class,
* provided that the class includes definitions for "icon", "title",
* "message", and "close".
*/
communicationError: {
div: "communication-error center",
icon: "communication-error-icon",
title: "title",
message: "message",
closeButton: "close"
}
},
/** Map of URLs to REST end points
*/
url: {
/** URL to the login service
*/
login: "login",
/** URL to the logoff service
*/
logoff: "logoff",
/** URL to the web socket endpoint that is sending CRUD notifications
*/
websocket: "/ws"
},
/** Map of keywords
*/
keywords: {
/** URL parameter used to indicate a preferred tab to raise
*/
requestedTab: "tab"
},
/** Used to define the maximum idle time for a user before calling
* logoff(). Units are in milliseconds. Default is false (i.e. no
* auto-logoff).
*/
autoLogoff: false,
/** If true, will enable users to navigate between tabs using the
* browser's forward and back buttons. Default is false.
*/
useBrowserHistory: false,
/** A shared array of javaxt.dhtml.Window components. All the windows in
* the array are automatically closed when a user logs off or when the
* logoff() method is called. You are encouraged to create your own
* array and pass it to the constructor via this config setting and
* update the array whenever you create a new window.
*/
windows: [],
renderers: {
profileButton: function(user, profileButton){}
},
messages: {
connectionLost: "The connection to the server has been lost. " +
"The internet might be down or there might be a problem with the server. " +
"Some features might not work as expected while the server is offline. " +
"Please do not refresh your browser. We will try to reconnect in a few moments.",
connectionTimeout: "We have lost contact with the server. " +
"It has been unavailable for over 5 minutes. Please check your " +
"internet connection or contact the system administrator for assistance.",
updateAvailable: "An update is available for this application. " +
"Would you like to update now?"
}
};
var waitmask;
var auth;
var currUser;
//Web socket stuff
var ws; //web socket listener
var connected = false;
var communicationError;
var timeoutWarning;
//Header components
var profileButton, menuButton; //header buttons
var mainMenu, profileMenu;
var callout;
//Other components
var tabbar, body, footer;
var tabs = {};
var panels = {};
var timers = {};
var userInteractions = ["mousemove","click","keydown","touchmove","wheel"];
//**************************************************************************
//** Constructor
//**************************************************************************
var init = function(){
if (!config) config = {};
config = merge(config, defaultConfig);
auth = new javaxt.dhtml.Authentication(config.url.login, config.url.logoff);
//Set global configuration variables
if (!config.fx) config.fx = new javaxt.dhtml.Effects();
if (!config.waitmask || !config.waitmask.el.parentNode)
config.waitmask = new javaxt.express.WaitMask(document.body);
waitmask = config.waitmask;
//Prevent native browser shortcuts (ctrl+a,h,o,p,s,...)
document.addEventListener("keydown", function(e){
if ((e.keyCode == 65 || e.keyCode == 72 || e.keyCode == 79 || e.keyCode == 80 || e.keyCode == 83) &&
(navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) {
e.preventDefault();
e.stopPropagation();
}
});
//Create main table
var table = createTable(parent);
//Create header
createHeader(table.addRow().addColumn(config.style.header.div));
//Create tabs
var td = table.addRow().addColumn(config.style.navbar.div);
tabbar = createElement("div", td, config.style.navbar.tabs);
//Create body
body = table.addRow().addColumn(config.style.body.div);
body.style.height = "100%";
//Create footer
footer = table.addRow().addColumn(config.style.footer.div);
me.el = table;
};
//**************************************************************************
//** update
//**************************************************************************
/** Used to initialize the app with a new user and a set of tabs
* @param user Simple json object with an id. Additional attributes such
* as name, contact info, etc may be present and used by the renderers
* defined in the config (e.g. profileButton)
* @param tabs Either an array or json object with tabs. Each entry should
* have a name and a class will be instantiated at runtime. The class
* constructor should accept two arguments:
* <ul>
* <li>parent: DOM object</li>
* <li>config: JSON object with optional config settings</li>
* </ul>
* Here's an example of an array of tabs:
<pre>
tabs = [
{name: "Home", class: com.acme.webapp.Home, config: { ... }},
{name: "Admin", class: com.acme.webapp.Admin, config: { ... }}
];
</pre>
* Here's an example of a json object with tabs:
<pre>
tabs = {
Home: com.acme.webapp.Home,
Admin: com.acme.webapp.Admin
};
</pre>
* The most significant difference between the two options is that the
* array includes an optional config key which will be used to instantiate
* the class. Note if the class has a public update() method, it will be
* called after the class is instantiated.
*/
this.update = function(user, tabs){
//Update title
document.title = config.name;
//Update tabs
updateTabs(tabs);
//Update user
var prevUserID = currUser ? currUser.id : null;
updateUser(user);
if (user.id===prevUserID) return;
//Watch for forward and back events via a 'popstate' listener
enablePopstateListener();
//Watch for user events
enableEventListeners();
//Create auto-logoff timer
if (config.autoLogoff && config.autoLogoff>0){
timers.logoff = setTimeout(me.logoff, config.autoLogoff);
}
//Create web socket listener. Note that the listener is destroyed on logoff()
if (!ws) ws = new javaxt.dhtml.WebSocket({
url: config.url.websocket,
onMessage: function(msg){
try { me.onMessage(msg); }
catch(e) {}
var arr = msg.split(",");
var op = arr[0];
var model = arr[1];
var id = arr[2];
var userID = arr[3];
//Parse id as needed
var n = id+"";
var isNumber = !isNaN(parseFloat(n)) && !isNaN(n - 0);
if (isNumber){
try {
var i = parseInt(id);
if (!isNaN(i)) id = i;
}
catch(e) {}
}
//Parse userID
try { userID = parseInt(userID); } catch(e) {}
//Process event
processEvent(op, model, id, userID);
},
onConnect: function(){
if (!connected){
connected = true;
processEvent("connect", "WebSocket", -1, -1);
}
},
onDisconnect: function(){
if (connected){
connected = false;
processEvent("disconnect", "WebSocket", -1, -1);
}
},
onTimeout: function(){
connected = false;
if (communicationError) communicationError.hide(true);
if (!timeoutWarning) createTimeoutWarning();
timeoutWarning.show();
}
});
};
//**************************************************************************
//** getTabs
//**************************************************************************
/** Returns an array of tabs. Each entry includes:
* <ul>
* <li>name: Name/label of the tab (String)</li>
* <li>tab: Tab in the tab bar (DOM Object)</li>
* <li>panel: The panel that is rendered in the body (Object). Note that
* the panel might be null/undefined if it has never been raised. This is
* because panels are only instantiated if a user clicks on a tab.
* </li>
* </ul>
*/
this.getTabs = function(){
var arr = [];
for (var key in tabs) {
if (tabs.hasOwnProperty(key)){
arr.push({
name: key,
tab: tabs[key],
panel: panels[key]
});
}
}
return arr;
};
//**************************************************************************
//** getTab
//**************************************************************************
/** Returns an individual tab for a given label.
*/
this.getTab = function(name){
var tab = tabs[name];
if (!tab) return null;
return {
name: name,
tab: tab,
panel: panels[name]
};
};
//**************************************************************************
//** beforeTabChange
//**************************************************************************
/** Called immediately before a tab is raised in the tab bar.
* @param currTab Object representing the current tab. Example:
* <ul>
* <li>name: Name/label of the tab (String)</li>
* <li>tab: Tab in the tab bar (DOM Object)</li>
* <li>panel: The panel that is rendered in the body (Object)</li>
* </ul>
* @param nextTab Object representing the tab that will be raised.
*/
this.beforeTabChange = function(currTab, nextTab){};
//**************************************************************************
//** onTabChange
//**************************************************************************
/** Called whenever a tab is raised in the tab bar.
* @param currTab Object with key/value pairs including:
* <ul>
* <li>name: Name/label of the tab (String)</li>
* <li>tab: Tab in the tab bar (DOM Object)</li>
* <li>panel: The panel that is rendered in the body (Object)</li>
* </ul>
*/
this.onTabChange = function(currTab){};
//**************************************************************************
//** sendMessage
//**************************************************************************
/** Used to send a message to the server via websockets.
*/
this.sendMessage = function(msg){
if (ws) ws.send(msg);
};
//**************************************************************************
//** onMessage
//**************************************************************************
/** Called whenever a message is recieved from the server via websockets.
* Used the onModelChangeEvent() event listener to receive CRUD events
* specifically.
*/
this.onMessage = function(msg){};
//**************************************************************************
//** onModelChangeEvent
//**************************************************************************
/** Called whenever a Model created, updated, or deleted.
* @param op Operation name. Options include "create", "update", or "delete"
* @param model The name of the model that was changed (e.g. "User").
* @param id The unique identifier associated with the model (e.g. 12345)
* @param userID The unique identifier associated with the user that's
* responsible for the change.
*/
this.onModelChangeEvent = function(op, model, id, userID){};
//**************************************************************************
//** onLogOff
//**************************************************************************
/** Called after the logoff() method is complete.
*/
this.onLogOff = function(){};
//**************************************************************************
//** onUserInteration
//**************************************************************************
/** Called whenever a user interacts with the app (mouse click, mouse move,
* keypress, or touch event).
*/
this.onUserInteration = function(e){};
var onUserInteration = function(e){
me.onUserInteration(e);
if (timers.logoff){
clearTimeout(timers.logoff);
timers.logoff = setTimeout(me.logoff, config.autoLogoff);
};
};
var enableEventListeners = function(){
userInteractions.forEach((interaction)=>{
document.body.addEventListener(interaction, onUserInteration);
});
};
var disableEventListeners = function(){
userInteractions.forEach((interaction)=>{
document.body.removeEventListener(interaction, onUserInteration);
});
};
//**************************************************************************
//** updateUser
//**************************************************************************
var updateUser = function(user){
currUser = user;
//Update the profile button
if (user) profileButton.show();
if (config.renderers.profileButton){
config.renderers.profileButton(user, profileButton);
}
//Get active and requested tab
var currTab, requestedTab;
var t = getParameter(config.keywords.requestedTab).toLowerCase();
for (var key in tabs) {
if (tabs.hasOwnProperty(key)){
var tab = tabs[key];
if (tab.isVisible()){
if (tab.className==="active"){
currTab = key;
}
if (key.toLowerCase()===t){
requestedTab = key;
}
}
}
}
//Get user preferences
user.preferences = new javaxt.express.UserPreferences(()=>{
//Raise tab
if (requestedTab){
//Remove tab parameter from the url
var url = window.location.href;
url = url.replace("tab="+getParameter(config.keywords.requestedTab),"");
if (url.lastIndexOf("&")===url.length-1) url = url.substring(0, url.length-1);
if (url.lastIndexOf("?")===url.length-1) url = url.substring(0, url.length-1);
//Update history
me.updateHistory({
title: config.name + " - " + requestedTab,
tab: requestedTab,
url: url
});
//Raise the tab
tabs[requestedTab].raise();
}
else{
//Click on user's last tab
if (!currTab) currTab = user.preferences.get("Tab");
if (currTab && tabs[currTab]){
me.updateHistory({
title: config.name + " - " + currTab,
tab: currTab
});
tabs[currTab].raise();
}
else{
for (var tabLabel in tabs) {
if (tabs.hasOwnProperty(tabLabel)){
me.updateHistory({
title: config.name + " - " + tabLabel,
tab: tabLabel
});
tabs[tabLabel].raise();
break;
}
}
}
}
});
};
//**************************************************************************
//** processEvent
//**************************************************************************
/** Used to process web socket events and dispatch them to other panels as
* needed
*/
var processEvent = function(op, model, id, userID){
//Process event
if (model==="WebSocket"){
if (currUser){
if (op==="connect"){
if (communicationError) communicationError.hide();
if (timeoutWarning) timeoutWarning.close();
menuButton.hideMessage();
}
else{
if (!communicationError) createErrorMessage();
communicationError.show();
}
}
else{
//logout initiated
}
}
else if (model==="WebFile"){
if (currUser && currUser.preferences){
var autoReload = currUser.preferences.get("AutoReload");
if (autoReload===true || autoReload==="true"){
location.reload();
}
else{
me.el.style.filter = "blur(3px)";
confirm({
width: 515,
resizable: false,
title: "Update Available",
text: config.messages.updateAvailable,
leftButton: {
label: "Yes",
value: true
},
rightButton: {
label: "No",
value: false
},
callback: function(answer){
if (answer===true) location.reload();
else{
me.el.style.filter = "";
menuButton.showMessage("Update Available");
}
}
});
}
}
}
else{
me.onModelChangeEvent(op, model, id, userID);
}
//Dispatch event to other panels
for (var key in panels) {
if (panels.hasOwnProperty(key)){
var panel = panels[key];
if (panel.notify) panel.notify(op, model, id, userID);
}
}
};
//**************************************************************************
//** createHeader
//**************************************************************************
var createHeader = function(parent){
var tr = createTable(parent).addRow();
//Render app icon/logo
createElement("div", tr.addColumn(), config.style.header.icon);
//Add spacer
tr.addColumn().style.width = "100%";
//Create buttons
createProfileButton(tr.addColumn());
createMenuButton(tr.addColumn());
};
//**************************************************************************
//** updateTabs
//**************************************************************************
var updateTabs = function(obj){
//Generate a list of tabs to render in the tabbar
var newTabs = {};
if (obj){
if (isArray(obj)){
obj.forEach((tab)=>{
if (tab.cls && !tab.class) tab.class = tab.cls;
if (typeof tab.class === 'function') {
newTabs[tab.name] = tab;
}
});
}
else{
for (var key in obj) {
if (obj.hasOwnProperty(key)){
var cls = obj[key];
if (typeof cls === 'function') {
newTabs[key] = {
class: cls
};
}
}
}
}
}
//Remove any existing tabs from the tabbar
var activeTab;
for (var key in tabs) {
if (tabs.hasOwnProperty(key)){
var tab = tabs[key];
if (tab.parentNode) tabbar.removeChild(tab);
if (tab.className==="active"){
activeTab = key;
}
}
}
//Update tabbar
for (var key in newTabs) {
if (newTabs.hasOwnProperty(key)){
if (tabs[key]){
var tab = tabs[key];
tabbar.appendChild(tab);
tab.show();
}
else{
createTab(key, newTabs[key]);
}
}
}
//Raise previously active tab
if (activeTab){
if (newTabs[activeTab]){
tabs[activeTab].className="active";
var panel = panels[activeTab];
if (panel) panel.show();
}
else{
tabs[activeTab].className="";
var panel = panels[activeTab];
if (panel) panel.hide();
}
}
};
//**************************************************************************
//** createTab
//**************************************************************************
var createTab = function(label, obj){
if (tabs[label]) return;
var tab = createElement("div", tabbar);
tab.innerText = label;
var fn = function(){
var panel = panels[label];
Object.values(panels).forEach((p)=>{
if (p===panel) return;
p.hide();
});
if (panel){
panel.show();
}
else{
//Get or create config
var cfg;
if (obj.config){
cfg = obj.config;
}
else{
//Create custom config for the panel
cfg = {
style: config.style.javaxt,
fx: config.fx,
waitmask: config.waitmask
};
//Update config with non-standard config options
for (var key in config) {
if (config.hasOwnProperty(key)){
if (defaultConfig[key]) continue;
cfg[key] = config[key];
}
}
}
//Instantiate panel
var fn = eval(obj.class);
panel = new fn(body, cfg);
addShowHide(panel);
panels[label] = panel;
if (panel.update) panel.update();
}
};
tab.raise = function(){
if (this.className==="active") return;
hideWindows();
for (var i=0; i<tabbar.childNodes.length; i++){
tabbar.childNodes[i].className = "";
}
this.className = "active";
fn.apply(me, []);
if (currUser) currUser.preferences.set("Tab", label);
me.onTabChange({
name: label,
tab: this,
panel: panels[label]
});
};
tab.onclick = function(){
if (this.className==="active") return;
var currTab;
for (var i=0; i<tabbar.childNodes.length; i++){
var t = tabbar.childNodes[i];
if (t.className==="active"){
var l = t.innerText;
currTab = {
name: l,
tab: t,
panel: panels[l]
};
break;
}
}
me.beforeTabChange(currTab, {
name: label,
tab: this,
panel: panels[label]
});
//Update history. Do this BEFORE raising the tab so that whatever
//history the tab panel wants to modify happens AFTER the tab change.
me.addHistory({
title: config.name + " - " + label,
tab: label
});
//Raise the tab
this.raise();
};
tabs[label] = tab;
addShowHide(tab);
};
//**************************************************************************
//** addHistory
//**************************************************************************
/** Used to add a "page" to the browser history
* @param params JSON object with the following:
* <ul>
* <li>title - text to display in the browser's title</li>
* <li>tab - label associated with a tab</li>
* <li>url - custom url</li>
* </ul>
*/
this.addHistory = function(params){
updateState(params, false);
};
//**************************************************************************
//** updateHistory
//**************************************************************************
/** Used to update browser history for the current "page"
* @param params JSON object with the following:
* <ul>
* <li>title - text to display in the browser's title</li>
* <li>tab - label associated with a tab</li>
* <li>url - custom url</li>
* </ul>
*/
this.updateHistory = function(params){
updateState(params, true);
};
//**************************************************************************
//** updateState
//**************************************************************************
var updateState = function(params, replace){
if (config.useBrowserHistory!==true) return;
var title = params.title;
if (!title) title = document.title;
var url = "";
if (params.url){
url = params.url;
delete params.url;
}
var state = window.history.state;
if (!state) state = {};
state[me.className] = params;
if (replace){
document.title = title;
history.replaceState(state, title, url);
}
else{
history.pushState(state, title, url);
document.title = title;
}
};
//**************************************************************************
//** enablePopstateListener
//**************************************************************************
var enablePopstateListener = function(){
disablePopstateListener();
if (config.useBrowserHistory===true){
//Add popstate listener
window.addEventListener('popstate', popstateListener);
//Set initial history. This is critical for the popstate listener
var state = window.history.state;
if (!state) state = {};
if (!state[me.className]) state[me.className] = {};
history.replaceState(state, null, '');
}
};
//**************************************************************************
//** disablePopstateListener
//**************************************************************************
var disablePopstateListener = function(){
window.removeEventListener('popstate', popstateListener);
};
//**************************************************************************
//** popstateListener
//**************************************************************************
/** Used to processes forward and back events from the browser