diff --git a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js index 2e761072a0..0092d5afa5 100644 --- a/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js +++ b/modules/ve-mw/dm/nodes/ve.dm.MWBlockImageNode.js @@ -24,6 +24,13 @@ ve.inheritClass( ve.dm.MWBlockImageNode, ve.dm.BranchNode ); /* 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.storeHtmlAttributes = { @@ -36,12 +43,9 @@ ve.dm.MWBlockImageNode.static.childNodeTypes = [ 'mwImageCaption' ]; ve.dm.MWBlockImageNode.static.matchTagNames = [ 'figure' ]; -ve.dm.MWBlockImageNode.static.matchRdfaTypes = [ - 'mw:Image', - 'mw:Image/Thumb', - 'mw:Image/Frame', - 'mw:Image/Frameless' -]; +ve.dm.MWBlockImageNode.static.getMatchRdfaTypes = function () { + return Object.keys( this.rdfaToType ); +}; ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter ) { var $figure = $( domElements[0] ), @@ -53,6 +57,7 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter classes = $figure.attr( 'class' ), recognizedClasses = [], attributes = { + type: this.rdfaToType[typeofAttr], href: $imgWrapper.attr( 'href' ) || '', src: $img.attr( 'src' ), width: $img.attr( 'width' ), @@ -64,22 +69,6 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter // Extract individual classes 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 if ( classes.indexOf( 'mw-halign-left' ) !== -1 ) { attributes.align = 'left'; @@ -108,15 +97,15 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter if ( $caption.length === 0 ) { return [ - { 'type': 'mwBlockImage', 'attributes': attributes }, + { 'type': this.name, 'attributes': attributes }, { 'type': 'mwImageCaption' }, { 'type': '/mwImageCaption' }, - { 'type': '/mwBlockImage' } + { 'type': '/' + this.name } ]; } else { - return [ { 'type': 'mwBlockImage', 'attributes': attributes } ]. + return [ { 'type': this.name, 'attributes': attributes } ]. 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' ), classes = [], 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 - switch ( 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; - } + figure.setAttribute( 'typeof', this.typeToRdfa[dataElement.attributes.type] ); // Default-size if ( dataElement.attributes.defaultSize === true ) {