MDL-44221 editor_atto: convert plugins to use insert_html_at_focus_point

This commit is contained in:
Sam Hemelryk
2014-03-26 10:01:44 +08:00
committed by Damyon Wiese
parent 2faf4c4584
commit a30a40cbf4
20 changed files with 33 additions and 84 deletions
@@ -429,11 +429,8 @@ M.atto_charmap = M.atto_charmap || {
M.atto_charmap.dialogue.hide();
M.editor_atto.set_selection(M.atto_charmap.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(character);
} else {
document.execCommand('insertHTML', false, character);
}
M.editor_atto.insert_html_at_focus_point(character);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_charmap.currentElementId);
File diff suppressed because one or more lines are too long
@@ -429,11 +429,8 @@ M.atto_charmap = M.atto_charmap || {
M.atto_charmap.dialogue.hide();
M.editor_atto.set_selection(M.atto_charmap.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(character);
} else {
document.execCommand('insertHTML', false, character);
}
M.editor_atto.insert_html_at_focus_point(character);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_charmap.currentElementId);
@@ -427,11 +427,8 @@ M.atto_charmap = M.atto_charmap || {
M.atto_charmap.dialogue.hide();
M.editor_atto.set_selection(M.atto_charmap.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(character);
} else {
document.execCommand('insertHTML', false, character);
}
M.editor_atto.insert_html_at_focus_point(character);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_charmap.currentElementId);
@@ -178,11 +178,8 @@ M.atto_emoticon = M.atto_emoticon || {
html = ' ' + emote.text + ' ';
M.editor_atto.set_selection(M.atto_emoticon.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(html);
} else {
document.execCommand('insertHTML', false, html);
}
M.editor_atto.insert_html_at_focus_point(html);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_emoticon.currentElementId);
@@ -1 +1 @@
YUI.add("moodle-atto_emoticon-button",function(e,t){var n={EMOTE:"atto_emoticon_emote",MAP:"atto_emoticon_map"},r={EMOTE:".atto_emoticon_emote"};M.atto_emoticon=M.atto_emoticon||{currentElementId:null,dialogue:null,emoticons:null,selection:null,init:function(e){M.atto_emoticon.emoticons=e.emoticons;var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_emoticon.selection=M.editor_atto.get_selection();if(M.atto_emoticon.selection===!1)return;M.atto_emoticon.currentElementId=t;var n;M.atto_emoticon.dialogue?n=M.atto_emoticon.dialogue:(n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.set("bodyContent",M.atto_emoticon.getDialogueContent()),n.set("headerContent",M.util.get_string("insertemoticon","atto_emoticon")),n.render(),n.centerDialogue(),M.atto_emoticon.dialogue=n),n.show()},n=M.util.image_url("e/emoticons","core");M.editor_atto.add_toolbar_button(e.elementid,"emoticon",n,e.group,t)},getDialogueContent:function(){var t,i,s,o="",u;o+='<div class="'+n.MAP+'">',o+="<ul>";for(u=0;u<M.atto_emoticon.emoticons.length;u++)i=M.atto_emoticon.emoticons[u],s=e.Escape.html(M.util.get_string(i.altidentifier,i.altcomponent)),o+="<li>",o+='<div><a href="#" class="'+n.EMOTE+'" data-index="'+u+'">',o+='<img src="'+M.util.image_url(i.imagename,i.imagecomponent)+'" alt="'+s+'" />',o+="</a></div>",o+="<div>"+e.Escape.html(i.text)+"</div>",o+="<div>"+s+"</div>",o+="</li>";return o+="</ul>",o+="</div>",t=e.Node.create(o),t.delegate("click",M.atto_emoticon.insertEmote,r.EMOTE,this),t.delegate("key",M.atto_emoticon.insertEmote,"32",r.EMOTE,this),t},insertEmote:function(e){var t=e.target.ancestor(r.EMOTE,!0),n=M.atto_emoticon.emoticons[t.getData("index")],i="";e.preventDefault(),e.stopPropagation(),M.atto_emoticon.dialogue.hide(),i=" "+n.text+" ",M.editor_atto.set_selection(M.atto_emoticon.selection),document.selection&&document.selection.createRange().pasteHTML?document.selection.createRange().pasteHTML(i):document.execCommand("insertHTML",!1,i),M.editor_atto.text_updated(M.atto_emoticon.currentElementId)}}},"@VERSION@",{requires:["node"]});
YUI.add("moodle-atto_emoticon-button",function(e,t){var n={EMOTE:"atto_emoticon_emote",MAP:"atto_emoticon_map"},r={EMOTE:".atto_emoticon_emote"};M.atto_emoticon=M.atto_emoticon||{currentElementId:null,dialogue:null,emoticons:null,selection:null,init:function(e){M.atto_emoticon.emoticons=e.emoticons;var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_emoticon.selection=M.editor_atto.get_selection();if(M.atto_emoticon.selection===!1)return;M.atto_emoticon.currentElementId=t;var n;M.atto_emoticon.dialogue?n=M.atto_emoticon.dialogue:(n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.set("bodyContent",M.atto_emoticon.getDialogueContent()),n.set("headerContent",M.util.get_string("insertemoticon","atto_emoticon")),n.render(),n.centerDialogue(),M.atto_emoticon.dialogue=n),n.show()},n=M.util.image_url("e/emoticons","core");M.editor_atto.add_toolbar_button(e.elementid,"emoticon",n,e.group,t)},getDialogueContent:function(){var t,i,s,o="",u;o+='<div class="'+n.MAP+'">',o+="<ul>";for(u=0;u<M.atto_emoticon.emoticons.length;u++)i=M.atto_emoticon.emoticons[u],s=e.Escape.html(M.util.get_string(i.altidentifier,i.altcomponent)),o+="<li>",o+='<div><a href="#" class="'+n.EMOTE+'" data-index="'+u+'">',o+='<img src="'+M.util.image_url(i.imagename,i.imagecomponent)+'" alt="'+s+'" />',o+="</a></div>",o+="<div>"+e.Escape.html(i.text)+"</div>",o+="<div>"+s+"</div>",o+="</li>";return o+="</ul>",o+="</div>",t=e.Node.create(o),t.delegate("click",M.atto_emoticon.insertEmote,r.EMOTE,this),t.delegate("key",M.atto_emoticon.insertEmote,"32",r.EMOTE,this),t},insertEmote:function(e){var t=e.target.ancestor(r.EMOTE,!0),n=M.atto_emoticon.emoticons[t.getData("index")],i="";e.preventDefault(),e.stopPropagation(),M.atto_emoticon.dialogue.hide(),i=" "+n.text+" ",M.editor_atto.set_selection(M.atto_emoticon.selection),M.editor_atto.insert_html_at_focus_point(i),M.editor_atto.text_updated(M.atto_emoticon.currentElementId)}}},"@VERSION@",{requires:["node"]});
@@ -178,11 +178,8 @@ M.atto_emoticon = M.atto_emoticon || {
html = ' ' + emote.text + ' ';
M.editor_atto.set_selection(M.atto_emoticon.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(html);
} else {
document.execCommand('insertHTML', false, html);
}
M.editor_atto.insert_html_at_focus_point(html);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_emoticon.currentElementId);
@@ -176,11 +176,8 @@ M.atto_emoticon = M.atto_emoticon || {
html = ' ' + emote.text + ' ';
M.editor_atto.set_selection(M.atto_emoticon.selection);
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(html);
} else {
document.execCommand('insertHTML', false, html);
}
M.editor_atto.insert_html_at_focus_point(html);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(M.atto_emoticon.currentElementId);
@@ -211,12 +211,7 @@ M.atto_equation = M.atto_equation || {
selectednode.set('text', text);
} else {
// Insert the new equation.
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(value);
} else {
document.execCommand('insertHTML', false, value);
}
M.editor_atto.insert_html_at_focus_point(value);
}
// Clean the YUI ids from the HTML.
File diff suppressed because one or more lines are too long
@@ -211,12 +211,7 @@ M.atto_equation = M.atto_equation || {
selectednode.set('text', text);
} else {
// Insert the new equation.
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(value);
} else {
document.execCommand('insertHTML', false, value);
}
M.editor_atto.insert_html_at_focus_point(value);
}
// Clean the YUI ids from the HTML.
@@ -209,12 +209,7 @@ M.atto_equation = M.atto_equation || {
selectednode.set('text', text);
} else {
// Insert the new equation.
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(value);
} else {
document.execCommand('insertHTML', false, value);
}
M.editor_atto.insert_html_at_focus_point(value);
}
// Clean the YUI ids from the HTML.
@@ -197,11 +197,8 @@ M.atto_image = M.atto_image || {
}
imagehtml += '/>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(imagehtml);
} else {
document.execCommand('insertHTML', false, imagehtml);
}
M.editor_atto.insert_html_at_focus_point(imagehtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
File diff suppressed because one or more lines are too long
@@ -197,11 +197,8 @@ M.atto_image = M.atto_image || {
}
imagehtml += '/>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(imagehtml);
} else {
document.execCommand('insertHTML', false, imagehtml);
}
M.editor_atto.insert_html_at_focus_point(imagehtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
+2 -5
View File
@@ -195,11 +195,8 @@ M.atto_image = M.atto_image || {
}
imagehtml += '/>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(imagehtml);
} else {
document.execCommand('insertHTML', false, imagehtml);
}
M.editor_atto.insert_html_at_focus_point(imagehtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
@@ -89,11 +89,8 @@ M.atto_media = M.atto_media || {
M.editor_atto.set_selection(M.atto_media.selection);
var mediahtml = '<a href="' + Y.Escape.html(url) + '">' + name + '</a>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(mediahtml);
} else {
document.execCommand('insertHTML', false, mediahtml);
}
M.editor_atto.insert_html_at_focus_point(mediahtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
@@ -1 +1 @@
YUI.add("moodle-atto_media-button",function(e,t){M.atto_media=M.atto_media||{dialogue:null,selection:null,init:function(e){if(!M.editor_atto.can_show_filepicker(e.elementid,"media"))return;var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_media.selection=M.editor_atto.get_selection();if(M.atto_media.selection!==!1){var n;M.atto_media.dialogue?n=M.atto_media.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_media.get_form_content(t)),n.set("headerContent",M.util.get_string("createmedia","atto_media")),n.centerDialogue(),n.show(),M.atto_media.dialogue=n}},n=M.util.image_url("e/insert_edit_video","core");M.editor_atto.add_toolbar_button(e.elementid,"media",n,e.group,t)},open_browser:function(e){var t=this.getAttribute("data-editor");e.preventDefault(),M.editor_atto.show_filepicker(t,"media",M.atto_media.filepicker_callback)},filepicker_callback:function(t){if(t.url!==""){var n=e.one("#atto_media_urlentry");n.set("value",t.url),n=e.one("#atto_media_nameentry"),n.set("value",t.file)}},set_media:function(t,n){t.preventDefault(),M.atto_media.dialogue.hide();var r=t.currentTarget.ancestor(".atto_form").one("#atto_media_urlentry"),i=r.get("value");r=t.currentTarget.ancestor(".atto_form").one("#atto_media_nameentry");var s=r.get("value");if(i!==""&&s!==""){M.editor_atto.set_selection(M.atto_media.selection);var o='<a href="'+e.Escape.html(i)+'">'+s+"</a>";document.selection&&document.selection.createRange().pasteHTML?document.selection.createRange().pasteHTML(o):document.execCommand("insertHTML",!1,o),M.editor_atto.text_updated(n)}},get_form_content:function(t){var n=e.Node.create('<form class="atto_form"><label for="atto_media_urlentry">'+M.util.get_string("enterurl","atto_media")+"</label>"+'<input class="fullwidth" type="url" value="" id="atto_media_urlentry" size="32"/><br/>'+'<button id="openmediabrowser" data-editor="'+e.Escape.html(t)+'" type="button">'+M.util.get_string("browserepositories","atto_media")+"</button>"+'<label for="atto_media_nameentry">'+M.util.get_string("entername","atto_media")+"</label>"+'<input class="fullwidth" type="text" value="" id="atto_media_nameentry" size="32" required="true"/>'+'<div class="mdl-align">'+"<br/>"+'<button id="atto_media_urlentrysubmit" type="submit">'+M.util.get_string("createmedia","atto_media")+"</button>"+"</div>"+"</form>");return n.one("#atto_media_urlentrysubmit").on("click",M.atto_media.set_media,this,t),n.one("#openmediabrowser").on("click",M.atto_media.open_browser),n}}},"@VERSION@",{requires:["node","escape"]});
YUI.add("moodle-atto_media-button",function(e,t){M.atto_media=M.atto_media||{dialogue:null,selection:null,init:function(e){if(!M.editor_atto.can_show_filepicker(e.elementid,"media"))return;var t=function(e,t){e.preventDefault(),M.editor_atto.is_active(t)||M.editor_atto.focus(t),M.atto_media.selection=M.editor_atto.get_selection();if(M.atto_media.selection!==!1){var n;M.atto_media.dialogue?n=M.atto_media.dialogue:n=new M.core.dialogue({visible:!1,modal:!0,close:!0,draggable:!0}),n.render(),n.set("bodyContent",M.atto_media.get_form_content(t)),n.set("headerContent",M.util.get_string("createmedia","atto_media")),n.centerDialogue(),n.show(),M.atto_media.dialogue=n}},n=M.util.image_url("e/insert_edit_video","core");M.editor_atto.add_toolbar_button(e.elementid,"media",n,e.group,t)},open_browser:function(e){var t=this.getAttribute("data-editor");e.preventDefault(),M.editor_atto.show_filepicker(t,"media",M.atto_media.filepicker_callback)},filepicker_callback:function(t){if(t.url!==""){var n=e.one("#atto_media_urlentry");n.set("value",t.url),n=e.one("#atto_media_nameentry"),n.set("value",t.file)}},set_media:function(t,n){t.preventDefault(),M.atto_media.dialogue.hide();var r=t.currentTarget.ancestor(".atto_form").one("#atto_media_urlentry"),i=r.get("value");r=t.currentTarget.ancestor(".atto_form").one("#atto_media_nameentry");var s=r.get("value");if(i!==""&&s!==""){M.editor_atto.set_selection(M.atto_media.selection);var o='<a href="'+e.Escape.html(i)+'">'+s+"</a>";M.editor_atto.insert_html_at_focus_point(o),M.editor_atto.text_updated(n)}},get_form_content:function(t){var n=e.Node.create('<form class="atto_form"><label for="atto_media_urlentry">'+M.util.get_string("enterurl","atto_media")+"</label>"+'<input class="fullwidth" type="url" value="" id="atto_media_urlentry" size="32"/><br/>'+'<button id="openmediabrowser" data-editor="'+e.Escape.html(t)+'" type="button">'+M.util.get_string("browserepositories","atto_media")+"</button>"+'<label for="atto_media_nameentry">'+M.util.get_string("entername","atto_media")+"</label>"+'<input class="fullwidth" type="text" value="" id="atto_media_nameentry" size="32" required="true"/>'+'<div class="mdl-align">'+"<br/>"+'<button id="atto_media_urlentrysubmit" type="submit">'+M.util.get_string("createmedia","atto_media")+"</button>"+"</div>"+"</form>");return n.one("#atto_media_urlentrysubmit").on("click",M.atto_media.set_media,this,t),n.one("#openmediabrowser").on("click",M.atto_media.open_browser),n}}},"@VERSION@",{requires:["node","escape"]});
@@ -89,11 +89,8 @@ M.atto_media = M.atto_media || {
M.editor_atto.set_selection(M.atto_media.selection);
var mediahtml = '<a href="' + Y.Escape.html(url) + '">' + name + '</a>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(mediahtml);
} else {
document.execCommand('insertHTML', false, mediahtml);
}
M.editor_atto.insert_html_at_focus_point(mediahtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}
+2 -5
View File
@@ -87,11 +87,8 @@ M.atto_media = M.atto_media || {
M.editor_atto.set_selection(M.atto_media.selection);
var mediahtml = '<a href="' + Y.Escape.html(url) + '">' + name + '</a>';
if (document.selection && document.selection.createRange().pasteHTML) {
document.selection.createRange().pasteHTML(mediahtml);
} else {
document.execCommand('insertHTML', false, mediahtml);
}
M.editor_atto.insert_html_at_focus_point(mediahtml);
// Clean the YUI ids from the HTML.
M.editor_atto.text_updated(elementid);
}