Skip to content

Commit 80380eb

Browse files
committed
runAngularOutside
1 parent 5ad5aa2 commit 80380eb

File tree

3 files changed

+49
-30
lines changed

3 files changed

+49
-30
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.idea/
1+
.idea/
2+
.history

elastic.js

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,30 @@
55
*/
66

77
angular.module('monospaced.elastic', [])
8+
.provider('msdElasticProvider', [function () {
89

10+
const _self = this;
11+
12+
this.runAngularOutside = null;
13+
14+
this.setRunAngularOutsideFn = function (fn) {
15+
_self.runAngularOutside = fn;
16+
};
17+
18+
}])
919
.constant('msdElasticConfig', {
1020
append: ''
1121
})
1222

1323
.directive('msdElastic', [
14-
'$timeout', '$window', 'msdElasticConfig',
15-
function($timeout, $window, config) {
24+
'$timeout', '$window', 'msdElasticConfig', 'msdElasticProvider',
25+
function ($timeout, $window, config, msdElasticProvider) {
1626
'use strict';
1727

1828
return {
1929
require: 'ngModel',
2030
restrict: 'A, C',
21-
link: function(scope, element, attrs, ngModel) {
31+
link: function (scope, element, attrs, ngModel) {
2232

2333
// cache a reference to the DOM element
2434
var ta = element[0],
@@ -56,20 +66,20 @@ angular.module('monospaced.elastic', [])
5666
borderBox = taStyle.getPropertyValue('box-sizing') === 'border-box' ||
5767
taStyle.getPropertyValue('-moz-box-sizing') === 'border-box' ||
5868
taStyle.getPropertyValue('-webkit-box-sizing') === 'border-box',
59-
boxOuter = !borderBox ? {width: 0, height: 0} : {
60-
width: parseInt(taStyle.getPropertyValue('border-right-width'), 10) +
61-
parseInt(taStyle.getPropertyValue('padding-right'), 10) +
62-
parseInt(taStyle.getPropertyValue('padding-left'), 10) +
63-
parseInt(taStyle.getPropertyValue('border-left-width'), 10),
69+
boxOuter = !borderBox ? { width: 0, height: 0 } : {
70+
width: parseInt(taStyle.getPropertyValue('border-right-width'), 10) +
71+
parseInt(taStyle.getPropertyValue('padding-right'), 10) +
72+
parseInt(taStyle.getPropertyValue('padding-left'), 10) +
73+
parseInt(taStyle.getPropertyValue('border-left-width'), 10),
6474
height: parseInt(taStyle.getPropertyValue('border-top-width'), 10) +
65-
parseInt(taStyle.getPropertyValue('padding-top'), 10) +
66-
parseInt(taStyle.getPropertyValue('padding-bottom'), 10) +
67-
parseInt(taStyle.getPropertyValue('border-bottom-width'), 10)
75+
parseInt(taStyle.getPropertyValue('padding-top'), 10) +
76+
parseInt(taStyle.getPropertyValue('padding-bottom'), 10) +
77+
parseInt(taStyle.getPropertyValue('border-bottom-width'), 10)
6878
},
6979
minHeightValue = parseInt(taStyle.getPropertyValue('min-height'), 10),
7080
heightValue = parseInt(taStyle.getPropertyValue('height'), 10),
7181
minHeight = Math.max(minHeightValue, heightValue) - boxOuter.height,
72-
maxHeight = scope.maxHeight?scope.maxHeight:parseInt(taStyle.getPropertyValue('max-height'), 10),
82+
maxHeight = scope.maxHeight ? scope.maxHeight : parseInt(taStyle.getPropertyValue('max-height'), 10),
7383
mirrored,
7484
active,
7585
copyStyle = ['font-family',
@@ -110,7 +120,7 @@ angular.module('monospaced.elastic', [])
110120
mirrored = ta;
111121
// copy the essential styles from the textarea to the mirror
112122
taStyle = getComputedStyle(ta);
113-
angular.forEach(copyStyle, function(val) {
123+
angular.forEach(copyStyle, function (val) {
114124
mirrorStyle += val + ':' + taStyle.getPropertyValue(val) + ';';
115125
});
116126
mirror.setAttribute('style', mirrorStyle);
@@ -162,7 +172,7 @@ angular.module('monospaced.elastic', [])
162172
}
163173

164174
// small delay to prevent an infinite loop
165-
$timeout(function() {
175+
$timeout(function () {
166176
active = false;
167177
}, 1);
168178

@@ -178,37 +188,45 @@ angular.module('monospaced.elastic', [])
178188
* initialise
179189
*/
180190

181-
// listen
182-
if ('onpropertychange' in ta && 'oninput' in ta) {
183-
// IE9
184-
ta['oninput'] = ta.onkeyup = adjust;
191+
var listen = function () {
192+
// listen
193+
if ('onpropertychange' in ta && 'oninput' in ta) {
194+
// IE9
195+
ta['oninput'] = ta.onkeyup = adjust;
196+
} else {
197+
ta['oninput'] = adjust;
198+
}
199+
$win.bind('resize', forceAdjust);
200+
};
201+
202+
if (msdElasticProvider.runAngularOutside) {
203+
msdElasticProvider.runAngularOutside(() => {
204+
listen();
205+
});
185206
} else {
186-
ta['oninput'] = adjust;
207+
listen();
187208
}
188-
189-
$win.bind('resize', forceAdjust);
190-
191-
scope.$watch(function() {
192-
if(scope.maxHeight && scope.maxHeight!= maxHeight){
209+
scope.$watch(function () {
210+
if (scope.maxHeight && scope.maxHeight != maxHeight) {
193211
maxHeight = scope.maxHeight
194212
}
195213
return ngModel.$modelValue;
196-
}, function(newValue) {
214+
}, function (newValue) {
197215
forceAdjust();
198216
});
199217

200-
scope.$on('elastic:adjust', function() {
218+
scope.$on('elastic:adjust', function () {
201219
initMirror();
202220
forceAdjust();
203221
});
204222

205-
$timeout(function(){adjust},5000);
223+
$timeout(function () { adjust }, 5000);
206224

207225
/*
208226
* destroy
209227
*/
210228

211-
scope.$on('$destroy', function() {
229+
scope.$on('$destroy', function () {
212230
$mirror.remove();
213231
$win.unbind('resize', forceAdjust);
214232
});

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-elastic",
3-
"version": "2.5.12",
3+
"version": "2.5.13",
44
"description": "Elastic (autosize) textareas for AngularJS, without jQuery dependency.",
55
"keywords": [
66
"angular",

0 commit comments

Comments
 (0)