1// Copyright (c) 2006 Sébastien Gruhier (http://xilinus.com, http://itseb.com)
2// YOU MUST INCLUDE window.js BEFORE
4// Object to store hide/show windows status in a cookie
5// Just add at the end of your HTML file this javascript line: WindowStore.init()
8 cookieName: "__window_store__",
11 // Init function with two optional parameters
12 // - cookieName (default = __window_store__)
13 // - expiration date (default 3 years from now)
14 init: function(cookieName, expired) {
15 WindowStore.cookieName = cookieName || WindowStore.cookieName
18 var today = new Date();
19 today.setYear(today.getYear()+1903);
20 WindowStore.expired = today;
23 WindowStore.expired = expired;
25 Windows.windows.each(function(win) {
26 win.setCookie(win.getId(), WindowStore.expired);
29 // Create observer on show/hide events
31 onShow: function(eventName, win) {
32 WindowStore._saveCookie();
35 onClose: function(eventName, win) {
36 WindowStore._saveCookie();
39 onHide: function(eventName, win) {
40 WindowStore._saveCookie();
43 Windows.addObserver(myObserver);
45 WindowStore._restoreWindows();
46 WindowStore._saveCookie();
50 eval("var cookie = " + WindowUtilities.getCookie(WindowStore.cookieName));
52 if (cookie[win.getId()])
59 // Function to store windows show/hide status in a cookie
60 _saveCookie: function() {
64 var cookieValue = "{";
65 Windows.windows.each(function(win) {
66 if (cookieValue != "{")
68 cookieValue += win.getId() + ": " + win.isVisible();
72 WindowUtilities.setCookie(cookieValue, [WindowStore.cookieName, WindowStore.expired]);
75 // Function to restore windows show/hide status from a cookie if exists
76 _restoreWindows: function() {
77 eval("var cookie = " + WindowUtilities.getCookie(WindowStore.cookieName));
80 Windows.windows.each(function(win) {
81 if (cookie[win.getId()])
89// Object to set a close key an all windows
91 keyCode: Event.KEY_ESC,
93 init: function(keyCode) {
95 WindowCloseKey.keyCode = keyCode;
97 Event.observe(document, 'keydown', this._closeCurrentWindow.bindAsEventListener(this));
100 _closeCurrentWindow: function(event) {
101 var e = event || window.event
102 var characterCode = e.which || e.keyCode;
104 // Check if there is a top window (it means it's an URL content)
105 var win = top.Windows.focusedWindow;
106 if (characterCode == WindowCloseKey.keyCode && win) {
107 if (win.cancelCallback)
108 top.Dialog.cancelCallback();
109 else if (win.okCallback)
110 top.Dialog.okCallback();
112 top.Windows.close(top.Windows.focusedWindow.getId());