Merge remote branch 'kc/master' into new/enh/bug_5917
[koha.git] / koha-tt / opac-tmpl / prog / en / lib / greybox / GreyBox_v5_5 / greybox_source / window / window.js
1 GB_show = function(caption, url, /* optional */ height, width, callback_fn) {
2     var options = {
3         caption: caption,
4         height: height || 500,
5         width: width || 500,
6         fullscreen: false,
7         callback_fn: callback_fn
8     }
9     var win = new GB_Window(options);
10     return win.show(url);
11 }
12
13 GB_showCenter = function(caption, url, /* optional */ height, width, callback_fn) {
14     var options = {
15         caption: caption,
16         center_win: true,
17         height: height || 500,
18         width: width || 500,
19         fullscreen: false,
20         callback_fn: callback_fn
21     }
22     var win = new GB_Window(options);
23     return win.show(url);
24 }
25
26 GB_showFullScreen = function(caption, url, callback_fn) {
27     var options = {
28         caption: caption,
29         fullscreen: true,
30         callback_fn: callback_fn
31     }
32     var win = new GB_Window(options);
33     return win.show(url);
34 }
35
36 GB_Window = GreyBox.extend({
37     init: function(options) {
38         this.parent({});
39         this.img_header = this.root_dir+"header_bg.gif";
40         this.img_close = this.root_dir+"w_close.gif";
41         this.show_close_img = true;
42         AJS.update(this, options);
43         this.addCallback(this.callback_fn);
44     },
45
46     initHook: function() {
47         AJS.addClass(this.g_window, 'GB_Window');
48
49         this.header = AJS.TABLE({'class': 'header'});
50         this.header.style.backgroundImage = "url("+ this.img_header +")";
51
52         var td_caption = AJS.TD({'class': 'caption'}, this.caption);
53         var td_close = AJS.TD({'class': 'close'});
54
55         if(this.show_close_img) {
56             var img_close = AJS.IMG({'src': this.img_close});
57             var span = AJS.SPAN('Close');
58
59             var btn = AJS.DIV(img_close, span);
60
61             AJS.AEV([img_close, span], 'mouseover', function() { AJS.addClass(span, 'on'); });
62             AJS.AEV([img_close, span], 'mouseout', function() { AJS.removeClass(span, 'on'); });
63             AJS.AEV([img_close, span], 'mousedown', function() { AJS.addClass(span, 'click'); });
64             AJS.AEV([img_close, span], 'mouseup', function() { AJS.removeClass(span, 'click'); });
65             AJS.AEV([img_close, span], 'click', GB_hide);
66
67             AJS.ACN(td_close, btn);
68         }
69
70         tbody_header = AJS.TBODY();
71         AJS.ACN(tbody_header, AJS.TR(td_caption, td_close));
72
73         AJS.ACN(this.header, tbody_header);
74         AJS.ACN(this.top_cnt, this.header);
75
76         if(this.fullscreen)
77             AJS.AEV(window, 'scroll', AJS.$b(this.setWindowPosition, this));
78     },
79
80     setFrameSize: function() {
81         if(this.fullscreen) {
82             var page_size = AJS.getWindowSize();
83             overlay_h = page_size.h;
84             this.width = Math.round(this.overlay.offsetWidth - (this.overlay.offsetWidth/100)*10);
85             this.height = Math.round(overlay_h - (overlay_h/100)*10);
86         }
87
88         AJS.setWidth(this.header, this.width+6); //6 is for the left+right border
89         AJS.setWidth(this.iframe, this.width);
90         AJS.setHeight(this.iframe, this.height);
91     },
92
93     setWindowPosition: function() {
94         var page_size = AJS.getWindowSize();
95         AJS.setLeft(this.g_window, ((page_size.w - this.width)/2)-13);
96
97         if(!this.center_win) {
98             AJS.setTop(this.g_window, AJS.getScrollTop());
99         }
100         else {
101             var fl = ((page_size.h - this.height) /2) - 20 + AJS.getScrollTop();
102             if(fl < 0)
103                 fl = 0;
104             AJS.setTop(this.g_window, fl);
105         }
106     }
107 });
108
109 AJS.preloadImages(GB_ROOT_DIR+'w_close.gif', GB_ROOT_DIR+'header_bg.gif');