Commit 028833e6 by Valera Rozuvan

Integrated RequireJS with xmodule for GST.

parent eb291858
...@@ -22,7 +22,19 @@ log = logging.getLogger("mitx.common.lib.gst_module") ...@@ -22,7 +22,19 @@ log = logging.getLogger("mitx.common.lib.gst_module")
class GraphicalSliderToolModule(XModule): class GraphicalSliderToolModule(XModule):
''' Graphical-Slider-Tool Module ''' Graphical-Slider-Tool Module
''' '''
js = {'js': [resource_string(__name__, 'js/src/graphical_slider_tool/gst.js')]}
js = {
'js': [
resource_string(__name__, 'js/src/graphical_slider_tool/gst_main.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/mod1.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/mod2.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/mod3.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/mod4.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/mod5.js'),
resource_string(__name__, 'js/src/graphical_slider_tool/gst.js')
]
}
js_module_name = "GraphicalSliderTool" js_module_name = "GraphicalSliderTool"
def __init__(self, system, location, definition, descriptor, instance_state=None, def __init__(self, system, location, definition, descriptor, instance_state=None,
......
// Graphical Slider Tool module /*
* We will add a function that will be called for all GraphicalSliderTool
(function() { * xmodule module instances. It must be available globally by design of
this.GraphicalSliderTool = (function() { * xmodule.
function GST(el) { */
console.log(el); window.GraphicalSliderTool = function (el) {
// element is : // All the work will be performed by the GstMain module. We will get access
//<section class="xmodule_display // to it, and all it's dependencies, via Require JS. Currently Require JS
// xmodule_GraphicalSliderToolModule" data-type="GST"> // is namespaced and is available via a global object RequireJS.
} RequireJS.require(['GstMain'], function (GstMain) {
// console.log('in GST'); // The GstMain module expects the DOM ID of a Graphical Slider Tool
return GST; // element. Since we are given a <section> element which might in
// theory contain multiple graphical_slider_tool <div> elements (each
})(); // with a unique DOM ID), we will iterate over all children, and for
}).call(this); // each match, we will call GstMain module.
// this=window, after call $(el).children('.graphical_slider_tool').each(function (index, value) {
// window['Graphical_Slider_Tool'] is available. GstMain($(value).attr('id'));
\ No newline at end of file });
});
};
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) {
define('GstMain', ['mod1', 'mod2', 'mod3', 'mod4'], function (mod1, mod2, mod3, mod4) {
return GstMain;
function GstMain(gstId) {
console.log('The DOM ID of the current GST element is ' + gstId);
}
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define)
...@@ -2,7 +2,8 @@ ...@@ -2,7 +2,8 @@
// define() functions from Require JS available inside the anonymous function. // define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) { (function (requirejs, require, define) {
define([], function () { define('mod1', [], function () {
console.log('we are in the mod1 callback');
return { return {
'module_status': 'OK' 'module_status': 'OK'
}; };
......
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) {
define('mod2', [], function () {
console.log('we are in the mod2 callback');
return {
'module_status': 'OK'
};
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define)
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) {
define('mod3', ['mod5'], function (mod5) {
console.log('we are in the mod3 callback');
console.log('mod5 status: [' + mod5.module_status + '].');
return {
'module_status': 'OK'
};
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define)
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) {
define('mod4', [], function () {
console.log('we are in the mod4 callback');
return {
'module_status': 'OK'
};
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define)
// Wrapper for RequireJS. It will make the standard requirejs(), require(), and
// define() functions from Require JS available inside the anonymous function.
(function (requirejs, require, define) {
define('mod5', [], function () {
console.log('we are in the mod5 callback');
return {
'module_status': 'OK'
};
});
// End of wrapper for RequireJS. As you can see, we are passing
// namespaced Require JS variables to an anonymous function. Within
// it, you can use the standard requirejs(), require(), and define()
// functions as if they were in the global namespace.
}(RequireJS.requirejs, RequireJS.require, RequireJS.define)); // End-of: (function (requirejs, require, define)
...@@ -397,7 +397,7 @@ courseware_only_js += [ ...@@ -397,7 +397,7 @@ courseware_only_js += [
] ]
main_vendor_js = [ main_vendor_js = [
'js/vendor/Requier.js', 'js/vendor/RequireJS.js',
'js/vendor/jquery.min.js', 'js/vendor/jquery.min.js',
'js/vendor/jquery-ui.min.js', 'js/vendor/jquery-ui.min.js',
'js/vendor/jquery.cookie.js', 'js/vendor/jquery.cookie.js',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment