diff --git a/bower.json b/bower.json index 2d0f01e..50f0c24 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "Read-More-Directive", - "version": "v0.0.3", + "version": "v0.0.4", "homepage": "https://github.com/andoulla/Read-More-Directive", "authors": [ "m.a.s.dev@outlook.com" diff --git a/js/directives/readmore.js b/js/directives/readmore.js index fd60a5b..1783b7b 100644 --- a/js/directives/readmore.js +++ b/js/directives/readmore.js @@ -17,31 +17,36 @@ var readMoreTemplate = " {{::showMoreText}}" + ""; -readMore.directive('readMore', ['$compile','$interpolate',function($compile, $interpolate) { +readMore.directive('readMore', ['$compile','$interpolate','$timeout',function($compile, $interpolate, $timeout) { return { restrict: 'A', scope: {}, + controller: function($element, $scope){ + }, compile : function(element, attrs){ + return { post: function(scope, element, attrs){ - scope.text = element.html().trim(); - scope.showLessText = attrs.showLessText || 'Show Less'; - scope.showMoreText = attrs.showMoreText || 'Show More'; - scope.textLength = attrs.length; - scope.isExpanded = false; // initialise extended status - scope.countingWords = attrs.words !== undefined ? (attrs.words === 'true') : true; //if this attr is not defined the we are counting words not characters - if (!scope.countingWords && scope.text.length > attrs.length) { - scope.showLinks = true; - } else if (scope.countingWords && scope.text.split(/\s+/).length > attrs.length) { - scope.showLinks = true; - } else { - scope.showLinks = false; - } - scope.changeLength = function (card) { - scope.isExpanded = !scope.isExpanded; - scope.textLength = scope.textLength !== attrs.length ? attrs.length : scope.text.length; - }; - element.html($compile(readMoreTemplate)(scope)); + $timeout(function(){ + scope.text = element.html().trim(); + scope.showLessText = attrs.showLessText || 'Show Less'; + scope.showMoreText = attrs.showMoreText || 'Show More'; + scope.textLength = attrs.length; + scope.isExpanded = false; // initialise extended status + scope.countingWords = attrs.words !== undefined ? (attrs.words === 'true') : true; //if this attr is not defined the we are counting words not characters + if (!scope.countingWords && scope.text.length > attrs.length) { + scope.showLinks = true; + } else if (scope.countingWords && scope.text.split(/\s+/).length > attrs.length) { + scope.showLinks = true; + } else { + scope.showLinks = false; + } + scope.changeLength = function (card) { + scope.isExpanded = !scope.isExpanded; + scope.textLength = scope.textLength !== attrs.length ? attrs.length : scope.text.length; + }; + element.html($compile(readMoreTemplate)(scope)); + }); } } }