| | |
| | | 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; |
| | |
| | | // set caret after inserted text |
| | | this.set_caret_pos(textarea, selection.start + insert.length); |
| | | textarea.focus(); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | |
| | | */ |
| | | 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); |
| | | } |
| | | } |
| | | |
| | |
| | | $('<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); |
| | |
| | | /********* helper methods *********/ |
| | | /********************************************************/ |
| | | |
| | | /** |
| | | * Quote html entities |
| | | */ |
| | | this.quote_html = function(str) |
| | | { |
| | | return String(str).replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
| | | }; |
| | | |
| | | // get window.opener.rcmail if available |
| | | this.opener = function() |
| | | { |
| | |
| | | normalizedValue = obj.value; |
| | | start = obj.selectionStart; |
| | | end = obj.selectionEnd; |
| | | } else { |
| | | } |
| | | else { |
| | | range = document.selection.createRange(); |
| | | |
| | | if (range && range.parentElement() == obj) { |
| | |
| | | |
| | | 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; |
| | | } |