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
9cd78ecd
Commit
9cd78ecd
authored
Nov 04, 2014
by
Aron Carroll
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1622 from hypothesis/simplify-highlights
Simplify highlight visibility toggling.
parents
5812f5c5
004f82a9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
49 deletions
+51
-49
guest.coffee
h/static/scripts/guest.coffee
+21
-18
toolbar.coffee
h/static/scripts/plugin/toolbar.coffee
+30
-31
No files found.
h/static/scripts/guest.coffee
View file @
9cd78ecd
...
...
@@ -3,13 +3,15 @@ $ = Annotator.$
class
Annotator
.
Guest
extends
Annotator
SHOW_HIGHLIGHTS_CLASS
=
'annotator-highlights-always-on'
# Events to be bound on Annotator#element.
events
:
".annotator-adder button click"
:
"onAdderClick"
".annotator-adder button mousedown"
:
"onAdderMousedown"
".annotator-adder button mouseup"
:
"onAdderMouseup"
"setTool"
:
"onSetTool"
"setVisibleHighlights"
:
"
onS
etVisibleHighlights"
"setVisibleHighlights"
:
"
s
etVisibleHighlights"
# Plugin configuration
options
:
...
...
@@ -188,7 +190,6 @@ class Annotator.Guest extends Annotator
)
.
bind
(
'setVisibleHighlights'
,
(
ctx
,
state
)
=>
this
.
setVisibleHighlights
state
,
false
this
.
publish
'setVisibleHighlights'
,
state
)
...
...
@@ -315,17 +316,23 @@ class Annotator.Guest extends Annotator
method
:
'setTool'
params
:
name
setVisibleHighlights
:
(
state
=
true
,
notify
=
true
)
->
if
notify
@
panel
?
.
notify
method
:
'setVisibleHighlights'
params
:
state
# Pass true to show the highlights in the frame or false to disable.
setVisibleHighlights
:
(
shouldShowHighlights
)
->
return
if
@
visibleHighlights
==
shouldShowHighlights
@
panel
?
.
notify
method
:
'setVisibleHighlights'
params
:
shouldShowHighlights
this
.
toggleHighlightClass
(
shouldShowHighlights
or
@
tool
==
'highlight'
)
toggleHighlightClass
:
(
shouldShowHighlights
)
->
if
shouldShowHighlights
@
element
.
addClass
(
SHOW_HIGHLIGHTS_CLASS
)
else
markerClass
=
'annotator-highlights-always-on'
if
state
or
this
.
tool
is
'highlight'
@
element
.
addClass
markerClass
else
@
element
.
removeClass
markerClass
@
element
.
removeClass
(
SHOW_HIGHLIGHTS_CLASS
)
@
visibleHighlights
=
shouldShowHighlights
addComment
:
->
this
.
showEditor
(
this
.
createAnnotation
())
...
...
@@ -360,10 +367,6 @@ class Annotator.Guest extends Annotator
onSetTool
:
(
name
)
->
switch
name
when
'comment'
this
.
setVisibleHighlights
this
.
visibleHighlights
,
false
this
.
setVisibleHighlights
this
.
visibleHighlights
when
'highlight'
this
.
setVisibleHighlights
true
,
false
onSetVisibleHighlights
:
(
state
)
=>
this
.
visibleHighlights
=
state
this
.
setVisibleHighlights
state
,
false
this
.
setVisibleHighlights
true
h/static/scripts/plugin/toolbar.coffee
View file @
9cd78ecd
$
=
Annotator
.
$
makeButton
=
(
item
)
->
anchor
=
$
(
'<a></a>'
)
.
attr
(
'href'
,
''
)
.
attr
(
'title'
,
item
.
title
)
.
on
(
item
.
on
)
.
addClass
(
item
.
class
)
button
=
$
(
'<li></li>'
).
append
(
anchor
)
return
button
[
0
]
class
Annotator
.
Plugin
.
Toolbar
extends
Annotator
.
Plugin
PUSHED_CLASS
=
'annotator-pushed'
...
...
@@ -11,19 +20,25 @@ class Annotator.Plugin.Toolbar extends Annotator.Plugin
html
:
'<div class="annotator-toolbar annotator-hide"></div>'
options
:
items
:
[
pluginInit
:
->
@
annotator
.
toolbar
=
@
toolbar
=
$
(
@
html
)
if
@
options
.
container
?
$
(
@
options
.
container
).
append
@
toolbar
else
$
(
@
element
).
append
@
toolbar
items
=
[
"title"
:
"Toggle Sidebar"
"class"
:
"annotator-toolbar-toggle h-icon-comment"
"on"
:
"click"
:
(
event
)
-
>
"click"
:
(
event
)
=
>
event
.
preventDefault
()
event
.
stopPropagation
()
collapsed
=
window
.
annotator
.
frame
.
hasClass
(
'annotator-collapsed'
)
collapsed
=
@
annotator
.
frame
.
hasClass
(
'annotator-collapsed'
)
if
collapsed
window
.
annotator
.
showFrame
()
@
annotator
.
showFrame
()
else
window
.
annotator
.
hideFrame
()
@
annotator
.
hideFrame
()
# Remove focus from the anchor when clicked, this removes the focus
# styles intended only for keyboard navigation. IE/FF apply the focus
# psuedo-class to a clicked element.
...
...
@@ -32,47 +47,31 @@ class Annotator.Plugin.Toolbar extends Annotator.Plugin
"title"
:
"Show Annotations"
"class"
:
"h-icon-visible"
"on"
:
"click"
:
(
event
)
-
>
"click"
:
(
event
)
=
>
event
.
preventDefault
()
event
.
stopPropagation
()
state
=
not
window
.
annotator
.
visibleHighlights
window
.
annotator
.
setVisibleHighlights
state
state
=
not
@
annotator
.
visibleHighlights
@
annotator
.
setVisibleHighlights
state
,
"title"
:
"Highlighting Mode"
"class"
:
"h-icon-highlighter"
"on"
:
"click"
:
(
event
)
-
>
"click"
:
(
event
)
=
>
event
.
preventDefault
()
event
.
stopPropagation
()
state
=
not
(
window
.
annotator
.
tool
is
'highlight'
)
state
=
not
(
@
annotator
.
tool
is
'highlight'
)
tool
=
if
state
then
'highlight'
else
'comment'
window
.
annotator
.
setTool
tool
@
annotator
.
setTool
tool
,
"title"
:
"New Comment"
"class"
:
"h-icon-plus"
"on"
:
"click"
:
(
event
)
-
>
"click"
:
(
event
)
=
>
event
.
preventDefault
()
event
.
stopPropagation
()
window
.
annotator
.
addComment
()
@
annotator
.
addComment
()
]
pluginInit
:
->
@
annotator
.
toolbar
=
@
toolbar
=
$
(
@
html
)
if
@
options
.
container
?
$
(
@
options
.
container
).
append
@
toolbar
else
$
(
@
element
).
append
@
toolbar
@
buttons
=
@
options
.
items
.
reduce
(
buttons
,
item
)
=>
anchor
=
$
(
'<a></a>'
)
.
attr
(
'href'
,
''
)
.
attr
(
'title'
,
item
.
title
)
.
on
(
item
.
on
)
.
addClass
(
item
.
class
)
button
=
$
(
'<li></li>'
).
append
(
anchor
)
buttons
.
add
button
,
$
()
@
buttons
=
$
(
makeButton
(
item
)
for
item
in
items
)
list
=
$
(
'<ul></ul>'
)
@
buttons
.
appendTo
(
list
)
...
...
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