Commit 9938aa08 authored by Aron Carroll's avatar Aron Carroll

De-bounce all calls for heatmap to update

Previously it would update on every scroll or resize event fired on
either the document or body.
parent f7070d7b
...@@ -38,6 +38,9 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -38,6 +38,9 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
# index for fast hit detection in the buckets # index for fast hit detection in the buckets
index: [] index: []
# tab elements
tabs: null
# whether to update the viewer as the window is scrolled # whether to update the viewer as the window is scrolled
dynamicBucket: true dynamicBucket: true
...@@ -66,8 +69,8 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -66,8 +69,8 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@element.on 'mouseup', (event) => @element.on 'mouseup', (event) =>
event.stopPropagation() event.stopPropagation()
$(window).on 'resize scroll', this._update $(window).on 'resize scroll', this._scheduleUpdate
$(document.body).on 'resize scroll', '*', this._update $(document.body).on 'resize scroll', '*', this._scheduleUpdate
# Event handler to finish scrolling when we have to # Event handler to finish scrolling when we have to
# wait for anchors to be realized # wait for anchors to be realized
...@@ -82,7 +85,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -82,7 +85,7 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
# Weird, but for now, let's work around it. # Weird, but for now, let's work around it.
highlights.anchor highlights.anchor
if anchor.annotation.id? # Is this a finished annotation ? if anchor.annotation.id? # Is this a finished annotation ?
@_scheduleUpdate() this._scheduleUpdate()
if @pendingScroll? and anchor in @pendingScroll.anchors if @pendingScroll? and anchor in @pendingScroll.anchors
# One of the wanted anchors has been realized # One of the wanted anchors has been realized
...@@ -105,18 +108,18 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin ...@@ -105,18 +108,18 @@ class Annotator.Plugin.Heatmap extends Annotator.Plugin
@annotator.subscribe "highlightRemoved", (highlight) => @annotator.subscribe "highlightRemoved", (highlight) =>
if highlight.annotation.id? # Is this a finished annotation ? if highlight.annotation.id? # Is this a finished annotation ?
@_scheduleUpdate() this._scheduleUpdate()
addEventListener "docPageScrolling", => @_update() addEventListener "docPageScrolling", this._scheduleUpdate
# Update the heatmap sometimes soon # Update the heatmap sometimes soon
_scheduleUpdate: => _scheduleUpdate: =>
return if @_updatePending return if @_updatePending
@_updatePending = true @_updatePending = true
setTimeout ( => setTimeout =>
delete @_updatePending delete @_updatePending
@_update() @_update()
), 200 , 60 / 1000
_maybeRebaseUrls: -> _maybeRebaseUrls: ->
# We can't rely on browsers to implement the xml:base property correctly. # We can't rely on browsers to implement the xml:base property correctly.
......
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