| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
s. |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
( function ( OO ) { |
| 12 |
|
| 13 |
'use strict'; |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
OO.ui.mixin.DraggableElement = function OoUiMixinDraggableElement( config ) { |
| 33 |
config = config || {}; |
| 34 |
|
| 35 |
|
| 36 |
this.index = null; |
| 37 |
this.$handle = config.$handle || this.$element; |
| 38 |
this.wasHandleUsed = null; |
| 39 |
|
| 40 |
|
| 41 |
this.$element |
| 42 |
.addClass( 'oo-ui-draggableElement' ) |
| 43 |
.on( { |
| 44 |
mousedown: this.onDragMouseDown.bind( this ), |
| 45 |
dragstart: this.onDragStart.bind( this ), |
| 46 |
dragover: this.onDragOver.bind( this ), |
| 47 |
dragend: this.onDragEnd.bind( this ), |
| 48 |
drop: this.onDrop.bind( this ) |
| 49 |
} ); |
| 50 |
this.$handle.addClass( 'oo-ui-draggableElement-handle' ); |
| 51 |
this.toggleDraggable( config.draggable === undefined ? true : !!config.draggable ); |
| 52 |
}; |
| 53 |
|
| 54 |
OO.initClass( OO.ui.mixin.DraggableElement ); |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
OO.ui.mixin.DraggableElement.static.cancelButtonMouseDownEvents = false; |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
OO.ui.mixin.DraggableElement.prototype.toggleDraggable = function ( isDraggable ) { |
| 96 |
isDraggable = isDraggable !== undefined ? !!isDraggable : !this.draggable; |
| 97 |
|
| 98 |
if ( this.draggable !== isDraggable ) { |
| 99 |
this.draggable = isDraggable; |
| 100 |
|
| 101 |
this.$handle.toggleClass( 'oo-ui-draggableElement-undraggable', !this.draggable ); |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
this.$element.prop( 'draggable', this.draggable ); |
| 107 |
} |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
OO.ui.mixin.DraggableElement.prototype.isDraggable = function () { |
| 116 |
return this.draggable; |
| 117 |
}; |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
OO.ui.mixin.DraggableElement.prototype.onDragMouseDown = function ( e ) { |
| 126 |
if ( !this.isDraggable() ) { |
| 127 |
return; |
| 128 |
} |
| 129 |
|
| 130 |
this.wasHandleUsed = |
| 131 |
|
| 132 |
this.$handle[ 0 ] === this.$element[ 0 ] || |
| 133 |
|
| 134 |
OO.ui.contains( this.$handle[ 0 ], e.target, true ); |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
OO.ui.mixin.DraggableElement.prototype.onDragStart = function ( e ) { |
| 146 |
if ( !this.wasHandleUsed || !this.isDraggable() ) { |
| 147 |
return false; |
| 148 |
} |
| 149 |
|
| 150 |
const dataTransfer = e.originalEvent.dataTransfer; |
| 151 |
|
| 152 |
dataTransfer.dropEffect = 'none'; |
| 153 |
dataTransfer.effectAllowed = 'move'; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
try { |
| 158 |
dataTransfer.setData( 'application-x/OOUI-draggable', this.getIndex() ); |
| 159 |
} catch ( err ) { |
| 160 |
|
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
if ( !dataTransfer.getData( 'text' ) ) { |
| 165 |
try { |
| 166 |
dataTransfer.setData( 'text', ' ' ); |
| 167 |
} catch ( err ) { |
| 168 |
|
| 169 |
|
| 170 |
} |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
this.$element.addClass( 'oo-ui-draggableElement-clone' ); |
| 175 |
|
| 176 |
setTimeout( () => { |
| 177 |
this.$element |
| 178 |
.removeClass( 'oo-ui-draggableElement-clone' ) |
| 179 |
.addClass( 'oo-ui-draggableElement-placeholder' ); |
| 180 |
} ); |
| 181 |
|
| 182 |
this.emit( 'dragstart', this ); |
| 183 |
return true; |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
OO.ui.mixin.DraggableElement.prototype.onDragEnd = function () { |
| 193 |
this.$element.removeClass( 'oo-ui-draggableElement-placeholder' ); |
| 194 |
this.emit( 'dragend' ); |
| 195 |
}; |
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
OO.ui.mixin.DraggableElement.prototype.onDrop = function ( e ) { |
| 205 |
e.preventDefault(); |
| 206 |
this.emit( 'drop', e ); |
| 207 |
}; |
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
OO.ui.mixin.DraggableElement.prototype.onDragOver = function ( e ) { |
| 217 |
e.preventDefault(); |
| 218 |
}; |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
OO.ui.mixin.DraggableElement.prototype.setIndex = function ( index ) { |
| 228 |
if ( this.index !== index ) { |
| 229 |
this.index = index; |
| 230 |
this.$element.data( 'index', index ); |
| 231 |
} |
| 232 |
}; |
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
OO.ui.mixin.DraggableElement.prototype.getIndex = function () { |
| 241 |
return this.index; |
| 242 |
}; |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
|
| 261 |
|
| 262 |
OO.ui.mixin.DraggableGroupElement = function OoUiMixinDraggableGroupElement( config ) { |
| 263 |
|
| 264 |
config = config || {}; |
| 265 |
|
| 266 |
|
| 267 |
OO.ui.mixin.GroupElement.call( this, config ); |
| 268 |
|
| 269 |
|
| 270 |
this.orientation = config.orientation || 'vertical'; |
| 271 |
this.dragItem = null; |
| 272 |
this.itemKeys = {}; |
| 273 |
this.dir = null; |
| 274 |
this.itemsOrder = null; |
| 275 |
this.draggable = config.draggable === undefined ? true : !!config.draggable; |
| 276 |
|
| 277 |
|
| 278 |
this.aggregate( { |
| 279 |
dragstart: 'itemDragStart', |
| 280 |
dragend: 'itemDragEnd', |
| 281 |
drop: 'itemDrop' |
| 282 |
} ); |
| 283 |
this.connect( this, { |
| 284 |
itemDragStart: 'onItemDragStart', |
| 285 |
itemDrop: 'onItemDropOrDragEnd', |
| 286 |
itemDragEnd: 'onItemDropOrDragEnd' |
| 287 |
} ); |
| 288 |
|
| 289 |
|
| 290 |
this.addItems( config.items || [] ); |
| 291 |
this.$element |
| 292 |
.addClass( 'oo-ui-draggableGroupElement' ) |
| 293 |
.toggleClass( 'oo-ui-draggableGroupElement-horizontal', this.orientation === 'horizontal' ); |
| 294 |
}; |
| 295 |
|
| 296 |
|
| 297 |
OO.mixinClass( OO.ui.mixin.DraggableGroupElement, OO.ui.mixin.GroupElement ); |
| 298 |
|
| 299 |
|
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
|
| 329 |
|
| 330 |
|
| 331 |
|
| 332 |
|
| 333 |
OO.ui.mixin.DraggableGroupElement.prototype.toggleDraggable = function ( isDraggable ) { |
| 334 |
isDraggable = isDraggable !== undefined ? !!isDraggable : !this.draggable; |
| 335 |
|
| 336 |
if ( this.draggable !== isDraggable ) { |
| 337 |
this.draggable = isDraggable; |
| 338 |
|
| 339 |
|
| 340 |
this.getItems().forEach( ( item ) => { |
| 341 |
item.toggleDraggable( this.draggable ); |
| 342 |
} ); |
| 343 |
|
| 344 |
|
| 345 |
this.emit( 'draggable', this.draggable ); |
| 346 |
} |
| 347 |
}; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
OO.ui.mixin.DraggableGroupElement.prototype.isDraggable = function () { |
| 355 |
return this.draggable; |
| 356 |
}; |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
OO.ui.mixin.DraggableGroupElement.prototype.onItemDragStart = function ( item ) { |
| 365 |
if ( !this.isDraggable() ) { |
| 366 |
return; |
| 367 |
} |
| 368 |
|
| 369 |
|
| 370 |
this.itemsOrder = this.items.slice(); |
| 371 |
this.updateIndexes(); |
| 372 |
if ( this.orientation === 'horizontal' ) { |
| 373 |
|
| 374 |
|
| 375 |
this.dir = this.$element.css( 'direction' ); |
| 376 |
} |
| 377 |
this.setDragItem( item ); |
| 378 |
}; |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
OO.ui.mixin.DraggableGroupElement.prototype.updateIndexes = function () { |
| 384 |
|
| 385 |
for ( let i = 0, len = this.itemsOrder.length; i < len; i++ ) { |
| 386 |
this.itemsOrder[ i ].setIndex( i ); |
| 387 |
} |
| 388 |
}; |
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
|
| 395 |
|
| 396 |
|
| 397 |
OO.ui.mixin.DraggableGroupElement.prototype.onItemDropOrDragEnd = function () { |
| 398 |
const item = this.getDragItem(); |
| 399 |
|
| 400 |
|
| 401 |
|
| 402 |
if ( item ) { |
| 403 |
const originalIndex = this.items.indexOf( item ); |
| 404 |
|
| 405 |
const targetIndex = item.getIndex() + ( item.getIndex() > originalIndex ? 1 : 0 ); |
| 406 |
if ( targetIndex !== originalIndex ) { |
| 407 |
this.reorder( this.getDragItem(), targetIndex ); |
| 408 |
this.emit( 'reorder', this.getDragItem(), targetIndex ); |
| 409 |
} |
| 410 |
this.updateIndexes(); |
| 411 |
} |
| 412 |
this.unsetDragItem(); |
| 413 |
|
| 414 |
return false; |
| 415 |
}; |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
|
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
OO.ui.mixin.DraggableGroupElement.prototype.onDragOver = function ( e ) { |
| 425 |
const item = this.getDragItem(), |
| 426 |
dragItemIndex = item.getIndex(); |
| 427 |
|
| 428 |
|
| 429 |
const overIndex = $( e.target ).closest( '.oo-ui-draggableElement' ).data( 'index' ); |
| 430 |
|
| 431 |
if ( overIndex !== undefined && overIndex !== dragItemIndex ) { |
| 432 |
const targetIndex = overIndex + ( overIndex > dragItemIndex ? 1 : 0 ); |
| 433 |
|
| 434 |
if ( targetIndex > 0 ) { |
| 435 |
this.$group.children().eq( targetIndex - 1 ).after( item.$element ); |
| 436 |
} else { |
| 437 |
this.$group.prepend( item.$element ); |
| 438 |
} |
| 439 |
|
| 440 |
this.itemsOrder.splice( overIndex, 0, |
| 441 |
this.itemsOrder.splice( dragItemIndex, 1 )[ 0 ] |
| 442 |
); |
| 443 |
this.updateIndexes(); |
| 444 |
this.emit( 'drag', item, targetIndex ); |
| 445 |
} |
| 446 |
|
| 447 |
e.preventDefault(); |
| 448 |
}; |
| 449 |
|
| 450 |
|
| 451 |
|
| 452 |
|
| 453 |
|
| 454 |
|
| 455 |
|
| 456 |
OO.ui.mixin.DraggableGroupElement.prototype.reorder = function ( item, newIndex ) { |
| 457 |
this.addItems( [ item ], newIndex ); |
| 458 |
}; |
| 459 |
|
| 460 |
|
| 461 |
|
| 462 |
|
| 463 |
|
| 464 |
|
| 465 |
OO.ui.mixin.DraggableGroupElement.prototype.setDragItem = function ( item ) { |
| 466 |
if ( this.dragItem !== item ) { |
| 467 |
this.dragItem = item; |
| 468 |
this.$element.on( 'dragover', this.onDragOver.bind( this ) ); |
| 469 |
this.$element.addClass( 'oo-ui-draggableGroupElement-dragging' ); |
| 470 |
} |
| 471 |
}; |
| 472 |
|
| 473 |
|
| 474 |
|
| 475 |
|
| 476 |
OO.ui.mixin.DraggableGroupElement.prototype.unsetDragItem = function () { |
| 477 |
if ( this.dragItem ) { |
| 478 |
this.dragItem = null; |
| 479 |
this.$element.off( 'dragover' ); |
| 480 |
this.$element.removeClass( 'oo-ui-draggableGroupElement-dragging' ); |
| 481 |
} |
| 482 |
}; |
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
OO.ui.mixin.DraggableGroupElement.prototype.getDragItem = function () { |
| 491 |
return this.dragItem; |
| 492 |
}; |
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
|
| 500 |
|
| 501 |
|
| 502 |
|
| 503 |
|
| 504 |
|
| 505 |
|
| 506 |
OO.ui.mixin.RequestManager = function OoUiMixinRequestManager( config ) { |
| 507 |
this.requestCache = {}; |
| 508 |
this.requestQuery = null; |
| 509 |
this.requestRequest = null; |
| 510 |
this.showPendingRequest = !!this.pushPending && config.showPendingRequest !== false; |
| 511 |
}; |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
OO.initClass( OO.ui.mixin.RequestManager ); |
| 516 |
|
| 517 |
|
| 518 |
|
| 519 |
|
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
OO.ui.mixin.RequestManager.prototype.getRequestData = function () { |
| 525 |
const value = this.getRequestQuery(), |
| 526 |
deferred = $.Deferred(); |
| 527 |
|
| 528 |
this.abortRequest(); |
| 529 |
if ( Object.prototype.hasOwnProperty.call( this.requestCache, value ) ) { |
| 530 |
deferred.resolve( this.requestCache[ value ] ); |
| 531 |
} else { |
| 532 |
if ( this.showPendingRequest ) { |
| 533 |
this.pushPending(); |
| 534 |
} |
| 535 |
this.requestQuery = value; |
| 536 |
const ourRequest = this.requestRequest = this.getRequest(); |
| 537 |
ourRequest |
| 538 |
.always( () => { |
| 539 |
|
| 540 |
|
| 541 |
|
| 542 |
|
| 543 |
|
| 544 |
|
| 545 |
if ( this.showPendingRequest ) { |
| 546 |
this.popPending(); |
| 547 |
} |
| 548 |
} ) |
| 549 |
.done( ( response ) => { |
| 550 |
|
| 551 |
|
| 552 |
if ( ourRequest === this.requestRequest ) { |
| 553 |
this.requestQuery = null; |
| 554 |
this.requestRequest = null; |
| 555 |
this.requestCache[ value ] = |
| 556 |
this.getRequestCacheDataFromResponse( response ); |
| 557 |
deferred.resolve( this.requestCache[ value ] ); |
| 558 |
} |
| 559 |
} ) |
| 560 |
.fail( () => { |
| 561 |
|
| 562 |
|
| 563 |
if ( ourRequest === this.requestRequest ) { |
| 564 |
this.requestQuery = null; |
| 565 |
this.requestRequest = null; |
| 566 |
deferred.reject(); |
| 567 |
} |
| 568 |
} ); |
| 569 |
} |
| 570 |
return deferred.promise(); |
| 571 |
}; |
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
OO.ui.mixin.RequestManager.prototype.abortRequest = function () { |
| 579 |
const oldRequest = this.requestRequest; |
| 580 |
if ( oldRequest ) { |
| 581 |
|
| 582 |
|
| 583 |
this.requestRequest = null; |
| 584 |
this.requestQuery = null; |
| 585 |
oldRequest.abort(); |
| 586 |
} |
| 587 |
}; |
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
OO.ui.mixin.RequestManager.prototype.getRequestQuery = null; |
| 598 |
|
| 599 |
|
| 600 |
|
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
OO.ui.mixin.RequestManager.prototype.getRequest = null; |
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
OO.ui.mixin.RequestManager.prototype.getRequestCacheDataFromResponse = null; |
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
|
| 635 |
|
| 636 |
|
| 637 |
|
| 638 |
|
| 639 |
|
| 640 |
|
| 641 |
|
| 642 |
|
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
|
| 647 |
|
| 648 |
|
| 649 |
|
| 650 |
|
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
|
| 656 |
|
| 657 |
|
| 658 |
|
| 659 |
|
| 660 |
OO.ui.mixin.LookupElement = function OoUiMixinLookupElement( config ) { |
| 661 |
|
| 662 |
config = Object.assign( { highlightFirst: true }, config ); |
| 663 |
|
| 664 |
|
| 665 |
OO.ui.mixin.RequestManager.call( this, config ); |
| 666 |
|
| 667 |
|
| 668 |
this.$overlay = ( config.$overlay === true ? |
| 669 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 670 |
this.lookupMenu = new OO.ui.MenuSelectWidget( Object.assign( { |
| 671 |
widget: this, |
| 672 |
input: this, |
| 673 |
$floatableContainer: config.$container || this.$element |
| 674 |
}, config.menu ) ); |
| 675 |
|
| 676 |
this.allowSuggestionsWhenEmpty = config.allowSuggestionsWhenEmpty || false; |
| 677 |
|
| 678 |
this.lookupsDisabled = false; |
| 679 |
this.lookupInputFocused = false; |
| 680 |
this.lookupHighlightFirstItem = config.highlightFirst; |
| 681 |
this.showSuggestionsOnFocus = config.showSuggestionsOnFocus !== false; |
| 682 |
|
| 683 |
|
| 684 |
this.$input.on( { |
| 685 |
focus: this.onLookupInputFocus.bind( this ), |
| 686 |
blur: this.onLookupInputBlur.bind( this ), |
| 687 |
mousedown: this.onLookupInputMouseDown.bind( this ) |
| 688 |
} ); |
| 689 |
this.connect( this, { |
| 690 |
change: 'onLookupInputChange' |
| 691 |
} ); |
| 692 |
this.lookupMenu.connect( this, { |
| 693 |
toggle: 'onLookupMenuToggle', |
| 694 |
choose: 'onLookupMenuChoose' |
| 695 |
} ); |
| 696 |
|
| 697 |
|
| 698 |
this.$input.attr( { |
| 699 |
role: 'combobox', |
| 700 |
'aria-owns': this.lookupMenu.getElementId(), |
| 701 |
'aria-autocomplete': 'list' |
| 702 |
} ); |
| 703 |
this.$element.addClass( 'oo-ui-lookupElement' ); |
| 704 |
this.lookupMenu.$element.addClass( 'oo-ui-lookupElement-menu' ); |
| 705 |
this.$overlay.append( this.lookupMenu.$element ); |
| 706 |
}; |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
OO.mixinClass( OO.ui.mixin.LookupElement, OO.ui.mixin.RequestManager ); |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
OO.ui.mixin.LookupElement.prototype.onLookupInputFocus = function () { |
| 721 |
this.lookupInputFocused = true; |
| 722 |
if ( this.showSuggestionsOnFocus ) { |
| 723 |
this.populateLookupMenu(); |
| 724 |
} |
| 725 |
}; |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
|
| 731 |
|
| 732 |
|
| 733 |
OO.ui.mixin.LookupElement.prototype.onLookupInputBlur = function () { |
| 734 |
this.closeLookupMenu(); |
| 735 |
this.lookupInputFocused = false; |
| 736 |
}; |
| 737 |
|
| 738 |
|
| 739 |
|
| 740 |
|
| 741 |
|
| 742 |
|
| 743 |
|
| 744 |
OO.ui.mixin.LookupElement.prototype.onLookupInputMouseDown = function () { |
| 745 |
if ( |
| 746 |
!this.lookupMenu.isVisible() && |
| 747 |
( |
| 748 |
|
| 749 |
|
| 750 |
|
| 751 |
this.lookupInputFocused || |
| 752 |
|
| 753 |
!this.showSuggestionsOnFocus |
| 754 |
) |
| 755 |
) { |
| 756 |
this.populateLookupMenu(); |
| 757 |
} |
| 758 |
}; |
| 759 |
|
| 760 |
|
| 761 |
|
| 762 |
|
| 763 |
|
| 764 |
|
| 765 |
|
| 766 |
OO.ui.mixin.LookupElement.prototype.onLookupInputChange = function () { |
| 767 |
if ( this.lookupInputFocused ) { |
| 768 |
this.populateLookupMenu(); |
| 769 |
} |
| 770 |
}; |
| 771 |
|
| 772 |
|
| 773 |
|
| 774 |
|
| 775 |
|
| 776 |
|
| 777 |
|
| 778 |
OO.ui.mixin.LookupElement.prototype.onLookupMenuToggle = function ( visible ) { |
| 779 |
if ( !visible ) { |
| 780 |
|
| 781 |
|
| 782 |
|
| 783 |
this.abortLookupRequest(); |
| 784 |
this.lookupMenu.clearItems(); |
| 785 |
} |
| 786 |
}; |
| 787 |
|
| 788 |
|
| 789 |
|
| 790 |
|
| 791 |
|
| 792 |
|
| 793 |
|
| 794 |
OO.ui.mixin.LookupElement.prototype.onLookupMenuChoose = function ( item ) { |
| 795 |
this.setValue( item.getData() ); |
| 796 |
}; |
| 797 |
|
| 798 |
|
| 799 |
|
| 800 |
|
| 801 |
|
| 802 |
|
| 803 |
|
| 804 |
OO.ui.mixin.LookupElement.prototype.getLookupMenu = function () { |
| 805 |
return this.lookupMenu; |
| 806 |
}; |
| 807 |
|
| 808 |
|
| 809 |
|
| 810 |
|
| 811 |
|
| 812 |
|
| 813 |
|
| 814 |
|
| 815 |
OO.ui.mixin.LookupElement.prototype.setLookupsDisabled = function ( disabled ) { |
| 816 |
this.lookupsDisabled = !!disabled; |
| 817 |
}; |
| 818 |
|
| 819 |
|
| 820 |
|
| 821 |
|
| 822 |
|
| 823 |
|
| 824 |
|
| 825 |
|
| 826 |
OO.ui.mixin.LookupElement.prototype.openLookupMenu = function () { |
| 827 |
if ( !this.lookupMenu.isEmpty() ) { |
| 828 |
this.lookupMenu.toggle( true ); |
| 829 |
} |
| 830 |
return this; |
| 831 |
}; |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
|
| 836 |
|
| 837 |
|
| 838 |
|
| 839 |
|
| 840 |
OO.ui.mixin.LookupElement.prototype.closeLookupMenu = function () { |
| 841 |
this.lookupMenu.toggle( false ); |
| 842 |
this.abortLookupRequest(); |
| 843 |
this.lookupMenu.clearItems(); |
| 844 |
return this; |
| 845 |
}; |
| 846 |
|
| 847 |
|
| 848 |
|
| 849 |
|
| 850 |
|
| 851 |
|
| 852 |
|
| 853 |
|
| 854 |
|
| 855 |
|
| 856 |
|
| 857 |
OO.ui.mixin.LookupElement.prototype.populateLookupMenu = function () { |
| 858 |
const value = this.getValue(); |
| 859 |
|
| 860 |
if ( this.lookupsDisabled || this.isReadOnly() ) { |
| 861 |
return; |
| 862 |
} |
| 863 |
|
| 864 |
|
| 865 |
if ( !this.allowSuggestionsWhenEmpty && value === '' ) { |
| 866 |
this.closeLookupMenu(); |
| 867 |
|
| 868 |
} else if ( value !== this.lookupQuery ) { |
| 869 |
this.getLookupMenuItems() |
| 870 |
.done( ( items ) => { |
| 871 |
this.lookupMenu.clearItems(); |
| 872 |
if ( items.length ) { |
| 873 |
this.lookupMenu |
| 874 |
.addItems( items ) |
| 875 |
.toggle( true ); |
| 876 |
this.initializeLookupMenuSelection(); |
| 877 |
} else { |
| 878 |
this.lookupMenu.toggle( false ); |
| 879 |
} |
| 880 |
} ) |
| 881 |
.fail( () => { |
| 882 |
this.lookupMenu.clearItems(); |
| 883 |
this.lookupMenu.toggle( false ); |
| 884 |
} ); |
| 885 |
} |
| 886 |
|
| 887 |
return this; |
| 888 |
}; |
| 889 |
|
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
OO.ui.mixin.LookupElement.prototype.initializeLookupMenuSelection = function () { |
| 897 |
if ( this.lookupHighlightFirstItem && !this.lookupMenu.findSelectedItem() ) { |
| 898 |
this.lookupMenu.highlightItem( this.lookupMenu.findFirstSelectableItem() ); |
| 899 |
} |
| 900 |
}; |
| 901 |
|
| 902 |
|
| 903 |
|
| 904 |
|
| 905 |
|
| 906 |
|
| 907 |
|
| 908 |
|
| 909 |
|
| 910 |
OO.ui.mixin.LookupElement.prototype.getLookupMenuItems = function () { |
| 911 |
return this.getRequestData().then( ( data ) => this.getLookupMenuOptionsFromData( data ) ); |
| 912 |
}; |
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
OO.ui.mixin.LookupElement.prototype.abortLookupRequest = function () { |
| 920 |
this.abortRequest(); |
| 921 |
}; |
| 922 |
|
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
OO.ui.mixin.LookupElement.prototype.getLookupRequest = null; |
| 932 |
|
| 933 |
|
| 934 |
|
| 935 |
|
| 936 |
|
| 937 |
|
| 938 |
|
| 939 |
|
| 940 |
|
| 941 |
|
| 942 |
|
| 943 |
|
| 944 |
|
| 945 |
OO.ui.mixin.LookupElement.prototype.getLookupCacheDataFromResponse = null; |
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
OO.ui.mixin.LookupElement.prototype.getLookupMenuOptionsFromData = null; |
| 958 |
|
| 959 |
|
| 960 |
|
| 961 |
|
| 962 |
|
| 963 |
|
| 964 |
|
| 965 |
|
| 966 |
|
| 967 |
|
| 968 |
OO.ui.mixin.LookupElement.prototype.setReadOnly = function ( readOnly ) { |
| 969 |
|
| 970 |
|
| 971 |
OO.ui.TextInputWidget.prototype.setReadOnly.call( this, readOnly ); |
| 972 |
|
| 973 |
|
| 974 |
if ( this.isReadOnly() && this.lookupMenu ) { |
| 975 |
this.closeLookupMenu(); |
| 976 |
} |
| 977 |
|
| 978 |
return this; |
| 979 |
}; |
| 980 |
|
| 981 |
|
| 982 |
|
| 983 |
|
| 984 |
OO.ui.mixin.LookupElement.prototype.getRequestQuery = function () { |
| 985 |
return this.getValue(); |
| 986 |
}; |
| 987 |
|
| 988 |
|
| 989 |
|
| 990 |
|
| 991 |
OO.ui.mixin.LookupElement.prototype.getRequest = function () { |
| 992 |
return this.getLookupRequest(); |
| 993 |
}; |
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
OO.ui.mixin.LookupElement.prototype.getRequestCacheDataFromResponse = function ( response ) { |
| 999 |
return this.getLookupCacheDataFromResponse( response ); |
| 1000 |
}; |
| 1001 |
|
| 1002 |
|
| 1003 |
|
| 1004 |
|
| 1005 |
|
| 1006 |
|
| 1007 |
|
| 1008 |
|
| 1009 |
|
| 1010 |
|
| 1011 |
|
| 1012 |
|
| 1013 |
|
| 1014 |
|
| 1015 |
|
| 1016 |
|
| 1017 |
|
| 1018 |
|
| 1019 |
|
| 1020 |
|
| 1021 |
OO.ui.TabPanelLayout = function OoUiTabPanelLayout( name, config ) { |
| 1022 |
|
| 1023 |
if ( OO.isPlainObject( name ) && config === undefined ) { |
| 1024 |
config = name; |
| 1025 |
name = config.name; |
| 1026 |
} |
| 1027 |
|
| 1028 |
|
| 1029 |
config = Object.assign( { scrollable: true }, config ); |
| 1030 |
|
| 1031 |
|
| 1032 |
OO.ui.TabPanelLayout.super.call( this, config ); |
| 1033 |
|
| 1034 |
|
| 1035 |
this.name = name; |
| 1036 |
this.label = config.label; |
| 1037 |
this.tabItemConfig = config.tabItemConfig || {}; |
| 1038 |
this.tabItem = null; |
| 1039 |
this.active = false; |
| 1040 |
|
| 1041 |
|
| 1042 |
this.$element |
| 1043 |
.addClass( 'oo-ui-tabPanelLayout' ) |
| 1044 |
.attr( 'role', 'tabpanel' ); |
| 1045 |
}; |
| 1046 |
|
| 1047 |
|
| 1048 |
|
| 1049 |
OO.inheritClass( OO.ui.TabPanelLayout, OO.ui.PanelLayout ); |
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
|
| 1057 |
|
| 1058 |
|
| 1059 |
|
| 1060 |
|
| 1061 |
|
| 1062 |
|
| 1063 |
|
| 1064 |
|
| 1065 |
|
| 1066 |
|
| 1067 |
|
| 1068 |
OO.ui.TabPanelLayout.prototype.getName = function () { |
| 1069 |
return this.name; |
| 1070 |
}; |
| 1071 |
|
| 1072 |
|
| 1073 |
|
| 1074 |
|
| 1075 |
|
| 1076 |
|
| 1077 |
|
| 1078 |
|
| 1079 |
|
| 1080 |
|
| 1081 |
OO.ui.TabPanelLayout.prototype.isActive = function () { |
| 1082 |
return this.active; |
| 1083 |
}; |
| 1084 |
|
| 1085 |
|
| 1086 |
|
| 1087 |
|
| 1088 |
|
| 1089 |
|
| 1090 |
|
| 1091 |
|
| 1092 |
|
| 1093 |
|
| 1094 |
OO.ui.TabPanelLayout.prototype.getTabItem = function () { |
| 1095 |
return this.tabItem; |
| 1096 |
}; |
| 1097 |
|
| 1098 |
|
| 1099 |
|
| 1100 |
|
| 1101 |
|
| 1102 |
|
| 1103 |
OO.ui.TabPanelLayout.prototype.getTabItemConfig = function () { |
| 1104 |
return this.tabItemConfig; |
| 1105 |
}; |
| 1106 |
|
| 1107 |
|
| 1108 |
|
| 1109 |
|
| 1110 |
|
| 1111 |
|
| 1112 |
|
| 1113 |
|
| 1114 |
|
| 1115 |
|
| 1116 |
|
| 1117 |
|
| 1118 |
OO.ui.TabPanelLayout.prototype.setTabItem = function ( tabItem ) { |
| 1119 |
this.tabItem = tabItem || null; |
| 1120 |
if ( tabItem ) { |
| 1121 |
this.setupTabItem(); |
| 1122 |
} |
| 1123 |
return this; |
| 1124 |
}; |
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
|
| 1133 |
|
| 1134 |
|
| 1135 |
|
| 1136 |
|
| 1137 |
OO.ui.TabPanelLayout.prototype.setupTabItem = function () { |
| 1138 |
this.$element.attr( 'aria-labelledby', this.tabItem.getElementId() ); |
| 1139 |
|
| 1140 |
this.tabItem.$element.attr( 'aria-controls', this.getElementId() ); |
| 1141 |
|
| 1142 |
if ( this.label ) { |
| 1143 |
this.tabItem.setLabel( this.label ); |
| 1144 |
} |
| 1145 |
return this; |
| 1146 |
}; |
| 1147 |
|
| 1148 |
|
| 1149 |
|
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
OO.ui.TabPanelLayout.prototype.setActive = function ( active ) { |
| 1159 |
active = !!active; |
| 1160 |
|
| 1161 |
if ( active !== this.active ) { |
| 1162 |
this.active = active; |
| 1163 |
this.$element.toggleClass( 'oo-ui-tabPanelLayout-active', this.active ); |
| 1164 |
this.emit( 'active', this.active ); |
| 1165 |
} |
| 1166 |
}; |
| 1167 |
|
| 1168 |
|
| 1169 |
|
| 1170 |
|
| 1171 |
|
| 1172 |
|
| 1173 |
|
| 1174 |
|
| 1175 |
|
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
OO.ui.PageLayout = function OoUiPageLayout( name, config ) { |
| 1186 |
|
| 1187 |
if ( OO.isPlainObject( name ) && config === undefined ) { |
| 1188 |
config = name; |
| 1189 |
name = config.name; |
| 1190 |
} |
| 1191 |
|
| 1192 |
|
| 1193 |
config = Object.assign( { scrollable: true }, config ); |
| 1194 |
|
| 1195 |
|
| 1196 |
OO.ui.PageLayout.super.call( this, config ); |
| 1197 |
|
| 1198 |
|
| 1199 |
this.name = name; |
| 1200 |
this.outlineItem = null; |
| 1201 |
this.active = false; |
| 1202 |
|
| 1203 |
|
| 1204 |
this.$element.addClass( 'oo-ui-pageLayout' ); |
| 1205 |
}; |
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
OO.inheritClass( OO.ui.PageLayout, OO.ui.PanelLayout ); |
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
|
| 1223 |
|
| 1224 |
|
| 1225 |
|
| 1226 |
|
| 1227 |
|
| 1228 |
OO.ui.PageLayout.prototype.getName = function () { |
| 1229 |
return this.name; |
| 1230 |
}; |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
OO.ui.PageLayout.prototype.isActive = function () { |
| 1242 |
return this.active; |
| 1243 |
}; |
| 1244 |
|
| 1245 |
|
| 1246 |
|
| 1247 |
|
| 1248 |
|
| 1249 |
|
| 1250 |
|
| 1251 |
|
| 1252 |
|
| 1253 |
|
| 1254 |
OO.ui.PageLayout.prototype.getOutlineItem = function () { |
| 1255 |
return this.outlineItem; |
| 1256 |
}; |
| 1257 |
|
| 1258 |
|
| 1259 |
|
| 1260 |
|
| 1261 |
|
| 1262 |
|
| 1263 |
|
| 1264 |
|
| 1265 |
|
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
OO.ui.PageLayout.prototype.setOutlineItem = function ( outlineItem ) { |
| 1270 |
this.outlineItem = outlineItem || null; |
| 1271 |
if ( outlineItem ) { |
| 1272 |
this.setupOutlineItem(); |
| 1273 |
} |
| 1274 |
return this; |
| 1275 |
}; |
| 1276 |
|
| 1277 |
|
| 1278 |
|
| 1279 |
|
| 1280 |
|
| 1281 |
|
| 1282 |
|
| 1283 |
|
| 1284 |
|
| 1285 |
|
| 1286 |
OO.ui.PageLayout.prototype.setupOutlineItem = function () { |
| 1287 |
}; |
| 1288 |
|
| 1289 |
|
| 1290 |
|
| 1291 |
|
| 1292 |
|
| 1293 |
|
| 1294 |
|
| 1295 |
|
| 1296 |
|
| 1297 |
|
| 1298 |
|
| 1299 |
OO.ui.PageLayout.prototype.setActive = function ( active ) { |
| 1300 |
active = !!active; |
| 1301 |
|
| 1302 |
if ( active !== this.active ) { |
| 1303 |
this.active = active; |
| 1304 |
this.$element.toggleClass( 'oo-ui-pageLayout-active', active ); |
| 1305 |
this.emit( 'active', this.active ); |
| 1306 |
} |
| 1307 |
}; |
| 1308 |
|
| 1309 |
|
| 1310 |
|
| 1311 |
|
| 1312 |
|
| 1313 |
|
| 1314 |
|
| 1315 |
|
| 1316 |
|
| 1317 |
|
| 1318 |
|
| 1319 |
|
| 1320 |
|
| 1321 |
|
| 1322 |
|
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
|
| 1343 |
|
| 1344 |
|
| 1345 |
OO.ui.StackLayout = function OoUiStackLayout( config ) { |
| 1346 |
|
| 1347 |
|
| 1348 |
|
| 1349 |
config = Object.assign( { scrollable: !!( config && config.continuous ) }, config ); |
| 1350 |
|
| 1351 |
|
| 1352 |
OO.ui.StackLayout.super.call( this, config ); |
| 1353 |
|
| 1354 |
|
| 1355 |
OO.ui.mixin.GroupElement.call( this, Object.assign( { $group: this.$element }, config ) ); |
| 1356 |
|
| 1357 |
|
| 1358 |
this.currentItem = null; |
| 1359 |
this.setContinuous( !!config.continuous ); |
| 1360 |
this.hideUntilFound = !!config.hideUntilFound; |
| 1361 |
|
| 1362 |
|
| 1363 |
this.$element.addClass( 'oo-ui-stackLayout' ); |
| 1364 |
this.addItems( config.items || [] ); |
| 1365 |
}; |
| 1366 |
|
| 1367 |
|
| 1368 |
|
| 1369 |
OO.inheritClass( OO.ui.StackLayout, OO.ui.PanelLayout ); |
| 1370 |
OO.mixinClass( OO.ui.StackLayout, OO.ui.mixin.GroupElement ); |
| 1371 |
|
| 1372 |
|
| 1373 |
|
| 1374 |
|
| 1375 |
|
| 1376 |
|
| 1377 |
|
| 1378 |
|
| 1379 |
|
| 1380 |
|
| 1381 |
|
| 1382 |
|
| 1383 |
|
| 1384 |
|
| 1385 |
|
| 1386 |
|
| 1387 |
|
| 1388 |
|
| 1389 |
OO.ui.StackLayout.prototype.setContinuous = function ( continuous ) { |
| 1390 |
this.continuous = continuous; |
| 1391 |
this.$element.toggleClass( 'oo-ui-stackLayout-continuous', !!continuous ); |
| 1392 |
|
| 1393 |
this.updateHiddenState( this.items, this.currentItem ); |
| 1394 |
}; |
| 1395 |
|
| 1396 |
|
| 1397 |
|
| 1398 |
|
| 1399 |
|
| 1400 |
|
| 1401 |
OO.ui.StackLayout.prototype.isContinuous = function () { |
| 1402 |
return this.continuous; |
| 1403 |
}; |
| 1404 |
|
| 1405 |
|
| 1406 |
|
| 1407 |
|
| 1408 |
|
| 1409 |
|
| 1410 |
OO.ui.StackLayout.prototype.getCurrentItem = function () { |
| 1411 |
return this.currentItem; |
| 1412 |
}; |
| 1413 |
|
| 1414 |
|
| 1415 |
|
| 1416 |
|
| 1417 |
|
| 1418 |
|
| 1419 |
|
| 1420 |
|
| 1421 |
OO.ui.StackLayout.prototype.unsetCurrentItem = function () { |
| 1422 |
const prevItem = this.currentItem; |
| 1423 |
if ( prevItem === null ) { |
| 1424 |
return; |
| 1425 |
} |
| 1426 |
|
| 1427 |
this.currentItem = null; |
| 1428 |
this.emit( 'set', null ); |
| 1429 |
}; |
| 1430 |
|
| 1431 |
|
| 1432 |
|
| 1433 |
|
| 1434 |
|
| 1435 |
|
| 1436 |
OO.ui.StackLayout.prototype.setHideUntilFound = function ( hideUntilFound ) { |
| 1437 |
this.hideUntilFound = hideUntilFound; |
| 1438 |
|
| 1439 |
this.updateHiddenState( this.items, this.currentItem ); |
| 1440 |
}; |
| 1441 |
|
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
OO.ui.StackLayout.prototype.addItems = function ( items, index ) { |
| 1455 |
if ( !items || items.length === 0 ) { |
| 1456 |
return this; |
| 1457 |
} |
| 1458 |
|
| 1459 |
|
| 1460 |
this.updateHiddenState( items, this.currentItem ); |
| 1461 |
|
| 1462 |
|
| 1463 |
OO.ui.mixin.GroupElement.prototype.addItems.call( this, items, index ); |
| 1464 |
|
| 1465 |
if ( !this.currentItem ) { |
| 1466 |
this.setItem( items[ 0 ] ); |
| 1467 |
} |
| 1468 |
|
| 1469 |
return this; |
| 1470 |
}; |
| 1471 |
|
| 1472 |
|
| 1473 |
|
| 1474 |
|
| 1475 |
|
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
OO.ui.StackLayout.prototype.removeItems = function ( itemsToRemove ) { |
| 1484 |
const isCurrentItemRemoved = itemsToRemove.indexOf( this.currentItem ) !== -1; |
| 1485 |
|
| 1486 |
let nextItem; |
| 1487 |
if ( isCurrentItemRemoved ) { |
| 1488 |
let i = this.items.indexOf( this.currentItem ); |
| 1489 |
do { |
| 1490 |
nextItem = this.items[ ++i ]; |
| 1491 |
} while ( nextItem && itemsToRemove.indexOf( nextItem ) !== -1 ); |
| 1492 |
} |
| 1493 |
|
| 1494 |
|
| 1495 |
OO.ui.mixin.GroupElement.prototype.removeItems.call( this, itemsToRemove ); |
| 1496 |
|
| 1497 |
if ( isCurrentItemRemoved ) { |
| 1498 |
if ( this.items.length ) { |
| 1499 |
this.setItem( nextItem || this.items[ this.items.length - 1 ] ); |
| 1500 |
} else { |
| 1501 |
this.unsetCurrentItem(); |
| 1502 |
} |
| 1503 |
} |
| 1504 |
|
| 1505 |
return this; |
| 1506 |
}; |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
|
| 1514 |
|
| 1515 |
|
| 1516 |
|
| 1517 |
|
| 1518 |
OO.ui.StackLayout.prototype.clearItems = function () { |
| 1519 |
this.unsetCurrentItem(); |
| 1520 |
OO.ui.mixin.GroupElement.prototype.clearItems.call( this ); |
| 1521 |
|
| 1522 |
return this; |
| 1523 |
}; |
| 1524 |
|
| 1525 |
|
| 1526 |
|
| 1527 |
|
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
OO.ui.StackLayout.prototype.setItem = function ( item ) { |
| 1536 |
if ( item !== this.currentItem ) { |
| 1537 |
this.updateHiddenState( this.items, item ); |
| 1538 |
|
| 1539 |
if ( this.items.indexOf( item ) !== -1 ) { |
| 1540 |
this.currentItem = item; |
| 1541 |
this.emit( 'set', item ); |
| 1542 |
} else { |
| 1543 |
this.unsetCurrentItem(); |
| 1544 |
} |
| 1545 |
} |
| 1546 |
|
| 1547 |
return this; |
| 1548 |
}; |
| 1549 |
|
| 1550 |
|
| 1551 |
|
| 1552 |
|
| 1553 |
|
| 1554 |
|
| 1555 |
OO.ui.StackLayout.prototype.resetScroll = function () { |
| 1556 |
if ( this.isContinuous() ) { |
| 1557 |
|
| 1558 |
return OO.ui.StackLayout.super.prototype.resetScroll.call( this ); |
| 1559 |
} |
| 1560 |
|
| 1561 |
this.getItems().forEach( ( panel ) => { |
| 1562 |
|
| 1563 |
const hidden = panel.$element.hasClass( 'oo-ui-element-hidden' ); |
| 1564 |
|
| 1565 |
panel.$element.removeClass( 'oo-ui-element-hidden' ); |
| 1566 |
panel.resetScroll(); |
| 1567 |
if ( hidden ) { |
| 1568 |
panel.$element.addClass( 'oo-ui-element-hidden' ); |
| 1569 |
} |
| 1570 |
} ); |
| 1571 |
|
| 1572 |
return this; |
| 1573 |
}; |
| 1574 |
|
| 1575 |
|
| 1576 |
|
| 1577 |
|
| 1578 |
|
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
OO.ui.StackLayout.prototype.updateHiddenState = function ( items, selectedItem ) { |
| 1586 |
if ( !this.isContinuous() ) { |
| 1587 |
items.forEach( ( item ) => { |
| 1588 |
if ( !selectedItem || selectedItem !== item ) { |
| 1589 |
|
| 1590 |
|
| 1591 |
|
| 1592 |
const isDisabled = item instanceof OO.ui.TabPanelLayout && |
| 1593 |
item.getTabItem() && item.getTabItem().isDisabled(); |
| 1594 |
const hideUntilFound = !isDisabled && this.hideUntilFound; |
| 1595 |
|
| 1596 |
|
| 1597 |
item.$element[ 0 ].setAttribute( 'hidden', hideUntilFound ? 'until-found' : 'hidden' ); |
| 1598 |
item.$element.attr( 'aria-hidden', 'true' ); |
| 1599 |
} |
| 1600 |
} ); |
| 1601 |
if ( selectedItem ) { |
| 1602 |
selectedItem.$element[ 0 ].removeAttribute( 'hidden' ); |
| 1603 |
selectedItem.$element.removeAttr( 'aria-hidden' ); |
| 1604 |
} |
| 1605 |
} else { |
| 1606 |
items.forEach( ( item ) => { |
| 1607 |
item.$element[ 0 ].removeAttribute( 'hidden' ); |
| 1608 |
item.$element.removeAttr( 'aria-hidden' ); |
| 1609 |
} ); |
| 1610 |
} |
| 1611 |
}; |
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
|
| 1616 |
|
| 1617 |
|
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
|
| 1625 |
|
| 1626 |
|
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
|
| 1634 |
|
| 1635 |
|
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
|
| 1645 |
|
| 1646 |
|
| 1647 |
|
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
|
| 1656 |
|
| 1657 |
|
| 1658 |
|
| 1659 |
|
| 1660 |
|
| 1661 |
|
| 1662 |
|
| 1663 |
|
| 1664 |
|
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
|
| 1676 |
|
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
|
| 1689 |
|
| 1690 |
|
| 1691 |
|
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
|
| 1696 |
|
| 1697 |
|
| 1698 |
OO.ui.MenuLayout = function OoUiMenuLayout( config ) { |
| 1699 |
|
| 1700 |
config = Object.assign( { |
| 1701 |
expanded: true, |
| 1702 |
showMenu: true, |
| 1703 |
menuPosition: 'before' |
| 1704 |
}, config ); |
| 1705 |
|
| 1706 |
|
| 1707 |
OO.ui.MenuLayout.super.call( this, config ); |
| 1708 |
|
| 1709 |
this.menuPanel = null; |
| 1710 |
this.contentPanel = null; |
| 1711 |
this.expanded = !!config.expanded; |
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
this.$menu = $( '<div>' ); |
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
this.$content = $( '<div>' ); |
| 1724 |
|
| 1725 |
|
| 1726 |
this.$menu.addClass( 'oo-ui-menuLayout-menu' ); |
| 1727 |
this.$content.addClass( 'oo-ui-menuLayout-content' ); |
| 1728 |
this.$element.addClass( 'oo-ui-menuLayout' ); |
| 1729 |
if ( config.expanded ) { |
| 1730 |
this.$element.addClass( 'oo-ui-menuLayout-expanded' ); |
| 1731 |
} else { |
| 1732 |
this.$element.addClass( 'oo-ui-menuLayout-static' ); |
| 1733 |
} |
| 1734 |
if ( config.menuPanel ) { |
| 1735 |
this.setMenuPanel( config.menuPanel ); |
| 1736 |
} |
| 1737 |
if ( config.contentPanel ) { |
| 1738 |
this.setContentPanel( config.contentPanel ); |
| 1739 |
} |
| 1740 |
this.setMenuPosition( config.menuPosition ); |
| 1741 |
this.toggleMenu( config.showMenu ); |
| 1742 |
}; |
| 1743 |
|
| 1744 |
|
| 1745 |
|
| 1746 |
OO.inheritClass( OO.ui.MenuLayout, OO.ui.Layout ); |
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
|
| 1754 |
|
| 1755 |
|
| 1756 |
|
| 1757 |
OO.ui.MenuLayout.prototype.toggleMenu = function ( showMenu ) { |
| 1758 |
showMenu = showMenu === undefined ? !this.showMenu : !!showMenu; |
| 1759 |
|
| 1760 |
if ( this.showMenu !== showMenu ) { |
| 1761 |
this.showMenu = showMenu; |
| 1762 |
this.$element |
| 1763 |
.toggleClass( 'oo-ui-menuLayout-showMenu', this.showMenu ) |
| 1764 |
.toggleClass( 'oo-ui-menuLayout-hideMenu', !this.showMenu ); |
| 1765 |
this.$menu.attr( 'aria-hidden', this.showMenu ? 'false' : 'true' ); |
| 1766 |
} |
| 1767 |
|
| 1768 |
return this; |
| 1769 |
}; |
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
|
| 1776 |
OO.ui.MenuLayout.prototype.isMenuVisible = function () { |
| 1777 |
return this.showMenu; |
| 1778 |
}; |
| 1779 |
|
| 1780 |
|
| 1781 |
|
| 1782 |
|
| 1783 |
|
| 1784 |
|
| 1785 |
|
| 1786 |
|
| 1787 |
OO.ui.MenuLayout.prototype.setMenuPosition = function ( position ) { |
| 1788 |
if ( [ 'top', 'bottom', 'before', 'after' ].indexOf( position ) === -1 ) { |
| 1789 |
position = 'before'; |
| 1790 |
} |
| 1791 |
|
| 1792 |
this.$element.removeClass( 'oo-ui-menuLayout-' + this.menuPosition ); |
| 1793 |
this.menuPosition = position; |
| 1794 |
if ( this.menuPosition === 'top' || this.menuPosition === 'before' ) { |
| 1795 |
this.$element.append( this.$menu, this.$content ); |
| 1796 |
} else { |
| 1797 |
this.$element.append( this.$content, this.$menu ); |
| 1798 |
} |
| 1799 |
this.$element.addClass( 'oo-ui-menuLayout-' + position ); |
| 1800 |
|
| 1801 |
return this; |
| 1802 |
}; |
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
OO.ui.MenuLayout.prototype.getMenuPosition = function () { |
| 1810 |
return this.menuPosition; |
| 1811 |
}; |
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
OO.ui.MenuLayout.prototype.setMenuPanel = function ( menuPanel ) { |
| 1819 |
this.menuPanel = menuPanel; |
| 1820 |
this.$menu.append( this.menuPanel.$element ); |
| 1821 |
}; |
| 1822 |
|
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
OO.ui.MenuLayout.prototype.setContentPanel = function ( contentPanel ) { |
| 1829 |
this.contentPanel = contentPanel; |
| 1830 |
this.$content.append( this.contentPanel.$element ); |
| 1831 |
}; |
| 1832 |
|
| 1833 |
|
| 1834 |
|
| 1835 |
|
| 1836 |
OO.ui.MenuLayout.prototype.clearMenuPanel = function () { |
| 1837 |
this.menuPanel = null; |
| 1838 |
this.$menu.empty(); |
| 1839 |
}; |
| 1840 |
|
| 1841 |
|
| 1842 |
|
| 1843 |
|
| 1844 |
OO.ui.MenuLayout.prototype.clearContentPanel = function () { |
| 1845 |
this.contentPanel = null; |
| 1846 |
this.$content.empty(); |
| 1847 |
}; |
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
OO.ui.MenuLayout.prototype.resetScroll = function () { |
| 1855 |
if ( this.menuPanel ) { |
| 1856 |
this.menuPanel.resetScroll(); |
| 1857 |
} |
| 1858 |
if ( this.contentPanel ) { |
| 1859 |
this.contentPanel.resetScroll(); |
| 1860 |
} |
| 1861 |
|
| 1862 |
return this; |
| 1863 |
}; |
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
|
| 1869 |
|
| 1870 |
|
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
|
| 1884 |
|
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
|
| 1892 |
|
| 1893 |
|
| 1894 |
|
| 1895 |
|
| 1896 |
|
| 1897 |
|
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
|
| 1908 |
|
| 1909 |
|
| 1910 |
|
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
|
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
OO.ui.BookletLayout = function OoUiBookletLayout( config ) { |
| 1919 |
|
| 1920 |
config = config || {}; |
| 1921 |
|
| 1922 |
|
| 1923 |
OO.ui.BookletLayout.super.call( this, config ); |
| 1924 |
|
| 1925 |
|
| 1926 |
this.currentPageName = null; |
| 1927 |
this.pages = {}; |
| 1928 |
this.ignoreFocus = false; |
| 1929 |
this.stackLayout = new OO.ui.StackLayout( { |
| 1930 |
continuous: !!config.continuous, |
| 1931 |
expanded: this.expanded |
| 1932 |
} ); |
| 1933 |
this.setContentPanel( this.stackLayout ); |
| 1934 |
this.autoFocus = config.autoFocus === undefined || !!config.autoFocus; |
| 1935 |
this.outlineVisible = false; |
| 1936 |
this.outlined = !!config.outlined; |
| 1937 |
if ( this.outlined ) { |
| 1938 |
this.editable = !!config.editable; |
| 1939 |
this.outlineControlsWidget = null; |
| 1940 |
this.outlineSelectWidget = new OO.ui.OutlineSelectWidget(); |
| 1941 |
this.outlinePanel = new OO.ui.PanelLayout( { |
| 1942 |
expanded: this.expanded, |
| 1943 |
scrollable: true |
| 1944 |
} ); |
| 1945 |
this.setMenuPanel( this.outlinePanel ); |
| 1946 |
this.outlineVisible = true; |
| 1947 |
if ( this.editable ) { |
| 1948 |
this.outlineControlsWidget = new OO.ui.OutlineControlsWidget( |
| 1949 |
this.outlineSelectWidget |
| 1950 |
); |
| 1951 |
} |
| 1952 |
} |
| 1953 |
this.toggleMenu( this.outlined ); |
| 1954 |
|
| 1955 |
|
| 1956 |
this.stackLayout.connect( this, { |
| 1957 |
set: 'onStackLayoutSet' |
| 1958 |
} ); |
| 1959 |
if ( this.outlined ) { |
| 1960 |
this.outlineSelectWidget.connect( this, { |
| 1961 |
select: 'onOutlineSelectWidgetSelect' |
| 1962 |
} ); |
| 1963 |
} |
| 1964 |
if ( this.autoFocus ) { |
| 1965 |
|
| 1966 |
this.stackLayout.$element.on( 'focusin', this.onStackLayoutFocus.bind( this ) ); |
| 1967 |
} |
| 1968 |
|
| 1969 |
|
| 1970 |
this.$element.addClass( 'oo-ui-bookletLayout' ); |
| 1971 |
this.stackLayout.$element.addClass( 'oo-ui-bookletLayout-stackLayout' ); |
| 1972 |
if ( this.outlined ) { |
| 1973 |
this.outlinePanel.$element |
| 1974 |
.addClass( 'oo-ui-bookletLayout-outlinePanel' ) |
| 1975 |
.append( this.outlineSelectWidget.$element ); |
| 1976 |
if ( this.editable ) { |
| 1977 |
this.outlinePanel.$element |
| 1978 |
.addClass( 'oo-ui-bookletLayout-outlinePanel-editable' ) |
| 1979 |
.append( this.outlineControlsWidget.$element ); |
| 1980 |
} |
| 1981 |
} |
| 1982 |
}; |
| 1983 |
|
| 1984 |
|
| 1985 |
|
| 1986 |
OO.inheritClass( OO.ui.BookletLayout, OO.ui.MenuLayout ); |
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
|
| 1994 |
|
| 1995 |
|
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
|
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
OO.ui.BookletLayout.prototype.onStackLayoutFocus = function ( e ) { |
| 2023 |
|
| 2024 |
const $target = $( e.target ).closest( '.oo-ui-pageLayout' ); |
| 2025 |
for ( const name in this.pages ) { |
| 2026 |
|
| 2027 |
if ( this.pages[ name ].$element[ 0 ] === $target[ 0 ] && name !== this.currentPageName ) { |
| 2028 |
this.setPage( name ); |
| 2029 |
break; |
| 2030 |
} |
| 2031 |
} |
| 2032 |
}; |
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
|
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
OO.ui.BookletLayout.prototype.onStackLayoutSet = function ( page ) { |
| 2041 |
|
| 2042 |
if ( !page ) { |
| 2043 |
return; |
| 2044 |
} |
| 2045 |
let promise; |
| 2046 |
|
| 2047 |
if ( this.stackLayout.isContinuous() && !this.scrolling ) { |
| 2048 |
promise = page.scrollElementIntoView(); |
| 2049 |
} else { |
| 2050 |
promise = $.Deferred().resolve(); |
| 2051 |
} |
| 2052 |
|
| 2053 |
|
| 2054 |
if ( this.autoFocus && !OO.ui.isMobile() && !this.scrolling ) { |
| 2055 |
promise.done( () => { |
| 2056 |
this.focus(); |
| 2057 |
} ); |
| 2058 |
} |
| 2059 |
}; |
| 2060 |
|
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
|
| 2069 |
OO.ui.BookletLayout.prototype.focus = function ( itemIndex ) { |
| 2070 |
const items = this.stackLayout.getItems(); |
| 2071 |
|
| 2072 |
let page; |
| 2073 |
if ( itemIndex !== undefined && items[ itemIndex ] ) { |
| 2074 |
page = items[ itemIndex ]; |
| 2075 |
} else { |
| 2076 |
page = this.stackLayout.getCurrentItem(); |
| 2077 |
} |
| 2078 |
|
| 2079 |
if ( !page && this.outlined ) { |
| 2080 |
this.selectFirstSelectablePage(); |
| 2081 |
page = this.stackLayout.getCurrentItem(); |
| 2082 |
} |
| 2083 |
if ( !page ) { |
| 2084 |
return; |
| 2085 |
} |
| 2086 |
|
| 2087 |
if ( !OO.ui.contains( page.$element[ 0 ], this.getElementDocument().activeElement, true ) ) { |
| 2088 |
page.focus(); |
| 2089 |
} |
| 2090 |
}; |
| 2091 |
|
| 2092 |
|
| 2093 |
|
| 2094 |
|
| 2095 |
|
| 2096 |
OO.ui.BookletLayout.prototype.focusFirstFocusable = function () { |
| 2097 |
OO.ui.findFocusable( this.stackLayout.$element ).focus(); |
| 2098 |
}; |
| 2099 |
|
| 2100 |
|
| 2101 |
|
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
OO.ui.BookletLayout.prototype.onOutlineSelectWidgetSelect = function ( item ) { |
| 2107 |
if ( item ) { |
| 2108 |
this.setPage( item.getData() ); |
| 2109 |
} |
| 2110 |
}; |
| 2111 |
|
| 2112 |
|
| 2113 |
|
| 2114 |
|
| 2115 |
|
| 2116 |
|
| 2117 |
OO.ui.BookletLayout.prototype.isOutlined = function () { |
| 2118 |
return this.outlined; |
| 2119 |
}; |
| 2120 |
|
| 2121 |
|
| 2122 |
|
| 2123 |
|
| 2124 |
|
| 2125 |
|
| 2126 |
OO.ui.BookletLayout.prototype.isEditable = function () { |
| 2127 |
return this.editable; |
| 2128 |
}; |
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
|
| 2135 |
OO.ui.BookletLayout.prototype.isOutlineVisible = function () { |
| 2136 |
return this.outlined && this.outlineVisible; |
| 2137 |
}; |
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
|
| 2144 |
|
| 2145 |
|
| 2146 |
OO.ui.BookletLayout.prototype.toggleOutline = function ( show ) { |
| 2147 |
if ( this.outlined ) { |
| 2148 |
show = show === undefined ? !this.outlineVisible : !!show; |
| 2149 |
this.outlineVisible = show; |
| 2150 |
this.toggleMenu( show ); |
| 2151 |
if ( show && this.editable ) { |
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
setTimeout( () => { |
| 2156 |
OO.ui.Element.static.reconsiderScrollbars( this.outlinePanel.$element[ 0 ] ); |
| 2157 |
}, OO.ui.theme.getDialogTransitionDuration() ); |
| 2158 |
} |
| 2159 |
} |
| 2160 |
|
| 2161 |
return this; |
| 2162 |
}; |
| 2163 |
|
| 2164 |
|
| 2165 |
|
| 2166 |
|
| 2167 |
|
| 2168 |
|
| 2169 |
|
| 2170 |
OO.ui.BookletLayout.prototype.findClosestPage = function ( page ) { |
| 2171 |
const pages = this.stackLayout.getItems(), |
| 2172 |
index = pages.indexOf( page ); |
| 2173 |
|
| 2174 |
if ( index === -1 ) { |
| 2175 |
return null; |
| 2176 |
} |
| 2177 |
|
| 2178 |
const next = pages[ index + 1 ]; |
| 2179 |
const prev = pages[ index - 1 ]; |
| 2180 |
|
| 2181 |
if ( this.outlined ) { |
| 2182 |
const level = this.outlineSelectWidget.findItemFromData( page.getName() ).getLevel(); |
| 2183 |
if ( |
| 2184 |
prev && |
| 2185 |
level === this.outlineSelectWidget.findItemFromData( prev.getName() ).getLevel() |
| 2186 |
) { |
| 2187 |
return prev; |
| 2188 |
} |
| 2189 |
if ( |
| 2190 |
next && |
| 2191 |
level === this.outlineSelectWidget.findItemFromData( next.getName() ).getLevel() |
| 2192 |
) { |
| 2193 |
return next; |
| 2194 |
} |
| 2195 |
} |
| 2196 |
return prev || next || null; |
| 2197 |
}; |
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
|
| 2202 |
|
| 2203 |
|
| 2204 |
|
| 2205 |
|
| 2206 |
OO.ui.BookletLayout.prototype.getOutline = function () { |
| 2207 |
return this.outlineSelectWidget; |
| 2208 |
}; |
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
|
| 2215 |
|
| 2216 |
|
| 2217 |
OO.ui.BookletLayout.prototype.getOutlineControls = function () { |
| 2218 |
return this.outlineControlsWidget; |
| 2219 |
}; |
| 2220 |
|
| 2221 |
|
| 2222 |
|
| 2223 |
|
| 2224 |
|
| 2225 |
|
| 2226 |
|
| 2227 |
OO.ui.BookletLayout.prototype.getPage = function ( name ) { |
| 2228 |
return this.pages[ name ]; |
| 2229 |
}; |
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
OO.ui.BookletLayout.prototype.getCurrentPage = function () { |
| 2237 |
const name = this.getCurrentPageName(); |
| 2238 |
return name ? this.getPage( name ) : undefined; |
| 2239 |
}; |
| 2240 |
|
| 2241 |
|
| 2242 |
|
| 2243 |
|
| 2244 |
|
| 2245 |
|
| 2246 |
OO.ui.BookletLayout.prototype.getCurrentPageName = function () { |
| 2247 |
return this.currentPageName; |
| 2248 |
}; |
| 2249 |
|
| 2250 |
|
| 2251 |
|
| 2252 |
|
| 2253 |
|
| 2254 |
|
| 2255 |
|
| 2256 |
|
| 2257 |
|
| 2258 |
|
| 2259 |
|
| 2260 |
|
| 2261 |
|
| 2262 |
OO.ui.BookletLayout.prototype.addPages = function ( pages, index ) { |
| 2263 |
const stackLayoutPages = this.stackLayout.getItems(), |
| 2264 |
remove = [], |
| 2265 |
items = []; |
| 2266 |
|
| 2267 |
let i, len; |
| 2268 |
let page, name; |
| 2269 |
|
| 2270 |
for ( i = 0, len = pages.length; i < len; i++ ) { |
| 2271 |
page = pages[ i ]; |
| 2272 |
name = page.getName(); |
| 2273 |
|
| 2274 |
if ( Object.prototype.hasOwnProperty.call( this.pages, name ) ) { |
| 2275 |
|
| 2276 |
const currentIndex = stackLayoutPages.indexOf( this.pages[ name ] ); |
| 2277 |
if ( currentIndex !== -1 && currentIndex + 1 < index ) { |
| 2278 |
index--; |
| 2279 |
} |
| 2280 |
remove.push( this.pages[ name ] ); |
| 2281 |
} |
| 2282 |
} |
| 2283 |
if ( remove.length ) { |
| 2284 |
this.removePages( remove ); |
| 2285 |
} |
| 2286 |
|
| 2287 |
|
| 2288 |
for ( i = 0, len = pages.length; i < len; i++ ) { |
| 2289 |
page = pages[ i ]; |
| 2290 |
name = page.getName(); |
| 2291 |
this.pages[ page.getName() ] = page; |
| 2292 |
if ( this.outlined ) { |
| 2293 |
const item = new OO.ui.OutlineOptionWidget( { data: name } ); |
| 2294 |
page.setOutlineItem( item ); |
| 2295 |
items.push( item ); |
| 2296 |
} |
| 2297 |
} |
| 2298 |
|
| 2299 |
if ( this.outlined ) { |
| 2300 |
this.outlineSelectWidget.addItems( items, index ); |
| 2301 |
|
| 2302 |
} |
| 2303 |
this.stackLayout.addItems( pages, index ); |
| 2304 |
this.emit( 'add', pages, index ); |
| 2305 |
|
| 2306 |
return this; |
| 2307 |
}; |
| 2308 |
|
| 2309 |
|
| 2310 |
|
| 2311 |
|
| 2312 |
|
| 2313 |
|
| 2314 |
|
| 2315 |
|
| 2316 |
|
| 2317 |
|
| 2318 |
|
| 2319 |
OO.ui.BookletLayout.prototype.removePages = function ( pages ) { |
| 2320 |
const itemsToRemove = []; |
| 2321 |
|
| 2322 |
for ( let i = 0, len = pages.length; i < len; i++ ) { |
| 2323 |
const page = pages[ i ]; |
| 2324 |
const name = page.getName(); |
| 2325 |
delete this.pages[ name ]; |
| 2326 |
if ( this.outlined ) { |
| 2327 |
itemsToRemove.push( this.outlineSelectWidget.findItemFromData( name ) ); |
| 2328 |
page.setOutlineItem( null ); |
| 2329 |
} |
| 2330 |
|
| 2331 |
if ( this.currentPageName === name ) { |
| 2332 |
this.currentPageName = null; |
| 2333 |
} |
| 2334 |
} |
| 2335 |
if ( itemsToRemove.length ) { |
| 2336 |
this.outlineSelectWidget.removeItems( itemsToRemove ); |
| 2337 |
|
| 2338 |
} |
| 2339 |
this.stackLayout.removeItems( pages ); |
| 2340 |
this.emit( 'remove', pages ); |
| 2341 |
|
| 2342 |
return this; |
| 2343 |
}; |
| 2344 |
|
| 2345 |
|
| 2346 |
|
| 2347 |
|
| 2348 |
|
| 2349 |
|
| 2350 |
|
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
OO.ui.BookletLayout.prototype.clearPages = function () { |
| 2355 |
const pages = this.stackLayout.getItems(); |
| 2356 |
|
| 2357 |
this.pages = {}; |
| 2358 |
this.currentPageName = null; |
| 2359 |
if ( this.outlined ) { |
| 2360 |
this.outlineSelectWidget.clearItems(); |
| 2361 |
for ( let i = 0, len = pages.length; i < len; i++ ) { |
| 2362 |
pages[ i ].setOutlineItem( null ); |
| 2363 |
} |
| 2364 |
} |
| 2365 |
this.stackLayout.clearItems(); |
| 2366 |
|
| 2367 |
this.emit( 'remove', pages ); |
| 2368 |
|
| 2369 |
return this; |
| 2370 |
}; |
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
|
| 2376 |
|
| 2377 |
|
| 2378 |
OO.ui.BookletLayout.prototype.setPage = function ( name ) { |
| 2379 |
const page = this.pages[ name ]; |
| 2380 |
if ( !page || name === this.currentPageName ) { |
| 2381 |
return; |
| 2382 |
} |
| 2383 |
|
| 2384 |
const previousPage = this.currentPageName ? this.pages[ this.currentPageName ] : null; |
| 2385 |
this.currentPageName = name; |
| 2386 |
|
| 2387 |
if ( this.outlined ) { |
| 2388 |
const selectedItem = this.outlineSelectWidget.findSelectedItem(); |
| 2389 |
if ( !selectedItem || selectedItem.getData() !== name ) { |
| 2390 |
|
| 2391 |
|
| 2392 |
|
| 2393 |
this.outlineSelectWidget.selectItemByData( name ); |
| 2394 |
} |
| 2395 |
} |
| 2396 |
|
| 2397 |
let $focused; |
| 2398 |
if ( previousPage ) { |
| 2399 |
previousPage.setActive( false ); |
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
if ( this.autoFocus && |
| 2406 |
!OO.ui.isMobile() && |
| 2407 |
this.stackLayout.isContinuous() && |
| 2408 |
OO.ui.findFocusable( page.$element ).length !== 0 |
| 2409 |
) { |
| 2410 |
$focused = previousPage.$element.find( ':focus' ); |
| 2411 |
if ( $focused.length ) { |
| 2412 |
$focused[ 0 ].blur(); |
| 2413 |
} |
| 2414 |
} |
| 2415 |
} |
| 2416 |
page.setActive( true ); |
| 2417 |
this.stackLayout.setItem( page ); |
| 2418 |
if ( !this.stackLayout.isContinuous() && previousPage ) { |
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
$focused = previousPage.$element.find( ':focus' ); |
| 2423 |
if ( $focused.length ) { |
| 2424 |
$focused[ 0 ].blur(); |
| 2425 |
} |
| 2426 |
} |
| 2427 |
this.emit( 'set', page ); |
| 2428 |
}; |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
OO.ui.BookletLayout.prototype.resetScroll = function () { |
| 2436 |
|
| 2437 |
OO.ui.BookletLayout.super.prototype.resetScroll.call( this ); |
| 2438 |
|
| 2439 |
if ( |
| 2440 |
this.outlined && |
| 2441 |
this.stackLayout.isContinuous() && |
| 2442 |
this.outlineSelectWidget.findFirstSelectableItem() |
| 2443 |
) { |
| 2444 |
this.scrolling = true; |
| 2445 |
this.outlineSelectWidget.selectItem( this.outlineSelectWidget.findFirstSelectableItem() ); |
| 2446 |
this.scrolling = false; |
| 2447 |
} |
| 2448 |
return this; |
| 2449 |
}; |
| 2450 |
|
| 2451 |
|
| 2452 |
|
| 2453 |
|
| 2454 |
|
| 2455 |
|
| 2456 |
|
| 2457 |
OO.ui.BookletLayout.prototype.selectFirstSelectablePage = function () { |
| 2458 |
if ( !this.outlineSelectWidget.findSelectedItem() ) { |
| 2459 |
this.outlineSelectWidget.selectItem( this.outlineSelectWidget.findFirstSelectableItem() ); |
| 2460 |
} |
| 2461 |
|
| 2462 |
return this; |
| 2463 |
}; |
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
|
| 2475 |
|
| 2476 |
|
| 2477 |
|
| 2478 |
|
| 2479 |
|
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
|
| 2488 |
|
| 2489 |
|
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
|
| 2509 |
OO.ui.IndexLayout = function OoUiIndexLayout( config ) { |
| 2510 |
|
| 2511 |
config = Object.assign( {}, config, { menuPosition: 'top' } ); |
| 2512 |
|
| 2513 |
|
| 2514 |
OO.ui.IndexLayout.super.call( this, config ); |
| 2515 |
|
| 2516 |
|
| 2517 |
this.currentTabPanelName = null; |
| 2518 |
|
| 2519 |
this.tabPanels = config.tabPanels || {}; |
| 2520 |
this.openMatchedPanels = config.openMatchedPanels === undefined || !!config.openMatchedPanels; |
| 2521 |
|
| 2522 |
this.ignoreFocus = false; |
| 2523 |
if ( this.contentPanel ) { |
| 2524 |
this.contentPanel.setHideUntilFound( this.openMatchedPanels ); |
| 2525 |
} |
| 2526 |
this.stackLayout = this.contentPanel || new OO.ui.StackLayout( { |
| 2527 |
continuous: !!config.continuous, |
| 2528 |
expanded: this.expanded, |
| 2529 |
hideUntilFound: this.openMatchedPanels |
| 2530 |
} ); |
| 2531 |
this.setContentPanel( this.stackLayout ); |
| 2532 |
this.autoFocus = config.autoFocus === undefined || !!config.autoFocus; |
| 2533 |
|
| 2534 |
if ( config.tabSelectWidget ) { |
| 2535 |
|
| 2536 |
|
| 2537 |
this.stackLayout.getItems().forEach( ( tabPanel, i ) => { |
| 2538 |
if ( !tabPanel.getTabItem() ) { |
| 2539 |
tabPanel.setTabItem( config.tabSelectWidget.items[ i ] || null ); |
| 2540 |
} |
| 2541 |
} ); |
| 2542 |
} |
| 2543 |
|
| 2544 |
this.tabSelectWidget = config.tabSelectWidget || new OO.ui.TabSelectWidget( { |
| 2545 |
framed: config.framed === undefined || config.framed |
| 2546 |
} ); |
| 2547 |
this.tabPanel = this.menuPanel || new OO.ui.PanelLayout( { |
| 2548 |
expanded: this.expanded |
| 2549 |
} ); |
| 2550 |
this.setMenuPanel( this.tabPanel ); |
| 2551 |
|
| 2552 |
this.toggleMenu( true ); |
| 2553 |
|
| 2554 |
|
| 2555 |
this.stackLayout.connect( this, { |
| 2556 |
set: 'onStackLayoutSet' |
| 2557 |
} ); |
| 2558 |
if ( this.openMatchedPanels ) { |
| 2559 |
this.stackLayout.$element.on( 'beforematch', this.onStackLayoutBeforeMatch.bind( this ) ); |
| 2560 |
} |
| 2561 |
this.tabSelectWidget.connect( this, { |
| 2562 |
select: 'onTabSelectWidgetSelect' |
| 2563 |
} ); |
| 2564 |
if ( this.autoFocus ) { |
| 2565 |
|
| 2566 |
this.stackLayout.$element.on( 'focusin', this.onStackLayoutFocus.bind( this ) ); |
| 2567 |
} |
| 2568 |
|
| 2569 |
|
| 2570 |
this.$element.addClass( 'oo-ui-indexLayout' ); |
| 2571 |
this.stackLayout.$element.addClass( 'oo-ui-indexLayout-stackLayout' ); |
| 2572 |
this.tabPanel.$element |
| 2573 |
.addClass( 'oo-ui-indexLayout-tabPanel' ) |
| 2574 |
.append( this.tabSelectWidget.$element ); |
| 2575 |
|
| 2576 |
this.selectFirstSelectableTabPanel(); |
| 2577 |
}; |
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
OO.inheritClass( OO.ui.IndexLayout, OO.ui.MenuLayout ); |
| 2582 |
|
| 2583 |
|
| 2584 |
|
| 2585 |
|
| 2586 |
|
| 2587 |
|
| 2588 |
|
| 2589 |
|
| 2590 |
|
| 2591 |
|
| 2592 |
|
| 2593 |
|
| 2594 |
|
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
|
| 2609 |
|
| 2610 |
|
| 2611 |
|
| 2612 |
|
| 2613 |
|
| 2614 |
|
| 2615 |
|
| 2616 |
|
| 2617 |
OO.ui.IndexLayout.prototype.onStackLayoutFocus = function ( e ) { |
| 2618 |
|
| 2619 |
const $target = $( e.target ).closest( '.oo-ui-tabPanelLayout' ); |
| 2620 |
for ( const name in this.tabPanels ) { |
| 2621 |
|
| 2622 |
if ( this.tabPanels[ name ].$element[ 0 ] === $target[ 0 ] && |
| 2623 |
name !== this.currentTabPanelName ) { |
| 2624 |
this.setTabPanel( name ); |
| 2625 |
break; |
| 2626 |
} |
| 2627 |
} |
| 2628 |
}; |
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
|
| 2635 |
|
| 2636 |
OO.ui.IndexLayout.prototype.onStackLayoutSet = function ( tabPanel ) { |
| 2637 |
|
| 2638 |
if ( !tabPanel ) { |
| 2639 |
return; |
| 2640 |
} |
| 2641 |
|
| 2642 |
if ( this.autoFocus && !OO.ui.isMobile() ) { |
| 2643 |
this.focus(); |
| 2644 |
} |
| 2645 |
}; |
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
OO.ui.IndexLayout.prototype.onStackLayoutBeforeMatch = function ( event ) { |
| 2653 |
let tabPanel; |
| 2654 |
|
| 2655 |
this.stackLayout.getItems().some( ( item ) => { |
| 2656 |
if ( item.$element[ 0 ] === event.target ) { |
| 2657 |
tabPanel = item; |
| 2658 |
return true; |
| 2659 |
} |
| 2660 |
return false; |
| 2661 |
} ); |
| 2662 |
if ( tabPanel ) { |
| 2663 |
const tabItem = tabPanel.getTabItem(); |
| 2664 |
if ( tabItem ) { |
| 2665 |
this.tabSelectWidget.selectItem( tabItem ); |
| 2666 |
} |
| 2667 |
} |
| 2668 |
}; |
| 2669 |
|
| 2670 |
|
| 2671 |
|
| 2672 |
|
| 2673 |
|
| 2674 |
|
| 2675 |
|
| 2676 |
|
| 2677 |
|
| 2678 |
OO.ui.IndexLayout.prototype.focus = function ( itemIndex ) { |
| 2679 |
const items = this.stackLayout.getItems(); |
| 2680 |
|
| 2681 |
let tabPanel; |
| 2682 |
if ( itemIndex !== undefined && items[ itemIndex ] ) { |
| 2683 |
tabPanel = items[ itemIndex ]; |
| 2684 |
} else { |
| 2685 |
tabPanel = this.stackLayout.getCurrentItem(); |
| 2686 |
} |
| 2687 |
|
| 2688 |
if ( !tabPanel ) { |
| 2689 |
this.selectFirstSelectableTabPanel(); |
| 2690 |
tabPanel = this.stackLayout.getCurrentItem(); |
| 2691 |
} |
| 2692 |
if ( !tabPanel ) { |
| 2693 |
return; |
| 2694 |
} |
| 2695 |
|
| 2696 |
if ( !OO.ui.contains( |
| 2697 |
tabPanel.$element[ 0 ], |
| 2698 |
this.getElementDocument().activeElement, |
| 2699 |
true |
| 2700 |
) ) { |
| 2701 |
tabPanel.focus(); |
| 2702 |
} |
| 2703 |
}; |
| 2704 |
|
| 2705 |
|
| 2706 |
|
| 2707 |
|
| 2708 |
|
| 2709 |
OO.ui.IndexLayout.prototype.focusFirstFocusable = function () { |
| 2710 |
OO.ui.findFocusable( this.stackLayout.$element ).focus(); |
| 2711 |
}; |
| 2712 |
|
| 2713 |
|
| 2714 |
|
| 2715 |
|
| 2716 |
|
| 2717 |
|
| 2718 |
|
| 2719 |
OO.ui.IndexLayout.prototype.onTabSelectWidgetSelect = function ( item ) { |
| 2720 |
if ( item ) { |
| 2721 |
this.setTabPanel( item.getData() ); |
| 2722 |
} |
| 2723 |
}; |
| 2724 |
|
| 2725 |
|
| 2726 |
|
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
OO.ui.IndexLayout.prototype.getClosestTabPanel = function ( tabPanel ) { |
| 2732 |
const tabPanels = this.stackLayout.getItems(), |
| 2733 |
index = tabPanels.indexOf( tabPanel ); |
| 2734 |
|
| 2735 |
if ( index === -1 ) { |
| 2736 |
return null; |
| 2737 |
} |
| 2738 |
|
| 2739 |
const next = tabPanels[ index + 1 ]; |
| 2740 |
const prev = tabPanels[ index - 1 ]; |
| 2741 |
|
| 2742 |
const level = this.tabSelectWidget.findItemFromData( tabPanel.getName() ).getLevel(); |
| 2743 |
if ( |
| 2744 |
prev && |
| 2745 |
level === this.tabSelectWidget.findItemFromData( prev.getName() ).getLevel() |
| 2746 |
) { |
| 2747 |
return prev; |
| 2748 |
} |
| 2749 |
if ( |
| 2750 |
next && |
| 2751 |
level === this.tabSelectWidget.findItemFromData( next.getName() ).getLevel() |
| 2752 |
) { |
| 2753 |
return next; |
| 2754 |
} |
| 2755 |
return prev || next || null; |
| 2756 |
}; |
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
OO.ui.IndexLayout.prototype.getTabs = function () { |
| 2764 |
return this.tabSelectWidget; |
| 2765 |
}; |
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
|
| 2773 |
OO.ui.IndexLayout.prototype.getTabPanel = function ( name ) { |
| 2774 |
return this.tabPanels[ name ]; |
| 2775 |
}; |
| 2776 |
|
| 2777 |
|
| 2778 |
|
| 2779 |
|
| 2780 |
|
| 2781 |
|
| 2782 |
OO.ui.IndexLayout.prototype.getCurrentTabPanel = function () { |
| 2783 |
const name = this.getCurrentTabPanelName(); |
| 2784 |
return name ? this.getTabPanel( name ) : undefined; |
| 2785 |
}; |
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
|
| 2790 |
|
| 2791 |
|
| 2792 |
OO.ui.IndexLayout.prototype.getCurrentTabPanelName = function () { |
| 2793 |
return this.currentTabPanelName; |
| 2794 |
}; |
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
|
| 2808 |
OO.ui.IndexLayout.prototype.addTabPanels = function ( tabPanels, index ) { |
| 2809 |
let i, len, name, tabPanel, tabItem, currentIndex; |
| 2810 |
const stackLayoutTabPanels = this.stackLayout.getItems(), |
| 2811 |
remove = [], |
| 2812 |
tabItems = []; |
| 2813 |
|
| 2814 |
|
| 2815 |
for ( i = 0, len = tabPanels.length; i < len; i++ ) { |
| 2816 |
tabPanel = tabPanels[ i ]; |
| 2817 |
name = tabPanel.getName(); |
| 2818 |
|
| 2819 |
if ( Object.prototype.hasOwnProperty.call( this.tabPanels, name ) ) { |
| 2820 |
|
| 2821 |
currentIndex = stackLayoutTabPanels.indexOf( this.tabPanels[ name ] ); |
| 2822 |
if ( currentIndex !== -1 && currentIndex + 1 < index ) { |
| 2823 |
index--; |
| 2824 |
} |
| 2825 |
remove.push( this.tabPanels[ name ] ); |
| 2826 |
} |
| 2827 |
} |
| 2828 |
if ( remove.length ) { |
| 2829 |
this.removeTabPanels( remove ); |
| 2830 |
} |
| 2831 |
|
| 2832 |
|
| 2833 |
for ( i = 0, len = tabPanels.length; i < len; i++ ) { |
| 2834 |
tabPanel = tabPanels[ i ]; |
| 2835 |
name = tabPanel.getName(); |
| 2836 |
this.tabPanels[ name ] = tabPanel; |
| 2837 |
tabItem = new OO.ui.TabOptionWidget( |
| 2838 |
Object.assign( { data: name }, tabPanel.getTabItemConfig() ) |
| 2839 |
); |
| 2840 |
tabPanel.setTabItem( tabItem ); |
| 2841 |
tabItems.push( tabItem ); |
| 2842 |
} |
| 2843 |
|
| 2844 |
if ( tabItems.length ) { |
| 2845 |
this.tabSelectWidget.addItems( tabItems, index ); |
| 2846 |
this.selectFirstSelectableTabPanel(); |
| 2847 |
} |
| 2848 |
this.stackLayout.addItems( tabPanels, index ); |
| 2849 |
this.emit( 'add', tabPanels, index ); |
| 2850 |
|
| 2851 |
return this; |
| 2852 |
}; |
| 2853 |
|
| 2854 |
|
| 2855 |
|
| 2856 |
|
| 2857 |
|
| 2858 |
|
| 2859 |
|
| 2860 |
|
| 2861 |
|
| 2862 |
|
| 2863 |
|
| 2864 |
OO.ui.IndexLayout.prototype.removeTabPanels = function ( tabPanels ) { |
| 2865 |
let i, len, name, tabPanel; |
| 2866 |
|
| 2867 |
const items = []; |
| 2868 |
|
| 2869 |
for ( i = 0, len = tabPanels.length; i < len; i++ ) { |
| 2870 |
tabPanel = tabPanels[ i ]; |
| 2871 |
name = tabPanel.getName(); |
| 2872 |
delete this.tabPanels[ name ]; |
| 2873 |
items.push( this.tabSelectWidget.findItemFromData( name ) ); |
| 2874 |
tabPanel.setTabItem( null ); |
| 2875 |
} |
| 2876 |
if ( items.length ) { |
| 2877 |
this.tabSelectWidget.removeItems( items ); |
| 2878 |
this.selectFirstSelectableTabPanel(); |
| 2879 |
} |
| 2880 |
this.stackLayout.removeItems( tabPanels ); |
| 2881 |
this.emit( 'remove', tabPanels ); |
| 2882 |
|
| 2883 |
return this; |
| 2884 |
}; |
| 2885 |
|
| 2886 |
|
| 2887 |
|
| 2888 |
|
| 2889 |
|
| 2890 |
|
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
OO.ui.IndexLayout.prototype.clearTabPanels = function () { |
| 2896 |
let i, len; |
| 2897 |
|
| 2898 |
const tabPanels = this.stackLayout.getItems(); |
| 2899 |
|
| 2900 |
this.tabPanels = {}; |
| 2901 |
this.currentTabPanelName = null; |
| 2902 |
this.tabSelectWidget.clearItems(); |
| 2903 |
for ( i = 0, len = tabPanels.length; i < len; i++ ) { |
| 2904 |
tabPanels[ i ].setTabItem( null ); |
| 2905 |
} |
| 2906 |
this.stackLayout.clearItems(); |
| 2907 |
|
| 2908 |
this.emit( 'remove', tabPanels ); |
| 2909 |
|
| 2910 |
return this; |
| 2911 |
}; |
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
OO.ui.IndexLayout.prototype.setTabPanel = function ( name ) { |
| 2920 |
let selectedItem, |
| 2921 |
$focused, |
| 2922 |
previousTabPanel, |
| 2923 |
tabPanel; |
| 2924 |
|
| 2925 |
if ( name !== this.currentTabPanelName ) { |
| 2926 |
tabPanel = this.getTabPanel( name ); |
| 2927 |
previousTabPanel = this.getCurrentTabPanel(); |
| 2928 |
selectedItem = this.tabSelectWidget.findSelectedItem(); |
| 2929 |
if ( !selectedItem || selectedItem.getData() !== name ) { |
| 2930 |
this.tabSelectWidget.selectItemByData( name ); |
| 2931 |
} |
| 2932 |
if ( tabPanel ) { |
| 2933 |
if ( previousTabPanel ) { |
| 2934 |
previousTabPanel.setActive( false ); |
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
if ( |
| 2941 |
this.autoFocus && |
| 2942 |
!OO.ui.isMobile() && |
| 2943 |
this.stackLayout.isContinuous() && |
| 2944 |
OO.ui.findFocusable( tabPanel.$element ).length !== 0 |
| 2945 |
) { |
| 2946 |
$focused = previousTabPanel.$element.find( ':focus' ); |
| 2947 |
if ( $focused.length ) { |
| 2948 |
$focused[ 0 ].blur(); |
| 2949 |
} |
| 2950 |
} |
| 2951 |
} |
| 2952 |
this.currentTabPanelName = name; |
| 2953 |
tabPanel.setActive( true ); |
| 2954 |
this.stackLayout.setItem( tabPanel ); |
| 2955 |
if ( !this.stackLayout.isContinuous() && previousTabPanel ) { |
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
$focused = previousTabPanel.$element.find( ':focus' ); |
| 2960 |
if ( $focused.length ) { |
| 2961 |
$focused[ 0 ].blur(); |
| 2962 |
} |
| 2963 |
} |
| 2964 |
this.emit( 'set', tabPanel ); |
| 2965 |
} |
| 2966 |
} |
| 2967 |
}; |
| 2968 |
|
| 2969 |
|
| 2970 |
|
| 2971 |
|
| 2972 |
|
| 2973 |
|
| 2974 |
|
| 2975 |
OO.ui.IndexLayout.prototype.selectFirstSelectableTabPanel = function () { |
| 2976 |
if ( !this.tabSelectWidget.findSelectedItem() ) { |
| 2977 |
this.tabSelectWidget.selectItem( this.tabSelectWidget.findFirstSelectableItem() ); |
| 2978 |
} |
| 2979 |
|
| 2980 |
return this; |
| 2981 |
}; |
| 2982 |
|
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
|
| 2996 |
OO.ui.CopyTextLayout = function OoUiCopyTextLayout( config ) { |
| 2997 |
config = config || {}; |
| 2998 |
|
| 2999 |
|
| 3000 |
const TextClass = config.multiline ? OO.ui.MultilineTextInputWidget : OO.ui.TextInputWidget; |
| 3001 |
|
| 3002 |
this.textInput = new TextClass( Object.assign( { |
| 3003 |
value: config.copyText, |
| 3004 |
readOnly: true |
| 3005 |
}, config.textInput ) ); |
| 3006 |
this.button = new OO.ui.ButtonWidget( Object.assign( { |
| 3007 |
label: OO.ui.msg( 'ooui-copytextlayout-copy' ), |
| 3008 |
icon: 'copy' |
| 3009 |
}, config.button ) ); |
| 3010 |
|
| 3011 |
|
| 3012 |
OO.ui.CopyTextLayout.super.call( this, this.textInput, this.button, config ); |
| 3013 |
|
| 3014 |
|
| 3015 |
if ( config.multiline ) { |
| 3016 |
this.$input.removeClass( 'oo-ui-actionFieldLayout-input' ); |
| 3017 |
this.$button |
| 3018 |
.removeClass( 'oo-ui-actionFieldLayout-button' ) |
| 3019 |
.addClass( 'oo-ui-copyTextLayout-multiline-button' ); |
| 3020 |
} |
| 3021 |
|
| 3022 |
|
| 3023 |
this.button.connect( this, { click: 'onButtonClick' } ); |
| 3024 |
this.textInput.$input.on( 'focus', this.onInputFocus.bind( this ) ); |
| 3025 |
|
| 3026 |
this.$element.addClass( 'oo-ui-copyTextLayout' ); |
| 3027 |
}; |
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
OO.inheritClass( OO.ui.CopyTextLayout, OO.ui.ActionFieldLayout ); |
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
|
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
|
| 3049 |
OO.ui.CopyTextLayout.prototype.onButtonClick = function () { |
| 3050 |
let copied; |
| 3051 |
|
| 3052 |
this.selectText(); |
| 3053 |
|
| 3054 |
try { |
| 3055 |
copied = document.execCommand( 'copy' ); |
| 3056 |
} catch ( e ) { |
| 3057 |
copied = false; |
| 3058 |
} |
| 3059 |
this.emit( 'copy', copied ); |
| 3060 |
}; |
| 3061 |
|
| 3062 |
|
| 3063 |
|
| 3064 |
|
| 3065 |
OO.ui.CopyTextLayout.prototype.onInputFocus = function () { |
| 3066 |
if ( !this.selecting ) { |
| 3067 |
this.selectText(); |
| 3068 |
} |
| 3069 |
}; |
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
OO.ui.CopyTextLayout.prototype.selectText = function () { |
| 3075 |
const input = this.textInput.$input[ 0 ], |
| 3076 |
scrollTop = input.scrollTop, |
| 3077 |
scrollLeft = input.scrollLeft; |
| 3078 |
|
| 3079 |
this.selecting = true; |
| 3080 |
this.textInput.select(); |
| 3081 |
this.selecting = false; |
| 3082 |
|
| 3083 |
|
| 3084 |
input.scrollTop = scrollTop; |
| 3085 |
input.scrollLeft = scrollLeft; |
| 3086 |
}; |
| 3087 |
|
| 3088 |
|
| 3089 |
ted by a |
| 3090 |
|
| 3091 |
|
| 3092 |
|
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
|
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
|
| 3105 |
|
| 3106 |
|
| 3107 |
|
| 3108 |
|
| 3109 |
|
| 3110 |
|
| 3111 |
|
| 3112 |
|
| 3113 |
|
| 3114 |
|
| 3115 |
|
| 3116 |
|
| 3117 |
|
| 3118 |
|
| 3119 |
|
| 3120 |
|
| 3121 |
|
| 3122 |
ff |
| 3123 |
|
| 3124 |
|
| 3125 |
OO.ui.ToggleButtonWidget = function OoUiToggleButtonWidget( config ) { |
| 3126 |
|
| 3127 |
config = config || {}; |
| 3128 |
|
| 3129 |
|
| 3130 |
OO.ui.ToggleButtonWidget.super.call( this, config ); |
| 3131 |
|
| 3132 |
|
| 3133 |
OO.ui.mixin.ButtonElement.call( this, Object.assign( { |
| 3134 |
active: this.active |
| 3135 |
}, config ) ); |
| 3136 |
OO.ui.mixin.IconElement.call( this, config ); |
| 3137 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 3138 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 3139 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 3140 |
OO.ui.mixin.TabIndexedElement.call( this, Object.assign( { |
| 3141 |
$tabIndexed: this.$button |
| 3142 |
}, config ) ); |
| 3143 |
|
| 3144 |
|
| 3145 |
this.connect( this, { |
| 3146 |
click: 'onAction' |
| 3147 |
} ); |
| 3148 |
|
| 3149 |
|
| 3150 |
this.$button.append( this.$icon, this.$label, this.$indicator ); |
| 3151 |
this.$element |
| 3152 |
.addClass( 'oo-ui-toggleButtonWidget' ) |
| 3153 |
.append( this.$button ); |
| 3154 |
this.setTitledElement( this.$button ); |
| 3155 |
}; |
| 3156 |
|
| 3157 |
|
| 3158 |
|
| 3159 |
OO.inheritClass( OO.ui.ToggleButtonWidget, OO.ui.ToggleWidget ); |
| 3160 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.ButtonElement ); |
| 3161 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.IconElement ); |
| 3162 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.IndicatorElement ); |
| 3163 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.LabelElement ); |
| 3164 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.FlaggedElement ); |
| 3165 |
OO.mixinClass( OO.ui.ToggleButtonWidget, OO.ui.mixin.TabIndexedElement ); |
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
OO.ui.ToggleButtonWidget.static.tagName = 'span'; |
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
OO.ui.ToggleButtonWidget.prototype.onAction = function () { |
| 3183 |
this.setValue( !this.value ); |
| 3184 |
}; |
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
OO.ui.ToggleButtonWidget.prototype.setValue = function ( value ) { |
| 3190 |
value = !!value; |
| 3191 |
if ( value !== this.value ) { |
| 3192 |
|
| 3193 |
if ( this.$button ) { |
| 3194 |
this.$button.attr( 'aria-pressed', value.toString() ); |
| 3195 |
} |
| 3196 |
this.setActive( value ); |
| 3197 |
} |
| 3198 |
|
| 3199 |
|
| 3200 |
OO.ui.ToggleButtonWidget.super.prototype.setValue.call( this, value ); |
| 3201 |
|
| 3202 |
return this; |
| 3203 |
}; |
| 3204 |
|
| 3205 |
|
| 3206 |
|
| 3207 |
|
| 3208 |
OO.ui.ToggleButtonWidget.prototype.setButtonElement = function ( $button ) { |
| 3209 |
if ( this.$button ) { |
| 3210 |
this.$button.removeAttr( 'aria-pressed' ); |
| 3211 |
} |
| 3212 |
OO.ui.mixin.ButtonElement.prototype.setButtonElement.call( this, $button ); |
| 3213 |
this.$button.attr( 'aria-pressed', this.value.toString() ); |
| 3214 |
}; |
| 3215 |
|
| 3216 |
|
| 3217 |
|
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
|
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
|
| 3234 |
OO.ui.OutlineControlsWidget = function OoUiOutlineControlsWidget( outline, config ) { |
| 3235 |
|
| 3236 |
if ( OO.isPlainObject( outline ) && config === undefined ) { |
| 3237 |
config = outline; |
| 3238 |
outline = config.outline; |
| 3239 |
} |
| 3240 |
|
| 3241 |
|
| 3242 |
config = config || {}; |
| 3243 |
|
| 3244 |
|
| 3245 |
OO.ui.OutlineControlsWidget.super.call( this, config ); |
| 3246 |
|
| 3247 |
|
| 3248 |
OO.ui.mixin.GroupElement.call( this, config ); |
| 3249 |
|
| 3250 |
|
| 3251 |
this.outline = outline; |
| 3252 |
this.$movers = $( '<div>' ); |
| 3253 |
this.upButton = new OO.ui.ButtonWidget( { |
| 3254 |
framed: false, |
| 3255 |
icon: 'upTriangle', |
| 3256 |
title: OO.ui.msg( 'ooui-outline-control-move-up' ) |
| 3257 |
} ); |
| 3258 |
this.downButton = new OO.ui.ButtonWidget( { |
| 3259 |
framed: false, |
| 3260 |
icon: 'downTriangle', |
| 3261 |
title: OO.ui.msg( 'ooui-outline-control-move-down' ) |
| 3262 |
} ); |
| 3263 |
this.removeButton = new OO.ui.ButtonWidget( { |
| 3264 |
framed: false, |
| 3265 |
icon: 'trash', |
| 3266 |
title: OO.ui.msg( 'ooui-outline-control-remove' ) |
| 3267 |
} ); |
| 3268 |
this.abilities = { move: true, remove: true }; |
| 3269 |
|
| 3270 |
|
| 3271 |
outline.connect( this, { |
| 3272 |
select: 'onOutlineChange', |
| 3273 |
add: 'onOutlineChange', |
| 3274 |
remove: 'onOutlineChange' |
| 3275 |
} ); |
| 3276 |
this.upButton.connect( this, { |
| 3277 |
click: [ 'emit', 'move', -1 ] |
| 3278 |
} ); |
| 3279 |
this.downButton.connect( this, { |
| 3280 |
click: [ 'emit', 'move', 1 ] |
| 3281 |
} ); |
| 3282 |
this.removeButton.connect( this, { |
| 3283 |
click: [ 'emit', 'remove' ] |
| 3284 |
} ); |
| 3285 |
|
| 3286 |
|
| 3287 |
this.$element.addClass( 'oo-ui-outlineControlsWidget' ); |
| 3288 |
this.$group.addClass( 'oo-ui-outlineControlsWidget-items' ); |
| 3289 |
this.$movers |
| 3290 |
.addClass( 'oo-ui-outlineControlsWidget-movers' ) |
| 3291 |
.append( this.upButton.$element, this.downButton.$element, this.removeButton.$element ); |
| 3292 |
this.$element.append( this.$icon, this.$group, this.$movers ); |
| 3293 |
this.setAbilities( config.abilities || {} ); |
| 3294 |
}; |
| 3295 |
|
| 3296 |
|
| 3297 |
|
| 3298 |
OO.inheritClass( OO.ui.OutlineControlsWidget, OO.ui.Widget ); |
| 3299 |
OO.mixinClass( OO.ui.OutlineControlsWidget, OO.ui.mixin.GroupElement ); |
| 3300 |
|
| 3301 |
|
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
|
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
OO.ui.OutlineControlsWidget.prototype.setAbilities = function ( abilities ) { |
| 3322 |
for ( const ability in this.abilities ) { |
| 3323 |
if ( abilities[ ability ] !== undefined ) { |
| 3324 |
this.abilities[ ability ] = !!abilities[ ability ]; |
| 3325 |
} |
| 3326 |
} |
| 3327 |
|
| 3328 |
this.onOutlineChange(); |
| 3329 |
}; |
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
OO.ui.OutlineControlsWidget.prototype.onOutlineChange = function () { |
| 3337 |
const items = this.outline.getItems(), |
| 3338 |
selectedItem = this.outline.findSelectedItem(), |
| 3339 |
movable = this.abilities.move && selectedItem && selectedItem.isMovable(), |
| 3340 |
removable = this.abilities.remove && selectedItem && selectedItem.isRemovable(); |
| 3341 |
|
| 3342 |
let firstMovable, lastMovable; |
| 3343 |
if ( movable ) { |
| 3344 |
let i = -1; |
| 3345 |
const len = items.length; |
| 3346 |
while ( ++i < len ) { |
| 3347 |
if ( items[ i ].isMovable() ) { |
| 3348 |
firstMovable = items[ i ]; |
| 3349 |
break; |
| 3350 |
} |
| 3351 |
} |
| 3352 |
i = len; |
| 3353 |
while ( i-- ) { |
| 3354 |
if ( items[ i ].isMovable() ) { |
| 3355 |
lastMovable = items[ i ]; |
| 3356 |
break; |
| 3357 |
} |
| 3358 |
} |
| 3359 |
} |
| 3360 |
this.upButton.setDisabled( !movable || selectedItem === firstMovable ); |
| 3361 |
this.downButton.setDisabled( !movable || selectedItem === lastMovable ); |
| 3362 |
this.removeButton.setDisabled( !removable ); |
| 3363 |
}; |
| 3364 |
|
| 3365 |
|
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
OO.ui.OutlineOptionWidget = function OoUiOutlineOptionWidget( config ) { |
| 3383 |
|
| 3384 |
config = config || {}; |
| 3385 |
|
| 3386 |
|
| 3387 |
OO.ui.OutlineOptionWidget.super.call( this, config ); |
| 3388 |
|
| 3389 |
|
| 3390 |
this.movable = !!config.movable; |
| 3391 |
this.removable = !!config.removable; |
| 3392 |
|
| 3393 |
|
| 3394 |
this.$element.addClass( 'oo-ui-outlineOptionWidget' ); |
| 3395 |
this.setLevel( config.level ); |
| 3396 |
}; |
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
OO.inheritClass( OO.ui.OutlineOptionWidget, OO.ui.DecoratedOptionWidget ); |
| 3401 |
|
| 3402 |
|
| 3403 |
|
| 3404 |
|
| 3405 |
|
| 3406 |
|
| 3407 |
|
| 3408 |
OO.ui.OutlineOptionWidget.static.highlightable = true; |
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
OO.ui.OutlineOptionWidget.static.scrollIntoViewOnSelect = true; |
| 3415 |
|
| 3416 |
|
| 3417 |
|
| 3418 |
|
| 3419 |
|
| 3420 |
OO.ui.OutlineOptionWidget.static.levelClass = 'oo-ui-outlineOptionWidget-level-'; |
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
OO.ui.OutlineOptionWidget.static.levels = 3; |
| 3427 |
|
| 3428 |
|
| 3429 |
|
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
OO.ui.OutlineOptionWidget.prototype.isMovable = function () { |
| 3438 |
return this.movable; |
| 3439 |
}; |
| 3440 |
|
| 3441 |
|
| 3442 |
|
| 3443 |
|
| 3444 |
|
| 3445 |
|
| 3446 |
|
| 3447 |
|
| 3448 |
OO.ui.OutlineOptionWidget.prototype.isRemovable = function () { |
| 3449 |
return this.removable; |
| 3450 |
}; |
| 3451 |
|
| 3452 |
|
| 3453 |
|
| 3454 |
|
| 3455 |
|
| 3456 |
|
| 3457 |
OO.ui.OutlineOptionWidget.prototype.getLevel = function () { |
| 3458 |
return this.level; |
| 3459 |
}; |
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
OO.ui.OutlineOptionWidget.prototype.setMovable = function ( movable ) { |
| 3471 |
this.movable = !!movable; |
| 3472 |
this.updateThemeClasses(); |
| 3473 |
return this; |
| 3474 |
}; |
| 3475 |
|
| 3476 |
|
| 3477 |
|
| 3478 |
|
| 3479 |
|
| 3480 |
|
| 3481 |
|
| 3482 |
|
| 3483 |
|
| 3484 |
|
| 3485 |
OO.ui.OutlineOptionWidget.prototype.setRemovable = function ( removable ) { |
| 3486 |
this.removable = !!removable; |
| 3487 |
this.updateThemeClasses(); |
| 3488 |
return this; |
| 3489 |
}; |
| 3490 |
|
| 3491 |
|
| 3492 |
|
| 3493 |
|
| 3494 |
|
| 3495 |
|
| 3496 |
|
| 3497 |
|
| 3498 |
OO.ui.OutlineOptionWidget.prototype.setLevel = function ( level ) { |
| 3499 |
level = level || 0; |
| 3500 |
if ( this.level === level ) { |
| 3501 |
return this; |
| 3502 |
} |
| 3503 |
|
| 3504 |
const levels = this.constructor.static.levels, |
| 3505 |
levelClass = this.constructor.static.levelClass; |
| 3506 |
|
| 3507 |
if ( this.level !== undefined ) { |
| 3508 |
this.$element.removeClass( levelClass + this.level ); |
| 3509 |
} |
| 3510 |
this.level = level > 0 ? Math.min( level, levels - 1 ) : 0; |
| 3511 |
this.$element.addClass( levelClass + this.level ); |
| 3512 |
this.updateThemeClasses(); |
| 3513 |
|
| 3514 |
return this; |
| 3515 |
}; |
| 3516 |
|
| 3517 |
|
| 3518 |
|
| 3519 |
|
| 3520 |
|
| 3521 |
|
| 3522 |
|
| 3523 |
|
| 3524 |
|
| 3525 |
|
| 3526 |
|
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
OO.ui.OutlineSelectWidget = function OoUiOutlineSelectWidget( config ) { |
| 3533 |
|
| 3534 |
OO.ui.OutlineSelectWidget.super.call( this, config ); |
| 3535 |
|
| 3536 |
|
| 3537 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 3538 |
|
| 3539 |
|
| 3540 |
this.$element.on( { |
| 3541 |
focus: this.bindDocumentKeyDownListener.bind( this ), |
| 3542 |
blur: this.unbindDocumentKeyDownListener.bind( this ) |
| 3543 |
} ); |
| 3544 |
|
| 3545 |
|
| 3546 |
this.$element.addClass( 'oo-ui-outlineSelectWidget' ); |
| 3547 |
}; |
| 3548 |
|
| 3549 |
|
| 3550 |
|
| 3551 |
OO.inheritClass( OO.ui.OutlineSelectWidget, OO.ui.SelectWidget ); |
| 3552 |
OO.mixinClass( OO.ui.OutlineSelectWidget, OO.ui.mixin.TabIndexedElement ); |
| 3553 |
|
| 3554 |
|
| 3555 |
|
| 3556 |
|
| 3557 |
|
| 3558 |
|
| 3559 |
|
| 3560 |
|
| 3561 |
|
| 3562 |
|
| 3563 |
|
| 3564 |
|
| 3565 |
|
| 3566 |
|
| 3567 |
|
| 3568 |
|
| 3569 |
|
| 3570 |
|
| 3571 |
OO.ui.ButtonOptionWidget = function OoUiButtonOptionWidget( config ) { |
| 3572 |
|
| 3573 |
config = config || {}; |
| 3574 |
|
| 3575 |
|
| 3576 |
OO.ui.ButtonOptionWidget.super.call( this, config ); |
| 3577 |
|
| 3578 |
|
| 3579 |
OO.ui.mixin.ButtonElement.call( this, config ); |
| 3580 |
OO.ui.mixin.IconElement.call( this, config ); |
| 3581 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 3582 |
|
| 3583 |
|
| 3584 |
this.$element.addClass( 'oo-ui-buttonOptionWidget' ); |
| 3585 |
this.$button.append( this.$icon, this.$label, this.$indicator ); |
| 3586 |
this.$element.append( this.$button ); |
| 3587 |
this.setTitledElement( this.$button ); |
| 3588 |
}; |
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
OO.inheritClass( OO.ui.ButtonOptionWidget, OO.ui.OptionWidget ); |
| 3593 |
OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.ButtonElement ); |
| 3594 |
OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.IconElement ); |
| 3595 |
OO.mixinClass( OO.ui.ButtonOptionWidget, OO.ui.mixin.IndicatorElement ); |
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
|
| 3603 |
|
| 3604 |
|
| 3605 |
OO.ui.ButtonOptionWidget.static.cancelButtonMouseDownEvents = false; |
| 3606 |
|
| 3607 |
|
| 3608 |
|
| 3609 |
|
| 3610 |
|
| 3611 |
OO.ui.ButtonOptionWidget.static.highlightable = false; |
| 3612 |
|
| 3613 |
|
| 3614 |
|
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
OO.ui.ButtonOptionWidget.prototype.setSelected = function ( state ) { |
| 3619 |
OO.ui.ButtonOptionWidget.super.prototype.setSelected.call( this, state ); |
| 3620 |
|
| 3621 |
if ( this.constructor.static.selectable ) { |
| 3622 |
this.setActive( state ); |
| 3623 |
} |
| 3624 |
|
| 3625 |
return this; |
| 3626 |
}; |
| 3627 |
|
| 3628 |
|
| 3629 |
|
| 3630 |
|
| 3631 |
|
| 3632 |
|
| 3633 |
|
| 3634 |
|
| 3635 |
|
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
|
| 3644 |
|
| 3645 |
|
| 3646 |
|
| 3647 |
|
| 3648 |
|
| 3649 |
|
| 3650 |
|
| 3651 |
|
| 3652 |
|
| 3653 |
|
| 3654 |
|
| 3655 |
|
| 3656 |
|
| 3657 |
|
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
|
| 3665 |
|
| 3666 |
OO.ui.ButtonSelectWidget = function OoUiButtonSelectWidget( config ) { |
| 3667 |
|
| 3668 |
OO.ui.ButtonSelectWidget.super.call( this, config ); |
| 3669 |
|
| 3670 |
|
| 3671 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 3672 |
|
| 3673 |
|
| 3674 |
this.$element.on( { |
| 3675 |
focus: this.bindDocumentKeyDownListener.bind( this ), |
| 3676 |
blur: this.unbindDocumentKeyDownListener.bind( this ) |
| 3677 |
} ); |
| 3678 |
|
| 3679 |
|
| 3680 |
this.$element.addClass( 'oo-ui-buttonSelectWidget' ); |
| 3681 |
}; |
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
OO.inheritClass( OO.ui.ButtonSelectWidget, OO.ui.SelectWidget ); |
| 3686 |
OO.mixinClass( OO.ui.ButtonSelectWidget, OO.ui.mixin.TabIndexedElement ); |
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
|
| 3695 |
|
| 3696 |
|
| 3697 |
|
| 3698 |
|
| 3699 |
|
| 3700 |
|
| 3701 |
|
| 3702 |
OO.ui.TabOptionWidget = function OoUiTabOptionWidget( config ) { |
| 3703 |
|
| 3704 |
config = config || {}; |
| 3705 |
|
| 3706 |
if ( config.href ) { |
| 3707 |
config = Object.assign( { |
| 3708 |
$label: $( '<a>' ).attr( 'href', config.href ) |
| 3709 |
}, config ); |
| 3710 |
} |
| 3711 |
|
| 3712 |
|
| 3713 |
OO.ui.TabOptionWidget.super.call( this, config ); |
| 3714 |
|
| 3715 |
|
| 3716 |
this.$element |
| 3717 |
.addClass( 'oo-ui-tabOptionWidget' ) |
| 3718 |
.attr( 'role', 'tab' ); |
| 3719 |
}; |
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
OO.inheritClass( OO.ui.TabOptionWidget, OO.ui.OptionWidget ); |
| 3724 |
|
| 3725 |
|
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
OO.ui.TabOptionWidget.static.highlightable = false; |
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
OO.ui.TabOptionWidget.static.scrollIntoViewOnSelect = true; |
| 3738 |
|
| 3739 |
|
| 3740 |
|
| 3741 |
|
| 3742 |
|
| 3743 |
|
| 3744 |
|
| 3745 |
OO.ui.TabOptionWidget.prototype.scrollElementIntoView = function ( config ) { |
| 3746 |
if ( !OO.ui.isMobile() || !this.getElementGroup() ) { |
| 3747 |
|
| 3748 |
return OO.ui.TabOptionWidget.super.prototype.scrollElementIntoView.call( this ); |
| 3749 |
} else { |
| 3750 |
const padding = Math.max( ( |
| 3751 |
this.getElementGroup().$element[ 0 ].clientWidth - this.$element[ 0 ].clientWidth |
| 3752 |
) / 2, 0 ); |
| 3753 |
|
| 3754 |
return OO.ui.TabOptionWidget.super.prototype.scrollElementIntoView.call( this, Object.assign( |
| 3755 |
{ |
| 3756 |
padding: { |
| 3757 |
left: padding, |
| 3758 |
right: padding |
| 3759 |
} |
| 3760 |
}, |
| 3761 |
config |
| 3762 |
) ); |
| 3763 |
} |
| 3764 |
}; |
| 3765 |
|
| 3766 |
|
| 3767 |
|
| 3768 |
|
| 3769 |
|
| 3770 |
|
| 3771 |
|
| 3772 |
|
| 3773 |
|
| 3774 |
|
| 3775 |
|
| 3776 |
|
| 3777 |
|
| 3778 |
|
| 3779 |
OO.ui.TabSelectWidget = function OoUiTabSelectWidget( config ) { |
| 3780 |
|
| 3781 |
OO.ui.TabSelectWidget.super.call( this, config ); |
| 3782 |
|
| 3783 |
|
| 3784 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 3785 |
|
| 3786 |
|
| 3787 |
this.$element.on( { |
| 3788 |
focus: this.bindDocumentKeyDownListener.bind( this ), |
| 3789 |
blur: this.unbindDocumentKeyDownListener.bind( this ) |
| 3790 |
} ); |
| 3791 |
|
| 3792 |
|
| 3793 |
this.$element |
| 3794 |
.addClass( 'oo-ui-tabSelectWidget' ) |
| 3795 |
.attr( 'role', 'tablist' ); |
| 3796 |
|
| 3797 |
this.toggleFramed( config.framed === undefined || config.framed ); |
| 3798 |
|
| 3799 |
if ( OO.ui.isMobile() ) { |
| 3800 |
this.$element.addClass( 'oo-ui-tabSelectWidget-mobile' ); |
| 3801 |
} |
| 3802 |
}; |
| 3803 |
|
| 3804 |
|
| 3805 |
|
| 3806 |
OO.inheritClass( OO.ui.TabSelectWidget, OO.ui.SelectWidget ); |
| 3807 |
OO.mixinClass( OO.ui.TabSelectWidget, OO.ui.mixin.TabIndexedElement ); |
| 3808 |
|
| 3809 |
|
| 3810 |
|
| 3811 |
|
| 3812 |
|
| 3813 |
|
| 3814 |
|
| 3815 |
|
| 3816 |
OO.ui.TabSelectWidget.prototype.isFramed = function () { |
| 3817 |
return this.framed; |
| 3818 |
}; |
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
OO.ui.TabSelectWidget.prototype.toggleFramed = function ( framed ) { |
| 3828 |
framed = framed === undefined ? !this.framed : !!framed; |
| 3829 |
if ( framed !== this.framed ) { |
| 3830 |
this.framed = framed; |
| 3831 |
this.$element |
| 3832 |
.toggleClass( 'oo-ui-tabSelectWidget-frameless', !framed ) |
| 3833 |
.toggleClass( 'oo-ui-tabSelectWidget-framed', framed ); |
| 3834 |
} |
| 3835 |
|
| 3836 |
return this; |
| 3837 |
}; |
| 3838 |
|
| 3839 |
|
| 3840 |
|
| 3841 |
|
| 3842 |
|
| 3843 |
|
| 3844 |
|
| 3845 |
|
| 3846 |
|
| 3847 |
|
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
|
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
|
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
|
| 3866 |
|
| 3867 |
|
| 3868 |
|
| 3869 |
|
| 3870 |
|
| 3871 |
|
| 3872 |
|
| 3873 |
|
| 3874 |
|
| 3875 |
|
| 3876 |
|
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
|
| 3883 |
|
| 3884 |
|
| 3885 |
|
| 3886 |
|
| 3887 |
|
| 3888 |
|
| 3889 |
|
| 3890 |
OO.ui.ButtonMenuSelectWidget = function OoUiButtonMenuSelectWidget( config ) { |
| 3891 |
|
| 3892 |
config = config || {}; |
| 3893 |
|
| 3894 |
OO.ui.ButtonMenuSelectWidget.super.call( this, config ); |
| 3895 |
|
| 3896 |
this.$overlay = ( config.$overlay === true ? |
| 3897 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 3898 |
|
| 3899 |
const MenuClass = config.menuClass || OO.ui.MenuSelectWidget; |
| 3900 |
|
| 3901 |
|
| 3902 |
this.clearOnSelect = config.clearOnSelect !== false; |
| 3903 |
this.menu = new MenuClass( Object.assign( { |
| 3904 |
widget: this, |
| 3905 |
$floatableContainer: this.$element, |
| 3906 |
spacing: 4 |
| 3907 |
}, config.menu ) ); |
| 3908 |
|
| 3909 |
|
| 3910 |
this.connect( this, { |
| 3911 |
click: 'onButtonMenuClick' |
| 3912 |
} ); |
| 3913 |
this.getMenu().connect( this, { |
| 3914 |
select: 'onMenuSelect', |
| 3915 |
toggle: 'onMenuToggle' |
| 3916 |
} ); |
| 3917 |
|
| 3918 |
|
| 3919 |
this.$button |
| 3920 |
.attr( { |
| 3921 |
'aria-expanded': 'false', |
| 3922 |
'aria-haspopup': 'true', |
| 3923 |
'aria-owns': this.menu.getElementId() |
| 3924 |
} ); |
| 3925 |
this.$element.addClass( 'oo-ui-buttonMenuSelectWidget' ); |
| 3926 |
this.$overlay.append( this.menu.$element ); |
| 3927 |
}; |
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
OO.inheritClass( OO.ui.ButtonMenuSelectWidget, OO.ui.ButtonWidget ); |
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
OO.ui.ButtonMenuSelectWidget.prototype.getMenu = function () { |
| 3941 |
return this.menu; |
| 3942 |
}; |
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
OO.ui.ButtonMenuSelectWidget.prototype.onMenuSelect = function ( item ) { |
| 3951 |
if ( this.clearOnSelect && item ) { |
| 3952 |
|
| 3953 |
|
| 3954 |
this.getMenu().selectItem(); |
| 3955 |
} |
| 3956 |
}; |
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
|
| 3963 |
|
| 3964 |
OO.ui.ButtonMenuSelectWidget.prototype.onMenuToggle = function ( isVisible ) { |
| 3965 |
this.$element.toggleClass( 'oo-ui-buttonElement-pressed', isVisible ); |
| 3966 |
}; |
| 3967 |
|
| 3968 |
|
| 3969 |
|
| 3970 |
|
| 3971 |
|
| 3972 |
|
| 3973 |
OO.ui.ButtonMenuSelectWidget.prototype.onButtonMenuClick = function () { |
| 3974 |
this.menu.toggle(); |
| 3975 |
}; |
| 3976 |
|
| 3977 |
|
| 3978 |
|
| 3979 |
|
| 3980 |
|
| 3981 |
|
| 3982 |
|
| 3983 |
|
| 3984 |
|
| 3985 |
|
| 3986 |
|
| 3987 |
|
| 3988 |
|
| 3989 |
|
| 3990 |
|
| 3991 |
|
| 3992 |
|
| 3993 |
|
| 3994 |
|
| 3995 |
OO.ui.TagItemWidget = function OoUiTagItemWidget( config ) { |
| 3996 |
config = config || {}; |
| 3997 |
|
| 3998 |
|
| 3999 |
OO.ui.TagItemWidget.super.call( this, config ); |
| 4000 |
|
| 4001 |
|
| 4002 |
OO.ui.mixin.ItemWidget.call( this ); |
| 4003 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 4004 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 4005 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 4006 |
OO.ui.mixin.DraggableElement.call( this, config ); |
| 4007 |
|
| 4008 |
this.valid = config.valid === undefined ? true : !!config.valid; |
| 4009 |
this.fixed = !!config.fixed; |
| 4010 |
|
| 4011 |
this.closeButton = new OO.ui.ButtonWidget( { |
| 4012 |
framed: false, |
| 4013 |
icon: 'close', |
| 4014 |
tabIndex: -1, |
| 4015 |
title: OO.ui.msg( 'ooui-item-remove' ) |
| 4016 |
} ); |
| 4017 |
this.closeButton.setDisabled( this.isDisabled() ); |
| 4018 |
|
| 4019 |
|
| 4020 |
this.closeButton.connect( this, { |
| 4021 |
click: 'remove' |
| 4022 |
} ); |
| 4023 |
this.$element |
| 4024 |
.on( 'click', this.select.bind( this ) ) |
| 4025 |
.on( 'keydown', this.onKeyDown.bind( this ) ) |
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
|
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
.on( 'mousedown', ( e ) => { |
| 4034 |
e.stopPropagation(); |
| 4035 |
} ); |
| 4036 |
|
| 4037 |
|
| 4038 |
this.$element |
| 4039 |
.addClass( 'oo-ui-tagItemWidget' ) |
| 4040 |
.append( this.$label, this.closeButton.$element ); |
| 4041 |
}; |
| 4042 |
|
| 4043 |
|
| 4044 |
|
| 4045 |
OO.inheritClass( OO.ui.TagItemWidget, OO.ui.Widget ); |
| 4046 |
OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.ItemWidget ); |
| 4047 |
OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.LabelElement ); |
| 4048 |
OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.FlaggedElement ); |
| 4049 |
OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.TabIndexedElement ); |
| 4050 |
OO.mixinClass( OO.ui.TagItemWidget, OO.ui.mixin.DraggableElement ); |
| 4051 |
|
| 4052 |
|
| 4053 |
|
| 4054 |
|
| 4055 |
|
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
|
| 4063 |
|
| 4064 |
|
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
|
| 4072 |
|
| 4073 |
|
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
|
| 4083 |
|
| 4084 |
|
| 4085 |
|
| 4086 |
|
| 4087 |
|
| 4088 |
|
| 4089 |
|
| 4090 |
|
| 4091 |
|
| 4092 |
|
| 4093 |
|
| 4094 |
|
| 4095 |
|
| 4096 |
|
| 4097 |
OO.ui.TagItemWidget.prototype.setFixed = function ( state ) { |
| 4098 |
state = state === undefined ? !this.fixed : !!state; |
| 4099 |
|
| 4100 |
if ( this.fixed !== state ) { |
| 4101 |
this.fixed = state; |
| 4102 |
if ( this.closeButton ) { |
| 4103 |
this.closeButton.toggle( !this.fixed ); |
| 4104 |
} |
| 4105 |
|
| 4106 |
if ( !this.fixed && this.elementGroup && !this.elementGroup.isDraggable() ) { |
| 4107 |
|
| 4108 |
|
| 4109 |
this.toggleDraggable( !this.fixed ); |
| 4110 |
} |
| 4111 |
this.$element.toggleClass( 'oo-ui-tagItemWidget-fixed', this.fixed ); |
| 4112 |
|
| 4113 |
this.emit( 'fixed', this.isFixed() ); |
| 4114 |
} |
| 4115 |
return this; |
| 4116 |
}; |
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
|
| 4121 |
|
| 4122 |
|
| 4123 |
OO.ui.TagItemWidget.prototype.isFixed = function () { |
| 4124 |
return this.fixed; |
| 4125 |
}; |
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
|
| 4131 |
|
| 4132 |
|
| 4133 |
|
| 4134 |
|
| 4135 |
|
| 4136 |
|
| 4137 |
OO.ui.TagItemWidget.prototype.remove = function () { |
| 4138 |
if ( !this.isDisabled() && !this.isFixed() ) { |
| 4139 |
this.emit( 'remove' ); |
| 4140 |
} |
| 4141 |
}; |
| 4142 |
|
| 4143 |
|
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
OO.ui.TagItemWidget.prototype.onKeyDown = function ( e ) { |
| 4152 |
if ( |
| 4153 |
!this.isDisabled() && |
| 4154 |
!this.isFixed() && |
| 4155 |
( e.keyCode === OO.ui.Keys.BACKSPACE || e.keyCode === OO.ui.Keys.DELETE ) |
| 4156 |
) { |
| 4157 |
this.remove(); |
| 4158 |
return false; |
| 4159 |
} else if ( e.keyCode === OO.ui.Keys.ENTER ) { |
| 4160 |
this.select(); |
| 4161 |
return false; |
| 4162 |
} else if ( |
| 4163 |
e.keyCode === OO.ui.Keys.LEFT || |
| 4164 |
e.keyCode === OO.ui.Keys.RIGHT |
| 4165 |
) { |
| 4166 |
let movement; |
| 4167 |
|
| 4168 |
if ( OO.ui.Element.static.getDir( this.$element ) === 'rtl' ) { |
| 4169 |
movement = { |
| 4170 |
left: 'forwards', |
| 4171 |
right: 'backwards' |
| 4172 |
}; |
| 4173 |
} else { |
| 4174 |
movement = { |
| 4175 |
left: 'backwards', |
| 4176 |
right: 'forwards' |
| 4177 |
}; |
| 4178 |
} |
| 4179 |
|
| 4180 |
this.emit( |
| 4181 |
'navigate', |
| 4182 |
e.keyCode === OO.ui.Keys.LEFT ? |
| 4183 |
movement.left : movement.right |
| 4184 |
); |
| 4185 |
return false; |
| 4186 |
} |
| 4187 |
}; |
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
OO.ui.TagItemWidget.prototype.select = function () { |
| 4195 |
if ( !this.isDisabled() ) { |
| 4196 |
this.emit( 'select' ); |
| 4197 |
} |
| 4198 |
}; |
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
|
| 4204 |
|
| 4205 |
|
| 4206 |
OO.ui.TagItemWidget.prototype.toggleValid = function ( valid ) { |
| 4207 |
valid = valid === undefined ? !this.valid : !!valid; |
| 4208 |
|
| 4209 |
if ( this.valid !== valid ) { |
| 4210 |
this.valid = valid; |
| 4211 |
|
| 4212 |
this.setFlags( { invalid: !this.valid } ); |
| 4213 |
|
| 4214 |
this.emit( 'valid', this.valid ); |
| 4215 |
} |
| 4216 |
}; |
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
OO.ui.TagItemWidget.prototype.isValid = function () { |
| 4224 |
return this.valid; |
| 4225 |
}; |
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
|
| 4232 |
|
| 4233 |
|
| 4234 |
|
| 4235 |
|
| 4236 |
|
| 4237 |
|
| 4238 |
|
| 4239 |
|
| 4240 |
|
| 4241 |
|
| 4242 |
|
| 4243 |
|
| 4244 |
|
| 4245 |
|
| 4246 |
|
| 4247 |
|
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
|
| 4252 |
|
| 4253 |
|
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
|
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
|
| 4272 |
|
| 4273 |
|
| 4274 |
|
| 4275 |
|
| 4276 |
|
| 4277 |
|
| 4278 |
|
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
|
| 4284 |
|
| 4285 |
|
| 4286 |
OO.ui.TagMultiselectWidget = function OoUiTagMultiselectWidget( config ) { |
| 4287 |
const rAF = window.requestAnimationFrame || setTimeout, |
| 4288 |
$tabFocus = $( '<span>' ).addClass( 'oo-ui-tagMultiselectWidget-focusTrap' ); |
| 4289 |
|
| 4290 |
config = config || {}; |
| 4291 |
|
| 4292 |
|
| 4293 |
OO.ui.TagMultiselectWidget.super.call( this, config ); |
| 4294 |
|
| 4295 |
|
| 4296 |
OO.ui.mixin.GroupWidget.call( this, config ); |
| 4297 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 4298 |
OO.ui.mixin.IconElement.call( this, config ); |
| 4299 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 4300 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 4301 |
OO.ui.mixin.DraggableGroupElement.call( this, config ); |
| 4302 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 4303 |
|
| 4304 |
this.toggleDraggable( |
| 4305 |
config.allowReordering === undefined ? |
| 4306 |
true : !!config.allowReordering |
| 4307 |
); |
| 4308 |
|
| 4309 |
this.inputPosition = |
| 4310 |
this.constructor.static.allowedInputPositions.indexOf( config.inputPosition ) > -1 ? |
| 4311 |
config.inputPosition : 'inline'; |
| 4312 |
this.allowEditTags = config.allowEditTags === undefined ? true : !!config.allowEditTags; |
| 4313 |
this.allowArbitrary = !!config.allowArbitrary; |
| 4314 |
this.allowDuplicates = !!config.allowDuplicates; |
| 4315 |
this.allowedValues = config.allowedValues || []; |
| 4316 |
this.allowDisplayInvalidTags = config.allowDisplayInvalidTags; |
| 4317 |
this.hasInput = this.inputPosition !== 'none'; |
| 4318 |
this.tagLimit = config.tagLimit; |
| 4319 |
this.height = null; |
| 4320 |
this.valid = true; |
| 4321 |
|
| 4322 |
this.$content = $( '<div>' ).addClass( 'oo-ui-tagMultiselectWidget-content' ); |
| 4323 |
this.$handle = $( '<div>' ) |
| 4324 |
.addClass( 'oo-ui-tagMultiselectWidget-handle' ) |
| 4325 |
.append( |
| 4326 |
this.$indicator, |
| 4327 |
this.$icon, |
| 4328 |
this.$content |
| 4329 |
.append( |
| 4330 |
this.$group.addClass( 'oo-ui-tagMultiselectWidget-group' ) |
| 4331 |
) |
| 4332 |
); |
| 4333 |
|
| 4334 |
|
| 4335 |
this.aggregate( { |
| 4336 |
remove: 'itemRemove', |
| 4337 |
navigate: 'itemNavigate', |
| 4338 |
select: 'itemSelect', |
| 4339 |
fixed: 'itemFixed' |
| 4340 |
} ); |
| 4341 |
this.connect( this, { |
| 4342 |
itemRemove: 'onTagRemove', |
| 4343 |
itemSelect: 'onTagSelect', |
| 4344 |
itemFixed: 'onTagFixed', |
| 4345 |
itemNavigate: 'onTagNavigate', |
| 4346 |
change: 'onChangeTags' |
| 4347 |
} ); |
| 4348 |
this.$handle.on( { |
| 4349 |
mousedown: this.onMouseDown.bind( this ) |
| 4350 |
} ); |
| 4351 |
|
| 4352 |
|
| 4353 |
this.$element |
| 4354 |
.addClass( 'oo-ui-tagMultiselectWidget' ) |
| 4355 |
.append( this.$handle ); |
| 4356 |
|
| 4357 |
if ( this.hasInput ) { |
| 4358 |
if ( config.inputWidget ) { |
| 4359 |
this.input = config.inputWidget; |
| 4360 |
} else { |
| 4361 |
this.input = new OO.ui.TextInputWidget( Object.assign( { |
| 4362 |
placeholder: config.placeholder, |
| 4363 |
classes: [ 'oo-ui-tagMultiselectWidget-input' ] |
| 4364 |
}, config.input ) ); |
| 4365 |
} |
| 4366 |
this.input.setDisabled( this.isDisabled() ); |
| 4367 |
|
| 4368 |
const inputEvents = { |
| 4369 |
focus: this.onInputFocus.bind( this ), |
| 4370 |
blur: this.onInputBlur.bind( this ), |
| 4371 |
'propertychange change click mouseup keydown keyup input cut paste select focus': |
| 4372 |
OO.ui.debounce( this.updateInputSize.bind( this ) ), |
| 4373 |
keydown: this.onInputKeyDown.bind( this ), |
| 4374 |
keypress: this.onInputKeyPress.bind( this ) |
| 4375 |
}; |
| 4376 |
|
| 4377 |
this.input.$input.on( inputEvents ); |
| 4378 |
this.inputPlaceholder = this.input.$input.attr( 'placeholder' ); |
| 4379 |
|
| 4380 |
if ( this.inputPosition === 'outline' ) { |
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
this.input.$element.css( 'max-width', 'inherit' ); |
| 4385 |
this.$element |
| 4386 |
.addClass( 'oo-ui-tagMultiselectWidget-outlined' ) |
| 4387 |
.append( this.input.$element ); |
| 4388 |
} else { |
| 4389 |
this.$element.addClass( 'oo-ui-tagMultiselectWidget-inlined' ); |
| 4390 |
|
| 4391 |
|
| 4392 |
|
| 4393 |
|
| 4394 |
|
| 4395 |
|
| 4396 |
|
| 4397 |
|
| 4398 |
|
| 4399 |
this.$group.append( this.input.$input ); |
| 4400 |
} |
| 4401 |
} else { |
| 4402 |
this.$content.append( $tabFocus ); |
| 4403 |
} |
| 4404 |
|
| 4405 |
this.setTabIndexedElement( |
| 4406 |
this.hasInput ? |
| 4407 |
this.input.$input : |
| 4408 |
$tabFocus |
| 4409 |
); |
| 4410 |
|
| 4411 |
if ( config.selected ) { |
| 4412 |
this.setValue( config.selected ); |
| 4413 |
} |
| 4414 |
|
| 4415 |
|
| 4416 |
|
| 4417 |
rAF( () => { |
| 4418 |
if ( this.hasInput ) { |
| 4419 |
this.updateInputSize(); |
| 4420 |
} |
| 4421 |
} ); |
| 4422 |
}; |
| 4423 |
|
| 4424 |
|
| 4425 |
|
| 4426 |
OO.inheritClass( OO.ui.TagMultiselectWidget, OO.ui.Widget ); |
| 4427 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.GroupWidget ); |
| 4428 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.DraggableGroupElement ); |
| 4429 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.IndicatorElement ); |
| 4430 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.IconElement ); |
| 4431 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.TabIndexedElement ); |
| 4432 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.FlaggedElement ); |
| 4433 |
OO.mixinClass( OO.ui.TagMultiselectWidget, OO.ui.mixin.TitledElement ); |
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
OO.ui.TagMultiselectWidget.static.allowedInputPositions = [ 'inline', 'outline', 'none' ]; |
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
OO.ui.TagMultiselectWidget.prototype.onMouseDown = function ( e ) { |
| 4464 |
if ( |
| 4465 |
!this.isDisabled() && |
| 4466 |
( !this.hasInput || e.target !== this.input.$input[ 0 ] ) && |
| 4467 |
e.which === OO.ui.MouseButtons.LEFT |
| 4468 |
) { |
| 4469 |
this.focus(); |
| 4470 |
return false; |
| 4471 |
} |
| 4472 |
}; |
| 4473 |
|
| 4474 |
|
| 4475 |
|
| 4476 |
|
| 4477 |
|
| 4478 |
|
| 4479 |
|
| 4480 |
|
| 4481 |
OO.ui.TagMultiselectWidget.prototype.onInputKeyPress = function ( e ) { |
| 4482 |
const withMetaKey = e.metaKey || e.ctrlKey; |
| 4483 |
|
| 4484 |
if ( !this.isDisabled() ) { |
| 4485 |
let stopOrContinue; |
| 4486 |
if ( e.which === OO.ui.Keys.ENTER ) { |
| 4487 |
stopOrContinue = this.doInputEnter( e, withMetaKey ); |
| 4488 |
} |
| 4489 |
|
| 4490 |
this.updateInputSize(); |
| 4491 |
return stopOrContinue; |
| 4492 |
} |
| 4493 |
}; |
| 4494 |
|
| 4495 |
|
| 4496 |
|
| 4497 |
|
| 4498 |
|
| 4499 |
|
| 4500 |
|
| 4501 |
|
| 4502 |
OO.ui.TagMultiselectWidget.prototype.onInputKeyDown = function ( e ) { |
| 4503 |
const withMetaKey = e.metaKey || e.ctrlKey; |
| 4504 |
|
| 4505 |
const isMovementInsideInput = ( dir ) => { |
| 4506 |
const inputRange = this.input.getRange(), |
| 4507 |
inputValue = this.hasInput && this.input.getValue(); |
| 4508 |
|
| 4509 |
if ( dir === 'forwards' && inputRange.to > inputValue.length - 1 ) { |
| 4510 |
return false; |
| 4511 |
} |
| 4512 |
|
| 4513 |
if ( dir === 'backwards' && inputRange.from <= 0 ) { |
| 4514 |
return false; |
| 4515 |
} |
| 4516 |
|
| 4517 |
return true; |
| 4518 |
}; |
| 4519 |
|
| 4520 |
if ( !this.isDisabled() ) { |
| 4521 |
|
| 4522 |
if ( e.keyCode === OO.ui.Keys.BACKSPACE ) { |
| 4523 |
return this.doInputBackspace( e, withMetaKey ); |
| 4524 |
} else if ( e.keyCode === OO.ui.Keys.ESCAPE ) { |
| 4525 |
return this.doInputEscape( e ); |
| 4526 |
} else if ( |
| 4527 |
e.keyCode === OO.ui.Keys.LEFT || |
| 4528 |
e.keyCode === OO.ui.Keys.RIGHT |
| 4529 |
) { |
| 4530 |
let movement; |
| 4531 |
if ( OO.ui.Element.static.getDir( this.$element ) === 'rtl' ) { |
| 4532 |
movement = { |
| 4533 |
left: 'forwards', |
| 4534 |
right: 'backwards' |
| 4535 |
}; |
| 4536 |
} else { |
| 4537 |
movement = { |
| 4538 |
left: 'backwards', |
| 4539 |
right: 'forwards' |
| 4540 |
}; |
| 4541 |
} |
| 4542 |
const direction = e.keyCode === OO.ui.Keys.LEFT ? |
| 4543 |
movement.left : movement.right; |
| 4544 |
|
| 4545 |
if ( !this.hasInput || !isMovementInsideInput( direction ) ) { |
| 4546 |
return this.doInputArrow( e, direction, withMetaKey ); |
| 4547 |
} |
| 4548 |
} |
| 4549 |
} |
| 4550 |
}; |
| 4551 |
|
| 4552 |
|
| 4553 |
|
| 4554 |
|
| 4555 |
OO.ui.TagMultiselectWidget.prototype.onInputFocus = function () { |
| 4556 |
this.$element.addClass( 'oo-ui-tagMultiselectWidget-focus' ); |
| 4557 |
|
| 4558 |
this.toggleValid( true ); |
| 4559 |
}; |
| 4560 |
|
| 4561 |
|
| 4562 |
|
| 4563 |
|
| 4564 |
OO.ui.TagMultiselectWidget.prototype.onInputBlur = function () { |
| 4565 |
|
| 4566 |
if ( this.changing ) { |
| 4567 |
return; |
| 4568 |
} |
| 4569 |
|
| 4570 |
this.$element.removeClass( 'oo-ui-tagMultiselectWidget-focus' ); |
| 4571 |
|
| 4572 |
|
| 4573 |
this.addTagFromInput(); |
| 4574 |
this.toggleValid( this.checkValidity() && ( !this.hasInput || !this.input.getValue() ) ); |
| 4575 |
}; |
| 4576 |
|
| 4577 |
|
| 4578 |
|
| 4579 |
|
| 4580 |
|
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
|
| 4585 |
OO.ui.TagMultiselectWidget.prototype.doInputEnter = function () { |
| 4586 |
this.addTagFromInput(); |
| 4587 |
return false; |
| 4588 |
}; |
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
OO.ui.TagMultiselectWidget.prototype.doInputBackspace = function ( e, withMetaKey ) { |
| 4599 |
if ( |
| 4600 |
this.inputPosition === 'inline' && |
| 4601 |
this.input.getValue() === '' && |
| 4602 |
!this.isEmpty() |
| 4603 |
) { |
| 4604 |
|
| 4605 |
const items = this.getItems(); |
| 4606 |
const item = items[ items.length - 1 ]; |
| 4607 |
|
| 4608 |
if ( !item.isDisabled() && !item.isFixed() ) { |
| 4609 |
this.removeItems( [ item ] ); |
| 4610 |
|
| 4611 |
|
| 4612 |
if ( !withMetaKey ) { |
| 4613 |
let itemLabel; |
| 4614 |
if ( typeof item.getLabel() === 'string' ) { |
| 4615 |
itemLabel = item.getLabel(); |
| 4616 |
} else if ( item.getLabel() instanceof $ ) { |
| 4617 |
itemLabel = item.getLabel().text(); |
| 4618 |
} |
| 4619 |
this.input.setValue( itemLabel ); |
| 4620 |
} |
| 4621 |
} |
| 4622 |
|
| 4623 |
return false; |
| 4624 |
} |
| 4625 |
}; |
| 4626 |
|
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
OO.ui.TagMultiselectWidget.prototype.doInputEscape = function () { |
| 4633 |
this.clearInput(); |
| 4634 |
}; |
| 4635 |
|
| 4636 |
|
| 4637 |
|
| 4638 |
|
| 4639 |
|
| 4640 |
|
| 4641 |
|
| 4642 |
|
| 4643 |
|
| 4644 |
|
| 4645 |
|
| 4646 |
OO.ui.TagMultiselectWidget.prototype.doInputArrow = function ( e, direction ) { |
| 4647 |
if ( |
| 4648 |
this.inputPosition === 'inline' && |
| 4649 |
!this.isEmpty() && |
| 4650 |
direction === 'backwards' |
| 4651 |
) { |
| 4652 |
|
| 4653 |
this.getPreviousItem().focus(); |
| 4654 |
} |
| 4655 |
}; |
| 4656 |
|
| 4657 |
|
| 4658 |
|
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
OO.ui.TagMultiselectWidget.prototype.onTagSelect = function ( item ) { |
| 4663 |
if ( this.hasInput && this.allowEditTags && !item.isFixed() ) { |
| 4664 |
if ( this.input.getValue() ) { |
| 4665 |
this.addTagFromInput(); |
| 4666 |
} |
| 4667 |
|
| 4668 |
this.input.setValue( item.getLabel() ); |
| 4669 |
|
| 4670 |
this.removeItems( [ item ] ); |
| 4671 |
|
| 4672 |
this.focus(); |
| 4673 |
} |
| 4674 |
}; |
| 4675 |
|
| 4676 |
|
| 4677 |
|
| 4678 |
|
| 4679 |
|
| 4680 |
|
| 4681 |
OO.ui.TagMultiselectWidget.prototype.onTagFixed = function ( item ) { |
| 4682 |
const items = this.getItems(); |
| 4683 |
|
| 4684 |
|
| 4685 |
let i; |
| 4686 |
for ( i = 0; i < items.length; i++ ) { |
| 4687 |
if ( items[ i ] !== item && !items[ i ].isFixed() ) { |
| 4688 |
break; |
| 4689 |
} |
| 4690 |
} |
| 4691 |
this.addItems( [ item ], i ); |
| 4692 |
}; |
| 4693 |
|
| 4694 |
|
| 4695 |
|
| 4696 |
OO.ui.TagMultiselectWidget.prototype.onChangeTags = function () { |
| 4697 |
const isUnderLimit = this.isUnderLimit(); |
| 4698 |
|
| 4699 |
this.changing = true; |
| 4700 |
|
| 4701 |
|
| 4702 |
this.toggleValid( this.checkValidity() ); |
| 4703 |
|
| 4704 |
if ( this.hasInput ) { |
| 4705 |
this.updateInputSize(); |
| 4706 |
if ( !isUnderLimit ) { |
| 4707 |
|
| 4708 |
this.input.setValue( '' ); |
| 4709 |
} |
| 4710 |
if ( this.inputPosition === 'outline' ) { |
| 4711 |
|
| 4712 |
|
| 4713 |
this.input.$input.attr( 'placeholder', isUnderLimit ? this.inputPlaceholder : '' ); |
| 4714 |
this.input.setDisabled( !isUnderLimit ); |
| 4715 |
} else { |
| 4716 |
const hadFocus = document.activeElement === this.input.$input[ 0 ]; |
| 4717 |
|
| 4718 |
this.$group.append( this.input.$input ); |
| 4719 |
|
| 4720 |
this.input.$input.toggleClass( 'oo-ui-element-hidden', !isUnderLimit ); |
| 4721 |
if ( hadFocus && isUnderLimit ) { |
| 4722 |
this.input.focus(); |
| 4723 |
} |
| 4724 |
} |
| 4725 |
} |
| 4726 |
this.updateIfHeightChanged(); |
| 4727 |
|
| 4728 |
this.changing = false; |
| 4729 |
}; |
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
OO.ui.TagMultiselectWidget.prototype.setDisabled = function ( isDisabled ) { |
| 4735 |
|
| 4736 |
OO.ui.TagMultiselectWidget.super.prototype.setDisabled.call( this, isDisabled ); |
| 4737 |
|
| 4738 |
if ( this.hasInput && this.input ) { |
| 4739 |
if ( !isDisabled ) { |
| 4740 |
this.updateInputSize(); |
| 4741 |
} |
| 4742 |
this.input.setDisabled( !!isDisabled || !this.isUnderLimit() ); |
| 4743 |
} |
| 4744 |
|
| 4745 |
if ( this.items ) { |
| 4746 |
this.getItems().forEach( ( item ) => { |
| 4747 |
item.setDisabled( !!isDisabled ); |
| 4748 |
} ); |
| 4749 |
} |
| 4750 |
}; |
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
|
| 4757 |
OO.ui.TagMultiselectWidget.prototype.onTagRemove = function ( item ) { |
| 4758 |
this.removeTagByData( item.getData() ); |
| 4759 |
}; |
| 4760 |
|
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
OO.ui.TagMultiselectWidget.prototype.onTagNavigate = function ( item, direction ) { |
| 4768 |
const firstItem = this.getItems()[ 0 ]; |
| 4769 |
|
| 4770 |
if ( direction === 'forwards' ) { |
| 4771 |
this.getNextItem( item ).focus(); |
| 4772 |
} else if ( !this.inputPosition === 'inline' || item !== firstItem ) { |
| 4773 |
|
| 4774 |
|
| 4775 |
this.getPreviousItem( item ).focus(); |
| 4776 |
} |
| 4777 |
}; |
| 4778 |
|
| 4779 |
|
| 4780 |
|
| 4781 |
|
| 4782 |
|
| 4783 |
|
| 4784 |
OO.ui.TagMultiselectWidget.prototype.getTagInfoFromInput = function () { |
| 4785 |
const val = this.input.getValue(); |
| 4786 |
return { data: val, label: val }; |
| 4787 |
}; |
| 4788 |
|
| 4789 |
|
| 4790 |
|
| 4791 |
|
| 4792 |
OO.ui.TagMultiselectWidget.prototype.addTagFromInput = function () { |
| 4793 |
const tagInfo = this.getTagInfoFromInput(); |
| 4794 |
|
| 4795 |
if ( !tagInfo.data ) { |
| 4796 |
return; |
| 4797 |
} |
| 4798 |
|
| 4799 |
if ( this.addTag( tagInfo.data, tagInfo.label ) ) { |
| 4800 |
this.clearInput(); |
| 4801 |
} |
| 4802 |
}; |
| 4803 |
|
| 4804 |
|
| 4805 |
|
| 4806 |
|
| 4807 |
OO.ui.TagMultiselectWidget.prototype.clearInput = function () { |
| 4808 |
this.input.setValue( '' ); |
| 4809 |
}; |
| 4810 |
|
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
|
| 4815 |
|
| 4816 |
|
| 4817 |
|
| 4818 |
OO.ui.TagMultiselectWidget.prototype.isDuplicateData = function ( data ) { |
| 4819 |
return !!this.findItemFromData( data ); |
| 4820 |
}; |
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
|
| 4827 |
|
| 4828 |
OO.ui.TagMultiselectWidget.prototype.isAllowedData = function ( data ) { |
| 4829 |
if ( |
| 4830 |
!this.allowDuplicates && |
| 4831 |
this.isDuplicateData( data ) |
| 4832 |
) { |
| 4833 |
return false; |
| 4834 |
} |
| 4835 |
|
| 4836 |
if ( this.allowArbitrary ) { |
| 4837 |
return true; |
| 4838 |
} |
| 4839 |
|
| 4840 |
|
| 4841 |
if ( |
| 4842 |
this.getAllowedValues().some( ( value ) => data === value ) |
| 4843 |
) { |
| 4844 |
return true; |
| 4845 |
} |
| 4846 |
|
| 4847 |
return false; |
| 4848 |
}; |
| 4849 |
|
| 4850 |
|
| 4851 |
|
| 4852 |
|
| 4853 |
|
| 4854 |
|
| 4855 |
OO.ui.TagMultiselectWidget.prototype.getAllowedValues = function () { |
| 4856 |
return this.allowedValues; |
| 4857 |
}; |
| 4858 |
|
| 4859 |
|
| 4860 |
|
| 4861 |
|
| 4862 |
|
| 4863 |
|
| 4864 |
OO.ui.TagMultiselectWidget.prototype.addAllowedValue = function ( value ) { |
| 4865 |
if ( this.allowedValues.indexOf( value ) === -1 ) { |
| 4866 |
this.allowedValues.push( value ); |
| 4867 |
} |
| 4868 |
}; |
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
OO.ui.TagMultiselectWidget.prototype.getValue = function () { |
| 4876 |
return this.getItems() |
| 4877 |
.filter( ( item ) => item.isValid() ) |
| 4878 |
.map( ( item ) => item.getData() ); |
| 4879 |
}; |
| 4880 |
|
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
|
| 4892 |
|
| 4893 |
|
| 4894 |
|
| 4895 |
|
| 4896 |
|
| 4897 |
|
| 4898 |
OO.ui.TagMultiselectWidget.prototype.setValue = function ( valueObject ) { |
| 4899 |
valueObject = Array.isArray( valueObject ) ? valueObject : [ valueObject ]; |
| 4900 |
|
| 4901 |
this.clearItems(); |
| 4902 |
valueObject.forEach( ( obj ) => { |
| 4903 |
if ( typeof obj === 'object' ) { |
| 4904 |
this.addTag( obj.data, obj.label ); |
| 4905 |
} else { |
| 4906 |
this.addTag( String( obj ) ); |
| 4907 |
} |
| 4908 |
} ); |
| 4909 |
}; |
| 4910 |
|
| 4911 |
|
| 4912 |
|
| 4913 |
|
| 4914 |
|
| 4915 |
|
| 4916 |
|
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
OO.ui.TagMultiselectWidget.prototype.addTag = function ( data, label ) { |
| 4922 |
const isValid = this.isAllowedData( data ); |
| 4923 |
|
| 4924 |
if ( this.isUnderLimit() && ( isValid || this.allowDisplayInvalidTags ) ) { |
| 4925 |
const newItemWidget = this.createTagItemWidget( data, label ); |
| 4926 |
newItemWidget.toggleValid( isValid ); |
| 4927 |
this.addItems( [ newItemWidget ] ); |
| 4928 |
return true; |
| 4929 |
} |
| 4930 |
|
| 4931 |
return false; |
| 4932 |
}; |
| 4933 |
|
| 4934 |
|
| 4935 |
|
| 4936 |
|
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
OO.ui.TagMultiselectWidget.prototype.isUnderLimit = function () { |
| 4941 |
return !this.tagLimit || |
| 4942 |
this.getItemCount() < this.tagLimit; |
| 4943 |
}; |
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
|
| 4950 |
OO.ui.TagMultiselectWidget.prototype.removeTagByData = function ( data ) { |
| 4951 |
const item = this.findItemFromData( data ); |
| 4952 |
|
| 4953 |
this.removeItems( [ item ] ); |
| 4954 |
}; |
| 4955 |
|
| 4956 |
|
| 4957 |
|
| 4958 |
|
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
OO.ui.TagMultiselectWidget.prototype.createTagItemWidget = function ( data, label ) { |
| 4965 |
return new OO.ui.TagItemWidget( { data: data, label: label || data } ); |
| 4966 |
}; |
| 4967 |
|
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
|
| 4975 |
|
| 4976 |
|
| 4977 |
OO.ui.TagMultiselectWidget.prototype.getNextItem = function ( item ) { |
| 4978 |
const itemIndex = this.items.indexOf( item ); |
| 4979 |
|
| 4980 |
if ( item === undefined || itemIndex === -1 ) { |
| 4981 |
return this.items[ 0 ]; |
| 4982 |
} |
| 4983 |
|
| 4984 |
if ( itemIndex === this.items.length - 1 ) { |
| 4985 |
if ( this.hasInput ) { |
| 4986 |
return this.input; |
| 4987 |
} else { |
| 4988 |
|
| 4989 |
return this.items[ 0 ]; |
| 4990 |
} |
| 4991 |
} else { |
| 4992 |
return this.items[ itemIndex + 1 ]; |
| 4993 |
} |
| 4994 |
}; |
| 4995 |
|
| 4996 |
|
| 4997 |
|
| 4998 |
|
| 4999 |
|
| 5000 |
|
| 5001 |
|
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
OO.ui.TagMultiselectWidget.prototype.getPreviousItem = function ( item ) { |
| 5006 |
const itemIndex = this.items.indexOf( item ); |
| 5007 |
|
| 5008 |
if ( item === undefined || itemIndex === -1 ) { |
| 5009 |
return this.items[ this.items.length - 1 ]; |
| 5010 |
} |
| 5011 |
|
| 5012 |
if ( itemIndex === 0 ) { |
| 5013 |
if ( this.hasInput ) { |
| 5014 |
return this.input; |
| 5015 |
} else { |
| 5016 |
|
| 5017 |
return this.items[ this.items.length - 1 ]; |
| 5018 |
} |
| 5019 |
} else { |
| 5020 |
return this.items[ itemIndex - 1 ]; |
| 5021 |
} |
| 5022 |
}; |
| 5023 |
|
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
|
| 5032 |
OO.ui.TagMultiselectWidget.prototype.updateInputSize = function () { |
| 5033 |
if ( this.inputPosition === 'inline' && !this.isDisabled() ) { |
| 5034 |
if ( this.input.$input[ 0 ].scrollWidth === 0 ) { |
| 5035 |
|
| 5036 |
|
| 5037 |
|
| 5038 |
return; |
| 5039 |
} |
| 5040 |
this.input.$input.css( 'width', '1em' ); |
| 5041 |
const $lastItem = this.$group.children().last(); |
| 5042 |
const direction = OO.ui.Element.static.getDir( this.$handle ); |
| 5043 |
|
| 5044 |
|
| 5045 |
|
| 5046 |
const placeholder = this.input.$input.attr( 'placeholder' ); |
| 5047 |
if ( |
| 5048 |
this.contentWidthWithPlaceholder === undefined && |
| 5049 |
this.input.getValue() === '' && |
| 5050 |
placeholder !== undefined |
| 5051 |
) { |
| 5052 |
|
| 5053 |
this.input.$input.val( placeholder ); |
| 5054 |
this.contentWidthWithPlaceholder = this.input.$input[ 0 ].scrollWidth; |
| 5055 |
this.input.$input.val( '' ); |
| 5056 |
|
| 5057 |
} |
| 5058 |
|
| 5059 |
|
| 5060 |
const contentWidth = Math.max( |
| 5061 |
this.input.$input[ 0 ].scrollWidth, |
| 5062 |
|
| 5063 |
( this.contentWidthWithPlaceholder === undefined ) ? |
| 5064 |
0 : this.contentWidthWithPlaceholder |
| 5065 |
); |
| 5066 |
const currentWidth = this.input.$input.width(); |
| 5067 |
|
| 5068 |
if ( contentWidth < currentWidth ) { |
| 5069 |
this.updateIfHeightChanged(); |
| 5070 |
|
| 5071 |
return; |
| 5072 |
} |
| 5073 |
|
| 5074 |
let bestWidth; |
| 5075 |
if ( $lastItem.length === 0 ) { |
| 5076 |
bestWidth = this.$content.innerWidth(); |
| 5077 |
} else { |
| 5078 |
bestWidth = direction === 'ltr' ? |
| 5079 |
this.$content.innerWidth() - $lastItem.position().left - $lastItem.outerWidth() : |
| 5080 |
$lastItem.position().left; |
| 5081 |
} |
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
bestWidth -= 13; |
| 5086 |
if ( contentWidth > bestWidth ) { |
| 5087 |
|
| 5088 |
bestWidth = this.$content.innerWidth() - 13; |
| 5089 |
} |
| 5090 |
this.input.$input.width( Math.floor( bestWidth ) ); |
| 5091 |
this.updateIfHeightChanged(); |
| 5092 |
} else { |
| 5093 |
this.updateIfHeightChanged(); |
| 5094 |
} |
| 5095 |
}; |
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
|
| 5101 |
|
| 5102 |
|
| 5103 |
|
| 5104 |
|
| 5105 |
|
| 5106 |
OO.ui.TagMultiselectWidget.prototype.updateIfHeightChanged = function () { |
| 5107 |
const height = this.$element.height(); |
| 5108 |
if ( height !== this.height ) { |
| 5109 |
this.height = height; |
| 5110 |
this.emit( 'resize' ); |
| 5111 |
} |
| 5112 |
}; |
| 5113 |
|
| 5114 |
|
| 5115 |
|
| 5116 |
|
| 5117 |
|
| 5118 |
|
| 5119 |
OO.ui.TagMultiselectWidget.prototype.checkValidity = function () { |
| 5120 |
return this.getItems().every( ( item ) => item.isValid() ); |
| 5121 |
}; |
| 5122 |
|
| 5123 |
|
| 5124 |
|
| 5125 |
|
| 5126 |
|
| 5127 |
|
| 5128 |
|
| 5129 |
OO.ui.TagMultiselectWidget.prototype.toggleValid = function ( valid ) { |
| 5130 |
valid = valid === undefined ? !this.valid : !!valid; |
| 5131 |
|
| 5132 |
if ( this.valid !== valid ) { |
| 5133 |
this.valid = valid; |
| 5134 |
|
| 5135 |
this.setFlags( { invalid: !this.valid } ); |
| 5136 |
|
| 5137 |
this.emit( 'valid', this.valid ); |
| 5138 |
} |
| 5139 |
}; |
| 5140 |
|
| 5141 |
|
| 5142 |
|
| 5143 |
|
| 5144 |
|
| 5145 |
|
| 5146 |
OO.ui.TagMultiselectWidget.prototype.isValid = function () { |
| 5147 |
return this.valid; |
| 5148 |
}; |
| 5149 |
|
| 5150 |
|
| 5151 |
|
| 5152 |
|
| 5153 |
|
| 5154 |
|
| 5155 |
|
| 5156 |
|
| 5157 |
|
| 5158 |
|
| 5159 |
|
| 5160 |
|
| 5161 |
|
| 5162 |
|
| 5163 |
|
| 5164 |
|
| 5165 |
|
| 5166 |
|
| 5167 |
|
| 5168 |
|
| 5169 |
|
| 5170 |
|
| 5171 |
|
| 5172 |
|
| 5173 |
|
| 5174 |
|
| 5175 |
|
| 5176 |
|
| 5177 |
|
| 5178 |
|
| 5179 |
|
| 5180 |
|
| 5181 |
|
| 5182 |
|
| 5183 |
OO.ui.PopupTagMultiselectWidget = function OoUiPopupTagMultiselectWidget( config ) { |
| 5184 |
const defaultConfig = { popup: {} }; |
| 5185 |
|
| 5186 |
config = config || {}; |
| 5187 |
|
| 5188 |
|
| 5189 |
OO.ui.PopupTagMultiselectWidget.super.call( this, Object.assign( { |
| 5190 |
inputPosition: 'none' |
| 5191 |
}, config ) ); |
| 5192 |
|
| 5193 |
this.$overlay = ( config.$overlay === true ? |
| 5194 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 5195 |
|
| 5196 |
if ( !config.popup ) { |
| 5197 |
|
| 5198 |
|
| 5199 |
|
| 5200 |
|
| 5201 |
const defaultInput = new OO.ui.TextInputWidget(); |
| 5202 |
|
| 5203 |
defaultConfig.popupInput = defaultInput; |
| 5204 |
defaultConfig.popup.$content = defaultInput.$element; |
| 5205 |
defaultConfig.popup.padded = true; |
| 5206 |
|
| 5207 |
this.$element.addClass( 'oo-ui-popupTagMultiselectWidget-defaultPopup' ); |
| 5208 |
} |
| 5209 |
|
| 5210 |
|
| 5211 |
defaultConfig.popup.$overlay = this.$overlay; |
| 5212 |
defaultConfig.popup.$autoCloseIgnore = this.hasInput ? |
| 5213 |
this.input.$element.add( this.$overlay ) : this.$overlay; |
| 5214 |
|
| 5215 |
|
| 5216 |
config = Object.assign( defaultConfig, config ); |
| 5217 |
|
| 5218 |
|
| 5219 |
OO.ui.mixin.PopupElement.call( this, config ); |
| 5220 |
|
| 5221 |
if ( this.hasInput ) { |
| 5222 |
this.input.$input.on( 'focus', this.popup.toggle.bind( this.popup, true ) ); |
| 5223 |
} |
| 5224 |
|
| 5225 |
|
| 5226 |
this.popupInput = config.popupInput; |
| 5227 |
if ( this.popupInput ) { |
| 5228 |
this.popupInput.connect( this, { |
| 5229 |
enter: 'onPopupInputEnter' |
| 5230 |
} ); |
| 5231 |
} |
| 5232 |
|
| 5233 |
|
| 5234 |
this.on( 'resize', this.popup.updateDimensions.bind( this.popup ) ); |
| 5235 |
this.popup.connect( this, { |
| 5236 |
toggle: 'onPopupToggle' |
| 5237 |
} ); |
| 5238 |
this.$tabIndexed.on( 'focus', this.onFocus.bind( this ) ); |
| 5239 |
|
| 5240 |
|
| 5241 |
this.$element |
| 5242 |
.append( this.popup.$element ) |
| 5243 |
.addClass( 'oo-ui-popupTagMultiselectWidget' ); |
| 5244 |
|
| 5245 |
|
| 5246 |
OO.ui.warnDeprecation( 'PopupTagMultiselectWidget: Deprecated widget. Use MenuTagMultiselectWidget instead. See T208821.' ); |
| 5247 |
}; |
| 5248 |
|
| 5249 |
|
| 5250 |
|
| 5251 |
OO.inheritClass( OO.ui.PopupTagMultiselectWidget, OO.ui.TagMultiselectWidget ); |
| 5252 |
OO.mixinClass( OO.ui.PopupTagMultiselectWidget, OO.ui.mixin.PopupElement ); |
| 5253 |
|
| 5254 |
|
| 5255 |
|
| 5256 |
|
| 5257 |
|
| 5258 |
|
| 5259 |
|
| 5260 |
|
| 5261 |
OO.ui.PopupTagMultiselectWidget.prototype.onFocus = function () { |
| 5262 |
this.popup.toggle( true ); |
| 5263 |
}; |
| 5264 |
|
| 5265 |
|
| 5266 |
|
| 5267 |
|
| 5268 |
|
| 5269 |
|
| 5270 |
OO.ui.PopupTagMultiselectWidget.prototype.onPopupToggle = function ( isVisible ) { |
| 5271 |
if ( isVisible && this.popupInput ) { |
| 5272 |
this.popupInput.focus(); |
| 5273 |
} |
| 5274 |
}; |
| 5275 |
|
| 5276 |
|
| 5277 |
|
| 5278 |
|
| 5279 |
OO.ui.PopupTagMultiselectWidget.prototype.onPopupInputEnter = function () { |
| 5280 |
if ( this.popupInput ) { |
| 5281 |
this.addTagByPopupValue( this.popupInput.getValue() ); |
| 5282 |
this.popupInput.setValue( '' ); |
| 5283 |
} |
| 5284 |
}; |
| 5285 |
|
| 5286 |
|
| 5287 |
|
| 5288 |
|
| 5289 |
OO.ui.PopupTagMultiselectWidget.prototype.onTagSelect = function ( item ) { |
| 5290 |
if ( this.popupInput && this.allowEditTags ) { |
| 5291 |
this.popupInput.setValue( item.getData() ); |
| 5292 |
this.removeItems( [ item ] ); |
| 5293 |
|
| 5294 |
this.popup.toggle( true ); |
| 5295 |
this.popupInput.focus(); |
| 5296 |
} else { |
| 5297 |
|
| 5298 |
OO.ui.PopupTagMultiselectWidget.super.prototype.onTagSelect.call( this, item ); |
| 5299 |
} |
| 5300 |
}; |
| 5301 |
|
| 5302 |
|
| 5303 |
|
| 5304 |
|
| 5305 |
|
| 5306 |
|
| 5307 |
|
| 5308 |
|
| 5309 |
|
| 5310 |
|
| 5311 |
OO.ui.PopupTagMultiselectWidget.prototype.addTagByPopupValue = function ( data, label ) { |
| 5312 |
this.addTag( data, label ); |
| 5313 |
}; |
| 5314 |
|
| 5315 |
|
| 5316 |
|
| 5317 |
|
| 5318 |
|
| 5319 |
|
| 5320 |
|
| 5321 |
|
| 5322 |
|
| 5323 |
|
| 5324 |
|
| 5325 |
|
| 5326 |
|
| 5327 |
|
| 5328 |
|
| 5329 |
|
| 5330 |
|
| 5331 |
|
| 5332 |
|
| 5333 |
|
| 5334 |
|
| 5335 |
|
| 5336 |
|
| 5337 |
|
| 5338 |
|
| 5339 |
|
| 5340 |
|
| 5341 |
… }` |
| 5342 |
|
| 5343 |
OO.ui.MenuTagMultiselectWidget = function OoUiMenuTagMultiselectWidget( config ) { |
| 5344 |
let $autoCloseIgnore = $( [] ); |
| 5345 |
|
| 5346 |
config = config || {}; |
| 5347 |
|
| 5348 |
|
| 5349 |
|
| 5350 |
let options = config.options || []; |
| 5351 |
const selected = config.selected || []; |
| 5352 |
options = options.concat( |
| 5353 |
selected.map( ( option ) => { |
| 5354 |
if ( typeof option === 'string' ) { |
| 5355 |
return { |
| 5356 |
data: option, |
| 5357 |
label: option |
| 5358 |
}; |
| 5359 |
} |
| 5360 |
return option; |
| 5361 |
} ) |
| 5362 |
); |
| 5363 |
|
| 5364 |
const configCopy = OO.copy( config ); |
| 5365 |
configCopy.options = options; |
| 5366 |
configCopy.selected = selected; |
| 5367 |
|
| 5368 |
|
| 5369 |
OO.ui.MenuTagMultiselectWidget.super.call( this, configCopy ); |
| 5370 |
|
| 5371 |
$autoCloseIgnore = $autoCloseIgnore.add( this.$group ); |
| 5372 |
if ( this.hasInput ) { |
| 5373 |
$autoCloseIgnore = $autoCloseIgnore.add( this.input.$element ); |
| 5374 |
} |
| 5375 |
|
| 5376 |
this.$overlay = ( config.$overlay === true ? |
| 5377 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 5378 |
this.clearInputOnChoose = config.clearInputOnChoose === undefined || |
| 5379 |
!!config.clearInputOnChoose; |
| 5380 |
this.menu = this.createMenuWidget( Object.assign( { |
| 5381 |
widget: this, |
| 5382 |
hideOnChoose: false, |
| 5383 |
input: this.hasInput ? this.input : null, |
| 5384 |
$input: this.hasInput ? this.input.$input : null, |
| 5385 |
filterFromInput: !!this.hasInput, |
| 5386 |
highlightOnFilter: !this.allowArbitrary, |
| 5387 |
multiselect: true, |
| 5388 |
$autoCloseIgnore: $autoCloseIgnore, |
| 5389 |
$floatableContainer: this.hasInput && this.inputPosition === 'outline' ? |
| 5390 |
this.input.$element : this.$element, |
| 5391 |
$overlay: this.$overlay, |
| 5392 |
disabled: this.isDisabled() |
| 5393 |
}, config.menu ) ); |
| 5394 |
this.addOptions( options ); |
| 5395 |
|
| 5396 |
|
| 5397 |
this.menu.connect( this, { |
| 5398 |
choose: 'onMenuChoose', |
| 5399 |
toggle: 'onMenuToggle' |
| 5400 |
} ); |
| 5401 |
if ( this.hasInput ) { |
| 5402 |
this.input.connect( this, { |
| 5403 |
change: 'onInputChange' |
| 5404 |
} ); |
| 5405 |
} |
| 5406 |
this.connect( this, { |
| 5407 |
resize: 'onResize' |
| 5408 |
} ); |
| 5409 |
|
| 5410 |
|
| 5411 |
this.$overlay.append( this.menu.$element ); |
| 5412 |
this.$element.addClass( 'oo-ui-menuTagMultiselectWidget' ); |
| 5413 |
|
| 5414 |
|
| 5415 |
this.menu.$focusOwner.removeAttr( 'aria-expanded' ); |
| 5416 |
|
| 5417 |
|
| 5418 |
if ( selected.length > 0 ) { |
| 5419 |
this.setValue( selected ); |
| 5420 |
} |
| 5421 |
}; |
| 5422 |
|
| 5423 |
|
| 5424 |
|
| 5425 |
OO.inheritClass( OO.ui.MenuTagMultiselectWidget, OO.ui.TagMultiselectWidget ); |
| 5426 |
|
| 5427 |
|
| 5428 |
|
| 5429 |
|
| 5430 |
|
| 5431 |
|
| 5432 |
OO.ui.MenuTagMultiselectWidget.prototype.onResize = function () { |
| 5433 |
|
| 5434 |
this.menu.position(); |
| 5435 |
}; |
| 5436 |
|
| 5437 |
|
| 5438 |
|
| 5439 |
|
| 5440 |
OO.ui.MenuTagMultiselectWidget.prototype.onInputFocus = function () { |
| 5441 |
const valid = this.isValid(); |
| 5442 |
|
| 5443 |
|
| 5444 |
OO.ui.MenuTagMultiselectWidget.super.prototype.onInputFocus.call( this ); |
| 5445 |
|
| 5446 |
this.menu.toggle( true ); |
| 5447 |
if ( !valid ) { |
| 5448 |
this.menu.highlightItem(); |
| 5449 |
} |
| 5450 |
}; |
| 5451 |
|
| 5452 |
|
| 5453 |
|
| 5454 |
|
| 5455 |
OO.ui.MenuTagMultiselectWidget.prototype.onInputChange = function () { |
| 5456 |
this.menu.toggle( true ); |
| 5457 |
}; |
| 5458 |
|
| 5459 |
|
| 5460 |
|
| 5461 |
|
| 5462 |
|
| 5463 |
|
| 5464 |
|
| 5465 |
OO.ui.MenuTagMultiselectWidget.prototype.onMenuChoose = function ( menuItem, selected ) { |
| 5466 |
if ( selected && !this.findItemFromData( menuItem.getData() ) ) { |
| 5467 |
|
| 5468 |
this.addTag( menuItem.getData(), menuItem.getLabel() ); |
| 5469 |
} else { |
| 5470 |
|
| 5471 |
this.removeTagByData( menuItem.getData() ); |
| 5472 |
} |
| 5473 |
|
| 5474 |
if ( this.hasInput && this.clearInputOnChoose ) { |
| 5475 |
this.input.setValue( '' ); |
| 5476 |
} |
| 5477 |
}; |
| 5478 |
|
| 5479 |
|
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
OO.ui.MenuTagMultiselectWidget.prototype.onMenuToggle = function ( isVisible ) { |
| 5485 |
if ( !isVisible ) { |
| 5486 |
this.menu.highlightItem( null ); |
| 5487 |
this.menu.scrollToTop(); |
| 5488 |
} |
| 5489 |
setTimeout( () => { |
| 5490 |
|
| 5491 |
|
| 5492 |
this.menu.$focusOwner.removeAttr( 'aria-expanded' ); |
| 5493 |
} ); |
| 5494 |
}; |
| 5495 |
|
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
OO.ui.MenuTagMultiselectWidget.prototype.onTagSelect = function ( tagItem ) { |
| 5500 |
const menuItem = this.menu.findItemFromData( tagItem.getData() ); |
| 5501 |
if ( !this.allowArbitrary ) { |
| 5502 |
|
| 5503 |
|
| 5504 |
|
| 5505 |
|
| 5506 |
|
| 5507 |
|
| 5508 |
if ( this.hasInput && this.menu.filterFromInput ) { |
| 5509 |
this.input.setValue( '' ); |
| 5510 |
} |
| 5511 |
|
| 5512 |
this.focus(); |
| 5513 |
|
| 5514 |
|
| 5515 |
this.menu.highlightItem( menuItem ); |
| 5516 |
this.menu.scrollItemIntoView( menuItem ); |
| 5517 |
|
| 5518 |
} else { |
| 5519 |
|
| 5520 |
OO.ui.MenuTagMultiselectWidget.super.prototype.onTagSelect.call( this, tagItem ); |
| 5521 |
} |
| 5522 |
}; |
| 5523 |
|
| 5524 |
|
| 5525 |
|
| 5526 |
|
| 5527 |
OO.ui.MenuTagMultiselectWidget.prototype.removeItems = function ( items ) { |
| 5528 |
|
| 5529 |
OO.ui.MenuTagMultiselectWidget.super.prototype.removeItems.call( this, items ); |
| 5530 |
|
| 5531 |
items.forEach( ( tagItem ) => { |
| 5532 |
const menuItem = this.menu.findItemFromData( tagItem.getData() ); |
| 5533 |
if ( menuItem ) { |
| 5534 |
|
| 5535 |
this.menu.unselectItem( menuItem ); |
| 5536 |
} |
| 5537 |
} ); |
| 5538 |
}; |
| 5539 |
|
| 5540 |
|
| 5541 |
|
| 5542 |
|
| 5543 |
OO.ui.MenuTagMultiselectWidget.prototype.setValue = function ( valueObject ) { |
| 5544 |
valueObject = Array.isArray( valueObject ) ? valueObject : [ valueObject ]; |
| 5545 |
|
| 5546 |
|
| 5547 |
|
| 5548 |
|
| 5549 |
if ( !this.menu ) { |
| 5550 |
return; |
| 5551 |
} |
| 5552 |
|
| 5553 |
this.clearItems(); |
| 5554 |
valueObject.forEach( ( obj ) => { |
| 5555 |
let data, label; |
| 5556 |
|
| 5557 |
if ( typeof obj === 'string' ) { |
| 5558 |
data = label = obj; |
| 5559 |
} else { |
| 5560 |
data = obj.data; |
| 5561 |
label = obj.label; |
| 5562 |
} |
| 5563 |
|
| 5564 |
|
| 5565 |
const menuItem = this.menu.getItemFromLabel( label ) || this.menu.findItemFromData( data ); |
| 5566 |
if ( menuItem ) { |
| 5567 |
|
| 5568 |
this.addTag( menuItem.getData(), menuItem.getLabel() ); |
| 5569 |
|
| 5570 |
this.menu.selectItem( menuItem ); |
| 5571 |
} else if ( this.allowArbitrary ) { |
| 5572 |
|
| 5573 |
|
| 5574 |
this.addTag( data, label ); |
| 5575 |
} |
| 5576 |
} ); |
| 5577 |
}; |
| 5578 |
|
| 5579 |
|
| 5580 |
|
| 5581 |
|
| 5582 |
OO.ui.MenuTagMultiselectWidget.prototype.setDisabled = function ( isDisabled ) { |
| 5583 |
|
| 5584 |
OO.ui.MenuTagMultiselectWidget.super.prototype.setDisabled.call( this, isDisabled ); |
| 5585 |
|
| 5586 |
if ( this.menu ) { |
| 5587 |
|
| 5588 |
this.menu.setDisabled( isDisabled ); |
| 5589 |
} |
| 5590 |
}; |
| 5591 |
|
| 5592 |
|
| 5593 |
|
| 5594 |
|
| 5595 |
|
| 5596 |
|
| 5597 |
|
| 5598 |
OO.ui.MenuTagMultiselectWidget.prototype.initializeMenuSelection = function () { |
| 5599 |
this.menu.highlightItem( |
| 5600 |
this.allowArbitrary ? |
| 5601 |
null : |
| 5602 |
this.menu.findFirstSelectableItem() |
| 5603 |
); |
| 5604 |
|
| 5605 |
const highlightedItem = this.menu.findHighlightedItem(); |
| 5606 |
|
| 5607 |
if ( highlightedItem ) { |
| 5608 |
this.menu.scrollItemIntoView( highlightedItem ); |
| 5609 |
} |
| 5610 |
}; |
| 5611 |
|
| 5612 |
|
| 5613 |
|
| 5614 |
|
| 5615 |
OO.ui.MenuTagMultiselectWidget.prototype.getTagInfoFromInput = function () { |
| 5616 |
const val = this.input.getValue(), |
| 5617 |
|
| 5618 |
|
| 5619 |
item = this.menu.findHighlightedItem() || this.menu.findItemFromData( val ), |
| 5620 |
data = item ? item.getData() : val, |
| 5621 |
label = item ? item.getLabel() : val; |
| 5622 |
|
| 5623 |
return { data: data, label: label }; |
| 5624 |
}; |
| 5625 |
|
| 5626 |
|
| 5627 |
|
| 5628 |
|
| 5629 |
|
| 5630 |
|
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
OO.ui.MenuTagMultiselectWidget.prototype.createMenuWidget = function ( menuConfig ) { |
| 5635 |
return new OO.ui.MenuSelectWidget( menuConfig ); |
| 5636 |
}; |
| 5637 |
|
| 5638 |
|
| 5639 |
|
| 5640 |
|
| 5641 |
|
| 5642 |
|
| 5643 |
OO.ui.MenuTagMultiselectWidget.prototype.addOptions = function ( menuOptions ) { |
| 5644 |
const optionsData = [], |
| 5645 |
items = []; |
| 5646 |
|
| 5647 |
menuOptions.forEach( ( obj ) => { |
| 5648 |
if ( optionsData.indexOf( obj.data ) === -1 ) { |
| 5649 |
optionsData.push( obj.data ); |
| 5650 |
items.push( |
| 5651 |
this.createMenuOptionWidget( obj.data, obj.label, obj.icon ) |
| 5652 |
); |
| 5653 |
} |
| 5654 |
} ); |
| 5655 |
|
| 5656 |
this.menu.addItems( items ); |
| 5657 |
}; |
| 5658 |
|
| 5659 |
|
| 5660 |
|
| 5661 |
|
| 5662 |
|
| 5663 |
|
| 5664 |
|
| 5665 |
|
| 5666 |
|
| 5667 |
OO.ui.MenuTagMultiselectWidget.prototype.createMenuOptionWidget = function ( data, label, icon ) { |
| 5668 |
return new OO.ui.MenuOptionWidget( { |
| 5669 |
data: data, |
| 5670 |
label: label || data, |
| 5671 |
icon: icon |
| 5672 |
} ); |
| 5673 |
}; |
| 5674 |
|
| 5675 |
|
| 5676 |
|
| 5677 |
|
| 5678 |
|
| 5679 |
|
| 5680 |
OO.ui.MenuTagMultiselectWidget.prototype.getMenu = function () { |
| 5681 |
return this.menu; |
| 5682 |
}; |
| 5683 |
|
| 5684 |
|
| 5685 |
|
| 5686 |
|
| 5687 |
|
| 5688 |
|
| 5689 |
OO.ui.MenuTagMultiselectWidget.prototype.getAllowedValues = function () { |
| 5690 |
let menuDatas = []; |
| 5691 |
if ( this.menu ) { |
| 5692 |
|
| 5693 |
menuDatas = this.menu.getItems().map( ( menuItem ) => menuItem.getData() ); |
| 5694 |
} |
| 5695 |
return this.allowedValues.concat( menuDatas ); |
| 5696 |
}; |
| 5697 |
|
| 5698 |
|
| 5699 |
|
| 5700 |
|
| 5701 |
|
| 5702 |
|
| 5703 |
|
| 5704 |
|
| 5705 |
|
| 5706 |
|
| 5707 |
|
| 5708 |
|
| 5709 |
|
| 5710 |
|
| 5711 |
|
| 5712 |
|
| 5713 |
|
| 5714 |
|
| 5715 |
|
| 5716 |
|
| 5717 |
|
| 5718 |
|
| 5719 |
|
| 5720 |
|
| 5721 |
|
| 5722 |
OO.ui.SearchWidget = function OoUiSearchWidget( config ) { |
| 5723 |
|
| 5724 |
config = config || {}; |
| 5725 |
|
| 5726 |
|
| 5727 |
OO.ui.SearchWidget.super.call( this, config ); |
| 5728 |
|
| 5729 |
|
| 5730 |
this.query = config.input || new OO.ui.SearchInputWidget( { |
| 5731 |
placeholder: config.placeholder, |
| 5732 |
value: config.value |
| 5733 |
} ); |
| 5734 |
this.results = new OO.ui.SelectWidget(); |
| 5735 |
this.results.setFocusOwner( this.query.$input ); |
| 5736 |
this.$query = $( '<div>' ); |
| 5737 |
this.$results = $( '<div>' ); |
| 5738 |
|
| 5739 |
|
| 5740 |
this.query.connect( this, { |
| 5741 |
change: 'onQueryChange', |
| 5742 |
enter: 'onQueryEnter' |
| 5743 |
} ); |
| 5744 |
this.query.$input.on( 'keydown', this.onQueryKeydown.bind( this ) ); |
| 5745 |
|
| 5746 |
|
| 5747 |
this.$query |
| 5748 |
.addClass( 'oo-ui-searchWidget-query' ) |
| 5749 |
.append( this.query.$element ); |
| 5750 |
this.$results |
| 5751 |
.addClass( 'oo-ui-searchWidget-results' ) |
| 5752 |
.append( this.results.$element ); |
| 5753 |
this.$element |
| 5754 |
.addClass( 'oo-ui-searchWidget' ) |
| 5755 |
.append( this.$results, this.$query ); |
| 5756 |
}; |
| 5757 |
|
| 5758 |
|
| 5759 |
|
| 5760 |
OO.inheritClass( OO.ui.SearchWidget, OO.ui.Widget ); |
| 5761 |
|
| 5762 |
|
| 5763 |
|
| 5764 |
|
| 5765 |
|
| 5766 |
|
| 5767 |
|
| 5768 |
|
| 5769 |
|
| 5770 |
OO.ui.SearchWidget.prototype.onQueryKeydown = function ( e ) { |
| 5771 |
const dir = e.which === OO.ui.Keys.DOWN ? 1 : ( e.which === OO.ui.Keys.UP ? -1 : 0 ); |
| 5772 |
|
| 5773 |
if ( dir ) { |
| 5774 |
const highlightedItem = this.results.findHighlightedItem() || this.results.findSelectedItem(); |
| 5775 |
const nextItem = this.results.findRelativeSelectableItem( highlightedItem, dir ); |
| 5776 |
|
| 5777 |
this.results.highlightItem( nextItem ); |
| 5778 |
if ( nextItem ) { |
| 5779 |
nextItem.scrollElementIntoView(); |
| 5780 |
} |
| 5781 |
} |
| 5782 |
}; |
| 5783 |
|
| 5784 |
|
| 5785 |
|
| 5786 |
|
| 5787 |
|
| 5788 |
|
| 5789 |
|
| 5790 |
|
| 5791 |
|
| 5792 |
OO.ui.SearchWidget.prototype.onQueryChange = function () { |
| 5793 |
|
| 5794 |
this.results.clearItems(); |
| 5795 |
}; |
| 5796 |
|
| 5797 |
|
| 5798 |
|
| 5799 |
|
| 5800 |
|
| 5801 |
|
| 5802 |
|
| 5803 |
|
| 5804 |
|
| 5805 |
OO.ui.SearchWidget.prototype.onQueryEnter = function () { |
| 5806 |
const highlightedItem = this.results.findHighlightedItem(); |
| 5807 |
if ( highlightedItem ) { |
| 5808 |
this.results.chooseItem( highlightedItem ); |
| 5809 |
} |
| 5810 |
}; |
| 5811 |
|
| 5812 |
|
| 5813 |
|
| 5814 |
|
| 5815 |
|
| 5816 |
|
| 5817 |
OO.ui.SearchWidget.prototype.getQuery = function () { |
| 5818 |
return this.query; |
| 5819 |
}; |
| 5820 |
|
| 5821 |
|
| 5822 |
|
| 5823 |
|
| 5824 |
|
| 5825 |
|
| 5826 |
OO.ui.SearchWidget.prototype.getResults = function () { |
| 5827 |
return this.results; |
| 5828 |
}; |
| 5829 |
|
| 5830 |
}( OO ) ); |
| 5831 |
|
| 5832 |
|