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