From 66eb8c14d070082634f3dee72553dcfab2971ad3 Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Tue, 4 Jul 2017 13:44:49 +0200 Subject: [PATCH 1/8] Added autogrow on spyed css proprties change --- angularjs-autogrow.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/angularjs-autogrow.js b/angularjs-autogrow.js index 81ecc75..425742a 100644 --- a/angularjs-autogrow.js +++ b/angularjs-autogrow.js @@ -62,6 +62,30 @@ $scope.$watch($attrs.ngModel, $scope.autogrowFn); + // Extract css properties to spy on + var spyProps = $attrs.autogrow.split(','); + angular.forEach(spyProps, function(property) { + // Set a watcher on each property + $scope.$watch( + function() { + return $element.css(property); + }, + styleChangedCallBack, + true + ); + }); + + /** + * + * @param newValue + * @param oldValue + */ + function styleChangedCallBack(newValue, oldValue) { + if (newValue !== oldValue) { + $scope.autogrowFn(); + } + } + /** * Auto-resize when there's content on page load */ From 2c49375736df82caeeab321ffad1fe6a9911f475 Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Tue, 4 Jul 2017 13:48:39 +0200 Subject: [PATCH 2/8] Updated README --- README.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/README.md b/README.md index efd66a9..01d198c 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,11 @@ You can set the initial line number using `rows` attribute: ```html ``` + + +### Autogrow on css properties change + +You can define which CSS properties have to be watched in order to trigger the auto-growing: +```html + +``` \ No newline at end of file From 0da294cd2d5708db7bb578987eaeef7439d1cc64 Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Tue, 4 Jul 2017 14:12:34 +0200 Subject: [PATCH 3/8] Updated minified version --- angularjs-autogrow.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 angularjs-autogrow.min.js diff --git a/angularjs-autogrow.min.js b/angularjs-autogrow.min.js old mode 100644 new mode 100755 index cc0803f..e8e0181 --- a/angularjs-autogrow.min.js +++ b/angularjs-autogrow.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("angularjs-autogrow",[]).directive("autogrow",["$window",function(t){return{link:function(e,o,r){e.attrs={rows:1,maxLines:999};for(var n in e.attrs)r[n]&&(e.attrs[n]=parseInt(r[n]));e.getOffset=function(){for(var e=t.getComputedStyle(o[0],null),r=["paddingTop","paddingBottom"],n=0,l=0;le.maxAllowedHeight?(o[0].style.overflowY="scroll",t=e.maxAllowedHeight):(o[0].style.overflowY="hidden",o[0].style.height="auto",t=o[0].scrollHeight-e.offset,r=!0),o[0].style.height=t+"px",r},e.offset=e.getOffset(),e.lineHeight=o[0].scrollHeight/e.attrs.rows-e.offset/e.attrs.rows,e.maxAllowedHeight=e.lineHeight*e.attrs.maxLines-e.offset,e.$watch(r.ngModel,e.autogrowFn),""!=o[0].value&&e.autogrowFn()}}}])}(); \ No newline at end of file +!function(){"use strict";angular.module("angularjs-autogrow",[]).directive("autogrow",["$window",function(t){return{link:function(o,e,r){function n(t,e){t!==e&&o.autogrowFn()}o.attrs={rows:1,maxLines:999};for(var a in o.attrs)r[a]&&(o.attrs[a]=parseInt(r[a]));o.getOffset=function(){for(var o=t.getComputedStyle(e[0],null),r=["paddingTop","paddingBottom"],n=0,a=0;ao.maxAllowedHeight?(e[0].style.overflowY="scroll",t=o.maxAllowedHeight):(e[0].style.overflowY="hidden",e[0].style.height="auto",t=e[0].scrollHeight-o.offset,r=!0),e[0].style.height=t+"px",r},o.offset=o.getOffset(),o.lineHeight=e[0].scrollHeight/o.attrs.rows-o.offset/o.attrs.rows,o.maxAllowedHeight=o.lineHeight*o.attrs.maxLines-o.offset,o.$watch(r.ngModel,o.autogrowFn);var l=r.autogrow.split(",");angular.forEach(l,function(t){o.$watch(function(){return e.css(t)},n,!0)}),""!=e[0].value&&o.autogrowFn()}}}])}(); From a39ebb0eea5db16143814db375d2bed663f4149f Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Tue, 4 Jul 2017 14:13:19 +0200 Subject: [PATCH 4/8] Updated to version 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 284c679..4277f0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angularjs-autogrow", - "version": "0.3.1", + "version": "0.4.0", "description": "AngularJS 1.x directive for auto-grow / auto-resize of textarea elements", "main": "angularjs-autogrow.js", "scripts": { From 2e6b1df808a02dc280ea5f037cad80fc9cea5072 Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Tue, 4 Jul 2017 15:21:26 +0200 Subject: [PATCH 5/8] Restored equality by reference in watched properties --- angularjs-autogrow.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/angularjs-autogrow.js b/angularjs-autogrow.js index 425742a..033768f 100644 --- a/angularjs-autogrow.js +++ b/angularjs-autogrow.js @@ -70,8 +70,7 @@ function() { return $element.css(property); }, - styleChangedCallBack, - true + styleChangedCallBack ); }); From c22d70f517cef4ed26bcb6a03c708de5b966114e Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Thu, 6 Jul 2017 11:41:33 +0200 Subject: [PATCH 6/8] Added check on empty attribute value --- angularjs-autogrow.js | 2 +- angularjs-autogrow.min.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/angularjs-autogrow.js b/angularjs-autogrow.js index 033768f..9501c8f 100644 --- a/angularjs-autogrow.js +++ b/angularjs-autogrow.js @@ -63,7 +63,7 @@ $scope.$watch($attrs.ngModel, $scope.autogrowFn); // Extract css properties to spy on - var spyProps = $attrs.autogrow.split(','); + var spyProps = $attrs.autogrow ? $attrs.autogrow.split(',') : []; angular.forEach(spyProps, function(property) { // Set a watcher on each property $scope.$watch( diff --git a/angularjs-autogrow.min.js b/angularjs-autogrow.min.js index e8e0181..f45314b 100755 --- a/angularjs-autogrow.min.js +++ b/angularjs-autogrow.min.js @@ -1 +1 @@ -!function(){"use strict";angular.module("angularjs-autogrow",[]).directive("autogrow",["$window",function(t){return{link:function(o,e,r){function n(t,e){t!==e&&o.autogrowFn()}o.attrs={rows:1,maxLines:999};for(var a in o.attrs)r[a]&&(o.attrs[a]=parseInt(r[a]));o.getOffset=function(){for(var o=t.getComputedStyle(e[0],null),r=["paddingTop","paddingBottom"],n=0,a=0;ao.maxAllowedHeight?(e[0].style.overflowY="scroll",t=o.maxAllowedHeight):(e[0].style.overflowY="hidden",e[0].style.height="auto",t=e[0].scrollHeight-o.offset,r=!0),e[0].style.height=t+"px",r},o.offset=o.getOffset(),o.lineHeight=e[0].scrollHeight/o.attrs.rows-o.offset/o.attrs.rows,o.maxAllowedHeight=o.lineHeight*o.attrs.maxLines-o.offset,o.$watch(r.ngModel,o.autogrowFn);var l=r.autogrow.split(",");angular.forEach(l,function(t){o.$watch(function(){return e.css(t)},n,!0)}),""!=e[0].value&&o.autogrowFn()}}}])}(); +!function(){"use strict";angular.module("angularjs-autogrow",[]).directive("autogrow",["$window",function(t){return{link:function(o,e,r){function n(t,e){t!==e&&o.autogrowFn()}o.attrs={rows:1,maxLines:999};for(var a in o.attrs)r[a]&&(o.attrs[a]=parseInt(r[a]));o.getOffset=function(){for(var o=t.getComputedStyle(e[0],null),r=["paddingTop","paddingBottom"],n=0,a=0;ao.maxAllowedHeight?(e[0].style.overflowY="scroll",t=o.maxAllowedHeight):(e[0].style.overflowY="hidden",e[0].style.height="auto",t=e[0].scrollHeight-o.offset,r=!0),e[0].style.height=t+"px",r},o.offset=o.getOffset(),o.lineHeight=e[0].scrollHeight/o.attrs.rows-o.offset/o.attrs.rows,o.maxAllowedHeight=o.lineHeight*o.attrs.maxLines-o.offset,o.$watch(r.ngModel,o.autogrowFn);var l=r.autogrow?r.autogrow.split(","):[];angular.forEach(l,function(t){o.$watch(function(){return e.css(t)},n)}),""!=e[0].value&&o.autogrowFn()}}}])}(); \ No newline at end of file From 11b00a55325f9f458fb748e72d21db410591e89f Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Thu, 6 Jul 2017 11:46:11 +0200 Subject: [PATCH 7/8] Updated to version 0.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4277f0b..f8e76e5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angularjs-autogrow", - "version": "0.4.0", + "version": "0.4.1", "description": "AngularJS 1.x directive for auto-grow / auto-resize of textarea elements", "main": "angularjs-autogrow.js", "scripts": { From f6f64fb9ed89fbc3eae1ac2fc30abfdebee012fd Mon Sep 17 00:00:00 2001 From: fbenedetto Date: Fri, 7 Jul 2017 15:25:26 +0200 Subject: [PATCH 8/8] Reverted to version 0.4.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index f8e76e5..4277f0b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "angularjs-autogrow", - "version": "0.4.1", + "version": "0.4.0", "description": "AngularJS 1.x directive for auto-grow / auto-resize of textarea elements", "main": "angularjs-autogrow.js", "scripts": {