Merge "ve.dm.MWBlockImageNode: Make toDomElements add more information to its output so round-tripping can work properly."

This commit is contained in:
jenkins-bot 2013-06-06 21:46:21 +00:00 committed by Gerrit Code Review
commit 72f661dc69
3 changed files with 36 additions and 4 deletions

View file

@ -90,7 +90,8 @@ ve.ce.MWBlockImageNode.static.alignToCssClass = {
'left': 'tleft',
'right': 'tright',
'center' : 'tnone',
'none' : 'tnone'
'none' : 'tnone',
'default': 'tright'
};
/* Methods */

View file

@ -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 );

View file

@ -3182,7 +3182,7 @@ ve.dm.example.domToDataCases = {
'type': 'mwBlockImage',
'attributes': {
'type': 'thumb',
'align': 'right',
'align': 'default',
'href': 'Foo',
'src': 'Bar',
'width': '1',