2014-10-10 10:38:23 +00:00
|
|
|
( function ( $ ) {
|
|
|
|
'use strict';
|
2015-07-22 22:10:46 +00:00
|
|
|
var img, url;
|
2014-10-10 19:25:42 +00:00
|
|
|
|
2014-10-10 10:38:23 +00:00
|
|
|
// If MathPlayer is installed we show the MathML rendering.
|
2015-09-14 18:46:13 +00:00
|
|
|
if ( navigator.userAgent.indexOf( 'MathPlayer' ) > -1 ) {
|
2014-10-10 10:38:23 +00:00
|
|
|
$( '.mwe-math-mathml-a11y' ).removeClass( 'mwe-math-mathml-a11y' );
|
2014-10-12 09:26:57 +00:00
|
|
|
$( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).css( 'display', 'none' );
|
2014-10-10 19:25:42 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We verify whether SVG as <img> is supported and otherwise use the
|
|
|
|
// PNG fallback. See https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
|
2015-09-14 18:46:13 +00:00
|
|
|
if ( !document.implementation.hasFeature( 'http://www.w3.org/TR/SVG11/feature#Image', '1.1' ) ) {
|
|
|
|
$( '.mwe-math-fallback-image-inline, .mwe-math-fallback-image-display' ).each( function () {
|
2014-10-11 15:26:00 +00:00
|
|
|
// Create a new PNG image to use as the fallback.
|
2015-09-14 18:46:13 +00:00
|
|
|
img = document.createElement( 'img' );
|
|
|
|
url = this.style.backgroundImage.match( /url\('?([^']*)'?\)/ )[ 1 ];
|
|
|
|
img.setAttribute( 'src', url.replace( 'mode=' + 'mathml', 'mode=' + 'png' ) );
|
|
|
|
img.setAttribute( 'class', 'tex mwe-math-fallback-image-' + ( $( this ).hasClass( 'mwe-math-fallback-image-inline' ) ? 'inline' : 'display' ) );
|
2014-10-11 15:26:00 +00:00
|
|
|
img.setAttribute( 'aria-hidden', 'true' );
|
|
|
|
this.parentNode.insertBefore( img, this );
|
|
|
|
|
|
|
|
// Hide the SVG fallback.
|
|
|
|
$( this ).css( 'display', 'none' );
|
2015-09-14 18:46:13 +00:00
|
|
|
} );
|
2014-10-10 10:38:23 +00:00
|
|
|
}
|
|
|
|
}( jQuery ) );
|