| 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 |
OO.ui = {}; |
| 21 |
|
| 22 |
OO.ui.bind = $.proxy; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
OO.ui.Keys = { |
| 28 |
UNDEFINED: 0, |
| 29 |
BACKSPACE: 8, |
| 30 |
DELETE: 46, |
| 31 |
LEFT: 37, |
| 32 |
RIGHT: 39, |
| 33 |
UP: 38, |
| 34 |
DOWN: 40, |
| 35 |
ENTER: 13, |
| 36 |
END: 35, |
| 37 |
HOME: 36, |
| 38 |
TAB: 9, |
| 39 |
PAGEUP: 33, |
| 40 |
PAGEDOWN: 34, |
| 41 |
ESCAPE: 27, |
| 42 |
SHIFT: 16, |
| 43 |
SPACE: 32 |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
OO.ui.MouseButtons = { |
| 52 |
LEFT: 1, |
| 53 |
MIDDLE: 2, |
| 54 |
RIGHT: 3 |
| 55 |
}; |
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
OO.ui.elementId = 0; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
OO.ui.generateElementId = function () { |
| 69 |
OO.ui.elementId++; |
| 70 |
return 'ooui-' + OO.ui.elementId; |
| 71 |
}; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
OO.ui.isFocusableElement = function ( $element ) { |
| 81 |
const element = $element[ 0 ]; |
| 82 |
|
| 83 |
|
| 84 |
if ( element.disabled ) { |
| 85 |
return false; |
| 86 |
} |
| 87 |
|
| 88 |
|
| 89 |
if ( !( |
| 90 |
|
| 91 |
$.expr.pseudos.visible( element ) && |
| 92 |
|
| 93 |
!$element.parents().addBack().filter( function () { |
| 94 |
return $.css( this, 'visibility' ) === 'hidden'; |
| 95 |
} ).length |
| 96 |
) ) { |
| 97 |
return false; |
| 98 |
} |
| 99 |
|
| 100 |
|
| 101 |
if ( element.contentEditable === 'true' ) { |
| 102 |
return true; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
if ( $element.prop( 'tabIndex' ) >= 0 ) { |
| 108 |
return true; |
| 109 |
} |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
const nodeName = element.nodeName.toLowerCase(); |
| 115 |
if ( [ 'input', 'select', 'textarea', 'button', 'object' ].indexOf( nodeName ) !== -1 ) { |
| 116 |
return true; |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
if ( ( nodeName === 'a' || nodeName === 'area' ) && $element.attr( 'href' ) !== undefined ) { |
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
return false; |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
OO.ui.findFocusable = function ( $container, backwards ) { |
| 135 |
let $focusable = $( [] ), |
| 136 |
|
| 137 |
|
| 138 |
$focusableCandidates = $container |
| 139 |
.find( 'input, select, textarea, button, object, a, area, [contenteditable], [tabindex]' ); |
| 140 |
|
| 141 |
if ( backwards ) { |
| 142 |
$focusableCandidates = Array.prototype.reverse.call( $focusableCandidates ); |
| 143 |
} |
| 144 |
|
| 145 |
$focusableCandidates.each( ( i, el ) => { |
| 146 |
const $el = $( el ); |
| 147 |
if ( OO.ui.isFocusableElement( $el ) ) { |
| 148 |
$focusable = $el; |
| 149 |
return false; |
| 150 |
} |
| 151 |
} ); |
| 152 |
return $focusable; |
| 153 |
}; |
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
|
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
OO.ui.getUserLanguages = function () { |
| 166 |
return [ 'en' ]; |
| 167 |
}; |
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
OO.ui.getLocalValue = function ( obj, lang, fallback ) { |
| 178 |
|
| 179 |
if ( obj[ lang ] ) { |
| 180 |
return obj[ lang ]; |
| 181 |
} |
| 182 |
|
| 183 |
const langs = OO.ui.getUserLanguages(); |
| 184 |
for ( let i = 0, len = langs.length; i < len; i++ ) { |
| 185 |
lang = langs[ i ]; |
| 186 |
if ( obj[ lang ] ) { |
| 187 |
return obj[ lang ]; |
| 188 |
} |
| 189 |
} |
| 190 |
|
| 191 |
if ( obj[ fallback ] ) { |
| 192 |
return obj[ fallback ]; |
| 193 |
} |
| 194 |
|
| 195 |
|
| 196 |
for ( lang in obj ) { |
| 197 |
return obj[ lang ]; |
| 198 |
} |
| 199 |
|
| 200 |
return undefined; |
| 201 |
}; |
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
OO.ui.contains = function ( containers, contained, matchContainers ) { |
| 216 |
if ( !Array.isArray( containers ) ) { |
| 217 |
containers = [ containers ]; |
| 218 |
} |
| 219 |
for ( let i = containers.length - 1; i >= 0; i-- ) { |
| 220 |
if ( |
| 221 |
( matchContainers && contained === containers[ i ] ) || |
| 222 |
$.contains( containers[ i ], contained ) |
| 223 |
) { |
| 224 |
return true; |
| 225 |
} |
| 226 |
} |
| 227 |
return false; |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
OO.ui.debounce = function ( func, wait, immediate ) { |
| 244 |
let timeout; |
| 245 |
return function () { |
| 246 |
const context = this, |
| 247 |
args = arguments, |
| 248 |
later = function () { |
| 249 |
timeout = null; |
| 250 |
if ( !immediate ) { |
| 251 |
func.apply( context, args ); |
| 252 |
} |
| 253 |
}; |
| 254 |
if ( immediate && !timeout ) { |
| 255 |
func.apply( context, args ); |
| 256 |
} |
| 257 |
if ( !timeout || wait ) { |
| 258 |
clearTimeout( timeout ); |
| 259 |
timeout = setTimeout( later, wait ); |
| 260 |
} |
| 261 |
}; |
| 262 |
}; |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
OO.ui.warnDeprecation = function ( message ) { |
| 270 |
if ( OO.getProp( window, 'console', 'warn' ) !== undefined ) { |
| 271 |
|
| 272 |
console.warn( message ); |
| 273 |
} |
| 274 |
}; |
| 275 |
|
| 276 |
|
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
|
| 286 |
|
| 287 |
|
| 288 |
|
| 289 |
OO.ui.throttle = function ( func, wait ) { |
| 290 |
let context, args, timeout, |
| 291 |
previous = Date.now() - wait; |
| 292 |
|
| 293 |
const run = function () { |
| 294 |
timeout = null; |
| 295 |
previous = Date.now(); |
| 296 |
func.apply( context, args ); |
| 297 |
}; |
| 298 |
|
| 299 |
return function () { |
| 300 |
|
| 301 |
|
| 302 |
|
| 303 |
|
| 304 |
|
| 305 |
const remaining = Math.max( wait - ( Date.now() - previous ), 0 ); |
| 306 |
context = this; |
| 307 |
args = arguments; |
| 308 |
if ( !timeout ) { |
| 309 |
|
| 310 |
|
| 311 |
timeout = setTimeout( run, remaining ); |
| 312 |
} |
| 313 |
}; |
| 314 |
}; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
|
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
OO.ui.infuse = function ( node, config ) { |
| 329 |
if ( typeof node === 'string' ) { |
| 330 |
|
| 331 |
|
| 332 |
OO.ui.warnDeprecation( |
| 333 |
'Passing a selector to infuse is deprecated. Use an HTMLElement or jQuery collection instead.' |
| 334 |
); |
| 335 |
} |
| 336 |
return OO.ui.Element.static.infuse( node, config ); |
| 337 |
}; |
| 338 |
|
| 339 |
|
| 340 |
|
| 341 |
|
| 342 |
|
| 343 |
|
| 344 |
|
| 345 |
|
| 346 |
|
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
|
| 354 |
|
| 355 |
|
| 356 |
|
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
|
| 369 |
|
| 370 |
|
| 371 |
|
| 372 |
|
| 373 |
|
| 374 |
|
| 375 |
|
| 376 |
|
| 377 |
|
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
|
| 388 |
|
| 389 |
OO.ui.msg = function ( key, ...params ) { |
| 390 |
|
| 391 |
const messages = OO.ui.msg.messages; |
| 392 |
|
| 393 |
let message = messages[ key ]; |
| 394 |
if ( typeof message === 'string' ) { |
| 395 |
|
| 396 |
message = message.replace( /\$(\d+)/g, ( unused, n ) => { |
| 397 |
const i = parseInt( n, 10 ); |
| 398 |
return params[ i - 1 ] !== undefined ? params[ i - 1 ] : '$' + n; |
| 399 |
} ); |
| 400 |
} else { |
| 401 |
|
| 402 |
message = '[' + key + ']'; |
| 403 |
} |
| 404 |
return message; |
| 405 |
}; |
| 406 |
|
| 407 |
|
| 408 |
|
| 409 |
|
| 410 |
|
| 411 |
|
| 412 |
|
| 413 |
|
| 414 |
|
| 415 |
|
| 416 |
OO.ui.deferMsg = function () { |
| 417 |
|
| 418 |
return () => OO.ui.msg( ...arguments ); |
| 419 |
}; |
| 420 |
|
| 421 |
|
| 422 |
|
| 423 |
|
| 424 |
|
| 425 |
|
| 426 |
|
| 427 |
|
| 428 |
|
| 429 |
|
| 430 |
OO.ui.resolveMsg = function ( msg ) { |
| 431 |
if ( typeof msg === 'function' ) { |
| 432 |
return msg(); |
| 433 |
} |
| 434 |
return msg; |
| 435 |
}; |
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
OO.ui.isSafeUrl = function ( url ) { |
| 442 |
|
| 443 |
|
| 444 |
function stringStartsWith( haystack, needle ) { |
| 445 |
return haystack.slice( 0, needle.length ) === needle; |
| 446 |
} |
| 447 |
|
| 448 |
const protocolAllowList = [ |
| 449 |
'bitcoin', 'ftp', 'ftps', 'geo', 'git', 'gopher', 'http', 'https', 'irc', 'ircs', |
| 450 |
'magnet', 'mailto', 'mms', 'news', 'nntp', 'redis', 'sftp', 'sip', 'sips', 'sms', 'ssh', |
| 451 |
'svn', 'tel', 'telnet', 'urn', 'worldwind', 'xmpp' |
| 452 |
]; |
| 453 |
|
| 454 |
if ( url === '' ) { |
| 455 |
return true; |
| 456 |
} |
| 457 |
|
| 458 |
for ( let i = 0; i < protocolAllowList.length; i++ ) { |
| 459 |
if ( stringStartsWith( url, protocolAllowList[ i ] + ':' ) ) { |
| 460 |
return true; |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
|
| 465 |
if ( stringStartsWith( url, '/' ) || stringStartsWith( url, './' ) ) { |
| 466 |
return true; |
| 467 |
} |
| 468 |
if ( stringStartsWith( url, '?' ) || stringStartsWith( url, '#' ) ) { |
| 469 |
return true; |
| 470 |
} |
| 471 |
|
| 472 |
return false; |
| 473 |
}; |
| 474 |
|
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
|
| 480 |
|
| 481 |
|
| 482 |
|
| 483 |
|
| 484 |
|
| 485 |
|
| 486 |
|
| 487 |
OO.ui.isMobile = function () { |
| 488 |
return false; |
| 489 |
}; |
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
OO.ui.getViewportSpacing = function () { |
| 500 |
return { |
| 501 |
top: 0, |
| 502 |
right: 0, |
| 503 |
bottom: 0, |
| 504 |
left: 0 |
| 505 |
}; |
| 506 |
}; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
|
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
|
| 517 |
OO.ui.getTeleportTarget = function () { |
| 518 |
return document.body; |
| 519 |
}; |
| 520 |
|
| 521 |
|
| 522 |
|
| 523 |
|
| 524 |
|
| 525 |
|
| 526 |
|
| 527 |
OO.ui.getDefaultOverlay = function () { |
| 528 |
if ( !OO.ui.$defaultOverlay ) { |
| 529 |
OO.ui.$defaultOverlay = $( '<div>' ).addClass( 'oo-ui-defaultOverlay' ); |
| 530 |
$( OO.ui.getTeleportTarget() ).append( OO.ui.$defaultOverlay ); |
| 531 |
} |
| 532 |
return OO.ui.$defaultOverlay; |
| 533 |
}; |
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
if ( window.customElements ) { |
| 538 |
window.customElements.define( 'ooui-connect-detector', class extends HTMLElement { |
| 539 |
connectedCallback() { |
| 540 |
if ( this.onConnectOOUI instanceof Function ) { |
| 541 |
this.onConnectOOUI(); |
| 542 |
} |
| 543 |
} |
| 544 |
} ); |
| 545 |
} |
| 546 |
|
| 547 |
|
| 548 |
|
| 549 |
|
| 550 |
|
| 551 |
|
| 552 |
|
| 553 |
|
| 554 |
|
| 555 |
OO.ui.msg.messages = { |
| 556 |
"ooui-copytextlayout-copy": "Copy", |
| 557 |
"ooui-outline-control-move-down": "Move item down", |
| 558 |
"ooui-outline-control-move-up": "Move item up", |
| 559 |
"ooui-outline-control-remove": "Remove item", |
| 560 |
"ooui-toolbar-more": "More", |
| 561 |
"ooui-toolgroup-expand": "More", |
| 562 |
"ooui-toolgroup-collapse": "Fewer", |
| 563 |
"ooui-item-remove": "Remove", |
| 564 |
"ooui-dialog-message-accept": "OK", |
| 565 |
"ooui-dialog-message-reject": "Cancel", |
| 566 |
"ooui-dialog-process-error": "Something went wrong", |
| 567 |
"ooui-dialog-process-dismiss": "Dismiss", |
| 568 |
"ooui-dialog-process-retry": "Try again", |
| 569 |
"ooui-dialog-process-continue": "Continue", |
| 570 |
"ooui-combobox-button-label": "Toggle options", |
| 571 |
"ooui-selectfile-button-select": "Select a file", |
| 572 |
"ooui-selectfile-button-select-multiple": "Select files", |
| 573 |
"ooui-selectfile-placeholder": "No file is selected", |
| 574 |
"ooui-selectfile-dragdrop-placeholder": "Drop file here", |
| 575 |
"ooui-selectfile-dragdrop-placeholder-multiple": "Drop files here", |
| 576 |
"ooui-popup-widget-close-button-aria-label": "Close", |
| 577 |
"ooui-field-help": "Help" |
| 578 |
}; |
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
|
| 585 |
|
| 586 |
|
| 587 |
|
| 588 |
|
| 589 |
|
| 590 |
|
| 591 |
|
| 592 |
|
| 593 |
|
| 594 |
OO.ui.mixin = {}; |
| 595 |
|
| 596 |
|
| 597 |
|
| 598 |
|
| 599 |
|
| 600 |
ng |
| 601 |
|
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
|
| 606 |
|
| 607 |
|
| 608 |
|
| 609 |
|
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
|
| 614 |
|
| 615 |
|
| 616 |
|
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
OO.ui.Element = function OoUiElement( config ) { |
| 625 |
if ( OO.ui.isDemo ) { |
| 626 |
this.initialConfig = config; |
| 627 |
} |
| 628 |
|
| 629 |
config = config || {}; |
| 630 |
|
| 631 |
|
| 632 |
this.elementId = null; |
| 633 |
this.visible = true; |
| 634 |
this.data = config.data; |
| 635 |
this.$element = config.$element || |
| 636 |
$( window.document.createElement( this.getTagName() ) ); |
| 637 |
this.elementGroup = null; |
| 638 |
|
| 639 |
|
| 640 |
const doc = OO.ui.Element.static.getDocument( this.$element ); |
| 641 |
if ( Array.isArray( config.classes ) ) { |
| 642 |
this.$element.addClass( config.classes ); |
| 643 |
} |
| 644 |
if ( config.id ) { |
| 645 |
this.setElementId( config.id ); |
| 646 |
} |
| 647 |
if ( config.text ) { |
| 648 |
this.$element.text( config.text ); |
| 649 |
} |
| 650 |
if ( config.content ) { |
| 651 |
|
| 652 |
|
| 653 |
|
| 654 |
this.$element.append( config.content.map( ( v ) => { |
| 655 |
if ( typeof v === 'string' ) { |
| 656 |
|
| 657 |
|
| 658 |
return v ? doc.createTextNode( v ) : undefined; |
| 659 |
} else if ( v instanceof OO.ui.HtmlSnippet ) { |
| 660 |
|
| 661 |
return v.toString(); |
| 662 |
} else if ( v instanceof OO.ui.Element ) { |
| 663 |
return v.$element; |
| 664 |
} |
| 665 |
return v; |
| 666 |
} ) ); |
| 667 |
} |
| 668 |
if ( config.$content ) { |
| 669 |
|
| 670 |
this.$element.append( config.$content ); |
| 671 |
} |
| 672 |
}; |
| 673 |
|
| 674 |
|
| 675 |
|
| 676 |
OO.initClass( OO.ui.Element ); |
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
OO.ui.Element.static.tagName = 'div'; |
| 689 |
|
| 690 |
|
| 691 |
|
| 692 |
|
| 693 |
|
| 694 |
|
| 695 |
|
| 696 |
|
| 697 |
|
| 698 |
|
| 699 |
|
| 700 |
|
| 701 |
|
| 702 |
|
| 703 |
|
| 704 |
|
| 705 |
OO.ui.Element.static.infuse = function ( node, config ) { |
| 706 |
const obj = OO.ui.Element.static.unsafeInfuse( node, config, false ); |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
|
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
|
| 715 |
return obj; |
| 716 |
}; |
| 717 |
|
| 718 |
|
| 719 |
|
| 720 |
|
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
|
| 725 |
|
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
|
| 730 |
OO.ui.Element.static.unsafeInfuse = function ( elem, config, domPromise ) { |
| 731 |
|
| 732 |
let $elem = $( elem ); |
| 733 |
|
| 734 |
if ( $elem.length > 1 ) { |
| 735 |
throw new Error( 'Collection contains more than one element' ); |
| 736 |
} |
| 737 |
if ( !$elem.length ) { |
| 738 |
throw new Error( 'Widget not found' ); |
| 739 |
} |
| 740 |
if ( $elem[ 0 ].$oouiInfused ) { |
| 741 |
$elem = $elem[ 0 ].$oouiInfused; |
| 742 |
} |
| 743 |
|
| 744 |
const id = $elem.attr( 'id' ); |
| 745 |
const doc = this.getDocument( $elem ); |
| 746 |
let data = $elem.data( 'ooui-infused' ); |
| 747 |
if ( data ) { |
| 748 |
|
| 749 |
if ( data === true ) { |
| 750 |
throw new Error( 'Circular dependency! ' + id ); |
| 751 |
} |
| 752 |
if ( domPromise ) { |
| 753 |
|
| 754 |
const stateCache = data.constructor.static.gatherPreInfuseState( $elem, data ); |
| 755 |
|
| 756 |
|
| 757 |
domPromise.done( data.restorePreInfuseState.bind( data, stateCache ) ); |
| 758 |
const infusedChildrenCache = $elem.data( 'ooui-infused-children' ); |
| 759 |
if ( infusedChildrenCache && infusedChildrenCache.length ) { |
| 760 |
infusedChildrenCache.forEach( ( childData ) => { |
| 761 |
const childState = childData.constructor.static.gatherPreInfuseState( |
| 762 |
$elem, |
| 763 |
childData |
| 764 |
); |
| 765 |
domPromise.done( |
| 766 |
childData.restorePreInfuseState.bind( childData, childState ) |
| 767 |
); |
| 768 |
} ); |
| 769 |
} |
| 770 |
} |
| 771 |
return data; |
| 772 |
} |
| 773 |
data = $elem.attr( 'data-ooui' ); |
| 774 |
if ( !data ) { |
| 775 |
throw new Error( 'No infusion data found: ' + id ); |
| 776 |
} |
| 777 |
try { |
| 778 |
data = JSON.parse( data ); |
| 779 |
} catch ( _ ) { |
| 780 |
data = null; |
| 781 |
} |
| 782 |
if ( !( data && data._ ) ) { |
| 783 |
throw new Error( 'No valid infusion data found: ' + id ); |
| 784 |
} |
| 785 |
if ( data._ === 'Tag' ) { |
| 786 |
|
| 787 |
return new OO.ui.Element( Object.assign( {}, config, { $element: $elem } ) ); |
| 788 |
} |
| 789 |
const parts = data._.split( '.' ); |
| 790 |
const cls = OO.getProp.apply( OO, [ window ].concat( parts ) ); |
| 791 |
|
| 792 |
if ( !( cls && ( cls === OO.ui.Element || cls.prototype instanceof OO.ui.Element ) ) ) { |
| 793 |
throw new Error( 'Unknown widget type: id: ' + id + ', class: ' + data._ ); |
| 794 |
} |
| 795 |
|
| 796 |
let top; |
| 797 |
if ( !domPromise ) { |
| 798 |
top = $.Deferred(); |
| 799 |
domPromise = top.promise(); |
| 800 |
} |
| 801 |
$elem.data( 'ooui-infused', true ); |
| 802 |
data.id = id; |
| 803 |
const infusedChildren = []; |
| 804 |
data = OO.copy( data, null, ( value ) => { |
| 805 |
let infused; |
| 806 |
if ( OO.isPlainObject( value ) ) { |
| 807 |
if ( value.tag && doc.getElementById( value.tag ) ) { |
| 808 |
infused = OO.ui.Element.static.unsafeInfuse( |
| 809 |
doc.getElementById( value.tag ), config, domPromise |
| 810 |
); |
| 811 |
infusedChildren.push( infused ); |
| 812 |
|
| 813 |
infusedChildren.push.apply( |
| 814 |
infusedChildren, |
| 815 |
infused.$element.data( 'ooui-infused-children' ) || [] |
| 816 |
); |
| 817 |
infused.$element.removeData( 'ooui-infused-children' ); |
| 818 |
return infused; |
| 819 |
} |
| 820 |
if ( value.html !== undefined ) { |
| 821 |
return new OO.ui.HtmlSnippet( value.html ); |
| 822 |
} |
| 823 |
} |
| 824 |
} ); |
| 825 |
|
| 826 |
data = cls.static.reusePreInfuseDOM( $elem[ 0 ], data ); |
| 827 |
|
| 828 |
const state = cls.static.gatherPreInfuseState( $elem[ 0 ], data ); |
| 829 |
|
| 830 |
|
| 831 |
const obj = new cls( Object.assign( {}, config, data ) ); |
| 832 |
|
| 833 |
|
| 834 |
|
| 835 |
$elem[ 0 ].$oouiInfused = obj.$element; |
| 836 |
|
| 837 |
if ( top ) { |
| 838 |
|
| 839 |
|
| 840 |
if ( $elem[ 0 ] !== obj.$element[ 0 ] ) { |
| 841 |
$elem.replaceWith( obj.$element ); |
| 842 |
} |
| 843 |
top.resolve(); |
| 844 |
} |
| 845 |
obj.$element |
| 846 |
.data( { |
| 847 |
'ooui-infused': obj, |
| 848 |
'ooui-infused-children': infusedChildren |
| 849 |
} ) |
| 850 |
|
| 851 |
.attr( 'data-ooui', '' ); |
| 852 |
|
| 853 |
domPromise.done( obj.restorePreInfuseState.bind( obj, state ) ); |
| 854 |
return obj; |
| 855 |
}; |
| 856 |
|
| 857 |
|
| 858 |
|
| 859 |
|
| 860 |
|
| 861 |
|
| 862 |
|
| 863 |
|
| 864 |
|
| 865 |
|
| 866 |
|
| 867 |
|
| 868 |
|
| 869 |
OO.ui.Element.static.reusePreInfuseDOM = function ( node, config ) { |
| 870 |
return config; |
| 871 |
}; |
| 872 |
|
| 873 |
|
| 874 |
|
| 875 |
|
| 876 |
|
| 877 |
|
| 878 |
|
| 879 |
|
| 880 |
|
| 881 |
|
| 882 |
|
| 883 |
|
| 884 |
|
| 885 |
|
| 886 |
|
| 887 |
OO.ui.Element.static.gatherPreInfuseState = function () { |
| 888 |
return {}; |
| 889 |
}; |
| 890 |
|
| 891 |
|
| 892 |
|
| 893 |
|
| 894 |
|
| 895 |
|
| 896 |
|
| 897 |
|
| 898 |
OO.ui.Element.static.getDocument = function ( obj ) { |
| 899 |
|
| 900 |
return obj.ownerDocument || |
| 901 |
|
| 902 |
obj.document || |
| 903 |
|
| 904 |
( obj.nodeType === Node.DOCUMENT_NODE && obj ) || |
| 905 |
|
| 906 |
( obj[ 0 ] && obj[ 0 ].ownerDocument ) || |
| 907 |
|
| 908 |
obj.context || |
| 909 |
null; |
| 910 |
}; |
| 911 |
|
| 912 |
|
| 913 |
|
| 914 |
|
| 915 |
|
| 916 |
|
| 917 |
|
| 918 |
|
| 919 |
OO.ui.Element.static.getWindow = function ( obj ) { |
| 920 |
const doc = this.getDocument( obj ); |
| 921 |
return doc.defaultView; |
| 922 |
}; |
| 923 |
|
| 924 |
|
| 925 |
|
| 926 |
|
| 927 |
|
| 928 |
|
| 929 |
|
| 930 |
|
| 931 |
OO.ui.Element.static.getDir = function ( obj ) { |
| 932 |
if ( obj instanceof $ ) { |
| 933 |
obj = obj[ 0 ]; |
| 934 |
} |
| 935 |
const isDoc = obj.nodeType === Node.DOCUMENT_NODE; |
| 936 |
const isWin = obj.document !== undefined; |
| 937 |
if ( isDoc || isWin ) { |
| 938 |
if ( isWin ) { |
| 939 |
obj = obj.document; |
| 940 |
} |
| 941 |
obj = obj.body; |
| 942 |
} |
| 943 |
return $( obj ).css( 'direction' ); |
| 944 |
}; |
| 945 |
|
| 946 |
|
| 947 |
|
| 948 |
|
| 949 |
|
| 950 |
|
| 951 |
|
| 952 |
|
| 953 |
|
| 954 |
|
| 955 |
|
| 956 |
|
| 957 |
OO.ui.Element.static.getFrameOffset = function ( from, to, offset ) { |
| 958 |
if ( !to ) { |
| 959 |
to = window; |
| 960 |
} |
| 961 |
if ( !offset ) { |
| 962 |
offset = { top: 0, left: 0 }; |
| 963 |
} |
| 964 |
if ( from.parent === from ) { |
| 965 |
return offset; |
| 966 |
} |
| 967 |
|
| 968 |
|
| 969 |
let frame; |
| 970 |
const frames = from.parent.document.getElementsByTagName( 'iframe' ); |
| 971 |
for ( let i = 0, len = frames.length; i < len; i++ ) { |
| 972 |
if ( frames[ i ].contentWindow === from ) { |
| 973 |
frame = frames[ i ]; |
| 974 |
break; |
| 975 |
} |
| 976 |
} |
| 977 |
|
| 978 |
|
| 979 |
if ( frame ) { |
| 980 |
const rect = frame.getBoundingClientRect(); |
| 981 |
offset.left += rect.left; |
| 982 |
offset.top += rect.top; |
| 983 |
if ( from !== to ) { |
| 984 |
this.getFrameOffset( from.parent, offset ); |
| 985 |
} |
| 986 |
} |
| 987 |
return offset; |
| 988 |
}; |
| 989 |
|
| 990 |
|
| 991 |
|
| 992 |
|
| 993 |
|
| 994 |
|
| 995 |
|
| 996 |
|
| 997 |
|
| 998 |
|
| 999 |
|
| 1000 |
|
| 1001 |
OO.ui.Element.static.getRelativePosition = function ( $element, $anchor ) { |
| 1002 |
const pos = $element.offset(); |
| 1003 |
const anchorPos = $anchor.offset(); |
| 1004 |
const anchorDocument = this.getDocument( $anchor ); |
| 1005 |
|
| 1006 |
let elementDocument = this.getDocument( $element ); |
| 1007 |
|
| 1008 |
|
| 1009 |
while ( elementDocument !== anchorDocument ) { |
| 1010 |
const iframe = elementDocument.defaultView.frameElement; |
| 1011 |
if ( !iframe ) { |
| 1012 |
throw new Error( '$element frame is not contained in $anchor frame' ); |
| 1013 |
} |
| 1014 |
const iframePos = $( iframe ).offset(); |
| 1015 |
pos.left += iframePos.left; |
| 1016 |
pos.top += iframePos.top; |
| 1017 |
elementDocument = this.getDocument( iframe ); |
| 1018 |
} |
| 1019 |
pos.left -= anchorPos.left; |
| 1020 |
pos.top -= anchorPos.top; |
| 1021 |
return pos; |
| 1022 |
}; |
| 1023 |
|
| 1024 |
|
| 1025 |
|
| 1026 |
|
| 1027 |
|
| 1028 |
|
| 1029 |
|
| 1030 |
|
| 1031 |
OO.ui.Element.static.getBorders = function ( el ) { |
| 1032 |
const doc = this.getDocument( el ), |
| 1033 |
win = doc.defaultView, |
| 1034 |
style = win.getComputedStyle( el, null ), |
| 1035 |
$el = $( el ), |
| 1036 |
top = parseFloat( style ? style.borderTopWidth : $el.css( 'borderTopWidth' ) ) || 0, |
| 1037 |
left = parseFloat( style ? style.borderLeftWidth : $el.css( 'borderLeftWidth' ) ) || 0, |
| 1038 |
bottom = parseFloat( style ? style.borderBottomWidth : $el.css( 'borderBottomWidth' ) ) || 0, |
| 1039 |
right = parseFloat( style ? style.borderRightWidth : $el.css( 'borderRightWidth' ) ) || 0; |
| 1040 |
|
| 1041 |
return { |
| 1042 |
top: top, |
| 1043 |
left: left, |
| 1044 |
bottom: bottom, |
| 1045 |
right: right |
| 1046 |
}; |
| 1047 |
}; |
| 1048 |
|
| 1049 |
|
| 1050 |
|
| 1051 |
|
| 1052 |
|
| 1053 |
|
| 1054 |
|
| 1055 |
|
| 1056 |
OO.ui.Element.static.getDimensions = function ( el ) { |
| 1057 |
const doc = this.getDocument( el ), |
| 1058 |
win = doc.defaultView; |
| 1059 |
|
| 1060 |
if ( win === el || el === doc.documentElement ) { |
| 1061 |
const $win = $( win ); |
| 1062 |
return { |
| 1063 |
borders: { top: 0, left: 0, bottom: 0, right: 0 }, |
| 1064 |
scroll: { |
| 1065 |
top: $win.scrollTop(), |
| 1066 |
left: OO.ui.Element.static.getScrollLeft( win ) |
| 1067 |
}, |
| 1068 |
scrollbar: { right: 0, bottom: 0 }, |
| 1069 |
rect: { |
| 1070 |
top: 0, |
| 1071 |
left: 0, |
| 1072 |
bottom: $win.innerHeight(), |
| 1073 |
right: $win.innerWidth() |
| 1074 |
} |
| 1075 |
}; |
| 1076 |
} else { |
| 1077 |
const $el = $( el ); |
| 1078 |
return { |
| 1079 |
borders: this.getBorders( el ), |
| 1080 |
scroll: { |
| 1081 |
top: $el.scrollTop(), |
| 1082 |
left: OO.ui.Element.static.getScrollLeft( el ) |
| 1083 |
}, |
| 1084 |
scrollbar: { |
| 1085 |
right: $el.innerWidth() - el.clientWidth, |
| 1086 |
bottom: $el.innerHeight() - el.clientHeight |
| 1087 |
}, |
| 1088 |
rect: el.getBoundingClientRect() |
| 1089 |
}; |
| 1090 |
} |
| 1091 |
}; |
| 1092 |
|
| 1093 |
( function () { |
| 1094 |
let rtlScrollType = null; |
| 1095 |
|
| 1096 |
|
| 1097 |
|
| 1098 |
function rtlScrollTypeTest() { |
| 1099 |
const $definer = $( '<div>' ).attr( { |
| 1100 |
dir: 'rtl', |
| 1101 |
style: 'font-size: 14px; width: 4px; height: 1px; position: absolute; top: -1000px; overflow: scroll;' |
| 1102 |
} ).text( 'ABCD' ), |
| 1103 |
definer = $definer[ 0 ]; |
| 1104 |
|
| 1105 |
$definer.appendTo( 'body' ); |
| 1106 |
if ( definer.scrollLeft > 0 ) { |
| 1107 |
|
| 1108 |
rtlScrollType = 'default'; |
| 1109 |
} else { |
| 1110 |
definer.scrollLeft = 1; |
| 1111 |
if ( definer.scrollLeft === 0 ) { |
| 1112 |
|
| 1113 |
rtlScrollType = 'negative'; |
| 1114 |
} |
| 1115 |
} |
| 1116 |
$definer.remove(); |
| 1117 |
} |
| 1118 |
|
| 1119 |
function isRoot( el ) { |
| 1120 |
return el === el.window || |
| 1121 |
el === el.ownerDocument.body || |
| 1122 |
el === el.ownerDocument.documentElement; |
| 1123 |
} |
| 1124 |
|
| 1125 |
|
| 1126 |
|
| 1127 |
|
| 1128 |
|
| 1129 |
|
| 1130 |
|
| 1131 |
|
| 1132 |
OO.ui.Element.static.computeNormalizedScrollLeft = function ( nativeOffset, el ) { |
| 1133 |
|
| 1134 |
|
| 1135 |
const direction = isRoot( el ) ? 'ltr' : $( el ).css( 'direction' ); |
| 1136 |
|
| 1137 |
if ( direction === 'rtl' ) { |
| 1138 |
if ( rtlScrollType === null ) { |
| 1139 |
rtlScrollTypeTest(); |
| 1140 |
} |
| 1141 |
if ( rtlScrollType === 'reverse' ) { |
| 1142 |
return -nativeOffset; |
| 1143 |
} else if ( rtlScrollType === 'default' ) { |
| 1144 |
return nativeOffset - el.scrollWidth + el.clientWidth; |
| 1145 |
} |
| 1146 |
} |
| 1147 |
|
| 1148 |
return nativeOffset; |
| 1149 |
}; |
| 1150 |
|
| 1151 |
|
| 1152 |
|
| 1153 |
|
| 1154 |
|
| 1155 |
|
| 1156 |
|
| 1157 |
|
| 1158 |
OO.ui.Element.static.computeNativeScrollLeft = function ( normalizedOffset, el ) { |
| 1159 |
|
| 1160 |
|
| 1161 |
const direction = isRoot( el ) ? 'ltr' : $( el ).css( 'direction' ); |
| 1162 |
|
| 1163 |
if ( direction === 'rtl' ) { |
| 1164 |
if ( rtlScrollType === null ) { |
| 1165 |
rtlScrollTypeTest(); |
| 1166 |
} |
| 1167 |
if ( rtlScrollType === 'reverse' ) { |
| 1168 |
return -normalizedOffset; |
| 1169 |
} else if ( rtlScrollType === 'default' ) { |
| 1170 |
return normalizedOffset + el.scrollWidth - el.clientWidth; |
| 1171 |
} |
| 1172 |
} |
| 1173 |
|
| 1174 |
return normalizedOffset; |
| 1175 |
}; |
| 1176 |
|
| 1177 |
|
| 1178 |
|
| 1179 |
|
| 1180 |
|
| 1181 |
|
| 1182 |
|
| 1183 |
|
| 1184 |
|
| 1185 |
|
| 1186 |
|
| 1187 |
|
| 1188 |
|
| 1189 |
|
| 1190 |
|
| 1191 |
|
| 1192 |
|
| 1193 |
|
| 1194 |
|
| 1195 |
|
| 1196 |
|
| 1197 |
|
| 1198 |
|
| 1199 |
|
| 1200 |
OO.ui.Element.static.getScrollLeft = function ( el ) { |
| 1201 |
let scrollLeft = isRoot( el ) ? $( window ).scrollLeft() : el.scrollLeft; |
| 1202 |
scrollLeft = OO.ui.Element.static.computeNormalizedScrollLeft( scrollLeft, el ); |
| 1203 |
return scrollLeft; |
| 1204 |
}; |
| 1205 |
|
| 1206 |
|
| 1207 |
|
| 1208 |
|
| 1209 |
|
| 1210 |
|
| 1211 |
|
| 1212 |
|
| 1213 |
|
| 1214 |
|
| 1215 |
|
| 1216 |
|
| 1217 |
|
| 1218 |
|
| 1219 |
|
| 1220 |
|
| 1221 |
|
| 1222 |
OO.ui.Element.static.setScrollLeft = function ( el, scrollLeft ) { |
| 1223 |
scrollLeft = OO.ui.Element.static.computeNativeScrollLeft( scrollLeft, el ); |
| 1224 |
if ( isRoot( el ) ) { |
| 1225 |
$( window ).scrollLeft( scrollLeft ); |
| 1226 |
} else { |
| 1227 |
el.scrollLeft = scrollLeft; |
| 1228 |
} |
| 1229 |
}; |
| 1230 |
}() ); |
| 1231 |
|
| 1232 |
|
| 1233 |
|
| 1234 |
|
| 1235 |
|
| 1236 |
|
| 1237 |
|
| 1238 |
|
| 1239 |
|
| 1240 |
|
| 1241 |
|
| 1242 |
|
| 1243 |
|
| 1244 |
|
| 1245 |
|
| 1246 |
OO.ui.Element.static.getRootScrollableElement = function ( el ) { |
| 1247 |
const doc = this.getDocument( el ); |
| 1248 |
|
| 1249 |
if ( OO.ui.scrollableElement === undefined ) { |
| 1250 |
const body = doc.body; |
| 1251 |
const scrollTop = body.scrollTop; |
| 1252 |
body.scrollTop = 1; |
| 1253 |
|
| 1254 |
|
| 1255 |
|
| 1256 |
if ( Math.round( body.scrollTop ) === 1 ) { |
| 1257 |
body.scrollTop = scrollTop; |
| 1258 |
OO.ui.scrollableElement = 'body'; |
| 1259 |
} else { |
| 1260 |
OO.ui.scrollableElement = 'documentElement'; |
| 1261 |
} |
| 1262 |
} |
| 1263 |
|
| 1264 |
return doc[ OO.ui.scrollableElement ]; |
| 1265 |
}; |
| 1266 |
|
| 1267 |
|
| 1268 |
|
| 1269 |
|
| 1270 |
|
| 1271 |
|
| 1272 |
|
| 1273 |
|
| 1274 |
|
| 1275 |
|
| 1276 |
|
| 1277 |
|
| 1278 |
OO.ui.Element.static.getClosestScrollableContainer = function ( el, dimension ) { |
| 1279 |
const doc = this.getDocument( el ); |
| 1280 |
const rootScrollableElement = this.getRootScrollableElement( el ); |
| 1281 |
|
| 1282 |
|
| 1283 |
let props = [ 'overflow-x', 'overflow-y' ]; |
| 1284 |
let $parent = $( el ).parent(); |
| 1285 |
|
| 1286 |
if ( el === doc.documentElement ) { |
| 1287 |
return rootScrollableElement; |
| 1288 |
} |
| 1289 |
|
| 1290 |
if ( dimension === 'x' || dimension === 'y' ) { |
| 1291 |
props = [ 'overflow-' + dimension ]; |
| 1292 |
} |
| 1293 |
|
| 1294 |
|
| 1295 |
while ( $parent.length && $parent[ 0 ] !== doc ) { |
| 1296 |
if ( $parent[ 0 ] === rootScrollableElement ) { |
| 1297 |
return $parent[ 0 ]; |
| 1298 |
} |
| 1299 |
let i = props.length; |
| 1300 |
while ( i-- ) { |
| 1301 |
const val = $parent.css( props[ i ] ); |
| 1302 |
|
| 1303 |
|
| 1304 |
|
| 1305 |
|
| 1306 |
|
| 1307 |
|
| 1308 |
if ( val === 'auto' || val === 'scroll' ) { |
| 1309 |
if ( $parent[ 0 ] === doc.body ) { |
| 1310 |
|
| 1311 |
|
| 1312 |
return rootScrollableElement; |
| 1313 |
} else { |
| 1314 |
return $parent[ 0 ]; |
| 1315 |
} |
| 1316 |
} |
| 1317 |
} |
| 1318 |
$parent = $parent.parent(); |
| 1319 |
} |
| 1320 |
e. |
| 1321 |
return rootScrollableElement; |
| 1322 |
}; |
| 1323 |
|
| 1324 |
|
| 1325 |
|
| 1326 |
|
| 1327 |
|
| 1328 |
|
| 1329 |
|
| 1330 |
|
| 1331 |
|
| 1332 |
|
| 1333 |
|
| 1334 |
|
| 1335 |
|
| 1336 |
|
| 1337 |
|
| 1338 |
|
| 1339 |
|
| 1340 |
|
| 1341 |
|
| 1342 |
OO.ui.Element.static.scrollIntoView = function ( elOrPosition, config ) { |
| 1343 |
const deferred = $.Deferred(); |
| 1344 |
|
| 1345 |
|
| 1346 |
config = config || {}; |
| 1347 |
|
| 1348 |
const padding = Object.assign( { |
| 1349 |
top: 0, |
| 1350 |
bottom: 0, |
| 1351 |
left: 0, |
| 1352 |
right: 0 |
| 1353 |
}, config.padding ); |
| 1354 |
|
| 1355 |
let animate = config.animate !== false; |
| 1356 |
if ( window.matchMedia( '(prefers-reduced-motion: reduce)' ).matches ) { |
| 1357 |
|
| 1358 |
animate = false; |
| 1359 |
} |
| 1360 |
|
| 1361 |
const animations = {}; |
| 1362 |
const elementPosition = elOrPosition instanceof HTMLElement ? |
| 1363 |
this.getDimensions( elOrPosition ).rect : |
| 1364 |
elOrPosition; |
| 1365 |
const container = config.scrollContainer || ( |
| 1366 |
elOrPosition instanceof HTMLElement ? |
| 1367 |
this.getClosestScrollableContainer( elOrPosition, config.direction ) : |
| 1368 |
|
| 1369 |
this.getClosestScrollableContainer( window.document.body ) |
| 1370 |
); |
| 1371 |
const $container = $( container ); |
| 1372 |
const containerDimensions = this.getDimensions( container ); |
| 1373 |
const $window = $( this.getWindow( container ) ); |
| 1374 |
|
| 1375 |
|
| 1376 |
let position; |
| 1377 |
if ( $container.is( 'html, body' ) ) { |
| 1378 |
|
| 1379 |
position = { |
| 1380 |
top: elementPosition.top, |
| 1381 |
bottom: $window.innerHeight() - elementPosition.bottom, |
| 1382 |
left: elementPosition.left, |
| 1383 |
right: $window.innerWidth() - elementPosition.right |
| 1384 |
}; |
| 1385 |
} else { |
| 1386 |
|
| 1387 |
position = { |
| 1388 |
top: elementPosition.top - |
| 1389 |
( containerDimensions.rect.top + containerDimensions.borders.top ), |
| 1390 |
bottom: containerDimensions.rect.bottom - containerDimensions.borders.bottom - |
| 1391 |
containerDimensions.scrollbar.bottom - elementPosition.bottom, |
| 1392 |
left: elementPosition.left - |
| 1393 |
( containerDimensions.rect.left + containerDimensions.borders.left ), |
| 1394 |
right: containerDimensions.rect.right - containerDimensions.borders.right - |
| 1395 |
containerDimensions.scrollbar.right - elementPosition.right |
| 1396 |
}; |
| 1397 |
} |
| 1398 |
|
| 1399 |
if ( !config.direction || config.direction === 'y' ) { |
| 1400 |
if ( position.top < padding.top || config.alignToTop ) { |
| 1401 |
animations.scrollTop = containerDimensions.scroll.top + position.top - padding.top; |
| 1402 |
} else if ( position.bottom < padding.bottom ) { |
| 1403 |
animations.scrollTop = containerDimensions.scroll.top + |
| 1404 |
|
| 1405 |
|
| 1406 |
Math.min( position.top - padding.top, -position.bottom + padding.bottom ); |
| 1407 |
} |
| 1408 |
} |
| 1409 |
if ( !config.direction || config.direction === 'x' ) { |
| 1410 |
if ( position.left < padding.left ) { |
| 1411 |
animations.scrollLeft = containerDimensions.scroll.left + position.left - padding.left; |
| 1412 |
} else if ( position.right < padding.right ) { |
| 1413 |
animations.scrollLeft = containerDimensions.scroll.left + |
| 1414 |
|
| 1415 |
|
| 1416 |
Math.min( position.left - padding.left, -position.right + padding.right ); |
| 1417 |
} |
| 1418 |
if ( animations.scrollLeft !== undefined ) { |
| 1419 |
animations.scrollLeft = |
| 1420 |
OO.ui.Element.static.computeNativeScrollLeft( animations.scrollLeft, container ); |
| 1421 |
} |
| 1422 |
} |
| 1423 |
if ( !$.isEmptyObject( animations ) ) { |
| 1424 |
if ( animate ) { |
| 1425 |
|
| 1426 |
$container.stop( true ).animate( animations, { |
| 1427 |
duration: config.duration === undefined ? 'fast' : config.duration, |
| 1428 |
always: deferred.resolve |
| 1429 |
} ); |
| 1430 |
} else { |
| 1431 |
$container.stop( true ); |
| 1432 |
for ( const method in animations ) { |
| 1433 |
$container[ method ]( animations[ method ] ); |
| 1434 |
} |
| 1435 |
deferred.resolve(); |
| 1436 |
} |
| 1437 |
} else { |
| 1438 |
deferred.resolve(); |
| 1439 |
} |
| 1440 |
return deferred.promise(); |
| 1441 |
}; |
| 1442 |
|
| 1443 |
|
| 1444 |
|
| 1445 |
|
| 1446 |
|
| 1447 |
|
| 1448 |
|
| 1449 |
|
| 1450 |
|
| 1451 |
|
| 1452 |
|
| 1453 |
|
| 1454 |
|
| 1455 |
OO.ui.Element.static.reconsiderScrollbars = function ( el ) { |
| 1456 |
|
| 1457 |
const scrollLeft = el.scrollLeft; |
| 1458 |
const scrollTop = el.scrollTop; |
| 1459 |
const nodes = []; |
| 1460 |
|
| 1461 |
while ( el.firstChild ) { |
| 1462 |
nodes.push( el.firstChild ); |
| 1463 |
el.removeChild( el.firstChild ); |
| 1464 |
} |
| 1465 |
|
| 1466 |
|
| 1467 |
el.offsetHeight; |
| 1468 |
|
| 1469 |
for ( let i = 0, len = nodes.length; i < len; i++ ) { |
| 1470 |
el.appendChild( nodes[ i ] ); |
| 1471 |
} |
| 1472 |
|
| 1473 |
el.scrollLeft = scrollLeft; |
| 1474 |
el.scrollTop = scrollTop; |
| 1475 |
}; |
| 1476 |
|
| 1477 |
|
| 1478 |
|
| 1479 |
|
| 1480 |
|
| 1481 |
|
| 1482 |
|
| 1483 |
|
| 1484 |
|
| 1485 |
|
| 1486 |
|
| 1487 |
OO.ui.Element.prototype.toggle = function ( show ) { |
| 1488 |
show = show === undefined ? !this.visible : !!show; |
| 1489 |
|
| 1490 |
if ( show !== this.isVisible() ) { |
| 1491 |
this.visible = show; |
| 1492 |
this.$element.toggleClass( 'oo-ui-element-hidden', !this.visible ); |
| 1493 |
this.emit( 'toggle', show ); |
| 1494 |
} |
| 1495 |
|
| 1496 |
return this; |
| 1497 |
}; |
| 1498 |
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
| 1502 |
|
| 1503 |
|
| 1504 |
OO.ui.Element.prototype.isVisible = function () { |
| 1505 |
return this.visible; |
| 1506 |
}; |
| 1507 |
|
| 1508 |
|
| 1509 |
|
| 1510 |
|
| 1511 |
|
| 1512 |
|
| 1513 |
OO.ui.Element.prototype.getData = function () { |
| 1514 |
return this.data; |
| 1515 |
}; |
| 1516 |
|
| 1517 |
|
| 1518 |
|
| 1519 |
|
| 1520 |
|
| 1521 |
|
| 1522 |
|
| 1523 |
|
| 1524 |
OO.ui.Element.prototype.setData = function ( data ) { |
| 1525 |
this.data = data; |
| 1526 |
return this; |
| 1527 |
}; |
| 1528 |
|
| 1529 |
|
| 1530 |
|
| 1531 |
|
| 1532 |
|
| 1533 |
|
| 1534 |
|
| 1535 |
|
| 1536 |
OO.ui.Element.prototype.setElementId = function ( id ) { |
| 1537 |
this.elementId = id; |
| 1538 |
this.$element.attr( 'id', id ); |
| 1539 |
return this; |
| 1540 |
}; |
| 1541 |
|
| 1542 |
|
| 1543 |
|
| 1544 |
|
| 1545 |
|
| 1546 |
|
| 1547 |
|
| 1548 |
OO.ui.Element.prototype.getElementId = function () { |
| 1549 |
if ( this.elementId === null ) { |
| 1550 |
this.setElementId( OO.ui.generateElementId() ); |
| 1551 |
} |
| 1552 |
return this.elementId; |
| 1553 |
}; |
| 1554 |
|
| 1555 |
|
| 1556 |
|
| 1557 |
|
| 1558 |
|
| 1559 |
|
| 1560 |
|
| 1561 |
OO.ui.Element.prototype.supports = function ( methods ) { |
| 1562 |
if ( !Array.isArray( methods ) ) { |
| 1563 |
return typeof this[ methods ] === 'function'; |
| 1564 |
} |
| 1565 |
|
| 1566 |
return methods.every( ( method ) => typeof this[ method ] === 'function' ); |
| 1567 |
}; |
| 1568 |
|
| 1569 |
|
| 1570 |
|
| 1571 |
|
| 1572 |
|
| 1573 |
|
| 1574 |
|
| 1575 |
|
| 1576 |
OO.ui.Element.prototype.updateThemeClasses = function () { |
| 1577 |
OO.ui.theme.queueUpdateElementClasses( this ); |
| 1578 |
}; |
| 1579 |
|
| 1580 |
|
| 1581 |
|
| 1582 |
|
| 1583 |
|
| 1584 |
|
| 1585 |
|
| 1586 |
|
| 1587 |
OO.ui.Element.prototype.getTagName = function () { |
| 1588 |
return this.constructor.static.tagName; |
| 1589 |
}; |
| 1590 |
|
| 1591 |
|
| 1592 |
|
| 1593 |
|
| 1594 |
|
| 1595 |
|
| 1596 |
OO.ui.Element.prototype.isElementAttached = function () { |
| 1597 |
return this.$element[ 0 ].isConnected; |
| 1598 |
}; |
| 1599 |
|
| 1600 |
|
| 1601 |
|
| 1602 |
|
| 1603 |
|
| 1604 |
|
| 1605 |
OO.ui.Element.prototype.getElementDocument = function () { |
| 1606 |
|
| 1607 |
return OO.ui.Element.static.getDocument( this.$element ); |
| 1608 |
}; |
| 1609 |
|
| 1610 |
|
| 1611 |
|
| 1612 |
|
| 1613 |
|
| 1614 |
|
| 1615 |
OO.ui.Element.prototype.getElementWindow = function () { |
| 1616 |
return OO.ui.Element.static.getWindow( this.$element ); |
| 1617 |
}; |
| 1618 |
|
| 1619 |
|
| 1620 |
|
| 1621 |
|
| 1622 |
|
| 1623 |
|
| 1624 |
OO.ui.Element.prototype.getClosestScrollableElementContainer = function () { |
| 1625 |
return OO.ui.Element.static.getClosestScrollableContainer( this.$element[ 0 ] ); |
| 1626 |
}; |
| 1627 |
|
| 1628 |
|
| 1629 |
|
| 1630 |
|
| 1631 |
|
| 1632 |
|
| 1633 |
OO.ui.Element.prototype.getElementGroup = function () { |
| 1634 |
return this.elementGroup; |
| 1635 |
}; |
| 1636 |
|
| 1637 |
|
| 1638 |
|
| 1639 |
|
| 1640 |
|
| 1641 |
|
| 1642 |
|
| 1643 |
|
| 1644 |
OO.ui.Element.prototype.setElementGroup = function ( group ) { |
| 1645 |
this.elementGroup = group; |
| 1646 |
return this; |
| 1647 |
}; |
| 1648 |
|
| 1649 |
|
| 1650 |
|
| 1651 |
|
| 1652 |
|
| 1653 |
|
| 1654 |
|
| 1655 |
OO.ui.Element.prototype.scrollElementIntoView = function ( config ) { |
| 1656 |
if ( |
| 1657 |
!this.isElementAttached() || |
| 1658 |
!this.isVisible() || |
| 1659 |
( this.getElementGroup() && !this.getElementGroup().isVisible() ) |
| 1660 |
) { |
| 1661 |
return $.Deferred().resolve(); |
| 1662 |
} |
| 1663 |
return OO.ui.Element.static.scrollIntoView( this.$element[ 0 ], config ); |
| 1664 |
}; |
| 1665 |
|
| 1666 |
|
| 1667 |
|
| 1668 |
|
| 1669 |
|
| 1670 |
|
| 1671 |
|
| 1672 |
|
| 1673 |
|
| 1674 |
|
| 1675 |
OO.ui.Element.prototype.restorePreInfuseState = function () { |
| 1676 |
}; |
| 1677 |
|
| 1678 |
|
| 1679 |
|
| 1680 |
|
| 1681 |
|
| 1682 |
|
| 1683 |
|
| 1684 |
|
| 1685 |
|
| 1686 |
|
| 1687 |
|
| 1688 |
OO.ui.HtmlSnippet = function OoUiHtmlSnippet( content ) { |
| 1689 |
|
| 1690 |
this.content = content; |
| 1691 |
}; |
| 1692 |
|
| 1693 |
|
| 1694 |
|
| 1695 |
OO.initClass( OO.ui.HtmlSnippet ); |
| 1696 |
|
| 1697 |
|
| 1698 |
|
| 1699 |
|
| 1700 |
|
| 1701 |
|
| 1702 |
|
| 1703 |
|
| 1704 |
OO.ui.HtmlSnippet.prototype.toString = function () { |
| 1705 |
return this.content; |
| 1706 |
}; |
| 1707 |
|
| 1708 |
|
| 1709 |
|
| 1710 |
|
| 1711 |
|
| 1712 |
|
| 1713 |
|
| 1714 |
|
| 1715 |
|
| 1716 |
|
| 1717 |
|
| 1718 |
|
| 1719 |
|
| 1720 |
|
| 1721 |
|
| 1722 |
|
| 1723 |
|
| 1724 |
|
| 1725 |
|
| 1726 |
OO.ui.Layout = function OoUiLayout( config ) { |
| 1727 |
|
| 1728 |
config = config || {}; |
| 1729 |
|
| 1730 |
|
| 1731 |
OO.ui.Layout.super.call( this, config ); |
| 1732 |
|
| 1733 |
|
| 1734 |
OO.EventEmitter.call( this ); |
| 1735 |
|
| 1736 |
|
| 1737 |
this.$element.addClass( 'oo-ui-layout' ); |
| 1738 |
}; |
| 1739 |
|
| 1740 |
|
| 1741 |
|
| 1742 |
OO.inheritClass( OO.ui.Layout, OO.ui.Element ); |
| 1743 |
OO.mixinClass( OO.ui.Layout, OO.EventEmitter ); |
| 1744 |
|
| 1745 |
|
| 1746 |
|
| 1747 |
|
| 1748 |
|
| 1749 |
|
| 1750 |
|
| 1751 |
|
| 1752 |
|
| 1753 |
OO.ui.Layout.prototype.resetScroll = function () { |
| 1754 |
this.$element[ 0 ].scrollTop = 0; |
| 1755 |
OO.ui.Element.static.setScrollLeft( this.$element[ 0 ], 0 ); |
| 1756 |
|
| 1757 |
return this; |
| 1758 |
}; |
| 1759 |
|
| 1760 |
|
| 1761 |
|
| 1762 |
|
| 1763 |
|
| 1764 |
|
| 1765 |
|
| 1766 |
|
| 1767 |
|
| 1768 |
|
| 1769 |
|
| 1770 |
|
| 1771 |
|
| 1772 |
|
| 1773 |
|
| 1774 |
|
| 1775 |
OO.ui.Widget = function OoUiWidget( config ) { |
| 1776 |
|
| 1777 |
OO.ui.Widget.super.call( this, config ); |
| 1778 |
|
| 1779 |
|
| 1780 |
OO.EventEmitter.call( this ); |
| 1781 |
|
| 1782 |
|
| 1783 |
this.disabled = null; |
| 1784 |
this.wasDisabled = null; |
| 1785 |
|
| 1786 |
|
| 1787 |
this.$element.addClass( 'oo-ui-widget' ); |
| 1788 |
this.setDisabled( config && config.disabled ); |
| 1789 |
}; |
| 1790 |
|
| 1791 |
|
| 1792 |
|
| 1793 |
OO.inheritClass( OO.ui.Widget, OO.ui.Element ); |
| 1794 |
OO.mixinClass( OO.ui.Widget, OO.EventEmitter ); |
| 1795 |
|
| 1796 |
|
| 1797 |
|
| 1798 |
|
| 1799 |
|
| 1800 |
|
| 1801 |
|
| 1802 |
|
| 1803 |
|
| 1804 |
|
| 1805 |
|
| 1806 |
|
| 1807 |
|
| 1808 |
|
| 1809 |
|
| 1810 |
|
| 1811 |
|
| 1812 |
|
| 1813 |
|
| 1814 |
|
| 1815 |
|
| 1816 |
|
| 1817 |
|
| 1818 |
|
| 1819 |
|
| 1820 |
OO.ui.Widget.prototype.isDisabled = function () { |
| 1821 |
return this.disabled; |
| 1822 |
}; |
| 1823 |
|
| 1824 |
|
| 1825 |
|
| 1826 |
|
| 1827 |
|
| 1828 |
|
| 1829 |
|
| 1830 |
|
| 1831 |
|
| 1832 |
|
| 1833 |
OO.ui.Widget.prototype.setDisabled = function ( disabled ) { |
| 1834 |
this.disabled = !!disabled; |
| 1835 |
const isDisabled = this.isDisabled(); |
| 1836 |
if ( isDisabled !== this.wasDisabled ) { |
| 1837 |
this.$element.toggleClass( 'oo-ui-widget-disabled', isDisabled ); |
| 1838 |
this.$element.toggleClass( 'oo-ui-widget-enabled', !isDisabled ); |
| 1839 |
this.$element.attr( 'aria-disabled', isDisabled ? 'true' : null ); |
| 1840 |
this.emit( 'disable', isDisabled ); |
| 1841 |
this.updateThemeClasses(); |
| 1842 |
this.wasDisabled = isDisabled; |
| 1843 |
} |
| 1844 |
|
| 1845 |
return this; |
| 1846 |
}; |
| 1847 |
|
| 1848 |
|
| 1849 |
|
| 1850 |
|
| 1851 |
|
| 1852 |
|
| 1853 |
|
| 1854 |
OO.ui.Widget.prototype.updateDisabled = function () { |
| 1855 |
this.setDisabled( this.disabled ); |
| 1856 |
return this; |
| 1857 |
}; |
| 1858 |
|
| 1859 |
|
| 1860 |
|
| 1861 |
|
| 1862 |
|
| 1863 |
|
| 1864 |
|
| 1865 |
|
| 1866 |
|
| 1867 |
|
| 1868 |
OO.ui.Widget.prototype.getInputId = function () { |
| 1869 |
return null; |
| 1870 |
}; |
| 1871 |
|
| 1872 |
|
| 1873 |
|
| 1874 |
|
| 1875 |
|
| 1876 |
|
| 1877 |
|
| 1878 |
|
| 1879 |
|
| 1880 |
|
| 1881 |
|
| 1882 |
|
| 1883 |
OO.ui.Widget.prototype.simulateLabelClick = function () { |
| 1884 |
}; |
| 1885 |
|
| 1886 |
|
| 1887 |
|
| 1888 |
|
| 1889 |
|
| 1890 |
|
| 1891 |
OO.ui.Widget.prototype.setLabelledBy = function ( id ) { |
| 1892 |
if ( id ) { |
| 1893 |
this.$element.attr( 'aria-labelledby', id ); |
| 1894 |
} else { |
| 1895 |
this.$element.removeAttr( 'aria-labelledby' ); |
| 1896 |
} |
| 1897 |
}; |
| 1898 |
|
| 1899 |
|
| 1900 |
|
| 1901 |
|
| 1902 |
|
| 1903 |
|
| 1904 |
|
| 1905 |
|
| 1906 |
|
| 1907 |
OO.ui.Theme = function OoUiTheme() { |
| 1908 |
this.elementClassesQueue = []; |
| 1909 |
this.debouncedUpdateQueuedElementClasses = OO.ui.debounce( this.updateQueuedElementClasses ); |
| 1910 |
}; |
| 1911 |
|
| 1912 |
|
| 1913 |
|
| 1914 |
OO.initClass( OO.ui.Theme ); |
| 1915 |
|
| 1916 |
|
| 1917 |
|
| 1918 |
|
| 1919 |
|
| 1920 |
|
| 1921 |
|
| 1922 |
|
| 1923 |
|
| 1924 |
|
| 1925 |
|
| 1926 |
|
| 1927 |
OO.ui.Theme.prototype.getElementClasses = function () { |
| 1928 |
return { on: [], off: [] }; |
| 1929 |
}; |
| 1930 |
|
| 1931 |
|
| 1932 |
|
| 1933 |
|
| 1934 |
|
| 1935 |
|
| 1936 |
|
| 1937 |
|
| 1938 |
OO.ui.Theme.prototype.updateElementClasses = function ( element ) { |
| 1939 |
const domElements = []; |
| 1940 |
|
| 1941 |
if ( element.$icon ) { |
| 1942 |
domElements.push( element.$icon[ 0 ] ); |
| 1943 |
} |
| 1944 |
if ( element.$indicator ) { |
| 1945 |
domElements.push( element.$indicator[ 0 ] ); |
| 1946 |
} |
| 1947 |
|
| 1948 |
if ( domElements.length ) { |
| 1949 |
const classes = this.getElementClasses( element ); |
| 1950 |
$( domElements ) |
| 1951 |
.removeClass( classes.off ) |
| 1952 |
.addClass( classes.on ); |
| 1953 |
} |
| 1954 |
}; |
| 1955 |
|
| 1956 |
|
| 1957 |
|
| 1958 |
|
| 1959 |
OO.ui.Theme.prototype.updateQueuedElementClasses = function () { |
| 1960 |
for ( let i = 0; i < this.elementClassesQueue.length; i++ ) { |
| 1961 |
this.updateElementClasses( this.elementClassesQueue[ i ] ); |
| 1962 |
} |
| 1963 |
|
| 1964 |
this.elementClassesQueue = []; |
| 1965 |
}; |
| 1966 |
|
| 1967 |
|
| 1968 |
|
| 1969 |
|
| 1970 |
|
| 1971 |
|
| 1972 |
|
| 1973 |
|
| 1974 |
|
| 1975 |
OO.ui.Theme.prototype.queueUpdateElementClasses = function ( element ) { |
| 1976 |
|
| 1977 |
|
| 1978 |
if ( this.elementClassesQueue.lastIndexOf( element ) !== -1 ) { |
| 1979 |
return; |
| 1980 |
} |
| 1981 |
this.elementClassesQueue.push( element ); |
| 1982 |
this.debouncedUpdateQueuedElementClasses(); |
| 1983 |
}; |
| 1984 |
|
| 1985 |
|
| 1986 |
|
| 1987 |
|
| 1988 |
|
| 1989 |
|
| 1990 |
|
| 1991 |
|
| 1992 |
|
| 1993 |
OO.ui.Theme.prototype.getDialogTransitionDuration = function () { |
| 1994 |
return 0; |
| 1995 |
}; |
| 1996 |
|
| 1997 |
|
| 1998 |
|
| 1999 |
the |
| 2000 |
|
| 2001 |
|
| 2002 |
|
| 2003 |
|
| 2004 |
|
| 2005 |
|
| 2006 |
|
| 2007 |
|
| 2008 |
|
| 2009 |
|
| 2010 |
|
| 2011 |
|
| 2012 |
|
| 2013 |
|
| 2014 |
|
| 2015 |
|
| 2016 |
|
| 2017 |
|
| 2018 |
|
| 2019 |
|
| 2020 |
|
| 2021 |
|
| 2022 |
|
| 2023 |
|
| 2024 |
|
| 2025 |
|
| 2026 |
|
| 2027 |
|
| 2028 |
|
| 2029 |
|
| 2030 |
|
| 2031 |
|
| 2032 |
|
| 2033 |
|
| 2034 |
|
| 2035 |
|
| 2036 |
he |
| 2037 |
|
| 2038 |
|
| 2039 |
|
| 2040 |
OO.ui.mixin.TabIndexedElement = function OoUiMixinTabIndexedElement( config ) { |
| 2041 |
|
| 2042 |
config = Object.assign( { tabIndex: 0 }, config ); |
| 2043 |
|
| 2044 |
|
| 2045 |
this.$tabIndexed = null; |
| 2046 |
this.tabIndex = null; |
| 2047 |
|
| 2048 |
|
| 2049 |
this.connect( this, { |
| 2050 |
disable: 'onTabIndexedElementDisable' |
| 2051 |
} ); |
| 2052 |
|
| 2053 |
|
| 2054 |
this.setTabIndex( config.tabIndex ); |
| 2055 |
this.setTabIndexedElement( config.$tabIndexed || this.$element ); |
| 2056 |
}; |
| 2057 |
|
| 2058 |
|
| 2059 |
|
| 2060 |
OO.initClass( OO.ui.mixin.TabIndexedElement ); |
| 2061 |
|
| 2062 |
|
| 2063 |
|
| 2064 |
|
| 2065 |
|
| 2066 |
|
| 2067 |
|
| 2068 |
’s |
| 2069 |
|
| 2070 |
|
| 2071 |
|
| 2072 |
|
| 2073 |
|
| 2074 |
|
| 2075 |
OO.ui.mixin.TabIndexedElement.prototype.setTabIndexedElement = function ( $tabIndexed ) { |
| 2076 |
const tabIndex = this.tabIndex; |
| 2077 |
|
| 2078 |
this.setTabIndex( null ); |
| 2079 |
|
| 2080 |
this.$tabIndexed = $tabIndexed; |
| 2081 |
this.tabIndex = tabIndex; |
| 2082 |
return this.updateTabIndex(); |
| 2083 |
}; |
| 2084 |
|
| 2085 |
|
| 2086 |
|
| 2087 |
|
| 2088 |
|
| 2089 |
|
| 2090 |
|
| 2091 |
|
| 2092 |
OO.ui.mixin.TabIndexedElement.prototype.setTabIndex = function ( tabIndex ) { |
| 2093 |
tabIndex = /^-?\d+$/.test( tabIndex ) ? Number( tabIndex ) : null; |
| 2094 |
|
| 2095 |
if ( this.tabIndex !== tabIndex ) { |
| 2096 |
this.tabIndex = tabIndex; |
| 2097 |
this.updateTabIndex(); |
| 2098 |
} |
| 2099 |
|
| 2100 |
return this; |
| 2101 |
}; |
| 2102 |
|
| 2103 |
|
| 2104 |
|
| 2105 |
|
| 2106 |
|
| 2107 |
|
| 2108 |
|
| 2109 |
|
| 2110 |
|
| 2111 |
OO.ui.mixin.TabIndexedElement.prototype.updateTabIndex = function () { |
| 2112 |
if ( this.$tabIndexed ) { |
| 2113 |
if ( this.tabIndex !== null ) { |
| 2114 |
|
| 2115 |
this.$tabIndexed.attr( { |
| 2116 |
tabindex: this.isDisabled() ? -1 : this.tabIndex, |
| 2117 |
|
| 2118 |
|
| 2119 |
'aria-disabled': this.isDisabled() ? 'true' : null |
| 2120 |
} ); |
| 2121 |
} else { |
| 2122 |
this.$tabIndexed.removeAttr( 'tabindex aria-disabled' ); |
| 2123 |
} |
| 2124 |
} |
| 2125 |
return this; |
| 2126 |
}; |
| 2127 |
|
| 2128 |
|
| 2129 |
|
| 2130 |
|
| 2131 |
|
| 2132 |
|
| 2133 |
|
| 2134 |
OO.ui.mixin.TabIndexedElement.prototype.onTabIndexedElementDisable = function () { |
| 2135 |
this.updateTabIndex(); |
| 2136 |
}; |
| 2137 |
|
| 2138 |
|
| 2139 |
|
| 2140 |
|
| 2141 |
|
| 2142 |
|
| 2143 |
OO.ui.mixin.TabIndexedElement.prototype.getTabIndex = function () { |
| 2144 |
return this.tabIndex; |
| 2145 |
}; |
| 2146 |
|
| 2147 |
|
| 2148 |
|
| 2149 |
|
| 2150 |
|
| 2151 |
|
| 2152 |
|
| 2153 |
|
| 2154 |
|
| 2155 |
OO.ui.mixin.TabIndexedElement.prototype.getInputId = function () { |
| 2156 |
if ( !this.$tabIndexed ) { |
| 2157 |
return null; |
| 2158 |
} |
| 2159 |
if ( !this.isLabelableNode( this.$tabIndexed ) ) { |
| 2160 |
return null; |
| 2161 |
} |
| 2162 |
|
| 2163 |
let id = this.$tabIndexed.attr( 'id' ); |
| 2164 |
if ( id === undefined ) { |
| 2165 |
id = OO.ui.generateElementId(); |
| 2166 |
this.$tabIndexed.attr( 'id', id ); |
| 2167 |
} |
| 2168 |
|
| 2169 |
return id; |
| 2170 |
}; |
| 2171 |
|
| 2172 |
|
| 2173 |
|
| 2174 |
). |
| 2175 |
|
| 2176 |
|
| 2177 |
|
| 2178 |
|
| 2179 |
|
| 2180 |
|
| 2181 |
OO.ui.mixin.TabIndexedElement.prototype.isLabelableNode = function ( $node ) { |
| 2182 |
const |
| 2183 |
labelableTags = [ 'button', 'meter', 'output', 'progress', 'select', 'textarea' ], |
| 2184 |
tagName = ( $node.prop( 'tagName' ) || '' ).toLowerCase(); |
| 2185 |
|
| 2186 |
if ( tagName === 'input' && $node.attr( 'type' ) !== 'hidden' ) { |
| 2187 |
return true; |
| 2188 |
} |
| 2189 |
if ( labelableTags.indexOf( tagName ) !== -1 ) { |
| 2190 |
return true; |
| 2191 |
} |
| 2192 |
return false; |
| 2193 |
}; |
| 2194 |
|
| 2195 |
|
| 2196 |
|
| 2197 |
|
| 2198 |
|
| 2199 |
|
| 2200 |
|
| 2201 |
OO.ui.mixin.TabIndexedElement.prototype.focus = function () { |
| 2202 |
if ( !this.isDisabled() ) { |
| 2203 |
this.$tabIndexed.trigger( 'focus' ); |
| 2204 |
} |
| 2205 |
return this; |
| 2206 |
}; |
| 2207 |
|
| 2208 |
|
| 2209 |
|
| 2210 |
|
| 2211 |
|
| 2212 |
|
| 2213 |
|
| 2214 |
OO.ui.mixin.TabIndexedElement.prototype.blur = function () { |
| 2215 |
this.$tabIndexed.trigger( 'blur' ); |
| 2216 |
return this; |
| 2217 |
}; |
| 2218 |
|
| 2219 |
|
| 2220 |
|
| 2221 |
|
| 2222 |
OO.ui.mixin.TabIndexedElement.prototype.simulateLabelClick = function () { |
| 2223 |
this.focus(); |
| 2224 |
}; |
| 2225 |
|
| 2226 |
|
| 2227 |
|
| 2228 |
|
| 2229 |
|
| 2230 |
|
| 2231 |
|
| 2232 |
|
| 2233 |
|
| 2234 |
|
| 2235 |
|
| 2236 |
|
| 2237 |
|
| 2238 |
|
| 2239 |
|
| 2240 |
|
| 2241 |
|
| 2242 |
OO.ui.mixin.ButtonElement = function OoUiMixinButtonElement( config ) { |
| 2243 |
|
| 2244 |
config = config || {}; |
| 2245 |
|
| 2246 |
|
| 2247 |
this.$button = null; |
| 2248 |
this.framed = null; |
| 2249 |
this.active = config.active !== undefined && config.active; |
| 2250 |
this.onDocumentMouseUpHandler = this.onDocumentMouseUp.bind( this ); |
| 2251 |
this.onMouseDownHandler = this.onMouseDown.bind( this ); |
| 2252 |
this.onDocumentKeyUpHandler = this.onDocumentKeyUp.bind( this ); |
| 2253 |
this.onKeyDownHandler = this.onKeyDown.bind( this ); |
| 2254 |
this.onClickHandler = this.onClick.bind( this ); |
| 2255 |
this.onKeyPressHandler = this.onKeyPress.bind( this ); |
| 2256 |
|
| 2257 |
|
| 2258 |
this.$element.addClass( 'oo-ui-buttonElement' ); |
| 2259 |
this.toggleFramed( config.framed === undefined || config.framed ); |
| 2260 |
this.setButtonElement( config.$button || $( '<a>' ) ); |
| 2261 |
}; |
| 2262 |
|
| 2263 |
|
| 2264 |
|
| 2265 |
OO.initClass( OO.ui.mixin.ButtonElement ); |
| 2266 |
|
| 2267 |
|
| 2268 |
|
| 2269 |
|
| 2270 |
|
| 2271 |
|
| 2272 |
|
| 2273 |
|
| 2274 |
|
| 2275 |
|
| 2276 |
|
| 2277 |
|
| 2278 |
|
| 2279 |
|
| 2280 |
|
| 2281 |
OO.ui.mixin.ButtonElement.static.cancelButtonMouseDownEvents = true; |
| 2282 |
|
| 2283 |
|
| 2284 |
|
| 2285 |
|
| 2286 |
|
| 2287 |
|
| 2288 |
|
| 2289 |
|
| 2290 |
|
| 2291 |
|
| 2292 |
|
| 2293 |
|
| 2294 |
|
| 2295 |
|
| 2296 |
|
| 2297 |
|
| 2298 |
t. |
| 2299 |
|
| 2300 |
|
| 2301 |
|
| 2302 |
OO.ui.mixin.ButtonElement.prototype.setButtonElement = function ( $button ) { |
| 2303 |
if ( this.$button ) { |
| 2304 |
this.$button |
| 2305 |
.removeClass( 'oo-ui-buttonElement-button' ) |
| 2306 |
.removeAttr( 'role accesskey' ) |
| 2307 |
.off( { |
| 2308 |
mousedown: this.onMouseDownHandler, |
| 2309 |
keydown: this.onKeyDownHandler, |
| 2310 |
click: this.onClickHandler, |
| 2311 |
keypress: this.onKeyPressHandler |
| 2312 |
} ); |
| 2313 |
} |
| 2314 |
|
| 2315 |
this.$button = $button |
| 2316 |
.addClass( 'oo-ui-buttonElement-button' ) |
| 2317 |
.on( { |
| 2318 |
mousedown: this.onMouseDownHandler, |
| 2319 |
keydown: this.onKeyDownHandler, |
| 2320 |
click: this.onClickHandler, |
| 2321 |
keypress: this.onKeyPressHandler |
| 2322 |
} ); |
| 2323 |
|
| 2324 |
|
| 2325 |
|
| 2326 |
if ( this.$button.prop( 'tagName' ).toUpperCase() === 'A' ) { |
| 2327 |
this.$button.attr( 'role', 'button' ); |
| 2328 |
} |
| 2329 |
}; |
| 2330 |
|
| 2331 |
|
| 2332 |
|
| 2333 |
|
| 2334 |
|
| 2335 |
|
| 2336 |
|
| 2337 |
|
| 2338 |
OO.ui.mixin.ButtonElement.prototype.onMouseDown = function ( e ) { |
| 2339 |
if ( this.isDisabled() || e.which !== OO.ui.MouseButtons.LEFT ) { |
| 2340 |
return; |
| 2341 |
} |
| 2342 |
this.$element.addClass( 'oo-ui-buttonElement-pressed' ); |
| 2343 |
|
| 2344 |
|
| 2345 |
this.getElementDocument().addEventListener( 'mouseup', this.onDocumentMouseUpHandler, true ); |
| 2346 |
|
| 2347 |
if ( this.constructor.static.cancelButtonMouseDownEvents ) { |
| 2348 |
return false; |
| 2349 |
} |
| 2350 |
}; |
| 2351 |
|
| 2352 |
|
| 2353 |
|
| 2354 |
|
| 2355 |
|
| 2356 |
|
| 2357 |
|
| 2358 |
OO.ui.mixin.ButtonElement.prototype.onDocumentMouseUp = function ( e ) { |
| 2359 |
if ( this.isDisabled() || e.which !== OO.ui.MouseButtons.LEFT ) { |
| 2360 |
return; |
| 2361 |
} |
| 2362 |
this.$element.removeClass( 'oo-ui-buttonElement-pressed' ); |
| 2363 |
|
| 2364 |
this.getElementDocument().removeEventListener( 'mouseup', this.onDocumentMouseUpHandler, true ); |
| 2365 |
}; |
| 2366 |
|
| 2367 |
|
| 2368 |
|
| 2369 |
|
| 2370 |
|
| 2371 |
|
| 2372 |
|
| 2373 |
|
| 2374 |
|
| 2375 |
OO.ui.mixin.ButtonElement.prototype.onClick = function ( e ) { |
| 2376 |
if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) { |
| 2377 |
if ( this.emit( 'click' ) ) { |
| 2378 |
return false; |
| 2379 |
} |
| 2380 |
} |
| 2381 |
}; |
| 2382 |
|
| 2383 |
|
| 2384 |
|
| 2385 |
|
| 2386 |
|
| 2387 |
|
| 2388 |
|
| 2389 |
OO.ui.mixin.ButtonElement.prototype.onKeyDown = function ( e ) { |
| 2390 |
if ( this.isDisabled() || ( e.which !== OO.ui.Keys.SPACE && e.which !== OO.ui.Keys.ENTER ) ) { |
| 2391 |
return; |
| 2392 |
} |
| 2393 |
this.$element.addClass( 'oo-ui-buttonElement-pressed' ); |
| 2394 |
|
| 2395 |
|
| 2396 |
this.getElementDocument().addEventListener( 'keyup', this.onDocumentKeyUpHandler, true ); |
| 2397 |
}; |
| 2398 |
|
| 2399 |
|
| 2400 |
|
| 2401 |
|
| 2402 |
|
| 2403 |
|
| 2404 |
|
| 2405 |
OO.ui.mixin.ButtonElement.prototype.onDocumentKeyUp = function ( e ) { |
| 2406 |
if ( this.isDisabled() || ( e.which !== OO.ui.Keys.SPACE && e.which !== OO.ui.Keys.ENTER ) ) { |
| 2407 |
return; |
| 2408 |
} |
| 2409 |
this.$element.removeClass( 'oo-ui-buttonElement-pressed' ); |
| 2410 |
|
| 2411 |
this.getElementDocument().removeEventListener( 'keyup', this.onDocumentKeyUpHandler, true ); |
| 2412 |
}; |
| 2413 |
|
| 2414 |
|
| 2415 |
|
| 2416 |
|
| 2417 |
|
| 2418 |
|
| 2419 |
|
| 2420 |
|
| 2421 |
|
| 2422 |
OO.ui.mixin.ButtonElement.prototype.onKeyPress = function ( e ) { |
| 2423 |
if ( !this.isDisabled() && ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) ) { |
| 2424 |
if ( this.emit( 'click' ) ) { |
| 2425 |
return false; |
| 2426 |
} |
| 2427 |
} |
| 2428 |
}; |
| 2429 |
|
| 2430 |
|
| 2431 |
|
| 2432 |
|
| 2433 |
|
| 2434 |
|
| 2435 |
OO.ui.mixin.ButtonElement.prototype.isFramed = function () { |
| 2436 |
return this.framed; |
| 2437 |
}; |
| 2438 |
|
| 2439 |
|
| 2440 |
|
| 2441 |
|
| 2442 |
|
| 2443 |
|
| 2444 |
|
| 2445 |
|
| 2446 |
|
| 2447 |
OO.ui.mixin.ButtonElement.prototype.toggleFramed = function ( framed ) { |
| 2448 |
framed = framed === undefined ? !this.framed : !!framed; |
| 2449 |
if ( framed !== this.framed ) { |
| 2450 |
this.framed = framed; |
| 2451 |
this.$element |
| 2452 |
.toggleClass( 'oo-ui-buttonElement-frameless', !framed ) |
| 2453 |
.toggleClass( 'oo-ui-buttonElement-framed', framed ); |
| 2454 |
this.updateThemeClasses(); |
| 2455 |
} |
| 2456 |
|
| 2457 |
return this; |
| 2458 |
}; |
| 2459 |
|
| 2460 |
|
| 2461 |
|
| 2462 |
|
| 2463 |
|
| 2464 |
|
| 2465 |
|
| 2466 |
|
| 2467 |
|
| 2468 |
|
| 2469 |
|
| 2470 |
|
| 2471 |
|
| 2472 |
|
| 2473 |
|
| 2474 |
OO.ui.mixin.ButtonElement.prototype.setActive = function ( value ) { |
| 2475 |
this.active = !!value; |
| 2476 |
this.$element.toggleClass( 'oo-ui-buttonElement-active', this.active ); |
| 2477 |
this.updateThemeClasses(); |
| 2478 |
return this; |
| 2479 |
}; |
| 2480 |
|
| 2481 |
|
| 2482 |
|
| 2483 |
|
| 2484 |
|
| 2485 |
|
| 2486 |
|
| 2487 |
OO.ui.mixin.ButtonElement.prototype.isActive = function () { |
| 2488 |
return this.active; |
| 2489 |
}; |
| 2490 |
|
| 2491 |
|
| 2492 |
|
| 2493 |
|
| 2494 |
|
| 2495 |
|
| 2496 |
|
| 2497 |
|
| 2498 |
|
| 2499 |
|
| 2500 |
|
| 2501 |
|
| 2502 |
|
| 2503 |
|
| 2504 |
|
| 2505 |
|
| 2506 |
|
| 2507 |
|
| 2508 |
OO.ui.mixin.GroupElement = function OoUiMixinGroupElement( config ) { |
| 2509 |
|
| 2510 |
config = config || {}; |
| 2511 |
|
| 2512 |
|
| 2513 |
OO.EmitterList.call( this, config ); |
| 2514 |
|
| 2515 |
|
| 2516 |
this.$group = null; |
| 2517 |
|
| 2518 |
|
| 2519 |
this.setGroupElement( config.$group || $( '<div>' ) ); |
| 2520 |
}; |
| 2521 |
|
| 2522 |
|
| 2523 |
|
| 2524 |
OO.mixinClass( OO.ui.mixin.GroupElement, OO.EmitterList ); |
| 2525 |
|
| 2526 |
|
| 2527 |
|
| 2528 |
|
| 2529 |
|
| 2530 |
|
| 2531 |
|
| 2532 |
|
| 2533 |
|
| 2534 |
|
| 2535 |
|
| 2536 |
|
| 2537 |
|
| 2538 |
|
| 2539 |
|
| 2540 |
|
| 2541 |
|
| 2542 |
|
| 2543 |
|
| 2544 |
OO.ui.mixin.GroupElement.prototype.setGroupElement = function ( $group ) { |
| 2545 |
this.$group = $group; |
| 2546 |
for ( let i = 0, len = this.items.length; i < len; i++ ) { |
| 2547 |
this.$group.append( this.items[ i ].$element ); |
| 2548 |
} |
| 2549 |
}; |
| 2550 |
|
| 2551 |
|
| 2552 |
|
| 2553 |
|
| 2554 |
|
| 2555 |
|
| 2556 |
|
| 2557 |
|
| 2558 |
|
| 2559 |
|
| 2560 |
OO.ui.mixin.GroupElement.prototype.findItemFromData = function ( data ) { |
| 2561 |
const hash = OO.getHash( data ); |
| 2562 |
|
| 2563 |
for ( let i = 0, len = this.items.length; i < len; i++ ) { |
| 2564 |
const item = this.items[ i ]; |
| 2565 |
if ( hash === OO.getHash( item.getData() ) ) { |
| 2566 |
return item; |
| 2567 |
} |
| 2568 |
} |
| 2569 |
|
| 2570 |
return null; |
| 2571 |
}; |
| 2572 |
|
| 2573 |
|
| 2574 |
|
| 2575 |
|
| 2576 |
|
| 2577 |
|
| 2578 |
|
| 2579 |
|
| 2580 |
|
| 2581 |
|
| 2582 |
OO.ui.mixin.GroupElement.prototype.findItemsFromData = function ( data ) { |
| 2583 |
const hash = OO.getHash( data ), |
| 2584 |
items = []; |
| 2585 |
|
| 2586 |
for ( let i = 0, len = this.items.length; i < len; i++ ) { |
| 2587 |
const item = this.items[ i ]; |
| 2588 |
if ( hash === OO.getHash( item.getData() ) ) { |
| 2589 |
items.push( item ); |
| 2590 |
} |
| 2591 |
} |
| 2592 |
|
| 2593 |
return items; |
| 2594 |
}; |
| 2595 |
|
| 2596 |
|
| 2597 |
|
| 2598 |
|
| 2599 |
|
| 2600 |
|
| 2601 |
|
| 2602 |
|
| 2603 |
|
| 2604 |
|
| 2605 |
|
| 2606 |
|
| 2607 |
|
| 2608 |
OO.ui.mixin.GroupElement.prototype.addItems = function ( items, index ) { |
| 2609 |
if ( !items || items.length === 0 ) { |
| 2610 |
return this; |
| 2611 |
} |
| 2612 |
|
| 2613 |
|
| 2614 |
OO.EmitterList.prototype.addItems.call( this, items, index ); |
| 2615 |
|
| 2616 |
this.emit( 'change', this.getItems() ); |
| 2617 |
return this; |
| 2618 |
}; |
| 2619 |
|
| 2620 |
|
| 2621 |
|
| 2622 |
|
| 2623 |
|
| 2624 |
|
| 2625 |
|
| 2626 |
|
| 2627 |
|
| 2628 |
|
| 2629 |
|
| 2630 |
|
| 2631 |
|
| 2632 |
|
| 2633 |
|
| 2634 |
OO.ui.mixin.GroupElement.prototype.moveItem = function ( items, newIndex ) { |
| 2635 |
|
| 2636 |
this.insertItemElements( items, newIndex ); |
| 2637 |
|
| 2638 |
|
| 2639 |
newIndex = OO.EmitterList.prototype.moveItem.call( this, items, newIndex ); |
| 2640 |
|
| 2641 |
return newIndex; |
| 2642 |
}; |
| 2643 |
|
| 2644 |
|
| 2645 |
|
| 2646 |
|
| 2647 |
|
| 2648 |
|
| 2649 |
|
| 2650 |
|
| 2651 |
|
| 2652 |
|
| 2653 |
|
| 2654 |
|
| 2655 |
|
| 2656 |
|
| 2657 |
|
| 2658 |
|
| 2659 |
|
| 2660 |
|
| 2661 |
|
| 2662 |
|
| 2663 |
|
| 2664 |
|
| 2665 |
|
| 2666 |
|
| 2667 |
|
| 2668 |
|
| 2669 |
OO.ui.mixin.GroupElement.prototype.insertItem = function ( item, index ) { |
| 2670 |
item.setElementGroup( this ); |
| 2671 |
this.insertItemElements( item, index ); |
| 2672 |
|
| 2673 |
|
| 2674 |
index = OO.EmitterList.prototype.insertItem.call( this, item, index ); |
| 2675 |
|
| 2676 |
return index; |
| 2677 |
}; |
| 2678 |
|
| 2679 |
|
| 2680 |
|
| 2681 |
|
| 2682 |
|
| 2683 |
|
| 2684 |
|
| 2685 |
|
| 2686 |
OO.ui.mixin.GroupElement.prototype.insertItemElements = function ( item, index ) { |
| 2687 |
if ( index === undefined || index < 0 || index >= this.items.length ) { |
| 2688 |
this.$group.append( item.$element ); |
| 2689 |
} else if ( index === 0 ) { |
| 2690 |
this.$group.prepend( item.$element ); |
| 2691 |
} else { |
| 2692 |
this.items[ index ].$element.before( item.$element ); |
| 2693 |
} |
| 2694 |
}; |
| 2695 |
|
| 2696 |
|
| 2697 |
|
| 2698 |
|
| 2699 |
|
| 2700 |
|
| 2701 |
|
| 2702 |
|
| 2703 |
|
| 2704 |
|
| 2705 |
|
| 2706 |
OO.ui.mixin.GroupElement.prototype.removeItems = function ( items ) { |
| 2707 |
if ( items.length === 0 ) { |
| 2708 |
return this; |
| 2709 |
} |
| 2710 |
|
| 2711 |
|
| 2712 |
for ( let i = 0, len = items.length; i < len; i++ ) { |
| 2713 |
const item = items[ i ]; |
| 2714 |
const index = this.items.indexOf( item ); |
| 2715 |
if ( index !== -1 ) { |
| 2716 |
item.setElementGroup( null ); |
| 2717 |
item.$element.detach(); |
| 2718 |
} |
| 2719 |
} |
| 2720 |
|
| 2721 |
|
| 2722 |
OO.EmitterList.prototype.removeItems.call( this, items ); |
| 2723 |
|
| 2724 |
this.emit( 'change', this.getItems() ); |
| 2725 |
return this; |
| 2726 |
}; |
| 2727 |
|
| 2728 |
|
| 2729 |
|
| 2730 |
|
| 2731 |
|
| 2732 |
|
| 2733 |
|
| 2734 |
|
| 2735 |
|
| 2736 |
|
| 2737 |
OO.ui.mixin.GroupElement.prototype.clearItems = function () { |
| 2738 |
|
| 2739 |
for ( let i = 0, len = this.items.length; i < len; i++ ) { |
| 2740 |
this.items[ i ].setElementGroup( null ); |
| 2741 |
this.items[ i ].$element.detach(); |
| 2742 |
} |
| 2743 |
|
| 2744 |
|
| 2745 |
OO.EmitterList.prototype.clearItems.call( this ); |
| 2746 |
|
| 2747 |
this.emit( 'change', this.getItems() ); |
| 2748 |
return this; |
| 2749 |
}; |
| 2750 |
|
| 2751 |
|
| 2752 |
|
| 2753 |
|
| 2754 |
|
| 2755 |
|
| 2756 |
|
| 2757 |
|
| 2758 |
|
| 2759 |
|
| 2760 |
|
| 2761 |
|
| 2762 |
|
| 2763 |
|
| 2764 |
|
| 2765 |
|
| 2766 |
|
| 2767 |
|
| 2768 |
|
| 2769 |
|
| 2770 |
|
| 2771 |
|
| 2772 |
OO.ui.mixin.LabelElement = function OoUiMixinLabelElement( config ) { |
| 2773 |
|
| 2774 |
config = config || {}; |
| 2775 |
|
| 2776 |
|
| 2777 |
this.$label = null; |
| 2778 |
this.label = null; |
| 2779 |
this.invisibleLabel = false; |
| 2780 |
|
| 2781 |
|
| 2782 |
this.setLabel( config.label || this.constructor.static.label ); |
| 2783 |
this.setLabelElement( config.$label || $( '<span>' ) ); |
| 2784 |
this.setInvisibleLabel( config.invisibleLabel ); |
| 2785 |
}; |
| 2786 |
|
| 2787 |
|
| 2788 |
|
| 2789 |
OO.initClass( OO.ui.mixin.LabelElement ); |
| 2790 |
|
| 2791 |
|
| 2792 |
|
| 2793 |
|
| 2794 |
|
| 2795 |
|
| 2796 |
|
| 2797 |
|
| 2798 |
|
| 2799 |
|
| 2800 |
|
| 2801 |
|
| 2802 |
|
| 2803 |
|
| 2804 |
|
| 2805 |
|
| 2806 |
|
| 2807 |
OO.ui.mixin.LabelElement.static.label = null; |
| 2808 |
|
| 2809 |
|
| 2810 |
|
| 2811 |
|
| 2812 |
|
| 2813 |
|
| 2814 |
|
| 2815 |
|
| 2816 |
|
| 2817 |
|
| 2818 |
|
| 2819 |
|
| 2820 |
|
| 2821 |
OO.ui.mixin.LabelElement.static.highlightQuery = function ( text, query, compare, combineMarks ) { |
| 2822 |
let offset = -1, |
| 2823 |
comboLength = 0, |
| 2824 |
comboMarks = '', |
| 2825 |
comboRegex, |
| 2826 |
comboMatch; |
| 2827 |
|
| 2828 |
const $result = $( '<span>' ); |
| 2829 |
|
| 2830 |
if ( compare ) { |
| 2831 |
const tLen = text.length; |
| 2832 |
const qLen = query.length; |
| 2833 |
for ( let i = 0; offset === -1 && i <= tLen - qLen; i++ ) { |
| 2834 |
if ( compare( query, text.slice( i, i + qLen ) ) === 0 ) { |
| 2835 |
offset = i; |
| 2836 |
} |
| 2837 |
} |
| 2838 |
} else { |
| 2839 |
offset = text.toLowerCase().indexOf( query.toLowerCase() ); |
| 2840 |
} |
| 2841 |
|
| 2842 |
if ( !query.length || offset === -1 ) { |
| 2843 |
$result.text( text ); |
| 2844 |
} else { |
| 2845 |
|
| 2846 |
if ( combineMarks ) { |
| 2847 |
|
| 2848 |
comboMarks = '[\u0300-\u036F\u0483-\u0489\u0591-\u05BD\u05BF\u05C1\u05C2\u05C4\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7\u06E8\u06EA-\u06ED\u0711\u0730-\u074A\u07A6-\u07B0\u07EB-\u07F3\u07FD\u0816-\u0819\u081B-\u0823\u0825-\u0827\u0829-\u082D\u0859-\u085B\u08D3-\u08E1\u08E3-\u0903\u093A-\u093C\u093E-\u094F\u0951-\u0957\u0962\u0963\u0981-\u0983\u09BC\u09BE-\u09C4\u09C7\u09C8\u09CB-\u09CD\u09D7\u09E2\u09E3\u09FE\u0A01-\u0A03\u0A3C\u0A3E-\u0A42\u0A47\u0A48\u0A4B-\u0A4D\u0A51\u0A70\u0A71\u0A75\u0A81-\u0A83\u0ABC\u0ABE-\u0AC5\u0AC7-\u0AC9\u0ACB-\u0ACD\u0AE2\u0AE3\u0AFA-\u0AFF\u0B01-\u0B03\u0B3C\u0B3E-\u0B44\u0B47\u0B48\u0B4B-\u0B4D\u0B56\u0B57\u0B62\u0B63\u0B82\u0BBE-\u0BC2\u0BC6-\u0BC8\u0BCA-\u0BCD\u0BD7\u0C00-\u0C04\u0C3E-\u0C44\u0C46-\u0C48\u0C4A-\u0C4D\u0C55\u0C56\u0C62\u0C63\u0C81-\u0C83\u0CBC\u0CBE-\u0CC4\u0CC6-\u0CC8\u0CCA-\u0CCD\u0CD5\u0CD6\u0CE2\u0CE3\u0D00-\u0D03\u0D3B\u0D3C\u0D3E-\u0D44\u0D46-\u0D48\u0D4A-\u0D4D\u0D57\u0D62\u0D63\u0D82\u0D83\u0DCA\u0DCF-\u0DD4\u0DD6\u0DD8-\u0DDF\u0DF2\u0DF3\u0E31\u0E34-\u0E3A\u0E47-\u0E4E\u0EB1\u0EB4-\u0EB9\u0EBB\u0EBC\u0EC8-\u0ECD\u0F18\u0F19\u0F35\u0F37\u0F39\u0F3E\u0F3F\u0F71-\u0F84\u0F86\u0F87\u0F8D-\u0F97\u0F99-\u0FBC\u0FC6\u102B-\u103E\u1056-\u1059\u105E-\u1060\u1062-\u1064\u1067-\u106D\u1071-\u1074\u1082-\u108D\u108F\u109A-\u109D\u135D-\u135F\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17B4-\u17D3\u17DD\u180B-\u180D\u1885\u1886\u18A9\u1920-\u192B\u1930-\u193B\u1A17-\u1A1B\u1A55-\u1A5E\u1A60-\u1A7C\u1A7F\u1AB0-\u1ABE\u1B00-\u1B04\u1B34-\u1B44\u1B6B-\u1B73\u1B80-\u1B82\u1BA1-\u1BAD\u1BE6-\u1BF3\u1C24-\u1C37\u1CD0-\u1CD2\u1CD4-\u1CE8\u1CED\u1CF2-\u1CF4\u1CF7-\u1CF9\u1DC0-\u1DF9\u1DFB-\u1DFF\u20D0-\u20F0\u2CEF-\u2CF1\u2D7F\u2DE0-\u2DFF\u302A-\u302F\u3099\u309A\uA66F-\uA672\uA674-\uA67D\uA69E\uA69F\uA6F0\uA6F1\uA802\uA806\uA80B\uA823-\uA827\uA880\uA881\uA8B4-\uA8C5\uA8E0-\uA8F1\uA8FF\uA926-\uA92D\uA947-\uA953\uA980-\uA983\uA9B3-\uA9C0\uA9E5\uAA29-\uAA36\uAA43\uAA4C\uAA4D\uAA7B-\uAA7D\uAAB0\uAAB2-\uAAB4\uAAB7\uAAB8\uAABE\uAABF\uAAC1\uAAEB-\uAAEF\uAAF5\uAAF6\uABE3-\uABEA\uABEC\uABED\uFB1E\uFE00-\uFE0F\uFE20-\uFE2F]'; |
| 2849 |
|
| 2850 |
comboRegex = new RegExp( '(^)' + comboMarks + '*' ); |
| 2851 |
comboMatch = text.slice( offset + query.length ).match( comboRegex ); |
| 2852 |
|
| 2853 |
if ( comboMatch && comboMatch.length ) { |
| 2854 |
comboLength = comboMatch[ 0 ].length; |
| 2855 |
} |
| 2856 |
} |
| 2857 |
|
| 2858 |
$result.append( |
| 2859 |
document.createTextNode( text.slice( 0, offset ) ), |
| 2860 |
$( '<span>' ) |
| 2861 |
.addClass( 'oo-ui-labelElement-label-highlight' ) |
| 2862 |
.text( text.slice( offset, offset + query.length + comboLength ) ), |
| 2863 |
document.createTextNode( text.slice( offset + query.length + comboLength ) ) |
| 2864 |
); |
| 2865 |
} |
| 2866 |
return $result.contents(); |
| 2867 |
}; |
| 2868 |
|
| 2869 |
|
| 2870 |
|
| 2871 |
|
| 2872 |
|
| 2873 |
l" |
| 2874 |
|
| 2875 |
|
| 2876 |
|
| 2877 |
|
| 2878 |
|
| 2879 |
|
| 2880 |
|
| 2881 |
|
| 2882 |
OO.ui.mixin.LabelElement.prototype.setLabelElement = function ( $label ) { |
| 2883 |
if ( this.$label ) { |
| 2884 |
this.$label.removeClass( 'oo-ui-labelElement-label' ).empty(); |
| 2885 |
} |
| 2886 |
|
| 2887 |
this.$label = $label.addClass( 'oo-ui-labelElement-label' ); |
| 2888 |
this.setLabelContent( this.label ); |
| 2889 |
return this; |
| 2890 |
}; |
| 2891 |
|
| 2892 |
|
| 2893 |
|
| 2894 |
|
| 2895 |
|
| 2896 |
|
| 2897 |
|
| 2898 |
|
| 2899 |
OO.ui.mixin.LabelElement.prototype.setLabelId = function ( id ) { |
| 2900 |
this.$label.attr( 'id', id ); |
| 2901 |
return this; |
| 2902 |
}; |
| 2903 |
|
| 2904 |
|
| 2905 |
|
| 2906 |
|
| 2907 |
|
| 2908 |
|
| 2909 |
|
| 2910 |
|
| 2911 |
|
| 2912 |
|
| 2913 |
|
| 2914 |
|
| 2915 |
|
| 2916 |
|
| 2917 |
|
| 2918 |
|
| 2919 |
OO.ui.mixin.LabelElement.prototype.setLabel = function ( label ) { |
| 2920 |
label = OO.ui.resolveMsg( label ); |
| 2921 |
label = ( ( typeof label === 'string' || label instanceof $ ) && label.length ) || ( label instanceof OO.ui.HtmlSnippet && label.toString().length ) ? label : null; |
| 2922 |
|
| 2923 |
if ( this.label !== label ) { |
| 2924 |
if ( this.$label ) { |
| 2925 |
this.setLabelContent( label ); |
| 2926 |
} |
| 2927 |
this.label = label; |
| 2928 |
this.$element.toggleClass( 'oo-ui-labelElement', !!this.label && !this.invisibleLabel ); |
| 2929 |
this.emit( 'labelChange' ); |
| 2930 |
} |
| 2931 |
|
| 2932 |
return this; |
| 2933 |
}; |
| 2934 |
|
| 2935 |
|
| 2936 |
|
| 2937 |
|
| 2938 |
|
| 2939 |
|
| 2940 |
|
| 2941 |
|
| 2942 |
OO.ui.mixin.LabelElement.prototype.setInvisibleLabel = function ( invisibleLabel ) { |
| 2943 |
invisibleLabel = !!invisibleLabel; |
| 2944 |
|
| 2945 |
if ( this.invisibleLabel !== invisibleLabel ) { |
| 2946 |
this.invisibleLabel = invisibleLabel; |
| 2947 |
this.$label.toggleClass( 'oo-ui-labelElement-invisible', this.invisibleLabel ); |
| 2948 |
|
| 2949 |
this.$element.toggleClass( 'oo-ui-labelElement', !!this.label && !this.invisibleLabel ); |
| 2950 |
this.emit( 'labelChange' ); |
| 2951 |
} |
| 2952 |
|
| 2953 |
return this; |
| 2954 |
}; |
| 2955 |
|
| 2956 |
|
| 2957 |
|
| 2958 |
|
| 2959 |
|
| 2960 |
|
| 2961 |
|
| 2962 |
|
| 2963 |
|
| 2964 |
|
| 2965 |
|
| 2966 |
OO.ui.mixin.LabelElement.prototype.setHighlightedQuery = function ( |
| 2967 |
text, query, compare, combineMarks |
| 2968 |
) { |
| 2969 |
return this.setLabel( |
| 2970 |
this.constructor.static.highlightQuery( text, query, compare, combineMarks ) |
| 2971 |
); |
| 2972 |
}; |
| 2973 |
|
| 2974 |
|
| 2975 |
|
| 2976 |
|
| 2977 |
|
| 2978 |
|
| 2979 |
|
| 2980 |
OO.ui.mixin.LabelElement.prototype.getLabel = function () { |
| 2981 |
return this.label; |
| 2982 |
}; |
| 2983 |
|
| 2984 |
|
| 2985 |
|
| 2986 |
|
| 2987 |
|
| 2988 |
|
| 2989 |
|
| 2990 |
|
| 2991 |
|
| 2992 |
|
| 2993 |
|
| 2994 |
|
| 2995 |
OO.ui.mixin.LabelElement.prototype.setLabelContent = function ( label ) { |
| 2996 |
if ( typeof label === 'string' ) { |
| 2997 |
if ( label.match( /^\s*$/ ) ) { |
| 2998 |
|
| 2999 |
this.$label.html( ' ' ); |
| 3000 |
} else { |
| 3001 |
this.$label.text( label ); |
| 3002 |
} |
| 3003 |
} else if ( label instanceof OO.ui.HtmlSnippet ) { |
| 3004 |
this.$label.html( label.toString() ); |
| 3005 |
} else if ( label instanceof $ ) { |
| 3006 |
this.$label.empty().append( label ); |
| 3007 |
} else { |
| 3008 |
this.$label.empty(); |
| 3009 |
} |
| 3010 |
}; |
| 3011 |
|
| 3012 |
|
| 3013 |
|
| 3014 |
|
| 3015 |
|
| 3016 |
|
| 3017 |
|
| 3018 |
|
| 3019 |
|
| 3020 |
|
| 3021 |
|
| 3022 |
|
| 3023 |
|
| 3024 |
|
| 3025 |
|
| 3026 |
|
| 3027 |
|
| 3028 |
|
| 3029 |
|
| 3030 |
|
| 3031 |
|
| 3032 |
|
| 3033 |
|
| 3034 |
|
| 3035 |
|
| 3036 |
|
| 3037 |
’), or a |
| 3038 |
|
| 3039 |
|
| 3040 |
|
| 3041 |
|
| 3042 |
|
| 3043 |
|
| 3044 |
|
| 3045 |
|
| 3046 |
|
| 3047 |
|
| 3048 |
OO.ui.mixin.IconElement = function OoUiMixinIconElement( config ) { |
| 3049 |
|
| 3050 |
config = config || {}; |
| 3051 |
|
| 3052 |
|
| 3053 |
this.$icon = null; |
| 3054 |
this.icon = null; |
| 3055 |
|
| 3056 |
|
| 3057 |
this.setIcon( config.icon || this.constructor.static.icon ); |
| 3058 |
this.setIconElement( config.$icon || $( '<span>' ) ); |
| 3059 |
}; |
| 3060 |
|
| 3061 |
|
| 3062 |
|
| 3063 |
OO.initClass( OO.ui.mixin.IconElement ); |
| 3064 |
|
| 3065 |
|
| 3066 |
|
| 3067 |
|
| 3068 |
s. A map |
| 3069 |
|
| 3070 |
|
| 3071 |
|
| 3072 |
|
| 3073 |
|
| 3074 |
|
| 3075 |
|
| 3076 |
|
| 3077 |
|
| 3078 |
|
| 3079 |
|
| 3080 |
|
| 3081 |
OO.ui.mixin.IconElement.static.icon = null; |
| 3082 |
|
| 3083 |
|
| 3084 |
|
| 3085 |
|
| 3086 |
|
| 3087 |
|
| 3088 |
|
| 3089 |
|
| 3090 |
|
| 3091 |
|
| 3092 |
OO.ui.mixin.IconElement.static.iconTitle = null; |
| 3093 |
|
| 3094 |
|
| 3095 |
|
| 3096 |
|
| 3097 |
|
| 3098 |
|
| 3099 |
es |
| 3100 |
|
| 3101 |
|
| 3102 |
|
| 3103 |
|
| 3104 |
OO.ui.mixin.IconElement.prototype.setIconElement = function ( $icon ) { |
| 3105 |
if ( this.$icon ) { |
| 3106 |
this.$icon |
| 3107 |
.removeClass( 'oo-ui-iconElement-icon oo-ui-icon-' + this.icon ) |
| 3108 |
.removeAttr( 'title' ); |
| 3109 |
} |
| 3110 |
|
| 3111 |
this.$icon = $icon |
| 3112 |
.addClass( 'oo-ui-iconElement-icon' ) |
| 3113 |
.toggleClass( 'oo-ui-iconElement-noIcon', !this.icon ) |
| 3114 |
.toggleClass( 'oo-ui-icon-' + this.icon, !!this.icon ); |
| 3115 |
if ( this.iconTitle !== null ) { |
| 3116 |
this.$icon.attr( 'title', this.iconTitle ); |
| 3117 |
} |
| 3118 |
|
| 3119 |
this.updateThemeClasses(); |
| 3120 |
}; |
| 3121 |
|
| 3122 |
|
| 3123 |
an icon. |
| 3124 |
|
| 3125 |
|
| 3126 |
|
| 3127 |
|
| 3128 |
|
| 3129 |
|
| 3130 |
|
| 3131 |
|
| 3132 |
OO.ui.mixin.IconElement.prototype.setIcon = function ( icon ) { |
| 3133 |
if ( icon && typeof icon !== 'string' ) { |
| 3134 |
icon = OO.ui.getLocalValue( icon, null, 'default' ); |
| 3135 |
} |
| 3136 |
|
| 3137 |
if ( this.icon === icon ) { |
| 3138 |
return this; |
| 3139 |
} |
| 3140 |
|
| 3141 |
this.$element.toggleClass( 'oo-ui-iconElement', !!icon ); |
| 3142 |
if ( this.$icon ) { |
| 3143 |
if ( this.icon ) { |
| 3144 |
this.$icon.removeClass( 'oo-ui-icon-' + this.icon ); |
| 3145 |
} |
| 3146 |
if ( icon ) { |
| 3147 |
this.$icon.addClass( 'oo-ui-icon-' + icon ); |
| 3148 |
} |
| 3149 |
this.$icon.toggleClass( 'oo-ui-iconElement-noIcon', !icon ); |
| 3150 |
} |
| 3151 |
|
| 3152 |
this.icon = icon; |
| 3153 |
this.updateThemeClasses(); |
| 3154 |
|
| 3155 |
return this; |
| 3156 |
}; |
| 3157 |
|
| 3158 |
|
| 3159 |
|
| 3160 |
|
| 3161 |
|
| 3162 |
|
| 3163 |
OO.ui.mixin.IconElement.prototype.getIcon = function () { |
| 3164 |
return this.icon; |
| 3165 |
}; |
| 3166 |
|
| 3167 |
|
| 3168 |
|
| 3169 |
|
| 3170 |
|
| 3171 |
|
| 3172 |
|
| 3173 |
|
| 3174 |
|
| 3175 |
|
| 3176 |
|
| 3177 |
|
| 3178 |
|
| 3179 |
|
| 3180 |
|
| 3181 |
|
| 3182 |
|
| 3183 |
|
| 3184 |
|
| 3185 |
|
| 3186 |
|
| 3187 |
|
| 3188 |
|
| 3189 |
|
| 3190 |
|
| 3191 |
|
| 3192 |
own’). |
| 3193 |
|
| 3194 |
|
| 3195 |
|
| 3196 |
|
| 3197 |
OO.ui.mixin.IndicatorElement = function OoUiMixinIndicatorElement( config ) { |
| 3198 |
|
| 3199 |
config = config || {}; |
| 3200 |
|
| 3201 |
|
| 3202 |
this.$indicator = null; |
| 3203 |
this.indicator = null; |
| 3204 |
|
| 3205 |
|
| 3206 |
this.setIndicator( config.indicator || this.constructor.static.indicator ); |
| 3207 |
this.setIndicatorElement( config.$indicator || $( '<span>' ) ); |
| 3208 |
}; |
| 3209 |
|
| 3210 |
|
| 3211 |
|
| 3212 |
OO.initClass( OO.ui.mixin.IndicatorElement ); |
| 3213 |
|
| 3214 |
|
| 3215 |
|
| 3216 |
|
| 3217 |
own’). |
| 3218 |
|
| 3219 |
|
| 3220 |
|
| 3221 |
|
| 3222 |
|
| 3223 |
OO.ui.mixin.IndicatorElement.static.indicator = null; |
| 3224 |
|
| 3225 |
|
| 3226 |
|
| 3227 |
|
| 3228 |
|
| 3229 |
|
| 3230 |
|
| 3231 |
|
| 3232 |
|
| 3233 |
OO.ui.mixin.IndicatorElement.static.indicatorTitle = null; |
| 3234 |
|
| 3235 |
|
| 3236 |
|
| 3237 |
|
| 3238 |
|
| 3239 |
|
| 3240 |
|
| 3241 |
|
| 3242 |
|
| 3243 |
|
| 3244 |
OO.ui.mixin.IndicatorElement.prototype.setIndicatorElement = function ( $indicator ) { |
| 3245 |
if ( this.$indicator ) { |
| 3246 |
this.$indicator |
| 3247 |
.removeClass( 'oo-ui-indicatorElement-indicator oo-ui-indicator-' + this.indicator ) |
| 3248 |
.removeAttr( 'title' ); |
| 3249 |
} |
| 3250 |
|
| 3251 |
this.$indicator = $indicator |
| 3252 |
.addClass( 'oo-ui-indicatorElement-indicator' ) |
| 3253 |
.toggleClass( 'oo-ui-indicatorElement-noIndicator', !this.indicator ) |
| 3254 |
.toggleClass( 'oo-ui-indicator-' + this.indicator, !!this.indicator ); |
| 3255 |
if ( this.indicatorTitle !== null ) { |
| 3256 |
this.$indicator.attr( 'title', this.indicatorTitle ); |
| 3257 |
} |
| 3258 |
|
| 3259 |
this.updateThemeClasses(); |
| 3260 |
}; |
| 3261 |
|
| 3262 |
|
| 3263 |
‘up’, |
| 3264 |
dicator. |
| 3265 |
|
| 3266 |
|
| 3267 |
|
| 3268 |
|
| 3269 |
|
| 3270 |
OO.ui.mixin.IndicatorElement.prototype.setIndicator = function ( indicator ) { |
| 3271 |
indicator = typeof indicator === 'string' && indicator.length ? indicator.trim() : null; |
| 3272 |
|
| 3273 |
if ( this.indicator !== indicator ) { |
| 3274 |
if ( this.$indicator ) { |
| 3275 |
if ( this.indicator !== null ) { |
| 3276 |
this.$indicator.removeClass( 'oo-ui-indicator-' + this.indicator ); |
| 3277 |
} |
| 3278 |
if ( indicator !== null ) { |
| 3279 |
this.$indicator.addClass( 'oo-ui-indicator-' + indicator ); |
| 3280 |
} |
| 3281 |
} |
| 3282 |
this.indicator = indicator; |
| 3283 |
} |
| 3284 |
|
| 3285 |
this.$element.toggleClass( 'oo-ui-indicatorElement', !!this.indicator ); |
| 3286 |
if ( this.$indicator ) { |
| 3287 |
this.$indicator.toggleClass( 'oo-ui-indicatorElement-noIndicator', !this.indicator ); |
| 3288 |
} |
| 3289 |
this.updateThemeClasses(); |
| 3290 |
|
| 3291 |
return this; |
| 3292 |
}; |
| 3293 |
|
| 3294 |
|
| 3295 |
own’). |
| 3296 |
|
| 3297 |
|
| 3298 |
|
| 3299 |
OO.ui.mixin.IndicatorElement.prototype.getIndicator = function () { |
| 3300 |
return this.indicator; |
| 3301 |
}; |
| 3302 |
|
| 3303 |
|
| 3304 |
|
| 3305 |
|
| 3306 |
ags, |
| 3307 |
|
| 3308 |
|
| 3309 |
|
| 3310 |
|
| 3311 |
|
| 3312 |
|
| 3313 |
|
| 3314 |
|
| 3315 |
|
| 3316 |
|
| 3317 |
|
| 3318 |
|
| 3319 |
|
| 3320 |
|
| 3321 |
|
| 3322 |
|
| 3323 |
|
| 3324 |
|
| 3325 |
|
| 3326 |
|
| 3327 |
|
| 3328 |
|
| 3329 |
|
| 3330 |
|
| 3331 |
|
| 3332 |
|
| 3333 |
|
| 3334 |
|
| 3335 |
|
| 3336 |
|
| 3337 |
|
| 3338 |
|
| 3339 |
|
| 3340 |
|
| 3341 |
|
| 3342 |
|
| 3343 |
|
| 3344 |
|
| 3345 |
|
| 3346 |
|
| 3347 |
|
| 3348 |
|
| 3349 |
|
| 3350 |
OO.ui.mixin.FlaggedElement = function OoUiMixinFlaggedElement( config ) { |
| 3351 |
|
| 3352 |
config = config || {}; |
| 3353 |
|
| 3354 |
|
| 3355 |
this.flags = {}; |
| 3356 |
this.$flagged = null; |
| 3357 |
|
| 3358 |
|
| 3359 |
this.setFlags( config.flags || this.constructor.static.flags ); |
| 3360 |
this.setFlaggedElement( config.$flagged || this.$element ); |
| 3361 |
}; |
| 3362 |
|
| 3363 |
|
| 3364 |
|
| 3365 |
OO.initClass( OO.ui.mixin.FlaggedElement ); |
| 3366 |
|
| 3367 |
|
| 3368 |
|
| 3369 |
|
| 3370 |
|
| 3371 |
|
| 3372 |
|
| 3373 |
|
| 3374 |
|
| 3375 |
|
| 3376 |
|
| 3377 |
|
| 3378 |
|
| 3379 |
|
| 3380 |
|
| 3381 |
|
| 3382 |
|
| 3383 |
|
| 3384 |
|
| 3385 |
|
| 3386 |
|
| 3387 |
OO.ui.mixin.FlaggedElement.static.flags = null; |
| 3388 |
|
| 3389 |
|
| 3390 |
|
| 3391 |
|
| 3392 |
|
| 3393 |
|
| 3394 |
|
| 3395 |
|
| 3396 |
t. |
| 3397 |
|
| 3398 |
|
| 3399 |
|
| 3400 |
OO.ui.mixin.FlaggedElement.prototype.setFlaggedElement = function ( $flagged ) { |
| 3401 |
const classNames = Object.keys( this.flags ).map( ( flag ) => 'oo-ui-flaggedElement-' + flag ); |
| 3402 |
|
| 3403 |
if ( this.$flagged ) { |
| 3404 |
this.$flagged.removeClass( classNames ); |
| 3405 |
} |
| 3406 |
|
| 3407 |
this.$flagged = $flagged.addClass( classNames ); |
| 3408 |
}; |
| 3409 |
|
| 3410 |
|
| 3411 |
|
| 3412 |
|
| 3413 |
|
| 3414 |
|
| 3415 |
|
| 3416 |
OO.ui.mixin.FlaggedElement.prototype.hasFlag = function ( flag ) { |
| 3417 |
|
| 3418 |
return this.flags && ( flag in this.flags ); |
| 3419 |
}; |
| 3420 |
|
| 3421 |
|
| 3422 |
|
| 3423 |
|
| 3424 |
|
| 3425 |
|
| 3426 |
OO.ui.mixin.FlaggedElement.prototype.getFlags = function () { |
| 3427 |
|
| 3428 |
return Object.keys( this.flags || {} ); |
| 3429 |
}; |
| 3430 |
|
| 3431 |
|
| 3432 |
|
| 3433 |
|
| 3434 |
|
| 3435 |
|
| 3436 |
|
| 3437 |
|
| 3438 |
OO.ui.mixin.FlaggedElement.prototype.clearFlags = function () { |
| 3439 |
const changes = {}, |
| 3440 |
remove = [], |
| 3441 |
classPrefix = 'oo-ui-flaggedElement-'; |
| 3442 |
|
| 3443 |
for ( const flag in this.flags ) { |
| 3444 |
const className = classPrefix + flag; |
| 3445 |
changes[ flag ] = false; |
| 3446 |
delete this.flags[ flag ]; |
| 3447 |
remove.push( className ); |
| 3448 |
} |
| 3449 |
|
| 3450 |
if ( this.$flagged ) { |
| 3451 |
this.$flagged.removeClass( remove ); |
| 3452 |
} |
| 3453 |
|
| 3454 |
this.updateThemeClasses(); |
| 3455 |
this.emit( 'flag', changes ); |
| 3456 |
|
| 3457 |
return this; |
| 3458 |
}; |
| 3459 |
|
| 3460 |
|
| 3461 |
|
| 3462 |
|
| 3463 |
|
| 3464 |
|
| 3465 |
|
| 3466 |
|
| 3467 |
|
| 3468 |
|
| 3469 |
|
| 3470 |
OO.ui.mixin.FlaggedElement.prototype.setFlags = function ( flags ) { |
| 3471 |
const changes = {}, |
| 3472 |
add = [], |
| 3473 |
remove = [], |
| 3474 |
classPrefix = 'oo-ui-flaggedElement-'; |
| 3475 |
|
| 3476 |
let className, flag; |
| 3477 |
if ( typeof flags === 'string' ) { |
| 3478 |
className = classPrefix + flags; |
| 3479 |
|
| 3480 |
if ( !this.flags[ flags ] ) { |
| 3481 |
this.flags[ flags ] = true; |
| 3482 |
add.push( className ); |
| 3483 |
} |
| 3484 |
} else if ( Array.isArray( flags ) ) { |
| 3485 |
for ( let i = 0, len = flags.length; i < len; i++ ) { |
| 3486 |
flag = flags[ i ]; |
| 3487 |
className = classPrefix + flag; |
| 3488 |
|
| 3489 |
if ( !this.flags[ flag ] ) { |
| 3490 |
changes[ flag ] = true; |
| 3491 |
this.flags[ flag ] = true; |
| 3492 |
add.push( className ); |
| 3493 |
} |
| 3494 |
} |
| 3495 |
} else if ( OO.isPlainObject( flags ) ) { |
| 3496 |
for ( flag in flags ) { |
| 3497 |
className = classPrefix + flag; |
| 3498 |
if ( flags[ flag ] ) { |
| 3499 |
|
| 3500 |
if ( !this.flags[ flag ] ) { |
| 3501 |
changes[ flag ] = true; |
| 3502 |
this.flags[ flag ] = true; |
| 3503 |
add.push( className ); |
| 3504 |
} |
| 3505 |
} else { |
| 3506 |
|
| 3507 |
if ( this.flags[ flag ] ) { |
| 3508 |
changes[ flag ] = false; |
| 3509 |
delete this.flags[ flag ]; |
| 3510 |
remove.push( className ); |
| 3511 |
} |
| 3512 |
} |
| 3513 |
} |
| 3514 |
} |
| 3515 |
|
| 3516 |
if ( this.$flagged ) { |
| 3517 |
this.$flagged |
| 3518 |
.addClass( add ) |
| 3519 |
.removeClass( remove ); |
| 3520 |
} |
| 3521 |
|
| 3522 |
this.updateThemeClasses(); |
| 3523 |
this.emit( 'flag', changes ); |
| 3524 |
|
| 3525 |
return this; |
| 3526 |
}; |
| 3527 |
|
| 3528 |
|
| 3529 |
|
| 3530 |
|
| 3531 |
|
| 3532 |
|
| 3533 |
|
| 3534 |
|
| 3535 |
|
| 3536 |
|
| 3537 |
|
| 3538 |
|
| 3539 |
|
| 3540 |
|
| 3541 |
|
| 3542 |
|
| 3543 |
|
| 3544 |
|
| 3545 |
|
| 3546 |
|
| 3547 |
|
| 3548 |
|
| 3549 |
|
| 3550 |
|
| 3551 |
|
| 3552 |
|
| 3553 |
|
| 3554 |
|
| 3555 |
OO.ui.mixin.TitledElement = function OoUiMixinTitledElement( config ) { |
| 3556 |
|
| 3557 |
config = config || {}; |
| 3558 |
|
| 3559 |
|
| 3560 |
this.$titled = null; |
| 3561 |
this.title = null; |
| 3562 |
|
| 3563 |
|
| 3564 |
let title = config.title !== undefined ? config.title : this.constructor.static.title; |
| 3565 |
if ( |
| 3566 |
title === null && |
| 3567 |
config.invisibleLabel && |
| 3568 |
typeof config.label === 'string' |
| 3569 |
) { |
| 3570 |
|
| 3571 |
title = config.label; |
| 3572 |
} |
| 3573 |
this.setTitle( title ); |
| 3574 |
this.setTitledElement( config.$titled || this.$element ); |
| 3575 |
}; |
| 3576 |
|
| 3577 |
|
| 3578 |
|
| 3579 |
OO.initClass( OO.ui.mixin.TitledElement ); |
| 3580 |
|
| 3581 |
|
| 3582 |
|
| 3583 |
|
| 3584 |
|
| 3585 |
|
| 3586 |
|
| 3587 |
|
| 3588 |
|
| 3589 |
|
| 3590 |
|
| 3591 |
|
| 3592 |
|
| 3593 |
OO.ui.mixin.TitledElement.static.title = null; |
| 3594 |
|
| 3595 |
|
| 3596 |
|
| 3597 |
|
| 3598 |
|
| 3599 |
|
| 3600 |
|
| 3601 |
|
| 3602 |
ew |
| 3603 |
|
| 3604 |
|
| 3605 |
|
| 3606 |
|
| 3607 |
OO.ui.mixin.TitledElement.prototype.setTitledElement = function ( $titled ) { |
| 3608 |
if ( this.$titled ) { |
| 3609 |
this.$titled.removeAttr( 'title' ); |
| 3610 |
} |
| 3611 |
|
| 3612 |
this.$titled = $titled; |
| 3613 |
this.updateTitle(); |
| 3614 |
}; |
| 3615 |
|
| 3616 |
|
| 3617 |
|
| 3618 |
|
| 3619 |
|
| 3620 |
|
| 3621 |
|
| 3622 |
|
| 3623 |
|
| 3624 |
OO.ui.mixin.TitledElement.prototype.setTitle = function ( title ) { |
| 3625 |
title = OO.ui.resolveMsg( title ); |
| 3626 |
title = typeof title === 'string' ? title : null; |
| 3627 |
|
| 3628 |
if ( this.title !== title ) { |
| 3629 |
this.title = title; |
| 3630 |
this.updateTitle(); |
| 3631 |
} |
| 3632 |
|
| 3633 |
return this; |
| 3634 |
}; |
| 3635 |
|
| 3636 |
|
| 3637 |
|
| 3638 |
|
| 3639 |
|
| 3640 |
|
| 3641 |
|
| 3642 |
|
| 3643 |
OO.ui.mixin.TitledElement.prototype.updateTitle = function () { |
| 3644 |
let title = this.getTitle(); |
| 3645 |
if ( this.$titled ) { |
| 3646 |
if ( title !== null ) { |
| 3647 |
|
| 3648 |
if ( this.formatTitleWithAccessKey ) { |
| 3649 |
title = this.formatTitleWithAccessKey( title ); |
| 3650 |
} |
| 3651 |
this.$titled.attr( 'title', title ); |
| 3652 |
} else { |
| 3653 |
this.$titled.removeAttr( 'title' ); |
| 3654 |
} |
| 3655 |
} |
| 3656 |
return this; |
| 3657 |
}; |
| 3658 |
|
| 3659 |
|
| 3660 |
|
| 3661 |
|
| 3662 |
|
| 3663 |
|
| 3664 |
OO.ui.mixin.TitledElement.prototype.getTitle = function () { |
| 3665 |
return this.title; |
| 3666 |
}; |
| 3667 |
|
| 3668 |
|
| 3669 |
|
| 3670 |
|
| 3671 |
|
| 3672 |
|
| 3673 |
|
| 3674 |
|
| 3675 |
|
| 3676 |
|
| 3677 |
|
| 3678 |
|
| 3679 |
|
| 3680 |
|
| 3681 |
|
| 3682 |
|
| 3683 |
|
| 3684 |
|
| 3685 |
|
| 3686 |
|
| 3687 |
|
| 3688 |
|
| 3689 |
|
| 3690 |
|
| 3691 |
|
| 3692 |
|
| 3693 |
|
| 3694 |
OO.ui.mixin.AccessKeyedElement = function OoUiMixinAccessKeyedElement( config ) { |
| 3695 |
|
| 3696 |
config = config || {}; |
| 3697 |
|
| 3698 |
|
| 3699 |
this.$accessKeyed = null; |
| 3700 |
this.accessKey = null; |
| 3701 |
|
| 3702 |
|
| 3703 |
this.setAccessKey( config.accessKey || null ); |
| 3704 |
this.setAccessKeyedElement( config.$accessKeyed || this.$element ); |
| 3705 |
|
| 3706 |
|
| 3707 |
|
| 3708 |
if ( this.updateTitle ) { |
| 3709 |
this.updateTitle(); |
| 3710 |
} |
| 3711 |
}; |
| 3712 |
|
| 3713 |
|
| 3714 |
|
| 3715 |
OO.initClass( OO.ui.mixin.AccessKeyedElement ); |
| 3716 |
|
| 3717 |
|
| 3718 |
|
| 3719 |
|
| 3720 |
|
| 3721 |
|
| 3722 |
|
| 3723 |
|
| 3724 |
|
| 3725 |
OO.ui.mixin.AccessKeyedElement.static.accessKey = null; |
| 3726 |
|
| 3727 |
|
| 3728 |
|
| 3729 |
|
| 3730 |
|
| 3731 |
|
| 3732 |
|
| 3733 |
|
| 3734 |
|
| 3735 |
|
| 3736 |
|
| 3737 |
|
| 3738 |
|
| 3739 |
OO.ui.mixin.AccessKeyedElement.prototype.setAccessKeyedElement = function ( $accessKeyed ) { |
| 3740 |
if ( this.$accessKeyed ) { |
| 3741 |
this.$accessKeyed.removeAttr( 'accesskey' ); |
| 3742 |
} |
| 3743 |
|
| 3744 |
this.$accessKeyed = $accessKeyed; |
| 3745 |
if ( this.accessKey ) { |
| 3746 |
this.$accessKeyed.attr( 'accesskey', this.accessKey ); |
| 3747 |
} |
| 3748 |
}; |
| 3749 |
|
| 3750 |
|
| 3751 |
|
| 3752 |
|
| 3753 |
|
| 3754 |
|
| 3755 |
|
| 3756 |
|
| 3757 |
|
| 3758 |
OO.ui.mixin.AccessKeyedElement.prototype.setAccessKey = function ( accessKey ) { |
| 3759 |
accessKey = OO.ui.resolveMsg( accessKey ); |
| 3760 |
accessKey = typeof accessKey === 'string' ? accessKey : null; |
| 3761 |
|
| 3762 |
if ( this.accessKey !== accessKey ) { |
| 3763 |
if ( this.$accessKeyed ) { |
| 3764 |
if ( accessKey !== null ) { |
| 3765 |
this.$accessKeyed.attr( 'accesskey', accessKey ); |
| 3766 |
} else { |
| 3767 |
this.$accessKeyed.removeAttr( 'accesskey' ); |
| 3768 |
} |
| 3769 |
} |
| 3770 |
this.accessKey = accessKey; |
| 3771 |
|
| 3772 |
|
| 3773 |
if ( this.updateTitle ) { |
| 3774 |
this.updateTitle(); |
| 3775 |
} |
| 3776 |
} |
| 3777 |
|
| 3778 |
return this; |
| 3779 |
}; |
| 3780 |
|
| 3781 |
|
| 3782 |
|
| 3783 |
|
| 3784 |
|
| 3785 |
|
| 3786 |
OO.ui.mixin.AccessKeyedElement.prototype.getAccessKey = function () { |
| 3787 |
return this.accessKey; |
| 3788 |
}; |
| 3789 |
|
| 3790 |
|
| 3791 |
|
| 3792 |
|
| 3793 |
|
| 3794 |
|
| 3795 |
|
| 3796 |
|
| 3797 |
OO.ui.mixin.AccessKeyedElement.prototype.formatTitleWithAccessKey = function ( title ) { |
| 3798 |
if ( !this.$accessKeyed ) { |
| 3799 |
|
| 3800 |
|
| 3801 |
return title; |
| 3802 |
} |
| 3803 |
|
| 3804 |
|
| 3805 |
let accessKey; |
| 3806 |
if ( $.fn.updateTooltipAccessKeys && $.fn.updateTooltipAccessKeys.getAccessKeyLabel ) { |
| 3807 |
accessKey = $.fn.updateTooltipAccessKeys.getAccessKeyLabel( this.$accessKeyed[ 0 ] ); |
| 3808 |
} else { |
| 3809 |
accessKey = this.getAccessKey(); |
| 3810 |
} |
| 3811 |
if ( accessKey ) { |
| 3812 |
title += ' [' + accessKey + ']'; |
| 3813 |
} |
| 3814 |
return title; |
| 3815 |
}; |
| 3816 |
|
| 3817 |
|
| 3818 |
|
| 3819 |
|
| 3820 |
|
| 3821 |
|
| 3822 |
|
| 3823 |
|
| 3824 |
|
| 3825 |
|
| 3826 |
|
| 3827 |
|
| 3828 |
|
| 3829 |
|
| 3830 |
|
| 3831 |
|
| 3832 |
|
| 3833 |
OO.ui.mixin.RequiredElement = function OoUiMixinRequiredElement( config ) { |
| 3834 |
|
| 3835 |
config = config || {}; |
| 3836 |
|
| 3837 |
|
| 3838 |
this.$required = config.$required || this.$input || this.$element; |
| 3839 |
this.required = false; |
| 3840 |
this.indicatorElement = config.indicatorElement !== undefined ? config.indicatorElement : this; |
| 3841 |
if ( this.indicatorElement && !this.indicatorElement.getIndicator ) { |
| 3842 |
throw new Error( 'config.indicatorElement must mixin OO.ui.mixin.IndicatorElement.' ); |
| 3843 |
} |
| 3844 |
|
| 3845 |
|
| 3846 |
this.setRequired( !!config.required ); |
| 3847 |
}; |
| 3848 |
|
| 3849 |
|
| 3850 |
|
| 3851 |
OO.initClass( OO.ui.mixin.RequiredElement ); |
| 3852 |
|
| 3853 |
|
| 3854 |
|
| 3855 |
|
| 3856 |
|
| 3857 |
|
| 3858 |
|
| 3859 |
|
| 3860 |
ew |
| 3861 |
|
| 3862 |
|
| 3863 |
|
| 3864 |
|
| 3865 |
OO.ui.mixin.RequiredElement.prototype.setRequiredElement = function ( $required ) { |
| 3866 |
if ( this.$required === $required ) { |
| 3867 |
return; |
| 3868 |
} |
| 3869 |
|
| 3870 |
if ( this.$required && this.required ) { |
| 3871 |
this.updateRequiredElement( false ); |
| 3872 |
} |
| 3873 |
|
| 3874 |
this.$required = $required; |
| 3875 |
this.updateRequiredElement(); |
| 3876 |
}; |
| 3877 |
|
| 3878 |
|
| 3879 |
|
| 3880 |
|
| 3881 |
|
| 3882 |
OO.ui.mixin.RequiredElement.prototype.updateRequiredElement = function ( state ) { |
| 3883 |
if ( state === undefined ) { |
| 3884 |
state = this.required; |
| 3885 |
} |
| 3886 |
|
| 3887 |
this.$required |
| 3888 |
.prop( 'required', state ); |
| 3889 |
}; |
| 3890 |
|
| 3891 |
|
| 3892 |
|
| 3893 |
|
| 3894 |
|
| 3895 |
|
| 3896 |
OO.ui.mixin.RequiredElement.prototype.isRequired = function () { |
| 3897 |
return this.required; |
| 3898 |
}; |
| 3899 |
|
| 3900 |
|
| 3901 |
|
| 3902 |
|
| 3903 |
|
| 3904 |
|
| 3905 |
|
| 3906 |
|
| 3907 |
OO.ui.mixin.RequiredElement.prototype.setRequired = function ( state ) { |
| 3908 |
if ( this.required === state ) { |
| 3909 |
return this; |
| 3910 |
} |
| 3911 |
|
| 3912 |
this.required = !!state; |
| 3913 |
this.updateRequiredElement(); |
| 3914 |
if ( this.indicatorElement ) { |
| 3915 |
|
| 3916 |
const expected = state ? null : 'required'; |
| 3917 |
if ( this.indicatorElement.getIndicator() === expected ) { |
| 3918 |
this.indicatorElement.setIndicator( state ? 'required' : null ); |
| 3919 |
} |
| 3920 |
} |
| 3921 |
return this; |
| 3922 |
}; |
| 3923 |
|
| 3924 |
|
| 3925 |
|
| 3926 |
ns |
| 3927 |
|
| 3928 |
|
| 3929 |
|
| 3930 |
|
| 3931 |
|
| 3932 |
|
| 3933 |
|
| 3934 |
|
| 3935 |
|
| 3936 |
|
| 3937 |
|
| 3938 |
|
| 3939 |
|
| 3940 |
|
| 3941 |
|
| 3942 |
|
| 3943 |
|
| 3944 |
|
| 3945 |
|
| 3946 |
|
| 3947 |
|
| 3948 |
|
| 3949 |
|
| 3950 |
|
| 3951 |
|
| 3952 |
|
| 3953 |
|
| 3954 |
|
| 3955 |
|
| 3956 |
|
| 3957 |
|
| 3958 |
|
| 3959 |
|
| 3960 |
|
| 3961 |
|
| 3962 |
OO.ui.ButtonWidget = function OoUiButtonWidget( config ) { |
| 3963 |
|
| 3964 |
config = config || {}; |
| 3965 |
|
| 3966 |
|
| 3967 |
OO.ui.ButtonWidget.super.call( this, config ); |
| 3968 |
|
| 3969 |
|
| 3970 |
OO.ui.mixin.ButtonElement.call( this, config ); |
| 3971 |
OO.ui.mixin.IconElement.call( this, config ); |
| 3972 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 3973 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 3974 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { |
| 3975 |
$titled: this.$button |
| 3976 |
}, config ) ); |
| 3977 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 3978 |
OO.ui.mixin.TabIndexedElement.call( this, Object.assign( { |
| 3979 |
$tabIndexed: this.$button |
| 3980 |
}, config ) ); |
| 3981 |
OO.ui.mixin.AccessKeyedElement.call( this, Object.assign( { |
| 3982 |
$accessKeyed: this.$button |
| 3983 |
}, config ) ); |
| 3984 |
|
| 3985 |
|
| 3986 |
this.href = null; |
| 3987 |
this.target = null; |
| 3988 |
this.noFollow = false; |
| 3989 |
this.rel = []; |
| 3990 |
|
| 3991 |
|
| 3992 |
this.connect( this, { |
| 3993 |
disable: 'onDisable' |
| 3994 |
} ); |
| 3995 |
|
| 3996 |
|
| 3997 |
this.$button.append( this.$icon, this.$label, this.$indicator ); |
| 3998 |
this.$element |
| 3999 |
.addClass( 'oo-ui-buttonWidget' ) |
| 4000 |
.append( this.$button ); |
| 4001 |
this.setActive( config.active ); |
| 4002 |
this.setHref( config.href ); |
| 4003 |
this.setTarget( config.target ); |
| 4004 |
if ( config.rel !== undefined ) { |
| 4005 |
this.setRel( config.rel ); |
| 4006 |
} else { |
| 4007 |
this.setNoFollow( config.noFollow ); |
| 4008 |
} |
| 4009 |
}; |
| 4010 |
|
| 4011 |
|
| 4012 |
|
| 4013 |
OO.inheritClass( OO.ui.ButtonWidget, OO.ui.Widget ); |
| 4014 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.ButtonElement ); |
| 4015 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.IconElement ); |
| 4016 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.IndicatorElement ); |
| 4017 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.LabelElement ); |
| 4018 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.TitledElement ); |
| 4019 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.FlaggedElement ); |
| 4020 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.TabIndexedElement ); |
| 4021 |
OO.mixinClass( OO.ui.ButtonWidget, OO.ui.mixin.AccessKeyedElement ); |
| 4022 |
|
| 4023 |
|
| 4024 |
|
| 4025 |
|
| 4026 |
|
| 4027 |
|
| 4028 |
|
| 4029 |
OO.ui.ButtonWidget.static.cancelButtonMouseDownEvents = false; |
| 4030 |
|
| 4031 |
|
| 4032 |
|
| 4033 |
|
| 4034 |
|
| 4035 |
OO.ui.ButtonWidget.static.tagName = 'span'; |
| 4036 |
|
| 4037 |
|
| 4038 |
|
| 4039 |
|
| 4040 |
|
| 4041 |
|
| 4042 |
|
| 4043 |
|
| 4044 |
OO.ui.ButtonWidget.prototype.getHref = function () { |
| 4045 |
return this.href; |
| 4046 |
}; |
| 4047 |
|
| 4048 |
|
| 4049 |
|
| 4050 |
|
| 4051 |
|
| 4052 |
|
| 4053 |
OO.ui.ButtonWidget.prototype.getTarget = function () { |
| 4054 |
return this.target; |
| 4055 |
}; |
| 4056 |
|
| 4057 |
|
| 4058 |
|
| 4059 |
|
| 4060 |
|
| 4061 |
|
| 4062 |
OO.ui.ButtonWidget.prototype.getNoFollow = function () { |
| 4063 |
return this.noFollow; |
| 4064 |
}; |
| 4065 |
|
| 4066 |
|
| 4067 |
|
| 4068 |
|
| 4069 |
|
| 4070 |
|
| 4071 |
OO.ui.ButtonWidget.prototype.getRel = function () { |
| 4072 |
return this.rel; |
| 4073 |
}; |
| 4074 |
|
| 4075 |
|
| 4076 |
|
| 4077 |
|
| 4078 |
|
| 4079 |
|
| 4080 |
|
| 4081 |
|
| 4082 |
OO.ui.ButtonWidget.prototype.setHref = function ( href ) { |
| 4083 |
href = typeof href === 'string' ? href : null; |
| 4084 |
if ( href !== null && !OO.ui.isSafeUrl( href ) ) { |
| 4085 |
href = './' + href; |
| 4086 |
} |
| 4087 |
|
| 4088 |
if ( href !== this.href ) { |
| 4089 |
this.href = href; |
| 4090 |
this.updateHref(); |
| 4091 |
} |
| 4092 |
|
| 4093 |
return this; |
| 4094 |
}; |
| 4095 |
|
| 4096 |
|
| 4097 |
|
| 4098 |
|
| 4099 |
|
| 4100 |
|
| 4101 |
|
| 4102 |
|
| 4103 |
|
| 4104 |
OO.ui.ButtonWidget.prototype.updateHref = function () { |
| 4105 |
if ( this.href !== null && !this.isDisabled() ) { |
| 4106 |
this.$button.attr( 'href', this.href ); |
| 4107 |
} else { |
| 4108 |
this.$button.removeAttr( 'href' ); |
| 4109 |
} |
| 4110 |
|
| 4111 |
return this; |
| 4112 |
}; |
| 4113 |
|
| 4114 |
|
| 4115 |
|
| 4116 |
|
| 4117 |
|
| 4118 |
|
| 4119 |
|
| 4120 |
OO.ui.ButtonWidget.prototype.onDisable = function () { |
| 4121 |
this.updateHref(); |
| 4122 |
}; |
| 4123 |
|
| 4124 |
|
| 4125 |
|
| 4126 |
|
| 4127 |
|
| 4128 |
|
| 4129 |
|
| 4130 |
OO.ui.ButtonWidget.prototype.setTarget = function ( target ) { |
| 4131 |
target = typeof target === 'string' ? target : null; |
| 4132 |
|
| 4133 |
if ( target !== this.target ) { |
| 4134 |
this.target = target; |
| 4135 |
if ( target !== null ) { |
| 4136 |
this.$button.attr( 'target', target ); |
| 4137 |
} else { |
| 4138 |
this.$button.removeAttr( 'target' ); |
| 4139 |
} |
| 4140 |
} |
| 4141 |
|
| 4142 |
return this; |
| 4143 |
}; |
| 4144 |
|
| 4145 |
|
| 4146 |
|
| 4147 |
|
| 4148 |
|
| 4149 |
|
| 4150 |
|
| 4151 |
OO.ui.ButtonWidget.prototype.setNoFollow = function ( noFollow ) { |
| 4152 |
noFollow = typeof noFollow === 'boolean' ? noFollow : true; |
| 4153 |
|
| 4154 |
if ( noFollow !== this.noFollow ) { |
| 4155 |
let rel; |
| 4156 |
if ( noFollow ) { |
| 4157 |
rel = this.rel.concat( [ 'nofollow' ] ); |
| 4158 |
} else { |
| 4159 |
rel = this.rel.filter( ( value ) => value !== 'nofollow' ); |
| 4160 |
} |
| 4161 |
this.setRel( rel ); |
| 4162 |
} |
| 4163 |
|
| 4164 |
return this; |
| 4165 |
}; |
| 4166 |
|
| 4167 |
|
| 4168 |
|
| 4169 |
|
| 4170 |
|
| 4171 |
|
| 4172 |
|
| 4173 |
OO.ui.ButtonWidget.prototype.setRel = function ( rel ) { |
| 4174 |
if ( !Array.isArray( rel ) ) { |
| 4175 |
rel = rel ? [ rel ] : []; |
| 4176 |
} |
| 4177 |
|
| 4178 |
this.rel = rel; |
| 4179 |
|
| 4180 |
this.noFollow = rel.indexOf( 'nofollow' ) !== -1; |
| 4181 |
this.$button.attr( 'rel', rel.join( ' ' ) || null ); |
| 4182 |
|
| 4183 |
return this; |
| 4184 |
}; |
| 4185 |
|
| 4186 |
|
| 4187 |
|
| 4188 |
|
| 4189 |
|
| 4190 |
|
| 4191 |
|
| 4192 |
|
| 4193 |
|
| 4194 |
|
| 4195 |
|
| 4196 |
|
| 4197 |
|
| 4198 |
|
| 4199 |
|
| 4200 |
|
| 4201 |
|
| 4202 |
|
| 4203 |
|
| 4204 |
|
| 4205 |
|
| 4206 |
|
| 4207 |
|
| 4208 |
|
| 4209 |
), |
| 4210 |
|
| 4211 |
|
| 4212 |
|
| 4213 |
|
| 4214 |
|
| 4215 |
|
| 4216 |
|
| 4217 |
|
| 4218 |
|
| 4219 |
|
| 4220 |
|
| 4221 |
|
| 4222 |
|
| 4223 |
|
| 4224 |
|
| 4225 |
|
| 4226 |
|
| 4227 |
|
| 4228 |
|
| 4229 |
|
| 4230 |
|
| 4231 |
OO.ui.ButtonGroupWidget = function OoUiButtonGroupWidget( config ) { |
| 4232 |
|
| 4233 |
config = config || {}; |
| 4234 |
|
| 4235 |
|
| 4236 |
OO.ui.ButtonGroupWidget.super.call( this, config ); |
| 4237 |
|
| 4238 |
|
| 4239 |
OO.ui.mixin.GroupElement.call( this, Object.assign( { |
| 4240 |
$group: this.$element |
| 4241 |
}, config ) ); |
| 4242 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 4243 |
|
| 4244 |
|
| 4245 |
this.$element.addClass( 'oo-ui-buttonGroupWidget' ); |
| 4246 |
this.addItems( config.items || [] ); |
| 4247 |
}; |
| 4248 |
|
| 4249 |
|
| 4250 |
|
| 4251 |
OO.inheritClass( OO.ui.ButtonGroupWidget, OO.ui.Widget ); |
| 4252 |
OO.mixinClass( OO.ui.ButtonGroupWidget, OO.ui.mixin.GroupElement ); |
| 4253 |
OO.mixinClass( OO.ui.ButtonGroupWidget, OO.ui.mixin.TitledElement ); |
| 4254 |
|
| 4255 |
|
| 4256 |
|
| 4257 |
|
| 4258 |
|
| 4259 |
|
| 4260 |
|
| 4261 |
OO.ui.ButtonGroupWidget.static.tagName = 'span'; |
| 4262 |
|
| 4263 |
|
| 4264 |
|
| 4265 |
|
| 4266 |
|
| 4267 |
|
| 4268 |
|
| 4269 |
|
| 4270 |
|
| 4271 |
OO.ui.ButtonGroupWidget.prototype.focus = function () { |
| 4272 |
if ( !this.isDisabled() ) { |
| 4273 |
if ( this.items[ 0 ] ) { |
| 4274 |
this.items[ 0 ].focus(); |
| 4275 |
} |
| 4276 |
} |
| 4277 |
return this; |
| 4278 |
}; |
| 4279 |
|
| 4280 |
|
| 4281 |
|
| 4282 |
|
| 4283 |
OO.ui.ButtonGroupWidget.prototype.simulateLabelClick = function () { |
| 4284 |
this.focus(); |
| 4285 |
}; |
| 4286 |
|
| 4287 |
|
| 4288 |
|
| 4289 |
|
| 4290 |
1] |
| 4291 |
|
| 4292 |
|
| 4293 |
|
| 4294 |
|
| 4295 |
|
| 4296 |
|
| 4297 |
|
| 4298 |
|
| 4299 |
|
| 4300 |
|
| 4301 |
|
| 4302 |
|
| 4303 |
|
| 4304 |
|
| 4305 |
|
| 4306 |
|
| 4307 |
|
| 4308 |
|
| 4309 |
|
| 4310 |
|
| 4311 |
|
| 4312 |
|
| 4313 |
|
| 4314 |
|
| 4315 |
|
| 4316 |
|
| 4317 |
OO.ui.IconWidget = function OoUiIconWidget( config ) { |
| 4318 |
|
| 4319 |
config = config || {}; |
| 4320 |
|
| 4321 |
|
| 4322 |
OO.ui.IconWidget.super.call( this, config ); |
| 4323 |
|
| 4324 |
|
| 4325 |
OO.ui.mixin.IconElement.call( this, Object.assign( { |
| 4326 |
$icon: this.$element |
| 4327 |
}, config ) ); |
| 4328 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { |
| 4329 |
$titled: this.$element |
| 4330 |
}, config ) ); |
| 4331 |
OO.ui.mixin.LabelElement.call( this, Object.assign( { |
| 4332 |
$label: this.$element, |
| 4333 |
invisibleLabel: true |
| 4334 |
}, config ) ); |
| 4335 |
OO.ui.mixin.FlaggedElement.call( this, Object.assign( { |
| 4336 |
$flagged: this.$element |
| 4337 |
}, config ) ); |
| 4338 |
|
| 4339 |
|
| 4340 |
this.$element.addClass( 'oo-ui-iconWidget' ); |
| 4341 |
|
| 4342 |
|
| 4343 |
this.$element.removeClass( 'oo-ui-labelElement-label' ); |
| 4344 |
}; |
| 4345 |
|
| 4346 |
|
| 4347 |
|
| 4348 |
OO.inheritClass( OO.ui.IconWidget, OO.ui.Widget ); |
| 4349 |
OO.mixinClass( OO.ui.IconWidget, OO.ui.mixin.IconElement ); |
| 4350 |
OO.mixinClass( OO.ui.IconWidget, OO.ui.mixin.TitledElement ); |
| 4351 |
OO.mixinClass( OO.ui.IconWidget, OO.ui.mixin.LabelElement ); |
| 4352 |
OO.mixinClass( OO.ui.IconWidget, OO.ui.mixin.FlaggedElement ); |
| 4353 |
|
| 4354 |
|
| 4355 |
|
| 4356 |
|
| 4357 |
|
| 4358 |
|
| 4359 |
|
| 4360 |
OO.ui.IconWidget.static.tagName = 'span'; |
| 4361 |
|
| 4362 |
|
| 4363 |
|
| 4364 |
|
| 4365 |
|
| 4366 |
|
| 4367 |
|
| 4368 |
|
| 4369 |
|
| 4370 |
|
| 4371 |
|
| 4372 |
|
| 4373 |
|
| 4374 |
|
| 4375 |
|
| 4376 |
|
| 4377 |
|
| 4378 |
|
| 4379 |
|
| 4380 |
|
| 4381 |
|
| 4382 |
|
| 4383 |
|
| 4384 |
|
| 4385 |
|
| 4386 |
|
| 4387 |
|
| 4388 |
|
| 4389 |
|
| 4390 |
|
| 4391 |
|
| 4392 |
OO.ui.IndicatorWidget = function OoUiIndicatorWidget( config ) { |
| 4393 |
|
| 4394 |
config = config || {}; |
| 4395 |
|
| 4396 |
|
| 4397 |
OO.ui.IndicatorWidget.super.call( this, config ); |
| 4398 |
|
| 4399 |
|
| 4400 |
OO.ui.mixin.IndicatorElement.call( this, Object.assign( { |
| 4401 |
$indicator: this.$element |
| 4402 |
}, config ) ); |
| 4403 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { |
| 4404 |
$titled: this.$element |
| 4405 |
}, config ) ); |
| 4406 |
OO.ui.mixin.LabelElement.call( this, Object.assign( { |
| 4407 |
$label: this.$element, |
| 4408 |
invisibleLabel: true |
| 4409 |
}, config ) ); |
| 4410 |
|
| 4411 |
|
| 4412 |
this.$element.addClass( 'oo-ui-indicatorWidget' ); |
| 4413 |
|
| 4414 |
|
| 4415 |
this.$element.removeClass( 'oo-ui-labelElement-label' ); |
| 4416 |
}; |
| 4417 |
|
| 4418 |
|
| 4419 |
|
| 4420 |
OO.inheritClass( OO.ui.IndicatorWidget, OO.ui.Widget ); |
| 4421 |
OO.mixinClass( OO.ui.IndicatorWidget, OO.ui.mixin.IndicatorElement ); |
| 4422 |
OO.mixinClass( OO.ui.IndicatorWidget, OO.ui.mixin.TitledElement ); |
| 4423 |
OO.mixinClass( OO.ui.IndicatorWidget, OO.ui.mixin.LabelElement ); |
| 4424 |
|
| 4425 |
|
| 4426 |
|
| 4427 |
|
| 4428 |
|
| 4429 |
|
| 4430 |
|
| 4431 |
OO.ui.IndicatorWidget.static.tagName = 'span'; |
| 4432 |
|
| 4433 |
|
| 4434 |
|
| 4435 |
|
| 4436 |
|
| 4437 |
|
| 4438 |
|
| 4439 |
|
| 4440 |
|
| 4441 |
|
| 4442 |
|
| 4443 |
|
| 4444 |
|
| 4445 |
|
| 4446 |
|
| 4447 |
|
| 4448 |
|
| 4449 |
|
| 4450 |
|
| 4451 |
|
| 4452 |
|
| 4453 |
|
| 4454 |
|
| 4455 |
|
| 4456 |
|
| 4457 |
|
| 4458 |
|
| 4459 |
|
| 4460 |
|
| 4461 |
|
| 4462 |
|
| 4463 |
|
| 4464 |
|
| 4465 |
|
| 4466 |
|
| 4467 |
|
| 4468 |
|
| 4469 |
|
| 4470 |
|
| 4471 |
|
| 4472 |
|
| 4473 |
OO.ui.LabelWidget = function OoUiLabelWidget( config ) { |
| 4474 |
|
| 4475 |
config = config || {}; |
| 4476 |
|
| 4477 |
|
| 4478 |
OO.ui.LabelWidget.super.call( this, config ); |
| 4479 |
|
| 4480 |
|
| 4481 |
OO.ui.mixin.LabelElement.call( this, Object.assign( { |
| 4482 |
$label: this.$element |
| 4483 |
}, config ) ); |
| 4484 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 4485 |
|
| 4486 |
|
| 4487 |
this.input = config.input; |
| 4488 |
|
| 4489 |
|
| 4490 |
if ( this.input ) { |
| 4491 |
if ( this.input.getInputId() ) { |
| 4492 |
this.$element.attr( 'for', this.input.getInputId() ); |
| 4493 |
} else { |
| 4494 |
this.$label.on( 'click', () => { |
| 4495 |
this.input.simulateLabelClick(); |
| 4496 |
} ); |
| 4497 |
} |
| 4498 |
} |
| 4499 |
this.$element.addClass( 'oo-ui-labelWidget' ); |
| 4500 |
}; |
| 4501 |
|
| 4502 |
|
| 4503 |
|
| 4504 |
OO.inheritClass( OO.ui.LabelWidget, OO.ui.Widget ); |
| 4505 |
OO.mixinClass( OO.ui.LabelWidget, OO.ui.mixin.LabelElement ); |
| 4506 |
OO.mixinClass( OO.ui.LabelWidget, OO.ui.mixin.TitledElement ); |
| 4507 |
|
| 4508 |
|
| 4509 |
|
| 4510 |
|
| 4511 |
|
| 4512 |
|
| 4513 |
|
| 4514 |
OO.ui.LabelWidget.static.tagName = 'label'; |
| 4515 |
|
| 4516 |
|
| 4517 |
|
| 4518 |
|
| 4519 |
|
| 4520 |
|
| 4521 |
|
| 4522 |
|
| 4523 |
|
| 4524 |
|
| 4525 |
|
| 4526 |
|
| 4527 |
|
| 4528 |
|
| 4529 |
|
| 4530 |
|
| 4531 |
|
| 4532 |
|
| 4533 |
|
| 4534 |
|
| 4535 |
|
| 4536 |
|
| 4537 |
|
| 4538 |
|
| 4539 |
OO.ui.MessageWidget = function OoUiMessageWidget( config ) { |
| 4540 |
|
| 4541 |
config = config || {}; |
| 4542 |
|
| 4543 |
|
| 4544 |
OO.ui.MessageWidget.super.call( this, config ); |
| 4545 |
|
| 4546 |
|
| 4547 |
OO.ui.mixin.IconElement.call( this, config ); |
| 4548 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 4549 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 4550 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 4551 |
|
| 4552 |
|
| 4553 |
this.setType( config.type ); |
| 4554 |
this.setInline( config.inline ); |
| 4555 |
|
| 4556 |
|
| 4557 |
|
| 4558 |
if ( config.icon ) { |
| 4559 |
this.setIcon( config.icon ); |
| 4560 |
} |
| 4561 |
|
| 4562 |
if ( !this.inline && config.showClose ) { |
| 4563 |
this.closeButton = new OO.ui.ButtonWidget( { |
| 4564 |
classes: [ 'oo-ui-messageWidget-close' ], |
| 4565 |
framed: false, |
| 4566 |
icon: 'close', |
| 4567 |
label: OO.ui.msg( 'ooui-popup-widget-close-button-aria-label' ), |
| 4568 |
invisibleLabel: true |
| 4569 |
} ); |
| 4570 |
this.closeButton.connect( this, { |
| 4571 |
click: 'onCloseButtonClick' |
| 4572 |
} ); |
| 4573 |
this.$element.addClass( 'oo-ui-messageWidget-showClose' ); |
| 4574 |
} |
| 4575 |
|
| 4576 |
|
| 4577 |
this.$element |
| 4578 |
.append( this.$icon, this.$label, this.closeButton && this.closeButton.$element ) |
| 4579 |
.addClass( 'oo-ui-messageWidget' ); |
| 4580 |
}; |
| 4581 |
|
| 4582 |
|
| 4583 |
|
| 4584 |
OO.inheritClass( OO.ui.MessageWidget, OO.ui.Widget ); |
| 4585 |
OO.mixinClass( OO.ui.MessageWidget, OO.ui.mixin.IconElement ); |
| 4586 |
OO.mixinClass( OO.ui.MessageWidget, OO.ui.mixin.LabelElement ); |
| 4587 |
OO.mixinClass( OO.ui.MessageWidget, OO.ui.mixin.TitledElement ); |
| 4588 |
OO.mixinClass( OO.ui.MessageWidget, OO.ui.mixin.FlaggedElement ); |
| 4589 |
|
| 4590 |
|
| 4591 |
|
| 4592 |
|
| 4593 |
|
| 4594 |
|
| 4595 |
|
| 4596 |
|
| 4597 |
|
| 4598 |
|
| 4599 |
|
| 4600 |
|
| 4601 |
|
| 4602 |
|
| 4603 |
|
| 4604 |
OO.ui.MessageWidget.static.iconMap = { |
| 4605 |
notice: 'infoFilled', |
| 4606 |
error: 'error', |
| 4607 |
warning: 'alert', |
| 4608 |
success: 'success' |
| 4609 |
}; |
| 4610 |
|
| 4611 |
|
| 4612 |
|
| 4613 |
|
| 4614 |
|
| 4615 |
|
| 4616 |
|
| 4617 |
|
| 4618 |
OO.ui.MessageWidget.prototype.setInline = function ( inline ) { |
| 4619 |
inline = !!inline; |
| 4620 |
|
| 4621 |
if ( this.inline !== inline ) { |
| 4622 |
this.inline = inline; |
| 4623 |
this.$element |
| 4624 |
.toggleClass( 'oo-ui-messageWidget-block', !this.inline ); |
| 4625 |
} |
| 4626 |
}; |
| 4627 |
|
| 4628 |
|
| 4629 |
|
| 4630 |
|
| 4631 |
|
| 4632 |
|
| 4633 |
OO.ui.MessageWidget.prototype.setType = function ( type ) { |
| 4634 |
if ( !this.constructor.static.iconMap[ type ] ) { |
| 4635 |
type = 'notice'; |
| 4636 |
} |
| 4637 |
|
| 4638 |
if ( this.type !== type ) { |
| 4639 |
|
| 4640 |
this.clearFlags(); |
| 4641 |
this.setFlags( type ); |
| 4642 |
|
| 4643 |
|
| 4644 |
this.setIcon( this.constructor.static.iconMap[ type ] ); |
| 4645 |
this.$icon.removeClass( 'oo-ui-image-' + this.type ); |
| 4646 |
this.$icon.addClass( 'oo-ui-image-' + type ); |
| 4647 |
|
| 4648 |
if ( type === 'error' ) { |
| 4649 |
this.$element.attr( 'role', 'alert' ); |
| 4650 |
this.$element.removeAttr( 'aria-live' ); |
| 4651 |
} else { |
| 4652 |
this.$element.removeAttr( 'role' ); |
| 4653 |
this.$element.attr( 'aria-live', 'polite' ); |
| 4654 |
} |
| 4655 |
|
| 4656 |
this.type = type; |
| 4657 |
} |
| 4658 |
}; |
| 4659 |
|
| 4660 |
|
| 4661 |
|
| 4662 |
|
| 4663 |
|
| 4664 |
|
| 4665 |
|
| 4666 |
OO.ui.MessageWidget.prototype.onCloseButtonClick = function () { |
| 4667 |
this.toggle( false ); |
| 4668 |
this.emit( 'close' ); |
| 4669 |
}; |
| 4670 |
|
| 4671 |
|
| 4672 |
|
| 4673 |
|
| 4674 |
|
| 4675 |
|
| 4676 |
|
| 4677 |
|
| 4678 |
|
| 4679 |
|
| 4680 |
|
| 4681 |
|
| 4682 |
e. |
| 4683 |
|
| 4684 |
|
| 4685 |
OO.ui.ToggleWidget = function OoUiToggleWidget( config ) { |
| 4686 |
|
| 4687 |
config = config || {}; |
| 4688 |
|
| 4689 |
|
| 4690 |
OO.ui.ToggleWidget.super.call( this, config ); |
| 4691 |
|
| 4692 |
|
| 4693 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 4694 |
|
| 4695 |
|
| 4696 |
this.value = null; |
| 4697 |
|
| 4698 |
|
| 4699 |
this.$element.addClass( 'oo-ui-toggleWidget' ); |
| 4700 |
this.setValue( !!config.value ); |
| 4701 |
}; |
| 4702 |
|
| 4703 |
|
| 4704 |
|
| 4705 |
OO.inheritClass( OO.ui.ToggleWidget, OO.ui.Widget ); |
| 4706 |
OO.mixinClass( OO.ui.ToggleWidget, OO.ui.mixin.TitledElement ); |
| 4707 |
|
| 4708 |
|
| 4709 |
|
| 4710 |
|
| 4711 |
|
| 4712 |
|
| 4713 |
|
| 4714 |
|
| 4715 |
|
| 4716 |
|
| 4717 |
|
| 4718 |
|
| 4719 |
|
| 4720 |
e. |
| 4721 |
|
| 4722 |
|
| 4723 |
|
| 4724 |
OO.ui.ToggleWidget.prototype.getValue = function () { |
| 4725 |
return this.value; |
| 4726 |
}; |
| 4727 |
|
| 4728 |
|
| 4729 |
|
| 4730 |
|
| 4731 |
|
| 4732 |
|
| 4733 |
|
| 4734 |
|
| 4735 |
|
| 4736 |
OO.ui.ToggleWidget.prototype.setValue = function ( value ) { |
| 4737 |
value = !!value; |
| 4738 |
if ( this.value !== value ) { |
| 4739 |
this.value = value; |
| 4740 |
this.emit( 'change', value ); |
| 4741 |
this.$element.toggleClass( 'oo-ui-toggleWidget-on', value ); |
| 4742 |
this.$element.toggleClass( 'oo-ui-toggleWidget-off', !value ); |
| 4743 |
} |
| 4744 |
return this; |
| 4745 |
}; |
| 4746 |
|
| 4747 |
|
| 4748 |
|
| 4749 |
resented |
| 4750 |
|
| 4751 |
|
| 4752 |
|
| 4753 |
|
| 4754 |
|
| 4755 |
|
| 4756 |
|
| 4757 |
|
| 4758 |
|
| 4759 |
|
| 4760 |
|
| 4761 |
|
| 4762 |
|
| 4763 |
|
| 4764 |
|
| 4765 |
|
| 4766 |
|
| 4767 |
|
| 4768 |
|
| 4769 |
|
| 4770 |
|
| 4771 |
|
| 4772 |
|
| 4773 |
|
| 4774 |
|
| 4775 |
|
| 4776 |
|
| 4777 |
|
| 4778 |
|
| 4779 |
|
| 4780 |
e. |
| 4781 |
|
| 4782 |
|
| 4783 |
OO.ui.ToggleSwitchWidget = function OoUiToggleSwitchWidget( config ) { |
| 4784 |
|
| 4785 |
OO.ui.ToggleSwitchWidget.super.call( this, config ); |
| 4786 |
|
| 4787 |
|
| 4788 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 4789 |
|
| 4790 |
|
| 4791 |
this.dragging = false; |
| 4792 |
this.dragStart = null; |
| 4793 |
this.sliding = false; |
| 4794 |
this.$glow = $( '<span>' ); |
| 4795 |
this.$grip = $( '<span>' ); |
| 4796 |
|
| 4797 |
|
| 4798 |
this.$element.on( { |
| 4799 |
click: this.onClick.bind( this ), |
| 4800 |
keypress: this.onKeyPress.bind( this ) |
| 4801 |
} ); |
| 4802 |
|
| 4803 |
|
| 4804 |
this.$glow.addClass( 'oo-ui-toggleSwitchWidget-glow' ); |
| 4805 |
this.$grip.addClass( 'oo-ui-toggleSwitchWidget-grip' ); |
| 4806 |
this.$element |
| 4807 |
.addClass( 'oo-ui-toggleSwitchWidget' ) |
| 4808 |
.attr( 'role', 'switch' ) |
| 4809 |
.append( this.$glow, this.$grip ); |
| 4810 |
}; |
| 4811 |
|
| 4812 |
|
| 4813 |
|
| 4814 |
OO.inheritClass( OO.ui.ToggleSwitchWidget, OO.ui.ToggleWidget ); |
| 4815 |
OO.mixinClass( OO.ui.ToggleSwitchWidget, OO.ui.mixin.TabIndexedElement ); |
| 4816 |
|
| 4817 |
|
| 4818 |
|
| 4819 |
|
| 4820 |
|
| 4821 |
|
| 4822 |
|
| 4823 |
|
| 4824 |
|
| 4825 |
|
| 4826 |
OO.ui.ToggleSwitchWidget.prototype.onClick = function ( e ) { |
| 4827 |
if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) { |
| 4828 |
this.setValue( !this.value ); |
| 4829 |
} |
| 4830 |
return false; |
| 4831 |
}; |
| 4832 |
|
| 4833 |
|
| 4834 |
|
| 4835 |
|
| 4836 |
|
| 4837 |
|
| 4838 |
|
| 4839 |
|
| 4840 |
OO.ui.ToggleSwitchWidget.prototype.onKeyPress = function ( e ) { |
| 4841 |
if ( !this.isDisabled() && ( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) ) { |
| 4842 |
this.setValue( !this.value ); |
| 4843 |
return false; |
| 4844 |
} |
| 4845 |
}; |
| 4846 |
|
| 4847 |
|
| 4848 |
|
| 4849 |
|
| 4850 |
OO.ui.ToggleSwitchWidget.prototype.setValue = function ( value ) { |
| 4851 |
OO.ui.ToggleSwitchWidget.super.prototype.setValue.call( this, value ); |
| 4852 |
this.$element.attr( 'aria-checked', this.value.toString() ); |
| 4853 |
return this; |
| 4854 |
}; |
| 4855 |
|
| 4856 |
|
| 4857 |
|
| 4858 |
|
| 4859 |
OO.ui.ToggleSwitchWidget.prototype.simulateLabelClick = function () { |
| 4860 |
if ( !this.isDisabled() ) { |
| 4861 |
this.setValue( !this.value ); |
| 4862 |
} |
| 4863 |
this.focus(); |
| 4864 |
}; |
| 4865 |
|
| 4866 |
|
| 4867 |
|
| 4868 |
|
| 4869 |
|
| 4870 |
|
| 4871 |
|
| 4872 |
|
| 4873 |
|
| 4874 |
|
| 4875 |
|
| 4876 |
|
| 4877 |
|
| 4878 |
|
| 4879 |
|
| 4880 |
|
| 4881 |
|
| 4882 |
|
| 4883 |
|
| 4884 |
|
| 4885 |
|
| 4886 |
|
| 4887 |
|
| 4888 |
|
| 4889 |
|
| 4890 |
|
| 4891 |
|
| 4892 |
|
| 4893 |
|
| 4894 |
|
| 4895 |
|
| 4896 |
|
| 4897 |
|
| 4898 |
|
| 4899 |
|
| 4900 |
|
| 4901 |
|
| 4902 |
|
| 4903 |
|
| 4904 |
|
| 4905 |
|
| 4906 |
|
| 4907 |
|
| 4908 |
|
| 4909 |
|
| 4910 |
|
| 4911 |
|
| 4912 |
|
| 4913 |
|
| 4914 |
|
| 4915 |
|
| 4916 |
|
| 4917 |
|
| 4918 |
|
| 4919 |
|
| 4920 |
|
| 4921 |
|
| 4922 |
|
| 4923 |
|
| 4924 |
|
| 4925 |
|
| 4926 |
OO.ui.mixin.PendingElement = function OoUiMixinPendingElement( config ) { |
| 4927 |
|
| 4928 |
config = config || {}; |
| 4929 |
|
| 4930 |
|
| 4931 |
this.pending = 0; |
| 4932 |
this.$pending = null; |
| 4933 |
|
| 4934 |
|
| 4935 |
this.setPendingElement( config.$pending || this.$element ); |
| 4936 |
}; |
| 4937 |
|
| 4938 |
|
| 4939 |
|
| 4940 |
OO.initClass( OO.ui.mixin.PendingElement ); |
| 4941 |
|
| 4942 |
|
| 4943 |
|
| 4944 |
|
| 4945 |
|
| 4946 |
|
| 4947 |
|
| 4948 |
|
| 4949 |
OO.ui.mixin.PendingElement.prototype.setPendingElement = function ( $pending ) { |
| 4950 |
if ( this.$pending ) { |
| 4951 |
this.$pending.removeClass( 'oo-ui-pendingElement-pending' ); |
| 4952 |
} |
| 4953 |
|
| 4954 |
this.$pending = $pending; |
| 4955 |
if ( this.pending > 0 ) { |
| 4956 |
this.$pending.addClass( 'oo-ui-pendingElement-pending' ); |
| 4957 |
} |
| 4958 |
}; |
| 4959 |
|
| 4960 |
|
| 4961 |
|
| 4962 |
|
| 4963 |
|
| 4964 |
|
| 4965 |
OO.ui.mixin.PendingElement.prototype.isPending = function () { |
| 4966 |
return !!this.pending; |
| 4967 |
}; |
| 4968 |
|
| 4969 |
|
| 4970 |
|
| 4971 |
|
| 4972 |
|
| 4973 |
|
| 4974 |
|
| 4975 |
|
| 4976 |
OO.ui.mixin.PendingElement.prototype.pushPending = function () { |
| 4977 |
if ( this.pending === 0 ) { |
| 4978 |
this.$pending.addClass( 'oo-ui-pendingElement-pending' ); |
| 4979 |
this.updateThemeClasses(); |
| 4980 |
} |
| 4981 |
this.pending++; |
| 4982 |
|
| 4983 |
return this; |
| 4984 |
}; |
| 4985 |
|
| 4986 |
|
| 4987 |
|
| 4988 |
|
| 4989 |
|
| 4990 |
|
| 4991 |
|
| 4992 |
|
| 4993 |
OO.ui.mixin.PendingElement.prototype.popPending = function () { |
| 4994 |
if ( this.pending === 1 ) { |
| 4995 |
this.$pending.removeClass( 'oo-ui-pendingElement-pending' ); |
| 4996 |
this.updateThemeClasses(); |
| 4997 |
} |
| 4998 |
this.pending = Math.max( 0, this.pending - 1 ); |
| 4999 |
|
| 5000 |
return this; |
| 5001 |
}; |
| 5002 |
|
| 5003 |
|
| 5004 |
|
| 5005 |
|
| 5006 |
|
| 5007 |
|
| 5008 |
|
| 5009 |
|
| 5010 |
|
| 5011 |
|
| 5012 |
|
| 5013 |
|
| 5014 |
|
| 5015 |
|
| 5016 |
|
| 5017 |
|
| 5018 |
|
| 5019 |
|
| 5020 |
|
| 5021 |
|
| 5022 |
|
| 5023 |
|
| 5024 |
|
| 5025 |
|
| 5026 |
|
| 5027 |
|
| 5028 |
|
| 5029 |
|
| 5030 |
|
| 5031 |
|
| 5032 |
|
| 5033 |
|
| 5034 |
|
| 5035 |
|
| 5036 |
|
| 5037 |
|
| 5038 |
|
| 5039 |
OO.ui.mixin.FloatableElement = function OoUiMixinFloatableElement( config ) { |
| 5040 |
|
| 5041 |
config = config || {}; |
| 5042 |
|
| 5043 |
|
| 5044 |
this.$floatable = null; |
| 5045 |
this.$floatableContainer = null; |
| 5046 |
this.$floatableWindow = null; |
| 5047 |
this.$floatableClosestScrollable = null; |
| 5048 |
this.floatableOutOfView = false; |
| 5049 |
this.onFloatableScrollHandler = this.position.bind( this ); |
| 5050 |
this.onFloatableWindowResizeHandler = this.position.bind( this ); |
| 5051 |
|
| 5052 |
|
| 5053 |
this.setFloatableContainer( config.$floatableContainer ); |
| 5054 |
this.setFloatableElement( config.$floatable || this.$element ); |
| 5055 |
this.setVerticalPosition( config.verticalPosition || 'below' ); |
| 5056 |
this.setHorizontalPosition( config.horizontalPosition || 'start' ); |
| 5057 |
this.spacing = config.spacing || 0; |
| 5058 |
this.hideWhenOutOfView = config.hideWhenOutOfView === undefined ? |
| 5059 |
true : !!config.hideWhenOutOfView; |
| 5060 |
}; |
| 5061 |
|
| 5062 |
|
| 5063 |
|
| 5064 |
|
| 5065 |
|
| 5066 |
|
| 5067 |
|
| 5068 |
|
| 5069 |
|
| 5070 |
|
| 5071 |
OO.ui.mixin.FloatableElement.prototype.setFloatableElement = function ( $floatable ) { |
| 5072 |
if ( this.$floatable ) { |
| 5073 |
this.$floatable.removeClass( 'oo-ui-floatableElement-floatable' ); |
| 5074 |
this.$floatable.css( { top: '', left: '', bottom: '', right: '' } ); |
| 5075 |
} |
| 5076 |
|
| 5077 |
this.$floatable = $floatable.addClass( 'oo-ui-floatableElement-floatable' ); |
| 5078 |
this.position(); |
| 5079 |
}; |
| 5080 |
|
| 5081 |
|
| 5082 |
|
| 5083 |
|
| 5084 |
|
| 5085 |
|
| 5086 |
|
| 5087 |
|
| 5088 |
OO.ui.mixin.FloatableElement.prototype.setFloatableContainer = function ( $floatableContainer ) { |
| 5089 |
this.$floatableContainer = $floatableContainer; |
| 5090 |
if ( this.$floatable ) { |
| 5091 |
this.position(); |
| 5092 |
} |
| 5093 |
}; |
| 5094 |
|
| 5095 |
|
| 5096 |
|
| 5097 |
|
| 5098 |
|
| 5099 |
|
| 5100 |
OO.ui.mixin.FloatableElement.prototype.setVerticalPosition = function ( position ) { |
| 5101 |
if ( [ 'below', 'above', 'top', 'bottom', 'center' ].indexOf( position ) === -1 ) { |
| 5102 |
throw new Error( 'Invalid value for vertical position: ' + position ); |
| 5103 |
} |
| 5104 |
if ( this.verticalPosition !== position ) { |
| 5105 |
this.verticalPosition = position; |
| 5106 |
if ( this.$floatable ) { |
| 5107 |
this.position(); |
| 5108 |
} |
| 5109 |
} |
| 5110 |
}; |
| 5111 |
|
| 5112 |
|
| 5113 |
|
| 5114 |
|
| 5115 |
|
| 5116 |
|
| 5117 |
OO.ui.mixin.FloatableElement.prototype.setHorizontalPosition = function ( position ) { |
| 5118 |
if ( [ 'before', 'after', 'start', 'end', 'center' ].indexOf( position ) === -1 ) { |
| 5119 |
throw new Error( 'Invalid value for horizontal position: ' + position ); |
| 5120 |
} |
| 5121 |
if ( this.horizontalPosition !== position ) { |
| 5122 |
this.horizontalPosition = position; |
| 5123 |
if ( this.$floatable ) { |
| 5124 |
this.position(); |
| 5125 |
} |
| 5126 |
} |
| 5127 |
}; |
| 5128 |
|
| 5129 |
|
| 5130 |
|
| 5131 |
|
| 5132 |
|
| 5133 |
|
| 5134 |
|
| 5135 |
|
| 5136 |
|
| 5137 |
|
| 5138 |
OO.ui.mixin.FloatableElement.prototype.togglePositioning = function ( positioning ) { |
| 5139 |
if ( !this.$floatable || !this.$floatableContainer ) { |
| 5140 |
return this; |
| 5141 |
} |
| 5142 |
|
| 5143 |
positioning = positioning === undefined ? !this.positioning : !!positioning; |
| 5144 |
|
| 5145 |
if ( positioning && !this.warnedUnattached && !this.isElementAttached() ) { |
| 5146 |
OO.ui.warnDeprecation( 'FloatableElement#togglePositioning: Before calling this method, the element must be attached to the DOM.' ); |
| 5147 |
this.warnedUnattached = true; |
| 5148 |
} |
| 5149 |
|
| 5150 |
if ( this.positioning !== positioning ) { |
| 5151 |
this.positioning = positioning; |
| 5152 |
|
| 5153 |
let closestScrollableOfContainer = OO.ui.Element.static.getClosestScrollableContainer( |
| 5154 |
this.$floatableContainer[ 0 ] |
| 5155 |
); |
| 5156 |
|
| 5157 |
|
| 5158 |
if ( $( closestScrollableOfContainer ).is( 'html, body' ) ) { |
| 5159 |
closestScrollableOfContainer = OO.ui.Element.static.getWindow( |
| 5160 |
closestScrollableOfContainer |
| 5161 |
); |
| 5162 |
} |
| 5163 |
|
| 5164 |
if ( positioning ) { |
| 5165 |
this.$floatableWindow = $( this.getElementWindow() ); |
| 5166 |
this.$floatableWindow.on( 'resize', this.onFloatableWindowResizeHandler ); |
| 5167 |
|
| 5168 |
this.$floatableClosestScrollable = $( closestScrollableOfContainer ); |
| 5169 |
this.$floatableClosestScrollable.on( 'scroll', this.onFloatableScrollHandler ); |
| 5170 |
|
| 5171 |
|
| 5172 |
this.position(); |
| 5173 |
} else { |
| 5174 |
if ( this.$floatableWindow ) { |
| 5175 |
this.$floatableWindow.off( 'resize', this.onFloatableWindowResizeHandler ); |
| 5176 |
this.$floatableWindow = null; |
| 5177 |
} |
| 5178 |
|
| 5179 |
if ( this.$floatableClosestScrollable ) { |
| 5180 |
this.$floatableClosestScrollable.off( 'scroll', this.onFloatableScrollHandler ); |
| 5181 |
this.$floatableClosestScrollable = null; |
| 5182 |
} |
| 5183 |
|
| 5184 |
this.$floatable.css( { top: '', left: '', bottom: '', right: '' } ); |
| 5185 |
} |
| 5186 |
} |
| 5187 |
|
| 5188 |
return this; |
| 5189 |
}; |
| 5190 |
|
| 5191 |
|
| 5192 |
|
| 5193 |
|
| 5194 |
|
| 5195 |
|
| 5196 |
|
| 5197 |
|
| 5198 |
|
| 5199 |
|
| 5200 |
OO.ui.mixin.FloatableElement.prototype.isElementInViewport = function ( $element, $container ) { |
| 5201 |
const direction = $element.css( 'direction' ); |
| 5202 |
|
| 5203 |
const elemRect = $element[ 0 ].getBoundingClientRect(); |
| 5204 |
let contRect; |
| 5205 |
if ( $container[ 0 ] === window ) { |
| 5206 |
const viewportSpacing = OO.ui.getViewportSpacing(); |
| 5207 |
contRect = { |
| 5208 |
top: 0, |
| 5209 |
left: 0, |
| 5210 |
right: document.documentElement.clientWidth, |
| 5211 |
bottom: document.documentElement.clientHeight |
| 5212 |
}; |
| 5213 |
contRect.top += viewportSpacing.top; |
| 5214 |
contRect.left += viewportSpacing.left; |
| 5215 |
contRect.right -= viewportSpacing.right; |
| 5216 |
contRect.bottom -= viewportSpacing.bottom; |
| 5217 |
} else { |
| 5218 |
contRect = $container[ 0 ].getBoundingClientRect(); |
| 5219 |
} |
| 5220 |
|
| 5221 |
const topEdgeInBounds = elemRect.top >= contRect.top && elemRect.top <= contRect.bottom; |
| 5222 |
const bottomEdgeInBounds = elemRect.bottom >= contRect.top && elemRect.bottom <= contRect.bottom; |
| 5223 |
const leftEdgeInBounds = elemRect.left >= contRect.left && elemRect.left <= contRect.right; |
| 5224 |
const rightEdgeInBounds = elemRect.right >= contRect.left && elemRect.right <= contRect.right; |
| 5225 |
let startEdgeInBounds, endEdgeInBounds; |
| 5226 |
if ( direction === 'rtl' ) { |
| 5227 |
startEdgeInBounds = rightEdgeInBounds; |
| 5228 |
endEdgeInBounds = leftEdgeInBounds; |
| 5229 |
} else { |
| 5230 |
startEdgeInBounds = leftEdgeInBounds; |
| 5231 |
endEdgeInBounds = rightEdgeInBounds; |
| 5232 |
} |
| 5233 |
|
| 5234 |
if ( this.verticalPosition === 'below' && !bottomEdgeInBounds ) { |
| 5235 |
return false; |
| 5236 |
} |
| 5237 |
if ( this.verticalPosition === 'above' && !topEdgeInBounds ) { |
| 5238 |
return false; |
| 5239 |
} |
| 5240 |
if ( this.horizontalPosition === 'before' && !startEdgeInBounds ) { |
| 5241 |
return false; |
| 5242 |
} |
| 5243 |
if ( this.horizontalPosition === 'after' && !endEdgeInBounds ) { |
| 5244 |
return false; |
| 5245 |
} |
| 5246 |
|
| 5247 |
|
| 5248 |
|
| 5249 |
return elemRect.top <= contRect.bottom && elemRect.bottom >= contRect.top && |
| 5250 |
elemRect.left <= contRect.right && elemRect.right >= contRect.left; |
| 5251 |
}; |
| 5252 |
|
| 5253 |
|
| 5254 |
|
| 5255 |
|
| 5256 |
|
| 5257 |
|
| 5258 |
OO.ui.mixin.FloatableElement.prototype.isFloatableOutOfView = function () { |
| 5259 |
return this.floatableOutOfView; |
| 5260 |
}; |
| 5261 |
|
| 5262 |
|
| 5263 |
|
| 5264 |
|
| 5265 |
|
| 5266 |
|
| 5267 |
|
| 5268 |
|
| 5269 |
|
| 5270 |
OO.ui.mixin.FloatableElement.prototype.position = function () { |
| 5271 |
if ( !this.positioning ) { |
| 5272 |
return this; |
| 5273 |
} |
| 5274 |
|
| 5275 |
if ( !( |
| 5276 |
|
| 5277 |
|
| 5278 |
this.isElementAttached() && ( |
| 5279 |
|
| 5280 |
this.$floatableClosestScrollable[ 0 ] === this.getElementWindow() || |
| 5281 |
|
| 5282 |
$.contains( this.getElementDocument(), this.$floatableClosestScrollable[ 0 ] ) |
| 5283 |
) |
| 5284 |
) ) { |
| 5285 |
|
| 5286 |
return this; |
| 5287 |
} |
| 5288 |
|
| 5289 |
this.floatableOutOfView = this.hideWhenOutOfView && |
| 5290 |
!this.isElementInViewport( this.$floatableContainer, this.$floatableClosestScrollable ); |
| 5291 |
this.$floatable.toggleClass( 'oo-ui-element-hidden', this.floatableOutOfView ); |
| 5292 |
if ( this.floatableOutOfView ) { |
| 5293 |
return this; |
| 5294 |
} |
| 5295 |
|
| 5296 |
this.$floatable.css( this.computePosition() ); |
| 5297 |
|
| 5298 |
|
| 5299 |
|
| 5300 |
|
| 5301 |
|
| 5302 |
|
| 5303 |
if ( this.clip ) { |
| 5304 |
this.clip(); |
| 5305 |
} |
| 5306 |
|
| 5307 |
return this; |
| 5308 |
}; |
| 5309 |
|
| 5310 |
|
| 5311 |
|
| 5312 |
|
| 5313 |
|
| 5314 |
|
| 5315 |
|
| 5316 |
|
| 5317 |
OO.ui.mixin.FloatableElement.prototype.computePosition = function () { |
| 5318 |
const newPos = { top: '', left: '', bottom: '', right: '' }; |
| 5319 |
const direction = this.$floatableContainer.css( 'direction' ); |
| 5320 |
|
| 5321 |
let $offsetParent = this.$floatable.offsetParent(); |
| 5322 |
|
| 5323 |
if ( $offsetParent.is( 'html' ) ) { |
| 5324 |
|
| 5325 |
|
| 5326 |
$offsetParent = $( $offsetParent[ 0 ].ownerDocument.body ); |
| 5327 |
} |
| 5328 |
const isBody = $offsetParent.is( 'body' ); |
| 5329 |
const scrollableX = $offsetParent.css( 'overflow-x' ) === 'scroll' || |
| 5330 |
$offsetParent.css( 'overflow-x' ) === 'auto'; |
| 5331 |
const scrollableY = $offsetParent.css( 'overflow-y' ) === 'scroll' || |
| 5332 |
$offsetParent.css( 'overflow-y' ) === 'auto'; |
| 5333 |
|
| 5334 |
const vertScrollbarWidth = $offsetParent.innerWidth() - $offsetParent.prop( 'clientWidth' ); |
| 5335 |
const horizScrollbarHeight = $offsetParent.innerHeight() - $offsetParent.prop( 'clientHeight' ); |
| 5336 |
|
| 5337 |
|
| 5338 |
const scrollTop = scrollableY && !isBody ? |
| 5339 |
$offsetParent.scrollTop() : 0; |
| 5340 |
const scrollLeft = scrollableX && !isBody ? |
| 5341 |
OO.ui.Element.static.getScrollLeft( $offsetParent[ 0 ] ) : 0; |
| 5342 |
|
| 5343 |
|
| 5344 |
|
| 5345 |
const containerPos = isBody ? |
| 5346 |
this.$floatableContainer.offset() : |
| 5347 |
OO.ui.Element.static.getRelativePosition( this.$floatableContainer, $offsetParent ); |
| 5348 |
containerPos.bottom = containerPos.top + this.$floatableContainer.outerHeight(); |
| 5349 |
containerPos.right = containerPos.left + this.$floatableContainer.outerWidth(); |
| 5350 |
containerPos.start = direction === 'rtl' ? containerPos.right : containerPos.left; |
| 5351 |
containerPos.end = direction === 'rtl' ? containerPos.left : containerPos.right; |
| 5352 |
|
| 5353 |
if ( this.verticalPosition === 'below' ) { |
| 5354 |
newPos.top = containerPos.bottom + this.spacing; |
| 5355 |
} else if ( this.verticalPosition === 'above' ) { |
| 5356 |
newPos.bottom = $offsetParent.outerHeight() - containerPos.top + this.spacing; |
| 5357 |
} else if ( this.verticalPosition === 'top' ) { |
| 5358 |
newPos.top = containerPos.top; |
| 5359 |
} else if ( this.verticalPosition === 'bottom' ) { |
| 5360 |
newPos.bottom = $offsetParent.outerHeight() - containerPos.bottom; |
| 5361 |
} else if ( this.verticalPosition === 'center' ) { |
| 5362 |
newPos.top = containerPos.top + |
| 5363 |
( this.$floatableContainer.height() - this.$floatable.height() ) / 2; |
| 5364 |
} |
| 5365 |
|
| 5366 |
if ( this.horizontalPosition === 'before' ) { |
| 5367 |
newPos.end = containerPos.start - this.spacing; |
| 5368 |
} else if ( this.horizontalPosition === 'after' ) { |
| 5369 |
newPos.start = containerPos.end + this.spacing; |
| 5370 |
} else if ( this.horizontalPosition === 'start' ) { |
| 5371 |
newPos.start = containerPos.start; |
| 5372 |
} else if ( this.horizontalPosition === 'end' ) { |
| 5373 |
newPos.end = containerPos.end; |
| 5374 |
} else if ( this.horizontalPosition === 'center' ) { |
| 5375 |
newPos.left = containerPos.left + |
| 5376 |
( this.$floatableContainer.width() - this.$floatable.width() ) / 2; |
| 5377 |
} |
| 5378 |
|
| 5379 |
if ( newPos.start !== undefined ) { |
| 5380 |
if ( direction === 'rtl' ) { |
| 5381 |
newPos.right = ( isBody ? $( $offsetParent[ 0 ].ownerDocument.documentElement ) : |
| 5382 |
$offsetParent ).outerWidth() - newPos.start; |
| 5383 |
} else { |
| 5384 |
newPos.left = newPos.start; |
| 5385 |
} |
| 5386 |
delete newPos.start; |
| 5387 |
} |
| 5388 |
if ( newPos.end !== undefined ) { |
| 5389 |
if ( direction === 'rtl' ) { |
| 5390 |
newPos.left = newPos.end; |
| 5391 |
} else { |
| 5392 |
newPos.right = ( isBody ? $( $offsetParent[ 0 ].ownerDocument.documentElement ) : |
| 5393 |
$offsetParent ).outerWidth() - newPos.end; |
| 5394 |
} |
| 5395 |
delete newPos.end; |
| 5396 |
} |
| 5397 |
|
| 5398 |
|
| 5399 |
if ( newPos.top !== '' ) { |
| 5400 |
newPos.top += scrollTop; |
| 5401 |
} |
| 5402 |
if ( newPos.bottom !== '' ) { |
| 5403 |
newPos.bottom -= scrollTop; |
| 5404 |
} |
| 5405 |
if ( newPos.left !== '' ) { |
| 5406 |
newPos.left += scrollLeft; |
| 5407 |
} |
| 5408 |
if ( newPos.right !== '' ) { |
| 5409 |
newPos.right -= scrollLeft; |
| 5410 |
} |
| 5411 |
|
| 5412 |
|
| 5413 |
if ( newPos.bottom !== '' ) { |
| 5414 |
newPos.bottom -= horizScrollbarHeight; |
| 5415 |
} |
| 5416 |
if ( direction === 'rtl' ) { |
| 5417 |
if ( newPos.left !== '' ) { |
| 5418 |
newPos.left -= vertScrollbarWidth; |
| 5419 |
} |
| 5420 |
} else { |
| 5421 |
if ( newPos.right !== '' ) { |
| 5422 |
newPos.right -= vertScrollbarWidth; |
| 5423 |
} |
| 5424 |
} |
| 5425 |
|
| 5426 |
return newPos; |
| 5427 |
}; |
| 5428 |
|
| 5429 |
|
| 5430 |
|
| 5431 |
|
| 5432 |
|
| 5433 |
|
| 5434 |
|
| 5435 |
|
| 5436 |
|
| 5437 |
|
| 5438 |
|
| 5439 |
|
| 5440 |
|
| 5441 |
|
| 5442 |
|
| 5443 |
|
| 5444 |
|
| 5445 |
|
| 5446 |
|
| 5447 |
|
| 5448 |
|
| 5449 |
|
| 5450 |
|
| 5451 |
|
| 5452 |
OO.ui.mixin.ClippableElement = function OoUiMixinClippableElement( config ) { |
| 5453 |
|
| 5454 |
config = config || {}; |
| 5455 |
|
| 5456 |
|
| 5457 |
this.$clippable = null; |
| 5458 |
this.$clippableContainer = null; |
| 5459 |
this.clipping = false; |
| 5460 |
this.clippedHorizontally = false; |
| 5461 |
this.clippedVertically = false; |
| 5462 |
this.$clippableScrollableContainer = null; |
| 5463 |
this.$clippableScroller = null; |
| 5464 |
this.$clippableWindow = null; |
| 5465 |
this.idealWidth = null; |
| 5466 |
this.idealHeight = null; |
| 5467 |
this.onClippableScrollHandler = this.clip.bind( this ); |
| 5468 |
this.onClippableWindowResizeHandler = this.clip.bind( this ); |
| 5469 |
|
| 5470 |
|
| 5471 |
if ( config.$clippableContainer ) { |
| 5472 |
this.setClippableContainer( config.$clippableContainer ); |
| 5473 |
} |
| 5474 |
this.setClippableElement( config.$clippable || this.$element ); |
| 5475 |
}; |
| 5476 |
|
| 5477 |
|
| 5478 |
|
| 5479 |
|
| 5480 |
|
| 5481 |
|
| 5482 |
|
| 5483 |
|
| 5484 |
|
| 5485 |
|
| 5486 |
OO.ui.mixin.ClippableElement.prototype.setClippableElement = function ( $clippable ) { |
| 5487 |
if ( this.$clippable ) { |
| 5488 |
this.$clippable.removeClass( 'oo-ui-clippableElement-clippable' ); |
| 5489 |
this.$clippable.css( { width: '', height: '', overflowX: '', overflowY: '' } ); |
| 5490 |
OO.ui.Element.static.reconsiderScrollbars( this.$clippable[ 0 ] ); |
| 5491 |
} |
| 5492 |
|
| 5493 |
this.$clippable = $clippable.addClass( 'oo-ui-clippableElement-clippable' ); |
| 5494 |
this.clip(); |
| 5495 |
}; |
| 5496 |
|
| 5497 |
|
| 5498 |
|
| 5499 |
|
| 5500 |
|
| 5501 |
|
| 5502 |
|
| 5503 |
|
| 5504 |
|
| 5505 |
|
| 5506 |
|
| 5507 |
OO.ui.mixin.ClippableElement.prototype.setClippableContainer = function ( $clippableContainer ) { |
| 5508 |
this.$clippableContainer = $clippableContainer; |
| 5509 |
if ( this.$clippable ) { |
| 5510 |
this.clip(); |
| 5511 |
} |
| 5512 |
}; |
| 5513 |
|
| 5514 |
|
| 5515 |
|
| 5516 |
|
| 5517 |
|
| 5518 |
|
| 5519 |
|
| 5520 |
|
| 5521 |
|
| 5522 |
|
| 5523 |
OO.ui.mixin.ClippableElement.prototype.toggleClipping = function ( clipping ) { |
| 5524 |
clipping = clipping === undefined ? !this.clipping : !!clipping; |
| 5525 |
|
| 5526 |
if ( clipping && !this.warnedUnattached && !this.isElementAttached() ) { |
| 5527 |
OO.ui.warnDeprecation( 'ClippableElement#toggleClipping: Before calling this method, the element must be attached to the DOM.' ); |
| 5528 |
this.warnedUnattached = true; |
| 5529 |
} |
| 5530 |
|
| 5531 |
if ( this.clipping !== clipping ) { |
| 5532 |
this.clipping = clipping; |
| 5533 |
if ( clipping ) { |
| 5534 |
this.$clippableScrollableContainer = $( this.getClosestScrollableElementContainer() ); |
| 5535 |
|
| 5536 |
|
| 5537 |
this.$clippableScroller = this.$clippableScrollableContainer.is( 'html, body' ) ? |
| 5538 |
$( OO.ui.Element.static.getWindow( this.$clippableScrollableContainer ) ) : |
| 5539 |
this.$clippableScrollableContainer; |
| 5540 |
this.$clippableScroller.on( 'scroll', this.onClippableScrollHandler ); |
| 5541 |
this.$clippableWindow = $( this.getElementWindow() ) |
| 5542 |
.on( 'resize', this.onClippableWindowResizeHandler ); |
| 5543 |
|
| 5544 |
this.clip(); |
| 5545 |
} else { |
| 5546 |
this.$clippable.css( { |
| 5547 |
width: '', |
| 5548 |
height: '', |
| 5549 |
maxWidth: '', |
| 5550 |
maxHeight: '', |
| 5551 |
overflowX: '', |
| 5552 |
overflowY: '' |
| 5553 |
} ); |
| 5554 |
OO.ui.Element.static.reconsiderScrollbars( this.$clippable[ 0 ] ); |
| 5555 |
|
| 5556 |
this.$clippableScrollableContainer = null; |
| 5557 |
this.$clippableScroller.off( 'scroll', this.onClippableScrollHandler ); |
| 5558 |
this.$clippableScroller = null; |
| 5559 |
this.$clippableWindow.off( 'resize', this.onClippableWindowResizeHandler ); |
| 5560 |
this.$clippableWindow = null; |
| 5561 |
} |
| 5562 |
} |
| 5563 |
|
| 5564 |
return this; |
| 5565 |
}; |
| 5566 |
|
| 5567 |
|
| 5568 |
|
| 5569 |
|
| 5570 |
|
| 5571 |
|
| 5572 |
OO.ui.mixin.ClippableElement.prototype.isClipping = function () { |
| 5573 |
return this.clipping; |
| 5574 |
}; |
| 5575 |
|
| 5576 |
|
| 5577 |
|
| 5578 |
|
| 5579 |
|
| 5580 |
|
| 5581 |
OO.ui.mixin.ClippableElement.prototype.isClipped = function () { |
| 5582 |
return this.clippedHorizontally || this.clippedVertically; |
| 5583 |
}; |
| 5584 |
|
| 5585 |
|
| 5586 |
|
| 5587 |
|
| 5588 |
|
| 5589 |
|
| 5590 |
OO.ui.mixin.ClippableElement.prototype.isClippedHorizontally = function () { |
| 5591 |
return this.clippedHorizontally; |
| 5592 |
}; |
| 5593 |
|
| 5594 |
|
| 5595 |
|
| 5596 |
|
| 5597 |
|
| 5598 |
|
| 5599 |
OO.ui.mixin.ClippableElement.prototype.isClippedVertically = function () { |
| 5600 |
return this.clippedVertically; |
| 5601 |
}; |
| 5602 |
|
| 5603 |
|
| 5604 |
|
| 5605 |
|
| 5606 |
|
| 5607 |
|
| 5608 |
|
| 5609 |
OO.ui.mixin.ClippableElement.prototype.setIdealSize = function ( width, height ) { |
| 5610 |
this.idealWidth = width; |
| 5611 |
this.idealHeight = height; |
| 5612 |
|
| 5613 |
if ( !this.clipping ) { |
| 5614 |
|
| 5615 |
this.$clippable.css( { width: width, height: height } ); |
| 5616 |
} |
| 5617 |
|
| 5618 |
}; |
| 5619 |
|
| 5620 |
|
| 5621 |
|
| 5622 |
|
| 5623 |
|
| 5624 |
|
| 5625 |
|
| 5626 |
|
| 5627 |
|
| 5628 |
|
| 5629 |
|
| 5630 |
|
| 5631 |
|
| 5632 |
|
| 5633 |
|
| 5634 |
|
| 5635 |
OO.ui.mixin.ClippableElement.prototype.getHorizontalAnchorEdge = function () { |
| 5636 |
if ( this.computePosition && this.positioning && this.computePosition().right !== '' ) { |
| 5637 |
return 'right'; |
| 5638 |
} |
| 5639 |
return 'left'; |
| 5640 |
}; |
| 5641 |
|
| 5642 |
|
| 5643 |
|
| 5644 |
|
| 5645 |
|
| 5646 |
|
| 5647 |
|
| 5648 |
|
| 5649 |
|
| 5650 |
|
| 5651 |
|
| 5652 |
|
| 5653 |
|
| 5654 |
|
| 5655 |
|
| 5656 |
|
| 5657 |
OO.ui.mixin.ClippableElement.prototype.getVerticalAnchorEdge = function () { |
| 5658 |
if ( this.computePosition && this.positioning && this.computePosition().bottom !== '' ) { |
| 5659 |
return 'bottom'; |
| 5660 |
} |
| 5661 |
return 'top'; |
| 5662 |
}; |
| 5663 |
|
| 5664 |
|
| 5665 |
|
| 5666 |
|
| 5667 |
|
| 5668 |
|
| 5669 |
|
| 5670 |
|
| 5671 |
|
| 5672 |
|
| 5673 |
|
| 5674 |
|
| 5675 |
|
| 5676 |
|
| 5677 |
|
| 5678 |
OO.ui.mixin.ClippableElement.prototype.clip = function () { |
| 5679 |
if ( !this.clipping ) { |
| 5680 |
|
| 5681 |
|
| 5682 |
return this; |
| 5683 |
} |
| 5684 |
|
| 5685 |
function rectCopy( rect ) { |
| 5686 |
return { |
| 5687 |
left: rect.left, |
| 5688 |
top: rect.top, |
| 5689 |
right: rect.right, |
| 5690 |
bottom: rect.bottom, |
| 5691 |
x: rect.x, |
| 5692 |
y: rect.y, |
| 5693 |
width: rect.width, |
| 5694 |
height: rect.height |
| 5695 |
}; |
| 5696 |
} |
| 5697 |
|
| 5698 |
function rectIntersection( a, b ) { |
| 5699 |
const out = {}; |
| 5700 |
out.top = Math.max( a.top, b.top ); |
| 5701 |
out.left = Math.max( a.left, b.left ); |
| 5702 |
out.bottom = Math.min( a.bottom, b.bottom ); |
| 5703 |
out.right = Math.min( a.right, b.right ); |
| 5704 |
return out; |
| 5705 |
} |
| 5706 |
|
| 5707 |
const viewportSpacing = OO.ui.getViewportSpacing(); |
| 5708 |
|
| 5709 |
let $viewport, viewportRect; |
| 5710 |
if ( this.$clippableScrollableContainer.is( 'html, body' ) ) { |
| 5711 |
$viewport = $( this.$clippableScrollableContainer[ 0 ].ownerDocument.body ); |
| 5712 |
|
| 5713 |
viewportRect = { |
| 5714 |
top: 0, |
| 5715 |
left: 0, |
| 5716 |
right: document.documentElement.clientWidth, |
| 5717 |
bottom: document.documentElement.clientHeight |
| 5718 |
}; |
| 5719 |
viewportRect.top += viewportSpacing.top; |
| 5720 |
viewportRect.left += viewportSpacing.left; |
| 5721 |
viewportRect.right -= viewportSpacing.right; |
| 5722 |
viewportRect.bottom -= viewportSpacing.bottom; |
| 5723 |
} else { |
| 5724 |
$viewport = this.$clippableScrollableContainer; |
| 5725 |
viewportRect = $viewport[ 0 ].getBoundingClientRect(); |
| 5726 |
|
| 5727 |
viewportRect = rectCopy( viewportRect ); |
| 5728 |
} |
| 5729 |
|
| 5730 |
|
| 5731 |
const direction = $viewport.css( 'direction' ); |
| 5732 |
const vertScrollbarWidth = $viewport.innerWidth() - $viewport.prop( 'clientWidth' ); |
| 5733 |
const horizScrollbarHeight = $viewport.innerHeight() - $viewport.prop( 'clientHeight' ); |
| 5734 |
viewportRect.bottom -= horizScrollbarHeight; |
| 5735 |
if ( direction === 'rtl' ) { |
| 5736 |
viewportRect.left += vertScrollbarWidth; |
| 5737 |
} else { |
| 5738 |
viewportRect.right -= vertScrollbarWidth; |
| 5739 |
} |
| 5740 |
|
| 5741 |
|
| 5742 |
|
| 5743 |
|
| 5744 |
const buffer = 7; |
| 5745 |
viewportRect.top += buffer; |
| 5746 |
viewportRect.left += buffer; |
| 5747 |
viewportRect.right -= buffer; |
| 5748 |
viewportRect.bottom -= buffer; |
| 5749 |
|
| 5750 |
const $item = this.$clippableContainer || this.$clippable; |
| 5751 |
|
| 5752 |
const extraHeight = $item.outerHeight() - this.$clippable.outerHeight(); |
| 5753 |
const extraWidth = $item.outerWidth() - this.$clippable.outerWidth(); |
| 5754 |
|
| 5755 |
let itemRect = $item[ 0 ].getBoundingClientRect(); |
| 5756 |
|
| 5757 |
itemRect = rectCopy( itemRect ); |
| 5758 |
|
| 5759 |
|
| 5760 |
|
| 5761 |
if ( this.getHorizontalAnchorEdge() === 'right' ) { |
| 5762 |
itemRect.left = viewportRect.left; |
| 5763 |
} else { |
| 5764 |
itemRect.right = viewportRect.right; |
| 5765 |
} |
| 5766 |
if ( this.getVerticalAnchorEdge() === 'bottom' ) { |
| 5767 |
itemRect.top = viewportRect.top; |
| 5768 |
} else { |
| 5769 |
itemRect.bottom = viewportRect.bottom; |
| 5770 |
} |
| 5771 |
|
| 5772 |
const availableRect = rectIntersection( viewportRect, itemRect ); |
| 5773 |
|
| 5774 |
let desiredWidth = Math.max( 0, availableRect.right - availableRect.left ); |
| 5775 |
let desiredHeight = Math.max( 0, availableRect.bottom - availableRect.top ); |
| 5776 |
|
| 5777 |
desiredWidth = Math.min( desiredWidth, |
| 5778 |
document.documentElement.clientWidth - viewportSpacing.left - viewportSpacing.right ); |
| 5779 |
desiredHeight = Math.min( desiredHeight, |
| 5780 |
document.documentElement.clientHeight - viewportSpacing.top - viewportSpacing.right ); |
| 5781 |
const allotedWidth = Math.ceil( desiredWidth - extraWidth ); |
| 5782 |
const allotedHeight = Math.ceil( desiredHeight - extraHeight ); |
| 5783 |
const naturalWidth = this.$clippable.prop( 'scrollWidth' ); |
| 5784 |
const naturalHeight = this.$clippable.prop( 'scrollHeight' ); |
| 5785 |
const clipWidth = allotedWidth < naturalWidth; |
| 5786 |
const clipHeight = allotedHeight < naturalHeight; |
| 5787 |
|
| 5788 |
if ( clipWidth ) { |
| 5789 |
|
| 5790 |
|
| 5791 |
|
| 5792 |
|
| 5793 |
|
| 5794 |
|
| 5795 |
|
| 5796 |
this.$clippable.css( 'overflowX', 'scroll' ); |
| 5797 |
|
| 5798 |
this.$clippable[ 0 ].offsetHeight; |
| 5799 |
|
| 5800 |
|
| 5801 |
this.$clippable.css( 'overflowX', 'auto' ); |
| 5802 |
|
| 5803 |
this.$clippable[ 0 ].offsetHeight; |
| 5804 |
this.$clippable.css( { |
| 5805 |
width: Math.max( 0, allotedWidth ), |
| 5806 |
maxWidth: '' |
| 5807 |
} ); |
| 5808 |
} else { |
| 5809 |
this.$clippable.css( { |
| 5810 |
overflowX: '', |
| 5811 |
width: this.idealWidth || '', |
| 5812 |
maxWidth: Math.max( 0, allotedWidth ) |
| 5813 |
} ); |
| 5814 |
} |
| 5815 |
if ( clipHeight ) { |
| 5816 |
|
| 5817 |
|
| 5818 |
|
| 5819 |
|
| 5820 |
|
| 5821 |
|
| 5822 |
|
| 5823 |
this.$clippable.css( 'overflowY', 'scroll' ); |
| 5824 |
|
| 5825 |
this.$clippable[ 0 ].offsetHeight; |
| 5826 |
|
| 5827 |
|
| 5828 |
this.$clippable.css( 'overflowY', 'auto' ); |
| 5829 |
|
| 5830 |
this.$clippable[ 0 ].offsetHeight; |
| 5831 |
this.$clippable.css( { |
| 5832 |
height: Math.max( 0, allotedHeight ), |
| 5833 |
maxHeight: '' |
| 5834 |
} ); |
| 5835 |
} else { |
| 5836 |
this.$clippable.css( { |
| 5837 |
overflowY: '', |
| 5838 |
height: this.idealHeight || '', |
| 5839 |
maxHeight: Math.max( 0, allotedHeight ) |
| 5840 |
} ); |
| 5841 |
} |
| 5842 |
|
| 5843 |
|
| 5844 |
if ( ( this.clippedHorizontally && !clipWidth ) || ( this.clippedVertically && !clipHeight ) ) { |
| 5845 |
OO.ui.Element.static.reconsiderScrollbars( this.$clippable[ 0 ] ); |
| 5846 |
} |
| 5847 |
|
| 5848 |
this.clippedHorizontally = clipWidth; |
| 5849 |
this.clippedVertically = clipHeight; |
| 5850 |
|
| 5851 |
return this; |
| 5852 |
}; |
| 5853 |
|
| 5854 |
|
| 5855 |
|
| 5856 |
|
| 5857 |
|
| 5858 |
|
| 5859 |
|
| 5860 |
|
| 5861 |
|
| 5862 |
|
| 5863 |
|
| 5864 |
|
| 5865 |
|
| 5866 |
|
| 5867 |
|
| 5868 |
|
| 5869 |
|
| 5870 |
|
| 5871 |
|
| 5872 |
|
| 5873 |
|
| 5874 |
|
| 5875 |
|
| 5876 |
|
| 5877 |
|
| 5878 |
|
| 5879 |
|
| 5880 |
|
| 5881 |
|
| 5882 |
|
| 5883 |
|
| 5884 |
|
| 5885 |
|
| 5886 |
|
| 5887 |
|
| 5888 |
|
| 5889 |
|
| 5890 |
|
| 5891 |
|
| 5892 |
|
| 5893 |
|
| 5894 |
|
| 5895 |
|
| 5896 |
|
| 5897 |
|
| 5898 |
|
| 5899 |
|
| 5900 |
|
| 5901 |
|
| 5902 |
|
| 5903 |
|
| 5904 |
|
| 5905 |
|
| 5906 |
|
| 5907 |
|
| 5908 |
|
| 5909 |
|
| 5910 |
|
| 5911 |
|
| 5912 |
|
| 5913 |
|
| 5914 |
|
| 5915 |
|
| 5916 |
|
| 5917 |
|
| 5918 |
|
| 5919 |
|
| 5920 |
|
| 5921 |
|
| 5922 |
|
| 5923 |
|
| 5924 |
|
| 5925 |
|
| 5926 |
|
| 5927 |
OO.ui.PopupWidget = function OoUiPopupWidget( config ) { |
| 5928 |
|
| 5929 |
config = config || {}; |
| 5930 |
|
| 5931 |
|
| 5932 |
OO.ui.PopupWidget.super.call( this, config ); |
| 5933 |
|
| 5934 |
|
| 5935 |
this.$body = $( '<div>' ); |
| 5936 |
this.$popup = $( '<div>' ); |
| 5937 |
|
| 5938 |
|
| 5939 |
OO.ui.mixin.IconElement.call( this, config ); |
| 5940 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 5941 |
OO.ui.mixin.ClippableElement.call( this, Object.assign( { |
| 5942 |
$clippable: this.$body, |
| 5943 |
$clippableContainer: this.$popup |
| 5944 |
}, config ) ); |
| 5945 |
OO.ui.mixin.FloatableElement.call( this, config ); |
| 5946 |
|
| 5947 |
|
| 5948 |
this.$anchor = $( '<div>' ); |
| 5949 |
|
| 5950 |
this.$container = config.$container; |
| 5951 |
this.containerPadding = config.containerPadding !== undefined ? config.containerPadding : 10; |
| 5952 |
this.autoClose = !!config.autoClose; |
| 5953 |
this.transitionTimeout = null; |
| 5954 |
this.anchored = false; |
| 5955 |
this.onDocumentMouseDownHandler = this.onDocumentMouseDown.bind( this ); |
| 5956 |
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this ); |
| 5957 |
this.onTabKeyDownHandler = this.onTabKeyDown.bind( this ); |
| 5958 |
this.onShiftTabKeyDownHandler = this.onShiftTabKeyDown.bind( this ); |
| 5959 |
|
| 5960 |
|
| 5961 |
this.setSize( config.width, config.height ); |
| 5962 |
this.toggleAnchor( config.anchor === undefined || config.anchor ); |
| 5963 |
this.setAlignment( config.align || 'center' ); |
| 5964 |
this.setPosition( config.position || 'below' ); |
| 5965 |
this.setAutoFlip( config.autoFlip === undefined || config.autoFlip ); |
| 5966 |
this.setAutoCloseIgnore( config.$autoCloseIgnore ); |
| 5967 |
this.$body.addClass( 'oo-ui-popupWidget-body' ); |
| 5968 |
this.$anchor.addClass( 'oo-ui-popupWidget-anchor' ); |
| 5969 |
this.$popup |
| 5970 |
.addClass( 'oo-ui-popupWidget-popup' ) |
| 5971 |
.append( this.$body ); |
| 5972 |
this.$element |
| 5973 |
.addClass( 'oo-ui-popupWidget' ) |
| 5974 |
.append( this.$popup, this.$anchor ); |
| 5975 |
|
| 5976 |
|
| 5977 |
if ( config.$content instanceof $ ) { |
| 5978 |
this.$body.append( config.$content ); |
| 5979 |
} |
| 5980 |
|
| 5981 |
this.padded = !!config.padded; |
| 5982 |
if ( config.padded ) { |
| 5983 |
this.$body.addClass( 'oo-ui-popupWidget-body-padded' ); |
| 5984 |
} |
| 5985 |
|
| 5986 |
if ( config.head ) { |
| 5987 |
if ( !config.hideCloseButton ) { |
| 5988 |
this.closeButton = new OO.ui.ButtonWidget( { |
| 5989 |
framed: false, |
| 5990 |
icon: 'close', |
| 5991 |
label: OO.ui.msg( 'ooui-popup-widget-close-button-aria-label' ), |
| 5992 |
invisibleLabel: true |
| 5993 |
} ); |
| 5994 |
this.closeButton.connect( this, { |
| 5995 |
click: 'onCloseButtonClick' |
| 5996 |
} ); |
| 5997 |
} |
| 5998 |
this.$head = $( '<div>' ) |
| 5999 |
.addClass( 'oo-ui-popupWidget-head' ) |
| 6000 |
.append( this.$icon, this.$label, this.closeButton && this.closeButton.$element ); |
| 6001 |
this.$popup.prepend( this.$head ); |
| 6002 |
} |
| 6003 |
|
| 6004 |
if ( config.$footer ) { |
| 6005 |
this.$footer = $( '<div>' ) |
| 6006 |
.addClass( 'oo-ui-popupWidget-footer' ) |
| 6007 |
.append( config.$footer ); |
| 6008 |
this.$popup.append( this.$footer ); |
| 6009 |
} |
| 6010 |
|
| 6011 |
|
| 6012 |
|
| 6013 |
|
| 6014 |
this.visible = false; |
| 6015 |
this.$element.addClass( 'oo-ui-element-hidden' ); |
| 6016 |
}; |
| 6017 |
|
| 6018 |
|
| 6019 |
|
| 6020 |
OO.inheritClass( OO.ui.PopupWidget, OO.ui.Widget ); |
| 6021 |
OO.mixinClass( OO.ui.PopupWidget, OO.ui.mixin.IconElement ); |
| 6022 |
OO.mixinClass( OO.ui.PopupWidget, OO.ui.mixin.LabelElement ); |
| 6023 |
OO.mixinClass( OO.ui.PopupWidget, OO.ui.mixin.ClippableElement ); |
| 6024 |
OO.mixinClass( OO.ui.PopupWidget, OO.ui.mixin.FloatableElement ); |
| 6025 |
|
| 6026 |
|
| 6027 |
|
| 6028 |
|
| 6029 |
|
| 6030 |
|
| 6031 |
|
| 6032 |
|
| 6033 |
|
| 6034 |
|
| 6035 |
|
| 6036 |
|
| 6037 |
|
| 6038 |
|
| 6039 |
|
| 6040 |
|
| 6041 |
|
| 6042 |
|
| 6043 |
|
| 6044 |
|
| 6045 |
|
| 6046 |
|
| 6047 |
|
| 6048 |
OO.ui.PopupWidget.prototype.onDocumentMouseDown = function ( e ) { |
| 6049 |
if ( |
| 6050 |
this.isVisible() && |
| 6051 |
!OO.ui.contains( this.$element.add( this.$autoCloseIgnore ).get(), e.target, true ) |
| 6052 |
) { |
| 6053 |
this.toggle( false ); |
| 6054 |
} |
| 6055 |
}; |
| 6056 |
|
| 6057 |
|
| 6058 |
|
| 6059 |
|
| 6060 |
|
| 6061 |
|
| 6062 |
OO.ui.PopupWidget.prototype.bindDocumentMouseDownListener = function () { |
| 6063 |
|
| 6064 |
this.getElementDocument().addEventListener( 'mousedown', this.onDocumentMouseDownHandler, true ); |
| 6065 |
|
| 6066 |
|
| 6067 |
|
| 6068 |
|
| 6069 |
|
| 6070 |
|
| 6071 |
this.getElementDocument().addEventListener( 'click', this.onDocumentMouseDownHandler, true ); |
| 6072 |
}; |
| 6073 |
|
| 6074 |
|
| 6075 |
|
| 6076 |
|
| 6077 |
|
| 6078 |
|
| 6079 |
OO.ui.PopupWidget.prototype.onCloseButtonClick = function () { |
| 6080 |
if ( this.isVisible() ) { |
| 6081 |
this.toggle( false ); |
| 6082 |
} |
| 6083 |
}; |
| 6084 |
|
| 6085 |
|
| 6086 |
|
| 6087 |
|
| 6088 |
|
| 6089 |
|
| 6090 |
OO.ui.PopupWidget.prototype.unbindDocumentMouseDownListener = function () { |
| 6091 |
this.getElementDocument().removeEventListener( 'mousedown', this.onDocumentMouseDownHandler, true ); |
| 6092 |
this.getElementDocument().removeEventListener( 'click', this.onDocumentMouseDownHandler, true ); |
| 6093 |
}; |
| 6094 |
|
| 6095 |
|
| 6096 |
|
| 6097 |
|
| 6098 |
|
| 6099 |
|
| 6100 |
|
| 6101 |
OO.ui.PopupWidget.prototype.onDocumentKeyDown = function ( e ) { |
| 6102 |
if ( |
| 6103 |
e.which === OO.ui.Keys.ESCAPE && |
| 6104 |
this.isVisible() |
| 6105 |
) { |
| 6106 |
this.toggle( false ); |
| 6107 |
e.preventDefault(); |
| 6108 |
e.stopPropagation(); |
| 6109 |
} |
| 6110 |
}; |
| 6111 |
|
| 6112 |
|
| 6113 |
|
| 6114 |
|
| 6115 |
|
| 6116 |
|
| 6117 |
OO.ui.PopupWidget.prototype.bindDocumentKeyDownListener = function () { |
| 6118 |
this.getElementDocument().addEventListener( 'keydown', this.onDocumentKeyDownHandler, true ); |
| 6119 |
}; |
| 6120 |
|
| 6121 |
|
| 6122 |
|
| 6123 |
|
| 6124 |
|
| 6125 |
|
| 6126 |
OO.ui.PopupWidget.prototype.unbindDocumentKeyDownListener = function () { |
| 6127 |
this.getElementDocument().removeEventListener( 'keydown', this.onDocumentKeyDownHandler, true ); |
| 6128 |
}; |
| 6129 |
|
| 6130 |
|
| 6131 |
|
| 6132 |
|
| 6133 |
|
| 6134 |
|
| 6135 |
|
| 6136 |
OO.ui.PopupWidget.prototype.onTabKeyDown = function ( e ) { |
| 6137 |
if ( !e.shiftKey && e.which === OO.ui.Keys.TAB ) { |
| 6138 |
e.preventDefault(); |
| 6139 |
this.toggle( false ); |
| 6140 |
} |
| 6141 |
}; |
| 6142 |
|
| 6143 |
|
| 6144 |
|
| 6145 |
|
| 6146 |
|
| 6147 |
|
| 6148 |
|
| 6149 |
OO.ui.PopupWidget.prototype.onShiftTabKeyDown = function ( e ) { |
| 6150 |
if ( e.shiftKey && e.which === OO.ui.Keys.TAB ) { |
| 6151 |
e.preventDefault(); |
| 6152 |
this.toggle( false ); |
| 6153 |
} |
| 6154 |
}; |
| 6155 |
|
| 6156 |
|
| 6157 |
|
| 6158 |
|
| 6159 |
|
| 6160 |
|
| 6161 |
OO.ui.PopupWidget.prototype.toggleAnchor = function ( show ) { |
| 6162 |
show = show === undefined ? !this.anchored : !!show; |
| 6163 |
|
| 6164 |
if ( this.anchored !== show ) { |
| 6165 |
this.$element.toggleClass( 'oo-ui-popupWidget-anchored oo-ui-popupWidget-anchored-' + this.anchorEdge, show ); |
| 6166 |
this.anchored = show; |
| 6167 |
} |
| 6168 |
}; |
| 6169 |
|
| 6170 |
|
| 6171 |
|
| 6172 |
|
| 6173 |
|
| 6174 |
|
| 6175 |
OO.ui.PopupWidget.prototype.setAnchorEdge = function ( edge ) { |
| 6176 |
if ( [ 'top', 'bottom', 'start', 'end' ].indexOf( edge ) === -1 ) { |
| 6177 |
throw new Error( 'Invalid value for edge: ' + edge ); |
| 6178 |
} |
| 6179 |
if ( this.anchorEdge !== null ) { |
| 6180 |
this.$element.removeClass( 'oo-ui-popupWidget-anchored-' + this.anchorEdge ); |
| 6181 |
} |
| 6182 |
this.anchorEdge = edge; |
| 6183 |
if ( this.anchored ) { |
| 6184 |
this.$element.addClass( 'oo-ui-popupWidget-anchored-' + edge ); |
| 6185 |
} |
| 6186 |
}; |
| 6187 |
|
| 6188 |
|
| 6189 |
|
| 6190 |
|
| 6191 |
|
| 6192 |
|
| 6193 |
OO.ui.PopupWidget.prototype.hasAnchor = function () { |
| 6194 |
return this.anchored; |
| 6195 |
}; |
| 6196 |
|
| 6197 |
|
| 6198 |
|
| 6199 |
|
| 6200 |
|
| 6201 |
|
| 6202 |
|
| 6203 |
|
| 6204 |
|
| 6205 |
|
| 6206 |
|
| 6207 |
|
| 6208 |
|
| 6209 |
OO.ui.PopupWidget.prototype.toggle = function ( show ) { |
| 6210 |
show = show === undefined ? !this.isVisible() : !!show; |
| 6211 |
|
| 6212 |
const change = show !== this.isVisible(); |
| 6213 |
|
| 6214 |
if ( show && !this.warnedUnattached && !this.isElementAttached() ) { |
| 6215 |
OO.ui.warnDeprecation( 'PopupWidget#toggle: Before calling this method, the popup must be attached to the DOM.' ); |
| 6216 |
this.warnedUnattached = true; |
| 6217 |
} |
| 6218 |
if ( show && !this.$floatableContainer && this.isElementAttached() ) { |
| 6219 |
|
| 6220 |
this.setFloatableContainer( this.$element.parent() ); |
| 6221 |
} |
| 6222 |
|
| 6223 |
if ( change && show && this.autoFlip ) { |
| 6224 |
|
| 6225 |
|
| 6226 |
this.isAutoFlipped = false; |
| 6227 |
} |
| 6228 |
|
| 6229 |
|
| 6230 |
OO.ui.PopupWidget.super.prototype.toggle.call( this, show ); |
| 6231 |
|
| 6232 |
if ( change ) { |
| 6233 |
this.togglePositioning( show && !!this.$floatableContainer ); |
| 6234 |
|
| 6235 |
|
| 6236 |
const $lastFocusableElement = OO.ui.findFocusable( this.$element, true ); |
| 6237 |
const $firstFocusableElement = OO.ui.findFocusable( this.$element, false ); |
| 6238 |
|
| 6239 |
if ( show ) { |
| 6240 |
if ( this.autoClose ) { |
| 6241 |
this.bindDocumentMouseDownListener(); |
| 6242 |
this.bindDocumentKeyDownListener(); |
| 6243 |
|
| 6244 |
|
| 6245 |
|
| 6246 |
|
| 6247 |
|
| 6248 |
|
| 6249 |
$lastFocusableElement.on( 'keydown', this.onTabKeyDownHandler ); |
| 6250 |
$firstFocusableElement.on( 'keydown', this.onShiftTabKeyDownHandler ); |
| 6251 |
} |
| 6252 |
this.updateDimensions(); |
| 6253 |
this.toggleClipping( true ); |
| 6254 |
|
| 6255 |
if ( this.autoFlip ) { |
| 6256 |
if ( this.popupPosition === 'above' || this.popupPosition === 'below' ) { |
| 6257 |
if ( this.isClippedVertically() || this.isFloatableOutOfView() ) { |
| 6258 |
|
| 6259 |
|
| 6260 |
const normalHeight = this.$element.height(); |
| 6261 |
this.isAutoFlipped = !this.isAutoFlipped; |
| 6262 |
this.position(); |
| 6263 |
if ( this.isClippedVertically() || this.isFloatableOutOfView() ) { |
| 6264 |
|
| 6265 |
|
| 6266 |
const oppositeHeight = this.$element.height(); |
| 6267 |
if ( oppositeHeight < normalHeight ) { |
| 6268 |
this.isAutoFlipped = !this.isAutoFlipped; |
| 6269 |
this.position(); |
| 6270 |
} |
| 6271 |
} |
| 6272 |
} |
| 6273 |
} |
| 6274 |
if ( this.popupPosition === 'before' || this.popupPosition === 'after' ) { |
| 6275 |
if ( this.isClippedHorizontally() || this.isFloatableOutOfView() ) { |
| 6276 |
|
| 6277 |
|
| 6278 |
const normalWidth = this.$element.width(); |
| 6279 |
this.isAutoFlipped = !this.isAutoFlipped; |
| 6280 |
|
| 6281 |
|
| 6282 |
|
| 6283 |
this.toggleClipping( false ); |
| 6284 |
this.position(); |
| 6285 |
this.toggleClipping( true ); |
| 6286 |
if ( this.isClippedHorizontally() || this.isFloatableOutOfView() ) { |
| 6287 |
|
| 6288 |
|
| 6289 |
const oppositeWidth = this.$element.width(); |
| 6290 |
if ( oppositeWidth < normalWidth ) { |
| 6291 |
this.isAutoFlipped = !this.isAutoFlipped; |
| 6292 |
|
| 6293 |
|
| 6294 |
|
| 6295 |
this.toggleClipping( false ); |
| 6296 |
this.position(); |
| 6297 |
this.toggleClipping( true ); |
| 6298 |
} |
| 6299 |
} |
| 6300 |
} |
| 6301 |
} |
| 6302 |
} |
| 6303 |
|
| 6304 |
this.emit( 'ready' ); |
| 6305 |
} else { |
| 6306 |
this.toggleClipping( false ); |
| 6307 |
if ( this.autoClose ) { |
| 6308 |
|
| 6309 |
|
| 6310 |
$lastFocusableElement.off( 'keydown', this.onTabKeyDownHandler ); |
| 6311 |
$firstFocusableElement.off( 'keydown', this.onShiftTabKeyDownHandler ); |
| 6312 |
|
| 6313 |
this.unbindDocumentMouseDownListener(); |
| 6314 |
this.unbindDocumentKeyDownListener(); |
| 6315 |
} |
| 6316 |
|
| 6317 |
|
| 6318 |
|
| 6319 |
|
| 6320 |
|
| 6321 |
this.emit( 'closing' ); |
| 6322 |
} |
| 6323 |
} |
| 6324 |
|
| 6325 |
return this; |
| 6326 |
}; |
| 6327 |
|
| 6328 |
|
| 6329 |
|
| 6330 |
|
| 6331 |
|
| 6332 |
|
| 6333 |
|
| 6334 |
|
| 6335 |
|
| 6336 |
|
| 6337 |
|
| 6338 |
OO.ui.PopupWidget.prototype.setSize = function ( width, height, transition ) { |
| 6339 |
this.width = width !== undefined ? width : 320; |
| 6340 |
this.height = height !== undefined ? height : null; |
| 6341 |
if ( this.isVisible() ) { |
| 6342 |
this.updateDimensions( transition ); |
| 6343 |
} |
| 6344 |
}; |
| 6345 |
|
| 6346 |
|
| 6347 |
|
| 6348 |
|
| 6349 |
|
| 6350 |
|
| 6351 |
|
| 6352 |
|
| 6353 |
|
| 6354 |
|
| 6355 |
OO.ui.PopupWidget.prototype.updateDimensions = function ( transition ) { |
| 6356 |
|
| 6357 |
clearTimeout( this.transitionTimeout ); |
| 6358 |
if ( transition ) { |
| 6359 |
|
| 6360 |
this.$element.addClass( 'oo-ui-popupWidget-transitioning' ); |
| 6361 |
} |
| 6362 |
|
| 6363 |
this.position(); |
| 6364 |
|
| 6365 |
if ( transition ) { |
| 6366 |
|
| 6367 |
this.transitionTimeout = setTimeout( () => { |
| 6368 |
this.$element.removeClass( 'oo-ui-popupWidget-transitioning' ); |
| 6369 |
}, 200 ); |
| 6370 |
} else { |
| 6371 |
|
| 6372 |
this.$element.removeClass( 'oo-ui-popupWidget-transitioning' ); |
| 6373 |
} |
| 6374 |
}; |
| 6375 |
|
| 6376 |
|
| 6377 |
|
| 6378 |
|
| 6379 |
OO.ui.PopupWidget.prototype.computePosition = function () { |
| 6380 |
const popupPos = {}, |
| 6381 |
anchorCss = { left: '', right: '', top: '', bottom: '' }, |
| 6382 |
popupPositionOppositeMap = { |
| 6383 |
above: 'below', |
| 6384 |
below: 'above', |
| 6385 |
before: 'after', |
| 6386 |
after: 'before' |
| 6387 |
}, |
| 6388 |
alignMap = { |
| 6389 |
ltr: { |
| 6390 |
'force-left': 'backwards', |
| 6391 |
'force-right': 'forwards' |
| 6392 |
}, |
| 6393 |
rtl: { |
| 6394 |
'force-left': 'forwards', |
| 6395 |
'force-right': 'backwards' |
| 6396 |
} |
| 6397 |
}, |
| 6398 |
anchorEdgeMap = { |
| 6399 |
above: 'bottom', |
| 6400 |
below: 'top', |
| 6401 |
before: 'end', |
| 6402 |
after: 'start' |
| 6403 |
}, |
| 6404 |
hPosMap = { |
| 6405 |
forwards: 'start', |
| 6406 |
center: 'center', |
| 6407 |
backwards: this.anchored ? 'before' : 'end' |
| 6408 |
}, |
| 6409 |
vPosMap = { |
| 6410 |
forwards: 'top', |
| 6411 |
center: 'center', |
| 6412 |
backwards: 'bottom' |
| 6413 |
}; |
| 6414 |
|
| 6415 |
if ( !this.$container ) { |
| 6416 |
|
| 6417 |
this.$container = $( this.getClosestScrollableElementContainer() ); |
| 6418 |
} |
| 6419 |
const direction = this.$container.css( 'direction' ); |
| 6420 |
|
| 6421 |
|
| 6422 |
|
| 6423 |
this.setIdealSize( |
| 6424 |
|
| 6425 |
|
| 6426 |
this.width !== null ? this.width - ( this.padded ? 24 : 0 ) : 'auto', |
| 6427 |
this.height !== null ? this.height - ( this.padded ? 10 : 0 ) : 'auto' |
| 6428 |
); |
| 6429 |
|
| 6430 |
const align = alignMap[ direction ][ this.align ] || this.align; |
| 6431 |
let popupPosition = this.popupPosition; |
| 6432 |
if ( this.isAutoFlipped ) { |
| 6433 |
popupPosition = popupPositionOppositeMap[ popupPosition ]; |
| 6434 |
} |
| 6435 |
|
| 6436 |
|
| 6437 |
|
| 6438 |
const vertical = popupPosition === 'before' || popupPosition === 'after'; |
| 6439 |
const start = vertical ? 'top' : ( direction === 'rtl' ? 'right' : 'left' ); |
| 6440 |
const end = vertical ? 'bottom' : ( direction === 'rtl' ? 'left' : 'right' ); |
| 6441 |
const near = vertical ? 'top' : 'left'; |
| 6442 |
const far = vertical ? 'bottom' : 'right'; |
| 6443 |
const sizeProp = vertical ? 'Height' : 'Width'; |
| 6444 |
const popupSize = vertical ? this.$popup.height() : this.$popup.width(); |
| 6445 |
|
| 6446 |
this.setAnchorEdge( anchorEdgeMap[ popupPosition ] ); |
| 6447 |
this.horizontalPosition = vertical ? popupPosition : hPosMap[ align ]; |
| 6448 |
this.verticalPosition = vertical ? vPosMap[ align ] : popupPosition; |
| 6449 |
|
| 6450 |
|
| 6451 |
const parentPosition = OO.ui.mixin.FloatableElement.prototype.computePosition.call( this ); |
| 6452 |
|
| 6453 |
const positionProp = vertical ? |
| 6454 |
( parentPosition.top !== '' ? 'top' : 'bottom' ) : |
| 6455 |
( parentPosition.left !== '' ? 'left' : 'right' ); |
| 6456 |
|
| 6457 |
|
| 6458 |
const floatablePos = this.$floatableContainer.offset(); |
| 6459 |
floatablePos[ far ] = floatablePos[ near ] + this.$floatableContainer[ 'outer' + sizeProp ](); |
| 6460 |
|
| 6461 |
const offsetParentPos = this.$element.offsetParent()[ 0 ] === document.documentElement ? |
| 6462 |
{ top: 0, left: 0 } : |
| 6463 |
this.$element.offsetParent().offset(); |
| 6464 |
|
| 6465 |
if ( positionProp === near ) { |
| 6466 |
popupPos[ near ] = offsetParentPos[ near ] + parentPosition[ near ]; |
| 6467 |
popupPos[ far ] = popupPos[ near ] + popupSize; |
| 6468 |
} else { |
| 6469 |
popupPos[ far ] = offsetParentPos[ near ] + |
| 6470 |
this.$element.offsetParent()[ 'inner' + sizeProp ]() - parentPosition[ far ]; |
| 6471 |
popupPos[ near ] = popupPos[ far ] - popupSize; |
| 6472 |
} |
| 6473 |
|
| 6474 |
let anchorOffset, positionAdjustment; |
| 6475 |
if ( this.anchored ) { |
| 6476 |
|
| 6477 |
|
| 6478 |
const anchorPos = ( floatablePos[ start ] + floatablePos[ end ] ) / 2; |
| 6479 |
anchorOffset = ( start === far ? -1 : 1 ) * ( anchorPos - popupPos[ start ] ); |
| 6480 |
|
| 6481 |
|
| 6482 |
|
| 6483 |
|
| 6484 |
const anchorSize = this.$anchor[ 0 ][ 'scroll' + sizeProp ]; |
| 6485 |
const anchorMargin = parseFloat( this.$anchor.css( 'margin-' + start ) ); |
| 6486 |
if ( anchorOffset + anchorMargin < 2 * anchorSize ) { |
| 6487 |
|
| 6488 |
positionAdjustment = ( positionProp === start ? -1 : 1 ) * |
| 6489 |
( 2 * anchorSize - ( anchorOffset + anchorMargin ) ); |
| 6490 |
} else if ( anchorOffset + anchorMargin > popupSize - 2 * anchorSize ) { |
| 6491 |
|
| 6492 |
positionAdjustment = ( positionProp === end ? -1 : 1 ) * |
| 6493 |
( anchorOffset + anchorMargin - ( popupSize - 2 * anchorSize ) ); |
| 6494 |
} else { |
| 6495 |
positionAdjustment = 0; |
| 6496 |
} |
| 6497 |
} else { |
| 6498 |
positionAdjustment = 0; |
| 6499 |
} |
| 6500 |
|
| 6501 |
|
| 6502 |
const containerPos = this.$container[ 0 ] === document.documentElement ? |
| 6503 |
{ top: 0, left: 0 } : |
| 6504 |
this.$container.offset(); |
| 6505 |
containerPos[ far ] = containerPos[ near ] + this.$container[ 'inner' + sizeProp ](); |
| 6506 |
if ( this.$container[ 0 ] === document.documentElement ) { |
| 6507 |
const viewportSpacing = OO.ui.getViewportSpacing(); |
| 6508 |
containerPos[ near ] += viewportSpacing[ near ]; |
| 6509 |
containerPos[ far ] -= viewportSpacing[ far ]; |
| 6510 |
} |
| 6511 |
|
| 6512 |
popupPos[ near ] += ( positionProp === near ? 1 : -1 ) * positionAdjustment; |
| 6513 |
popupPos[ far ] += ( positionProp === near ? 1 : -1 ) * positionAdjustment; |
| 6514 |
if ( containerPos[ near ] + this.containerPadding > popupPos[ near ] ) { |
| 6515 |
|
| 6516 |
positionAdjustment += ( positionProp === near ? 1 : -1 ) * |
| 6517 |
( containerPos[ near ] + this.containerPadding - popupPos[ near ] ); |
| 6518 |
} else if ( containerPos[ far ] - this.containerPadding < popupPos[ far ] ) { |
| 6519 |
|
| 6520 |
positionAdjustment += ( positionProp === far ? 1 : -1 ) * |
| 6521 |
( popupPos[ far ] - ( containerPos[ far ] - this.containerPadding ) ); |
| 6522 |
} |
| 6523 |
|
| 6524 |
if ( this.anchored ) { |
| 6525 |
|
| 6526 |
anchorOffset += ( positionProp === start ? -1 : 1 ) * positionAdjustment; |
| 6527 |
|
| 6528 |
|
| 6529 |
anchorCss[ start ] = anchorOffset; |
| 6530 |
this.$anchor.css( anchorCss ); |
| 6531 |
} |
| 6532 |
|
| 6533 |
|
| 6534 |
parentPosition[ positionProp ] += positionAdjustment; |
| 6535 |
|
| 6536 |
return parentPosition; |
| 6537 |
}; |
| 6538 |
|
| 6539 |
|
| 6540 |
|
| 6541 |
|
| 6542 |
|
| 6543 |
|
| 6544 |
|
| 6545 |
OO.ui.PopupWidget.prototype.setAlignment = function ( align ) { |
| 6546 |
|
| 6547 |
if ( [ 'force-left', 'force-right', 'backwards', 'forwards', 'center' ].indexOf( align ) > -1 ) { |
| 6548 |
this.align = align; |
| 6549 |
} else { |
| 6550 |
this.align = 'center'; |
| 6551 |
} |
| 6552 |
this.position(); |
| 6553 |
}; |
| 6554 |
|
| 6555 |
|
| 6556 |
|
| 6557 |
|
| 6558 |
|
| 6559 |
|
| 6560 |
|
| 6561 |
OO.ui.PopupWidget.prototype.getAlignment = function () { |
| 6562 |
return this.align; |
| 6563 |
}; |
| 6564 |
|
| 6565 |
|
| 6566 |
|
| 6567 |
|
| 6568 |
|
| 6569 |
|
| 6570 |
OO.ui.PopupWidget.prototype.setPosition = function ( position ) { |
| 6571 |
if ( [ 'above', 'below', 'before', 'after' ].indexOf( position ) === -1 ) { |
| 6572 |
position = 'below'; |
| 6573 |
} |
| 6574 |
this.popupPosition = position; |
| 6575 |
this.position(); |
| 6576 |
}; |
| 6577 |
|
| 6578 |
|
| 6579 |
|
| 6580 |
|
| 6581 |
|
| 6582 |
|
| 6583 |
OO.ui.PopupWidget.prototype.getPosition = function () { |
| 6584 |
return this.popupPosition; |
| 6585 |
}; |
| 6586 |
|
| 6587 |
|
| 6588 |
|
| 6589 |
|
| 6590 |
|
| 6591 |
|
| 6592 |
|
| 6593 |
|
| 6594 |
OO.ui.PopupWidget.prototype.setAutoFlip = function ( autoFlip ) { |
| 6595 |
autoFlip = !!autoFlip; |
| 6596 |
|
| 6597 |
if ( this.autoFlip !== autoFlip ) { |
| 6598 |
this.autoFlip = autoFlip; |
| 6599 |
} |
| 6600 |
}; |
| 6601 |
|
| 6602 |
|
| 6603 |
|
| 6604 |
|
| 6605 |
|
| 6606 |
|
| 6607 |
|
| 6608 |
|
| 6609 |
OO.ui.PopupWidget.prototype.setAutoCloseIgnore = function ( $autoCloseIgnore ) { |
| 6610 |
this.$autoCloseIgnore = $autoCloseIgnore; |
| 6611 |
}; |
| 6612 |
|
| 6613 |
|
| 6614 |
|
| 6615 |
|
| 6616 |
|
| 6617 |
|
| 6618 |
|
| 6619 |
OO.ui.PopupWidget.prototype.getBodyId = function () { |
| 6620 |
let id = this.$body.attr( 'id' ); |
| 6621 |
if ( id === undefined ) { |
| 6622 |
id = OO.ui.generateElementId(); |
| 6623 |
this.$body.attr( 'id', id ); |
| 6624 |
} |
| 6625 |
return id; |
| 6626 |
}; |
| 6627 |
|
| 6628 |
|
| 6629 |
|
| 6630 |
|
| 6631 |
n. |
| 6632 |
|
| 6633 |
|
| 6634 |
|
| 6635 |
|
| 6636 |
|
| 6637 |
|
| 6638 |
|
| 6639 |
|
| 6640 |
|
| 6641 |
|
| 6642 |
OO.ui.mixin.PopupElement = function OoUiMixinPopupElement( config ) { |
| 6643 |
|
| 6644 |
config = config || {}; |
| 6645 |
|
| 6646 |
|
| 6647 |
this.popup = new OO.ui.PopupWidget( Object.assign( |
| 6648 |
{ |
| 6649 |
autoClose: true, |
| 6650 |
$floatableContainer: this.$element |
| 6651 |
}, |
| 6652 |
config.popup, |
| 6653 |
{ |
| 6654 |
$autoCloseIgnore: this.$element.add( config.popup && config.popup.$autoCloseIgnore ) |
| 6655 |
} |
| 6656 |
) ); |
| 6657 |
}; |
| 6658 |
|
| 6659 |
|
| 6660 |
|
| 6661 |
|
| 6662 |
|
| 6663 |
|
| 6664 |
|
| 6665 |
|
| 6666 |
OO.ui.mixin.PopupElement.prototype.getPopup = function () { |
| 6667 |
return this.popup; |
| 6668 |
}; |
| 6669 |
|
| 6670 |
|
| 6671 |
|
| 6672 |
|
| 6673 |
|
| 6674 |
|
| 6675 |
|
| 6676 |
|
| 6677 |
|
| 6678 |
|
| 6679 |
|
| 6680 |
|
| 6681 |
|
| 6682 |
|
| 6683 |
|
| 6684 |
|
| 6685 |
|
| 6686 |
|
| 6687 |
|
| 6688 |
|
| 6689 |
|
| 6690 |
|
| 6691 |
|
| 6692 |
|
| 6693 |
|
| 6694 |
|
| 6695 |
|
| 6696 |
|
| 6697 |
|
| 6698 |
|
| 6699 |
|
| 6700 |
OO.ui.PopupButtonWidget = function OoUiPopupButtonWidget( config ) { |
| 6701 |
|
| 6702 |
config = config || {}; |
| 6703 |
|
| 6704 |
|
| 6705 |
OO.ui.PopupButtonWidget.super.call( this, config ); |
| 6706 |
|
| 6707 |
|
| 6708 |
OO.ui.mixin.PopupElement.call( this, config ); |
| 6709 |
|
| 6710 |
|
| 6711 |
this.$overlay = ( config.$overlay === true ? |
| 6712 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 6713 |
|
| 6714 |
|
| 6715 |
this.connect( this, { |
| 6716 |
click: 'onAction' |
| 6717 |
} ); |
| 6718 |
|
| 6719 |
|
| 6720 |
this.$element.addClass( 'oo-ui-popupButtonWidget' ); |
| 6721 |
this.$button.attr( { |
| 6722 |
'aria-haspopup': 'dialog', |
| 6723 |
'aria-owns': this.popup.getElementId() |
| 6724 |
} ); |
| 6725 |
this.popup.$element |
| 6726 |
.addClass( 'oo-ui-popupButtonWidget-popup' ) |
| 6727 |
.attr( { |
| 6728 |
role: 'dialog', |
| 6729 |
'aria-describedby': this.getElementId() |
| 6730 |
} ) |
| 6731 |
.toggleClass( 'oo-ui-popupButtonWidget-framed-popup', this.isFramed() ) |
| 6732 |
.toggleClass( 'oo-ui-popupButtonWidget-frameless-popup', !this.isFramed() ); |
| 6733 |
this.$overlay.append( this.popup.$element ); |
| 6734 |
}; |
| 6735 |
|
| 6736 |
|
| 6737 |
|
| 6738 |
OO.inheritClass( OO.ui.PopupButtonWidget, OO.ui.ButtonWidget ); |
| 6739 |
OO.mixinClass( OO.ui.PopupButtonWidget, OO.ui.mixin.PopupElement ); |
| 6740 |
|
| 6741 |
|
| 6742 |
|
| 6743 |
|
| 6744 |
|
| 6745 |
|
| 6746 |
|
| 6747 |
|
| 6748 |
OO.ui.PopupButtonWidget.prototype.onAction = function () { |
| 6749 |
this.popup.toggle(); |
| 6750 |
}; |
| 6751 |
|
| 6752 |
|
| 6753 |
|
| 6754 |
|
| 6755 |
|
| 6756 |
|
| 6757 |
|
| 6758 |
|
| 6759 |
|
| 6760 |
|
| 6761 |
|
| 6762 |
|
| 6763 |
|
| 6764 |
|
| 6765 |
OO.ui.mixin.GroupWidget = function OoUiMixinGroupWidget( config ) { |
| 6766 |
|
| 6767 |
OO.ui.mixin.GroupElement.call( this, config ); |
| 6768 |
}; |
| 6769 |
|
| 6770 |
|
| 6771 |
|
| 6772 |
OO.mixinClass( OO.ui.mixin.GroupWidget, OO.ui.mixin.GroupElement ); |
| 6773 |
|
| 6774 |
|
| 6775 |
|
| 6776 |
|
| 6777 |
|
| 6778 |
|
| 6779 |
|
| 6780 |
|
| 6781 |
|
| 6782 |
|
| 6783 |
|
| 6784 |
|
| 6785 |
OO.ui.mixin.GroupWidget.prototype.setDisabled = function ( disabled ) { |
| 6786 |
|
| 6787 |
|
| 6788 |
OO.ui.Widget.prototype.setDisabled.call( this, disabled ); |
| 6789 |
|
| 6790 |
|
| 6791 |
if ( this.items ) { |
| 6792 |
for ( let i = 0, len = this.items.length; i < len; i++ ) { |
| 6793 |
this.items[ i ].updateDisabled(); |
| 6794 |
} |
| 6795 |
} |
| 6796 |
|
| 6797 |
return this; |
| 6798 |
}; |
| 6799 |
|
| 6800 |
|
| 6801 |
|
| 6802 |
|
| 6803 |
|
| 6804 |
|
| 6805 |
|
| 6806 |
|
| 6807 |
|
| 6808 |
|
| 6809 |
|
| 6810 |
|
| 6811 |
|
| 6812 |
|
| 6813 |
|
| 6814 |
OO.ui.mixin.ItemWidget = function OoUiMixinItemWidget() { |
| 6815 |
|
| 6816 |
}; |
| 6817 |
|
| 6818 |
|
| 6819 |
|
| 6820 |
|
| 6821 |
|
| 6822 |
|
| 6823 |
|
| 6824 |
|
| 6825 |
|
| 6826 |
|
| 6827 |
OO.ui.mixin.ItemWidget.prototype.isDisabled = function () { |
| 6828 |
return this.disabled || |
| 6829 |
( this.elementGroup instanceof OO.ui.Widget && this.elementGroup.isDisabled() ); |
| 6830 |
}; |
| 6831 |
|
| 6832 |
|
| 6833 |
|
| 6834 |
|
| 6835 |
|
| 6836 |
|
| 6837 |
|
| 6838 |
|
| 6839 |
OO.ui.mixin.ItemWidget.prototype.setElementGroup = function ( group ) { |
| 6840 |
|
| 6841 |
|
| 6842 |
OO.ui.Element.prototype.setElementGroup.call( this, group ); |
| 6843 |
|
| 6844 |
|
| 6845 |
this.updateDisabled(); |
| 6846 |
|
| 6847 |
return this; |
| 6848 |
}; |
| 6849 |
|
| 6850 |
|
| 6851 |
|
| 6852 |
|
| 6853 |
|
| 6854 |
|
| 6855 |
|
| 6856 |
|
| 6857 |
|
| 6858 |
|
| 6859 |
|
| 6860 |
|
| 6861 |
|
| 6862 |
|
| 6863 |
|
| 6864 |
|
| 6865 |
|
| 6866 |
|
| 6867 |
|
| 6868 |
|
| 6869 |
|
| 6870 |
OO.ui.OptionWidget = function OoUiOptionWidget( config ) { |
| 6871 |
|
| 6872 |
config = config || {}; |
| 6873 |
|
| 6874 |
|
| 6875 |
OO.ui.OptionWidget.super.call( this, config ); |
| 6876 |
|
| 6877 |
|
| 6878 |
OO.ui.mixin.ItemWidget.call( this ); |
| 6879 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 6880 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 6881 |
OO.ui.mixin.AccessKeyedElement.call( this, config ); |
| 6882 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 6883 |
|
| 6884 |
|
| 6885 |
this.highlighted = false; |
| 6886 |
this.pressed = false; |
| 6887 |
this.setSelected( !!config.selected ); |
| 6888 |
|
| 6889 |
|
| 6890 |
this.$element |
| 6891 |
.data( 'oo-ui-optionWidget', this ) |
| 6892 |
|
| 6893 |
.attr( { |
| 6894 |
tabindex: '-1', |
| 6895 |
role: 'option' |
| 6896 |
} ) |
| 6897 |
.addClass( 'oo-ui-optionWidget' ) |
| 6898 |
.append( this.$label ); |
| 6899 |
}; |
| 6900 |
|
| 6901 |
|
| 6902 |
|
| 6903 |
OO.inheritClass( OO.ui.OptionWidget, OO.ui.Widget ); |
| 6904 |
OO.mixinClass( OO.ui.OptionWidget, OO.ui.mixin.ItemWidget ); |
| 6905 |
OO.mixinClass( OO.ui.OptionWidget, OO.ui.mixin.LabelElement ); |
| 6906 |
OO.mixinClass( OO.ui.OptionWidget, OO.ui.mixin.FlaggedElement ); |
| 6907 |
OO.mixinClass( OO.ui.OptionWidget, OO.ui.mixin.AccessKeyedElement ); |
| 6908 |
OO.mixinClass( OO.ui.OptionWidget, OO.ui.mixin.TitledElement ); |
| 6909 |
|
| 6910 |
|
| 6911 |
|
| 6912 |
|
| 6913 |
|
| 6914 |
|
| 6915 |
|
| 6916 |
|
| 6917 |
|
| 6918 |
OO.ui.OptionWidget.static.selectable = true; |
| 6919 |
|
| 6920 |
|
| 6921 |
|
| 6922 |
|
| 6923 |
|
| 6924 |
|
| 6925 |
|
| 6926 |
OO.ui.OptionWidget.static.highlightable = true; |
| 6927 |
|
| 6928 |
|
| 6929 |
|
| 6930 |
|
| 6931 |
|
| 6932 |
|
| 6933 |
|
| 6934 |
OO.ui.OptionWidget.static.pressable = true; |
| 6935 |
|
| 6936 |
|
| 6937 |
|
| 6938 |
|
| 6939 |
|
| 6940 |
|
| 6941 |
|
| 6942 |
OO.ui.OptionWidget.static.scrollIntoViewOnSelect = false; |
| 6943 |
|
| 6944 |
|
| 6945 |
|
| 6946 |
|
| 6947 |
|
| 6948 |
|
| 6949 |
|
| 6950 |
|
| 6951 |
OO.ui.OptionWidget.prototype.isSelectable = function () { |
| 6952 |
return this.constructor.static.selectable && !this.disabled && this.isVisible(); |
| 6953 |
}; |
| 6954 |
|
| 6955 |
|
| 6956 |
|
| 6957 |
|
| 6958 |
|
| 6959 |
|
| 6960 |
|
| 6961 |
|
| 6962 |
OO.ui.OptionWidget.prototype.isHighlightable = function () { |
| 6963 |
return this.constructor.static.highlightable && !this.disabled && this.isVisible(); |
| 6964 |
}; |
| 6965 |
|
| 6966 |
|
| 6967 |
|
| 6968 |
|
| 6969 |
|
| 6970 |
|
| 6971 |
|
| 6972 |
OO.ui.OptionWidget.prototype.isPressable = function () { |
| 6973 |
return this.constructor.static.pressable && !this.disabled && this.isVisible(); |
| 6974 |
}; |
| 6975 |
|
| 6976 |
|
| 6977 |
|
| 6978 |
|
| 6979 |
|
| 6980 |
|
| 6981 |
OO.ui.OptionWidget.prototype.isSelected = function () { |
| 6982 |
return this.selected; |
| 6983 |
}; |
| 6984 |
|
| 6985 |
|
| 6986 |
|
| 6987 |
|
| 6988 |
|
| 6989 |
|
| 6990 |
|
| 6991 |
OO.ui.OptionWidget.prototype.isHighlighted = function () { |
| 6992 |
return this.highlighted; |
| 6993 |
}; |
| 6994 |
|
| 6995 |
|
| 6996 |
|
| 6997 |
|
| 6998 |
|
| 6999 |
|
| 7000 |
|
| 7001 |
|
| 7002 |
OO.ui.OptionWidget.prototype.isPressed = function () { |
| 7003 |
return this.pressed; |
| 7004 |
}; |
| 7005 |
|
| 7006 |
|
| 7007 |
on |
| 7008 |
’s |
| 7009 |
|
| 7010 |
|
| 7011 |
|
| 7012 |
|
| 7013 |
|
| 7014 |
|
| 7015 |
OO.ui.OptionWidget.prototype.setSelected = function ( state ) { |
| 7016 |
if ( this.constructor.static.selectable ) { |
| 7017 |
this.selected = !!state; |
| 7018 |
this.$element |
| 7019 |
.toggleClass( 'oo-ui-optionWidget-selected', state ) |
| 7020 |
.attr( 'aria-selected', this.selected.toString() ); |
| 7021 |
if ( state && this.constructor.static.scrollIntoViewOnSelect ) { |
| 7022 |
this.scrollElementIntoView(); |
| 7023 |
} |
| 7024 |
this.updateThemeClasses(); |
| 7025 |
} |
| 7026 |
return this; |
| 7027 |
}; |
| 7028 |
|
| 7029 |
|
| 7030 |
ic |
| 7031 |
|
| 7032 |
)} |
| 7033 |
|
| 7034 |
|
| 7035 |
|
| 7036 |
|
| 7037 |
|
| 7038 |
|
| 7039 |
OO.ui.OptionWidget.prototype.setHighlighted = function ( state ) { |
| 7040 |
if ( this.constructor.static.highlightable ) { |
| 7041 |
this.highlighted = !!state; |
| 7042 |
this.$element.toggleClass( 'oo-ui-optionWidget-highlighted', state ); |
| 7043 |
this.updateThemeClasses(); |
| 7044 |
} |
| 7045 |
return this; |
| 7046 |
}; |
| 7047 |
|
| 7048 |
|
| 7049 |
ll |
| 7050 |
|
| 7051 |
)} |
| 7052 |
|
| 7053 |
|
| 7054 |
|
| 7055 |
|
| 7056 |
|
| 7057 |
|
| 7058 |
OO.ui.OptionWidget.prototype.setPressed = function ( state ) { |
| 7059 |
if ( this.constructor.static.pressable ) { |
| 7060 |
this.pressed = !!state; |
| 7061 |
this.$element.toggleClass( 'oo-ui-optionWidget-pressed', state ); |
| 7062 |
this.updateThemeClasses(); |
| 7063 |
} |
| 7064 |
return this; |
| 7065 |
}; |
| 7066 |
|
| 7067 |
|
| 7068 |
|
| 7069 |
|
| 7070 |
|
| 7071 |
|
| 7072 |
|
| 7073 |
|
| 7074 |
|
| 7075 |
OO.ui.OptionWidget.prototype.getMatchText = function () { |
| 7076 |
const label = this.getLabel(); |
| 7077 |
return typeof label === 'string' ? label : this.$label.text(); |
| 7078 |
}; |
| 7079 |
|
| 7080 |
|
| 7081 |
|
| 7082 |
|
| 7083 |
|
| 7084 |
|
| 7085 |
|
| 7086 |
|
| 7087 |
|
| 7088 |
|
| 7089 |
|
| 7090 |
|
| 7091 |
|
| 7092 |
|
| 7093 |
|
| 7094 |
|
| 7095 |
|
| 7096 |
|
| 7097 |
|
| 7098 |
|
| 7099 |
|
| 7100 |
|
| 7101 |
|
| 7102 |
|
| 7103 |
|
| 7104 |
|
| 7105 |
|
| 7106 |
|
| 7107 |
|
| 7108 |
|
| 7109 |
|
| 7110 |
|
| 7111 |
|
| 7112 |
|
| 7113 |
|
| 7114 |
|
| 7115 |
|
| 7116 |
|
| 7117 |
|
| 7118 |
|
| 7119 |
|
| 7120 |
|
| 7121 |
|
| 7122 |
|
| 7123 |
|
| 7124 |
OO.ui.SelectWidget = function OoUiSelectWidget( config ) { |
| 7125 |
|
| 7126 |
config = config || {}; |
| 7127 |
|
| 7128 |
|
| 7129 |
OO.ui.SelectWidget.super.call( this, config ); |
| 7130 |
|
| 7131 |
|
| 7132 |
OO.ui.mixin.GroupWidget.call( this, Object.assign( { |
| 7133 |
$group: this.$element |
| 7134 |
}, config ) ); |
| 7135 |
|
| 7136 |
|
| 7137 |
this.pressed = false; |
| 7138 |
this.selecting = null; |
| 7139 |
this.multiselect = !!config.multiselect; |
| 7140 |
this.onDocumentMouseUpHandler = this.onDocumentMouseUp.bind( this ); |
| 7141 |
this.onDocumentMouseMoveHandler = this.onDocumentMouseMove.bind( this ); |
| 7142 |
this.onDocumentKeyDownHandler = this.onDocumentKeyDown.bind( this ); |
| 7143 |
this.onDocumentKeyPressHandler = this.onDocumentKeyPress.bind( this ); |
| 7144 |
this.keyPressBuffer = ''; |
| 7145 |
this.keyPressBufferTimer = null; |
| 7146 |
this.blockMouseOverEvents = 0; |
| 7147 |
|
| 7148 |
|
| 7149 |
this.connect( this, { |
| 7150 |
toggle: 'onToggle' |
| 7151 |
} ); |
| 7152 |
this.$element.on( { |
| 7153 |
focusin: this.onFocus.bind( this ), |
| 7154 |
mousedown: this.onMouseDown.bind( this ), |
| 7155 |
mouseover: this.onMouseOver.bind( this ), |
| 7156 |
mouseleave: this.onMouseLeave.bind( this ) |
| 7157 |
} ); |
| 7158 |
|
| 7159 |
|
| 7160 |
this.$element |
| 7161 |
.addClass( 'oo-ui-selectWidget oo-ui-selectWidget-unpressed' ) |
| 7162 |
.attr( { |
| 7163 |
role: 'listbox', |
| 7164 |
'aria-multiselectable': this.multiselect.toString() |
| 7165 |
} ); |
| 7166 |
this.setFocusOwner( this.$element ); |
| 7167 |
this.addItems( config.items || [] ); |
| 7168 |
}; |
| 7169 |
|
| 7170 |
|
| 7171 |
|
| 7172 |
OO.inheritClass( OO.ui.SelectWidget, OO.ui.Widget ); |
| 7173 |
OO.mixinClass( OO.ui.SelectWidget, OO.ui.mixin.GroupWidget ); |
| 7174 |
|
| 7175 |
|
| 7176 |
|
| 7177 |
|
| 7178 |
|
| 7179 |
|
| 7180 |
|
| 7181 |
|
| 7182 |
|
| 7183 |
|
| 7184 |
|
| 7185 |
|
| 7186 |
|
| 7187 |
|
| 7188 |
|
| 7189 |
|
| 7190 |
|
| 7191 |
|
| 7192 |
|
| 7193 |
|
| 7194 |
|
| 7195 |
|
| 7196 |
|
| 7197 |
|
| 7198 |
|
| 7199 |
|
| 7200 |
|
| 7201 |
|
| 7202 |
|
| 7203 |
|
| 7204 |
|
| 7205 |
|
| 7206 |
|
| 7207 |
|
| 7208 |
|
| 7209 |
|
| 7210 |
|
| 7211 |
|
| 7212 |
|
| 7213 |
|
| 7214 |
|
| 7215 |
|
| 7216 |
|
| 7217 |
|
| 7218 |
|
| 7219 |
|
| 7220 |
|
| 7221 |
|
| 7222 |
|
| 7223 |
|
| 7224 |
|
| 7225 |
|
| 7226 |
|
| 7227 |
|
| 7228 |
|
| 7229 |
|
| 7230 |
|
| 7231 |
|
| 7232 |
OO.ui.SelectWidget.static.handleNavigationKeys = false; |
| 7233 |
|
| 7234 |
|
| 7235 |
|
| 7236 |
|
| 7237 |
|
| 7238 |
|
| 7239 |
|
| 7240 |
|
| 7241 |
OO.ui.SelectWidget.static.listWrapsAround = true; |
| 7242 |
|
| 7243 |
|
| 7244 |
|
| 7245 |
|
| 7246 |
|
| 7247 |
|
| 7248 |
|
| 7249 |
|
| 7250 |
|
| 7251 |
OO.ui.SelectWidget.static.normalizeForMatching = function ( text ) { |
| 7252 |
|
| 7253 |
let normalized = text.trim().replace( /\s+/, ' ' ).toLowerCase(); |
| 7254 |
|
| 7255 |
|
| 7256 |
normalized = normalized.normalize(); |
| 7257 |
|
| 7258 |
return normalized; |
| 7259 |
}; |
| 7260 |
|
| 7261 |
|
| 7262 |
|
| 7263 |
|
| 7264 |
|
| 7265 |
|
| 7266 |
|
| 7267 |
|
| 7268 |
|
| 7269 |
OO.ui.SelectWidget.prototype.onFocus = function ( event ) { |
| 7270 |
let item; |
| 7271 |
if ( event.target === this.$element[ 0 ] ) { |
| 7272 |
|
| 7273 |
|
| 7274 |
if ( !this.findFirstSelectedItem() ) { |
| 7275 |
item = this.findFirstSelectableItem(); |
| 7276 |
} |
| 7277 |
} else { |
| 7278 |
if ( event.target.tabIndex === -1 ) { |
| 7279 |
|
| 7280 |
|
| 7281 |
|
| 7282 |
item = this.findTargetItem( event ); |
| 7283 |
if ( item && !( item.isHighlightable() || item.isSelectable() ) ) { |
| 7284 |
|
| 7285 |
|
| 7286 |
return; |
| 7287 |
} |
| 7288 |
} else { |
| 7289 |
|
| 7290 |
|
| 7291 |
|
| 7292 |
return; |
| 7293 |
} |
| 7294 |
} |
| 7295 |
|
| 7296 |
if ( item ) { |
| 7297 |
if ( item.constructor.static.highlightable ) { |
| 7298 |
this.highlightItem( item ); |
| 7299 |
} else { |
| 7300 |
this.selectItem( item ); |
| 7301 |
} |
| 7302 |
} |
| 7303 |
|
| 7304 |
if ( event.target !== this.$element[ 0 ] ) { |
| 7305 |
this.$focusOwner.trigger( 'focus' ); |
| 7306 |
} |
| 7307 |
}; |
| 7308 |
|
| 7309 |
|
| 7310 |
|
| 7311 |
|
| 7312 |
|
| 7313 |
|
| 7314 |
|
| 7315 |
|
| 7316 |
OO.ui.SelectWidget.prototype.onMouseDown = function ( e ) { |
| 7317 |
if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) { |
| 7318 |
this.togglePressed( true ); |
| 7319 |
const item = this.findTargetItem( e ); |
| 7320 |
if ( item && item.isSelectable() ) { |
| 7321 |
this.pressItem( item ); |
| 7322 |
this.selecting = item; |
| 7323 |
this.getElementDocument().addEventListener( 'mouseup', this.onDocumentMouseUpHandler, true ); |
| 7324 |
this.getElementDocument().addEventListener( 'mousemove', this.onDocumentMouseMoveHandler, true ); |
| 7325 |
} |
| 7326 |
} |
| 7327 |
return false; |
| 7328 |
}; |
| 7329 |
|
| 7330 |
|
| 7331 |
|
| 7332 |
|
| 7333 |
|
| 7334 |
|
| 7335 |
|
| 7336 |
|
| 7337 |
OO.ui.SelectWidget.prototype.onDocumentMouseUp = function ( e ) { |
| 7338 |
this.togglePressed( false ); |
| 7339 |
if ( !this.selecting ) { |
| 7340 |
const item = this.findTargetItem( e ); |
| 7341 |
if ( item && item.isSelectable() ) { |
| 7342 |
this.selecting = item; |
| 7343 |
} |
| 7344 |
} |
| 7345 |
if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT && this.selecting ) { |
| 7346 |
this.pressItem( null ); |
| 7347 |
this.chooseItem( this.selecting ); |
| 7348 |
this.selecting = null; |
| 7349 |
} |
| 7350 |
|
| 7351 |
this.getElementDocument().removeEventListener( 'mouseup', this.onDocumentMouseUpHandler, true ); |
| 7352 |
this.getElementDocument().removeEventListener( 'mousemove', this.onDocumentMouseMoveHandler, true ); |
| 7353 |
|
| 7354 |
return false; |
| 7355 |
}; |
| 7356 |
|
| 7357 |
|
| 7358 |
|
| 7359 |
|
| 7360 |
|
| 7361 |
|
| 7362 |
|
| 7363 |
OO.ui.SelectWidget.prototype.onDocumentMouseMove = function ( e ) { |
| 7364 |
if ( !this.isDisabled() && this.pressed ) { |
| 7365 |
const item = this.findTargetItem( e ); |
| 7366 |
if ( item && item !== this.selecting && item.isSelectable() ) { |
| 7367 |
this.pressItem( item ); |
| 7368 |
this.selecting = item; |
| 7369 |
} |
| 7370 |
} |
| 7371 |
}; |
| 7372 |
|
| 7373 |
|
| 7374 |
|
| 7375 |
|
| 7376 |
|
| 7377 |
|
| 7378 |
|
| 7379 |
|
| 7380 |
OO.ui.SelectWidget.prototype.onMouseOver = function ( e ) { |
| 7381 |
if ( this.blockMouseOverEvents ) { |
| 7382 |
return; |
| 7383 |
} |
| 7384 |
if ( !this.isDisabled() ) { |
| 7385 |
const item = this.findTargetItem( e ); |
| 7386 |
this.highlightItem( item && item.isHighlightable() ? item : null ); |
| 7387 |
} |
| 7388 |
return false; |
| 7389 |
}; |
| 7390 |
|
| 7391 |
|
| 7392 |
|
| 7393 |
|
| 7394 |
|
| 7395 |
|
| 7396 |
|
| 7397 |
|
| 7398 |
OO.ui.SelectWidget.prototype.onMouseLeave = function () { |
| 7399 |
if ( !this.isDisabled() ) { |
| 7400 |
this.highlightItem( null ); |
| 7401 |
} |
| 7402 |
return false; |
| 7403 |
}; |
| 7404 |
|
| 7405 |
|
| 7406 |
|
| 7407 |
|
| 7408 |
|
| 7409 |
|
| 7410 |
|
| 7411 |
OO.ui.SelectWidget.prototype.onDocumentKeyDown = function ( e ) { |
| 7412 |
let handled = false; |
| 7413 |
|
| 7414 |
const currentItem = |
| 7415 |
( this.isVisible() && this.findHighlightedItem() ) || |
| 7416 |
( !this.multiselect && this.findSelectedItem() ); |
| 7417 |
|
| 7418 |
let nextItem; |
| 7419 |
if ( !this.isDisabled() ) { |
| 7420 |
switch ( e.keyCode ) { |
| 7421 |
case OO.ui.Keys.ENTER: |
| 7422 |
if ( currentItem ) { |
| 7423 |
|
| 7424 |
this.chooseItem( currentItem ); |
| 7425 |
handled = true; |
| 7426 |
} |
| 7427 |
break; |
| 7428 |
case OO.ui.Keys.UP: |
| 7429 |
case OO.ui.Keys.LEFT: |
| 7430 |
case OO.ui.Keys.DOWN: |
| 7431 |
case OO.ui.Keys.RIGHT: |
| 7432 |
this.clearKeyPressBuffer(); |
| 7433 |
nextItem = this.findRelativeSelectableItem( |
| 7434 |
currentItem, |
| 7435 |
e.keyCode === OO.ui.Keys.UP || e.keyCode === OO.ui.Keys.LEFT ? -1 : 1, |
| 7436 |
null, |
| 7437 |
this.constructor.static.listWrapsAround |
| 7438 |
); |
| 7439 |
handled = true; |
| 7440 |
break; |
| 7441 |
case OO.ui.Keys.HOME: |
| 7442 |
case OO.ui.Keys.END: |
| 7443 |
if ( this.constructor.static.handleNavigationKeys ) { |
| 7444 |
this.clearKeyPressBuffer(); |
| 7445 |
nextItem = this.findRelativeSelectableItem( |
| 7446 |
null, |
| 7447 |
e.keyCode === OO.ui.Keys.HOME ? 1 : -1, |
| 7448 |
null, |
| 7449 |
this.constructor.static.listWrapsAround |
| 7450 |
); |
| 7451 |
handled = true; |
| 7452 |
} |
| 7453 |
break; |
| 7454 |
case OO.ui.Keys.PAGEUP: |
| 7455 |
case OO.ui.Keys.PAGEDOWN: |
| 7456 |
if ( this.constructor.static.handleNavigationKeys ) { |
| 7457 |
this.clearKeyPressBuffer(); |
| 7458 |
nextItem = this.findRelativeSelectableItem( |
| 7459 |
currentItem, |
| 7460 |
e.keyCode === OO.ui.Keys.PAGEUP ? -10 : 10, |
| 7461 |
null, |
| 7462 |
this.constructor.static.listWrapsAround |
| 7463 |
); |
| 7464 |
handled = true; |
| 7465 |
} |
| 7466 |
break; |
| 7467 |
case OO.ui.Keys.ESCAPE: |
| 7468 |
case OO.ui.Keys.TAB: |
| 7469 |
if ( currentItem ) { |
| 7470 |
currentItem.setHighlighted( false ); |
| 7471 |
} |
| 7472 |
this.unbindDocumentKeyDownListener(); |
| 7473 |
this.unbindDocumentKeyPressListener(); |
| 7474 |
|
| 7475 |
handled = false; |
| 7476 |
break; |
| 7477 |
} |
| 7478 |
|
| 7479 |
if ( nextItem ) { |
| 7480 |
if ( this.isVisible() && nextItem.constructor.static.highlightable ) { |
| 7481 |
this.highlightItem( nextItem ); |
| 7482 |
} else { |
| 7483 |
if ( this.screenReaderMode ) { |
| 7484 |
this.highlightItem( nextItem ); |
| 7485 |
} |
| 7486 |
this.chooseItem( nextItem ); |
| 7487 |
} |
| 7488 |
this.scrollItemIntoView( nextItem ); |
| 7489 |
} |
| 7490 |
|
| 7491 |
if ( handled ) { |
| 7492 |
e.preventDefault(); |
| 7493 |
e.stopPropagation(); |
| 7494 |
} |
| 7495 |
} |
| 7496 |
}; |
| 7497 |
|
| 7498 |
|
| 7499 |
|
| 7500 |
|
| 7501 |
|
| 7502 |
|
| 7503 |
OO.ui.SelectWidget.prototype.bindDocumentKeyDownListener = function () { |
| 7504 |
this.getElementDocument().addEventListener( 'keydown', this.onDocumentKeyDownHandler, true ); |
| 7505 |
}; |
| 7506 |
|
| 7507 |
|
| 7508 |
|
| 7509 |
|
| 7510 |
|
| 7511 |
|
| 7512 |
OO.ui.SelectWidget.prototype.unbindDocumentKeyDownListener = function () { |
| 7513 |
this.getElementDocument().removeEventListener( 'keydown', this.onDocumentKeyDownHandler, true ); |
| 7514 |
}; |
| 7515 |
|
| 7516 |
|
| 7517 |
|
| 7518 |
|
| 7519 |
|
| 7520 |
|
| 7521 |
OO.ui.SelectWidget.prototype.scrollItemIntoView = function ( item ) { |
| 7522 |
|
| 7523 |
|
| 7524 |
this.blockMouseOverEvents++; |
| 7525 |
item.scrollElementIntoView().done( () => { |
| 7526 |
setTimeout( () => { |
| 7527 |
this.blockMouseOverEvents--; |
| 7528 |
}, 200 ); |
| 7529 |
} ); |
| 7530 |
}; |
| 7531 |
|
| 7532 |
|
| 7533 |
|
| 7534 |
|
| 7535 |
|
| 7536 |
|
| 7537 |
OO.ui.SelectWidget.prototype.clearKeyPressBuffer = function () { |
| 7538 |
if ( this.keyPressBufferTimer ) { |
| 7539 |
clearTimeout( this.keyPressBufferTimer ); |
| 7540 |
this.keyPressBufferTimer = null; |
| 7541 |
} |
| 7542 |
this.keyPressBuffer = ''; |
| 7543 |
}; |
| 7544 |
|
| 7545 |
|
| 7546 |
|
| 7547 |
|
| 7548 |
|
| 7549 |
|
| 7550 |
|
| 7551 |
|
| 7552 |
OO.ui.SelectWidget.prototype.onDocumentKeyPress = function ( e ) { |
| 7553 |
if ( !e.charCode ) { |
| 7554 |
if ( e.keyCode === OO.ui.Keys.BACKSPACE && this.keyPressBuffer !== '' ) { |
| 7555 |
this.keyPressBuffer = this.keyPressBuffer.slice( 0, this.keyPressBuffer.length - 1 ); |
| 7556 |
return false; |
| 7557 |
} |
| 7558 |
return; |
| 7559 |
} |
| 7560 |
|
| 7561 |
const c = String.fromCodePoint( e.charCode ); |
| 7562 |
|
| 7563 |
if ( this.keyPressBufferTimer ) { |
| 7564 |
clearTimeout( this.keyPressBufferTimer ); |
| 7565 |
} |
| 7566 |
this.keyPressBufferTimer = setTimeout( this.clearKeyPressBuffer.bind( this ), 1500 ); |
| 7567 |
|
| 7568 |
let item = ( this.isVisible() && this.findHighlightedItem() ) || |
| 7569 |
( !this.multiselect && this.findSelectedItem() ); |
| 7570 |
|
| 7571 |
if ( this.keyPressBuffer === c ) { |
| 7572 |
|
| 7573 |
|
| 7574 |
if ( item ) { |
| 7575 |
item = this.findRelativeSelectableItem( item, 1 ); |
| 7576 |
} |
| 7577 |
} else { |
| 7578 |
this.keyPressBuffer += c; |
| 7579 |
} |
| 7580 |
|
| 7581 |
const filter = this.getItemMatcher( this.keyPressBuffer, false ); |
| 7582 |
if ( !item || !filter( item ) ) { |
| 7583 |
item = this.findRelativeSelectableItem( item, 1, filter ); |
| 7584 |
} |
| 7585 |
if ( item ) { |
| 7586 |
if ( this.isVisible() && item.constructor.static.highlightable ) { |
| 7587 |
this.highlightItem( item ); |
| 7588 |
} else { |
| 7589 |
if ( this.screenReaderMode ) { |
| 7590 |
this.highlightItem( item ); |
| 7591 |
} |
| 7592 |
this.chooseItem( item ); |
| 7593 |
} |
| 7594 |
this.scrollItemIntoView( item ); |
| 7595 |
} |
| 7596 |
|
| 7597 |
e.preventDefault(); |
| 7598 |
e.stopPropagation(); |
| 7599 |
}; |
| 7600 |
|
| 7601 |
|
| 7602 |
|
| 7603 |
|
| 7604 |
|
| 7605 |
|
| 7606 |
|
| 7607 |
|
| 7608 |
|
| 7609 |
OO.ui.SelectWidget.prototype.getItemMatcher = function ( query, mode ) { |
| 7610 |
const normalizeForMatching = this.constructor.static.normalizeForMatching, |
| 7611 |
normalizedQuery = normalizeForMatching( query ); |
| 7612 |
|
| 7613 |
|
| 7614 |
if ( !normalizedQuery ) { |
| 7615 |
return function () { |
| 7616 |
return mode !== 'exact'; |
| 7617 |
}; |
| 7618 |
} |
| 7619 |
|
| 7620 |
return function ( item ) { |
| 7621 |
const matchText = normalizeForMatching( item.getMatchText() ); |
| 7622 |
switch ( mode ) { |
| 7623 |
case 'exact': |
| 7624 |
return matchText === normalizedQuery; |
| 7625 |
case 'substring': |
| 7626 |
return matchText.indexOf( normalizedQuery ) !== -1; |
| 7627 |
|
| 7628 |
default: |
| 7629 |
return matchText.indexOf( normalizedQuery ) === 0; |
| 7630 |
} |
| 7631 |
}; |
| 7632 |
}; |
| 7633 |
|
| 7634 |
|
| 7635 |
|
| 7636 |
|
| 7637 |
|
| 7638 |
|
| 7639 |
OO.ui.SelectWidget.prototype.bindDocumentKeyPressListener = function () { |
| 7640 |
this.getElementDocument().addEventListener( 'keypress', this.onDocumentKeyPressHandler, true ); |
| 7641 |
}; |
| 7642 |
|
| 7643 |
|
| 7644 |
|
| 7645 |
|
| 7646 |
|
| 7647 |
|
| 7648 |
|
| 7649 |
|
| 7650 |
|
| 7651 |
OO.ui.SelectWidget.prototype.unbindDocumentKeyPressListener = function () { |
| 7652 |
this.getElementDocument().removeEventListener( 'keypress', this.onDocumentKeyPressHandler, true ); |
| 7653 |
this.clearKeyPressBuffer(); |
| 7654 |
}; |
| 7655 |
|
| 7656 |
|
| 7657 |
|
| 7658 |
|
| 7659 |
|
| 7660 |
|
| 7661 |
|
| 7662 |
OO.ui.SelectWidget.prototype.onToggle = function ( visible ) { |
| 7663 |
if ( !visible ) { |
| 7664 |
this.clearKeyPressBuffer(); |
| 7665 |
} |
| 7666 |
}; |
| 7667 |
|
| 7668 |
|
| 7669 |
|
| 7670 |
|
| 7671 |
|
| 7672 |
|
| 7673 |
|
| 7674 |
|
| 7675 |
OO.ui.SelectWidget.prototype.findTargetItem = function ( e ) { |
| 7676 |
const $option = $( e.target ).closest( '.oo-ui-optionWidget' ); |
| 7677 |
if ( !$option.closest( '.oo-ui-selectWidget' ).is( this.$element ) ) { |
| 7678 |
return null; |
| 7679 |
} |
| 7680 |
return $option.data( 'oo-ui-optionWidget' ) || null; |
| 7681 |
}; |
| 7682 |
|
| 7683 |
|
| 7684 |
|
| 7685 |
|
| 7686 |
OO.ui.SelectWidget.prototype.findFirstSelectedItem = function () { |
| 7687 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 7688 |
if ( this.items[ i ].isSelected() ) { |
| 7689 |
return this.items[ i ]; |
| 7690 |
} |
| 7691 |
} |
| 7692 |
return null; |
| 7693 |
}; |
| 7694 |
|
| 7695 |
|
| 7696 |
|
| 7697 |
|
| 7698 |
|
| 7699 |
|
| 7700 |
|
| 7701 |
|
| 7702 |
|
| 7703 |
|
| 7704 |
|
| 7705 |
OO.ui.SelectWidget.prototype.findSelectedItems = function () { |
| 7706 |
if ( !this.multiselect ) { |
| 7707 |
return this.findFirstSelectedItem(); |
| 7708 |
} |
| 7709 |
|
| 7710 |
return this.items.filter( ( item ) => item.isSelected() ); |
| 7711 |
}; |
| 7712 |
|
| 7713 |
|
| 7714 |
|
| 7715 |
|
| 7716 |
|
| 7717 |
|
| 7718 |
|
| 7719 |
|
| 7720 |
|
| 7721 |
OO.ui.SelectWidget.prototype.findSelectedItem = function () { |
| 7722 |
return this.findSelectedItems(); |
| 7723 |
}; |
| 7724 |
|
| 7725 |
|
| 7726 |
|
| 7727 |
|
| 7728 |
|
| 7729 |
|
| 7730 |
OO.ui.SelectWidget.prototype.findHighlightedItem = function () { |
| 7731 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 7732 |
if ( this.items[ i ].isHighlighted() ) { |
| 7733 |
return this.items[ i ]; |
| 7734 |
} |
| 7735 |
} |
| 7736 |
return null; |
| 7737 |
}; |
| 7738 |
|
| 7739 |
|
| 7740 |
|
| 7741 |
|
| 7742 |
|
| 7743 |
|
| 7744 |
|
| 7745 |
|
| 7746 |
|
| 7747 |
|
| 7748 |
OO.ui.SelectWidget.prototype.togglePressed = function ( pressed ) { |
| 7749 |
if ( pressed === undefined ) { |
| 7750 |
pressed = !this.pressed; |
| 7751 |
} |
| 7752 |
if ( pressed !== this.pressed ) { |
| 7753 |
this.$element |
| 7754 |
.toggleClass( 'oo-ui-selectWidget-pressed', pressed ) |
| 7755 |
.toggleClass( 'oo-ui-selectWidget-unpressed', !pressed ); |
| 7756 |
this.pressed = pressed; |
| 7757 |
} |
| 7758 |
}; |
| 7759 |
|
| 7760 |
|
| 7761 |
|
| 7762 |
|
| 7763 |
|
| 7764 |
|
| 7765 |
|
| 7766 |
|
| 7767 |
|
| 7768 |
|
| 7769 |
OO.ui.SelectWidget.prototype.highlightItem = function ( item ) { |
| 7770 |
if ( item && item.isHighlighted() ) { |
| 7771 |
return this; |
| 7772 |
} |
| 7773 |
|
| 7774 |
let changed = false; |
| 7775 |
|
| 7776 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 7777 |
const highlighted = this.items[ i ] === item; |
| 7778 |
if ( this.items[ i ].isHighlighted() !== highlighted ) { |
| 7779 |
this.items[ i ].setHighlighted( highlighted ); |
| 7780 |
if ( changed ) { |
| 7781 |
|
| 7782 |
break; |
| 7783 |
} |
| 7784 |
|
| 7785 |
changed = !highlighted || this.items[ i ].isHighlighted(); |
| 7786 |
} |
| 7787 |
} |
| 7788 |
|
| 7789 |
if ( changed ) { |
| 7790 |
if ( item ) { |
| 7791 |
this.$focusOwner.attr( 'aria-activedescendant', item.getElementId() ); |
| 7792 |
} else { |
| 7793 |
this.$focusOwner.removeAttr( 'aria-activedescendant' ); |
| 7794 |
} |
| 7795 |
this.emit( 'highlight', item ); |
| 7796 |
} |
| 7797 |
|
| 7798 |
return this; |
| 7799 |
}; |
| 7800 |
|
| 7801 |
|
| 7802 |
|
| 7803 |
|
| 7804 |
|
| 7805 |
|
| 7806 |
|
| 7807 |
|
| 7808 |
OO.ui.SelectWidget.prototype.getItemFromLabel = function ( label, prefix ) { |
| 7809 |
const len = this.items.length; |
| 7810 |
|
| 7811 |
let filter = this.getItemMatcher( label, 'exact' ); |
| 7812 |
|
| 7813 |
let i, item; |
| 7814 |
for ( i = 0; i < len; i++ ) { |
| 7815 |
item = this.items[ i ]; |
| 7816 |
if ( item instanceof OO.ui.OptionWidget && item.isSelectable() && filter( item ) ) { |
| 7817 |
return item; |
| 7818 |
} |
| 7819 |
} |
| 7820 |
|
| 7821 |
if ( prefix ) { |
| 7822 |
let found = null; |
| 7823 |
filter = this.getItemMatcher( label, 'prefix' ); |
| 7824 |
for ( i = 0; i < len; i++ ) { |
| 7825 |
item = this.items[ i ]; |
| 7826 |
if ( item instanceof OO.ui.OptionWidget && item.isSelectable() && filter( item ) ) { |
| 7827 |
if ( found ) { |
| 7828 |
return null; |
| 7829 |
} |
| 7830 |
found = item; |
| 7831 |
} |
| 7832 |
} |
| 7833 |
if ( found ) { |
| 7834 |
return found; |
| 7835 |
} |
| 7836 |
} |
| 7837 |
|
| 7838 |
return null; |
| 7839 |
}; |
| 7840 |
|
| 7841 |
|
| 7842 |
|
| 7843 |
|
| 7844 |
|
| 7845 |
|
| 7846 |
|
| 7847 |
|
| 7848 |
|
| 7849 |
|
| 7850 |
|
| 7851 |
OO.ui.SelectWidget.prototype.selectItemByLabel = function ( label, prefix ) { |
| 7852 |
const itemFromLabel = this.getItemFromLabel( label, !!prefix ); |
| 7853 |
if ( label === undefined || !itemFromLabel ) { |
| 7854 |
return this.selectItem(); |
| 7855 |
} |
| 7856 |
return this.selectItem( itemFromLabel ); |
| 7857 |
}; |
| 7858 |
|
| 7859 |
|
| 7860 |
|
| 7861 |
|
| 7862 |
|
| 7863 |
|
| 7864 |
|
| 7865 |
|
| 7866 |
|
| 7867 |
|
| 7868 |
OO.ui.SelectWidget.prototype.selectItemByData = function ( data ) { |
| 7869 |
const itemFromData = this.findItemFromData( data ); |
| 7870 |
if ( data === undefined || !itemFromData ) { |
| 7871 |
return this.selectItem(); |
| 7872 |
} |
| 7873 |
return this.selectItem( itemFromData ); |
| 7874 |
}; |
| 7875 |
|
| 7876 |
|
| 7877 |
|
| 7878 |
|
| 7879 |
|
| 7880 |
|
| 7881 |
|
| 7882 |
|
| 7883 |
|
| 7884 |
|
| 7885 |
|
| 7886 |
|
| 7887 |
OO.ui.SelectWidget.prototype.unselectItem = function ( unselectedItem ) { |
| 7888 |
if ( !unselectedItem ) { |
| 7889 |
|
| 7890 |
this.selectItem(); |
| 7891 |
} else if ( unselectedItem.isSelected() ) { |
| 7892 |
unselectedItem.setSelected( false ); |
| 7893 |
|
| 7894 |
this.emit( 'select', this.findSelectedItems() ); |
| 7895 |
} |
| 7896 |
|
| 7897 |
return this; |
| 7898 |
}; |
| 7899 |
|
| 7900 |
|
| 7901 |
|
| 7902 |
|
| 7903 |
|
| 7904 |
|
| 7905 |
|
| 7906 |
|
| 7907 |
|
| 7908 |
|
| 7909 |
OO.ui.SelectWidget.prototype.selectItem = function ( item ) { |
| 7910 |
if ( item ) { |
| 7911 |
if ( item.isSelected() ) { |
| 7912 |
return this; |
| 7913 |
} else if ( this.multiselect ) { |
| 7914 |
|
| 7915 |
item.setSelected( true ); |
| 7916 |
this.emit( 'select', this.findSelectedItems() ); |
| 7917 |
return this; |
| 7918 |
} |
| 7919 |
} |
| 7920 |
|
| 7921 |
let changed = false; |
| 7922 |
|
| 7923 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 7924 |
const selected = this.items[ i ] === item; |
| 7925 |
if ( this.items[ i ].isSelected() !== selected ) { |
| 7926 |
this.items[ i ].setSelected( selected ); |
| 7927 |
if ( changed && !this.multiselect ) { |
| 7928 |
|
| 7929 |
break; |
| 7930 |
} |
| 7931 |
|
| 7932 |
changed = !selected || this.items[ i ].isSelected(); |
| 7933 |
} |
| 7934 |
} |
| 7935 |
|
| 7936 |
if ( changed ) { |
| 7937 |
|
| 7938 |
|
| 7939 |
|
| 7940 |
if ( !this.multiselect && item && !item.constructor.static.highlightable ) { |
| 7941 |
this.$focusOwner.attr( 'aria-activedescendant', item.getElementId() ); |
| 7942 |
} |
| 7943 |
this.emit( 'select', this.findSelectedItems() ); |
| 7944 |
} |
| 7945 |
|
| 7946 |
return this; |
| 7947 |
}; |
| 7948 |
|
| 7949 |
|
| 7950 |
|
| 7951 |
|
| 7952 |
|
| 7953 |
|
| 7954 |
|
| 7955 |
|
| 7956 |
|
| 7957 |
|
| 7958 |
|
| 7959 |
|
| 7960 |
|
| 7961 |
OO.ui.SelectWidget.prototype.pressItem = function ( item ) { |
| 7962 |
if ( item && item.isPressed() ) { |
| 7963 |
return this; |
| 7964 |
} |
| 7965 |
|
| 7966 |
let changed = false; |
| 7967 |
|
| 7968 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 7969 |
const pressed = this.items[ i ] === item; |
| 7970 |
if ( this.items[ i ].isPressed() !== pressed ) { |
| 7971 |
this.items[ i ].setPressed( pressed ); |
| 7972 |
if ( changed ) { |
| 7973 |
|
| 7974 |
break; |
| 7975 |
} |
| 7976 |
|
| 7977 |
changed = !pressed || this.items[ i ].isPressed(); |
| 7978 |
} |
| 7979 |
} |
| 7980 |
|
| 7981 |
if ( changed ) { |
| 7982 |
this.emit( 'press', item ); |
| 7983 |
} |
| 7984 |
|
| 7985 |
return this; |
| 7986 |
}; |
| 7987 |
|
| 7988 |
|
| 7989 |
|
| 7990 |
|
| 7991 |
oose |
| 7992 |
|
| 7993 |
|
| 7994 |
|
| 7995 |
|
| 7996 |
|
| 7997 |
|
| 7998 |
|
| 7999 |
|
| 8000 |
|
| 8001 |
|
| 8002 |
|
| 8003 |
OO.ui.SelectWidget.prototype.chooseItem = function ( item ) { |
| 8004 |
if ( item ) { |
| 8005 |
if ( this.multiselect && item.isSelected() ) { |
| 8006 |
this.unselectItem( item ); |
| 8007 |
} else { |
| 8008 |
this.selectItem( item ); |
| 8009 |
} |
| 8010 |
|
| 8011 |
this.emit( 'choose', item, item.isSelected() ); |
| 8012 |
} |
| 8013 |
|
| 8014 |
return this; |
| 8015 |
}; |
| 8016 |
|
| 8017 |
|
| 8018 |
|
| 8019 |
|
| 8020 |
|
| 8021 |
|
| 8022 |
|
| 8023 |
|
| 8024 |
|
| 8025 |
|
| 8026 |
|
| 8027 |
|
| 8028 |
|
| 8029 |
|
| 8030 |
|
| 8031 |
|
| 8032 |
OO.ui.SelectWidget.prototype.findRelativeSelectableItem = function ( item, offset, filter, wrap ) { |
| 8033 |
const step = offset > 0 ? 1 : -1, |
| 8034 |
len = this.items.length; |
| 8035 |
if ( wrap === undefined ) { |
| 8036 |
wrap = true; |
| 8037 |
} |
| 8038 |
|
| 8039 |
let nextIndex; |
| 8040 |
if ( item instanceof OO.ui.OptionWidget ) { |
| 8041 |
nextIndex = this.items.indexOf( item ); |
| 8042 |
} else { |
| 8043 |
|
| 8044 |
|
| 8045 |
nextIndex = offset > 0 ? 0 : len - 1; |
| 8046 |
offset -= step; |
| 8047 |
} |
| 8048 |
|
| 8049 |
const previousItem = item; |
| 8050 |
let nextItem = null; |
| 8051 |
for ( let i = 0; i < len; i++ ) { |
| 8052 |
item = this.items[ nextIndex ]; |
| 8053 |
if ( |
| 8054 |
item instanceof OO.ui.OptionWidget && item.isSelectable() && |
| 8055 |
( !filter || filter( item ) ) |
| 8056 |
) { |
| 8057 |
nextItem = item; |
| 8058 |
} |
| 8059 |
|
| 8060 |
if ( offset === 0 && nextItem && nextItem !== previousItem ) { |
| 8061 |
|
| 8062 |
|
| 8063 |
break; |
| 8064 |
} |
| 8065 |
|
| 8066 |
nextIndex += step; |
| 8067 |
if ( nextIndex < 0 || nextIndex >= len ) { |
| 8068 |
if ( wrap ) { |
| 8069 |
nextIndex = ( nextIndex + len ) % len; |
| 8070 |
} else { |
| 8071 |
|
| 8072 |
break; |
| 8073 |
} |
| 8074 |
} |
| 8075 |
if ( offset !== 0 ) { |
| 8076 |
offset -= step; |
| 8077 |
} |
| 8078 |
} |
| 8079 |
return nextItem; |
| 8080 |
}; |
| 8081 |
|
| 8082 |
|
| 8083 |
|
| 8084 |
|
| 8085 |
|
| 8086 |
|
| 8087 |
|
| 8088 |
OO.ui.SelectWidget.prototype.findFirstSelectableItem = function () { |
| 8089 |
return this.findRelativeSelectableItem( null, 1 ); |
| 8090 |
}; |
| 8091 |
|
| 8092 |
|
| 8093 |
|
| 8094 |
|
| 8095 |
|
| 8096 |
|
| 8097 |
|
| 8098 |
|
| 8099 |
|
| 8100 |
|
| 8101 |
|
| 8102 |
OO.ui.SelectWidget.prototype.addItems = function ( items, index ) { |
| 8103 |
if ( !items || items.length === 0 ) { |
| 8104 |
return this; |
| 8105 |
} |
| 8106 |
|
| 8107 |
|
| 8108 |
OO.ui.mixin.GroupWidget.prototype.addItems.call( this, items, index ); |
| 8109 |
|
| 8110 |
|
| 8111 |
this.emit( 'add', items, index === undefined ? this.items.length - items.length - 1 : index ); |
| 8112 |
|
| 8113 |
return this; |
| 8114 |
}; |
| 8115 |
|
| 8116 |
|
| 8117 |
|
| 8118 |
|
| 8119 |
|
| 8120 |
|
| 8121 |
|
| 8122 |
|
| 8123 |
|
| 8124 |
|
| 8125 |
|
| 8126 |
OO.ui.SelectWidget.prototype.removeItems = function ( items ) { |
| 8127 |
|
| 8128 |
for ( let i = 0; i < items.length; i++ ) { |
| 8129 |
const item = items[ i ]; |
| 8130 |
if ( item.isSelected() ) { |
| 8131 |
this.selectItem( null ); |
| 8132 |
} |
| 8133 |
} |
| 8134 |
|
| 8135 |
|
| 8136 |
OO.ui.mixin.GroupWidget.prototype.removeItems.call( this, items ); |
| 8137 |
|
| 8138 |
this.emit( 'remove', items ); |
| 8139 |
|
| 8140 |
return this; |
| 8141 |
}; |
| 8142 |
|
| 8143 |
|
| 8144 |
|
| 8145 |
|
| 8146 |
|
| 8147 |
|
| 8148 |
|
| 8149 |
|
| 8150 |
|
| 8151 |
|
| 8152 |
OO.ui.SelectWidget.prototype.clearItems = function () { |
| 8153 |
const items = this.items.slice(); |
| 8154 |
|
| 8155 |
|
| 8156 |
OO.ui.mixin.GroupWidget.prototype.clearItems.call( this ); |
| 8157 |
|
| 8158 |
|
| 8159 |
this.selectItem( null ); |
| 8160 |
|
| 8161 |
this.emit( 'remove', items ); |
| 8162 |
|
| 8163 |
return this; |
| 8164 |
}; |
| 8165 |
|
| 8166 |
|
| 8167 |
|
| 8168 |
|
| 8169 |
|
| 8170 |
|
| 8171 |
|
| 8172 |
|
| 8173 |
|
| 8174 |
OO.ui.SelectWidget.prototype.setFocusOwner = function ( $focusOwner ) { |
| 8175 |
this.$focusOwner = $focusOwner; |
| 8176 |
}; |
| 8177 |
|
| 8178 |
|
| 8179 |
|
| 8180 |
|
| 8181 |
|
| 8182 |
|
| 8183 |
|
| 8184 |
|
| 8185 |
|
| 8186 |
|
| 8187 |
|
| 8188 |
|
| 8189 |
|
| 8190 |
|
| 8191 |
|
| 8192 |
|
| 8193 |
|
| 8194 |
|
| 8195 |
|
| 8196 |
|
| 8197 |
|
| 8198 |
|
| 8199 |
|
| 8200 |
|
| 8201 |
|
| 8202 |
|
| 8203 |
|
| 8204 |
|
| 8205 |
|
| 8206 |
|
| 8207 |
|
| 8208 |
|
| 8209 |
|
| 8210 |
|
| 8211 |
|
| 8212 |
|
| 8213 |
|
| 8214 |
OO.ui.DecoratedOptionWidget = function OoUiDecoratedOptionWidget( config ) { |
| 8215 |
|
| 8216 |
OO.ui.DecoratedOptionWidget.super.call( this, config ); |
| 8217 |
|
| 8218 |
|
| 8219 |
OO.ui.mixin.IconElement.call( this, config ); |
| 8220 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 8221 |
|
| 8222 |
|
| 8223 |
this.$element |
| 8224 |
.addClass( 'oo-ui-decoratedOptionWidget' ) |
| 8225 |
.prepend( this.$icon ) |
| 8226 |
.append( this.$indicator ); |
| 8227 |
}; |
| 8228 |
|
| 8229 |
|
| 8230 |
|
| 8231 |
OO.inheritClass( OO.ui.DecoratedOptionWidget, OO.ui.OptionWidget ); |
| 8232 |
OO.mixinClass( OO.ui.DecoratedOptionWidget, OO.ui.mixin.IconElement ); |
| 8233 |
OO.mixinClass( OO.ui.DecoratedOptionWidget, OO.ui.mixin.IndicatorElement ); |
| 8234 |
|
| 8235 |
|
| 8236 |
|
| 8237 |
|
| 8238 |
|
| 8239 |
|
| 8240 |
|
| 8241 |
|
| 8242 |
|
| 8243 |
|
| 8244 |
|
| 8245 |
|
| 8246 |
|
| 8247 |
|
| 8248 |
OO.ui.MenuOptionWidget = function OoUiMenuOptionWidget( config ) { |
| 8249 |
|
| 8250 |
OO.ui.MenuOptionWidget.super.call( this, config ); |
| 8251 |
|
| 8252 |
|
| 8253 |
this.checkIcon = new OO.ui.IconWidget( { |
| 8254 |
icon: 'check', |
| 8255 |
classes: [ 'oo-ui-menuOptionWidget-checkIcon' ] |
| 8256 |
} ); |
| 8257 |
|
| 8258 |
|
| 8259 |
this.$element |
| 8260 |
.prepend( this.checkIcon.$element ) |
| 8261 |
.addClass( 'oo-ui-menuOptionWidget' ); |
| 8262 |
}; |
| 8263 |
|
| 8264 |
|
| 8265 |
|
| 8266 |
OO.inheritClass( OO.ui.MenuOptionWidget, OO.ui.DecoratedOptionWidget ); |
| 8267 |
|
| 8268 |
|
| 8269 |
|
| 8270 |
|
| 8271 |
|
| 8272 |
|
| 8273 |
|
| 8274 |
OO.ui.MenuOptionWidget.static.scrollIntoViewOnSelect = true; |
| 8275 |
|
| 8276 |
|
| 8277 |
|
| 8278 |
|
| 8279 |
|
| 8280 |
|
| 8281 |
|
| 8282 |
|
| 8283 |
|
| 8284 |
|
| 8285 |
|
| 8286 |
|
| 8287 |
|
| 8288 |
|
| 8289 |
|
| 8290 |
|
| 8291 |
|
| 8292 |
|
| 8293 |
|
| 8294 |
|
| 8295 |
|
| 8296 |
|
| 8297 |
|
| 8298 |
|
| 8299 |
|
| 8300 |
|
| 8301 |
|
| 8302 |
|
| 8303 |
|
| 8304 |
|
| 8305 |
|
| 8306 |
|
| 8307 |
|
| 8308 |
|
| 8309 |
|
| 8310 |
|
| 8311 |
|
| 8312 |
|
| 8313 |
|
| 8314 |
OO.ui.MenuSectionOptionWidget = function OoUiMenuSectionOptionWidget( config ) { |
| 8315 |
|
| 8316 |
OO.ui.MenuSectionOptionWidget.super.call( this, config ); |
| 8317 |
|
| 8318 |
|
| 8319 |
this.$element |
| 8320 |
.addClass( 'oo-ui-menuSectionOptionWidget' ) |
| 8321 |
.removeAttr( 'role aria-selected' ); |
| 8322 |
this.selected = false; |
| 8323 |
}; |
| 8324 |
|
| 8325 |
|
| 8326 |
|
| 8327 |
OO.inheritClass( OO.ui.MenuSectionOptionWidget, OO.ui.DecoratedOptionWidget ); |
| 8328 |
|
| 8329 |
|
| 8330 |
|
| 8331 |
|
| 8332 |
|
| 8333 |
|
| 8334 |
|
| 8335 |
OO.ui.MenuSectionOptionWidget.static.selectable = false; |
| 8336 |
|
| 8337 |
|
| 8338 |
|
| 8339 |
|
| 8340 |
|
| 8341 |
OO.ui.MenuSectionOptionWidget.static.highlightable = false; |
| 8342 |
|
| 8343 |
|
| 8344 |
|
| 8345 |
|
| 8346 |
|
| 8347 |
|
| 8348 |
|
| 8349 |
|
| 8350 |
|
| 8351 |
|
| 8352 |
|
| 8353 |
|
| 8354 |
|
| 8355 |
|
| 8356 |
|
| 8357 |
|
| 8358 |
|
| 8359 |
|
| 8360 |
|
| 8361 |
|
| 8362 |
|
| 8363 |
|
| 8364 |
|
| 8365 |
|
| 8366 |
|
| 8367 |
|
| 8368 |
|
| 8369 |
|
| 8370 |
|
| 8371 |
|
| 8372 |
|
| 8373 |
|
| 8374 |
|
| 8375 |
|
| 8376 |
|
| 8377 |
|
| 8378 |
|
| 8379 |
|
| 8380 |
|
| 8381 |
|
| 8382 |
|
| 8383 |
|
| 8384 |
|
| 8385 |
|
| 8386 |
|
| 8387 |
|
| 8388 |
|
| 8389 |
|
| 8390 |
|
| 8391 |
|
| 8392 |
|
| 8393 |
|
| 8394 |
|
| 8395 |
|
| 8396 |
OO.ui.MenuSelectWidget = function OoUiMenuSelectWidget( config ) { |
| 8397 |
|
| 8398 |
config = config || {}; |
| 8399 |
|
| 8400 |
|
| 8401 |
OO.ui.MenuSelectWidget.super.call( this, config ); |
| 8402 |
|
| 8403 |
|
| 8404 |
OO.ui.mixin.ClippableElement.call( this, Object.assign( { $clippable: this.$group }, config ) ); |
| 8405 |
OO.ui.mixin.FloatableElement.call( this, config ); |
| 8406 |
|
| 8407 |
|
| 8408 |
|
| 8409 |
|
| 8410 |
this.originalVerticalPosition = this.verticalPosition; |
| 8411 |
|
| 8412 |
|
| 8413 |
this.autoHide = config.autoHide === undefined || !!config.autoHide; |
| 8414 |
this.hideOnChoose = config.hideOnChoose === undefined || !!config.hideOnChoose; |
| 8415 |
this.filterFromInput = !!config.filterFromInput; |
| 8416 |
this.previouslySelectedValue = null; |
| 8417 |
this.$input = config.$input ? config.$input : config.input ? config.input.$input : null; |
| 8418 |
this.$widget = config.widget ? config.widget.$element : null; |
| 8419 |
this.$autoCloseIgnore = config.$autoCloseIgnore || $( [] ); |
| 8420 |
this.onDocumentMouseDownHandler = this.onDocumentMouseDown.bind( this ); |
| 8421 |
this.onInputEditHandler = OO.ui.debounce( this.updateItemVisibility.bind( this ), 100 ); |
| 8422 |
this.highlightOnFilter = !!config.highlightOnFilter; |
| 8423 |
this.lastHighlightedItem = null; |
| 8424 |
this.width = config.width; |
| 8425 |
this.filterMode = config.filterMode; |
| 8426 |
this.screenReaderMode = false; |
| 8427 |
|
| 8428 |
|
| 8429 |
this.$element.addClass( 'oo-ui-menuSelectWidget' ); |
| 8430 |
if ( config.widget ) { |
| 8431 |
this.setFocusOwner( config.widget.$tabIndexed ); |
| 8432 |
} |
| 8433 |
|
| 8434 |
|
| 8435 |
|
| 8436 |
|
| 8437 |
this.visible = false; |
| 8438 |
this.$element.addClass( 'oo-ui-element-hidden' ); |
| 8439 |
this.$focusOwner.attr( 'aria-expanded', 'false' ); |
| 8440 |
}; |
| 8441 |
|
| 8442 |
|
| 8443 |
|
| 8444 |
OO.inheritClass( OO.ui.MenuSelectWidget, OO.ui.SelectWidget ); |
| 8445 |
OO.mixinClass( OO.ui.MenuSelectWidget, OO.ui.mixin.ClippableElement ); |
| 8446 |
OO.mixinClass( OO.ui.MenuSelectWidget, OO.ui.mixin.FloatableElement ); |
| 8447 |
|
| 8448 |
|
| 8449 |
|
| 8450 |
|
| 8451 |
|
| 8452 |
|
| 8453 |
|
| 8454 |
|
| 8455 |
|
| 8456 |
|
| 8457 |
|
| 8458 |
OO.ui.MenuSelectWidget.static.handleNavigationKeys = true; |
| 8459 |
|
| 8460 |
OO.ui.MenuSelectWidget.static.listWrapsAround = false; |
| 8461 |
|
| 8462 |
|
| 8463 |
|
| 8464 |
|
| 8465 |
|
| 8466 |
|
| 8467 |
|
| 8468 |
OO.ui.MenuSelectWidget.static.flippedPositions = { |
| 8469 |
below: 'above', |
| 8470 |
above: 'below', |
| 8471 |
top: 'bottom', |
| 8472 |
bottom: 'top' |
| 8473 |
}; |
| 8474 |
|
| 8475 |
|
| 8476 |
|
| 8477 |
|
| 8478 |
|
| 8479 |
|
| 8480 |
|
| 8481 |
|
| 8482 |
|
| 8483 |
OO.ui.MenuSelectWidget.prototype.onDocumentMouseDown = function ( e ) { |
| 8484 |
if ( |
| 8485 |
this.isVisible() && |
| 8486 |
!OO.ui.contains( |
| 8487 |
this.$element.add( this.$widget ).add( this.$autoCloseIgnore ).get(), |
| 8488 |
e.target, |
| 8489 |
true |
| 8490 |
) |
| 8491 |
) { |
| 8492 |
this.toggle( false ); |
| 8493 |
} |
| 8494 |
}; |
| 8495 |
|
| 8496 |
|
| 8497 |
|
| 8498 |
|
| 8499 |
OO.ui.MenuSelectWidget.prototype.onDocumentKeyDown = function ( e ) { |
| 8500 |
let handled = false; |
| 8501 |
|
| 8502 |
const currentItem = this.findHighlightedItem() || this.findFirstSelectedItem(); |
| 8503 |
|
| 8504 |
if ( !this.isDisabled() && this.getVisibleItems().length ) { |
| 8505 |
switch ( e.keyCode ) { |
| 8506 |
case OO.ui.Keys.ENTER: |
| 8507 |
if ( this.isVisible() ) { |
| 8508 |
OO.ui.MenuSelectWidget.super.prototype.onDocumentKeyDown.call( this, e ); |
| 8509 |
} |
| 8510 |
break; |
| 8511 |
case OO.ui.Keys.TAB: |
| 8512 |
if ( this.isVisible() ) { |
| 8513 |
if ( currentItem && !currentItem.isSelected() ) { |
| 8514 |
|
| 8515 |
this.chooseItem( currentItem ); |
| 8516 |
handled = true; |
| 8517 |
} |
| 8518 |
this.toggle( false ); |
| 8519 |
} |
| 8520 |
break; |
| 8521 |
case OO.ui.Keys.LEFT: |
| 8522 |
case OO.ui.Keys.RIGHT: |
| 8523 |
case OO.ui.Keys.HOME: |
| 8524 |
case OO.ui.Keys.END: |
| 8525 |
|
| 8526 |
|
| 8527 |
if ( !this.$input ) { |
| 8528 |
OO.ui.MenuSelectWidget.super.prototype.onDocumentKeyDown.call( this, e ); |
| 8529 |
} |
| 8530 |
break; |
| 8531 |
case OO.ui.Keys.ESCAPE: |
| 8532 |
if ( this.isVisible() ) { |
| 8533 |
if ( currentItem && !this.multiselect ) { |
| 8534 |
currentItem.setHighlighted( false ); |
| 8535 |
} |
| 8536 |
this.toggle( false ); |
| 8537 |
handled = true; |
| 8538 |
} |
| 8539 |
break; |
| 8540 |
default: |
| 8541 |
return OO.ui.MenuSelectWidget.super.prototype.onDocumentKeyDown.call( this, e ); |
| 8542 |
} |
| 8543 |
if ( handled ) { |
| 8544 |
e.preventDefault(); |
| 8545 |
e.stopPropagation(); |
| 8546 |
} |
| 8547 |
} |
| 8548 |
}; |
| 8549 |
|
| 8550 |
|
| 8551 |
|
| 8552 |
|
| 8553 |
|
| 8554 |
|
| 8555 |
OO.ui.MenuSelectWidget.prototype.getVisibleItems = function () { |
| 8556 |
return this.getItems().filter( ( item ) => item.isVisible() ); |
| 8557 |
}; |
| 8558 |
|
| 8559 |
|
| 8560 |
|
| 8561 |
|
| 8562 |
|
| 8563 |
|
| 8564 |
|
| 8565 |
OO.ui.MenuSelectWidget.prototype.updateItemVisibility = function () { |
| 8566 |
if ( !this.filterFromInput || !this.$input ) { |
| 8567 |
this.clip(); |
| 8568 |
return; |
| 8569 |
} |
| 8570 |
|
| 8571 |
let anyVisible = false; |
| 8572 |
|
| 8573 |
const showAll = !this.isVisible() || this.previouslySelectedValue === this.$input.val(), |
| 8574 |
filter = showAll ? null : this.getItemMatcher( this.$input.val(), this.filterMode ); |
| 8575 |
|
| 8576 |
|
| 8577 |
let item; |
| 8578 |
let section, sectionEmpty; |
| 8579 |
for ( let i = 0; i < this.items.length; i++ ) { |
| 8580 |
item = this.items[ i ]; |
| 8581 |
if ( item instanceof OO.ui.MenuSectionOptionWidget ) { |
| 8582 |
if ( section ) { |
| 8583 |
|
| 8584 |
section.toggle( showAll || !sectionEmpty ); |
| 8585 |
} |
| 8586 |
section = item; |
| 8587 |
sectionEmpty = true; |
| 8588 |
} else if ( item instanceof OO.ui.OptionWidget ) { |
| 8589 |
const visible = !filter || filter( item ); |
| 8590 |
anyVisible = anyVisible || visible; |
| 8591 |
sectionEmpty = sectionEmpty && !visible; |
| 8592 |
item.toggle( visible ); |
| 8593 |
} |
| 8594 |
} |
| 8595 |
|
| 8596 |
if ( section ) { |
| 8597 |
section.toggle( showAll || !sectionEmpty ); |
| 8598 |
} |
| 8599 |
|
| 8600 |
if ( !anyVisible ) { |
| 8601 |
this.highlightItem( null ); |
| 8602 |
} |
| 8603 |
|
| 8604 |
this.$element.toggleClass( 'oo-ui-menuSelectWidget-invisible', !anyVisible ); |
| 8605 |
|
| 8606 |
if ( this.highlightOnFilter && |
| 8607 |
!( this.lastHighlightedItem && this.lastHighlightedItem.isSelectable() ) && |
| 8608 |
this.isVisible() |
| 8609 |
) { |
| 8610 |
|
| 8611 |
item = this.findFirstSelectableItem(); |
| 8612 |
this.highlightItem( item ); |
| 8613 |
this.lastHighlightedItem = item; |
| 8614 |
} |
| 8615 |
|
| 8616 |
|
| 8617 |
this.clip(); |
| 8618 |
}; |
| 8619 |
|
| 8620 |
|
| 8621 |
|
| 8622 |
|
| 8623 |
OO.ui.MenuSelectWidget.prototype.bindDocumentKeyDownListener = function () { |
| 8624 |
if ( this.$input ) { |
| 8625 |
this.$input.on( 'keydown', this.onDocumentKeyDownHandler ); |
| 8626 |
} else { |
| 8627 |
OO.ui.MenuSelectWidget.super.prototype.bindDocumentKeyDownListener.call( this ); |
| 8628 |
} |
| 8629 |
}; |
| 8630 |
|
| 8631 |
|
| 8632 |
|
| 8633 |
|
| 8634 |
OO.ui.MenuSelectWidget.prototype.unbindDocumentKeyDownListener = function () { |
| 8635 |
if ( this.$input ) { |
| 8636 |
this.$input.off( 'keydown', this.onDocumentKeyDownHandler ); |
| 8637 |
} else { |
| 8638 |
OO.ui.MenuSelectWidget.super.prototype.unbindDocumentKeyDownListener.call( this ); |
| 8639 |
} |
| 8640 |
}; |
| 8641 |
|
| 8642 |
|
| 8643 |
|
| 8644 |
|
| 8645 |
OO.ui.MenuSelectWidget.prototype.bindDocumentKeyPressListener = function () { |
| 8646 |
if ( this.$input ) { |
| 8647 |
if ( this.filterFromInput ) { |
| 8648 |
this.$input.on( |
| 8649 |
'keydown mouseup cut paste change input select', |
| 8650 |
this.onInputEditHandler |
| 8651 |
); |
| 8652 |
this.$input.one( 'keypress', () => { |
| 8653 |
this.previouslySelectedValue = null; |
| 8654 |
} ); |
| 8655 |
this.previouslySelectedValue = this.$input.val(); |
| 8656 |
this.updateItemVisibility(); |
| 8657 |
} |
| 8658 |
} else { |
| 8659 |
OO.ui.MenuSelectWidget.super.prototype.bindDocumentKeyPressListener.call( this ); |
| 8660 |
} |
| 8661 |
}; |
| 8662 |
|
| 8663 |
|
| 8664 |
|
| 8665 |
|
| 8666 |
OO.ui.MenuSelectWidget.prototype.unbindDocumentKeyPressListener = function () { |
| 8667 |
if ( this.$input ) { |
| 8668 |
if ( this.filterFromInput ) { |
| 8669 |
this.$input.off( |
| 8670 |
'keydown mouseup cut paste change input select', |
| 8671 |
this.onInputEditHandler |
| 8672 |
); |
| 8673 |
this.updateItemVisibility(); |
| 8674 |
} |
| 8675 |
} else { |
| 8676 |
OO.ui.MenuSelectWidget.super.prototype.unbindDocumentKeyPressListener.call( this ); |
| 8677 |
} |
| 8678 |
}; |
| 8679 |
|
| 8680 |
|
| 8681 |
|
| 8682 |
|
| 8683 |
|
| 8684 |
|
| 8685 |
|
| 8686 |
with |
| 8687 |
|
| 8688 |
|
| 8689 |
|
| 8690 |
|
| 8691 |
|
| 8692 |
|
| 8693 |
|
| 8694 |
OO.ui.MenuSelectWidget.prototype.chooseItem = function ( item ) { |
| 8695 |
OO.ui.MenuSelectWidget.super.prototype.chooseItem.call( this, item ); |
| 8696 |
if ( this.hideOnChoose ) { |
| 8697 |
this.toggle( false ); |
| 8698 |
} |
| 8699 |
return this; |
| 8700 |
}; |
| 8701 |
|
| 8702 |
|
| 8703 |
|
| 8704 |
|
| 8705 |
OO.ui.MenuSelectWidget.prototype.addItems = function ( items, index ) { |
| 8706 |
if ( !items || items.length === 0 ) { |
| 8707 |
return this; |
| 8708 |
} |
| 8709 |
|
| 8710 |
|
| 8711 |
OO.ui.MenuSelectWidget.super.prototype.addItems.call( this, items, index ); |
| 8712 |
|
| 8713 |
this.updateItemVisibility(); |
| 8714 |
|
| 8715 |
return this; |
| 8716 |
}; |
| 8717 |
|
| 8718 |
|
| 8719 |
|
| 8720 |
|
| 8721 |
OO.ui.MenuSelectWidget.prototype.removeItems = function ( items ) { |
| 8722 |
|
| 8723 |
OO.ui.MenuSelectWidget.super.prototype.removeItems.call( this, items ); |
| 8724 |
|
| 8725 |
this.updateItemVisibility(); |
| 8726 |
|
| 8727 |
return this; |
| 8728 |
}; |
| 8729 |
|
| 8730 |
|
| 8731 |
|
| 8732 |
|
| 8733 |
OO.ui.MenuSelectWidget.prototype.clearItems = function () { |
| 8734 |
|
| 8735 |
OO.ui.MenuSelectWidget.super.prototype.clearItems.call( this ); |
| 8736 |
|
| 8737 |
this.updateItemVisibility(); |
| 8738 |
|
| 8739 |
return this; |
| 8740 |
}; |
| 8741 |
|
| 8742 |
|
| 8743 |
|
| 8744 |
|
| 8745 |
|
| 8746 |
|
| 8747 |
OO.ui.MenuSelectWidget.prototype.toggleScreenReaderMode = function ( screenReaderMode ) { |
| 8748 |
screenReaderMode = !!screenReaderMode; |
| 8749 |
this.screenReaderMode = screenReaderMode; |
| 8750 |
|
| 8751 |
this.$element.toggleClass( 'oo-ui-menuSelectWidget-screenReaderMode', this.screenReaderMode ); |
| 8752 |
|
| 8753 |
if ( screenReaderMode ) { |
| 8754 |
this.bindDocumentKeyDownListener(); |
| 8755 |
this.bindDocumentKeyPressListener(); |
| 8756 |
} else { |
| 8757 |
this.$focusOwner.removeAttr( 'aria-activedescendant' ); |
| 8758 |
this.unbindDocumentKeyDownListener(); |
| 8759 |
this.unbindDocumentKeyPressListener(); |
| 8760 |
} |
| 8761 |
}; |
| 8762 |
|
| 8763 |
|
| 8764 |
|
| 8765 |
|
| 8766 |
|
| 8767 |
|
| 8768 |
|
| 8769 |
|
| 8770 |
|
| 8771 |
|
| 8772 |
|
| 8773 |
|
| 8774 |
|
| 8775 |
OO.ui.MenuSelectWidget.prototype.toggle = function ( visible ) { |
| 8776 |
visible = ( visible === undefined ? !this.visible : !!visible ) && !!this.items.length; |
| 8777 |
const change = visible !== this.isVisible(); |
| 8778 |
|
| 8779 |
if ( visible && !this.warnedUnattached && !this.isElementAttached() ) { |
| 8780 |
OO.ui.warnDeprecation( 'MenuSelectWidget#toggle: Before calling this method, the menu must be attached to the DOM.' ); |
| 8781 |
this.warnedUnattached = true; |
| 8782 |
} |
| 8783 |
|
| 8784 |
if ( change && visible ) { |
| 8785 |
|
| 8786 |
|
| 8787 |
this.setVerticalPosition( this.originalVerticalPosition ); |
| 8788 |
} |
| 8789 |
|
| 8790 |
|
| 8791 |
OO.ui.MenuSelectWidget.super.prototype.toggle.call( this, visible ); |
| 8792 |
|
| 8793 |
if ( change ) { |
| 8794 |
if ( visible ) { |
| 8795 |
|
| 8796 |
if ( this.width ) { |
| 8797 |
this.setIdealSize( this.width ); |
| 8798 |
} else if ( this.$floatableContainer ) { |
| 8799 |
this.$clippable.css( 'width', 'auto' ); |
| 8800 |
this.setIdealSize( |
| 8801 |
this.$floatableContainer[ 0 ].offsetWidth > this.$clippable[ 0 ].offsetWidth ? |
| 8802 |
|
| 8803 |
this.$floatableContainer[ 0 ].offsetWidth : |
| 8804 |
|
| 8805 |
'auto' |
| 8806 |
); |
| 8807 |
this.$clippable.css( 'width', '' ); |
| 8808 |
} |
| 8809 |
|
| 8810 |
this.togglePositioning( !!this.$floatableContainer ); |
| 8811 |
this.toggleClipping( true ); |
| 8812 |
|
| 8813 |
if ( !this.screenReaderMode ) { |
| 8814 |
this.bindDocumentKeyDownListener(); |
| 8815 |
this.bindDocumentKeyPressListener(); |
| 8816 |
} |
| 8817 |
|
| 8818 |
if ( |
| 8819 |
( this.isClippedVertically() || this.isFloatableOutOfView() ) && |
| 8820 |
this.originalVerticalPosition !== 'center' |
| 8821 |
) { |
| 8822 |
|
| 8823 |
const originalHeight = this.$element.height(); |
| 8824 |
this.setVerticalPosition( |
| 8825 |
this.constructor.static.flippedPositions[ this.originalVerticalPosition ] |
| 8826 |
); |
| 8827 |
if ( this.isClippedVertically() || this.isFloatableOutOfView() ) { |
| 8828 |
|
| 8829 |
|
| 8830 |
const flippedHeight = this.$element.height(); |
| 8831 |
if ( originalHeight > flippedHeight ) { |
| 8832 |
this.setVerticalPosition( this.originalVerticalPosition ); |
| 8833 |
} |
| 8834 |
} |
| 8835 |
} |
| 8836 |
|
| 8837 |
|
| 8838 |
|
| 8839 |
this.$focusOwner.attr( 'aria-expanded', 'true' ); |
| 8840 |
this.$focusOwner.attr( 'aria-owns', this.getElementId() ); |
| 8841 |
|
| 8842 |
const selectedItem = !this.multiselect && this.findSelectedItem(); |
| 8843 |
if ( selectedItem ) { |
| 8844 |
|
| 8845 |
|
| 8846 |
|
| 8847 |
this.$focusOwner.attr( 'aria-activedescendant', selectedItem.getElementId() ); |
| 8848 |
selectedItem.scrollElementIntoView( { duration: 0 } ); |
| 8849 |
} |
| 8850 |
|
| 8851 |
|
| 8852 |
if ( this.autoHide ) { |
| 8853 |
this.getElementDocument().addEventListener( 'mousedown', this.onDocumentMouseDownHandler, true ); |
| 8854 |
} |
| 8855 |
|
| 8856 |
this.emit( 'ready' ); |
| 8857 |
} else { |
| 8858 |
this.$focusOwner.removeAttr( 'aria-activedescendant' ); |
| 8859 |
if ( !this.screenReaderMode ) { |
| 8860 |
this.unbindDocumentKeyDownListener(); |
| 8861 |
this.unbindDocumentKeyPressListener(); |
| 8862 |
} |
| 8863 |
this.$focusOwner.attr( 'aria-expanded', 'false' ); |
| 8864 |
this.$focusOwner.removeAttr( 'aria-owns' ); |
| 8865 |
this.getElementDocument().removeEventListener( 'mousedown', this.onDocumentMouseDownHandler, true ); |
| 8866 |
this.togglePositioning( false ); |
| 8867 |
this.toggleClipping( false ); |
| 8868 |
this.lastHighlightedItem = null; |
| 8869 |
} |
| 8870 |
} |
| 8871 |
|
| 8872 |
return this; |
| 8873 |
}; |
| 8874 |
|
| 8875 |
|
| 8876 |
|
| 8877 |
|
| 8878 |
OO.ui.MenuSelectWidget.prototype.scrollToTop = function () { |
| 8879 |
this.$element.scrollTop( 0 ); |
| 8880 |
}; |
| 8881 |
|
| 8882 |
|
| 8883 |
|
| 8884 |
|
| 8885 |
|
| 8886 |
|
| 8887 |
|
| 8888 |
|
| 8889 |
|
| 8890 |
|
| 8891 |
|
| 8892 |
|
| 8893 |
|
| 8894 |
|
| 8895 |
|
| 8896 |
|
| 8897 |
|
| 8898 |
|
| 8899 |
|
| 8900 |
|
| 8901 |
|
| 8902 |
|
| 8903 |
|
| 8904 |
|
| 8905 |
|
| 8906 |
|
| 8907 |
|
| 8908 |
|
| 8909 |
|
| 8910 |
|
| 8911 |
|
| 8912 |
|
| 8913 |
|
| 8914 |
|
| 8915 |
|
| 8916 |
|
| 8917 |
|
| 8918 |
|
| 8919 |
|
| 8920 |
|
| 8921 |
|
| 8922 |
|
| 8923 |
|
| 8924 |
|
| 8925 |
|
| 8926 |
|
| 8927 |
|
| 8928 |
|
| 8929 |
|
| 8930 |
|
| 8931 |
|
| 8932 |
|
| 8933 |
|
| 8934 |
|
| 8935 |
|
| 8936 |
|
| 8937 |
|
| 8938 |
|
| 8939 |
|
| 8940 |
OO.ui.DropdownWidget = function OoUiDropdownWidget( config ) { |
| 8941 |
|
| 8942 |
config = Object.assign( { indicator: 'down' }, config ); |
| 8943 |
|
| 8944 |
|
| 8945 |
OO.ui.DropdownWidget.super.call( this, config ); |
| 8946 |
|
| 8947 |
|
| 8948 |
this.$handle = $( '<span>' ); |
| 8949 |
this.$overlay = ( config.$overlay === true ? |
| 8950 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 8951 |
|
| 8952 |
|
| 8953 |
OO.ui.mixin.IconElement.call( this, config ); |
| 8954 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 8955 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 8956 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { |
| 8957 |
$titled: this.$label |
| 8958 |
}, config ) ); |
| 8959 |
OO.ui.mixin.TabIndexedElement.call( this, Object.assign( { |
| 8960 |
$tabIndexed: this.$handle |
| 8961 |
}, config ) ); |
| 8962 |
|
| 8963 |
|
| 8964 |
this.menu = new OO.ui.MenuSelectWidget( Object.assign( { |
| 8965 |
widget: this, |
| 8966 |
$floatableContainer: this.$element |
| 8967 |
}, config.menu ) ); |
| 8968 |
|
| 8969 |
|
| 8970 |
this.$handle.on( { |
| 8971 |
click: this.onClick.bind( this ), |
| 8972 |
keydown: this.onKeyDown.bind( this ), |
| 8973 |
focus: this.onFocus.bind( this ), |
| 8974 |
blur: this.onBlur.bind( this ) |
| 8975 |
} ); |
| 8976 |
this.menu.connect( this, { |
| 8977 |
select: 'onMenuSelect', |
| 8978 |
toggle: 'onMenuToggle' |
| 8979 |
} ); |
| 8980 |
|
| 8981 |
|
| 8982 |
const labelId = OO.ui.generateElementId(); |
| 8983 |
this.setLabelId( labelId ); |
| 8984 |
this.$label |
| 8985 |
.attr( { |
| 8986 |
role: 'textbox', |
| 8987 |
'aria-readonly': 'true' |
| 8988 |
} ); |
| 8989 |
this.$handle |
| 8990 |
.addClass( 'oo-ui-dropdownWidget-handle' ) |
| 8991 |
.append( this.$icon, this.$label, this.$indicator ) |
| 8992 |
.attr( { |
| 8993 |
role: 'combobox', |
| 8994 |
'aria-autocomplete': 'list', |
| 8995 |
'aria-expanded': 'false', |
| 8996 |
'aria-haspopup': 'true', |
| 8997 |
'aria-labelledby': labelId |
| 8998 |
} ); |
| 8999 |
this.$element |
| 9000 |
.addClass( 'oo-ui-dropdownWidget' ) |
| 9001 |
.append( this.$handle ); |
| 9002 |
this.$overlay.append( this.menu.$element ); |
| 9003 |
}; |
| 9004 |
|
| 9005 |
|
| 9006 |
|
| 9007 |
OO.inheritClass( OO.ui.DropdownWidget, OO.ui.Widget ); |
| 9008 |
OO.mixinClass( OO.ui.DropdownWidget, OO.ui.mixin.IconElement ); |
| 9009 |
OO.mixinClass( OO.ui.DropdownWidget, OO.ui.mixin.IndicatorElement ); |
| 9010 |
OO.mixinClass( OO.ui.DropdownWidget, OO.ui.mixin.LabelElement ); |
| 9011 |
OO.mixinClass( OO.ui.DropdownWidget, OO.ui.mixin.TitledElement ); |
| 9012 |
OO.mixinClass( OO.ui.DropdownWidget, OO.ui.mixin.TabIndexedElement ); |
| 9013 |
|
| 9014 |
|
| 9015 |
|
| 9016 |
|
| 9017 |
|
| 9018 |
|
| 9019 |
|
| 9020 |
|
| 9021 |
OO.ui.DropdownWidget.prototype.getMenu = function () { |
| 9022 |
return this.menu; |
| 9023 |
}; |
| 9024 |
|
| 9025 |
|
| 9026 |
|
| 9027 |
|
| 9028 |
|
| 9029 |
|
| 9030 |
|
| 9031 |
OO.ui.DropdownWidget.prototype.onMenuSelect = function ( item ) { |
| 9032 |
let selectedLabel; |
| 9033 |
|
| 9034 |
if ( !item ) { |
| 9035 |
this.setLabel( null ); |
| 9036 |
return; |
| 9037 |
} |
| 9038 |
|
| 9039 |
selectedLabel = item.getLabel(); |
| 9040 |
|
| 9041 |
|
| 9042 |
if ( selectedLabel instanceof $ ) { |
| 9043 |
selectedLabel = selectedLabel.clone(); |
| 9044 |
} |
| 9045 |
|
| 9046 |
this.setLabel( selectedLabel ); |
| 9047 |
}; |
| 9048 |
|
| 9049 |
|
| 9050 |
|
| 9051 |
|
| 9052 |
|
| 9053 |
|
| 9054 |
|
| 9055 |
OO.ui.DropdownWidget.prototype.onMenuToggle = function ( isVisible ) { |
| 9056 |
this.$element.toggleClass( 'oo-ui-dropdownWidget-open', isVisible ); |
| 9057 |
}; |
| 9058 |
|
| 9059 |
|
| 9060 |
|
| 9061 |
|
| 9062 |
|
| 9063 |
|
| 9064 |
|
| 9065 |
|
| 9066 |
OO.ui.DropdownWidget.prototype.onClick = function ( e ) { |
| 9067 |
if ( !this.isDisabled() && e.which === OO.ui.MouseButtons.LEFT ) { |
| 9068 |
this.menu.toggle(); |
| 9069 |
} |
| 9070 |
return false; |
| 9071 |
}; |
| 9072 |
|
| 9073 |
|
| 9074 |
|
| 9075 |
|
| 9076 |
|
| 9077 |
|
| 9078 |
|
| 9079 |
|
| 9080 |
OO.ui.DropdownWidget.prototype.onKeyDown = function ( e ) { |
| 9081 |
if ( !this.isDisabled() ) { |
| 9082 |
switch ( e.keyCode ) { |
| 9083 |
case OO.ui.Keys.ENTER: |
| 9084 |
this.menu.toggle(); |
| 9085 |
return false; |
| 9086 |
case OO.ui.Keys.SPACE: |
| 9087 |
if ( this.menu.keyPressBuffer === '' ) { |
| 9088 |
|
| 9089 |
|
| 9090 |
this.menu.toggle(); |
| 9091 |
return false; |
| 9092 |
} |
| 9093 |
break; |
| 9094 |
} |
| 9095 |
} |
| 9096 |
}; |
| 9097 |
|
| 9098 |
|
| 9099 |
|
| 9100 |
|
| 9101 |
|
| 9102 |
|
| 9103 |
|
| 9104 |
OO.ui.DropdownWidget.prototype.onFocus = function () { |
| 9105 |
this.menu.toggleScreenReaderMode( true ); |
| 9106 |
}; |
| 9107 |
|
| 9108 |
|
| 9109 |
|
| 9110 |
|
| 9111 |
|
| 9112 |
|
| 9113 |
|
| 9114 |
OO.ui.DropdownWidget.prototype.onBlur = function () { |
| 9115 |
this.menu.toggleScreenReaderMode( false ); |
| 9116 |
}; |
| 9117 |
|
| 9118 |
|
| 9119 |
|
| 9120 |
|
| 9121 |
OO.ui.DropdownWidget.prototype.setLabelledBy = function ( id ) { |
| 9122 |
const labelId = this.$label.attr( 'id' ); |
| 9123 |
|
| 9124 |
if ( id ) { |
| 9125 |
this.$handle.attr( 'aria-labelledby', id + ' ' + labelId ); |
| 9126 |
} else { |
| 9127 |
this.$handle.attr( 'aria-labelledby', labelId ); |
| 9128 |
} |
| 9129 |
}; |
| 9130 |
|
| 9131 |
|
| 9132 |
|
| 9133 |
|
| 9134 |
|
| 9135 |
|
| 9136 |
|
| 9137 |
|
| 9138 |
|
| 9139 |
|
| 9140 |
|
| 9141 |
|
| 9142 |
|
| 9143 |
|
| 9144 |
|
| 9145 |
OO.ui.RadioOptionWidget = function OoUiRadioOptionWidget( config ) { |
| 9146 |
|
| 9147 |
config = config || {}; |
| 9148 |
|
| 9149 |
|
| 9150 |
this.radio = new OO.ui.RadioInputWidget( { value: config.data, tabIndex: -1 } ); |
| 9151 |
|
| 9152 |
|
| 9153 |
OO.ui.RadioOptionWidget.super.call( this, config ); |
| 9154 |
|
| 9155 |
|
| 9156 |
|
| 9157 |
this.radio.$input.attr( 'role', 'presentation' ); |
| 9158 |
this.$element |
| 9159 |
.addClass( 'oo-ui-radioOptionWidget' ) |
| 9160 |
.attr( { role: 'radio', 'aria-checked': 'false' } ) |
| 9161 |
.removeAttr( 'aria-selected' ) |
| 9162 |
.prepend( this.radio.$element ); |
| 9163 |
}; |
| 9164 |
|
| 9165 |
|
| 9166 |
|
| 9167 |
OO.inheritClass( OO.ui.RadioOptionWidget, OO.ui.OptionWidget ); |
| 9168 |
|
| 9169 |
|
| 9170 |
|
| 9171 |
|
| 9172 |
|
| 9173 |
|
| 9174 |
|
| 9175 |
OO.ui.RadioOptionWidget.static.highlightable = false; |
| 9176 |
|
| 9177 |
|
| 9178 |
|
| 9179 |
|
| 9180 |
|
| 9181 |
OO.ui.RadioOptionWidget.static.pressable = false; |
| 9182 |
|
| 9183 |
|
| 9184 |
|
| 9185 |
|
| 9186 |
|
| 9187 |
OO.ui.RadioOptionWidget.static.tagName = 'label'; |
| 9188 |
|
| 9189 |
|
| 9190 |
|
| 9191 |
|
| 9192 |
|
| 9193 |
|
| 9194 |
OO.ui.RadioOptionWidget.prototype.setSelected = function ( state ) { |
| 9195 |
OO.ui.RadioOptionWidget.super.prototype.setSelected.call( this, state ); |
| 9196 |
|
| 9197 |
this.radio.setSelected( state ); |
| 9198 |
this.$element |
| 9199 |
.attr( 'aria-checked', this.selected.toString() ) |
| 9200 |
.removeAttr( 'aria-selected' ); |
| 9201 |
|
| 9202 |
return this; |
| 9203 |
}; |
| 9204 |
|
| 9205 |
|
| 9206 |
|
| 9207 |
|
| 9208 |
OO.ui.RadioOptionWidget.prototype.setDisabled = function ( disabled ) { |
| 9209 |
OO.ui.RadioOptionWidget.super.prototype.setDisabled.call( this, disabled ); |
| 9210 |
|
| 9211 |
this.radio.setDisabled( this.isDisabled() ); |
| 9212 |
|
| 9213 |
return this; |
| 9214 |
}; |
| 9215 |
|
| 9216 |
|
| 9217 |
|
| 9218 |
|
| 9219 |
|
| 9220 |
|
| 9221 |
|
| 9222 |
|
| 9223 |
|
| 9224 |
|
| 9225 |
|
| 9226 |
|
| 9227 |
|
| 9228 |
|
| 9229 |
|
| 9230 |
|
| 9231 |
|
| 9232 |
|
| 9233 |
|
| 9234 |
|
| 9235 |
|
| 9236 |
|
| 9237 |
|
| 9238 |
|
| 9239 |
|
| 9240 |
|
| 9241 |
|
| 9242 |
|
| 9243 |
|
| 9244 |
|
| 9245 |
|
| 9246 |
|
| 9247 |
|
| 9248 |
|
| 9249 |
|
| 9250 |
|
| 9251 |
|
| 9252 |
|
| 9253 |
OO.ui.RadioSelectWidget = function OoUiRadioSelectWidget( config ) { |
| 9254 |
|
| 9255 |
OO.ui.RadioSelectWidget.super.call( this, config ); |
| 9256 |
|
| 9257 |
|
| 9258 |
OO.ui.mixin.TabIndexedElement.call( this, config ); |
| 9259 |
|
| 9260 |
|
| 9261 |
this.$element.on( { |
| 9262 |
focus: this.bindDocumentKeyDownListener.bind( this ), |
| 9263 |
blur: this.unbindDocumentKeyDownListener.bind( this ) |
| 9264 |
} ); |
| 9265 |
|
| 9266 |
|
| 9267 |
this.$element |
| 9268 |
.addClass( 'oo-ui-radioSelectWidget' ) |
| 9269 |
.attr( 'role', 'radiogroup' ) |
| 9270 |
|
| 9271 |
.removeAttr( 'aria-multiselectable' ); |
| 9272 |
}; |
| 9273 |
|
| 9274 |
|
| 9275 |
|
| 9276 |
OO.inheritClass( OO.ui.RadioSelectWidget, OO.ui.SelectWidget ); |
| 9277 |
OO.mixinClass( OO.ui.RadioSelectWidget, OO.ui.mixin.TabIndexedElement ); |
| 9278 |
|
| 9279 |
|
| 9280 |
|
| 9281 |
|
| 9282 |
|
| 9283 |
|
| 9284 |
|
| 9285 |
|
| 9286 |
|
| 9287 |
|
| 9288 |
|
| 9289 |
|
| 9290 |
|
| 9291 |
|
| 9292 |
|
| 9293 |
|
| 9294 |
|
| 9295 |
|
| 9296 |
|
| 9297 |
OO.ui.MultioptionWidget = function OoUiMultioptionWidget( config ) { |
| 9298 |
|
| 9299 |
config = config || {}; |
| 9300 |
|
| 9301 |
|
| 9302 |
OO.ui.MultioptionWidget.super.call( this, config ); |
| 9303 |
|
| 9304 |
|
| 9305 |
OO.ui.mixin.ItemWidget.call( this ); |
| 9306 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 9307 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 9308 |
|
| 9309 |
|
| 9310 |
this.selected = null; |
| 9311 |
|
| 9312 |
|
| 9313 |
this.$element |
| 9314 |
.addClass( 'oo-ui-multioptionWidget' ) |
| 9315 |
.append( this.$label ); |
| 9316 |
this.setSelected( config.selected ); |
| 9317 |
}; |
| 9318 |
|
| 9319 |
|
| 9320 |
|
| 9321 |
OO.inheritClass( OO.ui.MultioptionWidget, OO.ui.Widget ); |
| 9322 |
OO.mixinClass( OO.ui.MultioptionWidget, OO.ui.mixin.ItemWidget ); |
| 9323 |
OO.mixinClass( OO.ui.MultioptionWidget, OO.ui.mixin.LabelElement ); |
| 9324 |
OO.mixinClass( OO.ui.MultioptionWidget, OO.ui.mixin.TitledElement ); |
| 9325 |
|
| 9326 |
|
| 9327 |
|
| 9328 |
|
| 9329 |
|
| 9330 |
|
| 9331 |
|
| 9332 |
|
| 9333 |
|
| 9334 |
|
| 9335 |
|
| 9336 |
|
| 9337 |
|
| 9338 |
|
| 9339 |
|
| 9340 |
|
| 9341 |
|
| 9342 |
OO.ui.MultioptionWidget.prototype.isSelected = function () { |
| 9343 |
return this.selected; |
| 9344 |
}; |
| 9345 |
|
| 9346 |
|
| 9347 |
on |
| 9348 |
’s |
| 9349 |
|
| 9350 |
|
| 9351 |
|
| 9352 |
|
| 9353 |
|
| 9354 |
|
| 9355 |
OO.ui.MultioptionWidget.prototype.setSelected = function ( state ) { |
| 9356 |
state = !!state; |
| 9357 |
if ( this.selected !== state ) { |
| 9358 |
this.selected = state; |
| 9359 |
this.emit( 'change', state ); |
| 9360 |
this.$element.toggleClass( 'oo-ui-multioptionWidget-selected', state ); |
| 9361 |
} |
| 9362 |
return this; |
| 9363 |
}; |
| 9364 |
|
| 9365 |
|
| 9366 |
|
| 9367 |
|
| 9368 |
|
| 9369 |
|
| 9370 |
|
| 9371 |
|
| 9372 |
|
| 9373 |
|
| 9374 |
|
| 9375 |
|
| 9376 |
|
| 9377 |
|
| 9378 |
|
| 9379 |
|
| 9380 |
|
| 9381 |
|
| 9382 |
|
| 9383 |
OO.ui.MultiselectWidget = function OoUiMultiselectWidget( config ) { |
| 9384 |
|
| 9385 |
OO.ui.MultiselectWidget.super.call( this, config ); |
| 9386 |
|
| 9387 |
|
| 9388 |
config = config || {}; |
| 9389 |
|
| 9390 |
|
| 9391 |
OO.ui.mixin.GroupWidget.call( this, config ); |
| 9392 |
OO.ui.mixin.TitledElement.call( this, config ); |
| 9393 |
|
| 9394 |
|
| 9395 |
this.aggregate( { |
| 9396 |
change: 'select' |
| 9397 |
} ); |
| 9398 |
|
| 9399 |
|
| 9400 |
this.connect( this, { |
| 9401 |
select: [ 'emit', 'change' ] |
| 9402 |
} ); |
| 9403 |
|
| 9404 |
|
| 9405 |
this.addItems( config.items || [] ); |
| 9406 |
this.$group.addClass( 'oo-ui-multiselectWidget-group' ); |
| 9407 |
this.$element.addClass( 'oo-ui-multiselectWidget' ) |
| 9408 |
.append( this.$group ); |
| 9409 |
}; |
| 9410 |
|
| 9411 |
|
| 9412 |
|
| 9413 |
OO.inheritClass( OO.ui.MultiselectWidget, OO.ui.Widget ); |
| 9414 |
OO.mixinClass( OO.ui.MultiselectWidget, OO.ui.mixin.GroupWidget ); |
| 9415 |
OO.mixinClass( OO.ui.MultiselectWidget, OO.ui.mixin.TitledElement ); |
| 9416 |
|
| 9417 |
|
| 9418 |
|
| 9419 |
|
| 9420 |
|
| 9421 |
|
| 9422 |
|
| 9423 |
|
| 9424 |
|
| 9425 |
|
| 9426 |
|
| 9427 |
|
| 9428 |
|
| 9429 |
|
| 9430 |
|
| 9431 |
|
| 9432 |
|
| 9433 |
|
| 9434 |
|
| 9435 |
|
| 9436 |
|
| 9437 |
|
| 9438 |
OO.ui.MultiselectWidget.prototype.findSelectedItems = function () { |
| 9439 |
return this.items.filter( ( item ) => item.isSelected() ); |
| 9440 |
}; |
| 9441 |
|
| 9442 |
|
| 9443 |
|
| 9444 |
|
| 9445 |
|
| 9446 |
|
| 9447 |
OO.ui.MultiselectWidget.prototype.findSelectedItemsData = function () { |
| 9448 |
return this.findSelectedItems().map( ( item ) => item.data ); |
| 9449 |
}; |
| 9450 |
|
| 9451 |
|
| 9452 |
|
| 9453 |
|
| 9454 |
|
| 9455 |
|
| 9456 |
|
| 9457 |
|
| 9458 |
OO.ui.MultiselectWidget.prototype.selectItems = function ( items ) { |
| 9459 |
const itemsSet = new Set( items ); |
| 9460 |
this.items.forEach( ( item ) => { |
| 9461 |
const selected = itemsSet.has( item ); |
| 9462 |
item.setSelected( selected ); |
| 9463 |
} ); |
| 9464 |
return this; |
| 9465 |
}; |
| 9466 |
|
| 9467 |
|
| 9468 |
|
| 9469 |
|
| 9470 |
|
| 9471 |
|
| 9472 |
|
| 9473 |
|
| 9474 |
OO.ui.MultiselectWidget.prototype.selectItemsByData = function ( datas ) { |
| 9475 |
const dataHashSet = new Set( datas.map( ( data ) => OO.getHash( data ) ) ); |
| 9476 |
this.items.forEach( ( item ) => { |
| 9477 |
const selected = dataHashSet.has( OO.getHash( item.getData() ) ); |
| 9478 |
item.setSelected( selected ); |
| 9479 |
} ); |
| 9480 |
return this; |
| 9481 |
}; |
| 9482 |
|
| 9483 |
|
| 9484 |
|
| 9485 |
|
| 9486 |
|
| 9487 |
|
| 9488 |
|
| 9489 |
|
| 9490 |
|
| 9491 |
|
| 9492 |
|
| 9493 |
|
| 9494 |
|
| 9495 |
|
| 9496 |
OO.ui.CheckboxMultioptionWidget = function OoUiCheckboxMultioptionWidget( config ) { |
| 9497 |
|
| 9498 |
config = config || {}; |
| 9499 |
|
| 9500 |
|
| 9501 |
this.checkbox = new OO.ui.CheckboxInputWidget(); |
| 9502 |
|
| 9503 |
|
| 9504 |
OO.ui.CheckboxMultioptionWidget.super.call( this, config ); |
| 9505 |
|
| 9506 |
|
| 9507 |
this.checkbox.on( 'change', this.onCheckboxChange.bind( this ) ); |
| 9508 |
this.$element.on( 'keydown', this.onKeyDown.bind( this ) ); |
| 9509 |
|
| 9510 |
|
| 9511 |
this.$element |
| 9512 |
.addClass( 'oo-ui-checkboxMultioptionWidget' ) |
| 9513 |
.prepend( this.checkbox.$element ); |
| 9514 |
}; |
| 9515 |
|
| 9516 |
|
| 9517 |
|
| 9518 |
OO.inheritClass( OO.ui.CheckboxMultioptionWidget, OO.ui.MultioptionWidget ); |
| 9519 |
|
| 9520 |
|
| 9521 |
|
| 9522 |
|
| 9523 |
|
| 9524 |
|
| 9525 |
|
| 9526 |
OO.ui.CheckboxMultioptionWidget.static.tagName = 'label'; |
| 9527 |
|
| 9528 |
|
| 9529 |
|
| 9530 |
|
| 9531 |
|
| 9532 |
|
| 9533 |
|
| 9534 |
|
| 9535 |
OO.ui.CheckboxMultioptionWidget.prototype.onCheckboxChange = function () { |
| 9536 |
this.setSelected( this.checkbox.isSelected() ); |
| 9537 |
}; |
| 9538 |
|
| 9539 |
|
| 9540 |
|
| 9541 |
|
| 9542 |
OO.ui.CheckboxMultioptionWidget.prototype.setSelected = function ( state ) { |
| 9543 |
OO.ui.CheckboxMultioptionWidget.super.prototype.setSelected.call( this, state ); |
| 9544 |
this.checkbox.setSelected( state ); |
| 9545 |
return this; |
| 9546 |
}; |
| 9547 |
|
| 9548 |
|
| 9549 |
|
| 9550 |
|
| 9551 |
OO.ui.CheckboxMultioptionWidget.prototype.setDisabled = function ( disabled ) { |
| 9552 |
OO.ui.CheckboxMultioptionWidget.super.prototype.setDisabled.call( this, disabled ); |
| 9553 |
this.checkbox.setDisabled( this.isDisabled() ); |
| 9554 |
return this; |
| 9555 |
}; |
| 9556 |
|
| 9557 |
|
| 9558 |
|
| 9559 |
|
| 9560 |
OO.ui.CheckboxMultioptionWidget.prototype.focus = function () { |
| 9561 |
this.checkbox.focus(); |
| 9562 |
}; |
| 9563 |
|
| 9564 |
|
| 9565 |
|
| 9566 |
|
| 9567 |
|
| 9568 |
|
| 9569 |
|
| 9570 |
OO.ui.CheckboxMultioptionWidget.prototype.onKeyDown = function ( e ) { |
| 9571 |
const element = this.getElementGroup(); |
| 9572 |
|
| 9573 |
let nextItem; |
| 9574 |
if ( e.keyCode === OO.ui.Keys.LEFT || e.keyCode === OO.ui.Keys.UP ) { |
| 9575 |
nextItem = element.getRelativeFocusableItem( this, -1 ); |
| 9576 |
} else if ( e.keyCode === OO.ui.Keys.RIGHT || e.keyCode === OO.ui.Keys.DOWN ) { |
| 9577 |
nextItem = element.getRelativeFocusableItem( this, 1 ); |
| 9578 |
} |
| 9579 |
|
| 9580 |
if ( nextItem ) { |
| 9581 |
e.preventDefault(); |
| 9582 |
nextItem.focus(); |
| 9583 |
} |
| 9584 |
}; |
| 9585 |
|
| 9586 |
|
| 9587 |
|
| 9588 |
|
| 9589 |
|
| 9590 |
|
| 9591 |
|
| 9592 |
|
| 9593 |
|
| 9594 |
|
| 9595 |
|
| 9596 |
|
| 9597 |
|
| 9598 |
|
| 9599 |
|
| 9600 |
|
| 9601 |
|
| 9602 |
|
| 9603 |
|
| 9604 |
|
| 9605 |
|
| 9606 |
|
| 9607 |
|
| 9608 |
|
| 9609 |
|
| 9610 |
|
| 9611 |
|
| 9612 |
|
| 9613 |
|
| 9614 |
|
| 9615 |
|
| 9616 |
|
| 9617 |
|
| 9618 |
|
| 9619 |
OO.ui.CheckboxMultiselectWidget = function OoUiCheckboxMultiselectWidget( config ) { |
| 9620 |
|
| 9621 |
OO.ui.CheckboxMultiselectWidget.super.call( this, config ); |
| 9622 |
|
| 9623 |
|
| 9624 |
this.$lastClicked = null; |
| 9625 |
|
| 9626 |
|
| 9627 |
this.$group.on( 'click', this.onClick.bind( this ) ); |
| 9628 |
|
| 9629 |
|
| 9630 |
this.$element.addClass( 'oo-ui-checkboxMultiselectWidget' ); |
| 9631 |
}; |
| 9632 |
|
| 9633 |
|
| 9634 |
|
| 9635 |
OO.inheritClass( OO.ui.CheckboxMultiselectWidget, OO.ui.MultiselectWidget ); |
| 9636 |
|
| 9637 |
|
| 9638 |
|
| 9639 |
|
| 9640 |
|
| 9641 |
|
| 9642 |
|
| 9643 |
|
| 9644 |
|
| 9645 |
|
| 9646 |
|
| 9647 |
|
| 9648 |
|
| 9649 |
|
| 9650 |
|
| 9651 |
OO.ui.CheckboxMultiselectWidget.prototype.getRelativeFocusableItem = function ( item, direction ) { |
| 9652 |
const increase = direction > 0 ? 1 : -1, |
| 9653 |
len = this.items.length; |
| 9654 |
|
| 9655 |
let nextIndex; |
| 9656 |
if ( item ) { |
| 9657 |
const currentIndex = this.items.indexOf( item ); |
| 9658 |
nextIndex = ( currentIndex + increase + len ) % len; |
| 9659 |
} else { |
| 9660 |
|
| 9661 |
|
| 9662 |
nextIndex = direction > 0 ? 0 : len - 1; |
| 9663 |
} |
| 9664 |
|
| 9665 |
for ( let i = 0; i < len; i++ ) { |
| 9666 |
item = this.items[ nextIndex ]; |
| 9667 |
if ( item && !item.isDisabled() ) { |
| 9668 |
return item; |
| 9669 |
} |
| 9670 |
nextIndex = ( nextIndex + increase + len ) % len; |
| 9671 |
} |
| 9672 |
return null; |
| 9673 |
}; |
| 9674 |
|
| 9675 |
|
| 9676 |
|
| 9677 |
|
| 9678 |
|
| 9679 |
|
| 9680 |
OO.ui.CheckboxMultiselectWidget.prototype.onClick = function ( e ) { |
| 9681 |
const $lastClicked = this.$lastClicked, |
| 9682 |
$nowClicked = $( e.target ).closest( '.oo-ui-checkboxMultioptionWidget' ) |
| 9683 |
.not( '.oo-ui-widget-disabled' ); |
| 9684 |
|
| 9685 |
|
| 9686 |
if ( $lastClicked && $nowClicked.length && e.shiftKey ) { |
| 9687 |
const $options = this.$group.find( '.oo-ui-checkboxMultioptionWidget' ); |
| 9688 |
const lastClickedIndex = $options.index( $lastClicked ); |
| 9689 |
const nowClickedIndex = $options.index( $nowClicked ); |
| 9690 |
|
| 9691 |
|
| 9692 |
if ( nowClickedIndex !== lastClickedIndex ) { |
| 9693 |
const items = this.items; |
| 9694 |
const wasSelected = items[ nowClickedIndex ].isSelected(); |
| 9695 |
const direction = nowClickedIndex > lastClickedIndex ? 1 : -1; |
| 9696 |
|
| 9697 |
|
| 9698 |
|
| 9699 |
for ( let i = lastClickedIndex; i !== nowClickedIndex; i += direction ) { |
| 9700 |
if ( !items[ i ].isDisabled() ) { |
| 9701 |
items[ i ].setSelected( !wasSelected ); |
| 9702 |
} |
| 9703 |
} |
| 9704 |
|
| 9705 |
|
| 9706 |
|
| 9707 |
|
| 9708 |
e.preventDefault(); |
| 9709 |
setTimeout( () => { |
| 9710 |
if ( !items[ nowClickedIndex ].isDisabled() ) { |
| 9711 |
items[ nowClickedIndex ].setSelected( !wasSelected ); |
| 9712 |
} |
| 9713 |
} ); |
| 9714 |
} |
| 9715 |
} |
| 9716 |
|
| 9717 |
if ( $nowClicked.length ) { |
| 9718 |
this.$lastClicked = $nowClicked; |
| 9719 |
} |
| 9720 |
}; |
| 9721 |
|
| 9722 |
|
| 9723 |
|
| 9724 |
|
| 9725 |
|
| 9726 |
|
| 9727 |
|
| 9728 |
OO.ui.CheckboxMultiselectWidget.prototype.focus = function () { |
| 9729 |
if ( !this.isDisabled() ) { |
| 9730 |
const item = this.getRelativeFocusableItem( null, 1 ); |
| 9731 |
if ( item ) { |
| 9732 |
item.focus(); |
| 9733 |
} |
| 9734 |
} |
| 9735 |
return this; |
| 9736 |
}; |
| 9737 |
|
| 9738 |
|
| 9739 |
|
| 9740 |
|
| 9741 |
OO.ui.CheckboxMultiselectWidget.prototype.simulateLabelClick = function () { |
| 9742 |
this.focus(); |
| 9743 |
}; |
| 9744 |
|
| 9745 |
|
| 9746 |
|
| 9747 |
|
| 9748 |
|
| 9749 |
|
| 9750 |
|
| 9751 |
|
| 9752 |
|
| 9753 |
|
| 9754 |
|
| 9755 |
|
| 9756 |
|
| 9757 |
|
| 9758 |
|
| 9759 |
|
| 9760 |
|
| 9761 |
|
| 9762 |
|
| 9763 |
|
| 9764 |
|
| 9765 |
|
| 9766 |
|
| 9767 |
|
| 9768 |
|
| 9769 |
|
| 9770 |
|
| 9771 |
|
| 9772 |
|
| 9773 |
|
| 9774 |
|
| 9775 |
|
| 9776 |
|
| 9777 |
|
| 9778 |
|
| 9779 |
|
| 9780 |
|
| 9781 |
|
| 9782 |
|
| 9783 |
|
| 9784 |
|
| 9785 |
|
| 9786 |
|
| 9787 |
|
| 9788 |
|
| 9789 |
|
| 9790 |
|
| 9791 |
OO.ui.ProgressBarWidget = function OoUiProgressBarWidget( config ) { |
| 9792 |
|
| 9793 |
config = config || {}; |
| 9794 |
|
| 9795 |
|
| 9796 |
OO.ui.ProgressBarWidget.super.call( this, config ); |
| 9797 |
|
| 9798 |
|
| 9799 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 9800 |
|
| 9801 |
|
| 9802 |
this.$bar = $( '<div>' ); |
| 9803 |
this.progress = null; |
| 9804 |
|
| 9805 |
|
| 9806 |
this.setProgress( config.progress !== undefined ? config.progress : false ); |
| 9807 |
this.$bar.addClass( 'oo-ui-progressBarWidget-bar' ); |
| 9808 |
this.$element |
| 9809 |
.attr( { |
| 9810 |
role: 'progressbar', |
| 9811 |
'aria-valuemin': 0, |
| 9812 |
'aria-valuemax': 100 |
| 9813 |
} ) |
| 9814 |
.addClass( 'oo-ui-progressBarWidget' ) |
| 9815 |
.append( this.$bar ); |
| 9816 |
|
| 9817 |
if ( config.inline ) { |
| 9818 |
this.$element.addClass( 'oo-ui-progressBarWidget-inline' ); |
| 9819 |
} |
| 9820 |
}; |
| 9821 |
|
| 9822 |
|
| 9823 |
|
| 9824 |
OO.inheritClass( OO.ui.ProgressBarWidget, OO.ui.Widget ); |
| 9825 |
OO.mixinClass( OO.ui.ProgressBarWidget, OO.ui.mixin.PendingElement ); |
| 9826 |
|
| 9827 |
|
| 9828 |
|
| 9829 |
|
| 9830 |
|
| 9831 |
|
| 9832 |
|
| 9833 |
OO.ui.ProgressBarWidget.static.tagName = 'div'; |
| 9834 |
|
| 9835 |
|
| 9836 |
|
| 9837 |
|
| 9838 |
|
| 9839 |
|
| 9840 |
|
| 9841 |
|
| 9842 |
|
| 9843 |
OO.ui.ProgressBarWidget.prototype.getProgress = function () { |
| 9844 |
return this.progress; |
| 9845 |
}; |
| 9846 |
|
| 9847 |
|
| 9848 |
|
| 9849 |
|
| 9850 |
|
| 9851 |
|
| 9852 |
OO.ui.ProgressBarWidget.prototype.setProgress = function ( progress ) { |
| 9853 |
this.progress = progress; |
| 9854 |
|
| 9855 |
if ( progress !== false ) { |
| 9856 |
this.$bar.css( 'width', this.progress + '%' ); |
| 9857 |
this.$element.attr( 'aria-valuenow', this.progress ); |
| 9858 |
} else { |
| 9859 |
this.$bar.css( 'width', '' ); |
| 9860 |
this.$element.removeAttr( 'aria-valuenow' ); |
| 9861 |
} |
| 9862 |
this.$element.toggleClass( 'oo-ui-progressBarWidget-indeterminate', progress === false ); |
| 9863 |
}; |
| 9864 |
|
| 9865 |
|
| 9866 |
|
| 9867 |
|
| 9868 |
|
| 9869 |
|
| 9870 |
|
| 9871 |
|
| 9872 |
|
| 9873 |
|
| 9874 |
|
| 9875 |
|
| 9876 |
|
| 9877 |
|
| 9878 |
|
| 9879 |
|
| 9880 |
|
| 9881 |
|
| 9882 |
|
| 9883 |
e. |
| 9884 |
|
| 9885 |
|
| 9886 |
e. |
| 9887 |
|
| 9888 |
|
| 9889 |
|
| 9890 |
OO.ui.InputWidget = function OoUiInputWidget( config ) { |
| 9891 |
|
| 9892 |
config = config || {}; |
| 9893 |
|
| 9894 |
|
| 9895 |
OO.ui.InputWidget.super.call( this, config ); |
| 9896 |
|
| 9897 |
|
| 9898 |
|
| 9899 |
this.$input = config.$input || this.getInputElement( config ); |
| 9900 |
this.value = ''; |
| 9901 |
this.inputFilter = config.inputFilter; |
| 9902 |
|
| 9903 |
|
| 9904 |
OO.ui.mixin.TabIndexedElement.call( this, Object.assign( { |
| 9905 |
$tabIndexed: this.$input |
| 9906 |
}, config ) ); |
| 9907 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { |
| 9908 |
$titled: this.$input |
| 9909 |
}, config ) ); |
| 9910 |
OO.ui.mixin.AccessKeyedElement.call( this, Object.assign( { |
| 9911 |
$accessKeyed: this.$input |
| 9912 |
}, config ) ); |
| 9913 |
|
| 9914 |
|
| 9915 |
this.$input.on( 'keydown mouseup cut paste change input select', this.onEdit.bind( this ) ); |
| 9916 |
|
| 9917 |
|
| 9918 |
this.$input |
| 9919 |
.addClass( 'oo-ui-inputWidget-input' ) |
| 9920 |
.attr( 'name', config.name ) |
| 9921 |
.prop( 'disabled', this.isDisabled() ); |
| 9922 |
this.$element |
| 9923 |
.addClass( 'oo-ui-inputWidget' ) |
| 9924 |
.append( this.$input ); |
| 9925 |
this.setValue( config.value ); |
| 9926 |
if ( config.dir ) { |
| 9927 |
this.setDir( config.dir ); |
| 9928 |
} |
| 9929 |
if ( config.inputId !== undefined ) { |
| 9930 |
this.setInputId( config.inputId ); |
| 9931 |
} |
| 9932 |
}; |
| 9933 |
|
| 9934 |
|
| 9935 |
|
| 9936 |
OO.inheritClass( OO.ui.InputWidget, OO.ui.Widget ); |
| 9937 |
OO.mixinClass( OO.ui.InputWidget, OO.ui.mixin.TabIndexedElement ); |
| 9938 |
OO.mixinClass( OO.ui.InputWidget, OO.ui.mixin.TitledElement ); |
| 9939 |
OO.mixinClass( OO.ui.InputWidget, OO.ui.mixin.AccessKeyedElement ); |
| 9940 |
|
| 9941 |
|
| 9942 |
|
| 9943 |
|
| 9944 |
|
| 9945 |
|
| 9946 |
OO.ui.InputWidget.static.reusePreInfuseDOM = function ( node, config ) { |
| 9947 |
const $input = $( node ).find( '.oo-ui-inputWidget-input' ); |
| 9948 |
config = OO.ui.InputWidget.super.static.reusePreInfuseDOM( node, config ); |
| 9949 |
|
| 9950 |
if ( $input.length ) { |
| 9951 |
config.$input = $input; |
| 9952 |
} |
| 9953 |
return config; |
| 9954 |
}; |
| 9955 |
|
| 9956 |
|
| 9957 |
|
| 9958 |
|
| 9959 |
OO.ui.InputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 9960 |
const state = OO.ui.InputWidget.super.static.gatherPreInfuseState( node, config ); |
| 9961 |
if ( config.$input ) { |
| 9962 |
state.value = config.$input.val(); |
| 9963 |
|
| 9964 |
|
| 9965 |
state.focus = config.$input.is( ':focus' ); |
| 9966 |
} |
| 9967 |
return state; |
| 9968 |
}; |
| 9969 |
|
| 9970 |
|
| 9971 |
|
| 9972 |
|
| 9973 |
|
| 9974 |
|
| 9975 |
|
| 9976 |
|
| 9977 |
|
| 9978 |
|
| 9979 |
|
| 9980 |
|
| 9981 |
|
| 9982 |
|
| 9983 |
|
| 9984 |
|
| 9985 |
|
| 9986 |
|
| 9987 |
|
| 9988 |
|
| 9989 |
|
| 9990 |
|
| 9991 |
OO.ui.InputWidget.prototype.getInputElement = function () { |
| 9992 |
return $( '<input>' ); |
| 9993 |
}; |
| 9994 |
|
| 9995 |
|
| 9996 |
|
| 9997 |
|
| 9998 |
|
| 9999 |
|
| 10000 |
|
| 10001 |
OO.ui.InputWidget.prototype.onEdit = function () { |
| 10002 |
if ( !this.isDisabled() ) { |
| 10003 |
this.setValue( this.$input.val() ); |
| 10004 |
|
| 10005 |
|
| 10006 |
|
| 10007 |
|
| 10008 |
setTimeout( () => { |
| 10009 |
this.setValue( this.$input.val() ); |
| 10010 |
} ); |
| 10011 |
} |
| 10012 |
}; |
| 10013 |
|
| 10014 |
|
| 10015 |
|
| 10016 |
|
| 10017 |
|
| 10018 |
|
| 10019 |
OO.ui.InputWidget.prototype.getValue = function () { |
| 10020 |
|
| 10021 |
|
| 10022 |
const value = this.$input.val(); |
| 10023 |
if ( this.value !== value ) { |
| 10024 |
this.setValue( value ); |
| 10025 |
} |
| 10026 |
return this.value; |
| 10027 |
}; |
| 10028 |
|
| 10029 |
|
| 10030 |
|
| 10031 |
|
| 10032 |
|
| 10033 |
|
| 10034 |
|
| 10035 |
|
| 10036 |
OO.ui.InputWidget.prototype.setDir = function ( dir ) { |
| 10037 |
this.$input.prop( 'dir', dir ); |
| 10038 |
return this; |
| 10039 |
}; |
| 10040 |
|
| 10041 |
|
| 10042 |
|
| 10043 |
|
| 10044 |
|
| 10045 |
|
| 10046 |
|
| 10047 |
|
| 10048 |
|
| 10049 |
OO.ui.InputWidget.prototype.setValue = function ( value ) { |
| 10050 |
value = this.cleanUpValue( value ); |
| 10051 |
|
| 10052 |
|
| 10053 |
if ( this.$input.val() !== value ) { |
| 10054 |
this.$input.val( value ); |
| 10055 |
} |
| 10056 |
if ( this.value !== value ) { |
| 10057 |
this.value = value; |
| 10058 |
this.emit( 'change', this.value ); |
| 10059 |
} |
| 10060 |
|
| 10061 |
|
| 10062 |
|
| 10063 |
if ( this.defaultValue === undefined ) { |
| 10064 |
this.defaultValue = this.value; |
| 10065 |
this.$input[ 0 ].defaultValue = this.defaultValue; |
| 10066 |
} |
| 10067 |
return this; |
| 10068 |
}; |
| 10069 |
|
| 10070 |
|
| 10071 |
|
| 10072 |
|
| 10073 |
|
| 10074 |
|
| 10075 |
|
| 10076 |
|
| 10077 |
|
| 10078 |
|
| 10079 |
OO.ui.InputWidget.prototype.cleanUpValue = function ( value ) { |
| 10080 |
if ( value === undefined || value === null ) { |
| 10081 |
return ''; |
| 10082 |
} else if ( this.inputFilter ) { |
| 10083 |
return this.inputFilter( String( value ) ); |
| 10084 |
} else { |
| 10085 |
return String( value ); |
| 10086 |
} |
| 10087 |
}; |
| 10088 |
|
| 10089 |
|
| 10090 |
|
| 10091 |
|
| 10092 |
OO.ui.InputWidget.prototype.setDisabled = function ( state ) { |
| 10093 |
OO.ui.InputWidget.super.prototype.setDisabled.call( this, state ); |
| 10094 |
if ( this.$input ) { |
| 10095 |
this.$input.prop( 'disabled', this.isDisabled() ); |
| 10096 |
} |
| 10097 |
return this; |
| 10098 |
}; |
| 10099 |
|
| 10100 |
|
| 10101 |
|
| 10102 |
|
| 10103 |
|
| 10104 |
|
| 10105 |
|
| 10106 |
|
| 10107 |
OO.ui.InputWidget.prototype.setInputId = function ( id ) { |
| 10108 |
this.$input.attr( 'id', id ); |
| 10109 |
return this; |
| 10110 |
}; |
| 10111 |
|
| 10112 |
|
| 10113 |
|
| 10114 |
|
| 10115 |
OO.ui.InputWidget.prototype.restorePreInfuseState = function ( state ) { |
| 10116 |
OO.ui.InputWidget.super.prototype.restorePreInfuseState.call( this, state ); |
| 10117 |
if ( state.value !== undefined && state.value !== this.getValue() ) { |
| 10118 |
this.setValue( state.value ); |
| 10119 |
} |
| 10120 |
if ( state.focus ) { |
| 10121 |
this.focus(); |
| 10122 |
} |
| 10123 |
}; |
| 10124 |
|
| 10125 |
|
| 10126 |
|
| 10127 |
|
| 10128 |
|
| 10129 |
|
| 10130 |
|
| 10131 |
|
| 10132 |
|
| 10133 |
|
| 10134 |
e. |
| 10135 |
|
| 10136 |
OO.ui.HiddenInputWidget = function OoUiHiddenInputWidget( config ) { |
| 10137 |
|
| 10138 |
config = Object.assign( { value: '', name: '' }, config ); |
| 10139 |
|
| 10140 |
|
| 10141 |
OO.ui.HiddenInputWidget.super.call( this, config ); |
| 10142 |
|
| 10143 |
|
| 10144 |
this.$element.attr( { |
| 10145 |
type: 'hidden', |
| 10146 |
value: config.value, |
| 10147 |
name: config.name |
| 10148 |
} ); |
| 10149 |
this.$element.removeAttr( 'aria-disabled' ); |
| 10150 |
}; |
| 10151 |
|
| 10152 |
|
| 10153 |
|
| 10154 |
OO.inheritClass( OO.ui.HiddenInputWidget, OO.ui.Widget ); |
| 10155 |
|
| 10156 |
|
| 10157 |
|
| 10158 |
|
| 10159 |
|
| 10160 |
|
| 10161 |
|
| 10162 |
OO.ui.HiddenInputWidget.static.tagName = 'input'; |
| 10163 |
|
| 10164 |
|
| 10165 |
|
| 10166 |
|
| 10167 |
|
| 10168 |
|
| 10169 |
|
| 10170 |
|
| 10171 |
|
| 10172 |
|
| 10173 |
|
| 10174 |
|
| 10175 |
|
| 10176 |
|
| 10177 |
|
| 10178 |
|
| 10179 |
|
| 10180 |
|
| 10181 |
|
| 10182 |
|
| 10183 |
|
| 10184 |
|
| 10185 |
|
| 10186 |
|
| 10187 |
|
| 10188 |
|
| 10189 |
|
| 10190 |
|
| 10191 |
|
| 10192 |
|
| 10193 |
|
| 10194 |
|
| 10195 |
|
| 10196 |
|
| 10197 |
rm |
| 10198 |
|
| 10199 |
|
| 10200 |
|
| 10201 |
OO.ui.ButtonInputWidget = function OoUiButtonInputWidget( config ) { |
| 10202 |
|
| 10203 |
config = Object.assign( { type: 'button', useInputTag: false, formNoValidate: false }, config ); |
| 10204 |
|
| 10205 |
|
| 10206 |
if ( config.$input ) { |
| 10207 |
config.$input.empty(); |
| 10208 |
} |
| 10209 |
|
| 10210 |
|
| 10211 |
this.useInputTag = config.useInputTag; |
| 10212 |
|
| 10213 |
|
| 10214 |
OO.ui.ButtonInputWidget.super.call( this, config ); |
| 10215 |
|
| 10216 |
|
| 10217 |
OO.ui.mixin.ButtonElement.call( this, Object.assign( { |
| 10218 |
$button: this.$input |
| 10219 |
}, config ) ); |
| 10220 |
OO.ui.mixin.IconElement.call( this, config ); |
| 10221 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 10222 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 10223 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 10224 |
|
| 10225 |
|
| 10226 |
if ( !config.useInputTag ) { |
| 10227 |
this.$input.append( this.$icon, this.$label, this.$indicator ); |
| 10228 |
} |
| 10229 |
|
| 10230 |
if ( config.formNoValidate ) { |
| 10231 |
this.$input.attr( 'formnovalidate', 'formnovalidate' ); |
| 10232 |
} |
| 10233 |
|
| 10234 |
this.$element.addClass( 'oo-ui-buttonInputWidget' ); |
| 10235 |
}; |
| 10236 |
|
| 10237 |
|
| 10238 |
|
| 10239 |
OO.inheritClass( OO.ui.ButtonInputWidget, OO.ui.InputWidget ); |
| 10240 |
OO.mixinClass( OO.ui.ButtonInputWidget, OO.ui.mixin.ButtonElement ); |
| 10241 |
OO.mixinClass( OO.ui.ButtonInputWidget, OO.ui.mixin.IconElement ); |
| 10242 |
OO.mixinClass( OO.ui.ButtonInputWidget, OO.ui.mixin.IndicatorElement ); |
| 10243 |
OO.mixinClass( OO.ui.ButtonInputWidget, OO.ui.mixin.LabelElement ); |
| 10244 |
OO.mixinClass( OO.ui.ButtonInputWidget, OO.ui.mixin.FlaggedElement ); |
| 10245 |
|
| 10246 |
|
| 10247 |
|
| 10248 |
|
| 10249 |
|
| 10250 |
|
| 10251 |
|
| 10252 |
OO.ui.ButtonInputWidget.static.tagName = 'span'; |
| 10253 |
|
| 10254 |
|
| 10255 |
|
| 10256 |
|
| 10257 |
|
| 10258 |
|
| 10259 |
|
| 10260 |
OO.ui.ButtonInputWidget.prototype.getInputElement = function ( config ) { |
| 10261 |
const type = config.type === 'submit' || config.type === 'reset' ? config.type : 'button'; |
| 10262 |
return $( '<' + ( config.useInputTag ? 'input' : 'button' ) + ' type="' + type + '">' ); |
| 10263 |
}; |
| 10264 |
|
| 10265 |
|
| 10266 |
|
| 10267 |
|
| 10268 |
|
| 10269 |
|
| 10270 |
|
| 10271 |
|
| 10272 |
|
| 10273 |
|
| 10274 |
|
| 10275 |
OO.ui.ButtonInputWidget.prototype.setLabel = function ( label ) { |
| 10276 |
label = OO.ui.resolveMsg( label ); |
| 10277 |
|
| 10278 |
if ( this.useInputTag ) { |
| 10279 |
|
| 10280 |
if ( typeof label !== 'string' ) { |
| 10281 |
label = ''; |
| 10282 |
} |
| 10283 |
|
| 10284 |
this.$input.val( label ); |
| 10285 |
} |
| 10286 |
|
| 10287 |
return OO.ui.mixin.LabelElement.prototype.setLabel.call( this, label ); |
| 10288 |
}; |
| 10289 |
|
| 10290 |
|
| 10291 |
|
| 10292 |
|
| 10293 |
|
| 10294 |
|
| 10295 |
|
| 10296 |
|
| 10297 |
|
| 10298 |
|
| 10299 |
|
| 10300 |
OO.ui.ButtonInputWidget.prototype.setValue = function ( value ) { |
| 10301 |
if ( !this.useInputTag ) { |
| 10302 |
OO.ui.ButtonInputWidget.super.prototype.setValue.call( this, value ); |
| 10303 |
} |
| 10304 |
return this; |
| 10305 |
}; |
| 10306 |
|
| 10307 |
|
| 10308 |
|
| 10309 |
|
| 10310 |
OO.ui.ButtonInputWidget.prototype.getInputId = function () { |
| 10311 |
|
| 10312 |
|
| 10313 |
|
| 10314 |
return null; |
| 10315 |
}; |
| 10316 |
|
| 10317 |
|
| 10318 |
|
| 10319 |
|
| 10320 |
|
| 10321 |
|
| 10322 |
|
| 10323 |
|
| 10324 |
|
| 10325 |
|
| 10326 |
|
| 10327 |
|
| 10328 |
|
| 10329 |
|
| 10330 |
|
| 10331 |
|
| 10332 |
|
| 10333 |
|
| 10334 |
|
| 10335 |
|
| 10336 |
|
| 10337 |
|
| 10338 |
|
| 10339 |
|
| 10340 |
|
| 10341 |
|
| 10342 |
|
| 10343 |
|
| 10344 |
|
| 10345 |
|
| 10346 |
|
| 10347 |
|
| 10348 |
|
| 10349 |
|
| 10350 |
|
| 10351 |
|
| 10352 |
|
| 10353 |
|
| 10354 |
|
| 10355 |
|
| 10356 |
|
| 10357 |
|
| 10358 |
|
| 10359 |
|
| 10360 |
OO.ui.CheckboxInputWidget = function OoUiCheckboxInputWidget( config ) { |
| 10361 |
|
| 10362 |
config = config || {}; |
| 10363 |
|
| 10364 |
|
| 10365 |
OO.ui.CheckboxInputWidget.super.call( this, config ); |
| 10366 |
|
| 10367 |
|
| 10368 |
OO.ui.mixin.RequiredElement.call( this, Object.assign( {}, { |
| 10369 |
|
| 10370 |
indicatorElement: null |
| 10371 |
}, config ) ); |
| 10372 |
|
| 10373 |
|
| 10374 |
this.checkIcon = new OO.ui.IconWidget( { |
| 10375 |
icon: 'check', |
| 10376 |
classes: [ 'oo-ui-checkboxInputWidget-checkIcon' ] |
| 10377 |
} ); |
| 10378 |
|
| 10379 |
|
| 10380 |
this.$element |
| 10381 |
.addClass( 'oo-ui-checkboxInputWidget' ) |
| 10382 |
|
| 10383 |
.append( this.checkIcon.$element ); |
| 10384 |
this.setSelected( config.selected !== undefined ? config.selected : false ); |
| 10385 |
this.setIndeterminate( config.indeterminate !== undefined ? config.indeterminate : false ); |
| 10386 |
}; |
| 10387 |
|
| 10388 |
|
| 10389 |
|
| 10390 |
OO.inheritClass( OO.ui.CheckboxInputWidget, OO.ui.InputWidget ); |
| 10391 |
OO.mixinClass( OO.ui.CheckboxInputWidget, OO.ui.mixin.RequiredElement ); |
| 10392 |
|
| 10393 |
|
| 10394 |
|
| 10395 |
|
| 10396 |
|
| 10397 |
|
| 10398 |
|
| 10399 |
|
| 10400 |
|
| 10401 |
|
| 10402 |
|
| 10403 |
|
| 10404 |
|
| 10405 |
|
| 10406 |
|
| 10407 |
|
| 10408 |
OO.ui.CheckboxInputWidget.static.tagName = 'span'; |
| 10409 |
|
| 10410 |
|
| 10411 |
|
| 10412 |
|
| 10413 |
|
| 10414 |
|
| 10415 |
OO.ui.CheckboxInputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 10416 |
const state = OO.ui.CheckboxInputWidget.super.static.gatherPreInfuseState( node, config ); |
| 10417 |
if ( config.$input ) { |
| 10418 |
state.checked = config.$input.prop( 'checked' ); |
| 10419 |
} |
| 10420 |
return state; |
| 10421 |
}; |
| 10422 |
|
| 10423 |
|
| 10424 |
|
| 10425 |
|
| 10426 |
|
| 10427 |
|
| 10428 |
|
| 10429 |
OO.ui.CheckboxInputWidget.prototype.getInputElement = function () { |
| 10430 |
return $( '<input>' ).attr( 'type', 'checkbox' ); |
| 10431 |
}; |
| 10432 |
|
| 10433 |
|
| 10434 |
|
| 10435 |
|
| 10436 |
OO.ui.CheckboxInputWidget.prototype.onEdit = function () { |
| 10437 |
if ( !this.isDisabled() ) { |
| 10438 |
|
| 10439 |
setTimeout( () => { |
| 10440 |
this.setSelected( this.$input.prop( 'checked' ) ); |
| 10441 |
this.setIndeterminate( this.$input.prop( 'indeterminate' ) ); |
| 10442 |
} ); |
| 10443 |
} |
| 10444 |
}; |
| 10445 |
|
| 10446 |
|
| 10447 |
|
| 10448 |
|
| 10449 |
|
| 10450 |
|
| 10451 |
|
| 10452 |
|
| 10453 |
|
| 10454 |
OO.ui.CheckboxInputWidget.prototype.setSelected = function ( state, internal ) { |
| 10455 |
state = !!state; |
| 10456 |
if ( this.selected !== state ) { |
| 10457 |
this.selected = state; |
| 10458 |
this.$input.prop( 'checked', this.selected ); |
| 10459 |
if ( !internal ) { |
| 10460 |
this.setIndeterminate( false, true ); |
| 10461 |
this.emit( 'change', this.selected, this.indeterminate ); |
| 10462 |
} |
| 10463 |
} |
| 10464 |
|
| 10465 |
|
| 10466 |
|
| 10467 |
if ( this.defaultSelected === undefined ) { |
| 10468 |
this.defaultSelected = this.selected; |
| 10469 |
this.$input[ 0 ].defaultChecked = this.defaultSelected; |
| 10470 |
} |
| 10471 |
return this; |
| 10472 |
}; |
| 10473 |
|
| 10474 |
|
| 10475 |
|
| 10476 |
|
| 10477 |
|
| 10478 |
|
| 10479 |
OO.ui.CheckboxInputWidget.prototype.isSelected = function () { |
| 10480 |
|
| 10481 |
|
| 10482 |
const selected = this.$input.prop( 'checked' ); |
| 10483 |
if ( this.selected !== selected ) { |
| 10484 |
this.setSelected( selected ); |
| 10485 |
} |
| 10486 |
return this.selected; |
| 10487 |
}; |
| 10488 |
|
| 10489 |
|
| 10490 |
|
| 10491 |
|
| 10492 |
|
| 10493 |
|
| 10494 |
|
| 10495 |
|
| 10496 |
|
| 10497 |
OO.ui.CheckboxInputWidget.prototype.setIndeterminate = function ( state, internal ) { |
| 10498 |
state = !!state; |
| 10499 |
if ( this.indeterminate !== state ) { |
| 10500 |
this.indeterminate = state; |
| 10501 |
this.$input.prop( 'indeterminate', this.indeterminate ); |
| 10502 |
if ( !internal ) { |
| 10503 |
this.setSelected( false, true ); |
| 10504 |
this.emit( 'change', this.selected, this.indeterminate ); |
| 10505 |
} |
| 10506 |
} |
| 10507 |
return this; |
| 10508 |
}; |
| 10509 |
|
| 10510 |
|
| 10511 |
|
| 10512 |
|
| 10513 |
|
| 10514 |
|
| 10515 |
OO.ui.CheckboxInputWidget.prototype.isIndeterminate = function () { |
| 10516 |
|
| 10517 |
|
| 10518 |
const indeterminate = this.$input.prop( 'indeterminate' ); |
| 10519 |
if ( this.indeterminate !== indeterminate ) { |
| 10520 |
this.setIndeterminate( indeterminate ); |
| 10521 |
} |
| 10522 |
return this.indeterminate; |
| 10523 |
}; |
| 10524 |
|
| 10525 |
|
| 10526 |
|
| 10527 |
|
| 10528 |
OO.ui.CheckboxInputWidget.prototype.simulateLabelClick = function () { |
| 10529 |
if ( !this.isDisabled() ) { |
| 10530 |
this.$handle.trigger( 'click' ); |
| 10531 |
} |
| 10532 |
this.focus(); |
| 10533 |
}; |
| 10534 |
|
| 10535 |
|
| 10536 |
|
| 10537 |
|
| 10538 |
OO.ui.CheckboxInputWidget.prototype.restorePreInfuseState = function ( state ) { |
| 10539 |
OO.ui.CheckboxInputWidget.super.prototype.restorePreInfuseState.call( this, state ); |
| 10540 |
if ( state.checked !== undefined && state.checked !== this.isSelected() ) { |
| 10541 |
this.setSelected( state.checked ); |
| 10542 |
} |
| 10543 |
}; |
| 10544 |
|
| 10545 |
|
| 10546 |
|
| 10547 |
|
| 10548 |
|
| 10549 |
|
| 10550 |
|
| 10551 |
|
| 10552 |
|
| 10553 |
|
| 10554 |
|
| 10555 |
|
| 10556 |
|
| 10557 |
|
| 10558 |
|
| 10559 |
|
| 10560 |
|
| 10561 |
|
| 10562 |
|
| 10563 |
|
| 10564 |
|
| 10565 |
|
| 10566 |
|
| 10567 |
|
| 10568 |
|
| 10569 |
|
| 10570 |
|
| 10571 |
|
| 10572 |
|
| 10573 |
|
| 10574 |
|
| 10575 |
|
| 10576 |
|
| 10577 |
|
| 10578 |
|
| 10579 |
|
| 10580 |
|
| 10581 |
|
| 10582 |
|
| 10583 |
|
| 10584 |
OO.ui.DropdownInputWidget = function OoUiDropdownInputWidget( config ) { |
| 10585 |
|
| 10586 |
config = config || {}; |
| 10587 |
|
| 10588 |
|
| 10589 |
this.dropdownWidget = new OO.ui.DropdownWidget( Object.assign( |
| 10590 |
{ |
| 10591 |
$overlay: config.$overlay |
| 10592 |
}, |
| 10593 |
config.dropdown |
| 10594 |
) ); |
| 10595 |
|
| 10596 |
|
| 10597 |
this.setOptionsData( config.options || [] ); |
| 10598 |
|
| 10599 |
|
| 10600 |
OO.ui.DropdownInputWidget.super.call( this, config ); |
| 10601 |
|
| 10602 |
|
| 10603 |
OO.ui.mixin.RequiredElement.call( this, Object.assign( {}, { |
| 10604 |
|
| 10605 |
indicatorElement: null |
| 10606 |
}, config ) ); |
| 10607 |
|
| 10608 |
|
| 10609 |
this.dropdownWidget.getMenu().connect( this, { |
| 10610 |
select: 'onMenuSelect' |
| 10611 |
} ); |
| 10612 |
|
| 10613 |
|
| 10614 |
this.$element |
| 10615 |
.addClass( 'oo-ui-dropdownInputWidget' ) |
| 10616 |
.append( this.dropdownWidget.$element ); |
| 10617 |
if ( OO.ui.isMobile() ) { |
| 10618 |
this.$element.addClass( 'oo-ui-isMobile' ); |
| 10619 |
} |
| 10620 |
this.setTabIndexedElement( this.dropdownWidget.$tabIndexed ); |
| 10621 |
this.setTitledElement( this.dropdownWidget.$handle ); |
| 10622 |
}; |
| 10623 |
|
| 10624 |
|
| 10625 |
|
| 10626 |
OO.inheritClass( OO.ui.DropdownInputWidget, OO.ui.InputWidget ); |
| 10627 |
OO.mixinClass( OO.ui.DropdownInputWidget, OO.ui.mixin.RequiredElement ); |
| 10628 |
|
| 10629 |
|
| 10630 |
|
| 10631 |
|
| 10632 |
|
| 10633 |
|
| 10634 |
|
| 10635 |
OO.ui.DropdownInputWidget.prototype.getInputElement = function () { |
| 10636 |
return $( '<select>' ).addClass( 'oo-ui-indicator-down' ); |
| 10637 |
}; |
| 10638 |
|
| 10639 |
|
| 10640 |
|
| 10641 |
|
| 10642 |
|
| 10643 |
|
| 10644 |
|
| 10645 |
OO.ui.DropdownInputWidget.prototype.onMenuSelect = function ( item ) { |
| 10646 |
this.setValue( item ? item.getData() : '' ); |
| 10647 |
}; |
| 10648 |
|
| 10649 |
|
| 10650 |
|
| 10651 |
|
| 10652 |
OO.ui.DropdownInputWidget.prototype.setValue = function ( value ) { |
| 10653 |
value = this.cleanUpValue( value ); |
| 10654 |
|
| 10655 |
const selected = this.dropdownWidget.getMenu().findItemFromData( value ) || |
| 10656 |
this.dropdownWidget.getMenu().findFirstSelectableItem(); |
| 10657 |
this.dropdownWidget.getMenu().selectItem( selected ); |
| 10658 |
value = selected ? selected.getData() : ''; |
| 10659 |
OO.ui.DropdownInputWidget.super.prototype.setValue.call( this, value ); |
| 10660 |
if ( this.optionsDirty ) { |
| 10661 |
|
| 10662 |
|
| 10663 |
this.updateOptionsInterface(); |
| 10664 |
} |
| 10665 |
return this; |
| 10666 |
}; |
| 10667 |
|
| 10668 |
|
| 10669 |
|
| 10670 |
|
| 10671 |
OO.ui.DropdownInputWidget.prototype.setDisabled = function ( state ) { |
| 10672 |
this.dropdownWidget.setDisabled( state ); |
| 10673 |
OO.ui.DropdownInputWidget.super.prototype.setDisabled.call( this, state ); |
| 10674 |
return this; |
| 10675 |
}; |
| 10676 |
|
| 10677 |
|
| 10678 |
|
| 10679 |
|
| 10680 |
… }` |
| 10681 |
|
| 10682 |
|
| 10683 |
|
| 10684 |
OO.ui.DropdownInputWidget.prototype.setOptions = function ( options ) { |
| 10685 |
const value = this.getValue(); |
| 10686 |
|
| 10687 |
this.setOptionsData( options ); |
| 10688 |
|
| 10689 |
|
| 10690 |
|
| 10691 |
this.setValue( value ); |
| 10692 |
|
| 10693 |
return this; |
| 10694 |
}; |
| 10695 |
|
| 10696 |
|
| 10697 |
|
| 10698 |
|
| 10699 |
|
| 10700 |
|
| 10701 |
|
| 10702 |
|
| 10703 |
|
| 10704 |
|
| 10705 |
OO.ui.DropdownInputWidget.prototype.setOptionsData = function ( options ) { |
| 10706 |
this.optionsDirty = true; |
| 10707 |
|
| 10708 |
|
| 10709 |
|
| 10710 |
const optionWidgets = []; |
| 10711 |
let previousOptgroup; |
| 10712 |
for ( let optIndex = 0; optIndex < options.length; optIndex++ ) { |
| 10713 |
const opt = options[ optIndex ]; |
| 10714 |
|
| 10715 |
let optionWidget; |
| 10716 |
if ( opt.optgroup !== undefined ) { |
| 10717 |
|
| 10718 |
optionWidget = this.createMenuSectionOptionWidget( opt.optgroup ); |
| 10719 |
previousOptgroup = optionWidget; |
| 10720 |
|
| 10721 |
} else { |
| 10722 |
|
| 10723 |
const optValue = this.cleanUpValue( opt.data ); |
| 10724 |
optionWidget = this.createMenuOptionWidget( |
| 10725 |
optValue, |
| 10726 |
opt.label !== undefined ? opt.label : optValue |
| 10727 |
); |
| 10728 |
} |
| 10729 |
|
| 10730 |
|
| 10731 |
if ( |
| 10732 |
opt.disabled !== undefined || |
| 10733 |
previousOptgroup instanceof OO.ui.MenuSectionOptionWidget && |
| 10734 |
previousOptgroup.isDisabled() |
| 10735 |
) { |
| 10736 |
optionWidget.setDisabled( true ); |
| 10737 |
} |
| 10738 |
|
| 10739 |
optionWidgets.push( optionWidget ); |
| 10740 |
} |
| 10741 |
|
| 10742 |
this.dropdownWidget.getMenu().clearItems().addItems( optionWidgets ); |
| 10743 |
}; |
| 10744 |
|
| 10745 |
|
| 10746 |
|
| 10747 |
|
| 10748 |
|
| 10749 |
|
| 10750 |
|
| 10751 |
|
| 10752 |
|
| 10753 |
OO.ui.DropdownInputWidget.prototype.createMenuOptionWidget = function ( data, label ) { |
| 10754 |
return new OO.ui.MenuOptionWidget( { |
| 10755 |
data: data, |
| 10756 |
label: label |
| 10757 |
} ); |
| 10758 |
}; |
| 10759 |
|
| 10760 |
|
| 10761 |
|
| 10762 |
|
| 10763 |
|
| 10764 |
|
| 10765 |
|
| 10766 |
|
| 10767 |
OO.ui.DropdownInputWidget.prototype.createMenuSectionOptionWidget = function ( label ) { |
| 10768 |
return new OO.ui.MenuSectionOptionWidget( { |
| 10769 |
label: label |
| 10770 |
} ); |
| 10771 |
}; |
| 10772 |
|
| 10773 |
|
| 10774 |
|
| 10775 |
|
| 10776 |
|
| 10777 |
|
| 10778 |
|
| 10779 |
|
| 10780 |
OO.ui.DropdownInputWidget.prototype.updateOptionsInterface = function () { |
| 10781 |
let $optionsContainer = this.$input; |
| 10782 |
|
| 10783 |
const defaultValue = this.defaultValue; |
| 10784 |
|
| 10785 |
this.$input.empty(); |
| 10786 |
|
| 10787 |
this.dropdownWidget.getMenu().getItems().forEach( ( optionWidget ) => { |
| 10788 |
let $optionNode; |
| 10789 |
|
| 10790 |
if ( !( optionWidget instanceof OO.ui.MenuSectionOptionWidget ) ) { |
| 10791 |
$optionNode = $( '<option>' ) |
| 10792 |
.attr( 'value', optionWidget.getData() ) |
| 10793 |
.text( optionWidget.getLabel() ); |
| 10794 |
|
| 10795 |
|
| 10796 |
|
| 10797 |
$optionNode[ 0 ].defaultSelected = ( optionWidget.getData() === defaultValue ); |
| 10798 |
|
| 10799 |
$optionsContainer.append( $optionNode ); |
| 10800 |
} else { |
| 10801 |
$optionNode = $( '<optgroup>' ) |
| 10802 |
.attr( 'label', optionWidget.getLabel() ); |
| 10803 |
this.$input.append( $optionNode ); |
| 10804 |
$optionsContainer = $optionNode; |
| 10805 |
} |
| 10806 |
|
| 10807 |
|
| 10808 |
if ( optionWidget.isDisabled() ) { |
| 10809 |
$optionNode.prop( 'disabled', true ); |
| 10810 |
} |
| 10811 |
} ); |
| 10812 |
|
| 10813 |
this.optionsDirty = false; |
| 10814 |
}; |
| 10815 |
|
| 10816 |
|
| 10817 |
|
| 10818 |
|
| 10819 |
OO.ui.DropdownInputWidget.prototype.focus = function () { |
| 10820 |
this.dropdownWidget.focus(); |
| 10821 |
return this; |
| 10822 |
}; |
| 10823 |
|
| 10824 |
|
| 10825 |
|
| 10826 |
|
| 10827 |
OO.ui.DropdownInputWidget.prototype.blur = function () { |
| 10828 |
this.dropdownWidget.blur(); |
| 10829 |
return this; |
| 10830 |
}; |
| 10831 |
|
| 10832 |
|
| 10833 |
|
| 10834 |
|
| 10835 |
OO.ui.DropdownInputWidget.prototype.setLabelledBy = function ( id ) { |
| 10836 |
this.dropdownWidget.setLabelledBy( id ); |
| 10837 |
}; |
| 10838 |
|
| 10839 |
|
| 10840 |
|
| 10841 |
|
| 10842 |
|
| 10843 |
|
| 10844 |
|
| 10845 |
|
| 10846 |
|
| 10847 |
|
| 10848 |
|
| 10849 |
|
| 10850 |
|
| 10851 |
|
| 10852 |
|
| 10853 |
|
| 10854 |
|
| 10855 |
|
| 10856 |
|
| 10857 |
|
| 10858 |
|
| 10859 |
|
| 10860 |
|
| 10861 |
|
| 10862 |
|
| 10863 |
|
| 10864 |
|
| 10865 |
|
| 10866 |
|
| 10867 |
|
| 10868 |
|
| 10869 |
|
| 10870 |
|
| 10871 |
|
| 10872 |
|
| 10873 |
|
| 10874 |
|
| 10875 |
|
| 10876 |
|
| 10877 |
|
| 10878 |
|
| 10879 |
|
| 10880 |
|
| 10881 |
OO.ui.RadioInputWidget = function OoUiRadioInputWidget( config ) { |
| 10882 |
|
| 10883 |
config = config || {}; |
| 10884 |
|
| 10885 |
|
| 10886 |
OO.ui.RadioInputWidget.super.call( this, config ); |
| 10887 |
|
| 10888 |
|
| 10889 |
OO.ui.mixin.RequiredElement.call( this, Object.assign( {}, { |
| 10890 |
|
| 10891 |
indicatorElement: null |
| 10892 |
}, config ) ); |
| 10893 |
|
| 10894 |
|
| 10895 |
this.$element |
| 10896 |
.addClass( 'oo-ui-radioInputWidget' ) |
| 10897 |
|
| 10898 |
.append( $( '<span>' ) ); |
| 10899 |
this.setSelected( config.selected !== undefined ? config.selected : false ); |
| 10900 |
}; |
| 10901 |
|
| 10902 |
|
| 10903 |
|
| 10904 |
OO.inheritClass( OO.ui.RadioInputWidget, OO.ui.InputWidget ); |
| 10905 |
OO.mixinClass( OO.ui.RadioInputWidget, OO.ui.mixin.RequiredElement ); |
| 10906 |
|
| 10907 |
|
| 10908 |
|
| 10909 |
|
| 10910 |
|
| 10911 |
|
| 10912 |
|
| 10913 |
OO.ui.RadioInputWidget.static.tagName = 'span'; |
| 10914 |
|
| 10915 |
|
| 10916 |
|
| 10917 |
|
| 10918 |
|
| 10919 |
|
| 10920 |
OO.ui.RadioInputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 10921 |
const state = OO.ui.RadioInputWidget.super.static.gatherPreInfuseState( node, config ); |
| 10922 |
if ( config.$input ) { |
| 10923 |
state.checked = config.$input.prop( 'checked' ); |
| 10924 |
} |
| 10925 |
return state; |
| 10926 |
}; |
| 10927 |
|
| 10928 |
|
| 10929 |
|
| 10930 |
|
| 10931 |
|
| 10932 |
|
| 10933 |
|
| 10934 |
OO.ui.RadioInputWidget.prototype.getInputElement = function () { |
| 10935 |
return $( '<input>' ).attr( 'type', 'radio' ); |
| 10936 |
}; |
| 10937 |
|
| 10938 |
|
| 10939 |
|
| 10940 |
|
| 10941 |
OO.ui.RadioInputWidget.prototype.onEdit = function () { |
| 10942 |
|
| 10943 |
}; |
| 10944 |
|
| 10945 |
|
| 10946 |
|
| 10947 |
|
| 10948 |
|
| 10949 |
|
| 10950 |
|
| 10951 |
|
| 10952 |
OO.ui.RadioInputWidget.prototype.setSelected = function ( state ) { |
| 10953 |
|
| 10954 |
this.$input.prop( 'checked', state ); |
| 10955 |
|
| 10956 |
|
| 10957 |
|
| 10958 |
if ( this.defaultSelected === undefined ) { |
| 10959 |
this.defaultSelected = state; |
| 10960 |
this.$input[ 0 ].defaultChecked = this.defaultSelected; |
| 10961 |
} |
| 10962 |
return this; |
| 10963 |
}; |
| 10964 |
|
| 10965 |
|
| 10966 |
|
| 10967 |
|
| 10968 |
|
| 10969 |
|
| 10970 |
OO.ui.RadioInputWidget.prototype.isSelected = function () { |
| 10971 |
return this.$input.prop( 'checked' ); |
| 10972 |
}; |
| 10973 |
|
| 10974 |
|
| 10975 |
|
| 10976 |
|
| 10977 |
OO.ui.RadioInputWidget.prototype.simulateLabelClick = function () { |
| 10978 |
if ( !this.isDisabled() ) { |
| 10979 |
this.$input.trigger( 'click' ); |
| 10980 |
} |
| 10981 |
this.focus(); |
| 10982 |
}; |
| 10983 |
|
| 10984 |
|
| 10985 |
|
| 10986 |
|
| 10987 |
OO.ui.RadioInputWidget.prototype.restorePreInfuseState = function ( state ) { |
| 10988 |
OO.ui.RadioInputWidget.super.prototype.restorePreInfuseState.call( this, state ); |
| 10989 |
if ( state.checked !== undefined && state.checked !== this.isSelected() ) { |
| 10990 |
this.setSelected( state.checked ); |
| 10991 |
} |
| 10992 |
}; |
| 10993 |
|
| 10994 |
|
| 10995 |
|
| 10996 |
|
| 10997 |
|
| 10998 |
|
| 10999 |
|
| 11000 |
|
| 11001 |
|
| 11002 |
|
| 11003 |
|
| 11004 |
|
| 11005 |
|
| 11006 |
|
| 11007 |
|
| 11008 |
|
| 11009 |
|
| 11010 |
|
| 11011 |
|
| 11012 |
|
| 11013 |
|
| 11014 |
|
| 11015 |
|
| 11016 |
|
| 11017 |
|
| 11018 |
|
| 11019 |
|
| 11020 |
… }` |
| 11021 |
|
| 11022 |
OO.ui.RadioSelectInputWidget = function OoUiRadioSelectInputWidget( config ) { |
| 11023 |
|
| 11024 |
config = config || {}; |
| 11025 |
|
| 11026 |
|
| 11027 |
this.radioSelectWidget = new OO.ui.RadioSelectWidget(); |
| 11028 |
|
| 11029 |
|
| 11030 |
this.setOptionsData( config.options || [] ); |
| 11031 |
|
| 11032 |
|
| 11033 |
OO.ui.RadioSelectInputWidget.super.call( this, config ); |
| 11034 |
|
| 11035 |
|
| 11036 |
this.radioSelectWidget.connect( this, { |
| 11037 |
select: 'onMenuSelect' |
| 11038 |
} ); |
| 11039 |
|
| 11040 |
|
| 11041 |
this.$element |
| 11042 |
.addClass( 'oo-ui-radioSelectInputWidget' ) |
| 11043 |
.append( this.radioSelectWidget.$element ); |
| 11044 |
this.setTabIndexedElement( this.radioSelectWidget.$tabIndexed ); |
| 11045 |
}; |
| 11046 |
|
| 11047 |
|
| 11048 |
|
| 11049 |
OO.inheritClass( OO.ui.RadioSelectInputWidget, OO.ui.InputWidget ); |
| 11050 |
|
| 11051 |
|
| 11052 |
|
| 11053 |
|
| 11054 |
|
| 11055 |
|
| 11056 |
OO.ui.RadioSelectInputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 11057 |
const state = OO.ui.RadioSelectInputWidget.super.static.gatherPreInfuseState( node, config ); |
| 11058 |
state.value = $( node ).find( '.oo-ui-radioInputWidget .oo-ui-inputWidget-input:checked' ).val(); |
| 11059 |
return state; |
| 11060 |
}; |
| 11061 |
|
| 11062 |
|
| 11063 |
|
| 11064 |
|
| 11065 |
OO.ui.RadioSelectInputWidget.static.reusePreInfuseDOM = function ( node, config ) { |
| 11066 |
config = OO.ui.RadioSelectInputWidget.super.static.reusePreInfuseDOM( node, config ); |
| 11067 |
|
| 11068 |
delete config.$input; |
| 11069 |
return config; |
| 11070 |
}; |
| 11071 |
|
| 11072 |
|
| 11073 |
|
| 11074 |
|
| 11075 |
|
| 11076 |
|
| 11077 |
|
| 11078 |
OO.ui.RadioSelectInputWidget.prototype.getInputElement = function () { |
| 11079 |
|
| 11080 |
|
| 11081 |
return $( '<input>' ).addClass( 'oo-ui-element-hidden' ); |
| 11082 |
}; |
| 11083 |
|
| 11084 |
|
| 11085 |
|
| 11086 |
|
| 11087 |
|
| 11088 |
|
| 11089 |
|
| 11090 |
OO.ui.RadioSelectInputWidget.prototype.onMenuSelect = function ( item ) { |
| 11091 |
this.setValue( item.getData() ); |
| 11092 |
}; |
| 11093 |
|
| 11094 |
|
| 11095 |
|
| 11096 |
|
| 11097 |
OO.ui.RadioSelectInputWidget.prototype.setValue = function ( value ) { |
| 11098 |
value = this.cleanUpValue( value ); |
| 11099 |
|
| 11100 |
const selected = this.radioSelectWidget.findItemFromData( value ) || |
| 11101 |
this.radioSelectWidget.findFirstSelectableItem(); |
| 11102 |
this.radioSelectWidget.selectItem( selected ); |
| 11103 |
value = selected ? selected.getData() : ''; |
| 11104 |
OO.ui.RadioSelectInputWidget.super.prototype.setValue.call( this, value ); |
| 11105 |
return this; |
| 11106 |
}; |
| 11107 |
|
| 11108 |
|
| 11109 |
|
| 11110 |
|
| 11111 |
OO.ui.RadioSelectInputWidget.prototype.setDisabled = function ( state ) { |
| 11112 |
this.radioSelectWidget.setDisabled( state ); |
| 11113 |
OO.ui.RadioSelectInputWidget.super.prototype.setDisabled.call( this, state ); |
| 11114 |
return this; |
| 11115 |
}; |
| 11116 |
|
| 11117 |
|
| 11118 |
|
| 11119 |
|
| 11120 |
… }` |
| 11121 |
|
| 11122 |
|
| 11123 |
|
| 11124 |
OO.ui.RadioSelectInputWidget.prototype.setOptions = function ( options ) { |
| 11125 |
const value = this.getValue(); |
| 11126 |
|
| 11127 |
this.setOptionsData( options ); |
| 11128 |
|
| 11129 |
|
| 11130 |
|
| 11131 |
this.setValue( value ); |
| 11132 |
|
| 11133 |
return this; |
| 11134 |
}; |
| 11135 |
|
| 11136 |
|
| 11137 |
|
| 11138 |
|
| 11139 |
|
| 11140 |
|
| 11141 |
|
| 11142 |
… }` |
| 11143 |
|
| 11144 |
|
| 11145 |
OO.ui.RadioSelectInputWidget.prototype.setOptionsData = function ( options ) { |
| 11146 |
this.radioSelectWidget |
| 11147 |
.clearItems() |
| 11148 |
.addItems( options.map( ( opt ) => { |
| 11149 |
const optValue = this.cleanUpValue( opt.data ); |
| 11150 |
return new OO.ui.RadioOptionWidget( { |
| 11151 |
data: optValue, |
| 11152 |
label: opt.label !== undefined ? opt.label : optValue |
| 11153 |
} ); |
| 11154 |
} ) ); |
| 11155 |
}; |
| 11156 |
|
| 11157 |
|
| 11158 |
|
| 11159 |
|
| 11160 |
OO.ui.RadioSelectInputWidget.prototype.focus = function () { |
| 11161 |
this.radioSelectWidget.focus(); |
| 11162 |
return this; |
| 11163 |
}; |
| 11164 |
|
| 11165 |
|
| 11166 |
|
| 11167 |
|
| 11168 |
OO.ui.RadioSelectInputWidget.prototype.blur = function () { |
| 11169 |
this.radioSelectWidget.blur(); |
| 11170 |
return this; |
| 11171 |
}; |
| 11172 |
|
| 11173 |
|
| 11174 |
|
| 11175 |
|
| 11176 |
|
| 11177 |
|
| 11178 |
|
| 11179 |
|
| 11180 |
|
| 11181 |
|
| 11182 |
|
| 11183 |
|
| 11184 |
|
| 11185 |
|
| 11186 |
|
| 11187 |
|
| 11188 |
|
| 11189 |
|
| 11190 |
|
| 11191 |
|
| 11192 |
|
| 11193 |
|
| 11194 |
|
| 11195 |
|
| 11196 |
|
| 11197 |
|
| 11198 |
|
| 11199 |
… }` |
| 11200 |
|
| 11201 |
OO.ui.CheckboxMultiselectInputWidget = function OoUiCheckboxMultiselectInputWidget( config ) { |
| 11202 |
|
| 11203 |
config = config || {}; |
| 11204 |
|
| 11205 |
|
| 11206 |
this.checkboxMultiselectWidget = new OO.ui.CheckboxMultiselectWidget(); |
| 11207 |
|
| 11208 |
this.inputName = config.name; |
| 11209 |
|
| 11210 |
|
| 11211 |
this.setOptionsData( config.options || [] ); |
| 11212 |
|
| 11213 |
|
| 11214 |
OO.ui.CheckboxMultiselectInputWidget.super.call( this, config ); |
| 11215 |
|
| 11216 |
|
| 11217 |
|
| 11218 |
|
| 11219 |
|
| 11220 |
|
| 11221 |
|
| 11222 |
this.onCheckboxesSelectHandler = OO.ui.debounce( this.onCheckboxesSelect ); |
| 11223 |
this.checkboxMultiselectWidget.connect( this, { |
| 11224 |
select: 'onCheckboxesSelectHandler' |
| 11225 |
} ); |
| 11226 |
|
| 11227 |
|
| 11228 |
this.$element |
| 11229 |
.addClass( 'oo-ui-checkboxMultiselectInputWidget' ) |
| 11230 |
.append( this.checkboxMultiselectWidget.$element ); |
| 11231 |
|
| 11232 |
this.$input.detach(); |
| 11233 |
}; |
| 11234 |
|
| 11235 |
|
| 11236 |
|
| 11237 |
OO.inheritClass( OO.ui.CheckboxMultiselectInputWidget, OO.ui.InputWidget ); |
| 11238 |
|
| 11239 |
|
| 11240 |
|
| 11241 |
|
| 11242 |
|
| 11243 |
|
| 11244 |
OO.ui.CheckboxMultiselectInputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 11245 |
const state = OO.ui.CheckboxMultiselectInputWidget.super.static.gatherPreInfuseState( |
| 11246 |
node, config |
| 11247 |
); |
| 11248 |
state.value = $( node ).find( '.oo-ui-checkboxInputWidget .oo-ui-inputWidget-input:checked' ) |
| 11249 |
.toArray().map( ( el ) => el.value ); |
| 11250 |
return state; |
| 11251 |
}; |
| 11252 |
|
| 11253 |
|
| 11254 |
|
| 11255 |
|
| 11256 |
OO.ui.CheckboxMultiselectInputWidget.static.reusePreInfuseDOM = function ( node, config ) { |
| 11257 |
config = OO.ui.CheckboxMultiselectInputWidget.super.static.reusePreInfuseDOM( node, config ); |
| 11258 |
|
| 11259 |
delete config.$input; |
| 11260 |
return config; |
| 11261 |
}; |
| 11262 |
|
| 11263 |
|
| 11264 |
|
| 11265 |
|
| 11266 |
|
| 11267 |
|
| 11268 |
|
| 11269 |
OO.ui.CheckboxMultiselectInputWidget.prototype.getInputElement = function () { |
| 11270 |
|
| 11271 |
return $( '<unused>' ); |
| 11272 |
}; |
| 11273 |
|
| 11274 |
|
| 11275 |
|
| 11276 |
|
| 11277 |
|
| 11278 |
|
| 11279 |
OO.ui.CheckboxMultiselectInputWidget.prototype.onCheckboxesSelect = function () { |
| 11280 |
this.setValue( this.checkboxMultiselectWidget.findSelectedItemsData() ); |
| 11281 |
}; |
| 11282 |
|
| 11283 |
|
| 11284 |
|
| 11285 |
|
| 11286 |
OO.ui.CheckboxMultiselectInputWidget.prototype.getValue = function () { |
| 11287 |
const value = this.$element.find( '.oo-ui-checkboxInputWidget .oo-ui-inputWidget-input:checked' ) |
| 11288 |
.toArray().map( ( el ) => el.value ); |
| 11289 |
if ( !OO.compare( this.value, value ) ) { |
| 11290 |
this.setValue( value ); |
| 11291 |
} |
| 11292 |
return this.value; |
| 11293 |
}; |
| 11294 |
|
| 11295 |
|
| 11296 |
|
| 11297 |
|
| 11298 |
OO.ui.CheckboxMultiselectInputWidget.prototype.setValue = function ( value ) { |
| 11299 |
value = this.cleanUpValue( value ); |
| 11300 |
this.checkboxMultiselectWidget.selectItemsByData( value ); |
| 11301 |
OO.ui.CheckboxMultiselectInputWidget.super.prototype.setValue.call( this, value ); |
| 11302 |
if ( this.optionsDirty ) { |
| 11303 |
|
| 11304 |
|
| 11305 |
this.updateOptionsInterface(); |
| 11306 |
} |
| 11307 |
return this; |
| 11308 |
}; |
| 11309 |
|
| 11310 |
|
| 11311 |
|
| 11312 |
|
| 11313 |
|
| 11314 |
|
| 11315 |
|
| 11316 |
OO.ui.CheckboxMultiselectInputWidget.prototype.cleanUpValue = function ( value ) { |
| 11317 |
const cleanValue = []; |
| 11318 |
if ( !Array.isArray( value ) ) { |
| 11319 |
return cleanValue; |
| 11320 |
} |
| 11321 |
const dataHashSet = new Set( this.checkboxMultiselectWidget.getItems().map( ( item ) => OO.getHash( item.getData() ) ) ); |
| 11322 |
for ( let i = 0; i < value.length; i++ ) { |
| 11323 |
const singleValue = OO.ui.CheckboxMultiselectInputWidget.super.prototype.cleanUpValue |
| 11324 |
.call( this, value[ i ] ); |
| 11325 |
|
| 11326 |
if ( !dataHashSet.has( OO.getHash( singleValue ) ) ) { |
| 11327 |
continue; |
| 11328 |
} |
| 11329 |
cleanValue.push( singleValue ); |
| 11330 |
} |
| 11331 |
return cleanValue; |
| 11332 |
}; |
| 11333 |
|
| 11334 |
|
| 11335 |
|
| 11336 |
|
| 11337 |
OO.ui.CheckboxMultiselectInputWidget.prototype.setDisabled = function ( state ) { |
| 11338 |
this.checkboxMultiselectWidget.setDisabled( state ); |
| 11339 |
OO.ui.CheckboxMultiselectInputWidget.super.prototype.setDisabled.call( this, state ); |
| 11340 |
return this; |
| 11341 |
}; |
| 11342 |
|
| 11343 |
|
| 11344 |
|
| 11345 |
|
| 11346 |
|
| 11347 |
… }` |
| 11348 |
|
| 11349 |
|
| 11350 |
|
| 11351 |
OO.ui.CheckboxMultiselectInputWidget.prototype.setOptions = function ( options ) { |
| 11352 |
const value = this.getValue(); |
| 11353 |
|
| 11354 |
this.setOptionsData( options ); |
| 11355 |
|
| 11356 |
|
| 11357 |
|
| 11358 |
this.setValue( value ); |
| 11359 |
|
| 11360 |
return this; |
| 11361 |
}; |
| 11362 |
|
| 11363 |
|
| 11364 |
|
| 11365 |
|
| 11366 |
|
| 11367 |
|
| 11368 |
|
| 11369 |
|
| 11370 |
… }` |
| 11371 |
|
| 11372 |
|
| 11373 |
OO.ui.CheckboxMultiselectInputWidget.prototype.setOptionsData = function ( options ) { |
| 11374 |
this.optionsDirty = true; |
| 11375 |
|
| 11376 |
this.checkboxMultiselectWidget |
| 11377 |
.clearItems() |
| 11378 |
.addItems( options.map( ( opt ) => { |
| 11379 |
const optValue = OO.ui.CheckboxMultiselectInputWidget.super.prototype.cleanUpValue |
| 11380 |
.call( this, opt.data ); |
| 11381 |
const optDisabled = opt.disabled !== undefined ? opt.disabled : false; |
| 11382 |
const item = new OO.ui.CheckboxMultioptionWidget( { |
| 11383 |
data: optValue, |
| 11384 |
label: opt.label !== undefined ? opt.label : optValue, |
| 11385 |
disabled: optDisabled |
| 11386 |
} ); |
| 11387 |
|
| 11388 |
item.checkbox.$input.attr( 'name', this.inputName ); |
| 11389 |
item.checkbox.setValue( optValue ); |
| 11390 |
return item; |
| 11391 |
} ) ); |
| 11392 |
}; |
| 11393 |
|
| 11394 |
|
| 11395 |
|
| 11396 |
|
| 11397 |
|
| 11398 |
|
| 11399 |
|
| 11400 |
|
| 11401 |
OO.ui.CheckboxMultiselectInputWidget.prototype.updateOptionsInterface = function () { |
| 11402 |
const defaultValueSet = new Set( this.defaultValue ); |
| 11403 |
|
| 11404 |
this.checkboxMultiselectWidget.getItems().forEach( ( item ) => { |
| 11405 |
|
| 11406 |
|
| 11407 |
const isDefault = defaultValueSet.has( item.getData() ); |
| 11408 |
item.checkbox.defaultSelected = isDefault; |
| 11409 |
item.checkbox.$input[ 0 ].defaultChecked = isDefault; |
| 11410 |
} ); |
| 11411 |
|
| 11412 |
this.optionsDirty = false; |
| 11413 |
}; |
| 11414 |
|
| 11415 |
|
| 11416 |
|
| 11417 |
|
| 11418 |
OO.ui.CheckboxMultiselectInputWidget.prototype.focus = function () { |
| 11419 |
this.checkboxMultiselectWidget.focus(); |
| 11420 |
return this; |
| 11421 |
}; |
| 11422 |
|
| 11423 |
|
| 11424 |
|
| 11425 |
|
| 11426 |
|
| 11427 |
|
| 11428 |
|
| 11429 |
|
| 11430 |
|
| 11431 |
|
| 11432 |
|
| 11433 |
|
| 11434 |
|
| 11435 |
|
| 11436 |
|
| 11437 |
|
| 11438 |
|
| 11439 |
|
| 11440 |
|
| 11441 |
|
| 11442 |
|
| 11443 |
|
| 11444 |
|
| 11445 |
|
| 11446 |
|
| 11447 |
|
| 11448 |
|
| 11449 |
|
| 11450 |
|
| 11451 |
|
| 11452 |
|
| 11453 |
|
| 11454 |
|
| 11455 |
|
| 11456 |
|
| 11457 |
|
| 11458 |
|
| 11459 |
|
| 11460 |
|
| 11461 |
|
| 11462 |
|
| 11463 |
|
| 11464 |
|
| 11465 |
|
| 11466 |
|
| 11467 |
|
| 11468 |
|
| 11469 |
|
| 11470 |
|
| 11471 |
|
| 11472 |
|
| 11473 |
|
| 11474 |
|
| 11475 |
|
| 11476 |
OO.ui.TextInputWidget = function OoUiTextInputWidget( config ) { |
| 11477 |
|
| 11478 |
config = Object.assign( { |
| 11479 |
labelPosition: 'after' |
| 11480 |
}, config ); |
| 11481 |
config.type = this.getValidType( config ); |
| 11482 |
if ( config.autocomplete === false ) { |
| 11483 |
config.autocomplete = 'off'; |
| 11484 |
} else if ( config.autocomplete === true ) { |
| 11485 |
config.autocomplete = 'on'; |
| 11486 |
} |
| 11487 |
|
| 11488 |
|
| 11489 |
OO.ui.TextInputWidget.super.call( this, config ); |
| 11490 |
|
| 11491 |
|
| 11492 |
OO.ui.mixin.IconElement.call( this, config ); |
| 11493 |
OO.ui.mixin.IndicatorElement.call( this, config ); |
| 11494 |
OO.ui.mixin.PendingElement.call( this, Object.assign( { $pending: this.$input }, config ) ); |
| 11495 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 11496 |
OO.ui.mixin.FlaggedElement.call( this, config ); |
| 11497 |
OO.ui.mixin.RequiredElement.call( this, config ); |
| 11498 |
|
| 11499 |
|
| 11500 |
this.type = config.type; |
| 11501 |
this.readOnly = false; |
| 11502 |
this.validate = null; |
| 11503 |
this.scrollWidth = null; |
| 11504 |
|
| 11505 |
this.setValidation( config.validate ); |
| 11506 |
this.setLabelPosition( config.labelPosition ); |
| 11507 |
|
| 11508 |
|
| 11509 |
this.$input.on( { |
| 11510 |
keypress: this.onKeyPress.bind( this ), |
| 11511 |
blur: this.onBlur.bind( this ), |
| 11512 |
focus: this.onFocus.bind( this ) |
| 11513 |
} ); |
| 11514 |
this.$icon.on( 'mousedown', this.onIconMouseDown.bind( this ) ); |
| 11515 |
this.$indicator.on( 'mousedown', this.onIndicatorMouseDown.bind( this ) ); |
| 11516 |
this.on( 'labelChange', this.updatePosition.bind( this ) ); |
| 11517 |
this.on( 'change', OO.ui.debounce( this.onDebouncedChange.bind( this ), 250 ) ); |
| 11518 |
|
| 11519 |
|
| 11520 |
this.$element |
| 11521 |
.addClass( 'oo-ui-textInputWidget oo-ui-textInputWidget-type-' + config.type ) |
| 11522 |
.append( this.$icon, this.$indicator ); |
| 11523 |
this.setReadOnly( !!config.readOnly ); |
| 11524 |
if ( config.placeholder !== undefined ) { |
| 11525 |
this.$input.attr( 'placeholder', config.placeholder ); |
| 11526 |
} |
| 11527 |
if ( config.maxLength !== undefined ) { |
| 11528 |
this.$input.attr( 'maxlength', config.maxLength ); |
| 11529 |
} |
| 11530 |
if ( config.minLength !== undefined ) { |
| 11531 |
this.$input.attr( 'minlength', config.minLength ); |
| 11532 |
} |
| 11533 |
if ( config.autofocus ) { |
| 11534 |
this.$input.attr( 'autofocus', 'autofocus' ); |
| 11535 |
} |
| 11536 |
if ( config.autocomplete !== null && config.autocomplete !== undefined ) { |
| 11537 |
this.$input.attr( 'autocomplete', config.autocomplete ); |
| 11538 |
if ( config.autocomplete === 'off' ) { |
| 11539 |
|
| 11540 |
|
| 11541 |
|
| 11542 |
$( window ).on( { |
| 11543 |
beforeunload: function () { |
| 11544 |
this.$input.removeAttr( 'autocomplete' ); |
| 11545 |
}.bind( this ), |
| 11546 |
pageshow: function () { |
| 11547 |
|
| 11548 |
|
| 11549 |
this.$input.attr( 'autocomplete', 'off' ); |
| 11550 |
}.bind( this ) |
| 11551 |
} ); |
| 11552 |
} |
| 11553 |
} |
| 11554 |
if ( config.spellcheck !== undefined ) { |
| 11555 |
this.$input.attr( 'spellcheck', config.spellcheck ? 'true' : 'false' ); |
| 11556 |
} |
| 11557 |
if ( this.label ) { |
| 11558 |
this.isWaitingToBeAttached = true; |
| 11559 |
this.installParentChangeDetector(); |
| 11560 |
} |
| 11561 |
}; |
| 11562 |
|
| 11563 |
|
| 11564 |
|
| 11565 |
OO.inheritClass( OO.ui.TextInputWidget, OO.ui.InputWidget ); |
| 11566 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.IconElement ); |
| 11567 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.IndicatorElement ); |
| 11568 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.PendingElement ); |
| 11569 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.LabelElement ); |
| 11570 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.FlaggedElement ); |
| 11571 |
OO.mixinClass( OO.ui.TextInputWidget, OO.ui.mixin.RequiredElement ); |
| 11572 |
|
| 11573 |
|
| 11574 |
|
| 11575 |
OO.ui.TextInputWidget.static.validationPatterns = { |
| 11576 |
'non-empty': /.+/, |
| 11577 |
integer: /^\d+$/ |
| 11578 |
}; |
| 11579 |
|
| 11580 |
|
| 11581 |
|
| 11582 |
|
| 11583 |
|
| 11584 |
|
| 11585 |
|
| 11586 |
|
| 11587 |
|
| 11588 |
|
| 11589 |
|
| 11590 |
|
| 11591 |
|
| 11592 |
|
| 11593 |
|
| 11594 |
|
| 11595 |
|
| 11596 |
|
| 11597 |
OO.ui.TextInputWidget.prototype.onIconMouseDown = function ( e ) { |
| 11598 |
if ( e.which === OO.ui.MouseButtons.LEFT ) { |
| 11599 |
this.focus(); |
| 11600 |
return false; |
| 11601 |
} |
| 11602 |
}; |
| 11603 |
|
| 11604 |
|
| 11605 |
|
| 11606 |
|
| 11607 |
|
| 11608 |
|
| 11609 |
|
| 11610 |
|
| 11611 |
|
| 11612 |
|
| 11613 |
|
| 11614 |
OO.ui.TextInputWidget.prototype.onIndicatorMouseDown = function ( e ) { |
| 11615 |
if ( e.which === OO.ui.MouseButtons.LEFT ) { |
| 11616 |
this.focus(); |
| 11617 |
return false; |
| 11618 |
} |
| 11619 |
}; |
| 11620 |
|
| 11621 |
|
| 11622 |
|
| 11623 |
|
| 11624 |
|
| 11625 |
|
| 11626 |
|
| 11627 |
|
| 11628 |
OO.ui.TextInputWidget.prototype.onKeyPress = function ( e ) { |
| 11629 |
if ( e.which === OO.ui.Keys.ENTER ) { |
| 11630 |
this.emit( 'enter', e ); |
| 11631 |
} |
| 11632 |
}; |
| 11633 |
|
| 11634 |
|
| 11635 |
|
| 11636 |
|
| 11637 |
|
| 11638 |
|
| 11639 |
|
| 11640 |
OO.ui.TextInputWidget.prototype.onBlur = function () { |
| 11641 |
this.setValidityFlag(); |
| 11642 |
}; |
| 11643 |
|
| 11644 |
|
| 11645 |
|
| 11646 |
|
| 11647 |
|
| 11648 |
|
| 11649 |
|
| 11650 |
OO.ui.TextInputWidget.prototype.onFocus = function () { |
| 11651 |
if ( this.isWaitingToBeAttached ) { |
| 11652 |
|
| 11653 |
|
| 11654 |
this.onElementAttach(); |
| 11655 |
} |
| 11656 |
this.setValidityFlag( true ); |
| 11657 |
}; |
| 11658 |
|
| 11659 |
|
| 11660 |
|
| 11661 |
|
| 11662 |
|
| 11663 |
|
| 11664 |
|
| 11665 |
OO.ui.TextInputWidget.prototype.onElementAttach = function () { |
| 11666 |
this.isWaitingToBeAttached = false; |
| 11667 |
|
| 11668 |
this.valCache = null; |
| 11669 |
this.positionLabel(); |
| 11670 |
}; |
| 11671 |
|
| 11672 |
|
| 11673 |
|
| 11674 |
|
| 11675 |
|
| 11676 |
|
| 11677 |
|
| 11678 |
OO.ui.TextInputWidget.prototype.onDebouncedChange = function () { |
| 11679 |
this.setValidityFlag(); |
| 11680 |
}; |
| 11681 |
|
| 11682 |
|
| 11683 |
|
| 11684 |
|
| 11685 |
|
| 11686 |
|
| 11687 |
OO.ui.TextInputWidget.prototype.isReadOnly = function () { |
| 11688 |
return this.readOnly; |
| 11689 |
}; |
| 11690 |
|
| 11691 |
|
| 11692 |
|
| 11693 |
|
| 11694 |
|
| 11695 |
|
| 11696 |
|
| 11697 |
|
| 11698 |
OO.ui.TextInputWidget.prototype.setReadOnly = function ( state ) { |
| 11699 |
this.readOnly = !!state; |
| 11700 |
this.$input.prop( 'readOnly', this.readOnly ); |
| 11701 |
return this; |
| 11702 |
}; |
| 11703 |
|
| 11704 |
|
| 11705 |
|
| 11706 |
|
| 11707 |
OO.ui.TextInputWidget.prototype.installParentChangeDetector = function () { |
| 11708 |
this.connectDetectorNode = document.createElement( 'ooui-connect-detector' ); |
| 11709 |
this.connectDetectorNode.onConnectOOUI = () => { |
| 11710 |
if ( this.isElementAttached() ) { |
| 11711 |
this.onElementAttach(); |
| 11712 |
} |
| 11713 |
}; |
| 11714 |
|
| 11715 |
this.$element.append( this.connectDetectorNode ); |
| 11716 |
}; |
| 11717 |
|
| 11718 |
|
| 11719 |
|
| 11720 |
|
| 11721 |
|
| 11722 |
OO.ui.TextInputWidget.prototype.getInputElement = function ( config ) { |
| 11723 |
const $input = $( '<input>' ).attr( 'type', config.type ); |
| 11724 |
|
| 11725 |
if ( config.type === 'number' ) { |
| 11726 |
$input.attr( 'step', 'any' ); |
| 11727 |
} |
| 11728 |
|
| 11729 |
return $input; |
| 11730 |
}; |
| 11731 |
|
| 11732 |
|
| 11733 |
|
| 11734 |
|
| 11735 |
|
| 11736 |
|
| 11737 |
|
| 11738 |
|
| 11739 |
|
| 11740 |
OO.ui.TextInputWidget.prototype.getValidType = function ( config ) { |
| 11741 |
const allowedTypes = [ |
| 11742 |
'text', |
| 11743 |
'password', |
| 11744 |
'email', |
| 11745 |
'url', |
| 11746 |
'number' |
| 11747 |
]; |
| 11748 |
return allowedTypes.indexOf( config.type ) !== -1 ? config.type : 'text'; |
| 11749 |
}; |
| 11750 |
|
| 11751 |
|
| 11752 |
|
| 11753 |
|
| 11754 |
|
| 11755 |
|
| 11756 |
|
| 11757 |
|
| 11758 |
|
| 11759 |
OO.ui.TextInputWidget.prototype.selectRange = function ( from, to ) { |
| 11760 |
const input = this.$input[ 0 ]; |
| 11761 |
|
| 11762 |
to = to || from; |
| 11763 |
|
| 11764 |
const isBackwards = to < from, |
| 11765 |
start = isBackwards ? to : from, |
| 11766 |
end = isBackwards ? from : to; |
| 11767 |
|
| 11768 |
this.focus(); |
| 11769 |
|
| 11770 |
try { |
| 11771 |
input.setSelectionRange( start, end, isBackwards ? 'backward' : 'forward' ); |
| 11772 |
} catch ( e ) { |
| 11773 |
|
| 11774 |
|
| 11775 |
|
| 11776 |
if ( this.getElementDocument().body.contains( input ) ) { |
| 11777 |
throw e; |
| 11778 |
} |
| 11779 |
} |
| 11780 |
return this; |
| 11781 |
}; |
| 11782 |
|
| 11783 |
|
| 11784 |
|
| 11785 |
|
| 11786 |
|
| 11787 |
|
| 11788 |
OO.ui.TextInputWidget.prototype.getRange = function () { |
| 11789 |
const input = this.$input[ 0 ], |
| 11790 |
start = input.selectionStart, |
| 11791 |
end = input.selectionEnd, |
| 11792 |
isBackwards = input.selectionDirection === 'backward'; |
| 11793 |
|
| 11794 |
return { |
| 11795 |
from: isBackwards ? end : start, |
| 11796 |
to: isBackwards ? start : end |
| 11797 |
}; |
| 11798 |
}; |
| 11799 |
|
| 11800 |
|
| 11801 |
|
| 11802 |
|
| 11803 |
|
| 11804 |
|
| 11805 |
|
| 11806 |
|
| 11807 |
|
| 11808 |
OO.ui.TextInputWidget.prototype.getInputLength = function () { |
| 11809 |
return this.$input[ 0 ].value.length; |
| 11810 |
}; |
| 11811 |
|
| 11812 |
|
| 11813 |
|
| 11814 |
|
| 11815 |
|
| 11816 |
|
| 11817 |
|
| 11818 |
OO.ui.TextInputWidget.prototype.select = function () { |
| 11819 |
return this.selectRange( 0, this.getInputLength() ); |
| 11820 |
}; |
| 11821 |
|
| 11822 |
|
| 11823 |
|
| 11824 |
|
| 11825 |
|
| 11826 |
|
| 11827 |
|
| 11828 |
OO.ui.TextInputWidget.prototype.moveCursorToStart = function () { |
| 11829 |
return this.selectRange( 0 ); |
| 11830 |
}; |
| 11831 |
|
| 11832 |
|
| 11833 |
|
| 11834 |
|
| 11835 |
|
| 11836 |
|
| 11837 |
|
| 11838 |
OO.ui.TextInputWidget.prototype.moveCursorToEnd = function () { |
| 11839 |
return this.selectRange( this.getInputLength() ); |
| 11840 |
}; |
| 11841 |
|
| 11842 |
|
| 11843 |
|
| 11844 |
|
| 11845 |
|
| 11846 |
|
| 11847 |
|
| 11848 |
|
| 11849 |
OO.ui.TextInputWidget.prototype.insertContent = function ( content ) { |
| 11850 |
const value = this.getValue(), |
| 11851 |
range = this.getRange(), |
| 11852 |
start = Math.min( range.from, range.to ), |
| 11853 |
end = Math.max( range.from, range.to ); |
| 11854 |
|
| 11855 |
this.setValue( value.slice( 0, start ) + content + value.slice( end ) ); |
| 11856 |
this.selectRange( start + content.length ); |
| 11857 |
return this; |
| 11858 |
}; |
| 11859 |
|
| 11860 |
|
| 11861 |
|
| 11862 |
|
| 11863 |
|
| 11864 |
|
| 11865 |
|
| 11866 |
|
| 11867 |
|
| 11868 |
OO.ui.TextInputWidget.prototype.encapsulateContent = function ( pre, post ) { |
| 11869 |
const offset = pre.length, |
| 11870 |
range = this.getRange(), |
| 11871 |
start = Math.min( range.from, range.to ), |
| 11872 |
end = Math.max( range.from, range.to ); |
| 11873 |
|
| 11874 |
this.selectRange( start ).insertContent( pre ); |
| 11875 |
this.selectRange( offset + end ).insertContent( post ); |
| 11876 |
|
| 11877 |
this.selectRange( offset + start, offset + end ); |
| 11878 |
return this; |
| 11879 |
}; |
| 11880 |
|
| 11881 |
|
| 11882 |
|
| 11883 |
|
| 11884 |
|
| 11885 |
|
| 11886 |
|
| 11887 |
|
| 11888 |
|
| 11889 |
e class. |
| 11890 |
|
| 11891 |
OO.ui.TextInputWidget.prototype.setValidation = function ( validate ) { |
| 11892 |
this.validate = validate instanceof RegExp || validate instanceof Function ? |
| 11893 |
validate : |
| 11894 |
this.constructor.static.validationPatterns[ validate ]; |
| 11895 |
}; |
| 11896 |
|
| 11897 |
|
| 11898 |
|
| 11899 |
|
| 11900 |
|
| 11901 |
|
| 11902 |
OO.ui.TextInputWidget.prototype.setValidityFlag = function ( isValid ) { |
| 11903 |
const setFlag = ( valid ) => { |
| 11904 |
if ( !valid ) { |
| 11905 |
this.$input.attr( 'aria-invalid', 'true' ); |
| 11906 |
} else { |
| 11907 |
this.$input.removeAttr( 'aria-invalid' ); |
| 11908 |
} |
| 11909 |
this.setFlags( { invalid: !valid } ); |
| 11910 |
}; |
| 11911 |
|
| 11912 |
if ( isValid !== undefined ) { |
| 11913 |
setFlag( isValid ); |
| 11914 |
} else { |
| 11915 |
this.getValidity().then( () => { |
| 11916 |
setFlag( true ); |
| 11917 |
}, () => { |
| 11918 |
setFlag( false ); |
| 11919 |
} ); |
| 11920 |
} |
| 11921 |
}; |
| 11922 |
|
| 11923 |
|
| 11924 |
|
| 11925 |
|
| 11926 |
|
| 11927 |
|
| 11928 |
|
| 11929 |
|
| 11930 |
|
| 11931 |
OO.ui.TextInputWidget.prototype.getValidity = function () { |
| 11932 |
function rejectOrResolve( valid ) { |
| 11933 |
const deferred = $.Deferred(), |
| 11934 |
promise = valid ? deferred.resolve() : deferred.reject(); |
| 11935 |
return promise.promise(); |
| 11936 |
} |
| 11937 |
|
| 11938 |
|
| 11939 |
if ( this.$input[ 0 ].checkValidity && this.$input[ 0 ].checkValidity() === false ) { |
| 11940 |
return rejectOrResolve( false ); |
| 11941 |
} |
| 11942 |
|
| 11943 |
if ( !this.validate ) { |
| 11944 |
return rejectOrResolve( true ); |
| 11945 |
} |
| 11946 |
|
| 11947 |
|
| 11948 |
let result; |
| 11949 |
if ( this.validate instanceof Function ) { |
| 11950 |
result = this.validate( this.getValue() ); |
| 11951 |
if ( result && typeof result.promise === 'function' ) { |
| 11952 |
return result.promise().then( ( valid ) => rejectOrResolve( valid ) ); |
| 11953 |
} |
| 11954 |
} else { |
| 11955 |
|
| 11956 |
result = this.validate.test( this.getValue() ); |
| 11957 |
} |
| 11958 |
return rejectOrResolve( result ); |
| 11959 |
}; |
| 11960 |
|
| 11961 |
|
| 11962 |
ter’`. |
| 11963 |
|
| 11964 |
|
| 11965 |
|
| 11966 |
|
| 11967 |
|
| 11968 |
OO.ui.TextInputWidget.prototype.setLabelPosition = function ( labelPosition ) { |
| 11969 |
this.labelPosition = labelPosition; |
| 11970 |
if ( this.label ) { |
| 11971 |
|
| 11972 |
|
| 11973 |
this.updatePosition(); |
| 11974 |
} |
| 11975 |
return this; |
| 11976 |
}; |
| 11977 |
|
| 11978 |
|
| 11979 |
|
| 11980 |
|
| 11981 |
|
| 11982 |
|
| 11983 |
|
| 11984 |
|
| 11985 |
|
| 11986 |
|
| 11987 |
OO.ui.TextInputWidget.prototype.updatePosition = function () { |
| 11988 |
const after = this.labelPosition === 'after'; |
| 11989 |
|
| 11990 |
this.$element |
| 11991 |
.toggleClass( 'oo-ui-textInputWidget-labelPosition-after', !!this.label && after ) |
| 11992 |
.toggleClass( 'oo-ui-textInputWidget-labelPosition-before', !!this.label && !after ); |
| 11993 |
|
| 11994 |
this.valCache = null; |
| 11995 |
this.scrollWidth = null; |
| 11996 |
this.positionLabel(); |
| 11997 |
|
| 11998 |
return this; |
| 11999 |
}; |
| 12000 |
|
| 12001 |
|
| 12002 |
|
| 12003 |
|
| 12004 |
|
| 12005 |
|
| 12006 |
|
| 12007 |
|
| 12008 |
OO.ui.TextInputWidget.prototype.positionLabel = function () { |
| 12009 |
if ( this.isWaitingToBeAttached ) { |
| 12010 |
|
| 12011 |
return this; |
| 12012 |
} |
| 12013 |
|
| 12014 |
const newCss = { |
| 12015 |
'padding-right': '', |
| 12016 |
'padding-left': '' |
| 12017 |
}; |
| 12018 |
|
| 12019 |
if ( this.label ) { |
| 12020 |
this.$element.append( this.$label ); |
| 12021 |
} else { |
| 12022 |
this.$label.detach(); |
| 12023 |
|
| 12024 |
this.$input.css( newCss ); |
| 12025 |
return; |
| 12026 |
} |
| 12027 |
|
| 12028 |
const after = this.labelPosition === 'after', |
| 12029 |
rtl = this.$element.css( 'direction' ) === 'rtl', |
| 12030 |
property = after === rtl ? 'padding-left' : 'padding-right'; |
| 12031 |
|
| 12032 |
newCss[ property ] = this.$label.outerWidth( true ) + ( after ? this.scrollWidth : 0 ); |
| 12033 |
|
| 12034 |
this.$input.css( newCss ); |
| 12035 |
|
| 12036 |
return this; |
| 12037 |
}; |
| 12038 |
|
| 12039 |
|
| 12040 |
|
| 12041 |
|
| 12042 |
|
| 12043 |
|
| 12044 |
|
| 12045 |
|
| 12046 |
|
| 12047 |
|
| 12048 |
|
| 12049 |
|
| 12050 |
|
| 12051 |
|
| 12052 |
|
| 12053 |
OO.ui.SearchInputWidget = function OoUiSearchInputWidget( config ) { |
| 12054 |
config = Object.assign( { |
| 12055 |
icon: 'search' |
| 12056 |
}, config ); |
| 12057 |
|
| 12058 |
|
| 12059 |
OO.ui.SearchInputWidget.super.call( this, config ); |
| 12060 |
|
| 12061 |
|
| 12062 |
this.connect( this, { |
| 12063 |
change: 'onChange' |
| 12064 |
} ); |
| 12065 |
this.$indicator.on( 'click', this.onIndicatorClick.bind( this ) ); |
| 12066 |
this.$indicator.on( 'keydown', this.onIndicatorKeyDown.bind( this ) ); |
| 12067 |
|
| 12068 |
|
| 12069 |
this.updateSearchIndicator(); |
| 12070 |
this.connect( this, { |
| 12071 |
disable: 'onDisable' |
| 12072 |
} ); |
| 12073 |
this.$indicator |
| 12074 |
.attr( { |
| 12075 |
tabindex: -1, |
| 12076 |
role: 'button' |
| 12077 |
} ); |
| 12078 |
}; |
| 12079 |
|
| 12080 |
|
| 12081 |
|
| 12082 |
OO.inheritClass( OO.ui.SearchInputWidget, OO.ui.TextInputWidget ); |
| 12083 |
|
| 12084 |
|
| 12085 |
|
| 12086 |
|
| 12087 |
|
| 12088 |
|
| 12089 |
|
| 12090 |
OO.ui.SearchInputWidget.prototype.getValidType = function () { |
| 12091 |
return 'search'; |
| 12092 |
}; |
| 12093 |
|
| 12094 |
|
| 12095 |
|
| 12096 |
|
| 12097 |
|
| 12098 |
|
| 12099 |
|
| 12100 |
OO.ui.SearchInputWidget.prototype.onIndicatorKeyDown = function ( e ) { |
| 12101 |
if ( e.keyCode === OO.ui.Keys.ENTER ) { |
| 12102 |
|
| 12103 |
this.setValue( '' ); |
| 12104 |
this.focus(); |
| 12105 |
return false; |
| 12106 |
} |
| 12107 |
}; |
| 12108 |
|
| 12109 |
|
| 12110 |
|
| 12111 |
|
| 12112 |
|
| 12113 |
|
| 12114 |
|
| 12115 |
OO.ui.SearchInputWidget.prototype.onIndicatorClick = function ( e ) { |
| 12116 |
if ( e.which === OO.ui.MouseButtons.LEFT ) { |
| 12117 |
|
| 12118 |
this.setValue( '' ); |
| 12119 |
this.focus(); |
| 12120 |
return false; |
| 12121 |
} |
| 12122 |
}; |
| 12123 |
|
| 12124 |
|
| 12125 |
|
| 12126 |
|
| 12127 |
|
| 12128 |
|
| 12129 |
OO.ui.SearchInputWidget.prototype.updateSearchIndicator = function () { |
| 12130 |
if ( this.getValue() === '' || this.isDisabled() || this.isReadOnly() ) { |
| 12131 |
this.setIndicator( null ); |
| 12132 |
} else { |
| 12133 |
this.setIndicator( 'clear' ); |
| 12134 |
this.$indicator.attr( 'aria-label', OO.ui.msg( 'ooui-item-remove' ) ); |
| 12135 |
} |
| 12136 |
}; |
| 12137 |
|
| 12138 |
|
| 12139 |
|
| 12140 |
|
| 12141 |
|
| 12142 |
|
| 12143 |
OO.ui.SearchInputWidget.prototype.onChange = function () { |
| 12144 |
this.updateSearchIndicator(); |
| 12145 |
}; |
| 12146 |
|
| 12147 |
|
| 12148 |
|
| 12149 |
|
| 12150 |
|
| 12151 |
|
| 12152 |
|
| 12153 |
OO.ui.SearchInputWidget.prototype.onDisable = function () { |
| 12154 |
this.updateSearchIndicator(); |
| 12155 |
}; |
| 12156 |
|
| 12157 |
|
| 12158 |
|
| 12159 |
|
| 12160 |
OO.ui.SearchInputWidget.prototype.setReadOnly = function ( state ) { |
| 12161 |
OO.ui.SearchInputWidget.super.prototype.setReadOnly.call( this, state ); |
| 12162 |
this.updateSearchIndicator(); |
| 12163 |
return this; |
| 12164 |
}; |
| 12165 |
|
| 12166 |
|
| 12167 |
|
| 12168 |
|
| 12169 |
|
| 12170 |
|
| 12171 |
|
| 12172 |
|
| 12173 |
|
| 12174 |
|
| 12175 |
|
| 12176 |
|
| 12177 |
|
| 12178 |
|
| 12179 |
|
| 12180 |
|
| 12181 |
|
| 12182 |
|
| 12183 |
|
| 12184 |
|
| 12185 |
|
| 12186 |
|
| 12187 |
|
| 12188 |
|
| 12189 |
|
| 12190 |
|
| 12191 |
|
| 12192 |
|
| 12193 |
|
| 12194 |
|
| 12195 |
|
| 12196 |
|
| 12197 |
|
| 12198 |
|
| 12199 |
|
| 12200 |
|
| 12201 |
OO.ui.MultilineTextInputWidget = function OoUiMultilineTextInputWidget( config ) { |
| 12202 |
config = Object.assign( { |
| 12203 |
type: 'text' |
| 12204 |
}, config ); |
| 12205 |
|
| 12206 |
|
| 12207 |
|
| 12208 |
|
| 12209 |
this.allowLinebreaks = config.allowLinebreaks !== undefined ? config.allowLinebreaks : true; |
| 12210 |
|
| 12211 |
|
| 12212 |
OO.ui.MultilineTextInputWidget.super.call( this, config ); |
| 12213 |
|
| 12214 |
|
| 12215 |
this.autosize = !!config.autosize; |
| 12216 |
this.styleHeight = null; |
| 12217 |
this.minRows = config.rows !== undefined ? config.rows : ''; |
| 12218 |
this.maxRows = config.maxRows || Math.max( 2 * ( this.minRows || 0 ), 10 ); |
| 12219 |
|
| 12220 |
|
| 12221 |
if ( this.autosize ) { |
| 12222 |
this.$clone = this.$input |
| 12223 |
.clone() |
| 12224 |
.removeAttr( 'id' ) |
| 12225 |
.removeAttr( 'name' ) |
| 12226 |
.insertAfter( this.$input ) |
| 12227 |
.attr( 'aria-hidden', 'true' ) |
| 12228 |
|
| 12229 |
.css( 'overflow', 'hidden' ) |
| 12230 |
.addClass( 'oo-ui-element-hidden' ); |
| 12231 |
} |
| 12232 |
|
| 12233 |
|
| 12234 |
this.connect( this, { |
| 12235 |
change: 'onChange' |
| 12236 |
} ); |
| 12237 |
|
| 12238 |
|
| 12239 |
if ( config.rows ) { |
| 12240 |
this.$input.attr( 'rows', config.rows ); |
| 12241 |
} |
| 12242 |
if ( this.autosize ) { |
| 12243 |
this.$input.addClass( 'oo-ui-textInputWidget-autosized' ); |
| 12244 |
this.isWaitingToBeAttached = true; |
| 12245 |
this.installParentChangeDetector(); |
| 12246 |
} |
| 12247 |
}; |
| 12248 |
|
| 12249 |
|
| 12250 |
|
| 12251 |
OO.inheritClass( OO.ui.MultilineTextInputWidget, OO.ui.TextInputWidget ); |
| 12252 |
|
| 12253 |
|
| 12254 |
|
| 12255 |
|
| 12256 |
|
| 12257 |
|
| 12258 |
|
| 12259 |
|
| 12260 |
|
| 12261 |
|
| 12262 |
|
| 12263 |
|
| 12264 |
|
| 12265 |
|
| 12266 |
OO.ui.MultilineTextInputWidget.static.gatherPreInfuseState = function ( node, config ) { |
| 12267 |
const state = OO.ui.MultilineTextInputWidget.super.static.gatherPreInfuseState( node, config ); |
| 12268 |
if ( config.$input ) { |
| 12269 |
state.scrollTop = config.$input.scrollTop(); |
| 12270 |
} |
| 12271 |
return state; |
| 12272 |
}; |
| 12273 |
|
| 12274 |
|
| 12275 |
|
| 12276 |
|
| 12277 |
|
| 12278 |
|
| 12279 |
OO.ui.MultilineTextInputWidget.prototype.onElementAttach = function () { |
| 12280 |
OO.ui.MultilineTextInputWidget.super.prototype.onElementAttach.call( this ); |
| 12281 |
this.adjustSize(); |
| 12282 |
}; |
| 12283 |
|
| 12284 |
|
| 12285 |
|
| 12286 |
|
| 12287 |
|
| 12288 |
|
| 12289 |
OO.ui.MultilineTextInputWidget.prototype.onChange = function () { |
| 12290 |
this.adjustSize(); |
| 12291 |
}; |
| 12292 |
|
| 12293 |
|
| 12294 |
|
| 12295 |
|
| 12296 |
OO.ui.MultilineTextInputWidget.prototype.updatePosition = function () { |
| 12297 |
OO.ui.MultilineTextInputWidget.super.prototype.updatePosition.call( this ); |
| 12298 |
this.adjustSize(); |
| 12299 |
}; |
| 12300 |
|
| 12301 |
|
| 12302 |
|
| 12303 |
|
| 12304 |
|
| 12305 |
|
| 12306 |
OO.ui.MultilineTextInputWidget.prototype.onKeyPress = function ( e ) { |
| 12307 |
if ( !this.allowLinebreaks ) { |
| 12308 |
|
| 12309 |
|
| 12310 |
|
| 12311 |
if ( e.which === OO.ui.Keys.ENTER ) { |
| 12312 |
e.preventDefault(); |
| 12313 |
} |
| 12314 |
return OO.ui.TextInputWidget.prototype.onKeyPress.call( this, e ); |
| 12315 |
} |
| 12316 |
if ( |
| 12317 |
( e.which === OO.ui.Keys.ENTER && ( e.ctrlKey || e.metaKey ) ) || |
| 12318 |
|
| 12319 |
e.which === 10 |
| 12320 |
) { |
| 12321 |
this.emit( 'enter', e ); |
| 12322 |
} |
| 12323 |
}; |
| 12324 |
|
| 12325 |
|
| 12326 |
|
| 12327 |
|
| 12328 |
OO.ui.MultilineTextInputWidget.prototype.cleanUpValue = function ( value ) { |
| 12329 |
|
| 12330 |
value = OO.ui.MultilineTextInputWidget.super.prototype.cleanUpValue( value ); |
| 12331 |
if ( !this.allowLinebreaks ) { |
| 12332 |
|
| 12333 |
|
| 12334 |
|
| 12335 |
|
| 12336 |
value = value.replace( /\r?\n/g, ' ' ); |
| 12337 |
} |
| 12338 |
return value; |
| 12339 |
}; |
| 12340 |
|
| 12341 |
|
| 12342 |
|
| 12343 |
|
| 12344 |
|
| 12345 |
|
| 12346 |
|
| 12347 |
|
| 12348 |
|
| 12349 |
|
| 12350 |
|
| 12351 |
OO.ui.MultilineTextInputWidget.prototype.adjustSize = function ( force ) { |
| 12352 |
if ( force || this.$input.val() !== this.valCache ) { |
| 12353 |
if ( this.autosize ) { |
| 12354 |
this.$clone |
| 12355 |
.val( this.$input.val() ) |
| 12356 |
.attr( 'rows', this.minRows ) |
| 12357 |
|
| 12358 |
.css( 'height', 0 ) |
| 12359 |
.removeClass( 'oo-ui-element-hidden' ); |
| 12360 |
|
| 12361 |
this.valCache = this.$input.val(); |
| 12362 |
|
| 12363 |
|
| 12364 |
|
| 12365 |
this.$clone[ 0 ].scrollHeight; |
| 12366 |
const scrollHeight = this.$clone[ 0 ].scrollHeight; |
| 12367 |
|
| 12368 |
|
| 12369 |
this.$clone.css( 'height', '' ); |
| 12370 |
const innerHeight = this.$clone.innerHeight(); |
| 12371 |
const outerHeight = this.$clone.outerHeight(); |
| 12372 |
|
| 12373 |
|
| 12374 |
this.$clone |
| 12375 |
.attr( 'rows', this.maxRows ) |
| 12376 |
.css( 'height', 'auto' ) |
| 12377 |
.val( '' ); |
| 12378 |
const maxInnerHeight = this.$clone.innerHeight(); |
| 12379 |
|
| 12380 |
|
| 12381 |
|
| 12382 |
const measurementError = maxInnerHeight - this.$clone[ 0 ].scrollHeight; |
| 12383 |
const idealHeight = Math.min( maxInnerHeight, scrollHeight + measurementError ); |
| 12384 |
|
| 12385 |
this.$clone.addClass( 'oo-ui-element-hidden' ); |
| 12386 |
|
| 12387 |
|
| 12388 |
|
| 12389 |
const newHeight = idealHeight > innerHeight ? idealHeight + ( outerHeight - innerHeight ) : ''; |
| 12390 |
if ( newHeight !== this.styleHeight ) { |
| 12391 |
this.$input.css( 'height', newHeight ); |
| 12392 |
this.styleHeight = newHeight; |
| 12393 |
this.emit( 'resize' ); |
| 12394 |
} |
| 12395 |
} |
| 12396 |
const scrollWidth = this.$input[ 0 ].offsetWidth - this.$input[ 0 ].clientWidth; |
| 12397 |
if ( scrollWidth !== this.scrollWidth ) { |
| 12398 |
const property = this.$element.css( 'direction' ) === 'rtl' ? 'left' : 'right'; |
| 12399 |
|
| 12400 |
this.$label.css( { right: '', left: '' } ); |
| 12401 |
this.$indicator.css( { right: '', left: '' } ); |
| 12402 |
|
| 12403 |
if ( scrollWidth ) { |
| 12404 |
this.$indicator.css( property, scrollWidth ); |
| 12405 |
if ( this.labelPosition === 'after' ) { |
| 12406 |
this.$label.css( property, scrollWidth ); |
| 12407 |
} |
| 12408 |
} |
| 12409 |
|
| 12410 |
this.scrollWidth = scrollWidth; |
| 12411 |
this.positionLabel(); |
| 12412 |
} |
| 12413 |
} |
| 12414 |
return this; |
| 12415 |
}; |
| 12416 |
|
| 12417 |
|
| 12418 |
|
| 12419 |
|
| 12420 |
|
| 12421 |
OO.ui.MultilineTextInputWidget.prototype.getInputElement = function () { |
| 12422 |
return $( '<textarea>' ); |
| 12423 |
}; |
| 12424 |
|
| 12425 |
|
| 12426 |
|
| 12427 |
|
| 12428 |
|
| 12429 |
|
| 12430 |
OO.ui.MultilineTextInputWidget.prototype.isAutosizing = function () { |
| 12431 |
return !!this.autosize; |
| 12432 |
}; |
| 12433 |
|
| 12434 |
|
| 12435 |
|
| 12436 |
|
| 12437 |
OO.ui.MultilineTextInputWidget.prototype.restorePreInfuseState = function ( state ) { |
| 12438 |
OO.ui.MultilineTextInputWidget.super.prototype.restorePreInfuseState.call( this, state ); |
| 12439 |
if ( state.scrollTop !== undefined ) { |
| 12440 |
this.$input.scrollTop( state.scrollTop ); |
| 12441 |
} |
| 12442 |
}; |
| 12443 |
|
| 12444 |
|
| 12445 |
|
| 12446 |
|
| 12447 |
|
| 12448 |
|
| 12449 |
|
| 12450 |
|
| 12451 |
|
| 12452 |
|
| 12453 |
|
| 12454 |
|
| 12455 |
|
| 12456 |
|
| 12457 |
|
| 12458 |
|
| 12459 |
|
| 12460 |
|
| 12461 |
|
| 12462 |
|
| 12463 |
|
| 12464 |
|
| 12465 |
|
| 12466 |
|
| 12467 |
|
| 12468 |
|
| 12469 |
|
| 12470 |
|
| 12471 |
|
| 12472 |
|
| 12473 |
|
| 12474 |
|
| 12475 |
|
| 12476 |
|
| 12477 |
|
| 12478 |
|
| 12479 |
|
| 12480 |
|
| 12481 |
|
| 12482 |
|
| 12483 |
|
| 12484 |
|
| 12485 |
|
| 12486 |
|
| 12487 |
|
| 12488 |
|
| 12489 |
|
| 12490 |
|
| 12491 |
|
| 12492 |
|
| 12493 |
|
| 12494 |
|
| 12495 |
|
| 12496 |
|
| 12497 |
|
| 12498 |
|
| 12499 |
|
| 12500 |
|
| 12501 |
|
| 12502 |
… }` |
| 12503 |
|
| 12504 |
|
| 12505 |
|
| 12506 |
|
| 12507 |
|
| 12508 |
|
| 12509 |
|
| 12510 |
|
| 12511 |
OO.ui.ComboBoxInputWidget = function OoUiComboBoxInputWidget( config ) { |
| 12512 |
|
| 12513 |
config = Object.assign( { |
| 12514 |
autocomplete: false |
| 12515 |
}, config ); |
| 12516 |
|
| 12517 |
|
| 12518 |
if ( config.$input ) { |
| 12519 |
config.$input.removeAttr( 'list' ); |
| 12520 |
} |
| 12521 |
|
| 12522 |
|
| 12523 |
OO.ui.ComboBoxInputWidget.super.call( this, config ); |
| 12524 |
|
| 12525 |
|
| 12526 |
this.$overlay = ( config.$overlay === true ? |
| 12527 |
OO.ui.getDefaultOverlay() : config.$overlay ) || this.$element; |
| 12528 |
this.dropdownButton = new OO.ui.ButtonWidget( { |
| 12529 |
classes: [ 'oo-ui-comboBoxInputWidget-dropdownButton' ], |
| 12530 |
label: OO.ui.msg( 'ooui-combobox-button-label' ), |
| 12531 |
indicator: 'down', |
| 12532 |
invisibleLabel: true, |
| 12533 |
disabled: this.disabled |
| 12534 |
} ); |
| 12535 |
this.menu = new OO.ui.MenuSelectWidget( Object.assign( |
| 12536 |
{ |
| 12537 |
widget: this, |
| 12538 |
input: this, |
| 12539 |
$floatableContainer: this.$element, |
| 12540 |
disabled: this.isDisabled() |
| 12541 |
}, |
| 12542 |
config.menu |
| 12543 |
) ); |
| 12544 |
|
| 12545 |
|
| 12546 |
this.connect( this, { |
| 12547 |
change: 'onInputChange', |
| 12548 |
enter: 'onInputEnter' |
| 12549 |
} ); |
| 12550 |
this.dropdownButton.connect( this, { |
| 12551 |
click: 'onDropdownButtonClick' |
| 12552 |
} ); |
| 12553 |
this.menu.connect( this, { |
| 12554 |
choose: 'onMenuChoose', |
| 12555 |
add: 'onMenuItemsChange', |
| 12556 |
remove: 'onMenuItemsChange', |
| 12557 |
toggle: 'onMenuToggle' |
| 12558 |
} ); |
| 12559 |
|
| 12560 |
|
| 12561 |
this.$input.attr( { |
| 12562 |
role: 'combobox', |
| 12563 |
'aria-owns': this.menu.getElementId(), |
| 12564 |
'aria-autocomplete': 'list' |
| 12565 |
} ); |
| 12566 |
this.dropdownButton.$button.attr( { |
| 12567 |
'aria-controls': this.menu.getElementId() |
| 12568 |
} ); |
| 12569 |
|
| 12570 |
if ( config.options !== undefined ) { |
| 12571 |
this.setOptions( config.options ); |
| 12572 |
} |
| 12573 |
this.$field = $( '<div>' ) |
| 12574 |
.addClass( 'oo-ui-comboBoxInputWidget-field' ) |
| 12575 |
.append( this.$input, this.dropdownButton.$element ); |
| 12576 |
this.$element |
| 12577 |
.addClass( 'oo-ui-comboBoxInputWidget' ) |
| 12578 |
.append( this.$field ); |
| 12579 |
this.$overlay.append( this.menu.$element ); |
| 12580 |
this.onMenuItemsChange(); |
| 12581 |
}; |
| 12582 |
|
| 12583 |
|
| 12584 |
|
| 12585 |
OO.inheritClass( OO.ui.ComboBoxInputWidget, OO.ui.TextInputWidget ); |
| 12586 |
|
| 12587 |
|
| 12588 |
|
| 12589 |
|
| 12590 |
|
| 12591 |
|
| 12592 |
|
| 12593 |
|
| 12594 |
OO.ui.ComboBoxInputWidget.prototype.getMenu = function () { |
| 12595 |
return this.menu; |
| 12596 |
}; |
| 12597 |
|
| 12598 |
|
| 12599 |
|
| 12600 |
|
| 12601 |
|
| 12602 |
|
| 12603 |
OO.ui.ComboBoxInputWidget.prototype.getInput = function () { |
| 12604 |
return this; |
| 12605 |
}; |
| 12606 |
|
| 12607 |
|
| 12608 |
|
| 12609 |
|
| 12610 |
OO.ui.ComboBoxInputWidget.prototype.onEdit = function ( event ) { |
| 12611 |
|
| 12612 |
OO.ui.ComboBoxInputWidget.super.prototype.onEdit.apply( this, arguments ); |
| 12613 |
|
| 12614 |
if ( this.menu.isVisible() || this.isDisabled() || !this.isVisible() ) { |
| 12615 |
return; |
| 12616 |
} |
| 12617 |
|
| 12618 |
if ( event.type === 'input' || event.type === 'mouseup' || ( event.type === 'keydown' && ( |
| 12619 |
event.keyCode === OO.ui.Keys.ENTER || |
| 12620 |
event.keyCode === OO.ui.Keys.UP || |
| 12621 |
event.keyCode === OO.ui.Keys.DOWN |
| 12622 |
) ) ) { |
| 12623 |
this.menu.toggle( true ); |
| 12624 |
} |
| 12625 |
}; |
| 12626 |
|
| 12627 |
|
| 12628 |
|
| 12629 |
|
| 12630 |
|
| 12631 |
|
| 12632 |
|
| 12633 |
OO.ui.ComboBoxInputWidget.prototype.onInputChange = function ( value ) { |
| 12634 |
const match = this.menu.findItemFromData( value ); |
| 12635 |
|
| 12636 |
this.menu.selectItem( match ); |
| 12637 |
if ( this.menu.findHighlightedItem() ) { |
| 12638 |
this.menu.highlightItem( match ); |
| 12639 |
} |
| 12640 |
}; |
| 12641 |
|
| 12642 |
|
| 12643 |
|
| 12644 |
|
| 12645 |
|
| 12646 |
|
| 12647 |
OO.ui.ComboBoxInputWidget.prototype.onInputEnter = function () { |
| 12648 |
if ( !this.isDisabled() ) { |
| 12649 |
this.menu.toggle( false ); |
| 12650 |
} |
| 12651 |
}; |
| 12652 |
|
| 12653 |
|
| 12654 |
|
| 12655 |
|
| 12656 |
|
| 12657 |
|
| 12658 |
OO.ui.ComboBoxInputWidget.prototype.onDropdownButtonClick = function () { |
| 12659 |
this.menu.toggle(); |
| 12660 |
this.focus(); |
| 12661 |
}; |
| 12662 |
|
| 12663 |
|
| 12664 |
|
| 12665 |
|
| 12666 |
|
| 12667 |
|
| 12668 |
|
| 12669 |
OO.ui.ComboBoxInputWidget.prototype.onMenuChoose = function ( item ) { |
| 12670 |
this.setValue( item.getData() ); |
| 12671 |
}; |
| 12672 |
|
| 12673 |
|
| 12674 |
|
| 12675 |
|
| 12676 |
|
| 12677 |
|
| 12678 |
OO.ui.ComboBoxInputWidget.prototype.onMenuItemsChange = function () { |
| 12679 |
const match = this.menu.findItemFromData( this.getValue() ); |
| 12680 |
this.menu.selectItem( match ); |
| 12681 |
if ( this.menu.findHighlightedItem() ) { |
| 12682 |
this.menu.highlightItem( match ); |
| 12683 |
} |
| 12684 |
this.$element.toggleClass( 'oo-ui-comboBoxInputWidget-empty', this.menu.isEmpty() ); |
| 12685 |
}; |
| 12686 |
|
| 12687 |
|
| 12688 |
|
| 12689 |
|
| 12690 |
|
| 12691 |
|
| 12692 |
|
| 12693 |
OO.ui.ComboBoxInputWidget.prototype.onMenuToggle = function ( isVisible ) { |
| 12694 |
this.$element.toggleClass( 'oo-ui-comboBoxInputWidget-open', isVisible ); |
| 12695 |
}; |
| 12696 |
|
| 12697 |
|
| 12698 |
|
| 12699 |
|
| 12700 |
|
| 12701 |
|
| 12702 |
|
| 12703 |
|
| 12704 |
OO.ui.ComboBoxInputWidget.prototype.updateControlsDisabled = function () { |
| 12705 |
const disabled = this.isDisabled() || this.isReadOnly(); |
| 12706 |
if ( this.dropdownButton ) { |
| 12707 |
this.dropdownButton.setDisabled( disabled ); |
| 12708 |
} |
| 12709 |
if ( this.menu ) { |
| 12710 |
this.menu.setDisabled( disabled ); |
| 12711 |
} |
| 12712 |
return this; |
| 12713 |
}; |
| 12714 |
|
| 12715 |
|
| 12716 |
|
| 12717 |
|
| 12718 |
OO.ui.ComboBoxInputWidget.prototype.setDisabled = function () { |
| 12719 |
|
| 12720 |
OO.ui.ComboBoxInputWidget.super.prototype.setDisabled.apply( this, arguments ); |
| 12721 |
this.updateControlsDisabled(); |
| 12722 |
return this; |
| 12723 |
}; |
| 12724 |
|
| 12725 |
|
| 12726 |
|
| 12727 |
|
| 12728 |
OO.ui.ComboBoxInputWidget.prototype.setReadOnly = function () { |
| 12729 |
|
| 12730 |
OO.ui.ComboBoxInputWidget.super.prototype.setReadOnly.apply( this, arguments ); |
| 12731 |
this.updateControlsDisabled(); |
| 12732 |
return this; |
| 12733 |
}; |
| 12734 |
|
| 12735 |
|
| 12736 |
|
| 12737 |
|
| 12738 |
… }` |
| 12739 |
|
| 12740 |
|
| 12741 |
|
| 12742 |
OO.ui.ComboBoxInputWidget.prototype.setOptions = function ( options ) { |
| 12743 |
this.getMenu() |
| 12744 |
.clearItems() |
| 12745 |
.addItems( options.map( ( opt ) => new OO.ui.MenuOptionWidget( { |
| 12746 |
data: opt.data, |
| 12747 |
label: opt.label !== undefined ? opt.label : opt.data |
| 12748 |
} ) ) ); |
| 12749 |
|
| 12750 |
return this; |
| 12751 |
}; |
| 12752 |
|
| 12753 |
|
| 12754 |
|
| 12755 |
|
| 12756 |
|
| 12757 |
|
| 12758 |
|
| 12759 |
|
| 12760 |
|
| 12761 |
|
| 12762 |
|
| 12763 |
|
| 12764 |
|
| 12765 |
|
| 12766 |
|
| 12767 |
|
| 12768 |
|
| 12769 |
|
| 12770 |
|
| 12771 |
|
| 12772 |
|
| 12773 |
|
| 12774 |
|
| 12775 |
|
| 12776 |
|
| 12777 |
|
| 12778 |
|
| 12779 |
|
| 12780 |
|
| 12781 |
|
| 12782 |
|
| 12783 |
|
| 12784 |
|
| 12785 |
|
| 12786 |
|
| 12787 |
|
| 12788 |
|
| 12789 |
|
| 12790 |
|
| 12791 |
|
| 12792 |
|
| 12793 |
|
| 12794 |
|
| 12795 |
|
| 12796 |
|
| 12797 |
|
| 12798 |
|
| 12799 |
|
| 12800 |
|
| 12801 |
|
| 12802 |
|
| 12803 |
|
| 12804 |
|
| 12805 |
|
| 12806 |
|
| 12807 |
|
| 12808 |
|
| 12809 |
|
| 12810 |
|
| 12811 |
|
| 12812 |
|
| 12813 |
|
| 12814 |
|
| 12815 |
|
| 12816 |
|
| 12817 |
|
| 12818 |
|
| 12819 |
|
| 12820 |
OO.ui.FieldLayout = function OoUiFieldLayout( fieldWidget, config ) { |
| 12821 |
|
| 12822 |
if ( OO.isPlainObject( fieldWidget ) && config === undefined ) { |
| 12823 |
config = fieldWidget; |
| 12824 |
fieldWidget = config.fieldWidget; |
| 12825 |
} |
| 12826 |
|
| 12827 |
|
| 12828 |
if ( fieldWidget === undefined ) { |
| 12829 |
throw new Error( 'Widget not found' ); |
| 12830 |
} |
| 12831 |
|
| 12832 |
|
| 12833 |
config = Object.assign( { align: 'left', helpInline: false }, config ); |
| 12834 |
|
| 12835 |
if ( config.help && !config.label ) { |
| 12836 |
|
| 12837 |
|
| 12838 |
config.label = ' '; |
| 12839 |
} |
| 12840 |
|
| 12841 |
|
| 12842 |
OO.ui.FieldLayout.super.call( this, config ); |
| 12843 |
|
| 12844 |
|
| 12845 |
OO.ui.mixin.LabelElement.call( this, Object.assign( { |
| 12846 |
$label: $( '<label>' ) |
| 12847 |
}, config ) ); |
| 12848 |
OO.ui.mixin.TitledElement.call( this, Object.assign( { $titled: this.$label }, config ) ); |
| 12849 |
|
| 12850 |
|
| 12851 |
this.fieldWidget = fieldWidget; |
| 12852 |
this.errors = []; |
| 12853 |
this.warnings = []; |
| 12854 |
this.successMessages = []; |
| 12855 |
this.notices = []; |
| 12856 |
this.$field = this.isFieldInline() ? $( '<span>' ) : $( '<div>' ); |
| 12857 |
this.$messages = $( '<div>' ); |
| 12858 |
this.$header = $( '<span>' ); |
| 12859 |
this.$body = $( '<div>' ); |
| 12860 |
this.align = null; |
| 12861 |
this.helpInline = config.helpInline; |
| 12862 |
|
| 12863 |
|
| 12864 |
this.fieldWidget.connect( this, { |
| 12865 |
disable: 'onFieldDisable' |
| 12866 |
} ); |
| 12867 |
|
| 12868 |
|
| 12869 |
this.$help = config.help ? |
| 12870 |
this.createHelpElement( config.help, config.$overlay ) : |
| 12871 |
$( [] ); |
| 12872 |
if ( this.fieldWidget.getInputId() ) { |
| 12873 |
this.$label.attr( 'for', this.fieldWidget.getInputId() ); |
| 12874 |
if ( this.helpInline ) { |
| 12875 |
this.$help.attr( 'for', this.fieldWidget.getInputId() ); |
| 12876 |
} |
| 12877 |
} else { |
| 12878 |
|
| 12879 |
const id = OO.ui.generateElementId(); |
| 12880 |
this.$label.attr( 'id', id ); |
| 12881 |
this.fieldWidget.setLabelledBy( id ); |
| 12882 |
|
| 12883 |
|
| 12884 |
this.$label.on( 'click', this.onLabelClick.bind( this ) ); |
| 12885 |
if ( this.helpInline ) { |
| 12886 |
this.$help.on( 'click', this.onLabelClick.bind( this ) ); |
| 12887 |
} |
| 12888 |
} |
| 12889 |
this.$element |
| 12890 |
.addClass( 'oo-ui-fieldLayout' ) |
| 12891 |
.toggleClass( 'oo-ui-fieldLayout-disabled', this.fieldWidget.isDisabled() ) |
| 12892 |
.append( this.$body ); |
| 12893 |
this.$body.addClass( 'oo-ui-fieldLayout-body' ); |
| 12894 |
this.$header.addClass( 'oo-ui-fieldLayout-header' ); |
| 12895 |
this.$messages.addClass( 'oo-ui-fieldLayout-messages' ); |
| 12896 |
this.$field |
| 12897 |
.addClass( 'oo-ui-fieldLayout-field' ) |
| 12898 |
.append( this.fieldWidget.$element ); |
| 12899 |
|
| 12900 |
this.setErrors( config.errors || [] ); |
| 12901 |
this.setWarnings( config.warnings || [] ); |
| 12902 |
this.setSuccess( config.successMessages || [] ); |
| 12903 |
this.setNotices( config.notices || [] ); |
| 12904 |
this.setAlignment( config.align ); |
| 12905 |
|
| 12906 |
this.updateTitle(); |
| 12907 |
}; |
| 12908 |
|
| 12909 |
|
| 12910 |
|
| 12911 |
OO.inheritClass( OO.ui.FieldLayout, OO.ui.Layout ); |
| 12912 |
OO.mixinClass( OO.ui.FieldLayout, OO.ui.mixin.LabelElement ); |
| 12913 |
OO.mixinClass( OO.ui.FieldLayout, OO.ui.mixin.TitledElement ); |
| 12914 |
|
| 12915 |
|
| 12916 |
|
| 12917 |
|
| 12918 |
|
| 12919 |
|
| 12920 |
|
| 12921 |
|
| 12922 |
|
| 12923 |
OO.ui.FieldLayout.prototype.onFieldDisable = function ( value ) { |
| 12924 |
this.$element.toggleClass( 'oo-ui-fieldLayout-disabled', value ); |
| 12925 |
}; |
| 12926 |
|
| 12927 |
|
| 12928 |
|
| 12929 |
|
| 12930 |
|
| 12931 |
|
| 12932 |
OO.ui.FieldLayout.prototype.onLabelClick = function () { |
| 12933 |
this.fieldWidget.simulateLabelClick(); |
| 12934 |
}; |
| 12935 |
|
| 12936 |
|
| 12937 |
|
| 12938 |
|
| 12939 |
|
| 12940 |
|
| 12941 |
OO.ui.FieldLayout.prototype.getField = function () { |
| 12942 |
return this.fieldWidget; |
| 12943 |
}; |
| 12944 |
|
| 12945 |
|
| 12946 |
|
| 12947 |
|
| 12948 |
|
| 12949 |
|
| 12950 |
|
| 12951 |
OO.ui.FieldLayout.prototype.isFieldInline = function () { |
| 12952 |
|
| 12953 |
return this.getField().$element.prop( 'tagName' ).toLowerCase() === 'span'; |
| 12954 |
}; |
| 12955 |
|
| 12956 |
|
| 12957 |
|
| 12958 |
|
| 12959 |
|
| 12960 |
|
| 12961 |
|
| 12962 |
OO.ui.FieldLayout.prototype.makeMessage = function ( kind, text ) { |
| 12963 |
return new OO.ui.MessageWidget( { |
| 12964 |
type: kind, |
| 12965 |
inline: true, |
| 12966 |
label: text |
| 12967 |
} ).$element; |
| 12968 |
}; |
| 12969 |
|
| 12970 |
|
| 12971 |
|
| 12972 |
|
| 12973 |
|
| 12974 |
|
| 12975 |
|
| 12976 |
|
| 12977 |
|
| 12978 |
OO.ui.FieldLayout.prototype.setAlignment = function ( value ) { |
| 12979 |
if ( value !== this.align ) { |
| 12980 |
|
| 12981 |
if ( [ 'left', 'right', 'top', 'inline' ].indexOf( value ) === -1 ) { |
| 12982 |
value = 'left'; |
| 12983 |
} |
| 12984 |
|
| 12985 |
if ( value === 'inline' && !this.isFieldInline() ) { |
| 12986 |
value = 'top'; |
| 12987 |
} |
| 12988 |
|
| 12989 |
|
| 12990 |
if ( this.helpInline ) { |
| 12991 |
if ( value === 'top' ) { |
| 12992 |
this.$header.append( this.$label ); |
| 12993 |
this.$body.append( this.$header, this.$field, this.$help ); |
| 12994 |
} else if ( value === 'inline' ) { |
| 12995 |
this.$header.append( this.$label, this.$help ); |
| 12996 |
this.$body.append( this.$field, this.$header ); |
| 12997 |
} else { |
| 12998 |
this.$header.append( this.$label, this.$help ); |
| 12999 |
this.$body.append( this.$header, this.$field ); |
| 13000 |
} |
| 13001 |
} else { |
| 13002 |
if ( value === 'top' ) { |
| 13003 |
this.$header.append( this.$help, this.$label ); |
| 13004 |
this.$body.append( this.$header, this.$field ); |
| 13005 |
} else if ( value === 'inline' ) { |
| 13006 |
this.$header.append( this.$help, this.$label ); |
| 13007 |
this.$body.append( this.$field, this.$header ); |
| 13008 |
} else { |
| 13009 |
this.$header.append( this.$label ); |
| 13010 |
this.$body.append( this.$header, this.$help, this.$field ); |
| 13011 |
} |
| 13012 |
} |
| 13013 |
|
| 13014 |
|
| 13015 |
|
| 13016 |
|
| 13017 |
|
| 13018 |
if ( this.align ) { |
| 13019 |
this.$element.removeClass( 'oo-ui-fieldLayout-align-' + this.align ); |
| 13020 |
} |
| 13021 |
this.$element.addClass( 'oo-ui-fieldLayout-align-' + value ); |
| 13022 |
this.align = value; |
| 13023 |
} |
| 13024 |
|
| 13025 |
return this; |
| 13026 |
}; |
| 13027 |
|
| 13028 |
|
| 13029 |
|
| 13030 |
|
| 13031 |
|
| 13032 |
|
| 13033 |
|
| 13034 |
|
| 13035 |
|
| 13036 |
OO.ui.FieldLayout.prototype.setErrors = function ( errors ) { |
| 13037 |
this.errors = errors.slice(); |
| 13038 |
this.updateMessages(); |
| 13039 |
return this; |
| 13040 |
}; |
| 13041 |
|
| 13042 |
|
| 13043 |
|
| 13044 |
|
| 13045 |
|
| 13046 |
|
| 13047 |
|
| 13048 |
|
| 13049 |
|
| 13050 |
|
| 13051 |
OO.ui.FieldLayout.prototype.setWarnings = function ( warnings ) { |
| 13052 |
this.warnings = warnings.slice(); |
| 13053 |
this.updateMessages(); |
| 13054 |
return this; |
| 13055 |
}; |
| 13056 |
|
| 13057 |
|
| 13058 |
|
| 13059 |
|
| 13060 |
|
| 13061 |
|
| 13062 |
|
| 13063 |
|
| 13064 |
|
| 13065 |
|
| 13066 |
OO.ui.FieldLayout.prototype.setSuccess = function ( successMessages ) { |
| 13067 |
this.successMessages = successMessages.slice(); |
| 13068 |
this.updateMessages(); |
| 13069 |
return this; |
| 13070 |
}; |
| 13071 |
|
| 13072 |
|
| 13073 |
|
| 13074 |
|
| 13075 |
|
| 13076 |
|
| 13077 |
|
| 13078 |
|
| 13079 |
|
| 13080 |
OO.ui.FieldLayout.prototype.setNotices = function ( notices ) { |
| 13081 |
this.notices = notices.slice(); |
| 13082 |
this.updateMessages(); |
| 13083 |
return this; |
| 13084 |
}; |
| 13085 |
|
| 13086 |
|
| 13087 |
|
| 13088 |
|
| 13089 |
|
| 13090 |
|
| 13091 |
OO.ui.FieldLayout.prototype.updateMessages = function () { |
| 13092 |
this.$messages.empty(); |
| 13093 |
|
| 13094 |
if ( |
| 13095 |
this.errors.length || |
| 13096 |
this.warnings.length || |
| 13097 |
this.successMessages.length || |
| 13098 |
this.notices.length |
| 13099 |
) { |
| 13100 |
this.$body.after( this.$messages ); |
| 13101 |
} else { |
| 13102 |
this.$messages.remove(); |
| 13103 |
return; |
| 13104 |
} |
| 13105 |
|
| 13106 |
let i; |
| 13107 |
for ( i = 0; i < this.errors.length; i++ ) { |
| 13108 |
this.$messages.append( this.makeMessage( 'error', this.errors[ i ] ) ); |
| 13109 |
} |
| 13110 |
for ( i = 0; i < this.warnings.length; i++ ) { |
| 13111 |
this.$messages.append( this.makeMessage( 'warning', this.warnings[ i ] ) ); |
| 13112 |
} |
| 13113 |
for ( i = 0; i < this.successMessages.length; i++ ) { |
| 13114 |
this.$messages.append( this.makeMessage( 'success', this.successMessages[ i ] ) ); |
| 13115 |
} |
| 13116 |
for ( i = 0; i < this.notices.length; i++ ) { |
| 13117 |
this.$messages.append( this.makeMessage( 'notice', this.notices[ i ] ) ); |
| 13118 |
} |
| 13119 |
}; |
| 13120 |
|
| 13121 |
|
| 13122 |
|
| 13123 |
|
| 13124 |
|
| 13125 |
|
| 13126 |
|
| 13127 |
|
| 13128 |
|
| 13129 |
OO.ui.FieldLayout.prototype.formatTitleWithAccessKey = function ( title ) { |
| 13130 |
if ( this.fieldWidget && this.fieldWidget.formatTitleWithAccessKey ) { |
| 13131 |
return this.fieldWidget.formatTitleWithAccessKey( title ); |
| 13132 |
} |
| 13133 |
return title; |
| 13134 |
}; |
| 13135 |
|
| 13136 |
|
| 13137 |
|
| 13138 |
|
| 13139 |
|
| 13140 |
|
| 13141 |
|
| 13142 |
|
| 13143 |
|
| 13144 |
|
| 13145 |
OO.ui.FieldLayout.prototype.createHelpElement = function ( help, $overlay ) { |
| 13146 |
let helpId, helpWidget; |
| 13147 |
|
| 13148 |
if ( this.helpInline ) { |
| 13149 |
helpWidget = new OO.ui.LabelWidget( { |
| 13150 |
label: help, |
| 13151 |
classes: [ 'oo-ui-inline-help' ] |
| 13152 |
} ); |
| 13153 |
|
| 13154 |
helpId = helpWidget.getElementId(); |
| 13155 |
} else { |
| 13156 |
helpWidget = new OO.ui.PopupButtonWidget( { |
| 13157 |
$overlay: $overlay, |
| 13158 |
popup: { |
| 13159 |
padded: true |
| 13160 |
}, |
| 13161 |
classes: [ 'oo-ui-fieldLayout-help' ], |
| 13162 |
framed: false, |
| 13163 |
icon: 'info', |
| 13164 |
label: OO.ui.msg( 'ooui-field-help' ), |
| 13165 |
invisibleLabel: true |
| 13166 |
} ); |
| 13167 |
|
| 13168 |
helpWidget.popup.on( 'ready', () => { |
| 13169 |
const $popupElement = helpWidget.popup.$element; |
| 13170 |
$popupElement.attr( 'tabindex', 0 ); |
| 13171 |
$popupElement.trigger( 'focus' ); |
| 13172 |
} ); |
| 13173 |
|
| 13174 |
helpWidget.popup.on( 'closing', () => { |
| 13175 |
helpWidget.$button.trigger( 'focus' ); |
| 13176 |
} ); |
| 13177 |
|
| 13178 |
if ( help instanceof OO.ui.HtmlSnippet ) { |
| 13179 |
helpWidget.getPopup().$body.html( help.toString() ); |
| 13180 |
} else { |
| 13181 |
helpWidget.getPopup().$body.text( help ); |
| 13182 |
} |
| 13183 |
|
| 13184 |
helpId = helpWidget.getPopup().getBodyId(); |
| 13185 |
} |
| 13186 |
|
| 13187 |
|
| 13188 |
|
| 13189 |
( |
| 13190 |
this.fieldWidget.$input || |
| 13191 |
( this.fieldWidget.input && this.fieldWidget.input.$input ) || |
| 13192 |
this.fieldWidget.$button || |
| 13193 |
this.fieldWidget.$element |
| 13194 |
).attr( 'aria-describedby', helpId ); |
| 13195 |
|
| 13196 |
return helpWidget.$element; |
| 13197 |
}; |
| 13198 |
|
| 13199 |
|
| 13200 |
|
| 13201 |
|
| 13202 |
|
| 13203 |
|
| 13204 |
|
| 13205 |
|
| 13206 |
|
| 13207 |
|
| 13208 |
|
| 13209 |
|
| 13210 |
|
| 13211 |
|
| 13212 |
|
| 13213 |
|
| 13214 |
|
| 13215 |
|
| 13216 |
|
| 13217 |
|
| 13218 |
|
| 13219 |
|
| 13220 |
|
| 13221 |
|
| 13222 |
|
| 13223 |
|
| 13224 |
|
| 13225 |
|
| 13226 |
|
| 13227 |
|
| 13228 |
|
| 13229 |
|
| 13230 |
|
| 13231 |
|
| 13232 |
|
| 13233 |
|
| 13234 |
|
| 13235 |
|
| 13236 |
|
| 13237 |
|
| 13238 |
|
| 13239 |
|
| 13240 |
|
| 13241 |
|
| 13242 |
|
| 13243 |
|
| 13244 |
|
| 13245 |
|
| 13246 |
OO.ui.ActionFieldLayout = function OoUiActionFieldLayout( fieldWidget, buttonWidget, config ) { |
| 13247 |
|
| 13248 |
if ( OO.isPlainObject( fieldWidget ) && config === undefined ) { |
| 13249 |
config = fieldWidget; |
| 13250 |
fieldWidget = config.fieldWidget; |
| 13251 |
buttonWidget = config.buttonWidget; |
| 13252 |
} |
| 13253 |
|
| 13254 |
|
| 13255 |
OO.ui.ActionFieldLayout.super.call( this, fieldWidget, config ); |
| 13256 |
|
| 13257 |
|
| 13258 |
this.buttonWidget = buttonWidget; |
| 13259 |
this.$button = $( '<span>' ); |
| 13260 |
this.$input = this.isFieldInline() ? $( '<span>' ) : $( '<div>' ); |
| 13261 |
|
| 13262 |
|
| 13263 |
this.$element.addClass( 'oo-ui-actionFieldLayout' ); |
| 13264 |
this.$button |
| 13265 |
.addClass( 'oo-ui-actionFieldLayout-button' ) |
| 13266 |
.append( this.buttonWidget.$element ); |
| 13267 |
this.$input |
| 13268 |
.addClass( 'oo-ui-actionFieldLayout-input' ) |
| 13269 |
.append( this.fieldWidget.$element ); |
| 13270 |
this.$field.append( this.$input, this.$button ); |
| 13271 |
}; |
| 13272 |
|
| 13273 |
|
| 13274 |
|
| 13275 |
OO.inheritClass( OO.ui.ActionFieldLayout, OO.ui.FieldLayout ); |
| 13276 |
|
| 13277 |
|
| 13278 |
|
| 13279 |
|
| 13280 |
|
| 13281 |
|
| 13282 |
|
| 13283 |
|
| 13284 |
|
| 13285 |
|
| 13286 |
|
| 13287 |
|
| 13288 |
|
| 13289 |
|
| 13290 |
|
| 13291 |
|
| 13292 |
|
| 13293 |
|
| 13294 |
|
| 13295 |
|
| 13296 |
|
| 13297 |
|
| 13298 |
|
| 13299 |
|
| 13300 |
|
| 13301 |
|
| 13302 |
|
| 13303 |
|
| 13304 |
|
| 13305 |
|
| 13306 |
|
| 13307 |
|
| 13308 |
|
| 13309 |
|
| 13310 |
|
| 13311 |
|
| 13312 |
|
| 13313 |
|
| 13314 |
|
| 13315 |
|
| 13316 |
|
| 13317 |
|
| 13318 |
|
| 13319 |
|
| 13320 |
|
| 13321 |
|
| 13322 |
|
| 13323 |
|
| 13324 |
|
| 13325 |
|
| 13326 |
|
| 13327 |
|
| 13328 |
|
| 13329 |
|
| 13330 |
OO.ui.FieldsetLayout = function OoUiFieldsetLayout( config ) { |
| 13331 |
|
| 13332 |
config = config || {}; |
| 13333 |
|
| 13334 |
|
| 13335 |
OO.ui.FieldsetLayout.super.call( this, config ); |
| 13336 |
|
| 13337 |
|
| 13338 |
OO.ui.mixin.IconElement.call( this, config ); |
| 13339 |
OO.ui.mixin.LabelElement.call( this, config ); |
| 13340 |
OO.ui.mixin.GroupElement.call( this, config ); |
| 13341 |
|
| 13342 |
|
| 13343 |
this.$header = $( '<legend>' ); |
| 13344 |
|
| 13345 |
|
| 13346 |
this.$header |
| 13347 |
.addClass( 'oo-ui-fieldsetLayout-header' ) |
| 13348 |
.append( this.$icon, this.$label ); |
| 13349 |
this.$group.addClass( 'oo-ui-fieldsetLayout-group' ); |
| 13350 |
this.$element |
| 13351 |
.addClass( 'oo-ui-fieldsetLayout' ) |
| 13352 |
.prepend( this.$header, this.$group ); |
| 13353 |
|
| 13354 |
|
| 13355 |
if ( config.help ) { |
| 13356 |
if ( config.helpInline ) { |
| 13357 |
const inlineHelpWidget = new OO.ui.LabelWidget( { |
| 13358 |
label: config.help, |
| 13359 |
classes: [ 'oo-ui-inline-help' ] |
| 13360 |
} ); |
| 13361 |
this.$element.prepend( this.$header, inlineHelpWidget.$element, this.$group ); |
| 13362 |
} else { |
| 13363 |
const helpWidget = new OO.ui.PopupButtonWidget( { |
| 13364 |
$overlay: config.$overlay, |
| 13365 |
popup: { |
| 13366 |
padded: true |
| 13367 |
}, |
| 13368 |
classes: [ 'oo-ui-fieldsetLayout-help' ], |
| 13369 |
framed: false, |
| 13370 |
icon: 'info', |
| 13371 |
label: OO.ui.msg( 'ooui-field-help' ), |
| 13372 |
invisibleLabel: true |
| 13373 |
} ); |
| 13374 |
if ( config.help instanceof OO.ui.HtmlSnippet ) { |
| 13375 |
helpWidget.getPopup().$body.html( config.help.toString() ); |
| 13376 |
} else { |
| 13377 |
helpWidget.getPopup().$body.text( config.help ); |
| 13378 |
} |
| 13379 |
this.$header.append( helpWidget.$element ); |
| 13380 |
} |
| 13381 |
} |
| 13382 |
this.addItems( config.items || [] ); |
| 13383 |
}; |
| 13384 |
|
| 13385 |
|
| 13386 |
|
| 13387 |
OO.inheritClass( OO.ui.FieldsetLayout, OO.ui.Layout ); |
| 13388 |
OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.IconElement ); |
| 13389 |
OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.LabelElement ); |
| 13390 |
OO.mixinClass( OO.ui.FieldsetLayout, OO.ui.mixin.GroupElement ); |
| 13391 |
|
| 13392 |
|
| 13393 |
|
| 13394 |
|
| 13395 |
|
| 13396 |
|
| 13397 |
|
| 13398 |
OO.ui.FieldsetLayout.static.tagName = 'fieldset'; |
| 13399 |
|
| 13400 |
|
| 13401 |
|
| 13402 |
|
| 13403 |
|
| 13404 |
|
| 13405 |
|
| 13406 |
|
| 13407 |
|
| 13408 |
|
| 13409 |
|
| 13410 |
|
| 13411 |
nd |
| 13412 |
|
| 13413 |
|
| 13414 |
|
| 13415 |
|
| 13416 |
|
| 13417 |
|
| 13418 |
|
| 13419 |
|
| 13420 |
|
| 13421 |
|
| 13422 |
|
| 13423 |
|
| 13424 |
|
| 13425 |
|
| 13426 |
|
| 13427 |
|
| 13428 |
|
| 13429 |
|
| 13430 |
|
| 13431 |
|
| 13432 |
|
| 13433 |
|
| 13434 |
|
| 13435 |
|
| 13436 |
|
| 13437 |
|
| 13438 |
|
| 13439 |
|
| 13440 |
|
| 13441 |
|
| 13442 |
|
| 13443 |
|
| 13444 |
|
| 13445 |
|
| 13446 |
|
| 13447 |
|
| 13448 |
|
| 13449 |
|
| 13450 |
|
| 13451 |
|
| 13452 |
|
| 13453 |
|
| 13454 |
|
| 13455 |
|
| 13456 |
|
| 13457 |
|
| 13458 |
|
| 13459 |
|
| 13460 |
|
| 13461 |
|
| 13462 |
|
| 13463 |
OO.ui.FormLayout = function OoUiFormLayout( config ) { |
| 13464 |
|
| 13465 |
config = config || {}; |
| 13466 |
|
| 13467 |
|
| 13468 |
OO.ui.FormLayout.super.call( this, config ); |
| 13469 |
|
| 13470 |
|
| 13471 |
OO.ui.mixin.GroupElement.call( this, Object.assign( { $group: this.$element }, config ) ); |
| 13472 |
|
| 13473 |
|
| 13474 |
this.$element.on( 'submit', this.onFormSubmit.bind( this ) ); |
| 13475 |
|
| 13476 |
|
| 13477 |
let action = config.action; |
| 13478 |
if ( action !== undefined && !OO.ui.isSafeUrl( action ) ) { |
| 13479 |
action = './' + action; |
| 13480 |
} |
| 13481 |
|
| 13482 |
|
| 13483 |
this.$element |
| 13484 |
.addClass( 'oo-ui-formLayout' ) |
| 13485 |
.attr( { |
| 13486 |
method: config.method, |
| 13487 |
action: action, |
| 13488 |
enctype: config.enctype |
| 13489 |
} ); |
| 13490 |
this.addItems( config.items || [] ); |
| 13491 |
}; |
| 13492 |
|
| 13493 |
|
| 13494 |
|
| 13495 |
OO.inheritClass( OO.ui.FormLayout, OO.ui.Layout ); |
| 13496 |
OO.mixinClass( OO.ui.FormLayout, OO.ui.mixin.GroupElement ); |
| 13497 |
|
| 13498 |
|
| 13499 |
|
| 13500 |
|
| 13501 |
|
| 13502 |
|
| 13503 |
|
| 13504 |
|
| 13505 |
|
| 13506 |
|
| 13507 |
|
| 13508 |
|
| 13509 |
|
| 13510 |
|
| 13511 |
|
| 13512 |
OO.ui.FormLayout.static.tagName = 'form'; |
| 13513 |
|
| 13514 |
|
| 13515 |
|
| 13516 |
|
| 13517 |
|
| 13518 |
|
| 13519 |
|
| 13520 |
|
| 13521 |
|
| 13522 |
|
| 13523 |
|
| 13524 |
OO.ui.FormLayout.prototype.onFormSubmit = function () { |
| 13525 |
if ( this.emit( 'submit' ) ) { |
| 13526 |
return false; |
| 13527 |
} |
| 13528 |
}; |
| 13529 |
|
| 13530 |
|
| 13531 |
|
| 13532 |
|
| 13533 |
|
| 13534 |
|
| 13535 |
|
| 13536 |
|
| 13537 |
|
| 13538 |
|
| 13539 |
|
| 13540 |
|
| 13541 |
|
| 13542 |
|
| 13543 |
|
| 13544 |
|
| 13545 |
|
| 13546 |
|
| 13547 |
|
| 13548 |
|
| 13549 |
|
| 13550 |
|
| 13551 |
|
| 13552 |
|
| 13553 |
|
| 13554 |
|
| 13555 |
|
| 13556 |
OO.ui.PanelLayout = function OoUiPanelLayout( config ) { |
| 13557 |
|
| 13558 |
config = Object.assign( { |
| 13559 |
scrollable: false, |
| 13560 |
padded: false, |
| 13561 |
expanded: true, |
| 13562 |
framed: false |
| 13563 |
}, config ); |
| 13564 |
|
| 13565 |
|
| 13566 |
OO.ui.PanelLayout.super.call( this, config ); |
| 13567 |
|
| 13568 |
|
| 13569 |
this.$element.addClass( 'oo-ui-panelLayout' ); |
| 13570 |
if ( config.scrollable ) { |
| 13571 |
this.$element.addClass( 'oo-ui-panelLayout-scrollable' ); |
| 13572 |
} |
| 13573 |
if ( config.padded ) { |
| 13574 |
this.$element.addClass( 'oo-ui-panelLayout-padded' ); |
| 13575 |
} |
| 13576 |
if ( config.expanded ) { |
| 13577 |
this.$element.addClass( 'oo-ui-panelLayout-expanded' ); |
| 13578 |
} |
| 13579 |
if ( config.framed ) { |
| 13580 |
this.$element.addClass( 'oo-ui-panelLayout-framed' ); |
| 13581 |
} |
| 13582 |
}; |
| 13583 |
|
| 13584 |
|
| 13585 |
|
| 13586 |
OO.inheritClass( OO.ui.PanelLayout, OO.ui.Layout ); |
| 13587 |
|
| 13588 |
|
| 13589 |
|
| 13590 |
|
| 13591 |
|
| 13592 |
|
| 13593 |
OO.ui.PanelLayout.static.reusePreInfuseDOM = function ( node, config ) { |
| 13594 |
config = OO.ui.PanelLayout.super.static.reusePreInfuseDOM( node, config ); |
| 13595 |
if ( config.preserveContent !== false ) { |
| 13596 |
config.$content = $( node ).contents(); |
| 13597 |
} |
| 13598 |
return config; |
| 13599 |
}; |
| 13600 |
|
| 13601 |
|
| 13602 |
|
| 13603 |
|
| 13604 |
|
| 13605 |
|
| 13606 |
|
| 13607 |
|
| 13608 |
OO.ui.PanelLayout.prototype.focus = function () { |
| 13609 |
OO.ui.findFocusable( this.$element ).focus(); |
| 13610 |
}; |
| 13611 |
|
| 13612 |
|
| 13613 |
|
| 13614 |
|
| 13615 |
|
| 13616 |
|
| 13617 |
|
| 13618 |
|
| 13619 |
|
| 13620 |
|
| 13621 |
|
| 13622 |
|
| 13623 |
|
| 13624 |
|
| 13625 |
|
| 13626 |
|
| 13627 |
|
| 13628 |
|
| 13629 |
|
| 13630 |
|
| 13631 |
|
| 13632 |
|
| 13633 |
|
| 13634 |
|
| 13635 |
|
| 13636 |
|
| 13637 |
OO.ui.HorizontalLayout = function OoUiHorizontalLayout( config ) { |
| 13638 |
|
| 13639 |
config = config || {}; |
| 13640 |
|
| 13641 |
|
| 13642 |
OO.ui.HorizontalLayout.super.call( this, config ); |
| 13643 |
|
| 13644 |
|
| 13645 |
OO.ui.mixin.GroupElement.call( this, Object.assign( { $group: this.$element }, config ) ); |
| 13646 |
|
| 13647 |
|
| 13648 |
this.$element.addClass( 'oo-ui-horizontalLayout' ); |
| 13649 |
this.addItems( config.items || [] ); |
| 13650 |
}; |
| 13651 |
|
| 13652 |
|
| 13653 |
|
| 13654 |
OO.inheritClass( OO.ui.HorizontalLayout, OO.ui.Layout ); |
| 13655 |
OO.mixinClass( OO.ui.HorizontalLayout, OO.ui.mixin.GroupElement ); |
| 13656 |
|
| 13657 |
|
| 13658 |
|
| 13659 |
|
| 13660 |
|
| 13661 |
|
| 13662 |
|
| 13663 |
|
| 13664 |
|
| 13665 |
|
| 13666 |
|
| 13667 |
|
| 13668 |
|
| 13669 |
|
| 13670 |
|
| 13671 |
|
| 13672 |
|
| 13673 |
|
| 13674 |
|
| 13675 |
|
| 13676 |
|
| 13677 |
|
| 13678 |
|
| 13679 |
|
| 13680 |
|
| 13681 |
|
| 13682 |
|
| 13683 |
|
| 13684 |
|
| 13685 |
|
| 13686 |
|
| 13687 |
|
| 13688 |
|
| 13689 |
|
| 13690 |
OO.ui.NumberInputWidget = function OoUiNumberInputWidget( config ) { |
| 13691 |
const $field = $( '<div>' ).addClass( 'oo-ui-numberInputWidget-field' ); |
| 13692 |
|
| 13693 |
|
| 13694 |
config = Object.assign( { |
| 13695 |
min: -Infinity, |
| 13696 |
max: Infinity, |
| 13697 |
showButtons: true |
| 13698 |
}, config ); |
| 13699 |
|
| 13700 |
|
| 13701 |
Object.assign( config, config.input ); |
| 13702 |
this.input = this; |
| 13703 |
|
| 13704 |
|
| 13705 |
OO.ui.NumberInputWidget.super.call( this, Object.assign( config, { |
| 13706 |
type: 'number' |
| 13707 |
} ) ); |
| 13708 |
|
| 13709 |
if ( config.showButtons ) { |
| 13710 |
this.minusButton = new OO.ui.ButtonWidget( Object.assign( |
| 13711 |
{ |
| 13712 |
disabled: this.isDisabled(), |
| 13713 |
tabIndex: -1, |
| 13714 |
classes: [ 'oo-ui-numberInputWidget-minusButton' ], |
| 13715 |
icon: 'subtract' |
| 13716 |
}, |
| 13717 |
config.minusButton |
| 13718 |
) ); |
| 13719 |
this.minusButton.$element.attr( 'aria-hidden', 'true' ); |
| 13720 |
this.plusButton = new OO.ui.ButtonWidget( Object.assign( |
| 13721 |
{ |
| 13722 |
disabled: this.isDisabled(), |
| 13723 |
tabIndex: -1, |
| 13724 |
classes: [ 'oo-ui-numberInputWidget-plusButton' ], |
| 13725 |
icon: 'add' |
| 13726 |
}, |
| 13727 |
config.plusButton |
| 13728 |
) ); |
| 13729 |
this.plusButton.$element.attr( 'aria-hidden', 'true' ); |
| 13730 |
} |
| 13731 |
|
| 13732 |
|
| 13733 |
this.$input.on( { |
| 13734 |
keydown: this.onKeyDown.bind( this ), |
| 13735 |
'wheel mousewheel DOMMouseScroll': this.onWheel.bind( this ) |
| 13736 |
} ); |
| 13737 |
if ( config.showButtons ) { |
| 13738 |
this.plusButton.connect( this, { |
| 13739 |
click: [ 'onButtonClick', +1 ] |
| 13740 |
} ); |
| 13741 |
this.minusButton.connect( this, { |
| 13742 |
click: [ 'onButtonClick', -1 ] |
| 13743 |
} ); |
| 13744 |
} |
| 13745 |
|
| 13746 |
|
| 13747 |
$field.append( this.$input ); |
| 13748 |
if ( config.showButtons ) { |
| 13749 |
$field |
| 13750 |
.prepend( this.minusButton.$element ) |
| 13751 |
.append( this.plusButton.$element ); |
| 13752 |
} |
| 13753 |
|
| 13754 |
|
| 13755 |
if ( config.allowInteger || config.isInteger ) { |
| 13756 |
|
| 13757 |
config.step = 1; |
| 13758 |
} |
| 13759 |
this.setRange( config.min, config.max ); |
| 13760 |
this.setStep( config.buttonStep, config.pageStep, config.step ); |
| 13761 |
|
| 13762 |
|
| 13763 |
this.setValidation( this.validateNumber.bind( this ) ); |
| 13764 |
|
| 13765 |
this.$element |
| 13766 |
.addClass( 'oo-ui-numberInputWidget' ) |
| 13767 |
.toggleClass( 'oo-ui-numberInputWidget-buttoned', config.showButtons ) |
| 13768 |
.append( $field ); |
| 13769 |
}; |
| 13770 |
|
| 13771 |
|
| 13772 |
|
| 13773 |
OO.inheritClass( OO.ui.NumberInputWidget, OO.ui.TextInputWidget ); |
| 13774 |
|
| 13775 |
|
| 13776 |
|
| 13777 |
|
| 13778 |
OO.ui.NumberInputWidget.prototype.setAllowInteger = function ( flag ) { |
| 13779 |
this.setStep( flag ? 1 : null ); |
| 13780 |
}; |
| 13781 |
|
| 13782 |
OO.ui.NumberInputWidget.prototype.setIsInteger = OO.ui.NumberInputWidget.prototype.setAllowInteger; |
| 13783 |
|
| 13784 |
|
| 13785 |
OO.ui.NumberInputWidget.prototype.getAllowInteger = function () { |
| 13786 |
return this.step === 1; |
| 13787 |
}; |
| 13788 |
|
| 13789 |
OO.ui.NumberInputWidget.prototype.getIsInteger = OO.ui.NumberInputWidget.prototype.getAllowInteger; |
| 13790 |
|
| 13791 |
|
| 13792 |
|
| 13793 |
|
| 13794 |
|
| 13795 |
|
| 13796 |
|
| 13797 |
OO.ui.NumberInputWidget.prototype.setRange = function ( min, max ) { |
| 13798 |
if ( min > max ) { |
| 13799 |
throw new Error( 'Minimum (' + min + ') must not be greater than maximum (' + max + ')' ); |
| 13800 |
} |
| 13801 |
this.min = min; |
| 13802 |
this.max = max; |
| 13803 |
this.$input.attr( { min: this.min, max: this.max } ); |
| 13804 |
this.setValidityFlag(); |
| 13805 |
}; |
| 13806 |
|
| 13807 |
|
| 13808 |
|
| 13809 |
|
| 13810 |
|
| 13811 |
|
| 13812 |
OO.ui.NumberInputWidget.prototype.getRange = function () { |
| 13813 |
return [ this.min, this.max ]; |
| 13814 |
}; |
| 13815 |
|
| 13816 |
|
| 13817 |
|
| 13818 |
|
| 13819 |
|
| 13820 |
|
| 13821 |
|
| 13822 |
|
| 13823 |
|
| 13824 |
|
| 13825 |
|
| 13826 |
OO.ui.NumberInputWidget.prototype.setStep = function ( buttonStep, pageStep, step ) { |
| 13827 |
if ( buttonStep === undefined ) { |
| 13828 |
buttonStep = step || 1; |
| 13829 |
} |
| 13830 |
if ( pageStep === undefined ) { |
| 13831 |
pageStep = 10 * buttonStep; |
| 13832 |
} |
| 13833 |
if ( step !== null && step <= 0 ) { |
| 13834 |
throw new Error( 'Step value, if given, must be positive' ); |
| 13835 |
} |
| 13836 |
if ( buttonStep <= 0 ) { |
| 13837 |
throw new Error( 'Button step value must be positive' ); |
| 13838 |
} |
| 13839 |
if ( pageStep <= 0 ) { |
| 13840 |
throw new Error( 'Page step value must be positive' ); |
| 13841 |
} |
| 13842 |
this.step = step; |
| 13843 |
this.buttonStep = buttonStep; |
| 13844 |
this.pageStep = pageStep; |
| 13845 |
this.$input.attr( 'step', this.step || 'any' ); |
| 13846 |
this.setValidityFlag(); |
| 13847 |
}; |
| 13848 |
|
| 13849 |
|
| 13850 |
|
| 13851 |
|
| 13852 |
OO.ui.NumberInputWidget.prototype.setValue = function ( value ) { |
| 13853 |
if ( value === '' ) { |
| 13854 |
|
| 13855 |
|
| 13856 |
this.$input.val( '' ); |
| 13857 |
} |
| 13858 |
return OO.ui.NumberInputWidget.super.prototype.setValue.call( this, value ); |
| 13859 |
}; |
| 13860 |
|
| 13861 |
|
| 13862 |
|
| 13863 |
|
| 13864 |
|
| 13865 |
|
| 13866 |
OO.ui.NumberInputWidget.prototype.getStep = function () { |
| 13867 |
return [ this.buttonStep, this.pageStep, this.step ]; |
| 13868 |
}; |
| 13869 |
|
| 13870 |
|
| 13871 |
|
| 13872 |
|
| 13873 |
|
| 13874 |
|
| 13875 |
OO.ui.NumberInputWidget.prototype.getNumericValue = function () { |
| 13876 |
return +this.getValue(); |
| 13877 |
}; |
| 13878 |
|
| 13879 |
|
| 13880 |
|
| 13881 |
|
| 13882 |
|
| 13883 |
|
| 13884 |
OO.ui.NumberInputWidget.prototype.adjustValue = function ( delta ) { |
| 13885 |
const v = this.getNumericValue(); |
| 13886 |
|
| 13887 |
delta = +delta; |
| 13888 |
if ( isNaN( delta ) || !isFinite( delta ) ) { |
| 13889 |
throw new Error( 'Delta must be a finite number' ); |
| 13890 |
} |
| 13891 |
|
| 13892 |
let n; |
| 13893 |
if ( isNaN( v ) ) { |
| 13894 |
n = 0; |
| 13895 |
} else { |
| 13896 |
n = v + delta; |
| 13897 |
n = Math.max( Math.min( n, this.max ), this.min ); |
| 13898 |
if ( this.step ) { |
| 13899 |
n = Math.round( n / this.step ) * this.step; |
| 13900 |
} |
| 13901 |
} |
| 13902 |
|
| 13903 |
if ( n !== v ) { |
| 13904 |
this.setValue( n ); |
| 13905 |
} |
| 13906 |
}; |
| 13907 |
|
| 13908 |
|
| 13909 |
|
| 13910 |
|
| 13911 |
|
| 13912 |
|
| 13913 |
|
| 13914 |
OO.ui.NumberInputWidget.prototype.validateNumber = function ( value ) { |
| 13915 |
const n = +value; |
| 13916 |
if ( value === '' ) { |
| 13917 |
return !this.isRequired(); |
| 13918 |
} |
| 13919 |
|
| 13920 |
if ( isNaN( n ) || !isFinite( n ) ) { |
| 13921 |
return false; |
| 13922 |
} |
| 13923 |
|
| 13924 |
if ( this.step && Math.floor( n / this.step ) !== n / this.step ) { |
| 13925 |
return false; |
| 13926 |
} |
| 13927 |
|
| 13928 |
if ( n < this.min || n > this.max ) { |
| 13929 |
return false; |
| 13930 |
} |
| 13931 |
|
| 13932 |
return true; |
| 13933 |
}; |
| 13934 |
|
| 13935 |
|
| 13936 |
|
| 13937 |
|
| 13938 |
|
| 13939 |
|
| 13940 |
|
| 13941 |
OO.ui.NumberInputWidget.prototype.onButtonClick = function ( dir ) { |
| 13942 |
this.adjustValue( dir * this.buttonStep ); |
| 13943 |
}; |
| 13944 |
|
| 13945 |
|
| 13946 |
|
| 13947 |
|
| 13948 |
|
| 13949 |
|
| 13950 |
|
| 13951 |
|
| 13952 |
OO.ui.NumberInputWidget.prototype.onWheel = function ( event ) { |
| 13953 |
let delta = 0; |
| 13954 |
|
| 13955 |
if ( this.isDisabled() || this.isReadOnly() ) { |
| 13956 |
return; |
| 13957 |
} |
| 13958 |
|
| 13959 |
if ( this.$input.is( ':focus' ) ) { |
| 13960 |
|
| 13961 |
if ( event.originalEvent.deltaMode !== undefined ) { |
| 13962 |
this.sawWheelEvent = true; |
| 13963 |
} |
| 13964 |
if ( event.originalEvent.deltaY ) { |
| 13965 |
delta = -event.originalEvent.deltaY; |
| 13966 |
} else if ( event.originalEvent.deltaX ) { |
| 13967 |
delta = event.originalEvent.deltaX; |
| 13968 |
} |
| 13969 |
|
| 13970 |
|
| 13971 |
if ( !this.sawWheelEvent ) { |
| 13972 |
if ( event.originalEvent.wheelDeltaX ) { |
| 13973 |
delta = -event.originalEvent.wheelDeltaX; |
| 13974 |
} else if ( event.originalEvent.wheelDeltaY ) { |
| 13975 |
delta = event.originalEvent.wheelDeltaY; |
| 13976 |
} else if ( event.originalEvent.wheelDelta ) { |
| 13977 |
delta = event.originalEvent.wheelDelta; |
| 13978 |
} else if ( event.originalEvent.detail ) { |
| 13979 |
delta = -event.originalEvent.detail; |
| 13980 |
} |
| 13981 |
} |
| 13982 |
|
| 13983 |
if ( delta ) { |
| 13984 |
delta = delta < 0 ? -1 : 1; |
| 13985 |
this.adjustValue( delta * this.buttonStep ); |
| 13986 |
} |
| 13987 |
|
| 13988 |
return false; |
| 13989 |
} |
| 13990 |
}; |
| 13991 |
|
| 13992 |
|
| 13993 |
|
| 13994 |
|
| 13995 |
|
| 13996 |
|
| 13997 |
|
| 13998 |
|
| 13999 |
OO.ui.NumberInputWidget.prototype.onKeyDown = function ( e ) { |
| 14000 |
if ( this.isDisabled() || this.isReadOnly() ) { |
| 14001 |
return; |
| 14002 |
} |
| 14003 |
|
| 14004 |
switch ( e.which ) { |
| 14005 |
case OO.ui.Keys.UP: |
| 14006 |
this.adjustValue( this.buttonStep ); |
| 14007 |
return false; |
| 14008 |
case OO.ui.Keys.DOWN: |
| 14009 |
this.adjustValue( -this.buttonStep ); |
| 14010 |
return false; |
| 14011 |
case OO.ui.Keys.PAGEUP: |
| 14012 |
this.adjustValue( this.pageStep ); |
| 14013 |
return false; |
| 14014 |
case OO.ui.Keys.PAGEDOWN: |
| 14015 |
this.adjustValue( -this.pageStep ); |
| 14016 |
return false; |
| 14017 |
} |
| 14018 |
}; |
| 14019 |
|
| 14020 |
|
| 14021 |
|
| 14022 |
|
| 14023 |
|
| 14024 |
|
| 14025 |
|
| 14026 |
|
| 14027 |
OO.ui.NumberInputWidget.prototype.updateControlsDisabled = function () { |
| 14028 |
const disabled = this.isDisabled() || this.isReadOnly(); |
| 14029 |
if ( this.minusButton ) { |
| 14030 |
this.minusButton.setDisabled( disabled ); |
| 14031 |
} |
| 14032 |
if ( this.plusButton ) { |
| 14033 |
this.plusButton.setDisabled( disabled ); |
| 14034 |
} |
| 14035 |
return this; |
| 14036 |
}; |
| 14037 |
|
| 14038 |
|
| 14039 |
|
| 14040 |
|
| 14041 |
OO.ui.NumberInputWidget.prototype.setDisabled = function ( disabled ) { |
| 14042 |
|
| 14043 |
OO.ui.NumberInputWidget.super.prototype.setDisabled.call( this, disabled ); |
| 14044 |
this.updateControlsDisabled(); |
| 14045 |
return this; |
| 14046 |
}; |
| 14047 |
|
| 14048 |
|
| 14049 |
|
| 14050 |
|
| 14051 |
OO.ui.NumberInputWidget.prototype.setReadOnly = function () { |
| 14052 |
|
| 14053 |
OO.ui.NumberInputWidget.super.prototype.setReadOnly.apply( this, arguments ); |
| 14054 |
this.updateControlsDisabled(); |
| 14055 |
return this; |
| 14056 |
}; |
| 14057 |
|
| 14058 |
|
| 14059 |
|
| 14060 |
|
| 14061 |
|
| 14062 |
|
| 14063 |
|
| 14064 |
|
| 14065 |
|
| 14066 |
|
| 14067 |
|
| 14068 |
|
| 14069 |
|
| 14070 |
|
| 14071 |
|
| 14072 |
|
| 14073 |
|
| 14074 |
|
| 14075 |
|
| 14076 |
|
| 14077 |
|
| 14078 |
|
| 14079 |
|
| 14080 |
|
| 14081 |
|
| 14082 |
|
| 14083 |
|
| 14084 |
|
| 14085 |
|
| 14086 |
|
| 14087 |
|
| 14088 |
|
| 14089 |
|
| 14090 |
|
| 14091 |
|
| 14092 |
|
| 14093 |
OO.ui.SelectFileInputWidget = function OoUiSelectFileInputWidget( config ) { |
| 14094 |
config = config || {}; |
| 14095 |
|
| 14096 |
|
| 14097 |
this.selectButton = new OO.ui.ButtonWidget( Object.assign( { |
| 14098 |
$element: $( '<label>' ), |
| 14099 |
classes: [ 'oo-ui-selectFileInputWidget-selectButton' ], |
| 14100 |
label: OO.ui.msg( |
| 14101 |
config.multiple ? |
| 14102 |
'ooui-selectfile-button-select-multiple' : |
| 14103 |
'ooui-selectfile-button-select' |
| 14104 |
) |
| 14105 |
}, config.button ) ); |
| 14106 |
|
| 14107 |
|
| 14108 |
config = Object.assign( { |
| 14109 |
accept: null, |
| 14110 |
placeholder: OO.ui.msg( 'ooui-selectfile-placeholder' ), |
| 14111 |
$tabIndexed: this.selectButton.$tabIndexed, |
| 14112 |
droppable: true, |
| 14113 |
buttonOnly: false, |
| 14114 |
showDropTarget: false, |
| 14115 |
thumbnailSizeLimit: 20 |
| 14116 |
}, config ); |
| 14117 |
|
| 14118 |
this.canSetFiles = true; |
| 14119 |
|
| 14120 |
try { |
| 14121 |
|
| 14122 |
new DataTransfer(); |
| 14123 |
} catch ( e ) { |
| 14124 |
this.canSetFiles = false; |
| 14125 |
config.droppable = false; |
| 14126 |
} |
| 14127 |
|
| 14128 |
this.info = new OO.ui.SearchInputWidget( { |
| 14129 |
classes: [ 'oo-ui-selectFileInputWidget-info' ], |
| 14130 |
placeholder: config.placeholder, |
| 14131 |
|
| 14132 |
$tabIndexed: $( [] ) |
| 14133 |
} ).setIcon( config.icon ); |
| 14134 |
|
| 14135 |
|
| 14136 |
|
| 14137 |
this.info.$input.attr( 'tabindex', -1 ); |
| 14138 |
|
| 14139 |
this.info.$indicator.attr( 'tabindex', 0 ); |
| 14140 |
|
| 14141 |
|
| 14142 |
OO.ui.SelectFileInputWidget.super.call( this, config ); |
| 14143 |
|
| 14144 |
|
| 14145 |
OO.ui.mixin.RequiredElement.call( this, Object.assign( {}, { |
| 14146 |
|
| 14147 |
indicatorElement: null |
| 14148 |
}, config ) ); |
| 14149 |
OO.ui.mixin.PendingElement.call( this ); |
| 14150 |
|
| 14151 |
|
| 14152 |
this.currentFiles = this.filterFiles( this.$input[ 0 ].files || [] ); |
| 14153 |
if ( Array.isArray( config.accept ) ) { |
| 14154 |
this.accept = config.accept; |
| 14155 |
} else { |
| 14156 |
this.accept = null; |
| 14157 |
} |
| 14158 |
this.multiple = !!config.multiple; |
| 14159 |
this.showDropTarget = config.droppable && config.showDropTarget; |
| 14160 |
this.thumbnailSizeLimit = config.thumbnailSizeLimit; |
| 14161 |
|
| 14162 |
|
| 14163 |
this.fieldLayout = new OO.ui.ActionFieldLayout( this.info, this.selectButton, { align: 'top' } ); |
| 14164 |
|
| 14165 |
this.$input |
| 14166 |
.attr( { |
| 14167 |
type: 'file', |
| 14168 |
|
| 14169 |
tabindex: -1, |
| 14170 |
|
| 14171 |
|
| 14172 |
'aria-disabled': null |
| 14173 |
} ); |
| 14174 |
|
| 14175 |
if ( this.accept ) { |
| 14176 |
this.$input.attr( 'accept', this.accept.join( ', ' ) ); |
| 14177 |
} |
| 14178 |
if ( this.multiple ) { |
| 14179 |
this.$input.attr( 'multiple', '' ); |
| 14180 |
} |
| 14181 |
this.selectButton.$button.append( this.$input ); |
| 14182 |
|
| 14183 |
this.$element |
| 14184 |
.addClass( 'oo-ui-selectFileInputWidget oo-ui-selectFileWidget' ) |
| 14185 |
.append( this.fieldLayout.$element ); |
| 14186 |
|
| 14187 |
if ( this.showDropTarget ) { |
| 14188 |
this.selectButton.setIcon( 'upload' ); |
| 14189 |
this.$element |
| 14190 |
.addClass( 'oo-ui-selectFileInputWidget-dropTarget oo-ui-selectFileWidget-dropTarget' ) |
| 14191 |
.on( { |
| 14192 |
click: this.onDropTargetClick.bind( this ) |
| 14193 |
} ) |
| 14194 |
.append( |
| 14195 |
this.info.$element, |
| 14196 |
this.selectButton.$element, |
| 14197 |
$( '<span>' ) |
| 14198 |
.addClass( 'oo-ui-selectFileInputWidget-dropLabel oo-ui-selectFileWidget-dropLabel' ) |
| 14199 |
.text( OO.ui.msg( |
| 14200 |
this.multiple ? |
| 14201 |
'ooui-selectfile-dragdrop-placeholder-multiple' : |
| 14202 |
'ooui-selectfile-dragdrop-placeholder' |
| 14203 |
) ) |
| 14204 |
); |
| 14205 |
if ( !this.multiple ) { |
| 14206 |
this.$thumbnail = $( '<div>' ).addClass( 'oo-ui-selectFileInputWidget-thumbnail oo-ui-selectFileWidget-thumbnail' ); |
| 14207 |
this.setPendingElement( this.$thumbnail ); |
| 14208 |
this.$element |
| 14209 |
.addClass( 'oo-ui-selectFileInputWidget-withThumbnail oo-ui-selectFileWidget-withThumbnail' ) |
| 14210 |
.prepend( this.$thumbnail ); |
| 14211 |
} |
| 14212 |
this.fieldLayout.$element.remove(); |
| 14213 |
} else if ( config.buttonOnly ) { |
| 14214 |
|
| 14215 |
|
| 14216 |
this.selectButton.$element |
| 14217 |
.addClass( this.$element.attr( 'class' ) ) |
| 14218 |
.addClass( 'oo-ui-selectFileInputWidget-buttonOnly oo-ui-selectFileWidget-buttonOnly' ); |
| 14219 |
|
| 14220 |
this.$element = this.selectButton.$element; |
| 14221 |
} |
| 14222 |
|
| 14223 |
|
| 14224 |
this.info.connect( this, { change: 'onInfoChange' } ); |
| 14225 |
this.selectButton.$button.on( { |
| 14226 |
keypress: this.onKeyPress.bind( this ) |
| 14227 |
} ); |
| 14228 |
this.$input.on( { |
| 14229 |
change: this.onFileSelected.bind( this ), |
| 14230 |
click: function ( e ) { |
| 14231 |
|
| 14232 |
|
| 14233 |
e.stopPropagation(); |
| 14234 |
} |
| 14235 |
} ); |
| 14236 |
|
| 14237 |
this.connect( this, { change: 'updateUI' } ); |
| 14238 |
if ( config.droppable ) { |
| 14239 |
const dragHandler = this.onDragEnterOrOver.bind( this ); |
| 14240 |
this.$element.on( { |
| 14241 |
dragenter: dragHandler, |
| 14242 |
dragover: dragHandler, |
| 14243 |
dragleave: this.onDragLeave.bind( this ), |
| 14244 |
drop: this.onDrop.bind( this ) |
| 14245 |
} ); |
| 14246 |
} |
| 14247 |
|
| 14248 |
this.updateUI(); |
| 14249 |
}; |
| 14250 |
|
| 14251 |
|
| 14252 |
|
| 14253 |
OO.inheritClass( OO.ui.SelectFileInputWidget, OO.ui.InputWidget ); |
| 14254 |
OO.mixinClass( OO.ui.SelectFileInputWidget, OO.ui.mixin.RequiredElement ); |
| 14255 |
OO.mixinClass( OO.ui.SelectFileInputWidget, OO.ui.mixin.PendingElement ); |
| 14256 |
|
| 14257 |
|
| 14258 |
|
| 14259 |
|
| 14260 |
|
| 14261 |
|
| 14262 |
|
| 14263 |
|
| 14264 |
|
| 14265 |
|
| 14266 |
|
| 14267 |
|
| 14268 |
|
| 14269 |
OO.ui.SelectFileInputWidget.static.title = ''; |
| 14270 |
|
| 14271 |
|
| 14272 |
|
| 14273 |
|
| 14274 |
|
| 14275 |
|
| 14276 |
|
| 14277 |
|
| 14278 |
|
| 14279 |
|
| 14280 |
|
| 14281 |
OO.ui.SelectFileInputWidget.prototype.getValue = function () { |
| 14282 |
return this.multiple ? this.currentFiles : this.currentFiles[ 0 ]; |
| 14283 |
}; |
| 14284 |
|
| 14285 |
|
| 14286 |
|
| 14287 |
|
| 14288 |
|
| 14289 |
|
| 14290 |
|
| 14291 |
|
| 14292 |
|
| 14293 |
|
| 14294 |
|
| 14295 |
|
| 14296 |
OO.ui.SelectFileInputWidget.prototype.setValue = function ( files ) { |
| 14297 |
if ( files === undefined || typeof files === 'string' ) { |
| 14298 |
|
| 14299 |
return this; |
| 14300 |
} |
| 14301 |
|
| 14302 |
if ( files && !this.multiple ) { |
| 14303 |
files = files.slice( 0, 1 ); |
| 14304 |
} |
| 14305 |
|
| 14306 |
function comparableFile( file ) { |
| 14307 |
|
| 14308 |
|
| 14309 |
|
| 14310 |
return Object.assign( {}, file ); |
| 14311 |
} |
| 14312 |
|
| 14313 |
if ( !OO.compare( |
| 14314 |
files && files.map( comparableFile ), |
| 14315 |
this.currentFiles && this.currentFiles.map( comparableFile ) |
| 14316 |
) ) { |
| 14317 |
this.currentFiles = files || []; |
| 14318 |
this.emit( 'change', this.currentFiles ); |
| 14319 |
} |
| 14320 |
|
| 14321 |
if ( this.canSetFiles ) { |
| 14322 |
|
| 14323 |
const dataTransfer = new DataTransfer(); |
| 14324 |
Array.prototype.forEach.call( this.currentFiles || [], ( file ) => { |
| 14325 |
dataTransfer.items.add( file ); |
| 14326 |
} ); |
| 14327 |
this.$input[ 0 ].files = dataTransfer.files; |
| 14328 |
} else { |
| 14329 |
if ( !files || !files.length ) { |
| 14330 |
|
| 14331 |
|
| 14332 |
OO.ui.SelectFileInputWidget.super.prototype.setValue.call( this, '' ); |
| 14333 |
} |
| 14334 |
|
| 14335 |
|
| 14336 |
} |
| 14337 |
|
| 14338 |
return this; |
| 14339 |
}; |
| 14340 |
|
| 14341 |
|
| 14342 |
|
| 14343 |
|
| 14344 |
|
| 14345 |
|
| 14346 |
OO.ui.SelectFileInputWidget.prototype.getFilename = function () { |
| 14347 |
return this.currentFiles.map( ( file ) => file.name ).join( ', ' ); |
| 14348 |
}; |
| 14349 |
|
| 14350 |
|
| 14351 |
|
| 14352 |
|
| 14353 |
|
| 14354 |
|
| 14355 |
|
| 14356 |
OO.ui.SelectFileInputWidget.prototype.onFileSelected = function ( e ) { |
| 14357 |
const files = this.filterFiles( e.target.files || [] ); |
| 14358 |
this.setValue( files ); |
| 14359 |
}; |
| 14360 |
|
| 14361 |
|
| 14362 |
|
| 14363 |
|
| 14364 |
|
| 14365 |
|
| 14366 |
OO.ui.SelectFileInputWidget.prototype.onEdit = function () {}; |
| 14367 |
|
| 14368 |
|
| 14369 |
|
| 14370 |
|
| 14371 |
|
| 14372 |
|
| 14373 |
OO.ui.SelectFileInputWidget.prototype.updateUI = function () { |
| 14374 |
|
| 14375 |
if ( !this.selectButton ) { |
| 14376 |
return; |
| 14377 |
} |
| 14378 |
|
| 14379 |
this.info.setValue( this.getFilename() ); |
| 14380 |
|
| 14381 |
if ( this.currentFiles.length ) { |
| 14382 |
this.$element.removeClass( 'oo-ui-selectFileInputWidget-empty' ); |
| 14383 |
|
| 14384 |
if ( this.showDropTarget ) { |
| 14385 |
if ( !this.multiple ) { |
| 14386 |
this.pushPending(); |
| 14387 |
this.loadAndGetImageUrl( this.currentFiles[ 0 ] ).done( ( url ) => { |
| 14388 |
this.$thumbnail.css( 'background-image', 'url( ' + url + ' )' ); |
| 14389 |
} ).fail( () => { |
| 14390 |
this.$thumbnail.append( |
| 14391 |
new OO.ui.IconWidget( { |
| 14392 |
icon: 'attachment', |
| 14393 |
classes: [ 'oo-ui-selectFileInputWidget-noThumbnail-icon oo-ui-selectFileWidget-noThumbnail-icon' ] |
| 14394 |
} ).$element |
| 14395 |
); |
| 14396 |
} ).always( () => { |
| 14397 |
this.popPending(); |
| 14398 |
} ); |
| 14399 |
} |
| 14400 |
this.$element.off( 'click' ); |
| 14401 |
} |
| 14402 |
} else { |
| 14403 |
if ( this.showDropTarget ) { |
| 14404 |
this.$element.off( 'click' ); |
| 14405 |
this.$element.on( { |
| 14406 |
click: this.onDropTargetClick.bind( this ) |
| 14407 |
} ); |
| 14408 |
if ( !this.multiple ) { |
| 14409 |
this.$thumbnail |
| 14410 |
.empty() |
| 14411 |
.css( 'background-image', '' ); |
| 14412 |
} |
| 14413 |
} |
| 14414 |
this.$element.addClass( 'oo-ui-selectFileInputWidget-empty' ); |
| 14415 |
} |
| 14416 |
}; |
| 14417 |
|
| 14418 |
|
| 14419 |
|
| 14420 |
|
| 14421 |
|
| 14422 |
|
| 14423 |
|
| 14424 |
OO.ui.SelectFileInputWidget.prototype.loadAndGetImageUrl = function ( file ) { |
| 14425 |
const deferred = $.Deferred(), |
| 14426 |
reader = new FileReader(); |
| 14427 |
|
| 14428 |
if ( |
| 14429 |
( OO.getProp( file, 'type' ) || '' ).indexOf( 'image/' ) === 0 && |
| 14430 |
file.size < this.thumbnailSizeLimit * 1024 * 1024 |
| 14431 |
) { |
| 14432 |
reader.onload = function ( event ) { |
| 14433 |
const img = document.createElement( 'img' ); |
| 14434 |
img.addEventListener( 'load', () => { |
| 14435 |
if ( |
| 14436 |
img.naturalWidth === 0 || |
| 14437 |
img.naturalHeight === 0 || |
| 14438 |
img.complete === false |
| 14439 |
) { |
| 14440 |
deferred.reject(); |
| 14441 |
} else { |
| 14442 |
deferred.resolve( event.target.result ); |
| 14443 |
} |
| 14444 |
} ); |
| 14445 |
img.src = event.target.result; |
| 14446 |
}; |
| 14447 |
reader.readAsDataURL( file ); |
| 14448 |
} else { |
| 14449 |
deferred.reject(); |
| 14450 |
} |
| 14451 |
|
| 14452 |
return deferred.promise(); |
| 14453 |
}; |
| 14454 |
|
| 14455 |
|
| 14456 |
|
| 14457 |
|
| 14458 |
|
| 14459 |
|
| 14460 |
|
| 14461 |
|
| 14462 |
OO.ui.SelectFileInputWidget.prototype.filterFiles = function ( files ) { |
| 14463 |
const accept = this.accept; |
| 14464 |
|
| 14465 |
function mimeAllowed( file ) { |
| 14466 |
const mimeType = file.type; |
| 14467 |
|
| 14468 |
if ( !accept || !mimeType ) { |
| 14469 |
return true; |
| 14470 |
} |
| 14471 |
|
| 14472 |
for ( let i = 0; i < accept.length; i++ ) { |
| 14473 |
let mimeTest = accept[ i ]; |
| 14474 |
if ( mimeTest === mimeType ) { |
| 14475 |
return true; |
| 14476 |
} else if ( mimeTest.slice( -2 ) === '/*' ) { |
| 14477 |
mimeTest = mimeTest.slice( 0, mimeTest.length - 1 ); |
| 14478 |
if ( mimeType.slice( 0, mimeTest.length ) === mimeTest ) { |
| 14479 |
return true; |
| 14480 |
} |
| 14481 |
} |
| 14482 |
} |
| 14483 |
return false; |
| 14484 |
} |
| 14485 |
|
| 14486 |
return Array.prototype.filter.call( files, mimeAllowed ); |
| 14487 |
}; |
| 14488 |
|
| 14489 |
|
| 14490 |
|
| 14491 |
|
| 14492 |
|
| 14493 |
|
| 14494 |
|
| 14495 |
|
| 14496 |
|
| 14497 |
|
| 14498 |
OO.ui.SelectFileInputWidget.prototype.onInfoChange = function ( value ) { |
| 14499 |
if ( value === '' ) { |
| 14500 |
this.setValue( null ); |
| 14501 |
} |
| 14502 |
}; |
| 14503 |
|
| 14504 |
|
| 14505 |
|
| 14506 |
|
| 14507 |
|
| 14508 |
|
| 14509 |
|
| 14510 |
|
| 14511 |
OO.ui.SelectFileInputWidget.prototype.onKeyPress = function ( e ) { |
| 14512 |
if ( !this.isDisabled() && this.$input && |
| 14513 |
( e.which === OO.ui.Keys.SPACE || e.which === OO.ui.Keys.ENTER ) |
| 14514 |
) { |
| 14515 |
|
| 14516 |
this.$input.trigger( 'click' ); |
| 14517 |
|
| 14518 |
this.selectButton.onDocumentKeyUp( e ); |
| 14519 |
return false; |
| 14520 |
} |
| 14521 |
}; |
| 14522 |
|
| 14523 |
|
| 14524 |
|
| 14525 |
|
| 14526 |
OO.ui.SelectFileInputWidget.prototype.setDisabled = function ( disabled ) { |
| 14527 |
|
| 14528 |
OO.ui.SelectFileInputWidget.super.prototype.setDisabled.call( this, disabled ); |
| 14529 |
|
| 14530 |
this.selectButton.setDisabled( disabled ); |
| 14531 |
this.info.setDisabled( disabled ); |
| 14532 |
|
| 14533 |
|
| 14534 |
|
| 14535 |
|
| 14536 |
this.info.$input.attr( 'disabled', true ); |
| 14537 |
|
| 14538 |
return this; |
| 14539 |
}; |
| 14540 |
|
| 14541 |
|
| 14542 |
|
| 14543 |
|
| 14544 |
|
| 14545 |
|
| 14546 |
|
| 14547 |
|
| 14548 |
OO.ui.SelectFileInputWidget.prototype.onDropTargetClick = function () { |
| 14549 |
if ( !this.isDisabled() && this.$input ) { |
| 14550 |
this.$input.trigger( 'click' ); |
| 14551 |
return false; |
| 14552 |
} |
| 14553 |
}; |
| 14554 |
|
| 14555 |
|
| 14556 |
|
| 14557 |
|
| 14558 |
|
| 14559 |
|
| 14560 |
|
| 14561 |
|
| 14562 |
OO.ui.SelectFileInputWidget.prototype.onDragEnterOrOver = function ( e ) { |
| 14563 |
let hasDroppableFile = false; |
| 14564 |
|
| 14565 |
const dt = e.originalEvent.dataTransfer; |
| 14566 |
|
| 14567 |
e.preventDefault(); |
| 14568 |
e.stopPropagation(); |
| 14569 |
|
| 14570 |
if ( this.isDisabled() ) { |
| 14571 |
this.$element.removeClass( [ |
| 14572 |
'oo-ui-selectFileInputWidget-canDrop', |
| 14573 |
'oo-ui-selectFileWidget-canDrop', |
| 14574 |
'oo-ui-selectFileInputWidget-cantDrop' |
| 14575 |
] ); |
| 14576 |
dt.dropEffect = 'none'; |
| 14577 |
return false; |
| 14578 |
} |
| 14579 |
|
| 14580 |
|
| 14581 |
|
| 14582 |
const itemsOrFiles = dt.items || dt.files; |
| 14583 |
const hasFiles = !!( itemsOrFiles && itemsOrFiles.length ); |
| 14584 |
if ( hasFiles ) { |
| 14585 |
if ( this.filterFiles( itemsOrFiles ).length ) { |
| 14586 |
hasDroppableFile = true; |
| 14587 |
} |
| 14588 |
|
| 14589 |
} else if ( Array.prototype.indexOf.call( OO.getProp( dt, 'types' ) || [], 'Files' ) !== -1 ) { |
| 14590 |
|
| 14591 |
|
| 14592 |
|
| 14593 |
hasDroppableFile = true; |
| 14594 |
} |
| 14595 |
|
| 14596 |
this.$element.toggleClass( 'oo-ui-selectFileInputWidget-canDrop oo-ui-selectFileWidget-canDrop', hasDroppableFile ); |
| 14597 |
this.$element.toggleClass( 'oo-ui-selectFileInputWidget-cantDrop', !hasDroppableFile && hasFiles ); |
| 14598 |
if ( !hasDroppableFile ) { |
| 14599 |
dt.dropEffect = 'none'; |
| 14600 |
} |
| 14601 |
|
| 14602 |
return false; |
| 14603 |
}; |
| 14604 |
|
| 14605 |
|
| 14606 |
|
| 14607 |
|
| 14608 |
|
| 14609 |
|
| 14610 |
|
| 14611 |
OO.ui.SelectFileInputWidget.prototype.onDragLeave = function () { |
| 14612 |
this.$element.removeClass( [ |
| 14613 |
'oo-ui-selectFileInputWidget-canDrop', |
| 14614 |
'oo-ui-selectFileWidget-canDrop', |
| 14615 |
'oo-ui-selectFileInputWidget-cantDrop' |
| 14616 |
] ); |
| 14617 |
}; |
| 14618 |
|
| 14619 |
|
| 14620 |
|
| 14621 |
|
| 14622 |
|
| 14623 |
|
| 14624 |
|
| 14625 |
|
| 14626 |
OO.ui.SelectFileInputWidget.prototype.onDrop = function ( e ) { |
| 14627 |
const dt = e.originalEvent.dataTransfer; |
| 14628 |
|
| 14629 |
e.preventDefault(); |
| 14630 |
e.stopPropagation(); |
| 14631 |
this.$element.removeClass( [ |
| 14632 |
'oo-ui-selectFileInputWidget-canDrop', |
| 14633 |
'oo-ui-selectFileWidget-canDrop', |
| 14634 |
'oo-ui-selectFileInputWidget-cantDrop' |
| 14635 |
] ); |
| 14636 |
|
| 14637 |
if ( this.isDisabled() ) { |
| 14638 |
return false; |
| 14639 |
} |
| 14640 |
|
| 14641 |
const files = this.filterFiles( dt.files || [] ); |
| 14642 |
this.setValue( files ); |
| 14643 |
|
| 14644 |
return false; |
| 14645 |
}; |
| 14646 |
|
| 14647 |
|
| 14648 |
OO.ui.SelectFileWidget = function OoUiSelectFileWidget() { |
| 14649 |
OO.ui.warnDeprecation( 'SelectFileWidget: Deprecated alias, use SelectFileInputWidget instead.' ); |
| 14650 |
OO.ui.SelectFileWidget.super.apply( this, arguments ); |
| 14651 |
}; |
| 14652 |
|
| 14653 |
OO.inheritClass( OO.ui.SelectFileWidget, OO.ui.SelectFileInputWidget ); |
| 14654 |
|
| 14655 |
}( OO ) ); |
| 14656 |
|
| 14657 |
|