mediawiki-extensions-Visual.../modules/ve/init/ve.init.Target.js
Timo Tijhof ca40077866 Clean up Target properties
Move target.surface from mw.Target to Target
* All targets use this, let's standardise it.

Move target.$document from mw.ViewPageTarget to Target
* It was initialised with null in mw.ViewPageTarget, but the
  assignment happened in mw.Target. So it should be moved up
  at least to mw.Target.
* Since it is useful to have in sa.Target as well, moved it up
  to the abstract Target, and implemented in sa.Target and
  immediately used in the standalone demo where we were already
  duplicating the find( '.ve-ce-documentNode' ).

Add missing target.setupDone = false; in sa.Target

Add missing target.toolbar to Target
* Was used in all subclasses, but never initialised in any of
  the constructors. Let's standardise this property name as well
  (instead of initialising it in three places).

Move target#event-surfaceReady from mw.Target to Target
* sa.Target uses it as well, and considering Platform#initialize
  is already standardised in the abstract class, Target#setup
  being deferred is most likely to happen in each target as well
  so let's avoid different events being invented for the same
  thing and consistently use 'surfaceReady'.

Change-Id: Ia8bde188a4cde7e1615c2ae9c5b758eefc5d9cb7
2013-12-19 02:16:20 +00:00

125 lines
2.2 KiB
JavaScript

/*!
* VisualEditor Initialization Target class.
*
* @copyright 2011-2013 VisualEditor Team and others; see AUTHORS.txt
* @license The MIT License (MIT); see LICENSE.txt
*/
/**
* Generic Initialization target.
*
* @class
* @abstract
* @mixins OO.EventEmitter
*
* @constructor
* @param {jQuery} $container Conainter to render target into
*/
ve.init.Target = function VeInitTarget( $container ) {
// Mixin constructors
OO.EventEmitter.call( this );
// Properties
this.$element = $container;
/**
* @property {ve.ui.Surface}
*/
this.surface = null;
/**
* @property {jQuery} The ve-ce-documentNode of #surface
*/
this.$document = null;
/**
* @property {ve.ui.TargetToolbar}
*/
this.toolbar = null;
};
/* Events */
/**
* Fired when the #surface is ready.
*
* By default the surface document is not focussed. If the target wants
* the browsers' focus to be in the surface (ready for typing and cursoring)
* call `this.$document[0].focus();` in a handler for this event.
*
* @event surfaceReady
*/
/* Inheritance */
OO.mixinClass( ve.init.Target, OO.EventEmitter );
/* Static Properties */
ve.init.Target.static.toolbarGroups = [
// History
{ 'include': [ 'undo', 'redo' ] },
// Format
{
'type': 'menu',
'include': [ { 'group': 'format' } ],
'promote': [ 'paragraph' ],
'demote': [ 'preformatted' ]
},
// Style
{
'type': 'list',
'icon': 'text-style',
'include': [ { 'group': 'textStyle' }, 'clear' ],
'promote': [ 'bold', 'italic' ],
'demote': [ 'strikethrough', 'code', 'underline', 'clear' ]
},
// Link
{ 'include': [ 'link' ] },
// Structure
{
'type': 'bar',
'include': [ 'number', 'bullet', 'outdent', 'indent' ]
},
// Insert
{
'include': '*',
'label': 'visualeditor-toolbar-insert',
'demote': [ 'specialcharacter' ]
}
];
ve.init.Target.static.surfaceCommands = [
'undo',
'redo',
'bold',
'italic',
'link',
'clear',
'underline',
'subscript',
'superscript',
'indent',
'outdent',
'paragraph',
'heading1',
'heading2',
'heading3',
'heading4',
'heading5',
'heading6',
'preformatted',
'pasteSpecial'
];
ve.init.Target.static.pasteRules = {
'blacklist': [
// Annotations
// TODO: allow spans
'textStyle/span',
// Nodes
'alienInline', 'alienBlock'
]
};