%PDF- %PDF-
Direktori : /data/www_bck/varak.net_bck/tmp2/program/js/ |
Current File : //data/www_bck/varak.net_bck/tmp2/program/js/editor.min.js |
/** * 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(k,m){var g=this,p=location.href.replace(/[?#].*$/,"").replace(/\/$/,""),l={selector:"#"+($("#"+m).is(".mce_editor")?m:"fake-editor-id"),cache_suffix:"s=4010700",theme:"modern",language:k.lang,content_css:rcmail.assets_path("program/js/tinymce/roundcube/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(){};k.spellchecker&&(this.spellchecker=k.spellchecker,k.spellcheck_observer&&(this.spellchecker.spelling_state_observer=this.spellcheck_observer=k.spellcheck_observer));"identity"==k.mode?$.extend(l,{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(b,a,c,d){g.file_browser_callback(b,a,c)},file_browser_callback_types:"image"}):$.extend(l,{plugins:"autolink charmap code colorpicker directionality emoticons link image media nonbreaking paste table tabfocus textcolor searchreplace"+(k.spellcheck?" spellchecker":""),toolbar:"bold italic underline | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent ltr rtl blockquote | forecolor backcolor | fontselect fontsizeselect | link unlink table | emoticons charmap image media | code searchreplace undo redo", spellchecker_rpc_url:p+"/?_task=utils&_action=spell_html&_remote=1",spellchecker_language:rcmail.env.spell_lang,accessibility_focus:!1,file_browser_callback:function(b,a,c,d){g.file_browser_callback(b,a,c)},file_browser_callback_types:"image media"});window.rcmail_editor_settings&&$.extend(l,window.rcmail_editor_settings);l.setup=function(b){b.on("init",function(a){g.init_callback(a)});b.on("SpellcheckStart SpellcheckEnd",function(a){g.spellcheck_active="spellcheckstart"==a.type;g.spellcheck_observer()}); b.on("keypress",function(){rcmail.compose_type_activity++});tinymce.util.XHR.on("beforeSend",function(a){a.xhr.setRequestHeader("X-Roundcube-Request",rcmail.env.request_token)})};this.id=m;this.editor=null;tinymce.init(l);this.init_callback=function(b){this.editor=b.target;if("compose"==rcmail.env.action){b={};var a=rcube_find_object("_from"),c=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);a&&"select-one"==a.type&&(rcmail.env.identities_initialized||rcmail.change_identity(a),c&&c.id!=this.id&&window.setTimeout(function(){window.focus();c.focus()},10));this.tabindex(c&&c.id==this.id);window.setTimeout(function(){$(window).resize()},100)}};this.tabindex=function(b){if("mail"==rcmail.env.task&&this.editor){var a=this.editor.getElement(),c=this.editor.getContentAreaContainer().childNodes[0];a&&c&&(c.tabIndex=a.tabIndex); b&&this.editor.getBody().focus();if(0<a.tabIndex){var d=null,e=this.editor;b=[":prev",":next"];a=tinymce.DOM.select("*[tabindex="+a.tabIndex+"]:not(iframe)");tinymce.each(a,function(a,b){if(a.id==e.id)return d=b,!1});null!==d&&(a[d-1]&&a[d-1].id&&(b[0]=a[d-1].id),a[d+1]&&a[d+1].id&&(b[1]=a[d+1].id),e.settings.tabfocus_elements=b.join(","))}}};this.toggle=function(b,a){var c,d,e=$("#"+this.id),f=rcmail.env.identity?rcmail.env.signatures[rcmail.env.identity]:null,h=f&&f.text&&1<f.text.length;this.spellcheck_stop(); if(b)d=e.val(),h&&(d=d.replace(/\r\n/,"\n"),d=d.replace(f.text.replace(/\r\n/,"\n"),"\u0002\u0003")),c=function(a){h&&(a=a.replace("\u0002\u0003",'<div id="_rc_sig">'+f.html+"</div>"));e.val(a);tinymce.execCommand("mceAddEditor",!1,g.id);setTimeout(function(){g.editor&&(rcmail.env.default_font&&$(g.editor.getBody()).css("font-family",rcmail.env.default_font),g.tabindex(!0))},500)},a?(c(d),d=!0):d=rcmail.plain2html(d,c);else if(this.editor){if(h){if(c=this.editor.dom.get("_rc_sig"))c=c.innerHTML;this.editor.dom.setHTML("_rc_sig", "\u0002\u0003")}d=this.editor.getContent();var n=function(a){tinymce.execCommand("mceRemoveEditor",!1,g.id);g.editor=null;h&&(a=a.replace("\u0002\u0003","\n"+f.text));e.val(a).focus()};a?(n(e.val()),d=!0):d=rcmail.html2plain(d,n);!d&&c&&this.editor.dom.setHTML("_rc_sig",c)}return d};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 b= this.editor;b?b.plugins&&b.plugins.spellchecker&&this.spellcheck_active&&(b.execCommand("mceSpellCheck",!1),this.spellcheck_observer()):(b=this.spellchecker)&&b.state&&"ready"!=b.state&&"no_error_found"!=b.state&&$(b.spell_span).trigger("click")};this.spellcheck_state=function(){var b;if(this.editor)return this.spellcheck_active;if((b=this.spellchecker)&&b.state)return"ready"!=b.state&&"no_error_found"!=b.state};this.spellcheck_resume=function(b){var a=this.editor;if(a)a.plugins.spellchecker.markErrors(b); else if(a=this.spellchecker)a.prepare(!1,!0),a.processData(b)};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(b){var a=this.editor;a&&(a.settings.spellchecker_language=b);(a=this.spellchecker)&&a.setCurrentLanguage(b)};this.replace=function(b){var a=this.editor;if(a)a.getWin().focus(),a.selection.setContent(rcmail.quote_html(b).replace(/\r?\n/g,"<br/>"),{format:"text"}); else if(a=rcube_find_object(this.id)){var c=$(a).is(":focus")?rcmail.get_input_selection(a):{start:0,end:0},d=a.value;pre=d.substring(0,c.start);end=d.substring(c.end,d.length);a.value=pre+b+end;rcmail.set_caret_pos(a,c.start+b.length);a.focus()}};this.get_content=function(b){var a=this.editor,c="",d=!1;b=$.extend({refresh:!0,selection:!1,nosig:!1,format:"html"},b);b.refresh&&this.spellcheck_stop();if(a)a.getWin().focus(),b.selection&&(c=a.selection.getContent({format:b.format})),c||(c=a.getContent({format:b.format}), d="text"==b.format);else if(a=rcube_find_object(this.id))b.selection&&$(a).is(":focus")&&(c=rcmail.get_input_selection(a).text),c||(c=a.value,d=!0);d&&b.nosig&&(b=c.indexOf("-- \n"),0<b&&(c=c.substring(0,b)));return c};this.change_signature=function(b,a){var c;c=-1;var d=$("#"+this.id),e=d.val(),f=rcmail.env.identity;this.editor?a&&rcmail.env.signatures&&(d=this.editor.dom.get("_rc_sig"),d||(e=this.editor.getBody(),f=this.editor.getDoc(),d=f.createElement("div"),d.setAttribute("id","_rc_sig"),rcmail.env.top_posting? (this.editor.getWin().focus(),c=this.editor.selection.getNode(),"BODY"==c.nodeName?(e.insertBefore(d,e.firstChild),e.insertBefore(f.createElement("br"),e.firstChild)):(e.insertBefore(d,c.nextSibling),e.insertBefore(f.createElement("br"),c.nextSibling))):e.appendChild(d)),rcmail.env.signatures[b]&&(d.innerHTML=rcmail.env.signatures[b].html)):(a&&f&&rcmail.env.signatures&&rcmail.env.signatures[f]&&(f=rcmail.env.signatures[f].text,f=f.replace(/\r\n/g,"\n"),c=rcmail.env.top_posting?e.indexOf(f):e.lastIndexOf(f), 0<=c&&(e=e.substring(0,c)+e.substring(c+f.length,e.length))),a&&rcmail.env.signatures&&rcmail.env.signatures[b]?(f=rcmail.env.signatures[b].text,f=f.replace(/\r\n/g,"\n"),rcmail.env.top_posting?0<=c?(e=e.substring(0,c)+f+e.substring(c,e.length),c-=1):e?(pos=rcmail.get_caret_pos(d.get(0)))?(e=e.substring(0,pos)+"\n"+f+"\n\n"+e.substring(pos,e.length),c=pos):(c=0,e="\n\n"+f+"\n\n"+e.replace(/^[\r\n]+/,"")):(c=0,e="\n\n"+f):(e=e.replace(/[\r\n]+$/,""),c=!rcmail.env.top_posting&&e.length?e.length+1:0, e+="\n\n"+f)):c=rcmail.env.top_posting?0:e.length,d.val(e),rcmail.set_caret_pos(d.get(0),c))};this.save=function(){this.editor&&this.editor.save()};this.focus=function(){(this.editor||rcube_find_object(this.id)).focus()};this.file_browser_callback=function(b,a,c){var d,e,f,h=[];a=this.editor.windowManager.open({title:rcmail.gettext("select"+c),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(){g.file_browser_close()}}]});rcmail.env.file_browser_field=b;rcmail.env.file_browser_type=c;for(d in rcmail.env.attachments)(e=g.file_browser_entry(d,rcmail.env.attachments[d]))&&h.push(e);h.length&&$("#image-selector-list > ul").append(h).find("li:first").focus();$("div.mce-abs-end",a.getEl()).append($('<div class="hint">').text($("div.hint",rcmail.gui_objects.uploadform).text()));e=$("#image-upload-button").append($("<span>").text(rcmail.gettext("add"+c))); f=e.parents(".mce-panel").find("button:last").parent();e.keydown(function(a){if(9==a.which)return rcube_event.get_modifier(a)==SHIFT_KEY?$("#image-selector-list li:last").focus():f.focus(),!1});f.keydown(function(a){if(9==a.which)return rcube_event.get_modifier(a)==SHIFT_KEY?e.focus():$("#image-selector-list li:first").focus(),!1});this.hack_file_input(e,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").bind("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=g.file_browser_entry(a.name,a.attachment))$("#image-selector-list > ul").prepend(a),a.focus()}))};this.file_browser_close=function(b){var a=$("#"+rcmail.env.file_browser_field);b&&a.val(b);this.editor.windowManager.close();a.focus();rcmail.env.old_file_drop&&(rcmail.gui_objects.filedrop=rcmail.env.old_file_drop)};this.file_browser_entry=function(b,a){if(a.complete&&a.mimetype){rcmail.file_upload_id&&rcmail.set_busy(!1,null,rcmail.file_upload_id);var c,d;switch(rcmail.env.file_browser_type){case "image":c= /^image\//i;break;case "media":c=/^video\//i;d="program/js/tinymce/roundcube/video.png";break;default:return}if(c.test(a.mimetype))return c=rcmail.env.comm_path+"&_from="+rcmail.env.action+(rcmail.env.compose_id?"&_id="+rcmail.env.compose_id+"&_action=display-attachment":"&_action=upload-display")+"&_file="+b,d=$("<img>").attr({title:a.name,src:d?d:c+"&_thumbnail=1"}),$("<li>").attr({tabindex:0}).data("url",c).append($('<span class="img">').append(d)).append($('<span class="name">').text(a.name)).click(function(){g.file_browser_close($(this).data("url"))}).keydown(function(a){if(13== a.which)g.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(b,a){function c(a){e.css({top:a.pageY-g.top-10+"px",left:a.pageX-g.left-10+"px"})}var d=$(b),e=$("<input>").attr("name","_file[]"),f=$("<form>").attr({method:"post",enctype:"multipart/form-data"}), g=d.offset();a&&(e.attr("name",$('input[type="file"]',a).attr("name")),f.attr("action",$(a).attr("action")).append($("<input>").attr({type:"hidden",name:"_token",value:rcmail.env.request_token})));e.attr({type:"file",multiple:"multiple",size:5,title:"",tabindex:-1}).change(function(){rcmail.upload_file(f,"upload")}).click(function(){setTimeout(function(){d.mouseleave()},20)}).css({opacity:0,cursor:"pointer",position:"relative",outline:"none"}).appendTo(f);navigator.userAgent.match(/Firefox|MSIE/)&& e.css({marginLeft:"-80px"});d.css({overflow:"hidden",cursor:"pointer"}).mouseenter(function(){this.__active=!0}).mousemove(function(a){this.__active?c(a):$(this).mouseleave()}).mouseleave(function(){e.css({top:"-10000px",left:"-10000px"});this.__active=!1}).click(function(a){this.__active||(this.__active=!0,c(a),e.trigger(a))}).keydown(function(a){13==a.which&&e.trigger("click")}).mouseleave().append(f)}};