fix(mail(js)): add debouncing on keyup events of sgAutogrow

snyk-upgrade-0ec09bc7ae34af7c5d0348d49696b8f1
Francis Lachapelle 2021-05-05 17:37:42 -04:00
parent 049c17f15a
commit d303247481
1 changed files with 11 additions and 13 deletions

View File

@ -18,8 +18,8 @@
<textarea rows="9" md-no-autogrow sg-autogrow="!isPopup" />
*/
sgAutogrow.$inject = ['$document', '$timeout'];
function sgAutogrow($document, $timeout) {
sgAutogrow.$inject = ['$document', '$timeout', '$mdUtil'];
function sgAutogrow($document, $timeout, $mdUtil) {
return {
restrict: 'A',
scope: {
@ -44,19 +44,17 @@
textarea.style.overflow = 'hidden';
function AutoGrowTextArea() {
$timeout(function() {
content = textarea.value.encodeEntities();
content = content.replace(/\n/g, '<br>');
hiddenDiv.innerHTML = content + '<br style="line-height: 3px;">';
hiddenDiv.style.visibility = 'hidden';
hiddenDiv.style.display = 'block';
textarea.style.height = Math.max(minHeight, hiddenDiv.offsetHeight) + 'px';
hiddenDiv.style.visibility = 'visible';
hiddenDiv.style.display = 'none';
});
content = textarea.value.encodeEntities();
content = content.replace(/\n/g, '<br>');
hiddenDiv.innerHTML = content + '<br style="line-height: 3px;">';
hiddenDiv.style.visibility = 'hidden';
hiddenDiv.style.display = 'block';
textarea.style.height = Math.max(minHeight, hiddenDiv.offsetHeight) + 'px';
hiddenDiv.style.visibility = 'visible';
hiddenDiv.style.display = 'none';
}
elem.on('keyup', AutoGrowTextArea);
elem.on('keyup', $mdUtil.debounce(AutoGrowTextArea, 200));
elem.on('paste', AutoGrowTextArea);
var deregisterWatcher = scope.$watch(function() {