2013-10-11 18:42:46 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki Initialization MobileViewTarget class.
|
|
|
|
*
|
2014-01-05 12:05:05 +00:00
|
|
|
* @copyright 2011-2014 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
|
|
|
*/
|
2014-02-06 23:26:52 +00:00
|
|
|
ve.init.mw.MobileViewTarget = function VeInitMwMobileViewTarget( $container, config ) {
|
2013-10-11 18:42:46 +00:00
|
|
|
var currentUri = new mw.Uri();
|
2014-02-06 23:26:52 +00:00
|
|
|
config = config || {};
|
2013-10-11 18:42:46 +00:00
|
|
|
|
|
|
|
// Parent constructor
|
|
|
|
ve.init.mw.Target.call(
|
2014-02-06 23:26:52 +00:00
|
|
|
this, $container, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid
|
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;
|
2014-02-06 23:26:52 +00:00
|
|
|
|
2013-12-06 20:01:03 +00:00
|
|
|
// Events
|
|
|
|
this.connect( this, {
|
2014-08-22 20:50:48 +00:00
|
|
|
surfaceReady: 'onSurfaceReady'
|
2013-12-06 20:01:03 +00:00
|
|
|
} );
|
2013-10-11 18:42:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/* Inheritance */
|
|
|
|
|
|
|
|
OO.inheritClass( ve.init.mw.MobileViewTarget, ve.init.mw.Target );
|
|
|
|
|
|
|
|
/* Static Properties */
|
|
|
|
ve.init.mw.MobileViewTarget.static.toolbarGroups = [
|
2014-05-02 20:08:16 +00:00
|
|
|
// Style
|
2014-08-22 20:50:48 +00:00
|
|
|
{ include: [ 'bold', 'italic' ] },
|
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
|
|
|
];
|
|
|
|
|
|
|
|
ve.init.mw.MobileViewTarget.static.surfaceCommands = [
|
|
|
|
'bold',
|
2014-03-14 19:52:40 +00:00
|
|
|
'italic',
|
|
|
|
'link'
|
2013-10-11 18:42:46 +00:00
|
|
|
];
|
2013-12-06 20:01:03 +00:00
|
|
|
|
2013-12-10 01:39:46 +00:00
|
|
|
ve.init.mw.MobileViewTarget.static.name = 'mobile';
|
|
|
|
|
2013-12-06 20:01:03 +00:00
|
|
|
/* Methods */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Once surface is ready ready, init UI.
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileViewTarget.prototype.onSurfaceReady = function () {
|
2014-02-06 23:26:52 +00:00
|
|
|
this.restoreEditSection();
|
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}
|
|
|
|
*/
|
2014-05-23 10:51:17 +00:00
|
|
|
ve.init.mw.MobileViewTarget.prototype.createSurface = function ( dmDoc, config ) {
|
|
|
|
return new ve.ui.MobileSurface( dmDoc, config );
|
2014-03-14 19:52:40 +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
|
|
|
*/
|
2014-06-06 10:04:24 +00:00
|
|
|
ve.init.mw.MobileViewTarget.prototype.setupToolbar = function () {
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2014-06-06 10:04:24 +00:00
|
|
|
ve.init.mw.Target.prototype.setupToolbar.call( this );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2014-02-06 23:33:21 +00:00
|
|
|
this.toolbar.$element
|
2014-02-07 22:04:35 +00:00
|
|
|
// FIXME shouldn't be using viewPageTarget styles
|
2014-02-06 23:33:21 +00:00
|
|
|
.addClass( 've-init-mw-viewPageTarget-toolbar' )
|
2014-07-25 18:04:45 +00:00
|
|
|
.append( this.surface.context.$element )
|
2014-02-07 22:04:35 +00:00
|
|
|
// Move the toolbar to the overlay header
|
2014-02-07 19:08:24 +00:00
|
|
|
.appendTo( '.overlay-header > .toolbar' );
|
2014-02-06 23:33:21 +00:00
|
|
|
};
|
2014-07-23 22:30:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
2014-08-22 00:37:12 +00:00
|
|
|
ve.init.mw.MobileViewTarget.prototype.goToHeading = function ( headingNode ) {
|
|
|
|
this.scrollToHeading( headingNode );
|
|
|
|
};
|
2014-07-28 21:54:12 +00:00
|
|
|
|
2014-08-22 00:37:12 +00:00
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileViewTarget.prototype.scrollToHeading = function ( headingNode ) {
|
|
|
|
var target = this, position;
|
|
|
|
|
|
|
|
setTimeout( function () {
|
|
|
|
if ( target.isIos ) {
|
|
|
|
position = headingNode.$element.offset().top - target.toolbar.$element.height();
|
|
|
|
target.surface.$element.closest( '.overlay-content' ).scrollTop( position );
|
|
|
|
} else {
|
|
|
|
ve.init.mw.MobileViewTarget.super.prototype.scrollToHeading.call( target, headingNode );
|
|
|
|
}
|
|
|
|
} );
|
2014-07-23 22:30:38 +00:00
|
|
|
};
|