OSDN Git Service

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