X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=js%2Fwysiwyg%2Fcrm.wysiwyg.js;h=41adc35d4e74bf73899113780554858ed807951d;hb=9be4e9c5626a66612a33f63d60c5973fc7d0d881;hp=d61bcdea82e44f93356c89aaf42e594a624de7c7;hpb=977132359c34f54dfcf38a6f642bf92bfbadd98a;p=civicrm-core.git diff --git a/js/wysiwyg/crm.wysiwyg.js b/js/wysiwyg/crm.wysiwyg.js index d61bcdea82..41adc35d4e 100644 --- a/js/wysiwyg/crm.wysiwyg.js +++ b/js/wysiwyg/crm.wysiwyg.js @@ -34,14 +34,16 @@ }, // Fallback function to use when a wysiwyg has not been initialized _insertIntoTextarea: function(item, text) { - var origVal = $(item).val(); - var origPos = item[0].selectionStart; - var newVal = origVal + text; - $(item).val(newVal); - var newPos = (origPos + text.length); - item[0].selectionStart = newPos; - item[0].selectionEnd = newPos; - $(item).triggerHandler('change'); + var itemObj = $(item); + var origVal = itemObj.val(); + var origStart = itemObj[0].selectionStart; + var origEnd = itemObj[0].selectionEnd; + var newVal = origVal.substring(0, origStart) + text + origVal.substring(origEnd); + itemObj.val(newVal); + var newPos = (origStart + text.length); + itemObj[0].selectionStart = newPos; + itemObj[0].selectionEnd = newPos; + itemObj.triggerHandler('change'); CRM.wysiwyg.focus(item); }, // Create a "collapsed" textarea that expands into a wysiwyg when clicked @@ -52,6 +54,9 @@ CRM.wysiwyg.destroy(item); $(item).hide().next('.replace-plain').show().html($(item).val()); }) + .on('change', function() { + $(this).next('.replace-plain').html($(this).val()); + }) .after('
'); $(item).next('.replace-plain') .attr('title', ts('Click to edit'))