summaryrefslogtreecommitdiff
path: root/frontend/beta/js/YUI-extensions/Layer.js
Unidiff
Diffstat (limited to 'frontend/beta/js/YUI-extensions/Layer.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/beta/js/YUI-extensions/Layer.js246
1 files changed, 246 insertions, 0 deletions
diff --git a/frontend/beta/js/YUI-extensions/Layer.js b/frontend/beta/js/YUI-extensions/Layer.js
new file mode 100644
index 0000000..9eeaf7c
--- a/dev/null
+++ b/frontend/beta/js/YUI-extensions/Layer.js
@@ -0,0 +1,246 @@
1/**
2 * @class YAHOO.ext.Layer
3 * @extends YAHOO.ext.Element
4 * An extended Element object that supports a shadow and shim, constrain to viewport and
5 * automatic maintaining of shadow/shim positions.
6 * @cfg {Boolean} shim False to disable the iframe shim in browsers which need one (defaults to true)
7 * @cfg {String/Boolean} shadow True to create a shadow element with default class "ylayer-shadow" or
8 * you can pass a string with a css class name. False turns off the shadow.
9 * @cfg {Object} dh DomHelper object config to create element with (defaults to {tag: 'div', cls: 'ylayer'}).
10 * @cfg {Boolean} constrain False to disable constrain to viewport (defaults to true)
11 * @cfg {String} cls CSS class to add to the element
12 * @cfg {Number} zindex Starting z-index (defaults to 11000!)
13 * @cfg {Number} shadowOffset Offset for the shadow (defaults to 3)
14 * @constructor
15 * @param {Object} config
16 * @param {String/HTMLElement} existingEl (optional) Uses an existing dom element. If the element is not found it creates it.
17 */
18YAHOO.ext.Layer = function(config, existingEl){
19 config = config || {};
20 var dh = YAHOO.ext.DomHelper;
21 if(existingEl){
22 this.dom = YAHOO.util.Dom.get(existingEl);
23 }
24 if(!this.dom){
25 var o = config.dh || {tag: 'div', cls: 'ylayer'};
26 this.dom = dh.insertBefore(document.body.firstChild, o);
27 }
28 if(config.cls){
29 this.addClass(config.cls);
30 }
31 this.constrain = config.constrain !== false;
32 this.visibilityMode = YAHOO.ext.Element.VISIBILITY;
33 this.id = YAHOO.util.Dom.generateId(this.dom);
34 var zindex = (config.zindex || parseInt(this.getStyle('z-index'), 10)) || 11000;
35 this.setAbsolutePositioned(zindex);
36 if(config.shadow){
37 var cls = (typeof config.shadow == 'string' ? config.shadow : 'ylayer-shadow');
38 this.shadow = dh.insertBefore(this.dom,
39 {tag: 'div', cls: cls}, true);
40 this.shadowOffset = config.shadowOffset || 3;
41 this.shadow.setAbsolutePositioned(zindex-1);
42 }else{
43 this.shadowOffset = 0;
44 }
45 var b = YAHOO.ext.util.Browser;
46 if(config.shim !== false && (b.isIE || (b.isGecko && b.isMac))){
47 this.shim = this.createShim();
48 this.shim.setOpacity(0);
49 this.shim.setAbsolutePositioned(zindex-2);
50 }
51 this.hide();
52};
53YAHOO.extendX(YAHOO.ext.Layer, YAHOO.ext.Element, {
54 sync : function(doShow){
55 if(this.isVisible() && (this.shadow || this.shim)){
56 var b = this.getBox();
57 if(this.shim){
58 if(doShow){
59 this.shim.show();
60 }
61 this.shim.setBox(b);
62 }
63 if(this.shadow){
64 if(doShow){
65 this.shadow.show();
66 }
67 b.x += this.shadowOffset;
68 b.y += this.shadowOffset;
69 this.shadow.setBox(b);
70 }
71 }
72 },
73
74 syncLocalXY : function(){
75 var l = this.getLeft(true);
76 var t = this.getTop(true);
77 if(this.shim){
78 this.shim.setLeftTop(l, t);
79 }
80 if(this.shadow){
81 this.shadow.setLeftTop(l + this.shadowOffset,
82 t + this.shadowOffset);
83 }
84 },
85
86 hideUnders : function(negOffset){
87 if(this.shadow){
88 this.shadow.hide();
89 if(negOffset){
90 this.shadow.setLeftTop(-10000,-10000);
91 }
92 }
93 if(this.shim){
94 this.shim.hide();
95 if(negOffset){
96 this.shim.setLeftTop(-10000,-10000);
97 }
98 }
99 },
100
101 constrainXY : function(){
102 if(this.constrain){
103 var vw = YAHOO.util.Dom.getViewportWidth(),
104 vh = YAHOO.util.Dom.getViewportHeight();
105 var xy = this.getXY();
106 var x = xy[0], y = xy[1];
107 var w = this.dom.offsetWidth+this.shadowOffset, h = this.dom.offsetHeight+this.shadowOffset;
108 // only move it if it needs it
109 var moved = false;
110 // first validate right/bottom
111 if(x + w > vw){
112 x = vw - w;
113 moved = true;
114 }
115 if(y + h > vh){
116 y = vh - h;
117 moved = true;
118 }
119 // then make sure top/left isn't negative
120 if(x < 0){
121 x = 0;
122 moved = true;
123 }
124 if(y < 0){
125 y = 0;
126 moved = true;
127 }
128 if(moved){
129 xy = [x, y];
130 this.lastXY = xy;
131 this.beforeAction();
132 YAHOO.ext.Layer.superclass.setXY.call(this, xy);
133 this.sync(true);
134 }
135 }
136 },
137
138 setVisible : function(v, a, d, c, e){
139 if(this.lastXY){
140 YAHOO.ext.Layer.superclass.setXY.call(this, this.lastXY);
141 }
142 if(a && v){
143 var cb = function(){
144 this.sync(true);
145 if(c){
146 c();
147 }
148 }.createDelegate(this);
149 YAHOO.ext.Layer.superclass.setVisible.call(this, true, true, d, cb, e);
150 }else{
151 if(!v){
152 this.hideUnders(true);
153 }
154 var cb = c;
155 if(a){
156 cb = function(){
157 this.setLeftTop(-10000,-10000);
158 if(c){
159 c();
160 }
161 }.createDelegate(this);
162 }
163 YAHOO.ext.Layer.superclass.setVisible.call(this, v, a, d, cb, e);
164 if(v){
165 this.sync(true);
166 }else if(!a){
167 this.setLeftTop(-10000,-10000);
168 }
169 }
170 },
171
172 beforeAction : function(){
173 if(this.shadow){
174 this.shadow.hide();
175 }
176 },
177
178 setXY : function(xy, a, d, c, e){
179 this.lastXY = xy;
180 this.beforeAction();
181 var cb = this.createCB(c);
182 YAHOO.ext.Layer.superclass.setXY.call(this, xy, a, d, cb, e);
183 if(!a){
184 cb();
185 }
186 },
187
188 createCB : function(c){
189 var el = this;
190 return function(){
191 el.constrainXY();
192 el.sync(true);
193 if(c){
194 c();
195 }
196 };
197 },
198
199 setX : function(x, a, d, c, e){
200 this.setXY([x, this.getY()], a, d, c, e);
201 },
202
203 setY : function(y, a, d, c, e){
204 this.setXY([this.getX(), y], a, d, c, e);
205 },
206
207 setSize : function(w, h, a, d, c, e){
208 this.beforeAction();
209 var cb = this.createCB(c);
210 YAHOO.ext.Layer.superclass.setSize.call(this, w, h, a, d, cb, e);
211 if(!a){
212 cb();
213 }
214 },
215
216 setWidth : function(w, a, d, c, e){
217 this.beforeAction();
218 var cb = this.createCB(c);
219 YAHOO.ext.Layer.superclass.setWidth.call(this, w, a, d, cb, e);
220 if(!a){
221 cb();
222 }
223 },
224
225 setHeight : function(h, a, d, c, e){
226 this.beforeAction();
227 var cb = this.createCB(c);
228 YAHOO.ext.Layer.superclass.setHeight.call(this, h, a, d, cb, e);
229 if(!a){
230 cb();
231 }
232 },
233
234 setBounds : function(x, y, w, h, a, d, c, e){
235 this.beforeAction();
236 var cb = this.createCB(c);
237 if(!a){
238 YAHOO.ext.Layer.superclass.setXY.call(this, [x, y]);
239 YAHOO.ext.Layer.superclass.setSize.call(this, w, h, a, d, cb, e);
240 cb();
241 }else{
242 YAHOO.ext.Layer.superclass.setBounds.call(this, x, y, w, h, a, d, cb, e);
243 }
244 return this;
245 }
246});