MDL-44092 Atto: Add selectionchanged event and listeners in the buttons.

This means the buttons can indicate the state of the text under the cursor.
This commit is contained in:
Damyon Wiese 2014-02-12 17:32:03 +08:00
parent 99061b7ad1
commit 3ee53a425f
62 changed files with 1773 additions and 97 deletions

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_bold-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'b,strong'
};
/**
* Atto text editor bold plugin.
*
@ -36,6 +45,18 @@ M.atto_bold = M.atto_bold || {
var iconurl = M.util.image_url('e/bold', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'bold', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'bold');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_bold-button",function(e,t){M.atto_bold=M.atto_bold||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("bold",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/bold","core");M.editor_atto.add_toolbar_button(e.elementid,"bold",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_bold-button",function(e,t){var n={TAGS:"b,strong"};M.atto_bold=M.atto_bold||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("bold",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/bold","core");M.editor_atto.add_toolbar_button(e.elementid,"bold",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"bold"):M.editor_atto.remove_widget_highlight(e.elementid,"bold")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_bold-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'b,strong'
};
/**
* Atto text editor bold plugin.
*
@ -36,6 +45,18 @@ M.atto_bold = M.atto_bold || {
var iconurl = M.util.image_url('e/bold', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'bold', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'bold');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'b,strong'
};
/**
* Atto text editor bold plugin.
*
@ -34,5 +43,17 @@ M.atto_bold = M.atto_bold || {
var iconurl = M.util.image_url('e/bold', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'bold', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'bold');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'bold');
}
});
}
};

View File

@ -105,7 +105,10 @@ M.atto_equation = M.atto_equation || {
tabview.render();
dialogue.show();
M.atto_equation.resolve_equation();
var equation = M.atto_equation.resolve_equation();
if (equation) {
Y.one('#atto_equation_equation').set('text', equation);
}
M.atto_equation.update_preview(false, elementid);
M.atto_equation.dialogue = dialogue;
}
@ -128,6 +131,17 @@ M.atto_equation = M.atto_equation || {
// Add the button to the toolbar.
M.editor_atto.add_toolbar_button(params.elementid, 'equation', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
}
});
}
},
@ -136,6 +150,7 @@ M.atto_equation = M.atto_equation || {
* extract the equation (and set it in the form).
*
* @method resolve_equation
* @return {String|Boolean} The equation or false.
*/
resolve_equation : function() {
// Find the equation in the surrounding text.
@ -145,7 +160,7 @@ M.atto_equation = M.atto_equation || {
// Note this is a document fragment and YUI doesn't like them.
if (!selectednode) {
return;
return false;
}
text = Y.one(selectednode).get('text');
@ -156,8 +171,9 @@ M.atto_equation = M.atto_equation || {
equation = equation.pop();
// Replace the equation.
equation = equation.substring(2, equation.length - 2);
Y.one('#atto_equation_equation').set('text', equation);
return equation;
}
return false;
},
/**

View File

@ -105,7 +105,10 @@ M.atto_equation = M.atto_equation || {
tabview.render();
dialogue.show();
M.atto_equation.resolve_equation();
var equation = M.atto_equation.resolve_equation();
if (equation) {
Y.one('#atto_equation_equation').set('text', equation);
}
M.atto_equation.update_preview(false, elementid);
M.atto_equation.dialogue = dialogue;
}
@ -128,6 +131,17 @@ M.atto_equation = M.atto_equation || {
// Add the button to the toolbar.
M.editor_atto.add_toolbar_button(params.elementid, 'equation', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
}
});
}
},
@ -136,6 +150,7 @@ M.atto_equation = M.atto_equation || {
* extract the equation (and set it in the form).
*
* @method resolve_equation
* @return {String|Boolean} The equation or false.
*/
resolve_equation : function() {
// Find the equation in the surrounding text.
@ -145,7 +160,7 @@ M.atto_equation = M.atto_equation || {
// Note this is a document fragment and YUI doesn't like them.
if (!selectednode) {
return;
return false;
}
text = Y.one(selectednode).get('text');
@ -156,8 +171,9 @@ M.atto_equation = M.atto_equation || {
equation = equation.pop();
// Replace the equation.
equation = equation.substring(2, equation.length - 2);
Y.one('#atto_equation_equation').set('text', equation);
return equation;
}
return false;
},
/**

View File

@ -103,7 +103,10 @@ M.atto_equation = M.atto_equation || {
tabview.render();
dialogue.show();
M.atto_equation.resolve_equation();
var equation = M.atto_equation.resolve_equation();
if (equation) {
Y.one('#atto_equation_equation').set('text', equation);
}
M.atto_equation.update_preview(false, elementid);
M.atto_equation.dialogue = dialogue;
}
@ -126,6 +129,17 @@ M.atto_equation = M.atto_equation || {
// Add the button to the toolbar.
M.editor_atto.add_toolbar_button(params.elementid, 'equation', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.atto_equation.resolve_equation() !== false) {
M.editor_atto.add_widget_highlight(e.elementid, 'equation');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'equation');
}
});
}
},
@ -134,6 +148,7 @@ M.atto_equation = M.atto_equation || {
* extract the equation (and set it in the form).
*
* @method resolve_equation
* @return {String|Boolean} The equation or false.
*/
resolve_equation : function() {
// Find the equation in the surrounding text.
@ -143,7 +158,7 @@ M.atto_equation = M.atto_equation || {
// Note this is a document fragment and YUI doesn't like them.
if (!selectednode) {
return;
return false;
}
text = Y.one(selectednode).get('text');
@ -154,8 +169,9 @@ M.atto_equation = M.atto_equation || {
equation = equation.pop();
// Replace the equation.
equation = equation.substring(2, equation.length - 2);
Y.one('#atto_equation_equation').set('text', equation);
return equation;
}
return false;
},
/**

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_image-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'img'
};
/**
* Atto text editor image plugin.
*
@ -51,25 +60,11 @@ M.atto_image = M.atto_image || {
dialogue.centerDialogue();
M.atto_image.dialogue = dialogue;
var selectedText = M.editor_atto.get_selection_text();
var i = 0;
var images = M.editor_atto.get_selected_nodes(elementid);
images = images.filter(SELECTORS.TAGS);
var images = [];
for (i = 0; i < selectedText.childNodes.length; i++) {
var child = selectedText.childNodes[0];
if (images.length === 0) {
if (child.nodeName.toLowerCase() === 'img') {
images[0] = child;
} else {
if (child.getElementsByTagName) {
images = child.getElementsByTagName('img');
}
}
}
}
if (images.length > 0) {
var image = Y.one(images[0]);
if (images.size() > 0) {
var image = images.item(0);
var width = image.getAttribute('width');
var height = image.getAttribute('height');
if (width > 0) {
@ -93,6 +88,18 @@ M.atto_image = M.atto_image || {
var iconurl = M.util.image_url('e/insert_edit_image', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'image', iconurl, params.group, display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (e.selectedNodes.filter(SELECTORS.TAGS).size() > 0) {
M.editor_atto.add_widget_highlight(e.elementid, 'image');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'image');
}
});
},
open_filepicker : function(e) {
var elementid = this.getAttribute('data-editor');

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_image-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'img'
};
/**
* Atto text editor image plugin.
*
@ -51,25 +60,11 @@ M.atto_image = M.atto_image || {
dialogue.centerDialogue();
M.atto_image.dialogue = dialogue;
var selectedText = M.editor_atto.get_selection_text();
var i = 0;
var images = M.editor_atto.get_selected_nodes(elementid);
images = images.filter(SELECTORS.TAGS);
var images = [];
for (i = 0; i < selectedText.childNodes.length; i++) {
var child = selectedText.childNodes[0];
if (images.length === 0) {
if (child.nodeName.toLowerCase() === 'img') {
images[0] = child;
} else {
if (child.getElementsByTagName) {
images = child.getElementsByTagName('img');
}
}
}
}
if (images.length > 0) {
var image = Y.one(images[0]);
if (images.size() > 0) {
var image = images.item(0);
var width = image.getAttribute('width');
var height = image.getAttribute('height');
if (width > 0) {
@ -93,6 +88,18 @@ M.atto_image = M.atto_image || {
var iconurl = M.util.image_url('e/insert_edit_image', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'image', iconurl, params.group, display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (e.selectedNodes.filter(SELECTORS.TAGS).size() > 0) {
M.editor_atto.add_widget_highlight(e.elementid, 'image');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'image');
}
});
},
open_filepicker : function(e) {
var elementid = this.getAttribute('data-editor');

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'img'
};
/**
* Atto text editor image plugin.
*
@ -49,25 +58,11 @@ M.atto_image = M.atto_image || {
dialogue.centerDialogue();
M.atto_image.dialogue = dialogue;
var selectedText = M.editor_atto.get_selection_text();
var i = 0;
var images = M.editor_atto.get_selected_nodes(elementid);
images = images.filter(SELECTORS.TAGS);
var images = [];
for (i = 0; i < selectedText.childNodes.length; i++) {
var child = selectedText.childNodes[0];
if (images.length === 0) {
if (child.nodeName.toLowerCase() === 'img') {
images[0] = child;
} else {
if (child.getElementsByTagName) {
images = child.getElementsByTagName('img');
}
}
}
}
if (images.length > 0) {
var image = Y.one(images[0]);
if (images.size() > 0) {
var image = images.item(0);
var width = image.getAttribute('width');
var height = image.getAttribute('height');
if (width > 0) {
@ -91,6 +86,18 @@ M.atto_image = M.atto_image || {
var iconurl = M.util.image_url('e/insert_edit_image', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'image', iconurl, params.group, display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (e.selectedNodes.filter(SELECTORS.TAGS).size() > 0) {
M.editor_atto.add_widget_highlight(e.elementid, 'image');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'image');
}
});
},
open_filepicker : function(e) {
var elementid = this.getAttribute('data-editor');

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_italic-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'i'
};
/**
* Atto text editor italic plugin.
*
@ -36,6 +45,18 @@ M.atto_italic = M.atto_italic || {
var iconurl = M.util.image_url('e/italic', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'italic', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'italic');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'italic');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_italic-button",function(e,t){M.atto_italic=M.atto_italic||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("italic",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/italic","core");M.editor_atto.add_toolbar_button(e.elementid,"italic",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_italic-button",function(e,t){var n={TAGS:"i"};M.atto_italic=M.atto_italic||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("italic",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/italic","core");M.editor_atto.add_toolbar_button(e.elementid,"italic",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"italic"):M.editor_atto.remove_widget_highlight(e.elementid,"italic")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_italic-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'i'
};
/**
* Atto text editor italic plugin.
*
@ -36,6 +45,18 @@ M.atto_italic = M.atto_italic || {
var iconurl = M.util.image_url('e/italic', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'italic', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'italic');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'italic');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'i'
};
/**
* Atto text editor italic plugin.
*
@ -34,5 +43,17 @@ M.atto_italic = M.atto_italic || {
var iconurl = M.util.image_url('e/italic', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'italic', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'italic');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'italic');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_link-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor link plugin.
*
@ -87,6 +96,17 @@ M.atto_link = M.atto_link || {
init : function(params) {
var iconurl = M.util.image_url('e/insert_edit_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'link', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'link');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'link');
}
});
},
/**

View File

@ -1 +1 @@
YUI.add("moodle-atto_link-button",function(e,t){M.atto_link=M.atto_link||{dialogue:null,selection:null,display_chooser:function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_link.selection=M.editor_atto.get_selection();if(M.atto_link.selection!==!1&&!M.atto_link.selection.collapsed){var n;M.atto_link.dialogue?n=M.atto_link.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_link.get_form_content(t)),n.set("headerContent",M.util.get_string("createlink","atto_link")),M.atto_link.resolve_anchors(),n.show(),M.atto_link.dialogue=n}},init:function(e){var t=M.util.image_url("e/insert_edit_link","core");M.editor_atto.add_toolbar_button(e.elementid,"link",t,e.group,this.display_chooser)},resolve_anchors:function(){var t=M.editor_atto.get_selection_parent_node(),n,r,i;if(!t)return;n=M.atto_link.find_selected_anchors(e.one(t)),n.length>0&&(r=n[0],M.atto_link.selection=M.editor_atto.get_selection_from_node(r),i=r.getAttribute("href"),target=r.getAttribute("target"),i!==""&&e.one("#atto_link_urlentry").set("value",i),target==="_blank"?e.one("#atto_link_openinnewwindow").set("checked","checked"):e.one("#atto_link_openinnewwindow").set("checked",""))},open_filepicker:function(e){var t=this.getAttribute("data-editor");e.preventDefault(),M.editor_atto.show_filepicker(t,"link",M.atto_link.filepicker_callback)},filepicker_callback:function(e){M.atto_link.dialogue.hide(),e.url!==""&&(M.editor_atto.set_selection(M.atto_link.selection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,e.url))},set_link:function(t,n){var r,i,s,o,u;t.preventDefault(),M.atto_link.dialogue.hide(),r=t.currentTarget.ancestor(".atto_form").one("input[type=url]"),u=r.get("value");if(u!==""){M.editor_atto.set_selection(M.atto_link.selection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,u),s=M.editor_atto.get_selection_parent_node();if(!s)return;o=M.atto_link.find_selected_anchors(e.one(s)),e.Array.each(o,function(e){i=t.currentTarget.ancestor(".atto_form").one("input[type=checkbox]"),i.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")}),M.editor_atto.text_updated(n)}},find_selected_anchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&M.editor_atto.selection_contains_node(e)&&r.push(e)}),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},get_form_content:function(t){var n='<form class="atto_form"><label for="atto_link_urlentry">'+M.util.get_string("enterurl","atto_link")+"</label>"+'<input class="fullwidth" type="url" value="" id="atto_link_urlentry" size="32"/><br/>';M.editor_atto.can_show_filepicker(t,"link")&&(n+='<button id="openlinkbrowser" data-editor="'+e.Escape.html(t)+'" type="button" >'+M.util.get_string("browserepositories","atto_link")+"</button>"+"<br/>"),n+='<input type="checkbox" id="atto_link_openinnewwindow"/><label class="sameline" for="atto_link_openinnewwindow">'+M.util.get_string("openinnewwindow","atto_link")+"</label>"+"<br/>"+'<div class="mdl-align">'+"<br/>"+'<button type="submit" id="atto_link_urlentrysubmit">'+M.util.get_string("createlink","atto_link")+"</button>"+"</div>"+"</form>";var r=e.Node.create(n);return r.one("#atto_link_urlentrysubmit").on("click",M.atto_link.set_link,this,t),M.editor_atto.can_show_filepicker(t,"link")&&r.one("#openlinkbrowser").on("click",M.atto_link.open_filepicker),r}}},"@VERSION@",{requires:["node","escape"]});
YUI.add("moodle-atto_link-button",function(e,t){var n={TAGS:"a"};M.atto_link=M.atto_link||{dialogue:null,selection:null,display_chooser:function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_link.selection=M.editor_atto.get_selection();if(M.atto_link.selection!==!1&&!M.atto_link.selection.collapsed){var n;M.atto_link.dialogue?n=M.atto_link.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_link.get_form_content(t)),n.set("headerContent",M.util.get_string("createlink","atto_link")),M.atto_link.resolve_anchors(),n.show(),M.atto_link.dialogue=n}},init:function(e){var t=M.util.image_url("e/insert_edit_link","core");M.editor_atto.add_toolbar_button(e.elementid,"link",t,e.group,this.display_chooser);var r=M.editor_atto.get_editable_node(e.elementid);r.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"link"):M.editor_atto.remove_widget_highlight(e.elementid,"link")})},resolve_anchors:function(){var t=M.editor_atto.get_selection_parent_node(),n,r,i;if(!t)return;n=M.atto_link.find_selected_anchors(e.one(t)),n.length>0&&(r=n[0],M.atto_link.selection=M.editor_atto.get_selection_from_node(r),i=r.getAttribute("href"),target=r.getAttribute("target"),i!==""&&e.one("#atto_link_urlentry").set("value",i),target==="_blank"?e.one("#atto_link_openinnewwindow").set("checked","checked"):e.one("#atto_link_openinnewwindow").set("checked",""))},open_filepicker:function(e){var t=this.getAttribute("data-editor");e.preventDefault(),M.editor_atto.show_filepicker(t,"link",M.atto_link.filepicker_callback)},filepicker_callback:function(e){M.atto_link.dialogue.hide(),e.url!==""&&(M.editor_atto.set_selection(M.atto_link.selection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,e.url))},set_link:function(t,n){var r,i,s,o,u;t.preventDefault(),M.atto_link.dialogue.hide(),r=t.currentTarget.ancestor(".atto_form").one("input[type=url]"),u=r.get("value");if(u!==""){M.editor_atto.set_selection(M.atto_link.selection),document.execCommand("unlink",!1,null),document.execCommand("createLink",!1,u),s=M.editor_atto.get_selection_parent_node();if(!s)return;o=M.atto_link.find_selected_anchors(e.one(s)),e.Array.each(o,function(e){i=t.currentTarget.ancestor(".atto_form").one("input[type=checkbox]"),i.get("checked")?e.setAttribute("target","_blank"):e.removeAttribute("target")}),M.editor_atto.text_updated(n)}},find_selected_anchors:function(e){var t=e.get("tagName"),n,r;return t&&t.toLowerCase()==="a"?[e]:(r=[],e.all("a").each(function(e){!n&&M.editor_atto.selection_contains_node(e)&&r.push(e)}),r.length>0?r:(n=e.ancestor("a"),n?[n]:[]))},get_form_content:function(t){var n='<form class="atto_form"><label for="atto_link_urlentry">'+M.util.get_string("enterurl","atto_link")+"</label>"+'<input class="fullwidth" type="url" value="" id="atto_link_urlentry" size="32"/><br/>';M.editor_atto.can_show_filepicker(t,"link")&&(n+='<button id="openlinkbrowser" data-editor="'+e.Escape.html(t)+'" type="button" >'+M.util.get_string("browserepositories","atto_link")+"</button>"+"<br/>"),n+='<input type="checkbox" id="atto_link_openinnewwindow"/><label class="sameline" for="atto_link_openinnewwindow">'+M.util.get_string("openinnewwindow","atto_link")+"</label>"+"<br/>"+'<div class="mdl-align">'+"<br/>"+'<button type="submit" id="atto_link_urlentrysubmit">'+M.util.get_string("createlink","atto_link")+"</button>"+"</div>"+"</form>";var r=e.Node.create(n);return r.one("#atto_link_urlentrysubmit").on("click",M.atto_link.set_link,this,t),M.editor_atto.can_show_filepicker(t,"link")&&r.one("#openlinkbrowser").on("click",M.atto_link.open_filepicker),r}}},"@VERSION@",{requires:["node","escape"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_link-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor link plugin.
*
@ -87,6 +96,17 @@ M.atto_link = M.atto_link || {
init : function(params) {
var iconurl = M.util.image_url('e/insert_edit_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'link', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'link');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'link');
}
});
},
/**

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor link plugin.
*
@ -85,6 +94,17 @@ M.atto_link = M.atto_link || {
init : function(params) {
var iconurl = M.util.image_url('e/insert_edit_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'link', iconurl, params.group, this.display_chooser);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'link');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'link');
}
});
},
/**

View File

@ -148,7 +148,7 @@ M.atto_managefiles = M.atto_managefiles || {
content = editableNode.getHTML(),
params = M.atto_managefiles.params[elementid],
baseUrl = M.cfg.wwwroot + '/draftfile.php/' + params.usercontext + '/user/draft/' + params.area.itemid + '/',
pattern = new RegExp(baseUrl.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
filename = '',
match = '',
usedFiles = {};

View File

@ -1 +1 @@
YUI.add("moodle-atto_managefiles-button",function(e,t){M.atto_managefiles=M.atto_managefiles||{currentElementId:null,dialogue:null,params:{},init:function(t){if(t.disabled)return;if(!(!t.area.itemid&&M.editor_atto.filepickeroptions[t.elementid]&&M.editor_atto.filepickeroptions[t.elementid].image&&M.editor_atto.filepickeroptions[t.elementid].image.itemid)){console.log("Plugin managefiles not available because itemid is missing.");return}t.area.itemid=M.editor_atto.filepickeroptions[t.elementid].image.itemid,M.atto_managefiles.params[t.elementid]=t;var n=function(t,n){var r,i;t.preventDefault(),M.atto_managefiles.currentElementId=n,M.atto_managefiles.dialogue?r=M.atto_managefiles.dialogue:(r=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0,width:"800px"}),r.set("headerContent",M.util.get_string("managefiles","atto_managefiles")),M.atto_managefiles.dialogue=r,r.render(),r.centerDialogue()),i=e.Node.create("<iframe></iframe>"),i.setStyle("height","700px"),i.setStyle("border","none"),i.setStyle("width","100%"),i.setAttribute("src",M.atto_managefiles.getIframeURL()),r.set("bodyContent",i),r.show(),M.editor_atto.text_updated(n)},r=M.util.image_url("e/manage_files","core");M.editor_atto.add_toolbar_button(t.elementid,"managefiles",r,t.group,n)},getIframeURL:function(){var e,t,n="";n=M.cfg.wwwroot+"/lib/editor/atto/plugins/managefiles/manage.php?",t=M.atto_managefiles.params[M.atto_managefiles.currentElementId];for(e in t.area)n+=encodeURIComponent(e)+"="+encodeURIComponent(t.area[e])+"&";return n},getUsedFiles:function(){var e=M.atto_managefiles.currentElementId,t=M.editor_atto.get_editable_node(e),n=t.getHTML(),r=M.atto_managefiles.params[e],i=M.cfg.wwwroot+"/draftfile.php/"+r.usercontext+"/user/draft/"+r.area.itemid+"/",s=new RegExp(i.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")+"(.+?)[\\?\"']","gm"),o="",u="",a={};while((u=s.exec(n))!==null)o=unescape(u[1]),a[o]=!0;return a}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_managefiles-button",function(e,t){M.atto_managefiles=M.atto_managefiles||{currentElementId:null,dialogue:null,params:{},init:function(t){if(t.disabled)return;if(!(!t.area.itemid&&M.editor_atto.filepickeroptions[t.elementid]&&M.editor_atto.filepickeroptions[t.elementid].image&&M.editor_atto.filepickeroptions[t.elementid].image.itemid)){console.log("Plugin managefiles not available because itemid is missing.");return}t.area.itemid=M.editor_atto.filepickeroptions[t.elementid].image.itemid,M.atto_managefiles.params[t.elementid]=t;var n=function(t,n){var r,i;t.preventDefault(),M.atto_managefiles.currentElementId=n,M.atto_managefiles.dialogue?r=M.atto_managefiles.dialogue:(r=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0,width:"800px"}),r.set("headerContent",M.util.get_string("managefiles","atto_managefiles")),M.atto_managefiles.dialogue=r,r.render(),r.centerDialogue()),i=e.Node.create("<iframe></iframe>"),i.setStyle("height","700px"),i.setStyle("border","none"),i.setStyle("width","100%"),i.setAttribute("src",M.atto_managefiles.getIframeURL()),r.set("bodyContent",i),r.show(),M.editor_atto.text_updated(n)},r=M.util.image_url("e/manage_files","core");M.editor_atto.add_toolbar_button(t.elementid,"managefiles",r,t.group,n)},getIframeURL:function(){var e,t,n="";n=M.cfg.wwwroot+"/lib/editor/atto/plugins/managefiles/manage.php?",t=M.atto_managefiles.params[M.atto_managefiles.currentElementId];for(e in t.area)n+=encodeURIComponent(e)+"="+encodeURIComponent(t.area[e])+"&";return n},getUsedFiles:function(){var e=M.atto_managefiles.currentElementId,t=M.editor_atto.get_editable_node(e),n=t.getHTML(),r=M.atto_managefiles.params[e],i=M.cfg.wwwroot+"/draftfile.php/"+r.usercontext+"/user/draft/"+r.area.itemid+"/",s=new RegExp(i.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g,"\\$&")+"(.+?)[\\?\"']","gm"),o="",u="",a={};while((u=s.exec(n))!==null)o=unescape(u[1]),a[o]=!0;return a}}},"@VERSION@",{requires:["node"]});

View File

@ -148,7 +148,7 @@ M.atto_managefiles = M.atto_managefiles || {
content = editableNode.getHTML(),
params = M.atto_managefiles.params[elementid],
baseUrl = M.cfg.wwwroot + '/draftfile.php/' + params.usercontext + '/user/draft/' + params.area.itemid + '/',
pattern = new RegExp(baseUrl.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
filename = '',
match = '',
usedFiles = {};

View File

@ -146,7 +146,7 @@ M.atto_managefiles = M.atto_managefiles || {
content = editableNode.getHTML(),
params = M.atto_managefiles.params[elementid],
baseUrl = M.cfg.wwwroot + '/draftfile.php/' + params.usercontext + '/user/draft/' + params.area.itemid + '/',
pattern = new RegExp(baseUrl.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
pattern = new RegExp(baseUrl.replace(/[\-\/\\\^$*+?.()|\[\]{}]/g, '\\$&') + "(.+?)[\\?\"']", 'gm'),
filename = '',
match = '',
usedFiles = {};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_orderedlist-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ol'
};
/**
* Atto text editor orderedlist plugin.
*
@ -36,6 +45,18 @@ M.atto_orderedlist = M.atto_orderedlist || {
var iconurl = M.util.image_url('e/numbered_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'orderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'orderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'orderedlist');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_orderedlist-button",function(e,t){M.atto_orderedlist=M.atto_orderedlist||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("insertOrderedList",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/numbered_list","core");M.editor_atto.add_toolbar_button(e.elementid,"orderedlist",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_orderedlist-button",function(e,t){var n={TAGS:"ol"};M.atto_orderedlist=M.atto_orderedlist||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("insertOrderedList",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/numbered_list","core");M.editor_atto.add_toolbar_button(e.elementid,"orderedlist",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"orderedlist"):M.editor_atto.remove_widget_highlight(e.elementid,"orderedlist")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_orderedlist-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ol'
};
/**
* Atto text editor orderedlist plugin.
*
@ -36,6 +45,18 @@ M.atto_orderedlist = M.atto_orderedlist || {
var iconurl = M.util.image_url('e/numbered_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'orderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'orderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'orderedlist');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ol'
};
/**
* Atto text editor orderedlist plugin.
*
@ -34,5 +43,17 @@ M.atto_orderedlist = M.atto_orderedlist || {
var iconurl = M.util.image_url('e/numbered_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'orderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'orderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'orderedlist');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_strike-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'strike'
};
/**
* Atto text editor strike plugin.
*
@ -36,6 +45,18 @@ M.atto_strike = M.atto_strike || {
var iconurl = M.util.image_url('e/strikethrough', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'strike', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'strike');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'strike');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_strike-button",function(e,t){M.atto_strike=M.atto_strike||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("strikeThrough",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/strikethrough","core");M.editor_atto.add_toolbar_button(e.elementid,"strike",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_strike-button",function(e,t){var n={TAGS:"strike"};M.atto_strike=M.atto_strike||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("strikeThrough",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/strikethrough","core");M.editor_atto.add_toolbar_button(e.elementid,"strike",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"strike"):M.editor_atto.remove_widget_highlight(e.elementid,"strike")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_strike-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'strike'
};
/**
* Atto text editor strike plugin.
*
@ -36,6 +45,18 @@ M.atto_strike = M.atto_strike || {
var iconurl = M.util.image_url('e/strikethrough', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'strike', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'strike');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'strike');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'strike'
};
/**
* Atto text editor strike plugin.
*
@ -34,5 +43,17 @@ M.atto_strike = M.atto_strike || {
var iconurl = M.util.image_url('e/strikethrough', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'strike', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'strike');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'strike');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_subscript-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sub'
};
/**
* Atto text editor subscript plugin.
*
@ -36,6 +45,18 @@ M.atto_subscript = M.atto_subscript || {
var iconurl = M.util.image_url('e/subscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'subscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sub');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sub');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_subscript-button",function(e,t){M.atto_subscript=M.atto_subscript||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("subscript",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/subscript","core");M.editor_atto.add_toolbar_button(e.elementid,"subscript",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_subscript-button",function(e,t){var n={TAGS:"sub"};M.atto_subscript=M.atto_subscript||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("subscript",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/subscript","core");M.editor_atto.add_toolbar_button(e.elementid,"subscript",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"sub"):M.editor_atto.remove_widget_highlight(e.elementid,"sub")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_subscript-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sub'
};
/**
* Atto text editor subscript plugin.
*
@ -36,6 +45,18 @@ M.atto_subscript = M.atto_subscript || {
var iconurl = M.util.image_url('e/subscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'subscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sub');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sub');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sub'
};
/**
* Atto text editor subscript plugin.
*
@ -34,5 +43,17 @@ M.atto_subscript = M.atto_subscript || {
var iconurl = M.util.image_url('e/subscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'subscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sub');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sub');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_superscript-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sup'
};
/**
* Atto text editor superscript plugin.
*
@ -36,6 +45,18 @@ M.atto_superscript = M.atto_superscript || {
var iconurl = M.util.image_url('e/superscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'superscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sup');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sup');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_superscript-button",function(e,t){M.atto_superscript=M.atto_superscript||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("superscript",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/superscript","core");M.editor_atto.add_toolbar_button(e.elementid,"superscript",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_superscript-button",function(e,t){var n={TAGS:"sup"};M.atto_superscript=M.atto_superscript||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("superscript",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/superscript","core");M.editor_atto.add_toolbar_button(e.elementid,"superscript",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"sup"):M.editor_atto.remove_widget_highlight(e.elementid,"sup")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_superscript-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sup'
};
/**
* Atto text editor superscript plugin.
*
@ -36,6 +45,18 @@ M.atto_superscript = M.atto_superscript || {
var iconurl = M.util.image_url('e/superscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'superscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sup');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sup');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'sup'
};
/**
* Atto text editor superscript plugin.
*
@ -34,5 +43,17 @@ M.atto_superscript = M.atto_superscript || {
var iconurl = M.util.image_url('e/superscript', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'superscript', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'sup');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'sup');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_table-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'table'
};
/**
* Atto text editor table plugin.
*
@ -519,6 +528,17 @@ M.atto_table = M.atto_table || {
document.execCommand("enableObjectResizing", false, false);
}
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'table');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'table');
}
});
},
/**

File diff suppressed because one or more lines are too long

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_table-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'table'
};
/**
* Atto text editor table plugin.
*
@ -519,6 +528,17 @@ M.atto_table = M.atto_table || {
document.execCommand("enableObjectResizing", false, false);
}
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'table');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'table');
}
});
},
/**

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'table'
};
/**
* Atto text editor table plugin.
*
@ -517,6 +526,17 @@ M.atto_table = M.atto_table || {
document.execCommand("enableObjectResizing", false, false);
}
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'table');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'table');
}
});
},
/**

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_underline-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'u'
};
/**
* Atto text editor underline plugin.
*
@ -36,6 +45,18 @@ M.atto_underline = M.atto_underline || {
var iconurl = M.util.image_url('e/underline', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'underline', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'underline');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'underline');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_underline-button",function(e,t){M.atto_underline=M.atto_underline||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("underline",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/underline","core");M.editor_atto.add_toolbar_button(e.elementid,"underline",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_underline-button",function(e,t){var n={TAGS:"u"};M.atto_underline=M.atto_underline||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("underline",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/underline","core");M.editor_atto.add_toolbar_button(e.elementid,"underline",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"underline"):M.editor_atto.remove_widget_highlight(e.elementid,"underline")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_underline-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'u'
};
/**
* Atto text editor underline plugin.
*
@ -36,6 +45,18 @@ M.atto_underline = M.atto_underline || {
var iconurl = M.util.image_url('e/underline', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'underline', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'underline');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'underline');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'u'
};
/**
* Atto text editor underline plugin.
*
@ -34,5 +43,17 @@ M.atto_underline = M.atto_underline || {
var iconurl = M.util.image_url('e/underline', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'underline', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'underline');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'underline');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_unlink-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor unlink plugin.
*
@ -36,6 +45,18 @@ M.atto_unlink = M.atto_unlink || {
var iconurl = M.util.image_url('e/remove_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unlink', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unlink');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unlink');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_unlink-button",function(e,t){M.atto_unlink=M.atto_unlink||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("unlink",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/remove_link","core");M.editor_atto.add_toolbar_button(e.elementid,"unlink",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_unlink-button",function(e,t){var n={TAGS:"a"};M.atto_unlink=M.atto_unlink||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("unlink",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/remove_link","core");M.editor_atto.add_toolbar_button(e.elementid,"unlink",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"unlink"):M.editor_atto.remove_widget_highlight(e.elementid,"unlink")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_unlink-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor unlink plugin.
*
@ -36,6 +45,18 @@ M.atto_unlink = M.atto_unlink || {
var iconurl = M.util.image_url('e/remove_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unlink', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unlink');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unlink');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'a'
};
/**
* Atto text editor unlink plugin.
*
@ -34,5 +43,17 @@ M.atto_unlink = M.atto_unlink || {
var iconurl = M.util.image_url('e/remove_link', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unlink', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unlink');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unlink');
}
});
}
};

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_unorderedlist-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ul'
};
/**
* Atto text editor unorderedlist plugin.
*
@ -36,6 +45,18 @@ M.atto_unorderedlist = M.atto_unorderedlist || {
var iconurl = M.util.image_url('e/bullet_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unorderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unorderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unorderedlist');
}
});
}
};

View File

@ -1 +1 @@
YUI.add("moodle-atto_unorderedlist-button",function(e,t){M.atto_unorderedlist=M.atto_unorderedlist||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("insertUnorderedList",!1,null),M.editor_atto.text_updated(t)},n=M.util.image_url("e/bullet_list","core");M.editor_atto.add_toolbar_button(e.elementid,"unorderedlist",n,e.group,t)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_unorderedlist-button",function(e,t){var n={TAGS:"ul"};M.atto_unorderedlist=M.atto_unorderedlist||{init:function(e){var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("insertUnorderedList",!1,null),M.editor_atto.text_updated(t)},r=M.util.image_url("e/bullet_list","core");M.editor_atto.add_toolbar_button(e.elementid,"unorderedlist",r,e.group,t);var i=M.editor_atto.get_editable_node(e.elementid);i.on("atto:selectionchanged",function(e){M.editor_atto.selection_filter_matches(e.elementid,n.TAGS,e.selectedNodes)?M.editor_atto.add_widget_highlight(e.elementid,"unorderedlist"):M.editor_atto.remove_widget_highlight(e.elementid,"unorderedlist")})}}},"@VERSION@",{requires:["node"]});

View File

@ -15,6 +15,15 @@ YUI.add('moodle-atto_unorderedlist-button', function (Y, NAME) {
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ul'
};
/**
* Atto text editor unorderedlist plugin.
*
@ -36,6 +45,18 @@ M.atto_unorderedlist = M.atto_unorderedlist || {
var iconurl = M.util.image_url('e/bullet_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unorderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unorderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unorderedlist');
}
});
}
};

View File

@ -13,6 +13,15 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Selectors.
*
* @type {Object}
*/
var SELECTORS = {
TAGS : 'ul'
};
/**
* Atto text editor unorderedlist plugin.
*
@ -34,5 +43,17 @@ M.atto_unorderedlist = M.atto_unorderedlist || {
var iconurl = M.util.image_url('e/bullet_list', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'unorderedlist', iconurl, params.group, click);
// Attach an event listner to watch for "changes" in the contenteditable.
// This includes cursor changes, we check if the button should be active or not, based
// on the text selection.
var editable = M.editor_atto.get_editable_node(params.elementid);
editable.on('atto:selectionchanged', function(e) {
if (M.editor_atto.selection_filter_matches(e.elementid, SELECTORS.TAGS, e.selectedNodes)) {
M.editor_atto.add_widget_highlight(e.elementid, 'unorderedlist');
} else {
M.editor_atto.remove_widget_highlight(e.elementid, 'unorderedlist');
}
});
}
};

View File

@ -53,7 +53,7 @@ div.editor_atto_toolbar button[disabled] {
background-color: #ebebeb;
}
.editor_atto_toolbar button:active {
.editor_atto_toolbar button:active, .editor_atto_toolbar button.highlight {
background-image: radial-gradient(ellipse at center, #ffffff 40%,#dfdfdf 100%);
background-color: #dfdfdf;
}

View File

@ -30,7 +30,8 @@ CSS = {
CONTENT: 'editor_atto_content',
CONTENTWRAPPER: 'editor_atto_content_wrap',
TOOLBAR: 'editor_atto_toolbar',
WRAPPER: 'editor_atto'
WRAPPER: 'editor_atto',
HIGHLIGHT: 'highlight'
};
/**
@ -253,6 +254,22 @@ M.editor_atto = M.editor_atto || {
return !element.hasAttribute('disabled');
},
/**
* Determine if the specified toolbar button/menu is highlighted.
* @param string elementid, the element id of this editor.
* @param string plugin, the plugin that created the button/menu.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
is_highlighted : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
return !element.hasClass(CSS.HIGHLIGHT);
},
/**
* Enable a single widget in the toolbar.
* @param string elementid, the element id of this editor.
@ -271,6 +288,42 @@ M.editor_atto = M.editor_atto || {
}
},
/**
* Highlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
add_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.addClass(CSS.HIGHLIGHT);
}
},
/**
* Unhighlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
remove_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.removeClass(CSS.HIGHLIGHT);
}
},
/**
* Enable all buttons and menus in the toolbar.
* @param string elementid, the element id of this editor.
@ -558,8 +611,9 @@ M.editor_atto = M.editor_atto || {
// Hide the old textarea.
textarea.hide();
atto.on('keydown', this.save_selection, this, params.elementid);
atto.on('mouseup', this.save_selection, this, params.elementid);
this.publish_events();
atto.on('atto:selectionchanged', this.save_selection, this, params.elementid);
atto.on('focus', this.restore_selection, this, params.elementid);
// Do not restore selection when focus is from a click event.
atto.on('mousedown', function() { this.focusfromclick = true; }, this);
@ -607,6 +661,87 @@ M.editor_atto = M.editor_atto || {
}
}
}
},
/**
* Add code to trigger the a set of custom events on either the toolbar, or the contenteditable node
* that can be listened to by plugins (or even this class).
* @param string elementid - the id of the textarea we created this editor from.
*/
publish_events : function() {
Y.Event.define("atto:selectionchanged", {
/**
* Catch the keydown/mouseup events, and fire a synthetic event for the change event.
* @param {Y.Event} e - The real event that triggers this synthetic one.
* @param {Object} params - Object containing the subscription object and the notifier.
*/
changeHandler: function (e, params) {
// Add 3 properties to the event.
// 1. add the elementid.
var elementid = params.sub.node.getAttribute('id');
// Strip 'editable' from the end of the id.
elementid = elementid.substring(0, elementid.length - 8);
e.elementid = elementid;
// 2. The list of leaf nodes contained in the selection.
e.selectedNodes = M.editor_atto.get_selected_nodes(elementid);
// 3. The current selection (Range)
e.selection = M.editor_atto.get_selection();
params.notifier.fire(e);
},
/**
* Subscribe to the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
*/
on: function (node, sub, notifier) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetach = node.on('keydown', Y.throttle(this.changeHandler, 100), this, params);
sub.attoMouseUpDetach = node.on('mouseup', Y.throttle(this.changeHandler, 100), this, params);
sub.attoFocusDetach = node.on('focus', Y.throttle(this.changeHandler, 100), this, params);
},
/**
* Detach the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detach: function (node, sub) {
sub.attoKeyDownDetach.detach();
sub.attoMouseUpDetach.detach();
sub.attoFocusDetach.detach();
},
/**
* Delegate the atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
* @param {String} filter - CSS selector for the filter.
*/
delegate: function(node, sub, notifier, filter) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetachDelegate = node.delegate('keydown', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoMouseUpDetachDelegate = node.delegate('mouseup', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoFocusDetachDelegate = node.delegate('focus', Y.throttle(this.changeHandler, 100), filter, this, params);
},
/**
* Detach a delegated atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detachDelegate: function(node, sub) {
sub.attoKeyDownDetachDelegate.detach();
sub.attoMouseUpDetachDelegate.detach();
sub.attoFocusDetachDelegate.detach();
}
});
},
/**
@ -825,6 +960,169 @@ M.editor_atto = M.editor_atto || {
return sel.inRange(range);
},
/**
* Runs a selector on each node in the selection and will only return true if all nodes
* in the selection match the filter.
*
* @param {String} elementid
* @param {String} selector
* @param {NodeList} selectednodes (Optional) - for performance we can pass this instead of looking it up.
* @return {Boolean}
*/
selection_filter_matches : function(elementid, selector, selectednodes) {
var result = true;
if (!selectednodes) {
// Find this because it was not passed as a param.
selectednodes = M.editor_atto.get_selected_nodes(elementid);
}
selector = '.' + CSS.CONTENT + ' ' + selector;
if (selectednodes.size() === 0) {
return false;
}
selectednodes.each(function(node) {
if (!node.ancestor(selector, true)) {
result = false;
}
});
return result;
},
/**
* Returns a list of nodes that are ancestors of the selection nodes,
* and match the specified css selector (and are contained within the editable div).
*
* @param {String} elementid
* @param {String} selector
* @return Y.NodeList
*/
selection_filter : function(elementid, selector) {
var selectednodes = M.editor_atto.get_selected_nodes(elementid);
var result = new Y.NodeList();
selector = '.' + CSS.CONTENT + ' ' + selector;
selectednodes.each(function(node) {
node.ancestors(selector, true).each(function(match) {
if (result.indexOf(match) === -1) {
result.push(match);
}
});
});
return result;
},
/**
* Get the deepest possible list of nodes in the current selection.
* @param {String} elementid
* @return Y.NodeList
*/
get_selected_nodes : function(elementid) {
var editable = M.editor_atto.get_editable_node(elementid);
var startnode = M.editor_atto.get_selection_start_container();
var endnode = M.editor_atto.get_selection_end_container();
if (!startnode || !endnode) {
return new Y.NodeList();
}
/**
* Recursive function to walk the dom tree between 2 nodes and build
* a list of leaf nodes.
* @param {Y.Node} node - The current node.
* @param {Y.Node} endnode - The node to stop at.
* @param {Y.Node} boundingnode - A node that will contain the selection - do not result results outside this node.
* @param {Integer} skipchildren - When returning from a child to a parent, this is how many children to skip.
* @param {Boolean} isstart - Only true for the starting condition. Used in the case when startnode == endnode.
* @return {Y.NodeList} The list of leaf nodes found.
*/
var find_leaf_nodes = function(node, endnode, boundingnode, skipchildren, isstart) {
var leafnodes = new Y.NodeList();
if (endnode === node) {
// If there are child nodes and we didn't come from a child node, then skip this end condition.
if (!(endnode === node && startnode === node && isstart && node.hasChildNodes())) {
// If the end node is a leaf - return it.
if (!node.hasChildNodes()) {
leafnodes.push(node);
}
// We reached the end of the selection.
return leafnodes;
}
}
// Node is not a leaf, look at it's children.
if (node.hasChildNodes()) {
var children = node.get('childNodes');
// Skipchildren is used when returning from a child node, to make the parent look at the next child node.
var child = children.item(skipchildren);
if (child) {
// There was a child node, find all the leaf nodes in it.
leafnodes.concat(find_leaf_nodes(child, endnode, boundingnode, 0, false));
}
} else {
// This node has no children - so save it.
leafnodes.push(node);
}
// If we hit the bounding node - this is an end condition.
if (node === boundingnode) {
return leafnodes;
}
// We have added all the nodes in this branch, look at the next child of the parent.
var parent = node.ancestor();
if (parent) {
var currentindex = parent.get('childNodes').indexOf(node);
leafnodes.concat(find_leaf_nodes(parent, endnode, boundingnode, currentindex + 1, false));
}
return leafnodes;
};
// Kick off the recursive function.
return find_leaf_nodes(startnode, endnode, editable, 0, true);
},
/**
* Get the first node that contains the current selection.
* @return DOMNode or false
*/
get_selection_start_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.startContainer) {
return Y.one(selection.startContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(true);
return Y.one(range.parentElement());
}
},
/**
* Get the last node that contains the current selection.
* @return DOMNode or false
*/
get_selection_end_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.endContainer) {
return Y.one(selection.endContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(false);
return Y.one(range.parentElement());
}
return false;
},
/**
* Get the dom node representing the common anscestor of the selection nodes.
* @return DOMNode or false
@ -1150,4 +1448,16 @@ Y.Node.addMethod("cleanHTML", cleanHTML);
Y.NodeList.importMethod(Y.Node.prototype, "cleanHTML");
}, '@VERSION@', {"requires": ["node", "io", "overlay", "escape", "event", "event-simulate", "moodle-core-notification"]});
}, '@VERSION@', {
"requires": [
"node",
"io",
"overlay",
"escape",
"event",
"event-simulate",
"event-custom",
"yui-throttle",
"moodle-core-notification"
]
});

File diff suppressed because one or more lines are too long

View File

@ -30,7 +30,8 @@ CSS = {
CONTENT: 'editor_atto_content',
CONTENTWRAPPER: 'editor_atto_content_wrap',
TOOLBAR: 'editor_atto_toolbar',
WRAPPER: 'editor_atto'
WRAPPER: 'editor_atto',
HIGHLIGHT: 'highlight'
};
/**
@ -253,6 +254,22 @@ M.editor_atto = M.editor_atto || {
return !element.hasAttribute('disabled');
},
/**
* Determine if the specified toolbar button/menu is highlighted.
* @param string elementid, the element id of this editor.
* @param string plugin, the plugin that created the button/menu.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
is_highlighted : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
return !element.hasClass(CSS.HIGHLIGHT);
},
/**
* Enable a single widget in the toolbar.
* @param string elementid, the element id of this editor.
@ -271,6 +288,42 @@ M.editor_atto = M.editor_atto || {
}
},
/**
* Highlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
add_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.addClass(CSS.HIGHLIGHT);
}
},
/**
* Unhighlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
remove_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.removeClass(CSS.HIGHLIGHT);
}
},
/**
* Enable all buttons and menus in the toolbar.
* @param string elementid, the element id of this editor.
@ -558,8 +611,9 @@ M.editor_atto = M.editor_atto || {
// Hide the old textarea.
textarea.hide();
atto.on('keydown', this.save_selection, this, params.elementid);
atto.on('mouseup', this.save_selection, this, params.elementid);
this.publish_events();
atto.on('atto:selectionchanged', this.save_selection, this, params.elementid);
atto.on('focus', this.restore_selection, this, params.elementid);
// Do not restore selection when focus is from a click event.
atto.on('mousedown', function() { this.focusfromclick = true; }, this);
@ -607,6 +661,87 @@ M.editor_atto = M.editor_atto || {
}
}
}
},
/**
* Add code to trigger the a set of custom events on either the toolbar, or the contenteditable node
* that can be listened to by plugins (or even this class).
* @param string elementid - the id of the textarea we created this editor from.
*/
publish_events : function() {
Y.Event.define("atto:selectionchanged", {
/**
* Catch the keydown/mouseup events, and fire a synthetic event for the change event.
* @param {Y.Event} e - The real event that triggers this synthetic one.
* @param {Object} params - Object containing the subscription object and the notifier.
*/
changeHandler: function (e, params) {
// Add 3 properties to the event.
// 1. add the elementid.
var elementid = params.sub.node.getAttribute('id');
// Strip 'editable' from the end of the id.
elementid = elementid.substring(0, elementid.length - 8);
e.elementid = elementid;
// 2. The list of leaf nodes contained in the selection.
e.selectedNodes = M.editor_atto.get_selected_nodes(elementid);
// 3. The current selection (Range)
e.selection = M.editor_atto.get_selection();
params.notifier.fire(e);
},
/**
* Subscribe to the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
*/
on: function (node, sub, notifier) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetach = node.on('keydown', Y.throttle(this.changeHandler, 100), this, params);
sub.attoMouseUpDetach = node.on('mouseup', Y.throttle(this.changeHandler, 100), this, params);
sub.attoFocusDetach = node.on('focus', Y.throttle(this.changeHandler, 100), this, params);
},
/**
* Detach the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detach: function (node, sub) {
sub.attoKeyDownDetach.detach();
sub.attoMouseUpDetach.detach();
sub.attoFocusDetach.detach();
},
/**
* Delegate the atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
* @param {String} filter - CSS selector for the filter.
*/
delegate: function(node, sub, notifier, filter) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetachDelegate = node.delegate('keydown', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoMouseUpDetachDelegate = node.delegate('mouseup', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoFocusDetachDelegate = node.delegate('focus', Y.throttle(this.changeHandler, 100), filter, this, params);
},
/**
* Detach a delegated atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detachDelegate: function(node, sub) {
sub.attoKeyDownDetachDelegate.detach();
sub.attoMouseUpDetachDelegate.detach();
sub.attoFocusDetachDelegate.detach();
}
});
},
/**
@ -825,6 +960,169 @@ M.editor_atto = M.editor_atto || {
return sel.inRange(range);
},
/**
* Runs a selector on each node in the selection and will only return true if all nodes
* in the selection match the filter.
*
* @param {String} elementid
* @param {String} selector
* @param {NodeList} selectednodes (Optional) - for performance we can pass this instead of looking it up.
* @return {Boolean}
*/
selection_filter_matches : function(elementid, selector, selectednodes) {
var result = true;
if (!selectednodes) {
// Find this because it was not passed as a param.
selectednodes = M.editor_atto.get_selected_nodes(elementid);
}
selector = '.' + CSS.CONTENT + ' ' + selector;
if (selectednodes.size() === 0) {
return false;
}
selectednodes.each(function(node) {
if (!node.ancestor(selector, true)) {
result = false;
}
});
return result;
},
/**
* Returns a list of nodes that are ancestors of the selection nodes,
* and match the specified css selector (and are contained within the editable div).
*
* @param {String} elementid
* @param {String} selector
* @return Y.NodeList
*/
selection_filter : function(elementid, selector) {
var selectednodes = M.editor_atto.get_selected_nodes(elementid);
var result = new Y.NodeList();
selector = '.' + CSS.CONTENT + ' ' + selector;
selectednodes.each(function(node) {
node.ancestors(selector, true).each(function(match) {
if (result.indexOf(match) === -1) {
result.push(match);
}
});
});
return result;
},
/**
* Get the deepest possible list of nodes in the current selection.
* @param {String} elementid
* @return Y.NodeList
*/
get_selected_nodes : function(elementid) {
var editable = M.editor_atto.get_editable_node(elementid);
var startnode = M.editor_atto.get_selection_start_container();
var endnode = M.editor_atto.get_selection_end_container();
if (!startnode || !endnode) {
return new Y.NodeList();
}
/**
* Recursive function to walk the dom tree between 2 nodes and build
* a list of leaf nodes.
* @param {Y.Node} node - The current node.
* @param {Y.Node} endnode - The node to stop at.
* @param {Y.Node} boundingnode - A node that will contain the selection - do not result results outside this node.
* @param {Integer} skipchildren - When returning from a child to a parent, this is how many children to skip.
* @param {Boolean} isstart - Only true for the starting condition. Used in the case when startnode == endnode.
* @return {Y.NodeList} The list of leaf nodes found.
*/
var find_leaf_nodes = function(node, endnode, boundingnode, skipchildren, isstart) {
var leafnodes = new Y.NodeList();
if (endnode === node) {
// If there are child nodes and we didn't come from a child node, then skip this end condition.
if (!(endnode === node && startnode === node && isstart && node.hasChildNodes())) {
// If the end node is a leaf - return it.
if (!node.hasChildNodes()) {
leafnodes.push(node);
}
// We reached the end of the selection.
return leafnodes;
}
}
// Node is not a leaf, look at it's children.
if (node.hasChildNodes()) {
var children = node.get('childNodes');
// Skipchildren is used when returning from a child node, to make the parent look at the next child node.
var child = children.item(skipchildren);
if (child) {
// There was a child node, find all the leaf nodes in it.
leafnodes.concat(find_leaf_nodes(child, endnode, boundingnode, 0, false));
}
} else {
// This node has no children - so save it.
leafnodes.push(node);
}
// If we hit the bounding node - this is an end condition.
if (node === boundingnode) {
return leafnodes;
}
// We have added all the nodes in this branch, look at the next child of the parent.
var parent = node.ancestor();
if (parent) {
var currentindex = parent.get('childNodes').indexOf(node);
leafnodes.concat(find_leaf_nodes(parent, endnode, boundingnode, currentindex + 1, false));
}
return leafnodes;
};
// Kick off the recursive function.
return find_leaf_nodes(startnode, endnode, editable, 0, true);
},
/**
* Get the first node that contains the current selection.
* @return DOMNode or false
*/
get_selection_start_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.startContainer) {
return Y.one(selection.startContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(true);
return Y.one(range.parentElement());
}
},
/**
* Get the last node that contains the current selection.
* @return DOMNode or false
*/
get_selection_end_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.endContainer) {
return Y.one(selection.endContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(false);
return Y.one(range.parentElement());
}
return false;
},
/**
* Get the dom node representing the common anscestor of the selection nodes.
* @return DOMNode or false
@ -1150,4 +1448,16 @@ Y.Node.addMethod("cleanHTML", cleanHTML);
Y.NodeList.importMethod(Y.Node.prototype, "cleanHTML");
}, '@VERSION@', {"requires": ["node", "io", "overlay", "escape", "event", "event-simulate", "moodle-core-notification"]});
}, '@VERSION@', {
"requires": [
"node",
"io",
"overlay",
"escape",
"event",
"event-simulate",
"event-custom",
"yui-throttle",
"moodle-core-notification"
]
});

View File

@ -28,7 +28,8 @@ CSS = {
CONTENT: 'editor_atto_content',
CONTENTWRAPPER: 'editor_atto_content_wrap',
TOOLBAR: 'editor_atto_toolbar',
WRAPPER: 'editor_atto'
WRAPPER: 'editor_atto',
HIGHLIGHT: 'highlight'
};
/**
@ -251,6 +252,22 @@ M.editor_atto = M.editor_atto || {
return !element.hasAttribute('disabled');
},
/**
* Determine if the specified toolbar button/menu is highlighted.
* @param string elementid, the element id of this editor.
* @param string plugin, the plugin that created the button/menu.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
is_highlighted : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
return !element.hasClass(CSS.HIGHLIGHT);
},
/**
* Enable a single widget in the toolbar.
* @param string elementid, the element id of this editor.
@ -269,6 +286,42 @@ M.editor_atto = M.editor_atto || {
}
},
/**
* Highlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
add_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.addClass(CSS.HIGHLIGHT);
}
},
/**
* Unhighlight a single widget in the toolbar.
* @param string elementid, the element id of this editor.
* @param string plugin, the name of the plugin that created the widget.
* @param string buttonname, optional - used when a plugin has multiple buttons.
*/
remove_widget_highlight : function(elementid, plugin, button) {
var buttonpath = plugin;
if (button) {
buttonpath += '_' + button;
}
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + buttonpath + '_button');
if (element) {
element.removeClass(CSS.HIGHLIGHT);
}
},
/**
* Enable all buttons and menus in the toolbar.
* @param string elementid, the element id of this editor.
@ -556,8 +609,9 @@ M.editor_atto = M.editor_atto || {
// Hide the old textarea.
textarea.hide();
atto.on('keydown', this.save_selection, this, params.elementid);
atto.on('mouseup', this.save_selection, this, params.elementid);
this.publish_events();
atto.on('atto:selectionchanged', this.save_selection, this, params.elementid);
atto.on('focus', this.restore_selection, this, params.elementid);
// Do not restore selection when focus is from a click event.
atto.on('mousedown', function() { this.focusfromclick = true; }, this);
@ -605,6 +659,87 @@ M.editor_atto = M.editor_atto || {
}
}
}
},
/**
* Add code to trigger the a set of custom events on either the toolbar, or the contenteditable node
* that can be listened to by plugins (or even this class).
* @param string elementid - the id of the textarea we created this editor from.
*/
publish_events : function() {
Y.Event.define("atto:selectionchanged", {
/**
* Catch the keydown/mouseup events, and fire a synthetic event for the change event.
* @param {Y.Event} e - The real event that triggers this synthetic one.
* @param {Object} params - Object containing the subscription object and the notifier.
*/
changeHandler: function (e, params) {
// Add 3 properties to the event.
// 1. add the elementid.
var elementid = params.sub.node.getAttribute('id');
// Strip 'editable' from the end of the id.
elementid = elementid.substring(0, elementid.length - 8);
e.elementid = elementid;
// 2. The list of leaf nodes contained in the selection.
e.selectedNodes = M.editor_atto.get_selected_nodes(elementid);
// 3. The current selection (Range)
e.selection = M.editor_atto.get_selection();
params.notifier.fire(e);
},
/**
* Subscribe to the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
*/
on: function (node, sub, notifier) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetach = node.on('keydown', Y.throttle(this.changeHandler, 100), this, params);
sub.attoMouseUpDetach = node.on('mouseup', Y.throttle(this.changeHandler, 100), this, params);
sub.attoFocusDetach = node.on('focus', Y.throttle(this.changeHandler, 100), this, params);
},
/**
* Detach the atto:selectionchanged event.
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detach: function (node, sub) {
sub.attoKeyDownDetach.detach();
sub.attoMouseUpDetach.detach();
sub.attoFocusDetach.detach();
},
/**
* Delegate the atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
* @param {Y.Event.Notifier} notifier - YUI notifier object.
* @param {String} filter - CSS selector for the filter.
*/
delegate: function(node, sub, notifier, filter) {
var params = { notifier: notifier, sub: sub };
sub.attoKeyDownDetachDelegate = node.delegate('keydown', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoMouseUpDetachDelegate = node.delegate('mouseup', Y.throttle(this.changeHandler, 100), filter, this, params);
sub.attoFocusDetachDelegate = node.delegate('focus', Y.throttle(this.changeHandler, 100), filter, this, params);
},
/**
* Detach a delegated atto:selectionchanged event.
*
* @param {Y.Node} node - The node for the subscription - must be the contenteditable node.
* @param {Y.Subscription} sub - YUI Subscription object.
*/
detachDelegate: function(node, sub) {
sub.attoKeyDownDetachDelegate.detach();
sub.attoMouseUpDetachDelegate.detach();
sub.attoFocusDetachDelegate.detach();
}
});
},
/**
@ -823,6 +958,169 @@ M.editor_atto = M.editor_atto || {
return sel.inRange(range);
},
/**
* Runs a selector on each node in the selection and will only return true if all nodes
* in the selection match the filter.
*
* @param {String} elementid
* @param {String} selector
* @param {NodeList} selectednodes (Optional) - for performance we can pass this instead of looking it up.
* @return {Boolean}
*/
selection_filter_matches : function(elementid, selector, selectednodes) {
var result = true;
if (!selectednodes) {
// Find this because it was not passed as a param.
selectednodes = M.editor_atto.get_selected_nodes(elementid);
}
selector = '.' + CSS.CONTENT + ' ' + selector;
if (selectednodes.size() === 0) {
return false;
}
selectednodes.each(function(node) {
if (!node.ancestor(selector, true)) {
result = false;
}
});
return result;
},
/**
* Returns a list of nodes that are ancestors of the selection nodes,
* and match the specified css selector (and are contained within the editable div).
*
* @param {String} elementid
* @param {String} selector
* @return Y.NodeList
*/
selection_filter : function(elementid, selector) {
var selectednodes = M.editor_atto.get_selected_nodes(elementid);
var result = new Y.NodeList();
selector = '.' + CSS.CONTENT + ' ' + selector;
selectednodes.each(function(node) {
node.ancestors(selector, true).each(function(match) {
if (result.indexOf(match) === -1) {
result.push(match);
}
});
});
return result;
},
/**
* Get the deepest possible list of nodes in the current selection.
* @param {String} elementid
* @return Y.NodeList
*/
get_selected_nodes : function(elementid) {
var editable = M.editor_atto.get_editable_node(elementid);
var startnode = M.editor_atto.get_selection_start_container();
var endnode = M.editor_atto.get_selection_end_container();
if (!startnode || !endnode) {
return new Y.NodeList();
}
/**
* Recursive function to walk the dom tree between 2 nodes and build
* a list of leaf nodes.
* @param {Y.Node} node - The current node.
* @param {Y.Node} endnode - The node to stop at.
* @param {Y.Node} boundingnode - A node that will contain the selection - do not result results outside this node.
* @param {Integer} skipchildren - When returning from a child to a parent, this is how many children to skip.
* @param {Boolean} isstart - Only true for the starting condition. Used in the case when startnode == endnode.
* @return {Y.NodeList} The list of leaf nodes found.
*/
var find_leaf_nodes = function(node, endnode, boundingnode, skipchildren, isstart) {
var leafnodes = new Y.NodeList();
if (endnode === node) {
// If there are child nodes and we didn't come from a child node, then skip this end condition.
if (!(endnode === node && startnode === node && isstart && node.hasChildNodes())) {
// If the end node is a leaf - return it.
if (!node.hasChildNodes()) {
leafnodes.push(node);
}
// We reached the end of the selection.
return leafnodes;
}
}
// Node is not a leaf, look at it's children.
if (node.hasChildNodes()) {
var children = node.get('childNodes');
// Skipchildren is used when returning from a child node, to make the parent look at the next child node.
var child = children.item(skipchildren);
if (child) {
// There was a child node, find all the leaf nodes in it.
leafnodes.concat(find_leaf_nodes(child, endnode, boundingnode, 0, false));
}
} else {
// This node has no children - so save it.
leafnodes.push(node);
}
// If we hit the bounding node - this is an end condition.
if (node === boundingnode) {
return leafnodes;
}
// We have added all the nodes in this branch, look at the next child of the parent.
var parent = node.ancestor();
if (parent) {
var currentindex = parent.get('childNodes').indexOf(node);
leafnodes.concat(find_leaf_nodes(parent, endnode, boundingnode, currentindex + 1, false));
}
return leafnodes;
};
// Kick off the recursive function.
return find_leaf_nodes(startnode, endnode, editable, 0, true);
},
/**
* Get the first node that contains the current selection.
* @return DOMNode or false
*/
get_selection_start_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.startContainer) {
return Y.one(selection.startContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(true);
return Y.one(range.parentElement());
}
},
/**
* Get the last node that contains the current selection.
* @return DOMNode or false
*/
get_selection_end_container : function() {
var selection = M.editor_atto.get_selection();
if (selection.length) {
selection = selection.pop();
}
if (selection.endContainer) {
return Y.one(selection.endContainer);
} else if (selection.parentElement) {
var range = selection.duplicate();
range.collapse(false);
return Y.one(range.parentElement());
}
return false;
},
/**
* Get the dom node representing the common anscestor of the selection nodes.
* @return DOMNode or false

View File

@ -7,6 +7,8 @@
"escape",
"event",
"event-simulate",
"event-custom",
"yui-throttle",
"moodle-core-notification"
]
}