mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-09-27 12:16:51 +00:00
Merge "ve.dm.MWBlockImageNode: Make toDomElements add more information to its output so round-tripping can work properly."
This commit is contained in:
commit
72f661dc69
|
@ -90,7 +90,8 @@ ve.ce.MWBlockImageNode.static.alignToCssClass = {
|
||||||
'left': 'tleft',
|
'left': 'tleft',
|
||||||
'right': 'tright',
|
'right': 'tright',
|
||||||
'center' : 'tnone',
|
'center' : 'tnone',
|
||||||
'none' : 'tnone'
|
'none' : 'tnone',
|
||||||
|
'default': 'tright'
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Methods */
|
/* Methods */
|
||||||
|
|
|
@ -74,7 +74,7 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
|
||||||
} else if ( classes.indexOf( 'mw-halign-none' ) !== -1 ) {
|
} else if ( classes.indexOf( 'mw-halign-none' ) !== -1 ) {
|
||||||
attributes.align = 'none';
|
attributes.align = 'none';
|
||||||
} else {
|
} else {
|
||||||
attributes.align = 'right';
|
attributes.align = 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Default-size
|
// 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 ) {
|
ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter ) {
|
||||||
var dataElement = data[0],
|
var dataElement = data[0],
|
||||||
figure = doc.createElement( 'figure' ),
|
figure = doc.createElement( 'figure' ),
|
||||||
a = doc.createElement( 'a' ),
|
a = doc.createElement( 'a' ),
|
||||||
img = doc.createElement( 'img' ),
|
img = doc.createElement( 'img' ),
|
||||||
wrapper = doc.createElement( 'div' );
|
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( 'rel', 'mw:thumb' );
|
||||||
a.setAttribute( 'href', dataElement.attributes.href );
|
a.setAttribute( 'href', dataElement.attributes.href );
|
||||||
img.setAttribute( 'src', dataElement.attributes.src );
|
img.setAttribute( 'src', dataElement.attributes.src );
|
||||||
|
|
|
@ -3182,7 +3182,7 @@ ve.dm.example.domToDataCases = {
|
||||||
'type': 'mwBlockImage',
|
'type': 'mwBlockImage',
|
||||||
'attributes': {
|
'attributes': {
|
||||||
'type': 'thumb',
|
'type': 'thumb',
|
||||||
'align': 'right',
|
'align': 'default',
|
||||||
'href': 'Foo',
|
'href': 'Foo',
|
||||||
'src': 'Bar',
|
'src': 'Bar',
|
||||||
'width': '1',
|
'width': '1',
|
||||||
|
|
Loading…
Reference in a new issue