2015-09-29 15:44:21 +00:00
|
|
|
/*!
|
2017-01-11 21:50:35 +00:00
|
|
|
* VisualEditor user interface MWLatexPage class.
|
2015-09-29 15:44:21 +00:00
|
|
|
*
|
|
|
|
* @copyright 2015 VisualEditor Team and others; see AUTHORS.txt
|
2018-04-13 14:04:06 +00:00
|
|
|
* @license MIT
|
2015-09-29 15:44:21 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2017-01-11 21:50:35 +00:00
|
|
|
* Latex dialog symbols page
|
2015-09-29 15:44:21 +00:00
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends OO.ui.PageLayout
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {string} name Unique symbolic name of page
|
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
*/
|
2017-01-11 21:50:35 +00:00
|
|
|
ve.ui.MWLatexPage = function VeUiMWLatexPage( name, config ) {
|
2015-09-29 15:44:21 +00:00
|
|
|
// Parent constructor
|
2017-01-11 21:50:35 +00:00
|
|
|
ve.ui.MWLatexPage.super.call( this, name, config );
|
2015-09-29 15:44:21 +00:00
|
|
|
|
|
|
|
this.label = config.label;
|
|
|
|
|
2024-02-13 00:31:24 +00:00
|
|
|
const symbols = config.symbols;
|
|
|
|
const $symbols = $( '<div>' ).addClass( 've-ui-specialCharacterPage-characters' );
|
|
|
|
const symbolsNode = $symbols[ 0 ];
|
2015-09-29 15:44:21 +00:00
|
|
|
|
|
|
|
// Avoiding jQuery wrappers as advised in ve.ui.SpecialCharacterPage
|
2021-10-05 16:04:47 +00:00
|
|
|
symbols.forEach( function ( symbol ) {
|
2015-09-29 15:44:21 +00:00
|
|
|
if ( !symbol.notWorking && !symbol.duplicate ) {
|
2024-02-13 00:31:24 +00:00
|
|
|
const tex = symbol.tex || symbol.insert;
|
|
|
|
const classes = [ 've-ui-mwLatexPage-symbol' ];
|
2015-09-29 15:44:21 +00:00
|
|
|
classes.push(
|
2017-01-11 21:50:35 +00:00
|
|
|
've-ui-mwLatexSymbol-' + tex.replace( /[^\w]/g, function ( c ) {
|
2015-09-29 15:44:21 +00:00
|
|
|
return '_' + c.charCodeAt( 0 ) + '_';
|
|
|
|
} )
|
|
|
|
);
|
2016-10-14 02:04:37 +00:00
|
|
|
if ( symbol.width ) {
|
2017-01-11 21:50:35 +00:00
|
|
|
classes.push( 've-ui-mwLatexPage-symbol-' + symbol.width );
|
2015-09-29 15:44:21 +00:00
|
|
|
}
|
|
|
|
if ( symbol.contain ) {
|
2017-01-11 21:50:35 +00:00
|
|
|
classes.push( 've-ui-mwLatexPage-symbol-contain' );
|
2015-09-29 15:44:21 +00:00
|
|
|
}
|
|
|
|
if ( symbol.largeLayout ) {
|
2017-01-11 21:50:35 +00:00
|
|
|
classes.push( 've-ui-mwLatexPage-symbol-largeLayout' );
|
2015-09-29 15:44:21 +00:00
|
|
|
}
|
2024-02-13 00:31:24 +00:00
|
|
|
const symbolNode = document.createElement( 'div' );
|
2021-10-05 16:04:47 +00:00
|
|
|
classes.forEach( function ( className ) {
|
2020-06-16 14:45:59 +00:00
|
|
|
// The following classes are used here:
|
|
|
|
// * ve-ui-mwLatexPage-symbol
|
|
|
|
// * ve-ui-mwLatexPage-symbol-wide
|
|
|
|
// * ve-ui-mwLatexPage-symbol-wider
|
|
|
|
// * ve-ui-mwLatexPage-symbol-widest
|
|
|
|
// * ve-ui-mwLatexPage-symbol-contain
|
|
|
|
// * ve-ui-mwLatexPage-symbol-largeLayout
|
2021-10-05 16:04:47 +00:00
|
|
|
symbolNode.classList.add( className );
|
|
|
|
} );
|
2015-09-29 15:44:21 +00:00
|
|
|
$.data( symbolNode, 'symbol', symbol );
|
|
|
|
symbolsNode.appendChild( symbolNode );
|
|
|
|
}
|
2021-10-05 16:04:47 +00:00
|
|
|
} );
|
2015-09-29 15:44:21 +00:00
|
|
|
|
|
|
|
this.$element
|
2017-01-11 21:50:35 +00:00
|
|
|
.addClass( 've-ui-mwLatexPage' )
|
2015-09-29 15:44:21 +00:00
|
|
|
.append( $( '<h3>' ).text( name ), $symbols );
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2017-01-11 21:50:35 +00:00
|
|
|
OO.inheritClass( ve.ui.MWLatexPage, OO.ui.PageLayout );
|
2015-09-29 15:44:21 +00:00
|
|
|
|
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2017-01-11 21:50:35 +00:00
|
|
|
ve.ui.MWLatexPage.prototype.setupOutlineItem = function ( outlineItem ) {
|
|
|
|
ve.ui.MWLatexPage.super.prototype.setupOutlineItem.call( this, outlineItem );
|
2015-09-29 15:44:21 +00:00
|
|
|
this.outlineItem.setLabel( this.label );
|
2017-01-11 21:50:35 +00:00
|
|
|
this.outlineItem.$element.addClass( 've-ui-mwLatexPage-outline' );
|
2015-09-29 15:44:21 +00:00
|
|
|
};
|