From 08dd9d9bbbbc0b190b80e4a3ee93bc4957c13302 Mon Sep 17 00:00:00 2001 From: Jason Skomorowski Date: Tue, 12 Aug 2014 14:54:48 -0400 Subject: [PATCH] Use requirejs. --- mkwsxb/mkwsxb.py | 7 ++++--- mkwsxb/static/js/src/mkwsxb.js | 22 +++++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/mkwsxb/mkwsxb.py b/mkwsxb/mkwsxb.py index fe061b9..13822ea 100644 --- a/mkwsxb/mkwsxb.py +++ b/mkwsxb/mkwsxb.py @@ -30,10 +30,11 @@ class MKWSXB(XBlock): """The primary view of the MKWS XBlock, shown to students when viewing courses.""" html = self.resource_string("static/html/mkwsxb.html") frag = Fragment(html.format(query=self.query, team=random.randint(0, 100000))) - frag.add_javascript_url("//mkws.indexdata.com/mkws-complete.js") - frag.add_javascript_url("//example.indexdata.com/mkws-widget-ru.js") - frag.add_css(self.resource_string("static/css/mkws-widget-ru.css")) + # mkwsxb.js uses require.js as it cannot guarantee mkws-complete.js has loaded + # in studio without it + frag.add_javascript_url("/static/js/vendor/require.js"); frag.add_javascript(self.resource_string("static/js/src/mkwsxb.js")) + frag.add_css(self.resource_string("static/css/mkws-widget-ru.css")) frag.initialize_js('MKWSXB') return frag; diff --git a/mkwsxb/static/js/src/mkwsxb.js b/mkwsxb/static/js/src/mkwsxb.js index 88b9042..dcf79e6 100644 --- a/mkwsxb/static/js/src/mkwsxb.js +++ b/mkwsxb/static/js/src/mkwsxb.js @@ -1,6 +1,22 @@ /* Javascript for MKWSXB. */ +require.config({ + paths: { + mkws: "//mkws.indexdata.com/mkws-complete", + mkws_widget_ru: "//example.indexdata.com/mkws-widget-ru" + }, + shim: { + mkws: { + exports: "mkws" + }, + mkws_widget_ru: { + deps: ["mkws"] + } + } +}); function MKWSXB(runtime, element) { - $(function ($) { - mkws.init(); - }); + require(['mkws_widget_ru'], function() { + console.log(mkws); + //mkws.init("XBlock initialised.", element); + mkws.init("XBlock initialised."); + } ); } -- 1.7.10.4