widget-autohide-debug.js revision 897547688bb5907542df4114fc4a55979ad7ec12
9533104fb7447a0765dc2aafec105c729d2c1be7Luke SmithYUI.add('widget-autohide', function(Y) {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smithvar WIDGET_AUTOHIDE = 'widgetAutohide',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith AUTOHIDE = 'autohide',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith CLICK_OUTSIDE = 'clickoutside',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith FOCUS_OUTSIDE = 'focusoutside',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith PRESS_ESCAPE = 'down:27',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith BIND_UI = 'bindUI',
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith SYNC_UI = "syncUI",
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith RENDERED = "rendered",
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith BOUNDING_BOX = "boundingBox",
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith VISIBLE = "visible",
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith HOST = "host",
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith CHANGE = 'Change',
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith getCN = Y.ClassNameManager.getClassName;
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke SmithWidgetAutohide = Y.Base.create(WIDGET_AUTOHIDE, Y.Plugin.Base, [], {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith // *** Instance Members *** //
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9563d8a01a40e508f7697d9c674c164512940371Luke Smith _uiHandles : null,
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith // *** Lifecycle Methods *** //
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith initializer : function (config) {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this.afterHostMethod(BIND_UI, this.bindUI);
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this.afterHostMethod(SYNC_UI, this.syncUI);
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith if (this.get(HOST).get(RENDERED)) {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith this.bindUI();
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this.syncUI();
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith destructor : function () {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith this._detachUIHandles();
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith bindUI : function () {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this.afterHostEvent(VISIBLE+CHANGE, this._afterHostVisibleChange);
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith },
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith syncUI : function () {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this._uiSetHostVisible(this.get(HOST).get(VISIBLE));
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith // *** Private Methods *** //
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith _uiSetHostVisible : function (visible) {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith if (visible) {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith //this._attachUIHandles();
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith Y.later(1, this, '_attachUIHandles');
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith } else {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this._detachUIHandles();
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith _attachUIHandles : function () {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith if (this._uiHandles) { return; }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith var host = this.get(HOST),
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith bb = host.get(BOUNDING_BOX),
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith hide = Y.bind(host.hide, host),
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith uiHandles = [],
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith self = this,
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith hideOn = this.get('hideOn'),
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith i = 0,
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith o = {node: undefined, ev: undefined, keyCode: undefined};
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith //push all events on which the widget should be hidden
9563d8a01a40e508f7697d9c674c164512940371Luke Smith for (; i < hideOn.length; i++) {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
ef820a2b98579b004dc187276f739fd5774a791fLuke Smith o.node = hideOn[i].node;
9563d8a01a40e508f7697d9c674c164512940371Luke Smith o.ev = hideOn[i].eventName;
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith o.keyCode = hideOn[i].keyCode;
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9563d8a01a40e508f7697d9c674c164512940371Luke Smith //no keycode or node defined
9563d8a01a40e508f7697d9c674c164512940371Luke Smith if (!o.node && !o.keyCode && o.ev) {
ef820a2b98579b004dc187276f739fd5774a791fLuke Smith uiHandles.push(bb.on(o.ev, hide));
ef820a2b98579b004dc187276f739fd5774a791fLuke Smith }
9563d8a01a40e508f7697d9c674c164512940371Luke Smith
9563d8a01a40e508f7697d9c674c164512940371Luke Smith //node defined, no keycode (not a keypress)
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith else if (o.node && !o.keyCode && o.ev) {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith uiHandles.push(o.node.on(o.ev, hide));
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith }
9563d8a01a40e508f7697d9c674c164512940371Luke Smith
9563d8a01a40e508f7697d9c674c164512940371Luke Smith //node defined, keycode defined, event defined (its a key press)
9563d8a01a40e508f7697d9c674c164512940371Luke Smith else if (o.node && o.keyCode && o.ev) {
9563d8a01a40e508f7697d9c674c164512940371Luke Smith uiHandles.push(o.node.on(o.ev, hide, o.keyCode));
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
ef820a2b98579b004dc187276f739fd5774a791fLuke Smith }
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9563d8a01a40e508f7697d9c674c164512940371Luke Smith this._uiHandles = uiHandles;
9563d8a01a40e508f7697d9c674c164512940371Luke Smith },
9563d8a01a40e508f7697d9c674c164512940371Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith _detachUIHandles : function () {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith Y.each(this._uiHandles, function(h){
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith h.detach();
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith });
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this._uiHandles = null;
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith _afterHostVisibleChange : function (e) {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith this._uiSetHostVisible(e.newVal);
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith }
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith}, {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith // *** Static *** //
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith NS : AUTOHIDE,
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith ATTRS : {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith hideOn: {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith value: [
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith {
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith eventName: CLICK_OUTSIDE
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith },
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith eventName: FOCUS_OUTSIDE
9563d8a01a40e508f7697d9c674c164512940371Luke Smith },
9563d8a01a40e508f7697d9c674c164512940371Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith {
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith node: Y.one('doc'),
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith eventName: 'key',
9563d8a01a40e508f7697d9c674c164512940371Luke Smith keyCode: 'esc'
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith ],
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith validator: Y.Lang.isArray
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith }
daa301d2a0f17b5c1b04d777de3acf969b9b63d2Luke Smith }
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith});
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke SmithY.namespace("Plugin").Autohide = WidgetAutohide;
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith}, '@VERSION@' ,{requires:['base-build', 'widget', 'plugin', 'gallery-outside-events']});
9533104fb7447a0765dc2aafec105c729d2c1be7Luke Smith