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
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @class
|
|
|
|
* @extends ve.init.mw.Target
|
|
|
|
*
|
|
|
|
* @constructor
|
|
|
|
* @param {jQuery} $container Container to render target into
|
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
|
|
|
|
2015-07-01 11:11:36 +00:00
|
|
|
/* Events */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @event back
|
|
|
|
* Leave the editor
|
|
|
|
*/
|
|
|
|
|
2015-07-30 11:08:56 +00:00
|
|
|
/**
|
|
|
|
* @event editSource
|
|
|
|
* Switch to edit source mode
|
|
|
|
*/
|
|
|
|
|
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-07-01 11:11:36 +00:00
|
|
|
// Link
|
|
|
|
{ include: [ 'back' ] },
|
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' ]
|
2014-05-02 20:08:16 +00:00
|
|
|
}
|
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 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Once surface is ready ready, init UI.
|
|
|
|
*/
|
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-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
|
|
|
|
2014-03-14 19:52:40 +00:00
|
|
|
/**
|
|
|
|
* Create a surface.
|
|
|
|
*
|
|
|
|
* @method
|
|
|
|
* @param {ve.dm.Document} dmDoc Document model
|
2014-05-23 10:51:17 +00:00
|
|
|
* @param {Object} [config] Configuration options
|
2014-03-14 19:52:40 +00:00
|
|
|
* @returns {ve.ui.MobileSurface}
|
|
|
|
*/
|
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' ),
|
|
|
|
include: [ 'editModeSource' ]
|
|
|
|
}
|
|
|
|
], this.getSurface() );
|
|
|
|
|
|
|
|
this.actionsToolbar.emit( 'updateState' );
|
|
|
|
|
|
|
|
this.toolbar.$actions.append( this.actionsToolbar.$element, this.toolbarSaveButton.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileArticleTarget.prototype.editSource = function () {
|
|
|
|
this.emit( 'editSource' );
|
|
|
|
};
|
|
|
|
|
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
|
|
|
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
ve.ui.MWBackTool.static.group = 'history';
|
|
|
|
ve.ui.MWBackTool.static.icon = 'previous';
|
|
|
|
ve.ui.MWBackTool.static.title =
|
|
|
|
OO.ui.deferMsg( 'visualeditor-backbutton-tooltip' );
|
|
|
|
ve.ui.MWBackTool.static.commandName = 'back';
|
|
|
|
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 () {
|
|
|
|
ve.init.target.emit( 'back' );
|
|
|
|
};
|
|
|
|
ve.ui.commandRegistry.register( new ve.ui.MWBackCommand() );
|