Commit d550129e by Calen Pennington

Modularize sequence coffeescript in prepration for CMS preview

parent 7ca4f5b6
class @Sequence class @Sequence
constructor: (@id, @element_id, @elements, @tag, position) -> constructor: (element) ->
@el = $("##{@element_id}") (@id, @element_id, @elements, position) ->
@buildNavigation() @el = $(element)
@contents = @$('.seq_contents')
@id = @el.data('id')
@initProgress() @initProgress()
@bind() @bind()
@render position @render parseInt(@el.data('position'))
$: (selector) -> $: (selector) ->
$(selector, @el) $(selector, @el)
...@@ -58,19 +60,6 @@ class @Sequence ...@@ -58,19 +60,6 @@ class @Sequence
when 'in_progress' then element.addClass('progress-some') when 'in_progress' then element.addClass('progress-some')
when 'done' then element.addClass('progress-done') when 'done' then element.addClass('progress-done')
buildNavigation: ->
$.each @elements, (index, item) =>
link = $('<a>').attr class: "seq_#{item.type}_inactive", 'data-element': index + 1
title = $('<p>').html(item.title)
# TODO (vshnayder): add item.progress_detail either to the title or somewhere else.
# Make sure it gets updated after ajax calls.
# implementation note: will need to figure out how to handle combining detail
# statuses of multiple modules in js.
list_item = $('<li>').append(link.append(title))
@setProgress item.progress_status, link
@$('#sequence-list').append list_item
toggleArrows: => toggleArrows: =>
@$('.sequence-nav-buttons a').unbind('click') @$('.sequence-nav-buttons a').unbind('click')
...@@ -79,7 +68,7 @@ class @Sequence ...@@ -79,7 +68,7 @@ class @Sequence
else else
@$('.sequence-nav-buttons .prev a').removeClass('disabled').click(@previous) @$('.sequence-nav-buttons .prev a').removeClass('disabled').click(@previous)
if @position == @elements.length if @position == @contents.length
@$('.sequence-nav-buttons .next a').addClass('disabled') @$('.sequence-nav-buttons .next a').addClass('disabled')
else else
@$('.sequence-nav-buttons .next a').removeClass('disabled').click(@next) @$('.sequence-nav-buttons .next a').removeClass('disabled').click(@next)
...@@ -91,7 +80,7 @@ class @Sequence ...@@ -91,7 +80,7 @@ class @Sequence
$.postWithPrefix "/modx/#{@id}/goto_position", position: new_position $.postWithPrefix "/modx/#{@id}/goto_position", position: new_position
@mark_active new_position @mark_active new_position
@$('#seq_content').html @elements[new_position - 1].content @$('#seq_content').html @contents.eq(new_position - 1).text()
MathJax.Hub.Queue(["Typeset", MathJax.Hub]) MathJax.Hub.Queue(["Typeset", MathJax.Hub])
@position = new_position @position = new_position
...@@ -122,16 +111,14 @@ class @Sequence ...@@ -122,16 +111,14 @@ class @Sequence
mark_visited: (position) -> mark_visited: (position) ->
# Don't overwrite class attribute to avoid changing Progress class # Don't overwrite class attribute to avoid changing Progress class
type = @elements[position - 1].type
element = @link_for(position) element = @link_for(position)
element.removeClass("seq_#{type}_inactive") element.removeClass("inactive")
.removeClass("seq_#{type}_active") .removeClass("active")
.addClass("seq_#{type}_visited") .addClass("visited")
mark_active: (position) -> mark_active: (position) ->
# Don't overwrite class attribute to avoid changing Progress class # Don't overwrite class attribute to avoid changing Progress class
type = @elements[position - 1].type
element = @link_for(position) element = @link_for(position)
element.removeClass("seq_#{type}_inactive") element.removeClass("inactive")
.removeClass("seq_#{type}_visited") .removeClass("visited")
.addClass("seq_#{type}_active") .addClass("active")
...@@ -81,11 +81,7 @@ class SequenceModule(XModule): ...@@ -81,11 +81,7 @@ class SequenceModule(XModule):
'type': child.get_icon_class(), 'type': child.get_icon_class(),
}) })
# Split </script> tags -- browsers handle this as end params = {'items': contents,
# of script, even if it occurs mid-string. Do this after json.dumps()ing
# so that we can be sure of the quotations being used
import re
params = {'items': re.sub(r'(?i)</(script)', r'\u003c/\1', json.dumps(contents)), # ?i = re.IGNORECASE for py2.6 compatability
'element_id': self.location.html_id(), 'element_id': self.location.html_id(),
'item_id': self.id, 'item_id': self.id,
'position': self.position, 'position': self.position,
......
...@@ -87,60 +87,66 @@ nav.sequence-nav { ...@@ -87,60 +87,66 @@ nav.sequence-nav {
} }
//video //video
&.seq_video_inactive { &.seq_video {
@extend .inactive; &.inactive {
background-image: url('../images/sequence-nav/video-icon-normal.png'); @extend .inactive;
background-position: center; background-image: url('../images/sequence-nav/video-icon-normal.png');
} background-position: center;
}
&.seq_video_visited { &.visited {
@extend .visited; @extend .visited;
background-image: url('../images/sequence-nav/video-icon-visited.png'); background-image: url('../images/sequence-nav/video-icon-visited.png');
background-position: center; background-position: center;
} }
&.seq_video_active { &.active {
@extend .active; @extend .active;
background-image: url('../images/sequence-nav/video-icon-current.png'); background-image: url('../images/sequence-nav/video-icon-current.png');
background-position: center; background-position: center;
}
} }
//other //other
&.seq_other_inactive { &.seq_other {
@extend .inactive; &.inactive {
background-image: url('../images/sequence-nav/document-icon-normal.png'); @extend .inactive;
background-position: center; background-image: url('../images/sequence-nav/document-icon-normal.png');
} background-position: center;
}
&.seq_other_visited { &.visited {
@extend .visited; @extend .visited;
background-image: url('../images/sequence-nav/document-icon-visited.png'); background-image: url('../images/sequence-nav/document-icon-visited.png');
background-position: center; background-position: center;
} }
&.seq_other_active { &.active {
@extend .active; @extend .active;
background-image: url('../images/sequence-nav/document-icon-current.png'); background-image: url('../images/sequence-nav/document-icon-current.png');
background-position: center; background-position: center;
}
} }
//vertical & problems //vertical & problems
&.seq_vertical_inactive, &.seq_problem_inactive { &.seq_vertical, &.seq_problem {
@extend .inactive; &.inactive {
background-image: url('../images/sequence-nav/list-icon-normal.png'); @extend .inactive;
background-position: center; background-image: url('../images/sequence-nav/list-icon-normal.png');
} background-position: center;
}
&.seq_vertical_visited, &.seq_problem_visited { &.visited {
@extend .visited; @extend .visited;
background-image: url('../images/sequence-nav/list-icon-visited.png'); background-image: url('../images/sequence-nav/list-icon-visited.png');
background-position: center; background-position: center;
} }
&.seq_vertical_active, &.seq_problem_active { &.active {
@extend .active; @extend .active;
background-image: url('../images/sequence-nav/list-icon-current.png'); background-image: url('../images/sequence-nav/list-icon-current.png');
background-position: center; background-position: center;
}
} }
p { p {
...@@ -265,6 +271,10 @@ section.course-content { ...@@ -265,6 +271,10 @@ section.course-content {
} }
} }
div.seq_contents {
display: none;
}
nav.sequence-bottom { nav.sequence-bottom {
margin: lh(2) 0 0; margin: lh(2) 0 0;
text-align: center; text-align: center;
......
<div id="sequence_${element_id}" class="sequence"> <div id="sequence_${element_id}" class="sequence" data-id="${item_id}" data-position="${position}" >
<nav aria-label="Section Navigation" class="sequence-nav"> <nav aria-label="Section Navigation" class="sequence-nav">
<ol id="sequence-list"> <ol id="sequence-list">
% for idx, item in enumerate(items):
## TODO (vshnayder): add item.progress_detail either to the title or somewhere else.
## Make sure it gets updated after ajax calls.
## implementation note: will need to figure out how to handle combining detail
## statuses of multiple modules in js.
<li>
<a class="seq_${item['type']} inactive progress-${item['progress_status']}" data-element="${idx+1}">
<p>${item['title']}</p>
</a>
</li>
% endfor
</ol> </ol>
<ul class="sequence-nav-buttons"> <ul class="sequence-nav-buttons">
...@@ -9,6 +20,9 @@ ...@@ -9,6 +20,9 @@
</ul> </ul>
</nav> </nav>
% for item in items:
<div class="seq_contents">${item['content'] | h}</div>
% endfor
<div id="seq_content"></div> <div id="seq_content"></div>
<nav class="sequence-bottom"> <nav class="sequence-bottom">
...@@ -22,7 +36,7 @@ ...@@ -22,7 +36,7 @@
<%block name="js_extra"> <%block name="js_extra">
<script type="text/javascript"> <script type="text/javascript">
$(function(){ $(function(){
new Sequence('${item_id}', 'sequence_${element_id}', ${items}, '${tag}', ${position}); new Sequence($("#sequence_${element_id}"));
}); });
</script> </script>
</%block> </%block>
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