| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ui.MWTransclusionOutlineParameterSelectWidget = function VeUiMWTransclusionOutlineParameterSelectWidget( config ) { |
| 21 |
|
| 22 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.super.call( this, ve.extendObject( config, { |
| 23 |
classes: [ 've-ui-mwTransclusionOutlineParameterSelectWidget' ], |
| 24 |
multiselect: true |
| 25 |
} ) ); |
| 26 |
|
| 27 |
|
| 28 |
OO.ui.mixin.TabIndexedElement.call( this, { |
| 29 |
tabIndex: this.isEmpty() ? -1 : 0 |
| 30 |
} ); |
| 31 |
ve.ui.MWAriaDescribe.call( this, config ); |
| 32 |
|
| 33 |
this.$element |
| 34 |
.on( { |
| 35 |
focus: this.bindDocumentKeyDownListener.bind( this ), |
| 36 |
blur: this.onBlur.bind( this ) |
| 37 |
} ); |
| 38 |
|
| 39 |
this.activeParameter = null; |
| 40 |
this.stickyHeaderHeight = 0; |
| 41 |
}; |
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
OO.inheritClass( ve.ui.MWTransclusionOutlineParameterSelectWidget, OO.ui.SelectWidget ); |
| 46 |
OO.mixinClass( ve.ui.MWTransclusionOutlineParameterSelectWidget, OO.ui.mixin.TabIndexedElement ); |
| 47 |
OO.mixinClass( ve.ui.MWTransclusionOutlineParameterSelectWidget, ve.ui.MWAriaDescribe ); |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.static.createItem = function ( config ) { |
| 71 |
return new ve.ui.MWTransclusionOutlineParameterWidget( config ); |
| 72 |
}; |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.addItems = function ( items, index ) { |
| 83 |
items.forEach( ( item ) => { |
| 84 |
item.connect( this, { |
| 85 |
change: [ 'onCheckboxChange', item ] |
| 86 |
} ); |
| 87 |
} ); |
| 88 |
|
| 89 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.super.prototype.addItems.call( this, items, index ); |
| 90 |
this.setTabIndex( this.isEmpty() ? -1 : 0 ); |
| 91 |
return this; |
| 92 |
}; |
| 93 |
|
| 94 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.ensureVisibilityOfFirstCheckedParameter = function () { |
| 95 |
|
| 96 |
const firstChecked = this.findSelectedItems()[ 0 ]; |
| 97 |
if ( firstChecked ) { |
| 98 |
firstChecked.ensureVisibility( this.stickyHeaderHeight ); |
| 99 |
} |
| 100 |
}; |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.setActiveParameter = function ( paramName ) { |
| 106 |
|
| 107 |
const newItem = paramName ? this.findItemFromData( paramName ) : null; |
| 108 |
|
| 109 |
this.highlightItem( newItem ); |
| 110 |
|
| 111 |
paramName = paramName || null; |
| 112 |
if ( this.activeParameter === paramName ) { |
| 113 |
return; |
| 114 |
} |
| 115 |
|
| 116 |
const currentItem = this.activeParameter ? this.findItemFromData( this.activeParameter ) : null; |
| 117 |
this.activeParameter = paramName; |
| 118 |
|
| 119 |
if ( currentItem ) { |
| 120 |
currentItem.toggleActivePageIndicator( false ); |
| 121 |
} |
| 122 |
if ( newItem ) { |
| 123 |
newItem.toggleActivePageIndicator( true ); |
| 124 |
} |
| 125 |
}; |
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.highlightItem = function ( item ) { |
| 131 |
if ( item ) { |
| 132 |
item.ensureVisibility( this.stickyHeaderHeight ); |
| 133 |
} |
| 134 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.super.prototype.highlightItem.call( this, item ); |
| 135 |
}; |
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.markParameterAsUnused = function ( paramName ) { |
| 141 |
|
| 142 |
|
| 143 |
const item = paramName ? this.findItemFromData( paramName ) : null; |
| 144 |
if ( item ) { |
| 145 |
item.setSelected( false ); |
| 146 |
|
| 147 |
if ( this.activeParameter === paramName ) { |
| 148 |
this.activeParameter = null; |
| 149 |
item.toggleActivePageIndicator( false ); |
| 150 |
} |
| 151 |
} |
| 152 |
}; |
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
|
| 159 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onCheckboxChange = function ( item, value ) { |
| 160 |
|
| 161 |
if ( item.isSelected() !== value ) { |
| 162 |
on |
| 163 |
this.chooseItem( item ); |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onFocus = function ( event ) { |
| 171 |
if ( event.target !== this.$element[ 0 ] || this.findHighlightedItem() ) { |
| 172 |
return; |
| 173 |
} |
| 174 |
|
| 175 |
let index = 0; |
| 176 |
if ( event.relatedTarget ) { |
| 177 |
const toolbarClass = 've-ui-mwTransclusionOutlineControlsWidget', |
| 178 |
|
| 179 |
selector = '.ve-ui-mwTransclusionOutlinePartWidget, .' + toolbarClass, |
| 180 |
$fromPart = $( event.relatedTarget ).closest( selector ), |
| 181 |
$toPart = $( event.target ).closest( selector ); |
| 182 |
|
| 183 |
|
| 184 |
if ( $fromPart.hasClass( toolbarClass ) || $fromPart.index() > $toPart.index() ) { |
| 185 |
index = this.getItemCount() - 1; |
| 186 |
} |
| 187 |
} |
| 188 |
this.highlightItem( this.items[ index ] ); |
| 189 |
|
| 190 |
|
| 191 |
}; |
| 192 |
|
| 193 |
|
| 194 |
|
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onMouseDown = function ( e ) { |
| 199 |
if ( e.which === OO.ui.MouseButtons.LEFT ) { |
| 200 |
const item = this.findTargetItem( e ); |
| 201 |
|
| 202 |
if ( item && item.isSelected() ) { |
| 203 |
this.emit( 'choose', item, item.isSelected() ); |
| 204 |
|
| 205 |
|
| 206 |
return false; |
| 207 |
} |
| 208 |
} |
| 209 |
|
| 210 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.super.prototype.onMouseDown.call( this, e ); |
| 211 |
}; |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onDocumentKeyDown = function ( e ) { |
| 220 |
let item; |
| 221 |
|
| 222 |
switch ( e.keyCode ) { |
| 223 |
case OO.ui.Keys.HOME: |
| 224 |
item = this.items[ 0 ]; |
| 225 |
if ( item ) { |
| 226 |
this.highlightItem( item ); |
| 227 |
} |
| 228 |
break; |
| 229 |
case OO.ui.Keys.END: |
| 230 |
item = this.items[ this.items.length - 1 ]; |
| 231 |
if ( item ) { |
| 232 |
this.highlightItem( item ); |
| 233 |
} |
| 234 |
break; |
| 235 |
case OO.ui.Keys.SPACE: |
| 236 |
item = this.findHighlightedItem(); |
| 237 |
if ( item ) { |
| 238 |
|
| 239 |
|
| 240 |
if ( item.isSelected() ) { |
| 241 |
this.unselectItem( item ); |
| 242 |
} else { |
| 243 |
this.selectItem( item ); |
| 244 |
} |
| 245 |
this.emit( 'templateParameterSpaceDown', item, item.isSelected() ); |
| 246 |
} |
| 247 |
e.preventDefault(); |
| 248 |
break; |
| 249 |
case OO.ui.Keys.ENTER: |
| 250 |
item = this.findHighlightedItem(); |
| 251 |
|
| 252 |
if ( item && item.isSelected() ) { |
| 253 |
this.emit( 'choose', item, item.isSelected() ); |
| 254 |
e.preventDefault(); |
| 255 |
|
| 256 |
|
| 257 |
return false; |
| 258 |
} |
| 259 |
break; |
| 260 |
} |
| 261 |
|
| 262 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.super.prototype.onDocumentKeyDown.call( this, e ); |
| 263 |
}; |
| 264 |
|
| 265 |
ve.ui.MWTransclusionOutlineParameterSelectWidget.prototype.onBlur = function () { |
| 266 |
this.highlightItem(); |
| 267 |
this.unbindDocumentKeyDownListener(); |
| 268 |
}; |