From c3894c2c492411847e13bce1d89f8240f06986cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Wang?= Date: Fri, 10 Oct 2014 12:38:23 +0200 Subject: [PATCH] Display MathML when MathPlayer is installed When MathPlayer is installed, we show the MathML instead of the SVG fallback. This will in particular allow the sync highlighting feature of MathPlayer. This also introduces a module ext.math.js that could be used to do some Javascript postprocessing. Bug: 71748 Change-Id: I438a20032c312d12321ca4c5686bcfd107656b37 --- Math.hooks.php | 1 + Math.php | 5 +++++ MathMathML.php | 3 +++ modules/ext.math.css | 6 +++--- modules/ext.math.js | 10 ++++++++++ 5 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 modules/ext.math.js diff --git a/Math.hooks.php b/Math.hooks.php index 65819a1..e315974 100644 --- a/Math.hooks.php +++ b/Math.hooks.php @@ -135,6 +135,7 @@ class MathHooks { $parser->getOutput()->addModules( array( 'ext.math.mathjax.enabler' ) ); } $parser->getOutput()->addModuleStyles( array( 'ext.math.styles' ) ); + $parser->getOutput()->addModules( array( 'ext.math.scripts' ) ); // Writes cache if rendering was successful $renderer->writeCache(); diff --git a/Math.php b/Math.php index c85bdb9..0314aaa 100644 --- a/Math.php +++ b/Math.php @@ -235,6 +235,11 @@ $wgResourceModules['ext.math.styles'] = array( 'remoteExtPath' => 'Math/modules', 'styles' => 'ext.math.css', ); +$wgResourceModules['ext.math.scripts'] = array( + 'localBasePath' => __DIR__ . '/modules', + 'remoteExtPath' => 'Math/modules', + 'scripts' => 'ext.math.js', +); // MathJax module // If you modify these arrays, update ext.math.mathjax.enabler.js to ensure diff --git a/MathMathML.php b/MathMathML.php index b57d738..332454b 100644 --- a/MathMathML.php +++ b/MathMathML.php @@ -424,6 +424,9 @@ class MathMathML extends MathRenderer { } else { $class .= 'inline'; } + if ( !$fallback) { + $class .= ' mwe-math-mathml-a11y'; + } return $class; } /** diff --git a/modules/ext.math.css b/modules/ext.math.css index d8bffee..6b9b32b 100644 --- a/modules/ext.math.css +++ b/modules/ext.math.css @@ -10,8 +10,8 @@ /* Default style for MathML. */ .mwe-math-mathml-inline { display: inline !important; } .mwe-math-mathml-display { display: block !important; margin-left: auto; margin-right: auto; } -.mwe-math-mathml-inline, .mwe-math-mathml-display { - /* We try to hide the MathML formula in a way that still makes it accessible to screen readers. */ +.mwe-math-mathml-a11y { + /* We try to hide the MathML formula in a way that still makes it accessible to accessibility tools. */ clip: rect(1px, 1px, 1px, 1px); overflow: hidden; position: absolute; @@ -59,7 +59,7 @@ img.mwe-math-fallback-png-display { display: block; } @-moz-document url-prefix() { /* For Gecko browsers, hide the SVG fallback and show the MathML instead. We override the style for SVG and MathML above */ - .mwe-math-mathml-inline, .mwe-math-mathml-display { + .mwe-math-mathml-a11y { clip: auto; overflow: visible; position: static; diff --git a/modules/ext.math.js b/modules/ext.math.js new file mode 100644 index 0000000..a043014 --- /dev/null +++ b/modules/ext.math.js @@ -0,0 +1,10 @@ +( function ( $ ) { + 'use strict'; + // If MathPlayer is installed we show the MathML rendering. + if (navigator.userAgent.indexOf('MathPlayer') > -1) { + $( '.mwe-math-mathml-a11y' ).removeClass( 'mwe-math-mathml-a11y' ); + $( 'img' ).removeClass( 'mwe-math-fallback-svg-inline mwe-math-fallback-svg-display' ); + } + // FIXME: for browsers without SVG support, the fallback should be + // updated to point to PNG images. +}( jQuery ) );