| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const { Config } = require( 'mmv.bootstrap' ); |
| 19 |
const HtmlUtils = require( './mmv.HtmlUtils.js' ); |
| 20 |
const ViewLogger = require( './logging/mmv.logging.ViewLogger.js' ); |
| 21 |
const Api = require( './provider/mmv.provider.Api.js' ); |
| 22 |
const GuessedThumbnailInfo = require( './provider/mmv.provider.GuessedThumbnailInfo.js' ); |
| 23 |
const ImageProvider = require( './provider/mmv.provider.Image.js' ); |
| 24 |
const ImageInfo = require( './provider/mmv.provider.ImageInfo.js' ); |
| 25 |
const ThumbnailInfo = require( './provider/mmv.provider.ThumbnailInfo.js' ); |
| 26 |
const ImageModel = require( './model/mmv.model.Image.js' ); |
| 27 |
const License = require( './model/mmv.model.License.js' ); |
| 28 |
const TaskQueue = require( './model/mmv.model.TaskQueue.js' ); |
| 29 |
const Thumbnail = require( './model/mmv.model.Thumbnail.js' ); |
| 30 |
const ThumbnailWidth = require( './model/mmv.model.ThumbnailWidth.js' ); |
| 31 |
const Canvas = require( './ui/mmv.ui.canvas.js' ); |
| 32 |
const CanvasButtons = require( './ui/mmv.ui.canvasButtons.js' ); |
| 33 |
const Description = require( './ui/mmv.ui.description.js' ); |
| 34 |
const Dialog = require( './ui/mmv.ui.dialog.js' ); |
| 35 |
const UiElement = require( './ui/mmv.ui.js' ); |
| 36 |
const MetadataPanel = require( './ui/mmv.ui.metadataPanel.js' ); |
| 37 |
const MetadataPanelScroller = require( './ui/mmv.ui.metadataPanelScroller.js' ); |
| 38 |
const Permission = require( './ui/mmv.ui.permission.js' ); |
| 39 |
const ProgressBar = require( './ui/mmv.ui.progressBar.js' ); |
| 40 |
const StripeButtons = require( './ui/mmv.ui.stripeButtons.js' ); |
| 41 |
const TruncatableTextField = require( './ui/mmv.ui.truncatableTextField.js' ); |
| 42 |
const LightboxInterface = require( './mmv.lightboxinterface.js' ); |
| 43 |
const ThumbnailWidthCalculator = require( './mmv.ThumbnailWidthCalculator.js' ); |
| 44 |
const { extensions, useThumbnailGuessing } = require( './config.json' ); |
| 45 |
|
| 46 |
const router = require( 'mediawiki.router' ); |
| 47 |
let comingFromHashChange = false; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
class MultimediaViewer { |
| 54 |
constructor() { |
| 55 |
const apiCacheMaxAge = 86400; |
| 56 |
const apiCacheFiveMinutes = 300; |
| 57 |
const api = new mw.Api(); |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
this.imageProvider = new ImageProvider(); |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
this.imageInfoProvider = new ImageInfo( api, { |
| 70 |
language: Config.language(), |
| 71 |
maxage: apiCacheFiveMinutes |
| 72 |
} ); |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
this.thumbnailInfoProvider = new ThumbnailInfo( api, |
| 79 |
{ maxage: apiCacheMaxAge } ); |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
this.guessedThumbnailInfoProvider = new GuessedThumbnailInfo(); |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
this.currentIndex = 0; |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
this.router = router; |
| 98 |
this.setupRouter(); |
| 99 |
comingFromHashChange = false; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
this.ui = new LightboxInterface(); |
| 108 |
|
| 109 |
|
| 110 |
this.documentTitle = document.title; |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
this.viewLogger = new ViewLogger( window ); |
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
this.realThumbnailShown = false; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
initWithThumbs( thumbs ) { |
| 133 |
this.thumbs = thumbs; |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
resize() { |
| 140 |
const image = this.thumbs[ this.currentIndex ]; |
| 141 |
const ext = this.thumbs[ this.currentIndex ].filePageTitle.getExtension().toLowerCase(); |
| 142 |
|
| 143 |
this.preloadThumbnails(); |
| 144 |
|
| 145 |
if ( image ) { |
| 146 |
const imageWidths = this.ui.canvas.getCurrentImageWidths(); |
| 147 |
|
| 148 |
this.fetchThumbnailForLightboxImage( |
| 149 |
image, imageWidths.real |
| 150 |
).then( ( thumbnail, image2 ) => { |
| 151 |
|
| 152 |
image2.className = ext; |
| 153 |
this.setImage( thumbnail, image2, imageWidths ); |
| 154 |
}, ( error ) => { |
| 155 |
this.ui.canvas.showError( error ); |
| 156 |
} ); |
| 157 |
} |
| 158 |
|
| 159 |
this.ui.updateControls( this.thumbs.length > 1 ); |
| 160 |
} |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
setImage( thumbnail, imageElement, imageWidths ) { |
| 170 |
this.ui.canvas.setImageAndMaxDimensions( thumbnail, imageElement, imageWidths ); |
| 171 |
this.ui.updateControls( this.thumbs.length > 1 ); |
| 172 |
} |
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
loadImage( image ) { |
| 180 |
const $initialImage = $( image.thumbnail ).clone(); |
| 181 |
|
| 182 |
const pluginsPromise = this.loadExtensionPlugins( image.filePageTitle.getExtension().toLowerCase() ); |
| 183 |
|
| 184 |
this.currentIndex = image.index; |
| 185 |
|
| 186 |
this.currentImage = image; |
| 187 |
|
| 188 |
if ( !this.isOpen ) { |
| 189 |
$( document ).trigger( $.Event( 'mmv-setup-overlay' ) ); |
| 190 |
this.ui.open(); |
| 191 |
this.isOpen = true; |
| 192 |
} else { |
| 193 |
this.ui.empty(); |
| 194 |
} |
| 195 |
|
| 196 |
this.setTitle(); |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
$initialImage.hide() |
| 204 |
.removeAttr( 'style' ) |
| 205 |
.removeClass() |
| 206 |
.addClass( `mw-mmv-placeholder-image ${ image.filePageTitle.getExtension().toLowerCase() }` ); |
| 207 |
|
| 208 |
this.ui.canvas.set( image, $initialImage ); |
| 209 |
|
| 210 |
this.preloadImagesMetadata(); |
| 211 |
this.preloadThumbnails(); |
| 212 |
const imageWidths = this.ui.canvas.getCurrentImageWidths(); |
| 213 |
|
| 214 |
const imagePromise = this.fetchThumbnailForLightboxImage( image, imageWidths.real ); |
| 215 |
|
| 216 |
if ( imagePromise.state() === 'pending' ) { |
| 217 |
this.displayPlaceholderThumbnail( image, $initialImage, imageWidths ); |
| 218 |
} |
| 219 |
this.resetThumbnailStates(); |
| 220 |
this.setupProgressBar( image, imagePromise, imageWidths.real ); |
| 221 |
|
| 222 |
const metadataPromise = this.fetchSizeIndependentLightboxInfo( image.filePageTitle ); |
| 223 |
|
| 224 |
imagePromise.then( |
| 225 |
|
| 226 |
( thumbnail, imageElement ) => { |
| 227 |
if ( this.currentIndex !== image.index ) { |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
|
| 232 |
imageElement.className = `mw-mmv-final-image ${ image.filePageTitle.getExtension().toLowerCase() }`; |
| 233 |
imageElement.alt = image.alt; |
| 234 |
|
| 235 |
$.when( metadataPromise, pluginsPromise ).then( ( imageInfo ) => { |
| 236 |
$( document ).trigger( $.Event( 'mmv-metadata', { viewer: this, image, imageInfo } ) ); |
| 237 |
} ); |
| 238 |
|
| 239 |
this.displayRealThumbnail( thumbnail, imageElement, imageWidths ); |
| 240 |
}, |
| 241 |
|
| 242 |
( error ) => { |
| 243 |
this.ui.canvas.showError( error ); |
| 244 |
return $.Deferred().reject( error ); |
| 245 |
} |
| 246 |
); |
| 247 |
|
| 248 |
metadataPromise.then( |
| 249 |
|
| 250 |
( imageInfo ) => { |
| 251 |
if ( this.currentIndex !== image.index ) { |
| 252 |
return; |
| 253 |
} |
| 254 |
|
| 255 |
this.ui.panel.setImageInfo( image, imageInfo ); |
| 256 |
|
| 257 |
|
| 258 |
this.ui.setFileReuseData( imageInfo, image.caption, image.alt ); |
| 259 |
}, |
| 260 |
|
| 261 |
( error ) => { |
| 262 |
if ( this.currentIndex === image.index ) { |
| 263 |
|
| 264 |
|
| 265 |
this.ui.panel.showError( image.caption ? |
| 266 |
HtmlUtils.htmlToTextWithTags( image.caption ) : |
| 267 |
image.filePageTitle.getNameText(), error ); |
| 268 |
} |
| 269 |
|
| 270 |
return $.Deferred().reject( error ); |
| 271 |
} |
| 272 |
); |
| 273 |
|
| 274 |
$.when( imagePromise, metadataPromise ).then( () => { |
| 275 |
if ( this.currentIndex !== image.index ) { |
| 276 |
return; |
| 277 |
} |
| 278 |
|
| 279 |
this.ui.panel.scroller.animateMetadataOnce(); |
| 280 |
} ); |
| 281 |
} |
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
loadImageByTitle( title, position ) { |
| 290 |
if ( !this.thumbs || !this.thumbs.length ) { |
| 291 |
return; |
| 292 |
} |
| 293 |
|
| 294 |
const thumb = this.thumbs.find( ( t ) => t.filePageTitle.getPrefixedText() === title.getPrefixedText() && |
| 295 |
( !position || t.position === position ) |
| 296 |
); |
| 297 |
|
| 298 |
if ( !thumb ) { |
| 299 |
this.onTitleNotFound( title ); |
| 300 |
return; |
| 301 |
} |
| 302 |
|
| 303 |
this.loadImage( thumb ); |
| 304 |
} |
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
onTitleNotFound( title ) { |
| 314 |
this.close(); |
| 315 |
const text = mw.msg( 'multimediaviewer-file-not-found-error', title.getMainText() ); |
| 316 |
const $link = $( '<a>' ).text( mw.msg( 'multimediaviewer-file-page' ) ).prop( 'href', title.getUrl() ); |
| 317 |
const $message = $( '<div>' ).text( text ).append( $( '<br>' ) ).append( $link ); |
| 318 |
mw.notify( $message ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
resetThumbnailStates() { |
| 325 |
this.realThumbnailShown = false; |
| 326 |
} |
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
displayRealThumbnail( thumbnail, imageElement, imageWidths ) { |
| 336 |
this.realThumbnailShown = true; |
| 337 |
this.setImage( thumbnail, imageElement, imageWidths ); |
| 338 |
this.viewLogger.attach( thumbnail.url ); |
| 339 |
} |
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
displayPlaceholderThumbnail( image, $initialImage, imageWidths, recursion ) { |
| 350 |
const size = { width: image.originalWidth, height: image.originalHeight }; |
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
if ( this.realThumbnailShown ) { |
| 356 |
return; |
| 357 |
} |
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
if ( !size.width || !size.height ) { |
| 364 |
if ( recursion ) { |
| 365 |
|
| 366 |
|
| 367 |
throw new Error( 'MediaViewer internal error: displayPlaceholderThumbnail recursion' ); |
| 368 |
} |
| 369 |
this.imageInfoProvider.get( image.filePageTitle ).done( ( imageInfo ) => { |
| 370 |
|
| 371 |
if ( this.currentIndex === image.index ) { |
| 372 |
image.originalWidth = imageInfo.width; |
| 373 |
image.originalHeight = imageInfo.height; |
| 374 |
this.displayPlaceholderThumbnail( image, $initialImage, imageWidths, true ); |
| 375 |
} |
| 376 |
} ); |
| 377 |
} else { |
| 378 |
this.ui.canvas.maybeDisplayPlaceholder( size, $initialImage, imageWidths ); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
setupProgressBar( image, imagePromise, imageWidth ) { |
| 391 |
const progressBar = this.ui.panel.progressBar; |
| 392 |
const key = `${ image.filePageTitle.getPrefixedDb() }|${ imageWidth }`; |
| 393 |
|
| 394 |
if ( !this.progressCache[ key ] ) { |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
progressBar.jumpTo( 0 ); |
| 399 |
progressBar.animateTo( 5 ); |
| 400 |
this.progressCache[ key ] = 5; |
| 401 |
} else { |
| 402 |
progressBar.jumpTo( this.progressCache[ key ] ); |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
imagePromise.then( |
| 407 |
|
| 408 |
( thumbnail, imageElement ) => { |
| 409 |
this.progressCache[ key ] = 100; |
| 410 |
if ( this.currentIndex === image.index ) { |
| 411 |
|
| 412 |
progressBar.animateTo( 100 ); |
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
progressBar.hide(); |
| 417 |
} |
| 418 |
|
| 419 |
return $.Deferred().resolve( thumbnail, imageElement ); |
| 420 |
}, |
| 421 |
|
| 422 |
( error ) => { |
| 423 |
this.progressCache[ key ] = 100; |
| 424 |
|
| 425 |
if ( this.currentIndex === image.index ) { |
| 426 |
|
| 427 |
progressBar.hide(); |
| 428 |
} |
| 429 |
|
| 430 |
return $.Deferred().reject( error ); |
| 431 |
}, |
| 432 |
|
| 433 |
( progress ) => { |
| 434 |
|
| 435 |
|
| 436 |
if ( progress >= 5 && progress < 100 ) { |
| 437 |
this.progressCache[ key ] = progress; |
| 438 |
|
| 439 |
|
| 440 |
if ( this.currentIndex === image.index ) { |
| 441 |
progressBar.animateTo( progress ); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
return progress; |
| 446 |
} |
| 447 |
); |
| 448 |
} |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
|
| 457 |
|
| 458 |
eachPreloadableLightboxIndex( callback ) { |
| 459 |
for ( let i = 0; i <= this.preloadDistance; i++ ) { |
| 460 |
if ( this.currentIndex + i < this.thumbs.length ) { |
| 461 |
callback( |
| 462 |
this.currentIndex + i, |
| 463 |
this.thumbs[ this.currentIndex + i ] |
| 464 |
); |
| 465 |
} |
| 466 |
if ( i && this.currentIndex - i >= 0 ) { |
| 467 |
callback( |
| 468 |
this.currentIndex - i, |
| 469 |
this.thumbs[ this.currentIndex - i ] |
| 470 |
); |
| 471 |
} |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
pushLightboxImagesIntoQueue( taskFactory ) { |
| 484 |
const queue = new TaskQueue(); |
| 485 |
|
| 486 |
this.eachPreloadableLightboxIndex( ( i, lightboxImage ) => { |
| 487 |
queue.push( taskFactory( lightboxImage ) ); |
| 488 |
} ); |
| 489 |
|
| 490 |
return queue; |
| 491 |
} |
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
cancelImageMetadataPreloading() { |
| 497 |
if ( this.metadataPreloadQueue ) { |
| 498 |
this.metadataPreloadQueue.cancel(); |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
cancelThumbnailsPreloading() { |
| 506 |
if ( this.thumbnailPreloadQueue ) { |
| 507 |
this.thumbnailPreloadQueue.cancel(); |
| 508 |
} |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
preloadImagesMetadata() { |
| 517 |
this.cancelImageMetadataPreloading(); |
| 518 |
|
| 519 |
this.metadataPreloadQueue = this.pushLightboxImagesIntoQueue( ( lightboxImage ) => () => this.fetchSizeIndependentLightboxInfo( lightboxImage.filePageTitle ) ); |
| 520 |
|
| 521 |
this.metadataPreloadQueue.execute(); |
| 522 |
} |
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
preloadThumbnails() { |
| 530 |
this.cancelThumbnailsPreloading(); |
| 531 |
|
| 532 |
this.thumbnailPreloadQueue = this.pushLightboxImagesIntoQueue( ( lightboxImage ) => () => { |
| 533 |
|
| 534 |
|
| 535 |
if ( !this.isOpen ) { |
| 536 |
return; |
| 537 |
} |
| 538 |
|
| 539 |
const imageWidths = this.ui.canvas.getLightboxImageWidths( lightboxImage ); |
| 540 |
|
| 541 |
return this.fetchThumbnailForLightboxImage( lightboxImage, imageWidths.real ); |
| 542 |
} ); |
| 543 |
|
| 544 |
this.thumbnailPreloadQueue.execute(); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
fetchSizeIndependentLightboxInfo( fileTitle ) { |
| 555 |
return this.imageInfoProvider.get( fileTitle ); |
| 556 |
} |
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
|
| 564 |
|
| 565 |
fetchThumbnailForLightboxImage( image, width ) { |
| 566 |
return this.fetchThumbnail( |
| 567 |
image.filePageTitle, |
| 568 |
width, |
| 569 |
image.src, |
| 570 |
image.originalWidth, |
| 571 |
image.originalHeight |
| 572 |
); |
| 573 |
} |
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
fetchThumbnail( fileTitle, width, sampleUrl, originalWidth, originalHeight, useThumbnailGuessing0 = useThumbnailGuessing ) { |
| 589 |
let guessing = false; |
| 590 |
const combinedDeferred = $.Deferred(); |
| 591 |
let thumbnailPromise; |
| 592 |
let imagePromise; |
| 593 |
|
| 594 |
if ( fileTitle.getExtension().toLowerCase() !== 'svg' && originalWidth && width > originalWidth ) { |
| 595 |
|
| 596 |
width = originalWidth; |
| 597 |
} |
| 598 |
|
| 599 |
if ( sampleUrl && originalWidth && originalHeight && useThumbnailGuessing0 ) { |
| 600 |
guessing = true; |
| 601 |
thumbnailPromise = this.guessedThumbnailInfoProvider.get( |
| 602 |
fileTitle, sampleUrl, width, originalWidth, originalHeight |
| 603 |
).then( null, () => this.thumbnailInfoProvider.get( fileTitle, sampleUrl, width ) ); |
| 604 |
} else { |
| 605 |
thumbnailPromise = this.thumbnailInfoProvider.get( fileTitle, sampleUrl, width ); |
| 606 |
} |
| 607 |
|
| 608 |
imagePromise = thumbnailPromise.then( ( thumbnail ) => this.imageProvider.get( thumbnail.url ) ); |
| 609 |
|
| 610 |
if ( guessing ) { |
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
imagePromise = imagePromise |
| 615 |
.then( null, () => this.thumbnailInfoProvider.get( fileTitle, sampleUrl, width ) |
| 616 |
.then( ( thumbnail ) => this.imageProvider.get( thumbnail.url ) ) ); |
| 617 |
} |
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
$.when( thumbnailPromise, imagePromise ).then( combinedDeferred.resolve, combinedDeferred.reject ); |
| 622 |
imagePromise.then( null, null, ( arg, progress ) => { |
| 623 |
combinedDeferred.notify( progress ); |
| 624 |
} ); |
| 625 |
return combinedDeferred; |
| 626 |
} |
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
loadIndex( index ) { |
| 634 |
if ( index < this.thumbs.length && index >= 0 ) { |
| 635 |
this.viewLogger.recordViewDuration(); |
| 636 |
|
| 637 |
const thumb = this.thumbs[ index ]; |
| 638 |
this.loadImage( thumb ); |
| 639 |
router.navigateTo( null, { |
| 640 |
path: Config.getMediaHash( thumb.filePageTitle, thumb.position ), |
| 641 |
useReplaceState: true |
| 642 |
} ); |
| 643 |
} |
| 644 |
} |
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
firstImage() { |
| 650 |
this.loadIndex( 0 ); |
| 651 |
} |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
lastImage() { |
| 657 |
this.loadIndex( this.thumbs.length - 1 ); |
| 658 |
} |
| 659 |
|
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
nextImage() { |
| 664 |
if ( this.currentIndex === this.thumbs.length - 1 ) { |
| 665 |
this.firstImage(); |
| 666 |
} else { |
| 667 |
this.loadIndex( this.currentIndex + 1 ); |
| 668 |
} |
| 669 |
} |
| 670 |
|
| 671 |
|
| 672 |
|
| 673 |
|
| 674 |
prevImage() { |
| 675 |
if ( this.currentIndex === 0 ) { |
| 676 |
this.lastImage(); |
| 677 |
} else { |
| 678 |
this.loadIndex( this.currentIndex - 1 ); |
| 679 |
} |
| 680 |
} |
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
close() { |
| 686 |
this.viewLogger.recordViewDuration(); |
| 687 |
this.viewLogger.unattach(); |
| 688 |
|
| 689 |
if ( comingFromHashChange ) { |
| 690 |
comingFromHashChange = false; |
| 691 |
} else { |
| 692 |
this.router.back(); |
| 693 |
} |
| 694 |
|
| 695 |
document.title = this.createDocumentTitle( null ); |
| 696 |
|
| 697 |
|
| 698 |
$( document ).trigger( $.Event( 'mmv-cleanup-overlay' ) ); |
| 699 |
|
| 700 |
this.isOpen = false; |
| 701 |
} |
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
|
| 706 |
setupRouter() { |
| 707 |
|
| 708 |
this.router.addRoute( /.*$/, () => { |
| 709 |
if ( this.isOpen ) { |
| 710 |
comingFromHashChange = true; |
| 711 |
document.title = this.createDocumentTitle( null ); |
| 712 |
if ( this.ui ) { |
| 713 |
|
| 714 |
this.ui.unattach(); |
| 715 |
} else { |
| 716 |
this.close(); |
| 717 |
} |
| 718 |
} |
| 719 |
} ); |
| 720 |
} |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
setTitle() { |
| 726 |
|
| 727 |
document.title = this.createDocumentTitle( this.currentImage && this.currentImage.filePageTitle ); |
| 728 |
} |
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
|
| 734 |
|
| 735 |
|
| 736 |
|
| 737 |
createDocumentTitle( imageTitle ) { |
| 738 |
if ( imageTitle ) { |
| 739 |
return `${ imageTitle.getNameText() } - ${ this.documentTitle }`; |
| 740 |
} else { |
| 741 |
return this.documentTitle; |
| 742 |
} |
| 743 |
} |
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
|
| 752 |
|
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
|
| 769 |
|
| 770 |
|
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
|
| 779 |
setupEventHandlers() { |
| 780 |
this.ui.connect( this, { |
| 781 |
first: 'firstImage', |
| 782 |
last: 'lastImage', |
| 783 |
next: 'nextImage', |
| 784 |
prev: 'prevImage' |
| 785 |
} ); |
| 786 |
|
| 787 |
$( document ).on( 'mmv-close.mmvp', () => { |
| 788 |
this.close(); |
| 789 |
} ).on( 'mmv-resize-end.mmvp', () => { |
| 790 |
this.resize(); |
| 791 |
} ).on( 'mmv-request-thumbnail.mmvp', ( e, size ) => { |
| 792 |
if ( this.currentImage && this.currentImage.filePageTitle ) { |
| 793 |
return this.thumbnailInfoProvider.get( this.currentImage.filePageTitle, this.currentImage.src, size ); |
| 794 |
} else { |
| 795 |
return $.Deferred().reject(); |
| 796 |
} |
| 797 |
} ).on( 'mmv-viewfile.mmvp', () => { |
| 798 |
this.imageInfoProvider.get( this.currentImage.filePageTitle ).done( ( imageInfo ) => { |
| 799 |
document.location = imageInfo.url; |
| 800 |
} ); |
| 801 |
} ); |
| 802 |
} |
| 803 |
|
| 804 |
|
| 805 |
|
| 806 |
|
| 807 |
cleanupEventHandlers() { |
| 808 |
$( document ).off( 'mmv-close.mmvp mmv-resize-end.mmvp' ); |
| 809 |
|
| 810 |
this.ui.disconnect( this ); |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
|
| 819 |
loadExtensionPlugins( extension ) { |
| 820 |
const deferred = $.Deferred(); |
| 821 |
|
| 822 |
if ( !( extension in extensions ) || extensions[ extension ] === 'default' ) { |
| 823 |
return deferred.resolve(); |
| 824 |
} |
| 825 |
|
| 826 |
mw.loader.using( extensions[ extension ], () => { |
| 827 |
deferred.resolve(); |
| 828 |
} ); |
| 829 |
|
| 830 |
return deferred; |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
|
| 841 |
MultimediaViewer.prototype.progressCache = {}; |
| 842 |
|
| 843 |
|
| 844 |
|
| 845 |
|
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
MultimediaViewer.prototype.preloadDistance = 1; |
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
MultimediaViewer.prototype.metadataPreloadQueue = null; |
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
MultimediaViewer.prototype.thumbnailPreloadQueue = null; |
| 865 |
|
| 866 |
module.exports = { |
| 867 |
Api, |
| 868 |
Canvas, |
| 869 |
CanvasButtons, |
| 870 |
Description, |
| 871 |
Dialog, |
| 872 |
GuessedThumbnailInfo, |
| 873 |
HtmlUtils, |
| 874 |
ImageInfo, |
| 875 |
ImageModel, |
| 876 |
ImageProvider, |
| 877 |
License, |
| 878 |
LightboxInterface, |
| 879 |
MetadataPanel, |
| 880 |
MetadataPanelScroller, |
| 881 |
MultimediaViewer, |
| 882 |
Permission, |
| 883 |
ProgressBar, |
| 884 |
StripeButtons, |
| 885 |
TaskQueue, |
| 886 |
Thumbnail, |
| 887 |
ThumbnailInfo, |
| 888 |
ThumbnailWidth, |
| 889 |
ThumbnailWidthCalculator, |
| 890 |
TruncatableTextField, |
| 891 |
UiElement, |
| 892 |
ViewLogger |
| 893 |
}; |