mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
Work around DOM corruption for default-sized images
This doesn't really fix the underlying issue that the width and height are overridden to be the default size in the DM even if that's wrong (in the case the image's original size is smaller than the default thumbnail size), but it fixes the DOM corruption by storing the original width&height and restoring them if the image still has defaultSize=true on the way out. Bug: 62172 Change-Id: Iaee798c5bb501310e52d0ac832b2e7cd833fc438
This commit is contained in:
parent
07422e308c
commit
c0380f16a4
|
@ -126,10 +126,17 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
|
|||
attributes.type === 'thumb' ||
|
||||
attributes.type === 'frameless'
|
||||
) {
|
||||
// We're gonna change .width and .height, store the original
|
||||
// values so we can restore them later.
|
||||
// FIXME "just" don't modify .width and .height instead
|
||||
attributes.originalWidth = attributes.width;
|
||||
attributes.originalHeight = attributes.height;
|
||||
// Parsoid hands us images with default Wikipedia dimensions
|
||||
// rather than default MediaWiki configuration dimensions.
|
||||
// We must force local wiki default in edit mode for default
|
||||
// size images.
|
||||
// FIXME if the image's original size is less than the default size,
|
||||
// this is wrong.
|
||||
if ( attributes.width > attributes.height ) {
|
||||
if ( attributes.height !== null ) {
|
||||
attributes.height = ( attributes.height / attributes.width ) * defaultSizeBoundingBox;
|
||||
|
@ -169,15 +176,15 @@ ve.dm.MWBlockImageNode.static.toDataElement = function ( domElements, converter
|
|||
// 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],
|
||||
var rdfa, width, height,
|
||||
dataElement = data[0],
|
||||
figure = doc.createElement( 'figure' ),
|
||||
imgWrapper = doc.createElement( dataElement.attributes.href !== '' ? 'a' : 'span' ),
|
||||
img = doc.createElement( 'img' ),
|
||||
wrapper = doc.createElement( 'div' ),
|
||||
classes = [],
|
||||
originalClasses = dataElement.attributes.originalClasses,
|
||||
captionData = data.slice( 1, -1 ),
|
||||
rdfa;
|
||||
captionData = data.slice( 1, -1 );
|
||||
|
||||
if ( !this.typeToRdfa ) {
|
||||
this.typeToRdfa = {};
|
||||
|
@ -228,9 +235,23 @@ ve.dm.MWBlockImageNode.static.toDomElements = function ( data, doc, converter )
|
|||
if ( dataElement.attributes.href !== '' ) {
|
||||
imgWrapper.setAttribute( 'href', dataElement.attributes.href );
|
||||
}
|
||||
|
||||
width = dataElement.attributes.width;
|
||||
height = dataElement.attributes.height;
|
||||
// If defaultSize is set, and was set on the way in, use the original width and height
|
||||
// we got on the way in.
|
||||
if ( dataElement.attributes.defaultSize ) {
|
||||
if ( dataElement.attributes.originalWidth !== undefined ) {
|
||||
width = dataElement.attributes.originalWidth;
|
||||
}
|
||||
if ( dataElement.attributes.originalHeight !== undefined ) {
|
||||
height = dataElement.attributes.originalHeight;
|
||||
}
|
||||
}
|
||||
|
||||
img.setAttribute( 'src', dataElement.attributes.src );
|
||||
img.setAttribute( 'width', dataElement.attributes.width );
|
||||
img.setAttribute( 'height', dataElement.attributes.height );
|
||||
img.setAttribute( 'width', width );
|
||||
img.setAttribute( 'height', height );
|
||||
img.setAttribute( 'resource', dataElement.attributes.resource );
|
||||
if ( dataElement.attributes.alt !== undefined ) {
|
||||
img.setAttribute( 'alt', dataElement.attributes.alt );
|
||||
|
|
Loading…
Reference in a new issue