2013-10-11 18:42:46 +00:00
|
|
|
/*!
|
2015-07-29 13:41:30 +00:00
|
|
|
* VisualEditor MediaWiki Initialization MobileArticleTarget class.
|
2013-10-11 18:42:46 +00:00
|
|
|
*
|
2017-01-03 16:58:33 +00:00
|
|
|
* @copyright 2011-2017 VisualEditor Team and others; see AUTHORS.txt
|
2013-10-11 18:42:46 +00:00
|
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* MediaWiki mobile article target.
|
2013-10-11 18:42:46 +00:00
|
|
|
*
|
|
|
|
* @class
|
2015-12-10 16:07:50 +00:00
|
|
|
* @extends ve.init.mw.ArticleTarget
|
2013-10-11 18:42:46 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-02-06 23:26:52 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
|
|
|
* @cfg {number} [section] Number of the section target should scroll to
|
2013-10-11 18:42:46 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget = function VeInitMwMobileArticleTarget( config ) {
|
2014-02-06 23:26:52 +00:00
|
|
|
config = config || {};
|
2015-08-15 17:00:37 +00:00
|
|
|
config.toolbarConfig = $.extend( {
|
|
|
|
actions: false
|
|
|
|
}, config.toolbarConfig );
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2017-09-11 14:59:38 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.super.call( this, config );
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-02-06 23:26:52 +00:00
|
|
|
this.section = config.section;
|
2015-07-30 09:32:40 +00:00
|
|
|
|
|
|
|
// Initialization
|
|
|
|
this.$element.addClass( 've-init-mw-mobileArticleTarget' );
|
2013-10-11 18:42:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
2015-12-10 16:07:50 +00:00
|
|
|
OO.inheritClass( ve.init.mw.MobileArticleTarget, ve.init.mw.ArticleTarget );
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
/* Static Properties */
|
2014-11-24 17:43:16 +00:00
|
|
|
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.static.toolbarGroups = [
|
2015-08-06 14:22:15 +00:00
|
|
|
// History
|
|
|
|
{ include: [ 'undo' ] },
|
2014-05-02 20:08:16 +00:00
|
|
|
// Style
|
2015-07-29 16:11:06 +00:00
|
|
|
{
|
|
|
|
classes: [ 've-test-toolbar-style' ],
|
|
|
|
type: 'list',
|
|
|
|
icon: 'textStyle',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-style-tooltip' ),
|
|
|
|
include: [ { group: 'textStyle' }, 'language', 'clear' ],
|
|
|
|
forceExpand: [ 'bold', 'italic', 'clear' ],
|
|
|
|
promote: [ 'bold', 'italic' ],
|
|
|
|
demote: [ 'strikethrough', 'code', 'underline', 'language', 'clear' ]
|
|
|
|
},
|
2014-05-02 20:08:16 +00:00
|
|
|
// Link
|
2014-08-22 20:50:48 +00:00
|
|
|
{ include: [ 'link' ] },
|
2015-08-06 14:22:15 +00:00
|
|
|
// Done with editing toolbar
|
|
|
|
{ include: [ 'done' ] }
|
2013-10-11 18:42:46 +00:00
|
|
|
];
|
|
|
|
|
2016-04-21 11:28:00 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.static.trackingName = 'mobile';
|
2013-12-10 01:39:46 +00:00
|
|
|
|
2015-09-03 01:24:48 +00:00
|
|
|
// FIXME Some of these users will be on tablets, check for this
|
|
|
|
ve.init.mw.MobileArticleTarget.static.platformType = 'phone';
|
|
|
|
|
2013-12-06 20:01:03 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2013-12-06 20:01:03 +00:00
|
|
|
*/
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.surfaceReady = function () {
|
2015-08-19 18:05:01 +00:00
|
|
|
var surfaceModel;
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
// Parent method
|
2015-12-11 14:57:49 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.super.prototype.surfaceReady.apply( this, arguments );
|
2015-07-01 11:11:36 +00:00
|
|
|
|
2015-08-19 18:05:01 +00:00
|
|
|
surfaceModel = this.getSurface().getModel();
|
2015-08-07 12:56:55 +00:00
|
|
|
surfaceModel.connect( this, {
|
|
|
|
blur: 'onSurfaceBlur',
|
|
|
|
focus: 'onSurfaceFocus'
|
|
|
|
} );
|
2015-08-19 17:33:02 +00:00
|
|
|
this[ surfaceModel.getSelection().isNull() ? 'onSurfaceBlur' : 'onSurfaceFocus' ]();
|
2015-08-06 14:22:15 +00:00
|
|
|
|
2015-09-26 16:06:37 +00:00
|
|
|
if ( ve.init.platform.constructor.static.isIos() ) {
|
|
|
|
this.getSurface().$element.css( 'padding-bottom', this.$element.height() - this.getToolbar().$element.height() );
|
|
|
|
}
|
|
|
|
|
2015-04-09 03:48:46 +00:00
|
|
|
this.events.trackActivationComplete();
|
2013-12-06 20:01:03 +00:00
|
|
|
};
|
2014-02-06 23:33:21 +00:00
|
|
|
|
2015-08-06 14:22:15 +00:00
|
|
|
/**
|
2015-08-07 12:56:55 +00:00
|
|
|
* Handle surface blur events
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.onSurfaceBlur = function () {
|
|
|
|
var toolbar = this.getToolbar();
|
2015-08-15 17:00:37 +00:00
|
|
|
toolbar.$group.addClass( 've-init-mw-mobileArticleTarget-editTools-hidden' );
|
|
|
|
this.pageToolbar.$element.removeClass( 've-init-mw-mobileArticleTarget-pageToolbar-hidden' );
|
2015-08-07 12:56:55 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle surface focus events
|
2015-08-06 14:22:15 +00:00
|
|
|
*/
|
2015-08-07 12:56:55 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.onSurfaceFocus = function () {
|
2015-08-06 14:22:15 +00:00
|
|
|
var toolbar = this.getToolbar();
|
2015-08-15 17:00:37 +00:00
|
|
|
toolbar.$group.removeClass( 've-init-mw-mobileArticleTarget-editTools-hidden' );
|
|
|
|
this.pageToolbar.$element.addClass( 've-init-mw-mobileArticleTarget-pageToolbar-hidden' );
|
2015-08-06 14:22:15 +00:00
|
|
|
};
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2016-06-30 14:01:24 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.getSaveButtonLabel = function () {
|
2016-08-29 17:46:18 +00:00
|
|
|
if ( mw.config.get( 'wgEditSubmitButtonLabelPublish' ) ) {
|
2016-06-30 14:04:51 +00:00
|
|
|
return OO.ui.deferMsg( 'visualeditor-savedialog-label-publish-short' );
|
|
|
|
}
|
|
|
|
|
2016-06-30 14:01:24 +00:00
|
|
|
return OO.ui.deferMsg( 'visualeditor-savedialog-label-save-short' );
|
2015-07-01 11:11:36 +00:00
|
|
|
};
|
|
|
|
|
2014-02-06 23:33:21 +00:00
|
|
|
/**
|
2014-02-07 22:04:35 +00:00
|
|
|
* @inheritdoc
|
2014-02-06 23:33:21 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.setupToolbar = function ( surface ) {
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2015-07-01 11:11:36 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.super.prototype.setupToolbar.call( this, surface );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2015-07-30 11:08:56 +00:00
|
|
|
this.toolbar.$element.addClass( 've-init-mw-mobileArticleTarget-toolbar' );
|
2015-02-19 18:22:20 +00:00
|
|
|
// Append the context to the toolbar
|
2015-08-08 10:52:05 +00:00
|
|
|
this.toolbar.$bar.append( surface.getContext().$element );
|
2015-02-19 18:22:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.attachToolbar = function () {
|
2015-02-19 18:22:20 +00:00
|
|
|
// Move the toolbar to the overlay header
|
|
|
|
this.toolbar.$element.appendTo( '.overlay-header > .toolbar' );
|
2015-08-10 12:31:46 +00:00
|
|
|
this.toolbar.initialize();
|
2014-02-06 23:33:21 +00:00
|
|
|
};
|
2014-07-23 22:30:38 +00:00
|
|
|
|
2015-07-30 11:08:56 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.attachToolbarSaveButton = function () {
|
2017-01-19 22:09:20 +00:00
|
|
|
var surface = this.getSurface();
|
|
|
|
|
|
|
|
if ( !this.pageToolbar ) {
|
|
|
|
this.pageToolbar = new ve.ui.TargetToolbar( this, { actions: true } );
|
|
|
|
}
|
2015-07-30 11:08:56 +00:00
|
|
|
|
2015-08-15 17:00:37 +00:00
|
|
|
this.pageToolbar.setup( [
|
|
|
|
// Back
|
|
|
|
{ include: [ 'back' ] },
|
2015-07-30 11:08:56 +00:00
|
|
|
{
|
|
|
|
type: 'list',
|
2017-02-28 22:59:51 +00:00
|
|
|
icon: 'edit',
|
2017-02-24 14:29:21 +00:00
|
|
|
title: ve.msg( 'visualeditor-mweditmode-tooltip' ),
|
2017-01-19 22:09:20 +00:00
|
|
|
include: [ surface.getMode() === 'visual' ? 'editModeSource' : 'editModeVisual' ]
|
2015-07-30 11:08:56 +00:00
|
|
|
}
|
2017-01-19 22:09:20 +00:00
|
|
|
], surface );
|
2015-07-30 11:08:56 +00:00
|
|
|
|
2015-08-15 17:00:37 +00:00
|
|
|
this.pageToolbar.emit( 'updateState' );
|
|
|
|
|
2017-01-19 22:09:20 +00:00
|
|
|
if ( !this.$title ) {
|
|
|
|
this.$title = $( '<div>' ).addClass( 've-init-mw-mobileArticleTarget-title-container' ).append(
|
|
|
|
$( '<div>' ).addClass( 've-init-mw-mobileArticleTarget-title' ).text(
|
|
|
|
new mw.Title( ve.init.target.pageName ).getMainText()
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Insert title between 'back' and 'advanced'
|
|
|
|
this.$title.insertAfter( this.pageToolbar.items[ 0 ].$element );
|
2015-08-15 17:00:37 +00:00
|
|
|
|
|
|
|
this.pageToolbar.$element.addClass( 've-init-mw-mobileArticleTarget-pageToolbar' );
|
|
|
|
this.pageToolbar.$actions.append(
|
|
|
|
this.toolbarSaveButton.$element
|
|
|
|
);
|
|
|
|
|
|
|
|
this.toolbar.$element.append( this.pageToolbar.$element );
|
2015-09-07 18:30:30 +00:00
|
|
|
this.pageToolbar.initialize();
|
2015-08-15 17:00:37 +00:00
|
|
|
|
|
|
|
this.pageToolbar.$group.addClass( 've-init-mw-mobileArticleTarget-pageTools' );
|
|
|
|
this.toolbar.$group.addClass( 've-init-mw-mobileArticleTarget-editTools' );
|
2015-07-30 11:08:56 +00:00
|
|
|
};
|
|
|
|
|
2014-07-23 22:30:38 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.goToHeading = function ( headingNode ) {
|
2014-08-22 00:37:12 +00:00
|
|
|
this.scrollToHeading( headingNode );
|
|
|
|
};
|
2014-07-28 21:54:12 +00:00
|
|
|
|
2014-08-22 00:37:12 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.scrollToHeading = function ( headingNode ) {
|
2015-01-31 00:41:37 +00:00
|
|
|
var position,
|
|
|
|
target = this;
|
2014-08-22 00:37:12 +00:00
|
|
|
|
|
|
|
setTimeout( function () {
|
2015-08-07 12:57:28 +00:00
|
|
|
if ( ve.init.platform.constructor.static.isIos() ) {
|
2014-08-22 00:37:12 +00:00
|
|
|
position = headingNode.$element.offset().top - target.toolbar.$element.height();
|
|
|
|
target.surface.$element.closest( '.overlay-content' ).scrollTop( position );
|
|
|
|
} else {
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.super.prototype.scrollToHeading.call( target, headingNode );
|
2014-08-22 00:37:12 +00:00
|
|
|
}
|
|
|
|
} );
|
2014-07-23 22:30:38 +00:00
|
|
|
};
|
2015-07-01 11:11:36 +00:00
|
|
|
|
2015-08-04 13:37:13 +00:00
|
|
|
/**
|
|
|
|
* Close the mobile editor
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.close = function () {
|
|
|
|
};
|
|
|
|
|
2015-08-06 14:22:15 +00:00
|
|
|
/**
|
|
|
|
* Done with the editing toolbar
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.done = function () {
|
|
|
|
this.getSurface().getView().blur();
|
|
|
|
};
|
|
|
|
|
2016-04-21 11:28:00 +00:00
|
|
|
/* Registration */
|
|
|
|
|
|
|
|
ve.init.mw.targetFactory.register( ve.init.mw.MobileArticleTarget );
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/**
|
|
|
|
* Back tool
|
|
|
|
*/
|
|
|
|
ve.ui.MWBackTool = function VeUiMwBackTool() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWBackTool.super.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( ve.ui.MWBackTool, ve.ui.Tool );
|
|
|
|
ve.ui.MWBackTool.static.name = 'back';
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.ui.MWBackTool.static.group = 'navigation';
|
2015-07-01 11:11:36 +00:00
|
|
|
ve.ui.MWBackTool.static.icon = 'previous';
|
|
|
|
ve.ui.MWBackTool.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-backbutton-tooltip' );
|
|
|
|
ve.ui.MWBackTool.static.commandName = 'back';
|
2015-08-06 14:22:15 +00:00
|
|
|
|
|
|
|
/** */
|
|
|
|
ve.ui.MWBackTool.prototype.onUpdateState = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.ui.MWBackTool.super.prototype.onUpdateState.apply( this, arguments );
|
|
|
|
|
|
|
|
this.setActive( false );
|
|
|
|
this.setDisabled( false );
|
|
|
|
};
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
ve.ui.toolFactory.register( ve.ui.MWBackTool );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Back command
|
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWBackCommand = function VeUiMWBackCommand() {
|
2015-07-01 11:11:36 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWBackCommand.super.call( this, 'back' );
|
|
|
|
};
|
|
|
|
OO.inheritClass( ve.ui.MWBackCommand, ve.ui.Command );
|
|
|
|
ve.ui.MWBackCommand.prototype.execute = function () {
|
2015-08-04 13:37:13 +00:00
|
|
|
ve.init.target.close();
|
2015-07-01 11:11:36 +00:00
|
|
|
};
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWBackCommand() );
|
2015-08-06 14:22:15 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Done tool
|
|
|
|
*/
|
|
|
|
ve.ui.MWDoneTool = function VeUiMWDoneTool() {
|
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWDoneTool.super.apply( this, arguments );
|
|
|
|
};
|
|
|
|
OO.inheritClass( ve.ui.MWDoneTool, ve.ui.Tool );
|
|
|
|
ve.ui.MWDoneTool.static.name = 'done';
|
|
|
|
ve.ui.MWDoneTool.static.group = 'navigation';
|
|
|
|
ve.ui.MWDoneTool.static.icon = 'check';
|
|
|
|
ve.ui.MWDoneTool.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-donebutton-tooltip' );
|
|
|
|
ve.ui.MWDoneTool.static.commandName = 'done';
|
|
|
|
ve.ui.toolFactory.register( ve.ui.MWDoneTool );
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Done command
|
|
|
|
*/
|
2015-08-18 12:54:51 +00:00
|
|
|
ve.ui.MWDoneCommand = function VeUiMwDoneCommand() {
|
2015-08-06 14:22:15 +00:00
|
|
|
// Parent constructor
|
|
|
|
ve.ui.MWDoneCommand.super.call( this, 'done' );
|
|
|
|
};
|
|
|
|
OO.inheritClass( ve.ui.MWDoneCommand, ve.ui.Command );
|
|
|
|
ve.ui.MWDoneCommand.prototype.execute = function () {
|
|
|
|
ve.init.target.done();
|
|
|
|
};
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWDoneCommand() );
|