bb7f586042ef830a409ecff71c45fe29459c9b94Eric Ferraiuolo * A widget-level extension that provides ability to hide widget when
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * certain events occur.
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * @module widget-autohide
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * @author eferraiuolo, tilomitra
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * @since 3.4.0
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * The WidgetAutohide class provides the hideOn attribute which can
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * be used to hide the widget when certain events occur.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @class WidgetAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @param {Object} config User configuration object
bb7f586042ef830a409ecff71c45fe29459c9b94Eric Ferraiuolo* Static property used to define the default attribute
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra* configuration introduced by WidgetAutohide.
10d8bafc5c24f3a4285cf6060a1935ba5cfc4b85Luke Smith* @property ATTRS
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra* @type Object
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @attribute hideOn
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @type array
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @description An array of objects corresponding to the nodes, events, and keycodes to hide the widget on.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * The implementer can supply an array of objects, with each object having the following properties:
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * <p>eventName: (string, required): The eventName to listen to.</p>
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * <p>node: (Y.Node, optional): The Y.Node that will fire the event (defaults to the boundingBox of the widget)</p>
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * <p>keyCode: (string, optional): If listening for key events, specify the keyCode</p>
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * <p>By default, this attribute consists of one object which will cause the widget to hide if the
2cbd03cf7d25ed7f8942ecaf21a4b58d7f41ff11Tilo Mitra * escape key is pressed.</p>
aaf329295ffbaf63e71aea0b79b20a251a87aad8Eric Ferraiuolo valueFn : function() {
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra // *** Instance Members *** //
60e5271418c47637445291f3120af2a30d144471Tilo Mitra // *** Lifecycle Methods *** //
60e5271418c47637445291f3120af2a30d144471Tilo Mitra destructor : function () {
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Binds event listeners to the widget.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * This method in invoked after bindUI is invoked for the Widget class
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * using YUI's aop infrastructure.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _bindUIAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
60e5271418c47637445291f3120af2a30d144471Tilo Mitra _bindUIAutohide : function () {
60e5271418c47637445291f3120af2a30d144471Tilo Mitra this.after(VISIBLE+CHANGE, this._afterHostVisibleChangeAutohide);
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra this.after("hideOnChange", this._afterHideOnChange);
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Syncs up the widget based on its current state. In particular, removes event listeners if
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * widget is not visible, and attaches them otherwise.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * This method in invoked after syncUI is invoked for the Widget class
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * using YUI's aop infrastructure.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _syncUIAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
60e5271418c47637445291f3120af2a30d144471Tilo Mitra _syncUIAutohide : function () {
60e5271418c47637445291f3120af2a30d144471Tilo Mitra this._uiSetHostVisibleAutohide(this.get(VISIBLE));
60e5271418c47637445291f3120af2a30d144471Tilo Mitra // *** Private Methods *** //
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Removes event listeners if widget is not visible, and attaches them otherwise.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _uiSetHostVisibleAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra //this._attachUIHandlesAutohide();
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Iterates through all objects in the hideOn attribute and creates event listeners.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _attachUIHandlesAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
dc02f346c16a47973a2f3f375bf43937b86b3e75Tilo Mitra if (this._uiHandlesAutohide) { return; }
60e5271418c47637445291f3120af2a30d144471Tilo Mitra o = {node: undefined, ev: undefined, keyCode: undefined};
60e5271418c47637445291f3120af2a30d144471Tilo Mitra //push all events on which the widget should be hidden
60e5271418c47637445291f3120af2a30d144471Tilo Mitra //no keycode or node defined
60e5271418c47637445291f3120af2a30d144471Tilo Mitra //node defined, no keycode (not a keypress)
60e5271418c47637445291f3120af2a30d144471Tilo Mitra //node defined, keycode defined, event defined (its a key press)
60e5271418c47637445291f3120af2a30d144471Tilo Mitra uiHandles.push(o.node.on(o.ev, hide, o.keyCode));
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra Y.log('The event with name "'+o.ev+'" could not be attached.');
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Detaches all event listeners created by this extension
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _detachUIHandlesAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Default function called when the visibility of the widget changes. Determines
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * whether to attach or detach event listeners based on the visibility of the widget.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _afterHostVisibleChangeAutohide
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @protected
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * Default function called when hideOn Attribute is changed. Remove existing listeners and create new listeners.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * @method _afterHideOnChange
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra _afterHideOnChange : function(e) {
dc02f346c16a47973a2f3f375bf43937b86b3e75Tilo Mitra}, '@VERSION@' ,{requires:['base-build','widget','event-outside','event-key']});