From 48bdf86f31ccba69658939506719eb4b88f43717 Mon Sep 17 00:00:00 2001 From: Damyon Wiese Date: Fri, 31 Jan 2014 13:10:15 +0800 Subject: [PATCH] MDL-43869 Atto: Add functions to get the nodes from the elementids. If plugins try and do this themselves with Y.one, they will fall foul of the qtype essay page bug which uses : in the id for form elements. This is an alternative solution, to escaping the ids, which seemed unreliable for older version of ie. --- .../moodle-atto_html-button-debug.js | 4 +- .../moodle-atto_html-button-min.js | 2 +- .../moodle-atto_html-button.js | 4 +- .../plugins/html/yui/src/button/js/button.js | 4 +- .../moodle-atto_table-button-debug.js | 4 +- .../moodle-atto_table-button-min.js | 4 +- .../moodle-atto_table-button.js | 4 +- .../plugins/table/yui/src/button/js/button.js | 4 +- .../moodle-editor_atto-editor-debug.js | 103 ++++++++++++------ .../moodle-editor_atto-editor-min.js | 4 +- .../moodle-editor_atto-editor.js | 103 ++++++++++++------ lib/editor/atto/yui/src/editor/js/editor.js | 103 ++++++++++++------ 12 files changed, 227 insertions(+), 116 deletions(-) diff --git a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-debug.js b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-debug.js index 6855fe58c65..41cc4a45cff 100644 --- a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-debug.js +++ b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-debug.js @@ -31,8 +31,8 @@ M.atto_html = M.atto_html || { init : function(params) { var click = function(e, elementid) { e.preventDefault(); - var textarea = Y.one('#' + elementid); - var atto = Y.one('#' + elementid + 'editable'); + var textarea = M.editor_atto.get_textarea_node(elementid), + atto = M.editor_atto.get_editable_node(elementid); if (M.atto_html.ishtml) { M.editor_atto.enable_all_widgets(elementid); diff --git a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-min.js b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-min.js index 40aaeac859a..527cd8798fc 100644 --- a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-min.js +++ b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button-min.js @@ -1 +1 @@ -YUI.add("moodle-atto_html-button",function(e,t){M.atto_html=M.atto_html||{ishtml:!1,init:function(t){var n=function(t,n){t.preventDefault();var r=e.one("#"+n),i=e.one("#"+n+"editable");M.atto_html.ishtml?(M.editor_atto.enable_all_widgets(n),i.setHTML(""),i.append(r.get("value")),r.hide(),i.show(),i.focus()):(M.editor_atto.disable_all_widgets(n),M.editor_atto.enable_widget(n,"html"),M.editor_atto.text_updated(n),i.hide(),r.show(),r.focus()),M.atto_html.ishtml=!M.atto_html.ishtml},r=M.util.image_url("e/source_code","core");M.editor_atto.add_toolbar_button(t.elementid,"html",r,t.group,n)}}},"@VERSION@",{requires:["node","event-valuechange"]}); +YUI.add("moodle-atto_html-button",function(e,t){M.atto_html=M.atto_html||{ishtml:!1,init:function(e){var t=function(e,t){e.preventDefault();var n=M.editor_atto.get_textarea_node(t),r=M.editor_atto.get_editable_node(t);M.atto_html.ishtml?(M.editor_atto.enable_all_widgets(t),r.setHTML(""),r.append(n.get("value")),n.hide(),r.show(),r.focus()):(M.editor_atto.disable_all_widgets(t),M.editor_atto.enable_widget(t,"html"),M.editor_atto.text_updated(t),r.hide(),n.show(),n.focus()),M.atto_html.ishtml=!M.atto_html.ishtml},n=M.util.image_url("e/source_code","core");M.editor_atto.add_toolbar_button(e.elementid,"html",n,e.group,t)}}},"@VERSION@",{requires:["node","event-valuechange"]}); diff --git a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button.js b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button.js index 6855fe58c65..41cc4a45cff 100644 --- a/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button.js +++ b/lib/editor/atto/plugins/html/yui/build/moodle-atto_html-button/moodle-atto_html-button.js @@ -31,8 +31,8 @@ M.atto_html = M.atto_html || { init : function(params) { var click = function(e, elementid) { e.preventDefault(); - var textarea = Y.one('#' + elementid); - var atto = Y.one('#' + elementid + 'editable'); + var textarea = M.editor_atto.get_textarea_node(elementid), + atto = M.editor_atto.get_editable_node(elementid); if (M.atto_html.ishtml) { M.editor_atto.enable_all_widgets(elementid); diff --git a/lib/editor/atto/plugins/html/yui/src/button/js/button.js b/lib/editor/atto/plugins/html/yui/src/button/js/button.js index d624268797e..b3af8f57a45 100644 --- a/lib/editor/atto/plugins/html/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/html/yui/src/button/js/button.js @@ -29,8 +29,8 @@ M.atto_html = M.atto_html || { init : function(params) { var click = function(e, elementid) { e.preventDefault(); - var textarea = Y.one('#' + elementid); - var atto = Y.one('#' + elementid + 'editable'); + var textarea = M.editor_atto.get_textarea_node(elementid), + atto = M.editor_atto.get_editable_node(elementid); if (M.atto_html.ishtml) { M.editor_atto.enable_all_widgets(elementid); diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js index 696b542a980..023674cd882 100644 --- a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js +++ b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-debug.js @@ -480,7 +480,7 @@ M.atto_table = M.atto_table || { var iconurl = M.util.image_url('e/table', 'core'); M.editor_atto.add_toolbar_button(params.elementid, 'table', iconurl, params.group, this.display_chooser, this); - var contenteditable = Y.one('#' + params.elementid + 'editable'); + var contenteditable = M.editor_atto.get_editable_node(params.elementid); contenteditable.delegate('click', this.show_menu, 'td > .atto_control, th > .atto_control', this, params.elementid); contenteditable.delegate('key', this.show_menu, 'down:enter,space', 'td > .atto_control, th > .atto_control', this, params.elementid); // Disable mozilla table controls. @@ -502,7 +502,7 @@ M.atto_table = M.atto_table || { * @param String elementid - The id of the text area backed by the content editable field. */ insert_table_controls : function(elementid) { - var contenteditable = Y.one('#' + elementid + 'editable'), + var contenteditable = M.editor_atto.get_editable_node(elementid), allcells = contenteditable.all('td .atto_control,th .atto_control'), cells = contenteditable.all('td:last-child,th:last-child,tbody tr:last-child > td, tbody tr:last-child > th'); diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js index ada69f31624..22fe8ab1164 100644 --- a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js +++ b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-atto_table-button",function(e,t){M.atto_table=M.atto_table||{dialogue:null,selection:null,menunode:null,controlmenu:null,lasttarget:null,display_chooser:function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_table.selection=M.editor_atto.get_selection();if(M.atto_table.selection!==!1&&!M.atto_table.selection.collapsed){var n;M.atto_table.dialogue?n=M.atto_table.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_table.get_form_content(t)),n.set("headerContent",M.util.get_string("createtable","atto_table")),n.show(),M.atto_table.dialogue=n}},show_menu:function(t,n){var r=!1;t.preventDefault();if(this.controlmenu===null){r=!0;var i="",this.controlmenu=new M.editor_atto.controlmenu({headerText:M.util.get_string("edittable","atto_table"),bodyContent:i})}this.lasttarget=t.target.ancestor("td, th"),this.controlmenu.show(),this.controlmenu.align(t.target,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]);if(r){var s=this.controlmenu.get("boundingBox");s.delegate("click",this.handle_table_control,"a",this,n),s.delegate("key",this.handle_table_control,"down:enter,space","a",this,n)}},get_row_index:function(e){var t=e.ancestor("table"),n=e.ancestor("tr");if(!t||!n)return;var r=t.all("tr");return r.indexOf(n)},get_column_index:function(e){var t=e.ancestor("tr");if(!t)return;var n=t.all("td, th");return n.indexOf(e)},delete_row:function(e){var t=this.lasttarget.ancestor("tr");t&&t.one("td")&&t.remove(!0),M.editor_atto.text_updated(e)},move_row_up:function(e){var t=this.lasttarget.ancestor("tr"),n=t.previous("tr");if(!t||!n)return;t.swap(n),M.editor_atto.text_updated(e)},move_column_left:function(t){var n=this.get_column_index(this.lasttarget),r=this.lasttarget.ancestor("table").all("tr"),i=new e.NodeList,s=new e.NodeList,o=!1;r.each(function(e){var t=e.all("td, th"),r=t.item(n),u=t.item(n-1);i.push(r),u&&(u.get("tagName")==="TD"&&(o=!0),s.push(u))});if(o&&s.size()>0){var u=0;for(u=0;u0){var u=0;for(u=0;u");t.replace(n),t=n}t.setHTML(" ")}),r.insert(newrow,n),M.editor_atto.text_updated(t)},add_column_after:function(t){var n=this.get_column_index(this.lasttarget),r=this.lasttarget.ancestor("table"),i=r.all("tr");e.each(i,function(e){var t=e.one("td, th").cloneNode(!0);t.setHTML(" "),e.insert(t,n+1)},this),M.editor_atto.text_updated(t)},handle_table_control:function(e,t){e.preventDefault(),this.controlmenu.hide();switch(e.target.get("id")){case"addcolumnafter":this.add_column_after(t);break;case"addrowafter":this.add_row_after(t);break;case"deleterow":this.delete_row(t);break;case"deletecolumn":this.delete_column(t);break;case"moverowdown":this.move_row_down(t);break;case"moverowup":this.move_row_up(t);break;case"movecolumnleft":this.move_column_left(t);break;case"movecolumnright":this.move_column_right(t)}},init:function(t){if(!M.atto_table.menunode){var n=e.Node.create("");n.setAttrs({alt:M.util.get_string("edittable","atto_table"),src:M.util.image_url("t/contextmenu","core"),width:"12",height:"12"});var r=e.Node.create('');r.appendChild(n),r.addClass("atto_control"),M.atto_table.menunode=r}var i=M.util.image_url("e/table","core");M.editor_atto.add_toolbar_button(t.elementid,"table",i,t.group,this.display_chooser,this);var s=e.one("#"+t.elementid+"editable");s.delegate("click",this.show_menu,"td > .atto_control, th > .atto_control",this,t.elementid),s.delegate("key",this.show_menu,"down:enter,space","td > .atto_control, th > .atto_control",this,t.elementid),e.UA.gecko&&(document.execCommand("enableInlineTableEditing",!1,"false"),document.execCommand("enableObjectResizing",!1,!1)),this.insert_table_controls(t.elementid),M.editor_atto.add_text_updated_handler(t.elementid,this.insert_table_controls)},insert_table_controls:function(t){var n=e.one("#"+t+"editable"),r=n.all("td .atto_control,th .atto_control" -),i=n.all("td:last-child,th:last-child,tbody tr:last-child > td, tbody tr:last-child > th");r.each(function(e){i.indexOf(e)===-1&&e.remove(!0)}),i.each(function(e){e.one(".atto_control")||e.append(M.atto_table.menunode.cloneNode(!0))},this)},set_table:function(t,n){var r,i,s,o,u,a,f;t.preventDefault(),M.atto_table.dialogue.hide(),r=t.currentTarget.ancestor(".atto_form").one("#atto_table_caption"),i=t.currentTarget.ancestor(".atto_form").one("#atto_table_rows"),s=t.currentTarget.ancestor(".atto_form").one("#atto_table_columns"),o=t.currentTarget.ancestor(".atto_form").one("#atto_table_headers"),M.editor_atto.set_selection(M.atto_table.selection),u="
",u+="",a=0;if(o.get("value")==="columns"||o.get("value")==="both"){a=1,u+="";for(f=0;f';u+=""}u+="";for(;a";for(f=0;f":u+='';u+=""}u+="",u+="
"+e.Escape.html(r.get("value"))+"

",document.execCommand("insertHTML",!1,u),M.editor_atto.text_updated(n)},get_form_content:function(t){var n=e.Node.create('
"+''+"
"+'"+'"+"
"+'"+''+"
"+'"+''+"
"+'
'+"
"+'"+"
"+"
"+"
"+M.util.get_string("accessibilityhint","atto_table"));return n.one("#atto_table_submit").on("click",M.atto_table.set_table,this,t),n}}},"@VERSION@",{requires:["node","escape","event","event-valuechange"]}); +YUI.add("moodle-atto_table-button",function(e,t){M.atto_table=M.atto_table||{dialogue:null,selection:null,menunode:null,controlmenu:null,lasttarget:null,display_chooser:function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_table.selection=M.editor_atto.get_selection();if(M.atto_table.selection!==!1&&!M.atto_table.selection.collapsed){var n;M.atto_table.dialogue?n=M.atto_table.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_table.get_form_content(t)),n.set("headerContent",M.util.get_string("createtable","atto_table")),n.show(),M.atto_table.dialogue=n}},show_menu:function(t,n){var r=!1;t.preventDefault();if(this.controlmenu===null){r=!0;var i="
",this.controlmenu=new M.editor_atto.controlmenu({headerText:M.util.get_string("edittable","atto_table"),bodyContent:i})}this.lasttarget=t.target.ancestor("td, th"),this.controlmenu.show(),this.controlmenu.align(t.target,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]);if(r){var s=this.controlmenu.get("boundingBox");s.delegate("click",this.handle_table_control,"a",this,n),s.delegate("key",this.handle_table_control,"down:enter,space","a",this,n)}},get_row_index:function(e){var t=e.ancestor("table"),n=e.ancestor("tr");if(!t||!n)return;var r=t.all("tr");return r.indexOf(n)},get_column_index:function(e){var t=e.ancestor("tr");if(!t)return;var n=t.all("td, th");return n.indexOf(e)},delete_row:function(e){var t=this.lasttarget.ancestor("tr");t&&t.one("td")&&t.remove(!0),M.editor_atto.text_updated(e)},move_row_up:function(e){var t=this.lasttarget.ancestor("tr"),n=t.previous("tr");if(!t||!n)return;t.swap(n),M.editor_atto.text_updated(e)},move_column_left:function(t){var n=this.get_column_index(this.lasttarget),r=this.lasttarget.ancestor("table").all("tr"),i=new e.NodeList,s=new e.NodeList,o=!1;r.each(function(e){var t=e.all("td, th"),r=t.item(n),u=t.item(n-1);i.push(r),u&&(u.get("tagName")==="TD"&&(o=!0),s.push(u))});if(o&&s.size()>0){var u=0;for(u=0;u0){var u=0;for(u=0;u");t.replace(n),t=n}t.setHTML(" ")}),r.insert(newrow,n),M.editor_atto.text_updated(t)},add_column_after:function(t){var n=this.get_column_index(this.lasttarget),r=this.lasttarget.ancestor("table"),i=r.all("tr");e.each(i,function(e){var t=e.one("td, th").cloneNode(!0);t.setHTML(" "),e.insert(t,n+1)},this),M.editor_atto.text_updated(t)},handle_table_control:function(e,t){e.preventDefault(),this.controlmenu.hide();switch(e.target.get("id")){case"addcolumnafter":this.add_column_after(t);break;case"addrowafter":this.add_row_after(t);break;case"deleterow":this.delete_row(t);break;case"deletecolumn":this.delete_column(t);break;case"moverowdown":this.move_row_down(t);break;case"moverowup":this.move_row_up(t);break;case"movecolumnleft":this.move_column_left(t);break;case"movecolumnright":this.move_column_right(t)}},init:function(t){if(!M.atto_table.menunode){var n=e.Node.create("");n.setAttrs({alt:M.util.get_string("edittable","atto_table"),src:M.util.image_url("t/contextmenu","core"),width:"12",height:"12"});var r=e.Node.create('');r.appendChild(n),r.addClass("atto_control"),M.atto_table.menunode=r}var i=M.util.image_url("e/table","core");M.editor_atto.add_toolbar_button(t.elementid,"table",i,t.group,this.display_chooser,this);var s=M.editor_atto.get_editable_node(t.elementid);s.delegate("click",this.show_menu,"td > .atto_control, th > .atto_control",this,t.elementid),s.delegate("key",this.show_menu,"down:enter,space","td > .atto_control, th > .atto_control",this,t.elementid),e.UA.gecko&&(document.execCommand("enableInlineTableEditing",!1,"false"),document.execCommand("enableObjectResizing",!1,!1)),this.insert_table_controls(t.elementid),M.editor_atto.add_text_updated_handler(t.elementid,this.insert_table_controls)},insert_table_controls:function(e){var t=M.editor_atto.get_editable_node(e),n=t. +all("td .atto_control,th .atto_control"),r=t.all("td:last-child,th:last-child,tbody tr:last-child > td, tbody tr:last-child > th");n.each(function(e){r.indexOf(e)===-1&&e.remove(!0)}),r.each(function(e){e.one(".atto_control")||e.append(M.atto_table.menunode.cloneNode(!0))},this)},set_table:function(t,n){var r,i,s,o,u,a,f;t.preventDefault(),M.atto_table.dialogue.hide(),r=t.currentTarget.ancestor(".atto_form").one("#atto_table_caption"),i=t.currentTarget.ancestor(".atto_form").one("#atto_table_rows"),s=t.currentTarget.ancestor(".atto_form").one("#atto_table_columns"),o=t.currentTarget.ancestor(".atto_form").one("#atto_table_headers"),M.editor_atto.set_selection(M.atto_table.selection),u="
",u+="",a=0;if(o.get("value")==="columns"||o.get("value")==="both"){a=1,u+="";for(f=0;f';u+=""}u+="";for(;a";for(f=0;f":u+='';u+=""}u+="",u+="
"+e.Escape.html(r.get("value"))+"

",document.execCommand("insertHTML",!1,u),M.editor_atto.text_updated(n)},get_form_content:function(t){var n=e.Node.create('
"+''+"
"+'"+'"+"
"+'"+''+"
"+'"+''+"
"+'
'+"
"+'"+"
"+"
"+"
"+M.util.get_string("accessibilityhint","atto_table"));return n.one("#atto_table_submit").on("click",M.atto_table.set_table,this,t),n}}},"@VERSION@",{requires:["node","escape","event","event-valuechange"]}); diff --git a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js index 696b542a980..023674cd882 100644 --- a/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js +++ b/lib/editor/atto/plugins/table/yui/build/moodle-atto_table-button/moodle-atto_table-button.js @@ -480,7 +480,7 @@ M.atto_table = M.atto_table || { var iconurl = M.util.image_url('e/table', 'core'); M.editor_atto.add_toolbar_button(params.elementid, 'table', iconurl, params.group, this.display_chooser, this); - var contenteditable = Y.one('#' + params.elementid + 'editable'); + var contenteditable = M.editor_atto.get_editable_node(params.elementid); contenteditable.delegate('click', this.show_menu, 'td > .atto_control, th > .atto_control', this, params.elementid); contenteditable.delegate('key', this.show_menu, 'down:enter,space', 'td > .atto_control, th > .atto_control', this, params.elementid); // Disable mozilla table controls. @@ -502,7 +502,7 @@ M.atto_table = M.atto_table || { * @param String elementid - The id of the text area backed by the content editable field. */ insert_table_controls : function(elementid) { - var contenteditable = Y.one('#' + elementid + 'editable'), + var contenteditable = M.editor_atto.get_editable_node(elementid), allcells = contenteditable.all('td .atto_control,th .atto_control'), cells = contenteditable.all('td:last-child,th:last-child,tbody tr:last-child > td, tbody tr:last-child > th'); diff --git a/lib/editor/atto/plugins/table/yui/src/button/js/button.js b/lib/editor/atto/plugins/table/yui/src/button/js/button.js index 2d02e9567dc..920f0fb1c6c 100644 --- a/lib/editor/atto/plugins/table/yui/src/button/js/button.js +++ b/lib/editor/atto/plugins/table/yui/src/button/js/button.js @@ -478,7 +478,7 @@ M.atto_table = M.atto_table || { var iconurl = M.util.image_url('e/table', 'core'); M.editor_atto.add_toolbar_button(params.elementid, 'table', iconurl, params.group, this.display_chooser, this); - var contenteditable = Y.one('#' + params.elementid + 'editable'); + var contenteditable = M.editor_atto.get_editable_node(params.elementid); contenteditable.delegate('click', this.show_menu, 'td > .atto_control, th > .atto_control', this, params.elementid); contenteditable.delegate('key', this.show_menu, 'down:enter,space', 'td > .atto_control, th > .atto_control', this, params.elementid); // Disable mozilla table controls. @@ -500,7 +500,7 @@ M.atto_table = M.atto_table || { * @param String elementid - The id of the text area backed by the content editable field. */ insert_table_controls : function(elementid) { - var contenteditable = Y.one('#' + elementid + 'editable'), + var contenteditable = M.editor_atto.get_editable_node(elementid), allcells = contenteditable.all('td .atto_control,th .atto_control'), cells = contenteditable.all('td:last-child,th:last-child,tbody tr:last-child > td, tbody tr:last-child > th'); diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js index 47c967e0004..5645413a9cc 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-debug.js @@ -121,24 +121,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. - */ - is_enabled : function(elementid, plugin) { - var element = Y.one('#' + elementid + '_toolbar .atto_' + plugin + '_button'); - - return !element.hasAttribute('disabled'); - }, /** * Disable all buttons and menus in the toolbar. * @param string elementid, the element id of this editor. */ disable_all_widgets : function(elementid) { - var plugin, element; + var plugin, element, toolbar = M.editor_atto.get_toolbar_node(elementid); for (plugin in M.editor_atto.widgets) { - element = Y.one('#' + elementid + '_toolbar .atto_' + plugin + '_button'); + element = toolbar.one('.atto_' + plugin + '_button'); if (element) { element.setAttribute('disabled', 'true'); @@ -146,13 +136,60 @@ M.editor_atto = M.editor_atto || { } }, + /** + * Get the node of the original textarea element that this editor replaced. + * + * @param string elementid, the element id of this editor. + * @return Y.Node + */ + get_textarea_node : function(elementid) { + // Note - it is not safe to use a CSS selector like '#' + elementid + // because the id may have colons in it - e.g. quiz. + return Y.one(document.getElementById(elementid)); + }, + + /** + * Get the node of the toolbar container for this editor. + * + * @param string elementid, the element id of this editor. + * @return Y.Node + */ + get_toolbar_node : function(elementid) { + // Note - it is not safe to use a CSS selector like '#' + elementid + // because the id may have colons in it - e.g. quiz. + return Y.one(document.getElementById(elementid + '_toolbar')); + }, + + /** + * Get the node of the contenteditable container for this editor. + * + * @param string elementid, the element id of this editor. + * @return Y.Node + */ + get_editable_node : function(elementid) { + // Note - it is not safe to use a CSS selector like '#' + elementid + // because the id may have colons in it - e.g. quiz. + return Y.one(document.getElementById(elementid + 'editable')); + }, + + /** + * 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. + */ + is_enabled : function(elementid, plugin) { + var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button'); + + return !element.hasAttribute('disabled'); + }, + /** * 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. */ enable_widget : function(elementid, plugin) { - var element = Y.one('#' + elementid + '_toolbar .atto_' + plugin + '_button'); + var element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button'); if (element) { element.removeAttribute('disabled'); @@ -166,7 +203,7 @@ M.editor_atto = M.editor_atto || { enable_all_widgets : function(elementid) { var plugin, element; for (plugin in M.editor_atto.widgets) { - element = Y.one('#' + elementid + '_toolbar .atto_' + plugin + '_button'); + element = M.editor_atto.get_toolbar_node(elementid).one('.atto_' + plugin + '_button'); if (element) { element.removeAttribute('disabled'); @@ -199,8 +236,8 @@ M.editor_atto = M.editor_atto || { * @param array entries - List of menu entries with the string (entry.text) and the handlers (entry.handler). */ add_toolbar_menu : function(elementid, plugin, iconurl, groupname, entries) { - var toolbar = Y.one('#' + elementid + '_toolbar'), - group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'), + var toolbar = M.editor_atto.get_toolbar_node(elementid), + group = toolbar.one('.atto_group.' + groupname + '_group'), currentfocus, button, expimgurl; @@ -283,8 +320,8 @@ M.editor_atto = M.editor_atto || { * @handler function handler- A function to call when the button is clicked. */ add_toolbar_button : function(elementid, plugin, iconurl, groupname, handler) { - var toolbar = Y.one('#' + elementid + '_toolbar'), - group = Y.one('#' + elementid + '_toolbar .atto_group.' + groupname + '_group'), + var toolbar = M.editor_atto.get_toolbar_node(elementid), + group = toolbar.one('.atto_group.' + groupname + '_group'), button, currentfocus; @@ -347,7 +384,7 @@ M.editor_atto = M.editor_atto || { * @param string elementid of this editor */ focus : function(elementid) { - Y.one('#' + elementid + 'editable').focus(); + M.editor_atto.get_editable_node(elementid).focus(); }, /** @@ -366,8 +403,7 @@ M.editor_atto = M.editor_atto || { // Editable content wrapper. var content = Y.Node.create('
'); - var elementid = params.elementid.replace(':', '\\:'); - var textarea = Y.one('#' +elementid); + var textarea = M.editor_atto.get_textarea_node(params.elementid); content.appendChild(atto); @@ -400,19 +436,19 @@ M.editor_atto = M.editor_atto || { // Copy the current value back to the textarea when focus leaves us. atto.on('blur', function() { - this.text_updated(elementid); + this.text_updated(params.elementid); }, this); // Listen for Arrow left and Arrow right keys. Y.one(Y.config.doc.body).delegate('key', this.keyboard_navigation, 'down:37,39', - '#' + elementid + '_toolbar', + '#' + params.elementid + '_toolbar', this, - elementid); + params.elementid); // Save the file picker options for later. - M.editor_atto.filepickeroptions[elementid] = params.filepickeroptions; + M.editor_atto.filepickeroptions[params.elementid] = params.filepickeroptions; // Init each of the plugins var i, j; @@ -420,7 +456,7 @@ M.editor_atto = M.editor_atto || { var group = params.plugins[i].group; for (j = 0; j < params.plugins[i].plugins.length; j++) { var plugin = params.plugins[i].plugins[j]; - plugin.params.elementid = elementid; + plugin.params.elementid = params.elementid; plugin.params.group = group; M['atto_' + plugin.name].init(plugin.params); @@ -434,7 +470,7 @@ M.editor_atto = M.editor_atto || { * @param string elementid - the id of the textarea we created this editor from. */ text_updated : function(elementid) { - var textarea = Y.one('#' + elementid), + var textarea = M.editor_atto.get_textarea_node(elementid), cleancontent = this.get_clean_html(elementid); textarea.set('value', cleancontent); // Trigger handlers for this action. @@ -453,7 +489,7 @@ M.editor_atto = M.editor_atto || { * @return string HTML stripped of YUI ids */ get_clean_html : function(elementid) { - var atto = Y.one('#' + elementid + 'editable').cloneNode(true); + var atto = M.editor_atto.get_editable_node(elementid).cloneNode(true); Y.each(atto.all('[id]'), function(node) { var id = node.get('id'); @@ -481,12 +517,13 @@ M.editor_atto = M.editor_atto || { var buttons, current, currentid, - currentindex; + currentindex, + toolbar = M.editor_atto.get_toolbar_node(elementid); e.preventDefault(); - buttons = Y.all('#' + elementid + '_toolbar button'); - currentid = Y.one('#' + elementid + '_toolbar').getAttribute('aria-activedescendant'); + buttons = toolbar.all('button'); + currentid = toolbar.getAttribute('aria-activedescendant'); if (!currentid) { return; } @@ -512,7 +549,7 @@ M.editor_atto = M.editor_atto || { current = buttons.item(currentindex); current.setAttribute('tabindex', '0'); current.focus(); - Y.one('#' + elementid + '_toolbar').setAttribute('aria-activedescendant', current.generateID()); + toolbar.setAttribute('aria-activedescendant', current.generateID()); }, /** @@ -538,7 +575,7 @@ M.editor_atto = M.editor_atto || { var options = M.editor_atto.filepickeroptions[elementid][type]; options.formcallback = callback; - options.editor_target = Y.one(elementid); + options.editor_target = M.editor_atto.get_textarea_node(elementid); M.core_filepicker.show(Y, options); }); diff --git a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js index 113a2c9cdda..d0a7c77db2c 100644 --- a/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js +++ b/lib/editor/atto/yui/build/moodle-editor_atto-editor/moodle-editor_atto-editor-min.js @@ -1,2 +1,2 @@ -YUI.add("moodle-editor_atto-editor",function(e,t){function i(){var e=this.getHTML(),t=[{regex://gi,replace:""},{regex:/<\\?\?xml[^>]*>/gi,replace:""},{regex:/<\/?\w+:[^>]*>/gi,replace:""},{regex:/\s*MSO[-:][^;"']*;?/gi,replace:""},{regex:/]*>( |\s)*<\/span>/gi,replace:""},{regex:/class="Mso[^"]*"/gi,replace:""},{regex:/<(\/?title|\/?meta|\/?style|\/?st\d|\/?head|\/?font|\/?html|\/?body|!\[)[^>]*?>/gi,replace:""},{regex:new RegExp(String.fromCharCode(8220),"gi"),replace:'"'},{regex:new RegExp(String.fromCharCode(8216),"gi"),replace:"'"},{regex:new RegExp(String.fromCharCode(8217),"gi"),replace:"'"},{regex:new RegExp(String.fromCharCode(8211),"gi"),replace:"-"},{regex:new RegExp(String.fromCharCode(8212),"gi"),replace:"--"},{regex:new RegExp(String.fromCharCode(189),"gi"),replace:"1/2"},{regex:new RegExp(String.fromCharCode(188),"gi"),replace:"1/4"},{regex:new RegExp(String.fromCharCode(190),"gi"),replace:"3/4"},{regex:new RegExp(String.fromCharCode(169),"gi"),replace:"(c)"},{regex:new RegExp(String.fromCharCode(174),"gi"),replace:"(r)"},{regex:new RegExp(String.fromCharCode(8230),"gi"),replace:"..."}],n=0,r;for(n=0;n
'),o.append(u)),l=M.util.image_url("t/expanded","moodle"),f=e.Node.create('"),u.append(f),a=o.getAttribute("aria-activedescendant"),a||(f.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",f.generateID())),M.editor_atto.widgets[n]=n;var c=e.Node.create('
'),h=0,p={};for(h=0;h
'+p.text+""+"")),M.editor_atto.buttonhandlers[n+"_action_"+h]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+h),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+h),M.editor_atto.buttonhandlers[n+"_action_"+h]=p.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var d=new M.core.dialogue({bodyContent:c,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=d,d.render(),d.align(f,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),d.hide(),d.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=e.one("#"+t+"_toolbar"),u=e.one("#"+t+"_toolbar .atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(t){e.one("#"+t+"editable").focus()},init:function(t){var n=e.Node.create -('
'),r=e.Node.create('
'),i="",s=e.Node.create('")),M.editor_atto.buttonhandlers[n+"_action_"+h]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_action_"+h),e.one("body").delegate("key",M.editor_atto.buttonclicked_handler,"space,enter",".atto_"+n+"_action_"+h),M.editor_atto.buttonhandlers[n+"_action_"+h]=p.handler);M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.showhide_menu_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=!0);var d=new M.core.dialogue({bodyContent:c,visible:!1,width:"14em",zindex:100,lightbox:!1,closeButton:!1,center:!1});M.editor_atto.menus[n+"_"+t]=d,d.render(),d.align(f,[e.WidgetPositionAlign.TL,e.WidgetPositionAlign.BL]),d.hide(),d.headerNode.hide()},add_toolbar_button:function(t,n,r,i,s){var o=M.editor_atto.get_toolbar_node(t),u=o.one(".atto_group."+i+"_group"),a,f;u||(u=e.Node.create('
'),o.append(u)),a=e.Node.create('"),u.append(a),f=o.getAttribute("aria-activedescendant"),f||(a.setAttribute("tabindex","0"),o.setAttribute("aria-activedescendant",a.generateID())),M.editor_atto.buttonhandlers[n]||(e.one("body").delegate("click",M.editor_atto.buttonclicked_handler,".atto_"+n+"_button"),M.editor_atto.buttonhandlers[n]=s),M.editor_atto.widgets[n +]=n},is_active:function(t){var n=M.editor_atto.get_selection();n.length&&(n=n.pop());var r=null;return n.parentElement?r=e.one(n.parentElement()):r=e.one(n.startContainer),r&&r.ancestor("#"+t+"editable")!==null},focus:function(e){M.editor_atto.get_editable_node(e).focus()},init:function(t){var n=e.Node.create('
'),r=e.Node.create('
'),i="",s=e.Node.create('