From: Tim Otten Date: Wed, 20 May 2015 00:41:13 +0000 (-0700) Subject: CRM-16445 - crmUiRichtext - Fix "Source" mode. Listen to 'key' event. X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=774738e2d7c558847d25a996209ee5b62cc6a435;p=civicrm-core.git CRM-16445 - crmUiRichtext - Fix "Source" mode. Listen to 'key' event. 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). --- diff --git a/ang/crmUi.js b/ang/crmUi.js index 0c571c691d..24c7dceb42 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -422,10 +422,15 @@ // 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) {