mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 02:23:58 +00:00
8563668978
When I05f11246ca90a1ce3f741fd93194a827528cd597 gets merged, we will need this to be able to scroll to a section on iOS (where the content will be scrolled within a div, not as a whole page). Change-Id: I6e47edfa8c3a3a46fd7a4f11e4a54955f3694b9b
112 lines
2.7 KiB
JavaScript
112 lines
2.7 KiB
JavaScript
/*!
|
|
* VisualEditor MediaWiki Initialization MobileViewTarget class.
|
|
*
|
|
* @copyright 2011-2014 VisualEditor Team and others; see AUTHORS.txt
|
|
* @license The MIT License (MIT); see LICENSE.txt
|
|
*/
|
|
|
|
/**
|
|
*
|
|
* @class
|
|
* @extends ve.init.mw.Target
|
|
*
|
|
* @constructor
|
|
* @param {jQuery} $container Container to render target into
|
|
* @param {Object} [config] Configuration options
|
|
* @cfg {number} [section] Number of the section target should scroll to
|
|
* @cfg {boolean} [isIos=false] Whether the platform is an iOS device
|
|
*/
|
|
ve.init.mw.MobileViewTarget = function VeInitMwMobileViewTarget( $container, config ) {
|
|
var currentUri = new mw.Uri();
|
|
config = config || {};
|
|
|
|
// Parent constructor
|
|
ve.init.mw.Target.call(
|
|
this, $container, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid
|
|
);
|
|
|
|
this.section = config.section;
|
|
this.isIos = !!config.isIos;
|
|
|
|
// Events
|
|
this.connect( this, {
|
|
'surfaceReady': 'onSurfaceReady'
|
|
} );
|
|
};
|
|
|
|
/* Inheritance */
|
|
|
|
OO.inheritClass( ve.init.mw.MobileViewTarget, ve.init.mw.Target );
|
|
|
|
/* Static Properties */
|
|
ve.init.mw.MobileViewTarget.static.toolbarGroups = [
|
|
// Style
|
|
{ 'include': [ 'bold', 'italic' ] },
|
|
// Link
|
|
{ 'include': [ 'link' ] },
|
|
// Cite
|
|
{
|
|
'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' ]
|
|
}
|
|
];
|
|
|
|
ve.init.mw.MobileViewTarget.static.surfaceCommands = [
|
|
'bold',
|
|
'italic',
|
|
'link'
|
|
];
|
|
|
|
ve.init.mw.MobileViewTarget.static.name = 'mobile';
|
|
|
|
/* Methods */
|
|
|
|
/**
|
|
* Once surface is ready ready, init UI.
|
|
*/
|
|
ve.init.mw.MobileViewTarget.prototype.onSurfaceReady = function () {
|
|
this.surface.getView().focus();
|
|
this.restoreEditSection();
|
|
};
|
|
|
|
/**
|
|
* Create a surface.
|
|
*
|
|
* @method
|
|
* @param {ve.dm.Document} dmDoc Document model
|
|
* @param {Object} [config] Configuration options
|
|
* @returns {ve.ui.MobileSurface}
|
|
*/
|
|
ve.init.mw.MobileViewTarget.prototype.createSurface = function ( dmDoc, config ) {
|
|
return new ve.ui.MobileSurface( dmDoc, config );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.init.mw.MobileViewTarget.prototype.setupToolbar = function () {
|
|
// Parent method
|
|
ve.init.mw.Target.prototype.setupToolbar.call( this );
|
|
|
|
this.toolbar.$element
|
|
// FIXME shouldn't be using viewPageTarget styles
|
|
.addClass( 've-init-mw-viewPageTarget-toolbar' )
|
|
// Move the toolbar to the overlay header
|
|
.appendTo( '.overlay-header > .toolbar' );
|
|
};
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
ve.init.mw.MobileViewTarget.prototype.scrollTo = function ( position ) {
|
|
if ( this.isIos ) {
|
|
this.surface.$element.closest( '.overlay-content' ).scrollTop( position );
|
|
} else {
|
|
ve.init.mw.MobileViewTarget.super.prototype.scrollTo.call( this, position );
|
|
}
|
|
};
|