| 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 |
* Atto editor plugin.
|
|
|
18 |
*
|
|
|
19 |
* @module moodle-editor_atto-plugin
|
|
|
20 |
* @submodule plugin-base
|
|
|
21 |
* @package editor_atto
|
|
|
22 |
* @copyright 2014 Andrew Nicols
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
* A Plugin for the Atto Editor used in Moodle.
|
|
|
28 |
*
|
|
|
29 |
* This class should not be directly instantiated, and all Editor plugins
|
|
|
30 |
* should extend this class.
|
|
|
31 |
*
|
|
|
32 |
* @namespace M.editor_atto
|
|
|
33 |
* @class EditorPlugin
|
|
|
34 |
* @main
|
|
|
35 |
* @constructor
|
|
|
36 |
* @uses M.editor_atto.EditorPluginButtons
|
|
|
37 |
* @uses M.editor_atto.EditorPluginDialogue
|
|
|
38 |
*/
|
|
|
39 |
|
|
|
40 |
function EditorPlugin() {
|
|
|
41 |
EditorPlugin.superclass.constructor.apply(this, arguments);
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
var GROUPSELECTOR = '.atto_group.',
|
|
|
45 |
GROUP = '_group';
|
|
|
46 |
|
|
|
47 |
Y.extend(EditorPlugin, Y.Base, {
|
|
|
48 |
/**
|
|
|
49 |
* The name of the current plugin.
|
|
|
50 |
*
|
|
|
51 |
* @property name
|
|
|
52 |
* @type string
|
|
|
53 |
*/
|
|
|
54 |
name: null,
|
|
|
55 |
|
|
|
56 |
/**
|
|
|
57 |
* A Node reference to the editor.
|
|
|
58 |
*
|
|
|
59 |
* @property editor
|
|
|
60 |
* @type Node
|
|
|
61 |
*/
|
|
|
62 |
editor: null,
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* A Node reference to the editor toolbar.
|
|
|
66 |
*
|
|
|
67 |
* @property toolbar
|
|
|
68 |
* @type Node
|
|
|
69 |
*/
|
|
|
70 |
toolbar: null,
|
|
|
71 |
|
|
|
72 |
initializer: function(config) {
|
|
|
73 |
// Set the references to configuration parameters.
|
|
|
74 |
this.name = config.name;
|
|
|
75 |
this.toolbar = config.toolbar;
|
|
|
76 |
this.editor = config.editor;
|
|
|
77 |
|
|
|
78 |
// Set up the prototypal properties.
|
|
|
79 |
// These must be set up here becuase prototypal arrays and objects are copied across instances.
|
|
|
80 |
this.buttons = {};
|
|
|
81 |
this.buttonNames = [];
|
|
|
82 |
this.buttonStates = {};
|
|
|
83 |
this.menus = {};
|
|
|
84 |
this._primaryKeyboardShortcut = [];
|
|
|
85 |
this._buttonHandlers = [];
|
|
|
86 |
this._menuHideHandlers = [];
|
|
|
87 |
this._highlightQueue = {};
|
|
|
88 |
},
|
|
|
89 |
|
|
|
90 |
/**
|
|
|
91 |
* Mark the content ediable content as having been changed.
|
|
|
92 |
*
|
|
|
93 |
* This is a convenience function and passes through to
|
|
|
94 |
* {{#crossLink "M.editor_atto.EditorTextArea/updateOriginal"}}updateOriginal{{/crossLink}}.
|
|
|
95 |
*
|
|
|
96 |
* @method markUpdated
|
|
|
97 |
*/
|
|
|
98 |
markUpdated: function() {
|
|
|
99 |
// Save selection after changes to the DOM. If you don't do this here,
|
|
|
100 |
// subsequent calls to restoreSelection() will fail expecting the
|
|
|
101 |
// previous DOM state.
|
|
|
102 |
this.get('host').saveSelection();
|
|
|
103 |
|
|
|
104 |
return this.get('host').updateOriginal();
|
|
|
105 |
}
|
|
|
106 |
}, {
|
|
|
107 |
NAME: 'editorPlugin',
|
|
|
108 |
ATTRS: {
|
|
|
109 |
/**
|
|
|
110 |
* The editor instance that this plugin was instantiated by.
|
|
|
111 |
*
|
|
|
112 |
* @attribute host
|
|
|
113 |
* @type M.editor_atto.Editor
|
|
|
114 |
* @writeOnce
|
|
|
115 |
*/
|
|
|
116 |
host: {
|
|
|
117 |
writeOnce: true
|
|
|
118 |
},
|
|
|
119 |
|
|
|
120 |
/**
|
|
|
121 |
* The toolbar group that this button belongs to.
|
|
|
122 |
*
|
|
|
123 |
* When setting, the name of the group should be specified.
|
|
|
124 |
*
|
|
|
125 |
* When retrieving, the Node for the toolbar group is returned. If
|
|
|
126 |
* the group doesn't exist yet, then it is created first.
|
|
|
127 |
*
|
|
|
128 |
* @attribute group
|
|
|
129 |
* @type Node
|
|
|
130 |
* @writeOnce
|
|
|
131 |
*/
|
|
|
132 |
group: {
|
|
|
133 |
writeOnce: true,
|
|
|
134 |
getter: function(groupName) {
|
|
|
135 |
var group = this.toolbar.one(GROUPSELECTOR + groupName + GROUP);
|
|
|
136 |
if (!group) {
|
|
|
137 |
group = Y.Node.create('<div class="atto_group ' +
|
|
|
138 |
groupName + GROUP + '"></div>');
|
|
|
139 |
this.toolbar.append(group);
|
|
|
140 |
}
|
|
|
141 |
|
|
|
142 |
return group;
|
|
|
143 |
}
|
|
|
144 |
}
|
|
|
145 |
}
|
|
|
146 |
});
|
|
|
147 |
|
|
|
148 |
Y.namespace('M.editor_atto').EditorPlugin = EditorPlugin;
|