2013-04-29 14:33:37 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor DataModel MWDefaultSortMetaItem class.
|
|
|
|
*
|
2023-12-01 16:06:11 +00:00
|
|
|
* @copyright See AUTHORS.txt
|
2013-04-29 14:33:37 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DataModel category default sort meta item.
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.dm.MetaItem
|
|
|
|
* @constructor
|
|
|
|
* @param {Object} element Reference to element in meta-linmod
|
|
|
|
*/
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem = function VeDmMWDefaultSortMetaItem() {
|
2013-04-29 14:33:37 +00:00
|
|
|
// Parent constructor
|
2016-08-22 21:44:59 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem.super.apply( this, arguments );
|
2013-04-29 14:33:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2013-10-11 21:44:09 +00:00
|
|
|
OO.inheritClass( ve.dm.MWDefaultSortMetaItem, ve.dm.MetaItem );
|
2013-04-29 14:33:37 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem.static.name = 'mwDefaultSort';
|
2013-04-29 14:33:37 +00:00
|
|
|
|
2013-05-28 11:31:41 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem.static.group = 'mwDefaultSort';
|
2013-04-29 14:33:37 +00:00
|
|
|
|
2023-11-09 05:02:23 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem.static.matchTagNames = [ 'span' ];
|
2013-04-29 14:33:37 +00:00
|
|
|
|
2023-11-09 05:02:23 +00:00
|
|
|
ve.dm.MWDefaultSortMetaItem.static.matchRdfaTypes = [ 'mw:Transclusion' ];
|
|
|
|
|
|
|
|
ve.dm.MWDefaultSortMetaItem.static.matchFunction = function ( domElement ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const mwDataJSON = domElement.getAttribute( 'data-mw' ),
|
2023-11-09 05:02:23 +00:00
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
|
|
|
|
return ve.getProp( mwData, 'parts', '0', 'template', 'target', 'function' ) === 'defaultsort';
|
|
|
|
};
|
2013-04-29 14:33:37 +00:00
|
|
|
|
|
|
|
ve.dm.MWDefaultSortMetaItem.static.toDataElement = function ( domElements ) {
|
2024-05-21 16:40:36 +00:00
|
|
|
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
2023-11-09 05:02:23 +00:00
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
2024-05-21 16:40:36 +00:00
|
|
|
input = ve.getProp( mwData, 'parts', '0', 'template', 'target', 'wt' );
|
|
|
|
let prefix, sortKey;
|
2023-11-09 05:02:23 +00:00
|
|
|
if ( input ) {
|
|
|
|
prefix = input.split( ':' )[ 0 ];
|
|
|
|
sortKey = input.slice( prefix.length + 1 );
|
|
|
|
}
|
2013-04-29 14:33:37 +00:00
|
|
|
return {
|
2014-08-22 20:50:48 +00:00
|
|
|
type: this.name,
|
|
|
|
attributes: {
|
2023-11-09 05:02:23 +00:00
|
|
|
prefix: prefix,
|
|
|
|
sortkey: sortKey
|
2013-04-29 14:33:37 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
ve.dm.MWDefaultSortMetaItem.static.toDomElements = function ( dataElement, doc ) {
|
2024-05-21 14:22:56 +00:00
|
|
|
const prefix = dataElement.attributes.prefix ||
|
2023-11-09 05:02:23 +00:00
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).defaultSortPrefix,
|
|
|
|
sortKey = dataElement.attributes.sortkey || '',
|
|
|
|
mwData = {
|
|
|
|
parts: [
|
|
|
|
{
|
|
|
|
template: {
|
|
|
|
target: {
|
|
|
|
wt: prefix + ':' + sortKey,
|
|
|
|
function: 'defaultsort'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2024-05-21 14:22:56 +00:00
|
|
|
const span = doc.createElement( 'span' );
|
2023-11-09 05:02:23 +00:00
|
|
|
span.setAttribute( 'typeof', 'mw:Transclusion' );
|
|
|
|
span.setAttribute( 'data-mw', JSON.stringify( mwData ) );
|
|
|
|
return [ span ];
|
2013-04-29 14:33:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.dm.modelRegistry.register( ve.dm.MWDefaultSortMetaItem );
|