Skip to content

Commit

Permalink
Remove code that does UA sniffing and explicit stuff for IE11 only
Browse files Browse the repository at this point in the history
  • Loading branch information
BatJan authored and nul800sebastiaan committed Apr 11, 2020
1 parent 18e4299 commit 7a1bd34
Showing 1 changed file with 67 additions and 140 deletions.
Original file line number Diff line number Diff line change
@@ -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('<span style="white-space:pre;"></span>');

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('<div id="umb-ie-resize-input-wrapper" style="position:fixed; top:-999px; left:0;"></div>');
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();
}

});
}
};
});
};
});

0 comments on commit 7a1bd34

Please sign in to comment.