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 ) {
|
|
|
|
var mwDataJSON = domElement.getAttribute( 'data-mw' ),
|
|
|
|
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 ) {
|
2023-11-09 05:02:23 +00:00
|
|
|
var mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
|
|
|
|
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
|
|
|
|
input = ve.getProp( mwData, 'parts', '0', 'template', 'target', 'wt' ),
|
|
|
|
prefix, sortKey;
|
|
|
|
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 ) {
|
2023-11-09 05:02:23 +00:00
|
|
|
var prefix = dataElement.attributes.prefix ||
|
|
|
|
mw.config.get( 'wgVisualEditorConfig' ).defaultSortPrefix,
|
|
|
|
sortKey = dataElement.attributes.sortkey || '',
|
|
|
|
mwData = {
|
|
|
|
parts: [
|
|
|
|
{
|
|
|
|
template: {
|
|
|
|
target: {
|
|
|
|
wt: prefix + ':' + sortKey,
|
|
|
|
function: 'defaultsort'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var span = doc.createElement( 'span' );
|
|
|
|
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 );
|