widget-autohide-debug.js revision 4f4ba013cd866a655a896f39f944674d19ad1387
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * "widget-autohide" is a widget-level plugin that allows widgets to be hidden
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * when certain events occur.
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra * By default, the widget will be hidden when the following events occur
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * <li>something is clicked outside the widget's bounding box</li>
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * <li>something is focussed outside the widget's bounding box</li>
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * <li>the escape key is pressed</li>
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * Events can be added or removed from this list through the "hideOn" attribute.
c714ee41455a161bf18197074d7e205b9d03b377Tilo Mitra * The following code demonstrates how to do this. Suppose I want to close the widget when
c714ee41455a161bf18197074d7e205b9d03b377Tilo Mitra * another node is resized.
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * <code>widget.plug(Y.Plugin.Autohide, {hideOn: [{node: resize, eventName: 'resize:end'}]});</code>.
4f4ba013cd866a655a896f39f944674d19ad1387Tilo Mitra * The hideOn attribute must be an array of objects. For more details on this attribute, refer to the API docs for it.
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * This module was originally part of the overlay-extras package by Eric Ferraiuolo but was promoted and abstracted
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * into the core library.
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * @module widget-autohide
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * @author eferraiuolo, tilomitra
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra * @since 3.4.0
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo MitraWidgetAutohide = Y.Base.create(WIDGET_AUTOHIDE, Y.Plugin.Base, [], {
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra // *** Instance Members *** //
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra // *** Lifecycle Methods *** //
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra destructor : function () {
60e5271418c47637445291f3120af2a30d144471Tilo Mitra bindUI : function () {
dc02f346c16a47973a2f3f375bf43937b86b3e75Tilo Mitra this.afterHostEvent(VISIBLE+CHANGE, this._afterHostVisibleChange);
dc02f346c16a47973a2f3f375bf43937b86b3e75Tilo Mitra syncUI : function () {
60e5271418c47637445291f3120af2a30d144471Tilo Mitra this._uiSetHostVisible(this.get(HOST).get(VISIBLE));
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra // *** Private Methods *** //
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra //this._attachUIHandles();
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra _attachUIHandles : function () {
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra if (this._uiHandles) { return; }
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra o = {node: undefined, ev: undefined, keyCode: undefined};
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra //push all events on which the widget should be hidden
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra //no keycode or node defined
c3db5f41661b8fee6566b38dbffeabe56e4dce12Tilo Mitra //node defined, no keycode (not a keypress)
853244a9af0549d584b80ac65d4fcb92de7c58bcTilo Mitra //node defined, keycode defined, event defined (its a key press)
897547688bb5907542df4114fc4a55979ad7ec12Tilo 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.');
60e5271418c47637445291f3120af2a30d144471Tilo Mitra _detachUIHandles : function () {
60e5271418c47637445291f3120af2a30d144471Tilo Mitra // *** Static *** //
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * @description An array of events that will cause the widget to hide.
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * Each index in the array should be an object literal with the following properties:
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * eventName (required, string): Refers to the event to listen to. If no other properties are
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * provided, it listens to this event on the widget's boundingBox. (ex: "clickoutside", "focusoutside")
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * node (optional, Y.Node): Refers to the node on which the "eventName" event should be listening.
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * For example, to close the widget when a resize on "#someDiv" occurs, pass in "Y.one("#someDiv")" to node, and "resize:end" to eventName
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * keyCode (optional, string): When listening to "key" events, this property can be filled with a keyCode such as "esc" or "down:27"
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * By default, this attribute has 3 objects within its array, clicking outside the widget, focussing outside the widget, and pressing the escape key
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * @attribute hideOn
60e5271418c47637445291f3120af2a30d144471Tilo Mitra * @type array
dc02f346c16a47973a2f3f375bf43937b86b3e75Tilo Mitra}, '@VERSION@' ,{requires:['base-build', 'widget', 'plugin', 'event-outside']});