forked from BhattaRj/angular-show-more
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
74 lines (58 loc) · 3.8 KB
/
app.js
File metadata and controls
74 lines (58 loc) · 3.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
angular.module('app', []);
angular.module('app').controller('mainCtrl', ['$scope', function($scope) {
$scope.books = [{
name: 'PHP 7 For Beginner',
descripton: 'try. Lorem Ipsum has been the industry standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem ',
}, {
name: 'Fundamentals of angularjs',
descripton: 'try. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem '
}, {
name: 'Universal Hacking',
descripton: 'try. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem '
}, {
name: 'PageMaker',
descripton: 'try. Lorem Ipsum has been the industrys standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem '
}];
}])
/**
* Show more and show less in long text within ng-repeat.
* eg. <show-more text="job.description"> </show-more>
*/
angular.module('app').directive('showMore', [function() {
return {
restrict: 'AE',
replace: true,
scope: {
text: '=',
limit:'='
},
template: '<div><p ng-show="largeText"> {{ text | subString :0 :end }}.... <a href="javascript:;" ng-click="showMore()" ng-show="isShowMore">Show More</a><a href="javascript:;" ng-click="showLess()" ng-hide="isShowMore">Show Less </a></p><p ng-hide="largeText">{{ text }}</p></div> ',
link: function(scope, iElement, iAttrs) {
scope.end = scope.limit;
scope.isShowMore = true;
scope.largeText = true;
if (scope.text.length <= scope.limit) {
scope.largeText = false;
};
scope.showMore = function() {
scope.end = scope.text.length;
scope.isShowMore = false;
};
scope.showLess = function() {
scope.end = scope.limit;
scope.isShowMore = true;
};
}
};
}]);
/**
* Retrun the string from specified range.
* e.g<p><% course.description | subString : 0 :75 %> </p>
*/
angular.module('app').filter('subString', function() {
return function(str, start, end) {
if (str != undefined) {
return str.substr(start, end);
}
}
})