| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
ve.ui.MWTransclusionContextItem = function VeUiMWTransclusionContextItem() { |
| 19 |
|
| 20 |
ve.ui.MWTransclusionContextItem.super.apply( this, arguments ); |
| 21 |
|
| 22 |
|
| 23 |
this.$element.addClass( 've-ui-mwTransclusionContextItem' ); |
| 24 |
if ( !this.model.isSingleTemplate() ) { |
| 25 |
this.setLabel( ve.msg( 'visualeditor-dialog-transclusion-title-edit-transclusion' ) ); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
OO.inheritClass( ve.ui.MWTransclusionContextItem, ve.ui.LinearContextItem ); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
ve.ui.MWTransclusionContextItem.static.name = 'transclusion'; |
| 36 |
|
| 37 |
ve.ui.MWTransclusionContextItem.static.icon = 'puzzle'; |
| 38 |
|
| 39 |
ve.ui.MWTransclusionContextItem.static.label = |
| 40 |
OO.ui.deferMsg( 'visualeditor-dialogbutton-template-tooltip' ); |
| 41 |
|
| 42 |
ve.ui.MWTransclusionContextItem.static.modelClasses = [ ve.dm.MWTransclusionNode ]; |
| 43 |
|
| 44 |
ve.ui.MWTransclusionContextItem.static.commandName = 'transclusion'; |
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
ve.ui.MWTransclusionContextItem.static.template = null; |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
ve.ui.MWTransclusionContextItem.static.isCompatibleWith = |
| 62 |
ve.ui.MWTransclusionDialogTool.static.isCompatibleWith; |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
ve.ui.MWTransclusionContextItem.prototype.getDescription = function () { |
| 70 |
|
| 71 |
const nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name ); |
| 72 |
return ve.msg( |
| 73 |
'visualeditor-dialog-transclusion-contextitem-description', |
| 74 |
nodeClass.static.getDescription( this.model ), |
| 75 |
this.model.getPartsList().length |
| 76 |
); |
| 77 |
}; |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
ve.ui.MWTransclusionContextItem.prototype.renderBody = function () { |
| 83 |
const nodeClass = ve.ce.nodeFactory.lookup( this.model.constructor.static.name ); |
| 84 |
|
| 85 |
this.$body.append( ve.htmlMsg( |
| 86 |
'visualeditor-dialog-transclusion-contextitem-description', |
| 87 |
nodeClass.static.getDescriptionDom( this.model ), |
| 88 |
this.model.getPartsList().length |
| 89 |
) ); |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.MWTransclusionContextItem.prototype.onEditButtonClick = function () { |
| 96 |
const surfaceModel = this.context.getSurface().getModel(), |
| 97 |
selection = surfaceModel.getSelection(); |
| 98 |
|
| 99 |
if ( selection instanceof ve.dm.TableSelection ) { |
| 100 |
surfaceModel.setLinearSelection( selection.getOuterRanges( |
| 101 |
surfaceModel.getDocument() |
| 102 |
)[ 0 ] ); |
| 103 |
} |
| 104 |
|
| 105 |
ve.ui.MWTransclusionContextItem.super.prototype.onEditButtonClick.apply( this, arguments ); |
| 106 |
|
| 107 |
this.context.getSurface().getDialogs().once( 'opening', ( win, opening ) => { |
| 108 |
opening.then( () => { |
| 109 |
this.toggleLoadingVisualization( false ); |
| 110 |
} ); |
| 111 |
} ); |
| 112 |
this.toggleLoadingVisualization( true ); |
| 113 |
}; |
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
ve.ui.MWTransclusionContextItem.prototype.toggleLoadingVisualization = function ( isLoading ) { |
| 120 |
this.editButton.setDisabled( isLoading ); |
| 121 |
if ( isLoading ) { |
| 122 |
this.originalEditButtonLabel = this.editButton.getLabel(); |
| 123 |
this.editButton.setLabel( ve.msg( 'visualeditor-dialog-transclusion-contextitem-loading' ) ); |
| 124 |
} else if ( this.originalEditButtonLabel ) { |
| 125 |
this.editButton.setLabel( this.originalEditButtonLabel ); |
| 126 |
} |
| 127 |
}; |
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.ui.contextItemFactory.register( ve.ui.MWTransclusionContextItem ); |