diff --git a/common/djangoapps/xmodule_modifiers.py b/common/djangoapps/xmodule_modifiers.py index f82a194e9380a0b8bfaa6d0b5f4d5b36802162dc..160e3e5fb3c1b9952c1ad8425a1af576dac3e2f0 100644 --- a/common/djangoapps/xmodule_modifiers.py +++ b/common/djangoapps/xmodule_modifiers.py @@ -77,7 +77,11 @@ def wrap_xblock(runtime_class, block, view, frag, context, usage_id_serializer, css_classes = [ 'xblock', - 'xblock-{}'.format(markupsafe.escape(view)) + 'xblock-{}'.format(markupsafe.escape(view)), + 'xblock-{}-{}'.format( + markupsafe.escape(view), + markupsafe.escape(block.scope_ids.block_type), + ) ] if isinstance(block, (XModule, XModuleDescriptor)): @@ -90,7 +94,7 @@ def wrap_xblock(runtime_class, block, view, frag, context, usage_id_serializer, css_classes.append('xmodule_' + markupsafe.escape(class_name)) data['type'] = block.js_module_name - shim_xmodule_js(frag) + shim_xmodule_js(block, frag) if frag.js_init_fn: data['init'] = frag.js_init_fn diff --git a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js index 3b61f5744f829449a6246d5aa53a1a49fa21ddea..13542899b4b34ad6c9b534a801234731df2d77b3 100644 --- a/common/lib/xmodule/xmodule/js/src/poll/poll_main.js +++ b/common/lib/xmodule/xmodule/js/src/poll/poll_main.js @@ -273,7 +273,7 @@ function PollMain(el) { if ( (tempEl.tagName.toLowerCase() === 'div') && - ($(tempEl).hasClass('xmodule_WrapperModule') === true) + ($(tempEl).data('block-type') === 'wrapper') ) { _this.wrapperSectionEl = tempEl; diff --git a/common/lib/xmodule/xmodule/js/src/xmodule.js b/common/lib/xmodule/xmodule/js/src/xmodule.js index 7676f33da5fa0d6c128a1b71df9b3e4bdab07802..be3f911e4d10c10c29ddd380cc7f1f08f0de7b50 100644 --- a/common/lib/xmodule/xmodule/js/src/xmodule.js +++ b/common/lib/xmodule/xmodule/js/src/xmodule.js @@ -58,14 +58,20 @@ return Descriptor; }()); - this.XBlockToXModuleShim = function (runtime, element) { + this.XBlockToXModuleShim = function (runtime, element, initArgs) { /* * Load a single module (either an edit module or a display module) * from the supplied element, which should have a data-type attribute * specifying the class to load */ - var moduleType = $(element).data('type'), - module; + var moduleType, module; + + if (initArgs) { + moduleType = initArgs['xmodule-type']; + } + if (!moduleType) { + moduleType = $(element).data('type'); + } if (moduleType === 'None') { return; diff --git a/common/lib/xmodule/xmodule/x_module.py b/common/lib/xmodule/xmodule/x_module.py index 3d01be6a71ee374d09b89b149c26ce1f6972ed36..6bcc147c89d9eeccde0cf2c91ea8103b4b1dc879 100644 --- a/common/lib/xmodule/xmodule/x_module.py +++ b/common/lib/xmodule/xmodule/x_module.py @@ -237,12 +237,13 @@ class HTMLSnippet(object): .format(self.__class__)) -def shim_xmodule_js(fragment): +def shim_xmodule_js(block, fragment): """ Set up the XBlock -> XModule shim on the supplied :class:`xblock.fragment.Fragment` """ if not fragment.js_init_fn: fragment.initialize_js('XBlockToXModuleShim') + fragment.json_init_args = {'xmodule-type': block.js_module_name} class XModuleMixin(XBlockMixin): diff --git a/common/static/js/xblock/core.js b/common/static/js/xblock/core.js index 99b2ae0489b0f14845b8d794ca3877d7ff090fbb..1c6632c71dbeba40a52cc0ad9be1cb2b44c0ecd7 100644 --- a/common/static/js/xblock/core.js +++ b/common/static/js/xblock/core.js @@ -32,7 +32,7 @@ } function initArgs(element) { - var initargs = $('.xblock_json_init_args', element).text(); + var initargs = $(element).children('.xblock-json-init-args').remove().text(); return initargs ? JSON.parse(initargs) : {}; } diff --git a/common/templates/xblock_wrapper.html b/common/templates/xblock_wrapper.html index 41951dc61c8d97ac637550042ec840f57688cfd2..998d00a90ad4a43eda5a5af854a15b2b462a3373 100644 --- a/common/templates/xblock_wrapper.html +++ b/common/templates/xblock_wrapper.html @@ -1,8 +1,8 @@ <div class="${' '.join(classes) | n}" ${data_attributes}> % if js_init_parameters: - <script type="json/xblock-args" class="xblock_json_init_args"> + <script type="json/xblock-args" class="xblock-json-init-args"> ${js_init_parameters} </script> % endif - ${content} + ${content} </div> diff --git a/lms/djangoapps/courseware/tests/test_module_render.py b/lms/djangoapps/courseware/tests/test_module_render.py index d4d4ccc2b5076efbb9904f066ca2b47f52b59463..c803611e880c11e596a6549d6c0cbb9f214a9e70 100644 --- a/lms/djangoapps/courseware/tests/test_module_render.py +++ b/lms/djangoapps/courseware/tests/test_module_render.py @@ -432,7 +432,7 @@ class TestHandleXBlockCallback(ModuleStoreTestCase, LoginEnrollmentTestCase): for section in expected: self.assertIn(section, content) doc = PyQuery(content['html']) - self.assertEquals(len(doc('div.xblock.xblock-student_view')), 1) + self.assertEquals(len(doc('div.xblock-student_view-videosequence')), 1) @ddt.ddt