MDL-45253 editor_atto: Async the highlighting of buttons

This commit is contained in:
Frederic Massart
2014-05-05 17:46:13 +08:00
parent fafeb5a293
commit e76ae8077a
10 changed files with 100 additions and 24 deletions
@@ -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) {
File diff suppressed because one or more lines are too long
@@ -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) {
@@ -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"]});
File diff suppressed because one or more lines are too long
@@ -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
View File
@@ -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)
);
}
+1
View File
@@ -84,6 +84,7 @@ Y.extend(EditorPlugin, Y.Base, {
this._primaryKeyboardShortcut = [];
this._buttonHandlers = [];
this._menuHideHandlers = [];
this._highlightQueue = {};
},
/**
+7 -1
View File
@@ -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": {