root / trunk / web / dojo / dojox / image / LightboxNano.js @ 12
History | View | Annotate | Download (3.95 KB)
1 | 9 | andrej.cim | /*
|
---|---|---|---|
2 | Copyright (c) 2004-2010, The Dojo Foundation All Rights Reserved.
|
||
3 | Available via Academic Free License >= 2.1 OR the modified BSD license.
|
||
4 | see: http://dojotoolkit.org/license for details
|
||
5 | */
|
||
6 | |||
7 | |||
8 | if(!dojo._hasResource["dojox.image.LightboxNano"]){ |
||
9 | dojo._hasResource["dojox.image.LightboxNano"]=true; |
||
10 | dojo.provide("dojox.image.LightboxNano");
|
||
11 | dojo.require("dojo.fx");
|
||
12 | (function(d){
|
||
13 | var _1="absolute",_2="visibility",_3=function(){ |
||
14 | var _4=(d.doc.compatMode=="BackCompat")?d.body():d.doc.documentElement,_5=dojo._docScroll(); |
||
15 | return {w:_4.clientWidth,h:_4.clientHeight,l:_5.x,t:_5.y}; |
||
16 | }; |
||
17 | d.declare("dojox.image.LightboxNano",null,{href:"",duration:500,preloadDelay:5000,constructor:function(p,n){ |
||
18 | var _6=this; |
||
19 | d.mixin(_6,p); |
||
20 | n=_6._node=dojo.byId(n); |
||
21 | if(n){
|
||
22 | if(!/a/i.test(n.tagName)){ |
||
23 | var a=d.create("a",{href:_6.href,"class":n.className},n,"after"); |
||
24 | n.className="";
|
||
25 | a.appendChild(n); |
||
26 | n=a; |
||
27 | } |
||
28 | d.style(n,"position","relative"); |
||
29 | _6._createDiv("dojoxEnlarge",n);
|
||
30 | d.setSelectable(n,false);
|
||
31 | _6._onClickEvt=d.connect(n,"onclick",_6,"_load"); |
||
32 | } |
||
33 | if(_6.href){
|
||
34 | setTimeout(function(){
|
||
35 | (new Image()).src=_6.href;
|
||
36 | _6._hideLoading(); |
||
37 | },_6.preloadDelay); |
||
38 | } |
||
39 | },destroy:function(){ |
||
40 | var a=this._connects||[]; |
||
41 | a.push(this._onClickEvt);
|
||
42 | d.forEach(a,d.disconnect); |
||
43 | d.destroy(this._node);
|
||
44 | },_createDiv:function(_7,_8,_9){ |
||
45 | return d.create("div",{"class":_7,style:{position:_1,display:_9?"":"none"}},_8); |
||
46 | },_load:function(e){ |
||
47 | var _a=this; |
||
48 | e&&d.stopEvent(e); |
||
49 | if(!_a._loading){
|
||
50 | _a._loading=true;
|
||
51 | _a._reset(); |
||
52 | var i=_a._img=d.create("img",{style:{visibility:"hidden",cursor:"pointer",position:_1,top:0,left:0,zIndex:9999999}},d.body()),ln=_a._loadingNode,n=d.query("img",_a._node)[0]||_a._node,a=d.position(n,true),c=d.contentBox(n),b=d._getBorderExtents(n); |
||
53 | if(ln==null){ |
||
54 | _a._loadingNode=ln=_a._createDiv("dojoxLoading",_a._node,true); |
||
55 | var l=d.marginBox(ln);
|
||
56 | d.style(ln,{left:parseInt((c.w-l.w)/2)+"px",top:parseInt((c.h-l.h)/2)+"px"}); |
||
57 | } |
||
58 | c.x=a.x-10+b.l;
|
||
59 | c.y=a.y-10+b.t;
|
||
60 | _a._start=c; |
||
61 | _a._connects=[d.connect(i,"onload",_a,"_show")]; |
||
62 | i.src=_a.href; |
||
63 | } |
||
64 | },_hideLoading:function(){ |
||
65 | if(this._loadingNode){ |
||
66 | d.style(this._loadingNode,"display","none"); |
||
67 | } |
||
68 | this._loadingNode=false; |
||
69 | },_show:function(){ |
||
70 | var _b=this,vp=_3(),w=_b._img.width,h=_b._img.height,_c=parseInt((vp.w-20)*0.9),_d=parseInt((vp.h-20)*0.9),dd=d.doc,bg=_b._bg=d.create("div",{style:{backgroundColor:"#000",opacity:0,position:_1,zIndex:9999998}},d.body()),ln=_b._loadingNode; |
||
71 | if(_b._loadingNode){
|
||
72 | _b._hideLoading(); |
||
73 | } |
||
74 | d.style(_b._img,{border:"10px solid #fff",visibility:"visible"}); |
||
75 | d.style(_b._node,_2,"hidden");
|
||
76 | _b._loading=false;
|
||
77 | _b._connects=_b._connects.concat([d.connect(dd,"onmousedown",_b,"_hide"),d.connect(dd,"onkeypress",_b,"_key"),d.connect(window,"onresize",_b,"_sizeBg")]); |
||
78 | if(w>_c){
|
||
79 | h=h*_c/w; |
||
80 | w=_c; |
||
81 | } |
||
82 | if(h>_d){
|
||
83 | w=w*_d/h; |
||
84 | h=_d; |
||
85 | } |
||
86 | _b._end={x:(vp.w-20-w)/2+vp.l,y:(vp.h-20-h)/2+vp.t,w:w,h:h}; |
||
87 | _b._sizeBg(); |
||
88 | d.fx.combine([_b._anim(_b._img,_b._coords(_b._start,_b._end)),_b._anim(bg,{opacity:0.5})]).play(); |
||
89 | },_sizeBg:function(){ |
||
90 | var dd=d.doc.documentElement;
|
||
91 | d.style(this._bg,{top:0,left:0,width:dd.scrollWidth+"px",height:dd.scrollHeight+"px"}); |
||
92 | },_key:function(e){ |
||
93 | d.stopEvent(e); |
||
94 | this._hide();
|
||
95 | },_coords:function(s,e){ |
||
96 | return {left:{start:s.x,end:e.x},top:{start:s.y,end:e.y},width:{start:s.w,end:e.w},height:{start:s.h,end:e.h}}; |
||
97 | },_hide:function(){ |
||
98 | var _e=this; |
||
99 | d.forEach(_e._connects,d.disconnect); |
||
100 | _e._connects=[]; |
||
101 | d.fx.combine([_e._anim(_e._img,_e._coords(_e._end,_e._start),"_reset"),_e._anim(_e._bg,{opacity:0})]).play(); |
||
102 | },_reset:function(){ |
||
103 | d.style(this._node,_2,"visible"); |
||
104 | d.forEach([this._img,this._bg],function(n){ |
||
105 | d.destroy(n); |
||
106 | n=null;
|
||
107 | }); |
||
108 | this._node.focus();
|
||
109 | },_anim:function(_f,_10,_11){ |
||
110 | return d.animateProperty({node:_f,duration:this.duration,properties:_10,onEnd:_11?d.hitch(this,_11):null}); |
||
111 | },show:function(_12){ |
||
112 | _12=_12||{}; |
||
113 | this.href=_12.href||this.href; |
||
114 | var n=d.byId(_12.origin),vp=_3();
|
||
115 | this._node=n||d.create("div",{style:{position:_1,width:0,hieght:0,left:(vp.l+(vp.w/2))+"px",top:(vp.t+(vp.h/2))+"px"}},d.body()); |
||
116 | this._load();
|
||
117 | if(!n){
|
||
118 | d.destroy(this._node);
|
||
119 | } |
||
120 | }}); |
||
121 | })(dojo); |
||
122 | } |