From 7a1bd34fa5716ff54d8fe0080470b19d0af25665 Mon Sep 17 00:00:00 2001 From: BatJan Date: Sat, 11 Apr 2020 00:35:31 +0200 Subject: [PATCH] Remove code that does UA sniffing and explicit stuff for IE11 only --- .../forms/umbautoresize.directive.js | 207 ++++++------------ 1 file changed, 67 insertions(+), 140 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautoresize.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautoresize.directive.js index 69ec1be80527..2ec3960a59f8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautoresize.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/forms/umbautoresize.directive.js @@ -1,161 +1,88 @@ angular.module("umbraco.directives") - .directive('umbAutoResize', function($timeout) { - return { - require: ["^?umbTabs", "ngModel"], - link: function(scope, element, attr, controllersArr) { - - var domEl = element[0]; - var domElType = domEl.type; - var umbTabsController = controllersArr[0]; - var ngModelController = controllersArr[1]; - - // IE elements - var isIEFlag = false; - var wrapper = angular.element('#umb-ie-resize-input-wrapper'); - var mirror = angular.element(''); - - function isIE() { - - var ua = window.navigator.userAgent; - var msie = ua.indexOf("MSIE "); - - if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./) || navigator.userAgent.match(/Edge\/\d+/)) { - return true; - } else { - return false; - } - - } - - function activate() { - - // check if browser is Internet Explorere - isIEFlag = isIE(); - - // scrollWidth on element does not work in IE on inputs - // we have to do some dirty dom element copying. - if (isIEFlag === true && domElType === "text") { - setupInternetExplorerElements(); - } - - } - - function setupInternetExplorerElements() { - - if (!wrapper.length) { - wrapper = angular.element('
'); - angular.element('body').append(wrapper); - } - - angular.forEach(['fontFamily', 'fontSize', 'fontWeight', 'fontStyle', - 'letterSpacing', 'textTransform', 'wordSpacing', 'textIndent', - 'boxSizing', 'borderRightWidth', 'borderLeftWidth', 'borderLeftStyle', 'borderRightStyle', - 'paddingLeft', 'paddingRight', 'marginLeft', 'marginRight' - ], function(value) { - mirror.css(value, element.css(value)); - }); - - wrapper.append(mirror); - - } - - function resizeInternetExplorerInput() { - - mirror.text(element.val() || attr.placeholder); - element.css('width', mirror.outerWidth() + 1); - - } - - function resizeInput() { - - if (domEl.scrollWidth !== domEl.clientWidth) { - if (ngModelController.$modelValue) { - element.width(domEl.scrollWidth); - } - } - - if(!ngModelController.$modelValue && attr.placeholder) { - attr.$set('size', attr.placeholder.length); - element.width('auto'); - } - - } - - function resizeTextarea() { - - if(domEl.scrollHeight !== domEl.clientHeight) { - - element.height(domEl.scrollHeight); - - } + .directive('umbAutoResize', function ($timeout) { + return { + require: ["^?umbTabs", "ngModel"], + link: function (scope, element, attr, controllersArr) { + + var domEl = element[0]; + var domElType = domEl.type; + var umbTabsController = controllersArr[0]; + var ngModelController = controllersArr[1]; + + function resizeInput() { + + if (domEl.scrollWidth !== domEl.clientWidth) { + if (ngModelController.$modelValue) { + element.width(domEl.scrollWidth); + } + } - } + if (!ngModelController.$modelValue && attr.placeholder) { + attr.$set('size', attr.placeholder.length); + element.width('auto'); + } - var update = function(force) { + } + function resizeTextarea() { - if (force === true) { + if (domEl.scrollHeight !== domEl.clientHeight) { - if (domElType === "textarea") { - element.height(0); - } else if (domElType === "text") { - element.width(0); - } + element.height(domEl.scrollHeight); - } + } + } - if (isIEFlag === true && domElType === "text") { + var update = function (force) { - resizeInternetExplorerInput(); - } else { + if (force === true) { - if (domElType === "textarea") { + if (domElType === "textarea") { + element.height(0); + } else if (domElType === "text") { + element.width(0); + } - resizeTextarea(); + } - } else if (domElType === "text") { - resizeInput(); + if (domElType === "textarea") { - } + resizeTextarea(); - } + } else if (domElType === "text") { - }; + resizeInput(); - activate(); + } - //listen for tab changes - if (umbTabsController != null) { - umbTabsController.onTabShown(function(args) { - update(); - }); + }; + + //listen for tab changes + if (umbTabsController != null) { + umbTabsController.onTabShown(function (args) { + update(); + }); + } + + // listen for ng-model changes + var unbindModelWatcher = scope.$watch(function () { + return ngModelController.$modelValue; + }, function (newValue) { + $timeout( + function () { + update(true); + } + ); + }); + + scope.$on('$destroy', function () { + element.off('keyup keydown keypress change', update); + element.off('blur', update(true)); + unbindModelWatcher(); + }); } - - // listen for ng-model changes - var unbindModelWatcher = scope.$watch(function() { - return ngModelController.$modelValue; - }, function(newValue) { - $timeout( - function() { - update(true); - } - ); - }); - - scope.$on('$destroy', function() { - element.off('keyup keydown keypress change', update); - element.off('blur', update(true)); - unbindModelWatcher(); - - // clean up IE dom element - if (isIEFlag === true && domElType === "text") { - mirror.remove(); - } - - }); - } - }; - }); + }; + });