|
525
|
1 |
/* |
|
|
2 |
YUI 3.10.3 (build 2fb5187) |
|
|
3 |
Copyright 2013 Yahoo! Inc. All rights reserved. |
|
|
4 |
Licensed under the BSD License. |
|
|
5 |
http://yuilibrary.com/license/ |
|
|
6 |
*/ |
|
|
7 |
|
|
|
8 |
YUI.add('widget-position-align', function (Y, NAME) { |
|
|
9 |
|
|
|
10 |
/** |
|
|
11 |
Provides extended/advanced XY positioning support for Widgets, through an |
|
|
12 |
extension. |
|
|
13 |
|
|
|
14 |
It builds on top of the `widget-position` module, to provide alignment and |
|
|
15 |
centering support. Future releases aim to add constrained and fixed positioning |
|
|
16 |
support. |
|
|
17 |
|
|
|
18 |
@module widget-position-align |
|
|
19 |
**/ |
|
|
20 |
var Lang = Y.Lang, |
|
|
21 |
|
|
|
22 |
ALIGN = 'align', |
|
|
23 |
ALIGN_ON = 'alignOn', |
|
|
24 |
|
|
|
25 |
VISIBLE = 'visible', |
|
|
26 |
BOUNDING_BOX = 'boundingBox', |
|
|
27 |
|
|
|
28 |
OFFSET_WIDTH = 'offsetWidth', |
|
|
29 |
OFFSET_HEIGHT = 'offsetHeight', |
|
|
30 |
REGION = 'region', |
|
|
31 |
VIEWPORT_REGION = 'viewportRegion'; |
|
|
32 |
|
|
|
33 |
/** |
|
|
34 |
Widget extension, which can be used to add extended XY positioning support to |
|
|
35 |
the base Widget class, through the `Base.create` method. |
|
|
36 |
|
|
|
37 |
**Note:** This extension requires that the `WidgetPosition` extension be added |
|
|
38 |
to the Widget (before `WidgetPositionAlign`, if part of the same extension list |
|
|
39 |
passed to `Base.build`). |
|
|
40 |
|
|
|
41 |
@class WidgetPositionAlign |
|
|
42 |
@param {Object} config User configuration object. |
|
|
43 |
@constructor |
|
|
44 |
**/ |
|
|
45 |
function PositionAlign (config) { |
|
|
46 |
if ( ! this._posNode) { |
|
|
47 |
Y.error('WidgetPosition needs to be added to the Widget, ' + |
|
|
48 |
'before WidgetPositionAlign is added'); |
|
|
49 |
} |
|
|
50 |
|
|
|
51 |
Y.after(this._bindUIPosAlign, this, 'bindUI'); |
|
|
52 |
Y.after(this._syncUIPosAlign, this, 'syncUI'); |
|
|
53 |
} |
|
|
54 |
|
|
|
55 |
PositionAlign.ATTRS = { |
|
|
56 |
|
|
|
57 |
/** |
|
|
58 |
The alignment configuration for this widget. |
|
|
59 |
|
|
|
60 |
The `align` attribute is used to align a reference point on the widget, with |
|
|
61 |
the reference point on another `Node`, or the viewport. The object which |
|
|
62 |
`align` expects has the following properties: |
|
|
63 |
|
|
|
64 |
* __`node`__: The `Node` to which the widget is to be aligned. If set to |
|
|
65 |
`null`, or not provided, the widget is aligned to the viewport. |
|
|
66 |
|
|
|
67 |
* __`points`__: A two element Array, defining the two points on the widget |
|
|
68 |
and `Node`/viewport which are to be aligned. The first element is the |
|
|
69 |
point on the widget, and the second element is the point on the |
|
|
70 |
`Node`/viewport. Supported alignment points are defined as static |
|
|
71 |
properties on `WidgetPositionAlign`. |
|
|
72 |
|
|
|
73 |
@example Aligns the top-right corner of the widget with the top-left corner |
|
|
74 |
of the viewport: |
|
|
75 |
|
|
|
76 |
myWidget.set('align', { |
|
|
77 |
points: [Y.WidgetPositionAlign.TR, Y.WidgetPositionAlign.TL] |
|
|
78 |
}); |
|
|
79 |
|
|
|
80 |
@attribute align |
|
|
81 |
@type Object |
|
|
82 |
@default null |
|
|
83 |
**/ |
|
|
84 |
align: { |
|
|
85 |
value: null |
|
|
86 |
}, |
|
|
87 |
|
|
|
88 |
/** |
|
|
89 |
A convenience Attribute, which can be used as a shortcut for the `align` |
|
|
90 |
Attribute. |
|
|
91 |
|
|
|
92 |
If set to `true`, the widget is centered in the viewport. If set to a `Node` |
|
|
93 |
reference or valid selector String, the widget will be centered within the |
|
|
94 |
`Node`. If set to `false`, no center positioning is applied. |
|
|
95 |
|
|
|
96 |
@attribute centered |
|
|
97 |
@type Boolean|Node |
|
|
98 |
@default false |
|
|
99 |
**/ |
|
|
100 |
centered: { |
|
|
101 |
setter : '_setAlignCenter', |
|
|
102 |
lazyAdd:false, |
|
|
103 |
value :false |
|
|
104 |
}, |
|
|
105 |
|
|
|
106 |
/** |
|
|
107 |
An Array of Objects corresponding to the `Node`s and events that will cause |
|
|
108 |
the alignment of this widget to be synced to the DOM. |
|
|
109 |
|
|
|
110 |
The `alignOn` Attribute is expected to be an Array of Objects with the |
|
|
111 |
following properties: |
|
|
112 |
|
|
|
113 |
* __`eventName`__: The String event name to listen for. |
|
|
114 |
|
|
|
115 |
* __`node`__: The optional `Node` that will fire the event, it can be a |
|
|
116 |
`Node` reference or a selector String. This will default to the widget's |
|
|
117 |
`boundingBox`. |
|
|
118 |
|
|
|
119 |
@example Sync this widget's alignment on window resize: |
|
|
120 |
|
|
|
121 |
myWidget.set('alignOn', [ |
|
|
122 |
{ |
|
|
123 |
node : Y.one('win'), |
|
|
124 |
eventName: 'resize' |
|
|
125 |
} |
|
|
126 |
]); |
|
|
127 |
|
|
|
128 |
@attribute alignOn |
|
|
129 |
@type Array |
|
|
130 |
@default [] |
|
|
131 |
**/ |
|
|
132 |
alignOn: { |
|
|
133 |
value : [], |
|
|
134 |
validator: Y.Lang.isArray |
|
|
135 |
} |
|
|
136 |
}; |
|
|
137 |
|
|
|
138 |
/** |
|
|
139 |
Constant used to specify the top-left corner for alignment |
|
|
140 |
|
|
|
141 |
@property TL |
|
|
142 |
@type String |
|
|
143 |
@value 'tl' |
|
|
144 |
@static |
|
|
145 |
**/ |
|
|
146 |
PositionAlign.TL = 'tl'; |
|
|
147 |
|
|
|
148 |
/** |
|
|
149 |
Constant used to specify the top-right corner for alignment |
|
|
150 |
|
|
|
151 |
@property TR |
|
|
152 |
@type String |
|
|
153 |
@value 'tr' |
|
|
154 |
@static |
|
|
155 |
**/ |
|
|
156 |
PositionAlign.TR = 'tr'; |
|
|
157 |
|
|
|
158 |
/** |
|
|
159 |
Constant used to specify the bottom-left corner for alignment |
|
|
160 |
|
|
|
161 |
@property BL |
|
|
162 |
@type String |
|
|
163 |
@value 'bl' |
|
|
164 |
@static |
|
|
165 |
**/ |
|
|
166 |
PositionAlign.BL = 'bl'; |
|
|
167 |
|
|
|
168 |
/** |
|
|
169 |
Constant used to specify the bottom-right corner for alignment |
|
|
170 |
|
|
|
171 |
@property BR |
|
|
172 |
@type String |
|
|
173 |
@value 'br' |
|
|
174 |
@static |
|
|
175 |
**/ |
|
|
176 |
PositionAlign.BR = 'br'; |
|
|
177 |
|
|
|
178 |
/** |
|
|
179 |
Constant used to specify the top edge-center point for alignment |
|
|
180 |
|
|
|
181 |
@property TC |
|
|
182 |
@type String |
|
|
183 |
@value 'tc' |
|
|
184 |
@static |
|
|
185 |
**/ |
|
|
186 |
PositionAlign.TC = 'tc'; |
|
|
187 |
|
|
|
188 |
/** |
|
|
189 |
Constant used to specify the right edge, center point for alignment |
|
|
190 |
|
|
|
191 |
@property RC |
|
|
192 |
@type String |
|
|
193 |
@value 'rc' |
|
|
194 |
@static |
|
|
195 |
**/ |
|
|
196 |
PositionAlign.RC = 'rc'; |
|
|
197 |
|
|
|
198 |
/** |
|
|
199 |
Constant used to specify the bottom edge, center point for alignment |
|
|
200 |
|
|
|
201 |
@property BC |
|
|
202 |
@type String |
|
|
203 |
@value 'bc' |
|
|
204 |
@static |
|
|
205 |
**/ |
|
|
206 |
PositionAlign.BC = 'bc'; |
|
|
207 |
|
|
|
208 |
/** |
|
|
209 |
Constant used to specify the left edge, center point for alignment |
|
|
210 |
|
|
|
211 |
@property LC |
|
|
212 |
@type String |
|
|
213 |
@value 'lc' |
|
|
214 |
@static |
|
|
215 |
**/ |
|
|
216 |
PositionAlign.LC = 'lc'; |
|
|
217 |
|
|
|
218 |
/** |
|
|
219 |
Constant used to specify the center of widget/node/viewport for alignment |
|
|
220 |
|
|
|
221 |
@property CC |
|
|
222 |
@type String |
|
|
223 |
@value 'cc' |
|
|
224 |
@static |
|
|
225 |
*/ |
|
|
226 |
PositionAlign.CC = 'cc'; |
|
|
227 |
|
|
|
228 |
PositionAlign.prototype = { |
|
|
229 |
// -- Protected Properties ------------------------------------------------- |
|
|
230 |
|
|
|
231 |
/** |
|
|
232 |
Holds the alignment-syncing event handles. |
|
|
233 |
|
|
|
234 |
@property _posAlignUIHandles |
|
|
235 |
@type Array |
|
|
236 |
@default null |
|
|
237 |
@protected |
|
|
238 |
**/ |
|
|
239 |
_posAlignUIHandles: null, |
|
|
240 |
|
|
|
241 |
// -- Lifecycle Methods ---------------------------------------------------- |
|
|
242 |
|
|
|
243 |
destructor: function () { |
|
|
244 |
this._detachPosAlignUIHandles(); |
|
|
245 |
}, |
|
|
246 |
|
|
|
247 |
/** |
|
|
248 |
Bind event listeners responsible for updating the UI state in response to |
|
|
249 |
the widget's position-align related state changes. |
|
|
250 |
|
|
|
251 |
This method is invoked after `bindUI` has been invoked for the `Widget` |
|
|
252 |
class using the AOP infrastructure. |
|
|
253 |
|
|
|
254 |
@method _bindUIPosAlign |
|
|
255 |
@protected |
|
|
256 |
**/ |
|
|
257 |
_bindUIPosAlign: function () { |
|
|
258 |
this.after('alignChange', this._afterAlignChange); |
|
|
259 |
this.after('alignOnChange', this._afterAlignOnChange); |
|
|
260 |
this.after('visibleChange', this._syncUIPosAlign); |
|
|
261 |
}, |
|
|
262 |
|
|
|
263 |
/** |
|
|
264 |
Synchronizes the current `align` Attribute value to the DOM. |
|
|
265 |
|
|
|
266 |
This method is invoked after `syncUI` has been invoked for the `Widget` |
|
|
267 |
class using the AOP infrastructure. |
|
|
268 |
|
|
|
269 |
@method _syncUIPosAlign |
|
|
270 |
@protected |
|
|
271 |
**/ |
|
|
272 |
_syncUIPosAlign: function () { |
|
|
273 |
var align = this.get(ALIGN); |
|
|
274 |
|
|
|
275 |
this._uiSetVisiblePosAlign(this.get(VISIBLE)); |
|
|
276 |
|
|
|
277 |
if (align) { |
|
|
278 |
this._uiSetAlign(align.node, align.points); |
|
|
279 |
} |
|
|
280 |
}, |
|
|
281 |
|
|
|
282 |
// -- Public Methods ------------------------------------------------------- |
|
|
283 |
|
|
|
284 |
/** |
|
|
285 |
Aligns this widget to the provided `Node` (or viewport) using the provided |
|
|
286 |
points. This method can be invoked with no arguments which will cause the |
|
|
287 |
widget's current `align` Attribute value to be synced to the DOM. |
|
|
288 |
|
|
|
289 |
@example Aligning to the top-left corner of the `<body>`: |
|
|
290 |
|
|
|
291 |
myWidget.align('body', |
|
|
292 |
[Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.TR]); |
|
|
293 |
|
|
|
294 |
@method align |
|
|
295 |
@param {Node|String|null} [node] A reference (or selector String) for the |
|
|
296 |
`Node` which with the widget is to be aligned. If null is passed in, the |
|
|
297 |
widget will be aligned with the viewport. |
|
|
298 |
@param {Array[2]} [points] A two item array specifying the points on the |
|
|
299 |
widget and `Node`/viewport which will to be aligned. The first entry is |
|
|
300 |
the point on the widget, and the second entry is the point on the |
|
|
301 |
`Node`/viewport. Valid point references are defined as static constants on |
|
|
302 |
the `WidgetPositionAlign` extension. |
|
|
303 |
@chainable |
|
|
304 |
**/ |
|
|
305 |
align: function (node, points) { |
|
|
306 |
if (arguments.length) { |
|
|
307 |
// Set the `align` Attribute. |
|
|
308 |
this.set(ALIGN, { |
|
|
309 |
node : node, |
|
|
310 |
points: points |
|
|
311 |
}); |
|
|
312 |
} else { |
|
|
313 |
// Sync the current `align` Attribute value to the DOM. |
|
|
314 |
this._syncUIPosAlign(); |
|
|
315 |
} |
|
|
316 |
|
|
|
317 |
return this; |
|
|
318 |
}, |
|
|
319 |
|
|
|
320 |
/** |
|
|
321 |
Centers the widget in the viewport, or if a `Node` is passed in, it will |
|
|
322 |
be centered to that `Node`. |
|
|
323 |
|
|
|
324 |
@method centered |
|
|
325 |
@param {Node|String} [node] A `Node` reference or selector String defining |
|
|
326 |
the `Node` which the widget should be centered. If a `Node` is not passed |
|
|
327 |
in, then the widget will be centered to the viewport. |
|
|
328 |
@chainable |
|
|
329 |
**/ |
|
|
330 |
centered: function (node) { |
|
|
331 |
return this.align(node, [PositionAlign.CC, PositionAlign.CC]); |
|
|
332 |
}, |
|
|
333 |
|
|
|
334 |
// -- Protected Methods ---------------------------------------------------- |
|
|
335 |
|
|
|
336 |
/** |
|
|
337 |
Default setter for `center` Attribute changes. Sets up the appropriate |
|
|
338 |
value, and passes it through the to the align attribute. |
|
|
339 |
|
|
|
340 |
@method _setAlignCenter |
|
|
341 |
@param {Boolean|Node} val The Attribute value being set. |
|
|
342 |
@return {Boolean|Node} the value passed in. |
|
|
343 |
@protected |
|
|
344 |
**/ |
|
|
345 |
_setAlignCenter: function (val) { |
|
|
346 |
if (val) { |
|
|
347 |
this.set(ALIGN, { |
|
|
348 |
node : val === true ? null : val, |
|
|
349 |
points: [PositionAlign.CC, PositionAlign.CC] |
|
|
350 |
}); |
|
|
351 |
} |
|
|
352 |
|
|
|
353 |
return val; |
|
|
354 |
}, |
|
|
355 |
|
|
|
356 |
/** |
|
|
357 |
Updates the UI to reflect the `align` value passed in. |
|
|
358 |
|
|
|
359 |
**Note:** See the `align` Attribute documentation, for the Object structure |
|
|
360 |
expected. |
|
|
361 |
|
|
|
362 |
@method _uiSetAlign |
|
|
363 |
@param {Node|String|null} [node] The node to align to, or null to indicate |
|
|
364 |
the viewport. |
|
|
365 |
@param {Array} points The alignment points. |
|
|
366 |
@protected |
|
|
367 |
**/ |
|
|
368 |
_uiSetAlign: function (node, points) { |
|
|
369 |
if ( ! Lang.isArray(points) || points.length !== 2) { |
|
|
370 |
Y.error('align: Invalid Points Arguments'); |
|
|
371 |
return; |
|
|
372 |
} |
|
|
373 |
|
|
|
374 |
var nodeRegion = this._getRegion(node), |
|
|
375 |
widgetPoint, nodePoint, xy; |
|
|
376 |
|
|
|
377 |
if ( ! nodeRegion) { |
|
|
378 |
// No-op, nothing to align to. |
|
|
379 |
return; |
|
|
380 |
} |
|
|
381 |
|
|
|
382 |
widgetPoint = points[0]; |
|
|
383 |
nodePoint = points[1]; |
|
|
384 |
|
|
|
385 |
// TODO: Optimize KWeight - Would lookup table help? |
|
|
386 |
switch (nodePoint) { |
|
|
387 |
case PositionAlign.TL: |
|
|
388 |
xy = [nodeRegion.left, nodeRegion.top]; |
|
|
389 |
break; |
|
|
390 |
|
|
|
391 |
case PositionAlign.TR: |
|
|
392 |
xy = [nodeRegion.right, nodeRegion.top]; |
|
|
393 |
break; |
|
|
394 |
|
|
|
395 |
case PositionAlign.BL: |
|
|
396 |
xy = [nodeRegion.left, nodeRegion.bottom]; |
|
|
397 |
break; |
|
|
398 |
|
|
|
399 |
case PositionAlign.BR: |
|
|
400 |
xy = [nodeRegion.right, nodeRegion.bottom]; |
|
|
401 |
break; |
|
|
402 |
|
|
|
403 |
case PositionAlign.TC: |
|
|
404 |
xy = [ |
|
|
405 |
nodeRegion.left + Math.floor(nodeRegion.width / 2), |
|
|
406 |
nodeRegion.top |
|
|
407 |
]; |
|
|
408 |
break; |
|
|
409 |
|
|
|
410 |
case PositionAlign.BC: |
|
|
411 |
xy = [ |
|
|
412 |
nodeRegion.left + Math.floor(nodeRegion.width / 2), |
|
|
413 |
nodeRegion.bottom |
|
|
414 |
]; |
|
|
415 |
break; |
|
|
416 |
|
|
|
417 |
case PositionAlign.LC: |
|
|
418 |
xy = [ |
|
|
419 |
nodeRegion.left, |
|
|
420 |
nodeRegion.top + Math.floor(nodeRegion.height / 2) |
|
|
421 |
]; |
|
|
422 |
break; |
|
|
423 |
|
|
|
424 |
case PositionAlign.RC: |
|
|
425 |
xy = [ |
|
|
426 |
nodeRegion.right, |
|
|
427 |
nodeRegion.top + Math.floor(nodeRegion.height / 2) |
|
|
428 |
]; |
|
|
429 |
break; |
|
|
430 |
|
|
|
431 |
case PositionAlign.CC: |
|
|
432 |
xy = [ |
|
|
433 |
nodeRegion.left + Math.floor(nodeRegion.width / 2), |
|
|
434 |
nodeRegion.top + Math.floor(nodeRegion.height / 2) |
|
|
435 |
]; |
|
|
436 |
break; |
|
|
437 |
|
|
|
438 |
default: |
|
|
439 |
Y.log('align: Invalid Points Arguments', 'info', |
|
|
440 |
'widget-position-align'); |
|
|
441 |
break; |
|
|
442 |
|
|
|
443 |
} |
|
|
444 |
|
|
|
445 |
if (xy) { |
|
|
446 |
this._doAlign(widgetPoint, xy[0], xy[1]); |
|
|
447 |
} |
|
|
448 |
}, |
|
|
449 |
|
|
|
450 |
/** |
|
|
451 |
Attaches or detaches alignment-syncing event handlers based on the widget's |
|
|
452 |
`visible` Attribute state. |
|
|
453 |
|
|
|
454 |
@method _uiSetVisiblePosAlign |
|
|
455 |
@param {Boolean} visible The current value of the widget's `visible` |
|
|
456 |
Attribute. |
|
|
457 |
@protected |
|
|
458 |
**/ |
|
|
459 |
_uiSetVisiblePosAlign: function (visible) { |
|
|
460 |
if (visible) { |
|
|
461 |
this._attachPosAlignUIHandles(); |
|
|
462 |
} else { |
|
|
463 |
this._detachPosAlignUIHandles(); |
|
|
464 |
} |
|
|
465 |
}, |
|
|
466 |
|
|
|
467 |
/** |
|
|
468 |
Attaches the alignment-syncing event handlers. |
|
|
469 |
|
|
|
470 |
@method _attachPosAlignUIHandles |
|
|
471 |
@protected |
|
|
472 |
**/ |
|
|
473 |
_attachPosAlignUIHandles: function () { |
|
|
474 |
if (this._posAlignUIHandles) { |
|
|
475 |
// No-op if we have already setup the event handlers. |
|
|
476 |
return; |
|
|
477 |
} |
|
|
478 |
|
|
|
479 |
var bb = this.get(BOUNDING_BOX), |
|
|
480 |
syncAlign = Y.bind(this._syncUIPosAlign, this), |
|
|
481 |
handles = []; |
|
|
482 |
|
|
|
483 |
Y.Array.each(this.get(ALIGN_ON), function (o) { |
|
|
484 |
var event = o.eventName, |
|
|
485 |
node = Y.one(o.node) || bb; |
|
|
486 |
|
|
|
487 |
if (event) { |
|
|
488 |
handles.push(node.on(event, syncAlign)); |
|
|
489 |
} |
|
|
490 |
}); |
|
|
491 |
|
|
|
492 |
this._posAlignUIHandles = handles; |
|
|
493 |
}, |
|
|
494 |
|
|
|
495 |
/** |
|
|
496 |
Detaches the alignment-syncing event handlers. |
|
|
497 |
|
|
|
498 |
@method _detachPosAlignUIHandles |
|
|
499 |
@protected |
|
|
500 |
**/ |
|
|
501 |
_detachPosAlignUIHandles: function () { |
|
|
502 |
var handles = this._posAlignUIHandles; |
|
|
503 |
if (handles) { |
|
|
504 |
new Y.EventHandle(handles).detach(); |
|
|
505 |
this._posAlignUIHandles = null; |
|
|
506 |
} |
|
|
507 |
}, |
|
|
508 |
|
|
|
509 |
// -- Private Methods ------------------------------------------------------ |
|
|
510 |
|
|
|
511 |
/** |
|
|
512 |
Helper method, used to align the given point on the widget, with the XY page |
|
|
513 |
coordinates provided. |
|
|
514 |
|
|
|
515 |
@method _doAlign |
|
|
516 |
@param {String} widgetPoint Supported point constant |
|
|
517 |
(e.g. WidgetPositionAlign.TL) |
|
|
518 |
@param {Number} x X page coordinate to align to. |
|
|
519 |
@param {Number} y Y page coordinate to align to. |
|
|
520 |
@private |
|
|
521 |
**/ |
|
|
522 |
_doAlign: function (widgetPoint, x, y) { |
|
|
523 |
var widgetNode = this._posNode, |
|
|
524 |
xy; |
|
|
525 |
|
|
|
526 |
switch (widgetPoint) { |
|
|
527 |
case PositionAlign.TL: |
|
|
528 |
xy = [x, y]; |
|
|
529 |
break; |
|
|
530 |
|
|
|
531 |
case PositionAlign.TR: |
|
|
532 |
xy = [ |
|
|
533 |
x - widgetNode.get(OFFSET_WIDTH), |
|
|
534 |
y |
|
|
535 |
]; |
|
|
536 |
break; |
|
|
537 |
|
|
|
538 |
case PositionAlign.BL: |
|
|
539 |
xy = [ |
|
|
540 |
x, |
|
|
541 |
y - widgetNode.get(OFFSET_HEIGHT) |
|
|
542 |
]; |
|
|
543 |
break; |
|
|
544 |
|
|
|
545 |
case PositionAlign.BR: |
|
|
546 |
xy = [ |
|
|
547 |
x - widgetNode.get(OFFSET_WIDTH), |
|
|
548 |
y - widgetNode.get(OFFSET_HEIGHT) |
|
|
549 |
]; |
|
|
550 |
break; |
|
|
551 |
|
|
|
552 |
case PositionAlign.TC: |
|
|
553 |
xy = [ |
|
|
554 |
x - (widgetNode.get(OFFSET_WIDTH) / 2), |
|
|
555 |
y |
|
|
556 |
]; |
|
|
557 |
break; |
|
|
558 |
|
|
|
559 |
case PositionAlign.BC: |
|
|
560 |
xy = [ |
|
|
561 |
x - (widgetNode.get(OFFSET_WIDTH) / 2), |
|
|
562 |
y - widgetNode.get(OFFSET_HEIGHT) |
|
|
563 |
]; |
|
|
564 |
break; |
|
|
565 |
|
|
|
566 |
case PositionAlign.LC: |
|
|
567 |
xy = [ |
|
|
568 |
x, |
|
|
569 |
y - (widgetNode.get(OFFSET_HEIGHT) / 2) |
|
|
570 |
]; |
|
|
571 |
break; |
|
|
572 |
|
|
|
573 |
case PositionAlign.RC: |
|
|
574 |
xy = [ |
|
|
575 |
x - widgetNode.get(OFFSET_WIDTH), |
|
|
576 |
y - (widgetNode.get(OFFSET_HEIGHT) / 2) |
|
|
577 |
]; |
|
|
578 |
break; |
|
|
579 |
|
|
|
580 |
case PositionAlign.CC: |
|
|
581 |
xy = [ |
|
|
582 |
x - (widgetNode.get(OFFSET_WIDTH) / 2), |
|
|
583 |
y - (widgetNode.get(OFFSET_HEIGHT) / 2) |
|
|
584 |
]; |
|
|
585 |
break; |
|
|
586 |
|
|
|
587 |
default: |
|
|
588 |
Y.log('align: Invalid Points Argument', 'info', |
|
|
589 |
'widget-position-align'); |
|
|
590 |
break; |
|
|
591 |
|
|
|
592 |
} |
|
|
593 |
|
|
|
594 |
if (xy) { |
|
|
595 |
this.move(xy); |
|
|
596 |
} |
|
|
597 |
}, |
|
|
598 |
|
|
|
599 |
/** |
|
|
600 |
Returns the region of the passed-in `Node`, or the viewport region if |
|
|
601 |
calling with passing in a `Node`. |
|
|
602 |
|
|
|
603 |
@method _getRegion |
|
|
604 |
@param {Node} [node] The node to get the region of. |
|
|
605 |
@return {Object} The node's region. |
|
|
606 |
@private |
|
|
607 |
**/ |
|
|
608 |
_getRegion: function (node) { |
|
|
609 |
var nodeRegion; |
|
|
610 |
|
|
|
611 |
if ( ! node) { |
|
|
612 |
nodeRegion = this._posNode.get(VIEWPORT_REGION); |
|
|
613 |
} else { |
|
|
614 |
node = Y.Node.one(node); |
|
|
615 |
if (node) { |
|
|
616 |
nodeRegion = node.get(REGION); |
|
|
617 |
} |
|
|
618 |
} |
|
|
619 |
|
|
|
620 |
return nodeRegion; |
|
|
621 |
}, |
|
|
622 |
|
|
|
623 |
// -- Protected Event Handlers --------------------------------------------- |
|
|
624 |
|
|
|
625 |
/** |
|
|
626 |
Handles `alignChange` events by updating the UI in response to `align` |
|
|
627 |
Attribute changes. |
|
|
628 |
|
|
|
629 |
@method _afterAlignChange |
|
|
630 |
@param {EventFacade} e |
|
|
631 |
@protected |
|
|
632 |
**/ |
|
|
633 |
_afterAlignChange: function (e) { |
|
|
634 |
var align = e.newVal; |
|
|
635 |
if (align) { |
|
|
636 |
this._uiSetAlign(align.node, align.points); |
|
|
637 |
} |
|
|
638 |
}, |
|
|
639 |
|
|
|
640 |
/** |
|
|
641 |
Handles `alignOnChange` events by updating the alignment-syncing event |
|
|
642 |
handlers. |
|
|
643 |
|
|
|
644 |
@method _afterAlignOnChange |
|
|
645 |
@param {EventFacade} e |
|
|
646 |
@protected |
|
|
647 |
**/ |
|
|
648 |
_afterAlignOnChange: function(e) { |
|
|
649 |
this._detachPosAlignUIHandles(); |
|
|
650 |
|
|
|
651 |
if (this.get(VISIBLE)) { |
|
|
652 |
this._attachPosAlignUIHandles(); |
|
|
653 |
} |
|
|
654 |
} |
|
|
655 |
}; |
|
|
656 |
|
|
|
657 |
Y.WidgetPositionAlign = PositionAlign; |
|
|
658 |
|
|
|
659 |
|
|
|
660 |
}, '3.10.3', {"requires": ["widget-position"]}); |