| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
ve.ui.MobileActionsContextItem = function VeUiMobileActionsContextItem( context, model, config ) { |
| 21 |
|
| 22 |
ve.ui.MobileActionsContextItem.super.call( this, context, model, config ); |
| 23 |
|
| 24 |
this.copyButton = new OO.ui.ButtonWidget( { |
| 25 |
framed: false, |
| 26 |
label: ve.msg( 'visualeditor-clipboard-copy' ), |
| 27 |
icon: 'copy' |
| 28 |
} ); |
| 29 |
this.deleteButton = new OO.ui.ButtonWidget( { |
| 30 |
framed: false, |
| 31 |
label: ve.msg( 'visualeditor-contextitemwidget-label-remove' ), |
| 32 |
icon: 'trash', |
| 33 |
flags: [ 'destructive' ] |
| 34 |
} ); |
| 35 |
|
| 36 |
this.$head.append( this.copyButton.$element ); |
| 37 |
if ( !this.isReadOnly() ) { |
| 38 |
this.$head.append( this.deleteButton.$element ); |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
this.copyButton.connect( this, { click: 'onCopyButtonClick' } ); |
| 43 |
this.deleteButton.connect( this, { click: 'onDeleteButtonClick' } ); |
| 44 |
|
| 45 |
|
| 46 |
this.$element.addClass( 've-ui-mobileActionsContextItem' ); |
| 47 |
}; |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
OO.inheritClass( ve.ui.MobileActionsContextItem, ve.ui.LinearContextItem ); |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
ve.ui.MobileActionsContextItem.static.name = 'mobileActions'; |
| 56 |
|
| 57 |
ve.ui.MobileActionsContextItem.static.editable = false; |
| 58 |
|
| 59 |
|
| 60 |
ve.ui.MobileActionsContextItem.static.sortOrder = 1; |
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
ve.ui.MobileActionsContextItem.static.isCompatibleWith = function ( model ) { |
| 66 |
return OO.ui.isMobile() && model instanceof ve.dm.Node && ( |
| 67 |
model.isFocusable() || model.isCellable() |
| 68 |
); |
| 69 |
}; |
| 70 |
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
ve.ui.MobileActionsContextItem.prototype.onCopyButtonClick = function () { |
| 77 |
const surfaceView = this.context.getSurface().getView(); |
| 78 |
|
| 79 |
surfaceView.activate(); |
| 80 |
|
| 81 |
surfaceView.preparePasteTargetForCopy( true ); |
| 82 |
|
| 83 |
let copied; |
| 84 |
try { |
| 85 |
copied = document.execCommand( 'copy' ); |
| 86 |
} catch ( e ) { |
| 87 |
copied = false; |
| 88 |
} |
| 89 |
|
| 90 |
ve.init.platform.notify( ve.msg( copied ? 'visualeditor-clipboard-copy-success' : 'visualeditor-clipboard-copy-fail' ) ); |
| 91 |
|
| 92 |
|
| 93 |
surfaceView.preparePasteTargetForCopy(); |
| 94 |
if ( OO.ui.isMobile() ) { |
| 95 |
|
| 96 |
|
| 97 |
document.activeElement.blur(); |
| 98 |
} |
| 99 |
|
| 100 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'context-copy' } ); |
| 101 |
}; |
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
ve.ui.MobileActionsContextItem.prototype.onDeleteButtonClick = function () { |
| 109 |
const surface = this.context.getSurface(); |
| 110 |
const command = surface.commandRegistry.lookup( 'backspace' ); |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
if ( command ) { |
| 116 |
command.execute( surface, undefined, 'context' ); |
| 117 |
this.emit( 'command' ); |
| 118 |
ve.track( 'activity.' + this.constructor.static.name, { action: 'context-delete' } ); |
| 119 |
} |
| 120 |
}; |
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
ve.ui.contextItemFactory.register( ve.ui.MobileActionsContextItem ); |