Commit 082cb3b9 by jmclaus Committed by Jean-Michel Claus

Load OVA JS with requireJS in LMS.

parent 099d02d1
...@@ -1015,24 +1015,6 @@ main_vendor_js = base_vendor_js + [ ...@@ -1015,24 +1015,6 @@ main_vendor_js = base_vendor_js + [
'js/vendor/jquery.qtip.min.js', 'js/vendor/jquery.qtip.min.js',
'js/vendor/swfobject/swfobject.js', 'js/vendor/swfobject/swfobject.js',
'js/vendor/jquery.ba-bbq.min.js', 'js/vendor/jquery.ba-bbq.min.js',
'js/vendor/ova/annotator-full.js',
'js/vendor/ova/annotator-full-firebase-auth.js',
'js/vendor/ova/video.dev.js',
'js/vendor/ova/vjs.youtube.js',
'js/vendor/ova/rangeslider.js',
'js/vendor/ova/share-annotator.js',
'js/vendor/ova/richText-annotator.js',
'js/vendor/ova/reply-annotator.js',
'js/vendor/ova/tags-annotator.js',
'js/vendor/ova/flagging-annotator.js',
'js/vendor/ova/diacritic-annotator.js',
'js/vendor/ova/grouping-annotator.js',
'js/vendor/ova/jquery-Watch.js',
'js/vendor/ova/openseadragon.js',
'js/vendor/ova/OpenSeaDragonAnnotation.js',
'js/vendor/ova/ova.js',
'js/vendor/ova/catch/js/catch.js',
'js/vendor/ova/catch/js/handlebars-1.1.2.js',
'js/vendor/URI.min.js', 'js/vendor/URI.min.js',
] ]
......
;(function (require, define, _) {
var paths = {}, config;
// URI, tinymce, or jquery.tinymce may already have been loaded before the OVA templates and we do not want to load
// them a second time. Check if it is the case and use the global var in requireJS config.
if (window.URI) {
define("URI", [], function() {return window.URI;});
} else {
paths.URI = "js/vendor/URI.min";
}
if (window.tinymce) {
define('tinymce', [], function() {return window.tinymce;});
} else {
paths.tinymce = "js/vendor/tinymce/js/tinymce/tinymce.full.min";
}
if (window.jquery && window.jquery.tinymce) {
define("jquery.tinymce", [], function() {return window.jquery.tinymce;});
} else {
paths.tinymce = "js/vendor/tinymce/js/tinymce/jquery.tinymce.min";
}
config = {
// NOTE: baseUrl has been previously set in lms/templates/main.html
waitSeconds: 60,
paths: {
// Files only needed for OVA
"annotator": "js/vendor/ova/annotator-full",
"annotator-harvardx": "js/vendor/ova/annotator-full-firebase-auth",
"video.dev": "js/vendor/ova/video.dev",
"vjs.youtube": 'js/vendor/ova/vjs.youtube',
"rangeslider": 'js/vendor/ova/rangeslider',
"share-annotator": 'js/vendor/ova/share-annotator',
"richText-annotator": 'js/vendor/ova/richText-annotator',
"reply-annotator": 'js/vendor/ova/reply-annotator',
"grouping-annotator": 'js/vendor/ova/grouping-annotator',
"tags-annotator": 'js/vendor/ova/tags-annotator',
"diacritic-annotator": 'js/vendor/ova/diacritic-annotator',
"flagging-annotator": 'js/vendor/ova/flagging-annotator',
"jquery-Watch": 'js/vendor/ova/jquery-Watch',
"openseadragon": 'js/vendor/ova/openseadragon',
"osda": 'js/vendor/ova/OpenSeaDragonAnnotation',
"ova": 'js/vendor/ova/ova',
"catch": 'js/vendor/ova/catch/js/catch',
"handlebars": 'js/vendor/ova/catch/js/handlebars-1.1.2',
// end of files only needed for OVA
},
shim: {
// The following are all needed for OVA
"video.dev": {
exports:"videojs"
},
"vjs.youtube": {
deps: ["video.dev"]
},
"rangeslider": {
deps: ["video.dev"]
},
"annotator": {
exports: "Annotator"
},
"annotator-harvardx":{
deps: ["annotator"]
},
"share-annotator": {
deps: ["annotator"]
},
"richText-annotator": {
deps: ["annotator", "tinymce"]
},
"reply-annotator": {
deps: ["annotator"]
},
"tags-annotator": {
deps: ["annotator"]
},
"diacritic-annotator": {
deps: ["annotator"]
},
"flagging-annotator": {
deps: ["annotator"]
},
"grouping-annotator": {
deps: ["annotator"]
},
"ova": {
exports: "ova",
deps: [
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
"grouping-annotator", "diacritic-annotator", "jquery-Watch", "catch", "handlebars", "URI"
]
},
"osda": {
exports: "osda",
deps: [
"annotator", "annotator-harvardx", "video.dev", "vjs.youtube", "rangeslider", "share-annotator",
"richText-annotator", "reply-annotator", "tags-annotator", "flagging-annotator",
"grouping-annotator", "diacritic-annotator", "openseadragon", "jquery-Watch", "catch", "handlebars",
"URI"
]
},
// End of OVA
}
};
_.extend(config.paths, paths);
require.config(config);
}).call(this, require || RequireJS.require, define || RequireJS.define, _);
...@@ -41,7 +41,9 @@ ...@@ -41,7 +41,9 @@
</div> </div>
<script> <script>
// TODO: Fix indentation in the following block
(function (require) {
var init = function() {
function onClickHideInstructions(){ function onClickHideInstructions(){
//Reset function if there is more than one event handler //Reset function if there is more than one event handler
$(this).off(); $(this).off();
...@@ -191,7 +193,12 @@ ...@@ -191,7 +193,12 @@
delete osda; delete osda;
//Load the plugin Image/Text Annotation //Load the plugin Image/Text Annotation
osda = new OpenSeadragonAnnotation($('#imageHolder'),options); osda = new OpenSeadragonAnnotation($('#imageHolder'),options);
// TODO: Fix to avoid using global scope!
window.options = options;
window.osda = osda;
// END TODO
var userId = ('${default_tab}'.toLowerCase() === 'instructor') ? var userId = ('${default_tab}'.toLowerCase() === 'instructor') ?
'${instructor_email}': '${instructor_email}':
'${user.email}'; '${user.email}';
...@@ -214,24 +221,24 @@ ...@@ -214,24 +221,24 @@
// if annotations are opened to everyone (2) or if they want to create no annotations (1 with no instructor) // if annotations are opened to everyone (2) or if they want to create no annotations (1 with no instructor)
// then the table at the bottom of the source should be displayed // then the table at the bottom of the source should be displayed
if ("${annotation_mode}" == "everyone" || ("${annotation_mode}" == "instructor" && "${instructor_email}" != "")) if ("${annotation_mode}" == "everyone" || ("${annotation_mode}" == "instructor" && "${instructor_email}" != "")) {
Catch = new CatchAnnotation($('#catchDIV'),catchOptions); Catch = new CatchAnnotation($('#catchDIV'),catchOptions);
// TODO: Fix to avoid using global scope!
window.Catch = Catch;
// END TODO
}
// if it is in instructor mode only (1), the annotator should be destroyed for all except the instructor // if it is in instructor mode only (1), the annotator should be destroyed for all except the instructor
if ("${annotation_mode}" == "instructor" && "${instructor_email}" == "" && !is_staff) if ("${annotation_mode}" == "instructor" && "${instructor_email}" == "" && !is_staff)
osda.annotator.destroy(); osda.annotator.destroy();
} }
// if the following is true, template is being rendered in LMS, otherwise it is in Studio startosda();
if (typeof Annotator !== 'undefined') { };
startosda(); try {
} else { require(["osda"], init);
try { } catch(error) {
require(["osda"], function(osda){ console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
startosda();
});
} catch(error) {
console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
}
} }
</script> }).call(this, require || RequireJS.require);
\ No newline at end of file </script>
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
<% <%
# set doc language direction # set doc language direction
from django.utils.translation import get_language_bidi from django.utils.translation import get_language_bidi
from dealer.git import git
dir_rtl = 'rtl' if get_language_bidi() else 'ltr' dir_rtl = 'rtl' if get_language_bidi() else 'ltr'
%> %>
<head dir="${dir_rtl}"> <head dir="${dir_rtl}">
...@@ -73,6 +74,23 @@ ...@@ -73,6 +74,23 @@
<%static:js group='main_vendor'/> <%static:js group='main_vendor'/>
% endif % endif
<script>
window.baseUrl = "${settings.STATIC_URL}";
(function (require) {
% if settings.DEBUG is True:
## Using what amounts to a random number in the Development environment for cache-busting
var urlArgs = "bust=" + (new Date()).getTime();
% else:
var urlArgs = "v=${git.revision}";
% endif
require.config({
baseUrl: baseUrl,
urlArgs: urlArgs
});
}).call(this, require || RequireJS.require);
</script>
<script type="text/javascript" src="${static.url("require-config-lms.js")}"></script>
<%block name="headextra"/> <%block name="headextra"/>
<% <%
......
...@@ -4,8 +4,6 @@ ...@@ -4,8 +4,6 @@
${static.css(group='style-vendor-tinymce-content', raw=True)} ${static.css(group='style-vendor-tinymce-content', raw=True)}
${static.css(group='style-vendor-tinymce-skin', raw=True)} ${static.css(group='style-vendor-tinymce-skin', raw=True)}
${static.css(group='style-xmodule-annotations', raw=True)} ${static.css(group='style-xmodule-annotations', raw=True)}
<script type="text/javascript" src="${static.url('js/vendor/tinymce/js/tinymce/tinymce.full.min.js', raw=True)}"></script>
<script type="text/javascript" src="${static.url('js/vendor/tinymce/js/tinymce/jquery.tinymce.min.js', raw=True)}" ></script>
<%inherit file="main.html" /> <%inherit file="main.html" />
<%! <%!
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
...@@ -70,7 +68,9 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -70,7 +68,9 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
<div class="annotationListContainer">${_('You do not have any notes.')}</div> <div class="annotationListContainer">${_('You do not have any notes.')}</div>
</section> </section>
<script> <script>
// TODO: Fix indentation in the following block
(function (require) {
var init = function() {
//Grab uri of the course //Grab uri of the course
var parts = window.location.href.split("/"), var parts = window.location.href.split("/"),
uri = ''; uri = '';
...@@ -199,6 +199,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -199,6 +199,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
//Load the plugin Video/Text Annotation //Load the plugin Video/Text Annotation
var ova = new OpenVideoAnnotation.Annotator($('#notesHolder'),options); var ova = new OpenVideoAnnotation.Annotator($('#notesHolder'),options);
// TODO: Fix to avoid using global scope!
window.options = options;
window.ova = ova;
// END TODO
//Catch //Catch
var annotator = ova.annotator, var annotator = ova.annotator,
...@@ -213,6 +217,16 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -213,6 +217,16 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
default_tab: "${default_tab}", default_tab: "${default_tab}",
}, },
Catch = new CatchAnnotation($('#catchDIV'),catchOptions); Catch = new CatchAnnotation($('#catchDIV'),catchOptions);
// TODO: Fix to avoid using global scope!
window.Catch = Catch;
// END TODO
};
try {
require(["ova"], init);
} catch(error) {
console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
}
}).call(this, require || RequireJS.require);
</script> </script>
</div> </div>
</section> </section>
......
...@@ -32,8 +32,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -32,8 +32,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
</div> </div>
</div> </div>
<script> <script>
// TODO: Fix indentation in the following block
(function (require) {
var init = function() {
function onClickHideInstructions(){ function onClickHideInstructions(){
//Reset function if there is more than one event handler //Reset function if there is more than one event handler
$(this).off(); $(this).off();
...@@ -179,6 +181,11 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -179,6 +181,11 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
//Load the plugin Video/Text Annotation //Load the plugin Video/Text Annotation
ova = new OpenVideoAnnotation.Annotator($('#textHolder'),options); ova = new OpenVideoAnnotation.Annotator($('#textHolder'),options);
// TODO: Fix to avoid using global scope!
window.options = options;
window.ova = ova;
// END TODO
if (typeof Annotator.Plugin["Grouping"] === 'function') if (typeof Annotator.Plugin["Grouping"] === 'function')
ova.annotator.addPlugin("Grouping"); ova.annotator.addPlugin("Grouping");
...@@ -202,18 +209,17 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -202,18 +209,17 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
annotation_mode: "${annotation_mode}", annotation_mode: "${annotation_mode}",
}; };
Catch = new CatchAnnotation($('#catchDIV'),catchOptions); Catch = new CatchAnnotation($('#catchDIV'),catchOptions);
// TODO: Fix to avoid using global scope!
window.Catch = Catch;
// END TODO
} }
// if the following is true, template is being rendered in LMS, otherwise it is in Studio startova();
if (typeof Annotator !== 'undefined') { };
startova(); try {
} else { require(["ova"], init);
try { } catch(error) {
require(["ova"], function(ova) { console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
startova();
});
} catch(error) {
console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
}
} }
}).call(this, require || RequireJS.require);
</script> </script>
...@@ -36,8 +36,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -36,8 +36,10 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
</div> </div>
<script> <script>
// TODO: Fix indentation in the following block
function onClickHideInstructions(){ (function (require) {
var init = function() {
function onClickHideInstructions(){
//Reset function if there is more than one event handler //Reset function if there is more than one event handler
$(this).off(); $(this).off();
$(this).on('click',onClickHideInstructions); $(this).on('click',onClickHideInstructions);
...@@ -176,6 +178,11 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -176,6 +178,11 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
//Load the plugin Video/Text Annotation //Load the plugin Video/Text Annotation
ova = new OpenVideoAnnotation.Annotator($('#videoHolder'),options); ova = new OpenVideoAnnotation.Annotator($('#videoHolder'),options);
// TODO: Fix to avoid using global scope!
window.options = options;
window.ova = ova;
// END TODO
ova.annotator.addPlugin('Tags'); ova.annotator.addPlugin('Tags');
var userId = ('${default_tab}'.toLowerCase() === 'instructor') ? var userId = ('${default_tab}'.toLowerCase() === 'instructor') ?
'${instructor_email}': '${instructor_email}':
...@@ -197,16 +204,17 @@ ${static.css(group='style-xmodule-annotations', raw=True)} ...@@ -197,16 +204,17 @@ ${static.css(group='style-xmodule-annotations', raw=True)}
annotation_mode: "${annotation_mode}", annotation_mode: "${annotation_mode}",
}; };
Catch = new CatchAnnotation($('#catchDIV'),catchOptions); Catch = new CatchAnnotation($('#catchDIV'),catchOptions);
// TODO: Fix to avoid using global scope!
window.Catch = Catch;
// END TODO
} }
if (typeof Annotator !== 'undefined') {
startova(); startova();
} else { };
try { try {
require(["ova"], function(ova) { require(["ova"], init);
startova(); } catch(error) {
}); console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
} catch(error) {
console.log("Error: " + error.message + " - Annotator not loaded in LMS.");
}
} }
}).call(this, require || RequireJS.require);
</script> </script>
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