Merge branch 'master' of github.com:edx/edx-platform into bugfix/ichuang/make-edit-link-use-static-asset-path
This commit is contained in:
@@ -42,6 +42,6 @@ class CeleryConfigTest(unittest.TestCase):
|
||||
|
||||
# We don't know the other dict values exactly,
|
||||
# but we can assert that they take the right form
|
||||
self.assertTrue(isinstance(result_dict['task_id'], unicode))
|
||||
self.assertTrue(isinstance(result_dict['time'], float))
|
||||
self.assertIsInstance(result_dict['task_id'], unicode)
|
||||
self.assertIsInstance(result_dict['time'], float)
|
||||
self.assertTrue(result_dict['time'] > 0.0)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# pylint: disable=W0621
|
||||
|
||||
from lettuce import world
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.models import User, Group
|
||||
from student.models import CourseEnrollment
|
||||
from xmodule.modulestore.django import editable_modulestore
|
||||
from xmodule.contentstore.django import contentstore
|
||||
@@ -50,6 +50,21 @@ def register_by_course_id(course_id, username='robot', password='test', is_staff
|
||||
CourseEnrollment.enroll(user, course_id)
|
||||
|
||||
|
||||
@world.absorb
|
||||
def add_to_course_staff(username, course_num):
|
||||
"""
|
||||
Add the user with `username` to the course staff group
|
||||
for `course_num`.
|
||||
"""
|
||||
# Based on code in lms/djangoapps/courseware/access.py
|
||||
group_name = "instructor_{}".format(course_num)
|
||||
group, _ = Group.objects.get_or_create(name=group_name)
|
||||
group.save()
|
||||
|
||||
user = User.objects.get(username=username)
|
||||
user.groups.add(group)
|
||||
|
||||
|
||||
@world.absorb
|
||||
def clear_courses():
|
||||
# Flush and initialize the module store
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
# Disable the "unused argument" warning because lettuce uses "step"
|
||||
#pylint: disable=W0613
|
||||
|
||||
import re
|
||||
from lettuce import world, step
|
||||
from .course_helpers import *
|
||||
from .ui_helpers import *
|
||||
@@ -23,32 +22,15 @@ logger = getLogger(__name__)
|
||||
|
||||
|
||||
@step(r'I wait (?:for )?"(\d+\.?\d*)" seconds?$')
|
||||
def wait(step, seconds):
|
||||
def wait_for_seconds(step, seconds):
|
||||
world.wait(seconds)
|
||||
|
||||
REQUIREJS_WAIT = {
|
||||
re.compile('settings-details'): [
|
||||
"jquery", "js/models/course",
|
||||
"js/models/settings/course_details", "js/views/settings/main"],
|
||||
re.compile('settings-advanced'): [
|
||||
"jquery", "js/models/course", "js/models/settings/advanced",
|
||||
"js/views/settings/advanced", "codemirror"],
|
||||
re.compile('edit\/.+vertical'): [
|
||||
"jquery", "js/models/course", "coffee/src/models/module",
|
||||
"coffee/src/views/unit", "jquery.ui"],
|
||||
}
|
||||
|
||||
|
||||
@step('I reload the page$')
|
||||
def reload_the_page(step):
|
||||
world.wait_for_ajax_complete()
|
||||
world.browser.reload()
|
||||
requirements = None
|
||||
for test, req in REQUIREJS_WAIT.items():
|
||||
if test.search(world.browser.url):
|
||||
requirements = req
|
||||
break
|
||||
world.wait_for_requirejs(requirements)
|
||||
world.wait_for_js_to_load()
|
||||
|
||||
|
||||
@step('I press the browser back button$')
|
||||
@@ -163,9 +145,9 @@ def should_see_in_the_page(step, doesnt_appear, text):
|
||||
else:
|
||||
multiplier = 1
|
||||
if doesnt_appear:
|
||||
assert world.browser.is_text_not_present(text, wait_time=5*multiplier)
|
||||
assert world.browser.is_text_not_present(text, wait_time=5 * multiplier)
|
||||
else:
|
||||
assert world.browser.is_text_present(text, wait_time=5*multiplier)
|
||||
assert world.browser.is_text_present(text, wait_time=5 * multiplier)
|
||||
|
||||
|
||||
@step('I am logged in$')
|
||||
|
||||
@@ -4,11 +4,13 @@
|
||||
from lettuce import world
|
||||
import time
|
||||
import json
|
||||
import re
|
||||
import platform
|
||||
from textwrap import dedent
|
||||
from urllib import quote_plus
|
||||
from selenium.common.exceptions import (
|
||||
WebDriverException, TimeoutException, StaleElementReferenceException)
|
||||
WebDriverException, TimeoutException,
|
||||
StaleElementReferenceException)
|
||||
from selenium.webdriver.support import expected_conditions as EC
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.support.ui import WebDriverWait
|
||||
@@ -16,11 +18,50 @@ from lettuce.django import django_url
|
||||
from nose.tools import assert_true # pylint: disable=E0611
|
||||
|
||||
|
||||
REQUIREJS_WAIT = {
|
||||
# Settings - Schedule & Details
|
||||
re.compile('^Schedule & Details Settings \|'): [
|
||||
"jquery", "js/models/course",
|
||||
"js/models/settings/course_details", "js/views/settings/main"],
|
||||
|
||||
# Settings - Advanced Settings
|
||||
re.compile('^Advanced Settings \|'): [
|
||||
"jquery", "js/models/course", "js/models/settings/advanced",
|
||||
"js/views/settings/advanced", "codemirror"],
|
||||
|
||||
# Individual Unit (editing)
|
||||
re.compile('^Individual Unit \|'): [
|
||||
"coffee/src/models/module", "coffee/src/views/unit",
|
||||
"coffee/src/views/module_edit"],
|
||||
|
||||
# Content - Outline
|
||||
# Note that calling your org, course number, or display name, 'course' will mess this up
|
||||
re.compile('^Course Outline \|'): [
|
||||
"js/models/course", "js/models/location", "js/models/section",
|
||||
"js/views/overview", "js/views/section_edit"],
|
||||
|
||||
# Dashboard
|
||||
re.compile('^My Courses \|'): [
|
||||
"js/sock", "gettext", "js/base",
|
||||
"jquery.ui", "coffee/src/main", "underscore"],
|
||||
}
|
||||
|
||||
|
||||
@world.absorb
|
||||
def wait(seconds):
|
||||
time.sleep(float(seconds))
|
||||
|
||||
|
||||
@world.absorb
|
||||
def wait_for_js_to_load():
|
||||
requirements = None
|
||||
for test, req in REQUIREJS_WAIT.items():
|
||||
if test.search(world.browser.title):
|
||||
requirements = req
|
||||
break
|
||||
world.wait_for_requirejs(requirements)
|
||||
|
||||
|
||||
# Selenium's `execute_async_script` function pauses Selenium's execution
|
||||
# until the browser calls a specific Javascript callback; in effect,
|
||||
# Selenium goes to sleep until the JS callback function wakes it back up again.
|
||||
@@ -28,8 +69,6 @@ def wait(seconds):
|
||||
# passed to this callback get returned from the `execute_async_script`
|
||||
# function, which allows the JS to communicate information back to Python.
|
||||
# Ref: https://selenium.googlecode.com/svn/trunk/docs/api/dotnet/html/M_OpenQA_Selenium_IJavaScriptExecutor_ExecuteAsyncScript.htm
|
||||
|
||||
|
||||
@world.absorb
|
||||
def wait_for_js_variable_truthy(variable):
|
||||
"""
|
||||
@@ -37,7 +76,7 @@ def wait_for_js_variable_truthy(variable):
|
||||
environment until the given variable is defined and truthy. This process
|
||||
guards against page reloads, and seamlessly retries on the next page.
|
||||
"""
|
||||
js = """
|
||||
javascript = """
|
||||
var callback = arguments[arguments.length - 1];
|
||||
var unloadHandler = function() {{
|
||||
callback("unload");
|
||||
@@ -56,7 +95,13 @@ def wait_for_js_variable_truthy(variable):
|
||||
}}, 10);
|
||||
""".format(variable=variable)
|
||||
for _ in range(5): # 5 attempts max
|
||||
result = world.browser.driver.execute_async_script(dedent(js))
|
||||
try:
|
||||
result = world.browser.driver.execute_async_script(dedent(javascript))
|
||||
except WebDriverException as wde:
|
||||
if "document unloaded while waiting for result" in wde.msg:
|
||||
result = "unload"
|
||||
else:
|
||||
raise
|
||||
if result == "unload":
|
||||
# we ran this on the wrong page. Wait a bit, and try again, when the
|
||||
# browser has loaded the next page.
|
||||
@@ -105,7 +150,7 @@ def wait_for_requirejs(dependencies=None):
|
||||
if dependencies[0] != "jquery":
|
||||
dependencies.insert(0, "jquery")
|
||||
|
||||
js = """
|
||||
javascript = """
|
||||
var callback = arguments[arguments.length - 1];
|
||||
if(window.require) {{
|
||||
requirejs.onError = callback;
|
||||
@@ -126,19 +171,33 @@ def wait_for_requirejs(dependencies=None):
|
||||
}}
|
||||
""".format(deps=json.dumps(dependencies))
|
||||
for _ in range(5): # 5 attempts max
|
||||
result = world.browser.driver.execute_async_script(dedent(js))
|
||||
try:
|
||||
result = world.browser.driver.execute_async_script(dedent(javascript))
|
||||
except WebDriverException as wde:
|
||||
if "document unloaded while waiting for result" in wde.msg:
|
||||
result = "unload"
|
||||
else:
|
||||
raise
|
||||
if result == "unload":
|
||||
# we ran this on the wrong page. Wait a bit, and try again, when the
|
||||
# browser has loaded the next page.
|
||||
world.wait(1)
|
||||
continue
|
||||
elif result not in (None, True, False):
|
||||
# we got a require.js error
|
||||
msg = "Error loading dependencies: type={0} modules={1}".format(
|
||||
result['requireType'], result['requireModules'])
|
||||
err = RequireJSError(msg)
|
||||
err.error = result
|
||||
raise err
|
||||
# We got a require.js error
|
||||
# Sometimes requireJS will throw an error with requireType=require
|
||||
# This doesn't seem to cause problems on the page, so we ignore it
|
||||
if result['requireType'] == 'require':
|
||||
world.wait(1)
|
||||
continue
|
||||
|
||||
# Otherwise, fail and report the error
|
||||
else:
|
||||
msg = "Error loading dependencies: type={0} modules={1}".format(
|
||||
result['requireType'], result['requireModules'])
|
||||
err = RequireJSError(msg)
|
||||
err.error = result
|
||||
raise err
|
||||
else:
|
||||
return result
|
||||
|
||||
@@ -153,7 +212,7 @@ def wait_for_ajax_complete():
|
||||
keeps track of this information, go here:
|
||||
http://stackoverflow.com/questions/3148225/jquery-active-function#3148506
|
||||
"""
|
||||
js = """
|
||||
javascript = """
|
||||
var callback = arguments[arguments.length - 1];
|
||||
if(!window.jQuery) {callback(false);}
|
||||
var intervalID = setInterval(function() {
|
||||
@@ -163,13 +222,13 @@ def wait_for_ajax_complete():
|
||||
}
|
||||
}, 100);
|
||||
"""
|
||||
world.browser.driver.execute_async_script(dedent(js))
|
||||
world.browser.driver.execute_async_script(dedent(javascript))
|
||||
|
||||
|
||||
@world.absorb
|
||||
def visit(url):
|
||||
world.browser.visit(django_url(url))
|
||||
wait_for_requirejs()
|
||||
wait_for_js_to_load()
|
||||
|
||||
|
||||
@world.absorb
|
||||
@@ -238,11 +297,11 @@ def css_has_value(css_selector, value, index=0):
|
||||
|
||||
@world.absorb
|
||||
def wait_for(func, timeout=5):
|
||||
WebDriverWait(
|
||||
driver=world.browser.driver,
|
||||
timeout=timeout,
|
||||
ignored_exceptions=(StaleElementReferenceException)
|
||||
).until(func)
|
||||
WebDriverWait(
|
||||
driver=world.browser.driver,
|
||||
timeout=timeout,
|
||||
ignored_exceptions=(StaleElementReferenceException)
|
||||
).until(func)
|
||||
|
||||
|
||||
@world.absorb
|
||||
@@ -336,17 +395,15 @@ def css_click(css_selector, index=0, wait_time=30):
|
||||
This method will return True if the click worked.
|
||||
"""
|
||||
wait_for_clickable(css_selector, timeout=wait_time)
|
||||
assert_true(world.css_find(css_selector)[index].visible,
|
||||
msg="Element {}[{}] is present but not visible".format(css_selector, index))
|
||||
assert_true(
|
||||
world.css_visible(css_selector, index=index),
|
||||
msg="Element {}[{}] is present but not visible".format(css_selector, index)
|
||||
)
|
||||
|
||||
# Sometimes you can't click in the center of the element, as
|
||||
# another element might be on top of it. In this case, try
|
||||
# clicking in the upper left corner.
|
||||
try:
|
||||
return retry_on_exception(lambda: world.css_find(css_selector)[index].click())
|
||||
|
||||
except WebDriverException:
|
||||
return css_click_at(css_selector, index=index)
|
||||
result = retry_on_exception(lambda: world.css_find(css_selector)[index].click())
|
||||
if result:
|
||||
wait_for_js_to_load()
|
||||
return result
|
||||
|
||||
|
||||
@world.absorb
|
||||
@@ -361,22 +418,6 @@ def css_check(css_selector, index=0, wait_time=30):
|
||||
return css_click(css_selector=css_selector, index=index, wait_time=wait_time)
|
||||
|
||||
|
||||
@world.absorb
|
||||
def css_click_at(css_selector, index=0, x_coord=10, y_coord=10, timeout=5):
|
||||
'''
|
||||
A method to click at x,y coordinates of the element
|
||||
rather than in the center of the element
|
||||
'''
|
||||
wait_for_clickable(css_selector, timeout=timeout)
|
||||
element = css_find(css_selector)[index]
|
||||
assert_true(element.visible,
|
||||
msg="Element {}[{}] is present but not visible".format(css_selector, index))
|
||||
|
||||
element.action_chains.move_to_element_with_offset(element._element, x_coord, y_coord)
|
||||
element.action_chains.click()
|
||||
element.action_chains.perform()
|
||||
|
||||
|
||||
@world.absorb
|
||||
def select_option(name, value, index=0, wait_time=30):
|
||||
'''
|
||||
@@ -406,6 +447,7 @@ def css_fill(css_selector, text, index=0):
|
||||
@world.absorb
|
||||
def click_link(partial_text, index=0):
|
||||
retry_on_exception(lambda: world.browser.find_link_by_partial_text(partial_text)[index].click())
|
||||
wait_for_js_to_load()
|
||||
|
||||
|
||||
@world.absorb
|
||||
@@ -512,7 +554,6 @@ def retry_on_exception(func, max_attempts=5, ignored_exceptions=StaleElementRefe
|
||||
while attempt < max_attempts:
|
||||
try:
|
||||
return func()
|
||||
break
|
||||
except ignored_exceptions:
|
||||
world.wait(1)
|
||||
attempt += 1
|
||||
|
||||
@@ -11,7 +11,7 @@ from pymongo.errors import PyMongoError
|
||||
from track.backends import BaseBackend
|
||||
|
||||
|
||||
log = logging.getLogger('track.backends.mongodb')
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class MongoBackend(BaseBackend):
|
||||
@@ -64,14 +64,17 @@ class MongoBackend(BaseBackend):
|
||||
**extra
|
||||
)
|
||||
|
||||
self.collection = self.connection[db_name][collection_name]
|
||||
database = self.connection[db_name]
|
||||
|
||||
if user or password:
|
||||
self.collection.database.authenticate(user, password)
|
||||
database.authenticate(user, password)
|
||||
|
||||
self.collection = database[collection_name]
|
||||
|
||||
self._create_indexes()
|
||||
|
||||
def _create_indexes(self):
|
||||
"""Ensures the proper fields are indexed"""
|
||||
# WARNING: The collection will be locked during the index
|
||||
# creation. If the collection has a large number of
|
||||
# documents in it, the operation can take a long time.
|
||||
@@ -83,8 +86,12 @@ class MongoBackend(BaseBackend):
|
||||
self.collection.ensure_index('event_type')
|
||||
|
||||
def send(self, event):
|
||||
"""Insert the event in to the Mongo collection"""
|
||||
try:
|
||||
self.collection.insert(event, manipulate=False)
|
||||
except PyMongoError:
|
||||
# The event will be lost in case of a connection error.
|
||||
# pymongo will re-connect/re-authenticate automatically
|
||||
# during the next event.
|
||||
msg = 'Error inserting to MongoDB event tracker backend'
|
||||
log.exception(msg)
|
||||
|
||||
@@ -134,7 +134,7 @@ def add_histogram(user, block, view, frag, context): # pylint: disable=unused-a
|
||||
return frag
|
||||
|
||||
block_id = block.id
|
||||
if block.descriptor.has_score:
|
||||
if block.has_score:
|
||||
histogram = grade_histogram(block_id)
|
||||
render_histogram = len(histogram) > 0
|
||||
else:
|
||||
@@ -142,7 +142,7 @@ def add_histogram(user, block, view, frag, context): # pylint: disable=unused-a
|
||||
render_histogram = False
|
||||
|
||||
if settings.MITX_FEATURES.get('ENABLE_LMS_MIGRATION'):
|
||||
[filepath, filename] = getattr(block.descriptor, 'xml_attributes', {}).get('filename', ['', None])
|
||||
[filepath, filename] = getattr(block, 'xml_attributes', {}).get('filename', ['', None])
|
||||
osfs = block.system.filestore
|
||||
if filename is not None and osfs.exists(filename):
|
||||
# if original, unmangled filename exists then use it (github
|
||||
@@ -163,13 +163,13 @@ def add_histogram(user, block, view, frag, context): # pylint: disable=unused-a
|
||||
# TODO (ichuang): use _has_access_descriptor.can_load in lms.courseware.access, instead of now>mstart comparison here
|
||||
now = datetime.datetime.now(UTC())
|
||||
is_released = "unknown"
|
||||
mstart = block.descriptor.start
|
||||
mstart = block.start
|
||||
|
||||
if mstart is not None:
|
||||
is_released = "<font color='red'>Yes!</font>" if (now > mstart) else "<font color='green'>Not yet</font>"
|
||||
|
||||
staff_context = {'fields': [(name, field.read_from(block)) for name, field in block.fields.items()],
|
||||
'xml_attributes': getattr(block.descriptor, 'xml_attributes', {}),
|
||||
'xml_attributes': getattr(block, 'xml_attributes', {}),
|
||||
'location': block.location,
|
||||
'xqa_key': block.xqa_key,
|
||||
'source_file': source_file,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
<div class="drag_and_drop_problem_json" id="drag_and_drop_json_${id}"
|
||||
style="display:none;">${drag_and_drop_json}</div>
|
||||
|
||||
<div class="script_placeholder" data-src="/static/js/capa/drag_and_drop.js"></div>
|
||||
<div class="script_placeholder" data-src="${STATIC_URL}js/capa/drag_and_drop.js"></div>
|
||||
|
||||
% if status == 'unsubmitted':
|
||||
<div class="unanswered" id="status_${id}">
|
||||
|
||||
@@ -951,7 +951,7 @@ class DragAndDropTest(unittest.TestCase):
|
||||
'''
|
||||
|
||||
def test_rendering(self):
|
||||
path_to_images = '/static/images/'
|
||||
path_to_images = '/dummy-static/images/'
|
||||
|
||||
xml_str = """
|
||||
<drag_and_drop_input id="prob_1_2" img="{path}about_1.png" target_outline="false">
|
||||
@@ -978,15 +978,15 @@ class DragAndDropTest(unittest.TestCase):
|
||||
|
||||
user_input = { # order matters, for string comparison
|
||||
"target_outline": "false",
|
||||
"base_image": "/static/images/about_1.png",
|
||||
"base_image": "/dummy-static/images/about_1.png",
|
||||
"draggables": [
|
||||
{"can_reuse": "", "label": "Label 1", "id": "1", "icon": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "cc", "id": "name_with_icon", "icon": "/static/images/cc.jpg", "target_fields": []},
|
||||
{"can_reuse": "", "label": "arrow-left", "id": "with_icon", "icon": "/static/images/arrow-left.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "cc", "id": "name_with_icon", "icon": "/dummy-static/images/cc.jpg", "target_fields": []},
|
||||
{"can_reuse": "", "label": "arrow-left", "id": "with_icon", "icon": "/dummy-static/images/arrow-left.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Label2", "id": "5", "icon": "", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Mute", "id": "2", "icon": "/static/images/mute.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "spinner", "id": "name_label_icon3", "icon": "/static/images/spinner.gif", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Star", "id": "name4", "icon": "/static/images/volume.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Mute", "id": "2", "icon": "/dummy-static/images/mute.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "spinner", "id": "name_label_icon3", "icon": "/dummy-static/images/spinner.gif", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Star", "id": "name4", "icon": "/dummy-static/images/volume.png", "can_reuse": "", "target_fields": []},
|
||||
{"can_reuse": "", "label": "Label3", "id": "7", "icon": "", "can_reuse": "", "target_fields": []}],
|
||||
"one_per_target": "True",
|
||||
"targets": [
|
||||
|
||||
@@ -15,7 +15,7 @@ from capa.responsetypes import StudentInputError, \
|
||||
ResponseError, LoncapaProblemError
|
||||
from capa.util import convert_files_to_filenames
|
||||
from .progress import Progress
|
||||
from xmodule.x_module import XModule
|
||||
from xmodule.x_module import XModule, module_attr
|
||||
from xmodule.raw_module import RawDescriptor
|
||||
from xmodule.exceptions import NotFoundError, ProcessingError
|
||||
from xblock.fields import Scope, String, Boolean, Dict, Integer, Float
|
||||
@@ -884,6 +884,8 @@ class CapaModule(CapaFields, XModule):
|
||||
'max_value': score['total'],
|
||||
})
|
||||
|
||||
return {'grade': score['score'], 'max_grade': score['total']}
|
||||
|
||||
def check_problem(self, data):
|
||||
"""
|
||||
Checks whether answers to a problem are correct
|
||||
@@ -951,7 +953,7 @@ class CapaModule(CapaFields, XModule):
|
||||
return {'success': msg}
|
||||
raise
|
||||
|
||||
self.publish_grade()
|
||||
published_grade = self.publish_grade()
|
||||
|
||||
# success = correct if ALL questions in this problem are correct
|
||||
success = 'correct'
|
||||
@@ -961,6 +963,8 @@ class CapaModule(CapaFields, XModule):
|
||||
|
||||
# NOTE: We are logging both full grading and queued-grading submissions. In the latter,
|
||||
# 'success' will always be incorrect
|
||||
event_info['grade'] = published_grade['grade']
|
||||
event_info['max_grade'] = published_grade['max_grade']
|
||||
event_info['correct_map'] = correct_map.get_dict()
|
||||
event_info['success'] = success
|
||||
event_info['attempts'] = self.attempts
|
||||
@@ -1193,3 +1197,33 @@ class CapaDescriptor(CapaFields, RawDescriptor):
|
||||
CapaDescriptor.force_save_button, CapaDescriptor.markdown,
|
||||
CapaDescriptor.text_customization])
|
||||
return non_editable_fields
|
||||
|
||||
# Proxy to CapaModule for access to any of its attributes
|
||||
answer_available = module_attr('answer_available')
|
||||
check_button_name = module_attr('check_button_name')
|
||||
check_problem = module_attr('check_problem')
|
||||
choose_new_seed = module_attr('choose_new_seed')
|
||||
closed = module_attr('closed')
|
||||
get_answer = module_attr('get_answer')
|
||||
get_problem = module_attr('get_problem')
|
||||
get_problem_html = module_attr('get_problem_html')
|
||||
get_state_for_lcp = module_attr('get_state_for_lcp')
|
||||
handle_input_ajax = module_attr('handle_input_ajax')
|
||||
handle_problem_html_error = module_attr('handle_problem_html_error')
|
||||
handle_ungraded_response = module_attr('handle_ungraded_response')
|
||||
is_attempted = module_attr('is_attempted')
|
||||
is_correct = module_attr('is_correct')
|
||||
is_past_due = module_attr('is_past_due')
|
||||
is_submitted = module_attr('is_submitted')
|
||||
lcp = module_attr('lcp')
|
||||
make_dict_of_responses = module_attr('make_dict_of_responses')
|
||||
new_lcp = module_attr('new_lcp')
|
||||
publish_grade = module_attr('publish_grade')
|
||||
rescore_problem = module_attr('rescore_problem')
|
||||
reset_problem = module_attr('reset_problem')
|
||||
save_problem = module_attr('save_problem')
|
||||
set_state_from_lcp = module_attr('set_state_from_lcp')
|
||||
should_show_check_button = module_attr('should_show_check_button')
|
||||
should_show_reset_button = module_attr('should_show_reset_button')
|
||||
should_show_save_button = module_attr('should_show_save_button')
|
||||
update_score = module_attr('update_score')
|
||||
|
||||
@@ -496,7 +496,7 @@ class CombinedOpenEndedDescriptor(CombinedOpenEndedFields, RawDescriptor):
|
||||
metadata_translations = {
|
||||
'is_graded': 'graded',
|
||||
'attempts': 'max_attempts',
|
||||
}
|
||||
}
|
||||
|
||||
def get_context(self):
|
||||
_context = RawDescriptor.get_context(self)
|
||||
|
||||
@@ -18,6 +18,7 @@ log = logging.getLogger('mitx.' + __name__)
|
||||
|
||||
|
||||
class ConditionalFields(object):
|
||||
has_children = True
|
||||
show_tag_list = List(help="Poll answers", scope=Scope.content)
|
||||
|
||||
|
||||
@@ -148,7 +149,7 @@ class ConditionalModule(ConditionalFields, XModule):
|
||||
context)
|
||||
return json.dumps({'html': [html], 'message': bool(message)})
|
||||
|
||||
html = [self.runtime.render_child(child, None, 'student_view').content for child in self.get_display_items()]
|
||||
html = [child.render('student_view').content for child in self.get_display_items()]
|
||||
|
||||
return json.dumps({'html': html})
|
||||
|
||||
|
||||
@@ -113,17 +113,17 @@ class CrowdsourceHinterModule(CrowdsourceHinterFields, XModule):
|
||||
|
||||
try:
|
||||
child = self.get_display_items()[0]
|
||||
out = self.runtime.render_child(child, None, 'student_view').content
|
||||
out = child.render('student_view').content
|
||||
# The event listener uses the ajax url to find the child.
|
||||
child_url = child.runtime.ajax_url
|
||||
child_id = child.id
|
||||
except IndexError:
|
||||
out = u"Error in loading crowdsourced hinter - can't find child problem."
|
||||
child_url = ''
|
||||
child_id = ''
|
||||
|
||||
# Wrap the module in a <section>. This lets us pass data attributes to the javascript.
|
||||
out += u'<section class="crowdsource-wrapper" data-url="{ajax_url}" data-child-url="{child_url}"> </section>'.format(
|
||||
out += u'<section class="crowdsource-wrapper" data-url="{ajax_url}" data-child-id="{child_id}"> </section>'.format(
|
||||
ajax_url=self.runtime.ajax_url,
|
||||
child_url=child_url
|
||||
child_id=child_id
|
||||
)
|
||||
|
||||
return out
|
||||
|
||||
@@ -2,8 +2,23 @@ div.lti {
|
||||
// align center
|
||||
margin: 0 auto;
|
||||
|
||||
h3.error_message {
|
||||
display: block;
|
||||
.wrapper-lti-link {
|
||||
@include font-size(14);
|
||||
position: relative;
|
||||
background-color: $sidebar-color;
|
||||
padding: ($baseline*1.8) ($baseline*1.5) ($baseline*1.1) $baseline;
|
||||
|
||||
.lti-link {
|
||||
position: absolute;
|
||||
top: ($baseline*1.8);
|
||||
right: $baseline;
|
||||
|
||||
.link_lti_new_window {
|
||||
@extend .gray-button;
|
||||
@include font-size(13);
|
||||
@include line-height(14);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
form.ltiLaunchForm {
|
||||
@@ -13,18 +28,8 @@ div.lti {
|
||||
iframe.ltiLaunchFrame {
|
||||
width: 100%;
|
||||
height: 800px;
|
||||
display: none;
|
||||
display: block;
|
||||
border: 0px;
|
||||
overflow-x: hidden;
|
||||
}
|
||||
|
||||
&.rendered {
|
||||
iframe.ltiLaunchFrame {
|
||||
display: block;
|
||||
}
|
||||
|
||||
h3.error_message {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,33 @@ div.video {
|
||||
height: 0px;
|
||||
}
|
||||
|
||||
.wrapper-downloads {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
|
||||
.video-sources,
|
||||
.video-tracks {
|
||||
display: inline-block;
|
||||
margin: ($baseline*.75) ($baseline/2) 0 0;
|
||||
|
||||
a {
|
||||
@include transition(all 0.25s ease-in-out 0s);
|
||||
@include font-size(14);
|
||||
display: inline-block;
|
||||
border-radius: 3px 3px 3px 3px;
|
||||
background-color: $very-light-text;
|
||||
padding: ($baseline*.75);
|
||||
color: $lighter-base-font-color;
|
||||
|
||||
&:hover {
|
||||
background-color: $action-primary-active-bg;
|
||||
color: $very-light-text;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
article.video-wrapper {
|
||||
float: left;
|
||||
margin-right: flex-gutter(9);
|
||||
@@ -392,7 +419,7 @@ div.video {
|
||||
@include transition(none);
|
||||
-webkit-font-smoothing: antialiased;
|
||||
width: 30px;
|
||||
|
||||
|
||||
&:hover, &:active {
|
||||
background-color: #444;
|
||||
color: #fff;
|
||||
@@ -457,7 +484,7 @@ div.video {
|
||||
text-indent: -9999px;
|
||||
@include transition(none);
|
||||
width: 30px;
|
||||
|
||||
|
||||
&:hover, &:active {
|
||||
background-color: #444;
|
||||
color: #fff;
|
||||
@@ -611,7 +638,6 @@ div.video {
|
||||
ol.subtitles {
|
||||
width: 0;
|
||||
height: 0;
|
||||
visibility: hidden;
|
||||
}
|
||||
|
||||
ol.subtitles.html5 {
|
||||
@@ -645,7 +671,6 @@ div.video {
|
||||
ol.subtitles {
|
||||
right: -(flex-grid(4));
|
||||
width: auto;
|
||||
visibility: hidden;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ class ErrorDescriptor(ErrorFields, XModuleDescriptor):
|
||||
module_class = ErrorModule
|
||||
|
||||
def get_html(self):
|
||||
return ''
|
||||
return u''
|
||||
|
||||
@classmethod
|
||||
def _construct(cls, system, contents, error_msg, location):
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<li id="vert-0" data-id="i4x://Me/19.002/crowdsource_hinter/crowdsource_hinter_def7a1142dd0">
|
||||
|
||||
|
||||
|
||||
<section class="xmodule_display xmodule_CrowdsourceHinterModule" data-type="Hinter" id="hinter-root">
|
||||
|
||||
|
||||
|
||||
<section class="xmodule_display xmodule_CapaModule" data-type="Problem" id="problem">
|
||||
<section id="problem_i4x-Me-19_002-problem-Numerical_Input" class="problems-wrapper" data-problem-id="i4x://Me/19.002/problem/Numerical_Input" data-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/problem/Numerical_Input" data-progress_status="done" data-progress_detail="1/1">
|
||||
@@ -44,7 +44,7 @@
|
||||
|
||||
|
||||
|
||||
<section class="crowdsource-wrapper" data-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/crowdsource_hinter/crowdsource_hinter_def7a1142dd0" data-child-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/problem/Numerical_Input" style="display: none;"> </section>
|
||||
<section class="crowdsource-wrapper" data-url="/courses/Me/19.002/Test/modx/i4x://Me/19.002/crowdsource_hinter/crowdsource_hinter_def7a1142dd0" data-child-id="i4x://Me/19.002/problem/Numerical_Input" style="display: none;"> </section>
|
||||
</section>
|
||||
|
||||
|
||||
|
||||
@@ -1,36 +1,31 @@
|
||||
<div id="lti_id" class="lti">
|
||||
<div class="lti-wrapper">
|
||||
<div id="lti_id" class="lti" data-open_in_a_new_page="true">
|
||||
|
||||
<form
|
||||
action="http://www.example.com"
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="ltiLaunchFrame"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
<form
|
||||
action=""
|
||||
name="ltiLaunchForm"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="_blank"
|
||||
enctype="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
<input name="lti_version" value="LTI-1p0" />
|
||||
<input name="user_id" value="student" />
|
||||
<input name="oauth_nonce" value="28347958723982798572" />
|
||||
<input name="oauth_timestamp" value="2389479832" />
|
||||
<input name="oauth_consumer_key" value="" />
|
||||
<input name="lis_result_sourcedid" value="" />
|
||||
<input name="oauth_signature_method" value="HMAC-SHA1" />
|
||||
<input name="oauth_version" value="1.0" />
|
||||
<input name="role" value="student" />
|
||||
<input name="lis_outcome_service_url" value="" />
|
||||
<input name="oauth_signature" value="89ru3289r3ry283y3r82ryr38yr" />
|
||||
<input name="lti_message_type" value="basic-lti-launch-request" />
|
||||
<input name="oauth_callback" value="about:blank" />
|
||||
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
<h3 class="error_message">
|
||||
Please provide launch_url. Click "Edit", and fill in the
|
||||
required fields.
|
||||
</h3>
|
||||
|
||||
<iframe name="ltiLaunchFrame" class="ltiLaunchFrame" src=""></iframe>
|
||||
<input type="submit" value="Press to Launch" />
|
||||
</form>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="focus_grabber first"></div>
|
||||
|
||||
@@ -44,7 +45,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="add-fullscreen" title="Fill browser" role="button" aria-disabled="false">Fill Browser</a>
|
||||
<a href="#" class="quality_control" title="HD" role="button" aria-disabled="false">HD</a>
|
||||
<a href="#" class="quality_control" title="HD off" role="button" aria-disabled="false">HD off</a>
|
||||
<a href="#" class="hide-subtitles" title="Turn off captions" role="button" aria-disabled="false">Captions</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="focus_grabber first"></div>
|
||||
|
||||
@@ -47,7 +48,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="add-fullscreen" title="Fill browser" role="button" aria-disabled="false">Fill Browser</a>
|
||||
<a href="#" class="quality_control" title="HD" role="button" aria-disabled="false">HD</a>
|
||||
<a href="#" class="quality_control" title="HD off" role="button" aria-disabled="false">HD off</a>
|
||||
<a href="#" class="hide-subtitles" title="Turn off captions" role="button" aria-disabled="false">Captions</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="focus_grabber first"></div>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="focus_grabber first"></div>
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="focus_grabber first"></div>
|
||||
|
||||
@@ -44,7 +45,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<a href="#" class="add-fullscreen" title="Fill browser" role="button" aria-disabled="false">Fill Browser</a>
|
||||
<a href="#" class="quality_control" title="HD" role="button" aria-disabled="false">HD</a>
|
||||
<a href="#" class="quality_control" title="HD off" role="button" aria-disabled="false">HD off</a>
|
||||
<a href="#" class="hide-subtitles" title="Turn off captions" role="button" aria-disabled="false">Captions</a>
|
||||
</div>
|
||||
</div>
|
||||
@@ -73,6 +74,8 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="tc-wrapper">
|
||||
<article class="video-wrapper">
|
||||
@@ -130,6 +133,8 @@
|
||||
data-autoplay="False"
|
||||
data-yt-test-timeout="1500"
|
||||
data-yt-test-url="https://gdata.youtube.com/feeds/api/videos/"
|
||||
|
||||
data-autohide-html5="True"
|
||||
>
|
||||
<div class="tc-wrapper">
|
||||
<article class="video-wrapper">
|
||||
|
||||
@@ -139,12 +139,12 @@ describe 'Problem', ->
|
||||
|
||||
it 'log the problem_graded event, after the problem is done grading.', ->
|
||||
spyOn($, 'postWithPrefix').andCallFake (url, answers, callback) ->
|
||||
response =
|
||||
response =
|
||||
success: 'correct'
|
||||
contents: 'mock grader response'
|
||||
callback(response)
|
||||
@problem.check()
|
||||
expect(Logger.log).toHaveBeenCalledWith 'problem_graded', ['foo=1&bar=2', 'mock grader response'], @problem.url
|
||||
expect(Logger.log).toHaveBeenCalledWith 'problem_graded', ['foo=1&bar=2', 'mock grader response'], @problem.id
|
||||
|
||||
it 'submit the answer for check', ->
|
||||
spyOn $, 'postWithPrefix'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Stub Youtube API
|
||||
window.YT =
|
||||
Player: ->
|
||||
PlayerState:
|
||||
UNSTARTED: -1
|
||||
ENDED: 0
|
||||
@@ -7,6 +8,7 @@ window.YT =
|
||||
PAUSED: 2
|
||||
BUFFERING: 3
|
||||
CUED: 5
|
||||
ready: (f) -> f()
|
||||
|
||||
window.STATUS = window.YT.PlayerState
|
||||
|
||||
@@ -58,7 +60,7 @@ window.jQuery.ajaxWithPrefix = (url, settings) ->
|
||||
oldAjaxWithPrefix.apply @, arguments
|
||||
|
||||
# Time waitsFor() should wait for before failing a test.
|
||||
window.WAIT_TIMEOUT = 1000
|
||||
window.WAIT_TIMEOUT = 5000
|
||||
|
||||
jasmine.getFixtures().fixturesPath += 'fixtures'
|
||||
|
||||
|
||||
@@ -5,77 +5,158 @@
|
||||
*
|
||||
*
|
||||
* The front-end part of the LTI module is really simple. If an action
|
||||
* is set for the hidden LTI form, then it is submited, and the results are
|
||||
* redirected to an iframe.
|
||||
* is set for the hidden LTI form, then it is submitted, and the results are
|
||||
* redirected to an iframe or to a new window (based on the
|
||||
* "open_in_a_new_page" attribute).
|
||||
*
|
||||
* We will test that the form is only submited when the action is set (i.e.
|
||||
* not empty).
|
||||
* We will test that the form is only submitted when the action is set (i.e.
|
||||
* not empty, and not the default one).
|
||||
*
|
||||
* Other aspects of LTI module will be covered by Python unit tests and
|
||||
* acceptance tests.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* "Hence that general is skilful in attack whose opponent does not know what
|
||||
* to defend; and he is skilful in defense whose opponent does not know what
|
||||
* "Hence that general is skillful in attack whose opponent does not know what
|
||||
* to defend; and he is skillful in defense whose opponent does not know what
|
||||
* to attack."
|
||||
*
|
||||
* ~ Sun Tzu
|
||||
*/
|
||||
|
||||
(function () {
|
||||
var element, container, form, link,
|
||||
IN_NEW_WINDOW = 'true',
|
||||
IN_IFRAME = 'false',
|
||||
EMPTY_URL = '',
|
||||
DEFAULT_URL = 'http://www.example.com',
|
||||
NEW_URL = 'http://www.example.com/some_book';
|
||||
|
||||
function initialize(target, action) {
|
||||
var tempEl;
|
||||
|
||||
loadFixtures('lti.html');
|
||||
|
||||
element = $('.lti-wrapper');
|
||||
container = element.find('.lti');
|
||||
form = container.find('.ltiLaunchForm');
|
||||
|
||||
if (target === IN_IFRAME) {
|
||||
container.data('open_in_a_new_page', 'false');
|
||||
form.attr('target', 'ltiLaunchFrame');
|
||||
}
|
||||
|
||||
form.attr('action', action);
|
||||
|
||||
// If we have a new proper action (non-default), we create either
|
||||
// a link that will submit the form, or an iframe that will contain
|
||||
// the answer of auto submitted form.
|
||||
if (action !== EMPTY_URL && action !== DEFAULT_URL) {
|
||||
if (target === IN_NEW_WINDOW) {
|
||||
$('<a />', {
|
||||
href: '#',
|
||||
class: 'link_lti_new_window'
|
||||
}).appendTo(container);
|
||||
|
||||
link = container.find('.link_lti_new_window');
|
||||
} else {
|
||||
$('<iframe />', {
|
||||
name: 'ltiLaunchFrame',
|
||||
class: 'ltiLaunchFrame',
|
||||
src: ''
|
||||
}).appendTo(container);
|
||||
}
|
||||
}
|
||||
|
||||
spyOnEvent(form, 'submit');
|
||||
|
||||
LTI(element);
|
||||
}
|
||||
|
||||
describe('LTI', function () {
|
||||
describe('constructor', function () {
|
||||
describe('before settings were filled in', function () {
|
||||
var element, errorMessage, frame;
|
||||
describe('initialize', function () {
|
||||
describe(
|
||||
'open_in_a_new_page is "true", launch URL is empty',
|
||||
function () {
|
||||
|
||||
// This function will be executed before each of the it() specs
|
||||
// in this suite.
|
||||
beforeEach(function () {
|
||||
loadFixtures('lti.html');
|
||||
|
||||
element = $('#lti_id');
|
||||
errorMessage = element.find('.error_message');
|
||||
form = element.find('.ltiLaunchForm');
|
||||
frame = element.find('.ltiLaunchFrame');
|
||||
|
||||
spyOnEvent(form, 'submit');
|
||||
|
||||
LTI(element);
|
||||
initialize(IN_NEW_WINDOW, EMPTY_URL);
|
||||
});
|
||||
|
||||
it(
|
||||
'when URL setting is not filled form is not submited',
|
||||
function () {
|
||||
|
||||
it('form is not submitted', function () {
|
||||
expect('submit').not.toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
describe('After the settings were filled in', function () {
|
||||
var element, errorMessage, frame;
|
||||
describe(
|
||||
'open_in_a_new_page is "true", launch URL is default',
|
||||
function () {
|
||||
|
||||
// This function will be executed before each of the it() specs
|
||||
// in this suite.
|
||||
beforeEach(function () {
|
||||
loadFixtures('lti.html');
|
||||
|
||||
element = $('#lti_id');
|
||||
errorMessage = element.find('.error_message');
|
||||
form = element.find('.ltiLaunchForm');
|
||||
frame = element.find('.ltiLaunchFrame');
|
||||
|
||||
spyOnEvent(form, 'submit');
|
||||
|
||||
// The user "fills in" the necessary settings, and the
|
||||
// form will get an action URL.
|
||||
form.attr('action', 'http://www.example.com/test_submit');
|
||||
|
||||
LTI(element);
|
||||
initialize(IN_NEW_WINDOW, DEFAULT_URL);
|
||||
});
|
||||
|
||||
it('when URL setting is filled form is submited', function () {
|
||||
it('form is not submitted', function () {
|
||||
expect('submit').not.toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'open_in_a_new_page is "true", launch URL is not empty, and ' +
|
||||
'not default',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize(IN_NEW_WINDOW, NEW_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
expect('submit').not.toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
|
||||
it('after link is clicked, form is submitted', function () {
|
||||
link.trigger('click');
|
||||
|
||||
expect('submit').toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'open_in_a_new_page is "false", launch URL is empty',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize(IN_IFRAME, EMPTY_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
expect('submit').not.toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'open_in_a_new_page is "false", launch URL is default',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize(IN_IFRAME, DEFAULT_URL);
|
||||
});
|
||||
|
||||
it('form is not submitted', function () {
|
||||
expect('submit').not.toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'open_in_a_new_page is "false", launch URL is not empty, ' +
|
||||
'and not default',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize(IN_IFRAME, NEW_URL);
|
||||
});
|
||||
|
||||
it('form is submitted', function () {
|
||||
expect('submit').toHaveBeenTriggeredOn(form);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
|
||||
afterEach(function () {
|
||||
window.OldVideoPlayer = undefined;
|
||||
window.onYouTubePlayerAPIReady = undefined;
|
||||
window.onHTML5PlayerAPIReady = undefined;
|
||||
$('source').remove();
|
||||
});
|
||||
|
||||
@@ -214,14 +212,23 @@
|
||||
// Total ajax calls made.
|
||||
numAjaxCalls = $.ajax.calls.length;
|
||||
|
||||
// Subtract ajax calls to get captions.
|
||||
// Subtract ajax calls to get captions via
|
||||
// state.videoCaption.fetchCaption() function.
|
||||
numAjaxCalls -= $.ajaxWithPrefix.calls.length;
|
||||
|
||||
// Subtract ajax calls to get metadata for each video.
|
||||
// Subtract ajax calls to get metadata for each video via
|
||||
// state.getVideoMetadata() function.
|
||||
numAjaxCalls -= 3;
|
||||
|
||||
// Subtract ajax calls to log event 'pause_video' via
|
||||
// state.videoPlayer.log() function.
|
||||
numAjaxCalls -= 3;
|
||||
|
||||
// This should leave just one call. It was made to check
|
||||
// for YT availability.
|
||||
// for YT availability. This is done in state.initialize()
|
||||
// function. SPecifically, with the statement
|
||||
//
|
||||
// this.youtubeXhr = this.getVideoMetadata();
|
||||
expect(numAjaxCalls).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
YT.Player = void 0;
|
||||
state = undefined;
|
||||
$.fn.scrollTo.reset();
|
||||
$('.subtitles').remove();
|
||||
$('source').remove();
|
||||
@@ -28,7 +28,7 @@
|
||||
spyOn(player, 'callStateChangeCallback').andCallThrough();
|
||||
});
|
||||
|
||||
describe('click', function () {
|
||||
describe('[click]', function () {
|
||||
describe('when player is paused', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(player.video, 'play').andCallThrough();
|
||||
@@ -40,10 +40,7 @@
|
||||
expect(player.video.play).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// Fails with "timeout: timed out after 1000 msec waiting for Player state should be changed"
|
||||
// on Firefox
|
||||
xit('player state was changed', function () {
|
||||
it('player state was changed', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.PAUSED;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
@@ -63,41 +60,41 @@
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when player is played', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(player.video, 'pause').andCallThrough();
|
||||
player.playerState = STATUS.PLAYING;
|
||||
$(player.videoEl).trigger('click');
|
||||
});
|
||||
|
||||
it('native event was called', function () {
|
||||
expect(player.video.pause).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('player state was changed', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(player.getPlayerState()).toBe(STATUS.PAUSED);
|
||||
describe('[player is playing]', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(player.video, 'pause').andCallThrough();
|
||||
player.playerState = STATUS.PLAYING;
|
||||
$(player.videoEl).trigger('click');
|
||||
});
|
||||
});
|
||||
|
||||
it('callback was called', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
it('native event was called', function () {
|
||||
expect(player.video.pause).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
runs(function () {
|
||||
expect(player.callStateChangeCallback).toHaveBeenCalled();
|
||||
it('player state was changed', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(player.getPlayerState()).toBe(STATUS.PAUSED);
|
||||
});
|
||||
});
|
||||
|
||||
it('callback was called', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
expect(player.callStateChangeCallback).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('play', function () {
|
||||
describe('[play]', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(player.video, 'play').andCallThrough();
|
||||
player.playerState = STATUS.PAUSED;
|
||||
@@ -129,10 +126,14 @@
|
||||
});
|
||||
});
|
||||
|
||||
describe('pause', function () {
|
||||
describe('[pause]', function () {
|
||||
beforeEach(function () {
|
||||
spyOn(player.video, 'pause').andCallThrough();
|
||||
player.playerState = STATUS.UNSTARTED;
|
||||
player.playVideo();
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.UNSTARTED;
|
||||
}, 'Video never started playing', WAIT_TIMEOUT);
|
||||
player.pauseVideo();
|
||||
});
|
||||
|
||||
@@ -142,7 +143,7 @@
|
||||
|
||||
it('player state was changed', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.UNSTARTED;
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
|
||||
runs(function () {
|
||||
@@ -152,7 +153,7 @@
|
||||
|
||||
it('callback was called', function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.UNSTARTED;
|
||||
return player.getPlayerState() !== STATUS.PLAYING;
|
||||
}, 'Player state should be changed', WAIT_TIMEOUT);
|
||||
runs(function () {
|
||||
expect(player.callStateChangeCallback).toHaveBeenCalled();
|
||||
@@ -160,7 +161,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
describe('canplay', function () {
|
||||
describe('[canplay]', function () {
|
||||
beforeEach(function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.UNSTARTED;
|
||||
@@ -192,7 +193,7 @@
|
||||
});
|
||||
});
|
||||
|
||||
describe('ended', function () {
|
||||
describe('[ended]', function () {
|
||||
beforeEach(function () {
|
||||
waitsFor(function () {
|
||||
return player.getPlayerState() !== STATUS.UNSTARTED;
|
||||
|
||||
@@ -1,673 +1,798 @@
|
||||
(function() {
|
||||
describe('VideoCaption', function() {
|
||||
var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD;
|
||||
(function () {
|
||||
describe('VideoCaption', function () {
|
||||
var state, videoPlayer, videoCaption, videoSpeedControl, oldOTBD;
|
||||
|
||||
function initialize() {
|
||||
loadFixtures('video_all.html');
|
||||
state = new Video('#example');
|
||||
videoPlayer = state.videoPlayer;
|
||||
videoCaption = state.videoCaption;
|
||||
videoSpeedControl = state.videoSpeedControl;
|
||||
videoControl = state.videoControl;
|
||||
}
|
||||
function initialize() {
|
||||
loadFixtures('video_all.html');
|
||||
state = new Video('#example');
|
||||
videoPlayer = state.videoPlayer;
|
||||
videoCaption = state.videoCaption;
|
||||
videoSpeedControl = state.videoSpeedControl;
|
||||
videoControl = state.videoControl;
|
||||
}
|
||||
|
||||
beforeEach(function() {
|
||||
oldOTBD = window.onTouchBasedDevice;
|
||||
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice').andReturn(false);
|
||||
initialize();
|
||||
});
|
||||
|
||||
afterEach(function() {
|
||||
YT.Player = void 0;
|
||||
$.fn.scrollTo.reset();
|
||||
$('.subtitles').remove();
|
||||
$('source').remove();
|
||||
window.onTouchBasedDevice = oldOTBD;
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
describe('always', function() {
|
||||
beforeEach(function() {
|
||||
spyOn($, 'ajaxWithPrefix').andCallThrough();
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('create the caption element', function() {
|
||||
expect($('.video')).toContain('ol.subtitles');
|
||||
});
|
||||
|
||||
it('add caption control to video player', function() {
|
||||
expect($('.video')).toContain('a.hide-subtitles');
|
||||
});
|
||||
|
||||
it('fetch the caption', function() {
|
||||
waitsFor(function () {
|
||||
if (videoCaption.loaded === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}, 'Expect captions to be loaded.', 1000);
|
||||
|
||||
runs(function () {
|
||||
expect($.ajaxWithPrefix).toHaveBeenCalledWith({
|
||||
url: videoCaption.captionURL(),
|
||||
notifyOnError: false,
|
||||
success: jasmine.any(Function),
|
||||
error: jasmine.any(Function),
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('bind window resize event', function() {
|
||||
expect($(window)).toHandleWith('resize', videoCaption.resize);
|
||||
});
|
||||
|
||||
it('bind the hide caption button', function() {
|
||||
expect($('.hide-subtitles')).toHandleWith('click', videoCaption.toggle);
|
||||
});
|
||||
|
||||
it('bind the mouse movement', function() {
|
||||
expect($('.subtitles')).toHandleWith('mouseover', videoCaption.onMouseEnter);
|
||||
expect($('.subtitles')).toHandleWith('mouseout', videoCaption.onMouseLeave);
|
||||
expect($('.subtitles')).toHandleWith('mousemove', videoCaption.onMovement);
|
||||
expect($('.subtitles')).toHandleWith('mousewheel', videoCaption.onMovement);
|
||||
expect($('.subtitles')).toHandleWith('DOMMouseScroll', videoCaption.onMovement);
|
||||
});
|
||||
|
||||
it('bind the scroll', function() {
|
||||
expect($('.subtitles')).toHandleWith('scroll', videoCaption.autoShowCaptions);
|
||||
expect($('.subtitles')).toHandleWith('scroll', videoControl.showControls);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when on a non touch-based device', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('render the caption', function() {
|
||||
var captionsData;
|
||||
|
||||
captionsData = jasmine.stubbedCaption;
|
||||
$('.subtitles li[data-index]').each(function(index, link) {
|
||||
expect($(link)).toHaveData('index', index);
|
||||
expect($(link)).toHaveData('start', captionsData.start[index]);
|
||||
expect($(link)).toHaveAttr('tabindex', 0);
|
||||
expect($(link)).toHaveText(captionsData.text[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it('add a padding element to caption', function() {
|
||||
expect($('.subtitles li:first').hasClass('spacing')).toBe(true);
|
||||
expect($('.subtitles li:last').hasClass('spacing')).toBe(true);
|
||||
});
|
||||
|
||||
it('bind all the caption link', function() {
|
||||
$('.subtitles li[data-index]').each(function(index, link) {
|
||||
expect($(link)).toHandleWith('mouseover', videoCaption.captionMouseOverOut);
|
||||
expect($(link)).toHandleWith('mouseout', videoCaption.captionMouseOverOut);
|
||||
expect($(link)).toHandleWith('mousedown', videoCaption.captionMouseDown);
|
||||
expect($(link)).toHandleWith('click', videoCaption.captionClick);
|
||||
expect($(link)).toHandleWith('focus', videoCaption.captionFocus);
|
||||
expect($(link)).toHandleWith('blur', videoCaption.captionBlur);
|
||||
expect($(link)).toHandleWith('keydown', videoCaption.captionKeyDown);
|
||||
});
|
||||
});
|
||||
|
||||
it('set rendered to true', function() {
|
||||
expect(videoCaption.rendered).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when on a touch-based device', function() {
|
||||
beforeEach(function() {
|
||||
window.onTouchBasedDevice.andReturn(true);
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('show explaination message', function() {
|
||||
expect($('.subtitles li')).toHaveHtml("Caption will be displayed when you start playing the video.");
|
||||
});
|
||||
|
||||
it('does not set rendered to true', function() {
|
||||
expect(videoCaption.rendered).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when no captions file was specified', function () {
|
||||
beforeEach(function () {
|
||||
loadFixtures('video_all.html');
|
||||
|
||||
// Unspecify the captions file.
|
||||
$('#example').find('#video_id').data('sub', '');
|
||||
|
||||
state = new Video('#example');
|
||||
videoCaption = state.videoCaption;
|
||||
});
|
||||
|
||||
it('captions panel is not shown', function () {
|
||||
expect(videoCaption.hideSubtitlesEl).toBeHidden();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('mouse movement', function() {
|
||||
// We will store default window.setTimeout() function here.
|
||||
var oldSetTimeout = null;
|
||||
|
||||
beforeEach(function() {
|
||||
// Store original window.setTimeout() function. If we do not do this, then
|
||||
// all other tests that rely on code which uses window.setTimeout()
|
||||
// function might (and probably will) fail.
|
||||
oldSetTimeout = window.setTimeout;
|
||||
// Redefine window.setTimeout() function as a spy.
|
||||
window.setTimeout = jasmine.createSpy().andCallFake(function(callback, timeout) { return 5; })
|
||||
window.setTimeout.andReturn(100);
|
||||
spyOn(window, 'clearTimeout');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
// Reset the default window.setTimeout() function. If we do not do this,
|
||||
// then all other tests that rely on code which uses window.setTimeout()
|
||||
// function might (and probably will) fail.
|
||||
window.setTimeout = oldSetTimeout;
|
||||
});
|
||||
|
||||
describe('when cursor is outside of the caption box', function() {
|
||||
beforeEach(function() {
|
||||
$(window).trigger(jQuery.Event('mousemove'));
|
||||
});
|
||||
|
||||
it('does not set freezing timeout', function() {
|
||||
expect(videoCaption.frozen).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when cursor is in the caption box', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles').trigger(jQuery.Event('mouseenter'));
|
||||
});
|
||||
|
||||
it('set the freezing timeout', function() {
|
||||
expect(videoCaption.frozen).toEqual(100);
|
||||
});
|
||||
|
||||
describe('when the cursor is moving', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles').trigger(jQuery.Event('mousemove'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function() {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the mouse is scrolling', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles').trigger(jQuery.Event('mousewheel'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function() {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when cursor is moving out of the caption box', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.frozen = 100;
|
||||
$.fn.scrollTo.reset();
|
||||
});
|
||||
|
||||
describe('always', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function() {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
|
||||
it('unfreeze the caption', function() {
|
||||
expect(videoCaption.frozen).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player is playing', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.playing = true;
|
||||
$('.subtitles li[data-index]:first').addClass('current');
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('scroll the caption', function() {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player is not playing', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.playing = false;
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function() {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', function() {
|
||||
it('return a correct caption index', function() {
|
||||
expect(videoCaption.search(0)).toEqual(-1);
|
||||
expect(videoCaption.search(3120)).toEqual(1);
|
||||
expect(videoCaption.search(6270)).toEqual(2);
|
||||
expect(videoCaption.search(8490)).toEqual(2);
|
||||
expect(videoCaption.search(21620)).toEqual(4);
|
||||
expect(videoCaption.search(24920)).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('play', function() {
|
||||
describe('when the caption was not rendered', function() {
|
||||
beforeEach(function() {
|
||||
window.onTouchBasedDevice.andReturn(true);
|
||||
initialize();
|
||||
videoCaption.play();
|
||||
});
|
||||
|
||||
it('render the caption', function() {
|
||||
var captionsData;
|
||||
|
||||
captionsData = jasmine.stubbedCaption;
|
||||
$('.subtitles li[data-index]').each(function(index, link) {
|
||||
expect($(link)).toHaveData('index', index);
|
||||
expect($(link)).toHaveData('start', captionsData.start[index]);
|
||||
expect($(link)).toHaveAttr('tabindex', 0);
|
||||
expect($(link)).toHaveText(captionsData.text[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it('add a padding element to caption', function() {
|
||||
expect($('.subtitles li:first')).toBe('.spacing');
|
||||
expect($('.subtitles li:last')).toBe('.spacing');
|
||||
});
|
||||
|
||||
it('bind all the caption link', function() {
|
||||
$('.subtitles li[data-index]').each(function(index, link) {
|
||||
expect($(link)).toHandleWith('mouseover', videoCaption.captionMouseOverOut);
|
||||
expect($(link)).toHandleWith('mouseout', videoCaption.captionMouseOverOut);
|
||||
expect($(link)).toHandleWith('mousedown', videoCaption.captionMouseDown);
|
||||
expect($(link)).toHandleWith('click', videoCaption.captionClick);
|
||||
expect($(link)).toHandleWith('focus', videoCaption.captionFocus);
|
||||
expect($(link)).toHandleWith('blur', videoCaption.captionBlur);
|
||||
expect($(link)).toHandleWith('keydown', videoCaption.captionKeyDown);
|
||||
});
|
||||
});
|
||||
|
||||
it('set rendered to true', function() {
|
||||
expect(videoCaption.rendered).toBeTruthy();
|
||||
});
|
||||
|
||||
it('set playing to true', function() {
|
||||
expect(videoCaption.playing).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pause', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.playing = true;
|
||||
videoCaption.pause();
|
||||
});
|
||||
|
||||
it('set playing to false', function() {
|
||||
expect(videoCaption.playing).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('updatePlayTime', function() {
|
||||
describe('when the video speed is 1.0x', function() {
|
||||
beforeEach(function() {
|
||||
videoSpeedControl.currentSpeed = '1.0';
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('search the caption based on time', function() {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the video speed is not 1.0x', function() {
|
||||
beforeEach(function() {
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('search the caption based on 1.0x speed', function() {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the index is not the same', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.currentIndex = 1;
|
||||
$('.subtitles li[data-index=5]').addClass('current');
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('deactivate the previous caption', function() {
|
||||
expect($('.subtitles li[data-index=1]')).not.toHaveClass('current');
|
||||
});
|
||||
|
||||
it('activate new caption', function() {
|
||||
expect($('.subtitles li[data-index=5]')).toHaveClass('current');
|
||||
});
|
||||
|
||||
it('save new index', function() {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
|
||||
it('scroll caption to new position', function() {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the index is the same', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.currentIndex = 1;
|
||||
$('.subtitles li[data-index=3]').addClass('current');
|
||||
videoCaption.updatePlayTime(15.000);
|
||||
});
|
||||
|
||||
it('does not change current subtitle', function() {
|
||||
expect($('.subtitles li[data-index=3]')).toHaveClass('current');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('resize', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.resize();
|
||||
});
|
||||
|
||||
describe('set the height of caption container', function(){
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// with error "Expected 745 to be close to 805, 2." in Firefox
|
||||
xit('when CC button is enabled', function() {
|
||||
var realHeight = parseInt($('.subtitles').css('maxHeight'), 10),
|
||||
shouldBeHeight = $('.video-wrapper').height();
|
||||
|
||||
// Because of some problems with rounding on different enviroments:
|
||||
// Linux * Mac * FF * Chrome
|
||||
expect(realHeight).toBeCloseTo(shouldBeHeight, 2);
|
||||
});
|
||||
|
||||
it('when CC button is disabled ', function() {
|
||||
var realHeight, videoWrapperHeight, progressSliderHeight,
|
||||
controlHeight, shouldBeHeight;
|
||||
|
||||
state.captionsHidden = true;
|
||||
videoCaption.setSubtitlesHeight();
|
||||
|
||||
realHeight = parseInt($('.subtitles').css('maxHeight'), 10);
|
||||
videoWrapperHeight = $('.video-wrapper').height();
|
||||
progressSliderHeight = videoControl.sliderEl.height();
|
||||
controlHeight = videoControl.el.height();
|
||||
shouldBeHeight = videoWrapperHeight -
|
||||
0.5 * progressSliderHeight -
|
||||
controlHeight;
|
||||
|
||||
expect(realHeight).toBe(shouldBeHeight);
|
||||
});
|
||||
});
|
||||
|
||||
it('set the height of caption spacing', function() {
|
||||
var firstSpacing, lastSpacing;
|
||||
firstSpacing = Math.abs(parseInt($('.subtitles .spacing:first').css('height'), 10));
|
||||
lastSpacing = Math.abs(parseInt($('.subtitles .spacing:last').css('height'), 10));
|
||||
expect(firstSpacing - videoCaption.topSpacingHeight()).toBeLessThan(1);
|
||||
expect(lastSpacing - videoCaption.bottomSpacingHeight()).toBeLessThan(1);
|
||||
});
|
||||
|
||||
it('scroll caption to new position', function() {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('scrollCaption', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
});
|
||||
|
||||
describe('when frozen', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.frozen = true;
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function() {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not frozen', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.frozen = false;
|
||||
});
|
||||
|
||||
describe('when there is no current caption', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function() {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there is a current caption', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('scroll to current caption', function() {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('seekPlayer', function() {
|
||||
describe('when the video speed is 1.0x', function() {
|
||||
beforeEach(function() {
|
||||
videoSpeedControl.currentSpeed = '1.0';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// Fails with error: "InvalidStateError: An attempt was made to
|
||||
// use an object that is not, or is no longer, usable
|
||||
// Expected 0 to equal 14.91."
|
||||
// on Firefox
|
||||
xit('trigger seek event with the correct time', function() {
|
||||
expect(videoPlayer.currentTime).toEqual(14.91);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the video speed is not 1.0x', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
it('trigger seek event with the correct time', function() {
|
||||
expect(videoPlayer.currentTime).toEqual(14.91);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player type is Flash at speed 0.75x', function () {
|
||||
beforeEach(function () {
|
||||
oldOTBD = window.onTouchBasedDevice;
|
||||
window.onTouchBasedDevice = jasmine.createSpy('onTouchBasedDevice')
|
||||
.andReturn(false);
|
||||
initialize();
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
state.currentPlayerMode = 'flash';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
it('trigger seek event with the correct time', function () {
|
||||
expect(videoPlayer.currentTime).toEqual(15);
|
||||
afterEach(function () {
|
||||
YT.Player = undefined;
|
||||
$.fn.scrollTo.reset();
|
||||
$('.subtitles').remove();
|
||||
$('source').remove();
|
||||
window.onTouchBasedDevice = oldOTBD;
|
||||
});
|
||||
|
||||
describe('constructor', function () {
|
||||
describe('always', function () {
|
||||
beforeEach(function () {
|
||||
spyOn($, 'ajaxWithPrefix').andCallThrough();
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('create the caption element', function () {
|
||||
expect($('.video')).toContain('ol.subtitles');
|
||||
});
|
||||
|
||||
it('add caption control to video player', function () {
|
||||
expect($('.video')).toContain('a.hide-subtitles');
|
||||
});
|
||||
|
||||
it('fetch the caption', function () {
|
||||
waitsFor(function () {
|
||||
if (videoCaption.loaded === true) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}, 'Expect captions to be loaded.', 1000);
|
||||
|
||||
runs(function () {
|
||||
expect($.ajaxWithPrefix).toHaveBeenCalledWith({
|
||||
url: videoCaption.captionURL(),
|
||||
notifyOnError: false,
|
||||
success: jasmine.any(Function),
|
||||
error: jasmine.any(Function)
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('bind window resize event', function () {
|
||||
expect($(window)).toHandleWith(
|
||||
'resize', videoCaption.resize
|
||||
);
|
||||
});
|
||||
|
||||
it('bind the hide caption button', function () {
|
||||
expect($('.hide-subtitles')).toHandleWith(
|
||||
'click', videoCaption.toggle
|
||||
);
|
||||
});
|
||||
|
||||
it('bind the mouse movement', function () {
|
||||
expect($('.subtitles')).toHandleWith(
|
||||
'mouseover', videoCaption.onMouseEnter
|
||||
);
|
||||
expect($('.subtitles')).toHandleWith(
|
||||
'mouseout', videoCaption.onMouseLeave
|
||||
);
|
||||
expect($('.subtitles')).toHandleWith(
|
||||
'mousemove', videoCaption.onMovement
|
||||
);
|
||||
expect($('.subtitles')).toHandleWith(
|
||||
'mousewheel', videoCaption.onMovement
|
||||
);
|
||||
expect($('.subtitles')).toHandleWith(
|
||||
'DOMMouseScroll', videoCaption.onMovement
|
||||
);
|
||||
});
|
||||
|
||||
it('bind the scroll', function () {
|
||||
expect($('.subtitles'))
|
||||
.toHandleWith('scroll', videoCaption.autoShowCaptions);
|
||||
expect($('.subtitles'))
|
||||
.toHandleWith('scroll', videoControl.showControls);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when on a non touch-based device', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('render the caption', function () {
|
||||
var captionsData;
|
||||
|
||||
captionsData = jasmine.stubbedCaption;
|
||||
$('.subtitles li[data-index]').each(
|
||||
function (index, link) {
|
||||
|
||||
expect($(link)).toHaveData('index', index);
|
||||
expect($(link)).toHaveData(
|
||||
'start', captionsData.start[index]
|
||||
);
|
||||
expect($(link)).toHaveAttr('tabindex', 0);
|
||||
expect($(link)).toHaveText(captionsData.text[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it('add a padding element to caption', function () {
|
||||
expect($('.subtitles li:first').hasClass('spacing'))
|
||||
.toBe(true);
|
||||
expect($('.subtitles li:last').hasClass('spacing'))
|
||||
.toBe(true);
|
||||
});
|
||||
|
||||
it('bind all the caption link', function () {
|
||||
$('.subtitles li[data-index]').each(
|
||||
function (index, link) {
|
||||
|
||||
expect($(link)).toHandleWith(
|
||||
'mouseover', videoCaption.captionMouseOverOut
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'mouseout', videoCaption.captionMouseOverOut
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'mousedown', videoCaption.captionMouseDown
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'click', videoCaption.captionClick
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'focus', videoCaption.captionFocus
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'blur', videoCaption.captionBlur
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'keydown', videoCaption.captionKeyDown
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('set rendered to true', function () {
|
||||
expect(videoCaption.rendered).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when on a touch-based device', function () {
|
||||
beforeEach(function () {
|
||||
window.onTouchBasedDevice.andReturn(true);
|
||||
initialize();
|
||||
});
|
||||
|
||||
it('show explaination message', function () {
|
||||
expect($('.subtitles li')).toHaveHtml(
|
||||
'Caption will be displayed when you start playing ' +
|
||||
'the video.'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not set rendered to true', function () {
|
||||
expect(videoCaption.rendered).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when no captions file was specified', function () {
|
||||
beforeEach(function () {
|
||||
loadFixtures('video_all.html');
|
||||
|
||||
// Unspecify the captions file.
|
||||
$('#example').find('#video_id').data('sub', '');
|
||||
|
||||
state = new Video('#example');
|
||||
videoCaption = state.videoCaption;
|
||||
});
|
||||
|
||||
it('captions panel is not shown', function () {
|
||||
expect(videoCaption.hideSubtitlesEl).toBeHidden();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('mouse movement', function () {
|
||||
// We will store default window.setTimeout() function here.
|
||||
var oldSetTimeout = null;
|
||||
|
||||
beforeEach(function () {
|
||||
// Store original window.setTimeout() function. If we do not do
|
||||
// this, then all other tests that rely on code which uses
|
||||
// window.setTimeout() function might (and probably will) fail.
|
||||
oldSetTimeout = window.setTimeout;
|
||||
// Redefine window.setTimeout() function as a spy.
|
||||
window.setTimeout = jasmine.createSpy().andCallFake(
|
||||
function (callback, timeout) {
|
||||
return 5;
|
||||
}
|
||||
);
|
||||
window.setTimeout.andReturn(100);
|
||||
spyOn(window, 'clearTimeout');
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
// Reset the default window.setTimeout() function. If we do not
|
||||
// do this, then all other tests that rely on code which uses
|
||||
// window.setTimeout() function might (and probably will) fail.
|
||||
window.setTimeout = oldSetTimeout;
|
||||
});
|
||||
|
||||
describe('when cursor is outside of the caption box', function () {
|
||||
beforeEach(function () {
|
||||
$(window).trigger(jQuery.Event('mousemove'));
|
||||
});
|
||||
|
||||
it('does not set freezing timeout', function () {
|
||||
expect(videoCaption.frozen).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when cursor is in the caption box', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles').trigger(jQuery.Event('mouseenter'));
|
||||
});
|
||||
|
||||
it('set the freezing timeout', function () {
|
||||
expect(videoCaption.frozen).toEqual(100);
|
||||
});
|
||||
|
||||
describe('when the cursor is moving', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles').trigger(jQuery.Event('mousemove'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function () {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the mouse is scrolling', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles').trigger(jQuery.Event('mousewheel'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function () {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'when cursor is moving out of the caption box',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
videoCaption.frozen = 100;
|
||||
$.fn.scrollTo.reset();
|
||||
});
|
||||
|
||||
describe('always', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('reset the freezing timeout', function () {
|
||||
expect(window.clearTimeout).toHaveBeenCalledWith(100);
|
||||
});
|
||||
|
||||
it('unfreeze the caption', function () {
|
||||
expect(videoCaption.frozen).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player is playing', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.playing = true;
|
||||
$('.subtitles li[data-index]:first')
|
||||
.addClass('current');
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('scroll the caption', function () {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player is not playing', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.playing = false;
|
||||
$('.subtitles').trigger(jQuery.Event('mouseout'));
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function () {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('search', function () {
|
||||
it('return a correct caption index', function () {
|
||||
expect(videoCaption.search(0)).toEqual(-1);
|
||||
expect(videoCaption.search(3120)).toEqual(1);
|
||||
expect(videoCaption.search(6270)).toEqual(2);
|
||||
expect(videoCaption.search(8490)).toEqual(2);
|
||||
expect(videoCaption.search(21620)).toEqual(4);
|
||||
expect(videoCaption.search(24920)).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('play', function () {
|
||||
describe('when the caption was not rendered', function () {
|
||||
beforeEach(function () {
|
||||
window.onTouchBasedDevice.andReturn(true);
|
||||
initialize();
|
||||
videoCaption.play();
|
||||
});
|
||||
|
||||
it('render the caption', function () {
|
||||
var captionsData;
|
||||
|
||||
captionsData = jasmine.stubbedCaption;
|
||||
$('.subtitles li[data-index]').each(
|
||||
function (index, link) {
|
||||
|
||||
expect($(link)).toHaveData('index', index);
|
||||
expect($(link)).toHaveData(
|
||||
'start', captionsData.start[index]
|
||||
);
|
||||
expect($(link)).toHaveAttr('tabindex', 0);
|
||||
expect($(link)).toHaveText(captionsData.text[index]);
|
||||
});
|
||||
});
|
||||
|
||||
it('add a padding element to caption', function () {
|
||||
expect($('.subtitles li:first')).toBe('.spacing');
|
||||
expect($('.subtitles li:last')).toBe('.spacing');
|
||||
});
|
||||
|
||||
it('bind all the caption link', function () {
|
||||
$('.subtitles li[data-index]').each(
|
||||
function (index, link) {
|
||||
|
||||
expect($(link)).toHandleWith(
|
||||
'mouseover', videoCaption.captionMouseOverOut
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'mouseout', videoCaption.captionMouseOverOut
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'mousedown', videoCaption.captionMouseDown
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'click', videoCaption.captionClick
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'focus', videoCaption.captionFocus
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'blur', videoCaption.captionBlur
|
||||
);
|
||||
expect($(link)).toHandleWith(
|
||||
'keydown', videoCaption.captionKeyDown
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('set rendered to true', function () {
|
||||
expect(videoCaption.rendered).toBeTruthy();
|
||||
});
|
||||
|
||||
it('set playing to true', function () {
|
||||
expect(videoCaption.playing).toBeTruthy();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('pause', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.playing = true;
|
||||
videoCaption.pause();
|
||||
});
|
||||
|
||||
it('set playing to false', function () {
|
||||
expect(videoCaption.playing).toBeFalsy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('updatePlayTime', function () {
|
||||
describe('when the video speed is 1.0x', function () {
|
||||
beforeEach(function () {
|
||||
videoSpeedControl.currentSpeed = '1.0';
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('search the caption based on time', function () {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the video speed is not 1.0x', function () {
|
||||
beforeEach(function () {
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('search the caption based on 1.0x speed', function () {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the index is not the same', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.currentIndex = 1;
|
||||
$('.subtitles li[data-index=5]').addClass('current');
|
||||
videoCaption.updatePlayTime(25.000);
|
||||
});
|
||||
|
||||
it('deactivate the previous caption', function () {
|
||||
expect($('.subtitles li[data-index=1]'))
|
||||
.not.toHaveClass('current');
|
||||
});
|
||||
|
||||
it('activate new caption', function () {
|
||||
expect($('.subtitles li[data-index=5]'))
|
||||
.toHaveClass('current');
|
||||
});
|
||||
|
||||
it('save new index', function () {
|
||||
expect(videoCaption.currentIndex).toEqual(5);
|
||||
});
|
||||
|
||||
it('scroll caption to new position', function () {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the index is the same', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.currentIndex = 1;
|
||||
$('.subtitles li[data-index=3]').addClass('current');
|
||||
videoCaption.updatePlayTime(15.000);
|
||||
});
|
||||
|
||||
it('does not change current subtitle', function () {
|
||||
expect($('.subtitles li[data-index=3]'))
|
||||
.toHaveClass('current');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('resize', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.resize();
|
||||
});
|
||||
|
||||
describe('set the height of caption container', function () {
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// with error "Expected 745 to be close to 805, 2." in Firefox
|
||||
xit('when CC button is enabled', function () {
|
||||
var realHeight = parseInt(
|
||||
$('.subtitles').css('maxHeight'), 10
|
||||
),
|
||||
shouldBeHeight = $('.video-wrapper').height();
|
||||
|
||||
// Because of some problems with rounding on different
|
||||
// environments: Linux * Mac * FF * Chrome
|
||||
expect(realHeight).toBeCloseTo(shouldBeHeight, 2);
|
||||
});
|
||||
|
||||
it('when CC button is disabled ', function () {
|
||||
var realHeight, videoWrapperHeight, progressSliderHeight,
|
||||
controlHeight, shouldBeHeight;
|
||||
|
||||
state.captionsHidden = true;
|
||||
videoCaption.setSubtitlesHeight();
|
||||
|
||||
realHeight = parseInt(
|
||||
$('.subtitles').css('maxHeight'), 10
|
||||
);
|
||||
videoWrapperHeight = $('.video-wrapper').height();
|
||||
progressSliderHeight = videoControl.sliderEl.height();
|
||||
controlHeight = videoControl.el.height();
|
||||
shouldBeHeight = videoWrapperHeight -
|
||||
0.5 * progressSliderHeight -
|
||||
controlHeight;
|
||||
|
||||
expect(realHeight).toBe(shouldBeHeight);
|
||||
});
|
||||
});
|
||||
|
||||
it('set the height of caption spacing', function () {
|
||||
var firstSpacing, lastSpacing;
|
||||
|
||||
firstSpacing = Math.abs(parseInt(
|
||||
$('.subtitles .spacing:first').css('height'), 10
|
||||
));
|
||||
lastSpacing = Math.abs(parseInt(
|
||||
$('.subtitles .spacing:last').css('height'), 10
|
||||
));
|
||||
|
||||
expect(firstSpacing - videoCaption.topSpacingHeight())
|
||||
.toBeLessThan(1);
|
||||
expect(lastSpacing - videoCaption.bottomSpacingHeight())
|
||||
.toBeLessThan(1);
|
||||
});
|
||||
|
||||
it('scroll caption to new position', function () {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('scrollCaption', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
});
|
||||
|
||||
describe('when frozen', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.frozen = true;
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function () {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when not frozen', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.frozen = false;
|
||||
});
|
||||
|
||||
describe('when there is no current caption', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('does not scroll the caption', function () {
|
||||
expect($.fn.scrollTo).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when there is a current caption', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
videoCaption.scrollCaption();
|
||||
});
|
||||
|
||||
it('scroll to current caption', function () {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('seekPlayer', function () {
|
||||
describe('when the video speed is 1.0x', function () {
|
||||
beforeEach(function () {
|
||||
videoSpeedControl.currentSpeed = '1.0';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// Fails with error: "InvalidStateError: An attempt was made to
|
||||
// use an object that is not, or is no longer, usable
|
||||
// Expected 0 to equal 14.91."
|
||||
// on Firefox
|
||||
xit('trigger seek event with the correct time', function () {
|
||||
expect(videoPlayer.currentTime).toEqual(14.91);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the video speed is not 1.0x', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
it('trigger seek event with the correct time', function () {
|
||||
expect(videoPlayer.currentTime).toEqual(14.91);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the player type is Flash at speed 0.75x',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
videoSpeedControl.currentSpeed = '0.75';
|
||||
state.currentPlayerMode = 'flash';
|
||||
$('.subtitles li[data-start="14910"]').trigger('click');
|
||||
});
|
||||
|
||||
it('trigger seek event with the correct time', function () {
|
||||
expect(videoPlayer.currentTime).toEqual(15);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggle', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
spyOn(videoPlayer, 'log');
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
});
|
||||
|
||||
describe('when the caption is visible', function () {
|
||||
beforeEach(function () {
|
||||
state.el.removeClass('closed');
|
||||
videoCaption.toggle(jQuery.Event('click'));
|
||||
});
|
||||
|
||||
it('log the hide_transcript event', function () {
|
||||
expect(videoPlayer.log).toHaveBeenCalledWith(
|
||||
'hide_transcript',
|
||||
{
|
||||
currentTime: videoPlayer.currentTime
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('hide the caption', function () {
|
||||
expect(state.el).toHaveClass('closed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the caption is hidden', function () {
|
||||
beforeEach(function () {
|
||||
state.el.addClass('closed');
|
||||
videoCaption.toggle(jQuery.Event('click'));
|
||||
});
|
||||
|
||||
it('log the show_transcript event', function () {
|
||||
expect(videoPlayer.log).toHaveBeenCalledWith(
|
||||
'show_transcript',
|
||||
{
|
||||
currentTime: videoPlayer.currentTime
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('show the caption', function () {
|
||||
expect(state.el).not.toHaveClass('closed');
|
||||
});
|
||||
|
||||
it('scroll the caption', function () {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('caption accessibility', function () {
|
||||
beforeEach(function () {
|
||||
initialize();
|
||||
});
|
||||
|
||||
describe('when getting focus through TAB key', function () {
|
||||
beforeEach(function () {
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]').trigger(
|
||||
jQuery.Event('focus')
|
||||
);
|
||||
});
|
||||
|
||||
it('shows an outline around the caption', function () {
|
||||
expect($('.subtitles li[data-index=0]'))
|
||||
.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling disabled', function () {
|
||||
expect(videoCaption.autoScrolling).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when loosing focus through TAB key', function () {
|
||||
beforeEach(function () {
|
||||
$('.subtitles li[data-index=0]').trigger(
|
||||
jQuery.Event('blur')
|
||||
);
|
||||
});
|
||||
|
||||
it('does not show an outline around the caption', function () {
|
||||
expect($('.subtitles li[data-index=0]'))
|
||||
.not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function () {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'when same caption gets the focus through mouse after ' +
|
||||
'having focus through TAB key',
|
||||
function () {
|
||||
|
||||
beforeEach(function () {
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]')
|
||||
.trigger(jQuery.Event('focus'));
|
||||
$('.subtitles li[data-index=0]')
|
||||
.trigger(jQuery.Event('mousedown'));
|
||||
});
|
||||
|
||||
it('does not show an outline around it', function () {
|
||||
expect($('.subtitles li[data-index=0]'))
|
||||
.not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function () {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe(
|
||||
'when a second caption gets focus through mouse after ' +
|
||||
'first had focus through TAB key',
|
||||
function () {
|
||||
|
||||
var subDataLiIdx__0, subDataLiIdx__1;
|
||||
|
||||
beforeEach(function () {
|
||||
subDataLiIdx__0 = $('.subtitles li[data-index=0]');
|
||||
subDataLiIdx__1 = $('.subtitles li[data-index=1]');
|
||||
|
||||
videoCaption.isMouseFocus = false;
|
||||
|
||||
subDataLiIdx__0.trigger(jQuery.Event('focus'));
|
||||
subDataLiIdx__0.trigger(jQuery.Event('blur'));
|
||||
|
||||
videoCaption.isMouseFocus = true;
|
||||
|
||||
subDataLiIdx__1.trigger(jQuery.Event('mousedown'));
|
||||
});
|
||||
|
||||
it('does not show an outline around the first', function () {
|
||||
expect(subDataLiIdx__0).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('does not show an outline around the second', function () {
|
||||
expect(subDataLiIdx__1).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function () {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe('when enter key is pressed on a caption', function () {
|
||||
var subDataLiIdx__0;
|
||||
|
||||
beforeEach(function () {
|
||||
var e;
|
||||
|
||||
subDataLiIdx__0 = $('.subtitles li[data-index=0]');
|
||||
|
||||
spyOn(videoCaption, 'seekPlayer').andCallThrough();
|
||||
videoCaption.isMouseFocus = false;
|
||||
subDataLiIdx__0.trigger(jQuery.Event('focus'));
|
||||
e = jQuery.Event('keydown');
|
||||
e.which = 13; // ENTER key
|
||||
subDataLiIdx__0.trigger(e);
|
||||
});
|
||||
|
||||
// Temporarily disabled due to intermittent failures.
|
||||
//
|
||||
// Fails with error: "InvalidStateError: InvalidStateError: An
|
||||
// attempt was made to use an object that is not, or is no
|
||||
// longer, usable".
|
||||
xit('shows an outline around it', function () {
|
||||
expect(subDataLiIdx__0).toHaveClass('focused');
|
||||
});
|
||||
|
||||
xit('calls seekPlayer', function () {
|
||||
expect(videoCaption.seekPlayer).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toggle', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
spyOn(videoPlayer, 'log');
|
||||
$('.subtitles li[data-index=1]').addClass('current');
|
||||
});
|
||||
|
||||
describe('when the caption is visible', function() {
|
||||
beforeEach(function() {
|
||||
state.el.removeClass('closed');
|
||||
videoCaption.toggle(jQuery.Event('click'));
|
||||
});
|
||||
|
||||
it('log the hide_transcript event', function() {
|
||||
expect(videoPlayer.log).toHaveBeenCalledWith('hide_transcript', {
|
||||
currentTime: videoPlayer.currentTime
|
||||
});
|
||||
});
|
||||
|
||||
it('hide the caption', function() {
|
||||
expect(state.el).toHaveClass('closed');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the caption is hidden', function() {
|
||||
beforeEach(function() {
|
||||
state.el.addClass('closed');
|
||||
videoCaption.toggle(jQuery.Event('click'));
|
||||
});
|
||||
|
||||
it('log the show_transcript event', function() {
|
||||
expect(videoPlayer.log).toHaveBeenCalledWith('show_transcript', {
|
||||
currentTime: videoPlayer.currentTime
|
||||
});
|
||||
});
|
||||
|
||||
it('show the caption', function() {
|
||||
expect(state.el).not.toHaveClass('closed');
|
||||
});
|
||||
|
||||
it('scroll the caption', function() {
|
||||
expect($.fn.scrollTo).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('caption accessibility', function() {
|
||||
beforeEach(function() {
|
||||
initialize();
|
||||
});
|
||||
|
||||
describe('when getting focus through TAB key', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
|
||||
});
|
||||
|
||||
it('shows an outline around the caption', function() {
|
||||
expect($('.subtitles li[data-index=0]')).toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling disabled', function() {
|
||||
expect(videoCaption.autoScrolling).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when loosing focus through TAB key', function() {
|
||||
beforeEach(function() {
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('blur'));
|
||||
});
|
||||
|
||||
it('does not show an outline around the caption', function() {
|
||||
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function() {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when same caption gets the focus through mouse after having focus through TAB key', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('mousedown'));
|
||||
});
|
||||
|
||||
it('does not show an outline around it', function() {
|
||||
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function() {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when a second caption gets focus through mouse after first had focus through TAB key', function() {
|
||||
beforeEach(function() {
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('blur'));
|
||||
videoCaption.isMouseFocus = true;
|
||||
$('.subtitles li[data-index=1]').trigger(jQuery.Event('mousedown'));
|
||||
});
|
||||
|
||||
it('does not show an outline around the first', function() {
|
||||
expect($('.subtitles li[data-index=0]')).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('does not show an outline around the second', function() {
|
||||
expect($('.subtitles li[data-index=1]')).not.toHaveClass('focused');
|
||||
});
|
||||
|
||||
it('has automatic scrolling enabled', function() {
|
||||
expect(videoCaption.autoScrolling).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
xdescribe('when enter key is pressed on a caption', function() {
|
||||
beforeEach(function() {
|
||||
var e;
|
||||
spyOn(videoCaption, 'seekPlayer').andCallThrough();
|
||||
videoCaption.isMouseFocus = false;
|
||||
$('.subtitles li[data-index=0]').trigger(jQuery.Event('focus'));
|
||||
e = jQuery.Event('keydown');
|
||||
e.which = 13; // ENTER key
|
||||
$('.subtitles li[data-index=0]').trigger(e);
|
||||
});
|
||||
|
||||
// Temporarily disabled due to intermittent failures
|
||||
// Fails with error: "InvalidStateError: InvalidStateError: An attempt
|
||||
// was made to use an object that is not, or is no longer, usable"
|
||||
xit('shows an outline around it', function() {
|
||||
expect($('.subtitles li[data-index=0]')).toHaveClass('focused');
|
||||
});
|
||||
|
||||
xit('calls seekPlayer', function() {
|
||||
expect(videoCaption.seekPlayer).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
}).call(this);
|
||||
|
||||
@@ -83,7 +83,8 @@
|
||||
|
||||
window.YT = {
|
||||
Player: function () { },
|
||||
PlayerState: oldYT.PlayerState
|
||||
PlayerState: oldYT.PlayerState,
|
||||
ready: function(f){f();}
|
||||
};
|
||||
|
||||
spyOn(window.YT, 'Player');
|
||||
|
||||
@@ -20,17 +20,38 @@
|
||||
});
|
||||
|
||||
describe('constructor', function() {
|
||||
var oldYT = window.YT;
|
||||
|
||||
beforeEach(function() {
|
||||
window.YT = {
|
||||
Player: function () { },
|
||||
PlayerState: oldYT.PlayerState,
|
||||
ready: function(f){f();}
|
||||
};
|
||||
|
||||
initialize();
|
||||
});
|
||||
|
||||
// Disabled when ARIA markup was added to the anchor
|
||||
xit('render the quality control', function() {
|
||||
expect(videoControl.secondaryControlsEl.html()).toContain("<a href=\"#\" class=\"quality_control\" title=\"HD\">");
|
||||
afterEach(function () {
|
||||
window.YT = oldYT;
|
||||
});
|
||||
|
||||
it('render the quality control', function() {
|
||||
expect(videoControl.secondaryControlsEl.html())
|
||||
.toContain(
|
||||
'<a ' +
|
||||
'href="#" ' +
|
||||
'class="quality_control" ' +
|
||||
'title="HD off" ' +
|
||||
'role="button" ' +
|
||||
'aria-disabled="false"' +
|
||||
'>HD off</a>'
|
||||
);
|
||||
});
|
||||
|
||||
it('bind the quality control', function() {
|
||||
expect($('.quality_control')).toHandleWith('click', videoQualityControl.toggleQuality);
|
||||
expect($('.quality_control'))
|
||||
.toHandleWith('click', videoQualityControl.toggleQuality);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -248,7 +248,7 @@ class @Problem
|
||||
@updateProgress response
|
||||
else
|
||||
@gentle_alert response.success
|
||||
Logger.log 'problem_graded', [@answers, response.contents], @url
|
||||
Logger.log 'problem_graded', [@answers, response.contents], @id
|
||||
|
||||
if not abort_submission
|
||||
$.ajaxWithPrefix("#{@url}/problem_check", settings)
|
||||
@@ -271,7 +271,7 @@ class @Problem
|
||||
@el.removeClass 'showed'
|
||||
else
|
||||
@gentle_alert response.success
|
||||
Logger.log 'problem_graded', [@answers, response.contents], @url
|
||||
Logger.log 'problem_graded', [@answers, response.contents], @id
|
||||
|
||||
reset: =>
|
||||
Logger.log 'problem_reset', @answers
|
||||
|
||||
@@ -533,7 +533,7 @@ class @CombinedOpenEnded
|
||||
gentle_alert: (msg) =>
|
||||
if @$el.find(@oe_alert_sel).length
|
||||
@$el.find(@oe_alert_sel).remove()
|
||||
alert_elem = "<div class='open-ended-alert'>" + msg + "</div>"
|
||||
alert_elem = "<div class='open-ended-alert' role='alert'>" + msg + "</div>"
|
||||
@$el.find('.open-ended-action').after(alert_elem)
|
||||
@$el.find(@oe_alert_sel).css(opacity: 0).animate(opacity: 1, 700)
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ class @Hinter
|
||||
constructor: (element) ->
|
||||
@el = $(element).find('.crowdsource-wrapper')
|
||||
@url = @el.data('url')
|
||||
Logger.listen('problem_graded', @el.data('child-url'), @capture_problem)
|
||||
Logger.listen('problem_graded', @el.data('child-id'), @capture_problem)
|
||||
@render()
|
||||
|
||||
capture_problem: (event_type, data, element) =>
|
||||
|
||||
@@ -1,9 +1,43 @@
|
||||
/**
|
||||
* File: lti.js
|
||||
*
|
||||
* Purpose: LTI module constructor. Given an LTI element, we process it.
|
||||
*
|
||||
*
|
||||
* Inside the element there is a form. If that form has a valid action
|
||||
* attribute, then we do one of:
|
||||
*
|
||||
* 1.) Submit the form. The results will be shown on the current page in an
|
||||
* iframe.
|
||||
* 2.) Attach a handler function to a link which will submit the form. The
|
||||
* results will be shown in a new window.
|
||||
*
|
||||
* The 'open_in_a_new_page' data attribute of the LTI element dictates which of
|
||||
* the two actions will be performed.
|
||||
*/
|
||||
|
||||
/*
|
||||
* So the thing to do when working on a motorcycle, as in any other task, is to
|
||||
* cultivate the peace of mind which does not separate one's self from one's
|
||||
* surroundings. When that is done successfully, then everything else follows
|
||||
* naturally. Peace of mind produces right values, right values produce right
|
||||
* thoughts. Right thoughts produce right actions and right actions produce
|
||||
* work which will be a material reflection for others to see of the serenity
|
||||
* at the center of it all.
|
||||
*
|
||||
* ~ Robert M. Pirsig
|
||||
*/
|
||||
|
||||
window.LTI = (function () {
|
||||
// Function initialize(element)
|
||||
//
|
||||
// Initialize the LTI iframe.
|
||||
// Initialize the LTI module.
|
||||
//
|
||||
// @param element DOM element, or jQuery element object.
|
||||
//
|
||||
// @return undefined
|
||||
function initialize(element) {
|
||||
var form;
|
||||
var form, openInANewPage, formAction;
|
||||
|
||||
// In cms (Studio) the element is already a jQuery object. In lms it is
|
||||
// a DOM object.
|
||||
@@ -13,12 +47,36 @@ window.LTI = (function () {
|
||||
element = $(element);
|
||||
|
||||
form = element.find('.ltiLaunchForm');
|
||||
formAction = form.attr('action');
|
||||
|
||||
// If action is empty string, or action is the default URL that should
|
||||
// not cause a form submit.
|
||||
if (!formAction || formAction === 'http://www.example.com') {
|
||||
|
||||
// Nothing to do - no valid action provided. Error message will be
|
||||
// displaced in browser (HTML).
|
||||
return;
|
||||
}
|
||||
|
||||
// We want a Boolean 'true' or 'false'. First we will retrieve the data
|
||||
// attribute, and then we will parse it via native JSON.parse().
|
||||
openInANewPage = element.find('.lti').data('open_in_a_new_page');
|
||||
openInANewPage = JSON.parse(openInANewPage);
|
||||
|
||||
// If the Form's action attribute is set (i.e. we can perform a normal
|
||||
// submit), then we submit the form and make the frame shown.
|
||||
if (form.attr('action') && form.attr('action') !== 'http://www.example.com') {
|
||||
// submit), then we (depending on instance settings) submit the form
|
||||
// when user will click on a link, or submit the form immediately.
|
||||
if (openInANewPage === true) {
|
||||
element.find('.link_lti_new_window').on('click', function () {
|
||||
form.submit();
|
||||
});
|
||||
} else {
|
||||
// At this stage the form exists on the page and has a valid
|
||||
// action. We are safe to submit it, even if `openInANewPage` is
|
||||
// set to some weird value.
|
||||
//
|
||||
// Best case scenario is that `openInANewPage` is set to `true`.
|
||||
form.submit();
|
||||
element.find('.lti').addClass('rendered');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -92,23 +92,12 @@ function (VideoPlayer) {
|
||||
// Require JS. At the time when we reach this code, the stand alone
|
||||
// HTML5 player is already loaded, so no further testing in that case
|
||||
// is required.
|
||||
var onPlayerReadyFunc;
|
||||
if (
|
||||
(
|
||||
(state.videoType === 'youtube') &&
|
||||
(window.YT) &&
|
||||
(window.YT.Player)
|
||||
) ||
|
||||
(state.videoType === 'html5')
|
||||
) {
|
||||
VideoPlayer(state);
|
||||
if(state.videoType === 'youtube') {
|
||||
YT.ready(function() {
|
||||
VideoPlayer(state);
|
||||
})
|
||||
} else {
|
||||
if (state.videoType === 'youtube') {
|
||||
onPlayerReadyFunc = 'onYouTubePlayerAPIReady';
|
||||
} else {
|
||||
onPlayerReadyFunc = 'onHTML5PlayerAPIReady';
|
||||
}
|
||||
window[onPlayerReadyFunc] = _.bind(VideoPlayer, window, state);
|
||||
VideoPlayer(state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,15 +253,21 @@ function (VideoPlayer) {
|
||||
// The function set initial configuration and preparation.
|
||||
|
||||
function initialize(element) {
|
||||
var _this = this, tempYtTestTimeout;
|
||||
var _this = this,
|
||||
regExp = /^true$/i,
|
||||
data, tempYtTestTimeout;
|
||||
// This is used in places where we instead would have to check if an
|
||||
// element has a CSS class 'fullscreen'.
|
||||
this.isFullScreen = false;
|
||||
|
||||
// The parent element of the video, and the ID.
|
||||
this.el = $(element).find('.video');
|
||||
this.elVideoWrapper = this.el.find('.video-wrapper');
|
||||
this.id = this.el.attr('id').replace(/video_/, '');
|
||||
|
||||
// jQuery .data() return object with keys in lower camelCase format.
|
||||
data = this.el.data();
|
||||
|
||||
console.log(
|
||||
'[Video info]: Initializing video with id "' + this.id + '".'
|
||||
);
|
||||
@@ -283,32 +278,26 @@ function (VideoPlayer) {
|
||||
this.config = {
|
||||
element: element,
|
||||
|
||||
start: this.el.data('start'),
|
||||
end: this.el.data('end'),
|
||||
|
||||
caption_data_dir: this.el.data('caption-data-dir'),
|
||||
caption_asset_path: this.el.data('caption-asset-path'),
|
||||
show_captions: (
|
||||
this.el.data('show-captions')
|
||||
.toString().toLowerCase() === 'true'
|
||||
),
|
||||
youtubeStreams: this.el.data('streams'),
|
||||
|
||||
sub: this.el.data('sub'),
|
||||
mp4Source: this.el.data('mp4-source'),
|
||||
webmSource: this.el.data('webm-source'),
|
||||
oggSource: this.el.data('ogg-source'),
|
||||
|
||||
ytTestUrl: this.el.data('yt-test-url'),
|
||||
|
||||
start: data['start'],
|
||||
end: data['end'],
|
||||
caption_data_dir: data['captionDataDir'],
|
||||
caption_asset_path: data['captionAssetPath'],
|
||||
show_captions: regExp.test(data['showCaptions'].toString()),
|
||||
youtubeStreams: data['streams'],
|
||||
autohideHtml5: regExp.test(data['autohideHtml5'].toString()),
|
||||
sub: data['sub'],
|
||||
mp4Source: data['mp4Source'],
|
||||
webmSource: data['webmSource'],
|
||||
oggSource: data['oggSource'],
|
||||
ytTestUrl: data['ytTestUrl'],
|
||||
fadeOutTimeout: 1400,
|
||||
|
||||
captionsFreezeTime: 10000,
|
||||
availableQualities: ['hd720', 'hd1080', 'highres']
|
||||
};
|
||||
|
||||
// Check if the YT test timeout has been set. If not, or it is in
|
||||
// improper format, then set to default value.
|
||||
tempYtTestTimeout = parseInt(this.el.data('yt-test-timeout'), 10);
|
||||
tempYtTestTimeout = parseInt(data['ytTestTimeout'], 10);
|
||||
if (!isFinite(tempYtTestTimeout)) {
|
||||
tempYtTestTimeout = 1500;
|
||||
}
|
||||
|
||||
@@ -420,7 +420,7 @@ function (HTML5Video) {
|
||||
this.videoPlayer.player.setPlaybackRate(this.speed);
|
||||
}
|
||||
|
||||
/* The following has been commented out to make sure autoplay is
|
||||
/* The following has been commented out to make sure autoplay is
|
||||
disabled for students.
|
||||
if (
|
||||
!onTouchBasedDevice() &&
|
||||
|
||||
@@ -57,7 +57,7 @@ function () {
|
||||
state.videoControl.play();
|
||||
}
|
||||
|
||||
if (state.videoType === 'html5') {
|
||||
if ((state.videoType === 'html5') && (state.config.autohideHtml5)) {
|
||||
state.videoControl.fadeOutTimeout = state.config.fadeOutTimeout;
|
||||
|
||||
state.videoControl.el.addClass('html5');
|
||||
@@ -81,7 +81,7 @@ function () {
|
||||
state.videoControl.fullScreenEl.on('click', state.videoControl.toggleFullScreen);
|
||||
$(document).on('keyup', state.videoControl.exitFullScreen);
|
||||
|
||||
if (state.videoType === 'html5') {
|
||||
if ((state.videoType === 'html5') && (state.config.autohideHtml5)) {
|
||||
state.el.on('mousemove', state.videoControl.showControls);
|
||||
state.el.on('keydown', state.videoControl.showControls);
|
||||
}
|
||||
|
||||
@@ -59,14 +59,24 @@ function () {
|
||||
// ***************************************************************
|
||||
|
||||
function onQualityChange(value) {
|
||||
var controlStateStr;
|
||||
this.videoQualityControl.quality = value;
|
||||
|
||||
if (_.indexOf(this.config.availableQualities, value) !== -1) {
|
||||
this.videoQualityControl.el.addClass('active');
|
||||
controlStateStr = gettext('HD on');
|
||||
this.videoQualityControl.el
|
||||
.addClass('active')
|
||||
.attr('title', controlStateStr)
|
||||
.text(controlStateStr);
|
||||
} else {
|
||||
this.videoQualityControl.el.removeClass('active');
|
||||
controlStateStr = gettext('HD off');
|
||||
this.videoQualityControl.el
|
||||
.removeClass('active')
|
||||
.attr('title', controlStateStr)
|
||||
.text(controlStateStr);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// This function change quality of video.
|
||||
// Right now we haven't ability to choose quality of HD video,
|
||||
|
||||
@@ -34,46 +34,63 @@ function () {
|
||||
|
||||
// function _makeFunctionsPublic(state)
|
||||
//
|
||||
// Functions which will be accessible via 'state' object. When called, these functions will
|
||||
// get the 'state' object as a context.
|
||||
// Functions which will be accessible via 'state' object. When called,
|
||||
// these functions will get the 'state' object as a context.
|
||||
function _makeFunctionsPublic(state) {
|
||||
state.videoCaption.autoShowCaptions = _.bind(autoShowCaptions, state);
|
||||
state.videoCaption.autoHideCaptions = _.bind(autoHideCaptions, state);
|
||||
state.videoCaption.resize = _.bind(resize, state);
|
||||
state.videoCaption.toggle = _.bind(toggle, state);
|
||||
state.videoCaption.onMouseEnter = _.bind(onMouseEnter, state);
|
||||
state.videoCaption.onMouseLeave = _.bind(onMouseLeave, state);
|
||||
state.videoCaption.onMovement = _.bind(onMovement, state);
|
||||
state.videoCaption.renderCaption = _.bind(renderCaption, state);
|
||||
state.videoCaption.captionHeight = _.bind(captionHeight, state);
|
||||
state.videoCaption.topSpacingHeight = _.bind(topSpacingHeight, state);
|
||||
state.videoCaption.bottomSpacingHeight = _.bind(bottomSpacingHeight, state);
|
||||
state.videoCaption.scrollCaption = _.bind(scrollCaption, state);
|
||||
state.videoCaption.search = _.bind(search, state);
|
||||
state.videoCaption.play = _.bind(play, state);
|
||||
state.videoCaption.pause = _.bind(pause, state);
|
||||
state.videoCaption.seekPlayer = _.bind(seekPlayer, state);
|
||||
state.videoCaption.hideCaptions = _.bind(hideCaptions, state);
|
||||
state.videoCaption.calculateOffset = _.bind(calculateOffset, state);
|
||||
state.videoCaption.updatePlayTime = _.bind(updatePlayTime, state);
|
||||
state.videoCaption.setSubtitlesHeight = _.bind(setSubtitlesHeight, state);
|
||||
state.videoCaption.autoShowCaptions = _.bind(
|
||||
autoShowCaptions, state
|
||||
);
|
||||
state.videoCaption.autoHideCaptions = _.bind(
|
||||
autoHideCaptions, state
|
||||
);
|
||||
state.videoCaption.resize = _.bind(resize, state);
|
||||
state.videoCaption.toggle = _.bind(toggle, state);
|
||||
state.videoCaption.onMouseEnter = _.bind(onMouseEnter, state);
|
||||
state.videoCaption.onMouseLeave = _.bind(onMouseLeave, state);
|
||||
state.videoCaption.onMovement = _.bind(onMovement, state);
|
||||
state.videoCaption.renderCaption = _.bind(renderCaption, state);
|
||||
state.videoCaption.captionHeight = _.bind(captionHeight, state);
|
||||
state.videoCaption.topSpacingHeight = _.bind(
|
||||
topSpacingHeight, state
|
||||
);
|
||||
state.videoCaption.bottomSpacingHeight = _.bind(
|
||||
bottomSpacingHeight, state
|
||||
);
|
||||
state.videoCaption.scrollCaption = _.bind(scrollCaption, state);
|
||||
state.videoCaption.search = _.bind(search, state);
|
||||
state.videoCaption.play = _.bind(play, state);
|
||||
state.videoCaption.pause = _.bind(pause, state);
|
||||
state.videoCaption.seekPlayer = _.bind(seekPlayer, state);
|
||||
state.videoCaption.hideCaptions = _.bind(hideCaptions, state);
|
||||
state.videoCaption.calculateOffset = _.bind(
|
||||
calculateOffset, state
|
||||
);
|
||||
state.videoCaption.updatePlayTime = _.bind(updatePlayTime, state);
|
||||
state.videoCaption.setSubtitlesHeight = _.bind(
|
||||
setSubtitlesHeight, state
|
||||
);
|
||||
|
||||
state.videoCaption.renderElements = _.bind(renderElements, state);
|
||||
state.videoCaption.bindHandlers = _.bind(bindHandlers, state);
|
||||
state.videoCaption.fetchCaption = _.bind(fetchCaption, state);
|
||||
state.videoCaption.captionURL = _.bind(captionURL, state);
|
||||
state.videoCaption.captionMouseOverOut = _.bind(captionMouseOverOut, state);
|
||||
state.videoCaption.captionMouseDown = _.bind(captionMouseDown, state);
|
||||
state.videoCaption.captionClick = _.bind(captionClick, state);
|
||||
state.videoCaption.captionFocus = _.bind(captionFocus, state);
|
||||
state.videoCaption.captionBlur = _.bind(captionBlur, state);
|
||||
state.videoCaption.captionKeyDown = _.bind(captionKeyDown, state);
|
||||
state.videoCaption.renderElements = _.bind(renderElements, state);
|
||||
state.videoCaption.bindHandlers = _.bind(bindHandlers, state);
|
||||
state.videoCaption.fetchCaption = _.bind(fetchCaption, state);
|
||||
state.videoCaption.captionURL = _.bind(captionURL, state);
|
||||
state.videoCaption.captionMouseOverOut = _.bind(
|
||||
captionMouseOverOut, state
|
||||
);
|
||||
state.videoCaption.captionMouseDown = _.bind(
|
||||
captionMouseDown, state
|
||||
);
|
||||
state.videoCaption.captionClick = _.bind(captionClick, state);
|
||||
state.videoCaption.captionFocus = _.bind(captionFocus, state);
|
||||
state.videoCaption.captionBlur = _.bind(captionBlur, state);
|
||||
state.videoCaption.captionKeyDown = _.bind(captionKeyDown, state);
|
||||
}
|
||||
|
||||
// ***************************************************************
|
||||
// Public functions start here.
|
||||
// These are available via the 'state' object. Their context ('this' keyword) is the 'state' object.
|
||||
// The magic private function that makes them available and sets up their context is makeFunctionsPublic().
|
||||
// These are available via the 'state' object. Their context ('this'
|
||||
// keyword) is the 'state' object. The magic private function that makes
|
||||
// them available and sets up their context is makeFunctionsPublic().
|
||||
// ***************************************************************
|
||||
|
||||
/**
|
||||
@@ -109,10 +126,13 @@ function () {
|
||||
|
||||
// function bindHandlers()
|
||||
//
|
||||
// Bind any necessary function callbacks to DOM events (click, mousemove, etc.).
|
||||
// Bind any necessary function callbacks to DOM events (click,
|
||||
// mousemove, etc.).
|
||||
function bindHandlers() {
|
||||
$(window).bind('resize', this.videoCaption.resize);
|
||||
this.videoCaption.hideSubtitlesEl.on('click', this.videoCaption.toggle);
|
||||
this.videoCaption.hideSubtitlesEl.on(
|
||||
'click', this.videoCaption.toggle
|
||||
);
|
||||
|
||||
this.videoCaption.subtitlesEl
|
||||
.on(
|
||||
@@ -132,14 +152,40 @@ function () {
|
||||
this.videoCaption.onMovement
|
||||
);
|
||||
|
||||
if (this.videoType === 'html5') {
|
||||
this.el.on('mousemove', this.videoCaption.autoShowCaptions);
|
||||
this.el.on('keydown', this.videoCaption.autoShowCaptions);
|
||||
if ((this.videoType === 'html5') && (this.config.autohideHtml5)) {
|
||||
this.el.on({
|
||||
mousemove: this.videoCaption.autoShowCaptions,
|
||||
keydown: this.videoCaption.autoShowCaptions
|
||||
});
|
||||
|
||||
// Moving slider on subtitles is not a mouse move,
|
||||
// but captions and controls should be showed.
|
||||
this.videoCaption.subtitlesEl.on('scroll', this.videoCaption.autoShowCaptions);
|
||||
this.videoCaption.subtitlesEl.on('scroll', this.videoControl.showControls);
|
||||
// Moving slider on subtitles is not a mouse move, but captions and
|
||||
// controls should be shown.
|
||||
this.videoCaption.subtitlesEl
|
||||
.on(
|
||||
'scroll', this.videoCaption.autoShowCaptions
|
||||
)
|
||||
.on(
|
||||
'scroll', this.videoControl.showControls
|
||||
);
|
||||
} else if (!this.config.autohideHtml5) {
|
||||
this.videoCaption.subtitlesEl.on({
|
||||
keydown: this.videoCaption.autoShowCaptions,
|
||||
focus: this.videoCaption.autoShowCaptions,
|
||||
|
||||
// Moving slider on subtitles is not a mouse move, but captions
|
||||
// should not be auto-hidden.
|
||||
scroll: this.videoCaption.autoShowCaptions,
|
||||
|
||||
mouseout: this.videoCaption.autoHideCaptions,
|
||||
blur: this.videoCaption.autoHideCaptions
|
||||
});
|
||||
|
||||
this.videoCaption.hideSubtitlesEl.on({
|
||||
mousemove: this.videoCaption.autoShowCaptions,
|
||||
|
||||
mouseout: this.videoCaption.autoHideCaptions,
|
||||
blur: this.videoCaption.autoHideCaptions
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -209,7 +255,8 @@ function () {
|
||||
}
|
||||
|
||||
function captionURL() {
|
||||
return '' + this.config.caption_asset_path + this.youtubeId('1.0') + '.srt.sjson';
|
||||
return '' + this.config.caption_asset_path +
|
||||
this.youtubeId('1.0') + '.srt.sjson';
|
||||
}
|
||||
|
||||
function autoShowCaptions(event) {
|
||||
@@ -224,13 +271,19 @@ function () {
|
||||
this.videoCaption.subtitlesEl.show();
|
||||
this.captionState = 'visible';
|
||||
} else if (this.captionState === 'hiding') {
|
||||
this.videoCaption.subtitlesEl.stop(true, false).css('opacity', 1).show();
|
||||
this.videoCaption.subtitlesEl
|
||||
.stop(true, false).css('opacity', 1).show();
|
||||
this.captionState = 'visible';
|
||||
} else if (this.captionState === 'visible') {
|
||||
clearTimeout(this.captionHideTimeout);
|
||||
}
|
||||
|
||||
this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout);
|
||||
if (this.config.autohideHtml5) {
|
||||
this.captionHideTimeout = setTimeout(
|
||||
this.videoCaption.autoHideCaptions,
|
||||
this.videoCaption.fadeOutTimeout
|
||||
);
|
||||
}
|
||||
|
||||
this.captionsShowLock = false;
|
||||
}
|
||||
@@ -249,15 +302,21 @@ function () {
|
||||
|
||||
_this = this;
|
||||
|
||||
this.videoCaption.subtitlesEl.fadeOut(this.videoCaption.fadeOutTimeout, function () {
|
||||
_this.captionState = 'invisible';
|
||||
});
|
||||
this.videoCaption.subtitlesEl
|
||||
.fadeOut(
|
||||
this.videoCaption.fadeOutTimeout,
|
||||
function () {
|
||||
_this.captionState = 'invisible';
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function resize() {
|
||||
this.videoCaption.subtitlesEl
|
||||
.find('.spacing:first').height(this.videoCaption.topSpacingHeight())
|
||||
.find('.spacing:last').height(this.videoCaption.bottomSpacingHeight());
|
||||
.find('.spacing:first')
|
||||
.height(this.videoCaption.topSpacingHeight())
|
||||
.find('.spacing:last')
|
||||
.height(this.videoCaption.bottomSpacingHeight());
|
||||
|
||||
this.videoCaption.scrollCaption();
|
||||
|
||||
@@ -269,7 +328,10 @@ function () {
|
||||
clearTimeout(this.videoCaption.frozen);
|
||||
}
|
||||
|
||||
this.videoCaption.frozen = setTimeout(this.videoCaption.onMouseLeave, 10000);
|
||||
this.videoCaption.frozen = setTimeout(
|
||||
this.videoCaption.onMouseLeave,
|
||||
this.config.captionsFreezeTime
|
||||
);
|
||||
}
|
||||
|
||||
function onMouseLeave() {
|
||||
@@ -285,6 +347,10 @@ function () {
|
||||
}
|
||||
|
||||
function onMovement() {
|
||||
if (!this.config.autohideHtml5) {
|
||||
this.videoCaption.autoShowCaptions();
|
||||
}
|
||||
|
||||
this.videoCaption.onMouseEnter();
|
||||
}
|
||||
|
||||
@@ -292,16 +358,28 @@ function () {
|
||||
var container = $('<ol>'),
|
||||
_this = this;
|
||||
|
||||
this.el.find('.video-wrapper').after(this.videoCaption.subtitlesEl);
|
||||
this.el.find('.video-controls .secondary-controls').append(this.videoCaption.hideSubtitlesEl);
|
||||
this.elVideoWrapper.after(this.videoCaption.subtitlesEl);
|
||||
this.el.find('.video-controls .secondary-controls')
|
||||
.append(this.videoCaption.hideSubtitlesEl);
|
||||
|
||||
this.videoCaption.setSubtitlesHeight();
|
||||
|
||||
if (this.videoType === 'html5') {
|
||||
if ((this.videoType === 'html5') && (this.config.autohideHtml5)) {
|
||||
this.videoCaption.fadeOutTimeout = this.config.fadeOutTimeout;
|
||||
|
||||
this.videoCaption.subtitlesEl.addClass('html5');
|
||||
this.captionHideTimeout = setTimeout(this.videoCaption.autoHideCaptions, this.videoCaption.fadeOutTimeout);
|
||||
this.captionHideTimeout = setTimeout(
|
||||
this.videoCaption.autoHideCaptions,
|
||||
this.videoCaption.fadeOutTimeout
|
||||
);
|
||||
} else if (!this.config.autohideHtml5) {
|
||||
this.videoCaption.fadeOutTimeout = this.config.fadeOutTimeout;
|
||||
this.videoCaption.subtitlesEl.addClass('html5');
|
||||
|
||||
this.captionHideTimeout = setTimeout(
|
||||
this.videoCaption.autoHideCaptions,
|
||||
0
|
||||
);
|
||||
}
|
||||
|
||||
this.videoCaption.hideCaptions(this.hide_captions);
|
||||
@@ -322,17 +400,18 @@ function () {
|
||||
container.append(liEl);
|
||||
});
|
||||
|
||||
this.videoCaption.subtitlesEl.html(container.html());
|
||||
|
||||
this.videoCaption.subtitlesEl.find('li[data-index]').on({
|
||||
mouseover: this.videoCaption.captionMouseOverOut,
|
||||
mouseout: this.videoCaption.captionMouseOverOut,
|
||||
mousedown: this.videoCaption.captionMouseDown,
|
||||
click: this.videoCaption.captionClick,
|
||||
focus: this.videoCaption.captionFocus,
|
||||
blur: this.videoCaption.captionBlur,
|
||||
keydown: this.videoCaption.captionKeyDown
|
||||
});
|
||||
this.videoCaption.subtitlesEl
|
||||
.html(container.html())
|
||||
.find('li[data-index]')
|
||||
.on({
|
||||
mouseover: this.videoCaption.captionMouseOverOut,
|
||||
mouseout: this.videoCaption.captionMouseOverOut,
|
||||
mousedown: this.videoCaption.captionMouseDown,
|
||||
click: this.videoCaption.captionClick,
|
||||
focus: this.videoCaption.captionFocus,
|
||||
blur: this.videoCaption.captionBlur,
|
||||
keydown: this.videoCaption.captionKeyDown
|
||||
});
|
||||
|
||||
// Enables or disables automatic scrolling of the captions when the
|
||||
// video is playing. This feature has to be disabled when tabbing
|
||||
@@ -344,16 +423,24 @@ function () {
|
||||
this.videoCaption.autoScrolling = true;
|
||||
// Keeps track of where the focus is situated in the array of captions.
|
||||
// Used to implement the automatic scrolling behavior and decide if the
|
||||
// outline around a caption has to be hidden or shown on a mouseenter or
|
||||
// mouseleave. Initially, no caption has the focus, set the index to -1.
|
||||
// outline around a caption has to be hidden or shown on a mouseenter
|
||||
// or mouseleave. Initially, no caption has the focus, set the
|
||||
// index to -1.
|
||||
this.videoCaption.currentCaptionIndex = -1;
|
||||
// Used to track if the focus is coming from a click or tabbing. This
|
||||
// has to be known to decide if, when a caption gets the focus, an
|
||||
// outline has to be drawn (tabbing) or not (mouse click).
|
||||
this.videoCaption.isMouseFocus = false;
|
||||
|
||||
this.videoCaption.subtitlesEl.prepend($('<li class="spacing">').height(this.videoCaption.topSpacingHeight()));
|
||||
this.videoCaption.subtitlesEl.append($('<li class="spacing">').height(this.videoCaption.bottomSpacingHeight()));
|
||||
this.videoCaption.subtitlesEl
|
||||
.prepend(
|
||||
$('<li class="spacing">')
|
||||
.height(this.videoCaption.topSpacingHeight())
|
||||
)
|
||||
.append(
|
||||
$('<li class="spacing">')
|
||||
.height(this.videoCaption.bottomSpacingHeight())
|
||||
);
|
||||
|
||||
this.videoCaption.rendered = true;
|
||||
}
|
||||
@@ -403,7 +490,10 @@ function () {
|
||||
caption.addClass('focused');
|
||||
// The second and second to last elements turn automatic scrolling
|
||||
// off again as it may have been enabled in captionBlur.
|
||||
if (captionIndex <= 1 || captionIndex >= this.videoCaption.captions.length-2) {
|
||||
if (
|
||||
captionIndex <= 1 ||
|
||||
captionIndex >= this.videoCaption.captions.length - 2
|
||||
) {
|
||||
this.videoCaption.autoScrolling = false;
|
||||
}
|
||||
}
|
||||
@@ -413,13 +503,15 @@ function () {
|
||||
var caption = $(event.target),
|
||||
captionIndex = parseInt(caption.attr('data-index'), 10);
|
||||
caption.removeClass('focused');
|
||||
// If we are on first or last index, we have to turn automatic scroll on
|
||||
// again when losing focus. There is no way to know in what direction we
|
||||
// are tabbing. So we could be on the first element and tabbing back out
|
||||
// of the captions or on the last element and tabbing forward out of the
|
||||
// captions.
|
||||
// If we are on first or last index, we have to turn automatic scroll
|
||||
// on again when losing focus. There is no way to know in what
|
||||
// direction we are tabbing. So we could be on the first element and
|
||||
// tabbing back out of the captions or on the last element and tabbing
|
||||
// forward out of the captions.
|
||||
if (captionIndex === 0 ||
|
||||
captionIndex === this.videoCaption.captions.length-1) {
|
||||
this.videoCaption.autoHideCaptions();
|
||||
|
||||
this.videoCaption.autoScrolling = true;
|
||||
}
|
||||
}
|
||||
@@ -434,9 +526,13 @@ function () {
|
||||
function scrollCaption() {
|
||||
var el = this.videoCaption.subtitlesEl.find('.current:first');
|
||||
|
||||
// Automatic scrolling gets disabled if one of the captions has received
|
||||
// focus through tabbing.
|
||||
if (!this.videoCaption.frozen && el.length && this.videoCaption.autoScrolling) {
|
||||
// Automatic scrolling gets disabled if one of the captions has
|
||||
// received focus through tabbing.
|
||||
if (
|
||||
!this.videoCaption.frozen &&
|
||||
el.length &&
|
||||
this.videoCaption.autoScrolling
|
||||
) {
|
||||
this.videoCaption.subtitlesEl.scrollTo(
|
||||
el,
|
||||
{
|
||||
@@ -565,25 +661,46 @@ function () {
|
||||
}
|
||||
|
||||
function topSpacingHeight() {
|
||||
return this.videoCaption.calculateOffset(this.videoCaption.subtitlesEl.find('li:not(.spacing):first'));
|
||||
return this.videoCaption.calculateOffset(
|
||||
this.videoCaption.subtitlesEl.find('li:not(.spacing):first')
|
||||
);
|
||||
}
|
||||
|
||||
function bottomSpacingHeight() {
|
||||
return this.videoCaption.calculateOffset(this.videoCaption.subtitlesEl.find('li:not(.spacing):last'));
|
||||
return this.videoCaption.calculateOffset(
|
||||
this.videoCaption.subtitlesEl.find('li:not(.spacing):last')
|
||||
);
|
||||
}
|
||||
|
||||
function toggle(event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (this.el.hasClass('closed')) {
|
||||
this.videoCaption.autoShowCaptions();
|
||||
this.videoCaption.hideCaptions(false);
|
||||
} else {
|
||||
this.videoCaption.hideCaptions(true);
|
||||
|
||||
// In the case when captions are not auto-hidden based on mouse
|
||||
// movement anywhere on the video, we must hide them explicitly
|
||||
// after the "CC" button has been clicked (to hide captions).
|
||||
//
|
||||
// Otherwise, in order for the captions to disappear again, the
|
||||
// user must move the mouse button over the "CC" button, or over
|
||||
// the captions themselves. In this case, an "autoShow" will be
|
||||
// triggered, and after a timeout, an "autoHide".
|
||||
if (!this.config.autohideHtml5) {
|
||||
this.captionHideTimeout = setTimeout(
|
||||
this.videoCaption.autoHideCaptions(),
|
||||
0
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function hideCaptions(hide_captions, update_cookie) {
|
||||
var type;
|
||||
var hideSubtitlesEl = this.videoCaption.hideSubtitlesEl,
|
||||
type;
|
||||
|
||||
if (typeof update_cookie === 'undefined') {
|
||||
update_cookie = true;
|
||||
@@ -592,14 +709,20 @@ function () {
|
||||
if (hide_captions) {
|
||||
type = 'hide_transcript';
|
||||
this.captionsHidden = true;
|
||||
this.videoCaption.hideSubtitlesEl.attr('title', gettext('Turn on captions'));
|
||||
this.videoCaption.hideSubtitlesEl.text(gettext('Turn on captions'));
|
||||
|
||||
hideSubtitlesEl
|
||||
.attr('title', gettext('Turn on captions'))
|
||||
.text(gettext('Turn on captions'));
|
||||
|
||||
this.el.addClass('closed');
|
||||
} else {
|
||||
type = 'show_transcript';
|
||||
this.captionsHidden = false;
|
||||
this.videoCaption.hideSubtitlesEl.attr('title', gettext('Turn off captions'));
|
||||
this.videoCaption.hideSubtitlesEl.text(gettext('Turn off captions'));
|
||||
|
||||
hideSubtitlesEl
|
||||
.attr('title', gettext('Turn off captions'))
|
||||
.text(gettext('Turn off captions'));
|
||||
|
||||
this.el.removeClass('closed');
|
||||
this.videoCaption.scrollCaption();
|
||||
}
|
||||
@@ -621,27 +744,43 @@ function () {
|
||||
}
|
||||
|
||||
function captionHeight() {
|
||||
var paddingTop;
|
||||
|
||||
if (this.isFullScreen) {
|
||||
return $(window).height() - this.el.find('.video-controls').height() -
|
||||
0.5 * this.videoControl.sliderEl.height() -
|
||||
2 * parseInt(this.videoCaption.subtitlesEl.css('padding-top'), 10);
|
||||
paddingTop = parseInt(
|
||||
this.videoCaption.subtitlesEl.css('padding-top'), 10
|
||||
);
|
||||
|
||||
return $(window).height() -
|
||||
this.videoControl.el.height() -
|
||||
0.5 * this.videoControl.sliderEl.height() -
|
||||
2 * paddingTop;
|
||||
} else {
|
||||
return this.el.find('.video-wrapper').height();
|
||||
return this.elVideoWrapper.height();
|
||||
}
|
||||
}
|
||||
|
||||
function setSubtitlesHeight() {
|
||||
var height = 0;
|
||||
if (this.videoType === 'html5'){
|
||||
if (
|
||||
((this.videoType === 'html5') && (this.config.autohideHtml5)) ||
|
||||
(!this.config.autohideHtml5)
|
||||
){
|
||||
// on page load captionHidden = undefined
|
||||
if (
|
||||
(this.captionsHidden === undefined && this.hide_captions === true ) ||
|
||||
(this.captionsHidden === true) ) {
|
||||
// In case of html5 autoshowing subtitles,
|
||||
// we ajdust height of subs, by height of scrollbar
|
||||
height = this.videoControl.el.height() + 0.5 * this.videoControl.sliderEl.height();
|
||||
// height of videoControl does not contain height of slider.
|
||||
// (css is set to absolute, to avoid yanking when slider autochanges its height)
|
||||
(
|
||||
this.captionsHidden === undefined &&
|
||||
this.hide_captions === true
|
||||
) ||
|
||||
(this.captionsHidden === true)
|
||||
) {
|
||||
// In case of html5 autoshowing subtitles, we adjust height of
|
||||
// subs, by height of scrollbar.
|
||||
height = this.videoControl.el.height() +
|
||||
0.5 * this.videoControl.sliderEl.height();
|
||||
// Height of videoControl does not contain height of slider.
|
||||
// css is set to absolute, to avoid yanking when slider
|
||||
// autochanges its height.
|
||||
}
|
||||
}
|
||||
this.videoCaption.subtitlesEl.css({
|
||||
|
||||
@@ -1,5 +1,42 @@
|
||||
(function (requirejs, require, define) {
|
||||
|
||||
// In the case when the Video constructor will be called before
|
||||
// RequireJS finishes loading all of the Video dependencies, we will have
|
||||
// a mock function that will collect all the elements that must be
|
||||
// initialized as Video elements.
|
||||
//
|
||||
// Once RequireJS will load all of the necessary dependencies, main code
|
||||
// will invoke the mock function with the second parameter set to truthy value.
|
||||
// This will trigger the actual Video constructor on all elements that
|
||||
// are stored in a temporary list.
|
||||
window.Video = (function () {
|
||||
// Temporary storage place for elements that must be initialized as Video
|
||||
// elements.
|
||||
var tempCallStack = [];
|
||||
|
||||
return function (element, processTempCallStack) {
|
||||
// If mock function was called with second parameter set to truthy
|
||||
// value, we invoke the real `window.Video` on all the stored elements
|
||||
// so far.
|
||||
if (processTempCallStack) {
|
||||
$.each(tempCallStack, function (index, element) {
|
||||
// By now, `window.Video` is the real constructor.
|
||||
window.Video(element);
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// If normal call to `window.Video` constructor, store the element
|
||||
// for later initializing.
|
||||
tempCallStack.push(element);
|
||||
|
||||
// Real Video constructor returns the `state` object. The mock
|
||||
// function will return an empty object.
|
||||
return {};
|
||||
};
|
||||
}());
|
||||
|
||||
// Main module.
|
||||
require(
|
||||
[
|
||||
@@ -23,7 +60,8 @@ function (
|
||||
VideoCaption
|
||||
) {
|
||||
var previousState,
|
||||
youtubeXhr = null;
|
||||
youtubeXhr = null,
|
||||
oldVideo = window.Video;
|
||||
|
||||
// Because this constructor can be called multiple times on a single page (when
|
||||
// the user switches verticals, the page doesn't reload, but the content changes), we must
|
||||
@@ -79,6 +117,10 @@ function (
|
||||
window.Video.clearYoutubeXhr = function () {
|
||||
youtubeXhr = null;
|
||||
};
|
||||
|
||||
// Invoke the mock Video constructor so that the elements stored within
|
||||
// it can be processed by the real `window.Video` constructor.
|
||||
oldVideo(null, true);
|
||||
});
|
||||
|
||||
}(RequireJS.requirejs, RequireJS.require, RequireJS.define));
|
||||
|
||||
@@ -8,12 +8,15 @@ http://www.imsglobal.org/LTI/v1p1p1/ltiIMGv1p1p1.html
|
||||
import logging
|
||||
import oauthlib.oauth1
|
||||
import urllib
|
||||
import json
|
||||
|
||||
from xmodule.editing_module import MetadataOnlyEditingDescriptor
|
||||
from xmodule.raw_module import EmptyDataRawDescriptor
|
||||
from xmodule.x_module import XModule
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from pkg_resources import resource_string
|
||||
from xblock.core import String, Scope, List
|
||||
from xblock.fields import Boolean
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@@ -45,6 +48,7 @@ class LTIFields(object):
|
||||
lti_id = String(help="Id of the tool", default='', scope=Scope.settings)
|
||||
launch_url = String(help="URL of the tool", default='http://www.example.com', scope=Scope.settings)
|
||||
custom_parameters = List(help="Custom parameters (vbid, book_location, etc..)", scope=Scope.settings)
|
||||
open_in_a_new_page = Boolean(help="Should LTI be opened in new page?", default=True, scope=Scope.settings)
|
||||
|
||||
|
||||
class LTIModule(LTIFields, XModule):
|
||||
@@ -92,10 +96,10 @@ class LTIModule(LTIFields, XModule):
|
||||
|
||||
<form
|
||||
action="${launch_url}"
|
||||
name="ltiLaunchForm"
|
||||
name="ltiLaunchForm-${element_id}"
|
||||
class="ltiLaunchForm"
|
||||
method="post"
|
||||
target="ltiLaunchFrame"
|
||||
target="ltiLaunchFrame-${element_id}"
|
||||
encType="application/x-www-form-urlencoded"
|
||||
>
|
||||
<input name="launch_presentation_return_url" value="" />
|
||||
@@ -169,14 +173,15 @@ class LTIModule(LTIFields, XModule):
|
||||
client_key,
|
||||
client_secret
|
||||
)
|
||||
|
||||
context = {
|
||||
'input_fields': input_fields,
|
||||
|
||||
# these params do not participate in oauth signing
|
||||
'launch_url': self.launch_url,
|
||||
'element_id': self.location.html_id(),
|
||||
'element_class': self.location.category,
|
||||
'element_class': self.category,
|
||||
'open_in_a_new_page': self.open_in_a_new_page,
|
||||
'display_name': self.display_name,
|
||||
}
|
||||
|
||||
return self.system.render_template('lti.html', context)
|
||||
@@ -254,8 +259,8 @@ oauth_consumer_key="", oauth_signature="frVp4JuvT1mVXlxktiAUjQ7%2F1cw%3D"'}
|
||||
return params
|
||||
|
||||
|
||||
class LTIModuleDescriptor(LTIFields, MetadataOnlyEditingDescriptor):
|
||||
class LTIModuleDescriptor(LTIFields, MetadataOnlyEditingDescriptor, EmptyDataRawDescriptor):
|
||||
"""
|
||||
LTIModuleDescriptor provides no export/import to xml.
|
||||
Descriptor for LTI Xmodule.
|
||||
"""
|
||||
module_class = LTIModule
|
||||
|
||||
@@ -7,10 +7,13 @@ Passes settings.MODULESTORE as kwargs to MongoModuleStore
|
||||
from __future__ import absolute_import
|
||||
from importlib import import_module
|
||||
|
||||
import re
|
||||
|
||||
from django.conf import settings
|
||||
from django.core.cache import get_cache, InvalidCacheBackendError
|
||||
from django.dispatch import Signal
|
||||
from xmodule.modulestore.loc_mapper_store import LocMapperStore
|
||||
from xmodule.util.django import get_current_request_hostname
|
||||
|
||||
# We may not always have the request_cache module available
|
||||
try:
|
||||
@@ -67,11 +70,41 @@ def create_modulestore_instance(engine, options):
|
||||
)
|
||||
|
||||
|
||||
def modulestore(name='default'):
|
||||
def get_default_store_name_for_current_request():
|
||||
"""
|
||||
This method will return the appropriate default store mapping for the current Django request,
|
||||
else 'default' which is the system default
|
||||
"""
|
||||
store_name = 'default'
|
||||
|
||||
# see what request we are currently processing - if any at all - and get hostname for the request
|
||||
hostname = get_current_request_hostname()
|
||||
|
||||
# get mapping information which is defined in configurations
|
||||
mappings = getattr(settings, 'HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS', None)
|
||||
|
||||
# compare hostname against the regex expressions set of mappings
|
||||
# which will tell us which store name to use
|
||||
if hostname and mappings:
|
||||
for key in mappings.keys():
|
||||
if re.match(key, hostname):
|
||||
store_name = mappings[key]
|
||||
return store_name
|
||||
|
||||
return store_name
|
||||
|
||||
|
||||
def modulestore(name=None):
|
||||
"""
|
||||
This returns an instance of a modulestore of given name. This will wither return an existing
|
||||
modulestore or create a new one
|
||||
"""
|
||||
|
||||
if not name:
|
||||
# If caller did not specify name then we should
|
||||
# determine what should be the default
|
||||
name = get_default_store_name_for_current_request()
|
||||
|
||||
if name not in _MODULESTORES:
|
||||
_MODULESTORES[name] = create_modulestore_instance(settings.MODULESTORE[name]['ENGINE'],
|
||||
settings.MODULESTORE[name]['OPTIONS'])
|
||||
|
||||
@@ -21,7 +21,6 @@ from bson.son import SON
|
||||
from fs.osfs import OSFS
|
||||
from itertools import repeat
|
||||
from path import path
|
||||
from operator import attrgetter
|
||||
|
||||
from importlib import import_module
|
||||
from xmodule.errortracker import null_error_tracker, exc_info_to_str
|
||||
@@ -81,7 +80,7 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
else:
|
||||
return self._data[key.field_name]
|
||||
else:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
|
||||
def set(self, key, value):
|
||||
if key.scope == Scope.children:
|
||||
@@ -94,7 +93,7 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
else:
|
||||
self._data[key.field_name] = value
|
||||
else:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
|
||||
def delete(self, key):
|
||||
if key.scope == Scope.children:
|
||||
@@ -108,7 +107,7 @@ class MongoKeyValueStore(InheritanceKeyValueStore):
|
||||
else:
|
||||
del self._data[key.field_name]
|
||||
else:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
|
||||
def has(self, key):
|
||||
if key.scope in (Scope.children, Scope.parent):
|
||||
@@ -246,7 +245,9 @@ def location_to_query(location, wildcard=True):
|
||||
return query
|
||||
|
||||
|
||||
metadata_cache_key = attrgetter('org', 'course')
|
||||
def metadata_cache_key(location):
|
||||
"""Turn a `Location` into a useful cache key."""
|
||||
return u"{0.org}/{0.course}".format(location)
|
||||
|
||||
|
||||
class MongoModuleStore(ModuleStoreBase):
|
||||
|
||||
@@ -53,12 +53,12 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
|
||||
raise KeyError()
|
||||
else:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
|
||||
def set(self, key, value):
|
||||
# handle any special cases
|
||||
if key.scope not in [Scope.children, Scope.settings, Scope.content]:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
if key.scope == Scope.content:
|
||||
self._load_definition()
|
||||
|
||||
@@ -75,7 +75,7 @@ class SplitMongoKVS(InheritanceKeyValueStore):
|
||||
def delete(self, key):
|
||||
# handle any special cases
|
||||
if key.scope not in [Scope.children, Scope.settings, Scope.content]:
|
||||
raise InvalidScopeError(key.scope)
|
||||
raise InvalidScopeError(key)
|
||||
if key.scope == Scope.content:
|
||||
self._load_definition()
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ from pytz import UTC
|
||||
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.x_module import XModuleDescriptor
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
|
||||
|
||||
class Dummy(object):
|
||||
@@ -124,16 +123,28 @@ class ItemFactory(XModuleFactory):
|
||||
:target_class: is ignored
|
||||
"""
|
||||
|
||||
# All class attributes (from this class and base classes) are
|
||||
# passed in via **kwargs. However, some of those aren't actual field values,
|
||||
# so pop those off for use separately
|
||||
|
||||
DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info']
|
||||
# catch any old style users before they get into trouble
|
||||
assert not 'template' in kwargs
|
||||
data = kwargs.get('data')
|
||||
category = kwargs.get('category')
|
||||
display_name = kwargs.get('display_name')
|
||||
metadata = kwargs.get('metadata', {})
|
||||
location = kwargs.get('location')
|
||||
if kwargs.get('boilerplate') is not None:
|
||||
template_id = kwargs.get('boilerplate')
|
||||
assert 'template' not in kwargs
|
||||
parent_location = Location(kwargs.pop('parent_location', None))
|
||||
data = kwargs.pop('data', None)
|
||||
category = kwargs.pop('category', None)
|
||||
display_name = kwargs.pop('display_name', None)
|
||||
metadata = kwargs.pop('metadata', {})
|
||||
location = kwargs.pop('location')
|
||||
assert location != parent_location
|
||||
|
||||
store = kwargs.pop('modulestore')
|
||||
|
||||
# This code was based off that in cms/djangoapps/contentstore/views.py
|
||||
parent = kwargs.pop('parent', None) or store.get_item(parent_location)
|
||||
|
||||
if 'boilerplate' in kwargs:
|
||||
template_id = kwargs.pop('boilerplate')
|
||||
clz = XModuleDescriptor.load_class(category)
|
||||
template = clz.get_template(template_id)
|
||||
assert template is not None
|
||||
@@ -141,21 +152,20 @@ class ItemFactory(XModuleFactory):
|
||||
if not isinstance(data, basestring):
|
||||
data.update(template.get('data'))
|
||||
|
||||
store = kwargs.get('modulestore')
|
||||
|
||||
# replace the display name with an optional parameter passed in from the caller
|
||||
if display_name is not None:
|
||||
metadata['display_name'] = display_name
|
||||
store.create_and_save_xmodule(location, metadata=metadata, definition_data=data)
|
||||
module = store.create_and_save_xmodule(location, metadata=metadata, definition_data=data)
|
||||
|
||||
module = store.get_item(location)
|
||||
|
||||
for attr, val in kwargs.items():
|
||||
setattr(module, attr, val)
|
||||
module.save()
|
||||
|
||||
store.save_xmodule(module)
|
||||
|
||||
if location.category not in DETACHED_CATEGORIES:
|
||||
|
||||
parent_location = Location(kwargs.get('parent_location'))
|
||||
assert location != parent_location
|
||||
|
||||
# This code was based off that in cms/djangoapps/contentstore/views.py
|
||||
parent = kwargs.get('parent') or store.get_item(parent_location)
|
||||
|
||||
parent.children.append(location.url())
|
||||
store.update_children(parent_location, parent.children)
|
||||
|
||||
|
||||
@@ -129,7 +129,7 @@ class TestPublish(unittest.TestCase):
|
||||
"""
|
||||
Applies action depth-first down tree and to item last.
|
||||
|
||||
A copy of cms.djangoapps.contentstore.views.requests._xmodule_recurse to reproduce its use and behavior
|
||||
A copy of cms.djangoapps.contentstore.views.helpers._xmodule_recurse to reproduce its use and behavior
|
||||
outside of django.
|
||||
"""
|
||||
for child in item.get_children():
|
||||
|
||||
@@ -204,7 +204,7 @@ class ImportSystem(XMLParsingSystem, MakoDescriptorSystem):
|
||||
descriptor.save()
|
||||
return descriptor
|
||||
|
||||
render_template = lambda: ''
|
||||
render_template = lambda template, context: u''
|
||||
# TODO (vshnayder): we are somewhat architecturally confused in the loading code:
|
||||
# load_item should actually be get_instance, because it expects the course-specific
|
||||
# policy to be loaded. For now, just add the course_id here...
|
||||
|
||||
@@ -38,7 +38,7 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
|
||||
Export all modules from `modulestore` and content from `contentstore` as xml to `root_dir`.
|
||||
|
||||
`modulestore`: A `ModuleStore` object that is the source of the modules to export
|
||||
`contentstore`: A `ContentStore` object that is the source of the content to export
|
||||
`contentstore`: A `ContentStore` object that is the source of the content to export, can be None
|
||||
`course_location`: The `Location` of the `CourseModuleDescriptor` to export
|
||||
`root_dir`: The directory to write the exported xml to
|
||||
`course_dir`: The name of the directory inside `root_dir` to write the course content to
|
||||
@@ -46,7 +46,12 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
|
||||
alongside the public content in the course.
|
||||
"""
|
||||
|
||||
course = modulestore.get_item(course_location)
|
||||
# we use get_instance instead of get_item to support modulestores
|
||||
# that can't guarantee that definitions are unique
|
||||
course = modulestore.get_instance(
|
||||
course_location.course_id,
|
||||
course_location
|
||||
)
|
||||
|
||||
fs = OSFS(root_dir)
|
||||
export_fs = fs.makeopendir(course_dir)
|
||||
@@ -55,13 +60,14 @@ def export_to_xml(modulestore, contentstore, course_location, root_dir, course_d
|
||||
with export_fs.open('course.xml', 'w') as course_xml:
|
||||
course_xml.write(xml)
|
||||
|
||||
policies_dir = export_fs.makeopendir('policies')
|
||||
# export the static assets
|
||||
contentstore.export_all_for_course(
|
||||
course_location,
|
||||
root_dir + '/' + course_dir + '/static/',
|
||||
root_dir + '/' + course_dir + '/policies/assets.json',
|
||||
)
|
||||
policies_dir = export_fs.makeopendir('policies')
|
||||
if contentstore:
|
||||
contentstore.export_all_for_course(
|
||||
course_location,
|
||||
root_dir + '/' + course_dir + '/static/',
|
||||
root_dir + '/' + course_dir + '/policies/assets.json',
|
||||
)
|
||||
|
||||
# export the static tabs
|
||||
export_extra_content(export_fs, modulestore, course_location, 'static_tab', 'tabs', '.html')
|
||||
|
||||
@@ -819,10 +819,14 @@ class CombinedOpenEndedV1Module():
|
||||
Output: The status html to be rendered
|
||||
"""
|
||||
status = []
|
||||
current_task_human_name = ""
|
||||
for i in xrange(0, len(self.task_xml)):
|
||||
human_task_name = self.extract_human_name_from_task(self.task_xml[i])
|
||||
|
||||
task_data = {'task_number': i + 1, 'human_task' : human_task_name, 'current' : self.current_task_number==i}
|
||||
# Extract the name of the current task for screen readers.
|
||||
if self.current_task_number == i:
|
||||
current_task_human_name = human_task_name
|
||||
task_data = {'task_number': i + 1, 'human_task': human_task_name, 'current': self.current_task_number==i}
|
||||
status.append(task_data)
|
||||
|
||||
context = {
|
||||
@@ -830,6 +834,7 @@ class CombinedOpenEndedV1Module():
|
||||
'grader_type_image_dict': GRADER_TYPE_IMAGE_DICT,
|
||||
'legend_list': LEGEND_LIST,
|
||||
'render_via_ajax': render_via_ajax,
|
||||
'current_task_human_name': current_task_human_name,
|
||||
}
|
||||
status_html = self.system.render_template("{0}/combined_open_ended_status.html".format(self.TEMPLATE_DIR),
|
||||
context)
|
||||
|
||||
@@ -696,6 +696,13 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
correct = ""
|
||||
previous_answer = self.get_display_answer()
|
||||
|
||||
# Use the module name as a unique id to pass to the template.
|
||||
try:
|
||||
module_id = self.system.location.name
|
||||
except AttributeError:
|
||||
# In cases where we don't have a system or a location, use a fallback.
|
||||
module_id = "open_ended"
|
||||
|
||||
context = {
|
||||
'prompt': self.child_prompt,
|
||||
'previous_answer': previous_answer,
|
||||
@@ -703,7 +710,7 @@ class OpenEndedModule(openendedchild.OpenEndedChild):
|
||||
'allow_reset': self._allow_reset(),
|
||||
'rows': 30,
|
||||
'cols': 80,
|
||||
'id': 'open_ended',
|
||||
'module_id': module_id,
|
||||
'msg': post_assessment,
|
||||
'child_type': 'openended',
|
||||
'correct': correct,
|
||||
|
||||
@@ -57,6 +57,13 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
# set context variables and render template
|
||||
previous_answer = self.get_display_answer()
|
||||
|
||||
# Use the module name as a unique id to pass to the template.
|
||||
try:
|
||||
module_id = self.system.location.name
|
||||
except AttributeError:
|
||||
# In cases where we don't have a system or a location, use a fallback.
|
||||
module_id = "self_assessment"
|
||||
|
||||
context = {
|
||||
'prompt': self.child_prompt,
|
||||
'previous_answer': previous_answer,
|
||||
@@ -66,6 +73,7 @@ class SelfAssessmentModule(openendedchild.OpenEndedChild):
|
||||
'allow_reset': self._allow_reset(),
|
||||
'child_type': 'selfassessment',
|
||||
'accept_file_upload': self.accept_file_upload,
|
||||
'module_id': module_id,
|
||||
}
|
||||
|
||||
html = system.render_template('{0}/self_assessment_prompt.html'.format(self.TEMPLATE_DIR), context)
|
||||
|
||||
@@ -6,7 +6,7 @@ from lxml import etree
|
||||
from datetime import datetime
|
||||
from pkg_resources import resource_string
|
||||
from .capa_module import ComplexEncoder
|
||||
from .x_module import XModule
|
||||
from .x_module import XModule, module_attr
|
||||
from xmodule.raw_module import RawDescriptor
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError, NoPathToItem
|
||||
from .timeinfo import TimeInfo
|
||||
@@ -106,7 +106,7 @@ class PeerGradingModule(PeerGradingFields, XModule):
|
||||
|
||||
#We need to set the location here so the child modules can use it
|
||||
self.runtime.set('location', self.location)
|
||||
if (self.system.open_ended_grading_interface):
|
||||
if (self.runtime.open_ended_grading_interface):
|
||||
self.peer_gs = PeerGradingService(self.system.open_ended_grading_interface, self.system)
|
||||
else:
|
||||
self.peer_gs = MockPeerGradingService()
|
||||
@@ -662,3 +662,19 @@ class PeerGradingDescriptor(PeerGradingFields, RawDescriptor):
|
||||
return [self.system.load_item(self.link_to_location)]
|
||||
else:
|
||||
return []
|
||||
|
||||
# Proxy to PeerGradingModule so that external callers don't have to know if they're working
|
||||
# with a module or a descriptor
|
||||
closed = module_attr('closed')
|
||||
get_instance_state = module_attr('get_instance_state')
|
||||
get_next_submission = module_attr('get_next_submission')
|
||||
is_student_calibrated = module_attr('is_student_calibrated')
|
||||
peer_grading = module_attr('peer_grading')
|
||||
peer_grading_closed = module_attr('peer_grading_closed')
|
||||
peer_grading_problem = module_attr('peer_grading_problem')
|
||||
peer_gs = module_attr('peer_gs')
|
||||
query_data_for_location = module_attr('query_data_for_location')
|
||||
save_calibration_essay = module_attr('save_calibration_essay')
|
||||
save_grade = module_attr('save_grade')
|
||||
show_calibration_essay = module_attr('show_calibration_essay')
|
||||
_find_corresponding_module_for_location = module_attr('_find_corresponding_module_for_location')
|
||||
|
||||
@@ -7,6 +7,7 @@ from xmodule.seq_module import SequenceDescriptor
|
||||
from lxml import etree
|
||||
|
||||
from xblock.fields import Scope, Integer
|
||||
from xblock.fragment import Fragment
|
||||
|
||||
log = logging.getLogger('mitx.' + __name__)
|
||||
|
||||
@@ -77,12 +78,12 @@ class RandomizeModule(RandomizeFields, XModule):
|
||||
return [self.child_descriptor]
|
||||
|
||||
|
||||
def get_html(self):
|
||||
def student_view(self, context):
|
||||
if self.child is None:
|
||||
# raise error instead? In fact, could complain on descriptor load...
|
||||
return u"<div>Nothing to randomize between</div>"
|
||||
return Fragment(content=u"<div>Nothing to randomize between</div>")
|
||||
|
||||
return self.runtime.render_child(self.child, None, 'student_view').content
|
||||
return self.child.render('student_view', context)
|
||||
|
||||
def get_icon_class(self):
|
||||
return self.child.get_icon_class() if self.child else 'other'
|
||||
|
||||
@@ -9,6 +9,7 @@ from xmodule.x_module import XModule
|
||||
from xmodule.progress import Progress
|
||||
from xmodule.exceptions import NotFoundError
|
||||
from xblock.fields import Integer, Scope
|
||||
from xblock.fragment import Fragment
|
||||
from pkg_resources import resource_string
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -43,15 +44,6 @@ class SequenceModule(SequenceFields, XModule):
|
||||
if getattr(self.system, 'position', None) is not None:
|
||||
self.position = int(self.system.position)
|
||||
|
||||
self.rendered = False
|
||||
|
||||
def get_instance_state(self):
|
||||
return json.dumps({'position': self.position})
|
||||
|
||||
def get_html(self):
|
||||
self.render()
|
||||
return self.content
|
||||
|
||||
def get_progress(self):
|
||||
''' Return the total progress, adding total done and total available.
|
||||
(assumes that each submodule uses the same "units" for progress.)
|
||||
@@ -69,20 +61,24 @@ class SequenceModule(SequenceFields, XModule):
|
||||
return json.dumps({'success': True})
|
||||
raise NotFoundError('Unexpected dispatch type')
|
||||
|
||||
def render(self):
|
||||
def student_view(self, context):
|
||||
# If we're rendering this sequence, but no position is set yet,
|
||||
# default the position to the first element
|
||||
if self.position is None:
|
||||
self.position = 1
|
||||
|
||||
if self.rendered:
|
||||
return
|
||||
## Returns a set of all types of all sub-children
|
||||
contents = []
|
||||
|
||||
fragment = Fragment()
|
||||
|
||||
for child in self.get_display_items():
|
||||
progress = child.get_progress()
|
||||
rendered_child = child.render('student_view', context)
|
||||
fragment.add_frag_resources(rendered_child)
|
||||
|
||||
childinfo = {
|
||||
'content': self.runtime.render_child(child, None, 'student_view').content,
|
||||
'content': rendered_child.content,
|
||||
'title': "\n".join(
|
||||
grand_child.display_name
|
||||
for grand_child in child.get_children()
|
||||
@@ -101,11 +97,12 @@ class SequenceModule(SequenceFields, XModule):
|
||||
'element_id': self.location.html_id(),
|
||||
'item_id': self.id,
|
||||
'position': self.position,
|
||||
'tag': self.location.category
|
||||
'tag': self.location.category,
|
||||
}
|
||||
|
||||
self.content = self.system.render_template('seq_module.html', params)
|
||||
self.rendered = True
|
||||
fragment.add_content(self.system.render_template('seq_module.html', params))
|
||||
|
||||
return fragment
|
||||
|
||||
def get_icon_class(self):
|
||||
child_classes = set(child.get_icon_class()
|
||||
|
||||
@@ -9,6 +9,7 @@ Run like this:
|
||||
|
||||
import json
|
||||
import os
|
||||
import pprint
|
||||
import unittest
|
||||
|
||||
from mock import Mock
|
||||
@@ -18,6 +19,7 @@ from xblock.field_data import DictFieldData
|
||||
from xmodule.x_module import ModuleSystem, XModuleDescriptor, XModuleMixin
|
||||
from xmodule.modulestore.inheritance import InheritanceMixin
|
||||
from xmodule.mako_module import MakoDescriptorSystem
|
||||
from xmodule.error_module import ErrorDescriptor
|
||||
|
||||
|
||||
# Location of common test DATA directory
|
||||
@@ -54,18 +56,18 @@ def get_test_system(course_id=''):
|
||||
ajax_url='courses/course_id/modx/a_location',
|
||||
track_function=Mock(),
|
||||
get_module=Mock(),
|
||||
render_template=lambda template, context: repr(context),
|
||||
replace_urls=lambda html: str(html),
|
||||
render_template=mock_render_template,
|
||||
replace_urls=str,
|
||||
user=Mock(is_staff=False),
|
||||
filestore=Mock(),
|
||||
debug=True,
|
||||
hostname="edx.org",
|
||||
xqueue={'interface': None, 'callback_url': '/', 'default_queuename': 'testqueue', 'waittime': 10, 'construct_callback' : Mock(side_effect="/")},
|
||||
node_path=os.environ.get("NODE_PATH", "/usr/local/lib/node_modules"),
|
||||
xmodule_field_data=lambda descriptor: descriptor._field_data,
|
||||
anonymous_student_id='student',
|
||||
open_ended_grading_interface=open_ended_grading_interface,
|
||||
course_id=course_id,
|
||||
error_descriptor_class=ErrorDescriptor,
|
||||
)
|
||||
|
||||
|
||||
@@ -77,11 +79,21 @@ def get_test_descriptor_system():
|
||||
load_item=Mock(),
|
||||
resources_fs=Mock(),
|
||||
error_tracker=Mock(),
|
||||
render_template=lambda template, context: repr(context),
|
||||
render_template=mock_render_template,
|
||||
mixins=(InheritanceMixin, XModuleMixin),
|
||||
)
|
||||
|
||||
|
||||
def mock_render_template(*args, **kwargs):
|
||||
"""
|
||||
Pretty-print the args and kwargs.
|
||||
|
||||
Allows us to not depend on any actual template rendering mechanism,
|
||||
while still returning a unicode object
|
||||
"""
|
||||
return pprint.pformat((args, kwargs)).decode()
|
||||
|
||||
|
||||
class ModelsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
@@ -52,7 +52,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
|
||||
|
||||
actual_attr = self.annotatable._get_annotation_data_attr(0, el)
|
||||
|
||||
self.assertTrue(type(actual_attr) is dict)
|
||||
self.assertIsInstance(actual_attr, dict)
|
||||
self.assertDictEqual(expected_attr, actual_attr)
|
||||
|
||||
def test_annotation_class_attr_default(self):
|
||||
@@ -62,7 +62,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
|
||||
expected_attr = { 'class': { 'value': 'annotatable-span highlight' } }
|
||||
actual_attr = self.annotatable._get_annotation_class_attr(0, el)
|
||||
|
||||
self.assertTrue(type(actual_attr) is dict)
|
||||
self.assertIsInstance(actual_attr, dict)
|
||||
self.assertDictEqual(expected_attr, actual_attr)
|
||||
|
||||
def test_annotation_class_attr_with_valid_highlight(self):
|
||||
@@ -78,7 +78,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
|
||||
}
|
||||
actual_attr = self.annotatable._get_annotation_class_attr(0, el)
|
||||
|
||||
self.assertTrue(type(actual_attr) is dict)
|
||||
self.assertIsInstance(actual_attr, dict)
|
||||
self.assertDictEqual(expected_attr, actual_attr)
|
||||
|
||||
def test_annotation_class_attr_with_invalid_highlight(self):
|
||||
@@ -92,7 +92,7 @@ class AnnotatableModuleTestCase(unittest.TestCase):
|
||||
}
|
||||
actual_attr = self.annotatable._get_annotation_class_attr(0, el)
|
||||
|
||||
self.assertTrue(type(actual_attr) is dict)
|
||||
self.assertIsInstance(actual_attr, dict)
|
||||
self.assertDictEqual(expected_attr, actual_attr)
|
||||
|
||||
def test_render_annotation(self):
|
||||
|
||||
@@ -350,11 +350,11 @@ class OpenEndedModuleTest(unittest.TestCase):
|
||||
"""
|
||||
Test storing answer with the open ended module.
|
||||
"""
|
||||
|
||||
|
||||
# Create a module with no state yet. Important that this start off as a blank slate.
|
||||
test_module = OpenEndedModule(self.test_system, self.location,
|
||||
self.definition, self.descriptor, self.static_data, self.metadata)
|
||||
|
||||
|
||||
saved_response = "Saved response."
|
||||
submitted_response = "Submitted response."
|
||||
|
||||
@@ -519,7 +519,7 @@ class CombinedOpenEndedModuleTest(unittest.TestCase):
|
||||
"""
|
||||
See if we can get the max score from the actual xmodule
|
||||
"""
|
||||
#The progress view requires that this function be exposed
|
||||
# The progress view requires that this function be exposed
|
||||
max_score = self.combinedoe_container.max_score()
|
||||
self.assertEqual(max_score, None)
|
||||
|
||||
@@ -751,30 +751,38 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
|
||||
assessment = [0, 1]
|
||||
module = self.get_module_from_location(self.problem_location, COURSE)
|
||||
|
||||
#Simulate a student saving an answer
|
||||
# Simulate a student saving an answer
|
||||
html = module.handle_ajax("get_html", {})
|
||||
module.save()
|
||||
module.handle_ajax("save_answer", {"student_answer": self.answer})
|
||||
module.save()
|
||||
html = module.handle_ajax("get_html", {})
|
||||
module.save()
|
||||
|
||||
#Mock a student submitting an assessment
|
||||
# Mock a student submitting an assessment
|
||||
assessment_dict = MockQueryDict()
|
||||
assessment_dict.update({'assessment': sum(assessment), 'score_list[]': assessment})
|
||||
module.handle_ajax("save_assessment", assessment_dict)
|
||||
module.save()
|
||||
task_one_json = json.loads(module.task_states[0])
|
||||
self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment)
|
||||
rubric = module.handle_ajax("get_combined_rubric", {})
|
||||
module.save()
|
||||
|
||||
#Move to the next step in the problem
|
||||
# Move to the next step in the problem
|
||||
module.handle_ajax("next_problem", {})
|
||||
module.save()
|
||||
self.assertEqual(module.current_task_number, 0)
|
||||
|
||||
html = module.get_html()
|
||||
self.assertTrue(isinstance(html, basestring))
|
||||
html = module.render('student_view').content
|
||||
self.assertIsInstance(html, basestring)
|
||||
|
||||
rubric = module.handle_ajax("get_combined_rubric", {})
|
||||
self.assertTrue(isinstance(rubric, basestring))
|
||||
module.save()
|
||||
self.assertIsInstance(rubric, basestring)
|
||||
self.assertEqual(module.state, "assessing")
|
||||
module.handle_ajax("reset", {})
|
||||
module.save()
|
||||
self.assertEqual(module.current_task_number, 0)
|
||||
|
||||
def test_open_ended_flow_correct(self):
|
||||
@@ -784,38 +792,43 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
|
||||
@return:
|
||||
"""
|
||||
assessment = [1, 1]
|
||||
#Load the module
|
||||
# Load the module
|
||||
module = self.get_module_from_location(self.problem_location, COURSE)
|
||||
|
||||
#Simulate a student saving an answer
|
||||
# Simulate a student saving an answer
|
||||
module.handle_ajax("save_answer", {"student_answer": self.answer})
|
||||
module.save()
|
||||
status = module.handle_ajax("get_status", {})
|
||||
self.assertTrue(isinstance(status, basestring))
|
||||
module.save()
|
||||
self.assertIsInstance(status, basestring)
|
||||
|
||||
#Mock a student submitting an assessment
|
||||
# Mock a student submitting an assessment
|
||||
assessment_dict = MockQueryDict()
|
||||
assessment_dict.update({'assessment': sum(assessment), 'score_list[]': assessment})
|
||||
module.handle_ajax("save_assessment", assessment_dict)
|
||||
module.save()
|
||||
task_one_json = json.loads(module.task_states[0])
|
||||
self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment)
|
||||
|
||||
#Move to the next step in the problem
|
||||
# Move to the next step in the problem
|
||||
try:
|
||||
module.handle_ajax("next_problem", {})
|
||||
module.save()
|
||||
except GradingServiceError:
|
||||
#This error is okay. We don't have a grading service to connect to!
|
||||
# This error is okay. We don't have a grading service to connect to!
|
||||
pass
|
||||
self.assertEqual(module.current_task_number, 1)
|
||||
try:
|
||||
module.get_html()
|
||||
module.render('student_view')
|
||||
except GradingServiceError:
|
||||
#This error is okay. We don't have a grading service to connect to!
|
||||
# This error is okay. We don't have a grading service to connect to!
|
||||
pass
|
||||
|
||||
#Try to get the rubric from the module
|
||||
# Try to get the rubric from the module
|
||||
module.handle_ajax("get_combined_rubric", {})
|
||||
module.save()
|
||||
|
||||
#Make a fake reply from the queue
|
||||
# Make a fake reply from the queue
|
||||
queue_reply = {
|
||||
'queuekey': "",
|
||||
'xqueue_body': json.dumps({
|
||||
@@ -832,22 +845,27 @@ class OpenEndedModuleXmlTest(unittest.TestCase, DummyModulestore):
|
||||
}
|
||||
|
||||
module.handle_ajax("check_for_score", {})
|
||||
module.save()
|
||||
|
||||
#Update the module with the fake queue reply
|
||||
# Update the module with the fake queue reply
|
||||
module.handle_ajax("score_update", queue_reply)
|
||||
module.save()
|
||||
self.assertFalse(module.ready_to_reset)
|
||||
self.assertEqual(module.current_task_number, 1)
|
||||
|
||||
#Get html and other data client will request
|
||||
module.get_html()
|
||||
# Get html and other data client will request
|
||||
module.render('student_view')
|
||||
|
||||
module.handle_ajax("skip_post_assessment", {})
|
||||
module.save()
|
||||
|
||||
#Get all results
|
||||
# Get all results
|
||||
module.handle_ajax("get_combined_rubric", {})
|
||||
module.save()
|
||||
|
||||
#reset the problem
|
||||
# reset the problem
|
||||
module.handle_ajax("reset", {})
|
||||
module.save()
|
||||
self.assertEqual(module.state, "initial")
|
||||
|
||||
|
||||
@@ -876,31 +894,37 @@ class OpenEndedModuleXmlAttemptTest(unittest.TestCase, DummyModulestore):
|
||||
"""
|
||||
assessment = [0, 1]
|
||||
module = self.get_module_from_location(self.problem_location, COURSE)
|
||||
module.save()
|
||||
|
||||
#Simulate a student saving an answer
|
||||
# Simulate a student saving an answer
|
||||
module.handle_ajax("save_answer", {"student_answer": self.answer})
|
||||
module.save()
|
||||
|
||||
#Mock a student submitting an assessment
|
||||
# Mock a student submitting an assessment
|
||||
assessment_dict = MockQueryDict()
|
||||
assessment_dict.update({'assessment': sum(assessment), 'score_list[]': assessment})
|
||||
module.handle_ajax("save_assessment", assessment_dict)
|
||||
module.save()
|
||||
task_one_json = json.loads(module.task_states[0])
|
||||
self.assertEqual(json.loads(task_one_json['child_history'][0]['post_assessment']), assessment)
|
||||
|
||||
#Move to the next step in the problem
|
||||
# Move to the next step in the problem
|
||||
module.handle_ajax("next_problem", {})
|
||||
module.save()
|
||||
self.assertEqual(module.current_task_number, 0)
|
||||
|
||||
html = module.get_html()
|
||||
self.assertTrue(isinstance(html, basestring))
|
||||
html = module.render('student_view').content
|
||||
self.assertIsInstance(html, basestring)
|
||||
|
||||
#Module should now be done
|
||||
# Module should now be done
|
||||
rubric = module.handle_ajax("get_combined_rubric", {})
|
||||
self.assertTrue(isinstance(rubric, basestring))
|
||||
module.save()
|
||||
self.assertIsInstance(rubric, basestring)
|
||||
self.assertEqual(module.state, "done")
|
||||
|
||||
#Try to reset, should fail because only 1 attempt is allowed
|
||||
# Try to reset, should fail because only 1 attempt is allowed
|
||||
reset_data = json.loads(module.handle_ajax("reset", {}))
|
||||
module.save()
|
||||
self.assertEqual(reset_data['success'], False)
|
||||
|
||||
class OpenEndedModuleXmlImageUploadTest(unittest.TestCase, DummyModulestore):
|
||||
@@ -929,7 +953,7 @@ class OpenEndedModuleXmlImageUploadTest(unittest.TestCase, DummyModulestore):
|
||||
"""
|
||||
module = self.get_module_from_location(self.problem_location, COURSE)
|
||||
|
||||
#Simulate a student saving an answer
|
||||
# Simulate a student saving an answer
|
||||
response = module.handle_ajax("save_answer", {"student_answer": self.answer_text})
|
||||
response = json.loads(response)
|
||||
self.assertFalse(response['success'])
|
||||
@@ -949,7 +973,7 @@ class OpenEndedModuleXmlImageUploadTest(unittest.TestCase, DummyModulestore):
|
||||
"""
|
||||
module = self.get_module_from_location(self.problem_location, COURSE)
|
||||
|
||||
#Simulate a student saving an answer with a file
|
||||
# Simulate a student saving an answer with a file
|
||||
response = module.handle_ajax("save_answer", {
|
||||
"student_answer": self.answer_text,
|
||||
"valid_files_attached": True,
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
from ast import literal_eval
|
||||
import json
|
||||
import unittest
|
||||
@@ -8,12 +7,11 @@ from mock import Mock, patch
|
||||
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds
|
||||
from xblock.fragment import Fragment
|
||||
from xmodule.error_module import NonStaffErrorDescriptor
|
||||
from xmodule.modulestore import Location
|
||||
from xmodule.modulestore.xml import ImportSystem, XMLModuleStore
|
||||
from xmodule.conditional_module import ConditionalModule
|
||||
from xmodule.tests import DATA_DIR, get_test_system
|
||||
from xmodule.conditional_module import ConditionalDescriptor
|
||||
from xmodule.tests import DATA_DIR, get_test_system, get_test_descriptor_system
|
||||
|
||||
|
||||
ORG = 'test_org'
|
||||
@@ -26,20 +24,15 @@ class DummySystem(ImportSystem):
|
||||
def __init__(self, load_error_modules):
|
||||
|
||||
xmlstore = XMLModuleStore("data_dir", course_dirs=[], load_error_modules=load_error_modules)
|
||||
course_id = "/".join([ORG, COURSE, 'test_run'])
|
||||
course_dir = "test_dir"
|
||||
policy = {}
|
||||
error_tracker = Mock()
|
||||
parent_tracker = Mock()
|
||||
|
||||
super(DummySystem, self).__init__(
|
||||
xmlstore,
|
||||
course_id,
|
||||
course_dir,
|
||||
policy,
|
||||
error_tracker,
|
||||
parent_tracker,
|
||||
xmlstore=xmlstore,
|
||||
course_id='/'.join([ORG, COURSE, 'test_run']),
|
||||
course_dir='test_dir',
|
||||
error_tracker=Mock(),
|
||||
parent_tracker=Mock(),
|
||||
load_error_modules=load_error_modules,
|
||||
policy={},
|
||||
)
|
||||
|
||||
def render_template(self, template, context):
|
||||
@@ -59,52 +52,58 @@ class ConditionalFactory(object):
|
||||
|
||||
if the source_is_error_module flag is set, create a real ErrorModule for the source.
|
||||
"""
|
||||
descriptor_system = get_test_descriptor_system()
|
||||
|
||||
# construct source descriptor and module:
|
||||
source_location = Location(["i4x", "edX", "conditional_test", "problem", "SampleProblem"])
|
||||
if source_is_error_module:
|
||||
# Make an error descriptor and module
|
||||
source_descriptor = NonStaffErrorDescriptor.from_xml('some random xml data',
|
||||
system,
|
||||
org=source_location.org,
|
||||
course=source_location.course,
|
||||
error_msg='random error message')
|
||||
source_module = source_descriptor.xmodule(system)
|
||||
source_descriptor = NonStaffErrorDescriptor.from_xml(
|
||||
'some random xml data',
|
||||
system,
|
||||
org=source_location.org,
|
||||
course=source_location.course,
|
||||
error_msg='random error message'
|
||||
)
|
||||
else:
|
||||
source_descriptor = Mock()
|
||||
source_descriptor.location = source_location
|
||||
source_module = Mock()
|
||||
|
||||
source_descriptor.runtime = descriptor_system
|
||||
source_descriptor.render = lambda view, context=None: descriptor_system.render(source_descriptor, view, context)
|
||||
|
||||
# construct other descriptors:
|
||||
child_descriptor = Mock()
|
||||
cond_descriptor = Mock()
|
||||
cond_descriptor.runtime = system
|
||||
cond_descriptor.get_required_module_descriptors = lambda: [source_descriptor, ]
|
||||
cond_descriptor.get_children = lambda: [child_descriptor, ]
|
||||
cond_descriptor.xml_attributes = {"attempted": "true"}
|
||||
child_descriptor._xmodule.student_view.return_value.content = u'<p>This is a secret</p>'
|
||||
child_descriptor.student_view = child_descriptor._xmodule.student_view
|
||||
child_descriptor.displayable_items.return_value = [child_descriptor]
|
||||
child_descriptor.runtime = descriptor_system
|
||||
child_descriptor.xmodule_runtime = get_test_system()
|
||||
child_descriptor.render = lambda view, context=None: descriptor_system.render(child_descriptor, view, context)
|
||||
|
||||
# create child module:
|
||||
child_module = Mock()
|
||||
child_module.runtime = system
|
||||
child_module.get_html.return_value = u'<p>This is a secret</p>'
|
||||
child_module.student_view.return_value = Fragment(child_module.get_html.return_value)
|
||||
child_module.displayable_items = lambda: [child_module]
|
||||
module_map = {source_descriptor: source_module, child_descriptor: child_module}
|
||||
system.get_module = lambda descriptor: module_map[descriptor]
|
||||
descriptor_system.load_item = {'child': child_descriptor, 'source': source_descriptor}.get
|
||||
|
||||
# construct conditional module:
|
||||
cond_location = Location(["i4x", "edX", "conditional_test", "conditional", "SampleConditional"])
|
||||
field_data = DictFieldData({'data': '<conditional/>', 'location': cond_location})
|
||||
cond_module = ConditionalModule(
|
||||
cond_descriptor,
|
||||
system,
|
||||
field_data = DictFieldData({
|
||||
'data': '<conditional/>',
|
||||
'xml_attributes': {'attempted': 'true'},
|
||||
'children': ['child'],
|
||||
})
|
||||
|
||||
cond_descriptor = ConditionalDescriptor(
|
||||
descriptor_system,
|
||||
field_data,
|
||||
ScopeIds(None, None, cond_location, cond_location)
|
||||
)
|
||||
cond_descriptor.xmodule_runtime = system
|
||||
system.get_module = lambda desc: desc
|
||||
cond_descriptor.get_required_module_descriptors = Mock(return_value=[source_descriptor])
|
||||
|
||||
# return dict:
|
||||
return {'cond_module': cond_module,
|
||||
'source_module': source_module,
|
||||
'child_module': child_module}
|
||||
return {'cond_module': cond_descriptor,
|
||||
'source_module': source_descriptor,
|
||||
'child_module': child_descriptor}
|
||||
|
||||
|
||||
class ConditionalModuleBasicTest(unittest.TestCase):
|
||||
@@ -129,16 +128,20 @@ class ConditionalModuleBasicTest(unittest.TestCase):
|
||||
modules = ConditionalFactory.create(self.test_system)
|
||||
# because get_test_system returns the repr of the context dict passed to render_template,
|
||||
# we reverse it here
|
||||
html = modules['cond_module'].get_html()
|
||||
html_dict = literal_eval(html)
|
||||
self.assertEqual(html_dict['element_id'], 'i4x-edX-conditional_test-conditional-SampleConditional')
|
||||
self.assertEqual(html_dict['id'], 'i4x://edX/conditional_test/conditional/SampleConditional')
|
||||
self.assertEqual(html_dict['depends'], 'i4x-edX-conditional_test-problem-SampleProblem')
|
||||
html = modules['cond_module'].render('student_view').content
|
||||
expected = modules['cond_module'].xmodule_runtime.render_template('conditional_ajax.html', {
|
||||
'ajax_url': modules['cond_module'].xmodule_runtime.ajax_url,
|
||||
'element_id': 'i4x-edX-conditional_test-conditional-SampleConditional',
|
||||
'id': 'i4x://edX/conditional_test/conditional/SampleConditional',
|
||||
'depends': 'i4x-edX-conditional_test-problem-SampleProblem',
|
||||
})
|
||||
self.assertEquals(expected, html)
|
||||
|
||||
def test_handle_ajax(self):
|
||||
modules = ConditionalFactory.create(self.test_system)
|
||||
modules['source_module'].is_attempted = "false"
|
||||
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
|
||||
modules['cond_module'].save()
|
||||
print "ajax: ", ajax
|
||||
html = ajax['html']
|
||||
self.assertFalse(any(['This is a secret' in item for item in html]))
|
||||
@@ -146,6 +149,7 @@ class ConditionalModuleBasicTest(unittest.TestCase):
|
||||
# now change state of the capa problem to make it completed
|
||||
modules['source_module'].is_attempted = "true"
|
||||
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
|
||||
modules['cond_module'].save()
|
||||
print "post-attempt ajax: ", ajax
|
||||
html = ajax['html']
|
||||
self.assertTrue(any(['This is a secret' in item for item in html]))
|
||||
@@ -157,6 +161,7 @@ class ConditionalModuleBasicTest(unittest.TestCase):
|
||||
'''
|
||||
modules = ConditionalFactory.create(self.test_system, source_is_error_module=True)
|
||||
ajax = json.loads(modules['cond_module'].handle_ajax('', ''))
|
||||
modules['cond_module'].save()
|
||||
html = ajax['html']
|
||||
self.assertFalse(any(['This is a secret' in item for item in html]))
|
||||
|
||||
@@ -196,7 +201,9 @@ class ConditionalModuleXmlTest(unittest.TestCase):
|
||||
if isinstance(descriptor, Location):
|
||||
location = descriptor
|
||||
descriptor = self.modulestore.get_instance(course.id, location, depth=None)
|
||||
return descriptor.xmodule(self.test_system)
|
||||
descriptor.xmodule_runtime = get_test_system()
|
||||
descriptor.xmodule_runtime.get_module = inner_get_module
|
||||
return descriptor
|
||||
|
||||
# edx - HarvardX
|
||||
# cond_test - ER22x
|
||||
@@ -209,20 +216,28 @@ class ConditionalModuleXmlTest(unittest.TestCase):
|
||||
|
||||
module = inner_get_module(location)
|
||||
print "module: ", module
|
||||
print "module.conditions_map: ", module.conditions_map
|
||||
print "module children: ", module.get_children()
|
||||
print "module display items (children): ", module.get_display_items()
|
||||
|
||||
html = module.get_html()
|
||||
html = module.render('student_view').content
|
||||
print "html type: ", type(html)
|
||||
print "html: ", html
|
||||
html_expect = "{'ajax_url': 'courses/course_id/modx/a_location', 'element_id': 'i4x-HarvardX-ER22x-conditional-condone', 'id': 'i4x://HarvardX/ER22x/conditional/condone', 'depends': 'i4x-HarvardX-ER22x-problem-choiceprob'}"
|
||||
html_expect = module.xmodule_runtime.render_template(
|
||||
'conditional_ajax.html',
|
||||
{
|
||||
'ajax_url': 'courses/course_id/modx/a_location',
|
||||
'element_id': 'i4x-HarvardX-ER22x-conditional-condone',
|
||||
'id': 'i4x://HarvardX/ER22x/conditional/condone',
|
||||
'depends': 'i4x-HarvardX-ER22x-problem-choiceprob'
|
||||
}
|
||||
)
|
||||
self.assertEqual(html, html_expect)
|
||||
|
||||
gdi = module.get_display_items()
|
||||
print "gdi=", gdi
|
||||
|
||||
ajax = json.loads(module.handle_ajax('', ''))
|
||||
module.save()
|
||||
print "ajax: ", ajax
|
||||
html = ajax['html']
|
||||
self.assertFalse(any(['This is a secret' in item for item in html]))
|
||||
@@ -234,6 +249,7 @@ class ConditionalModuleXmlTest(unittest.TestCase):
|
||||
inner_module.save()
|
||||
|
||||
ajax = json.loads(module.handle_ajax('', ''))
|
||||
module.save()
|
||||
print "post-attempt ajax: ", ajax
|
||||
html = ajax['html']
|
||||
self.assertTrue(any(['This is a secret' in item for item in html]))
|
||||
|
||||
@@ -10,6 +10,7 @@ from xmodule.crowdsource_hinter import CrowdsourceHinterModule
|
||||
from xmodule.vertical_module import VerticalModule, VerticalDescriptor
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fragment import Fragment
|
||||
from xblock.core import XBlock
|
||||
|
||||
from . import get_test_system
|
||||
|
||||
@@ -62,7 +63,8 @@ class CHModuleFactory(object):
|
||||
"""
|
||||
A factory method for making CHM's
|
||||
"""
|
||||
field_data = {'data': CHModuleFactory.sample_problem_xml}
|
||||
# Should have a single child, but it doesn't matter what that child is
|
||||
field_data = {'data': CHModuleFactory.sample_problem_xml, 'children': [None]}
|
||||
|
||||
if hints is not None:
|
||||
field_data['hints'] = hints
|
||||
@@ -106,7 +108,8 @@ class CHModuleFactory(object):
|
||||
# Make the descriptor have a capa problem child.
|
||||
capa_descriptor = MagicMock()
|
||||
capa_descriptor.name = 'capa'
|
||||
descriptor.get_children = lambda: [capa_descriptor]
|
||||
capa_descriptor.displayable_items.return_value = [capa_descriptor]
|
||||
descriptor.get_children.return_value = [capa_descriptor]
|
||||
|
||||
# Make a fake capa module.
|
||||
capa_module = MagicMock()
|
||||
@@ -128,7 +131,7 @@ class CHModuleFactory(object):
|
||||
responder.compare_answer = compare_answer
|
||||
|
||||
capa_module.lcp.responders = {'responder0': responder}
|
||||
capa_module.displayable_items = lambda: [capa_module]
|
||||
capa_module.displayable_items.return_value = [capa_module]
|
||||
|
||||
system = get_test_system()
|
||||
# Make the system have a marginally-functional get_module
|
||||
@@ -137,8 +140,7 @@ class CHModuleFactory(object):
|
||||
"""
|
||||
A fake module-maker.
|
||||
"""
|
||||
if descriptor.name == 'capa':
|
||||
return capa_module
|
||||
return capa_module
|
||||
system.get_module = fake_get_module
|
||||
module = CrowdsourceHinterModule(descriptor, system, DictFieldData(field_data), Mock())
|
||||
|
||||
@@ -205,15 +207,15 @@ class VerticalWithModulesFactory(object):
|
||||
return module
|
||||
|
||||
|
||||
class FakeChild(object):
|
||||
class FakeChild(XBlock):
|
||||
"""
|
||||
A fake Xmodule.
|
||||
"""
|
||||
def __init__(self):
|
||||
self.runtime = get_test_system()
|
||||
self.runtime.ajax_url = 'this/is/a/fake/ajax/url'
|
||||
self.student_view = Mock(return_value=Fragment(self.get_html()))
|
||||
self.save = Mock()
|
||||
self.id = 'i4x://this/is/a/fake/id'
|
||||
|
||||
def get_html(self):
|
||||
"""
|
||||
@@ -241,9 +243,9 @@ class CrowdsourceHinterTest(unittest.TestCase):
|
||||
"""
|
||||
return [FakeChild()]
|
||||
mock_module.get_display_items = fake_get_display_items
|
||||
out_html = mock_module.runtime.render(mock_module, None, 'student_view').content
|
||||
out_html = mock_module.render('student_view').content
|
||||
self.assertTrue('This is supposed to be test html.' in out_html)
|
||||
self.assertTrue('this/is/a/fake/ajax/url' in out_html)
|
||||
self.assertTrue('i4x://this/is/a/fake/id' in out_html)
|
||||
|
||||
def test_gethtml_nochild(self):
|
||||
"""
|
||||
@@ -258,7 +260,7 @@ class CrowdsourceHinterTest(unittest.TestCase):
|
||||
"""
|
||||
return []
|
||||
mock_module.get_display_items = fake_get_display_items
|
||||
out_html = mock_module.runtime.render(mock_module, None, 'student_view').content
|
||||
out_html = mock_module.render('student_view').content
|
||||
self.assertTrue('Error in loading crowdsourced hinter' in out_html)
|
||||
|
||||
@unittest.skip("Needs to be finished.")
|
||||
@@ -269,7 +271,7 @@ class CrowdsourceHinterTest(unittest.TestCase):
|
||||
NOT WORKING RIGHT NOW
|
||||
"""
|
||||
mock_module = VerticalWithModulesFactory.create()
|
||||
out_html = mock_module.runtime.render(mock_module, None, 'student_view').content
|
||||
out_html = mock_module.render('student_view').content
|
||||
self.assertTrue('Test numerical problem.' in out_html)
|
||||
self.assertTrue('Another test numerical problem.' in out_html)
|
||||
|
||||
|
||||
@@ -29,9 +29,9 @@ class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
|
||||
def test_error_module_xml_rendering(self):
|
||||
descriptor = error_module.ErrorDescriptor.from_xml(
|
||||
self.valid_xml, self.system, self.org, self.course, self.error_msg)
|
||||
self.assertTrue(isinstance(descriptor, error_module.ErrorDescriptor))
|
||||
module = descriptor.xmodule(self.system)
|
||||
context_repr = module.get_html()
|
||||
self.assertIsInstance(descriptor, error_module.ErrorDescriptor)
|
||||
descriptor.xmodule_runtime = self.system
|
||||
context_repr = self.system.render(descriptor, 'student_view').content
|
||||
self.assertIn(self.error_msg, context_repr)
|
||||
self.assertIn(repr(self.valid_xml), context_repr)
|
||||
|
||||
@@ -43,9 +43,9 @@ class TestErrorModule(unittest.TestCase, SetupTestErrorModules):
|
||||
|
||||
error_descriptor = error_module.ErrorDescriptor.from_descriptor(
|
||||
descriptor, self.error_msg)
|
||||
self.assertTrue(isinstance(error_descriptor, error_module.ErrorDescriptor))
|
||||
module = error_descriptor.xmodule(self.system)
|
||||
context_repr = module.get_html()
|
||||
self.assertIsInstance(error_descriptor, error_module.ErrorDescriptor)
|
||||
error_descriptor.xmodule_runtime = self.system
|
||||
context_repr = self.system.render(error_descriptor, 'student_view').content
|
||||
self.assertIn(self.error_msg, context_repr)
|
||||
self.assertIn(repr(descriptor), context_repr)
|
||||
|
||||
@@ -60,13 +60,13 @@ class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules):
|
||||
def test_non_staff_error_module_create(self):
|
||||
descriptor = error_module.NonStaffErrorDescriptor.from_xml(
|
||||
self.valid_xml, self.system, self.org, self.course)
|
||||
self.assertTrue(isinstance(descriptor, error_module.NonStaffErrorDescriptor))
|
||||
self.assertIsInstance(descriptor, error_module.NonStaffErrorDescriptor)
|
||||
|
||||
def test_from_xml_render(self):
|
||||
descriptor = error_module.NonStaffErrorDescriptor.from_xml(
|
||||
self.valid_xml, self.system, self.org, self.course)
|
||||
module = descriptor.xmodule(self.system)
|
||||
context_repr = module.get_html()
|
||||
descriptor.xmodule_runtime = self.system
|
||||
context_repr = self.system.render(descriptor, 'student_view').content
|
||||
self.assertNotIn(self.error_msg, context_repr)
|
||||
self.assertNotIn(repr(self.valid_xml), context_repr)
|
||||
|
||||
@@ -78,8 +78,8 @@ class TestNonStaffErrorModule(unittest.TestCase, SetupTestErrorModules):
|
||||
|
||||
error_descriptor = error_module.NonStaffErrorDescriptor.from_descriptor(
|
||||
descriptor, self.error_msg)
|
||||
self.assertTrue(isinstance(error_descriptor, error_module.ErrorDescriptor))
|
||||
module = error_descriptor.xmodule(self.system)
|
||||
context_repr = module.get_html()
|
||||
self.assertIsInstance(error_descriptor, error_module.ErrorDescriptor)
|
||||
error_descriptor.xmodule_runtime = self.system
|
||||
context_repr = self.system.render(error_descriptor, 'student_view').content
|
||||
self.assertNotIn(self.error_msg, context_repr)
|
||||
self.assertNotIn(str(descriptor), context_repr)
|
||||
|
||||
@@ -199,6 +199,7 @@ class PeerGradingModuleScoredTest(unittest.TestCase, DummyModulestore):
|
||||
html = peer_grading.peer_grading()
|
||||
self.assertIn("Peer-Graded", html)
|
||||
|
||||
|
||||
class PeerGradingModuleLinkedTest(unittest.TestCase, DummyModulestore):
|
||||
"""
|
||||
Test peer grading that is linked to an open ended module.
|
||||
|
||||
@@ -137,6 +137,6 @@ class ModuleProgressTest(unittest.TestCase):
|
||||
'''
|
||||
def test_xmodule_default(self):
|
||||
'''Make sure default get_progress exists, returns None'''
|
||||
xm = x_module.XModule(None, get_test_system(), DictFieldData({'location': 'a://b/c/d/e'}), Mock())
|
||||
xm = x_module.XModule(Mock(), get_test_system(), DictFieldData({'location': 'a://b/c/d/e'}), Mock())
|
||||
p = xm.get_progress()
|
||||
self.assertEqual(p, None)
|
||||
|
||||
File diff suppressed because one or more lines are too long
20
common/lib/xmodule/xmodule/tests/test_utils_django.py
Normal file
20
common/lib/xmodule/xmodule/tests/test_utils_django.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""Tests for methods defined in util/django.py"""
|
||||
from xmodule.util.django import get_current_request, get_current_request_hostname
|
||||
from nose.tools import assert_is_none
|
||||
from unittest import TestCase
|
||||
|
||||
class UtilDjangoTests(TestCase):
|
||||
"""
|
||||
Tests for methods exposed in util/django
|
||||
"""
|
||||
def test_get_current_request(self):
|
||||
"""
|
||||
Since we are running outside of Django assert that get_current_request returns None
|
||||
"""
|
||||
assert_is_none(get_current_request())
|
||||
|
||||
def test_get_current_request_hostname(self):
|
||||
"""
|
||||
Since we are running outside of Django assert that get_current_request_hostname returns None
|
||||
"""
|
||||
assert_is_none(get_current_request_hostname())
|
||||
@@ -2,6 +2,8 @@
|
||||
Tests for the wrapping layer that provides the XBlock API using XModule/Descriptor
|
||||
functionality
|
||||
"""
|
||||
# For tests, ignore access to protected members
|
||||
# pylint: disable=protected-access
|
||||
|
||||
from nose.tools import assert_equal # pylint: disable=E0611
|
||||
from unittest.case import SkipTest
|
||||
@@ -10,13 +12,14 @@ from mock import Mock
|
||||
from xblock.field_data import DictFieldData
|
||||
from xblock.fields import ScopeIds
|
||||
|
||||
from xmodule.x_module import ModuleSystem
|
||||
from xmodule.x_module import ModuleSystem, XModule, XModuleDescriptor
|
||||
from xmodule.mako_module import MakoDescriptorSystem
|
||||
from xmodule.annotatable_module import AnnotatableDescriptor
|
||||
from xmodule.capa_module import CapaDescriptor
|
||||
from xmodule.course_module import CourseDescriptor
|
||||
from xmodule.combined_open_ended_module import CombinedOpenEndedDescriptor
|
||||
from xmodule.discussion_module import DiscussionDescriptor
|
||||
from xmodule.error_module import ErrorDescriptor
|
||||
from xmodule.gst_module import GraphicalSliderToolDescriptor
|
||||
from xmodule.html_module import HtmlDescriptor
|
||||
from xmodule.peer_grading_module import PeerGradingDescriptor
|
||||
@@ -29,7 +32,7 @@ from xmodule.conditional_module import ConditionalDescriptor
|
||||
from xmodule.randomize_module import RandomizeDescriptor
|
||||
from xmodule.vertical_module import VerticalDescriptor
|
||||
from xmodule.wrapper_module import WrapperDescriptor
|
||||
from xmodule.tests import get_test_descriptor_system
|
||||
from xmodule.tests import get_test_descriptor_system, mock_render_template
|
||||
|
||||
LEAF_XMODULES = (
|
||||
AnnotatableDescriptor,
|
||||
@@ -40,21 +43,20 @@ LEAF_XMODULES = (
|
||||
HtmlDescriptor,
|
||||
PeerGradingDescriptor,
|
||||
PollDescriptor,
|
||||
WordCloudDescriptor,
|
||||
# This is being excluded because it has dependencies on django
|
||||
#VideoDescriptor,
|
||||
WordCloudDescriptor,
|
||||
)
|
||||
|
||||
|
||||
CONTAINER_XMODULES = (
|
||||
CrowdsourceHinterDescriptor,
|
||||
CourseDescriptor,
|
||||
SequenceDescriptor,
|
||||
ConditionalDescriptor,
|
||||
CourseDescriptor,
|
||||
CrowdsourceHinterDescriptor,
|
||||
RandomizeDescriptor,
|
||||
SequenceDescriptor,
|
||||
VerticalDescriptor,
|
||||
WrapperDescriptor,
|
||||
CourseDescriptor,
|
||||
)
|
||||
|
||||
# These modules are editable in studio yet
|
||||
@@ -66,26 +68,24 @@ NOT_STUDIO_EDITABLE = (
|
||||
|
||||
|
||||
class TestXBlockWrapper(object):
|
||||
|
||||
@property
|
||||
def leaf_module_runtime(self):
|
||||
runtime = ModuleSystem(
|
||||
render_template=lambda *args, **kwargs: u'{!r}, {!r}'.format(args, kwargs),
|
||||
render_template=mock_render_template,
|
||||
anonymous_student_id='dummy_anonymous_student_id',
|
||||
open_ended_grading_interface={},
|
||||
static_url='/static',
|
||||
ajax_url='dummy_ajax_url',
|
||||
xmodule_field_data=lambda d: d._field_data,
|
||||
get_module=Mock(),
|
||||
replace_urls=Mock(),
|
||||
track_function=Mock(),
|
||||
error_descriptor_class=ErrorDescriptor,
|
||||
)
|
||||
return runtime
|
||||
|
||||
def leaf_descriptor(self, descriptor_cls):
|
||||
location = 'i4x://org/course/category/name'
|
||||
runtime = get_test_descriptor_system()
|
||||
runtime.render_template = lambda *args, **kwargs: u'{!r}, {!r}'.format(args, kwargs)
|
||||
return runtime.construct_xblock_from_class(
|
||||
descriptor_cls,
|
||||
ScopeIds(None, descriptor_cls.__name__, location, location),
|
||||
@@ -93,7 +93,10 @@ class TestXBlockWrapper(object):
|
||||
)
|
||||
|
||||
def leaf_module(self, descriptor_cls):
|
||||
return self.leaf_descriptor(descriptor_cls).xmodule(self.leaf_module_runtime)
|
||||
"""Returns a descriptor that is ready to proxy as an xmodule"""
|
||||
descriptor = self.leaf_descriptor(descriptor_cls)
|
||||
descriptor.xmodule_runtime = self.leaf_module_runtime
|
||||
return descriptor
|
||||
|
||||
def container_module_runtime(self, depth):
|
||||
runtime = self.leaf_module_runtime
|
||||
@@ -104,10 +107,16 @@ class TestXBlockWrapper(object):
|
||||
runtime.position = 2
|
||||
return runtime
|
||||
|
||||
def container_descriptor(self, descriptor_cls):
|
||||
def container_descriptor(self, descriptor_cls, depth):
|
||||
"""Return an instance of `descriptor_cls` with `depth` levels of children"""
|
||||
location = 'i4x://org/course/category/name'
|
||||
runtime = get_test_descriptor_system()
|
||||
runtime.render_template = lambda *args, **kwargs: u'{!r}, {!r}'.format(args, kwargs)
|
||||
|
||||
if depth == 0:
|
||||
runtime.load_item.side_effect = lambda x: self.leaf_module(HtmlDescriptor)
|
||||
else:
|
||||
runtime.load_item.side_effect = lambda x: self.container_module(VerticalDescriptor, depth - 1)
|
||||
|
||||
return runtime.construct_xblock_from_class(
|
||||
descriptor_cls,
|
||||
ScopeIds(None, descriptor_cls.__name__, location, location),
|
||||
@@ -117,7 +126,10 @@ class TestXBlockWrapper(object):
|
||||
)
|
||||
|
||||
def container_module(self, descriptor_cls, depth):
|
||||
return self.container_descriptor(descriptor_cls).xmodule(self.container_module_runtime(depth))
|
||||
"""Returns a descriptor that is ready to proxy as an xmodule"""
|
||||
descriptor = self.container_descriptor(descriptor_cls, depth)
|
||||
descriptor.xmodule_runtime = self.container_module_runtime(depth)
|
||||
return descriptor
|
||||
|
||||
class TestStudentView(TestXBlockWrapper):
|
||||
|
||||
@@ -131,9 +143,15 @@ class TestStudentView(TestXBlockWrapper):
|
||||
# Check that when an xmodule is instantiated from descriptor_cls
|
||||
# it generates the same thing from student_view that it does from get_html
|
||||
def check_student_view_leaf_node(self, descriptor_cls):
|
||||
xmodule = self.leaf_module(descriptor_cls)
|
||||
assert_equal(xmodule.get_html(), xmodule.runtime.render(xmodule, None, 'student_view').content)
|
||||
|
||||
if descriptor_cls.module_class.student_view != XModule.student_view:
|
||||
raise SkipTest(descriptor_cls.__name__ + " implements student_view")
|
||||
|
||||
descriptor = self.leaf_module(descriptor_cls)
|
||||
assert_equal(
|
||||
descriptor._xmodule.get_html(),
|
||||
descriptor.render('student_view').content
|
||||
)
|
||||
|
||||
# Test that for all container XModule Descriptors,
|
||||
# their corresponding XModule renders the same thing using student_view
|
||||
@@ -147,13 +165,19 @@ class TestStudentView(TestXBlockWrapper):
|
||||
yield self.check_student_view_container_node_mixed, descriptor_cls
|
||||
yield self.check_student_view_container_node_xblocks_only, descriptor_cls
|
||||
|
||||
|
||||
# Check that when an xmodule is generated from descriptor_cls
|
||||
# with only xmodule children, it generates the same html from student_view
|
||||
# as it does using get_html
|
||||
def check_student_view_container_node_xmodules_only(self, descriptor_cls):
|
||||
xmodule = self.container_module(descriptor_cls, 2)
|
||||
assert_equal(xmodule.get_html(), xmodule.runtime.render(xmodule, None, 'student_view').content)
|
||||
|
||||
if descriptor_cls.module_class.student_view != XModule.student_view:
|
||||
raise SkipTest(descriptor_cls.__name__ + " implements student_view")
|
||||
|
||||
descriptor = self.container_module(descriptor_cls, 2)
|
||||
assert_equal(
|
||||
descriptor._xmodule.get_html(),
|
||||
descriptor.render('student_view').content
|
||||
)
|
||||
|
||||
# Check that when an xmodule is generated from descriptor_cls
|
||||
# with mixed xmodule and xblock children, it generates the same html from student_view
|
||||
@@ -181,10 +205,13 @@ class TestStudioView(TestXBlockWrapper):
|
||||
# it generates the same thing from studio_view that it does from get_html
|
||||
def check_studio_view_leaf_node(self, descriptor_cls):
|
||||
if descriptor_cls in NOT_STUDIO_EDITABLE:
|
||||
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")
|
||||
raise SkipTest(descriptor_cls.__name__ + " is not editable in studio")
|
||||
|
||||
if descriptor_cls.studio_view != XModuleDescriptor.studio_view:
|
||||
raise SkipTest(descriptor_cls.__name__ + " implements studio_view")
|
||||
|
||||
descriptor = self.leaf_descriptor(descriptor_cls)
|
||||
assert_equal(descriptor.get_html(), descriptor.runtime.render(descriptor, None, 'studio_view').content)
|
||||
assert_equal(descriptor.get_html(), descriptor.render('studio_view').content)
|
||||
|
||||
|
||||
# Test that for all of the Descriptors listed in CONTAINER_XMODULES
|
||||
@@ -206,8 +233,11 @@ class TestStudioView(TestXBlockWrapper):
|
||||
if descriptor_cls in NOT_STUDIO_EDITABLE:
|
||||
raise SkipTest(descriptor_cls.__name__ + "is not editable in studio")
|
||||
|
||||
descriptor = self.container_descriptor(descriptor_cls)
|
||||
assert_equal(descriptor.get_html(), descriptor.runtime.render(descriptor, None, 'studio_view').content)
|
||||
if descriptor_cls.studio_view != XModuleDescriptor.studio_view:
|
||||
raise SkipTest(descriptor_cls.__name__ + " implements studio_view")
|
||||
|
||||
descriptor = self.container_descriptor(descriptor_cls, 2)
|
||||
assert_equal(descriptor.get_html(), descriptor.render('studio_view').content)
|
||||
|
||||
# Check that when a descriptor is generated from descriptor_cls
|
||||
# with mixed xmodule and xblock children, it generates the same html from studio_view
|
||||
|
||||
@@ -9,6 +9,7 @@ from xmodule.x_module import XModule
|
||||
from xmodule.progress import Progress
|
||||
from xmodule.exceptions import NotFoundError
|
||||
from xblock.fields import Float, String, Boolean, Scope
|
||||
from xblock.fragment import Fragment
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -84,14 +85,14 @@ class TimeLimitModule(TimeLimitFields, XModule):
|
||||
def get_remaining_time_in_ms(self):
|
||||
return int((self.ending_at - time()) * 1000)
|
||||
|
||||
def get_html(self):
|
||||
def student_view(self, context):
|
||||
# assumes there is one and only one child, so it only renders the first child
|
||||
children = self.get_display_items()
|
||||
if children:
|
||||
child = children[0]
|
||||
return self.runtime.render_child(child, None, 'student_view').content
|
||||
return child.render('student_view', context)
|
||||
else:
|
||||
return u""
|
||||
return Fragment()
|
||||
|
||||
def get_progress(self):
|
||||
''' Return the total progress, adding total done and total available.
|
||||
|
||||
20
common/lib/xmodule/xmodule/util/django.py
Normal file
20
common/lib/xmodule/xmodule/util/django.py
Normal file
@@ -0,0 +1,20 @@
|
||||
"""
|
||||
Exposes Django utilities for consumption in the xmodule library
|
||||
NOTE: This file should only be imported into 'django-safe' code, i.e. known that this code runs int the Django
|
||||
runtime environment with the djangoapps in common configured to load
|
||||
"""
|
||||
|
||||
# NOTE: we are importing this method so that any module that imports us has access to get_current_request
|
||||
from crum import get_current_request
|
||||
|
||||
|
||||
def get_current_request_hostname():
|
||||
"""
|
||||
This method will return the hostname that was used in the current Django request
|
||||
"""
|
||||
hostname = None
|
||||
request = get_current_request()
|
||||
if request:
|
||||
hostname = request.META.get('HTTP_HOST')
|
||||
|
||||
return hostname
|
||||
@@ -1,3 +1,4 @@
|
||||
from xblock.fragment import Fragment
|
||||
from xmodule.x_module import XModule
|
||||
from xmodule.seq_module import SequenceDescriptor
|
||||
from xmodule.progress import Progress
|
||||
@@ -17,18 +18,24 @@ class VerticalModule(VerticalFields, XModule):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
XModule.__init__(self, *args, **kwargs)
|
||||
self.contents = None
|
||||
|
||||
def get_html(self):
|
||||
if self.contents is None:
|
||||
self.contents = [{
|
||||
def student_view(self, context):
|
||||
fragment = Fragment()
|
||||
contents = []
|
||||
|
||||
for child in self.get_display_items():
|
||||
rendered_child = child.render('student_view', context)
|
||||
fragment.add_frag_resources(rendered_child)
|
||||
|
||||
contents.append({
|
||||
'id': child.id,
|
||||
'content': self.runtime.render_child(child, None, 'student_view').content
|
||||
} for child in self.get_display_items()]
|
||||
'content': rendered_child.content
|
||||
})
|
||||
|
||||
return self.system.render_template('vert_module.html', {
|
||||
'items': self.contents
|
||||
})
|
||||
fragment.add_content(self.system.render_template('vert_module.html', {
|
||||
'items': contents
|
||||
}))
|
||||
return fragment
|
||||
|
||||
def get_progress(self):
|
||||
# TODO: Cache progress or children array?
|
||||
|
||||
@@ -157,10 +157,6 @@ class VideoModule(VideoFields, XModule):
|
||||
log.debug(u"DISPATCH {0}".format(dispatch))
|
||||
raise Http404()
|
||||
|
||||
def get_instance_state(self):
|
||||
"""Return information about state (position)."""
|
||||
return json.dumps({'position': self.position})
|
||||
|
||||
def get_html(self):
|
||||
caption_asset_path = "/static/subs/"
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import logging
|
||||
import yaml
|
||||
import os
|
||||
import sys
|
||||
|
||||
from functools import partial
|
||||
from lxml import etree
|
||||
from collections import namedtuple
|
||||
from pkg_resources import resource_listdir, resource_string, resource_isdir
|
||||
@@ -13,6 +15,7 @@ from xblock.core import XBlock
|
||||
from xblock.fields import Scope, Integer, Float, List, XBlockMixin, String
|
||||
from xblock.fragment import Fragment
|
||||
from xblock.runtime import Runtime
|
||||
from xmodule.errortracker import exc_info_to_str
|
||||
from xmodule.modulestore.locator import BlockUsageLocator
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
@@ -214,78 +217,6 @@ class XModuleMixin(XBlockMixin):
|
||||
return child
|
||||
return None
|
||||
|
||||
|
||||
class XModule(XModuleMixin, HTMLSnippet, XBlock): # pylint: disable=abstract-method
|
||||
""" Implements a generic learning module.
|
||||
|
||||
Subclasses must at a minimum provide a definition for get_html in order
|
||||
to be displayed to users.
|
||||
|
||||
See the HTML module for a simple example.
|
||||
"""
|
||||
|
||||
# The default implementation of get_icon_class returns the icon_class
|
||||
# attribute of the class
|
||||
#
|
||||
# This attribute can be overridden by subclasses, and
|
||||
# the function can also be overridden if the icon class depends on the data
|
||||
# in the module
|
||||
icon_class = 'other'
|
||||
|
||||
def __init__(self, descriptor, *args, **kwargs):
|
||||
"""
|
||||
Construct a new xmodule
|
||||
|
||||
runtime: An XBlock runtime allowing access to external resources
|
||||
|
||||
descriptor: the XModuleDescriptor that this module is an instance of.
|
||||
|
||||
field_data: A dictionary-like object that maps field names to values
|
||||
for those fields.
|
||||
"""
|
||||
super(XModule, self).__init__(*args, **kwargs)
|
||||
self.system = self.runtime
|
||||
self.descriptor = descriptor
|
||||
self._loaded_children = None
|
||||
|
||||
def get_children(self):
|
||||
"""
|
||||
Return module instances for all the children of this module.
|
||||
"""
|
||||
if self._loaded_children is None:
|
||||
child_descriptors = self.get_child_descriptors()
|
||||
|
||||
# This deliberately uses system.get_module, rather than runtime.get_block,
|
||||
# because we're looking at XModule children, rather than XModuleDescriptor children.
|
||||
# That means it can use the deprecated XModule apis, rather than future XBlock apis
|
||||
|
||||
# TODO: Once we're in a system where this returns a mix of XModuleDescriptors
|
||||
# and XBlocks, we're likely to have to change this more
|
||||
children = [self.system.get_module(descriptor) for descriptor in child_descriptors]
|
||||
# get_module returns None if the current user doesn't have access
|
||||
# to the location.
|
||||
self._loaded_children = [c for c in children if c is not None]
|
||||
|
||||
return self._loaded_children
|
||||
|
||||
def __unicode__(self):
|
||||
return '<x_module(id={0})>'.format(self.id)
|
||||
|
||||
def get_child_descriptors(self):
|
||||
"""
|
||||
Returns the descriptors of the child modules
|
||||
|
||||
Overriding this changes the behavior of get_children and
|
||||
anything that uses get_children, such as get_display_items.
|
||||
|
||||
This method will not instantiate the modules of the children
|
||||
unless absolutely necessary, so it is cheaper to call than get_children
|
||||
|
||||
These children will be the same children returned by the
|
||||
descriptor unless descriptor.has_dynamic_children() is true.
|
||||
"""
|
||||
return self.descriptor.get_children()
|
||||
|
||||
def get_icon_class(self):
|
||||
"""
|
||||
Return a css class identifying this module in the context of an icon
|
||||
@@ -333,11 +264,156 @@ class XModule(XModuleMixin, HTMLSnippet, XBlock): # pylint: disable=abstract-me
|
||||
"""
|
||||
return None
|
||||
|
||||
def bind_for_student(self, xmodule_runtime, field_data):
|
||||
"""
|
||||
Set up this XBlock to act as an XModule instead of an XModuleDescriptor.
|
||||
|
||||
:param xmodule_runtime: the runtime to use when accessing student facing methods
|
||||
:type xmodule_runtime: :class:`ModuleSystem`
|
||||
:param field_data: The :class:`FieldData` to use for all subsequent data access
|
||||
:type field_data: :class:`FieldData`
|
||||
"""
|
||||
# pylint: disable=attribute-defined-outside-init
|
||||
self.xmodule_runtime = xmodule_runtime
|
||||
self._field_data = field_data
|
||||
|
||||
|
||||
class ProxyAttribute(object):
|
||||
"""
|
||||
A (python) descriptor that proxies attribute access.
|
||||
|
||||
For example:
|
||||
|
||||
class Foo(object):
|
||||
def __init__(self, value):
|
||||
self.foo_attr = value
|
||||
|
||||
class Bar(object):
|
||||
foo = Foo('x')
|
||||
foo_attr = ProxyAttribute('foo', 'foo_attr')
|
||||
|
||||
bar = Bar()
|
||||
|
||||
assert bar.foo_attr == 'x'
|
||||
bar.foo_attr = 'y'
|
||||
assert bar.foo.foo_attr == 'y'
|
||||
del bar.foo_attr
|
||||
assert not hasattr(bar.foo, 'foo_attr')
|
||||
"""
|
||||
def __init__(self, source, name):
|
||||
"""
|
||||
:param source: The name of the attribute to proxy to
|
||||
:param name: The name of the attribute to proxy
|
||||
"""
|
||||
self._source = source
|
||||
self._name = name
|
||||
|
||||
def __get__(self, instance, owner):
|
||||
if instance is None:
|
||||
return self
|
||||
|
||||
return getattr(getattr(instance, self._source), self._name)
|
||||
|
||||
def __set__(self, instance, value):
|
||||
setattr(getattr(instance, self._source), self._name, value)
|
||||
|
||||
def __delete__(self, instance):
|
||||
delattr(getattr(instance, self._source), self._name)
|
||||
|
||||
|
||||
module_attr = partial(ProxyAttribute, '_xmodule') # pylint: disable=invalid-name
|
||||
descriptor_attr = partial(ProxyAttribute, 'descriptor') # pylint: disable=invalid-name
|
||||
module_runtime_attr = partial(ProxyAttribute, 'xmodule_runtime') # pylint: disable=invalid-name
|
||||
|
||||
|
||||
class XModule(XModuleMixin, HTMLSnippet, XBlock): # pylint: disable=abstract-method
|
||||
""" Implements a generic learning module.
|
||||
|
||||
Subclasses must at a minimum provide a definition for get_html in order
|
||||
to be displayed to users.
|
||||
|
||||
See the HTML module for a simple example.
|
||||
"""
|
||||
|
||||
# The default implementation of get_icon_class returns the icon_class
|
||||
# attribute of the class
|
||||
#
|
||||
# This attribute can be overridden by subclasses, and
|
||||
# the function can also be overridden if the icon class depends on the data
|
||||
# in the module
|
||||
icon_class = 'other'
|
||||
|
||||
has_score = descriptor_attr('has_score')
|
||||
_field_data_cache = descriptor_attr('_field_data_cache')
|
||||
_field_data = descriptor_attr('_field_data')
|
||||
_dirty_fields = descriptor_attr('_dirty_fields')
|
||||
|
||||
def __init__(self, descriptor, *args, **kwargs):
|
||||
"""
|
||||
Construct a new xmodule
|
||||
|
||||
runtime: An XBlock runtime allowing access to external resources
|
||||
|
||||
descriptor: the XModuleDescriptor that this module is an instance of.
|
||||
|
||||
field_data: A dictionary-like object that maps field names to values
|
||||
for those fields.
|
||||
"""
|
||||
# Set the descriptor first so that we can proxy to it
|
||||
self.descriptor = descriptor
|
||||
super(XModule, self).__init__(*args, **kwargs)
|
||||
self._loaded_children = None
|
||||
self.system = self.runtime
|
||||
|
||||
def __unicode__(self):
|
||||
return u'<x_module(id={0})>'.format(self.id)
|
||||
|
||||
def handle_ajax(self, _dispatch, _data):
|
||||
""" dispatch is last part of the URL.
|
||||
data is a dictionary-like object with the content of the request"""
|
||||
return ""
|
||||
return u""
|
||||
|
||||
def get_children(self):
|
||||
"""
|
||||
Return module instances for all the children of this module.
|
||||
"""
|
||||
if self._loaded_children is None:
|
||||
child_descriptors = self.get_child_descriptors()
|
||||
|
||||
# This deliberately uses system.get_module, rather than runtime.get_block,
|
||||
# because we're looking at XModule children, rather than XModuleDescriptor children.
|
||||
# That means it can use the deprecated XModule apis, rather than future XBlock apis
|
||||
|
||||
# TODO: Once we're in a system where this returns a mix of XModuleDescriptors
|
||||
# and XBlocks, we're likely to have to change this more
|
||||
children = [self.system.get_module(descriptor) for descriptor in child_descriptors]
|
||||
# get_module returns None if the current user doesn't have access
|
||||
# to the location.
|
||||
self._loaded_children = [c for c in children if c is not None]
|
||||
|
||||
return self._loaded_children
|
||||
|
||||
def get_child_descriptors(self):
|
||||
"""
|
||||
Returns the descriptors of the child modules
|
||||
|
||||
Overriding this changes the behavior of get_children and
|
||||
anything that uses get_children, such as get_display_items.
|
||||
|
||||
This method will not instantiate the modules of the children
|
||||
unless absolutely necessary, so it is cheaper to call than get_children
|
||||
|
||||
These children will be the same children returned by the
|
||||
descriptor unless descriptor.has_dynamic_children() is true.
|
||||
"""
|
||||
return self.descriptor.get_children()
|
||||
|
||||
def displayable_items(self):
|
||||
"""
|
||||
Returns list of displayable modules contained by this module. If this
|
||||
module is visible, should return [self].
|
||||
"""
|
||||
return [self.descriptor]
|
||||
|
||||
# ~~~~~~~~~~~~~~~ XBlock API Wrappers ~~~~~~~~~~~~~~~~
|
||||
def student_view(self, context):
|
||||
@@ -489,24 +565,7 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
|
||||
# by following previous until None
|
||||
# definition_locator is only used by mongostores which separate definitions from blocks
|
||||
self.edited_by = self.edited_on = self.previous_version = self.update_version = self.definition_locator = None
|
||||
self._child_instances = None
|
||||
|
||||
|
||||
def xmodule(self, system):
|
||||
"""
|
||||
Returns an XModule.
|
||||
|
||||
system: Module system
|
||||
"""
|
||||
# save any field changes
|
||||
module = system.construct_xblock_from_class(
|
||||
self.module_class,
|
||||
descriptor=self,
|
||||
scope_ids=self.scope_ids,
|
||||
field_data=system.xmodule_field_data(self),
|
||||
)
|
||||
module.save()
|
||||
return module
|
||||
self.xmodule_runtime = None
|
||||
|
||||
def has_dynamic_children(self):
|
||||
"""
|
||||
@@ -644,6 +703,42 @@ class XModuleDescriptor(XModuleMixin, HTMLSnippet, ResourceTemplates, XBlock):
|
||||
|
||||
return metadata_fields
|
||||
|
||||
# ~~~~~~~~~~~~~~~ XModule Indirection ~~~~~~~~~~~~~~~~
|
||||
@property
|
||||
def _xmodule(self):
|
||||
"""
|
||||
Returns the XModule corresponding to this descriptor. Expects that the system
|
||||
already supports all of the attributes needed by xmodules
|
||||
"""
|
||||
assert self.xmodule_runtime is not None
|
||||
assert self.xmodule_runtime.error_descriptor_class is not None
|
||||
if self.xmodule_runtime.xmodule_instance is None:
|
||||
try:
|
||||
self.xmodule_runtime.xmodule_instance = self.xmodule_runtime.construct_xblock_from_class(
|
||||
self.module_class,
|
||||
descriptor=self,
|
||||
scope_ids=self.scope_ids,
|
||||
field_data=self._field_data,
|
||||
)
|
||||
self.xmodule_runtime.xmodule_instance.save()
|
||||
except Exception: # pylint: disable=broad-except
|
||||
log.exception('Error creating xmodule')
|
||||
descriptor = self.xmodule_runtime.error_descriptor_class.from_descriptor(
|
||||
self,
|
||||
error_msg=exc_info_to_str(sys.exc_info())
|
||||
)
|
||||
self.xmodule_runtime.xmodule_instance = descriptor._xmodule # pylint: disable=protected-access
|
||||
return self.xmodule_runtime.xmodule_instance
|
||||
|
||||
displayable_items = module_attr('displayable_items')
|
||||
get_display_items = module_attr('get_display_items')
|
||||
get_icon_class = module_attr('get_icon_class')
|
||||
get_progress = module_attr('get_progress')
|
||||
get_score = module_attr('get_score')
|
||||
handle_ajax = module_attr('handle_ajax')
|
||||
max_score = module_attr('max_score')
|
||||
student_view = module_attr('student_view')
|
||||
|
||||
# ~~~~~~~~~~~~~~~ XBlock API Wrappers ~~~~~~~~~~~~~~~~
|
||||
def studio_view(self, _context):
|
||||
"""
|
||||
@@ -766,6 +861,13 @@ class DescriptorSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable
|
||||
result['default_value'] = field.to_json(field.default)
|
||||
return result
|
||||
|
||||
def render(self, block, view_name, context=None):
|
||||
if isinstance(block, (XModule, XModuleDescriptor)) and view_name == 'student_view':
|
||||
assert block.xmodule_runtime is not None
|
||||
return block.xmodule_runtime.render(block._xmodule, view_name, context)
|
||||
else:
|
||||
return super(DescriptorSystem, self).render(block, view_name, context)
|
||||
|
||||
|
||||
class XMLParsingSystem(DescriptorSystem):
|
||||
def __init__(self, process_xml, policy, **kwargs):
|
||||
@@ -795,12 +897,12 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
|
||||
"""
|
||||
def __init__(
|
||||
self, static_url, ajax_url, track_function, get_module, render_template,
|
||||
replace_urls, xmodule_field_data, user=None, filestore=None,
|
||||
replace_urls, user=None, filestore=None,
|
||||
debug=False, hostname="", xqueue=None, publish=None, node_path="",
|
||||
anonymous_student_id='', course_id=None,
|
||||
open_ended_grading_interface=None, s3_interface=None,
|
||||
cache=None, can_execute_unsafe_code=None, replace_course_urls=None,
|
||||
replace_jump_to_id_urls=None, **kwargs):
|
||||
replace_jump_to_id_urls=None, error_descriptor_class=None, **kwargs):
|
||||
"""
|
||||
Create a closure around the system environment.
|
||||
|
||||
@@ -842,9 +944,6 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
|
||||
|
||||
publish(event) - A function that allows XModules to publish events (such as grade changes)
|
||||
|
||||
xmodule_field_data - A function that constructs a field_data for an xblock from its
|
||||
corresponding descriptor
|
||||
|
||||
cache - A cache object with two methods:
|
||||
.get(key) returns an object from the cache or None.
|
||||
.set(key, value, timeout_secs=None) stores a value in the cache with a timeout.
|
||||
@@ -852,6 +951,8 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
|
||||
can_execute_unsafe_code - A function returning a boolean, whether or
|
||||
not to allow the execution of unsafe, unsandboxed code.
|
||||
|
||||
error_descriptor_class - The class to use to render XModules with errors
|
||||
|
||||
"""
|
||||
|
||||
# Right now, usage_store is unused, and field_data is always supplanted
|
||||
@@ -873,7 +974,6 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
|
||||
self.anonymous_student_id = anonymous_student_id
|
||||
self.course_id = course_id
|
||||
self.user_is_staff = user is not None and user.is_staff
|
||||
self.xmodule_field_data = xmodule_field_data
|
||||
|
||||
if publish is None:
|
||||
publish = lambda e: None
|
||||
@@ -887,6 +987,8 @@ class ModuleSystem(ConfigurableFragmentWrapper, Runtime): # pylint: disable=abs
|
||||
self.can_execute_unsafe_code = can_execute_unsafe_code or (lambda: False)
|
||||
self.replace_course_urls = replace_course_urls
|
||||
self.replace_jump_to_id_urls = replace_jump_to_id_urls
|
||||
self.error_descriptor_class = error_descriptor_class
|
||||
self.xmodule_instance = None
|
||||
|
||||
def get(self, attr):
|
||||
""" provide uniform access to attributes (like etree)."""
|
||||
|
||||
@@ -3,7 +3,7 @@ $ ->
|
||||
window.$$contents = {}
|
||||
$.fn.extend
|
||||
loading: ->
|
||||
@$_loading = $("<div class='loading-animation'></div>")
|
||||
@$_loading = $("<div class='loading-animation'><span class='sr'>Loading content</span></div>")
|
||||
$(this).after(@$_loading)
|
||||
loaded: ->
|
||||
@$_loading.remove()
|
||||
|
||||
@@ -4,7 +4,7 @@ if Backbone?
|
||||
|
||||
events:
|
||||
"click .discussion-flag-abuse": "toggleFlagAbuse"
|
||||
|
||||
"keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress"
|
||||
|
||||
attrRenderer:
|
||||
endorsed: (endorsed) ->
|
||||
@@ -106,6 +106,10 @@ if Backbone?
|
||||
@model.bind('change', @renderPartialAttrs, @)
|
||||
|
||||
|
||||
toggleFlagAbuseKeypress: (event) ->
|
||||
# Activate on spacebar or enter
|
||||
if event.which == 32 or event.which == 13
|
||||
@toggleFlagAbuse(event)
|
||||
|
||||
toggleFlagAbuse: (event) ->
|
||||
event.preventDefault()
|
||||
|
||||
@@ -124,7 +124,7 @@ if Backbone?
|
||||
loadMorePages: (event) ->
|
||||
if event
|
||||
event.preventDefault()
|
||||
@$(".more-pages").html('<div class="loading-animation"></div>')
|
||||
@$(".more-pages").html('<div class="loading-animation"><span class="sr">Loading more threads</span></div>')
|
||||
@$(".more-pages").addClass("loading")
|
||||
options = {}
|
||||
switch @mode
|
||||
@@ -405,7 +405,7 @@ if Backbone?
|
||||
type: "GET"
|
||||
$loading: $
|
||||
loadingCallback: =>
|
||||
@$(".post-list").html('<li class="loading"><div class="loading-animation"></div></li>')
|
||||
@$(".post-list").html('<li class="loading"><div class="loading-animation"><span class="sr">Loading thread list</span></div></li>')
|
||||
loadedCallback: =>
|
||||
if callback
|
||||
callback.apply @, [value]
|
||||
|
||||
@@ -4,6 +4,7 @@ if Backbone?
|
||||
events:
|
||||
"click .discussion-vote": "toggleVote"
|
||||
"click .discussion-flag-abuse": "toggleFlagAbuse"
|
||||
"keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress"
|
||||
"click .admin-pin": "togglePin"
|
||||
"click .action-follow": "toggleFollowing"
|
||||
"click .action-edit": "edit"
|
||||
@@ -51,10 +52,12 @@ if Backbone?
|
||||
if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0)
|
||||
@$("[data-role=thread-flag]").addClass("flagged")
|
||||
@$("[data-role=thread-flag]").removeClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "true")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Misuse Reported")
|
||||
else
|
||||
@$("[data-role=thread-flag]").removeClass("flagged")
|
||||
@$("[data-role=thread-flag]").addClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "false")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Report Misuse")
|
||||
|
||||
renderPinned: =>
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
if Backbone?
|
||||
class @ResponseCommentShowView extends DiscussionContentView
|
||||
|
||||
events:
|
||||
"click .discussion-flag-abuse": "toggleFlagAbuse"
|
||||
|
||||
tagName: "li"
|
||||
|
||||
initialize: ->
|
||||
@@ -48,9 +45,15 @@ if Backbone?
|
||||
if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0)
|
||||
@$("[data-role=thread-flag]").addClass("flagged")
|
||||
@$("[data-role=thread-flag]").removeClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "true")
|
||||
@$(".discussion-flag-abuse").attr("data-tooltip", "Misuse Reported")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Misuse Reported")
|
||||
else
|
||||
@$("[data-role=thread-flag]").removeClass("flagged")
|
||||
@$("[data-role=thread-flag]").addClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "false")
|
||||
@$(".discussion-flag-abuse").attr("data-tooltip", "Report Misuse")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Report Misuse")
|
||||
|
||||
updateModelDetails: =>
|
||||
@renderFlagged()
|
||||
|
||||
@@ -6,6 +6,7 @@ if Backbone?
|
||||
"click .action-delete": "_delete"
|
||||
"click .action-edit": "edit"
|
||||
"click .discussion-flag-abuse": "toggleFlagAbuse"
|
||||
"keypress .discussion-flag-abuse": "toggleFlagAbuseKeypress"
|
||||
|
||||
$: (selector) ->
|
||||
@$el.find(selector)
|
||||
@@ -104,10 +105,12 @@ if Backbone?
|
||||
if window.user.id in @model.get("abuse_flaggers") or (DiscussionUtil.isFlagModerator and @model.get("abuse_flaggers").length > 0)
|
||||
@$("[data-role=thread-flag]").addClass("flagged")
|
||||
@$("[data-role=thread-flag]").removeClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "true")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Misuse Reported")
|
||||
else
|
||||
@$("[data-role=thread-flag]").removeClass("flagged")
|
||||
@$("[data-role=thread-flag]").addClass("notflagged")
|
||||
@$(".discussion-flag-abuse").attr("aria-pressed", "false")
|
||||
@$(".discussion-flag-abuse .flag-label").html("Report Misuse")
|
||||
|
||||
updateModelDetails: =>
|
||||
|
||||
@@ -4,9 +4,10 @@
|
||||
// See https://edx-wiki.atlassian.net/wiki/display/LMS/Integration+of+Require+JS+into+the+system
|
||||
(function (requirejs, require, define) {
|
||||
|
||||
requirejs.config({
|
||||
'baseUrl': '/static/js/capa/drag_and_drop/'
|
||||
});
|
||||
// HACK: this should be removed when it is safe to do so
|
||||
if(window.baseUrl) {
|
||||
requirejs.config({baseUrl: baseUrl});
|
||||
}
|
||||
|
||||
// The current JS file will be loaded and run each time. It will require a
|
||||
// single dependency which will be loaded and stored by RequireJS. On
|
||||
@@ -14,7 +15,7 @@ requirejs.config({
|
||||
// than loading it again from the server. For that reason, it is a good idea to
|
||||
// keep the current JS file as small as possible, and move everything else into
|
||||
// RequireJS module dependencies.
|
||||
requirejs(['main'], function (Main) {
|
||||
require(['js/capa/drag_and_drop/main'], function (Main) {
|
||||
Main();
|
||||
});
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return BaseImage;
|
||||
|
||||
function BaseImage(state) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return configParser;
|
||||
|
||||
function configParser(state, config) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return Container;
|
||||
|
||||
function Container(state) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return {
|
||||
'attachMouseEventsTo': function (element) {
|
||||
var self;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme', 'update_input', 'targets'], function (logme, updateInput, Targets) {
|
||||
define(['js/capa/drag_and_drop/logme', 'js/capa/drag_and_drop/update_input', 'js/capa/drag_and_drop/targets'], function (logme, updateInput, Targets) {
|
||||
return {
|
||||
'moveDraggableTo': function (moveType, target, funcCallback) {
|
||||
var self, offset;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme', 'draggable_events', 'draggable_logic'], function (logme, draggableEvents, draggableLogic) {
|
||||
define(['js/capa/drag_and_drop/logme', 'js/capa/drag_and_drop/draggable_events', 'js/capa/drag_and_drop/draggable_logic'], function (logme, draggableEvents, draggableLogic) {
|
||||
return {
|
||||
'init': init
|
||||
};
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(
|
||||
['logme', 'state', 'config_parser', 'container', 'base_image', 'scroller', 'draggables', 'targets', 'update_input'],
|
||||
['js/capa/drag_and_drop/logme', 'js/capa/drag_and_drop/state',
|
||||
'js/capa/drag_and_drop/config_parser', 'js/capa/drag_and_drop/container',
|
||||
'js/capa/drag_and_drop/base_image', 'js/capa/drag_and_drop/scroller',
|
||||
'js/capa/drag_and_drop/draggables', 'js/capa/drag_and_drop/targets',
|
||||
'js/capa/drag_and_drop/update_input'],
|
||||
function (logme, State, configParser, Container, BaseImage, Scroller, Draggables, Targets, updateInput) {
|
||||
return Main;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return Scroller;
|
||||
|
||||
function Scroller(state) {
|
||||
@@ -40,7 +40,7 @@ define(['logme'], function (logme) {
|
||||
'-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset; ' +
|
||||
'box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset; ' +
|
||||
|
||||
'background-image: url(\'/static/images/arrow-left.png\'); ' +
|
||||
"background-image: url('"+baseUrl+"images/arrow-left.png'); " +
|
||||
'background-position: center center; ' +
|
||||
'background-repeat: no-repeat; ' +
|
||||
'" ' +
|
||||
@@ -136,7 +136,7 @@ define(['logme'], function (logme) {
|
||||
'-webkit-box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset; ' +
|
||||
'box-shadow: 0 1px 0 rgba(255, 255, 255, 0.7) inset; ' +
|
||||
|
||||
'background-image: url(\'/static/images/arrow-right.png\'); ' +
|
||||
"background-image: url('"+baseUrl+"images/arrow-right.png'); " +
|
||||
'background-position: center center; ' +
|
||||
'background-repeat: no-repeat; ' +
|
||||
'" ' +
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return {
|
||||
'initializeBaseTargets': initializeBaseTargets,
|
||||
'initializeTargetField': initializeTargetField,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
(function (requirejs, require, define) {
|
||||
define(['logme'], function (logme) {
|
||||
define(['js/capa/drag_and_drop/logme'], function (logme) {
|
||||
return {
|
||||
'check': check,
|
||||
'update': update
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
define(["jquery"], function($) {
|
||||
var url = "//www.youtube.com/player_api";
|
||||
$("head").append($("<script/>", {src: url}));
|
||||
return window.YT;
|
||||
});
|
||||
1376
common/static/js/vendor/draggabilly.pkgd.js
vendored
Normal file
1376
common/static/js/vendor/draggabilly.pkgd.js
vendored
Normal file
@@ -0,0 +1,1376 @@
|
||||
/*!
|
||||
* Draggabilly PACKAGED v1.0.5
|
||||
* Make that shiz draggable
|
||||
* http://draggabilly.desandro.com
|
||||
*/
|
||||
|
||||
/*!
|
||||
* classie - class helper functions
|
||||
* from bonzo https://github.com/ded/bonzo
|
||||
*
|
||||
* classie.has( elem, 'my-class' ) -> true/false
|
||||
* classie.add( elem, 'my-new-class' )
|
||||
* classie.remove( elem, 'my-unwanted-class' )
|
||||
* classie.toggle( elem, 'my-class' )
|
||||
*/
|
||||
|
||||
/*jshint browser: true, strict: true, undef: true */
|
||||
/*global define: false */
|
||||
|
||||
( function( window ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// class helper functions from bonzo https://github.com/ded/bonzo
|
||||
|
||||
function classReg( className ) {
|
||||
return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
|
||||
}
|
||||
|
||||
// classList support for class management
|
||||
// altho to be fair, the api sucks because it won't accept multiple classes at once
|
||||
var hasClass, addClass, removeClass;
|
||||
|
||||
if ( 'classList' in document.documentElement ) {
|
||||
hasClass = function( elem, c ) {
|
||||
return elem.classList.contains( c );
|
||||
};
|
||||
addClass = function( elem, c ) {
|
||||
elem.classList.add( c );
|
||||
};
|
||||
removeClass = function( elem, c ) {
|
||||
elem.classList.remove( c );
|
||||
};
|
||||
}
|
||||
else {
|
||||
hasClass = function( elem, c ) {
|
||||
return classReg( c ).test( elem.className );
|
||||
};
|
||||
addClass = function( elem, c ) {
|
||||
if ( !hasClass( elem, c ) ) {
|
||||
elem.className = elem.className + ' ' + c;
|
||||
}
|
||||
};
|
||||
removeClass = function( elem, c ) {
|
||||
elem.className = elem.className.replace( classReg( c ), ' ' );
|
||||
};
|
||||
}
|
||||
|
||||
function toggleClass( elem, c ) {
|
||||
var fn = hasClass( elem, c ) ? removeClass : addClass;
|
||||
fn( elem, c );
|
||||
}
|
||||
|
||||
var classie = {
|
||||
// full names
|
||||
hasClass: hasClass,
|
||||
addClass: addClass,
|
||||
removeClass: removeClass,
|
||||
toggleClass: toggleClass,
|
||||
// short names
|
||||
has: hasClass,
|
||||
add: addClass,
|
||||
remove: removeClass,
|
||||
toggle: toggleClass
|
||||
};
|
||||
|
||||
// transport
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define("classie", classie);
|
||||
} else {
|
||||
// browser global
|
||||
window.classie = classie;
|
||||
}
|
||||
|
||||
})( window );
|
||||
|
||||
/*!
|
||||
* eventie v1.0.3
|
||||
* event binding helper
|
||||
* eventie.bind( elem, 'click', myFn )
|
||||
* eventie.unbind( elem, 'click', myFn )
|
||||
*/
|
||||
|
||||
/*jshint browser: true, undef: true, unused: true */
|
||||
/*global define: false */
|
||||
|
||||
( function( window ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var docElem = document.documentElement;
|
||||
|
||||
var bind = function() {};
|
||||
|
||||
if ( docElem.addEventListener ) {
|
||||
bind = function( obj, type, fn ) {
|
||||
obj.addEventListener( type, fn, false );
|
||||
};
|
||||
} else if ( docElem.attachEvent ) {
|
||||
bind = function( obj, type, fn ) {
|
||||
obj[ type + fn ] = fn.handleEvent ?
|
||||
function() {
|
||||
var event = window.event;
|
||||
// add event.target
|
||||
event.target = event.target || event.srcElement;
|
||||
fn.handleEvent.call( fn, event );
|
||||
} :
|
||||
function() {
|
||||
var event = window.event;
|
||||
// add event.target
|
||||
event.target = event.target || event.srcElement;
|
||||
fn.call( obj, event );
|
||||
};
|
||||
obj.attachEvent( "on" + type, obj[ type + fn ] );
|
||||
};
|
||||
}
|
||||
|
||||
var unbind = function() {};
|
||||
|
||||
if ( docElem.removeEventListener ) {
|
||||
unbind = function( obj, type, fn ) {
|
||||
obj.removeEventListener( type, fn, false );
|
||||
};
|
||||
} else if ( docElem.detachEvent ) {
|
||||
unbind = function( obj, type, fn ) {
|
||||
obj.detachEvent( "on" + type, obj[ type + fn ] );
|
||||
try {
|
||||
delete obj[ type + fn ];
|
||||
} catch ( err ) {
|
||||
// can't delete window object properties
|
||||
obj[ type + fn ] = undefined;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
var eventie = {
|
||||
bind: bind,
|
||||
unbind: unbind
|
||||
};
|
||||
|
||||
// transport
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define("eventie", eventie);
|
||||
} else {
|
||||
// browser global
|
||||
window.eventie = eventie;
|
||||
}
|
||||
|
||||
})( this );
|
||||
|
||||
/*!
|
||||
* EventEmitter v4.2.4 - git.io/ee
|
||||
* Oliver Caldwell
|
||||
* MIT license
|
||||
* @preserve
|
||||
*/
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Class for managing events.
|
||||
* Can be extended to provide event functionality in other classes.
|
||||
*
|
||||
* @class EventEmitter Manages event registering and emitting.
|
||||
*/
|
||||
function EventEmitter() {}
|
||||
|
||||
// Shortcuts to improve speed and size
|
||||
|
||||
// Easy access to the prototype
|
||||
var proto = EventEmitter.prototype;
|
||||
|
||||
/**
|
||||
* Finds the index of the listener for the event in it's storage array.
|
||||
*
|
||||
* @param {Function[]} listeners Array of listeners to search through.
|
||||
* @param {Function} listener Method to look for.
|
||||
* @return {Number} Index of the specified listener, -1 if not found
|
||||
* @api private
|
||||
*/
|
||||
function indexOfListener(listeners, listener) {
|
||||
var i = listeners.length;
|
||||
while (i--) {
|
||||
if (listeners[i].listener === listener) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias a method while keeping the context correct, to allow for overwriting of target method.
|
||||
*
|
||||
* @param {String} name The name of the target method.
|
||||
* @return {Function} The aliased method
|
||||
* @api private
|
||||
*/
|
||||
function alias(name) {
|
||||
return function aliasClosure() {
|
||||
return this[name].apply(this, arguments);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the listener array for the specified event.
|
||||
* Will initialise the event object and listener arrays if required.
|
||||
* Will return an object if you use a regex search. The object contains keys for each matched event. So /ba[rz]/ might return an object containing bar and baz. But only if you have either defined them with defineEvent or added some listeners to them.
|
||||
* Each property in the object response is an array of listener functions.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to return the listeners from.
|
||||
* @return {Function[]|Object} All listener functions for the event.
|
||||
*/
|
||||
proto.getListeners = function getListeners(evt) {
|
||||
var events = this._getEvents();
|
||||
var response;
|
||||
var key;
|
||||
|
||||
// Return a concatenated array of all matching events if
|
||||
// the selector is a regular expression.
|
||||
if (typeof evt === 'object') {
|
||||
response = {};
|
||||
for (key in events) {
|
||||
if (events.hasOwnProperty(key) && evt.test(key)) {
|
||||
response[key] = events[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
response = events[evt] || (events[evt] = []);
|
||||
}
|
||||
|
||||
return response;
|
||||
};
|
||||
|
||||
/**
|
||||
* Takes a list of listener objects and flattens it into a list of listener functions.
|
||||
*
|
||||
* @param {Object[]} listeners Raw listener objects.
|
||||
* @return {Function[]} Just the listener functions.
|
||||
*/
|
||||
proto.flattenListeners = function flattenListeners(listeners) {
|
||||
var flatListeners = [];
|
||||
var i;
|
||||
|
||||
for (i = 0; i < listeners.length; i += 1) {
|
||||
flatListeners.push(listeners[i].listener);
|
||||
}
|
||||
|
||||
return flatListeners;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches the requested listeners via getListeners but will always return the results inside an object. This is mainly for internal use but others may find it useful.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to return the listeners from.
|
||||
* @return {Object} All listener functions for an event in an object.
|
||||
*/
|
||||
proto.getListenersAsObject = function getListenersAsObject(evt) {
|
||||
var listeners = this.getListeners(evt);
|
||||
var response;
|
||||
|
||||
if (listeners instanceof Array) {
|
||||
response = {};
|
||||
response[evt] = listeners;
|
||||
}
|
||||
|
||||
return response || listeners;
|
||||
};
|
||||
|
||||
/**
|
||||
* Adds a listener function to the specified event.
|
||||
* The listener will not be added if it is a duplicate.
|
||||
* If the listener returns true then it will be removed after it is called.
|
||||
* If you pass a regular expression as the event name then the listener will be added to all events that match it.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to attach the listener to.
|
||||
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.addListener = function addListener(evt, listener) {
|
||||
var listeners = this.getListenersAsObject(evt);
|
||||
var listenerIsWrapped = typeof listener === 'object';
|
||||
var key;
|
||||
|
||||
for (key in listeners) {
|
||||
if (listeners.hasOwnProperty(key) && indexOfListener(listeners[key], listener) === -1) {
|
||||
listeners[key].push(listenerIsWrapped ? listener : {
|
||||
listener: listener,
|
||||
once: false
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias of addListener
|
||||
*/
|
||||
proto.on = alias('addListener');
|
||||
|
||||
/**
|
||||
* Semi-alias of addListener. It will add a listener that will be
|
||||
* automatically removed after it's first execution.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to attach the listener to.
|
||||
* @param {Function} listener Method to be called when the event is emitted. If the function returns true then it will be removed after calling.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.addOnceListener = function addOnceListener(evt, listener) {
|
||||
return this.addListener(evt, {
|
||||
listener: listener,
|
||||
once: true
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias of addOnceListener.
|
||||
*/
|
||||
proto.once = alias('addOnceListener');
|
||||
|
||||
/**
|
||||
* Defines an event name. This is required if you want to use a regex to add a listener to multiple events at once. If you don't do this then how do you expect it to know what event to add to? Should it just add to every possible match for a regex? No. That is scary and bad.
|
||||
* You need to tell it what event names should be matched by a regex.
|
||||
*
|
||||
* @param {String} evt Name of the event to create.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.defineEvent = function defineEvent(evt) {
|
||||
this.getListeners(evt);
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Uses defineEvent to define multiple events.
|
||||
*
|
||||
* @param {String[]} evts An array of event names to define.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.defineEvents = function defineEvents(evts) {
|
||||
for (var i = 0; i < evts.length; i += 1) {
|
||||
this.defineEvent(evts[i]);
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes a listener function from the specified event.
|
||||
* When passed a regular expression as the event name, it will remove the listener from all events that match it.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to remove the listener from.
|
||||
* @param {Function} listener Method to remove from the event.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.removeListener = function removeListener(evt, listener) {
|
||||
var listeners = this.getListenersAsObject(evt);
|
||||
var index;
|
||||
var key;
|
||||
|
||||
for (key in listeners) {
|
||||
if (listeners.hasOwnProperty(key)) {
|
||||
index = indexOfListener(listeners[key], listener);
|
||||
|
||||
if (index !== -1) {
|
||||
listeners[key].splice(index, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias of removeListener
|
||||
*/
|
||||
proto.off = alias('removeListener');
|
||||
|
||||
/**
|
||||
* Adds listeners in bulk using the manipulateListeners method.
|
||||
* If you pass an object as the second argument you can add to multiple events at once. The object should contain key value pairs of events and listeners or listener arrays. You can also pass it an event name and an array of listeners to be added.
|
||||
* You can also pass it a regular expression to add the array of listeners to all events that match it.
|
||||
* Yeah, this function does quite a bit. That's probably a bad thing.
|
||||
*
|
||||
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add to multiple events at once.
|
||||
* @param {Function[]} [listeners] An optional array of listener functions to add.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.addListeners = function addListeners(evt, listeners) {
|
||||
// Pass through to manipulateListeners
|
||||
return this.manipulateListeners(false, evt, listeners);
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes listeners in bulk using the manipulateListeners method.
|
||||
* If you pass an object as the second argument you can remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
|
||||
* You can also pass it an event name and an array of listeners to be removed.
|
||||
* You can also pass it a regular expression to remove the listeners from all events that match it.
|
||||
*
|
||||
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to remove from multiple events at once.
|
||||
* @param {Function[]} [listeners] An optional array of listener functions to remove.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.removeListeners = function removeListeners(evt, listeners) {
|
||||
// Pass through to manipulateListeners
|
||||
return this.manipulateListeners(true, evt, listeners);
|
||||
};
|
||||
|
||||
/**
|
||||
* Edits listeners in bulk. The addListeners and removeListeners methods both use this to do their job. You should really use those instead, this is a little lower level.
|
||||
* The first argument will determine if the listeners are removed (true) or added (false).
|
||||
* If you pass an object as the second argument you can add/remove from multiple events at once. The object should contain key value pairs of events and listeners or listener arrays.
|
||||
* You can also pass it an event name and an array of listeners to be added/removed.
|
||||
* You can also pass it a regular expression to manipulate the listeners of all events that match it.
|
||||
*
|
||||
* @param {Boolean} remove True if you want to remove listeners, false if you want to add.
|
||||
* @param {String|Object|RegExp} evt An event name if you will pass an array of listeners next. An object if you wish to add/remove from multiple events at once.
|
||||
* @param {Function[]} [listeners] An optional array of listener functions to add/remove.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.manipulateListeners = function manipulateListeners(remove, evt, listeners) {
|
||||
var i;
|
||||
var value;
|
||||
var single = remove ? this.removeListener : this.addListener;
|
||||
var multiple = remove ? this.removeListeners : this.addListeners;
|
||||
|
||||
// If evt is an object then pass each of it's properties to this method
|
||||
if (typeof evt === 'object' && !(evt instanceof RegExp)) {
|
||||
for (i in evt) {
|
||||
if (evt.hasOwnProperty(i) && (value = evt[i])) {
|
||||
// Pass the single listener straight through to the singular method
|
||||
if (typeof value === 'function') {
|
||||
single.call(this, i, value);
|
||||
}
|
||||
else {
|
||||
// Otherwise pass back to the multiple function
|
||||
multiple.call(this, i, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// So evt must be a string
|
||||
// And listeners must be an array of listeners
|
||||
// Loop over it and pass each one to the multiple method
|
||||
i = listeners.length;
|
||||
while (i--) {
|
||||
single.call(this, evt, listeners[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Removes all listeners from a specified event.
|
||||
* If you do not specify an event then all listeners will be removed.
|
||||
* That means every event will be emptied.
|
||||
* You can also pass a regex to remove all events that match it.
|
||||
*
|
||||
* @param {String|RegExp} [evt] Optional name of the event to remove all listeners for. Will remove from every event if not passed.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.removeEvent = function removeEvent(evt) {
|
||||
var type = typeof evt;
|
||||
var events = this._getEvents();
|
||||
var key;
|
||||
|
||||
// Remove different things depending on the state of evt
|
||||
if (type === 'string') {
|
||||
// Remove all listeners for the specified event
|
||||
delete events[evt];
|
||||
}
|
||||
else if (type === 'object') {
|
||||
// Remove all events matching the regex.
|
||||
for (key in events) {
|
||||
if (events.hasOwnProperty(key) && evt.test(key)) {
|
||||
delete events[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Remove all listeners in all events
|
||||
delete this._events;
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias of removeEvent.
|
||||
*
|
||||
* Added to mirror the node API.
|
||||
*/
|
||||
proto.removeAllListeners = alias('removeEvent');
|
||||
|
||||
/**
|
||||
* Emits an event of your choice.
|
||||
* When emitted, every listener attached to that event will be executed.
|
||||
* If you pass the optional argument array then those arguments will be passed to every listener upon execution.
|
||||
* Because it uses `apply`, your array of arguments will be passed as if you wrote them out separately.
|
||||
* So they will not arrive within the array on the other side, they will be separate.
|
||||
* You can also pass a regular expression to emit to all events that match it.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
|
||||
* @param {Array} [args] Optional array of arguments to be passed to each listener.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.emitEvent = function emitEvent(evt, args) {
|
||||
var listeners = this.getListenersAsObject(evt);
|
||||
var listener;
|
||||
var i;
|
||||
var key;
|
||||
var response;
|
||||
|
||||
for (key in listeners) {
|
||||
if (listeners.hasOwnProperty(key)) {
|
||||
i = listeners[key].length;
|
||||
|
||||
while (i--) {
|
||||
// If the listener returns true then it shall be removed from the event
|
||||
// The function is executed either with a basic call or an apply if there is an args array
|
||||
listener = listeners[key][i];
|
||||
|
||||
if (listener.once === true) {
|
||||
this.removeListener(evt, listener.listener);
|
||||
}
|
||||
|
||||
response = listener.listener.apply(this, args || []);
|
||||
|
||||
if (response === this._getOnceReturnValue()) {
|
||||
this.removeListener(evt, listener.listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Alias of emitEvent
|
||||
*/
|
||||
proto.trigger = alias('emitEvent');
|
||||
|
||||
/**
|
||||
* Subtly different from emitEvent in that it will pass its arguments on to the listeners, as opposed to taking a single array of arguments to pass on.
|
||||
* As with emitEvent, you can pass a regex in place of the event name to emit to all events that match it.
|
||||
*
|
||||
* @param {String|RegExp} evt Name of the event to emit and execute listeners for.
|
||||
* @param {...*} Optional additional arguments to be passed to each listener.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.emit = function emit(evt) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
return this.emitEvent(evt, args);
|
||||
};
|
||||
|
||||
/**
|
||||
* Sets the current value to check against when executing listeners. If a
|
||||
* listeners return value matches the one set here then it will be removed
|
||||
* after execution. This value defaults to true.
|
||||
*
|
||||
* @param {*} value The new value to check for when executing listeners.
|
||||
* @return {Object} Current instance of EventEmitter for chaining.
|
||||
*/
|
||||
proto.setOnceReturnValue = function setOnceReturnValue(value) {
|
||||
this._onceReturnValue = value;
|
||||
return this;
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches the current value to check against when executing listeners. If
|
||||
* the listeners return value matches this one then it should be removed
|
||||
* automatically. It will return true by default.
|
||||
*
|
||||
* @return {*|Boolean} The current value to check for or the default, true.
|
||||
* @api private
|
||||
*/
|
||||
proto._getOnceReturnValue = function _getOnceReturnValue() {
|
||||
if (this.hasOwnProperty('_onceReturnValue')) {
|
||||
return this._onceReturnValue;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Fetches the events object and creates one if required.
|
||||
*
|
||||
* @return {Object} The events storage object.
|
||||
* @api private
|
||||
*/
|
||||
proto._getEvents = function _getEvents() {
|
||||
return this._events || (this._events = {});
|
||||
};
|
||||
|
||||
// Expose the class either via AMD, CommonJS or the global object
|
||||
if (typeof define === 'function' && define.amd) {
|
||||
define("EventEmitter", function () {
|
||||
return EventEmitter;
|
||||
});
|
||||
}
|
||||
else if (typeof module === 'object' && module.exports){
|
||||
module.exports = EventEmitter;
|
||||
}
|
||||
else {
|
||||
this.EventEmitter = EventEmitter;
|
||||
}
|
||||
}.call(this));
|
||||
|
||||
/*!
|
||||
* getStyleProperty by kangax
|
||||
* http://perfectionkills.com/feature-testing-css-properties/
|
||||
*/
|
||||
|
||||
/*jshint browser: true, strict: true, undef: true */
|
||||
/*globals define: false */
|
||||
|
||||
( function( window ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
var prefixes = 'Webkit Moz ms Ms O'.split(' ');
|
||||
var docElemStyle = document.documentElement.style;
|
||||
|
||||
function getStyleProperty( propName ) {
|
||||
if ( !propName ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// test standard property first
|
||||
if ( typeof docElemStyle[ propName ] === 'string' ) {
|
||||
return propName;
|
||||
}
|
||||
|
||||
// capitalize
|
||||
propName = propName.charAt(0).toUpperCase() + propName.slice(1);
|
||||
|
||||
// test vendor specific properties
|
||||
var prefixed;
|
||||
for ( var i=0, len = prefixes.length; i < len; i++ ) {
|
||||
prefixed = prefixes[i] + propName;
|
||||
if ( typeof docElemStyle[ prefixed ] === 'string' ) {
|
||||
return prefixed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// transport
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define("getStyleProperty", function() {
|
||||
return getStyleProperty;
|
||||
});
|
||||
} else {
|
||||
// browser global
|
||||
window.getStyleProperty = getStyleProperty;
|
||||
}
|
||||
|
||||
})( window );
|
||||
|
||||
/**
|
||||
* getSize v1.1.4
|
||||
* measure size of elements
|
||||
*/
|
||||
|
||||
/*jshint browser: true, strict: true, undef: true, unused: true */
|
||||
/*global define: false */
|
||||
|
||||
( function( window, undefined ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// -------------------------- helpers -------------------------- //
|
||||
|
||||
var defView = document.defaultView;
|
||||
|
||||
var getStyle = defView && defView.getComputedStyle ?
|
||||
function( elem ) {
|
||||
return defView.getComputedStyle( elem, null );
|
||||
} :
|
||||
function( elem ) {
|
||||
return elem.currentStyle;
|
||||
};
|
||||
|
||||
// get a number from a string, not a percentage
|
||||
function getStyleSize( value ) {
|
||||
var num = parseFloat( value );
|
||||
// not a percent like '100%', and a number
|
||||
var isValid = value.indexOf('%') === -1 && !isNaN( num );
|
||||
return isValid && num;
|
||||
}
|
||||
|
||||
// -------------------------- measurements -------------------------- //
|
||||
|
||||
var measurements = [
|
||||
'paddingLeft',
|
||||
'paddingRight',
|
||||
'paddingTop',
|
||||
'paddingBottom',
|
||||
'marginLeft',
|
||||
'marginRight',
|
||||
'marginTop',
|
||||
'marginBottom',
|
||||
'borderLeftWidth',
|
||||
'borderRightWidth',
|
||||
'borderTopWidth',
|
||||
'borderBottomWidth'
|
||||
];
|
||||
|
||||
function getZeroSize() {
|
||||
var size = {
|
||||
width: 0,
|
||||
height: 0,
|
||||
innerWidth: 0,
|
||||
innerHeight: 0,
|
||||
outerWidth: 0,
|
||||
outerHeight: 0
|
||||
};
|
||||
for ( var i=0, len = measurements.length; i < len; i++ ) {
|
||||
var measurement = measurements[i];
|
||||
size[ measurement ] = 0;
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
|
||||
function defineGetSize( getStyleProperty ) {
|
||||
|
||||
// -------------------------- box sizing -------------------------- //
|
||||
|
||||
var boxSizingProp = getStyleProperty('boxSizing');
|
||||
var isBoxSizeOuter;
|
||||
|
||||
/**
|
||||
* WebKit measures the outer-width on style.width on border-box elems
|
||||
* IE & Firefox measures the inner-width
|
||||
*/
|
||||
( function() {
|
||||
if ( !boxSizingProp ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var div = document.createElement('div');
|
||||
div.style.width = '200px';
|
||||
div.style.padding = '1px 2px 3px 4px';
|
||||
div.style.borderStyle = 'solid';
|
||||
div.style.borderWidth = '1px 2px 3px 4px';
|
||||
div.style[ boxSizingProp ] = 'border-box';
|
||||
|
||||
var body = document.body || document.documentElement;
|
||||
body.appendChild( div );
|
||||
var style = getStyle( div );
|
||||
|
||||
isBoxSizeOuter = getStyleSize( style.width ) === 200;
|
||||
body.removeChild( div );
|
||||
})();
|
||||
|
||||
|
||||
// -------------------------- getSize -------------------------- //
|
||||
|
||||
function getSize( elem ) {
|
||||
// use querySeletor if elem is string
|
||||
if ( typeof elem === 'string' ) {
|
||||
elem = document.querySelector( elem );
|
||||
}
|
||||
|
||||
// do not proceed on non-objects
|
||||
if ( !elem || typeof elem !== 'object' || !elem.nodeType ) {
|
||||
return;
|
||||
}
|
||||
|
||||
var style = getStyle( elem );
|
||||
|
||||
// if hidden, everything is 0
|
||||
if ( style.display === 'none' ) {
|
||||
return getZeroSize();
|
||||
}
|
||||
|
||||
var size = {};
|
||||
size.width = elem.offsetWidth;
|
||||
size.height = elem.offsetHeight;
|
||||
|
||||
var isBorderBox = size.isBorderBox = !!( boxSizingProp &&
|
||||
style[ boxSizingProp ] && style[ boxSizingProp ] === 'border-box' );
|
||||
|
||||
// get all measurements
|
||||
for ( var i=0, len = measurements.length; i < len; i++ ) {
|
||||
var measurement = measurements[i];
|
||||
var value = style[ measurement ];
|
||||
var num = parseFloat( value );
|
||||
// any 'auto', 'medium' value will be 0
|
||||
size[ measurement ] = !isNaN( num ) ? num : 0;
|
||||
}
|
||||
|
||||
var paddingWidth = size.paddingLeft + size.paddingRight;
|
||||
var paddingHeight = size.paddingTop + size.paddingBottom;
|
||||
var marginWidth = size.marginLeft + size.marginRight;
|
||||
var marginHeight = size.marginTop + size.marginBottom;
|
||||
var borderWidth = size.borderLeftWidth + size.borderRightWidth;
|
||||
var borderHeight = size.borderTopWidth + size.borderBottomWidth;
|
||||
|
||||
var isBorderBoxSizeOuter = isBorderBox && isBoxSizeOuter;
|
||||
|
||||
// overwrite width and height if we can get it from style
|
||||
var styleWidth = getStyleSize( style.width );
|
||||
if ( styleWidth !== false ) {
|
||||
size.width = styleWidth +
|
||||
// add padding and border unless it's already including it
|
||||
( isBorderBoxSizeOuter ? 0 : paddingWidth + borderWidth );
|
||||
}
|
||||
|
||||
var styleHeight = getStyleSize( style.height );
|
||||
if ( styleHeight !== false ) {
|
||||
size.height = styleHeight +
|
||||
// add padding and border unless it's already including it
|
||||
( isBorderBoxSizeOuter ? 0 : paddingHeight + borderHeight );
|
||||
}
|
||||
|
||||
size.innerWidth = size.width - ( paddingWidth + borderWidth );
|
||||
size.innerHeight = size.height - ( paddingHeight + borderHeight );
|
||||
|
||||
size.outerWidth = size.width + marginWidth;
|
||||
size.outerHeight = size.height + marginHeight;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
return getSize;
|
||||
|
||||
}
|
||||
|
||||
// transport
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define("getSize", [ 'getStyleProperty' ], defineGetSize );
|
||||
} else {
|
||||
// browser global
|
||||
window.getSize = defineGetSize( window.getStyleProperty );
|
||||
}
|
||||
|
||||
})( window );
|
||||
|
||||
/*!
|
||||
* Draggabilly v1.0.5
|
||||
* Make that shiz draggable
|
||||
* http://draggabilly.desandro.com
|
||||
*/
|
||||
|
||||
( function( window ) {
|
||||
|
||||
'use strict';
|
||||
|
||||
// vars
|
||||
var document = window.document;
|
||||
|
||||
// -------------------------- helpers -------------------------- //
|
||||
|
||||
// extend objects
|
||||
function extend( a, b ) {
|
||||
for ( var prop in b ) {
|
||||
a[ prop ] = b[ prop ];
|
||||
}
|
||||
return a;
|
||||
}
|
||||
|
||||
function noop() {}
|
||||
|
||||
// ----- get style ----- //
|
||||
|
||||
var defView = document.defaultView;
|
||||
|
||||
var getStyle = defView && defView.getComputedStyle ?
|
||||
function( elem ) {
|
||||
return defView.getComputedStyle( elem, null );
|
||||
} :
|
||||
function( elem ) {
|
||||
return elem.currentStyle;
|
||||
};
|
||||
|
||||
|
||||
// http://stackoverflow.com/a/384380/182183
|
||||
var isElement = ( typeof HTMLElement === 'object' ) ?
|
||||
function isElementDOM2( obj ) {
|
||||
return obj instanceof HTMLElement;
|
||||
} :
|
||||
function isElementQuirky( obj ) {
|
||||
return obj && typeof obj === 'object' &&
|
||||
obj.nodeType === 1 && typeof obj.nodeName === 'string';
|
||||
};
|
||||
|
||||
// -------------------------- requestAnimationFrame -------------------------- //
|
||||
|
||||
// https://gist.github.com/1866474
|
||||
|
||||
var lastTime = 0;
|
||||
var prefixes = 'webkit moz ms o'.split(' ');
|
||||
// get unprefixed rAF and cAF, if present
|
||||
var requestAnimationFrame = window.requestAnimationFrame;
|
||||
var cancelAnimationFrame = window.cancelAnimationFrame;
|
||||
// loop through vendor prefixes and get prefixed rAF and cAF
|
||||
var prefix;
|
||||
for( var i = 0; i < prefixes.length; i++ ) {
|
||||
if ( requestAnimationFrame && cancelAnimationFrame ) {
|
||||
break;
|
||||
}
|
||||
prefix = prefixes[i];
|
||||
requestAnimationFrame = requestAnimationFrame || window[ prefix + 'RequestAnimationFrame' ];
|
||||
cancelAnimationFrame = cancelAnimationFrame || window[ prefix + 'CancelAnimationFrame' ] ||
|
||||
window[ prefix + 'CancelRequestAnimationFrame' ];
|
||||
}
|
||||
|
||||
// fallback to setTimeout and clearTimeout if either request/cancel is not supported
|
||||
if ( !requestAnimationFrame || !cancelAnimationFrame ) {
|
||||
requestAnimationFrame = function( callback ) {
|
||||
var currTime = new Date().getTime();
|
||||
var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
|
||||
var id = window.setTimeout( function() {
|
||||
callback( currTime + timeToCall );
|
||||
}, timeToCall );
|
||||
lastTime = currTime + timeToCall;
|
||||
return id;
|
||||
};
|
||||
|
||||
cancelAnimationFrame = function( id ) {
|
||||
window.clearTimeout( id );
|
||||
};
|
||||
}
|
||||
|
||||
// -------------------------- definition -------------------------- //
|
||||
|
||||
function draggabillyDefinition( classie, EventEmitter, eventie, getStyleProperty, getSize ) {
|
||||
|
||||
// -------------------------- support -------------------------- //
|
||||
|
||||
var transformProperty = getStyleProperty('transform');
|
||||
// TODO fix quick & dirty check for 3D support
|
||||
var is3d = !!getStyleProperty('perspective');
|
||||
|
||||
// -------------------------- -------------------------- //
|
||||
|
||||
function Draggabilly( element, options ) {
|
||||
this.element = element;
|
||||
|
||||
this.options = extend( {}, this.options );
|
||||
extend( this.options, options );
|
||||
|
||||
this._create();
|
||||
|
||||
}
|
||||
|
||||
// inherit EventEmitter methods
|
||||
extend( Draggabilly.prototype, EventEmitter.prototype );
|
||||
|
||||
Draggabilly.prototype.options = {
|
||||
};
|
||||
|
||||
Draggabilly.prototype._create = function() {
|
||||
|
||||
// properties
|
||||
this.position = {};
|
||||
this._getPosition();
|
||||
|
||||
this.startPoint = { x: 0, y: 0 };
|
||||
this.dragPoint = { x: 0, y: 0 };
|
||||
|
||||
this.startPosition = extend( {}, this.position );
|
||||
|
||||
// set relative positioning
|
||||
var style = getStyle( this.element );
|
||||
if ( style.position !== 'relative' && style.position !== 'absolute' ) {
|
||||
this.element.style.position = 'relative';
|
||||
}
|
||||
|
||||
this.enable();
|
||||
this.setHandles();
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* set this.handles and bind start events to 'em
|
||||
*/
|
||||
Draggabilly.prototype.setHandles = function() {
|
||||
this.handles = this.options.handle ?
|
||||
this.element.querySelectorAll( this.options.handle ) : [ this.element ];
|
||||
|
||||
for ( var i=0, len = this.handles.length; i < len; i++ ) {
|
||||
var handle = this.handles[i];
|
||||
// bind pointer start event
|
||||
// listen for both, for devices like Chrome Pixel
|
||||
// which has touch and mouse events
|
||||
eventie.bind( handle, 'mousedown', this );
|
||||
eventie.bind( handle, 'touchstart', this );
|
||||
disableImgOndragstart( handle );
|
||||
}
|
||||
};
|
||||
|
||||
// remove default dragging interaction on all images in IE8
|
||||
// IE8 does its own drag thing on images, which messes stuff up
|
||||
|
||||
function noDragStart() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO replace this with a IE8 test
|
||||
var isIE8 = 'attachEvent' in document.documentElement;
|
||||
|
||||
// IE8 only
|
||||
var disableImgOndragstart = !isIE8 ? noop : function( handle ) {
|
||||
|
||||
if ( handle.nodeName === 'IMG' ) {
|
||||
handle.ondragstart = noDragStart;
|
||||
}
|
||||
|
||||
var images = handle.querySelectorAll('img');
|
||||
for ( var i=0, len = images.length; i < len; i++ ) {
|
||||
var img = images[i];
|
||||
img.ondragstart = noDragStart;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// get left/top position from style
|
||||
Draggabilly.prototype._getPosition = function() {
|
||||
// properties
|
||||
var style = getStyle( this.element );
|
||||
|
||||
var x = parseInt( style.left, 10 );
|
||||
var y = parseInt( style.top, 10 );
|
||||
|
||||
// clean up 'auto' or other non-integer values
|
||||
this.position.x = isNaN( x ) ? 0 : x;
|
||||
this.position.y = isNaN( y ) ? 0 : y;
|
||||
|
||||
this._addTransformPosition( style );
|
||||
};
|
||||
|
||||
// add transform: translate( x, y ) to position
|
||||
Draggabilly.prototype._addTransformPosition = function( style ) {
|
||||
if ( !transformProperty ) {
|
||||
return;
|
||||
}
|
||||
var transform = style[ transformProperty ];
|
||||
// bail out if value is 'none'
|
||||
if ( transform.indexOf('matrix') !== 0 ) {
|
||||
return;
|
||||
}
|
||||
// split matrix(1, 0, 0, 1, x, y)
|
||||
var matrixValues = transform.split(',');
|
||||
// translate X value is in 12th or 4th position
|
||||
var xIndex = transform.indexOf('matrix3d') === 0 ? 12 : 4;
|
||||
var translateX = parseInt( matrixValues[ xIndex ], 10 );
|
||||
// translate Y value is in 13th or 5th position
|
||||
var translateY = parseInt( matrixValues[ xIndex + 1 ], 10 );
|
||||
this.position.x += translateX;
|
||||
this.position.y += translateY;
|
||||
};
|
||||
|
||||
// -------------------------- events -------------------------- //
|
||||
|
||||
// trigger handler methods for events
|
||||
Draggabilly.prototype.handleEvent = function( event ) {
|
||||
var method = 'on' + event.type;
|
||||
if ( this[ method ] ) {
|
||||
this[ method ]( event );
|
||||
}
|
||||
};
|
||||
|
||||
// returns the touch that we're keeping track of
|
||||
Draggabilly.prototype.getTouch = function( touches ) {
|
||||
for ( var i=0, len = touches.length; i < len; i++ ) {
|
||||
var touch = touches[i];
|
||||
if ( touch.identifier === this.pointerIdentifier ) {
|
||||
return touch;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// ----- start event ----- //
|
||||
|
||||
Draggabilly.prototype.onmousedown = function( event ) {
|
||||
this.dragStart( event, event );
|
||||
};
|
||||
|
||||
Draggabilly.prototype.ontouchstart = function( event ) {
|
||||
// disregard additional touches
|
||||
if ( this.isDragging ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.dragStart( event, event.changedTouches[0] );
|
||||
};
|
||||
|
||||
function setPointerPoint( point, pointer ) {
|
||||
point.x = pointer.pageX !== undefined ? pointer.pageX : pointer.clientX;
|
||||
point.y = pointer.pageY !== undefined ? pointer.pageY : pointer.clientY;
|
||||
}
|
||||
|
||||
/**
|
||||
* drag start
|
||||
* @param {Event} event
|
||||
* @param {Event or Touch} pointer
|
||||
*/
|
||||
Draggabilly.prototype.dragStart = function( event, pointer ) {
|
||||
if ( !this.isEnabled ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ( event.preventDefault ) {
|
||||
event.preventDefault();
|
||||
} else {
|
||||
event.returnValue = false;
|
||||
}
|
||||
|
||||
var isTouch = event.type === 'touchstart';
|
||||
|
||||
// save pointer identifier to match up touch events
|
||||
this.pointerIdentifier = pointer.identifier;
|
||||
|
||||
this._getPosition();
|
||||
|
||||
this.measureContainment();
|
||||
|
||||
// point where drag began
|
||||
setPointerPoint( this.startPoint, pointer );
|
||||
// position _when_ drag began
|
||||
this.startPosition.x = this.position.x;
|
||||
this.startPosition.y = this.position.y;
|
||||
|
||||
// reset left/top style
|
||||
this.setLeftTop();
|
||||
|
||||
this.dragPoint.x = 0;
|
||||
this.dragPoint.y = 0;
|
||||
|
||||
// bind move and end events
|
||||
this._bindEvents({
|
||||
events: isTouch ? [ 'touchmove', 'touchend', 'touchcancel' ] :
|
||||
[ 'mousemove', 'mouseup' ],
|
||||
// IE8 needs to be bound to document
|
||||
node: event.preventDefault ? window : document
|
||||
});
|
||||
|
||||
classie.add( this.element, 'is-dragging' );
|
||||
|
||||
// reset isDragging flag
|
||||
this.isDragging = true;
|
||||
|
||||
this.emitEvent( 'dragStart', [ this, event, pointer ] );
|
||||
|
||||
// start animation
|
||||
this.animate();
|
||||
};
|
||||
|
||||
Draggabilly.prototype._bindEvents = function( args ) {
|
||||
for ( var i=0, len = args.events.length; i < len; i++ ) {
|
||||
var event = args.events[i];
|
||||
eventie.bind( args.node, event, this );
|
||||
}
|
||||
// save these arguments
|
||||
this._boundEvents = args;
|
||||
};
|
||||
|
||||
Draggabilly.prototype._unbindEvents = function() {
|
||||
var args = this._boundEvents;
|
||||
for ( var i=0, len = args.events.length; i < len; i++ ) {
|
||||
var event = args.events[i];
|
||||
eventie.unbind( args.node, event, this );
|
||||
}
|
||||
delete this._boundEvents;
|
||||
};
|
||||
|
||||
Draggabilly.prototype.measureContainment = function() {
|
||||
var containment = this.options.containment;
|
||||
if ( !containment ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.size = getSize( this.element );
|
||||
var elemRect = this.element.getBoundingClientRect();
|
||||
|
||||
// use element if element
|
||||
var container = isElement( containment ) ? containment :
|
||||
// fallback to querySelector if string
|
||||
typeof containment === 'string' ? document.querySelector( containment ) :
|
||||
// otherwise just `true`, use the parent
|
||||
this.element.parentNode;
|
||||
|
||||
this.containerSize = getSize( container );
|
||||
var containerRect = container.getBoundingClientRect();
|
||||
|
||||
this.relativeStartPosition = {
|
||||
x: elemRect.left - containerRect.left,
|
||||
y: elemRect.top - containerRect.top
|
||||
};
|
||||
};
|
||||
|
||||
// ----- move event ----- //
|
||||
|
||||
Draggabilly.prototype.onmousemove = function( event ) {
|
||||
this.dragMove( event, event );
|
||||
};
|
||||
|
||||
Draggabilly.prototype.ontouchmove = function( event ) {
|
||||
var touch = this.getTouch( event.changedTouches );
|
||||
if ( touch ) {
|
||||
this.dragMove( event, touch );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* drag move
|
||||
* @param {Event} event
|
||||
* @param {Event or Touch} pointer
|
||||
*/
|
||||
Draggabilly.prototype.dragMove = function( event, pointer ) {
|
||||
|
||||
setPointerPoint( this.dragPoint, pointer );
|
||||
this.dragPoint.x -= this.startPoint.x;
|
||||
this.dragPoint.y -= this.startPoint.y;
|
||||
|
||||
if ( this.options.containment ) {
|
||||
var relX = this.relativeStartPosition.x;
|
||||
var relY = this.relativeStartPosition.y;
|
||||
this.dragPoint.x = Math.max( this.dragPoint.x, -relX );
|
||||
this.dragPoint.y = Math.max( this.dragPoint.y, -relY );
|
||||
this.dragPoint.x = Math.min( this.dragPoint.x, this.containerSize.width - relX - this.size.width );
|
||||
this.dragPoint.y = Math.min( this.dragPoint.y, this.containerSize.height - relY - this.size.height );
|
||||
}
|
||||
|
||||
this.position.x = this.startPosition.x + this.dragPoint.x;
|
||||
this.position.y = this.startPosition.y + this.dragPoint.y;
|
||||
|
||||
this.emitEvent( 'dragMove', [ this, event, pointer ] );
|
||||
};
|
||||
|
||||
|
||||
// ----- end event ----- //
|
||||
|
||||
Draggabilly.prototype.onmouseup = function( event ) {
|
||||
this.dragEnd( event, event );
|
||||
};
|
||||
|
||||
Draggabilly.prototype.ontouchend = function( event ) {
|
||||
var touch = this.getTouch( event.changedTouches );
|
||||
if ( touch ) {
|
||||
this.dragEnd( event, touch );
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* drag end
|
||||
* @param {Event} event
|
||||
* @param {Event or Touch} pointer
|
||||
*/
|
||||
Draggabilly.prototype.dragEnd = function( event, pointer ) {
|
||||
this.isDragging = false;
|
||||
|
||||
delete this.pointerIdentifier;
|
||||
|
||||
// use top left position when complete
|
||||
if ( transformProperty ) {
|
||||
this.element.style[ transformProperty ] = '';
|
||||
this.setLeftTop();
|
||||
}
|
||||
|
||||
// remove events
|
||||
this._unbindEvents();
|
||||
|
||||
classie.remove( this.element, 'is-dragging' );
|
||||
|
||||
this.emitEvent( 'dragEnd', [ this, event, pointer ] );
|
||||
|
||||
};
|
||||
|
||||
// ----- cancel event ----- //
|
||||
|
||||
// coerce to end event
|
||||
Draggabilly.prototype.ontouchcancel = function( event ) {
|
||||
var touch = this.getTouch( event.changedTouches );
|
||||
this.dragEnd( event, touch );
|
||||
};
|
||||
|
||||
// -------------------------- animation -------------------------- //
|
||||
|
||||
Draggabilly.prototype.animate = function() {
|
||||
// only render and animate if dragging
|
||||
if ( !this.isDragging ) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.positionDrag();
|
||||
|
||||
var _this = this;
|
||||
requestAnimationFrame( function animateFrame() {
|
||||
_this.animate();
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
// transform translate function
|
||||
var translate = is3d ?
|
||||
function( x, y ) {
|
||||
return 'translate3d( ' + x + 'px, ' + y + 'px, 0)';
|
||||
} :
|
||||
function( x, y ) {
|
||||
return 'translate( ' + x + 'px, ' + y + 'px)';
|
||||
};
|
||||
|
||||
// left/top positioning
|
||||
Draggabilly.prototype.setLeftTop = function() {
|
||||
this.element.style.left = this.position.x + 'px';
|
||||
this.element.style.top = this.position.y + 'px';
|
||||
};
|
||||
|
||||
Draggabilly.prototype.positionDrag = transformProperty ?
|
||||
function() {
|
||||
// position with transform
|
||||
this.element.style[ transformProperty ] = translate( this.dragPoint.x, this.dragPoint.y );
|
||||
} : Draggabilly.prototype.setLeftTop;
|
||||
|
||||
Draggabilly.prototype.enable = function() {
|
||||
this.isEnabled = true;
|
||||
};
|
||||
|
||||
Draggabilly.prototype.disable = function() {
|
||||
this.isEnabled = false;
|
||||
if ( this.isDragging ) {
|
||||
this.dragEnd();
|
||||
}
|
||||
};
|
||||
|
||||
return Draggabilly;
|
||||
|
||||
} // end definition
|
||||
|
||||
// -------------------------- transport -------------------------- //
|
||||
|
||||
if ( typeof define === 'function' && define.amd ) {
|
||||
// AMD
|
||||
define('draggabilly', [
|
||||
'classie',
|
||||
'EventEmitter',
|
||||
'eventie',
|
||||
'getStyleProperty',
|
||||
'getSize'
|
||||
],
|
||||
draggabillyDefinition );
|
||||
} else {
|
||||
// browser global
|
||||
window.Draggabilly = draggabillyDefinition(
|
||||
window.classie,
|
||||
window.EventEmitter,
|
||||
window.eventie,
|
||||
window.getStyleProperty,
|
||||
window.getSize
|
||||
);
|
||||
}
|
||||
|
||||
})( window );
|
||||
@@ -281,7 +281,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
@mixin gray-button {
|
||||
.gray-button {
|
||||
@include button;
|
||||
@include linear-gradient(top, $white-t1, rgba(255, 255, 255, 0));
|
||||
box-shadow: 0 1px 0 $white-t1 inset;
|
||||
@@ -358,11 +358,7 @@
|
||||
background: $lightGrey;
|
||||
|
||||
.branch {
|
||||
margin-bottom: 10px;
|
||||
|
||||
&.collapsed {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.branch > .section-item {
|
||||
@@ -370,6 +366,7 @@
|
||||
}
|
||||
|
||||
.section-item {
|
||||
@include transition(background $tmg-avg ease-in-out 0);
|
||||
position: relative;
|
||||
display: block;
|
||||
padding: 6px 8px 8px 16px;
|
||||
@@ -377,7 +374,7 @@
|
||||
font-size: 13px;
|
||||
|
||||
&:hover {
|
||||
background: #fffcf1;
|
||||
background: $orange-l4;
|
||||
|
||||
.item-actions {
|
||||
display: block;
|
||||
@@ -385,7 +382,7 @@
|
||||
}
|
||||
|
||||
&.editing {
|
||||
background: #fffcf1;
|
||||
background: $orange-l4;
|
||||
}
|
||||
|
||||
.draft-item:after,
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
<section class="about">
|
||||
<h2>About This Course</h2>
|
||||
<p>Include your long course description here. The long course description should contain 150-400 words.</p>
|
||||
|
||||
<p>This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.</p>
|
||||
</section>
|
||||
|
||||
<section class="prerequisites">
|
||||
<h2>Prerequisites</h2>
|
||||
<p>Add information about course prerequisites here.</p>
|
||||
</section>
|
||||
|
||||
<section class="course-staff">
|
||||
<h2>Course Staff</h2>
|
||||
<article class="teacher">
|
||||
<div class="teacher-image">
|
||||
<img src="/static/images/pl-faculty.png" align="left" style="margin:0 20 px 0">
|
||||
</div>
|
||||
|
||||
<h3>Staff Member #1</h3>
|
||||
<p>Biography of instructor/staff member #1</p>
|
||||
</article>
|
||||
|
||||
<article class="teacher">
|
||||
<div class="teacher-image">
|
||||
<img src="/static/images/pl-faculty.png" align="left" style="margin:0 20 px 0">
|
||||
</div>
|
||||
|
||||
<h3>Staff Member #2</h3>
|
||||
<p>Biography of instructor/staff member #2</p>
|
||||
</article>
|
||||
</section>
|
||||
|
||||
<section class="faq">
|
||||
<section class="responses">
|
||||
<h2>Frequently Asked Questions</h2>
|
||||
<article class="response">
|
||||
<h3>Do I need to buy a textbook?</h3>
|
||||
<p>No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.</p>
|
||||
</article>
|
||||
|
||||
<article class="response">
|
||||
<h3>Question #2</h3>
|
||||
<p>Your answer would be displayed here.</p>
|
||||
</article>
|
||||
</section>
|
||||
</section>
|
||||
@@ -1,3 +0,0 @@
|
||||
<chapter display_name="Section">
|
||||
<sequential url_name="c804fa32227142a1bd9d5bc183d4a20d"/>
|
||||
</chapter>
|
||||
@@ -1 +0,0 @@
|
||||
<course url_name="2013_fall" org="edX" course="due_date"/>
|
||||
@@ -1,3 +0,0 @@
|
||||
<course display_name="due_date">
|
||||
<chapter url_name="c8ee0db7e5a84c85bac80b7013cf6512"/>
|
||||
</course>
|
||||
@@ -1 +0,0 @@
|
||||
{"GRADER": [{"short_label": "HW", "min_count": 12, "type": "Homework", "drop_count": 2, "weight": 0.15}, {"min_count": 12, "type": "Lab", "drop_count": 2, "weight": 0.15}, {"short_label": "Midterm", "min_count": 1, "type": "Midterm Exam", "drop_count": 0, "weight": 0.3}, {"short_label": "Final", "min_count": 1, "type": "Final Exam", "drop_count": 0, "weight": 0.4}], "GRADE_CUTOFFS": {"Pass": 0.5}}
|
||||
@@ -1 +0,0 @@
|
||||
{"course/2013_fall": {"tabs": [{"type": "courseware"}, {"type": "course_info", "name": "Course Info"}, {"type": "textbooks"}, {"type": "discussion", "name": "Discussion"}, {"type": "wiki", "name": "Wiki"}, {"type": "progress", "name": "Progress"}], "display_name": "due_date", "discussion_topics": {"General": {"id": "i4x-edX-due_date-course-2013_fall"}}, "show_timezone": "false"}}
|
||||
@@ -1,23 +0,0 @@
|
||||
<problem display_name="Multiple Choice" markdown="A multiple choice problem presents radio buttons for student input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets. One of the main elements that goes into a good multiple choice question is the existence of good distractors. That is, each of the alternate responses presented to the student should be the result of a plausible mistake that a student might make. What Apple device competed with the portable CD player? ( ) The iPad ( ) Napster (x) The iPod ( ) The vegetable peeler [explanation] The release of the iPod allowed consumers to carry their entire music library with them in a format that did not rely on fragile and energy-intensive spinning disks. [explanation] ">
|
||||
<p>
|
||||
A multiple choice problem presents radio buttons for student
|
||||
input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.</p>
|
||||
<p> One of the main elements that goes into a good multiple choice question is the existence of good distractors. That is, each of the alternate responses presented to the student should be the result of a plausible mistake that a student might make.
|
||||
</p>
|
||||
|
||||
<p>What Apple device competed with the portable CD player?</p>
|
||||
<multiplechoiceresponse>
|
||||
<choicegroup type="MultipleChoice">
|
||||
<choice correct="false" name="ipad">The iPad</choice>
|
||||
<choice correct="false" name="beatles">Napster</choice>
|
||||
<choice correct="true" name="ipod">The iPod</choice>
|
||||
<choice correct="false" name="peeler">The vegetable peeler</choice>
|
||||
</choicegroup>
|
||||
</multiplechoiceresponse>
|
||||
<solution>
|
||||
<div class="detailed-solution">
|
||||
<p>Explanation</p>
|
||||
<p>The release of the iPod allowed consumers to carry their entire music library with them in a format that did not rely on fragile and energy-intensive spinning disks. </p>
|
||||
</div>
|
||||
</solution>
|
||||
</problem>
|
||||
@@ -1,3 +0,0 @@
|
||||
<sequential display_name="Subsection" due="2013-09-18T11:30:00Z" start="1970-01-01T00:00:00Z">
|
||||
<vertical url_name="45640305a210424ebcc6f8e045fad0be"/>
|
||||
</sequential>
|
||||
@@ -1,3 +0,0 @@
|
||||
<vertical display_name="New Unit">
|
||||
<problem url_name="d392c80f5c044e45a4a5f2d62f94efc5"/>
|
||||
</vertical>
|
||||
BIN
common/test/data/imports/get_html_exception_test.tar.gz
Normal file
BIN
common/test/data/imports/get_html_exception_test.tar.gz
Normal file
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user