Commit 280fad95 authored by Ujvari Gergely's avatar Ujvari Gergely

Issue #26: Added handle (for the toolbar) to resize the tool

parent 31619902
...@@ -65,6 +65,13 @@ class Annotator.Host extends Annotator ...@@ -65,6 +65,13 @@ class Annotator.Host extends Annotator
onEditorSubmit: this.onEditorSubmit onEditorSubmit: this.onEditorSubmit
showFrame: => @frame.removeClass('annotator-collapsed') showFrame: => @frame.removeClass('annotator-collapsed')
hideFrame: => @frame.addClass('annotator-collapsed') hideFrame: => @frame.addClass('annotator-collapsed')
resetFrameWidth: =>
@frame.css({ "width": "", "margin-left" : "" })
setFrameWidth: (width) =>
@frame.css({ "width": width, "margin-left" : (-1)*width })
addtoFrameWidth: (width, innerWidth) =>
if isNaN(parseInt(@frame[0].style.width)) then old = innerWidth else old = parseInt(@frame[0].style.width)
@frame.css({ "width": (old + width), "margin-left" : (-1)*(old + width) })
getHighlights: => getHighlights: =>
highlights: $(@wrapper).find('.annotator-hl').map -> highlights: $(@wrapper).find('.annotator-hl').map ->
offset: $(this).offset() offset: $(this).offset()
...@@ -100,6 +107,8 @@ class Annotator.Host extends Annotator ...@@ -100,6 +107,8 @@ class Annotator.Host extends Annotator
Math.max.apply(Math, all) Math.max.apply(Math, all)
scrollTop: (y) => scrollTop: (y) =>
$('html, body').stop().animate {scrollTop: y}, 600 $('html, body').stop().animate {scrollTop: y}, 600
debounce: (fn, delay) =>
util.debounce(fn, delay)
remote: remote:
publish: {} publish: {}
addPlugin: {} addPlugin: {}
...@@ -149,7 +158,7 @@ class Annotator.Host extends Annotator ...@@ -149,7 +158,7 @@ class Annotator.Host extends Annotator
do update do update
document.addEventListener 'touchstart', => document.addEventListener 'touchstart', =>
touch = true touch = true
do update do update
$(window).on 'resize scroll', update $(window).on 'resize scroll', update
$(document.body).on 'resize scroll', '*', util.debounce => @consumer.update() $(document.body).on 'resize scroll', '*', util.debounce => @consumer.update()
super super
......
...@@ -5,6 +5,8 @@ class Hypothesis extends Annotator ...@@ -5,6 +5,8 @@ class Hypothesis extends Annotator
this::hash = -1 # * cheap UUID :cake: this::hash = -1 # * cheap UUID :cake:
this::cache = {} # * object cache this::cache = {} # * object cache
this::visible = false # * Whether the sidebar is visible this::visible = false # * Whether the sidebar is visible
this::dragstartposX =0# * Frame's draggin start position
this::lastWidth = 0 # * Frame's width before close
# Plugin configuration # Plugin configuration
options: options:
...@@ -61,10 +63,14 @@ class Hypothesis extends Annotator ...@@ -61,10 +63,14 @@ class Hypothesis extends Annotator
onEditorSubmit: {} onEditorSubmit: {}
showFrame: {} showFrame: {}
hideFrame: {} hideFrame: {}
resetFrameWidth: {}
setFrameWidth: {}
addtoFrameWidth: {}
getHighlights: {} getHighlights: {}
setActiveHighlights: {} setActiveHighlights: {}
getMaxBottom: {} getMaxBottom: {}
scrollTop: {} scrollTop: {}
debounce: {}
# Prepare a MarkDown renderer, and add some post-processing # Prepare a MarkDown renderer, and add some post-processing
# so that all created links have their target set to _blank # so that all created links have their target set to _blank
...@@ -123,6 +129,15 @@ class Hypothesis extends Annotator ...@@ -123,6 +129,15 @@ class Hypothesis extends Annotator
if @viewer.isShown() and @bucket == -1 if @viewer.isShown() and @bucket == -1
this._fillDynamicBucket() this._fillDynamicBucket()
this.show() this.show()
document.getElementById('toolbar').addEventListener 'dragstart', (event) =>
@dragstartposX = event.screenX
document.getElementById('toolbar').addEventListener 'drag', (event, ui) =>
@provider.debounce( =>
@provider.addtoFrameWidth(@dragstartposX - event.screenX, window.innerWidth)
@dragstartposX = event.screenX
, 250)
document.getElementById('toolbar').addEventListener 'dragend', (event) =>
@provider.addtoFrameWidth(@dragstartposX - event.screenX, window.innerWidth)
this this
_setupDynamicStyle: -> _setupDynamicStyle: ->
...@@ -545,16 +560,20 @@ class Hypothesis extends Annotator ...@@ -545,16 +560,20 @@ class Hypothesis extends Annotator
annotations = @heatmap.buckets[@bucket]?.map (a) => a.hash.valueOf() annotations = @heatmap.buckets[@bucket]?.map (a) => a.hash.valueOf()
@visible = true @visible = true
if @lastWidth > 0 then @provider.setFrameWidth(@lastWidth)
@provider.setActiveHighlights annotations @provider.setActiveHighlights annotations
@provider.showFrame() @provider.showFrame()
$("#toolbar").addClass "shown" $("#toolbar").addClass "shown"
$("#toolbar").draggable = true
hide: => hide: =>
@lastWidth = window.innerWidth
@visible = false @visible = false
@provider.setActiveHighlights [] @provider.setActiveHighlights []
@provider.resetFrameWidth()
@provider.hideFrame() @provider.hideFrame()
$("#toolbar").removeClass "shown" $("#toolbar").removeClass "shown"
$("#toolbar").draggable = false
threadId: (annotation) -> threadId: (annotation) ->
if annotation?.thread? if annotation?.thread?
......
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