diff --git a/modules/ve/ce/nodes/ve.ce.MWBlockImageNode.js b/modules/ve/ce/nodes/ve.ce.MWBlockImageNode.js index 61191339a7..932410f517 100644 --- a/modules/ve/ce/nodes/ve.ce.MWBlockImageNode.js +++ b/modules/ve/ce/nodes/ve.ce.MWBlockImageNode.js @@ -90,7 +90,8 @@ ve.ce.MWBlockImageNode.static.alignToCssClass = { 'left': 'tleft', 'right': 'tright', 'center' : 'tnone', - 'none' : 'tnone' + 'none' : 'tnone', + 'default': 'tright' }; /* Methods */ diff --git a/modules/ve/dm/nodes/ve.dm.MWBlockImageNode.js b/modules/ve/dm/nodes/ve.dm.MWBlockImageNode.js index ed39504bf0..ff43a6f19c 100644 --- a/modules/ve/dm/nodes/ve.dm.MWBlockImageNode.js +++ b/modules/ve/dm/nodes/ve.dm.MWBlockImageNode.js @@ -74,7 +74,7 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter } else if ( classes.indexOf( 'mw-halign-none' ) !== -1 ) { attributes.align = 'none'; } else { - attributes.align = 'right'; + attributes.align = 'default'; } // Default-size @@ -96,13 +96,44 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter } }; +// TODO: Consider using jQuery instead of pure JS. +// TODO: At this moment node is not resizable but when it will be then adding defaultSize class +// should be more conditional. ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter ) { var dataElement = data[0], figure = doc.createElement( 'figure' ), a = doc.createElement( 'a' ), img = doc.createElement( 'img' ), wrapper = doc.createElement( 'div' ); - figure.setAttribute( 'typeof', 'mw:Image/Thumb' ); + + // Type + if ( dataElement.attributes.type === 'thumb' ) { + figure.setAttribute( 'typeof', 'mw:Image/Thumb' ); + } else { + figure.setAttribute( 'typeof', 'mw:Image/Frame' ); + } + + // Default-size + if ( dataElement.attributes.defaultSize === true ) { + figure.className += ' mw-default-size'; + } + + // Horizontal alignment + switch ( dataElement.attributes.align ) { + case 'left': + figure.className += ' mw-halign-left'; + break; + case 'right': + figure.className += ' mw-halign-right'; + break; + case 'center': + figure.className += ' mw-halign-center'; + break; + case 'none': + figure.className += ' mw-halign-none'; + break; + } + a.setAttribute( 'rel', 'mw:thumb' ); a.setAttribute( 'href', dataElement.attributes.href ); img.setAttribute( 'src', dataElement.attributes.src ); diff --git a/modules/ve/test/dm/ve.dm.example.js b/modules/ve/test/dm/ve.dm.example.js index 10adedeef9..b0adc163c1 100644 --- a/modules/ve/test/dm/ve.dm.example.js +++ b/modules/ve/test/dm/ve.dm.example.js @@ -3182,7 +3182,7 @@ ve.dm.example.domToDataCases = { 'type': 'mwBlockImage', 'attributes': { 'type': 'thumb', - 'align': 'right', + 'align': 'default', 'href': 'Foo', 'src': 'Bar', 'width': '1',