-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduces auto-truncation of long bodies and quotes which expand when you click on a "More" link. Feature flagged as 'truncate_annotations'.
- Loading branch information
1 parent
81ca666
commit f4414f7
Showing
10 changed files
with
152 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
'use strict'; | ||
|
||
/** | ||
* @ngdoc directive | ||
* @name excerpt | ||
* @restrict E | ||
* @description This directive truncates its contents to a height specified in | ||
* CSS, and provides controls for expanding and collapsing the | ||
* resulting truncated element. For example, with the following | ||
* template HTML: | ||
* | ||
* <article class="post"> | ||
* <excerpt> | ||
* <div class="body" ng-model="post.body"></div> | ||
* </excerpt> | ||
* </article> | ||
* | ||
* You would need to define the allowable height of the excerpt in | ||
* CSS: | ||
* | ||
* article.post .excerpt { | ||
* max-height: 10em; | ||
* } | ||
* | ||
* And the excerpt directive will take care of the rest. | ||
* | ||
* You can selectively disable truncation by providing a boolean | ||
* expression to the `enabled` parameter, e.g.: | ||
* | ||
* <excerpt enabled="!post.inFull">...</excerpt> | ||
*/ | ||
module.exports = function () { | ||
return { | ||
link: function (scope, elem, attr, ctrl) { | ||
scope.collapsed = true; | ||
|
||
if (typeof scope.enabled === 'undefined') { | ||
scope.enabled = function () { return true; }; | ||
} | ||
|
||
scope.isOverflowing = function () { | ||
var excerpt = elem[0].querySelector('.excerpt'); | ||
if (!excerpt) { | ||
return false; | ||
} | ||
return (excerpt.scrollHeight > excerpt.clientHeight); | ||
}; | ||
|
||
scope.toggle = function () { | ||
scope.collapsed = !scope.collapsed; | ||
}; | ||
}, | ||
scope: { | ||
enabled: '&?', | ||
}, | ||
restrict: 'E', | ||
transclude: true, | ||
templateUrl: 'excerpt.html', | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
@import "compass/css3/images"; | ||
@import "variables"; | ||
|
||
.excerpt { | ||
position: relative; | ||
overflow: hidden; | ||
} | ||
|
||
.excerpt--collapsed:after { | ||
position: absolute; | ||
bottom: 0; | ||
height: $base-line-height * 3; // This controls the apparent height of the gradient. | ||
width: 100%; | ||
content: ""; | ||
pointer-events: none; | ||
@include background(linear-gradient(to bottom, | ||
rgba(255,255,255,0) 20%, | ||
rgba(255,255,255,1) 100% | ||
)); | ||
} | ||
|
||
.excerpt--uncollapsed { | ||
max-height: 100% !important; | ||
} | ||
|
||
.excerpt-control a { | ||
display: block; | ||
text-align: right; | ||
font-weight: bold; | ||
width: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<div ng-transclude ng-if="!enabled()"></div> | ||
<div ng-if="enabled()"> | ||
<div class="excerpt" | ||
ng-class="{'excerpt--uncollapsed': !collapsed, | ||
'excerpt--collapsed': isOverflowing() && collapsed}" | ||
ng-transclude></div> | ||
|
||
<div class="excerpt-control"> | ||
<a ng-if="isOverflowing() && collapsed" | ||
ng-click="toggle()" | ||
class="more" | ||
href="">More</a> | ||
<a ng-if="!collapsed" | ||
class="less" | ||
ng-click="toggle()" | ||
href="">Less</a> | ||
</div> | ||
</div> |