Aleksander Machniak
2014-10-30 a075df6f086656f9a01f0023111be6eb83c9d0db
program/js/editor.js
@@ -40,7 +40,7 @@
      selector: '#' + ($('#' + id).is('.mce_editor') ? id : 'fake-editor-id'),
      theme: 'modern',
      language: config.lang,
      content_css: 'program/js/tinymce/roundcube/content.css?v1',
      content_css: 'program/js/tinymce/roundcube/content.css?v2',
      menubar: false,
      statusbar: false,
      toolbar_items_size: 'small',
@@ -50,7 +50,8 @@
      convert_urls: false, // #1486944
      image_description: false,
      paste_webkit_style: "color font-size font-family",
      paste_data_images: true
      paste_data_images: true,
      browser_spellcheck: true
    };
  // register spellchecker for plain text editor
@@ -103,6 +104,10 @@
    });
    ed.on('keypress', function() {
      rcmail.compose_type_activity++;
    });
    // secure spellchecker requests with Roundcube token
    tinymce.util.XHR.on('beforeSend', function(e) {
      e.xhr.setRequestHeader('X-Roundcube-Request', rcmail.env.request_token);
    });
  };
@@ -189,7 +194,7 @@
  };
  // switch html/plain mode
  this.toggle = function(ishtml)
  this.toggle = function(ishtml, noconvert)
  {
    var curr, content, result,
      // these non-printable chars are not removed on text2html and html2text
@@ -209,8 +214,7 @@
      if (is_sig)
        content = content.replace(signature.text, sig_mark);
      // convert to html
      result = rcmail.plain2html(content, function(data) {
      var init_editor = function(data) {
        // replace signature mark with html version of the signature
        if (is_sig)
          data = data.replace(sig_mark, '<div id="_rc_sig">' + signature.html + '</div>');
@@ -226,7 +230,16 @@
            ref.tabindex(true);
          }
        }, 500);
      });
      };
      // convert to html
      if (!noconvert) {
        result = rcmail.plain2html(content, init_editor);
      }
      else {
        init_editor(content);
        result = true;
      }
    }
    else if (this.editor) {
      if (is_sig) {
@@ -245,8 +258,7 @@
      // get html content
      content = this.editor.getContent();
      // convert html to text
      result = rcmail.html2plain(content, function(data) {
      var init_plaintext = function(data) {
        tinymce.execCommand('mceRemoveEditor', false, ref.id);
        ref.editor = null;
@@ -255,7 +267,16 @@
          data = data.replace(sig_mark, "\n" + signature.text);
        input.val(data).focus();
      });
      };
      // convert html to text
      if (!noconvert) {
        result = rcmail.html2plain(content, init_plaintext);
      }
      else {
        init_plaintext(input.val());
        result = true;
      }
      // bring back current signature
      if (!result && curr)
@@ -283,9 +304,10 @@
    var ed = this.editor;
    if (ed) {
      if (ed.plugins && ed.plugins.spellchecker && this.spellcheck_active)
        ed.execCommand('mceSpellCheck');
      if (ed.plugins && ed.plugins.spellchecker && this.spellcheck_active) {
        ed.execCommand('mceSpellCheck', false);
        this.spellcheck_observer();
      }
    }
    else if (ed = this.spellchecker) {
      if (ed.state && ed.state != 'ready' && ed.state != 'no_error_found')
@@ -304,17 +326,13 @@
      return ed.state != 'ready' && ed.state != 'no_error_found';
  };
  // resume spellchecking, highlight provided mispellings without new ajax request
  // resume spellchecking, highlight provided mispellings without a new ajax request
  this.spellcheck_resume = function(data)
  {
    var ed = this.editor;
    if (ed) {
      ed.settings.spellchecker_callback = function(name, text, done, error) { done(data); };
      ed.execCommand('mceSpellCheck');
      ed.settings.spellchecker_callback = null;
      this.spellcheck_observer();
      ed.plugins.spellchecker.markErrors(data);
    }
    else if (ed = this.spellchecker) {
      ed.prepare(false, true);
@@ -373,29 +391,33 @@
  };
  // get selected text (if no selection returns all text) from the editor
  this.get_content = function(selected, plain)
  this.get_content = function(args)
  {
    // apply spellcheck changes if spell checker is active
    this.spellcheck_stop();
    var sigstart, ed = this.editor, text = '', strip = false,
      defaults = {refresh: true, selection: false, nosig: false, format: 'html'};
    var sigstart, ed = this.editor,
      format = plain ? 'text' : 'html',
      text = '', strip = false;
    args = $.extend(defaults, args);
    // apply spellcheck changes if spell checker is active
    if (args.refresh) {
      this.spellcheck_stop();
    }
    // get selected text from tinymce editor
    if (ed) {
      ed.getWin().focus(); // correct focus in IE & Chrome
      if (selected)
        text = ed.selection.getContent({format: format});
      if (args.selection)
        text = ed.selection.getContent({format: args.format});
      if (!text) {
        text = ed.getContent({format: format});
        strip = true;
        text = ed.getContent({format: args.format});
        // @todo: strip signature in html mode
        strip = args.format == 'text';
      }
    }
    // get selected text from compose textarea
    else if (ed = rcube_find_object(this.id)) {
      if (selected && $(ed).is(':focus')) {
      if (args.selection && $(ed).is(':focus')) {
        text = rcmail.get_input_selection(ed).text;
      }
@@ -406,7 +428,8 @@
    }
    // strip off signature
    if (strip) {
    // @todo: make this optional
    if (strip && args.nosig) {
      sigstart = text.indexOf('-- \n');
      if (sigstart > 0) {
        text = text.substring(0, sigstart);
@@ -589,8 +612,14 @@
    this.hack_file_input(elem, rcmail.gui_objects.uploadform);
    // enable drag-n-drop area
    if (rcmail.gui_objects.filedrop && rcmail.env.filedrop && ((window.XMLHttpRequest && XMLHttpRequest.prototype && XMLHttpRequest.prototype.sendAsBinary) || window.FormData)) {
      rcmail.env.old_file_drop = rcmail.gui_objects.filedrop;
    if ((window.XMLHttpRequest && XMLHttpRequest.prototype && XMLHttpRequest.prototype.sendAsBinary) || window.FormData) {
      if (!rcmail.env.filedrop) {
        rcmail.env.filedrop = {};
      }
      if (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(e) {
@@ -637,6 +666,10 @@
  {
    if (!file.complete || !file.mimetype) {
      return;
    }
    if (rcmail.file_upload_id) {
      rcmail.set_busy(false, null, rcmail.file_upload_id);
    }
    var rx, img_src;
@@ -692,7 +725,7 @@
  this.hack_file_input = function(elem, clone_form)
  {
    var link = $(elem),
      file = $('<input>').attr('name', '_files[]'),
      file = $('<input>').attr('name', '_file[]'),
      form = $('<form>').attr({method: 'post', enctype: 'multipart/form-data'}),
      offset = link.offset();