widget-position-align-debug.js revision aa8244deeaefbb75db6af5d0a2599f6e181c1fbe
/**
*
* It builds on top of the widget-position module, to provide alignmentment and centering support.
* Future releases aim to add constrained and fixed positioning support.
*
* @module widget-position-align
*/
var L = Y.Lang,
ALIGN = "align",
BINDUI = "bindUI",
SYNCUI = "syncUI",
OFFSET_WIDTH = "offsetWidth",
OFFSET_HEIGHT = "offsetHeight",
VIEWPORT_REGION = "viewportRegion",
REGION = "region",
WINDOW = 'window',
RESIZE = 'resize',
SCROLL = 'scroll',
VISIBLE = "visible",
AlignChange = "alignChange",
VisibleChange = "visibleChange";
/**
* Widget extension, which can be used to add extended XY positioning support to the base Widget class,
* through the <a href="Base.html#method_build">Base.build</a> method. This extension requires that
* the WidgetPosition extension be added to the Widget (before WidgetPositionAlign, if part of the same
* extension list passed to Base.build).
*
* @class WidgetPositionAlign
* @param {Object} User configuration object
*/
function PositionAlign(config) {
if (!this._posNode) {
Y.error("WidgetPosition needs to be added to the Widget, before WidgetPositionAlign is added");
}
}
/**
* Static property used to define the default attribute
* configuration introduced by WidgetPositionAlign.
*
* @property WidgetPositionAlign.ATTRS
* @type Object
* @static
*/
PositionAlign.ATTRS = {
/**
* @attribute align
* @type Object
* @default null
* @desciption The align attribute is used to align a reference point on the widget, with the refernce point on another node, or the viewport.
* The object which align expects has the following properties:
* <dl>
* <dt>node</dt>
* <dd>
* The node to which the Widget is to be aligned. If set to null, or not provided, the Widget is aligned to the viewport
* </dd>
* <dt>points</dt>
* <dd>
* <p>
* A two element array, defining the two points on the Widget and node/viewport which are to be aligned. The first element is the point on the Widget, and the second element is the point on the node/viewport.
* Supported alignment points are defined as static properties on <code>WidgetPositionAlign</code>.
* </p>
* <p>
* e.g. <code>[WidgetPositionAlign.TR, WidgetPositionAlign.TL]</code> aligns the Top-Right corner of the Widget with the
* Top-Left corner of the node/viewport, and <code>[WidgetPositionAlign.CC, WidgetPositionAlign.TC]</code> aligns the Center of the
* </p>
* </dd>
* </dl>
*/
align: {
value:null
},
/**
* @attribute centered
* @type {boolean | node}
* @default false
* @description A convenience attribute, which can be used as a shortcut for the align attribute.
* If set to true, the Widget is centered in the viewport. If set to a node reference or valid selector string,
* the Widget will be centered within the node. If set the false, no center positioning is applied.
*/
centered: {
setter: "_setAlignCenter",
lazyAdd:false,
value:false
}
};
/**
* Constant used to specify the top-left corner for alignment
*
* @property WidgetPositionAlign.TL
* @type String
* @static
* @value "tl"
*/
/**
* Constant used to specify the top-right corner for alignment
*
* @property WidgetPositionAlign.TR
* @type String
* @static
* @value "tr"
*/
/**
* Constant used to specify the bottom-left corner for alignment
*
* @property WidgetPositionAlign.BL
* @type String
* @static
* @value "bl"
*/
/**
* Constant used to specify the bottom-right corner for alignment
*
* @property WidgetPositionAlign.BR
* @type String
* @static
* @value "br"
*/
/**
* Constant used to specify the top edge-center point for alignment
*
* @property WidgetPositionAlign.TC
* @type String
* @static
* @value "tc"
*/
/**
* Constant used to specify the right edge, center point for alignment
*
* @property WidgetPositionAlign.RC
* @type String
* @static
* @value "rc"
*/
/**
* Constant used to specify the bottom edge, center point for alignment
*
* @property WidgetPositionAlign.BC
* @type String
* @static
* @value "bc"
*/
/**
* Constant used to specify the left edge, center point for alignment
*
* @property WidgetPositionAlign.LC
* @type String
* @static
* @value "lc"
*/
/**
*
* @property WidgetPositionAlign.CC
* @type String
* @static
* @value "cc"
*/
/**
* Synchronizes the UI to match the Widgets align configuration.
*
* This method in invoked after syncUI is invoked for the Widget class
* using YUI's aop infrastructure.
*
* @method _syncUIPosAlign
* @protected
*/
_syncUIPosAlign : function() {
if (align) {
}
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget extended positioning related state changes.
* <p>
* This method is invoked after bindUI is invoked for the Widget class
* using YUI's aop infrastructure.
* </p>
* @method _bindUIStack
* @protected
*/
_bindUIPosAlign : function() {
},
_attachUIHandles: function() {
if (this._uiHandles) { return; }
this._uiHandles = [
];
},
_detachUIHandles : function () {
Y.each(this._uiHandles, function(h){
h.detach();
});
this._uiHandles = null;
},
_syncAlign: function() {
this._syncUIPosAlign();
},
/**
* Default setter for center attribute changes. Sets up the appropriate value, and passes
* it through the to the align attribute.
*
* @method _setAlignCenter
* @protected
* @param {boolean | node} The attribute value being set.
* @return {Number} The attribute value being set.
*/
_setAlignCenter : function(val) {
if (val) {
});
}
return val;
},
/**
* Default attribute change listener for the align attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterAlignChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterAlignChange : function(e) {
if (e.newVal) {
}
},
_uiSetHostVisible: function(visible) {
if (visible) {
this._attachUIHandles();
}
else {
this._detachUIHandles();
}
},
_afterVisibleChange: function(e) {
this._uiSetHostVisible(e.newVal);
},
/**
* Updates the UI to reflect the align value passed in (see the align attribute documentation, for the object stucture expected)
* @method _uiSetAlign
* @protected
* @param {Node | null} The node to align to, or null to indicate the viewport
*/
Y.error("align: Invalid Points Arguments");
return;
}
xy;
if (nodeRegion) {
// TODO: Optimize KWeight - Would lookup table help?
switch (nodePoint) {
case PositionAlign.TL:
break;
case PositionAlign.TR:
break;
case PositionAlign.BL:
break;
case PositionAlign.BR:
break;
case PositionAlign.TC:
break;
case PositionAlign.BC:
break;
case PositionAlign.LC:
break;
case PositionAlign.RC:
break;
case PositionAlign.CC:
xy = [nodeRegion.left + Math.floor(nodeRegion.width/2), nodeRegion.top + Math.floor(nodeRegion.height/2), widgetPoint];
break;
default:
break;
}
if (xy) {
}
}
},
/**
* Helper method, used to align the given point on the widget, with the XY page co-ordinates provided.
*
* @method _doAlign
* @private
* @param {String} widgetPoint Supported point constant (e.g. WidgetPositionAlign.TL)
* @param {Number} x X page co-ordinate to align to
* @param {Number} y Y page co-ordinate to align to
*/
_doAlign : function(widgetPoint, x, y) {
var widgetNode = this._posNode,
xy;
switch (widgetPoint) {
case PositionAlign.TL:
xy = [x, y];
break;
case PositionAlign.TR:
break;
case PositionAlign.BL:
break;
case PositionAlign.BR:
break;
case PositionAlign.TC:
break;
case PositionAlign.BC:
break;
case PositionAlign.LC:
break;
case PositionAlign.RC:
break;
case PositionAlign.CC:
break;
default:
break;
}
if (xy) {
}
},
_getRegion : function(node) {
var nodeRegion;
if (!node) {
} else {
if (node) {
}
}
return nodeRegion;
},
/**
* Aligns the Widget to the provided node (or viewport) using the provided
* points. The method can be invoked directly, however it will result in
* the align attribute being out of sync with current position of the of Widget.
*
* @method align
* @param {Node | String | null} node A reference (or selector string) for the Node which with the Widget is to be aligned.
* If null is passed in, the Widget will be aligned with the viewport.
* @param {Array[2]} points A two element array, specifying the points on the Widget and node/viewport which need to be aligned.
* The first entry is the point on the Widget, and the second entry is the point on the node/viewport which need to align.
* Valid point references are defined as static constants on the WidgetPositionAlign class.
*
* e.g. [WidgetPositionAlign.TL, WidgetPositionAlign.TR] will align the top-left corner of the Widget with the top-right corner of the node/viewport.
*/
},
/**
* Centers the container in the viewport, or if a node is passed in,
* the node.
*
* @method centered
* @param {Node | String} node Optional. A node reference or selector string defining the node
* inside which the Widget is to be centered. If not passed in, the Widget will be centered in the
* viewport.
*/
}
};