| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ce.MWInlineImageNode = function VeCeMWInlineImageNode( model, config ) { |
| 20 |
let $image; |
| 21 |
let hasHref = false; |
| 22 |
|
| 23 |
if ( model.getAttribute( 'isError' ) ) { |
| 24 |
this.$element = $( '<a>' ) |
| 25 |
.addClass( 'new' ) |
| 26 |
.append( |
| 27 |
$( '<span>' ) |
| 28 |
.addClass( 'mw-file-element mw-broken-media' ) |
| 29 |
.text( model.getAttribute( 'errorText' ) ) |
| 30 |
); |
| 31 |
$image = $( [] ); |
| 32 |
} else { |
| 33 |
$image = $( '<img>' ).addClass( 'mw-file-element' ); |
| 34 |
if ( model.getAttribute( 'href' ) ) { |
| 35 |
hasHref = true; |
| 36 |
this.$element = $( '<a>' ).addClass( 'mw-file-description' ); |
| 37 |
$image.appendTo( this.$element ); |
| 38 |
} else { |
| 39 |
this.$element = $image; |
| 40 |
} |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
ve.ce.MWInlineImageNode.super.call( this, model, ve.extendObject( {}, config, { $element: this.$element } ) ); |
| 47 |
|
| 48 |
|
| 49 |
ve.ce.MWImageNode.call( this, this.$element, $image ); |
| 50 |
|
| 51 |
$image |
| 52 |
.attr( 'src', this.getResolvedAttribute( 'src' ) ) |
| 53 |
.attr( 'width', this.model.getAttribute( 'width' ) ) |
| 54 |
.attr( 'height', this.model.getAttribute( 'height' ) ); |
| 55 |
|
| 56 |
if ( hasHref ) { |
| 57 |
|
| 58 |
ve.setAttributeSafe( this.$element[ 0 ], 'href', this.getResolvedAttribute( 'href' ) || '', '#' ); |
| 59 |
} |
| 60 |
|
| 61 |
this.showHandles( [ this.$element.css( 'direction' ) === 'rtl' ? 'sw' : 'se' ] ); |
| 62 |
|
| 63 |
this.updateClasses(); |
| 64 |
|
| 65 |
|
| 66 |
this.$element.addClass( 've-ce-mwInlineImageNode' ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
OO.inheritClass( ve.ce.MWInlineImageNode, ve.ce.LeafNode ); |
| 72 |
|
| 73 |
|
| 74 |
OO.mixinClass( ve.ce.MWInlineImageNode, ve.ce.GeneratedContentNode ); |
| 75 |
|
| 76 |
OO.mixinClass( ve.ce.MWInlineImageNode, ve.ce.MWImageNode ); |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
ve.ce.MWInlineImageNode.static.name = 'mwInlineImage'; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
ve.ce.MWInlineImageNode.prototype.updateClasses = function () { |
| 88 |
const valign = this.model.getAttribute( 'valign' ); |
| 89 |
|
| 90 |
|
| 91 |
this.$element.toggleClass( 'mw-image-border', !!this.model.getAttribute( 'borderImage' ) ); |
| 92 |
|
| 93 |
|
| 94 |
this.$element.toggleClass( 'mw-default-size', !!this.model.getAttribute( 'defaultSize' ) ); |
| 95 |
|
| 96 |
|
| 97 |
if ( valign !== 'default' ) { |
| 98 |
this.$image.css( 'vertical-align', valign ); |
| 99 |
} |
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.ce.MWInlineImageNode.prototype.onAttributeChange = function ( key, from, to ) { |
| 106 |
|
| 107 |
ve.ce.MWImageNode.prototype.onAttributeChange.apply( this, arguments ); |
| 108 |
|
| 109 |
if ( key === 'height' || key === 'width' ) { |
| 110 |
to = parseInt( to, 10 ); |
| 111 |
} |
| 112 |
|
| 113 |
if ( from !== to ) { |
| 114 |
switch ( key ) { |
| 115 |
|
| 116 |
case 'width': |
| 117 |
this.$image.css( 'width', to ); |
| 118 |
break; |
| 119 |
case 'height': |
| 120 |
this.$image.css( 'height', to ); |
| 121 |
break; |
| 122 |
case 'mediaType': |
| 123 |
this.updateMediaType(); |
| 124 |
break; |
| 125 |
} |
| 126 |
this.updateClasses(); |
| 127 |
} |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
ve.ce.nodeFactory.register( ve.ce.MWInlineImageNode ); |