Merge "Define RDFa types in ve.dm.MWBlockImageNode once and reuse whenever possible"

This commit is contained in:
jenkins-bot 2013-09-05 22:56:22 +00:00 committed by Gerrit Code Review
commit c5aaf37139

View file

@ -24,6 +24,13 @@ ve.inheritClass( ve.dm.MWBlockImageNode, ve.dm.BranchNode );
/* Static Properties */ /* Static Properties */
ve.dm.MWBlockImageNode.static.rdfaToType = {
'mw:Image/Thumb': 'thumb',
'mw:Image/Frame': 'frame',
'mw:Image/Frameless': 'frameless',
'mw:Image': 'none'
};
ve.dm.MWBlockImageNode.static.name = 'mwBlockImage'; ve.dm.MWBlockImageNode.static.name = 'mwBlockImage';
ve.dm.MWBlockImageNode.static.storeHtmlAttributes = { ve.dm.MWBlockImageNode.static.storeHtmlAttributes = {
@ -36,12 +43,9 @@ ve.dm.MWBlockImageNode.static.childNodeTypes = [ 'mwImageCaption' ];
ve.dm.MWBlockImageNode.static.matchTagNames = [ 'figure' ]; ve.dm.MWBlockImageNode.static.matchTagNames = [ 'figure' ];
ve.dm.MWBlockImageNode.static.matchRdfaTypes = [ ve.dm.MWBlockImageNode.static.getMatchRdfaTypes = function () {
'mw:Image', return Object.keys( this.rdfaToType );
'mw:Image/Thumb', };
'mw:Image/Frame',
'mw:Image/Frameless'
];
ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter ) { ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter ) {
var $figure = $( domElements[0] ), var $figure = $( domElements[0] ),
@ -53,6 +57,7 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
classes = $figure.attr( 'class' ), classes = $figure.attr( 'class' ),
recognizedClasses = [], recognizedClasses = [],
attributes = { attributes = {
type: this.rdfaToType[typeofAttr],
href: $imgWrapper.attr( 'href' ) || '', href: $imgWrapper.attr( 'href' ) || '',
src: $img.attr( 'src' ), src: $img.attr( 'src' ),
width: $img.attr( 'width' ), width: $img.attr( 'width' ),
@ -64,22 +69,6 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
// Extract individual classes // Extract individual classes
classes = typeof classes === 'string' ? classes.trim().split( /\s+/ ) : []; classes = typeof classes === 'string' ? classes.trim().split( /\s+/ ) : [];
// Type
switch ( typeofAttr ) {
case 'mw:Image/Thumb':
attributes.type = 'thumb';
break;
case 'mw:Image/Frame':
attributes.type = 'frame';
break;
case 'mw:Image/Frameless':
attributes.type = 'frameless';
break;
case 'mw:Image':
attributes.type = 'none';
break;
}
// Horizontal alignment // Horizontal alignment
if ( classes.indexOf( 'mw-halign-left' ) !== -1 ) { if ( classes.indexOf( 'mw-halign-left' ) !== -1 ) {
attributes.align = 'left'; attributes.align = 'left';
@ -108,15 +97,15 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
if ( $caption.length === 0 ) { if ( $caption.length === 0 ) {
return [ return [
{ 'type': 'mwBlockImage', 'attributes': attributes }, { 'type': this.name, 'attributes': attributes },
{ 'type': 'mwImageCaption' }, { 'type': 'mwImageCaption' },
{ 'type': '/mwImageCaption' }, { 'type': '/mwImageCaption' },
{ 'type': '/mwBlockImage' } { 'type': '/' + this.name }
]; ];
} else { } else {
return [ { 'type': 'mwBlockImage', 'attributes': attributes } ]. return [ { 'type': this.name, 'attributes': attributes } ].
concat( converter.getDataFromDomRecursionClean( $caption[0], { 'type': 'mwImageCaption' } ) ). concat( converter.getDataFromDomRecursionClean( $caption[0], { 'type': 'mwImageCaption' } ) ).
concat( [ { 'type': '/mwBlockImage' } ] ); concat( [ { 'type': '/' + this.name } ] );
} }
}; };
@ -131,23 +120,18 @@ ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter )
wrapper = doc.createElement( 'div' ), wrapper = doc.createElement( 'div' ),
classes = [], classes = [],
originalClasses = dataElement.attributes.originalClasses, originalClasses = dataElement.attributes.originalClasses,
captionData = data.slice( 1, -1 ); captionData = data.slice( 1, -1 ),
rdfa;
if ( !this.typeToRdfa ) {
this.typeToRdfa = {};
for ( rdfa in this.rdfaToType ) {
this.typeToRdfa[this.rdfaToType[rdfa]] = rdfa;
}
}
// Type // Type
switch ( dataElement.attributes.type ) { figure.setAttribute( 'typeof', this.typeToRdfa[dataElement.attributes.type] );
case 'thumb':
figure.setAttribute( 'typeof', 'mw:Image/Thumb' );
break;
case 'frame':
figure.setAttribute( 'typeof', 'mw:Image/Frame' );
break;
case 'frameless':
figure.setAttribute( 'typeof', 'mw:Image/Frameless' );
break;
case 'none':
figure.setAttribute( 'typeof', 'mw:Image' );
break;
}
// Default-size // Default-size
if ( dataElement.attributes.defaultSize === true ) { if ( dataElement.attributes.defaultSize === true ) {