| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ce.ImageNode = function VeCeImageNode( $figure, $image, config ) { |
| 21 |
config = ve.extendObject( { |
| 22 |
enforceMax: false, |
| 23 |
minDimensions: { width: 1, height: 1 }, |
| 24 |
$bounding: this.$element |
| 25 |
}, config ); |
| 26 |
|
| 27 |
this.$figure = $figure; |
| 28 |
this.$image = $image || $figure; |
| 29 |
|
| 30 |
|
| 31 |
ve.ce.FocusableNode.call( this, this.$figure, config ); |
| 32 |
ve.ce.ResizableNode.call( this, this.$image, config ); |
| 33 |
|
| 34 |
|
| 35 |
this.$image.on( 'load', this.onLoad.bind( this ) ); |
| 36 |
this.model.connect( this, { attributeChange: 'onAttributeChange' } ); |
| 37 |
|
| 38 |
|
| 39 |
this.$element.addClass( 've-ce-imageNode' ); |
| 40 |
}; |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
OO.mixinClass( ve.ce.ImageNode, ve.ce.FocusableNode ); |
| 45 |
|
| 46 |
OO.mixinClass( ve.ce.ImageNode, ve.ce.ResizableNode ); |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
ve.ce.ImageNode.static.getDescription = function ( model ) { |
| 55 |
return model.getAttribute( 'src' ); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ce.ImageNode.prototype.onAttributeChange = function ( key, from, to ) { |
| 69 |
switch ( key ) { |
| 70 |
case 'src': |
| 71 |
this.$image.prop( 'src', this.getResolvedAttribute( 'src' ) ); |
| 72 |
break; |
| 73 |
|
| 74 |
case 'width': |
| 75 |
case 'height': |
| 76 |
this.$image.css( key, to !== null ? to : '' ); |
| 77 |
break; |
| 78 |
} |
| 79 |
}; |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
ve.ce.ImageNode.prototype.onLoad = function () { |
| 87 |
if ( !this.model ) { |
| 88 |
|
| 89 |
|
| 90 |
return; |
| 91 |
} |
| 92 |
this.setOriginalDimensions( { |
| 93 |
width: this.$image.prop( 'naturalWidth' ), |
| 94 |
height: this.$image.prop( 'naturalHeight' ) |
| 95 |
} ); |
| 96 |
}; |