Commit 0ca71319 by Arthur Barrett

Clicking on annotation span should scroll to the discussion widget.

parent 8f005a5a
...@@ -26,6 +26,7 @@ class AnnotatableModule(XModule): ...@@ -26,6 +26,7 @@ class AnnotatableModule(XModule):
} }
js_module_name = "Annotatable" js_module_name = "Annotatable"
css = {'scss': [resource_string(__name__, 'css/annotatable/display.scss')]} css = {'scss': [resource_string(__name__, 'css/annotatable/display.scss')]}
icon_class = 'annotatable'
def _is_span(self, element): def _is_span(self, element):
""" Returns true if the element is a valid annotation span, false otherwise. """ """ Returns true if the element is a valid annotation span, false otherwise. """
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
} }
} }
span.annotatable { span.annotatable {
color: $blue; color: $blue;
cursor: pointer;
.annotatable-icon { .annotatable-icon {
margin: auto 2px auto 4px; margin: auto 2px auto 4px;
} }
......
class @Annotatable class @Annotatable
@_debug: true
constructor: (el) -> constructor: (el) ->
console.log "loaded Annotatable" console.log 'loaded Annotatable' if @_debug
$(el).find(".annotatable").on "click", (e) -> @el = el
data = $(".annotatable-wrapper", el).data("spans") @spandata = $('.annotatable-wrapper', @el).data "spans"
span_id = e.target.getAttribute("data-span-id") @initSpans()
msg = "annotatable span clicked. discuss span [" + span_id + "] in discussion [" + data[span_id] + "]"
console.log data initSpans: () ->
window.alert msg selector = 'span.annotatable[data-span-id]'
$(@el).find(selector).on 'click', (e) =>
@onClickSpan.call this, e
onClickSpan: (e) ->
span_id = e.target.getAttribute('data-span-id')
discussion_id = @spandata[span_id]
selector = '.annotatable-discussion[data-discussion-id="'+discussion_id+'"]';
$discussion = $(selector, @el)
padding = 20
top = $discussion.offset().top - padding
highlighted = false
complete = () ->
if !highlighted
$discussion.effect('highlight', {}, 1000)
highlighted = true
$('html, body').animate({
scrollTop: top,
}, 1000, 'swing', complete)
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