| 1 |
( function () { |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
mw.echo.ui.MenuItemWidget = function MwEchoUiMenuItemWidget( config ) { |
| 20 |
config = config || {}; |
| 21 |
|
| 22 |
this.dynamic = config.type === 'dynamic-action'; |
| 23 |
|
| 24 |
|
| 25 |
this.isLink = config.url && !this.isDynamicAction(); |
| 26 |
|
| 27 |
|
| 28 |
mw.echo.ui.MenuItemWidget.super.call( this, Object.assign( { framed: false }, config ) ); |
| 29 |
|
| 30 |
|
| 31 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 32 |
|
| 33 |
this.prioritized = !!config.prioritized; |
| 34 |
this.messages = this.isDynamicAction() ? |
| 35 |
config.actionData.messages : |
| 36 |
{}; |
| 37 |
|
| 38 |
this.actionData = config.actionData || {}; |
| 39 |
|
| 40 |
|
| 41 |
this.descriptionLabel = new OO.ui.LabelWidget( { |
| 42 |
classes: [ 'mw-echo-ui-menuItemWidget-description' ], |
| 43 |
label: config.description || '' |
| 44 |
} ); |
| 45 |
this.descriptionLabel.toggle( !this.prioritized && config.description ); |
| 46 |
|
| 47 |
this.$label.append( this.descriptionLabel.$element ); |
| 48 |
|
| 49 |
|
| 50 |
this.$element |
| 51 |
.addClass( 'mw-echo-ui-menuItemWidget' ) |
| 52 |
.toggleClass( 'mw-echo-ui-menuItemWidget-prioritized', this.prioritized ) |
| 53 |
.toggleClass( 'mw-echo-ui-menuItemWidget-dynamic-action', this.isDynamicAction() ); |
| 54 |
|
| 55 |
if ( this.isLink ) { |
| 56 |
this.$element.attr( { |
| 57 |
href: config.url, |
| 58 |
title: config.tooltip |
| 59 |
} ); |
| 60 |
} |
| 61 |
}; |
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
OO.inheritClass( mw.echo.ui.MenuItemWidget, OO.ui.ButtonOptionWidget ); |
| 66 |
OO.mixinClass( mw.echo.ui.MenuItemWidget, OO.ui.mixin.PendingElement ); |
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
mw.echo.ui.MenuItemWidget.static.highlightable = false; |
| 71 |
mw.echo.ui.MenuItemWidget.static.pressable = false; |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
mw.echo.ui.MenuItemWidget.prototype.getTagName = function () { |
| 76 |
return this.isLink ? 'a' : 'div'; |
| 77 |
}; |
| 78 |
|
| 79 |
mw.echo.ui.MenuItemWidget.prototype.onClick = function ( e ) { |
| 80 |
|
| 81 |
|
| 82 |
e.stopPropagation(); |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
if ( !this.isLink ) { |
| 88 |
e.preventDefault(); |
| 89 |
} |
| 90 |
|
| 91 |
return mw.echo.ui.MenuItemWidget.super.prototype.onClick.apply( this, arguments ); |
| 92 |
}; |
| 93 |
|
| 94 |
mw.echo.ui.MenuItemWidget.prototype.isSelectable = function () { |
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
return !this.isLink && mw.echo.ui.MenuItemWidget.super.prototype.isSelectable.apply( this, arguments ); |
| 99 |
}; |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
mw.echo.ui.MenuItemWidget.prototype.isPrioritized = function () { |
| 107 |
return this.prioritized; |
| 108 |
}; |
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
mw.echo.ui.MenuItemWidget.prototype.getConfirmationMessages = function () { |
| 127 |
return this.messages.confirmation; |
| 128 |
}; |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|
| 134 |
|
| 135 |
mw.echo.ui.MenuItemWidget.prototype.getActionData = function () { |
| 136 |
return this.actionData; |
| 137 |
}; |
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
mw.echo.ui.MenuItemWidget.prototype.isDynamicAction = function () { |
| 145 |
return this.dynamic; |
| 146 |
}; |
| 147 |
}() ); |