| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
ve.ui.MWTransclusionOutlineWidget = function VeUiMWTransclusionOutlineWidget() { |
| 13 |
|
| 14 |
ve.ui.MWTransclusionOutlineWidget.super.call( this, { |
| 15 |
classes: [ 've-ui-mwTransclusionOutlineWidget' ] |
| 16 |
} ); |
| 17 |
|
| 18 |
|
| 19 |
this.partWidgets = {}; |
| 20 |
}; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
OO.inheritClass( ve.ui.MWTransclusionOutlineWidget, OO.ui.Widget ); |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
ve.ui.MWTransclusionOutlineWidget.prototype.onReplacePart = function ( removed, added, newPosition ) { |
| 51 |
if ( removed ) { |
| 52 |
this.removePartWidget( removed ); |
| 53 |
} |
| 54 |
if ( added ) { |
| 55 |
this.addPartWidget( added, newPosition, removed ); |
| 56 |
} |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ui.MWTransclusionOutlineWidget.prototype.onTransclusionPartSoftSelected = function ( pageName ) { |
| 66 |
this.emit( 'sidebarItemSelected', pageName, true ); |
| 67 |
}; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
ve.ui.MWTransclusionOutlineWidget.prototype.removePartWidget = function ( part ) { |
| 74 |
const id = part.getId(); |
| 75 |
if ( id in this.partWidgets ) { |
| 76 |
this.partWidgets[ id ] |
| 77 |
.disconnect( this ) |
| 78 |
.$element.remove(); |
| 79 |
delete this.partWidgets[ id ]; |
| 80 |
} |
| 81 |
}; |
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
ve.ui.MWTransclusionOutlineWidget.prototype.addPartWidget = function ( part, newPosition, removed ) { |
| 91 |
const keys = Object.keys( this.partWidgets ), |
| 92 |
onlyPart = keys.length === 1 && this.partWidgets[ keys[ 0 ] ]; |
| 93 |
if ( onlyPart instanceof ve.ui.MWTransclusionOutlineTemplateWidget ) { |
| 94 |
|
| 95 |
onlyPart.recalculateStickyHeaderHeight(); |
| 96 |
} |
| 97 |
|
| 98 |
let widget; |
| 99 |
if ( part instanceof ve.dm.MWTemplateModel ) { |
| 100 |
widget = new ve.ui.MWTransclusionOutlineTemplateWidget( part, removed instanceof ve.dm.MWTemplatePlaceholderModel ); |
| 101 |
|
| 102 |
widget.connect( this, { |
| 103 |
filterParametersById: 'onFilterParametersByName' |
| 104 |
} ); |
| 105 |
} else if ( part instanceof ve.dm.MWTemplatePlaceholderModel ) { |
| 106 |
widget = new ve.ui.MWTransclusionOutlinePlaceholderWidget( part ); |
| 107 |
} else if ( part instanceof ve.dm.MWTransclusionContentModel ) { |
| 108 |
widget = new ve.ui.MWTransclusionOutlineWikitextWidget( part ); |
| 109 |
} |
| 110 |
|
| 111 |
widget.connect( this, { |
| 112 |
transclusionPartSoftSelected: 'onTransclusionPartSoftSelected', |
| 113 |
transclusionOutlineItemSelected: [ 'emit', 'sidebarItemSelected' ] |
| 114 |
} ); |
| 115 |
|
| 116 |
this.partWidgets[ part.getId() ] = widget; |
| 117 |
if ( typeof newPosition === 'number' && newPosition < this.$element.children().length ) { |
| 118 |
this.$element.children().eq( newPosition ).before( widget.$element ); |
| 119 |
} else { |
| 120 |
this.$element.append( widget.$element ); |
| 121 |
} |
| 122 |
|
| 123 |
if ( widget instanceof ve.ui.MWTransclusionOutlineTemplateWidget ) { |
| 124 |
|
| 125 |
widget.recalculateStickyHeaderHeight(); |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
ve.ui.MWTransclusionOutlineWidget.prototype.hideAllUnusedParameters = function () { |
| 130 |
for ( const id in this.partWidgets ) { |
| 131 |
const partWidget = this.partWidgets[ id ]; |
| 132 |
if ( partWidget instanceof ve.ui.MWTransclusionOutlineTemplateWidget && |
| 133 |
partWidget.toggleUnusedWidget |
| 134 |
) { |
| 135 |
partWidget.toggleUnusedWidget.toggleUnusedParameters( false ); |
| 136 |
} |
| 137 |
} |
| 138 |
}; |
| 139 |
|
| 140 |
ve.ui.MWTransclusionOutlineWidget.prototype.initializeAllStickyHeaderHeights = function () { |
| 141 |
for ( const id in this.partWidgets ) { |
| 142 |
const partWidget = this.partWidgets[ id ]; |
| 143 |
if ( partWidget instanceof ve.ui.MWTransclusionOutlineTemplateWidget ) { |
| 144 |
partWidget.recalculateStickyHeaderHeight(); |
| 145 |
} |
| 146 |
} |
| 147 |
}; |
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
ve.ui.MWTransclusionOutlineWidget.prototype.setSelectionByPageName = function ( pageName ) { |
| 155 |
const selectedPartId = pageName ? pageName.split( '/', 1 )[ 0 ] : null, |
| 156 |
isParameter = pageName ? pageName.length > selectedPartId.length : false; |
| 157 |
|
| 158 |
for ( const partId in this.partWidgets ) { |
| 159 |
const partWidget = this.partWidgets[ partId ], |
| 160 |
selected = partId === pageName; |
| 161 |
|
| 162 |
partWidget.setSelected( selected ); |
| 163 |
if ( selected && !isParameter ) { |
| 164 |
partWidget.scrollElementIntoView(); |
| 165 |
} |
| 166 |
|
| 167 |
if ( partWidget instanceof ve.ui.MWTransclusionOutlineTemplateWidget ) { |
| 168 |
const selectedParamName = ( partId === selectedPartId && isParameter ) ? |
| 169 |
pageName.slice( selectedPartId.length + 1 ) : null; |
| 170 |
partWidget.setParameter( selectedParamName ); |
| 171 |
} |
| 172 |
} |
| 173 |
}; |
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
ve.ui.MWTransclusionOutlineWidget.prototype.toggleHasValueByPageName = function ( pageName, hasValue ) { |
| 180 |
const idParts = pageName.split( '/', 2 ), |
| 181 |
templatePartWidget = this.partWidgets[ idParts[ 0 ] ]; |
| 182 |
|
| 183 |
templatePartWidget.toggleHasValue( idParts[ 1 ], hasValue ); |
| 184 |
}; |
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
|
| 194 |
ve.ui.MWTransclusionOutlineWidget.prototype.findPartIdContainingElement = function ( element ) { |
| 195 |
if ( element ) { |
| 196 |
for ( const id in this.partWidgets ) { |
| 197 |
const part = this.partWidgets[ id ]; |
| 198 |
if ( $.contains( part.$element[ 0 ], element ) ) { |
| 199 |
return id; |
| 200 |
} |
| 201 |
} |
| 202 |
} |
| 203 |
}; |
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
ve.ui.MWTransclusionOutlineWidget.prototype.clear = function () { |
| 209 |
for ( const id in this.partWidgets ) { |
| 210 |
this.partWidgets[ id ] |
| 211 |
.disconnect( this ) |
| 212 |
.$element.remove(); |
| 213 |
} |
| 214 |
this.partWidgets = {}; |
| 215 |
}; |
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
ve.ui.MWTransclusionOutlineWidget.prototype.onFilterParametersByName = function ( visibility ) { |
| 223 |
this.emit( 'filterPagesByName', visibility ); |
| 224 |
this.setSelectionByPageName(); |
| 225 |
}; |