[MediaWiki-commits] [Gerrit] Improvements to the PNG fallback style. - change (mediawiki...Math)

2014-10-11 Thread Code Review
Frédéric Wang has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/166193

Change subject: Improvements to the PNG fallback style.
..

Improvements to the PNG fallback style.

- create a new img tag to avoid copying unwanted style from the SVG fallback.
- keep the legacy tex class for consistency with the PNG mode.

Bug: 71912
Change-Id: Ibe4683d2898b49fda190e2f1535cab1b952250b0
---
M modules/ext.math.js
1 file changed, 11 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Math 
refs/changes/93/166193/1

diff --git a/modules/ext.math.js b/modules/ext.math.js
index 48c84ed..2f6e5d1 100644
--- a/modules/ext.math.js
+++ b/modules/ext.math.js
@@ -1,7 +1,7 @@
 ( function ( $ ) {
'use strict';
-   // These constants are taken from Math.php
-   var MW_MATH_PNG = 0, MW_MATH_MATHML = 5;
+   // The MW_MATH_PNG and MW_MATH_MATHML constants are taken from Math.php
+   var MW_MATH_PNG = 0, MW_MATH_MATHML = 5, img;
 
// If MathPlayer is installed we show the MathML rendering.
if (navigator.userAgent.indexOf('MathPlayer')  -1) {
@@ -14,9 +14,15 @@
// PNG fallback. See 
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
if 
(!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image',
 '1.1')) {
$( 'img.mwe-math-fallback-svg-inline, 
img.mwe-math-fallback-svg-display' ).each(function() {
-   this.setAttribute('src', this.src.replace('mode=' + 
MW_MATH_MATHML, 'mode=' + MW_MATH_PNG));
+   // Create a new PNG image to use as the fallback.
+   img = document.createElement('img');
+   img.setAttribute( 'src', this.src.replace('mode=' + 
MW_MATH_MATHML, 'mode=' + MW_MATH_PNG) );
+   img.setAttribute( 'class', 'tex mwe-math-fallback-png-' 
+ ($( this ).hasClass('mwe-math-fallback-svg-inline') ? 'inline' : 'display') );
+   img.setAttribute( 'aria-hidden', 'true' );
+   this.parentNode.insertBefore( img, this );
+
+   // Hide the SVG fallback.
+   $( this ).css( 'display', 'none' );
});
-   $( 'img.mwe-math-fallback-svg-inline' ).removeClass( 
'mwe-math-fallback-svg-inline' ).addClass( 'mwe-math-fallback-png-inline' );
-   $( 'img.mwe-math-fallback-svg-display' ).removeClass( 
'mwe-math-fallback-svg-display' ).addClass( 'mwe-math-fallback-png-display' );
}
 }( jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/166193
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibe4683d2898b49fda190e2f1535cab1b952250b0
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Frédéric Wang fred.w...@free.fr
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits


[MediaWiki-commits] [Gerrit] Improvements to the PNG fallback style. - change (mediawiki...Math)

2014-10-11 Thread Physikerwelt (Code Review)
Physikerwelt has submitted this change and it was merged.

Change subject: Improvements to the PNG fallback style.
..


Improvements to the PNG fallback style.

- create a new img tag to avoid copying unwanted style from the SVG fallback.
- keep the legacy tex class for consistency with the PNG mode.

Bug: 71912
Change-Id: Ibe4683d2898b49fda190e2f1535cab1b952250b0
---
M modules/ext.math.js
1 file changed, 11 insertions(+), 5 deletions(-)

Approvals:
  Physikerwelt: Verified; Looks good to me, approved



diff --git a/modules/ext.math.js b/modules/ext.math.js
index 48c84ed..2f6e5d1 100644
--- a/modules/ext.math.js
+++ b/modules/ext.math.js
@@ -1,7 +1,7 @@
 ( function ( $ ) {
'use strict';
-   // These constants are taken from Math.php
-   var MW_MATH_PNG = 0, MW_MATH_MATHML = 5;
+   // The MW_MATH_PNG and MW_MATH_MATHML constants are taken from Math.php
+   var MW_MATH_PNG = 0, MW_MATH_MATHML = 5, img;
 
// If MathPlayer is installed we show the MathML rendering.
if (navigator.userAgent.indexOf('MathPlayer')  -1) {
@@ -14,9 +14,15 @@
// PNG fallback. See 
https://github.com/Modernizr/Modernizr/blob/master/feature-detects/svg/asimg.js
if 
(!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image',
 '1.1')) {
$( 'img.mwe-math-fallback-svg-inline, 
img.mwe-math-fallback-svg-display' ).each(function() {
-   this.setAttribute('src', this.src.replace('mode=' + 
MW_MATH_MATHML, 'mode=' + MW_MATH_PNG));
+   // Create a new PNG image to use as the fallback.
+   img = document.createElement('img');
+   img.setAttribute( 'src', this.src.replace('mode=' + 
MW_MATH_MATHML, 'mode=' + MW_MATH_PNG) );
+   img.setAttribute( 'class', 'tex mwe-math-fallback-png-' 
+ ($( this ).hasClass('mwe-math-fallback-svg-inline') ? 'inline' : 'display') );
+   img.setAttribute( 'aria-hidden', 'true' );
+   this.parentNode.insertBefore( img, this );
+
+   // Hide the SVG fallback.
+   $( this ).css( 'display', 'none' );
});
-   $( 'img.mwe-math-fallback-svg-inline' ).removeClass( 
'mwe-math-fallback-svg-inline' ).addClass( 'mwe-math-fallback-png-inline' );
-   $( 'img.mwe-math-fallback-svg-display' ).removeClass( 
'mwe-math-fallback-svg-display' ).addClass( 'mwe-math-fallback-png-display' );
}
 }( jQuery ) );

-- 
To view, visit https://gerrit.wikimedia.org/r/166193
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ibe4683d2898b49fda190e2f1535cab1b952250b0
Gerrit-PatchSet: 3
Gerrit-Project: mediawiki/extensions/Math
Gerrit-Branch: master
Gerrit-Owner: Frédéric Wang fred.w...@free.fr
Gerrit-Reviewer: Frédéric Wang fred.w...@free.fr
Gerrit-Reviewer: Physikerwelt w...@physikerwelt.de
Gerrit-Reviewer: TheDJ hartman.w...@gmail.com
Gerrit-Reviewer: jenkins-bot 

___
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits