GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.mediawiki.org — VisualEditor/Developers/Getting started - MediaWiki VisualEditor: Getting Started With DevelopmentVisualEditor is a rich-text editor, developed primarily for use with MediaWiki. It is a general purpose editor and can be integrated anywhere. As such, it’s maintained in two parts:
This document is concerned primarily with explaining the concepts VisualEditor uses, and will simplify examples somewhat to avoid getting caught in unnecessary details. StructureVisualEditor has three layers:
As a simplified view, the user can interact directly with the UserInterface and ContentEditable, both of which then translate the user's input into the DataModel. The DataModel is never exposed to the user. DM: DataModelThis is the underlying model of the document, divorced from knowledge of the DOM. It’s a linear data structure, which breaks down the document as a mixed series of characters and nodes, stored in order. A simple document might be: 0: <paragraph> 1: 'F' 2: 'o' 3: 'o' 4: </paragraph> All data in the model is referred to in terms of offsets from the start of the model. E.g. Nodes are most block-level elements, such as paragraphs and images. Nodes which can contain other data are called branch nodes. Nodes which cannot contain other data are called leaf nodes. The Any offset can have “annotations”, which are extra data attached to that particular character.
Extending our earlier example, we might bold the 0: <paragraph> 1: ['F', 'bold'] 2: ['o', 'bold'] 3: 'o' 4: </paragraph> Annotations include text styles, links, and language data. The rule of thumb for whether something should be a node or an annotation is whether text contained within it should bring along its annotation when copied around. E.g. italic text should probably still be italic if you move it elsewhere, whereas text in a table cell probably shouldn’t still be in a table cell if you copy it to a paragraph. It's useful to keep this rule of thumb in mind because it's technically possible to implement most elements as a node or an annotation. The 'bold' annotation discussed above could be implemented as a CE: ContentEditableThis is the view. It turns the DataModel into a DOM which can be interacted with. These interactions are based on browser Once inputs occur, they are applied to the DataModel to keep it in sync with the DOM. UI: UserInterfaceThis is the layer surrounding the editing surface. It handles everything which isn’t direct keyboard input to the surface, such as toolbars, dialogs, and context popups. Keyboard shortcuts and commands triggered from special inputs also live on this layer. Changes that the UI makes are applied directly to the DataModel, rather than interacting with the DOM. The DOM is then updated to match the model. A Making changesEach edit to the document becomes a A Allowed operations are:
You could think of an example
Each transaction must result in a valid DataModel – no unbalanced nodes, or nodes in places they’re not allowed to be. If you manually create a
Part of the design goal of this system is to have a format that can be used for collaboration when synchronizing a document being edited by multiple editors. How it fits togetherThat's enough theory. Let’s get our feet wet and walk through how VisualEditor initializes itself, looking at the standalone VisualEditor instance in VisualEditor initialization relies on several things, mostly stored in the
// Set up the platform and wait for i18n messages to load new ve.init.sa.Platform( ve.messagePaths ).getInitializedPromise() If this Next, it creates the UI framework surrounding the editor on the demo page. // Create the target target = new ve.init.sa.Target(); // Append the target to the document $( '.ve-instance' ).append( target.$element ); // Create a document model for a new surface target.addSurface( ve.dm.converter.getModelFromDom( ve.createDocumentFromHtml( '<p><b>Hello,</b> <i>World!</i></p>' ), // Optional: Document language, directionality (ltr/rtl) { lang: $.i18n().locale, dir: $( 'body' ).css( 'direction' ) } ) ); This creates a DOM We now have a working VisualEditor instance. DebuggingHere are some useful shortcuts into a VisualEditor instance, which you might want to use in the console: // The target: ve.init.target // Which contains a ui.Surface: ve.init.target.surface // Which contains a ce.Surface: ve.init.target.surface.view // Or a dm.Surface: ve.init.target.surface.model // The data model for the current document is: ve.init.target.surface.model.documentModel.data Below your VisualEditor surface there's a debug bar. If you're using VisualEditor on MediaWiki, you'll need to trigger debug mode first as well (add
OO + OOUI and youVisualEditor is built on top of OOjs, and you may want to familiarize yourself with it. In particular, OO.EventEmitter is used extensively. VisualEditor uses OOjs UI for its UI widgets. As well as all of |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |