Mercurial > hg > rc2
view program/js/editor.min.js @ 0:4681f974d28b
vanilla 1.3.3 distro, I hope
author | Charlie Root |
---|---|
date | Thu, 04 Jan 2018 15:52:31 -0500 |
parents | |
children |
line wrap: on
line source
/** * Roundcube editor js library * * This file is part of the Roundcube Webmail client * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (c) 2006-2014, The Roundcube Dev Team * * The JavaScript code in this page is free software: you can * redistribute it and/or modify it under the terms of the GNU * General Public License (GNU GPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this file. * * @author Eric Stadtherr <estadtherr@gmail.com> * @author Aleksander Machniak <alec@alec.pl> */ function rcube_text_editor(l,m){var h=this,n=location.href.replace(/[?#].*$/,"").replace(/\/$/,""),k={selector:"#"+($("#"+m).is(".mce_editor")?m:"fake-editor-id"),cache_suffix:"s=4050800",theme:"modern",language:l.lang,content_css:rcmail.assets_path("program/resources/tinymce/content.css"),menubar:!1,statusbar:!1,toolbar_items_size:"small",extended_valid_elements:"font[face|size|color|style],span[id|class|align|style]",relative_urls:!1,remove_script_host:!1,convert_urls:!1,image_description:!1,paste_webkit_style:"color font-size font-family", paste_data_images:!0,browser_spellcheck:!0};this.spellcheck_observer=function(){};l.spellchecker&&(this.spellchecker=l.spellchecker,l.spellcheck_observer&&(this.spellchecker.spelling_state_observer=this.spellcheck_observer=l.spellcheck_observer));tinymce.registered_request_token||(tinymce.registered_request_token=!0,tinymce.util.XHR.on("beforeSend",function(a){a.xhr.setRequestHeader("X-Roundcube-Request",rcmail.env.request_token)}));"identity"==l.mode?$.extend(k,{plugins:"autolink charmap code colorpicker hr image link paste tabfocus textcolor", toolbar:"bold italic underline alignleft aligncenter alignright alignjustify | outdent indent charmap hr link unlink image code forecolor | fontselect fontsizeselect",file_browser_callback:function(a,b,e,d){h.file_browser_callback(a,b,e)},file_browser_callback_types:"image"}):$.extend(k,{plugins:"autolink charmap code colorpicker directionality link lists image media nonbreaking paste table tabfocus textcolor searchreplace spellchecker",toolbar:"bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent ltr rtl blockquote | forecolor backcolor | fontselect fontsizeselect | link unlink table | $extra charmap image media | code searchreplace undo redo", spellchecker_rpc_url:n+"/?_task=utils&_action=spell_html&_remote=1",spellchecker_language:rcmail.env.spell_lang,accessibility_focus:!1,file_browser_callback:function(a,b,e,d){h.file_browser_callback(a,b,e)},file_browser_callback_types:"image media"});$.each(l.extra_plugins||[],function(){0>k.plugins.indexOf(this)&&(k.plugins=k.plugins+" "+this)});$.each(l.extra_buttons||[],function(){0>k.toolbar.indexOf(this)&&(k.toolbar=k.toolbar.replace("$extra","$extra "+this))});$.each(l.disabled_plugins||[], function(){k.plugins=k.plugins.replace(this,"")});$.each(l.disabled_buttons||[],function(){k.toolbar=k.toolbar.replace(this,"")});k.toolbar=k.toolbar.replace("$extra","").replace(/\|\s+\|/g,"|");window.rcmail_editor_settings&&$.extend(k,window.rcmail_editor_settings);k.setup=function(a){a.on("init",function(a){h.init_callback(a)});a.on("SpellcheckStart SpellcheckEnd",function(a){h.spellcheck_active="spellcheckstart"==a.type;h.spellcheck_observer()});a.on("keypress",function(){rcmail.compose_type_activity++})}; this.id=m;this.editor=null;tinymce.init(k);this.init_callback=function(a){this.editor=a.target;if("compose"==rcmail.env.action){var b=$("#"+this.id),e=$("div.mce-toolbar-grp:first",b.parent()).height();if(200<e||e>b.height())return setTimeout(function(){h.init_callback(a)},300);b={};e=rcube_find_object("_from");var d=rcmail.env.compose_focus_elem;rcmail.env.default_font&&(b["font-family"]=rcmail.env.default_font);rcmail.env.default_font_size&&(b["font-size"]=rcmail.env.default_font_size);(b["font-family"]|| b["font-size"])&&$(this.editor.getBody()).css(b);e&&"select-one"==e.type&&(rcmail.env.identities_initialized||rcmail.change_identity(e),d&&d.id!=this.id&&"BODY"!=d.nodeName&&(window.focus(),d.focus(),rcmail.env.compose_focus_elem=null));h.tabindex(d&&d.id==h.id);$(window).resize()}};this.tabindex=function(a){if("mail"==rcmail.env.task&&this.editor){var b=this.editor.getElement(),e=this.editor.getBody(),d=this.editor.getContentAreaContainer().childNodes[0];b&&d&&(d.tabIndex=b.tabIndex);if(0<b.tabIndex){var c= null;d=[":prev",":next"];b=tinymce.DOM.select("*[tabindex="+b.tabIndex+"]:not(iframe)");tinymce.each(b,function(a,b){if(a.id==h.id)return c=b,!1});null!==c&&(b[c-1]&&b[c-1].id&&(d[0]=b[c-1].id),b[c+1]&&b[c+1].id&&(d[1]=b[c+1].id),this.editor.settings.tabfocus_elements=d.join(","))}bw.mz&&25>bw.vendver&&$(e).prop("contenteditable",!1).prop("contenteditable",!0);a&&e.focus()}};this.toggle=function(a,b){var e=$("#"+this.id),d=rcmail.env.identity?rcmail.env.signatures[rcmail.env.identity]:null,c=d&&d.text&& 1<d.text.length;this.spellcheck_stop();if(a){a=e.val();c&&(a=a.replace(/\r\n/,"\n"),a=a.replace(d.text.replace(/\r\n/,"\n"),"\u0002\u0003"));var f=function(a){c&&(a=a.replace("\u0002\u0003",'<div id="_rc_sig">'+d.html+"</div>"));e.val(a);tinymce.execCommand("mceAddEditor",!1,h.id);h.editor&&(a=$(h.editor.getBody()),h.tabindex(!0),h.editor.selection.setCursorLocation(a.children().first().get(0)))};if(b){f(a);var g=!0}else g=rcmail.plain2html(a,f)}else if(this.editor){if(c){if(f=this.editor.dom.get("_rc_sig"))f= f.innerHTML;this.editor.dom.setHTML("_rc_sig","\u0002\u0003")}a=this.editor.getContent();g=function(a){tinymce.execCommand("mceRemoveEditor",!1,h.id);h.editor=null;c&&(a=a.replace("\u0002\u0003","\n"+d.text));e.val(a).focus();rcmail.set_caret_pos(e.get(0),0)};b?(g(e.val()),g=!0):g=rcmail.html2plain(a,g);!g&&f&&this.editor.dom.setHTML("_rc_sig",f)}return g};this.spellcheck_start=function(){this.editor?(tinymce.execCommand("mceSpellCheck",!0),this.spellcheck_observer()):this.spellchecker&&this.spellchecker.spellCheck&& this.spellchecker.spellCheck()};this.spellcheck_stop=function(){var a=this.editor;a?a.plugins&&a.plugins.spellchecker&&this.spellcheck_active&&(a.execCommand("mceSpellCheck",!1),this.spellcheck_observer()):(a=this.spellchecker)&&a.state&&"ready"!=a.state&&"no_error_found"!=a.state&&$(a.spell_span).trigger("click")};this.spellcheck_state=function(){var a;if(this.editor)return this.spellcheck_active;if((a=this.spellchecker)&&a.state)return"ready"!=a.state&&"no_error_found"!=a.state};this.spellcheck_resume= function(a){var b=this.editor;if(b)b.plugins.spellchecker.markErrors(a);else if(b=this.spellchecker)b.prepare(!1,!0),b.processData(a)};this.get_language=function(){if(this.editor)return this.editor.settings.spellchecker_language||rcmail.env.spell_lang;if(this.spellchecker)return GOOGIE_CUR_LANG};this.set_language=function(a){var b=this.editor;b&&(b.settings.spellchecker_language=a);(b=this.spellchecker)&&b.setCurrentLanguage(a)};this.replace=function(a){var b=this.editor;if(!a)return!1;if(b){b.getWin().focus(); if("object"==$.type(a)&&"html"in a){a=a.html;var e="html"}else"object"==$.type(a)&&(a=a.text||""),a=rcmail.quote_html(a).replace(/\r?\n/g,"<br/>"),e="text";b.selection.setContent(a,{format:e})}else if(b=rcube_find_object(this.id)){e=$(b).is(":focus")?rcmail.get_input_selection(b):{start:0,end:0};var d=b.value;pre=d.substring(0,e.start);end=d.substring(e.end,d.length);"object"==$.type(a)&&(a=a.text||"");b.value=pre+a+end;rcmail.set_caret_pos(b,e.start+a.length);b.focus()}};this.get_content=function(a){var b= this.editor,e="",d=!1;a=$.extend({refresh:!0,selection:!1,nosig:!1,format:"html"},a);a.refresh&&this.spellcheck_stop();if(b)a.selection&&(e=b.selection.getContent({format:a.format})),e||(e=b.getContent({format:a.format}),d="text"==a.format);else if(b=rcube_find_object(this.id))a.selection&&$(b).is(":focus")&&(e=rcmail.get_input_selection(b).text),e||(e=b.value,d=!0);d&&a.nosig&&(a=e.indexOf("-- \n"),0<a&&(e=e.substring(0,a)));return e};this.change_signature=function(a,b){var e=-1,d=$("#"+this.id), c=d.val(),f=rcmail.env.identity;if(this.editor)if(b&&rcmail.env.signatures){d=this.editor.dom.get("_rc_sig");if(!d)if(c=this.editor.getBody(),d=$('<div id="_rc_sig"></div>').get(0),rcmail.env.top_posting&&!rcmail.env.sig_below&&rcmail.env.compose_mode&&(1<c.childNodes.length||$(c).text()))this.editor.getWin().focus(),f=this.editor.selection.getNode(),$(d).insertBefore("BODY"==f.nodeName?c.firstChild:f.nextSibling),$("<p>").append($("<br>")).insertBefore(d);else{c.appendChild(d);var g=rcmail.env.top_posting&& rcmail.env.compose_mode?c.firstChild:$(d).prev()}d.innerHTML=rcmail.env.signatures[a]?rcmail.env.signatures[a].html:""}else rcmail.env.top_posting||(g=$(this.editor.getBody()).children().last());else b&&f&&rcmail.env.signatures&&rcmail.env.signatures[f]&&(f=rcmail.env.signatures[f].text,f=f.replace(/\r\n/g,"\n"),e=rcmail.env.top_posting?c.indexOf(f):c.lastIndexOf(f),0<=e&&(c=c.substring(0,e)+c.substring(e+f.length,c.length))),b&&rcmail.env.signatures&&rcmail.env.signatures[a]?(f=rcmail.env.signatures[a].text, f=f.replace(/\r\n/g,"\n"),0<=e?(c=c.substring(0,e)+f+c.substring(e,c.length),a=e-1):c&&rcmail.env.compose_mode?rcmail.env.top_posting&&!rcmail.env.sig_below?(pos=rcmail.get_caret_pos(d.get(0)))?(c=c.substring(0,pos)+"\n"+f+"\n\n"+c.substring(pos,c.length),a=pos):(c="\n\n"+f+"\n\n"+c.replace(/^[\r\n]+/,""),a=0):(c=c.replace(/[\r\n]+$/,""),a=!rcmail.env.top_posting&&c.length?c.length+1:0,c+="\n\n"+f):(a=c.length,c+="\n\n"+f)):a=rcmail.env.top_posting?0:c.length,d.val(c),rcmail.set_caret_pos(d.get(0), a);this.editor&&g&&g.length&&(this.editor.selection.setCursorLocation(g.get(0)),this.editor.getWin().scroll(0,g.offset().top))};this.save=function(){this.editor&&this.editor.save()};this.focus=function(){(this.editor||rcube_find_object(this.id)).focus()};this.file_browser_callback=function(a,b,e){var d,c,f=[];b=this.editor.windowManager.open({title:rcmail.get_label("select"+e),width:500,height:300,html:'<div id="image-selector-list"><ul></ul></div><div id="image-selector-form"><div id="image-upload-button" class="mce-widget mce-btn" role="button" tabindex="0"></div></div>', buttons:[{text:"Cancel",onclick:function(){h.file_browser_close()}}]});rcmail.env.file_browser_field=a;rcmail.env.file_browser_type=e;for(d in rcmail.env.attachments)(c=h.file_browser_entry(d,rcmail.env.attachments[d]))&&f.push(c);f.length&&$("#image-selector-list > ul").append(f).find("li:first").focus();$("div.mce-abs-end",b.getEl()).append($('<div class="hint">').text($("div.hint",rcmail.gui_objects.uploadform).text()));c=$("#image-upload-button").append($("<span>").text(rcmail.get_label("add"+ e)));var g=c.parents(".mce-panel").find("button:last").parent();c.keydown(function(a){if(9==a.which)return rcube_event.get_modifier(a)==SHIFT_KEY?$("#image-selector-list li:last").focus():g.focus(),!1});g.keydown(function(a){if(9==a.which)return rcube_event.get_modifier(a)==SHIFT_KEY?c.focus():$("#image-selector-list li:first").focus(),!1});this.hack_file_input(c,rcmail.gui_objects.uploadform);if(window.XMLHttpRequest&&XMLHttpRequest.prototype&&XMLHttpRequest.prototype.sendAsBinary||window.FormData)rcmail.env.filedrop|| (rcmail.env.filedrop={}),rcmail.gui_objects.filedrop&&(rcmail.env.old_file_drop=rcmail.gui_objects.filedrop),rcmail.gui_objects.filedrop=$("#image-selector-form"),rcmail.gui_objects.filedrop.addClass("droptarget").on("dragover dragleave",function(a){a.preventDefault();a.stopPropagation();$(this)["dragover"==a.type?"addClass":"removeClass"]("hover")}).get(0).addEventListener("drop",function(a){return rcmail.file_dropped(a)},!1);rcmail.env.file_dialog_event||(rcmail.env.file_dialog_event=!0,rcmail.addEventListener("fileuploaded", function(a){if(a=h.file_browser_entry(a.name,a.attachment))$("#image-selector-list > ul").prepend(a),a.focus()}))};this.file_browser_close=function(a){var b=$("#"+rcmail.env.file_browser_field);a&&b.val(a);this.editor.windowManager.close();b.focus();rcmail.env.old_file_drop&&(rcmail.gui_objects.filedrop=rcmail.env.old_file_drop)};this.file_browser_entry=function(a,b){if(b.complete&&b.mimetype){rcmail.file_upload_id&&rcmail.set_busy(!1,null,rcmail.file_upload_id);switch(rcmail.env.file_browser_type){case "image":var e= /^image\//i;break;case "media":e=/^video\//i;var d="program/resources/tinymce/video.png";break;default:return}if(e.test(b.mimetype))return a=rcmail.env.comm_path+"&_from="+rcmail.env.action+(rcmail.env.compose_id?"&_id="+rcmail.env.compose_id+"&_action=display-attachment":"&_action=upload-display")+"&_file="+a,d=$("<img>").attr({title:b.name,src:d?d:a+"&_thumbnail=1"}),$("<li>").attr({tabindex:0}).data("url",a).append($('<span class="img">').append(d)).append($('<span class="name">').text(b.name)).click(function(){h.file_browser_close($(this).data("url"))}).keydown(function(a){if(13== a.which)h.file_browser_close($(this).data("url"));else if(9==a.which)return rcube_event.get_modifier(a)==SHIFT_KEY?$(this).prev().focus().length||$("#image-upload-button").parents(".mce-panel").find("button:last").parent().focus():$(this).next().focus().length||$("#image-upload-button").focus(),!1})}};this.hack_file_input=function(a,b){function e(a){d||(d=c.offset());f.css({top:a.pageY-d.top-10+"px",left:a.pageX-d.left-10+"px"})}var d,c=$(a),f=$("<input>").attr("name","_file[]"),g=$("<form>").attr({method:"post", enctype:"multipart/form-data"});b&&(f.attr("name",$('input[type="file"]',b).attr("name")),g.attr("action",$(b).attr("action")).append($("<input>").attr({type:"hidden",name:"_token",value:rcmail.env.request_token})));f.attr({type:"file",multiple:"multiple",size:5,title:"",tabindex:-1}).change(function(){rcmail.upload_file(g,"upload")}).click(function(){setTimeout(function(){c.mouseleave()},20)}).css({opacity:0,cursor:"pointer",position:"relative",outline:"none"}).appendTo(g);navigator.userAgent.match(/Firefox|MSIE/)&& f.css({marginLeft:"-80px"});c.css({overflow:"hidden",cursor:"pointer"}).mouseenter(function(){this.__active=!0}).mousemove(function(a){this.__active?e(a):$(this).mouseleave()}).mouseleave(function(){f.css({top:"-10000px",left:"-10000px"});this.__active=!1}).click(function(a){this.__active||(this.__active=!0,e(a),f.trigger(a))}).keydown(function(a){13==a.which&&f.trigger("click")}).mouseleave().append(g)}};