2
Copyright (c) 2008, Yahoo! Inc. All rights reserved.
3
Code licensed under the BSD License:
4
http://developer.yahoo.net/yui/license.txt
7
YUI.add('widget-position', function(Y) {
10
* Provides basic XY positioning support for Widgets, though an extension
12
* @module widget-position
19
POSITIONED = "positioned",
20
BOUNDING_BOX = "boundingBox",
22
RENDERUI = "renderUI",
28
XYChange = "xyChange";
31
* Widget extension, which can be used to add positioning support to the base Widget class,
32
* through the <a href="Base.html#method_build">Base.build</a> method.
34
* @class WidgetPosition
35
* @param {Object} config User configuration object
37
function Position(config) {
38
this._posNode = this.get(BOUNDING_BOX);
40
// WIDGET METHOD OVERLAP
41
Y.after(this._renderUIPosition, this, RENDERUI);
42
Y.after(this._syncUIPosition, this, SYNCUI);
43
Y.after(this._bindUIPosition, this, BINDUI);
47
* Static property used to define the default attribute
48
* configuration introduced by WidgetPosition.
50
* @property WidgetPosition.ATTRS
61
* @description Page X co-ordinate for the widget. This attribute acts as a facade for the
62
* xy attribute. Changes in position can be monitored by listening for xyChange events.
78
* @description Page Y co-ordinate for the widget. This attribute acts as a facade for the
79
* xy attribute. Changes in position can be monitored by listening for xyChange events.
95
* @description Page XY co-ordinate pair for the widget.
99
validator: function(val) {
100
return this._validateXY(val);
106
* Default class used to mark the boundingBox of a positioned widget.
108
* @property WidgetPosition.POSITIONED_CLASS_NAME
110
* @default "yui-widget-positioned"
113
Position.POSITIONED_CLASS_NAME = Widget.getClassName(POSITIONED);
115
Position.prototype = {
118
* Creates/Initializes the DOM to support xy page positioning.
120
* This method in invoked after renderUI is invoked for the Widget class
121
* using YUI's aop infrastructure.
123
* @method _renderUIPosition
126
_renderUIPosition : function() {
127
this._posNode.addClass(Position.POSITIONED_CLASS_NAME);
131
* Synchronizes the UI to match the Widgets xy page position state.
133
* This method in invoked after syncUI is invoked for the Widget class
134
* using YUI's aop infrastructure.
136
* @method _syncUIPosition
139
_syncUIPosition : function() {
140
this._uiSetXY(this.get(XY_COORD));
144
* Binds event listeners responsible for updating the UI state in response to
145
* Widget position related state changes.
147
* This method in invoked after bindUI is invoked for the Widget class
148
* using YUI's aop infrastructure.
150
* @method _bindUIPosition
153
_bindUIPosition :function() {
154
this.after(XYChange, this._afterXYChange);
158
* Moves the Widget to the specified page xy co-ordinate position.
162
* @param {Number} x The new x position
163
* @param {Number} y The new y position
165
* @param {Array} x, y values passed as an array ([x, y]), to support
166
* simple pass through of Node.getXY results
169
var args = arguments,
170
coord = (Lang.isArray(args[0])) ? args[0] : [args[0], args[1]];
171
this.set(XY_COORD, coord);
175
* Synchronizes the Panel's "xy", "x", and "y" properties with the
176
* Widget's position in the DOM.
180
syncXY : function () {
181
this.set(XY_COORD, this._posNode.getXY(), {src: UI});
185
* Default validator for the XY attribute
187
* @method _validateXY
188
* @param {Array} val The XY page co-ordinate value which is being set.
189
* @return {boolean} true if valid, false if not.
191
_validateXY : function(val) {
192
return (Lang.isArray(val) && Lang.isNumber(val[0]) && Lang.isNumber(val[1]));
196
* Default setter for the X attribute. The setter passes the X value through
197
* to the XY attribute, which is the sole store for the XY state.
200
* @param {Number} val The X page co-ordinate value
202
_setX : function(val) {
203
this.set(XY_COORD, [val, this.get(XY_COORD)[0]]);
207
* Default setter for the Y attribute. The setter passes the Y value through
208
* to the XY attribute, which is the sole store for the XY state.
211
* @param {Number} val The Y page co-ordinate value
213
_setY : function(val) {
214
this.set(XY_COORD, [this.get(XY_COORD)[1], val]);
218
* Default getter for the X attribute. The value is retrieved from
219
* the XY attribute, which is the sole store for the XY state.
222
* @return {Number} The X page co-ordinate value
225
return this.get(XY_COORD)[0];
229
* Default getter for the Y attribute. The value is retrieved from
230
* the XY attribute, which is the sole store for the XY state.
233
* @return {Number} The Y page co-ordinate value
236
return this.get(XY_COORD)[1];
240
* Default attribute change listener for the xy attribute, responsible
241
* for updating the UI, in response to attribute changes.
243
* @method _afterXYChange
245
* @param {Event.Facade} e The event facade for the attribute change
247
_afterXYChange : function(e) {
249
this._uiSetXY(e.newVal);
254
* Updates the UI to reflect the XY page co-ordinates passed in.
258
* @param {String} val The XY page co-ordinates value to be reflected in the UI
260
_uiSetXY : function(val) {
261
this._posNode.setXY(val);
265
Y.WidgetPosition = Position;
269
}, '3.0.0pr2' ,{requires:['widget']});