Adding MARC preview to acqui screens
[koha.git] / koha-tmpl / intranet-tmpl / prog / en / lib / greybox / gb_scripts.js
1 var GB_CURRENT=null;
2 GB_hide=function(){
3 GB_CURRENT.hide();
4 };
5 GreyBox=new AJS.Class({init:function(_1){
6 this.use_fx=AJS.fx;
7 this.type="page";
8 this.overlay_click_close=false;
9 this.salt=0;
10 this.root_dir=GB_ROOT_DIR;
11 this.callback_fns=[];
12 this.reload_on_close=false;
13 this.src_loader=this.root_dir+"loader_frame.html";
14 var _2=window.location.hostname.indexOf("www");
15 var _3=this.src_loader.indexOf("www");
16 if(_2!=-1&&_3==-1){
17 this.src_loader=this.src_loader.replace("://","://www.");
18 }
19 if(_2==-1&&_3!=-1){
20 this.src_loader=this.src_loader.replace("://www.","://");
21 }
22 this.show_loading=true;
23 AJS.update(this,_1);
24 },addCallback:function(fn){
25 if(fn){
26 this.callback_fns.push(fn);
27 }
28 },show:function(_5){
29 GB_CURRENT=this;
30 this.url=_5;
31 var _6=[AJS.$bytc("object"),AJS.$bytc("select")];
32 AJS.map(AJS.flattenList(_6),function(_7){
33 _7.style.visibility="hidden";
34 });
35 this.createElements();
36 return false;
37 },hide:function(){
38 var _8=this.callback_fns;
39 if(_8!=[]){
40 AJS.map(_8,function(fn){
41 fn();
42 });
43 }
44 this.onHide();
45 if(this.use_fx){
46 var _a=this.overlay;
47 AJS.fx.fadeOut(this.overlay,{onComplete:function(){
48 AJS.removeElement(_a);
49 _a=null;
50 },duration:300});
51 AJS.removeElement(this.g_window);
52 }else{
53 AJS.removeElement(this.g_window,this.overlay);
54 }
55 this.removeFrame();
56 AJS.REV(window,"scroll",_GB_setOverlayDimension);
57 AJS.REV(window,"resize",_GB_update);
58 var _b=[AJS.$bytc("object"),AJS.$bytc("select")];
59 AJS.map(AJS.flattenList(_b),function(_c){
60 _c.style.visibility="visible";
61 });
62 GB_CURRENT=null;
63 if(this.reload_on_close){
64 window.location.reload();
65 }
66 },update:function(){
67 this.setOverlayDimension();
68 this.setFrameSize();
69 this.setWindowPosition();
70 },createElements:function(){
71 this.initOverlay();
72 this.g_window=AJS.DIV({"id":"GB_window"});
73 AJS.hideElement(this.g_window);
74 AJS.getBody().insertBefore(this.g_window,this.overlay.nextSibling);
75 this.initFrame();
76 this.initHook();
77 this.update();
78 var me=this;
79 if(this.use_fx){
80 AJS.fx.fadeIn(this.overlay,{duration:300,to:0.7,onComplete:function(){
81 me.onShow();
82 AJS.showElement(me.g_window);
83 me.startLoading();
84 }});
85 }else{
86 AJS.setOpacity(this.overlay,0.7);
87 AJS.showElement(this.g_window);
88 this.onShow();
89 this.startLoading();
90 }
91 AJS.AEV(window,"scroll",_GB_setOverlayDimension);
92 AJS.AEV(window,"resize",_GB_update);
93 },removeFrame:function(){
94 try{
95 AJS.removeElement(this.iframe);
96 }
97 catch(e){
98 }
99 this.iframe=null;
100 },startLoading:function(){
101 this.iframe.src=this.src_loader+"?s="+this.salt++;
102 AJS.showElement(this.iframe);
103 },setOverlayDimension:function(){
104 var _e=AJS.getWindowSize();
105 if(AJS.isMozilla()||AJS.isOpera()){
106 AJS.setWidth(this.overlay,"100%");
107 }else{
108 AJS.setWidth(this.overlay,_e.w);
109 }
110 var _f=Math.max(AJS.getScrollTop()+_e.h,AJS.getScrollTop()+this.height);
111 if(_f<AJS.getScrollTop()){
112 AJS.setHeight(this.overlay,_f);
113 }else{
114 AJS.setHeight(this.overlay,AJS.getScrollTop()+_e.h);
115 }
116 },initOverlay:function(){
117 this.overlay=AJS.DIV({"id":"GB_overlay"});
118 if(this.overlay_click_close){
119 AJS.AEV(this.overlay,"click",GB_hide);
120 }
121 AJS.setOpacity(this.overlay,0);
122 AJS.getBody().insertBefore(this.overlay,AJS.getBody().firstChild);
123 },initFrame:function(){
124 if(!this.iframe){
125 var d={"name":"GB_frame","class":"GB_frame","frameBorder":0};
126 this.iframe=AJS.IFRAME(d);
127 this.middle_cnt=AJS.DIV({"class":"content"},this.iframe);
128 this.top_cnt=AJS.DIV();
129 this.bottom_cnt=AJS.DIV();
130 AJS.ACN(this.g_window,this.top_cnt,this.middle_cnt,this.bottom_cnt);
131 }
132 },onHide:function(){
133 },onShow:function(){
134 },setFrameSize:function(){
135 },setWindowPosition:function(){
136 },initHook:function(){
137 }});
138 _GB_update=function(){
139 if(GB_CURRENT){
140 GB_CURRENT.update();
141 }
142 };
143 _GB_setOverlayDimension=function(){
144 if(GB_CURRENT){
145 GB_CURRENT.setOverlayDimension();
146 }
147 };
148 AJS.preloadImages(GB_ROOT_DIR+"indicator.gif");
149 script_loaded=true;
150 var GB_SETS={};
151 function decoGreyboxLinks(){
152 var as=AJS.$bytc("a");
153 AJS.map(as,function(a){
154 if(a.getAttribute("href")&&a.getAttribute("rel")){
155 var rel=a.getAttribute("rel");
156 if(rel.indexOf("gb_")==0){
157 var _14=rel.match(/\w+/)[0];
158 var _15=rel.match(/\[(.*)\]/)[1];
159 var _16=0;
160 var _17={"caption":a.title||"","url":a.href};
161 if(_14=="gb_pageset"||_14=="gb_imageset"){
162 if(!GB_SETS[_15]){
163 GB_SETS[_15]=[];
164 }
165 GB_SETS[_15].push(_17);
166 _16=GB_SETS[_15].length;
167 }
168 if(_14=="gb_pageset"){
169 a.onclick=function(){
170 GB_showFullScreenSet(GB_SETS[_15],_16);
171 return false;
172 };
173 }
174 if(_14=="gb_imageset"){
175 a.onclick=function(){
176 GB_showImageSet(GB_SETS[_15],_16);
177 return false;
178 };
179 }
180 if(_14=="gb_image"){
181 a.onclick=function(){
182 GB_showImage(_17.caption,_17.url);
183 return false;
184 };
185 }
186 if(_14=="gb_page"){
187 a.onclick=function(){
188 var sp=_15.split(/, ?/);
189 GB_show(_17.caption,_17.url,parseInt(sp[1]),parseInt(sp[0]));
190 return false;
191 };
192 }
193 if(_14=="gb_page_fs"){
194 a.onclick=function(){
195 GB_showFullScreen(_17.caption,_17.url);
196 return false;
197 };
198 }
199 if(_14=="gb_page_center"){
200 a.onclick=function(){
201 var sp=_15.split(/, ?/);
202 GB_showCenter(_17.caption,_17.url,parseInt(sp[1]),parseInt(sp[0]));
203 return false;
204 };
205 }
206 }
207 }
208 });
209 }
210 AJS.AEV(window,"load",decoGreyboxLinks);
211 GB_showImage=function(_1a,url,_1c){
212 var _1d={width:300,height:300,type:"image",fullscreen:false,center_win:true,caption:_1a,callback_fn:_1c};
213 var win=new GB_Gallery(_1d);
214 return win.show(url);
215 };
216 GB_showPage=function(_1f,url,_21){
217 var _22={type:"page",caption:_1f,callback_fn:_21,fullscreen:true,center_win:false};
218 var win=new GB_Gallery(_22);
219 return win.show(url);
220 };
221 GB_Gallery=GreyBox.extend({init:function(_24){
222 this.parent({});
223 this.img_close=this.root_dir+"g_close.gif";
224 AJS.update(this,_24);
225 this.addCallback(this.callback_fn);
226 },initHook:function(){
227 AJS.addClass(this.g_window,"GB_Gallery");
228 var _25=AJS.DIV({"class":"inner"});
229 this.header=AJS.DIV({"class":"GB_header"},_25);
230 AJS.setOpacity(this.header,0);
231 AJS.getBody().insertBefore(this.header,this.overlay.nextSibling);
232 var _26=AJS.TD({"id":"GB_caption","class":"caption","width":"40%"},this.caption);
233 var _27=AJS.TD({"id":"GB_middle","class":"middle","width":"20%"});
234 var _28=AJS.IMG({"src":this.img_close});
235 AJS.AEV(_28,"click",GB_hide);
236 var _29=AJS.TD({"class":"close","width":"40%"},_28);
237 var _2a=AJS.TBODY(AJS.TR(_26,_27,_29));
238 var _2b=AJS.TABLE({"cellspacing":"0","cellpadding":0,"border":0},_2a);
239 AJS.ACN(_25,_2b);
240 if(this.fullscreen){
241 AJS.AEV(window,"scroll",AJS.$b(this.setWindowPosition,this));
242 }else{
243 AJS.AEV(window,"scroll",AJS.$b(this._setHeaderPos,this));
244 }
245 },setFrameSize:function(){
246 var _2c=this.overlay.offsetWidth;
247 var _2d=AJS.getWindowSize();
248 if(this.fullscreen){
249 this.width=_2c-40;
250 this.height=_2d.h-80;
251 }
252 AJS.setWidth(this.iframe,this.width);
253 AJS.setHeight(this.iframe,this.height);
254 AJS.setWidth(this.header,_2c);
255 },_setHeaderPos:function(){
256 AJS.setTop(this.header,AJS.getScrollTop()+10);
257 },setWindowPosition:function(){
258 var _2e=this.overlay.offsetWidth;
259 var _2f=AJS.getWindowSize();
260 AJS.setLeft(this.g_window,((_2e-50-this.width)/2));
261 var _30=AJS.getScrollTop()+55;
262 if(!this.center_win){
263 AJS.setTop(this.g_window,_30);
264 }else{
265 var fl=((_2f.h-this.height)/2)+20+AJS.getScrollTop();
266 if(fl<0){
267 fl=0;
268 }
269 if(_30>fl){
270 fl=_30;
271 }
272 AJS.setTop(this.g_window,fl);
273 }
274 this._setHeaderPos();
275 },onHide:function(){
276 AJS.removeElement(this.header);
277 AJS.removeClass(this.g_window,"GB_Gallery");
278 },onShow:function(){
279 if(this.use_fx){
280 AJS.fx.fadeIn(this.header,{to:1});
281 }else{
282 AJS.setOpacity(this.header,1);
283 }
284 }});
285 AJS.preloadImages(GB_ROOT_DIR+"g_close.gif");
286 GB_showFullScreenSet=function(set,_33,_34){
287 var _35={type:"page",fullscreen:true,center_win:false};
288 var _36=new GB_Sets(_35,set);
289 _36.addCallback(_34);
290 _36.showSet(_33-1);
291 return false;
292 };
293 GB_showImageSet=function(set,_38,_39){
294 var _3a={type:"image",fullscreen:false,center_win:true,width:300,height:300};
295 var _3b=new GB_Sets(_3a,set);
296 _3b.addCallback(_39);
297 _3b.showSet(_38-1);
298 return false;
299 };
300 GB_Sets=GB_Gallery.extend({init:function(_3c,set){
301 this.parent(_3c);
302 if(!this.img_next){
303 this.img_next=this.root_dir+"next.gif";
304 }
305 if(!this.img_prev){
306 this.img_prev=this.root_dir+"prev.gif";
307 }
308 this.current_set=set;
309 },showSet:function(_3e){
310 this.current_index=_3e;
311 var _3f=this.current_set[this.current_index];
312 this.show(_3f.url);
313 this._setCaption(_3f.caption);
314 this.btn_prev=AJS.IMG({"class":"left",src:this.img_prev});
315 this.btn_next=AJS.IMG({"class":"right",src:this.img_next});
316 AJS.AEV(this.btn_prev,"click",AJS.$b(this.switchPrev,this));
317 AJS.AEV(this.btn_next,"click",AJS.$b(this.switchNext,this));
318 GB_STATUS=AJS.SPAN({"class":"GB_navStatus"});
319 AJS.ACN(AJS.$("GB_middle"),this.btn_prev,GB_STATUS,this.btn_next);
320 this.updateStatus();
321 },updateStatus:function(){
322 AJS.setHTML(GB_STATUS,(this.current_index+1)+" / "+this.current_set.length);
323 if(this.current_index==0){
324 AJS.addClass(this.btn_prev,"disabled");
325 }else{
326 AJS.removeClass(this.btn_prev,"disabled");
327 }
328 if(this.current_index==this.current_set.length-1){
329 AJS.addClass(this.btn_next,"disabled");
330 }else{
331 AJS.removeClass(this.btn_next,"disabled");
332 }
333 },_setCaption:function(_40){
334 AJS.setHTML(AJS.$("GB_caption"),_40);
335 },updateFrame:function(){
336 var _41=this.current_set[this.current_index];
337 this._setCaption(_41.caption);
338 this.url=_41.url;
339 this.startLoading();
340 },switchPrev:function(){
341 if(this.current_index!=0){
342 this.current_index--;
343 this.updateFrame();
344 this.updateStatus();
345 }
346 },switchNext:function(){
347 if(this.current_index!=this.current_set.length-1){
348 this.current_index++;
349 this.updateFrame();
350 this.updateStatus();
351 }
352 }});
353 AJS.AEV(window,"load",function(){
354 AJS.preloadImages(GB_ROOT_DIR+"next.gif",GB_ROOT_DIR+"prev.gif");
355 });
356 GB_show=function(_42,url,_44,_45,_46){
357 var _47={caption:_42,height:_44||500,width:_45||500,fullscreen:false,callback_fn:_46};
358 var win=new GB_Window(_47);
359 return win.show(url);
360 };
361 GB_showCenter=function(_49,url,_4b,_4c,_4d){
362 var _4e={caption:_49,center_win:true,height:_4b||500,width:_4c||500,fullscreen:false,callback_fn:_4d};
363 var win=new GB_Window(_4e);
364 return win.show(url);
365 };
366 GB_showFullScreen=function(_50,url,_52){
367 var _53={caption:_50,fullscreen:true,callback_fn:_52};
368 var win=new GB_Window(_53);
369 return win.show(url);
370 };
371 GB_Window=GreyBox.extend({init:function(_55){
372 this.parent({});
373 this.img_header=this.root_dir+"header_bg.gif";
374 this.img_close=this.root_dir+"w_close.gif";
375 this.show_close_img=true;
376 AJS.update(this,_55);
377 this.addCallback(this.callback_fn);
378 },initHook:function(){
379 AJS.addClass(this.g_window,"GB_Window");
380 this.header=AJS.TABLE({"class":"header"});
381 this.header.style.backgroundImage="url("+this.img_header+")";
382 var _56=AJS.TD({"class":"caption"},this.caption);
383 var _57=AJS.TD({"class":"close"});
384 if(this.show_close_img){
385 var _58=AJS.IMG({"src":this.img_close});
386 var _59=AJS.SPAN("Close");
387 var btn=AJS.DIV(_58,_59);
388 AJS.AEV([_58,_59],"mouseover",function(){
389 AJS.addClass(_59,"on");
390 });
391 AJS.AEV([_58,_59],"mouseout",function(){
392 AJS.removeClass(_59,"on");
393 });
394 AJS.AEV([_58,_59],"mousedown",function(){
395 AJS.addClass(_59,"click");
396 });
397 AJS.AEV([_58,_59],"mouseup",function(){
398 AJS.removeClass(_59,"click");
399 });
400 AJS.AEV([_58,_59],"click",GB_hide);
401 AJS.ACN(_57,btn);
402 }
403 tbody_header=AJS.TBODY();
404 AJS.ACN(tbody_header,AJS.TR(_56,_57));
405 AJS.ACN(this.header,tbody_header);
406 AJS.ACN(this.top_cnt,this.header);
407 if(this.fullscreen){
408 AJS.AEV(window,"scroll",AJS.$b(this.setWindowPosition,this));
409 }
410 },setFrameSize:function(){
411 if(this.fullscreen){
412 var _5b=AJS.getWindowSize();
413 overlay_h=_5b.h;
414 this.width=Math.round(this.overlay.offsetWidth-(this.overlay.offsetWidth/100)*10);
415 this.height=Math.round(overlay_h-(overlay_h/100)*10);
416 }
417 AJS.setWidth(this.header,this.width+6);
418 AJS.setWidth(this.iframe,this.width);
419 AJS.setHeight(this.iframe,this.height);
420 },setWindowPosition:function(){
421 var _5c=AJS.getWindowSize();
422 AJS.setLeft(this.g_window,((_5c.w-this.width)/2)-13);
423 if(!this.center_win){
424 AJS.setTop(this.g_window,AJS.getScrollTop());
425 }else{
426 var fl=((_5c.h-this.height)/2)-20+AJS.getScrollTop();
427 if(fl<0){
428 fl=0;
429 }
430 AJS.setTop(this.g_window,fl);
431 }
432 }});
433 AJS.preloadImages(GB_ROOT_DIR+"w_close.gif",GB_ROOT_DIR+"header_bg.gif");
434
435
436 script_loaded=true;