Prepare for MediaWiki integration

Create context instance in surface.
Move over getSelectionRect into ce.surface
Cleanup ve.surface contstructor class
Move linmod/html test objects to sandbox.js

Change-Id: I0cf602ef991100bf6128c68750b02a00566911dc
This commit is contained in:
Rob Moen 2012-05-21 16:06:30 -07:00
parent 8286508491
commit 95e06e96bf
4 changed files with 73 additions and 79 deletions

View file

@ -510,13 +510,66 @@ $(document).ready( function() {
);
}
var linearModel = [
{ 'type': 'paragraph' },
// Overwrite input data with example data
/*
data = [
{ 'type': 'heading', 'attributes': { 'level': 1 } },
'a',
'b',
'c',
{ 'type': '/paragraph' }
{ 'type': '/heading' },
{ 'type': 'paragraph' },
'a',
['b', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
['c', { '{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' } }],
{ 'type': '/paragraph' },
{ 'type': 'paragraph' },
{ 'type': 'image', 'attributes': { 'html/src': 'http://placekitten.com/g/120/120' } },
{ 'type': '/image' },
'L',
'o',
'r',
'e',
'm',
' ',
'i',
'p',
's',
'u',
'm',
' ',
{ 'type': 'image', 'attributes': { 'html/src': 'http://placekitten.com/g/100/100' } },
{ 'type': '/image' },
' ',
'a',
'n',
'd',
{ 'type': '/paragraph' },
{ 'type': 'table' },
{ 'type': 'tableRow' },
{ 'type': 'tableCell' },
{ 'type': 'paragraph' },
['a', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
{ 'type': '/paragraph' },
{ 'type': '/tableCell' },
{ 'type': '/tableRow' },
{ 'type': '/table' },
{ 'type': 'list', 'attributes': { 'style': 'bullet' } },
{ 'type': 'listItem', 'attributes': { 'style': 'item' } },
{ 'type': 'paragraph' },
'a',
{ 'type': '/paragraph' },
{ 'type': '/listItem' },
{ 'type': '/list' },
{ 'type': 'image', 'attributes': { 'html/src': 'http://dl.dropbox.com/u/1026938/wikia.jpeg' } },
{ 'type': '/image' },
];
*/
// Define HTML5 DOM
var HTML = $( '<div><alien><b>Hello world!</b> What\'s up?</alien><h1>abc</h1><p>a<b>b</b><i>c</i></p><p>Lorem ipsum and</p><table><tbody><tr><td><p><i><b>a</b></i></p></td></tr></tbody></table><ul><li><p>a</p></li></ul><img src="http://dl.dropbox.com/u/1026938/wikia.jpeg"></div>' );
/* Sandbox config object. */
var options = {
@ -532,7 +585,7 @@ $(document).ready( function() {
Create Sandbox instance of VE
Attach to #content element
*/
var sandboxEditor = new ve.Surface( '#content', linearModel, options ),
var sandboxEditor = new ve.Surface( '#content', HTML[0], options ),
surfaceModel = sandboxEditor.getSurfaceModel(),
documentModel = sandboxEditor.getDocumentModel(),
parent = sandboxEditor.getParent();

View file

@ -12,6 +12,7 @@ ve.ce.Surface = function( $container, model ) {
// Properties
this.model = model;
this.documentView = new ve.ce.Document( model.getDocument() );
this.contextView = new ve.ui.Context( this );
this.$ = $container;
// Initialization
@ -19,7 +20,7 @@ ve.ce.Surface = function( $container, model ) {
try {
document.execCommand( "enableObjectResizing", false, false );
document.execCommand( "enableInlineTableEditing", false, false );
document.execCommand( "enableInlineTableEditing", false, false );
} catch (e) { }
};
@ -94,6 +95,14 @@ ve.ce.Surface.prototype.showSelection = function( range ) {
rangySel.setSingleRange( rangyRange, range.start !== range.from );
};
ve.ce.Surface.prototype.getSelectionRect = function() {
var rangySel = rangy.getSelection();
return {
start: rangySel.getStartDocumentPos(),
end: rangySel.getEndDocumentPos()
};
};
/* Inheritance */
ve.extendClass( ve.ce.Surface, ve.EventEmitter );

View file

@ -1,6 +1,6 @@
/**
* Creates an ve.ui.Context object.
*
*
* @class
* @constructor
* @param {jQuery} $overlay DOM selection to add nodes to
@ -13,7 +13,7 @@ ve.ui.Context = function( surfaceView, $overlay ) {
// Properties
this.surfaceView = surfaceView;
this.surfaceView.attachContextView( this );
//this.surfaceView.attachContextView( this );
this.inspectors = {};
this.inspector = null;
this.position = null;

View file

@ -6,10 +6,12 @@
* @class
* @constructor
* @param {String} parent Selector of element to attach to
* @param {Array} data Document data
* @param {Array} html Document html
* @param {Object} options Configuration options
*/
ve.Surface = function( parent, data, options ) {
ve.Surface = function( parent, html, options ) {
// Create linear model from HTML5 DOM
var data = ve.dm.HTMLConverter.getLinearModel( html );
// Properties
this.parent = parent;
this.modes = {};
@ -42,69 +44,6 @@ ve.Surface = function( parent, data, options ) {
this.$surface = null;
this.toolbarWrapper = {};
// Overwrite input data with example data
/*
data = [
{ 'type': 'heading', 'attributes': { 'level': 1 } },
'a',
'b',
'c',
{ 'type': '/heading' },
{ 'type': 'paragraph' },
'a',
['b', { '{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' } }],
['c', { '{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' } }],
{ 'type': '/paragraph' },
{ 'type': 'paragraph' },
{ 'type': 'image', 'attributes': { 'html/src': 'http://placekitten.com/g/120/120' } },
{ 'type': '/image' },
'L',
'o',
'r',
'e',
'm',
' ',
'i',
'p',
's',
'u',
'm',
' ',
{ 'type': 'image', 'attributes': { 'html/src': 'http://placekitten.com/g/100/100' } },
{ 'type': '/image' },
' ',
'a',
'n',
'd',
{ 'type': '/paragraph' },
{ 'type': 'table' },
{ 'type': 'tableRow' },
{ 'type': 'tableCell' },
{ 'type': 'paragraph' },
['a', {
'{"type":"textStyle/italic"}': { 'type': 'textStyle/italic' },
'{"type":"textStyle/bold"}': { 'type': 'textStyle/bold' }
}],
{ 'type': '/paragraph' },
{ 'type': '/tableCell' },
{ 'type': '/tableRow' },
{ 'type': '/table' },
{ 'type': 'list', 'attributes': { 'style': 'bullet' } },
{ 'type': 'listItem', 'attributes': { 'style': 'item' } },
{ 'type': 'paragraph' },
'a',
{ 'type': '/paragraph' },
{ 'type': '/listItem' },
{ 'type': '/list' },
{ 'type': 'image', 'attributes': { 'html/src': 'http://dl.dropbox.com/u/1026938/wikia.jpeg' } },
{ 'type': '/image' },
];
*/
// Define HTML5 DOM
var HTML = $( '<div><alien><b>Hello world!</b> What\'s up?</alien><h1>abc</h1><p>a<b>b</b><i>c</i></p><p>Lorem ipsum and</p><table><tbody><tr><td><p><i><b>a</b></i></p></td></tr></tbody></table><ul><li><p>a</p></li></ul><img src="http://dl.dropbox.com/u/1026938/wikia.jpeg"></div>' );
// Create linear model from HTML5 DOM
data = ve.dm.HTMLConverter.getLinearModel( HTML[0] );
/* Create document model object with the linear model */
this.documentModel = new ve.dm.Document ( data );
this.surfaceModel = new ve.dm.Surface( this.documentModel );
@ -112,15 +51,11 @@ ve.Surface = function( parent, data, options ) {
// Setup VE DOM Skeleton
this.setupBaseElements();
// Setup Surface View
//this.setupSurfaceView();
this.$surface = $('<div />').attr('class', 'es-editor');
this.$base.find('.es-visual').append( this.$surface );
/* Instantiate surface layer */
this.view = new ve.ce.Surface( $( '.es-editor' ), this.getSurfaceModel() );
//this.context = new ve.ui.Context( this.view );
// Setup toolbars based on this.options
this.setupToolbars();
@ -159,9 +94,6 @@ ve.Surface.prototype.setupBaseElements = function() {
$( this.getParent() ).append( this.$base );
};
ve.Surface.prototype.setupSurfaceView = function() {
};
ve.Surface.prototype.setupToolbars = function() {
var _this = this;