[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 YUI.add('moodle-core-widget-focusafterclose', function (Y, NAME) { 2 3 /** 4 * Provides support for focusing on different nodes after the Widget is 5 * hidden. 6 * 7 * If the focusOnPreviousTargetAfterHide attribute is true, then the module hooks 8 * into the show function for that Widget to try and determine which Node 9 * caused the Widget to be shown. 10 * 11 * Alternatively, the focusAfterHide attribute can be passed a Node. 12 * 13 * @module moodle-core-widget-focusafterhide 14 */ 15 16 var CAN_RECEIVE_FOCUS_SELECTOR = 'input:not([type="hidden"]), a[href], button, textarea, select, [tabindex], [contenteditable="true"]'; 17 18 /** 19 * Provides support for focusing on different nodes after the Widget is 20 * hidden. 21 * 22 * @class M.core.WidgetFocusAfterHide 23 */ 24 function WidgetFocusAfterHide() { 25 Y.after(this._bindUIFocusAfterHide, this, 'bindUI'); 26 if (this.get('rendered')) { 27 this._bindUIFocusAfterHide(); 28 } 29 } 30 31 WidgetFocusAfterHide.ATTRS = { 32 /** 33 * Whether to focus on the target that caused the Widget to be shown. 34 * 35 * <em>If this is true, and a valid Node is found, any Node specified to focusAfterHide 36 * will be ignored.</em> 37 * 38 * @attribute focusOnPreviousTargetAfterHide 39 * @default false 40 * @type boolean 41 */ 42 focusOnPreviousTargetAfterHide: { 43 value: false 44 }, 45 46 /** 47 * The Node to focus on after hiding the Widget. 48 * 49 * <em>Note: If focusOnPreviousTargetAfterHide is true, and a valid Node is found, then this 50 * value will be ignored. If it is true and not found, then this value will be used as 51 * a fallback.</em> 52 * 53 * @attribute focusAfterHide 54 * @default null 55 * @type Node 56 */ 57 focusAfterHide: { 58 value: null, 59 type: Y.Node 60 } 61 }; 62 63 WidgetFocusAfterHide.prototype = { 64 /** 65 * The list of Event Handles which we should cancel when the dialogue is destroyed. 66 * 67 * @property uiHandleFocusAfterHide 68 * @type array 69 * @protected 70 */ 71 _uiHandlesFocusAfterHide: [], 72 73 /** 74 * A reference to the real show method which is being overwritten. 75 * 76 * @property _showFocusAfterHide 77 * @type function 78 * @default null 79 * @protected 80 */ 81 _showFocusAfterHide: null, 82 83 /** 84 * A reference to the detected previous target. 85 * 86 * @property _previousTargetFocusAfterHide 87 * @type function 88 * @default null 89 * @protected 90 */ 91 _previousTargetFocusAfterHide: null, 92 93 initializer: function() { 94 95 if (this.get('focusOnPreviousTargetAfterHide') && this.show) { 96 // Overwrite the parent method so that we can get the focused 97 // target. 98 this._showFocusAfterHide = this.show; 99 this.show = function(e) { 100 this._showFocusAfterHide.apply(this, arguments); 101 102 // We use a property rather than overriding the focusAfterHide parameter in 103 // case the target cannot be found at hide time. 104 this._previousTargetFocusAfterHide = null; 105 if (e && e.currentTarget) { 106 this._previousTargetFocusAfterHide = e.currentTarget; 107 } 108 }; 109 } 110 }, 111 112 destructor: function() { 113 new Y.EventHandle(this.uiHandleFocusAfterHide).detach(); 114 }, 115 116 /** 117 * Set up the event handling required for this module to work. 118 * 119 * @method _bindUIFocusAfterHide 120 * @private 121 */ 122 _bindUIFocusAfterHide: function() { 123 // Detach the old handles first. 124 new Y.EventHandle(this.uiHandleFocusAfterHide).detach(); 125 this.uiHandleFocusAfterHide = [ 126 this.after('visibleChange', this._afterHostVisibleChangeFocusAfterHide) 127 ]; 128 }, 129 130 /** 131 * Handle the change in UI visibility. 132 * 133 * This method changes the focus after the hide has taken place. 134 * 135 * @method _afterHostVisibleChangeFocusAfterHide 136 * @private 137 */ 138 _afterHostVisibleChangeFocusAfterHide: function() { 139 if (!this.get('visible')) { 140 if (this._attemptFocus(this._previousTargetFocusAfterHide)) { 141 142 } else if (this._attemptFocus(this.get('focusAfterHide'))) { 143 // Fall back to the focusAfterHide value if one was specified. 144 145 } else { 146 147 } 148 } 149 }, 150 151 _attemptFocus: function(node) { 152 var focusTarget = Y.one(node); 153 if (focusTarget) { 154 focusTarget = focusTarget.ancestor(CAN_RECEIVE_FOCUS_SELECTOR, true); 155 if (focusTarget) { 156 focusTarget.focus(); 157 return true; 158 } 159 } 160 return false; 161 } 162 }; 163 164 var NS = Y.namespace('M.core'); 165 NS.WidgetFocusAfterHide = WidgetFocusAfterHide; 166 167 168 }, '@VERSION@', {"requires": ["base-build", "widget"]});
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |