mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-09-23 10:21:31 +00:00
Simplify VE data modules using 'packageFiles'
We can now serve the JSON data almost directly (although, curiously, we need a main file in the module that is JavaScript, not JSON), and without using global state in the JS code. Change-Id: I203b3e396b28f4b4ef49c3c0918a4025082308c4
This commit is contained in:
parent
e3d54827cf
commit
9207931f53
|
@ -304,26 +304,22 @@
|
|||
"mobile"
|
||||
]
|
||||
},
|
||||
"ext.math.visualEditor.mathSymbolsData": {
|
||||
"class": "MediaWiki\\Extension\\Math\\MathMathSymbolsDataModule"
|
||||
},
|
||||
"ext.math.visualEditor.mathSymbols": {
|
||||
"packageFiles": [
|
||||
"ve-math/mathSymbols.js",
|
||||
"ve-math/mathSymbols.json"
|
||||
],
|
||||
"styles": [
|
||||
"ve-math/ve.ui.MWMathSymbols.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.math.visualEditor.mathSymbolsData"
|
||||
]
|
||||
},
|
||||
"ext.math.visualEditor.chemSymbolsData": {
|
||||
"class": "MediaWiki\\Extension\\Math\\MathChemSymbolsDataModule"
|
||||
},
|
||||
"ext.math.visualEditor.chemSymbols": {
|
||||
"packageFiles": [
|
||||
"ve-math/chemSymbols.js",
|
||||
"ve-math/chemSymbols.json"
|
||||
],
|
||||
"styles": [
|
||||
"ve-math/ve.ui.MWChemSymbols.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.math.visualEditor.chemSymbolsData"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
1
modules/ve-math/chemSymbols.js
Normal file
1
modules/ve-math/chemSymbols.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require( './chemSymbols.json' );
|
1
modules/ve-math/mathSymbols.js
Normal file
1
modules/ve-math/mathSymbols.js
Normal file
|
@ -0,0 +1 @@
|
|||
module.exports = require( './mathSymbols.json' );
|
|
@ -31,21 +31,8 @@ ve.ui.MWLatexDialog.static.size = 'larger';
|
|||
|
||||
ve.ui.MWLatexDialog.static.dir = 'ltr';
|
||||
|
||||
ve.ui.MWLatexDialog.static.symbols = null;
|
||||
|
||||
ve.ui.MWLatexDialog.static.symbolsModule = null;
|
||||
|
||||
/* static methods */
|
||||
|
||||
/**
|
||||
* Set the symbols property
|
||||
*
|
||||
* @param {Object} symbols The symbols and their group names
|
||||
*/
|
||||
ve.ui.MWLatexDialog.static.setSymbols = function ( symbols ) {
|
||||
this.symbols = symbols;
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
|
@ -151,8 +138,8 @@ ve.ui.MWLatexDialog.prototype.initialize = function () {
|
|||
continuous: true
|
||||
} );
|
||||
this.pages = [];
|
||||
this.symbolsPromise = mw.loader.using( this.constructor.static.symbolsModule ).done( function () {
|
||||
var symbols = dialog.constructor.static.symbols;
|
||||
this.symbolsPromise = mw.loader.using( this.constructor.static.symbolsModule ).done( function ( require ) {
|
||||
var symbols = require( dialog.constructor.static.symbolsModule );
|
||||
for ( var category in symbols ) {
|
||||
dialog.pages.push(
|
||||
new ve.ui.MWLatexPage(
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Math;
|
||||
|
||||
use MediaWiki\ResourceLoader as RL;
|
||||
|
||||
/**
|
||||
* Resource loader module providing extra data from the server to Chem.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class MathChemSymbolsDataModule extends RL\Module {
|
||||
|
||||
/** @inheritDoc */
|
||||
protected $targets = [ 'desktop', 'mobile' ];
|
||||
|
||||
public function getScript( RL\Context $context ) {
|
||||
return 've.ui.MWChemDialog.static.setSymbols(' .
|
||||
file_get_contents( __DIR__ . '/../modules/ve-math/chemSymbols.json' ) .
|
||||
');';
|
||||
}
|
||||
|
||||
public function getDependencies( RL\Context $context = null ) {
|
||||
return [
|
||||
'ext.math.visualEditor',
|
||||
];
|
||||
}
|
||||
|
||||
public function enableModuleContentVersion() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,33 +0,0 @@
|
|||
<?php
|
||||
|
||||
namespace MediaWiki\Extension\Math;
|
||||
|
||||
use MediaWiki\ResourceLoader as RL;
|
||||
|
||||
/**
|
||||
* Resource loader module providing extra data from the server to Math.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license MIT
|
||||
*/
|
||||
class MathMathSymbolsDataModule extends RL\Module {
|
||||
|
||||
/** @inheritDoc */
|
||||
protected $targets = [ 'desktop', 'mobile' ];
|
||||
|
||||
public function getScript( RL\Context $context ) {
|
||||
return 've.ui.MWMathDialog.static.setSymbols(' .
|
||||
file_get_contents( __DIR__ . '/../modules/ve-math/mathSymbols.json' ) .
|
||||
');';
|
||||
}
|
||||
|
||||
public function getDependencies( RL\Context $context = null ) {
|
||||
return [
|
||||
'ext.math.visualEditor',
|
||||
];
|
||||
}
|
||||
|
||||
public function enableModuleContentVersion() {
|
||||
return true;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue