1 |
efrain |
1 |
// This file is part of Moodle - http://moodle.org/
|
|
|
2 |
//
|
|
|
3 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
4 |
// it under the terms of the GNU General Public License as published by
|
|
|
5 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
6 |
// (at your option) any later version.
|
|
|
7 |
//
|
|
|
8 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
9 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
10 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
11 |
// GNU General Public License for more details.
|
|
|
12 |
//
|
|
|
13 |
// You should have received a copy of the GNU General Public License
|
|
|
14 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
15 |
|
|
|
16 |
/**
|
|
|
17 |
* @module moodle-editor_atto-plugin
|
|
|
18 |
* @submodule dialogue
|
|
|
19 |
*/
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Dialogue functions for an Atto Plugin.
|
|
|
23 |
*
|
|
|
24 |
* See {{#crossLink "M.editor_atto.EditorPlugin"}}{{/crossLink}} for details.
|
|
|
25 |
*
|
|
|
26 |
* @namespace M.editor_atto
|
|
|
27 |
* @class EditorPluginDialogue
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
function EditorPluginDialogue() {}
|
|
|
31 |
|
|
|
32 |
EditorPluginDialogue.ATTRS = {
|
|
|
33 |
};
|
|
|
34 |
|
|
|
35 |
EditorPluginDialogue.prototype = {
|
|
|
36 |
/**
|
|
|
37 |
* A reference to the instantiated dialogue.
|
|
|
38 |
*
|
|
|
39 |
* @property _dialogue
|
|
|
40 |
* @private
|
|
|
41 |
* @type M.core.Dialogue
|
|
|
42 |
*/
|
|
|
43 |
_dialogue: null,
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Fetch the instantiated dialogue. If a dialogue has not yet been created, instantiate one.
|
|
|
47 |
*
|
|
|
48 |
* <em><b>Note:</b> Only one dialogue is supported through this interface.</em>
|
|
|
49 |
*
|
|
|
50 |
* For a full list of options, see documentation for {{#crossLink "M.core.dialogue"}}{{/crossLink}}.
|
|
|
51 |
*
|
|
|
52 |
* A sensible default is provided for the focusAfterHide attribute.
|
|
|
53 |
*
|
|
|
54 |
* @method getDialogue
|
|
|
55 |
* @param {object} config
|
|
|
56 |
* @param {boolean|string|Node} [config.focusAfterHide=undefined] Set the focusAfterHide setting to the
|
|
|
57 |
* specified Node according to the following values:
|
|
|
58 |
* <ul>
|
|
|
59 |
* <li>If true was passed, the first button for this plugin will be used instead; or</li>
|
|
|
60 |
* <li>If a String was passed, the named button for this plugin will be used instead; or</li>
|
|
|
61 |
* <li>If a Node was passed, that Node will be used instead.</li>
|
|
|
62 |
*
|
|
|
63 |
* This setting is checked each time that getDialogue is called.
|
|
|
64 |
*
|
|
|
65 |
* @return {M.core.dialogue}
|
|
|
66 |
*/
|
|
|
67 |
getDialogue: function(config) {
|
|
|
68 |
// Config is an optional param - define a default.
|
|
|
69 |
config = config || {};
|
|
|
70 |
|
|
|
71 |
var focusAfterHide = false;
|
|
|
72 |
if (config.focusAfterHide) {
|
|
|
73 |
// Remove the focusAfterHide because we may pass it a non-node value.
|
|
|
74 |
focusAfterHide = config.focusAfterHide;
|
|
|
75 |
delete config.focusAfterHide;
|
|
|
76 |
}
|
|
|
77 |
|
|
|
78 |
if (!this._dialogue) {
|
|
|
79 |
// Merge the default configuration with any provided configuration.
|
|
|
80 |
var dialogueConfig = Y.merge({
|
|
|
81 |
visible: false,
|
|
|
82 |
modal: true,
|
|
|
83 |
close: true,
|
|
|
84 |
draggable: true
|
|
|
85 |
}, config);
|
|
|
86 |
|
|
|
87 |
// Instantiate the dialogue.
|
|
|
88 |
this._dialogue = new M.core.dialogue(dialogueConfig);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
if (focusAfterHide !== false) {
|
|
|
92 |
if (focusAfterHide === true) {
|
|
|
93 |
this._dialogue.set('focusAfterHide', this.buttons[this.buttonNames[0]]);
|
|
|
94 |
|
|
|
95 |
} else if (typeof focusAfterHide === 'string') {
|
|
|
96 |
this._dialogue.set('focusAfterHide', this.buttons[focusAfterHide]);
|
|
|
97 |
|
|
|
98 |
} else {
|
|
|
99 |
this._dialogue.set('focusAfterHide', focusAfterHide);
|
|
|
100 |
|
|
|
101 |
}
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
return this._dialogue;
|
|
|
105 |
}
|
|
|
106 |
};
|
|
|
107 |
|
|
|
108 |
Y.Base.mix(Y.M.editor_atto.EditorPlugin, [EditorPluginDialogue]);
|