Widget-Stack.js revision 10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85
/**
* Provides stackable (z-index) support for Widgets through an extension.
*
* @module widget-stack
*/
var L = Y.Lang,
ZINDEX = "zIndex",
SHIM = "shim",
VISIBLE = "visible",
BOUNDING_BOX = "boundingBox",
RENDER_UI = "renderUI",
BIND_UI = "bindUI",
SYNC_UI = "syncUI",
OFFSET_WIDTH = "offsetWidth",
OFFSET_HEIGHT = "offsetHeight",
PARENT_NODE = "parentNode",
FIRST_CHILD = "firstChild",
OWNER_DOCUMENT = "ownerDocument",
WIDTH = "width",
HEIGHT = "height",
PX = "px",
// HANDLE KEYS
SHIM_DEFERRED = "shimdeferred",
SHIM_RESIZE = "shimresize",
// Events
VisibleChange = "visibleChange",
WidthChange = "widthChange",
HeightChange = "heightChange",
ShimChange = "shimChange",
ZIndexChange = "zIndexChange",
ContentUpdate = "contentUpdate",
// CSS
STACKED = "stacked";
/**
* Widget extension, which can be used to add stackable (z-index) support to the
* base Widget class along with a shimming solution, through the
* <a href="Base.html#method_build">Base.build</a> method.
*
* @class WidgetStack
* @param {Object} User configuration object
*/
this._stackHandles = {};
// WIDGET METHOD OVERLAP
}
// Static Properties
/**
* Static property used to define the default attribute
* configuration introduced by WidgetStack.
*
* @property ATTRS
* @type Object
* @static
*/
/**
* @attribute shim
* @type boolean
* @default false, for all browsers other than IE6, for which a shim is enabled by default.
*
* @description Boolean flag to indicate whether or not a shim should be added to the Widgets
* boundingBox, to protect it from select box bleedthrough.
*/
shim: {
},
/**
* @attribute zIndex
* @type number
* @default 0
* @description The z-index to apply to the Widgets boundingBox. Non-numerical values for
* zIndex will be converted to 0
*/
zIndex: {
value:1,
return this._setZIndex(val);
}
}
};
/**
* The HTML parsing rules for the WidgetStack class.
*
* @property HTML_PARSER
* @static
* @type Object
*/
Stack.HTML_PARSER = {
zIndex: function(contentBox) {
}
};
/**
* Default class used to mark the shim element
*
* @property SHIM_CLASS_NAME
* @type String
* @static
* @default "yui-widget-shim"
*/
/**
* Default class used to mark the boundingBox of a stacked widget.
*
* @property STACKED_CLASS_NAME
* @type String
* @static
* @default "yui-widget-stacked"
*/
/**
* Default markup template used to generate the shim element.
*
* @property SHIM_TEMPLATE
* @type String
* @static
*/
Stack.SHIM_TEMPLATE = '<iframe class="' + Stack.SHIM_CLASS_NAME + '" frameborder="0" title="Widget Stacking Shim" src="javascript:false" tabindex="-1" role="presentation"></iframe>';
/**
* Synchronizes the UI to match the Widgets stack state. This method in
* invoked after syncUI is invoked for the Widget class using YUI's aop infrastructure.
*
* @method _syncUIStack
* @protected
*/
_syncUIStack: function() {
},
/**
* Binds event listeners responsible for updating the UI state in response to
* Widget stack 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
*/
_bindUIStack: function() {
},
/**
* Creates/Initializes the DOM to support stackability.
* <p>
* This method in invoked after renderUI is invoked for the Widget class
* using YUI's aop infrastructure.
* </p>
* @method _renderUIStack
* @protected
*/
_renderUIStack: function() {
},
/**
* Default setter for zIndex attribute changes. Normalizes zIndex values to
* numbers, converting non-numerical values to 0.
*
* @method _setZIndex
* @protected
* @param {String | Number} zIndex
* @return {Number} Normalized zIndex
*/
_setZIndex: function(zIndex) {
}
zIndex = 0;
}
return zIndex;
},
/**
* Default attribute change listener for the shim attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterShimChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterShimChange : function(e) {
this._uiSetShim(e.newVal);
},
/**
* Default attribute change listener for the zIndex attribute, responsible
* for updating the UI, in response to attribute changes.
*
* @method _afterZIndexChange
* @protected
* @param {EventFacade} e The event facade for the attribute change
*/
_afterZIndexChange : function(e) {
this._uiSetZIndex(e.newVal);
},
/**
* Updates the UI to reflect the zIndex value passed in.
*
* @method _uiSetZIndex
* @protected
* @param {number} zIndex The zindex to be reflected in the UI
*/
_uiSetZIndex: function (zIndex) {
},
/**
* creation of the shim is deferred until it is made visible, for performance reasons.
*
* @method _uiSetShim
* @protected
*/
_uiSetShim: function (enable) {
if (enable) {
// Lazy creation
this._renderShim();
} else {
this._renderShimDeferred();
}
} else {
this._destroyShim();
}
},
/**
* until the Widget is made visible.
*
* @method _renderShimDeferred
* @private
*/
_renderShimDeferred : function() {
createBeforeVisible = function(e) {
if (e.newVal) {
this._renderShim();
}
};
},
/**
* Sets up event listeners to resize the shim when the size of the Widget changes.
* <p>
* NOTE: This method is only used for IE6 currently, since IE6 doesn't support a way to
* set.
* </p>
* @method _addShimResizeHandlers
* @private
*/
_addShimResizeHandlers : function() {
this.sizeShim();
},
/**
* Detaches any handles stored for the provided key
*
* @method _detachStackHandles
* @param String handleKey The key defining the group of handles which should be detached
* @private
*/
_detachStackHandles : function(handleKey) {
}
}
},
/**
* Creates the shim element and adds it to the DOM
*
* @method _renderShim
* @private
*/
_renderShim : function() {
stackEl = this._stackNode;
if (!shimEl) {
this._addShimResizeHandlers();
}
this._detachStackHandles(SHIM_DEFERRED);
}
},
/**
* Removes the shim from the DOM, and detaches any related event
* listeners.
*
* @method _destroyShim
* @private
*/
_destroyShim : function() {
if (this._shimNode) {
this._shimNode = null;
this._detachStackHandles(SHIM_DEFERRED);
this._detachStackHandles(SHIM_RESIZE);
}
},
/**
* For IE6, synchronizes the size and position of iframe shim to that of
* Widget bounding box which it is protecting. For all other browsers,
* this method does not do anything.
*
* @method sizeShim
*/
sizeShim: function () {
node = this._stackNode;
}
},
/**
* Creates a cloned shim node, using the SHIM_TEMPLATE html template, for use on a new instance.
*
* @method _getShimTemplate
* @private
* @return {Node} node A new shim Node instance.
*/
_getShimTemplate : function() {
}
};
Y.WidgetStack = Stack;