CRM-16445 - crmUiRichtext - Fix "Source" mode. Listen to 'key' event.
authorTim Otten <totten@civicrm.org>
Wed, 20 May 2015 00:41:13 +0000 (17:41 -0700)
committerTim Otten <totten@civicrm.org>
Wed, 20 May 2015 00:43:48 +0000 (17:43 -0700)
See also:
 * http://civicrm.stackexchange.com/questions/2492/civimail-mailings-not-saving-or-corrupting
 * http://stackoverflow.com/questions/17358203/how-to-detect-ckeditor-source-mode-on-change-event

This is not strictly part of CRM-16445, but it's very similar (dealing with
the events emitted by ckeditor).

ang/crmUi.js

index 0c571c691dc3fc17738fffa90ee95f1a3756787b..24c7dceb42429380c3fde5b57d0b18e70d7a3a91 100644 (file)
           // afterCommandExec, afterInsertHtml, afterPaste, afterSetData, change, insertElement,
           // insertHtml, insertText, pasteState. It seems that 'pasteState' is the general equivalent of
           // what 'change' should be, except (in the case of image insertion) it fires too soon.
-          ck.on('pasteState', function(evt) {
-            $timeout(function() {
-              ngModel.$setViewValue(ck.getData());
-            }, 50);
+          // The 'key' event is needed to detect changes in "Source" mode.
+          var debounce = null;
+          angular.forEach(['key', 'pasteState'], function(evName){
+            ck.on(evName, function(evt) {
+              $timeout.cancel(debounce);
+              debounce = $timeout(function() {
+                ngModel.$setViewValue(ck.getData());
+              }, 50);
+            });
           });
 
           ngModel.$render = function (value) {