| 1 | /*! |
| 2 | * MediaWiki Widgets - CopyTextLayout class. |
| 3 | * |
| 4 | * @copyright 2011-2015 MediaWiki Widgets Team and others; see AUTHORS.txt |
| 5 | * @license The MIT License (MIT); see LICENSE.txt |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * @classdesc Extends CopyTextLayout with MediaWiki notifications. |
| 10 | * |
| 11 | * @class |
| 12 | * @extends OO.ui.CopyTextLayout |
| 13 | * |
| 14 | * @constructor |
| 15 | * @description Create an instance of `mw.widgets.CopyTextLayout`. |
| 16 | * @param {Object} [config] Configuration options |
| 17 | * @param {string} [config.successMessage] Success message, |
| 18 | * defaults to the {@link mw.Message} 'mw-widgets-copytextlayout-copy-success'. |
| 19 | * @param {string} [config.failMessage] Failure message, |
| 20 | * defaults to the {@link mw.Message} 'mw-widgets-copytextlayout-copy-fail'. |
| 21 | */ |
| 22 | mw.widgets.CopyTextLayout = function MwWidgetsCopyTextLayout( config ) { |
| 23 | // Parent constructor |
| 24 | mw.widgets.CopyTextLayout.super.apply( this, arguments ); |
| 25 | |
| 26 | this.successMessage = config.successMessage || mw.msg( 'mw-widgets-copytextlayout-copy-success' ); |
| 27 | this.failMessage = config.failMessage || mw.msg( 'mw-widgets-copytextlayout-copy-fail' ); |
| 28 | |
| 29 | this.connect( this, { copy: 'onMwCopy' } ); |
| 30 | }; |
| 31 | |
| 32 | /* Inheritence */ |
| 33 | |
| 34 | OO.inheritClass( mw.widgets.CopyTextLayout, OO.ui.CopyTextLayout ); |
| 35 | |
| 36 | /* Methods */ |
| 37 | |
| 38 | /** |
| 39 | * Handle copy events. |
| 40 | * |
| 41 | * @param {boolean} copied |
| 42 | */ |
| 43 | mw.widgets.CopyTextLayout.prototype.onMwCopy = function ( copied ) { |
| 44 | if ( copied ) { |
| 45 | mw.notify( this.successMessage ); |
| 46 | } else { |
| 47 | mw.notify( this.failMessage, { type: 'error' } ); |
| 48 | } |
| 49 | }; |