| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
ve.ui.LinearContextItem = function VeUiLinearContextItem( context, model, config ) { |
| 20 |
config = config || {}; |
| 21 |
|
| 22 |
|
| 23 |
ve.ui.LinearContextItem.super.apply( this, arguments ); |
| 24 |
|
| 25 |
|
| 26 |
OO.ui.mixin.PendingElement.call( this, config ); |
| 27 |
|
| 28 |
|
| 29 |
this.$head = $( '<div>' ); |
| 30 |
this.$title = $( '<div>' ); |
| 31 |
this.$actions = $( '<div>' ); |
| 32 |
this.$body = $( '<div>' ); |
| 33 |
|
| 34 |
this.icon = new OO.ui.IconWidget( { icon: config.icon || this.constructor.static.icon } ); |
| 35 |
this.label = new OO.ui.LabelWidget( { label: config.label || this.constructor.static.label } ); |
| 36 |
this.actionButtons = new OO.ui.ButtonGroupWidget(); |
| 37 |
|
| 38 |
if ( this.context.isMobile() ) { |
| 39 |
this.editButton = new OO.ui.ButtonWidget( { |
| 40 |
framed: false, |
| 41 |
label: ve.msg( this.isReadOnly() ? 'visualeditor-contextitemwidget-label-view' : 'visualeditor-contextitemwidget-label-secondary' ), |
| 42 |
invisibleLabel: true, |
| 43 |
icon: this.isReadOnly() ? 'eye' : 'edit', |
| 44 |
flags: [ 'progressive' ] |
| 45 |
} ); |
| 46 |
this.$foot = $( '<div>' ); |
| 47 |
this.$bodyAction = $( '<div>' ); |
| 48 |
} else { |
| 49 |
|
| 50 |
this.editButton = new OO.ui.ButtonWidget( { |
| 51 |
label: ve.msg( this.isReadOnly() ? 'visualeditor-contextitemwidget-label-view' : 'visualeditor-contextitemwidget-label-secondary' ), |
| 52 |
flags: [ 'progressive' ] |
| 53 |
} ); |
| 54 |
} |
| 55 |
if ( this.isEditable() ) { |
| 56 |
this.actionButtons.addItems( [ this.editButton ] ); |
| 57 |
} |
| 58 |
|
| 59 |
|
| 60 |
this.editButton.connect( this, { click: 'onEditButtonClick' } ); |
| 61 |
|
| 62 |
|
| 63 |
this.$title |
| 64 |
.addClass( 've-ui-linearContextItem-title' ) |
| 65 |
.append( this.icon.$element, this.label.$element ); |
| 66 |
this.$actions |
| 67 |
.addClass( 've-ui-linearContextItem-actions' ) |
| 68 |
.append( this.actionButtons.$element ); |
| 69 |
this.$head |
| 70 |
.addClass( 've-ui-linearContextItem-head' ) |
| 71 |
.append( this.$title, this.$actions ); |
| 72 |
this.$body.addClass( 've-ui-linearContextItem-body' ); |
| 73 |
this.$element |
| 74 |
.addClass( 've-ui-linearContextItem' ) |
| 75 |
.append( this.$head, this.$body ); |
| 76 |
|
| 77 |
if ( this.context.isMobile() ) { |
| 78 |
this.$foot.addClass( 've-ui-linearContextItem-foot' ); |
| 79 |
this.$bodyAction.addClass( 've-ui-linearContextItem-body-action' ).append( this.$body, this.$actions ); |
| 80 |
this.$element.append( |
| 81 |
this.$head, |
| 82 |
$( '<div>' ).addClass( 've-ui-linearContextItem-body-action-wrapper' ).append( this.$bodyAction ), |
| 83 |
this.$foot |
| 84 |
); |
| 85 |
} |
| 86 |
}; |
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
OO.inheritClass( ve.ui.LinearContextItem, ve.ui.ContextItem ); |
| 91 |
OO.mixinClass( ve.ui.ContextItem, OO.ui.mixin.PendingElement ); |
| 92 |
|
| 93 |
|
| 94 |
|
| 95 |
ve.ui.LinearContextItem.static.editable = true; |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
ve.ui.LinearContextItem.static.embeddable = true; |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
ve.ui.LinearContextItem.prototype.onEditButtonClick = function () { |
| 118 |
const command = this.getCommand(); |
| 119 |
|
| 120 |
if ( command ) { |
| 121 |
command.execute( this.context.getSurface(), undefined, 'context' ); |
| 122 |
this.emit( 'command' ); |
| 123 |
} |
| 124 |
}; |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
ve.ui.LinearContextItem.prototype.isEditable = function () { |
| 132 |
return this.constructor.static.editable && ( !this.model || this.model.isEditable() ); |
| 133 |
}; |
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
ve.ui.LinearContextItem.prototype.getDescription = function () { |
| 142 |
return ''; |
| 143 |
}; |
| 144 |
|
| 145 |
ve.ui.LinearContextItem.prototype.setIcon = function ( icon ) { |
| 146 |
return this.icon.setIcon( icon ); |
| 147 |
}; |
| 148 |
|
| 149 |
ve.ui.LinearContextItem.prototype.setLabel = function ( label ) { |
| 150 |
return this.label.setLabel( label ); |
| 151 |
}; |
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
|
| 158 |
ve.ui.LinearContextItem.prototype.renderBody = function () { |
| 159 |
this.$body.text( this.getDescription() ); |
| 160 |
}; |
| 161 |
|
| 162 |
|
| 163 |
|
| 164 |
|
| 165 |
ve.ui.LinearContextItem.prototype.setup = function ( refreshing ) { |
| 166 |
this.renderBody(); |
| 167 |
|
| 168 |
const isEmpty = this.$body.is( ':empty' ); |
| 169 |
if ( isEmpty && this.context.isMobile() ) { |
| 170 |
if ( this.isEditable() ) { |
| 171 |
this.$head.append( this.editButton.$element ); |
| 172 |
} |
| 173 |
} |
| 174 |
this.$element.toggleClass( 've-ui-linearContextItem-empty', isEmpty ); |
| 175 |
|
| 176 |
if ( !refreshing ) { |
| 177 |
|
| 178 |
|
| 179 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'context-show' } ); |
| 180 |
} |
| 181 |
|
| 182 |
return this; |
| 183 |
}; |
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
ve.ui.LinearContextItem.prototype.teardown = function () { |
| 189 |
this.$body.empty(); |
| 190 |
return this; |
| 191 |
}; |