From: Jason Skomorowski Date: Tue, 12 Aug 2014 18:54:48 +0000 (-0400) Subject: Use requirejs. X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=08dd9d9bbbbc0b190b80e4a3ee93bc4957c13302;p=mkwsxb-moved-to-github.git Use requirejs. --- 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."); + } ); }