mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Math
synced 2024-11-24 23:46:39 +00:00
Merge "Add support for chemical formulae in VisualEditor"
This commit is contained in:
commit
87c2cb4ab1
36
MathChemSymbolsDataModule.php
Normal file
36
MathChemSymbolsDataModule.php
Normal file
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
/**
|
||||
* Resource loader module providing extra data from the server to Chem.
|
||||
*
|
||||
* @file
|
||||
* @ingroup Extensions
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
class MathChemSymbolsDataModule extends ResourceLoaderModule {
|
||||
|
||||
/* Protected Members */
|
||||
|
||||
protected $origin = self::ORIGIN_USER_SITEWIDE;
|
||||
protected $targets = [ 'desktop', 'mobile' ];
|
||||
|
||||
/* Methods */
|
||||
|
||||
public function getScript( ResourceLoaderContext $context ) {
|
||||
return
|
||||
've.ui.MWChemDialog.static.setSymbols(' .
|
||||
file_get_contents( __DIR__ . '/modules/ve-math/chemSymbols.json' ) .
|
||||
');';
|
||||
}
|
||||
|
||||
public function getDependencies( ResourceLoaderContext $context = null ) {
|
||||
return [
|
||||
'ext.math.visualEditor',
|
||||
];
|
||||
}
|
||||
|
||||
public function enableModuleContentVersion() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -8,7 +8,7 @@
|
|||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
class MathDataModule extends ResourceLoaderModule {
|
||||
class MathMathSymbolsDataModule extends ResourceLoaderModule {
|
||||
|
||||
/* Protected Members */
|
||||
|
||||
|
@ -20,7 +20,7 @@ class MathDataModule extends ResourceLoaderModule {
|
|||
public function getScript( ResourceLoaderContext $context ) {
|
||||
return
|
||||
've.ui.MWMathDialog.static.setSymbols(' .
|
||||
file_get_contents( __DIR__ . '/modules/ve-math/symbols.json' ) .
|
||||
file_get_contents( __DIR__ . '/modules/ve-math/mathSymbols.json' ) .
|
||||
');';
|
||||
}
|
||||
|
125
extension.json
125
extension.json
|
@ -13,7 +13,8 @@
|
|||
"callback": "MathHooks::registerExtension",
|
||||
"type": "parserhook",
|
||||
"AutoloadClasses": {
|
||||
"MathDataModule": "MathDataModule.php",
|
||||
"MathMathSymbolsDataModule": "MathMathSymbolsDataModule.php",
|
||||
"MathChemSymbolsDataModule": "MathChemSymbolsDataModule.php",
|
||||
"MathHooks": "Math.hooks.php",
|
||||
"MathRenderer": "MathRenderer.php",
|
||||
"MathRestbaseInterface": "MathRestbaseInterface.php",
|
||||
|
@ -149,75 +150,111 @@
|
|||
},
|
||||
"ext.math.visualEditor": {
|
||||
"scripts": [
|
||||
"ve-math/ve.dm.MWLatexNode.js",
|
||||
"ve-math/ve.ce.MWLatexNode.js",
|
||||
"ve-math/ve.ui.MWLatexInspector.js",
|
||||
"ve-math/ve.ui.MWLatexContextItem.js",
|
||||
"ve-math/ve.ui.MWLatexPage.js",
|
||||
"ve-math/ve.ui.MWLatexDialog.js",
|
||||
"ve-math/ve.dm.MWChemNode.js",
|
||||
"ve-math/ve.ce.MWChemNode.js",
|
||||
"ve-math/ve.ui.MWChemInspector.js",
|
||||
"ve-math/ve.ui.MWChemContextItem.js",
|
||||
"ve-math/ve.ui.MWChemDialog.js",
|
||||
"ve-math/ve.ui.MWChemDialogTool.js",
|
||||
"ve-math/ve.dm.MWMathNode.js",
|
||||
"ve-math/ve.ce.MWMathNode.js",
|
||||
"ve-math/ve.ui.MWMathInspector.js",
|
||||
"ve-math/ve.ui.MWMathContextItem.js",
|
||||
"ve-math/ve.ui.MWMathDialog.js",
|
||||
"ve-math/ve.ui.MWMathPage.js",
|
||||
"ve-math/ve.ui.MWMathDialogTool.js"
|
||||
],
|
||||
"styles": [
|
||||
"ve-math/ve.ce.MWMathNode.css",
|
||||
"ve-math/ve.ui.MWMathIcons.css",
|
||||
"ve-math/ve.ui.MWMathInspector.css",
|
||||
"ve-math/ve.ui.MWMathPage.css",
|
||||
"ve-math/ve.ui.MWMathDialog.css"
|
||||
"ve-math/ve.ui.MWLatexDialog.css",
|
||||
"ve-math/ve.ce.MWLatexNode.css",
|
||||
"ve-math/ve.ui.MWLatexInspector.css",
|
||||
"ve-math/ve.ui.MWLatexPage.css",
|
||||
"ve-math/ve.ui.MWLatexIcons.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.visualEditor.mwcore",
|
||||
"ext.math.styles"
|
||||
],
|
||||
"messages": [
|
||||
"math-visualeditor-mwmathcontextitem-quickedit",
|
||||
"math-visualeditor-mwchemdialog-title",
|
||||
"math-visualeditor-mwlatexcontextitem-quickedit",
|
||||
"math-visualeditor-mwlatexdialog-card-formula",
|
||||
"math-visualeditor-mwlatexdialog-card-options",
|
||||
"math-visualeditor-mwlatexinspector-display",
|
||||
"math-visualeditor-mwlatexinspector-display-block",
|
||||
"math-visualeditor-mwlatexinspector-display-default",
|
||||
"math-visualeditor-mwlatexinspector-display-inline",
|
||||
"math-visualeditor-mwlatexinspector-id",
|
||||
"math-visualeditor-mwmathdialog-title",
|
||||
"math-visualeditor-mwmathdialog-card-formula",
|
||||
"math-visualeditor-mwmathdialog-card-options",
|
||||
"math-visualeditor-mwmathinspector-display",
|
||||
"math-visualeditor-mwmathinspector-display-block",
|
||||
"math-visualeditor-mwmathinspector-display-default",
|
||||
"math-visualeditor-mwmathinspector-display-inline",
|
||||
"math-visualeditor-mwmathinspector-id",
|
||||
"math-visualeditor-mwmathinspector-title",
|
||||
"math-visualeditor-symbol-group-accents",
|
||||
"math-visualeditor-symbol-group-arrows",
|
||||
"math-visualeditor-symbol-group-bounds",
|
||||
"math-visualeditor-symbol-group-derivatives",
|
||||
"math-visualeditor-symbol-group-functions",
|
||||
"math-visualeditor-symbol-group-geometry",
|
||||
"math-visualeditor-symbol-group-greek",
|
||||
"math-visualeditor-symbol-group-hebrew",
|
||||
"math-visualeditor-symbol-group-large",
|
||||
"math-visualeditor-symbol-group-logic",
|
||||
"math-visualeditor-symbol-group-matrices",
|
||||
"math-visualeditor-symbol-group-modular",
|
||||
"math-visualeditor-symbol-group-operators",
|
||||
"math-visualeditor-symbol-group-parentheses",
|
||||
"math-visualeditor-symbol-group-projections",
|
||||
"math-visualeditor-symbol-group-relations",
|
||||
"math-visualeditor-symbol-group-root",
|
||||
"math-visualeditor-symbol-group-sets",
|
||||
"math-visualeditor-symbol-group-spacing",
|
||||
"math-visualeditor-symbol-group-special",
|
||||
"math-visualeditor-symbol-group-subscripts",
|
||||
"math-visualeditor-symbol-group-symbols",
|
||||
"math-visualeditor-symbol-group-typefaces",
|
||||
"math-visualeditor-symbol-group-unsorted"
|
||||
"math-visualeditor-symbol-group-chem-addition",
|
||||
"math-visualeditor-symbol-group-chem-aggregation",
|
||||
"math-visualeditor-symbol-group-chem-arrows",
|
||||
"math-visualeditor-symbol-group-chem-brackets",
|
||||
"math-visualeditor-symbol-group-chem-charges",
|
||||
"math-visualeditor-symbol-group-chem-dots",
|
||||
"math-visualeditor-symbol-group-chem-equations",
|
||||
"math-visualeditor-symbol-group-chem-formulae",
|
||||
"math-visualeditor-symbol-group-chem-greek",
|
||||
"math-visualeditor-symbol-group-chem-isotopes",
|
||||
"math-visualeditor-symbol-group-chem-operations",
|
||||
"math-visualeditor-symbol-group-chem-oxidation",
|
||||
"math-visualeditor-symbol-group-chem-precipitate",
|
||||
"math-visualeditor-symbol-group-chem-stoichiometric",
|
||||
"math-visualeditor-symbol-group-math-accents",
|
||||
"math-visualeditor-symbol-group-math-arrows",
|
||||
"math-visualeditor-symbol-group-math-bounds",
|
||||
"math-visualeditor-symbol-group-math-derivatives",
|
||||
"math-visualeditor-symbol-group-math-functions",
|
||||
"math-visualeditor-symbol-group-math-geometry",
|
||||
"math-visualeditor-symbol-group-math-greek",
|
||||
"math-visualeditor-symbol-group-math-hebrew",
|
||||
"math-visualeditor-symbol-group-math-large",
|
||||
"math-visualeditor-symbol-group-math-logic",
|
||||
"math-visualeditor-symbol-group-math-matrices",
|
||||
"math-visualeditor-symbol-group-math-modular",
|
||||
"math-visualeditor-symbol-group-math-operators",
|
||||
"math-visualeditor-symbol-group-math-parentheses",
|
||||
"math-visualeditor-symbol-group-math-projections",
|
||||
"math-visualeditor-symbol-group-math-relations",
|
||||
"math-visualeditor-symbol-group-math-root",
|
||||
"math-visualeditor-symbol-group-math-sets",
|
||||
"math-visualeditor-symbol-group-math-spacing",
|
||||
"math-visualeditor-symbol-group-math-special",
|
||||
"math-visualeditor-symbol-group-math-subscripts",
|
||||
"math-visualeditor-symbol-group-math-symbols",
|
||||
"math-visualeditor-symbol-group-math-typefaces",
|
||||
"math-visualeditor-symbol-group-math-unsorted"
|
||||
],
|
||||
"targets": [
|
||||
"desktop",
|
||||
"mobile"
|
||||
]
|
||||
},
|
||||
"ext.math.visualEditor.data": {
|
||||
"class": "MathDataModule"
|
||||
"ext.math.visualEditor.mathSymbolsData": {
|
||||
"class": "MathMathSymbolsDataModule"
|
||||
},
|
||||
"ext.math.visualEditor.symbols": {
|
||||
"ext.math.visualEditor.mathSymbols": {
|
||||
"styles": [
|
||||
"ve-math/ve.ui.MWMathSymbols.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.math.visualEditor.data"
|
||||
"ext.math.visualEditor.mathSymbolsData"
|
||||
]
|
||||
},
|
||||
"ext.math.visualEditor.chemSymbolsData": {
|
||||
"class": "MathChemSymbolsDataModule"
|
||||
},
|
||||
"ext.math.visualEditor.chemSymbols": {
|
||||
"styles": [
|
||||
"ve-math/ve.ui.MWChemSymbols.css"
|
||||
],
|
||||
"dependencies": [
|
||||
"ext.math.visualEditor.chemSymbolsData"
|
||||
]
|
||||
}
|
||||
},
|
||||
|
|
83
i18n/en.json
83
i18n/en.json
|
@ -18,40 +18,55 @@
|
|||
]
|
||||
},
|
||||
"math-desc": "Render mathematical formulas between <code><math></code> ... <code></math></code> tags",
|
||||
"math-visualeditor-mwmathcontextitem-quickedit": "Quick edit",
|
||||
"math-visualeditor-mwmathdialog-title": "Formula",
|
||||
"math-visualeditor-mwmathdialog-card-formula": "Formula",
|
||||
"math-visualeditor-mwmathdialog-card-options": "Options",
|
||||
"math-visualeditor-mwmathinspector-display": "Display",
|
||||
"math-visualeditor-mwmathinspector-display-block": "Block",
|
||||
"math-visualeditor-mwmathinspector-display-default": "Default",
|
||||
"math-visualeditor-mwmathinspector-display-inline": "Inline",
|
||||
"math-visualeditor-mwmathinspector-id": "Link ID (optional)",
|
||||
"math-visualeditor-mwmathinspector-title": "Formula",
|
||||
"math-visualeditor-symbol-group-accents": "Accents and diacritics",
|
||||
"math-visualeditor-symbol-group-arrows": "Arrows",
|
||||
"math-visualeditor-symbol-group-bounds": "Bounds",
|
||||
"math-visualeditor-symbol-group-derivatives": "Differentials and derivatives",
|
||||
"math-visualeditor-symbol-group-functions": "Standard numerical functions",
|
||||
"math-visualeditor-symbol-group-geometry": "Geometric",
|
||||
"math-visualeditor-symbol-group-greek": "Greek alphabet",
|
||||
"math-visualeditor-symbol-group-hebrew": "Hebrew alphabet",
|
||||
"math-visualeditor-symbol-group-large": "Large layouts",
|
||||
"math-visualeditor-symbol-group-logic": "Logic",
|
||||
"math-visualeditor-symbol-group-matrices": "Matrices",
|
||||
"math-visualeditor-symbol-group-modular": "Modular arithmetic",
|
||||
"math-visualeditor-symbol-group-operators": "Operators",
|
||||
"math-visualeditor-symbol-group-projections": "Projections",
|
||||
"math-visualeditor-symbol-group-parentheses": "Parentheses",
|
||||
"math-visualeditor-symbol-group-relations": "Relations",
|
||||
"math-visualeditor-symbol-group-root": "Radicals",
|
||||
"math-visualeditor-symbol-group-sets": "Sets",
|
||||
"math-visualeditor-symbol-group-spacing": "Spacing",
|
||||
"math-visualeditor-symbol-group-special": "Special",
|
||||
"math-visualeditor-symbol-group-subscripts": "Subscripts, superscripts and integrals",
|
||||
"math-visualeditor-symbol-group-symbols": "Symbols and constants",
|
||||
"math-visualeditor-symbol-group-typefaces": "Typefaces",
|
||||
"math-visualeditor-symbol-group-unsorted": "Unsorted",
|
||||
"math-visualeditor-mwchemdialog-title": "Chemical formula",
|
||||
"math-visualeditor-mwcheminspector-title": "Chemical formula",
|
||||
"math-visualeditor-mwlatexcontextitem-quickedit": "Quick edit",
|
||||
"math-visualeditor-mwlatexdialog-card-formula": "Formula",
|
||||
"math-visualeditor-mwlatexdialog-card-options": "Options",
|
||||
"math-visualeditor-mwlatexinspector-display": "Display",
|
||||
"math-visualeditor-mwlatexinspector-display-block": "Block",
|
||||
"math-visualeditor-mwlatexinspector-display-default": "Default",
|
||||
"math-visualeditor-mwlatexinspector-display-inline": "Inline",
|
||||
"math-visualeditor-mwlatexinspector-id": "Link ID (optional)",
|
||||
"math-visualeditor-mwmathdialog-title": "Math formula",
|
||||
"math-visualeditor-symbol-group-chem-addition": "Addition compounds",
|
||||
"math-visualeditor-symbol-group-chem-aggregation": "States of aggregation",
|
||||
"math-visualeditor-symbol-group-chem-arrows": "Reaction arrows",
|
||||
"math-visualeditor-symbol-group-chem-brackets": "Parenthesis, brackets & braces",
|
||||
"math-visualeditor-symbol-group-chem-charges": "Charges",
|
||||
"math-visualeditor-symbol-group-chem-dots": "Unpaired electrons & radical dots",
|
||||
"math-visualeditor-symbol-group-chem-equations": "Chemical equations",
|
||||
"math-visualeditor-symbol-group-chem-formulae": "Chemical formulae",
|
||||
"math-visualeditor-symbol-group-chem-greek": "Greek characters",
|
||||
"math-visualeditor-symbol-group-chem-isotopes": "Isotopes",
|
||||
"math-visualeditor-symbol-group-chem-operations": "Equation operators",
|
||||
"math-visualeditor-symbol-group-chem-oxidation": "Oxidation states",
|
||||
"math-visualeditor-symbol-group-chem-precipitate": "Precipitate and gas",
|
||||
"math-visualeditor-symbol-group-chem-stoichiometric": "Stoichiometric numbers",
|
||||
"math-visualeditor-symbol-group-math-accents": "Accents and diacritics",
|
||||
"math-visualeditor-symbol-group-math-arrows": "Arrows",
|
||||
"math-visualeditor-symbol-group-math-bounds": "Bounds",
|
||||
"math-visualeditor-symbol-group-math-derivatives": "Differentials and derivatives",
|
||||
"math-visualeditor-symbol-group-math-functions": "Standard numerical functions",
|
||||
"math-visualeditor-symbol-group-math-geometry": "Geometric",
|
||||
"math-visualeditor-symbol-group-math-greek": "Greek alphabet",
|
||||
"math-visualeditor-symbol-group-math-hebrew": "Hebrew alphabet",
|
||||
"math-visualeditor-symbol-group-math-large": "Large layouts",
|
||||
"math-visualeditor-symbol-group-math-logic": "Logic",
|
||||
"math-visualeditor-symbol-group-math-matrices": "Matrices",
|
||||
"math-visualeditor-symbol-group-math-modular": "Modular arithmetic",
|
||||
"math-visualeditor-symbol-group-math-operators": "Operators",
|
||||
"math-visualeditor-symbol-group-math-parentheses": "Parentheses",
|
||||
"math-visualeditor-symbol-group-math-projections": "Projections",
|
||||
"math-visualeditor-symbol-group-math-relations": "Relations",
|
||||
"math-visualeditor-symbol-group-math-root": "Radicals",
|
||||
"math-visualeditor-symbol-group-math-sets": "Sets",
|
||||
"math-visualeditor-symbol-group-math-spacing": "Spacing",
|
||||
"math-visualeditor-symbol-group-math-special": "Special",
|
||||
"math-visualeditor-symbol-group-math-subscripts": "Subscripts, superscripts and integrals",
|
||||
"math-visualeditor-symbol-group-math-symbols": "Symbols and constants",
|
||||
"math-visualeditor-symbol-group-math-typefaces": "Typefaces",
|
||||
"math-visualeditor-symbol-group-math-unsorted": "Unsorted",
|
||||
"math_bad_output": "Cannot write to or create math output directory",
|
||||
"math_bad_tmpdir": "Cannot write to or create math temp directory",
|
||||
"math_failure": "Failed to parse",
|
||||
|
|
|
@ -17,40 +17,55 @@
|
|||
]
|
||||
},
|
||||
"math-desc": "{{desc|name=Math|url=https://www.mediawiki.org/wiki/Extension:Math}}",
|
||||
"math-visualeditor-mwmathcontextitem-quickedit": "Label for the quick edit button in the math context item",
|
||||
"math-visualeditor-mwchemdialog-title": "Title for the dialog to edit <nowiki><chem></nowiki> formula blocks.\n{{Identical|Formula}}",
|
||||
"math-visualeditor-mwcheminspector-title": "Title for the inspector to edit <nowiki><chem></nowiki> formula blocks.",
|
||||
"math-visualeditor-mwlatexcontextitem-quickedit": "Label for the quick edit button in the math context item",
|
||||
"math-visualeditor-mwlatexdialog-card-formula": "Label for the generic formula card of the dialog for mathematics, chemistry, etc.\n{{Identical|Formula}}",
|
||||
"math-visualeditor-mwlatexdialog-card-options": "Label for the options card of the formula dialog.\n{{Identical|Options}}",
|
||||
"math-visualeditor-mwlatexinspector-display": "Label for the display attribute of the math node\n{{Identical|Display}}",
|
||||
"math-visualeditor-mwlatexinspector-display-block": "Label for the 'block' value of the display attribute\n{{Identical|Block}}",
|
||||
"math-visualeditor-mwlatexinspector-display-default": "Label for the 'default' value of the display attribute\n{{Identical|Default}}",
|
||||
"math-visualeditor-mwlatexinspector-display-inline": "Label for the 'inline' value of the display attribute\n{{Identical|Inline}}",
|
||||
"math-visualeditor-mwlatexinspector-id": "Label for the link ID attribute of the math node",
|
||||
"math-visualeditor-mwmathdialog-title": "Title for the dialog to edit <nowiki><math></nowiki> formula blocks.\n{{Identical|Formula}}",
|
||||
"math-visualeditor-mwmathdialog-card-formula": "Label for the formula card of the math dialog\n{{Identical|Formula}}",
|
||||
"math-visualeditor-mwmathdialog-card-options": "Label for the options card of the math dialog\n{{Identical|Options}}",
|
||||
"math-visualeditor-mwmathinspector-display": "Label for the display attribute of the math node\n{{Identical|Display}}",
|
||||
"math-visualeditor-mwmathinspector-display-block": "Label for the 'block' value of the display attribute\n{{Identical|Block}}",
|
||||
"math-visualeditor-mwmathinspector-display-default": "Label for the 'default' value of the display attribute\n{{Identical|Default}}",
|
||||
"math-visualeditor-mwmathinspector-display-inline": "Label for the 'inline' value of the display attribute\n{{Identical|Inline}}",
|
||||
"math-visualeditor-mwmathinspector-id": "Label for the link ID attribute of the math node",
|
||||
"math-visualeditor-mwmathinspector-title": "Title for the inspector to edit <nowiki><math></nowiki> formula blocks.\n{{Identical|Formula}}",
|
||||
"math-visualeditor-symbol-group-accents": "Label for the accents group of math symbols",
|
||||
"math-visualeditor-symbol-group-arrows": "Label for the arrows group of math symbols\n{{Identical|Arrow}}",
|
||||
"math-visualeditor-symbol-group-bounds": "Label for the bounds group of math symbols",
|
||||
"math-visualeditor-symbol-group-derivatives": "Label for the derivatives group of math symbols",
|
||||
"math-visualeditor-symbol-group-functions": "Label for the functions group of math symbols",
|
||||
"math-visualeditor-symbol-group-geometry": "Label for the geometry group of math symbols",
|
||||
"math-visualeditor-symbol-group-greek": "Label for the Greek group of math symbols",
|
||||
"math-visualeditor-symbol-group-hebrew": "Label for the Hebrew group of math symbols",
|
||||
"math-visualeditor-symbol-group-large": "Label for the large group of math symbols",
|
||||
"math-visualeditor-symbol-group-logic": "Label for the logic group of math symbols\n{{Identical|Logic}}",
|
||||
"math-visualeditor-symbol-group-matrices": "Label for the matrices group of math symbols",
|
||||
"math-visualeditor-symbol-group-modular": "Label for the modular group of math symbols",
|
||||
"math-visualeditor-symbol-group-operators": "Label for the operators group of math symbols\n{{Identical|Operator}}",
|
||||
"math-visualeditor-symbol-group-projections": "Label for the projections group of math symbols",
|
||||
"math-visualeditor-symbol-group-parentheses": "Label for the parentheses group of math symbols",
|
||||
"math-visualeditor-symbol-group-relations": "Label for the relations group of math symbols\n{{Identical|Relation}}",
|
||||
"math-visualeditor-symbol-group-root": "Label for the root group of math symbols\nIdentifies math radicals.",
|
||||
"math-visualeditor-symbol-group-sets": "Label for the sets group of math symbols",
|
||||
"math-visualeditor-symbol-group-spacing": "Label for the spacing group of math symbols",
|
||||
"math-visualeditor-symbol-group-special": "Label for the special group of math symbols\n{{Identical|Special}}",
|
||||
"math-visualeditor-symbol-group-subscripts": "Label for the subscripts group of math symbols",
|
||||
"math-visualeditor-symbol-group-symbols": "Label for the symbols group of math symbols",
|
||||
"math-visualeditor-symbol-group-typefaces": "Label for the typefaces group of math symbols",
|
||||
"math-visualeditor-symbol-group-unsorted": "Label for the unsorted group of math symbols",
|
||||
"math-visualeditor-symbol-group-chem-addition": "Label for the addition compounds group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-aggregation": "Label for the states of aggregation group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-arrows": "Label for the reaction arrows group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-brackets": "Label for the parenthesis, brackets & braces group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-charges": "Label for the charges group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-dots": "Label for the unpaired electrons & radical dots group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-equations": "Label for the chemical equations group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-formulae": "Label for the chemical formulae group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-greek": "Label for the greek characters group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-isotopes": "Label for the isotopes group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-operations": "Label for the equation operators group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-oxidation": "Label for the oxidation states group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-precipitate": "Label for the precipitate and gas group of chem symbols",
|
||||
"math-visualeditor-symbol-group-chem-stoichiometric": "Label for the stoichiometric numbers group of chem symbols",
|
||||
"math-visualeditor-symbol-group-math-accents": "Label for the accents group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-arrows": "Label for the arrows group of math symbols\n{{Identical|Arrow}}",
|
||||
"math-visualeditor-symbol-group-math-bounds": "Label for the bounds group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-derivatives": "Label for the derivatives group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-functions": "Label for the functions group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-geometry": "Label for the geometry group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-greek": "Label for the Greek group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-hebrew": "Label for the Hebrew group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-large": "Label for the large group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-logic": "Label for the logic group of math symbols\n{{Identical|Logic}}",
|
||||
"math-visualeditor-symbol-group-math-matrices": "Label for the matrices group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-modular": "Label for the modular group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-operators": "Label for the operators group of math symbols\n{{Identical|Operator}}",
|
||||
"math-visualeditor-symbol-group-math-parentheses": "Label for the parentheses group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-projections": "Label for the projections group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-relations": "Label for the relations group of math symbols\n{{Identical|Relation}}",
|
||||
"math-visualeditor-symbol-group-math-root": "Label for the root group of math symbols\nIdentifies math radicals.",
|
||||
"math-visualeditor-symbol-group-math-sets": "Label for the sets group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-spacing": "Label for the spacing group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-special": "Label for the special group of math symbols\n{{Identical|Special}}",
|
||||
"math-visualeditor-symbol-group-math-subscripts": "Label for the subscripts group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-symbols": "Label for the symbols group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-typefaces": "Label for the typefaces group of math symbols",
|
||||
"math-visualeditor-symbol-group-math-unsorted": "Label for the unsorted group of math symbols",
|
||||
"math_bad_output": "Used as error message.\n\nThis message follows the message {{msg-mw|Math failure}}.",
|
||||
"math_bad_tmpdir": "Used as error message.\n\nThis message follows the message {{msg-mw|Math failure}}.",
|
||||
"math_failure": "Used as error message.\n\nThis message is followed by \"(\", Error message(*1), Additional message, \"): \" and Source code.\n\n(*1) The error message is any one of the following messages:\n* {{msg-mw|Math unknown error}}\n* {{msg-mw|Math unknown function}}\n* {{msg-mw|Math lexing error}}\n* {{msg-mw|Math syntax error}}\n* {{msg-mw|Math image error}}\n* {{msg-mw|Math bad tmpdir}}\n* {{msg-mw|Math bad output}}\n* {{msg-mw|Math notexvc}}\n* {{msg-mw|Math notexvccheck}}\n* {{msg-mw|Math output error}}\n* {{msg-mw|Math timeout}}\n* {{msg-mw|Math invalidresponse}}\n* {{msg-mw|Math invalidxml}}\n* {{msg-mw|Math invalidjson}}",
|
||||
|
|
228
modules/ve-math/chemSymbols.json
Normal file
228
modules/ve-math/chemSymbols.json
Normal file
|
@ -0,0 +1,228 @@
|
|||
{
|
||||
"math-visualeditor-symbol-group-chem-equations": [
|
||||
{
|
||||
"insert": "CO2 + C -> 2 CO",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "Hg^2+ ->[I-] HgI2 ->[I-] {[Hg^{II}I4]^2-}",
|
||||
"largeLayout": true,
|
||||
"width": "wide",
|
||||
"contain": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-formulae": [
|
||||
{
|
||||
"insert": "H2O",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "Sb2O3",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-charges": [
|
||||
{
|
||||
"insert": "H+",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "CrO4^2-",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "[AgCl2]-",
|
||||
"width": "wide",
|
||||
"contain": true
|
||||
},
|
||||
{
|
||||
"insert": "Y^99+",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "Y^{99+}",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-oxidation": [
|
||||
{
|
||||
"insert": "Fe^{II}Fe^{III}204",
|
||||
"width": "wider"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-stoichiometric": [
|
||||
{
|
||||
"insert": "2H2O",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "1/2H2O",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "(1/2)H2O",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "nH2O",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-isotopes": [
|
||||
{
|
||||
"insert": "^{227}_{90}Th+",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "^227_90Th+",
|
||||
"width": "widest"
|
||||
},
|
||||
{
|
||||
"insert": "^{0}_{-1}n^{-}",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-brackets": [
|
||||
{
|
||||
"insert": "(NH4)2S",
|
||||
"width": "wider"
|
||||
},
|
||||
{
|
||||
"insert": "[\\{(X2)3\\}2]^3+",
|
||||
"width": "widest",
|
||||
"contain": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-aggregation": [
|
||||
{
|
||||
"insert": "H2(aq)",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "CO3^2-{}_{(aq)}",
|
||||
"width": "wider"
|
||||
},
|
||||
{
|
||||
"insert": "NaOH(aq,\\infty)",
|
||||
"width": "widest",
|
||||
"contain": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-dots": [
|
||||
{
|
||||
"insert": "OCO^{.-}",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "NO^{(2.)-}",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-greek": [
|
||||
{
|
||||
"insert": "\\mu-Cl",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "[Pt(\\eta^2-C2H4)Cl3]-",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-addition": [
|
||||
{
|
||||
"insert": "KCr(SO4)2*12H2O",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "KCr(SO4)2.12H2O",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "KCr(SO4)2 * 12 H2O",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-arrows": [
|
||||
{
|
||||
"insert": "A -> B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A <- B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A <-> B",
|
||||
"width": "wide",
|
||||
"contain": true
|
||||
},
|
||||
{
|
||||
"insert": "A <--> B",
|
||||
"width": "widest",
|
||||
"contain": true
|
||||
},
|
||||
{
|
||||
"insert": "A <=> B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A <=>> B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A <<=> B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A ->[H2O] B",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A ->[{text above}][{text below}] B",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A ->[x][x_i] B",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A ->[{x}] B",
|
||||
"largeLayout": true,
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-operators": [
|
||||
{
|
||||
"insert": "A + B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A - B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A = B",
|
||||
"width": "wide"
|
||||
},
|
||||
{
|
||||
"insert": "A \\pm B",
|
||||
"width": "wide"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-chem-precipitate": [
|
||||
{
|
||||
"insert": "SO4^2- + Ba^2+ -> BaSO4 v",
|
||||
"largeLayout": true,
|
||||
"width": "wide",
|
||||
"contain": true
|
||||
}
|
||||
]
|
||||
}
|
|
@ -1,5 +1,5 @@
|
|||
{
|
||||
"math-visualeditor-symbol-group-accents": [
|
||||
"math-visualeditor-symbol-group-math-accents": [
|
||||
{
|
||||
"tex": "\\dot{a}",
|
||||
"encapsulate": {
|
||||
|
@ -100,7 +100,7 @@
|
|||
"alignBaseline": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-functions": [
|
||||
"math-visualeditor-symbol-group-math-functions": [
|
||||
{
|
||||
"insert": "\\exp",
|
||||
"alignBaseline": true
|
||||
|
@ -277,7 +277,7 @@
|
|||
"alignBaseline": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-bounds": [
|
||||
"math-visualeditor-symbol-group-math-bounds": [
|
||||
{
|
||||
"insert": "\\min",
|
||||
"alignBaseline": true
|
||||
|
@ -325,7 +325,7 @@
|
|||
"alignBaseline": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-projections": [
|
||||
"math-visualeditor-symbol-group-math-projections": [
|
||||
{
|
||||
"insert": "\\Pr",
|
||||
"alignBaseline": true
|
||||
|
@ -349,7 +349,7 @@
|
|||
"alignBaseline": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-derivatives": [
|
||||
"math-visualeditor-symbol-group-math-derivatives": [
|
||||
{
|
||||
"insert": "dt"
|
||||
},
|
||||
|
@ -413,7 +413,7 @@
|
|||
"insert": "\\ddot y"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-symbols": [
|
||||
"math-visualeditor-symbol-group-math-symbols": [
|
||||
{
|
||||
"insert": "\\infty"
|
||||
},
|
||||
|
@ -463,7 +463,7 @@
|
|||
"insert": "\\circledS"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-modular": [
|
||||
"math-visualeditor-symbol-group-math-modular": [
|
||||
{
|
||||
"width": "widest",
|
||||
"tex": "\\pmod{m}",
|
||||
|
@ -517,7 +517,7 @@
|
|||
"insert": "\\nshortmid"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-root": [
|
||||
"math-visualeditor-symbol-group-math-root": [
|
||||
{
|
||||
"insert": "\\surd"
|
||||
},
|
||||
|
@ -538,7 +538,7 @@
|
|||
}
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-operators": [
|
||||
"math-visualeditor-symbol-group-math-operators": [
|
||||
{
|
||||
"insert": "+"
|
||||
},
|
||||
|
@ -634,7 +634,7 @@
|
|||
"insert": "\\bigodot"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-sets": [
|
||||
"math-visualeditor-symbol-group-math-sets": [
|
||||
{
|
||||
"insert": "\\{"
|
||||
},
|
||||
|
@ -786,7 +786,7 @@
|
|||
"insert": "\\varsupsetneqq"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-relations": [
|
||||
"math-visualeditor-symbol-group-math-relations": [
|
||||
{
|
||||
"insert": "="
|
||||
},
|
||||
|
@ -1079,7 +1079,7 @@
|
|||
"insert": "\\succnapprox"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-geometry": [
|
||||
"math-visualeditor-symbol-group-math-geometry": [
|
||||
{
|
||||
"insert": "\\parallel"
|
||||
},
|
||||
|
@ -1161,7 +1161,7 @@
|
|||
"insert": "\\blacktriangleright"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-logic": [
|
||||
"math-visualeditor-symbol-group-math-logic": [
|
||||
{
|
||||
"insert": "\\forall"
|
||||
},
|
||||
|
@ -1257,7 +1257,7 @@
|
|||
"insert": "\\lrcorner"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-arrows": [
|
||||
"math-visualeditor-symbol-group-math-arrows": [
|
||||
{
|
||||
"insert": "\\Rrightarrow"
|
||||
},
|
||||
|
@ -1470,7 +1470,7 @@
|
|||
"insert": "\\twoheadleftarrow"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-special": [
|
||||
"math-visualeditor-symbol-group-math-special": [
|
||||
{
|
||||
"insert": "\\amalg"
|
||||
},
|
||||
|
@ -1536,7 +1536,7 @@
|
|||
"insert": "\\sharp"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-unsorted": [
|
||||
"math-visualeditor-symbol-group-math-unsorted": [
|
||||
{
|
||||
"insert": "\\diagup"
|
||||
},
|
||||
|
@ -1625,7 +1625,7 @@
|
|||
"insert": "\\ntrianglerighteq"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-greek": [
|
||||
"math-visualeditor-symbol-group-math-greek": [
|
||||
{
|
||||
"insert": "\\alpha",
|
||||
"alignBaseline": true
|
||||
|
@ -1820,7 +1820,7 @@
|
|||
"alignBaseline": true
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-hebrew": [
|
||||
"math-visualeditor-symbol-group-math-hebrew": [
|
||||
{
|
||||
"insert": "\\aleph"
|
||||
},
|
||||
|
@ -1834,7 +1834,7 @@
|
|||
"insert": "\\daleth"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-typefaces": [
|
||||
"math-visualeditor-symbol-group-math-typefaces": [
|
||||
{
|
||||
"tex": "\\mathit{1}",
|
||||
"encapsulate": {
|
||||
|
@ -1908,7 +1908,7 @@
|
|||
}
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-spacing": [
|
||||
"math-visualeditor-symbol-group-math-spacing": [
|
||||
{
|
||||
"width": "wider",
|
||||
"tex": "a \\qquad b",
|
||||
|
@ -1952,7 +1952,7 @@
|
|||
}
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-parentheses": [
|
||||
"math-visualeditor-symbol-group-math-parentheses": [
|
||||
{
|
||||
"contain": true,
|
||||
"tex": "\\left ( \\frac{1}{2} \\right )",
|
||||
|
@ -2134,7 +2134,7 @@
|
|||
"insert": "\\rceil"
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-matrices": [
|
||||
"math-visualeditor-symbol-group-math-matrices": [
|
||||
{
|
||||
"contain": true,
|
||||
"tex": "\\frac{2}{4}",
|
||||
|
@ -2239,7 +2239,7 @@
|
|||
}
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-subscripts": [
|
||||
"math-visualeditor-symbol-group-math-subscripts": [
|
||||
{
|
||||
"tex": "a^2",
|
||||
"encapsulate": {
|
||||
|
@ -2640,7 +2640,7 @@
|
|||
}
|
||||
}
|
||||
],
|
||||
"math-visualeditor-symbol-group-large": [
|
||||
"math-visualeditor-symbol-group-math-large": [
|
||||
{
|
||||
"insert": "f(n) = \\begin{cases} n/2, & \\text{if }n\\text{ is even} \\\\ 3n+1, & \\text{if }n\\text{ is odd} \\end{cases}",
|
||||
"largeLayout": true,
|
|
@ -4,210 +4,213 @@
|
|||
/* eslint-disable no-console, no-use-before-define */
|
||||
|
||||
( function () {
|
||||
var i, count, currentClassName, group, symbol, symbols, symbolObject,
|
||||
symbolsData, cssData, cssLines, alignBaseline,
|
||||
unmodifiedClasses = {},
|
||||
cssRules = [], // Whole CSS rules
|
||||
cssClasses = {}, // Unique part of class name and whether baseline is shifted
|
||||
currentRule = [],
|
||||
symbolList = [], // Symbols whose CSS rules need to be added or adjusted
|
||||
symbolsFile = '../symbols.json',
|
||||
cssFile = '../ve.ui.MWMathSymbols.css',
|
||||
cssPrefix = '.ve-ui-mwMathSymbol-',
|
||||
fs = require( 'fs' ),
|
||||
http = require( 'http' ),
|
||||
querystring = require( 'querystring' ),
|
||||
mathoidMaxConnections = 20,
|
||||
// If symbol.alignBaseline is true, a background-position property will be added to the
|
||||
// CSS rule to shift the baseline of the SVG to be a certain proportion of the way up the
|
||||
// button.
|
||||
singleButtonHeight = 1.8, // Height of the single-height math dialog buttons in em
|
||||
baseline = 0.65; // Proportion of the way down the button the baseline should be
|
||||
function generateCSS( symbolsFile, cssFile, inputType ) {
|
||||
var i, count, currentClassName, group, symbol, symbols, symbolObject,
|
||||
symbolsData, cssData, cssLines, alignBaseline,
|
||||
unmodifiedClasses = {},
|
||||
cssRules = [], // Whole CSS rules
|
||||
cssClasses = {}, // Unique part of class name and whether baseline is shifted
|
||||
currentRule = [],
|
||||
symbolList = [], // Symbols whose CSS rules need to be added or adjusted
|
||||
cssPrefix = '.ve-ui-mwLatexSymbol-',
|
||||
fs = require( 'fs' ),
|
||||
http = require( 'http' ),
|
||||
querystring = require( 'querystring' ),
|
||||
mathoidMaxConnections = 20,
|
||||
// If symbol.alignBaseline is true, a background-position property will be added to the
|
||||
// CSS rule to shift the baseline of the SVG to be a certain proportion of the way up the
|
||||
// button.
|
||||
singleButtonHeight = 1.8, // Height of the single-height math dialog buttons in em
|
||||
baseline = 0.65; // Proportion of the way down the button the baseline should be
|
||||
|
||||
symbolsData = fs.readFileSync( symbolsFile ).toString();
|
||||
try {
|
||||
cssData = fs.readFileSync( cssFile ).toString();
|
||||
} catch ( e ) {}
|
||||
symbolsData = fs.readFileSync( symbolsFile ).toString();
|
||||
try {
|
||||
cssData = fs.readFileSync( cssFile ).toString();
|
||||
} catch ( e ) {}
|
||||
|
||||
function encodeURIComponentForCSS( str ) {
|
||||
return encodeURIComponent( str )
|
||||
.replace( /[!'\(\)\*]/g, function ( chr ) {
|
||||
return '%' + chr.charCodeAt( 0 ).toString( 16 );
|
||||
function encodeURIComponentForCSS( str ) {
|
||||
return encodeURIComponent( str )
|
||||
.replace( /[!'\(\)\*]/g, function ( chr ) {
|
||||
return '%' + chr.charCodeAt( 0 ).toString( 16 );
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the className, replacing any non-alphanumerics with their character code
|
||||
*
|
||||
* The reverse of function would look like this, although we have no use for it yet:
|
||||
*
|
||||
* return className.replace( /_([0-9]+)_/g, function () {
|
||||
* return String.fromCharCode( +arguments[ 1 ] );
|
||||
* } );
|
||||
*
|
||||
* @param {string} tex TeX input
|
||||
* @return {string} Class name
|
||||
*/
|
||||
function texToClass( tex ) {
|
||||
return tex.replace( /[^\w]/g, function ( c ) {
|
||||
return '_' + c.charCodeAt( 0 ) + '_';
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make the className, replacing any non-alphanumerics with their character code
|
||||
*
|
||||
* The reverse of function would look like this, although we have no use for it yet:
|
||||
*
|
||||
* return className.replace( /_([0-9]+)_/g, function () {
|
||||
* return String.fromCharCode( +arguments[ 1 ] );
|
||||
* } );
|
||||
*
|
||||
* @param {string} tex TeX input
|
||||
* @return {string} Class name
|
||||
*/
|
||||
function texToClass( tex ) {
|
||||
return tex.replace( /[^\w]/g, function ( c ) {
|
||||
return '_' + c.charCodeAt( 0 ) + '_';
|
||||
} );
|
||||
}
|
||||
function makeRequest( symbol ) {
|
||||
var request,
|
||||
tex = symbol.tex || symbol.insert,
|
||||
data = querystring.stringify( {
|
||||
q: inputType === 'chem' ? '\\ce{' + tex + '}' : tex,
|
||||
type: inputType
|
||||
} ),
|
||||
// API call to mathoid
|
||||
options = {
|
||||
host: 'localhost',
|
||||
port: '10044',
|
||||
path: '/',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Length': Buffer.byteLength( data )
|
||||
}
|
||||
};
|
||||
// Populate and make the API call
|
||||
request = http.request( options, function ( res ) {
|
||||
var body = '';
|
||||
res.setEncoding( 'utf8' );
|
||||
|
||||
function makeRequest( symbol ) {
|
||||
var request,
|
||||
tex = symbol.tex || symbol.insert,
|
||||
data = querystring.stringify( {
|
||||
q: tex
|
||||
} ),
|
||||
// API call to mathoid
|
||||
options = {
|
||||
host: 'mathoid.testme.wmflabs.org',
|
||||
port: '80',
|
||||
path: '/',
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/x-www-form-urlencoded',
|
||||
'Content-Length': Buffer.byteLength( data )
|
||||
}
|
||||
};
|
||||
// Populate and make the API call
|
||||
request = http.request( options, function ( res ) {
|
||||
var body = '';
|
||||
res.setEncoding( 'utf8' );
|
||||
res.on( 'data', function ( data ) {
|
||||
body += data;
|
||||
} );
|
||||
|
||||
res.on( 'data', function ( data ) {
|
||||
body += data;
|
||||
} );
|
||||
res.on( 'end', function () {
|
||||
var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset,
|
||||
className = texToClass( tex ),
|
||||
data = JSON.parse( body ),
|
||||
svg = data.svg;
|
||||
|
||||
res.on( 'end', function () {
|
||||
var cssRule, buttonHeight, height, verticalAlign, heightDifference, offset,
|
||||
className = texToClass( tex ),
|
||||
data = JSON.parse( body ),
|
||||
svg = data.svg;
|
||||
if ( !svg ) {
|
||||
console.log( tex + ' FAILED: ' + body );
|
||||
onEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !svg ) {
|
||||
console.log( tex + ' FAILED: ' + body );
|
||||
cssRule = cssPrefix + className + ' {\n' +
|
||||
'\tbackground-image: url( data:image/svg+xml,' + encodeURIComponentForCSS( svg ) + ' );\n';
|
||||
|
||||
if ( symbol.alignBaseline ) {
|
||||
// Convert buttonHeight from em to ex, because SVG height is given in ex. (This is an
|
||||
// approximation, since the em:ex ratio differs from font to font.)
|
||||
buttonHeight = symbol.largeLayout ? singleButtonHeight * 4 : singleButtonHeight * 1.9931;
|
||||
// height and verticalAlign rely on the format of the SVG parameters
|
||||
// HACK: Adjust these by a factor of 0.8 to match VE's default font size of 0.8em
|
||||
height = parseFloat( data.mathoidStyle.match( /height\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
|
||||
verticalAlign = -parseFloat( data.mathoidStyle.match( /vertical-align\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
|
||||
// CSS percentage positioning is based on the difference between the image and container sizes
|
||||
heightDifference = buttonHeight - height;
|
||||
offset = 100 * ( verticalAlign - height + ( baseline * buttonHeight ) ) / heightDifference;
|
||||
|
||||
cssRule += '\tbackground-position: 50% ' + offset + '%;\n' +
|
||||
'}';
|
||||
cssRules.push( cssRule );
|
||||
console.log( tex + ' -> ' + className );
|
||||
} else {
|
||||
cssRule += '}';
|
||||
cssRules.push( cssRule );
|
||||
console.log( tex + ' -> ' + className );
|
||||
}
|
||||
onEnd();
|
||||
return;
|
||||
}
|
||||
|
||||
cssRule = cssPrefix + className + ' {\n' +
|
||||
'\tbackground-image: url( data:image/svg+xml,' + encodeURIComponentForCSS( svg ) + ' );\n';
|
||||
|
||||
if ( symbol.alignBaseline ) {
|
||||
// Convert buttonHeight from em to ex, because SVG height is given in ex. (This is an
|
||||
// approximation, since the em:ex ratio differs from font to font.)
|
||||
buttonHeight = symbol.largeLayout ? singleButtonHeight * 4 : singleButtonHeight * 1.9931;
|
||||
// height and verticalAlign rely on the format of the SVG parameters
|
||||
// HACK: Adjust these by a factor of 0.8 to match VE's default font size of 0.8em
|
||||
height = parseFloat( data.mathoidStyle.match( /height\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
|
||||
verticalAlign = -parseFloat( data.mathoidStyle.match( /vertical-align\:\s*(.*)ex/ )[ 1 ] ) * 0.8;
|
||||
// CSS percentage positioning is based on the difference between the image and container sizes
|
||||
heightDifference = buttonHeight - height;
|
||||
offset = 100 * ( verticalAlign - height + ( baseline * buttonHeight ) ) / heightDifference;
|
||||
|
||||
cssRule += '\tbackground-position: 50% ' + offset + '%;\n' +
|
||||
'}';
|
||||
cssRules.push( cssRule );
|
||||
console.log( tex + ' -> ' + className );
|
||||
} else {
|
||||
cssRule += '}';
|
||||
cssRules.push( cssRule );
|
||||
console.log( tex + ' -> ' + className );
|
||||
}
|
||||
onEnd();
|
||||
|
||||
} );
|
||||
} );
|
||||
request.setTimeout( 10000 );
|
||||
request.write( data );
|
||||
request.end();
|
||||
runNext();
|
||||
}
|
||||
|
||||
function onEnd() {
|
||||
count--;
|
||||
runNext();
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
if ( count < mathoidMaxConnections && symbolList.length ) {
|
||||
count++;
|
||||
makeRequest( symbolList.shift() );
|
||||
}
|
||||
if ( !symbolList.length && !count ) {
|
||||
cssRules.sort();
|
||||
fs.writeFileSync(
|
||||
cssFile,
|
||||
'/*!\n' +
|
||||
' * This file is GENERATED by tools/makeSvgsAndCss.js\n' +
|
||||
' * DO NOT EDIT\n' +
|
||||
' */\n' +
|
||||
'\n' +
|
||||
cssRules.join( '\n\n' ) +
|
||||
'\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( cssData ) {
|
||||
cssLines = cssData.split( '\n' );
|
||||
for ( i = 0; i < cssLines.length; i++ ) {
|
||||
if ( cssLines[ i ].indexOf( cssPrefix ) === 0 ) {
|
||||
currentClassName = cssLines[ i ].slice( cssPrefix.length, -2 );
|
||||
currentRule.push( cssLines[ i ] );
|
||||
cssClasses[ currentClassName ] = false; // Default to false
|
||||
} else if ( currentRule.length ) {
|
||||
currentRule.push( cssLines[ i ] );
|
||||
if ( cssLines[ i ].indexOf( '\tbackground-position' ) === 0 ) {
|
||||
cssClasses[ currentClassName ] = true;
|
||||
}
|
||||
if ( cssLines[ i ].indexOf( '}' ) === 0 ) {
|
||||
cssRules.push( currentRule.join( '\n' ) );
|
||||
currentRule.splice( 0, currentRule.length );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
symbolObject = JSON.parse( symbolsData );
|
||||
for ( group in symbolObject ) {
|
||||
symbols = symbolObject[ group ];
|
||||
for ( i = 0; i < symbols.length; i++ ) {
|
||||
symbol = symbols[ i ];
|
||||
if ( symbol.duplicate || symbol.notWorking ) {
|
||||
continue;
|
||||
}
|
||||
currentClassName = texToClass( symbol.tex || symbol.insert );
|
||||
alignBaseline = !symbol.alignBaseline;
|
||||
// If symbol is not in the old CSS file, or its alignBaseline status has changed,
|
||||
// add it to symbolList. Check to make sure it hasn't already been added.
|
||||
if ( cssClasses[ currentClassName ] === undefined ||
|
||||
( unmodifiedClasses[ currentClassName ] !== true &&
|
||||
cssClasses[ currentClassName ] === alignBaseline ) ) {
|
||||
symbolList.push( symbol );
|
||||
} else {
|
||||
// At the end of this loop, any CSS class names that aren't in unmodifiedClasses
|
||||
// will be deleted from cssRules. cssRules will then only contain rules that will
|
||||
// stay unmodified.
|
||||
unmodifiedClasses[ currentClassName ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep only classes that will stay the same. Remove classes that are being adjusted and
|
||||
// classes of symbols that have been deleted from the JSON.
|
||||
cssRules = cssRules.filter( function ( rule ) {
|
||||
currentClassName = rule.split( '\n' )[ 0 ].slice( cssPrefix.length, -2 );
|
||||
if ( unmodifiedClasses[ currentClassName ] ) {
|
||||
return true;
|
||||
}
|
||||
console.log( 'Removing or adjusting: ' + currentClassName );
|
||||
return false;
|
||||
} );
|
||||
request.setTimeout( 10000 );
|
||||
request.write( data );
|
||||
request.end();
|
||||
|
||||
count = 0;
|
||||
runNext();
|
||||
}
|
||||
|
||||
function onEnd() {
|
||||
count--;
|
||||
runNext();
|
||||
}
|
||||
|
||||
function runNext() {
|
||||
if ( count < mathoidMaxConnections && symbolList.length ) {
|
||||
count++;
|
||||
makeRequest( symbolList.shift() );
|
||||
}
|
||||
if ( !symbolList.length && !count ) {
|
||||
cssRules.sort();
|
||||
fs.writeFileSync(
|
||||
cssFile,
|
||||
'/*!\n' +
|
||||
' * This file is GENERATED by tools/makeSvgsAndCss.js\n' +
|
||||
' * DO NOT EDIT\n' +
|
||||
' */\n' +
|
||||
'\n' +
|
||||
cssRules.join( '\n\n' ) +
|
||||
'\n'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if ( cssData ) {
|
||||
cssLines = cssData.split( '\n' );
|
||||
for ( i = 0; i < cssLines.length; i++ ) {
|
||||
if ( cssLines[ i ].indexOf( cssPrefix ) === 0 ) {
|
||||
currentClassName = cssLines[ i ].slice( cssPrefix.length, -2 );
|
||||
currentRule.push( cssLines[ i ] );
|
||||
cssClasses[ currentClassName ] = false; // Default to false
|
||||
} else if ( currentRule.length ) {
|
||||
currentRule.push( cssLines[ i ] );
|
||||
if ( cssLines[ i ].indexOf( '\tbackground-position' ) === 0 ) {
|
||||
cssClasses[ currentClassName ] = true;
|
||||
}
|
||||
if ( cssLines[ i ].indexOf( '}' ) === 0 ) {
|
||||
cssRules.push( currentRule.join( '\n' ) );
|
||||
currentRule.splice( 0, currentRule.length );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
symbolObject = JSON.parse( symbolsData );
|
||||
for ( group in symbolObject ) {
|
||||
symbols = symbolObject[ group ];
|
||||
for ( i = 0; i < symbols.length; i++ ) {
|
||||
symbol = symbols[ i ];
|
||||
if ( symbol.duplicate || symbol.notWorking ) {
|
||||
continue;
|
||||
}
|
||||
currentClassName = texToClass( symbol.tex || symbol.insert );
|
||||
alignBaseline = !symbol.alignBaseline;
|
||||
// If symbol is not in the old CSS file, or its alignBaseline status has changed,
|
||||
// add it to symbolList. Check to make sure it hasn't already been added.
|
||||
if ( cssClasses[ currentClassName ] === undefined ||
|
||||
( unmodifiedClasses[ currentClassName ] !== true &&
|
||||
cssClasses[ currentClassName ] === alignBaseline ) ) {
|
||||
symbolList.push( symbol );
|
||||
} else {
|
||||
// At the end of this loop, any CSS class names that aren't in unmodifiedClasses
|
||||
// will be deleted from cssRules. cssRules will then only contain rules that will
|
||||
// stay unmodified.
|
||||
unmodifiedClasses[ currentClassName ] = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Keep only classes that will stay the same. Remove classes that are being adjusted and
|
||||
// classes of symbols that have been deleted from the JSON.
|
||||
cssRules = cssRules.filter( function ( rule ) {
|
||||
currentClassName = rule.split( '\n' )[ 0 ].slice( cssPrefix.length, -2 );
|
||||
if ( unmodifiedClasses[ currentClassName ] ) {
|
||||
return true;
|
||||
}
|
||||
console.log( 'Removing or adjusting: ' + currentClassName );
|
||||
return false;
|
||||
} );
|
||||
|
||||
count = 0;
|
||||
runNext();
|
||||
|
||||
generateCSS( '../mathSymbols.json', '../ve.ui.MWMathSymbols.css', 'tex' );
|
||||
generateCSS( '../chemSymbols.json', '../ve.ui.MWChemSymbols.css', 'chem' );
|
||||
}() );
|
||||
|
|
35
modules/ve-math/ve.ce.MWChemNode.js
Normal file
35
modules/ve-math/ve.ce.MWChemNode.js
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*!
|
||||
* VisualEditor ContentEditable MWChemNode class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* ContentEditable MediaWiki chem node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ce.MWInlineExtensionNode
|
||||
*
|
||||
* @constructor
|
||||
* @param {ve.dm.MWChemNode} model Model to observe
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ce.MWChemNode = function VeCeMWChemNode() {
|
||||
// Parent constructor
|
||||
ve.ce.MWChemNode.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ce.MWChemNode, ve.ce.MWLatexNode );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ce.MWChemNode.static.name = 'mwChem';
|
||||
|
||||
ve.ce.MWChemNode.static.primaryCommandName = 'chemDialog';
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ce.nodeFactory.register( ve.ce.MWChemNode );
|
|
@ -4,7 +4,7 @@
|
|||
* See http://browserhacks.com
|
||||
*/
|
||||
@media screen and ( -webkit-min-device-pixel-ratio: 0 ) { /* stylelint-disable-line media-feature-name-no-vendor-prefix */
|
||||
.ve-ce-mwMathNode .mwe-math-mathml-a11y {
|
||||
.ve-ce-mwLatexNode .mwe-math-mathml-a11y {
|
||||
display: none !important; /* stylelint-disable-line declaration-no-important */
|
||||
}
|
||||
}
|
49
modules/ve-math/ve.ce.MWLatexNode.js
Normal file
49
modules/ve-math/ve.ce.MWLatexNode.js
Normal file
|
@ -0,0 +1,49 @@
|
|||
/*!
|
||||
* VisualEditor ContentEditable MWLatexNode class.
|
||||
*
|
||||
* An abstract class that has most of the common functionality
|
||||
* for the different tags in the Math extension.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* ContentEditable MediaWiki abstract LaTeX node: <math>, <chem>, etc.
|
||||
*
|
||||
* @abstract
|
||||
* @class
|
||||
* @extends ve.ce.MWInlineExtensionNode
|
||||
*
|
||||
* @constructor
|
||||
* @param {ve.dm.MWLatexNode} model Model to observe
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ce.MWLatexNode = function VeCeMWLatexNode() {
|
||||
// Parent constructor
|
||||
ve.ce.MWLatexNode.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ce.MWLatexNode, ve.ce.MWInlineExtensionNode );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ce.MWLatexNode.prototype.onSetup = function () {
|
||||
// Parent method
|
||||
ve.ce.MWLatexNode.super.prototype.onSetup.call( this );
|
||||
|
||||
// DOM changes
|
||||
this.$element.addClass( 've-ce-mwLatexNode' );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc ve.ce.GeneratedContentNode
|
||||
*/
|
||||
ve.ce.MWLatexNode.prototype.validateGeneratedContents = function ( $element ) {
|
||||
return !( $element.find( '.error' ).addBack( '.error' ).length );
|
||||
};
|
|
@ -22,7 +22,7 @@ ve.ce.MWMathNode = function VeCeMWMathNode() {
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ce.MWMathNode, ve.ce.MWInlineExtensionNode );
|
||||
OO.inheritClass( ve.ce.MWMathNode, ve.ce.MWLatexNode );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
|
@ -30,26 +30,6 @@ ve.ce.MWMathNode.static.name = 'mwMath';
|
|||
|
||||
ve.ce.MWMathNode.static.primaryCommandName = 'mathDialog';
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ce.MWMathNode.prototype.onSetup = function () {
|
||||
// Parent method
|
||||
ve.ce.MWMathNode.super.prototype.onSetup.call( this );
|
||||
|
||||
// DOM changes
|
||||
this.$element.addClass( 've-ce-mwMathNode' );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc ve.ce.GeneratedContentNode
|
||||
*/
|
||||
ve.ce.MWMathNode.prototype.validateGeneratedContents = function ( $element ) {
|
||||
return !( $element.find( '.error' ).addBack( '.error' ).length );
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ce.nodeFactory.register( ve.ce.MWMathNode );
|
||||
|
|
41
modules/ve-math/ve.dm.MWChemNode.js
Normal file
41
modules/ve-math/ve.dm.MWChemNode.js
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*!
|
||||
* VisualEditor DataModel MWChemNode class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* DataModel MediaWiki chem node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.dm.MWLatexNode
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [element]
|
||||
*/
|
||||
ve.dm.MWChemNode = function VeDmMWChemNode() {
|
||||
// Parent constructor
|
||||
ve.dm.MWChemNode.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.dm.MWChemNode, ve.dm.MWLatexNode );
|
||||
|
||||
/* Static members */
|
||||
|
||||
ve.dm.MWChemNode.static.name = 'mwChem';
|
||||
|
||||
ve.dm.MWChemNode.static.extensionName = 'chem';
|
||||
|
||||
ve.dm.MWChemNode.static.getMatchRdfaTypes = function () {
|
||||
return [
|
||||
'mw:Extension/chem',
|
||||
'mw:Extension/ce' // Deprecated, kept for backwards compatibility
|
||||
];
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.dm.modelRegistry.register( ve.dm.MWChemNode );
|
48
modules/ve-math/ve.dm.MWLatexNode.js
Normal file
48
modules/ve-math/ve.dm.MWLatexNode.js
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*!
|
||||
* VisualEditor DataModel MWLatexNode class.
|
||||
*
|
||||
* An abstract class that has most of the common functionality
|
||||
* for the different tags in the Math extension.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* DataModel MediaWiki abstract LaTeX node: <math>, <chem>, etc.
|
||||
*
|
||||
* @abstract
|
||||
* @class
|
||||
* @extends ve.dm.MWInlineExtensionNode
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [element]
|
||||
*/
|
||||
ve.dm.MWLatexNode = function VeDmMWLatexNode() {
|
||||
// Parent constructor
|
||||
ve.dm.MWLatexNode.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.dm.MWLatexNode, ve.dm.MWInlineExtensionNode );
|
||||
|
||||
/* Static members */
|
||||
|
||||
ve.dm.MWLatexNode.static.tagName = 'img';
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc ve.dm.GeneratedContentNode
|
||||
*/
|
||||
ve.dm.MWLatexNode.static.getHashObjectForRendering = function ( dataElement ) {
|
||||
// Parent method
|
||||
var hashObject = ve.dm.MWLatexNode.super.static.getHashObjectForRendering.call( this, dataElement );
|
||||
|
||||
// The id does not affect the rendering.
|
||||
if ( hashObject.mw.attrs ) {
|
||||
delete hashObject.mw.attrs.id;
|
||||
}
|
||||
return hashObject;
|
||||
};
|
|
@ -9,7 +9,7 @@
|
|||
* DataModel MediaWiki math node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.dm.MWInlineExtensionNode
|
||||
* @extends ve.dm.MWLatexNode
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [element]
|
||||
|
@ -21,32 +21,14 @@ ve.dm.MWMathNode = function VeDmMWMathNode() {
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.dm.MWMathNode, ve.dm.MWInlineExtensionNode );
|
||||
OO.inheritClass( ve.dm.MWMathNode, ve.dm.MWLatexNode );
|
||||
|
||||
/* Static members */
|
||||
|
||||
ve.dm.MWMathNode.static.name = 'mwMath';
|
||||
|
||||
ve.dm.MWMathNode.static.tagName = 'img';
|
||||
|
||||
ve.dm.MWMathNode.static.extensionName = 'math';
|
||||
|
||||
/* Static Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc ve.dm.GeneratedContentNode
|
||||
*/
|
||||
ve.dm.MWMathNode.static.getHashObjectForRendering = function ( dataElement ) {
|
||||
// Parent method
|
||||
var hashObject = ve.dm.MWMathNode.super.static.getHashObjectForRendering.call( this, dataElement );
|
||||
|
||||
// The id does not affect the rendering.
|
||||
if ( hashObject.mw.attrs ) {
|
||||
delete hashObject.mw.attrs.id;
|
||||
}
|
||||
return hashObject;
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.dm.modelRegistry.register( ve.dm.MWMathNode );
|
||||
|
|
44
modules/ve-math/ve.ui.MWChemContextItem.js
Normal file
44
modules/ve-math/ve.ui.MWChemContextItem.js
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*!
|
||||
* VisualEditor MWChemContextItem class.
|
||||
*
|
||||
* @copyright 2015 VisualEditor Team and others; see http://ve.mit-license.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* Context item for a chem node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWLatexContextItem
|
||||
*
|
||||
* @param {ve.ui.Context} context Context item is in
|
||||
* @param {ve.dm.Model} model Model item is related to
|
||||
* @param {Object} config Configuration options
|
||||
*/
|
||||
ve.ui.MWChemContextItem = function VeUiMWChemContextItem() {
|
||||
// Parent constructor
|
||||
ve.ui.MWChemContextItem.super.apply( this, arguments );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWChemContextItem, ve.ui.MWLatexContextItem );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ui.MWChemContextItem.static.name = 'chem';
|
||||
|
||||
ve.ui.MWChemContextItem.static.icon = 'chem';
|
||||
|
||||
ve.ui.MWChemContextItem.static.label = OO.ui.deferMsg( 'math-visualeditor-mwchemdialog-title' );
|
||||
|
||||
ve.ui.MWChemContextItem.static.modelClasses = [ ve.dm.MWChemNode ];
|
||||
|
||||
ve.ui.MWChemContextItem.static.embeddable = false;
|
||||
|
||||
ve.ui.MWChemContextItem.static.commandName = 'chemDialog';
|
||||
|
||||
ve.ui.MWChemContextItem.static.inlineEditCommand = 'chemInspector';
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.contextItemFactory.register( ve.ui.MWChemContextItem );
|
42
modules/ve-math/ve.ui.MWChemDialog.js
Normal file
42
modules/ve-math/ve.ui.MWChemDialog.js
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*!
|
||||
* VisualEditor user interface MWChemDialog class.
|
||||
*
|
||||
* @copyright 2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dialog for inserting and editing chem formulas.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWExtensionPreviewDialog
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
|
||||
ve.ui.MWChemDialog = function VeUiMWChemDialog( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWChemDialog.super.call( this, config );
|
||||
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWChemDialog, ve.ui.MWLatexDialog );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
ve.ui.MWChemDialog.static.name = 'chemDialog';
|
||||
|
||||
ve.ui.MWChemDialog.static.title = OO.ui.deferMsg( 'math-visualeditor-mwchemdialog-title' );
|
||||
|
||||
ve.ui.MWChemDialog.static.modelClasses = [ ve.dm.MWChemNode ];
|
||||
|
||||
ve.ui.MWChemDialog.static.symbolsModule = 'ext.math.visualEditor.chemSymbols';
|
||||
|
||||
ve.ui.MWChemDialog.static.autocompleteWordList = [];
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWChemDialog );
|
51
modules/ve-math/ve.ui.MWChemDialogTool.js
Normal file
51
modules/ve-math/ve.ui.MWChemDialogTool.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWChemDialogTool class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* MediaWiki UserInterface chem tool.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.FragmentWindowTool
|
||||
* @constructor
|
||||
* @param {OO.ui.ToolGroup} toolGroup
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWChemDialogTool = function VeUiMWChemDialogTool( toolGroup, config ) {
|
||||
ve.ui.MWChemDialogTool.super.call( this, toolGroup, config );
|
||||
};
|
||||
OO.inheritClass( ve.ui.MWChemDialogTool, ve.ui.FragmentWindowTool );
|
||||
ve.ui.MWChemDialogTool.static.name = 'chem';
|
||||
ve.ui.MWChemDialogTool.static.group = 'object';
|
||||
ve.ui.MWChemDialogTool.static.icon = 'chem';
|
||||
ve.ui.MWChemDialogTool.static.title = OO.ui.deferMsg(
|
||||
'math-visualeditor-mwchemdialog-title' );
|
||||
ve.ui.MWChemDialogTool.static.modelClasses = [ ve.dm.MWChemNode ];
|
||||
ve.ui.MWChemDialogTool.static.commandName = 'chemDialog';
|
||||
ve.ui.toolFactory.register( ve.ui.MWChemDialogTool );
|
||||
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
'chemDialog', 'window', 'open',
|
||||
{ args: [ 'chemDialog' ], supportedSelections: [ 'linear' ] }
|
||||
)
|
||||
);
|
||||
|
||||
ve.ui.commandRegistry.register(
|
||||
new ve.ui.Command(
|
||||
'chemInspector', 'window', 'open',
|
||||
{ args: [ 'chemInspector' ], supportedSelections: [ 'linear' ] }
|
||||
)
|
||||
);
|
||||
|
||||
ve.ui.sequenceRegistry.register(
|
||||
new ve.ui.Sequence( 'wikitextChem', 'chemDialog', '<chem', 5 )
|
||||
);
|
||||
|
||||
ve.ui.commandHelpRegistry.register( 'insert', 'chemDialog', {
|
||||
sequences: [ 'wikitextChem' ],
|
||||
label: OO.ui.deferMsg( 'math-visualeditor-mwchemdialog-title' )
|
||||
} );
|
36
modules/ve-math/ve.ui.MWChemInspector.js
Normal file
36
modules/ve-math/ve.ui.MWChemInspector.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWChemInspector class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* MediaWiki chem inspector.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWLiveExtensionInspector
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWChemInspector = function VeUiMWChemInspector( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWChemInspector.super.call( this, config );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWChemInspector, ve.ui.MWLatexInspector );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
ve.ui.MWChemInspector.static.name = 'chemInspector';
|
||||
|
||||
ve.ui.MWChemInspector.static.title = OO.ui.deferMsg( 'math-visualeditor-mwchemdialog-title' );
|
||||
|
||||
ve.ui.MWChemInspector.static.modelClasses = [ ve.dm.MWChemNode ];
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWChemInspector );
|
184
modules/ve-math/ve.ui.MWChemSymbols.css
Normal file
184
modules/ve-math/ve.ui.MWChemSymbols.css
Normal file
File diff suppressed because one or more lines are too long
65
modules/ve-math/ve.ui.MWLatexContextItem.js
Normal file
65
modules/ve-math/ve.ui.MWLatexContextItem.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
/*!
|
||||
* VisualEditor MWLatexContextItem class.
|
||||
*
|
||||
* @copyright 2015 VisualEditor Team and others; see http://ve.mit-license.org
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract context item for a node of a formula provided
|
||||
* by the Math extension.
|
||||
*
|
||||
* @abstract
|
||||
* @class
|
||||
* @extends ve.ui.LinearContextItem
|
||||
*
|
||||
* @param {ve.ui.Context} context Context item is in
|
||||
* @param {ve.dm.Model} model Model item is related to
|
||||
* @param {Object} config Configuration options
|
||||
*/
|
||||
ve.ui.MWLatexContextItem = function VeUiMWLatexContextItem() {
|
||||
// Parent constructor
|
||||
ve.ui.MWLatexContextItem.super.apply( this, arguments );
|
||||
|
||||
this.quickEditButton = new OO.ui.ButtonWidget( {
|
||||
label: ve.msg( 'math-visualeditor-mwlatexcontextitem-quickedit' ),
|
||||
flags: [ 'progressive' ]
|
||||
} );
|
||||
|
||||
// Don't show quick edit button in mobile as the primary action will be quick edit
|
||||
if ( !this.context.isMobile() ) {
|
||||
this.actionButtons.addItems( [ this.quickEditButton ], 0 );
|
||||
}
|
||||
|
||||
this.quickEditButton.connect( this, { click: 'onInlineEditButtonClick' } );
|
||||
|
||||
// Initialization
|
||||
this.$element.addClass( 've-ui-mwLatexContextItem' );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWLatexContextItem, ve.ui.LinearContextItem );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
ve.ui.MWLatexContextItem.static.embeddable = false;
|
||||
|
||||
ve.ui.MWLatexContextItem.static.inlineEditCommand = null;
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Handle inline edit button click events.
|
||||
*/
|
||||
ve.ui.MWLatexContextItem.prototype.onInlineEditButtonClick = function () {
|
||||
this.context.getSurface().executeCommand( this.constructor.static.inlineEditCommand );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexContextItem.prototype.getCommand = function () {
|
||||
return this.context.getSurface().commandRegistry.lookup(
|
||||
this.context.isMobile() ? this.constructor.static.inlineEditCommand : this.constructor.static.commandName
|
||||
);
|
||||
};
|
55
modules/ve-math/ve.ui.MWLatexDialog.css
Normal file
55
modules/ve-math/ve.ui.MWLatexDialog.css
Normal file
|
@ -0,0 +1,55 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWLatexDialog styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwLatexDialog-content .oo-ui-bookletLayout-stackLayout {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-content .oo-ui-bookletLayout-stackLayout h3 {
|
||||
margin: 0 0 0.5em 0;
|
||||
color: #888;
|
||||
font-weight: normal;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-content .oo-ui-textInputWidget {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-menuLayout > .oo-ui-menuLayout-content {
|
||||
border-bottom: 1px solid #e6e6e6;
|
||||
box-shadow: 0 1px 0 0 rgba( 0, 0, 0, 0.05 ); /* stylelint-disable-line no-unsupported-browser-features */
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-menuLayout-short .oo-ui-menuLayout-menu {
|
||||
height: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-menuLayout-short .oo-ui-menuLayout-content {
|
||||
bottom: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-preview {
|
||||
text-align: center;
|
||||
line-height: 10em;
|
||||
height: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-menuLayout-short .ve-ui-mwLatexDialog-preview {
|
||||
line-height: 6em;
|
||||
height: 6em;
|
||||
}
|
||||
|
||||
/* Ensures the preview image is vertically centred */
|
||||
.ve-ui-mwLatexDialog-preview .mwe-math-fallback-image-display {
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexDialog-symbols .oo-ui-outlineOptionWidget {
|
||||
padding-left: 0.75em;
|
||||
}
|
322
modules/ve-math/ve.ui.MWLatexDialog.js
Normal file
322
modules/ve-math/ve.ui.MWLatexDialog.js
Normal file
|
@ -0,0 +1,322 @@
|
|||
/*!
|
||||
* VisualEditor user interface MWLatexDialog class.
|
||||
*
|
||||
* @copyright 2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract dialog for inserting and editing different formulas
|
||||
* provided by the Math extension.
|
||||
*
|
||||
* @abstract
|
||||
* @class
|
||||
* @extends ve.ui.MWExtensionPreviewDialog
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
|
||||
ve.ui.MWLatexDialog = function VeUiMWLatexDialog( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWLatexDialog.super.call( this, config );
|
||||
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWLatexDialog, ve.ui.MWExtensionPreviewDialog );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
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 */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.initialize = function () {
|
||||
var formulaPanel, inputField, displayField, idField, category,
|
||||
formulaCard, optionsCard,
|
||||
dialog = this;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWLatexDialog.super.prototype.initialize.call( this );
|
||||
|
||||
// Layout for the formula inserter (formula card) and options form (options card)
|
||||
this.indexLayout = new OO.ui.IndexLayout( {
|
||||
scrollable: false,
|
||||
expanded: true
|
||||
} );
|
||||
|
||||
formulaCard = new OO.ui.CardLayout( 'formula', {
|
||||
label: ve.msg( 'math-visualeditor-mwlatexdialog-card-formula' ),
|
||||
expandable: false,
|
||||
scrollable: false,
|
||||
padded: true
|
||||
} );
|
||||
optionsCard = new OO.ui.CardLayout( 'options', {
|
||||
label: ve.msg( 'math-visualeditor-mwlatexdialog-card-options' ),
|
||||
expandable: false,
|
||||
scrollable: false,
|
||||
padded: true
|
||||
} );
|
||||
|
||||
this.indexLayout.addCards( [
|
||||
formulaCard,
|
||||
optionsCard
|
||||
] );
|
||||
|
||||
// Layout for symbol picker (menu) and input and preview (content)
|
||||
this.menuLayout = new OO.ui.MenuLayout( {
|
||||
menuPosition: 'bottom',
|
||||
classes: [ 've-ui-mwLatexDialog-menuLayout' ]
|
||||
} );
|
||||
|
||||
this.previewElement.$element.addClass(
|
||||
've-ui-mwLatexDialog-preview'
|
||||
);
|
||||
|
||||
this.input = new ve.ui.MWAceEditorWidget( {
|
||||
multiline: true,
|
||||
rows: 1, // This will be recalculated later in onWindowManagerResize
|
||||
autocomplete: 'live',
|
||||
autocompleteWordList: this.constructor.static.autocompleteWordList
|
||||
} ).setLanguage( 'latex' );
|
||||
|
||||
this.input.togglePrintMargin( false );
|
||||
|
||||
this.displaySelect = new OO.ui.ButtonSelectWidget( {
|
||||
items: [
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'default',
|
||||
icon: 'math-display-default',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-default' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'inline',
|
||||
icon: 'math-display-inline',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-inline' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'block',
|
||||
icon: 'math-display-block',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-block' )
|
||||
} )
|
||||
]
|
||||
} );
|
||||
|
||||
this.idInput = new OO.ui.TextInputWidget();
|
||||
|
||||
inputField = new OO.ui.FieldLayout( this.input, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexdialog-card-formula' )
|
||||
} );
|
||||
displayField = new OO.ui.FieldLayout( this.displaySelect, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display' )
|
||||
} );
|
||||
idField = new OO.ui.FieldLayout( this.idInput, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-id' )
|
||||
} );
|
||||
|
||||
formulaPanel = new OO.ui.PanelLayout( {
|
||||
padded: true
|
||||
} );
|
||||
|
||||
// Layout for the symbol picker
|
||||
this.bookletLayout = new OO.ui.BookletLayout( {
|
||||
classes: [ 've-ui-mwLatexDialog-symbols' ],
|
||||
menuPosition: 'before',
|
||||
outlined: true,
|
||||
continuous: true
|
||||
} );
|
||||
this.pages = [];
|
||||
this.symbolsPromise = mw.loader.using( this.constructor.static.symbolsModule ).done( function () {
|
||||
var symbols = dialog.constructor.static.symbols;
|
||||
for ( category in symbols ) {
|
||||
dialog.pages.push(
|
||||
new ve.ui.MWLatexPage( ve.msg( category ), {
|
||||
label: ve.msg( category ),
|
||||
symbols: symbols[ category ]
|
||||
} )
|
||||
);
|
||||
}
|
||||
dialog.bookletLayout.addPages( dialog.pages );
|
||||
dialog.bookletLayout.$element.on(
|
||||
'click',
|
||||
'.ve-ui-mwLatexPage-symbol',
|
||||
dialog.onListClick.bind( dialog )
|
||||
);
|
||||
|
||||
// Append everything
|
||||
dialog.menuLayout.$menu.append(
|
||||
dialog.bookletLayout.$element
|
||||
);
|
||||
|
||||
dialog.menuLayout.$content.append(
|
||||
formulaPanel.$element.append(
|
||||
dialog.previewElement.$element,
|
||||
inputField.$element
|
||||
)
|
||||
);
|
||||
|
||||
formulaCard.$element.append(
|
||||
dialog.menuLayout.$element
|
||||
);
|
||||
optionsCard.$element.append(
|
||||
displayField.$element,
|
||||
idField.$element
|
||||
);
|
||||
|
||||
dialog.$body
|
||||
.addClass( 've-ui-mwLatexDialog-content' )
|
||||
.append( dialog.indexLayout.$element );
|
||||
} );
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWLatexDialog.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
var attributes = this.selectedNode && this.selectedNode.getAttribute( 'mw' ).attrs,
|
||||
display = attributes && attributes.display || 'default',
|
||||
id = attributes && attributes.id || '';
|
||||
|
||||
// Populate form
|
||||
this.displaySelect.selectItemByData( display );
|
||||
this.idInput.setValue( id );
|
||||
|
||||
// Add event handlers
|
||||
this.input.on( 'change', this.onChangeHandler );
|
||||
this.displaySelect.on( 'choose', this.onChangeHandler );
|
||||
this.idInput.on( 'change', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.getReadyProcess = function ( data ) {
|
||||
return ve.ui.MWLatexDialog.super.prototype.getReadyProcess.call( this, data )
|
||||
.next( function () {
|
||||
return this.symbolsPromise;
|
||||
}, this )
|
||||
.next( function () {
|
||||
// Resize the input once the dialog has been appended
|
||||
this.input.adjustSize( true ).focus().moveCursorToEnd();
|
||||
this.getManager().connect( this, { resize: 'onWindowManagerResize' } );
|
||||
this.onWindowManagerResize();
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWLatexDialog.super.prototype.getTeardownProcess.call( this, data )
|
||||
.first( function () {
|
||||
this.input.off( 'change', this.onChangeHandler );
|
||||
this.displaySelect.off( 'choose', this.onChangeHandler );
|
||||
this.idInput.off( 'change', this.onChangeHandler );
|
||||
this.getManager().disconnect( this );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.updateMwData = function ( mwData ) {
|
||||
var display, id;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWLatexDialog.super.prototype.updateMwData.call( this, mwData );
|
||||
|
||||
// Get data from dialog
|
||||
display = this.displaySelect.getSelectedItem().getData();
|
||||
id = this.idInput.getValue();
|
||||
|
||||
// Update attributes
|
||||
mwData.attrs.display = display !== 'default' ? display : undefined;
|
||||
mwData.attrs.id = id || undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.getBodyHeight = function () {
|
||||
return 600;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the window resize event
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.onWindowManagerResize = function () {
|
||||
var dialog = this;
|
||||
this.input.loadingPromise.done( function () {
|
||||
var availableSpace, maxInputHeight, singleLineHeight, minRows,
|
||||
border = 1,
|
||||
padding = 3,
|
||||
borderAndPadding = 2 * ( border + padding );
|
||||
|
||||
// Toggle short mode as necessary
|
||||
// NB a change of mode triggers a transition...
|
||||
dialog.menuLayout.$element.toggleClass(
|
||||
've-ui-mwLatexDialog-menuLayout-short', dialog.menuLayout.$element.height() < 450
|
||||
);
|
||||
|
||||
// ...So wait for the possible menuLayout transition to finish
|
||||
setTimeout( function () {
|
||||
// Give the input the right number of rows to fit the space
|
||||
availableSpace = dialog.menuLayout.$content.height() - dialog.input.$element.position().top;
|
||||
singleLineHeight = 19;
|
||||
maxInputHeight = availableSpace - borderAndPadding;
|
||||
minRows = Math.floor( maxInputHeight / singleLineHeight );
|
||||
dialog.input.setMinRows( minRows );
|
||||
}, OO.ui.theme.getDialogTransitionDuration() );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the click event on the list
|
||||
*
|
||||
* @param {jQuery.Event} e Mouse click event
|
||||
*/
|
||||
ve.ui.MWLatexDialog.prototype.onListClick = function ( e ) {
|
||||
var symbol = $( e.target ).data( 'symbol' ),
|
||||
encapsulate = symbol.encapsulate,
|
||||
insert = symbol.insert,
|
||||
range = this.input.getRange();
|
||||
|
||||
if ( encapsulate ) {
|
||||
if ( range.from === range.to ) {
|
||||
this.input.insertContent( encapsulate.placeholder );
|
||||
this.input.selectRange( range.from, range.from + encapsulate.placeholder.length );
|
||||
}
|
||||
this.input.encapsulateContent( encapsulate.pre, encapsulate.post );
|
||||
} else {
|
||||
this.input.insertContent( insert );
|
||||
}
|
||||
};
|
|
@ -1,5 +1,5 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface Math icon styles.
|
||||
* VisualEditor UserInterface LaTeX icon styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
|
@ -24,3 +24,8 @@
|
|||
/* @embed */
|
||||
background-image: url( math-display-inline.svg );
|
||||
}
|
||||
|
||||
.oo-ui-icon-chem {
|
||||
/* @embed */
|
||||
background-image: url( chem.svg );
|
||||
}
|
11
modules/ve-math/ve.ui.MWLatexInspector.css
Normal file
11
modules/ve-math/ve.ui.MWLatexInspector.css
Normal file
|
@ -0,0 +1,11 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWLatexInspector styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwLatexInspector-content .ve-ui-mwExtensionWindow-input textarea {
|
||||
/* Specify a valid second value to fix size in Chrome/FF */
|
||||
font-family: monospace, 'Courier';
|
||||
}
|
131
modules/ve-math/ve.ui.MWLatexInspector.js
Normal file
131
modules/ve-math/ve.ui.MWLatexInspector.js
Normal file
|
@ -0,0 +1,131 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWLatexInspector class.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* MediaWiki abstract inspector for quick editing of different formulas
|
||||
* that the Math extension provides.
|
||||
*
|
||||
* @abstract
|
||||
* @class
|
||||
* @extends ve.ui.MWLiveExtensionInspector
|
||||
*
|
||||
* @constructor
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWLatexInspector = function VeUiMWLatexInspector( config ) {
|
||||
// Parent constructor
|
||||
ve.ui.MWLatexInspector.super.call( this, config );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWLatexInspector, ve.ui.MWLiveExtensionInspector );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
ve.ui.MWLatexInspector.static.dir = 'ltr';
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexInspector.prototype.initialize = function () {
|
||||
var inputField, displayField, idField;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWLatexInspector.super.prototype.initialize.call( this );
|
||||
|
||||
this.displaySelect = new OO.ui.ButtonSelectWidget( {
|
||||
items: [
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'default',
|
||||
icon: 'math-display-default',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-default' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'inline',
|
||||
icon: 'math-display-inline',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-inline' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'block',
|
||||
icon: 'math-display-block',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display-block' )
|
||||
} )
|
||||
]
|
||||
} );
|
||||
|
||||
this.idInput = new OO.ui.TextInputWidget();
|
||||
|
||||
inputField = new OO.ui.FieldLayout( this.input, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexdialog-card-formula' )
|
||||
} );
|
||||
displayField = new OO.ui.FieldLayout( this.displaySelect, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-display' )
|
||||
} );
|
||||
idField = new OO.ui.FieldLayout( this.idInput, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwlatexinspector-id' )
|
||||
} );
|
||||
|
||||
// Initialization
|
||||
this.$content.addClass( 've-ui-mwLatexInspector-content' );
|
||||
this.form.$element.append(
|
||||
inputField.$element,
|
||||
this.generatedContentsError.$element,
|
||||
displayField.$element,
|
||||
idField.$element
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexInspector.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWLatexInspector.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
var display = this.selectedNode.getAttribute( 'mw' ).attrs.display || 'default';
|
||||
this.displaySelect.selectItemByData( display );
|
||||
this.displaySelect.on( 'choose', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexInspector.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWLatexInspector.super.prototype.getTeardownProcess.call( this, data )
|
||||
.first( function () {
|
||||
this.displaySelect.off( 'choose', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexInspector.prototype.updateMwData = function ( mwData ) {
|
||||
var display, id;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWLatexInspector.super.prototype.updateMwData.call( this, mwData );
|
||||
|
||||
display = this.displaySelect.getSelectedItem().getData();
|
||||
id = this.idInput.getValue();
|
||||
|
||||
mwData.attrs.display = display !== 'default' ? display : undefined;
|
||||
mwData.attrs.id = id || undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWLatexInspector.prototype.formatGeneratedContentsError = function ( $element ) {
|
||||
return $element.text().trim();
|
||||
};
|
|
@ -1,11 +1,11 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWMathPage styles.
|
||||
* VisualEditor UserInterface MWLatexPage styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwMathPage-symbol {
|
||||
.ve-ui-mwLatexPage-symbol {
|
||||
background-position: center;
|
||||
background-repeat: no-repeat;
|
||||
cursor: pointer;
|
||||
|
@ -24,35 +24,35 @@
|
|||
/* stylelint-enable no-unsupported-browser-features */
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-wide {
|
||||
.ve-ui-mwLatexPage-symbol:hover {
|
||||
border-color: #ccc;
|
||||
}
|
||||
|
||||
.ve-ui-mwLatexPage-symbol-wide {
|
||||
/* 2(symbol width) + margin */
|
||||
width: 3.7em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-wider {
|
||||
.ve-ui-mwLatexPage-symbol-wider {
|
||||
/* 2.5(symbol width) + 1.5(margin) */
|
||||
width: 4.65em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-widest {
|
||||
.ve-ui-mwLatexPage-symbol-widest {
|
||||
/* 3(symbol width) + 2(margin) */
|
||||
width: 5.6em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-contain {
|
||||
.ve-ui-mwLatexPage-symbol-contain {
|
||||
background-size: contain; /* stylelint-disable-line no-unsupported-browser-features */
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-largeLayout {
|
||||
.ve-ui-mwLatexPage-symbol-largeLayout {
|
||||
height: 3.7em;
|
||||
width: 4.65em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathPage-symbol-largeLayout.ve-ui-mwMathPage-symbol-wide {
|
||||
.ve-ui-mwLatexPage-symbol-largeLayout.ve-ui-mwLatexPage-symbol-wide {
|
||||
/* 5(symbol width) + 4(margin) */
|
||||
width: 9.4em;
|
||||
}
|
||||
|
||||
.ve.ui.mwMathPage-symbol:hover {
|
||||
border-color: #ccc;
|
||||
}
|
|
@ -1,12 +1,12 @@
|
|||
/*!
|
||||
* VisualEditor user interface MWMathPage class.
|
||||
* VisualEditor user interface MWLatexPage class.
|
||||
*
|
||||
* @copyright 2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
/**
|
||||
* Math dialog symbols page
|
||||
* Latex dialog symbols page
|
||||
*
|
||||
* @class
|
||||
* @extends OO.ui.PageLayout
|
||||
|
@ -15,12 +15,12 @@
|
|||
* @param {string} name Unique symbolic name of page
|
||||
* @param {Object} [config] Configuration options
|
||||
*/
|
||||
ve.ui.MWMathPage = function VeUiMWMathPage( name, config ) {
|
||||
ve.ui.MWLatexPage = function VeUiMWLatexPage( name, config ) {
|
||||
var i, ilen, j, jlen, symbol, symbols, $symbols,
|
||||
symbolNode, symbolsNode, tex, classes;
|
||||
|
||||
// Parent constructor
|
||||
ve.ui.MWMathPage.super.call( this, name, config );
|
||||
ve.ui.MWLatexPage.super.call( this, name, config );
|
||||
|
||||
this.label = config.label;
|
||||
|
||||
|
@ -33,20 +33,20 @@ ve.ui.MWMathPage = function VeUiMWMathPage( name, config ) {
|
|||
symbol = symbols[ i ];
|
||||
if ( !symbol.notWorking && !symbol.duplicate ) {
|
||||
tex = symbol.tex || symbol.insert;
|
||||
classes = [ 've-ui-mwMathPage-symbol' ];
|
||||
classes = [ 've-ui-mwLatexPage-symbol' ];
|
||||
classes.push(
|
||||
've-ui-mwMathSymbol-' + tex.replace( /[^\w]/g, function ( c ) {
|
||||
've-ui-mwLatexSymbol-' + tex.replace( /[^\w]/g, function ( c ) {
|
||||
return '_' + c.charCodeAt( 0 ) + '_';
|
||||
} )
|
||||
);
|
||||
if ( symbol.width ) {
|
||||
classes.push( 've-ui-mwMathPage-symbol-' + symbol.width );
|
||||
classes.push( 've-ui-mwLatexPage-symbol-' + symbol.width );
|
||||
}
|
||||
if ( symbol.contain ) {
|
||||
classes.push( 've-ui-mwMathPage-symbol-contain' );
|
||||
classes.push( 've-ui-mwLatexPage-symbol-contain' );
|
||||
}
|
||||
if ( symbol.largeLayout ) {
|
||||
classes.push( 've-ui-mwMathPage-symbol-largeLayout' );
|
||||
classes.push( 've-ui-mwLatexPage-symbol-largeLayout' );
|
||||
}
|
||||
symbolNode = document.createElement( 'div' );
|
||||
for ( j = 0, jlen = classes.length; j < jlen; j++ ) {
|
||||
|
@ -58,21 +58,21 @@ ve.ui.MWMathPage = function VeUiMWMathPage( name, config ) {
|
|||
}
|
||||
|
||||
this.$element
|
||||
.addClass( 've-ui-mwMathPage' )
|
||||
.addClass( 've-ui-mwLatexPage' )
|
||||
.append( $( '<h3>' ).text( name ), $symbols );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWMathPage, OO.ui.PageLayout );
|
||||
OO.inheritClass( ve.ui.MWLatexPage, OO.ui.PageLayout );
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathPage.prototype.setupOutlineItem = function ( outlineItem ) {
|
||||
ve.ui.MWMathPage.super.prototype.setupOutlineItem.call( this, outlineItem );
|
||||
ve.ui.MWLatexPage.prototype.setupOutlineItem = function ( outlineItem ) {
|
||||
ve.ui.MWLatexPage.super.prototype.setupOutlineItem.call( this, outlineItem );
|
||||
this.outlineItem.setLabel( this.label );
|
||||
this.outlineItem.$element.addClass( 've-ui-mwMathPage-outline' );
|
||||
this.outlineItem.$element.addClass( 've-ui-mwLatexPage-outline' );
|
||||
};
|
|
@ -8,7 +8,7 @@
|
|||
* Context item for a math node.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.LinearContextItem
|
||||
* @extends ve.ui.MWLatexContextItem
|
||||
*
|
||||
* @param {ve.ui.Context} context Context item is in
|
||||
* @param {ve.dm.Model} model Model item is related to
|
||||
|
@ -17,26 +17,11 @@
|
|||
ve.ui.MWMathContextItem = function VeUiMWMathContextItem() {
|
||||
// Parent constructor
|
||||
ve.ui.MWMathContextItem.super.apply( this, arguments );
|
||||
|
||||
this.quickEditButton = new OO.ui.ButtonWidget( {
|
||||
label: ve.msg( 'math-visualeditor-mwmathcontextitem-quickedit' ),
|
||||
flags: [ 'progressive' ]
|
||||
} );
|
||||
|
||||
// Don't show quick edit button in mobile as the primary action will be quick edit
|
||||
if ( !this.context.isMobile() ) {
|
||||
this.actionButtons.addItems( [ this.quickEditButton ], 0 );
|
||||
}
|
||||
|
||||
this.quickEditButton.connect( this, { click: 'onInlineEditButtonClick' } );
|
||||
|
||||
// Initialization
|
||||
this.$element.addClass( 've-ui-mwMathContextItem' );
|
||||
};
|
||||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWMathContextItem, ve.ui.LinearContextItem );
|
||||
OO.inheritClass( ve.ui.MWMathContextItem, ve.ui.MWLatexContextItem );
|
||||
|
||||
/* Static Properties */
|
||||
|
||||
|
@ -44,7 +29,7 @@ ve.ui.MWMathContextItem.static.name = 'math';
|
|||
|
||||
ve.ui.MWMathContextItem.static.icon = 'math';
|
||||
|
||||
ve.ui.MWMathContextItem.static.label = OO.ui.deferMsg( 'math-visualeditor-mwmathinspector-title' );
|
||||
ve.ui.MWMathContextItem.static.label = OO.ui.deferMsg( 'math-visualeditor-mwmathdialog-title' );
|
||||
|
||||
ve.ui.MWMathContextItem.static.modelClasses = [ ve.dm.MWMathNode ];
|
||||
|
||||
|
@ -52,23 +37,7 @@ ve.ui.MWMathContextItem.static.embeddable = false;
|
|||
|
||||
ve.ui.MWMathContextItem.static.commandName = 'mathDialog';
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* Handle inline edit button click events.
|
||||
*/
|
||||
ve.ui.MWMathContextItem.prototype.onInlineEditButtonClick = function () {
|
||||
this.context.getSurface().executeCommand( 'mathInspector' );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathContextItem.prototype.getCommand = function () {
|
||||
return this.context.getSurface().commandRegistry.lookup(
|
||||
this.context.isMobile() ? 'mathInspector' : this.constructor.static.commandName
|
||||
);
|
||||
};
|
||||
ve.ui.MWMathContextItem.static.inlineEditCommand = 'mathInspector';
|
||||
|
||||
/* Registration */
|
||||
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWMathDialog styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwMathDialog-content .oo-ui-bookletLayout-stackLayout {
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-content .oo-ui-bookletLayout-stackLayout h3 {
|
||||
margin: 0 0 0.5em 0;
|
||||
color: #888;
|
||||
font-weight: normal;
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-content .oo-ui-textInputWidget {
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-menuLayout > .oo-ui-menuLayout-content {
|
||||
border-bottom: 1px solid #e6e6e6;
|
||||
box-shadow: 0 1px 0 0 rgba( 0, 0, 0, 0.05 ); /* stylelint-disable-line no-unsupported-browser-features */
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-menuLayout-short .oo-ui-menuLayout-menu {
|
||||
height: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-menuLayout-short .oo-ui-menuLayout-content {
|
||||
bottom: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-preview {
|
||||
text-align: center;
|
||||
line-height: 10em;
|
||||
height: 10em;
|
||||
}
|
||||
|
||||
.ve-ui-mwMathDialog-menuLayout-short .ve-ui-mwMathDialog-preview {
|
||||
line-height: 6em;
|
||||
height: 6em;
|
||||
}
|
||||
|
||||
/* Ensures the preview image is vertically centred */
|
||||
.ve-ui-mwMathDialog-preview .mwe-math-fallback-image-display {
|
||||
display: inline-block;
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
*/
|
||||
|
||||
/**
|
||||
* Dialog for inserting and editing formulas.
|
||||
* Dialog for inserting and editing math formulas.
|
||||
*
|
||||
* @class
|
||||
* @extends ve.ui.MWExtensionPreviewDialog
|
||||
|
@ -23,7 +23,7 @@ ve.ui.MWMathDialog = function VeUiMWMathDialog( config ) {
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWMathDialog, ve.ui.MWExtensionPreviewDialog );
|
||||
OO.inheritClass( ve.ui.MWMathDialog, ve.ui.MWLatexDialog );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
|
@ -31,13 +31,9 @@ ve.ui.MWMathDialog.static.name = 'mathDialog';
|
|||
|
||||
ve.ui.MWMathDialog.static.title = OO.ui.deferMsg( 'math-visualeditor-mwmathdialog-title' );
|
||||
|
||||
ve.ui.MWMathDialog.static.size = 'larger';
|
||||
|
||||
ve.ui.MWMathDialog.static.modelClasses = [ ve.dm.MWMathNode ];
|
||||
|
||||
ve.ui.MWMathDialog.static.dir = 'ltr';
|
||||
|
||||
ve.ui.MWMathDialog.static.symbols = null;
|
||||
ve.ui.MWMathDialog.static.symbolsModule = 'ext.math.visualEditor.mathSymbols';
|
||||
|
||||
ve.ui.MWMathDialog.static.autocompleteWordList = [
|
||||
'AA', 'acute', 'alef', 'alefsym', 'aleph', 'alpha', 'Alpha', 'amalg', 'And',
|
||||
|
@ -109,289 +105,6 @@ ve.ui.MWMathDialog.static.autocompleteWordList = [
|
|||
'xcancel', 'xi', 'Xi', 'xleftarrow', 'xrightarrow', 'Z', 'zeta', 'Zeta'
|
||||
];
|
||||
|
||||
/* static methods */
|
||||
|
||||
/**
|
||||
* Set the symbols property
|
||||
*
|
||||
* @param {Object} symbols The math symbols and their group names
|
||||
*/
|
||||
ve.ui.MWMathDialog.static.setSymbols = function ( symbols ) {
|
||||
this.symbols = symbols;
|
||||
};
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.initialize = function () {
|
||||
var formulaPanel, inputField, displayField, idField, category,
|
||||
formulaCard, optionsCard,
|
||||
dialog = this;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWMathDialog.super.prototype.initialize.call( this );
|
||||
|
||||
// Layout for the formula inserter (formula card) and options form (options card)
|
||||
this.indexLayout = new OO.ui.IndexLayout( {
|
||||
scrollable: false,
|
||||
expanded: true
|
||||
} );
|
||||
|
||||
formulaCard = new OO.ui.CardLayout( 'formula', {
|
||||
label: ve.msg( 'math-visualeditor-mwmathdialog-card-formula' ),
|
||||
expandable: false,
|
||||
scrollable: false,
|
||||
padded: true
|
||||
} );
|
||||
optionsCard = new OO.ui.CardLayout( 'options', {
|
||||
label: ve.msg( 'math-visualeditor-mwmathdialog-card-options' ),
|
||||
expandable: false,
|
||||
scrollable: false,
|
||||
padded: true
|
||||
} );
|
||||
|
||||
this.indexLayout.addCards( [
|
||||
formulaCard,
|
||||
optionsCard
|
||||
] );
|
||||
|
||||
// Layout for symbol picker (menu) and input and preview (content)
|
||||
this.menuLayout = new OO.ui.MenuLayout( {
|
||||
menuPosition: 'bottom',
|
||||
classes: [ 've-ui-mwMathDialog-menuLayout' ]
|
||||
} );
|
||||
|
||||
this.previewElement.$element.addClass(
|
||||
've-ui-mwMathDialog-preview'
|
||||
);
|
||||
|
||||
this.input = new ve.ui.MWAceEditorWidget( {
|
||||
multiline: true,
|
||||
rows: 1, // This will be recalculated later in onWindowManagerResize
|
||||
autocomplete: 'live',
|
||||
autocompleteWordList: ve.ui.MWMathDialog.static.autocompleteWordList
|
||||
} ).setLanguage( 'latex' );
|
||||
|
||||
this.input.togglePrintMargin( false );
|
||||
|
||||
this.displaySelect = new OO.ui.ButtonSelectWidget( {
|
||||
items: [
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'default',
|
||||
icon: 'math-display-default',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-default' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'inline',
|
||||
icon: 'math-display-inline',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-inline' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'block',
|
||||
icon: 'math-display-block',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-block' )
|
||||
} )
|
||||
]
|
||||
} );
|
||||
|
||||
this.idInput = new OO.ui.TextInputWidget();
|
||||
|
||||
inputField = new OO.ui.FieldLayout( this.input, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-title' )
|
||||
} );
|
||||
displayField = new OO.ui.FieldLayout( this.displaySelect, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display' )
|
||||
} );
|
||||
idField = new OO.ui.FieldLayout( this.idInput, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-id' )
|
||||
} );
|
||||
|
||||
formulaPanel = new OO.ui.PanelLayout( {
|
||||
padded: true
|
||||
} );
|
||||
|
||||
// Layout for the symbol picker
|
||||
this.bookletLayout = new OO.ui.BookletLayout( {
|
||||
menuPosition: 'before',
|
||||
outlined: true,
|
||||
continuous: true
|
||||
} );
|
||||
this.pages = [];
|
||||
this.symbolsPromise = mw.loader.using( 'ext.math.visualEditor.symbols' ).done( function () {
|
||||
var symbols = dialog.constructor.static.symbols;
|
||||
for ( category in symbols ) {
|
||||
dialog.pages.push(
|
||||
new ve.ui.MWMathPage( ve.msg( category ), {
|
||||
label: ve.msg( category ),
|
||||
symbols: symbols[ category ]
|
||||
} )
|
||||
);
|
||||
}
|
||||
dialog.bookletLayout.addPages( dialog.pages );
|
||||
dialog.bookletLayout.$element.on(
|
||||
'click',
|
||||
'.ve-ui-mwMathPage-symbol',
|
||||
dialog.onListClick.bind( dialog )
|
||||
);
|
||||
|
||||
// Append everything
|
||||
dialog.menuLayout.$menu.append(
|
||||
dialog.bookletLayout.$element
|
||||
);
|
||||
|
||||
dialog.menuLayout.$content.append(
|
||||
formulaPanel.$element.append(
|
||||
dialog.previewElement.$element,
|
||||
inputField.$element
|
||||
)
|
||||
);
|
||||
|
||||
formulaCard.$element.append(
|
||||
dialog.menuLayout.$element
|
||||
);
|
||||
optionsCard.$element.append(
|
||||
displayField.$element,
|
||||
idField.$element
|
||||
);
|
||||
|
||||
dialog.$body
|
||||
.addClass( 've-ui-mwMathDialog-content' )
|
||||
.append( dialog.indexLayout.$element );
|
||||
} );
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWMathDialog.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
var attributes = this.selectedNode && this.selectedNode.getAttribute( 'mw' ).attrs,
|
||||
display = attributes && attributes.display || 'default',
|
||||
id = attributes && attributes.id || '';
|
||||
|
||||
// Populate form
|
||||
this.displaySelect.selectItemByData( display );
|
||||
this.idInput.setValue( id );
|
||||
|
||||
// Add event handlers
|
||||
this.input.on( 'change', this.onChangeHandler );
|
||||
this.displaySelect.on( 'choose', this.onChangeHandler );
|
||||
this.idInput.on( 'change', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.getReadyProcess = function ( data ) {
|
||||
return ve.ui.MWMathDialog.super.prototype.getReadyProcess.call( this, data )
|
||||
.next( function () {
|
||||
return this.symbolsPromise;
|
||||
}, this )
|
||||
.next( function () {
|
||||
// Resize the input once the dialog has been appended
|
||||
this.input.adjustSize( true ).focus().moveCursorToEnd();
|
||||
this.getManager().connect( this, { resize: 'onWindowManagerResize' } );
|
||||
this.onWindowManagerResize();
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWMathDialog.super.prototype.getTeardownProcess.call( this, data )
|
||||
.first( function () {
|
||||
this.input.off( 'change', this.onChangeHandler );
|
||||
this.displaySelect.off( 'choose', this.onChangeHandler );
|
||||
this.idInput.off( 'change', this.onChangeHandler );
|
||||
this.getManager().disconnect( this );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.updateMwData = function ( mwData ) {
|
||||
var display, id;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWMathDialog.super.prototype.updateMwData.call( this, mwData );
|
||||
|
||||
// Get data from dialog
|
||||
display = this.displaySelect.getSelectedItem().getData();
|
||||
id = this.idInput.getValue();
|
||||
|
||||
// Update attributes
|
||||
mwData.attrs.display = display !== 'default' ? display : undefined;
|
||||
mwData.attrs.id = id || undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.getBodyHeight = function () {
|
||||
return 600;
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the window resize event
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.onWindowManagerResize = function () {
|
||||
var dialog = this;
|
||||
this.input.loadingPromise.done( function () {
|
||||
var availableSpace, maxInputHeight, singleLineHeight, minRows,
|
||||
border = 1,
|
||||
padding = 3,
|
||||
borderAndPadding = 2 * ( border + padding );
|
||||
|
||||
// Toggle short mode as necessary
|
||||
// NB a change of mode triggers a transition...
|
||||
dialog.menuLayout.$element.toggleClass(
|
||||
've-ui-mwMathDialog-menuLayout-short', dialog.menuLayout.$element.height() < 450
|
||||
);
|
||||
|
||||
// ...So wait for the possible menuLayout transition to finish
|
||||
setTimeout( function () {
|
||||
// Give the input the right number of rows to fit the space
|
||||
availableSpace = dialog.menuLayout.$content.height() - dialog.input.$element.position().top;
|
||||
singleLineHeight = 19;
|
||||
maxInputHeight = availableSpace - borderAndPadding;
|
||||
minRows = Math.floor( maxInputHeight / singleLineHeight );
|
||||
dialog.input.setMinRows( minRows );
|
||||
}, OO.ui.theme.getDialogTransitionDuration() );
|
||||
} );
|
||||
};
|
||||
|
||||
/**
|
||||
* Handle the click event on the list
|
||||
*
|
||||
* @param {jQuery.Event} e Mouse click event
|
||||
*/
|
||||
ve.ui.MWMathDialog.prototype.onListClick = function ( e ) {
|
||||
var symbol = $( e.target ).data( 'symbol' ),
|
||||
encapsulate = symbol.encapsulate,
|
||||
insert = symbol.insert,
|
||||
range = this.input.getRange();
|
||||
|
||||
if ( encapsulate ) {
|
||||
if ( range.from === range.to ) {
|
||||
this.input.insertContent( encapsulate.placeholder );
|
||||
this.input.selectRange( range.from, range.from + encapsulate.placeholder.length );
|
||||
}
|
||||
this.input.encapsulateContent( encapsulate.pre, encapsulate.post );
|
||||
} else {
|
||||
this.input.insertContent( insert );
|
||||
}
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWMathDialog );
|
||||
|
|
|
@ -22,7 +22,7 @@ ve.ui.MWMathDialogTool.static.name = 'math';
|
|||
ve.ui.MWMathDialogTool.static.group = 'object';
|
||||
ve.ui.MWMathDialogTool.static.icon = 'math';
|
||||
ve.ui.MWMathDialogTool.static.title = OO.ui.deferMsg(
|
||||
'math-visualeditor-mwmathinspector-title' );
|
||||
'math-visualeditor-mwmathdialog-title' );
|
||||
ve.ui.MWMathDialogTool.static.modelClasses = [ ve.dm.MWMathNode ];
|
||||
ve.ui.MWMathDialogTool.static.commandName = 'mathDialog';
|
||||
ve.ui.toolFactory.register( ve.ui.MWMathDialogTool );
|
||||
|
@ -47,5 +47,5 @@ ve.ui.sequenceRegistry.register(
|
|||
|
||||
ve.ui.commandHelpRegistry.register( 'insert', 'mathDialog', {
|
||||
sequences: [ 'wikitextMath' ],
|
||||
label: OO.ui.deferMsg( 'math-visualeditor-mwmathinspector-title' )
|
||||
label: OO.ui.deferMsg( 'math-visualeditor-mwmathdialog-title' )
|
||||
} );
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
/*!
|
||||
* VisualEditor UserInterface MWMathInspector styles.
|
||||
*
|
||||
* @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt
|
||||
* @license The MIT License (MIT); see LICENSE.txt
|
||||
*/
|
||||
|
||||
.ve-ui-mwMathInspector-content .ve-ui-mwExtensionWindow-input textarea {
|
||||
font-family: monospace, 'Courier';
|
||||
}
|
|
@ -21,119 +21,16 @@ ve.ui.MWMathInspector = function VeUiMWMathInspector( config ) {
|
|||
|
||||
/* Inheritance */
|
||||
|
||||
OO.inheritClass( ve.ui.MWMathInspector, ve.ui.MWLiveExtensionInspector );
|
||||
OO.inheritClass( ve.ui.MWMathInspector, ve.ui.MWLatexInspector );
|
||||
|
||||
/* Static properties */
|
||||
|
||||
ve.ui.MWMathInspector.static.name = 'mathInspector';
|
||||
|
||||
ve.ui.MWMathInspector.static.title = OO.ui.deferMsg( 'math-visualeditor-mwmathinspector-title' );
|
||||
ve.ui.MWMathInspector.static.title = OO.ui.deferMsg( 'math-visualeditor-mwmathdialog-title' );
|
||||
|
||||
ve.ui.MWMathInspector.static.modelClasses = [ ve.dm.MWMathNode ];
|
||||
|
||||
ve.ui.MWMathInspector.static.dir = 'ltr';
|
||||
|
||||
/* Methods */
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.initialize = function () {
|
||||
var inputField, displayField, idField;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWMathInspector.super.prototype.initialize.call( this );
|
||||
|
||||
this.displaySelect = new OO.ui.ButtonSelectWidget( {
|
||||
items: [
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'default',
|
||||
icon: 'math-display-default',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-default' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'inline',
|
||||
icon: 'math-display-inline',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-inline' )
|
||||
} ),
|
||||
new OO.ui.ButtonOptionWidget( {
|
||||
data: 'block',
|
||||
icon: 'math-display-block',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display-block' )
|
||||
} )
|
||||
]
|
||||
} );
|
||||
|
||||
this.idInput = new OO.ui.TextInputWidget();
|
||||
|
||||
inputField = new OO.ui.FieldLayout( this.input, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-title' )
|
||||
} );
|
||||
displayField = new OO.ui.FieldLayout( this.displaySelect, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-display' )
|
||||
} );
|
||||
idField = new OO.ui.FieldLayout( this.idInput, {
|
||||
align: 'top',
|
||||
label: ve.msg( 'math-visualeditor-mwmathinspector-id' )
|
||||
} );
|
||||
|
||||
// Initialization
|
||||
this.$content.addClass( 've-ui-mwMathInspector-content' );
|
||||
this.form.$element.append(
|
||||
inputField.$element,
|
||||
this.generatedContentsError.$element,
|
||||
displayField.$element,
|
||||
idField.$element
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.getSetupProcess = function ( data ) {
|
||||
return ve.ui.MWMathInspector.super.prototype.getSetupProcess.call( this, data )
|
||||
.next( function () {
|
||||
var display = this.selectedNode.getAttribute( 'mw' ).attrs.display || 'default';
|
||||
this.displaySelect.selectItemByData( display );
|
||||
this.displaySelect.on( 'choose', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.getTeardownProcess = function ( data ) {
|
||||
return ve.ui.MWMathInspector.super.prototype.getTeardownProcess.call( this, data )
|
||||
.first( function () {
|
||||
this.displaySelect.off( 'choose', this.onChangeHandler );
|
||||
}, this );
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.updateMwData = function ( mwData ) {
|
||||
var display, id;
|
||||
|
||||
// Parent method
|
||||
ve.ui.MWMathInspector.super.prototype.updateMwData.call( this, mwData );
|
||||
|
||||
display = this.displaySelect.getSelectedItem().getData();
|
||||
id = this.idInput.getValue();
|
||||
|
||||
mwData.attrs.display = display !== 'default' ? display : undefined;
|
||||
mwData.attrs.id = id || undefined;
|
||||
};
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
ve.ui.MWMathInspector.prototype.formatGeneratedContentsError = function ( $element ) {
|
||||
return $element.text().trim();
|
||||
};
|
||||
|
||||
/* Registration */
|
||||
|
||||
ve.ui.windowFactory.register( ve.ui.MWMathInspector );
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in a new issue