MDL-45253 editor_atto: Async the highlighting of buttons
This commit is contained in:
+7
-1
@@ -1097,9 +1097,15 @@ EditorSelection.prototype = {
|
||||
|
||||
var editor = this.editor,
|
||||
stopFn = function(node) {
|
||||
return !editor.contains(node);
|
||||
// The function getSelectedNodes only returns nodes within the editor, so this test is safe.
|
||||
return node === editor;
|
||||
};
|
||||
|
||||
// If we do not find at least one match in the editor, no point trying to find them in the selection.
|
||||
if (!editor.one(selector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
selectednodes.each(function(node){
|
||||
// Check each node, if it doesn't match the tags AND is not within the specified tags then fail this thing.
|
||||
if (requireall) {
|
||||
|
||||
+1
-1
File diff suppressed because one or more lines are too long
+7
-1
@@ -1092,9 +1092,15 @@ EditorSelection.prototype = {
|
||||
|
||||
var editor = this.editor,
|
||||
stopFn = function(node) {
|
||||
return !editor.contains(node);
|
||||
// The function getSelectedNodes only returns nodes within the editor, so this test is safe.
|
||||
return node === editor;
|
||||
};
|
||||
|
||||
// If we do not find at least one match in the editor, no point trying to find them in the selection.
|
||||
if (!editor.one(selector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
selectednodes.each(function(node){
|
||||
// Check each node, if it doesn't match the tags AND is not within the specified tags then fail this thing.
|
||||
if (requireall) {
|
||||
|
||||
+25
-6
@@ -86,6 +86,7 @@ Y.extend(EditorPlugin, Y.Base, {
|
||||
this._primaryKeyboardShortcut = [];
|
||||
this._buttonHandlers = [];
|
||||
this._menuHideHandlers = [];
|
||||
this._highlightQueue = {};
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -289,6 +290,18 @@ EditorPluginButtons.prototype = {
|
||||
*/
|
||||
_primaryKeyboardShortcut: null,
|
||||
|
||||
/**
|
||||
* An list of objects returned by Y.soon().
|
||||
*
|
||||
* The keys will be the buttonName of the button, and the value the Y.soon() object.
|
||||
*
|
||||
* @property _highlightQueue
|
||||
* @protected
|
||||
* @type Object
|
||||
* @default null
|
||||
*/
|
||||
_highlightQueue: null,
|
||||
|
||||
/**
|
||||
* Add a button for this plugin to the toolbar.
|
||||
*
|
||||
@@ -386,17 +399,23 @@ EditorPluginButtons.prototype = {
|
||||
|
||||
// Handle highlighting of the button.
|
||||
if (config.tags) {
|
||||
var tagMatchRequiresAll = null;
|
||||
var tagMatchRequiresAll = false;
|
||||
if (typeof config.tagMatchRequiresAll === 'boolean') {
|
||||
tagMatchRequiresAll = config.tagMatchRequiresAll;
|
||||
}
|
||||
this._buttonHandlers.push(
|
||||
host.on(['atto:selectionchanged', 'change'], function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
if (typeof this._highlightQueue[config.buttonName] !== 'undefined') {
|
||||
this._highlightQueue[config.buttonName].cancel();
|
||||
}
|
||||
// Async the highlighting.
|
||||
this._highlightQueue[config.buttonName] = Y.soon(Y.bind(function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
}
|
||||
}, this, e));
|
||||
}, this)
|
||||
);
|
||||
}
|
||||
@@ -1101,4 +1120,4 @@ EditorPluginDialogue.prototype = {
|
||||
Y.Base.mix(Y.M.editor_atto.EditorPlugin, [EditorPluginDialogue]);
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "base", "escape", "event", "event-outside", "handlebars", "event-custom"]});
|
||||
}, '@VERSION@', {"requires": ["node", "base", "escape", "event", "event-outside", "handlebars", "event-custom", "timers"]});
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
+25
-6
@@ -86,6 +86,7 @@ Y.extend(EditorPlugin, Y.Base, {
|
||||
this._primaryKeyboardShortcut = [];
|
||||
this._buttonHandlers = [];
|
||||
this._menuHideHandlers = [];
|
||||
this._highlightQueue = {};
|
||||
},
|
||||
|
||||
/**
|
||||
@@ -289,6 +290,18 @@ EditorPluginButtons.prototype = {
|
||||
*/
|
||||
_primaryKeyboardShortcut: null,
|
||||
|
||||
/**
|
||||
* An list of objects returned by Y.soon().
|
||||
*
|
||||
* The keys will be the buttonName of the button, and the value the Y.soon() object.
|
||||
*
|
||||
* @property _highlightQueue
|
||||
* @protected
|
||||
* @type Object
|
||||
* @default null
|
||||
*/
|
||||
_highlightQueue: null,
|
||||
|
||||
/**
|
||||
* Add a button for this plugin to the toolbar.
|
||||
*
|
||||
@@ -386,17 +399,23 @@ EditorPluginButtons.prototype = {
|
||||
|
||||
// Handle highlighting of the button.
|
||||
if (config.tags) {
|
||||
var tagMatchRequiresAll = null;
|
||||
var tagMatchRequiresAll = false;
|
||||
if (typeof config.tagMatchRequiresAll === 'boolean') {
|
||||
tagMatchRequiresAll = config.tagMatchRequiresAll;
|
||||
}
|
||||
this._buttonHandlers.push(
|
||||
host.on(['atto:selectionchanged', 'change'], function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
if (typeof this._highlightQueue[config.buttonName] !== 'undefined') {
|
||||
this._highlightQueue[config.buttonName].cancel();
|
||||
}
|
||||
// Async the highlighting.
|
||||
this._highlightQueue[config.buttonName] = Y.soon(Y.bind(function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
}
|
||||
}, this, e));
|
||||
}, this)
|
||||
);
|
||||
}
|
||||
@@ -1097,4 +1116,4 @@ EditorPluginDialogue.prototype = {
|
||||
Y.Base.mix(Y.M.editor_atto.EditorPlugin, [EditorPluginDialogue]);
|
||||
|
||||
|
||||
}, '@VERSION@', {"requires": ["node", "base", "escape", "event", "event-outside", "handlebars", "event-custom"]});
|
||||
}, '@VERSION@', {"requires": ["node", "base", "escape", "event", "event-outside", "handlebars", "event-custom", "timers"]});
|
||||
|
||||
+23
-5
@@ -141,6 +141,18 @@ EditorPluginButtons.prototype = {
|
||||
*/
|
||||
_primaryKeyboardShortcut: null,
|
||||
|
||||
/**
|
||||
* An list of objects returned by Y.soon().
|
||||
*
|
||||
* The keys will be the buttonName of the button, and the value the Y.soon() object.
|
||||
*
|
||||
* @property _highlightQueue
|
||||
* @protected
|
||||
* @type Object
|
||||
* @default null
|
||||
*/
|
||||
_highlightQueue: null,
|
||||
|
||||
/**
|
||||
* Add a button for this plugin to the toolbar.
|
||||
*
|
||||
@@ -238,17 +250,23 @@ EditorPluginButtons.prototype = {
|
||||
|
||||
// Handle highlighting of the button.
|
||||
if (config.tags) {
|
||||
var tagMatchRequiresAll = null;
|
||||
var tagMatchRequiresAll = false;
|
||||
if (typeof config.tagMatchRequiresAll === 'boolean') {
|
||||
tagMatchRequiresAll = config.tagMatchRequiresAll;
|
||||
}
|
||||
this._buttonHandlers.push(
|
||||
host.on(['atto:selectionchanged', 'change'], function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
if (typeof this._highlightQueue[config.buttonName] !== 'undefined') {
|
||||
this._highlightQueue[config.buttonName].cancel();
|
||||
}
|
||||
// Async the highlighting.
|
||||
this._highlightQueue[config.buttonName] = Y.soon(Y.bind(function(e) {
|
||||
if (host.selectionFilterMatches(config.tags, e.selectedNodes, tagMatchRequiresAll)) {
|
||||
this.highlightButtons(config.buttonName);
|
||||
} else {
|
||||
this.unHighlightButtons(config.buttonName);
|
||||
}
|
||||
}, this, e));
|
||||
}, this)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ Y.extend(EditorPlugin, Y.Base, {
|
||||
this._primaryKeyboardShortcut = [];
|
||||
this._buttonHandlers = [];
|
||||
this._menuHideHandlers = [];
|
||||
this._highlightQueue = {};
|
||||
},
|
||||
|
||||
/**
|
||||
|
||||
+7
-1
@@ -204,9 +204,15 @@ EditorSelection.prototype = {
|
||||
|
||||
var editor = this.editor,
|
||||
stopFn = function(node) {
|
||||
return !editor.contains(node);
|
||||
// The function getSelectedNodes only returns nodes within the editor, so this test is safe.
|
||||
return node === editor;
|
||||
};
|
||||
|
||||
// If we do not find at least one match in the editor, no point trying to find them in the selection.
|
||||
if (!editor.one(selector)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
selectednodes.each(function(node){
|
||||
// Check each node, if it doesn't match the tags AND is not within the specified tags then fail this thing.
|
||||
if (requireall) {
|
||||
|
||||
@@ -22,7 +22,8 @@
|
||||
"event",
|
||||
"event-outside",
|
||||
"handlebars",
|
||||
"event-custom"
|
||||
"event-custom",
|
||||
"timers"
|
||||
]
|
||||
},
|
||||
"moodle-editor_atto-menu": {
|
||||
|
||||
Reference in New Issue
Block a user