mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-12-19 11:00:45 +00:00
Fix for Preview has wrong location in MathML mode
The previewin MathML mode was always at the left side of the website. Added values for `node.offsetWidth` and `node.offsetHeight`. Values are taken from `node.getBoundingClientRect()`. Cleaned up if-clause(node.dataset.title) as it is not needed anymore. In-lined IsValidId funtion as there was only one remaining reference. Bug: T381311 Change-Id: Ied17aaaaf9156e2712ed6c7d6d6f08ecccc12286
This commit is contained in:
parent
500b9bcefc
commit
b66e28b237
|
@ -3,9 +3,6 @@
|
||||||
const previewType = 'math';
|
const previewType = 'math';
|
||||||
const selector = '.mwe-math-element[href*="qid"], .mwe-math-element[data-qid] img';
|
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 ) {
|
|
||||||
return qid.match( /Q\d+/g ) === null;
|
|
||||||
};
|
|
||||||
const fetch = function ( qid ) {
|
const fetch = function ( qid ) {
|
||||||
return api.get( '/math/v0/popup/html/' + qid, {}, {
|
return api.get( '/math/v0/popup/html/' + qid, {}, {
|
||||||
Accept: 'application/json; charset=utf-8',
|
Accept: 'application/json; charset=utf-8',
|
||||||
|
@ -29,7 +26,7 @@
|
||||||
if ( parent.dataset.qid ) {
|
if ( parent.dataset.qid ) {
|
||||||
qidstr = parent.dataset.qid;
|
qidstr = parent.dataset.qid;
|
||||||
}
|
}
|
||||||
if ( !qidstr || isValidId( qidstr ) ) {
|
if ( !qidstr || ( qidstr.match( /Q\d+/g ) === null ) ) {
|
||||||
return deferred.reject();
|
return deferred.reject();
|
||||||
}
|
}
|
||||||
qidstr = qidstr.slice( 1 );
|
qidstr = qidstr.slice( 1 );
|
||||||
|
@ -48,13 +45,15 @@
|
||||||
} );
|
} );
|
||||||
return deferred.promise();
|
return deferred.promise();
|
||||||
};
|
};
|
||||||
// popups require title attributes
|
// popups require offsetHeight and offsetWidth attributes
|
||||||
[].forEach.call(
|
[].forEach.call(
|
||||||
document.querySelectorAll( selector ),
|
document.querySelectorAll( selector ),
|
||||||
( node ) => {
|
( node ) => {
|
||||||
const qidstr = getQidStr( node );
|
if ( typeof node.offsetWidth === 'undefined' ) {
|
||||||
if ( qidstr && isValidId( qidstr ) ) {
|
node.offsetWidth = node.getBoundingClientRect().width || 1;
|
||||||
node.dataset.title = 'math-unique-identifier';
|
}
|
||||||
|
if ( typeof node.offsetHeight === 'undefined' ) {
|
||||||
|
node.offsetHeight = node.getBoundingClientRect().height || 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue