Skip to content

Commit

Permalink
Fixing interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaibhav Gupta committed Jun 26, 2015
1 parent 465303c commit 2eb15ab
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
43 changes: 24 additions & 19 deletions js/directives/readmore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,31 +17,36 @@ var readMoreTemplate = "<span><span ng-bind-html='text | readMoreFilter:[text, c
"<strong ng-show='!isExpanded'> {{::showMoreText}}</strong>" +
"</a></span>";

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));
});
}
}
}
Expand Down

0 comments on commit 2eb15ab

Please sign in to comment.