2011-11-02 21:19:42 +00:00
$ ( document ) . ready ( function ( ) {
2011-12-09 20:40:26 +00:00
var wikidoms = {
2011-12-13 17:49:42 +00:00
'Wikipedia article' : {
2011-12-09 20:40:26 +00:00
'type' : 'document' ,
'children' : [
{
'type' : 'paragraph' ,
'content' : {
'text' : 'In computer science, direct manipulation is a human-computer interaction style which involves continuous representation of objects of interest, and rapid, reversible, incremental actions and feedback. The intention is to allow a user to directly manipulate objects presented to them, using actions that correspond at least loosely to the physical world. An example of direct-manipulation is resizing a graphical shape, such as a rectangle, by dragging its corners or edges with a mouse.' ,
'annotations' : [
{
'type' : 'link/internal' ,
'range' : {
'start' : 3 ,
'end' : 19
2012-03-29 21:05:25 +00:00
} ,
'data' : {
'title' : 'Computer_science'
2011-12-09 20:40:26 +00:00
}
2011-11-21 22:32:22 +00:00
} ,
2011-12-09 20:40:26 +00:00
{
'type' : 'link/internal' ,
'range' : {
'start' : 46 ,
'end' : 72
} ,
'data' : {
2012-03-29 21:05:25 +00:00
'title' : 'Human-computer interaction'
2011-12-09 20:40:26 +00:00
}
2011-11-21 22:32:22 +00:00
} ,
2011-12-09 20:40:26 +00:00
{
2012-03-29 21:05:25 +00:00
'type' : 'textStyle/bold' ,
2011-12-09 20:40:26 +00:00
'range' : {
2012-03-29 21:05:25 +00:00
'start' : 21 ,
'end' : 40
2011-12-09 20:40:26 +00:00
}
2011-11-21 22:32:22 +00:00
} ,
2011-12-04 02:54:33 +00:00
{
2012-03-29 21:05:25 +00:00
'type' : 'textStyle/italic' ,
2011-12-09 20:40:26 +00:00
'range' : {
2012-03-29 21:05:25 +00:00
'start' : 28 ,
'end' : 40
2011-12-09 20:40:26 +00:00
}
2011-11-07 21:30:13 +00:00
}
]
2011-12-09 20:40:26 +00:00
}
2011-12-12 23:04:37 +00:00
} ,
{
2012-03-29 21:05:25 +00:00
'type' : 'table' ,
'attributes' : { 'html/style' : 'width: 300px; float: left; margin: 0 1em 1em 0; border: solid 1px;' } ,
2011-12-12 23:04:37 +00:00
'children' : [
{
2012-03-29 21:05:25 +00:00
'type' : 'tableRow' ,
'children' : [
2011-12-12 23:04:37 +00:00
{
2012-03-29 21:05:25 +00:00
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 1 & cell 1' }
}
]
} ,
2011-12-12 23:04:37 +00:00
{
2012-03-29 21:05:25 +00:00
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 1 & cell 2' }
}
]
2011-12-12 23:04:37 +00:00
}
]
} ,
{
2012-03-29 21:05:25 +00:00
'type' : 'tableRow' ,
'children' : [
2011-12-12 23:04:37 +00:00
{
2012-03-29 21:05:25 +00:00
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 2 & cell 1' }
}
]
} ,
{
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 2 & cell 2' }
}
]
2011-12-12 23:04:37 +00:00
}
]
}
]
} ,
{
'type' : 'paragraph' ,
2012-03-29 21:05:25 +00:00
'content' : { 'text' : 'Test 1' }
} ,
2011-12-12 23:04:37 +00:00
{
'type' : 'paragraph' ,
2012-03-29 21:05:25 +00:00
'content' : { 'text' : 'Test 2' }
} ,
2011-12-12 23:04:37 +00:00
{
'type' : 'paragraph' ,
'content' : {
2012-03-29 21:05:25 +00:00
'text' : 'The ViewTouch graphic touchscreen POS (point of sale) GUI developed by Gene Mosher on the Atari ST computer and first installed in restaurants in 1986 is an early example of an application specific GUI that manifests all of the characteristics of direct manipulation.' ,
'annotations' : [
{
'type' : 'textStyle/bold' ,
'range' : {
'start' : 0 ,
'end' : 13
}
} ,
{
'type' : 'textStyle/italic' ,
'range' : {
'start' : 34 ,
'end' : 37
}
}
]
2011-12-12 23:04:37 +00:00
}
2012-03-29 21:05:25 +00:00
}
2011-12-09 20:40:26 +00:00
]
} ,
2011-12-13 17:49:42 +00:00
'Formatting' : {
2011-12-09 20:40:26 +00:00
'type' : 'document' ,
'children' : [
{
'type' : 'heading' ,
'attributes' : { 'level' : 1 } ,
'content' : {
'text' : 'This is a heading (level 1)' ,
'annotations' : [
2011-11-07 21:30:13 +00:00
{
2011-12-09 20:40:26 +00:00
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
2011-11-07 21:30:13 +00:00
}
2011-12-09 20:40:26 +00:00
]
}
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'heading' ,
'attributes' : { 'level' : 2 } ,
'content' : {
'text' : 'This is a heading (level 2)' ,
'annotations' : [
2011-11-07 21:30:13 +00:00
{
2011-12-09 20:40:26 +00:00
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
2011-11-07 21:30:13 +00:00
}
2011-12-09 20:40:26 +00:00
]
}
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'heading' ,
'attributes' : { 'level' : 3 } ,
'content' : {
'text' : 'This is a heading (level 3)' ,
'annotations' : [
2011-11-07 21:30:13 +00:00
{
2011-12-09 20:40:26 +00:00
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
2011-11-07 21:30:13 +00:00
}
2011-12-09 20:40:26 +00:00
]
}
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'heading' ,
'attributes' : { 'level' : 4 } ,
'content' : {
'text' : 'This is a heading (level 4)' ,
'annotations' : [
2011-11-07 21:30:13 +00:00
{
2011-12-09 20:40:26 +00:00
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
2011-11-07 21:30:13 +00:00
}
2011-12-09 20:40:26 +00:00
]
}
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'heading' ,
'attributes' : { 'level' : 5 } ,
'content' : {
'text' : 'This is a heading (level 5)' ,
'annotations' : [
2011-11-07 21:30:13 +00:00
{
2011-12-09 20:40:26 +00:00
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
2011-11-07 21:30:13 +00:00
}
2011-12-09 20:40:26 +00:00
]
2011-11-02 21:19:42 +00:00
}
2011-12-09 20:40:26 +00:00
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'heading' ,
'attributes' : { 'level' : 6 } ,
'content' : {
'text' : 'This is a heading (level 6)' ,
'annotations' : [
{
'type' : 'textStyle/italic' ,
'range' : {
'start' : 10 ,
'end' : 17
}
}
]
}
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
2011-12-06 22:13:52 +00:00
'type' : 'pre' ,
'content' : { 'text' : 'A lot of text goes here... and at some point it wraps.. A lot of text goes here... and at some point it wraps.. A lot of text goes here... and at some point it wraps.. A lot of text goes here... and at some point it wraps.. A lot of text goes here... and at some point it wraps..' }
2011-12-13 17:49:42 +00:00
} ,
2011-12-09 20:40:26 +00:00
{
'type' : 'heading' ,
'attributes' : { 'level' : 1 } ,
'content' : { 'text' : 'Lists' }
} ,
{
'type' : 'list' ,
'children' : [
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Bullet' }
}
]
}
]
} ,
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Paragraph' }
} ,
{
'type' : 'list' ,
'children' : [
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Bullet' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' , 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Bullet bullet' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' , 'bullet' , 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Bullet bullet bullet' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'number' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Number' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'number' , 'number' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Number number' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'term' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Term' }
}
]
} ,
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'definition' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Definition' }
}
]
}
]
}
]
} ,
2011-12-13 17:49:42 +00:00
/ *
2011-12-09 20:40:26 +00:00
'Tables' : {
'type' : 'document' ,
'children' : [
{
'type' : 'heading' ,
'attributes' : { 'level' : 1 } ,
'content' : { 'text' : 'Tables' }
} ,
{
'type' : 'table' ,
'attributes' : { 'html/style' : 'width: 600px; border: solid 1px;' } ,
'children' : [
{
'type' : 'tableRow' ,
'children' : [
{
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 1 & cell 1' }
} ,
{
'type' : 'list' ,
'children' : [
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Test 4444' }
}
]
2011-11-02 21:19:42 +00:00
} ,
2011-12-09 20:40:26 +00:00
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'bullet' , 'bullet' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Test 55555' }
}
]
2011-11-02 21:19:42 +00:00
} ,
2011-12-09 20:40:26 +00:00
{
'type' : 'listItem' ,
'attributes' : {
'styles' : [ 'number' ]
} ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'Test 666666' }
}
]
}
]
}
]
} ,
{
'type' : 'tableCell' ,
'attributes' : { 'html/style' : 'border: solid 1px;' } ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : 'row 1 & cell 2' }
}
]
}
]
}
]
}
]
2011-12-13 17:49:42 +00:00
} , * /
2011-12-13 08:08:02 +00:00
'New document' : {
'type' : 'document' ,
'children' : [
{
'type' : 'paragraph' ,
'content' : { 'text' : '' }
}
]
2011-12-09 20:40:26 +00:00
}
2011-11-02 21:19:42 +00:00
} ;
2012-02-06 23:50:56 +00:00
window . documentModel = ve . dm . DocumentNode . newFromPlainObject ( wikidoms [ 'Wikipedia article' ] ) ;
window . surfaceModel = new ve . dm . Surface ( window . documentModel ) ;
2012-03-29 21:05:25 +00:00
window . surfaceView = new ve . ce . Surface ( $ ( '#es-editor' ) , window . surfaceModel ) ;
2012-02-06 23:50:56 +00:00
window . toolbarView = new ve . ui . Toolbar ( $ ( '#es-toolbar' ) , window . surfaceView ) ;
window . contextView = new ve . ui . Context ( window . surfaceView ) ;
window . surfaceModel . select ( new ve . Range ( 1 , 1 ) ) ;
2011-11-10 01:28:01 +00:00
2011-12-12 23:41:15 +00:00
/ *
* This code is responsible for switching toolbar into floating mode when scrolling ( with
* keyboard or mouse ) .
* /
var $toolbarWrapper = $ ( '#es-toolbar-wrapper' ) ,
$toolbar = $ ( '#es-toolbar' ) ,
$window = $ ( window ) ;
$window . scroll ( function ( ) {
var toolbarWrapperOffset = $toolbarWrapper . offset ( ) ;
if ( $window . scrollTop ( ) > toolbarWrapperOffset . top ) {
if ( ! $toolbarWrapper . hasClass ( 'float' ) ) {
var left = toolbarWrapperOffset . left ,
right = $window . width ( ) - $toolbarWrapper . outerWidth ( ) - left ;
$toolbarWrapper . css ( 'height' , $toolbarWrapper . height ( ) ) . addClass ( 'float' ) ;
$toolbar . css ( { 'left' : left , 'right' : right } ) ;
}
} else {
if ( $toolbarWrapper . hasClass ( 'float' ) ) {
$toolbarWrapper . css ( 'height' , 'auto' ) . removeClass ( 'float' ) ;
$toolbar . css ( { 'left' : 0 , 'right' : 0 } ) ;
}
}
} ) ;
2011-12-07 21:17:34 +00:00
var $modeButtons = $ ( '.es-modes-button' ) ,
$panels = $ ( '.es-panel' ) ,
$base = $ ( '#es-base' ) ,
currentMode = null ,
modes = {
'wikitext' : {
'$' : $ ( '#es-mode-wikitext' ) ,
'$panel' : $ ( '#es-panel-wikitext' ) ,
'update' : function ( ) {
2011-12-09 20:40:26 +00:00
this . $panel . text (
2012-02-06 23:50:56 +00:00
ve . dm . WikitextSerializer . stringify ( documentModel . getPlainObject ( ) )
2011-12-09 20:40:26 +00:00
) ;
2011-12-07 21:17:34 +00:00
}
} ,
'json' : {
'$' : $ ( '#es-mode-json' ) ,
'$panel' : $ ( '#es-panel-json' ) ,
'update' : function ( ) {
2012-02-06 23:50:56 +00:00
this . $panel . text ( ve . dm . JsonSerializer . stringify ( documentModel . getPlainObject ( ) , {
2011-12-07 21:17:34 +00:00
'indentWith' : ' '
} ) ) ;
}
} ,
'html' : {
'$' : $ ( '#es-mode-html' ) ,
'$panel' : $ ( '#es-panel-html' ) ,
'update' : function ( ) {
2011-12-09 20:40:26 +00:00
this . $panel . text (
2012-02-06 23:50:56 +00:00
ve . dm . HtmlSerializer . stringify ( documentModel . getPlainObject ( ) )
2011-12-09 20:40:26 +00:00
) ;
2011-11-10 01:28:01 +00:00
}
2011-12-07 21:17:34 +00:00
} ,
'render' : {
'$' : $ ( '#es-mode-render' ) ,
'$panel' : $ ( '#es-panel-render' ) ,
'update' : function ( ) {
2011-12-09 20:40:26 +00:00
this . $panel . html (
2012-02-06 23:50:56 +00:00
ve . dm . HtmlSerializer . stringify ( documentModel . getPlainObject ( ) )
2011-12-09 20:40:26 +00:00
) ;
2011-12-07 21:17:34 +00:00
}
} ,
'history' : {
'$' : $ ( '#es-mode-history' ) ,
'$panel' : $ ( '#es-panel-history' ) ,
'update' : function ( ) {
2011-12-13 00:56:29 +00:00
var history = surfaceModel . getHistory ( ) ,
i = history . length ,
end = Math . max ( 0 , i - 25 ) ,
j ,
k ,
ops ,
events = '' ,
z = 0 ,
2012-03-29 21:05:25 +00:00
operations ,
data ;
2011-12-12 22:50:57 +00:00
2011-12-13 00:56:29 +00:00
while ( -- i >= end ) {
z ++ ;
operations = [ ] ;
for ( j = 0 ; j < history [ i ] . stack . length ; j ++ ) {
ops = history [ i ] . stack [ j ] . getOperations ( ) . slice ( 0 ) ;
for ( k = 0 ; k < ops . length ; k ++ ) {
2012-03-29 21:05:25 +00:00
data = ops [ k ] . data || ops [ k ] . length ;
2012-02-06 23:50:56 +00:00
if ( ve . isArray ( data ) ) {
2011-12-07 21:17:34 +00:00
data = data [ 0 ] ;
2012-02-06 23:50:56 +00:00
if ( ve . isArray ( data ) ) {
2011-12-07 21:17:34 +00:00
data = data [ 0 ] ;
}
}
if ( typeof data !== 'string' && typeof data !== 'number' ) {
data = '-' ;
}
2011-12-13 00:56:29 +00:00
ops [ k ] = ops [ k ] . type . substr ( 0 , 3 ) + '(' + data + ')' ;
2011-12-07 21:17:34 +00:00
}
2011-12-13 00:56:29 +00:00
operations . push ( '[' + ops . join ( ', ' ) + ']' ) ;
2011-12-12 22:50:57 +00:00
}
2011-12-13 00:56:29 +00:00
events += '<div' + ( z === surfaceModel . undoIndex ? ' class="es-panel-history-active"' : '' ) + '>' + operations . join ( ', ' ) + '</div>' ;
2011-12-07 21:17:34 +00:00
}
2011-12-12 22:50:57 +00:00
2011-12-07 21:17:34 +00:00
this . $panel . html ( events ) ;
}
2011-12-12 22:09:15 +00:00
} ,
'help' : {
'$' : $ ( '#es-mode-help' ) ,
'$panel' : $ ( '#es-panel-help' ) ,
'update' : function ( ) { }
2011-12-07 21:17:34 +00:00
}
} ;
$ . each ( modes , function ( name , mode ) {
mode . $ . click ( function ( ) {
var disable = $ ( this ) . hasClass ( 'es-modes-button-down' ) ;
var visible = $base . hasClass ( 'es-showData' ) ;
$modeButtons . removeClass ( 'es-modes-button-down' ) ;
$panels . hide ( ) ;
if ( disable ) {
if ( visible ) {
$base . removeClass ( 'es-showData' ) ;
$window . resize ( ) ;
}
currentMode = null ;
} else {
$ ( this ) . addClass ( 'es-modes-button-down' ) ;
mode . $panel . show ( ) ;
if ( ! visible ) {
$base . addClass ( 'es-showData' ) ;
$window . resize ( ) ;
}
mode . update . call ( mode ) ;
currentMode = mode ;
2011-11-10 01:28:01 +00:00
}
2011-12-07 21:17:34 +00:00
} ) ;
} ) ;
2011-12-09 20:56:49 +00:00
var $docsList = $ ( '#es-docs-list' ) ;
$ . each ( wikidoms , function ( title , wikidom ) {
$docsList . append (
$ ( '<li class="es-docs-listItem"></li>' )
. append (
$ ( '<a href="#"></a>' )
. text ( title )
. click ( function ( ) {
2012-02-06 23:50:56 +00:00
var newDocumentModel = ve . dm . DocumentNode . newFromPlainObject ( wikidom ) ;
2011-12-09 20:56:49 +00:00
documentModel . data . splice ( 0 , documentModel . data . length ) ;
2012-02-06 23:50:56 +00:00
ve . insertIntoArray ( documentModel . data , 0 , newDocumentModel . data ) ;
surfaceModel . select ( new ve . Range ( 1 , 1 ) ) ;
2012-03-10 00:31:28 +00:00
// FIXME: this should be using ve.batchedSplice(), otherwise things
// could explode if newDocumentModel.getChildren() is very long
2011-12-09 20:56:49 +00:00
documentModel . splice . apply (
documentModel ,
[ 0 , documentModel . getChildren ( ) . length ]
. concat ( newDocumentModel . getChildren ( ) )
) ;
surfaceModel . purgeHistory ( ) ;
if ( currentMode ) {
currentMode . update . call ( currentMode ) ;
}
return false ;
} )
)
) ;
} ) ;
2011-12-07 22:37:41 +00:00
2011-12-07 21:17:34 +00:00
surfaceModel . on ( 'transact' , function ( ) {
if ( currentMode ) {
currentMode . update . call ( currentMode ) ;
}
} ) ;
surfaceModel . on ( 'select' , function ( ) {
if ( currentMode === modes . history ) {
currentMode . update . call ( currentMode ) ;
2011-11-10 01:28:01 +00:00
}
} ) ;
2011-12-13 04:06:02 +00:00
$ ( '#es-docs' ) . css ( { 'visibility' : 'visible' } ) ;
$ ( '#es-base' ) . css ( { 'visibility' : 'visible' } ) ;
2012-03-29 21:05:25 +00:00
$ ( '#es-mode-wikitext' ) . click ( ) ;
2011-11-02 21:19:42 +00:00
} ) ;