1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
/*!
* VisualEditor DataModel MWDefaultSortMetaItem class.
*
* @copyright See AUTHORS.txt
* @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
*/
ve.dm.MWDefaultSortMetaItem = function VeDmMWDefaultSortMetaItem() {
// Parent constructor
ve.dm.MWDefaultSortMetaItem.super.apply( this, arguments );
};
/* Inheritance */
OO.inheritClass( ve.dm.MWDefaultSortMetaItem, ve.dm.MetaItem );
/* Static Properties */
ve.dm.MWDefaultSortMetaItem.static.name = 'mwDefaultSort';
ve.dm.MWDefaultSortMetaItem.static.group = 'mwDefaultSort';
ve.dm.MWDefaultSortMetaItem.static.matchTagNames = [ 'span' ];
ve.dm.MWDefaultSortMetaItem.static.matchRdfaTypes = [ 'mw:Transclusion' ];
ve.dm.MWDefaultSortMetaItem.static.matchFunction = function ( domElement ) {
const mwDataJSON = domElement.getAttribute( 'data-mw' ),
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {};
return ve.getProp( mwData, 'parts', '0', 'template', 'target', 'function' ) === 'defaultsort';
};
ve.dm.MWDefaultSortMetaItem.static.toDataElement = function ( domElements ) {
const mwDataJSON = domElements[ 0 ].getAttribute( 'data-mw' ),
mwData = mwDataJSON ? JSON.parse( mwDataJSON ) : {},
input = ve.getProp( mwData, 'parts', '0', 'template', 'target', 'wt' );
let prefix, sortKey;
if ( input ) {
prefix = input.split( ':' )[ 0 ];
sortKey = input.slice( prefix.length + 1 );
}
return {
type: this.name,
attributes: {
prefix: prefix,
sortkey: sortKey
}
};
};
ve.dm.MWDefaultSortMetaItem.static.toDomElements = function ( dataElement, doc ) {
const prefix = dataElement.attributes.prefix ||
mw.config.get( 'wgVisualEditorConfig' ).defaultSortPrefix,
sortKey = dataElement.attributes.sortkey || '',
mwData = {
parts: [
{
template: {
target: {
wt: prefix + ':' + sortKey,
function: 'defaultsort'
}
}
}
]
};
const span = doc.createElement( 'span' );
span.setAttribute( 'typeof', 'mw:Transclusion' );
span.setAttribute( 'data-mw', JSON.stringify( mwData ) );
return [ span ];
};
/* Registration */
ve.dm.modelRegistry.register( ve.dm.MWDefaultSortMetaItem );
|