| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
ve.ui.MWTwoPaneTransclusionDialogLayout = function VeUiMWTwoPaneTransclusionDialogLayout( config ) { |
| 25 |
|
| 26 |
ve.ui.MWTwoPaneTransclusionDialogLayout.super.call( this, config ); |
| 27 |
|
| 28 |
|
| 29 |
this.pages = {}; |
| 30 |
this.currentPageName = null; |
| 31 |
this.stackLayout = new ve.ui.MWVerticalLayout(); |
| 32 |
this.setContentPanel( this.stackLayout ); |
| 33 |
this.sidebar = new ve.ui.MWTransclusionOutlineWidget(); |
| 34 |
this.outlinePanel = new OO.ui.PanelLayout( { expanded: this.expanded, scrollable: true } ); |
| 35 |
this.setMenuPanel( this.outlinePanel ); |
| 36 |
this.outlineControlsWidget = new ve.ui.MWTransclusionOutlineControlsWidget(); |
| 37 |
|
| 38 |
|
| 39 |
this.sidebar.connect( this, { |
| 40 |
filterPagesByName: 'onFilterPagesByName', |
| 41 |
sidebarItemSelected: 'onSidebarItemSelected' |
| 42 |
} ); |
| 43 |
|
| 44 |
this.stackLayout.$element.on( 'focusin', this.onStackLayoutFocus.bind( this ) ); |
| 45 |
|
| 46 |
|
| 47 |
this.$element.addClass( 've-ui-mwTwoPaneTransclusionDialogLayout' ); |
| 48 |
this.stackLayout.$element.addClass( 've-ui-mwTwoPaneTransclusionDialogLayout-stackLayout' ); |
| 49 |
this.outlinePanel.$element |
| 50 |
.addClass( 've-ui-mwTwoPaneTransclusionDialogLayout-outlinePanel' ) |
| 51 |
.append( |
| 52 |
$( '<div>' ).addClass( 've-ui-mwTwoPaneTransclusionDialogLayout-sidebar-container' ) |
| 53 |
.append( this.sidebar.$element ), |
| 54 |
this.outlineControlsWidget.$element |
| 55 |
); |
| 56 |
}; |
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
OO.inheritClass( ve.ui.MWTwoPaneTransclusionDialogLayout, OO.ui.MenuLayout ); |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onFilterPagesByName = function ( visibility ) { |
| 69 |
this.currentPageName = null; |
| 70 |
for ( const pageName in visibility ) { |
| 71 |
const page = this.getPage( pageName ); |
| 72 |
if ( page ) { |
| 73 |
page.toggle( visibility[ pageName ] ); |
| 74 |
} |
| 75 |
} |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onReplacePart = function ( removed, added, newPosition ) { |
| 84 |
this.sidebar.onReplacePart( removed, added, newPosition ); |
| 85 |
|
| 86 |
const keys = Object.keys( this.pages ), |
| 87 |
isMultiPart = keys.length > 1, |
| 88 |
isLastPlaceholder = keys.length === 1 && |
| 89 |
this.pages[ keys[ 0 ] ] instanceof ve.ui.MWTemplatePlaceholderPage; |
| 90 |
|
| 91 |
|
| 92 |
this.outlineControlsWidget.removeButton.toggle( !isLastPlaceholder ); |
| 93 |
|
| 94 |
if ( isMultiPart ) { |
| 95 |
|
| 96 |
this.outlineControlsWidget.toggle( true ); |
| 97 |
} |
| 98 |
}; |
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onStackLayoutFocus = function ( e ) { |
| 105 |
|
| 106 |
const $target = $( e.target ).closest( '.oo-ui-pageLayout' ); |
| 107 |
for ( const name in this.pages ) { |
| 108 |
if ( this.pages[ name ].$element[ 0 ] === $target[ 0 ] ) { |
| 109 |
this.setPage( name ); |
| 110 |
break; |
| 111 |
} |
| 112 |
} |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.focus = function () { |
| 121 |
const page = this.pages[ this.currentPageName ]; |
| 122 |
if ( !page ) { |
| 123 |
return; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
if ( page.$element[ 0 ].offsetParent !== null && |
| 128 |
!OO.ui.contains( page.$element[ 0 ], this.getElementDocument().activeElement, true ) |
| 129 |
) { |
| 130 |
page.focus(); |
| 131 |
} |
| 132 |
}; |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.focusPart = function ( pageName ) { |
| 138 |
this.setPage( pageName ); |
| 139 |
this.focus(); |
| 140 |
}; |
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.onSidebarItemSelected = function ( pageName, soft ) { |
| 149 |
this.setPage( pageName ); |
| 150 |
|
| 151 |
const page = this.pages[ pageName ]; |
| 152 |
if ( page ) { |
| 153 |
|
| 154 |
|
| 155 |
page.scrollElementIntoView( { alignToTop: true, padding: { top: 20 } } ); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
|
| 160 |
if ( !soft && !OO.ui.isMobile() ) { |
| 161 |
this.focus(); |
| 162 |
} |
| 163 |
}; |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.toggleOutline = function ( show ) { |
| 169 |
this.toggleMenu( show ); |
| 170 |
if ( show ) { |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
setTimeout( () => { |
| 175 |
OO.ui.Element.static.reconsiderScrollbars( this.outlinePanel.$element[ 0 ] ); |
| 176 |
}, OO.ui.theme.getDialogTransitionDuration() ); |
| 177 |
} |
| 178 |
}; |
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getOutlineControls = function () { |
| 184 |
return this.outlineControlsWidget; |
| 185 |
}; |
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getPagesOrdered = function () { |
| 193 |
return this.stackLayout.getItems(); |
| 194 |
}; |
| 195 |
|
| 196 |
|
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getPage = function ( name ) { |
| 201 |
return this.pages[ name ]; |
| 202 |
}; |
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getCurrentPage = function () { |
| 208 |
return this.pages[ this.currentPageName ]; |
| 209 |
}; |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getSelectedTopLevelPartId = function () { |
| 216 |
const page = this.getCurrentPage(), |
| 217 |
isParameter = page instanceof ve.ui.MWParameterPage || page instanceof ve.ui.MWAddParameterPage; |
| 218 |
return page && !isParameter ? page.getName() : null; |
| 219 |
}; |
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.getTopLevelPartIdForSelection = function () { |
| 227 |
return this.currentPageName ? this.currentPageName.split( '/', 1 )[ 0 ] : null; |
| 228 |
}; |
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.addPages = function ( pages, index ) { |
| 238 |
const stackLayoutPages = this.stackLayout.getItems(); |
| 239 |
|
| 240 |
|
| 241 |
const remove = []; |
| 242 |
for ( let i = 0; i < pages.length; i++ ) { |
| 243 |
const page = pages[ i ]; |
| 244 |
const name = page.getName(); |
| 245 |
|
| 246 |
if ( Object.prototype.hasOwnProperty.call( this.pages, name ) ) { |
| 247 |
|
| 248 |
const currentIndex = stackLayoutPages.indexOf( this.pages[ name ] ); |
| 249 |
if ( currentIndex !== -1 && currentIndex + 1 < index ) { |
| 250 |
index--; |
| 251 |
} |
| 252 |
remove.push( name ); |
| 253 |
} |
| 254 |
} |
| 255 |
if ( remove.length ) { |
| 256 |
this.removePages( remove ); |
| 257 |
} |
| 258 |
|
| 259 |
|
| 260 |
for ( let i = 0; i < pages.length; i++ ) { |
| 261 |
const page = pages[ i ]; |
| 262 |
const name = page.getName(); |
| 263 |
this.pages[ name ] = page; |
| 264 |
} |
| 265 |
|
| 266 |
this.stackLayout.addItems( pages, index ); |
| 267 |
}; |
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.removePages = function ( pagesNamesToRemove ) { |
| 273 |
const pagesToRemove = [], |
| 274 |
isCurrentParameter = this.pages[ this.currentPageName ] instanceof ve.ui.MWParameterPage; |
| 275 |
let isCurrentPageRemoved = false, |
| 276 |
prevSelectionCandidate, nextSelectionCandidate; |
| 277 |
|
| 278 |
this.stackLayout.getItems().forEach( ( page ) => { |
| 279 |
const pageName = page.getName(); |
| 280 |
|
| 281 |
if ( pagesNamesToRemove.indexOf( pageName ) !== -1 ) { |
| 282 |
pagesToRemove.push( page ); |
| 283 |
delete this.pages[ pageName ]; |
| 284 |
if ( this.currentPageName === pageName ) { |
| 285 |
this.currentPageName = null; |
| 286 |
isCurrentPageRemoved = true; |
| 287 |
} |
| 288 |
return; |
| 289 |
} |
| 290 |
|
| 291 |
|
| 292 |
if ( pageName.indexOf( '/' ) === -1 ) { |
| 293 |
if ( !isCurrentPageRemoved ) { |
| 294 |
|
| 295 |
prevSelectionCandidate = pageName; |
| 296 |
} else if ( !nextSelectionCandidate ) { |
| 297 |
|
| 298 |
nextSelectionCandidate = pageName; |
| 299 |
} |
| 300 |
} |
| 301 |
} ); |
| 302 |
|
| 303 |
this.stackLayout.removeItems( pagesToRemove ); |
| 304 |
if ( isCurrentPageRemoved && !isCurrentParameter ) { |
| 305 |
this.setPage( nextSelectionCandidate || prevSelectionCandidate ); |
| 306 |
} |
| 307 |
}; |
| 308 |
|
| 309 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.clearPages = function () { |
| 310 |
this.pages = {}; |
| 311 |
this.currentPageName = null; |
| 312 |
this.sidebar.clear(); |
| 313 |
this.stackLayout.clearItems(); |
| 314 |
}; |
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.setPage = function ( name ) { |
| 322 |
const page = this.pages[ name ]; |
| 323 |
|
| 324 |
if ( page && name === this.currentPageName ) { |
| 325 |
return; |
| 326 |
} |
| 327 |
|
| 328 |
const previousPage = this.currentPageName ? this.pages[ this.currentPageName ] : null; |
| 329 |
this.currentPageName = name; |
| 330 |
|
| 331 |
if ( previousPage ) { |
| 332 |
|
| 333 |
|
| 334 |
|
| 335 |
if ( !OO.ui.isMobile() && |
| 336 |
( !page || OO.ui.findFocusable( page.$element ).length !== 0 ) |
| 337 |
) { |
| 338 |
const $focused = previousPage.$element.find( ':focus' ); |
| 339 |
if ( $focused.length ) { |
| 340 |
$focused[ 0 ].blur(); |
| 341 |
} |
| 342 |
} |
| 343 |
} |
| 344 |
|
| 345 |
this.sidebar.setSelectionByPageName( name ); |
| 346 |
this.refreshControls(); |
| 347 |
}; |
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
ve.ui.MWTwoPaneTransclusionDialogLayout.prototype.refreshControls = function () { |
| 353 |
const partId = this.getSelectedTopLevelPartId(), |
| 354 |
canBeDeleted = !!partId; |
| 355 |
|
| 356 |
let canMoveUp, canMoveDown = false; |
| 357 |
if ( partId ) { |
| 358 |
const pages = this.stackLayout.getItems(), |
| 359 |
page = this.getPage( partId ), |
| 360 |
index = pages.indexOf( page ); |
| 361 |
canMoveUp = index > 0; |
| 362 |
|
| 363 |
for ( let i = index + 1; i < pages.length; i++ ) { |
| 364 |
if ( !( pages[ i ] instanceof ve.ui.MWParameterPage || pages[ i ] instanceof ve.ui.MWAddParameterPage ) ) { |
| 365 |
canMoveDown = true; |
| 366 |
break; |
| 367 |
} |
| 368 |
} |
| 369 |
} |
| 370 |
|
| 371 |
this.outlineControlsWidget.setButtonsEnabled( { |
| 372 |
canMoveUp: canMoveUp, |
| 373 |
canMoveDown: canMoveDown, |
| 374 |
canBeDeleted: canBeDeleted |
| 375 |
} ); |
| 376 |
}; |