| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
const Description = require( './mmv.ui.description.js' ); |
| 19 |
const UiElement = require( './mmv.ui.js' ); |
| 20 |
const MetadataPanelScroller = require( './mmv.ui.metadataPanelScroller.js' ); |
| 21 |
const Permission = require( './mmv.ui.permission.js' ); |
| 22 |
const ProgressBar = require( './mmv.ui.progressBar.js' ); |
| 23 |
const StripeButtons = require( './mmv.ui.stripeButtons.js' ); |
| 24 |
const TruncatableTextField = require( './mmv.ui.truncatableTextField.js' ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
class MetadataPanel extends UiElement { |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
constructor( $container, $aboveFold ) { |
| 37 |
super( $container ); |
| 38 |
|
| 39 |
this.$aboveFold = $aboveFold; |
| 40 |
|
| 41 |
this.initializeHeader(); |
| 42 |
this.initializeImageMetadata(); |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
isFullscreened() { |
| 51 |
return $( this.$container ).closest( '.jq-fullscreened' ).length > 0; |
| 52 |
} |
| 53 |
|
| 54 |
attach() { |
| 55 |
this.scroller.attach(); |
| 56 |
this.buttons.attach(); |
| 57 |
this.title.attach(); |
| 58 |
this.creditField.attach(); |
| 59 |
|
| 60 |
this.$title |
| 61 |
.add( this.$authorAndSource ) |
| 62 |
.add( this.title.$ellipsis ) |
| 63 |
.add( this.creditField.$ellipsis ) |
| 64 |
.on( 'click.mmv-mp', ( e ) => { |
| 65 |
const clickTargetIsLink = $( e.target ).is( 'a' ); |
| 66 |
const clickTargetIsTruncated = !!$( e.target ).closest( '.mw-mmv-ttf-truncated' ).length; |
| 67 |
const someTextIsExpanded = !!$( e.target ).closest( '.mw-mmv-untruncated' ).length; |
| 68 |
|
| 69 |
if ( !clickTargetIsLink && |
| 70 |
clickTargetIsTruncated && |
| 71 |
!someTextIsExpanded |
| 72 |
) { |
| 73 |
if ( this.isFullscreened() ) { |
| 74 |
this.revealTruncatedText(); |
| 75 |
} else { |
| 76 |
this.scroller.toggle( 'up' ); |
| 77 |
} |
| 78 |
} |
| 79 |
} ); |
| 80 |
|
| 81 |
$( this.$container ).on( 'mmv-metadata-open.mmv-mp mmv-metadata-reveal-truncated-text.mmv-mp', () => { |
| 82 |
this.revealTruncatedText(); |
| 83 |
} ).on( 'mmv-metadata-close.mmv-mp', () => { |
| 84 |
this.hideTruncatedText(); |
| 85 |
} ).on( 'mouseleave.mmv-mp', () => { |
| 86 |
if ( this.isFullscreened() ) { |
| 87 |
const duration = parseFloat( this.$container.css( 'transition-duration' ) ) * 1000 || 0; |
| 88 |
this.panelShrinkTimeout = setTimeout( () => { |
| 89 |
this.hideTruncatedText(); |
| 90 |
}, duration ); |
| 91 |
} |
| 92 |
} ).on( 'mouseenter.mmv-mp', () => { |
| 93 |
clearTimeout( this.panelShrinkTimeout ); |
| 94 |
} ).on( 'mmv-permission-grow.mmv-mp', () => { |
| 95 |
this.$permissionLink |
| 96 |
.text( mw.msg( 'multimediaviewer-permission-link-hide' ) ); |
| 97 |
} ).on( 'mmv-permission-shrink.mmv-mp', () => { |
| 98 |
this.$permissionLink |
| 99 |
.text( mw.msg( 'multimediaviewer-permission-link' ) ); |
| 100 |
} ); |
| 101 |
|
| 102 |
this.handleEvent( 'fullscreenchange.lip', () => { |
| 103 |
this.hideTruncatedText(); |
| 104 |
} ); |
| 105 |
} |
| 106 |
|
| 107 |
unattach() { |
| 108 |
this.scroller.freezeHeight(); |
| 109 |
|
| 110 |
this.$title |
| 111 |
.add( this.title.$ellipsis ) |
| 112 |
.add( this.$authorAndSource ) |
| 113 |
.add( this.creditField.$ellipsis ) |
| 114 |
.off( 'click.mmv-mp' ); |
| 115 |
|
| 116 |
$( this.$container ).off( '.mmv-mp' ); |
| 117 |
|
| 118 |
this.scroller.unattach(); |
| 119 |
this.buttons.unattach(); |
| 120 |
this.clearEvents(); |
| 121 |
} |
| 122 |
|
| 123 |
empty() { |
| 124 |
this.scroller.freezeHeight(); |
| 125 |
this.scroller.empty(); |
| 126 |
|
| 127 |
this.buttons.empty(); |
| 128 |
|
| 129 |
this.description.empty(); |
| 130 |
this.permission.empty(); |
| 131 |
|
| 132 |
this.$title.removeClass( 'error' ); |
| 133 |
this.title.empty(); |
| 134 |
this.creditField.empty(); |
| 135 |
|
| 136 |
this.$license.empty().prop( 'href', '#' ); |
| 137 |
this.$licenseLi.addClass( 'empty' ); |
| 138 |
this.$permissionLink.hide(); |
| 139 |
this.$restrictions.children().hide(); |
| 140 |
|
| 141 |
this.$filename.empty(); |
| 142 |
this.$filenamePrefix.empty(); |
| 143 |
this.$filenameLi.addClass( 'empty' ); |
| 144 |
|
| 145 |
this.$datetimeCreated.empty(); |
| 146 |
this.$datetimeCreatedLi.addClass( 'empty' ); |
| 147 |
this.$datetimeUpdated.empty(); |
| 148 |
this.$datetimeUpdatedLi.addClass( 'empty' ); |
| 149 |
|
| 150 |
this.$location.empty(); |
| 151 |
this.$locationLi.addClass( 'empty' ); |
| 152 |
|
| 153 |
this.progressBar.empty(); |
| 154 |
|
| 155 |
this.$container.removeClass( 'mw-mmv-untruncated' ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
initializeHeader() { |
| 163 |
this.progressBar = new ProgressBar( this.$aboveFold ); |
| 164 |
|
| 165 |
this.scroller = new MetadataPanelScroller( this.$container, this.$aboveFold ); |
| 166 |
|
| 167 |
this.$titleDiv = $( '<div>' ) |
| 168 |
.addClass( 'mw-mmv-title-contain' ) |
| 169 |
.appendTo( this.$aboveFold ); |
| 170 |
|
| 171 |
this.$container.append( this.$aboveFold ); |
| 172 |
|
| 173 |
this.initializeButtons(); |
| 174 |
this.initializeTitle(); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
initializeTitle() { |
| 181 |
this.$titlePara = $( '<p>' ) |
| 182 |
.addClass( 'mw-mmv-title-para mw-parser-output' ) |
| 183 |
.appendTo( this.$aboveFold ); |
| 184 |
|
| 185 |
this.$title = $( '<span>' ) |
| 186 |
.addClass( 'mw-mmv-title' ); |
| 187 |
|
| 188 |
this.title = new TruncatableTextField( this.$titlePara, this.$title, { |
| 189 |
styles: [ 'mw-mmv-title-small', 'mw-mmv-title-smaller' ] |
| 190 |
} ); |
| 191 |
this.title.setTitle( |
| 192 |
mw.message( 'multimediaviewer-title-popup-text' ), |
| 193 |
mw.message( 'multimediaviewer-title-popup-text-more' ) |
| 194 |
); |
| 195 |
|
| 196 |
this.$title.add( this.title.$ellipsis ); |
| 197 |
} |
| 198 |
|
| 199 |
initializeButtons() { |
| 200 |
this.buttons = new StripeButtons( this.$titleDiv ); |
| 201 |
} |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
initializeImageMetadata() { |
| 207 |
this.$container.addClass( 'mw-mmv-ttf-ellipsis-container' ); |
| 208 |
|
| 209 |
this.$imageMetadata = $( '<div>' ) |
| 210 |
.addClass( 'mw-mmv-image-metadata' ) |
| 211 |
.appendTo( this.$container ); |
| 212 |
|
| 213 |
this.$imageMetadataLeft = $( '<div>' ) |
| 214 |
.addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-desc-column' ) |
| 215 |
.appendTo( this.$imageMetadata ); |
| 216 |
|
| 217 |
this.$imageMetadataRight = $( '<div>' ) |
| 218 |
.addClass( 'mw-mmv-image-metadata-column mw-mmv-image-metadata-links-column' ) |
| 219 |
.appendTo( this.$imageMetadata ); |
| 220 |
|
| 221 |
this.initializeCredit(); |
| 222 |
this.description = new Description( this.$imageMetadataLeft ); |
| 223 |
this.permission = new Permission( this.$imageMetadataLeft, this.scroller ); |
| 224 |
this.initializeImageLinks(); |
| 225 |
} |
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
initializeCredit() { |
| 231 |
this.$credit = $( '<p>' ) |
| 232 |
.addClass( 'mw-mmv-credit empty' ) |
| 233 |
.appendTo( this.$imageMetadataLeft ); |
| 234 |
|
| 235 |
|
| 236 |
this.$authorAndSource = $( '<span>' ) |
| 237 |
.addClass( 'mw-mmv-source-author' ); |
| 238 |
|
| 239 |
this.creditField = new TruncatableTextField( |
| 240 |
this.$credit, |
| 241 |
this.$authorAndSource, |
| 242 |
{ styles: [] } |
| 243 |
); |
| 244 |
|
| 245 |
this.creditField.setTitle( |
| 246 |
mw.message( 'multimediaviewer-credit-popup-text' ), |
| 247 |
mw.message( 'multimediaviewer-credit-popup-text-more' ) |
| 248 |
); |
| 249 |
|
| 250 |
this.$authorAndSource.add( this.creditField.$ellipsis ); |
| 251 |
} |
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
initializeImageLinks() { |
| 257 |
this.$imageLinkDiv = $( '<div>' ) |
| 258 |
.addClass( 'mw-mmv-image-links-div' ) |
| 259 |
.appendTo( this.$imageMetadataRight ); |
| 260 |
|
| 261 |
this.$imageLinks = $( '<ul>' ) |
| 262 |
.addClass( 'mw-mmv-image-links' ) |
| 263 |
.appendTo( this.$imageLinkDiv ); |
| 264 |
|
| 265 |
this.initializeLicense(); |
| 266 |
this.initializeFilename(); |
| 267 |
this.initializeDatetime(); |
| 268 |
this.initializeLocation(); |
| 269 |
} |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
|
| 274 |
initializeLicense() { |
| 275 |
this.$licenseLi = $( '<li>' ) |
| 276 |
.addClass( 'mw-mmv-license-li empty' ) |
| 277 |
.appendTo( this.$imageLinks ); |
| 278 |
|
| 279 |
this.$license = $( '<a>' ) |
| 280 |
.addClass( 'mw-mmv-license' ) |
| 281 |
.prop( 'href', '#' ) |
| 282 |
.appendTo( this.$licenseLi ); |
| 283 |
|
| 284 |
this.$restrictions = $( '<span>' ) |
| 285 |
.addClass( 'mw-mmv-restrictions' ) |
| 286 |
.appendTo( this.$licenseLi ); |
| 287 |
|
| 288 |
this.$permissionLink = $( '<span>' ) |
| 289 |
.addClass( 'mw-mmv-permission-link mw-mmv-label' ) |
| 290 |
.text( mw.msg( 'multimediaviewer-permission-link' ) ) |
| 291 |
.appendTo( this.$licenseLi ) |
| 292 |
.hide() |
| 293 |
.on( 'click', () => { |
| 294 |
if ( this.permission.isFullSize() ) { |
| 295 |
this.permission.shrink(); |
| 296 |
} else { |
| 297 |
this.permission.grow(); |
| 298 |
this.scroller.toggle( 'up' ); |
| 299 |
} |
| 300 |
return false; |
| 301 |
} ); |
| 302 |
} |
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
initializeFilename() { |
| 308 |
this.$filenameLi = $( '<li>' ) |
| 309 |
.addClass( 'mw-mmv-filename-li empty' ) |
| 310 |
.appendTo( this.$imageLinks ); |
| 311 |
|
| 312 |
this.$filenamePrefix = $( '<span>' ) |
| 313 |
.addClass( 'mw-mmv-filename-prefix' ) |
| 314 |
.appendTo( this.$filenameLi ); |
| 315 |
|
| 316 |
this.$filename = $( '<span>' ) |
| 317 |
.addClass( 'mw-mmv-filename' ) |
| 318 |
.appendTo( this.$filenameLi ); |
| 319 |
} |
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
initializeDatetime() { |
| 325 |
this.$datetimeCreatedLi = $( '<li>' ) |
| 326 |
.addClass( 'mw-mmv-datetime-li empty' ) |
| 327 |
.appendTo( this.$imageLinks ); |
| 328 |
|
| 329 |
this.$datetimeCreated = $( '<span>' ) |
| 330 |
.addClass( 'mw-mmv-datetime' ) |
| 331 |
.appendTo( this.$datetimeCreatedLi ); |
| 332 |
|
| 333 |
this.$datetimeUpdatedLi = $( '<li>' ) |
| 334 |
.addClass( 'mw-mmv-datetime-li empty' ) |
| 335 |
.appendTo( this.$imageLinks ); |
| 336 |
|
| 337 |
this.$datetimeUpdated = $( '<span>' ) |
| 338 |
.addClass( 'mw-mmv-datetime' ) |
| 339 |
.appendTo( this.$datetimeUpdatedLi ); |
| 340 |
} |
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
initializeLocation() { |
| 346 |
this.$locationLi = $( '<li>' ) |
| 347 |
.addClass( 'mw-mmv-location-li empty' ) |
| 348 |
.appendTo( this.$imageLinks ); |
| 349 |
|
| 350 |
this.$location = $( '<a>' ) |
| 351 |
.addClass( 'mw-mmv-location' ) |
| 352 |
.appendTo( this.$locationLi ); |
| 353 |
} |
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
setTitle( image, imageData ) { |
| 367 |
let title; |
| 368 |
|
| 369 |
if ( image.caption ) { |
| 370 |
title = image.caption; |
| 371 |
} else if ( imageData.description ) { |
| 372 |
title = imageData.description; |
| 373 |
} else { |
| 374 |
title = image.filePageTitle.getNameText(); |
| 375 |
} |
| 376 |
|
| 377 |
this.title.set( title ); |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
setFileName( filename ) { |
| 386 |
this.$filenamePrefix.text( |
| 387 |
mw.config.get( 'wgFormattedNamespaces' )[ |
| 388 |
mw.config.get( 'wgNamespaceIds' ).file |
| 389 |
] + ':' |
| 390 |
); |
| 391 |
this.$filename.text( filename ); |
| 392 |
|
| 393 |
this.$filenameLi.removeClass( 'empty' ); |
| 394 |
} |
| 395 |
|
| 396 |
|
| 397 |
|
| 398 |
|
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
|
| 404 |
|
| 405 |
setCredit( attribution, source, author, authorCount, filepageUrl ) { |
| 406 |
|
| 407 |
if ( attribution && ( authorCount <= 1 || !authorCount ) ) { |
| 408 |
this.creditField.set( this.wrapAttribution( attribution ) ); |
| 409 |
} else if ( author && source ) { |
| 410 |
this.creditField.set( |
| 411 |
mw.message( |
| 412 |
'multimediaviewer-credit', |
| 413 |
this.wrapAuthor( author, authorCount, filepageUrl ), |
| 414 |
this.wrapSource( source ) |
| 415 |
).plain() |
| 416 |
); |
| 417 |
} else if ( author ) { |
| 418 |
this.creditField.set( this.wrapAuthor( author, authorCount, filepageUrl ) ); |
| 419 |
} else if ( source ) { |
| 420 |
this.creditField.set( this.wrapSource( source ) ); |
| 421 |
} else { |
| 422 |
this.creditField.set( |
| 423 |
$( '<a>' ) |
| 424 |
.addClass( 'mw-mmv-credit-fallback' ) |
| 425 |
.prop( 'href', filepageUrl ) |
| 426 |
.text( mw.message( 'multimediaviewer-credit-fallback' ).plain() ) |
| 427 |
.get( 0 ).outerHTML |
| 428 |
); |
| 429 |
} |
| 430 |
|
| 431 |
this.$credit.removeClass( 'empty' ); |
| 432 |
} |
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
wrapSource( source ) { |
| 441 |
return $( '<span>' ) |
| 442 |
.addClass( 'mw-mmv-source' ) |
| 443 |
.append( $.parseHTML( source ) ) |
| 444 |
.get( 0 ).outerHTML; |
| 445 |
} |
| 446 |
|
| 447 |
|
| 448 |
|
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
wrapAuthor( author, authorCount, filepageUrl ) { |
| 456 |
const $wrapper = $( '<span>' ) |
| 457 |
.addClass( 'mw-mmv-author' ); |
| 458 |
|
| 459 |
if ( authorCount > 1 ) { |
| 460 |
const $moreLink = $( '<a>' ) |
| 461 |
.addClass( 'mw-mmv-more-authors' ) |
| 462 |
.text( mw.msg( 'multimediaviewer-multiple-authors', authorCount - 1 ) ) |
| 463 |
.attr( 'href', filepageUrl ); |
| 464 |
$wrapper.append( mw.message( |
| 465 |
'multimediaviewer-multiple-authors-combine', |
| 466 |
$( $.parseHTML( author ) ), |
| 467 |
$moreLink |
| 468 |
).parseDom() ); |
| 469 |
} else { |
| 470 |
$wrapper.append( author ); |
| 471 |
} |
| 472 |
|
| 473 |
return $wrapper.get( 0 ).outerHTML; |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
wrapAttribution( attribution ) { |
| 483 |
return $( '<span>' ) |
| 484 |
.addClass( 'mw-mmv-author' ) |
| 485 |
.addClass( 'mw-mmv-source' ) |
| 486 |
.append( $.parseHTML( attribution ) ) |
| 487 |
.get( 0 ).outerHTML; |
| 488 |
} |
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
setLicense( license, filePageUrl ) { |
| 497 |
let shortName; |
| 498 |
let url; |
| 499 |
let isCc; |
| 500 |
let isPd; |
| 501 |
|
| 502 |
filePageUrl += `?uselang=${ mw.config.get( 'wgUserLanguage' ) }#${ mw.msg( 'license-header' ) }`; |
| 503 |
|
| 504 |
if ( license ) { |
| 505 |
shortName = license.getShortName(); |
| 506 |
url = license.deedUrl || filePageUrl; |
| 507 |
isCc = license.isCc(); |
| 508 |
isPd = license.isPd(); |
| 509 |
} else { |
| 510 |
shortName = mw.msg( 'multimediaviewer-license-default' ); |
| 511 |
url = filePageUrl; |
| 512 |
isCc = isPd = false; |
| 513 |
} |
| 514 |
|
| 515 |
this.$license |
| 516 |
.text( shortName ) |
| 517 |
.prop( 'href', url ) |
| 518 |
.prop( 'target', license && license.deedUrl ? '_blank' : '' ); |
| 519 |
|
| 520 |
this.$licenseLi |
| 521 |
.toggleClass( 'cc-license', isCc ) |
| 522 |
.toggleClass( 'pd-license', isPd ) |
| 523 |
.removeClass( 'empty' ); |
| 524 |
} |
| 525 |
|
| 526 |
|
| 527 |
|
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
setPermission( permission ) { |
| 532 |
this.$permissionLink.show(); |
| 533 |
this.permission.set( permission ); |
| 534 |
} |
| 535 |
|
| 536 |
|
| 537 |
|
| 538 |
|
| 539 |
|
| 540 |
|
| 541 |
setRestrictions( restrictions ) { |
| 542 |
const restrictionsSet = {}; |
| 543 |
let showDefault = false; |
| 544 |
let validRestrictions = 0; |
| 545 |
|
| 546 |
restrictions.forEach( ( value, index ) => { |
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
|
| 556 |
|
| 557 |
|
| 558 |
|
| 559 |
|
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
if ( !mw.message( `multimediaviewer-restriction-${ value }` ).exists() || value === 'default' || index + 1 > MetadataPanel.MAX_RESTRICT ) { |
| 564 |
showDefault = true; |
| 565 |
return; |
| 566 |
} |
| 567 |
if ( restrictionsSet[ value ] ) { |
| 568 |
return; |
| 569 |
} else { |
| 570 |
restrictionsSet[ value ] = true; |
| 571 |
} |
| 572 |
|
| 573 |
this.$restrictions.append( this.createRestriction( value ) ); |
| 574 |
validRestrictions++; |
| 575 |
} ); |
| 576 |
|
| 577 |
if ( showDefault ) { |
| 578 |
if ( validRestrictions ) { |
| 579 |
this.$restrictions.append( this.createRestriction( 'default-and-others' ) ); |
| 580 |
} else { |
| 581 |
this.$restrictions.append( this.createRestriction( 'default' ) ); |
| 582 |
} |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
createRestriction( type ) { |
| 593 |
mw.loader.using( 'mmv.ui.restriction', () => {} ); |
| 594 |
const $label = $( '<span>' ) |
| 595 |
.addClass( 'mw-mmv-label mw-mmv-restriction-label' ) |
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
.prop( 'title', mw.msg( `multimediaviewer-restriction-${ type }` ) ); |
| 613 |
|
| 614 |
$( '<span>' ) |
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
.addClass( `mw-mmv-restriction-label-inner mw-mmv-restriction-${ type === 'default-and-others' ? 'default' : type }` ) |
| 631 |
.text( mw.msg( `multimediaviewer-restriction-${ type }` ) ) |
| 632 |
.appendTo( $label ); |
| 633 |
|
| 634 |
return $label; |
| 635 |
} |
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
setLocationData( imageData ) { |
| 643 |
if ( !imageData.hasCoords() ) { |
| 644 |
return; |
| 645 |
} |
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
function convertDegMinSec( value ) { |
| 654 |
value = Math.abs( value ); |
| 655 |
const deg = Math.floor( value ); |
| 656 |
value -= deg; |
| 657 |
const min = Math.floor( value * 60 ); |
| 658 |
value -= min / 60; |
| 659 |
const sec = Math.round( value * 100 * 60 * 60 ) / 100; |
| 660 |
return [ deg, min, sec ].map( ( n ) => mw.language.convertNumber( n ) ); |
| 661 |
} |
| 662 |
|
| 663 |
this.$location.text( |
| 664 |
mw.msg( 'multimediaviewer-geolocation', |
| 665 |
mw.msg( 'multimediaviewer-geoloc-coords', |
| 666 |
mw.msg( 'multimediaviewer-geoloc-coord', |
| 667 |
...convertDegMinSec( imageData.latitude ), |
| 668 |
|
| 669 |
|
| 670 |
|
| 671 |
mw.msg( `multimediaviewer-geoloc-${ imageData.latitude >= 0 ? 'north' : 'south' }` ) |
| 672 |
), |
| 673 |
|
| 674 |
mw.msg( 'multimediaviewer-geoloc-coord', |
| 675 |
...convertDegMinSec( imageData.longitude ), |
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
mw.msg( `multimediaviewer-geoloc-${ imageData.longitude >= 0 ? 'east' : 'west' }` ) |
| 680 |
) |
| 681 |
) |
| 682 |
) |
| 683 |
); |
| 684 |
|
| 685 |
this.$location.prop( 'href', ( |
| 686 |
'https://geohack.toolforge.org/geohack.php?pagename=' + |
| 687 |
`${ imageData.title.getPrefixedText() |
| 688 |
}¶ms=${ |
| 689 |
Math.abs( imageData.latitude ) }${ imageData.latitude >= 0 ? '_N_' : '_S_' |
| 690 |
}${ Math.abs( imageData.longitude ) }${ imageData.longitude >= 0 ? '_E_' : '_W_' |
| 691 |
}&language=${ encodeURIComponent( mw.config.get( 'wgUserLanguage' ) ) }` |
| 692 |
) ); |
| 693 |
|
| 694 |
this.$locationLi.removeClass( 'empty' ); |
| 695 |
} |
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
setImageInfo( image, imageData ) { |
| 704 |
if ( imageData.creationDateTime ) { |
| 705 |
this.$datetimeCreated.text( |
| 706 |
mw.msg( 'multimediaviewer-datetime-created', this.formatDate( imageData.creationDateTime ) ) |
| 707 |
); |
| 708 |
this.$datetimeCreatedLi.removeClass( 'empty' ); |
| 709 |
} |
| 710 |
if ( imageData.uploadDateTime ) { |
| 711 |
this.$datetimeUpdated.text( |
| 712 |
mw.msg( 'multimediaviewer-datetime-uploaded', this.formatDate( imageData.uploadDateTime ) ) |
| 713 |
); |
| 714 |
this.$datetimeUpdatedLi.removeClass( 'empty' ); |
| 715 |
} |
| 716 |
|
| 717 |
this.buttons.set( image, imageData ); |
| 718 |
this.description.set( imageData.description, image.caption ); |
| 719 |
|
| 720 |
this.setLicense( imageData.license, imageData.descriptionUrl ); |
| 721 |
|
| 722 |
this.setFileName( imageData.title.getMainText() ); |
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
this.setTitle( image, imageData ); |
| 727 |
this.setCredit( imageData.attribution, imageData.source, imageData.author, imageData.authorCount, imageData.descriptionUrl ); |
| 728 |
|
| 729 |
if ( imageData.permission ) { |
| 730 |
this.setPermission( imageData.permission ); |
| 731 |
} |
| 732 |
|
| 733 |
if ( imageData.restrictions ) { |
| 734 |
this.setRestrictions( imageData.restrictions ); |
| 735 |
} |
| 736 |
|
| 737 |
this.setLocationData( imageData ); |
| 738 |
|
| 739 |
this.resetTruncatedText(); |
| 740 |
this.scroller.unfreezeHeight(); |
| 741 |
} |
| 742 |
|
| 743 |
|
| 744 |
|
| 745 |
|
| 746 |
|
| 747 |
|
| 748 |
|
| 749 |
showError( title, error ) { |
| 750 |
this.$credit.text( mw.msg( 'multimediaviewer-metadata-error', error ) ); |
| 751 |
this.$title.html( title ); |
| 752 |
} |
| 753 |
|
| 754 |
|
| 755 |
|
| 756 |
|
| 757 |
|
| 758 |
|
| 759 |
|
| 760 |
|
| 761 |
formatDate( dateString ) { |
| 762 |
let lang = mw.config.get( 'wgUserLanguage' ); |
| 763 |
if ( lang === 'en' || lang === 'qqx' ) { |
| 764 |
|
| 765 |
|
| 766 |
|
| 767 |
|
| 768 |
lang = 'en-GB'; |
| 769 |
} |
| 770 |
if ( dateString.length === 4 ) { |
| 771 |
|
| 772 |
return dateString; |
| 773 |
} |
| 774 |
const date = new Date( dateString ); |
| 775 |
try { |
| 776 |
if ( date instanceof Date && !isNaN( date ) ) { |
| 777 |
return date.toLocaleString( lang, { |
| 778 |
day: 'numeric', |
| 779 |
month: 'long', |
| 780 |
year: 'numeric', |
| 781 |
timeZone: 'UTC' |
| 782 |
} ); |
| 783 |
} |
| 784 |
} catch ( ignore ) { } |
| 785 |
|
| 786 |
return dateString; |
| 787 |
} |
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
revealTruncatedText() { |
| 793 |
if ( this.$container.hasClass( 'mw-mmv-untruncated' ) ) { |
| 794 |
return; |
| 795 |
} |
| 796 |
this.$container.addClass( 'mw-mmv-untruncated' ); |
| 797 |
this.title.grow(); |
| 798 |
this.creditField.grow(); |
| 799 |
} |
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
hideTruncatedText() { |
| 805 |
if ( !this.$container.hasClass( 'mw-mmv-untruncated' ) ) { |
| 806 |
return; |
| 807 |
} |
| 808 |
this.title.shrink(); |
| 809 |
this.creditField.shrink(); |
| 810 |
this.$container.removeClass( 'mw-mmv-untruncated' ); |
| 811 |
} |
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
|
| 816 |
|
| 817 |
|
| 818 |
resetTruncatedText() { |
| 819 |
if ( this.scroller.panelIsOpen() ) { |
| 820 |
this.revealTruncatedText(); |
| 821 |
} else { |
| 822 |
this.hideTruncatedText(); |
| 823 |
} |
| 824 |
} |
| 825 |
} |
| 826 |
|
| 827 |
|
| 828 |
|
| 829 |
|
| 830 |
|
| 831 |
|
| 832 |
|
| 833 |
MetadataPanel.MAX_RESTRICT = 4; |
| 834 |
|
| 835 |
module.exports = MetadataPanel; |