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
00e28ae1
Commit
00e28ae1
authored
Jun 26, 2017
by
Sean Roberts
Committed by
GitHub
Jun 26, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #439 from evidentpoint/crossframe-sidebar-hide-show
Use CrossFrame to show/hide the Sidebar
parents
2f01e455
ee9b09a8
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
77 additions
and
41 deletions
+77
-41
guest.coffee
src/annotator/guest.coffee
+17
-0
sidebar.coffee
src/annotator/sidebar.coffee
+4
-28
guest-test.coffee
src/annotator/test/guest-test.coffee
+19
-0
sidebar-test.coffee
src/annotator/test/sidebar-test.coffee
+14
-13
frame-sync.js
src/sidebar/frame-sync.js
+9
-0
frame-sync-test.js
src/sidebar/test/frame-sync-test.js
+14
-0
No files found.
src/annotator/guest.coffee
View file @
00e28ae1
...
@@ -39,6 +39,8 @@ module.exports = class Guest extends Delegator
...
@@ -39,6 +39,8 @@ module.exports = class Guest extends Delegator
".annotator-hl click"
:
"onHighlightClick"
".annotator-hl click"
:
"onHighlightClick"
".annotator-hl mouseover"
:
"onHighlightMouseover"
".annotator-hl mouseover"
:
"onHighlightMouseover"
".annotator-hl mouseout"
:
"onHighlightMouseout"
".annotator-hl mouseout"
:
"onHighlightMouseout"
"click"
:
"onElementClick"
"touchstart"
:
"onElementTouchStart"
options
:
options
:
Document
:
{}
Document
:
{}
...
@@ -336,6 +338,7 @@ module.exports = class Guest extends Delegator
...
@@ -336,6 +338,7 @@ module.exports = class Guest extends Delegator
targets
.
then
(
->
self
.
publish
(
'beforeAnnotationCreated'
,
[
annotation
]))
targets
.
then
(
->
self
.
publish
(
'beforeAnnotationCreated'
,
[
annotation
]))
targets
.
then
(
->
self
.
anchor
(
annotation
))
targets
.
then
(
->
self
.
anchor
(
annotation
))
@
crossframe
?
.
call
(
'showSidebar'
)
unless
annotation
.
$highlight
annotation
annotation
createHighlight
:
->
createHighlight
:
->
...
@@ -374,6 +377,7 @@ module.exports = class Guest extends Delegator
...
@@ -374,6 +377,7 @@ module.exports = class Guest extends Delegator
showAnnotations
:
(
annotations
)
->
showAnnotations
:
(
annotations
)
->
tags
=
(
a
.
$tag
for
a
in
annotations
)
tags
=
(
a
.
$tag
for
a
in
annotations
)
@
crossframe
?
.
call
(
'showAnnotations'
,
tags
)
@
crossframe
?
.
call
(
'showAnnotations'
,
tags
)
@
crossframe
?
.
call
(
'showSidebar'
)
toggleAnnotationSelection
:
(
annotations
)
->
toggleAnnotationSelection
:
(
annotations
)
->
tags
=
(
a
.
$tag
for
a
in
annotations
)
tags
=
(
a
.
$tag
for
a
in
annotations
)
...
@@ -421,6 +425,19 @@ module.exports = class Guest extends Delegator
...
@@ -421,6 +425,19 @@ module.exports = class Guest extends Delegator
else
else
this
.
showAnnotations
annotations
this
.
showAnnotations
annotations
onElementClick
:
(
event
)
->
if
!
@
selectedTargets
?
.
length
@
crossframe
?
.
call
(
'hideSidebar'
)
onElementTouchStart
:
(
event
)
->
# Mobile browsers do not register click events on
# elements without cursor: pointer. So instead of
# adding that to every element, we can add the initial
# touchstart event which is always registered to
# make up for the lack of click support for all elements.
if
!
@
selectedTargets
?
.
length
@
crossframe
?
.
call
(
'hideSidebar'
)
onHighlightMouseover
:
(
event
)
->
onHighlightMouseover
:
(
event
)
->
return
unless
@
visibleHighlights
return
unless
@
visibleHighlights
annotation
=
$
(
event
.
currentTarget
).
data
(
'annotation'
)
annotation
=
$
(
event
.
currentTarget
).
data
(
'annotation'
)
...
...
src/annotator/sidebar.coffee
View file @
00e28ae1
...
@@ -47,30 +47,14 @@ module.exports = class Sidebar extends Host
...
@@ -47,30 +47,14 @@ module.exports = class Sidebar extends Host
@
onHelpRequest
=
serviceConfig
.
onHelpRequest
@
onHelpRequest
=
serviceConfig
.
onHelpRequest
this
.
_setupSidebarEvents
()
this
.
_setupSidebarEvents
()
this
.
_setupDocumentEvents
()
_setupDocumentEvents
:
->
sidebarTrigger
(
document
.
body
,
=>
this
.
show
())
@
element
.
on
'click'
,
(
event
)
=>
if
!
@
selectedTargets
?
.
length
this
.
hide
()
# Mobile browsers do not register click events on
# elements without cursor: pointer. So instead of
# adding that to every element, we can add the initial
# touchstart event which is always registered to
# make up for the lack of click support for all elements.
@
element
.
on
'touchstart'
,
(
event
)
=>
if
!
@
selectedTargets
?
.
length
this
.
hide
()
return
this
_setupSidebarEvents
:
->
_setupSidebarEvents
:
->
annotationCounts
(
document
.
body
,
@
crossframe
)
annotationCounts
(
document
.
body
,
@
crossframe
)
features
.
init
(
@
crossframe
);
sidebarTrigger
(
document
.
body
,
=>
this
.
show
())
features
.
init
(
@
crossframe
)
@
crossframe
.
on
(
'showSidebar'
,
=>
this
.
show
())
@
crossframe
.
on
(
'hideSidebar'
,
=>
this
.
hide
())
@
crossframe
.
on
(
events
.
LOGIN_REQUESTED
,
=>
@
crossframe
.
on
(
events
.
LOGIN_REQUESTED
,
=>
if
@
onLoginRequest
if
@
onLoginRequest
@
onLoginRequest
()
@
onLoginRequest
()
...
@@ -206,11 +190,3 @@ module.exports = class Sidebar extends Host
...
@@ -206,11 +190,3 @@ module.exports = class Sidebar extends Host
isOpen
:
->
isOpen
:
->
!
@
frame
.
hasClass
(
'annotator-collapsed'
)
!
@
frame
.
hasClass
(
'annotator-collapsed'
)
createAnnotation
:
(
annotation
=
{})
->
super
this
.
show
()
unless
annotation
.
$highlight
showAnnotations
:
(
annotations
)
->
super
this
.
show
()
src/annotator/test/guest-test.coffee
View file @
00e28ae1
...
@@ -86,6 +86,7 @@ describe 'Guest', ->
...
@@ -86,6 +86,7 @@ describe 'Guest', ->
fakeCrossFrame
=
{
fakeCrossFrame
=
{
onConnect
:
sinon
.
stub
()
onConnect
:
sinon
.
stub
()
on
:
sinon
.
stub
()
on
:
sinon
.
stub
()
call
:
sinon
.
stub
()
sync
:
sinon
.
stub
()
sync
:
sinon
.
stub
()
destroy
:
sinon
.
stub
()
destroy
:
sinon
.
stub
()
}
}
...
@@ -280,6 +281,24 @@ describe 'Guest', ->
...
@@ -280,6 +281,24 @@ describe 'Guest', ->
emitGuestEvent
(
'getDocumentInfo'
,
assertComplete
)
emitGuestEvent
(
'getDocumentInfo'
,
assertComplete
)
describe
'document events'
,
->
guest
=
null
beforeEach
->
guest
=
createGuest
()
it
'emits "hideSidebar" on cross frame when the user taps or clicks in the page'
,
->
methods
=
'click'
:
'onElementClick'
'touchstart'
:
'onElementTouchStart'
for
event
in
[
'click'
,
'touchstart'
]
sandbox
.
spy
(
guest
,
methods
[
event
])
guest
.
element
.
trigger
(
event
)
assert
.
called
(
guest
[
methods
[
event
]])
assert
.
calledWith
(
guest
.
plugins
.
CrossFrame
.
call
,
'hideSidebar'
)
describe
'when the selection changes'
,
->
describe
'when the selection changes'
,
->
it
'shows the adder if the selection contains text'
,
->
it
'shows the adder if the selection contains text'
,
->
guest
=
createGuest
()
guest
=
createGuest
()
...
...
src/annotator/test/sidebar-test.coffee
View file @
00e28ae1
...
@@ -32,6 +32,20 @@ describe 'Sidebar', ->
...
@@ -32,6 +32,20 @@ describe 'Sidebar', ->
emitEvent
=
(
event
,
args
...)
->
emitEvent
=
(
event
,
args
...)
->
fn
(
args
...)
for
[
evt
,
fn
]
in
fakeCrossFrame
.
on
.
args
when
event
==
evt
fn
(
args
...)
for
[
evt
,
fn
]
in
fakeCrossFrame
.
on
.
args
when
event
==
evt
describe
'on "show" event'
,
->
it
'shows the frame'
,
->
target
=
sandbox
.
stub
(
Sidebar
.
prototype
,
'show'
)
sidebar
=
createSidebar
()
emitEvent
(
'showSidebar'
)
assert
.
called
(
target
)
describe
'on "hide" event'
,
->
it
'hides the frame'
,
->
target
=
sandbox
.
stub
(
Sidebar
.
prototype
,
'hide'
)
sidebar
=
createSidebar
()
emitEvent
(
'hideSidebar'
)
assert
.
called
(
target
)
describe
'on LOGIN_REQUESTED event'
,
->
describe
'on LOGIN_REQUESTED event'
,
->
it
'calls the onLoginRequest callback function if one was provided'
,
->
it
'calls the onLoginRequest callback function if one was provided'
,
->
onLoginRequest
=
sandbox
.
stub
()
onLoginRequest
=
sandbox
.
stub
()
...
@@ -195,19 +209,6 @@ describe 'Sidebar', ->
...
@@ -195,19 +209,6 @@ describe 'Sidebar', ->
sidebar
.
onSwipe
({
type
:
'swiperight'
})
sidebar
.
onSwipe
({
type
:
'swiperight'
})
assert
.
calledOnce
(
hide
)
assert
.
calledOnce
(
hide
)
describe
'document events'
,
->
sidebar
=
null
beforeEach
->
sidebar
=
createSidebar
({})
it
'closes the sidebar when the user taps or clicks in the page'
,
->
for
event
in
[
'click'
,
'touchstart'
]
sidebar
.
show
()
sidebar
.
element
.
trigger
(
event
)
assert
.
isFalse
(
sidebar
.
isOpen
())
describe
'destruction'
,
->
describe
'destruction'
,
->
sidebar
=
null
sidebar
=
null
...
...
src/sidebar/frame-sync.js
View file @
00e28ae1
...
@@ -149,6 +149,15 @@ function FrameSync($rootScope, $window, Discovery, annotationUI, bridge) {
...
@@ -149,6 +149,15 @@ function FrameSync($rootScope, $window, Discovery, annotationUI, bridge) {
bridge
.
on
(
'sidebarOpened'
,
function
()
{
bridge
.
on
(
'sidebarOpened'
,
function
()
{
$rootScope
.
$broadcast
(
'sidebarOpened'
);
$rootScope
.
$broadcast
(
'sidebarOpened'
);
});
});
// These merely relay calls
bridge
.
on
(
'showSidebar'
,
function
()
{
bridge
.
call
(
'showSidebar'
);
});
bridge
.
on
(
'hideSidebar'
,
function
()
{
bridge
.
call
(
'hideSidebar'
);
});
}
}
/**
/**
...
...
src/sidebar/test/frame-sync-test.js
View file @
00e28ae1
...
@@ -249,4 +249,18 @@ describe('FrameSync', function () {
...
@@ -249,4 +249,18 @@ describe('FrameSync', function () {
assert
.
called
(
onSidebarOpened
);
assert
.
called
(
onSidebarOpened
);
});
});
});
});
describe
(
'on a relayed bridge call'
,
function
()
{
it
(
'calls "showSidebar"'
,
function
()
{
fakeBridge
.
emit
(
'showSidebar'
);
assert
.
calledWith
(
fakeBridge
.
call
,
'showSidebar'
);
});
it
(
'calls "hideSidebar"'
,
function
()
{
fakeBridge
.
emit
(
'hideSidebar'
);
assert
.
calledWith
(
fakeBridge
.
call
,
'hideSidebar'
);
});
});
});
});
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