MDL-44127 Atto: Improve Atto API to allow plugins with multiple buttons/menus

This commit is contained in:
Damyon Wiese
2014-03-26 10:01:42 +08:00
parent 8095505e3c
commit 5ec54dd125
16 changed files with 243 additions and 116 deletions
@@ -74,6 +74,8 @@ M.atto_backcolor = M.atto_backcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4');
},
@@ -131,4 +133,5 @@ M.atto_backcolor = M.atto_backcolor || {
}
};
}, '@VERSION@');
@@ -1 +1 @@
YUI.add("moodle-atto_backcolor-button",function(e,t){M.atto_backcolor=M.atto_backcolor||{init:function(e){var t="backcolor",n="#FFFFFF",r="#EF4540",i="#FFCF35",s="#98CA3E",o="#7D9FD3",u="#333333",a=function(e,t){M.atto_backcolor.change_color(e,t,n)},f=function(e,t){M.atto_backcolor.change_color(e,t,r)},l=function(e,t){M.atto_backcolor.change_color(e,t,i)},c=function(e,t){M.atto_backcolor.change_color(e,t,s)},h=function(e,t){M.atto_backcolor.change_color(e,t,o)},p=function(e,t){M.atto_backcolor.change_color(e,t,u)},d="width: 20px; height: 20px; border: 1px solid #CCC; background-color: ",v='<div style="'+d+n+'"></div>',m='<div style="'+d+r+'"></div>',g='<div style="'+d+i+'"></div>',y='<div style="'+d+s+'"></div>',b='<div style="'+d+o+'"></div>',w='<div style="'+d+u+'"></div>',E=M.util.image_url("e/text_highlight","core");M.editor_atto.add_toolbar_menu(e.elementid,t,E,e.group,[{text:v,handler:a},{text:m,handler:f},{text:g,handler:l},{text:y,handler:c},{text:b,handler:h},{text:w,handler:p}],"4")},change_color:function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t);if(window.getSelection)try{document.execCommand("BackColor",!1,n)||M.atto_backcolor.set_back_color(n)}catch(r){M.atto_backcolor.set_back_color(n)}else document.selection&&document.selection.createRange&&(range=document.selection.createRange(),range.execCommand("BackColor",!1,n));M.editor_atto.text_updated(t)},set_back_color:function(e){var t=window.getSelection(),n=null;t.rangeCount&&t.getRangeAt&&(n=t.getRangeAt(0)),document.designMode="on",n&&(t.removeAllRanges(),t.addRange(n)),document.execCommand("HiliteColor",!1,e)||document.execCommand("BackColor",!1,e),document.designMode="off"}}},"@VERSION@");
YUI.add("moodle-atto_backcolor-button",function(e,t){M.atto_backcolor=M.atto_backcolor||{init:function(e){var t="backcolor",n="#FFFFFF",r="#EF4540",i="#FFCF35",s="#98CA3E",o="#7D9FD3",u="#333333",a=function(e,t){M.atto_backcolor.change_color(e,t,n)},f=function(e,t){M.atto_backcolor.change_color(e,t,r)},l=function(e,t){M.atto_backcolor.change_color(e,t,i)},c=function(e,t){M.atto_backcolor.change_color(e,t,s)},h=function(e,t){M.atto_backcolor.change_color(e,t,o)},p=function(e,t){M.atto_backcolor.change_color(e,t,u)},d="width: 20px; height: 20px; border: 1px solid #CCC; background-color: ",v='<div style="'+d+n+'"></div>',m='<div style="'+d+r+'"></div>',g='<div style="'+d+i+'"></div>',y='<div style="'+d+s+'"></div>',b='<div style="'+d+o+'"></div>',w='<div style="'+d+u+'"></div>',E=M.util.image_url("e/text_highlight","core");M.editor_atto.add_toolbar_menu(e.elementid,t,E,e.group,[{text:v,handler:a},{text:m,handler:f},{text:g,handler:l},{text:y,handler:c},{text:b,handler:h},{text:w,handler:p}],!1,!1,"4")},change_color:function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t);if(window.getSelection)try{document.execCommand("BackColor",!1,n)||M.atto_backcolor.set_back_color(n)}catch(r){M.atto_backcolor.set_back_color(n)}else document.selection&&document.selection.createRange&&(range=document.selection.createRange(),range.execCommand("BackColor",!1,n));M.editor_atto.text_updated(t)},set_back_color:function(e){var t=window.getSelection(),n=null;t.rangeCount&&t.getRangeAt&&(n=t.getRangeAt(0)),document.designMode="on",n&&(t.removeAllRanges(),t.addRange(n)),document.execCommand("HiliteColor",!1,e)||document.execCommand("BackColor",!1,e),document.designMode="off"}}},"@VERSION@");
@@ -74,6 +74,8 @@ M.atto_backcolor = M.atto_backcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4');
},
@@ -131,4 +133,5 @@ M.atto_backcolor = M.atto_backcolor || {
}
};
}, '@VERSION@');
@@ -72,6 +72,8 @@ M.atto_backcolor = M.atto_backcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4');
},
@@ -127,4 +129,4 @@ M.atto_backcolor = M.atto_backcolor || {
}
document.designMode = "off";
}
};
};
@@ -75,6 +75,8 @@ M.atto_fontcolor = M.atto_fontcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4',
'#333333');
},
@@ -96,4 +98,5 @@ M.atto_fontcolor = M.atto_fontcolor || {
}
};
}, '@VERSION@');
@@ -1 +1 @@
YUI.add("moodle-atto_fontcolor-button",function(e,t){M.atto_fontcolor=M.atto_fontcolor||{dialogue:null,init:function(e){var t="fontcolor",n="#FFFFFF",r="#EF4540",i="#FFCF35",s="#98CA3E",o="#7D9FD3",u="#333333",a=function(e,t){M.atto_fontcolor.change_color(e,t,"transparent")},f=function(e,t){M.atto_fontcolor.change_color(e,t,r)},l=function(e,t){M.atto_fontcolor.change_color(e,t,i)},c=function(e,t){M.atto_fontcolor.change_color(e,t,s)},h=function(e,t){M.atto_fontcolor.change_color(e,t,o)},p=function(e,t){M.atto_fontcolor.change_color(e,t,u)},d="width: 20px; height: 20px; border: 1px solid #CCC; background-color: ",v='<div style="'+d+n+'"></div>',m='<div style="'+d+r+'"></div>',g='<div style="'+d+i+'"></div>',y='<div style="'+d+s+'"></div>',b='<div style="'+d+o+'"></div>',w='<div style="'+d+u+'"></div>',E=M.util.image_url("e/text_color","core");M.editor_atto.add_toolbar_menu(e.elementid,t,E,e.group,[{text:v,handler:a},{text:m,handler:f},{text:g,handler:l},{text:y,handler:c},{text:b,handler:h},{text:w,handler:p}],"4","#333333")},change_color:function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("foreColor",0,n),M.editor_atto.text_updated(t)}}},"@VERSION@");
YUI.add("moodle-atto_fontcolor-button",function(e,t){M.atto_fontcolor=M.atto_fontcolor||{dialogue:null,init:function(e){var t="fontcolor",n="#FFFFFF",r="#EF4540",i="#FFCF35",s="#98CA3E",o="#7D9FD3",u="#333333",a=function(e,t){M.atto_fontcolor.change_color(e,t,"transparent")},f=function(e,t){M.atto_fontcolor.change_color(e,t,r)},l=function(e,t){M.atto_fontcolor.change_color(e,t,i)},c=function(e,t){M.atto_fontcolor.change_color(e,t,s)},h=function(e,t){M.atto_fontcolor.change_color(e,t,o)},p=function(e,t){M.atto_fontcolor.change_color(e,t,u)},d="width: 20px; height: 20px; border: 1px solid #CCC; background-color: ",v='<div style="'+d+n+'"></div>',m='<div style="'+d+r+'"></div>',g='<div style="'+d+i+'"></div>',y='<div style="'+d+s+'"></div>',b='<div style="'+d+o+'"></div>',w='<div style="'+d+u+'"></div>',E=M.util.image_url("e/text_color","core");M.editor_atto.add_toolbar_menu(e.elementid,t,E,e.group,[{text:v,handler:a},{text:m,handler:f},{text:g,handler:l},{text:y,handler:c},{text:b,handler:h},{text:w,handler:p}],!1,!1,"4","#333333")},change_color:function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),document.execCommand("foreColor",0,n),M.editor_atto.text_updated(t)}}},"@VERSION@");
@@ -75,6 +75,8 @@ M.atto_fontcolor = M.atto_fontcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4',
'#333333');
},
@@ -96,4 +98,5 @@ M.atto_fontcolor = M.atto_fontcolor || {
}
};
}, '@VERSION@');
@@ -73,6 +73,8 @@ M.atto_fontcolor = M.atto_fontcolor || {
{'text' : blue, 'handler' : click_blue},
{'text' : black, 'handler' : click_black}
],
false,
false,
'4',
'#333333');
},
@@ -92,4 +94,4 @@ M.atto_fontcolor = M.atto_fontcolor || {
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
};
};
@@ -58,10 +58,10 @@ M.atto_rtl = M.atto_rtl || {
};
var iconurl = M.util.image_url('e/left_to_right', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'ltr', iconurl, params.group, ltrclick, M.util.get_string('ltr', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, ltrclick, 'ltr', M.util.get_string('ltr', 'atto_rtl'));
iconurl = M.util.image_url('e/right_to_left', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, M.util.get_string('rtl', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, 'rtl', M.util.get_string('rtl', 'atto_rtl'));
}
};
@@ -1 +1 @@
YUI.add("moodle-atto_rtl-button",function(e,t){M.atto_rtl=M.atto_rtl||{init:function(e){var t=function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_rtl.selection=M.editor_atto.get_selection();if(M.atto_rtl.selection!==!1){var r=M.editor_atto.format_selection_block(t);parentnodeelement=r.getDOMNode();var i=parentnodeelement.getAttribute("dir");i===n?parentnodeelement.removeAttribute("dir"):parentnodeelement.setAttribute("dir",n)}M.editor_atto.text_updated(t)},n=function(e,n){t(e,n,"rtl")},r=function(e,n){t(e,n,"ltr")},i=M.util.image_url("e/left_to_right","core");M.editor_atto.add_toolbar_button(e.elementid,"ltr",i,e.group,r,M.util.get_string("ltr","atto_rtl")),i=M.util.image_url("e/right_to_left","core"),M.editor_atto.add_toolbar_button(e.elementid,"rtl",i,e.group,n,M.util.get_string("rtl","atto_rtl"))}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_rtl-button",function(e,t){M.atto_rtl=M.atto_rtl||{init:function(e){var t=function(e,t,n){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_rtl.selection=M.editor_atto.get_selection();if(M.atto_rtl.selection!==!1){var r=M.editor_atto.format_selection_block(t);parentnodeelement=r.getDOMNode();var i=parentnodeelement.getAttribute("dir");i===n?parentnodeelement.removeAttribute("dir"):parentnodeelement.setAttribute("dir",n)}M.editor_atto.text_updated(t)},n=function(e,n){t(e,n,"rtl")},r=function(e,n){t(e,n,"ltr")},i=M.util.image_url("e/left_to_right","core");M.editor_atto.add_toolbar_button(e.elementid,"rtl",i,e.group,r,"ltr",M.util.get_string("ltr","atto_rtl")),i=M.util.image_url("e/right_to_left","core"),M.editor_atto.add_toolbar_button(e.elementid,"rtl",i,e.group,n,"rtl",M.util.get_string("rtl","atto_rtl"))}}},"@VERSION@",{requires:["node"]});
@@ -58,10 +58,10 @@ M.atto_rtl = M.atto_rtl || {
};
var iconurl = M.util.image_url('e/left_to_right', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'ltr', iconurl, params.group, ltrclick, M.util.get_string('ltr', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, ltrclick, 'ltr', M.util.get_string('ltr', 'atto_rtl'));
iconurl = M.util.image_url('e/right_to_left', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, M.util.get_string('rtl', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, 'rtl', M.util.get_string('rtl', 'atto_rtl'));
}
};
+2 -2
View File
@@ -56,9 +56,9 @@ M.atto_rtl = M.atto_rtl || {
};
var iconurl = M.util.image_url('e/left_to_right', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'ltr', iconurl, params.group, ltrclick, M.util.get_string('ltr', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, ltrclick, 'ltr', M.util.get_string('ltr', 'atto_rtl'));
iconurl = M.util.image_url('e/right_to_left', 'core');
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, M.util.get_string('rtl', 'atto_rtl'));
M.editor_atto.add_toolbar_button(params.elementid, 'rtl', iconurl, params.group, rtlclick, 'rtl', M.util.get_string('rtl', 'atto_rtl'));
}
};
@@ -159,6 +159,7 @@ M.editor_atto = M.editor_atto || {
buttonclicked_handler : function(e) {
var elementid = this.getAttribute('data-editor');
var plugin = this.getAttribute('data-plugin');
var button = this.getAttribute('data-button');
var handler = this.getAttribute('data-handler');
var overlay = M.editor_atto.menus[plugin + '_' + elementid];
var toolbar = M.editor_atto.get_toolbar_node(elementid);
@@ -178,7 +179,7 @@ M.editor_atto = M.editor_atto || {
overlay.hide();
}
if (M.editor_atto.is_enabled(elementid, plugin)) {
if (M.editor_atto.is_enabled(elementid, plugin, button)) {
// Pass it on.
handler = M.editor_atto.buttonhandlers[handler];
return handler(e, elementid);
@@ -240,9 +241,14 @@ M.editor_atto = M.editor_atto || {
* Determine if the specified toolbar button/menu is enabled.
* @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_enabled : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
is_enabled : 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.hasAttribute('disabled');
},
@@ -251,9 +257,14 @@ M.editor_atto = M.editor_atto || {
* Enable 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.
*/
enable_widget : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
enable_widget : 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.removeAttribute('disabled');
@@ -265,9 +276,9 @@ M.editor_atto = M.editor_atto || {
* @param string elementid, the element id of this editor.
*/
enable_all_widgets : function(elementid) {
var plugin, element;
for (plugin in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
var path, element;
for (path in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + path + '_button');
if (element) {
element.removeAttribute('disabled');
@@ -298,16 +309,30 @@ M.editor_atto = M.editor_atto || {
* @param string icon - the html used for the content of the button
* @param string groupname - the group the button should be appended to.
* @param array entries - List of menu entries with the string (entry.text) and the handlers (entry.handler).
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
* @param int overlaywidth - the overlay width size in 'ems'.
* @param string menucolor - menu icon background color
*/
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, overlaywidth, menucolor) {
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, buttonname, buttontitle, overlaywidth, menucolor) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
currentfocus,
button,
buttonpath,
expimgurl;
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if ((typeof overlaywidth) === 'undefined') {
overlaywidth = '14';
}
@@ -320,12 +345,12 @@ M.editor_atto = M.editor_atto || {
toolbar.append(group);
}
expimgurl = M.util.image_url('t/expanded', 'moodle');
button = Y.Node.create('<button class="atto_' + plugin + '_button atto_hasmenu" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button atto_hasmenu" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'tabindex="-1" ' +
'type="button" ' +
'data-menu="' + plugin + '_' + elementid + '" ' +
'title="' + Y.Escape.html(M.util.get_string('pluginname', 'atto_' + plugin)) + '">' +
'data-menu="' + buttonpath + '_' + elementid + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" '+
'style="background-color:' + menucolor + ';" src="' + iconurl + '"/>' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + expimgurl + '"/>' +
@@ -341,9 +366,9 @@ M.editor_atto = M.editor_atto || {
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
var menu = Y.Node.create('<div class="atto_' + plugin + '_menu' +
var menu = Y.Node.create('<div class="atto_' + buttonpath + '_menu' +
' atto_menu" data-editor="' + Y.Escape.html(elementid) + '"' +
' style="min-width:' + (overlaywidth-2) + 'em"' +
'"></div>');
@@ -353,23 +378,25 @@ M.editor_atto = M.editor_atto || {
entry = entries[i];
menu.append(Y.Node.create('<div class="atto_menuentry">' +
'<a href="#" class="atto_' + plugin + '_action_' + i + '" ' +
'<a href="#" class="atto_' + buttonpath + '_action_' + i + '" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-handler="' + Y.Escape.html(plugin + '_action_' + i) + '">' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'data-handler="' + Y.Escape.html(buttonpath + '_action_' + i) + '">' +
entry.text +
'</a>' +
'</div>'));
if (!M.editor_atto.buttonhandlers[plugin + '_action_' + i]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_action_' + i);
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, 'space,enter', '.atto_' + plugin + '_action_' + i);
M.editor_atto.buttonhandlers[plugin + '_action_' + i] = entry.handler;
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_action_' + i);
// Activate the link on space or enter.
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, '32,enter', '.atto_' + buttonpath + '_action_' + i);
M.editor_atto.buttonhandlers[buttonpath + '_action_' + i] = entry.handler;
}
}
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = true;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = true;
}
var overlay = new M.core.dialogue({
@@ -381,7 +408,7 @@ M.editor_atto = M.editor_atto || {
center : false
});
M.editor_atto.menus[plugin + '_' + elementid] = overlay;
M.editor_atto.menus[buttonpath + '_' + elementid] = overlay;
overlay.align(button, [Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.BL]);
overlay.hide();
overlay.headerNode.hide();
@@ -394,29 +421,39 @@ M.editor_atto = M.editor_atto || {
* @param string plugin - the plugin defining the button.
* @param string icon - the url to the image for the icon
* @param string groupname - the group the button should be appended to.
* @param string title - button title. If null, then the title is the 'pluginname' string.
* @handler function handler- A function to call when the button is clicked.
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
*/
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, title) {
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, buttonname, buttontitle) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
button,
buttonpath,
currentfocus;
if (!title) {
title = M.util.get_string('pluginname', 'atto_' + plugin);
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if (!group) {
group = Y.Node.create('<div class="atto_group ' + groupname +'_group"></div>');
toolbar.append(group);
}
button = Y.Node.create('<button class="atto_' + plugin + '_button" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'tabindex="-1" ' +
'data-handler="' + Y.Escape.html(plugin) + '" ' +
'title="' + Y.Escape.html(title) + '">' +
'data-handler="' + Y.Escape.html(buttonpath) + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + iconurl + '"/>' +
'</button>');
@@ -430,13 +467,13 @@ M.editor_atto = M.editor_atto || {
}
// We only need to attach this once.
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = handler;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = handler;
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
},
File diff suppressed because one or more lines are too long
@@ -159,6 +159,7 @@ M.editor_atto = M.editor_atto || {
buttonclicked_handler : function(e) {
var elementid = this.getAttribute('data-editor');
var plugin = this.getAttribute('data-plugin');
var button = this.getAttribute('data-button');
var handler = this.getAttribute('data-handler');
var overlay = M.editor_atto.menus[plugin + '_' + elementid];
var toolbar = M.editor_atto.get_toolbar_node(elementid);
@@ -178,7 +179,7 @@ M.editor_atto = M.editor_atto || {
overlay.hide();
}
if (M.editor_atto.is_enabled(elementid, plugin)) {
if (M.editor_atto.is_enabled(elementid, plugin, button)) {
// Pass it on.
handler = M.editor_atto.buttonhandlers[handler];
return handler(e, elementid);
@@ -240,9 +241,14 @@ M.editor_atto = M.editor_atto || {
* Determine if the specified toolbar button/menu is enabled.
* @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_enabled : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
is_enabled : 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.hasAttribute('disabled');
},
@@ -251,9 +257,14 @@ M.editor_atto = M.editor_atto || {
* Enable 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.
*/
enable_widget : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
enable_widget : 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.removeAttribute('disabled');
@@ -265,9 +276,9 @@ M.editor_atto = M.editor_atto || {
* @param string elementid, the element id of this editor.
*/
enable_all_widgets : function(elementid) {
var plugin, element;
for (plugin in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
var path, element;
for (path in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + path + '_button');
if (element) {
element.removeAttribute('disabled');
@@ -298,16 +309,30 @@ M.editor_atto = M.editor_atto || {
* @param string icon - the html used for the content of the button
* @param string groupname - the group the button should be appended to.
* @param array entries - List of menu entries with the string (entry.text) and the handlers (entry.handler).
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
* @param int overlaywidth - the overlay width size in 'ems'.
* @param string menucolor - menu icon background color
*/
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, overlaywidth, menucolor) {
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, buttonname, buttontitle, overlaywidth, menucolor) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
currentfocus,
button,
buttonpath,
expimgurl;
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if ((typeof overlaywidth) === 'undefined') {
overlaywidth = '14';
}
@@ -320,12 +345,12 @@ M.editor_atto = M.editor_atto || {
toolbar.append(group);
}
expimgurl = M.util.image_url('t/expanded', 'moodle');
button = Y.Node.create('<button class="atto_' + plugin + '_button atto_hasmenu" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button atto_hasmenu" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'tabindex="-1" ' +
'type="button" ' +
'data-menu="' + plugin + '_' + elementid + '" ' +
'title="' + Y.Escape.html(M.util.get_string('pluginname', 'atto_' + plugin)) + '">' +
'data-menu="' + buttonpath + '_' + elementid + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" '+
'style="background-color:' + menucolor + ';" src="' + iconurl + '"/>' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + expimgurl + '"/>' +
@@ -341,9 +366,9 @@ M.editor_atto = M.editor_atto || {
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
var menu = Y.Node.create('<div class="atto_' + plugin + '_menu' +
var menu = Y.Node.create('<div class="atto_' + buttonpath + '_menu' +
' atto_menu" data-editor="' + Y.Escape.html(elementid) + '"' +
' style="min-width:' + (overlaywidth-2) + 'em"' +
'"></div>');
@@ -353,23 +378,25 @@ M.editor_atto = M.editor_atto || {
entry = entries[i];
menu.append(Y.Node.create('<div class="atto_menuentry">' +
'<a href="#" class="atto_' + plugin + '_action_' + i + '" ' +
'<a href="#" class="atto_' + buttonpath + '_action_' + i + '" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-handler="' + Y.Escape.html(plugin + '_action_' + i) + '">' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'data-handler="' + Y.Escape.html(buttonpath + '_action_' + i) + '">' +
entry.text +
'</a>' +
'</div>'));
if (!M.editor_atto.buttonhandlers[plugin + '_action_' + i]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_action_' + i);
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, 'space,enter', '.atto_' + plugin + '_action_' + i);
M.editor_atto.buttonhandlers[plugin + '_action_' + i] = entry.handler;
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_action_' + i);
// Activate the link on space or enter.
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, '32,enter', '.atto_' + buttonpath + '_action_' + i);
M.editor_atto.buttonhandlers[buttonpath + '_action_' + i] = entry.handler;
}
}
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = true;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = true;
}
var overlay = new M.core.dialogue({
@@ -381,7 +408,7 @@ M.editor_atto = M.editor_atto || {
center : false
});
M.editor_atto.menus[plugin + '_' + elementid] = overlay;
M.editor_atto.menus[buttonpath + '_' + elementid] = overlay;
overlay.align(button, [Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.BL]);
overlay.hide();
overlay.headerNode.hide();
@@ -394,29 +421,39 @@ M.editor_atto = M.editor_atto || {
* @param string plugin - the plugin defining the button.
* @param string icon - the url to the image for the icon
* @param string groupname - the group the button should be appended to.
* @param string title - button title. If null, then the title is the 'pluginname' string.
* @handler function handler- A function to call when the button is clicked.
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
*/
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, title) {
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, buttonname, buttontitle) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
button,
buttonpath,
currentfocus;
if (!title) {
title = M.util.get_string('pluginname', 'atto_' + plugin);
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if (!group) {
group = Y.Node.create('<div class="atto_group ' + groupname +'_group"></div>');
toolbar.append(group);
}
button = Y.Node.create('<button class="atto_' + plugin + '_button" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'tabindex="-1" ' +
'data-handler="' + Y.Escape.html(plugin) + '" ' +
'title="' + Y.Escape.html(title) + '">' +
'data-handler="' + Y.Escape.html(buttonpath) + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + iconurl + '"/>' +
'</button>');
@@ -430,13 +467,13 @@ M.editor_atto = M.editor_atto || {
}
// We only need to attach this once.
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = handler;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = handler;
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
},
+71 -34
View File
@@ -157,6 +157,7 @@ M.editor_atto = M.editor_atto || {
buttonclicked_handler : function(e) {
var elementid = this.getAttribute('data-editor');
var plugin = this.getAttribute('data-plugin');
var button = this.getAttribute('data-button');
var handler = this.getAttribute('data-handler');
var overlay = M.editor_atto.menus[plugin + '_' + elementid];
var toolbar = M.editor_atto.get_toolbar_node(elementid);
@@ -176,7 +177,7 @@ M.editor_atto = M.editor_atto || {
overlay.hide();
}
if (M.editor_atto.is_enabled(elementid, plugin)) {
if (M.editor_atto.is_enabled(elementid, plugin, button)) {
// Pass it on.
handler = M.editor_atto.buttonhandlers[handler];
return handler(e, elementid);
@@ -238,9 +239,14 @@ M.editor_atto = M.editor_atto || {
* Determine if the specified toolbar button/menu is enabled.
* @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_enabled : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
is_enabled : 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.hasAttribute('disabled');
},
@@ -249,9 +255,14 @@ M.editor_atto = M.editor_atto || {
* Enable 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.
*/
enable_widget : function(elementid, plugin) {
var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
enable_widget : 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.removeAttribute('disabled');
@@ -263,9 +274,9 @@ M.editor_atto = M.editor_atto || {
* @param string elementid, the element id of this editor.
*/
enable_all_widgets : function(elementid) {
var plugin, element;
for (plugin in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button');
var path, element;
for (path in M.editor_atto.widgets) {
element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + path + '_button');
if (element) {
element.removeAttribute('disabled');
@@ -296,16 +307,30 @@ M.editor_atto = M.editor_atto || {
* @param string icon - the html used for the content of the button
* @param string groupname - the group the button should be appended to.
* @param array entries - List of menu entries with the string (entry.text) and the handlers (entry.handler).
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
* @param int overlaywidth - the overlay width size in 'ems'.
* @param string menucolor - menu icon background color
*/
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, overlaywidth, menucolor) {
add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries, buttonname, buttontitle, overlaywidth, menucolor) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
currentfocus,
button,
buttonpath,
expimgurl;
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if ((typeof overlaywidth) === 'undefined') {
overlaywidth = '14';
}
@@ -318,12 +343,12 @@ M.editor_atto = M.editor_atto || {
toolbar.append(group);
}
expimgurl = M.util.image_url('t/expanded', 'moodle');
button = Y.Node.create('<button class="atto_' + plugin + '_button atto_hasmenu" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button atto_hasmenu" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'tabindex="-1" ' +
'type="button" ' +
'data-menu="' + plugin + '_' + elementid + '" ' +
'title="' + Y.Escape.html(M.util.get_string('pluginname', 'atto_' + plugin)) + '">' +
'data-menu="' + buttonpath + '_' + elementid + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" '+
'style="background-color:' + menucolor + ';" src="' + iconurl + '"/>' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + expimgurl + '"/>' +
@@ -339,9 +364,9 @@ M.editor_atto = M.editor_atto || {
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
var menu = Y.Node.create('<div class="atto_' + plugin + '_menu' +
var menu = Y.Node.create('<div class="atto_' + buttonpath + '_menu' +
' atto_menu" data-editor="' + Y.Escape.html(elementid) + '"' +
' style="min-width:' + (overlaywidth-2) + 'em"' +
'"></div>');
@@ -351,23 +376,25 @@ M.editor_atto = M.editor_atto || {
entry = entries[i];
menu.append(Y.Node.create('<div class="atto_menuentry">' +
'<a href="#" class="atto_' + plugin + '_action_' + i + '" ' +
'<a href="#" class="atto_' + buttonpath + '_action_' + i + '" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-handler="' + Y.Escape.html(plugin + '_action_' + i) + '">' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'data-handler="' + Y.Escape.html(buttonpath + '_action_' + i) + '">' +
entry.text +
'</a>' +
'</div>'));
if (!M.editor_atto.buttonhandlers[plugin + '_action_' + i]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_action_' + i);
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, 'space,enter', '.atto_' + plugin + '_action_' + i);
M.editor_atto.buttonhandlers[plugin + '_action_' + i] = entry.handler;
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_action_' + i);
// Activate the link on space or enter.
Y.one('body').delegate('key', M.editor_atto.buttonclicked_handler, '32,enter', '.atto_' + buttonpath + '_action_' + i);
M.editor_atto.buttonhandlers[buttonpath + '_action_' + i] = entry.handler;
}
}
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = true;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.showhide_menu_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = true;
}
var overlay = new M.core.dialogue({
@@ -379,7 +406,7 @@ M.editor_atto = M.editor_atto || {
center : false
});
M.editor_atto.menus[plugin + '_' + elementid] = overlay;
M.editor_atto.menus[buttonpath + '_' + elementid] = overlay;
overlay.align(button, [Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.BL]);
overlay.hide();
overlay.headerNode.hide();
@@ -392,29 +419,39 @@ M.editor_atto = M.editor_atto || {
* @param string plugin - the plugin defining the button.
* @param string icon - the url to the image for the icon
* @param string groupname - the group the button should be appended to.
* @param string title - button title. If null, then the title is the 'pluginname' string.
* @handler function handler- A function to call when the button is clicked.
* @param string buttonname - (optional) a name for the button. Required if a plugin creates more than one button.
* @param string buttontitle - (optional) a title for the button. Required if a plugin creates more than one button.
*/
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, title) {
add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler, buttonname, buttontitle) {
var toolbar = M.editor_atto.get_toolbar_node(elementid),
group = toolbar.one('.atto_group.' + groupname + '_group'),
button,
buttonpath,
currentfocus;
if (!title) {
title = M.util.get_string('pluginname', 'atto_' + plugin);
if (buttonname) {
buttonpath = plugin + '_' + buttonname;
} else {
buttonname = '';
buttonpath = plugin;
}
if (!buttontitle) {
buttontitle = M.util.get_string('pluginname', 'atto_' + plugin);
}
if (!group) {
group = Y.Node.create('<div class="atto_group ' + groupname +'_group"></div>');
toolbar.append(group);
}
button = Y.Node.create('<button class="atto_' + plugin + '_button" ' +
button = Y.Node.create('<button class="atto_' + buttonpath + '_button" ' +
'data-editor="' + Y.Escape.html(elementid) + '" ' +
'data-plugin="' + Y.Escape.html(plugin) + '" ' +
'data-button="' + Y.Escape.html(buttonname) + '" ' +
'tabindex="-1" ' +
'data-handler="' + Y.Escape.html(plugin) + '" ' +
'title="' + Y.Escape.html(title) + '">' +
'data-handler="' + Y.Escape.html(buttonpath) + '" ' +
'title="' + Y.Escape.html(buttontitle) + '">' +
'<img class="icon" aria-hidden="true" role="presentation" width="16" height="16" src="' + iconurl + '"/>' +
'</button>');
@@ -428,13 +465,13 @@ M.editor_atto = M.editor_atto || {
}
// We only need to attach this once.
if (!M.editor_atto.buttonhandlers[plugin]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + plugin + '_button');
M.editor_atto.buttonhandlers[plugin] = handler;
if (!M.editor_atto.buttonhandlers[buttonpath]) {
Y.one('body').delegate('click', M.editor_atto.buttonclicked_handler, '.atto_' + buttonpath + '_button');
M.editor_atto.buttonhandlers[buttonpath] = handler;
}
// Save the name of the plugin.
M.editor_atto.widgets[plugin] = plugin;
M.editor_atto.widgets[buttonpath] = buttonpath;
},