| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
ve.ce.MWImageNode = function VeCeMWImageNode( $focusable, $image, config ) { |
| 23 |
config = ve.extendObject( { |
| 24 |
enforceMax: false, |
| 25 |
minDimensions: { width: 1, height: 1 }, |
| 26 |
$bounding: this.$element |
| 27 |
}, config ); |
| 28 |
|
| 29 |
|
| 30 |
this.$image = $image; |
| 31 |
|
| 32 |
this.renderedDimensions = null; |
| 33 |
|
| 34 |
|
| 35 |
ve.ce.GeneratedContentNode.call( this ); |
| 36 |
|
| 37 |
|
| 38 |
ve.ce.FocusableNode.call( this, $focusable, config ); |
| 39 |
ve.ce.MWResizableNode.call( this, this.$image, config ); |
| 40 |
|
| 41 |
|
| 42 |
this.model.connect( this, { attributeChange: 'onAttributeChange' } ); |
| 43 |
|
| 44 |
|
| 45 |
this.updateMediaType(); |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
OO.inheritClass( ve.ce.MWImageNode, ve.ce.GeneratedContentNode ); |
| 51 |
|
| 52 |
OO.mixinClass( ve.ce.MWImageNode, ve.ce.FocusableNode ); |
| 53 |
|
| 54 |
|
| 55 |
OO.mixinClass( ve.ce.MWImageNode, ve.ce.ResizableNode ); |
| 56 |
|
| 57 |
OO.mixinClass( ve.ce.MWImageNode, ve.ce.MWResizableNode ); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ce.MWImageNode.static.primaryCommandName = 'media'; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ce.MWImageNode.static.getDescription = function ( model ) { |
| 69 |
const title = new mw.Title( model.getFilename() ); |
| 70 |
return title.getMainText(); |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ve.ce.MWImageNode.prototype.onAttributeChange = function () { |
| 84 |
this.update(); |
| 85 |
}; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
ve.ce.MWImageNode.prototype.onGeneratedContentNodeUpdate = function () { |
| 91 |
|
| 92 |
|
| 93 |
}; |
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
ve.ce.MWImageNode.prototype.generateContents = function () { |
| 99 |
const model = this.getModel(), |
| 100 |
height = model.getAttribute( 'height' ), |
| 101 |
mwData = model.getAttribute( 'mw' ) || {}, |
| 102 |
deferred = ve.createDeferred(); |
| 103 |
let width = model.getAttribute( 'width' ); |
| 104 |
|
| 105 |
|
| 106 |
if ( this.renderedDimensions && this.renderedDimensions.width > width ) { |
| 107 |
return deferred.reject().promise(); |
| 108 |
} |
| 109 |
|
| 110 |
let params; |
| 111 |
if ( mwData.thumbtime !== undefined ) { |
| 112 |
params = 'seek=' + mwData.thumbtime; |
| 113 |
} else if ( mwData.page !== undefined ) { |
| 114 |
params = 'page' + mwData.page + '-' + width + 'px'; |
| 115 |
|
| 116 |
width = undefined; |
| 117 |
} |
| 118 |
|
| 119 |
const xhr = ve.init.target.getContentApi( this.getModel().getDocument() ).get( { |
| 120 |
action: 'query', |
| 121 |
prop: 'imageinfo', |
| 122 |
iiprop: 'url', |
| 123 |
iiurlwidth: width, |
| 124 |
iiurlheight: height, |
| 125 |
iiurlparam: params, |
| 126 |
titles: this.getModel().getFilename() |
| 127 |
} ) |
| 128 |
.done( this.onParseSuccess.bind( this, deferred ) ) |
| 129 |
.fail( this.onParseError.bind( this, deferred ) ); |
| 130 |
|
| 131 |
return deferred.promise( { abort: xhr.abort } ); |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
ve.ce.MWImageNode.prototype.onParseSuccess = function ( deferred, response ) { |
| 141 |
const thumburl = ve.getProp( response.query.pages[ 0 ], 'imageinfo', 0, 'thumburl' ); |
| 142 |
if ( thumburl ) { |
| 143 |
deferred.resolve( thumburl ); |
| 144 |
} else { |
| 145 |
deferred.reject(); |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
ve.ce.MWImageNode.prototype.render = function ( generatedContents ) { |
| 153 |
this.$image.attr( 'src', generatedContents ); |
| 154 |
|
| 155 |
|
| 156 |
this.renderedDimensions = ve.copy( this.model.getScalable().getCurrentDimensions() ); |
| 157 |
if ( this.live ) { |
| 158 |
this.afterRender(); |
| 159 |
} |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
ve.ce.MWImageNode.prototype.onParseError = function ( deferred ) { |
| 169 |
deferred.reject(); |
| 170 |
}; |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
ve.ce.MWImageNode.prototype.updateMediaType = function () { |
| 176 |
this.$image.toggleClass( 've-ce-mwImageNode-audioPlayer', this.model.getMediaType() === 'AUDIO' ); |
| 177 |
}; |