From d14b2c514d63680cfbbab505ae96474d1c57092f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Inez=20Korczyn=CC=81ski?= Date: Wed, 5 Jun 2013 14:34:53 -0700 Subject: [PATCH] ve.dm.MWBlockImageNode: Make toDomElements add more information to its output so round-tripping can work properly. Change-Id: Ieacf9187371a1687869bcb4bb0244f1bc251a803 --- modules/ve/ce/nodes/ve.ce.MWBlockImageNode.js | 3 +- modules/ve/dm/nodes/ve.dm.MWBlockImageNode.js | 35 +++++++++++++++++-- modules/ve/test/dm/ve.dm.example.js | 2 +- 3 files changed, 36 insertions(+), 4 deletions(-) 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 59559557eb..06a64c3d88 100644 --- a/modules/ve/test/dm/ve.dm.example.js +++ b/modules/ve/test/dm/ve.dm.example.js @@ -3166,7 +3166,7 @@ ve.dm.example.domToDataCases = { 'type': 'mwBlockImage', 'attributes': { 'type': 'thumb', - 'align': 'right', + 'align': 'default', 'href': 'Foo', 'src': 'Bar', 'width': '1',