Commit 4c19128c authored by Aron Carroll's avatar Aron Carroll

Update Host to show/hide the sidebar UI

Also removed a couple of unused event handlers.
parent 00e09913
......@@ -31,6 +31,7 @@ class Annotator.Host extends Annotator.Guest
.attr('src', src)
super element, options, dontScan: true
this._addCrossFrameListeners()
app.appendTo(@frame)
......@@ -62,41 +63,14 @@ class Annotator.Host extends Annotator.Guest
@frame.addClass 'annotator-no-transition'
@frame.removeClass 'annotator-collapsed'
_setupXDM: (options) ->
channel = super
channel
.bind 'showFrame', (ctx) => this.showFrame()
.bind('hideFrame', (ctx) =>
hideFrame: ->
@frame.css 'margin-left': ''
@frame.removeClass 'annotator-no-transition'
@frame.addClass 'annotator-collapsed'
)
.bind('dragFrame', (ctx, screenX) => this._dragUpdate screenX)
.bind('getMaxBottom', =>
sel = '*' + (":not(.annotator-#{x})" for x in [
'adder', 'outer', 'notice', 'filter', 'frame'
]).join('')
# use the maximum bottom position in the page
all = for el in $(document.body).find(sel)
p = $(el).css('position')
t = $(el).offset().top
z = $(el).css('z-index')
if (y = /\d+/.exec($(el).css('top'))?[0])
t = Math.min(Number y, t)
if (p == 'absolute' or p == 'fixed') and t == 0 and z != 'auto'
bottom = $(el).outerHeight(false)
# but don't go larger than 80, because this isn't bulletproof
if bottom > 80 then 0 else bottom
else
0
Math.max.apply(Math, all)
)
_addCrossFrameListeners: ->
@crossframe.on('showFrame', this.showFrame.bind(this, null))
@crossframe.on('hideFrame', this.hideFrame.bind(this, null))
_setupDragEvents: ->
el = document.createElementNS 'http://www.w3.org/1999/xhtml', 'canvas'
......
......@@ -3,8 +3,9 @@ sinon.assert.expose(assert, prefix: '')
describe 'Annotator.Host', ->
sandbox = sinon.sandbox.create()
fakeCrossFrame = null
createHost = (options) ->
createHost = (options={}) ->
element = document.createElement('div')
return new Annotator.Host(element, options)
......@@ -12,9 +13,10 @@ describe 'Annotator.Host', ->
# Disable Annotator's ridiculous logging.
sandbox.stub(console, 'log')
fakeCrossFrame =
onConnect: sandbox.stub()
on: sandbox.stub()
fakeCrossFrame = {}
fakeCrossFrame.onConnect = sandbox.stub().returns(fakeCrossFrame)
fakeCrossFrame.on = sandbox.stub().returns(fakeCrossFrame)
fakeCrossFrame.notify = sandbox.stub().returns(fakeCrossFrame)
sandbox.stub(Annotator.Plugin, 'CrossFrame').returns(fakeCrossFrame)
......@@ -34,3 +36,21 @@ describe 'Annotator.Host', ->
assert.isFalse(host.visibleHighlights)
done()
host.publish('panelReady')
describe 'crossframe listeners', ->
emitHostEvent = (event, args...) ->
fn(args...) for [evt, fn] in fakeCrossFrame.on.args when event == evt
describe 'on "showFrame" event', ->
it 'shows the frame', ->
target = sandbox.stub(Annotator.Host.prototype, 'showFrame')
host = createHost()
emitHostEvent('showFrame')
assert.called(target)
describe 'on "hideFrame" event', ->
it 'hides the frame', ->
target = sandbox.stub(Annotator.Host.prototype, 'hideFrame')
host = createHost()
emitHostEvent('hideFrame')
assert.called(target)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment