Bug 12101 - Move Greybox library outside of language-specific directory
[koha.git] / koha-tmpl / intranet-tmpl / lib / greybox / GreyBox_v5_5 / greybox_source / gallery / gallery.js
1 GB_showImage = function(caption, url, callback_fn) {
2     var options = {
3         width: 300,
4         height: 300,
5         type: 'image',
6
7         fullscreen: false,
8         center_win: true,
9         caption: caption,
10         callback_fn: callback_fn
11     }
12     var win = new GB_Gallery(options);
13     return win.show(url);
14 }
15
16 GB_showPage = function(caption, url, callback_fn) {
17     var options = {
18         type: 'page',
19
20         caption: caption,
21         callback_fn: callback_fn,
22         fullscreen: true,
23         center_win: false
24     }
25     var win = new GB_Gallery(options);
26     return win.show(url);
27 }
28
29 GB_Gallery = GreyBox.extend({
30     init: function(options) {
31         this.parent({});
32         this.img_close = this.root_dir + 'g_close.gif';
33         AJS.update(this, options);
34         this.addCallback(this.callback_fn);
35     },
36
37     initHook: function() {
38         AJS.addClass(this.g_window, 'GB_Gallery');
39
40         var inner = AJS.DIV({'class': 'inner'});
41         this.header = AJS.DIV({'class': 'GB_header'}, inner);
42         AJS.setOpacity(this.header, 0);
43         AJS.getBody().insertBefore(this.header, this.overlay.nextSibling);
44
45         var td_caption = AJS.TD({'id': 'GB_caption', 'class': 'caption', 'width': '40%'}, this.caption);
46         var td_middle = AJS.TD({'id': 'GB_middle', 'class': 'middle', 'width': '20%'});
47
48         var img_close = AJS.IMG({'src': this.img_close});
49         AJS.AEV(img_close, 'click', GB_hide);
50         var td_close = AJS.TD({'class': 'close', 'width': '40%'}, img_close);
51
52         var tbody = AJS.TBODY(AJS.TR(td_caption, td_middle, td_close));
53
54         var table = AJS.TABLE({'cellspacing': '0', 'cellpadding': 0, 'border': 0}, tbody);
55         AJS.ACN(inner, table);
56
57         if(this.fullscreen)
58             AJS.AEV(window, 'scroll', AJS.$b(this.setWindowPosition, this));
59         else
60             AJS.AEV(window, 'scroll', AJS.$b(this._setHeaderPos, this));
61     },
62
63     setFrameSize: function() {
64         var overlay_w = this.overlay.offsetWidth;
65         var page_size = AJS.getWindowSize();
66
67         if(this.fullscreen) {
68             this.width = overlay_w-40;
69             this.height = page_size.h-80;
70         }
71         AJS.setWidth(this.iframe, this.width);
72         AJS.setHeight(this.iframe, this.height);
73
74         AJS.setWidth(this.header, overlay_w);
75     },
76
77     _setHeaderPos: function() {
78         AJS.setTop(this.header, AJS.getScrollTop()+10);
79     },
80
81     setWindowPosition: function() {
82         var overlay_w = this.overlay.offsetWidth;
83         var page_size = AJS.getWindowSize();
84         AJS.setLeft(this.g_window, ((overlay_w - 50 - this.width)/2));
85
86         var header_top = AJS.getScrollTop()+55;
87         if(!this.center_win) {
88             AJS.setTop(this.g_window, header_top);
89         }
90         else {
91             var fl = ((page_size.h - this.height) /2) + 20 + AJS.getScrollTop();
92             if(fl < 0) fl = 0;
93             if(header_top > fl) {
94                 fl = header_top;
95             }
96             AJS.setTop(this.g_window, fl);
97         }
98         this._setHeaderPos();
99     },
100
101     onHide: function() {
102         AJS.removeElement(this.header);
103         AJS.removeClass(this.g_window, 'GB_Gallery');
104     },
105
106     onShow: function() {
107         if(this.use_fx)
108             AJS.fx.fadeIn(this.header, {to: 1});
109         else
110             AJS.setOpacity(this.header, 1);
111     }
112 });
113
114 AJS.preloadImages(GB_ROOT_DIR+'g_close.gif');