Commit 4a09c7c9 authored by Randall Leeds's avatar Randall Leeds

rework dragging to use rAF

parent 7c8acc6e
...@@ -22,6 +22,11 @@ class Annotator.Host extends Annotator ...@@ -22,6 +22,11 @@ class Annotator.Host extends Annotator
# timer used to throttle event frequency # timer used to throttle event frequency
updateTimer: null updateTimer: null
# Drag state variables
drag:
delta: 0
tick: false
constructor: (element, options) -> constructor: (element, options) ->
super super
...@@ -63,20 +68,19 @@ class Annotator.Host extends Annotator ...@@ -63,20 +68,19 @@ class Annotator.Host extends Annotator
setupAnnotation: => this.setupAnnotation arguments... setupAnnotation: => this.setupAnnotation arguments...
onEditorHide: this.onEditorHide onEditorHide: this.onEditorHide
onEditorSubmit: this.onEditorSubmit onEditorSubmit: this.onEditorSubmit
showFrame: => @frame.removeClass('annotator-collapsed') showFrame: =>
hideFrame: => @frame.addClass('annotator-collapsed') @frame.css 'margin-left': "#{-1 * @frame.width()}px"
resetFrameWidth: => @frame.removeClass 'annotator-no-transition'
@frame.css({ "width": "", "margin-left" : "" }) @frame.removeClass 'annotator-collapsed'
setFrameWidth: (width) => hideFrame: =>
@frame.css({ "width": width, "margin-left" : (-1)*width }) @frame.css 'margin-left': ''
addToFrameWidth: (width, innerWidth) => @frame.removeClass 'annotator-no-transition'
if isNaN(parseInt(@frame[0].style.width)) @frame.addClass 'annotator-collapsed'
old = innerWidth dragFrame: (d) =>
else @drag.delta += d
old = parseInt(@frame[0].style.width) unless @drag.tick
@frame.css @drag.tick = true
width: old + width requestAnimationFrame @dragRefresh
'margin-left': -(old + width)
getHighlights: => getHighlights: =>
highlights: $(@wrapper).find('.annotator-hl').map -> highlights: $(@wrapper).find('.annotator-hl').map ->
offset: $(this).offset() offset: $(this).offset()
...@@ -173,6 +177,21 @@ class Annotator.Host extends Annotator ...@@ -173,6 +177,21 @@ class Annotator.Host extends Annotator
_setupEditor: -> _setupEditor: ->
true true
dragRefresh: =>
d = @drag.delta
@drag.delta = 0
@drag.tick = false
m = parseInt (getComputedStyle @frame[0]).marginLeft
w = -1 * m
m += d
w -= d
@frame.addClass 'annotator-no-transition'
@frame.css
'margin-left': "#{m}px"
width: "#{w}px"
showEditor: (annotation) => showEditor: (annotation) =>
stub = stub =
ranges: annotation.ranges ranges: annotation.ranges
......
...@@ -5,7 +5,6 @@ class Hypothesis extends Annotator ...@@ -5,7 +5,6 @@ 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::lastWidth = 0 # * Frame's width before close
# Plugin configuration # Plugin configuration
options: options:
...@@ -75,9 +74,7 @@ class Hypothesis extends Annotator ...@@ -75,9 +74,7 @@ class Hypothesis extends Annotator
onEditorSubmit: {} onEditorSubmit: {}
showFrame: {} showFrame: {}
hideFrame: {} hideFrame: {}
resetFrameWidth: {} dragFrame: {}
setFrameWidth: {}
addToFrameWidth: {}
getHighlights: {} getHighlights: {}
setActiveHighlights: {} setActiveHighlights: {}
getMaxBottom: {} getMaxBottom: {}
...@@ -169,7 +166,6 @@ class Hypothesis extends Annotator ...@@ -169,7 +166,6 @@ class Hypothesis extends Annotator
this this
_setupDocumentEvents: -> _setupDocumentEvents: ->
dragStart = 0
@element.find('#toolbar .tri').click => @element.find('#toolbar .tri').click =>
if @visible if @visible
this.hide() this.hide()
...@@ -178,15 +174,16 @@ class Hypothesis extends Annotator ...@@ -178,15 +174,16 @@ class Hypothesis extends Annotator
this._fillDynamicBucket() this._fillDynamicBucket()
this.show() this.show()
dragLast = 0
handle = @element.find('#toolbar .tri')[0] handle = @element.find('#toolbar .tri')[0]
handle.addEventListener 'dragstart', (event) => handle.addEventListener 'dragstart', (event) =>
dragStart = event.screenX dragLast = event.screenX
handle.addEventListener 'dragend', (event) => handle.addEventListener 'dragend', (event) =>
@provider.addToFrameWidth (dragStart - event.screenX), window.innerWidth @provider.dragFrame (event.screenX - dragLast)
handle.addEventListener 'drag', (event) => handle.addEventListener 'drag', (event) =>
if event.screenX > 0 if event.screenX > 0
@provider.addToFrameWidth (dragStart - event.screenX), window.innerWidth @provider.dragFrame (event.screenX - dragLast)
dragStart = event.screenX dragLast = event.screenX
this this
_setupDynamicStyle: -> _setupDynamicStyle: ->
...@@ -609,7 +606,6 @@ class Hypothesis extends Annotator ...@@ -609,7 +606,6 @@ 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()
@element.find("#toolbar").addClass "shown" @element.find("#toolbar").addClass "shown"
...@@ -619,7 +615,6 @@ class Hypothesis extends Annotator ...@@ -619,7 +615,6 @@ class Hypothesis extends Annotator
@lastWidth = window.innerWidth @lastWidth = window.innerWidth
@visible = false @visible = false
@provider.setActiveHighlights [] @provider.setActiveHighlights []
@provider.resetFrameWidth()
@provider.hideFrame() @provider.hideFrame()
@element.find("#toolbar").removeClass "shown" @element.find("#toolbar").removeClass "shown"
document.getElementsByClassName('tri')[0].draggable = false document.getElementsByClassName('tri')[0].draggable = false
......
...@@ -108,10 +108,13 @@ ...@@ -108,10 +108,13 @@
&.annotator-collapsed { &.annotator-collapsed {
margin-left: -$heatmap-width - 17px; margin-left: -$heatmap-width - 17px;
} }
} }
.annotator-no-transition {
@include transition(none !important);
}
/* /*
Mobile layout Mobile layout
......
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