2013-10-11 18:42:46 +00:00
|
|
|
/*!
|
|
|
|
* VisualEditor MediaWiki Initialization MobileViewTarget class.
|
|
|
|
*
|
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
|
|
|
*/
|
2014-12-18 00:56:57 +00:00
|
|
|
ve.init.mw.MobileViewTarget = function VeInitMwMobileViewTarget( 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-12-18 00:56:57 +00:00
|
|
|
this, 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 */
|
2014-11-24 17:43:16 +00:00
|
|
|
|
2013-10-11 18:42:46 +00:00
|
|
|
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
|
|
|
];
|
|
|
|
|
2014-11-24 17:43:16 +00:00
|
|
|
ve.init.mw.MobileViewTarget.static.excludeCommands = [];
|
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-12-18 10:53:26 +00:00
|
|
|
ve.init.mw.MobileViewTarget.prototype.setupToolbar = function ( surface ) {
|
2014-02-07 22:04:35 +00:00
|
|
|
// Parent method
|
2014-12-18 10:53:26 +00:00
|
|
|
ve.init.mw.Target.prototype.setupToolbar.call( this, surface );
|
2014-02-07 22:04:35 +00:00
|
|
|
|
2015-02-19 18:22:20 +00:00
|
|
|
// Append the context to the toolbar
|
|
|
|
this.toolbar.$element.append( surface.context.$element );
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @inheritdoc
|
|
|
|
*/
|
|
|
|
ve.init.mw.MobileViewTarget.prototype.attachToolbar = function () {
|
|
|
|
// 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
|
|
|
|
|
|
|
/**
|
|
|
|
* @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 ) {
|
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 {
|
|
|
|
ve.init.mw.MobileViewTarget.super.prototype.scrollToHeading.call( target, headingNode );
|
|
|
|
}
|
|
|
|
} );
|
2014-07-23 22:30:38 +00:00
|
|
|
};
|