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
|
|
|
*
|
2015-01-08 23:54:03 +00:00
|
|
|
* @copyright 2011-2015 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
|
|
|
|
* @extends ve.init.mw.Target
|
|
|
|
*
|
|
|
|
* @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
|
2014-07-23 22:30:38 +00:00
|
|
|
* @cfg {boolean} [isIos=false] Whether the platform is an iOS device
|
2013-10-11 18:42:46 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget = function VeInitMwMobileArticleTarget( config ) {
|
2013-10-11 18:42:46 +00:00
|
|
|
var currentUri = new mw.Uri();
|
2015-07-30 09:32:40 +00:00
|
|
|
|
2014-02-06 23:26:52 +00:00
|
|
|
config = config || {};
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
2015-08-02 11:30:49 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.super.call(
|
2015-07-30 09:32:40 +00:00
|
|
|
this, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid, config
|
2013-10-11 18:42:46 +00:00
|
|
|
);
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2014-02-06 23:26:52 +00:00
|
|
|
this.section = config.section;
|
2014-07-23 22:30:38 +00:00
|
|
|
this.isIos = !!config.isIos;
|
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-07-29 13:41:30 +00:00
|
|
|
OO.inheritClass( ve.init.mw.MobileArticleTarget, ve.init.mw.Target );
|
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',
|
|
|
|
indicator: 'down',
|
|
|
|
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' ] },
|
2014-05-02 20:08:16 +00:00
|
|
|
// Cite
|
|
|
|
{
|
2014-08-22 20:50:48 +00:00
|
|
|
header: OO.ui.deferMsg( 'visualeditor-toolbar-cite-label' ),
|
|
|
|
indicator: 'down',
|
|
|
|
type: 'list',
|
|
|
|
icon: 'reference',
|
|
|
|
title: OO.ui.deferMsg( 'visualeditor-toolbar-cite-label' ),
|
|
|
|
include: [ { group: 'cite' }, 'reference/existing' ]
|
2015-08-06 14:22:15 +00:00
|
|
|
},
|
|
|
|
// Done with editing toolbar
|
|
|
|
{ include: [ 'done' ] }
|
2013-10-11 18:42:46 +00:00
|
|
|
];
|
|
|
|
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.static.name = 'mobile';
|
2013-12-10 01:39:46 +00:00
|
|
|
|
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-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.onSurfaceReady = function () {
|
2015-07-01 11:11:36 +00:00
|
|
|
// Parent method
|
|
|
|
ve.init.mw.MobileArticleTarget.super.prototype.onSurfaceReady.apply( this, arguments );
|
|
|
|
|
2015-08-06 14:22:15 +00:00
|
|
|
this.getSurface().getModel().connect( this, { select: 'onSurfaceSelect' } );
|
|
|
|
this.onSurfaceSelect();
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Handle surface select events
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.onSurfaceSelect = function () {
|
|
|
|
var toolbar = this.getToolbar();
|
|
|
|
if ( this.getSurface().getModel().getSelection().isNull() ) {
|
|
|
|
toolbar.$group.addClass( 'oo-ui-element-hidden' );
|
|
|
|
toolbar.$actions.removeClass( 'oo-ui-element-hidden' );
|
|
|
|
} else {
|
|
|
|
toolbar.$group.removeClass( 'oo-ui-element-hidden' );
|
|
|
|
toolbar.$actions.addClass( 'oo-ui-element-hidden' );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2014-03-14 19:52:40 +00:00
|
|
|
/**
|
2015-08-04 13:37:13 +00:00
|
|
|
* @inheritdoc
|
2014-03-14 19:52:40 +00:00
|
|
|
*/
|
2015-07-29 13:41:30 +00:00
|
|
|
ve.init.mw.MobileArticleTarget.prototype.createSurface = function ( dmDoc, config ) {
|
2014-05-23 10:51:17 +00:00
|
|
|
return new ve.ui.MobileSurface( dmDoc, config );
|
2014-03-14 19:52:40 +00:00
|
|
|
};
|
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.setupToolbarSaveButton = function () {
|
|
|
|
// Parent method
|
|
|
|
ve.init.mw.MobileArticleTarget.super.prototype.setupToolbarSaveButton.call( this, {
|
|
|
|
label: ve.msg( 'visualeditor-toolbar-savedialog-short' )
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
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-07-30 11:08:56 +00:00
|
|
|
this.toolbar.$bar.append( surface.context.$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' );
|
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 () {
|
|
|
|
this.actionsToolbar = new ve.ui.TargetToolbar( this );
|
|
|
|
|
|
|
|
this.actionsToolbar.setup( [
|
|
|
|
{
|
|
|
|
type: 'list',
|
|
|
|
icon: 'menu',
|
|
|
|
title: ve.msg( 'visualeditor-pagemenu-tooltip' ),
|
2015-08-06 14:22:15 +00:00
|
|
|
include: [ 'back', 'editModeSource' ]
|
2015-07-30 11:08:56 +00:00
|
|
|
}
|
|
|
|
], this.getSurface() );
|
|
|
|
|
|
|
|
this.actionsToolbar.emit( 'updateState' );
|
|
|
|
|
2015-08-06 14:22:15 +00:00
|
|
|
this.toolbar.$actions.append(
|
|
|
|
this.actionsToolbar.$element,
|
|
|
|
$( '<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()
|
|
|
|
)
|
|
|
|
),
|
|
|
|
this.toolbarSaveButton.$element
|
|
|
|
);
|
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 () {
|
|
|
|
if ( target.isIos ) {
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
ve.ui.MWBackCommand = function VeUiMwBackCommmand() {
|
|
|
|
// 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
|
|
|
|
*/
|
|
|
|
ve.ui.MWDoneCommand = function VeUiMwDoneCommmand() {
|
|
|
|
// 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() );
|