Thomas Bruederli
2013-07-25 2d6242ffb25b199b569d956b65dec36170026d1e
Make canned response insertion and extraction work with both plaintext and HTML editors
1 files modified
52 ■■■■ changed files
program/js/app.js 52 ●●●● patch | view | raw | blame | history
program/js/app.js
@@ -3307,7 +3307,14 @@
    if (!insert)
      return false;
    // get cursor pos
    // insert into tinyMCE editor
    if ($("input[name='_is_html']").val() == '1') {
      var editor = tinyMCE.get(this.env.composebody);
      editor.getWin().focus(); // correct focus in IE & Chrome
      editor.selection.setContent(insert, { format:'text' });
    }
    // replace selection in compose textarea
    else {
    var textarea = rcube_find_object(this.env.composebody),
      selection = $(textarea).is(':focus') ? this.get_input_selection(textarea) : { start:0, end:0 },
      inp_value = textarea.value;
@@ -3320,6 +3327,7 @@
    // set caret after inserted text
    this.set_caret_pos(textarea, selection.start + insert.length);
    textarea.focus();
    }
  };
  /**
@@ -3327,20 +3335,37 @@
   */
  this.save_response = function()
  {
    var textarea = rcube_find_object(this.env.composebody),
      text = '', sigstart;
    var sigstart, text = '', strip = false;
    // get selected text from tinyMCE editor
    if ($("input[name='_is_html']").val() == '1') {
      var editor = tinyMCE.get(this.env.composebody);
      editor.getWin().focus(); // correct focus in IE & Chrome
      text = editor.selection.getContent({ format:'text' });
      if (!text) {
        text = editor.getContent({ format:'text' });
        strip = true;
      }
    }
    // get selected text from compose textarea
    else {
      var textarea = rcube_find_object(this.env.composebody), sigstart;
    if (textarea && $(textarea).is(':focus')) {
      text = this.get_input_selection(textarea).text;
    }
    if (!text && textarea) {
      text = textarea.value;
        strip = true;
      }
    }
      // strip off signature
    if (strip) {
      sigstart = text.indexOf('-- \n');
      if (sigstart > 0) {
        text = textarea.value.substring(0, sigstart);
        text = text.substring(0, sigstart);
      }
    }
@@ -3390,7 +3415,7 @@
      $('<a>').addClass('insertresponse active')
        .attr('href', '#')
        .attr('rel', key)
        .html(response.name)
        .html(this.quote_html(response.name))
        .appendTo(li)
        .mousedown(function(e){
          return rcube_event.cancel(e);
@@ -6878,6 +6903,14 @@
  /*********            helper methods            *********/
  /********************************************************/
  /**
   * Quote html entities
   */
  this.quote_html = function(str)
  {
    return String(str).replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
  };
  // get window.opener.rcmail if available
  this.opener = function()
  {
@@ -6954,7 +6987,8 @@
        normalizedValue = obj.value;
        start = obj.selectionStart;
        end = obj.selectionEnd;
    } else {
    }
    else {
        range = document.selection.createRange();
        if (range && range.parentElement() == obj) {
@@ -6973,13 +7007,15 @@
            if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) {
                start = end = len;
            } else {
        }
        else {
                start = -textInputRange.moveStart("character", -len);
                start += normalizedValue.slice(0, start).split("\n").length - 1;
                if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) {
                    end = len;
                } else {
          }
          else {
                    end = -textInputRange.moveEnd("character", -len);
                    end += normalizedValue.slice(0, end).split("\n").length - 1;
                }