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
09922220
Commit
09922220
authored
Apr 12, 2017
by
Sean Hammond
Committed by
GitHub
Apr 12, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #351 from hypothesis/simplify-quote-display
Simplify handling of quotes in annotations
parents
fa7c1a7f
ac16b2a4
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
25 deletions
+34
-25
annotation.js
src/sidebar/components/annotation.js
+12
-10
annotation-test.js
src/sidebar/components/test/annotation-test.js
+18
-8
annotation.html
src/sidebar/templates/annotation.html
+2
-6
annotation-fixtures.js
src/sidebar/test/annotation-fixtures.js
+2
-1
No files found.
src/sidebar/components/annotation.js
View file @
09922220
...
...
@@ -283,14 +283,20 @@ function AnnotationController(
};
/**
*
@returns {boolean} True if this annotation has quotes
*
Return the annotation's quote if it has one or `null` otherwise.
*/
vm
.
hasQuotes
=
function
()
{
return
vm
.
annotation
.
target
.
some
(
function
(
target
)
{
return
target
.
selector
&&
target
.
selector
.
some
(
function
(
selector
)
{
return
selector
.
type
===
'TextQuoteSelector'
;
});
vm
.
quote
=
function
()
{
if
(
vm
.
annotation
.
target
.
length
===
0
)
{
return
null
;
}
var
target
=
vm
.
annotation
.
target
[
0
];
if
(
!
target
.
selector
)
{
return
null
;
}
var
quoteSel
=
target
.
selector
.
find
(
function
(
sel
)
{
return
sel
.
type
===
'TextQuoteSelector'
;
});
return
quoteSel
?
quoteSel
.
exact
:
null
;
};
vm
.
id
=
function
()
{
...
...
@@ -437,10 +443,6 @@ function AnnotationController(
return
serviceUrl
(
'search.tag'
,
{
tag
:
tag
});
};
vm
.
target
=
function
()
{
return
vm
.
annotation
.
target
;
};
// Note: We fetch the feature flag outside the `isOrphan` method to avoid a
// lookup on every $digest cycle
var
indicateOrphans
=
features
.
flagEnabled
(
'orphans_tab'
);
...
...
src/sidebar/components/test/annotation-test.js
View file @
09922220
...
...
@@ -598,29 +598,40 @@ describe('annotation', function() {
});
});
describe
(
'#
hasQuotes
'
,
function
()
{
it
(
'returns
false
if the annotation has no quotes'
,
function
()
{
describe
(
'#
quote
'
,
function
()
{
it
(
'returns
`null`
if the annotation has no quotes'
,
function
()
{
var
annotation
=
fixtures
.
defaultAnnotation
();
annotation
.
target
=
[{}];
var
controller
=
createDirective
(
annotation
).
controller
;
assert
.
is
False
(
controller
.
hasQuotes
());
assert
.
is
Null
(
controller
.
quote
());
});
it
(
'returns true if the annotation has quotes'
,
function
()
{
it
(
'returns `null` if the annotation has selectors but no quote selector'
,
function
()
{
var
annotation
=
fixtures
.
defaultAnnotation
();
annotation
.
target
=
[{
selector
:
[],
}];
var
controller
=
createDirective
(
annotation
).
controller
;
assert
.
isNull
(
controller
.
quote
());
});
it
(
"returns the first quote's text if the annotation has quotes"
,
function
()
{
var
annotation
=
fixtures
.
defaultAnnotation
();
annotation
.
target
=
[
{
selector
:
[
{
type
:
'TextQuoteSelector'
,
exact
:
'The text that the user selected'
,
},
],
},
];
var
controller
=
createDirective
(
annotation
).
controller
;
assert
.
isTrue
(
controller
.
hasQuotes
()
);
assert
.
equal
(
controller
.
quote
(),
'The text that the user selected'
);
});
});
...
...
@@ -943,10 +954,9 @@ describe('annotation', function() {
.
withArgs
(
'search.tag'
,
{
tag
:
'atag'
})
.
returns
(
'https://test.hypothes.is/stream?q=tag:atag'
);
var
directive
=
createDirective
({
id
:
'1234'
,
var
directive
=
createDirective
(
Object
.
assign
(
fixtures
.
defaultAnnotation
(),
{
tags
:
[
'atag'
],
});
})
)
;
var
links
=
[].
slice
.
apply
(
directive
.
element
[
0
].
querySelectorAll
(
'a'
));
var
tagLinks
=
links
.
filter
(
function
(
link
)
{
return
link
.
textContent
===
'atag'
;
...
...
src/sidebar/templates/annotation.html
View file @
09922220
...
...
@@ -16,18 +16,14 @@
<!-- Excerpts -->
<section
class=
"annotation-quote-list"
ng-class=
"{'is-orphan' : vm.isOrphan()}"
ng-repeat=
"target in vm.target() track by $index"
ng-if=
"vm.hasQuotes()"
>
ng-if=
"vm.quote()"
>
<excerpt
collapsed-height=
"35"
inline-controls=
"true"
overflow-hysteresis=
"20"
content-data=
"selector.exact"
>
<blockquote
class=
"annotation-quote"
h-branding=
"selectionFontFamily"
ng-bind=
"selector.exact"
ng-repeat=
"selector in target.selector
| filter : {'type': 'TextQuoteSelector'}
track by $index"
></blockquote>
ng-bind=
"vm.quote()"
></blockquote>
</excerpt>
</section>
...
...
src/sidebar/test/annotation-fixtures.js
View file @
09922220
...
...
@@ -89,6 +89,7 @@ function newHighlight() {
return
{
id
:
undefined
,
$highlight
:
true
,
target
:
[{
source
:
'http://example.org'
}],
};
}
...
...
@@ -126,7 +127,7 @@ function oldHighlight() {
function
oldPageNote
()
{
return
{
highlight
:
undefined
,
target
:
[],
target
:
[
{
source
:
'http://example.org'
}
],
references
:
[],
text
:
''
,
tags
:
[],
...
...
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