mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-12 16:05:09 +00:00
Merge "Fix Preview not working with MathML rendering"
This commit is contained in:
commit
500b9bcefc
|
@ -1,6 +1,7 @@
|
||||||
( function () {
|
( function () {
|
||||||
'use strict';
|
'use strict';
|
||||||
const previewType = 'math';
|
const previewType = 'math';
|
||||||
|
const selector = '.mwe-math-element[href*="qid"], .mwe-math-element[data-qid] img';
|
||||||
const api = new mw.Rest();
|
const api = new mw.Rest();
|
||||||
const isValidId = function ( qid ) {
|
const isValidId = function ( qid ) {
|
||||||
return qid.match( /Q\d+/g ) === null;
|
return qid.match( /Q\d+/g ) === null;
|
||||||
|
@ -11,10 +12,24 @@
|
||||||
'Accept-Language': mw.config.language
|
'Accept-Language': mw.config.language
|
||||||
} );
|
} );
|
||||||
};
|
};
|
||||||
|
const getQidStr = function ( parent ) {
|
||||||
|
if ( parent.getAttribute( 'href' ) ) {
|
||||||
|
const href = parent.getAttribute( 'href' );
|
||||||
|
const match = href.match( /qid=(Q\d+)/ );
|
||||||
|
if ( match ) {
|
||||||
|
return match[ 1 ];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
const fetchPreviewForTitle = function ( title, el ) {
|
const fetchPreviewForTitle = function ( title, el ) {
|
||||||
const deferred = $.Deferred();
|
const deferred = $.Deferred();
|
||||||
let qidstr = el.parentNode.parentNode.dataset.qid;
|
const parent = el.closest( '.mwe-math-element' );
|
||||||
if ( isValidId( qidstr ) ) {
|
let qidstr = getQidStr( parent );
|
||||||
|
if ( parent.dataset.qid ) {
|
||||||
|
qidstr = parent.dataset.qid;
|
||||||
|
}
|
||||||
|
if ( !qidstr || isValidId( qidstr ) ) {
|
||||||
return deferred.reject();
|
return deferred.reject();
|
||||||
}
|
}
|
||||||
qidstr = qidstr.slice( 1 );
|
qidstr = qidstr.slice( 1 );
|
||||||
|
@ -35,16 +50,16 @@
|
||||||
};
|
};
|
||||||
// popups require title attributes
|
// popups require title attributes
|
||||||
[].forEach.call(
|
[].forEach.call(
|
||||||
document.querySelectorAll( '.mwe-math-element[data-qid] img' ),
|
document.querySelectorAll( selector ),
|
||||||
( node ) => {
|
( node ) => {
|
||||||
if ( isValidId( node.parentNode.parentNode.dataset.qid ) ) {
|
const qidstr = getQidStr( node );
|
||||||
|
if ( qidstr && isValidId( qidstr ) ) {
|
||||||
node.dataset.title = 'math-unique-identifier';
|
node.dataset.title = 'math-unique-identifier';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const mathDisabledByUser = mw.user.isNamed() && mw.user.options.get( 'math-popups' ) !== '1';
|
const mathDisabledByUser = mw.user.isNamed() && mw.user.options.get( 'math-popups' ) !== '1';
|
||||||
const selector = '.mwe-math-element[data-qid] img';
|
|
||||||
const mathAppliesToThisPage = document.querySelectorAll( selector ).length > 0;
|
const mathAppliesToThisPage = document.querySelectorAll( selector ).length > 0;
|
||||||
|
|
||||||
module.exports = !mathAppliesToThisPage || mathDisabledByUser ? null : {
|
module.exports = !mathAppliesToThisPage || mathDisabledByUser ? null : {
|
||||||
|
|
Loading…
Reference in a new issue