Commit 8034072c authored by Nick Stenning's avatar Nick Stenning

Move highlights.coffee into texthighlights.coffee

This file provides an abstract base class that's only used in one place,
so this commit just moves it into the one place where it's used.
parent 97220dc8
...@@ -308,7 +308,7 @@ class Annotator extends Delegator ...@@ -308,7 +308,7 @@ class Annotator extends Delegator
# #
# Returns deleted annotation. # Returns deleted annotation.
deleteAnnotation: (annotation) -> deleteAnnotation: (annotation) ->
if annotation.anchors? if annotation.anchors?
for a in annotation.anchors for a in annotation.anchors
a.remove() a.remove()
...@@ -417,7 +417,7 @@ class Annotator extends Delegator ...@@ -417,7 +417,7 @@ class Annotator extends Delegator
this this
# Callback method called when the @editor fires the "hide" event. Itself # Callback method called when the @editor fires the "hide" event. Itself
# publishes the 'annotationEditorHidden' event # publishes the 'annotationEditorHidden' event
# #
# Returns nothing. # Returns nothing.
onEditorHide: => onEditorHide: =>
...@@ -545,7 +545,7 @@ class Annotator extends Delegator ...@@ -545,7 +545,7 @@ class Annotator extends Delegator
isAnnotator: (element) -> isAnnotator: (element) ->
!!$(element).parents().addBack().filter('[class^=annotator-]').not(@wrapper).length !!$(element).parents().addBack().filter('[class^=annotator-]').not(@wrapper).length
# Annotator#element callback. # Annotator#element callback.
# #
# event - A mousedown Event object # event - A mousedown Event object
# #
...@@ -711,8 +711,6 @@ Annotator.Util = Util ...@@ -711,8 +711,6 @@ Annotator.Util = Util
# Expose a global instance registry # Expose a global instance registry
Annotator._instances = [] Annotator._instances = []
Annotator.Highlight = Highlight
# Bind gettext helper so plugins can use localisation. # Bind gettext helper so plugins can use localisation.
Annotator._t = _t Annotator._t = _t
......
# Abstract highlight class
class Highlight
constructor: (@anchor, @pageIndex) ->
@annotation = @anchor.annotation
@anchoring = @anchor.anchoring
@annotator = @anchoring.annotator
# Mark/unmark this hl as temporary (while creating an annotation)
setTemporary: (value) ->
throw "Operation not implemented."
# Is this a temporary hl?
isTemporary: ->
throw "Operation not implemented."
# TODO: review the usage of the batch parameters.
# Mark/unmark this hl as focused
#
# Value specifies whether it should be focused or not
#
# The 'batch' field specifies whether this call is only one of
# many subsequent calls, which should be executed together.
#
# In this case, a "finalizeHighlights" event will be published
# when all the flags have been set, and the changes should be
# executed.
setFocused: (value, batch = false) ->
throw "Operation not implemented."
# React to changes in the underlying annotation
annotationUpdated: ->
#console.log "In HL", this, "annotation has been updated."
# Remove all traces of this hl from the document
removeFromDocument: ->
throw "Operation not implemented."
# Get the HTML elements making up the highlight
# If you implement this, you get automatic implementation for the functions
# below. However, if you need a more sophisticated control mechanism,
# you are free to leave this unimplemented, and manually implement the
# rest.
_getDOMElements: ->
throw "Operation not implemented."
# Get the Y offset of the highlight. Override for more control
getTop: -> $(@_getDOMElements()).offset().top
# Get the height of the highlight. Override for more control
getHeight: -> $(@_getDOMElements()).outerHeight true
# Get the bottom Y offset of the highlight. Override for more control.
getBottom: -> @getTop() + @getBottom()
# Scroll the highlight into view. Override for more control
scrollTo: -> $(@_getDOMElements()).scrollintoview()
# Scroll the highlight into view, with a comfortable margin.
# up should be true if we need to scroll up; false otherwise
paddedScrollTo: (direction) ->
unless direction? then throw "Direction is required"
dir = if direction is "up" then -1 else +1
where = $(@_getDOMElements())
wrapper = @annotator.wrapper
defaultView = wrapper[0].ownerDocument.defaultView
pad = defaultView.innerHeight * .2
where.scrollintoview
complete: ->
scrollable = if this.parentNode is this.ownerDocument
$(this.ownerDocument.body)
else
$(this)
top = scrollable.scrollTop()
correction = pad * dir
scrollable.stop().animate {scrollTop: top + correction}, 300
# Scroll up to the highlight, with a comfortable margin.
paddedScrollUpTo: -> @paddedScrollTo "up"
# Scroll down to the highlight, with a comfortable margin.
paddedScrollDownTo: -> @paddedScrollTo "down"
$ = Annotator.$
# Abstract highlight class
class Highlight
constructor: (@anchor, @pageIndex) ->
@annotation = @anchor.annotation
@anchoring = @anchor.anchoring
@annotator = @anchoring.annotator
# Mark/unmark this hl as temporary (while creating an annotation)
setTemporary: (value) ->
throw "Operation not implemented."
# Is this a temporary hl?
isTemporary: ->
throw "Operation not implemented."
# TODO: review the usage of the batch parameters.
# Mark/unmark this hl as focused
#
# Value specifies whether it should be focused or not
#
# The 'batch' field specifies whether this call is only one of
# many subsequent calls, which should be executed together.
#
# In this case, a "finalizeHighlights" event will be published
# when all the flags have been set, and the changes should be
# executed.
setFocused: (value, batch = false) ->
throw "Operation not implemented."
# React to changes in the underlying annotation
annotationUpdated: ->
#console.log "In HL", this, "annotation has been updated."
# Remove all traces of this hl from the document
removeFromDocument: ->
throw "Operation not implemented."
# Get the HTML elements making up the highlight
# If you implement this, you get automatic implementation for the functions
# below. However, if you need a more sophisticated control mechanism,
# you are free to leave this unimplemented, and manually implement the
# rest.
_getDOMElements: ->
throw "Operation not implemented."
# Get the Y offset of the highlight. Override for more control
getTop: -> $(@_getDOMElements()).offset().top
# Get the height of the highlight. Override for more control
getHeight: -> $(@_getDOMElements()).outerHeight true
# Get the bottom Y offset of the highlight. Override for more control.
getBottom: -> @getTop() + @getBottom()
# Scroll the highlight into view. Override for more control
scrollTo: -> $(@_getDOMElements()).scrollintoview()
# Scroll the highlight into view, with a comfortable margin.
# up should be true if we need to scroll up; false otherwise
paddedScrollTo: (direction) ->
unless direction? then throw "Direction is required"
dir = if direction is "up" then -1 else +1
where = $(@_getDOMElements())
wrapper = @annotator.wrapper
defaultView = wrapper[0].ownerDocument.defaultView
pad = defaultView.innerHeight * .2
where.scrollintoview
complete: ->
scrollable = if this.parentNode is this.ownerDocument
$(this.ownerDocument.body)
else
$(this)
top = scrollable.scrollTop()
correction = pad * dir
scrollable.stop().animate {scrollTop: top + correction}, 300
# Scroll up to the highlight, with a comfortable margin.
paddedScrollUpTo: -> @paddedScrollTo "up"
# Scroll down to the highlight, with a comfortable margin.
paddedScrollDownTo: -> @paddedScrollTo "down"
# This plugin containts the text highlight implementation, # This plugin containts the text highlight implementation,
# required for annotating text. # required for annotating text.
class TextHighlight extends Highlight
class TextHighlight extends Annotator.Highlight
@createFrom: (segment, anchor, page) -> @createFrom: (segment, anchor, page) ->
return null if segment.type isnt "magic range" return null if segment.type isnt "magic range"
new TextHighlight anchor, page, segment.data new TextHighlight anchor, page, segment.data
# XXX: This is a temporay workaround until the Highlighter extension # XXX: This is a temporay workaround until the Highlighter extension
# PR will be merged which will restore separation properly # PR will be merged which will restore separation properly
@highlightClass = 'annotator-hl' @highlightClass = 'annotator-hl'
...@@ -134,4 +220,4 @@ class Annotator.Plugin.TextHighlights extends Annotator.Plugin ...@@ -134,4 +220,4 @@ class Annotator.Plugin.TextHighlights extends Annotator.Plugin
# Plugin initialization # Plugin initialization
pluginInit: -> pluginInit: ->
# Export the text highlight class for other plugins # Export the text highlight class for other plugins
Annotator.TextHighlight = TextHighlight Annotator.TextHighlight = TextHighlight
\ No newline at end of file
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