Commit af2bfa9d by Arthur Barrett

Saving work in progress on v2 with capa template for annotation problem.

parent 610e210c
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
border-radius: 3px; border-radius: 3px;
.annotatable-toggle { .annotatable-toggle {
position: absolute; position: absolute;
top: 0;
right: 30px; right: 30px;
} }
.annotatable-help-icon { .annotatable-help-icon {
...@@ -25,7 +24,9 @@ ...@@ -25,7 +24,9 @@
height: 17px; height: 17px;
background: url(../images/info-icon.png) no-repeat; background: url(../images/info-icon.png) no-repeat;
} }
.annotatable-toggle, .annotatable-help-icon { margin: 2px 7px 2px 0; } .annotatable-toggle, .annotatable-help-icon {
margin: 2px 7px 2px 0;
}
} }
} }
...@@ -159,16 +160,12 @@ ...@@ -159,16 +160,12 @@
.ui-tooltip.qtip.ui-tooltip-annotatable { .ui-tooltip.qtip.ui-tooltip-annotatable {
max-width: 375px; max-width: 375px;
.ui-tooltip-title:before {
font-weight: normal;
content: "Guided Discussion: ";
}
.ui-tooltip-content { .ui-tooltip-content {
padding: 0 10px; padding: 0 10px;
.annotatable-comment { .annotatable-comment {
display: block; display: block;
margin: 0px 0px 10px 0; margin: 0px 0px 10px 0;
max-height: 225px; // truncate the text via JS so we can get an ellipsis max-height: 225px;
overflow: auto; overflow: auto;
} }
.annotatable-reply { .annotatable-reply {
......
...@@ -4,19 +4,13 @@ class @Annotatable ...@@ -4,19 +4,13 @@ class @Annotatable
wrapperSelector: '.annotatable-wrapper' wrapperSelector: '.annotatable-wrapper'
toggleSelector: '.annotatable-toggle' toggleSelector: '.annotatable-toggle'
spanSelector: '.annotatable-span' spanSelector: '.annotatable-span'
commentSelector: '.annotatable-comment'
replySelector: '.annotatable-reply' replySelector: '.annotatable-reply'
helpSelector: '.annotatable-help-icon' helpSelector: '.annotatable-help-icon'
returnSelector: '.annotatable-return' returnSelector: '.annotatable-return'
problemSelector: '.annotatable-problem'
problemSubmitSelector: '.annotatable-problem-submit'
problemTagSelector: '.annotatable-problem-tags > li'
discussionXModuleSelector: '.xmodule_DiscussionModule' discussionXModuleSelector: '.xmodule_DiscussionModule'
discussionSelector: '.discussion-module' discussionSelector: '.discussion-module'
commentMaxLength: 750 # Max length characters to show in the comment hover state
constructor: (el) -> constructor: (el) ->
console.log 'loaded Annotatable' if @_debug console.log 'loaded Annotatable' if @_debug
@el = el @el = el
...@@ -28,6 +22,7 @@ class @Annotatable ...@@ -28,6 +22,7 @@ class @Annotatable
init: () -> init: () ->
@initEvents() @initEvents()
@initTips() @initTips()
@initDiscussion()
initEvents: () -> initEvents: () ->
@annotationsHidden = false @annotationsHidden = false
...@@ -35,13 +30,9 @@ class @Annotatable ...@@ -35,13 +30,9 @@ class @Annotatable
@$(@wrapperSelector).delegate @replySelector, 'click', @onClickReply @$(@wrapperSelector).delegate @replySelector, 'click', @onClickReply
$(@discussionXModuleSelector).delegate @returnSelector, 'click', @onClickReturn $(@discussionXModuleSelector).delegate @returnSelector, 'click', @onClickReturn
problemSelector = @problemSelector initDiscussion: () ->
@$(@problemSubmitSelector).bind 'click', (e) -> 1
$(this).closest(problemSelector).next().show()
@$(@problemTagSelector).bind 'click', (e) ->
$(this).toggleClass('selected')
initTips: () -> initTips: () ->
@savedTips = [] @savedTips = []
@$(@spanSelector).each (index, el) => $(el).qtip(@getTipOptions el) @$(@spanSelector).each (index, el) => $(el).qtip(@getTipOptions el)
...@@ -86,13 +77,11 @@ class @Annotatable ...@@ -86,13 +77,11 @@ class @Annotatable
onClickReply: (e) => onClickReply: (e) =>
e.preventDefault() e.preventDefault()
discussion_el = @getInlineDiscussion e.currentTarget problem_el = @getProblemEl e.currentTarget
return_el = discussion_el.prev(@returnSelector) if problem_el.length == 1
@scrollTo(problem_el, @afterScrollToProblem)
if return_el.length == 1
@scrollTo(return_el, () -> @afterScrollToDiscussion(discussion_el))
else else
@scrollTo(discussion_el, @afterScrollToDiscussion) console.log 'Problem not found! Event: ', e
onClickReturn: (e) => onClickReturn: (e) =>
e.preventDefault() e.preventDefault()
...@@ -103,15 +92,24 @@ class @Annotatable ...@@ -103,15 +92,24 @@ class @Annotatable
@scrollTo(el, @afterScrollToSpan, offset) @scrollTo(el, @afterScrollToSpan, offset)
getSpan: (el) -> getSpan: (el) ->
discussion_id = @getDiscussionId(el) span_id = @getSpanId(el)
@$(@spanSelector).filter("[data-discussion-id='#{discussion_id}']") @$(@spanSelector).filter("[data-span-id='#{span_id}']")
getInlineDiscussion: (el) -> getDiscussion: (el) ->
discussion_id = @getDiscussionId(el) discussion_id = @getDiscussionId()
$(@discussionXModuleSelector).find(@discussionSelector).filter("[data-discussion-id='#{discussion_id}']") $(@discussionXModuleSelector).find(@discussionSelector).filter("[data-discussion-id='#{discussion_id}']")
getDiscussionId: (el) -> getProblem: (el) ->
$(el).data('discussion-id') el # TODO
getProblemId: (el) ->
$(el).data('problem-id')
getSpanId: (el) ->
$(el).data('span-id')
getDiscussionId: () ->
@$(@wrapperSelector).data('discussion-id')
toggleAnnotations: () -> toggleAnnotations: () ->
hide = (@annotationsHidden = not @annotationsHidden) hide = (@annotationsHidden = not @annotationsHidden)
...@@ -144,30 +142,32 @@ class @Annotatable ...@@ -144,30 +142,32 @@ class @Annotatable
btn = $('.discussion-show', discussion_el) btn = $('.discussion-show', discussion_el)
btn.click() if !btn.hasClass('shown') btn.click() if !btn.hasClass('shown')
afterScrollToProblem: (problem_el) ->
problem_el.effect 'highlight', {}, 500
afterScrollToSpan: (span_el) -> afterScrollToSpan: (span_el) ->
span_el.effect 'highlight', {color: 'rgba(0,0,0,0.5)' }, 1000 span_el.effect 'highlight', {color: 'rgba(0,0,0,0.5)' }, 1000
makeTipContent: (el) -> makeTipContent: (el) ->
(api) => (api) =>
discussion_id = @getDiscussionId(el) text = $(el).data('comment-body')
comment = $(@commentSelector, el).first().clone() comment = @createCommentEl(text)
text = @_truncate comment.text().trim(), @commentMaxLength reply = @createReplyLink('dummy-problem-id')
comment.text(text) $(comment).add(reply)
if discussion_id
comment = comment.after(@createReplyLink discussion_id)
comment
makeTipTitle: (el) -> makeTipTitle: (el) ->
(api) => (api) =>
comment = $(@commentSelector, el).first() title = $(el).data('comment-title')
title = comment.attr('title')
(if title then title else 'Commentary') (if title then title else 'Commentary')
createReplyLink: (discussion_id) -> createCommentEl: (text) ->
$("<a class=\"annotatable-reply\" href=\"javascript:void(0);\" data-discussion-id=\"#{discussion_id}\">See Full Discussion</a>") $("<div class=\"annotatable-comment\">#{text}</div>")
createReplyLink: (problem_id) ->
$("<a class=\"annotatable-reply\" href=\"javascript:void(0);\" data-problem-id=\"#{problem_id}\">Reply to Annotation</a>")
createReturnLink: (discussion_id) -> createReturnLink: (span_id) ->
$("<a class=\"annotatable-return\" href=\"javascript:void(0);\" data-discussion-id=\"#{discussion_id}\">Return to annotation</a>") $("<a class=\"annotatable-return\" href=\"javascript:void(0);\" data-span-id=\"#{span_id}\">Return to annotation</a>")
openSavedTips: () -> openSavedTips: () ->
@showTips @savedTips @showTips @savedTips
...@@ -200,10 +200,4 @@ class @Annotatable ...@@ -200,10 +200,4 @@ class @Annotatable
done = false done = false
return => return =>
fn.call this unless done fn.call this unless done
done = true done = true
\ No newline at end of file
_truncate: (text = '', limit) ->
if text.length > limit
text.substring(0, limit - 1).split(' ').slice(0, -1).join(' ') + '...' # truncate on word boundary
else
text
<%namespace name="annotatable" file="annotatable_problem.html"/> <div class="annotatable-wrapper" data-discussion-id="${discussion_id}">
<div class="annotatable-wrapper" id="${element_id}-wrapper">
<div class="annotatable-header"> <div class="annotatable-header">
% if display_name is not UNDEFINED and display_name is not None: % if display_name is not UNDEFINED and display_name is not None:
<div class="annotatable-title">${display_name} </div> <div class="annotatable-title">${display_name} </div>
% endif % endif
<div class="annotatable-description"> <div class="annotatable-description">
${problem_name} Guided Discussion
<a href="javascript:void(0)" class="annotatable-toggle">Hide Annotations</a> <a class="annotatable-toggle" href="javascript:void(0)">Hide Annotations</a>
<div class="annotatable-help-icon" title="Move your cursor over the highlighted areas to display annotations. Discuss the annotations in the forums using the link at the bottom of the annotation. You may hide annotations at any time by using the button at the top of the section."></div> <div class="annotatable-help-icon" title="Move your cursor over the highlighted areas to display annotations. Discuss the annotations in the forums using the link at the bottom of the annotation. You may hide annotations at any time by using the button at the top of the section."></div>
</div> </div>
</div> </div>
<div class="annotatable-content">${content_html}</div>
<div class="annotatable-content">${html_content}</div> </div>
\ No newline at end of file
% if render_as_problems:
<div class="annotatable-problems">
% for item in items:
${annotatable.render_problem(item['problem'],loop.index,len(items))}
% if item['discussion']:
<div class="annotatable-discussion">${item['discussion']['content']}</div>
% endif
% endfor
</div>
% else:
<div class="annotatable-discussions">
% for item in items:
<div class="annotatable-discussion">
<a class="annotatable-return" href="javascript:void(0);" data-discussion-id="${item['discussion']['discussion_id']}">Return to annotation</a>
${item['discussion']['content']}
</div>
% endfor
</div>
% endif
</div>
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