OSDN Git Service

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