Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
07bc28fd
Commit
07bc28fd
authored
Jan 13, 2016
by
Nick Stenning
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2859 from hypothesis/excerpt-hysteresis
Implement a hysteresis threshold in excerpts
parents
ce51f53e
ba672e41
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
12 deletions
+46
-12
excerpt.js
h/static/scripts/directive/excerpt.js
+22
-11
excerpt-test.js
h/static/scripts/directive/test/excerpt-test.js
+22
-0
annotation.html
h/templates/client/annotation.html
+2
-1
No files found.
h/static/scripts/directive/excerpt.js
View file @
07bc28fd
...
...
@@ -65,16 +65,16 @@ function excerpt() {
return
{};
}
var
maxHeight
;
if
(
ctrl
.
collapse
)
{
maxHeight
=
toPx
(
ctrl
.
collapsedHeight
);
}
else
if
(
ctrl
.
animate
)
{
// animating the height change requires that the final
// height be specified exactly, rather than relying on
// auto height
maxHeight
=
toPx
(
contentElem
.
scrollHeight
);
}
else
{
maxHeight
=
''
;
var
maxHeight
=
''
;
if
(
ctrl
.
overflowing
()
)
{
if
(
ctrl
.
collapse
)
{
maxHeight
=
toPx
(
ctrl
.
collapsedHeight
);
}
else
if
(
ctrl
.
animate
)
{
// animating the height change requires that the final
// height be specified exactly, rather than relying on
// auto height
maxHeight
=
toPx
(
contentElem
.
scrollHeight
);
}
}
return
{
...
...
@@ -86,7 +86,10 @@ function excerpt() {
if
(
!
contentElem
)
{
return
false
;
}
return
contentElem
.
scrollHeight
>
ctrl
.
collapsedHeight
;
var
hysteresisPx
=
ctrl
.
overflowHysteresis
|
0
;
return
contentElem
.
scrollHeight
>
(
ctrl
.
collapsedHeight
+
hysteresisPx
);
};
scope
.
$watch
(
'vm.enabled()'
,
function
(
isEnabled
)
{
...
...
@@ -131,6 +134,14 @@ function excerpt() {
/** The height of this container in pixels when collapsed.
*/
collapsedHeight
:
'='
,
/**
* The number of pixels by which the height of the excerpt's content
* must extend beyond the collapsed height in order for truncation to
* be activated. This prevents the 'More' link from being shown to expand
* the excerpt if it has only been truncated by a very small amount, such
* that expanding the excerpt would reveal no extra lines of text.
*/
overflowHysteresis
:
'=?'
,
},
restrict
:
'E'
,
transclude
:
true
,
...
...
h/static/scripts/directive/test/excerpt-test.js
View file @
07bc28fd
...
...
@@ -145,4 +145,26 @@ describe('excerpt directive', function () {
assert
.
calledWith
(
callback
,
false
);
});
});
describe
(
'overflowHysteresis'
,
function
()
{
it
(
'does not collapse if overflow is less than hysteresis'
,
function
()
{
var
slightlyOverflowingDiv
=
'<div class="foo" style="height:45px;"></div>'
;
var
element
=
excerptDirective
({
collapsedHeight
:
40
,
overflowHysteresis
:
10
,
},
slightlyOverflowingDiv
);
element
.
scope
.
$digest
();
assert
.
isAbove
(
height
(
element
[
0
]),
44
);
});
it
(
'does collapse if overflow exceeds hysteresis'
,
function
()
{
var
overflowingDiv
=
'<div style="height:60px;"></div>'
;
var
element
=
excerptDirective
({
collapsedHeight
:
40
,
overflowHysteresis
:
10
,
},
overflowingDiv
);
element
.
scope
.
$digest
();
assert
.
isBelow
(
height
(
element
[
0
]),
50
);
});
});
});
h/templates/client/annotation.html
View file @
07bc28fd
...
...
@@ -76,7 +76,8 @@
inline-controls=
"false"
on-collapsible-changed=
"vm.setBodyCollapsible(collapsible)"
collapse=
"vm.collapseBody"
collapsed-height=
"200"
>
collapsed-height=
"200"
overflow-hysteresis=
"20"
>
<markdown
ng-model=
"vm.form.text"
read-only=
"!vm.editing()"
embeds-enabled=
"vm.feature('embed_media')"
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment