Commit 80c97c65 by Prem Sichanugrist

Refactor module loading using class detection

parent 8624927f
......@@ -32,9 +32,7 @@ class Module(XModule):
return ["video"]
def video_list(self):
l = self.youtube.split(',')
l = [i.split(":") for i in l]
return json.dumps(dict(l))
return self.youtube
def get_html(self):
return render_to_string('video.html',{'streams':self.video_list(),
......
class window.Calculator
@bind: ->
calculator = new Calculator
$('.calc').click calculator.toggle
$('form#calculator').submit(calculator.calculate).submit (e) ->
class Calculator
constructor: ->
$('.calc').click @toggle
$('form#calculator').submit(@calculate).submit (e) ->
e.preventDefault()
$('div.help-wrapper a').hover(calculator.helpToggle).click (e) ->
$('div.help-wrapper a').hover(@helpToggle).click (e) ->
e.preventDefault()
toggle: ->
......
class window.Courseware
@bind: ->
@Navigation.bind()
class @Navigation
@bind: ->
if $('#accordion').length
navigation = new Navigation
active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', navigation.log).accordion
active: if active >= 0 then active else 1
header: 'h3'
autoHeight: false
$('#open_close_accordion a').click navigation.toggle
$('#accordion').show()
log: (event, ui) ->
log_event 'accordion',
newheader: ui.newHeader.text()
oldheader: ui.oldHeader.text()
toggle: ->
$('.course-wrapper').toggleClass('closed')
constructor: ->
new CoursewareNavigation
new Calculator
new FeedbackForm
@renderModules()
@start: ->
new Courseware
renderModules: ->
$('.course-content .video').each ->
id = $(this).attr('id').replace(/video_/, '')
new Video id, $(this).data('streams')
class window.FeedbackForm
@bind: ->
class FeedbackForm
constructor: ->
$('#feedback_button').click ->
data =
subject: $('#feedback_subject').val()
......
......@@ -5,8 +5,7 @@ $ ->
window.onTouchBasedDevice = ->
navigator.userAgent.match /iPhone|iPod|iPad/i
Calculator.bind()
Courseware.bind()
FeedbackForm.bind()
$("a[rel*=leanModal]").leanModal()
if $('body').hasClass('courseware')
Courseware.start()
......@@ -351,7 +351,6 @@ section.course-content {
float: left;
max-height: 460px;
overflow: auto;
padding-top: 10px;
width: flex-grid(3, 9);
li {
......
class CoursewareNavigation
constructor: ->
if $('#accordion').length
active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', @log).accordion
active: if active >= 0 then active else 1
header: 'h3'
autoHeight: false
$('#open_close_accordion a').click @toggle
$('#accordion').show()
log: (event, ui) ->
log_event 'accordion',
newheader: ui.newHeader.text()
oldheader: ui.oldHeader.text()
toggle: ->
$('.course-wrapper').toggleClass('closed')
......@@ -40,20 +40,20 @@ class window.Sequence
@position = new_position
@toggleArrows()
goto: (e) =>
e.preventDefault()
new_position = $(e.srcElement).data('element')
goto: (event) =>
event.preventDefault()
new_position = $(event.target).data('element')
log_event("seq_goto", old: @position, new: new_position, id: @id)
@render new_position
next: (e) =>
e.preventDefault()
next: (event) =>
event.preventDefault()
new_position = @position + 1
log_event("seq_next", old: @position, new: new_position, id: @id)
@render new_position
previous: (e) =>
e.preventDefault()
previous: (event) =>
event.preventDefault()
new_position = @position - 1
log_event("seq_prev", old: @position, new: new_position, id: @id)
@render new_position
......
class window.Video
class Video
constructor: (@id, videos) ->
@element = $("#video_#{@id}")
@parseVideos videos
......@@ -14,9 +14,10 @@ class window.Video
parseVideos: (videos) ->
@videos = {}
$.each videos, (speed, url) =>
speed = parseFloat(speed).toFixed(2).replace /\.00$/, '.0'
@videos[speed] = url
$.each videos.split(/,/), (index, video) =>
video = video.split(/:/)
speed = parseFloat(video[0]).toFixed(2).replace /\.00$/, '.0'
@videos[speed] = video[1]
parseSpeed: ->
@setSpeed($.cookie('video_speed'))
......
class Courseware::Navigation
constructor: ->
if $('#accordion').length
active = $('#accordion ul:has(li.active)').index('#accordion ul')
$('#accordion').bind('accordionchange', @log).accordion
active: if active >= 0 then active else 1
header: 'h3'
autoHeight: false
$('#open_close_accordion a').click @toggle
$('#accordion').show()
log: (event, ui) ->
log_event 'accordion',
newheader: ui.newHeader.text()
oldheader: ui.oldHeader.text()
toggle: ->
$('.course-wrapper').toggleClass('closed')
......@@ -2,7 +2,7 @@
<h1> ${name} </h1>
% endif
<div id="video_${id}" class="video">
<div id="video_${id}" class="video" data-streams="${streams}">
<div class="tc-wrapper">
<article class="video-wrapper">
<section class="video-player">
......@@ -41,14 +41,6 @@
</div>
</div>
<%block name="js_extra">
<script type="text/javascript">
$(function(){
new Video('${id}', ${streams});
});
</script>
</%block>
<ol class="video-mod">
% for t in annotations:
<li id="video-${annotations.index(t)}">
......
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