/*! * VisualEditor MediaWiki Initialization MobileArticleTarget class. * * @copyright 2011-2015 VisualEditor Team and others; see AUTHORS.txt * @license The MIT License (MIT); see LICENSE.txt */ /** * MediaWiki mobile article target. * * @class * @extends ve.init.mw.Target * * @constructor * @param {Object} [config] Configuration options * @cfg {number} [section] Number of the section target should scroll to */ ve.init.mw.MobileArticleTarget = function VeInitMwMobileArticleTarget( config ) { var currentUri = new mw.Uri(); config = config || {}; config.toolbarConfig = $.extend( { actions: false }, config.toolbarConfig ); // Parent constructor ve.init.mw.MobileArticleTarget.super.call( this, mw.config.get( 'wgRelevantPageName' ), currentUri.query.oldid, config ); this.section = config.section; // Initialization this.$element.addClass( 've-init-mw-mobileArticleTarget' ); }; /* Inheritance */ OO.inheritClass( ve.init.mw.MobileArticleTarget, ve.init.mw.Target ); /* Static Properties */ ve.init.mw.MobileArticleTarget.static.toolbarGroups = [ // History { include: [ 'undo' ] }, // Style { 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' ] }, // 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' ] }, // Done with editing toolbar { include: [ 'done' ] } ]; ve.init.mw.MobileArticleTarget.static.name = 'mobile'; /* Methods */ /** * @inheritdoc */ ve.init.mw.MobileArticleTarget.prototype.onSurfaceReady = function () { var surfaceModel; // Parent method ve.init.mw.MobileArticleTarget.super.prototype.onSurfaceReady.apply( this, arguments ); surfaceModel = this.getSurface().getModel(); surfaceModel.connect( this, { blur: 'onSurfaceBlur', focus: 'onSurfaceFocus' } ); this[ surfaceModel.getSelection().isNull() ? 'onSurfaceBlur' : 'onSurfaceFocus' ](); this.events.trackActivationComplete(); }; /** * Handle surface blur events */ ve.init.mw.MobileArticleTarget.prototype.onSurfaceBlur = function () { var toolbar = this.getToolbar(); toolbar.$group.addClass( 've-init-mw-mobileArticleTarget-editTools-hidden' ); this.pageToolbar.$element.removeClass( 've-init-mw-mobileArticleTarget-pageToolbar-hidden' ); }; /** * Handle surface focus events */ ve.init.mw.MobileArticleTarget.prototype.onSurfaceFocus = function () { var toolbar = this.getToolbar(); toolbar.$group.removeClass( 've-init-mw-mobileArticleTarget-editTools-hidden' ); this.pageToolbar.$element.addClass( 've-init-mw-mobileArticleTarget-pageToolbar-hidden' ); }; /** * @inheritdoc */ ve.init.mw.MobileArticleTarget.prototype.createSurface = function ( dmDoc, config ) { return new ve.ui.MobileSurface( dmDoc, config ); }; /** * @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' ) } ); }; /** * @inheritdoc */ ve.init.mw.MobileArticleTarget.prototype.setupToolbar = function ( surface ) { // Parent method ve.init.mw.MobileArticleTarget.super.prototype.setupToolbar.call( this, surface ); this.toolbar.$element.addClass( 've-init-mw-mobileArticleTarget-toolbar' ); // Append the context to the toolbar this.toolbar.$bar.append( surface.getContext().$element ); }; /** * @inheritdoc */ ve.init.mw.MobileArticleTarget.prototype.attachToolbar = function () { // Move the toolbar to the overlay header this.toolbar.$element.appendTo( '.overlay-header > .toolbar' ); this.toolbar.initialize(); }; /** * @inheritdoc */ ve.init.mw.MobileArticleTarget.prototype.attachToolbarSaveButton = function () { this.pageToolbar = new ve.ui.TargetToolbar( this, { actions: true } ); this.pageToolbar.setup( [ // Back { include: [ 'back' ] }, { type: 'list', icon: 'advanced', indicator: 'down', title: ve.msg( 'visualeditor-pagemenu-tooltip' ), include: [ 'editModeSource' ] } ], this.getSurface() ); this.pageToolbar.emit( 'updateState' ); $( '