From 3bd8fcd3c0a8dd70927281f3bec142a265033cc1 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 14 Sep 2015 12:11:01 +0100 Subject: [PATCH 1/3] Avoid unnecessary calls to dotdotdot plugin, include example in README --- README.md | 12 ++++++++++++ js/angular-dotdotdot.js | 28 ++++++++++++++++++---------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index f219249..ea061b8 100644 --- a/README.md +++ b/README.md @@ -2,3 +2,15 @@ angular-dotdotot ================ Angular directive for applying the dotdotdot jquery plugin- http://dotdotdot.frebsite.nl/ + +Usage: +------ +Include the directive in your app (see js/angular-dotdotdot.js). + +Then in your controller: + + $scope.myText = 'some really long text'; + +Template: + +

{{myText}}

diff --git a/js/angular-dotdotdot.js b/js/angular-dotdotdot.js index 821cd9f..e6d24b5 100644 --- a/js/angular-dotdotdot.js +++ b/js/angular-dotdotdot.js @@ -1,11 +1,19 @@ angular.module('dotdotdot-angular', []) - .directive('dotdotdot', function(){ - return { - restrict: 'A', - link: function(scope, element, attributes) { - scope.$watch(function() { - element.dotdotdot({watch: true}); - }); - } - } - }); + .directive('dotdotdot', ['$timeout', function($timeout){ + return { + restrict: 'A', + link: function(scope, element, attributes) { + + // We must pass in the scope binding, e.g. dotdotdot='myText' for scope.myText + scope.$watch(attributes.dotdotdot, function() { + + // Wait for DOM to render + $timeout(function() { + + // Don't use { watch: true } as it polls continuously + element.dotdotdot(); + }, 400); + }); + } + } +}]); From 76117d882e36d71fe8dcb46d5012600c6db54749 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 14 Sep 2015 12:18:52 +0100 Subject: [PATCH 2/3] Convert spaces to tabs for consistency --- js/angular-dotdotdot.js | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/js/angular-dotdotdot.js b/js/angular-dotdotdot.js index e6d24b5..4b5486c 100644 --- a/js/angular-dotdotdot.js +++ b/js/angular-dotdotdot.js @@ -1,19 +1,16 @@ angular.module('dotdotdot-angular', []) - .directive('dotdotdot', ['$timeout', function($timeout){ - return { - restrict: 'A', - link: function(scope, element, attributes) { + .directive('dotdotdot', ['$timeout', function($timeout) { + return { + restrict: 'A', + link: function(scope, element, attributes) { - // We must pass in the scope binding, e.g. dotdotdot='myText' for scope.myText - scope.$watch(attributes.dotdotdot, function() { + // We must pass in the scope binding, e.g. dotdotdot='myText' for scope.myText + scope.$watch(attributes.dotdotdot, function() { - // Wait for DOM to render - $timeout(function() { - - // Don't use { watch: true } as it polls continuously - element.dotdotdot(); - }, 400); - }); - } - } + // Wait for DOM to render + // NB. Don't use { watch: true } option in dotdotdot as it needlessly polls + $timeout(element.dotdotdot, 400); + }); + } + } }]); From 447768236f1e94f4556ecfe432873a53bc8cc3d6 Mon Sep 17 00:00:00 2001 From: Duncan Smith Date: Mon, 14 Sep 2015 14:13:33 +0100 Subject: [PATCH 3/3] Fix $timeout callback context --- js/angular-dotdotdot.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/js/angular-dotdotdot.js b/js/angular-dotdotdot.js index 4b5486c..e896111 100644 --- a/js/angular-dotdotdot.js +++ b/js/angular-dotdotdot.js @@ -9,7 +9,9 @@ angular.module('dotdotdot-angular', []) // Wait for DOM to render // NB. Don't use { watch: true } option in dotdotdot as it needlessly polls - $timeout(element.dotdotdot, 400); + $timeout(function() { + element.dotdotdot(); + }, 400); }); } }