From e954eb01a0b0c6ae1bad0e5fd450ad8d0e007e40 Mon Sep 17 00:00:00 2001 From: DawoudSheraz Date: Tue, 4 Dec 2018 16:29:15 +0500 Subject: [PATCH] EDUCATOR-3764 Mathjax accessibility inclusion inside edx-platform --- cms/djangoapps/pipeline_js/js/xmodule.js | 2 +- cms/static/cms/js/require-config.js | 7 +++++-- cms/static/cms/js/spec/main.js | 2 +- cms/static/cms/js/spec/main_squire.js | 2 +- .../static/common/js/discussion/mathjax_include.js | 11 ++++++++++- common/static/common/js/discussion/utils.js | 2 +- .../views/discussion_thread_show_view.js | 3 +-- .../js/discussion/views/discussion_thread_view.js | 14 +++++++++----- .../discussion/views/response_comment_show_view.js | 2 ++ .../js/discussion/views/thread_response_view.js | 6 +++++- common/templates/mathjax_include.html | 13 ++++++++++++- lms/static/lms/js/spec/main.js | 2 +- 12 files changed, 49 insertions(+), 17 deletions(-) diff --git a/cms/djangoapps/pipeline_js/js/xmodule.js b/cms/djangoapps/pipeline_js/js/xmodule.js index 3acc0958e0..f27ead886d 100644 --- a/cms/djangoapps/pipeline_js/js/xmodule.js +++ b/cms/djangoapps/pipeline_js/js/xmodule.js @@ -18,7 +18,7 @@ define( window._ = _; $script( - '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js' + + 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js' + '?config=TeX-MML-AM_SVG&delayStartupUntil=configured', 'mathjax', function() { diff --git a/cms/static/cms/js/require-config.js b/cms/static/cms/js/require-config.js index 4b7e60f2ac..d043708c5a 100644 --- a/cms/static/cms/js/require-config.js +++ b/cms/static/cms/js/require-config.js @@ -55,8 +55,11 @@ // the option as displayed in the context menu to false. // When upgrading to 2.6, check if this variable name changed. window.MathJax = { - menuSettings: {CHTMLpreview: false} + menuSettings: { + CHTMLpreview: false + } }; + }; defineDependency('jQuery', 'jquery'); @@ -131,7 +134,7 @@ 'lang_edx': 'js/src/lang_edx', // externally hosted files - mathjax: '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len + mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len 'youtube': [ // youtube URL does not end in '.js'. We add '?noext' to the path so // that require.js adds the '.js' to the query component of the URL, diff --git a/cms/static/cms/js/spec/main.js b/cms/static/cms/js/spec/main.js index 1f32ced8d6..f5aa089b04 100644 --- a/cms/static/cms/js/spec/main.js +++ b/cms/static/cms/js/spec/main.js @@ -69,7 +69,7 @@ 'domReady': 'xmodule_js/common_static/js/vendor/domReady', 'URI': 'xmodule_js/common_static/js/vendor/URI.min', 'mock-ajax': 'xmodule_js/common_static/js/vendor/mock-ajax', - mathjax: '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len + mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len 'youtube': '//www.youtube.com/player_api?noext', 'js/src/ajax_prefix': 'xmodule_js/common_static/js/src/ajax_prefix', 'js/spec/test_utils': 'js/spec/test_utils' diff --git a/cms/static/cms/js/spec/main_squire.js b/cms/static/cms/js/spec/main_squire.js index 936aa39055..34ff4ace8f 100644 --- a/cms/static/cms/js/spec/main_squire.js +++ b/cms/static/cms/js/spec/main_squire.js @@ -48,7 +48,7 @@ 'draggabilly': 'xmodule_js/common_static/js/vendor/draggabilly', 'domReady': 'xmodule_js/common_static/js/vendor/domReady', 'URI': 'xmodule_js/common_static/js/vendor/URI.min', - mathjax: '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len + mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len 'youtube': '//www.youtube.com/player_api?noext', 'js/src/ajax_prefix': 'xmodule_js/common_static/js/src/ajax_prefix' }, diff --git a/common/static/common/js/discussion/mathjax_include.js b/common/static/common/js/discussion/mathjax_include.js index a2e8f36898..f5d18e8077 100644 --- a/common/static/common/js/discussion/mathjax_include.js +++ b/common/static/common/js/discussion/mathjax_include.js @@ -42,6 +42,15 @@ if (typeof MathJax === 'undefined') { }); }; }; - vendorScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG'; + + // Automatic loading of Mathjax accessibility files + window.MathJax = { + menuSettings: { + collapsible: true, + autocollapse: true, + explorer: true + } + }; + vendorScript.src = 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG'; document.body.appendChild(vendorScript); } diff --git a/common/static/common/js/discussion/utils.js b/common/static/common/js/discussion/utils.js index 576c062ec4..a4bcbd4d31 100644 --- a/common/static/common/js/discussion/utils.js +++ b/common/static/common/js/discussion/utils.js @@ -482,10 +482,10 @@ this.postMathJaxProcessor(this.markdownWithHighlight(element.text())) ); - this.typesetMathJax(element); }; DiscussionUtil.typesetMathJax = function(element) { + if (typeof MathJax !== 'undefined' && MathJax !== null) { MathJax.Hub.Queue(['Typeset', MathJax.Hub, element[0]]); } diff --git a/common/static/common/js/discussion/views/discussion_thread_show_view.js b/common/static/common/js/discussion/views/discussion_thread_show_view.js index f9b70fe672..51ca3aa3c1 100644 --- a/common/static/common/js/discussion/views/discussion_thread_show_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_show_view.js @@ -59,13 +59,12 @@ this.renderAttrs(); this.$('span.timeago').timeago(); this.convertMath(); - this.$('.post-body'); - this.$('h1,h3'); return this; }; DiscussionThreadShowView.prototype.convertMath = function() { DiscussionUtil.convertMath(this.$('.post-body')); + DiscussionUtil.typesetMathJax(this.$('.post-body')); }; DiscussionThreadShowView.prototype.edit = function(event) { diff --git a/common/static/common/js/discussion/views/discussion_thread_view.js b/common/static/common/js/discussion/views/discussion_thread_view.js index 3346575328..7978eb7486 100644 --- a/common/static/common/js/discussion/views/discussion_thread_view.js +++ b/common/static/common/js/discussion/views/discussion_thread_view.js @@ -317,7 +317,10 @@ if (options.focusAddedResponse) { this.focusToTheAddedResponse(view.el); } - DiscussionUtil.typesetMathJax(view.$el.find('.js-response-list')); + + // Typeset the response when initially loaded for any forum + DiscussionUtil.typesetMathJax(view.$el); + return view; }; DiscussionThreadView.prototype.renderAddResponseButton = function() { @@ -345,7 +348,7 @@ }; DiscussionThreadView.prototype.submitComment = function(event) { - var body, comment, url; + var body, comment, url, view; event.preventDefault(); url = this.model.urlFor('reply'); body = this.getWmdContent('reply-body'); @@ -365,7 +368,7 @@ user_id: window.user.get('id') }); comment.set('thread', this.model.get('thread')); - this.renderResponseToList(comment, '.js-response-list', { + view = this.renderResponseToList(comment, '.js-response-list', { focusAddedResponse: true }); this.model.addComment(); @@ -379,8 +382,9 @@ body: body }, success: function(data) { - comment.updateInfo(data.annotated_content_info); - return comment.set(data.content); + comment.updateInfo(data.annotated_content_info); + comment.set(data.content); + DiscussionUtil.typesetMathJax(view.$el.find('.response-body')); } }); }; diff --git a/common/static/common/js/discussion/views/response_comment_show_view.js b/common/static/common/js/discussion/views/response_comment_show_view.js index da66d28315..99f425036d 100644 --- a/common/static/common/js/discussion/views/response_comment_show_view.js +++ b/common/static/common/js/discussion/views/response_comment_show_view.js @@ -72,6 +72,8 @@ ResponseCommentShowView.prototype.convertMath = function() { DiscussionUtil.convertMath(this.$el.find('.response-body')); + DiscussionUtil.typesetMathJax(this.$el.find('.response-body')); + }; ResponseCommentShowView.prototype._delete = function(event) { diff --git a/common/static/common/js/discussion/views/thread_response_view.js b/common/static/common/js/discussion/views/thread_response_view.js index 3fb47e9650..e3f4dd3b6e 100644 --- a/common/static/common/js/discussion/views/thread_response_view.js +++ b/common/static/common/js/discussion/views/thread_response_view.js @@ -82,7 +82,9 @@ ThreadResponseView.prototype.render = function() { this.$el.addClass('response_' + this.model.get('id')); - this.$el.html(this.renderTemplate()); + + // Setting the HTML through utils to cope for tag-less text + edx.HtmlUtils.setHtml(this.$el, edx.HtmlUtils.HTML(this.renderTemplate())); this.delegateEvents(); this.renderShowView(); this.renderAttrs(); @@ -309,6 +311,7 @@ event.preventDefault(); this.createShowView(); this.renderShowView(); + DiscussionUtil.typesetMathJax(this.$el.find('.response-body')); return this.showCommentForm(); }; @@ -342,6 +345,7 @@ }); self.createShowView(); self.renderShowView(); + DiscussionUtil.typesetMathJax(self.$el.find('.response-body')); return self.showCommentForm(); } }); diff --git a/common/templates/mathjax_include.html b/common/templates/mathjax_include.html index cbae907011..1f46d5098b 100644 --- a/common/templates/mathjax_include.html +++ b/common/templates/mathjax_include.html @@ -75,9 +75,20 @@ } + + - + %endif diff --git a/lms/static/lms/js/spec/main.js b/lms/static/lms/js/spec/main.js index dd63fbdc47..787591b083 100644 --- a/lms/static/lms/js/spec/main.js +++ b/lms/static/lms/js/spec/main.js @@ -56,7 +56,7 @@ 'squire': 'common/js/vendor/Squire', 'jasmine-imagediff': 'xmodule_js/common_static/js/vendor/jasmine-imagediff', 'domReady': 'xmodule_js/common_static/js/vendor/domReady', - mathjax: '//cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len + mathjax: 'https://cdn.jsdelivr.net/npm/mathjax@2.7.5/MathJax.js?config=TeX-MML-AM_SVG&delayStartupUntil=configured', // eslint-disable-line max-len 'youtube': '//www.youtube.com/player_api?noext', 'js/src/ajax_prefix': 'xmodule_js/common_static/js/src/ajax_prefix', 'js/instructor_dashboard/student_admin': 'js/instructor_dashboard/student_admin',