Index: trunk/parsers/wikidom/tests/annotations/test.js |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | } |
53 | 53 | ]; |
54 | 54 | |
55 | | -var content = Content.newFromLines( lines ); |
| 55 | +var content = es.Content.newFromLines( lines ); |
56 | 56 | |
57 | 57 | /* Tests */ |
58 | 58 | |
— | — | @@ -148,7 +148,7 @@ |
149 | 149 | ]; |
150 | 150 | |
151 | 151 | deepEqual( |
152 | | - Content.newFromLines( lines1 ).getLines(), |
| 152 | + es.Content.newFromLines( lines1 ).getLines(), |
153 | 153 | lines1, |
154 | 154 | 'Content.getLines returns correct array of all lines for annotations overlapping between lines' |
155 | 155 | ); |
Index: trunk/parsers/wikidom/lib/es/es.Document.js |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | /** |
3 | 3 | * |
4 | | - * @extends {EventEmitter} |
| 4 | + * @extends {es.EventEmitter} |
5 | 5 | * @param blocks {Array} List of blocks |
6 | | - * @returns {Document} |
| 6 | + * @returns {es.Document} |
7 | 7 | */ |
8 | | -function Document( blocks ) { |
9 | | - EventEmitter.call( this ); |
| 8 | +es.Document = function( blocks ) { |
| 9 | + es.EventEmitter.call( this ); |
10 | 10 | this.blocks = []; |
11 | 11 | var i; |
12 | 12 | for( i = 0; i < blocks.length; i++ ) { |
— | — | @@ -19,27 +19,27 @@ |
20 | 20 | /** |
21 | 21 | * Gets the first block in the document. |
22 | 22 | * |
23 | | - * @returns {Block} |
| 23 | + * @returns {es.Block} |
24 | 24 | */ |
25 | | -Document.prototype.firstBlock = function() { |
| 25 | +es.Document.prototype.firstBlock = function() { |
26 | 26 | return this.blocks.length ? this.blocks[0] : null; |
27 | 27 | }; |
28 | 28 | |
29 | 29 | /** |
30 | 30 | * Gets the last block in the document. |
31 | 31 | * |
32 | | - * @returns {Block} |
| 32 | + * @returns {es.Block} |
33 | 33 | */ |
34 | | -Document.prototype.lastBlock = function() { |
| 34 | +es.Document.prototype.lastBlock = function() { |
35 | 35 | return this.blocks.length ? this.blocks[this.blocks.length - 1] : null; |
36 | 36 | }; |
37 | 37 | |
38 | 38 | /** |
39 | 39 | * Adds a block to the end of the document. |
40 | 40 | * |
41 | | - * @param {Block} Block to append |
| 41 | + * @param {es.Block} Block to append |
42 | 42 | */ |
43 | | -Document.prototype.appendBlock = function( block ) { |
| 43 | +es.Document.prototype.appendBlock = function( block ) { |
44 | 44 | block.document = this; |
45 | 45 | block.on( 'update', function() { |
46 | 46 | block.document.emit( 'update' ); |
— | — | @@ -50,9 +50,9 @@ |
51 | 51 | /** |
52 | 52 | * Adds a block to the beginning of the document. |
53 | 53 | * |
54 | | - * @param {Block} Block to prepend |
| 54 | + * @param {es.Block} Block to prepend |
55 | 55 | */ |
56 | | -Document.prototype.prependBlock = function( block ) { |
| 56 | +es.Document.prototype.prependBlock = function( block ) { |
57 | 57 | block.document = this; |
58 | 58 | block.on( 'update', function() { |
59 | 59 | block.document.emit( 'update' ); |
— | — | @@ -63,10 +63,10 @@ |
64 | 64 | /** |
65 | 65 | * Adds a block to the document after an existing block. |
66 | 66 | * |
67 | | - * @param block {Block} Block to insert |
68 | | - * @param before {Block} Block to insert before, if null then block will be inserted at the end |
| 67 | + * @param block {es.Block} Block to insert |
| 68 | + * @param before {es.Block} Block to insert before, if null then block will be inserted at the end |
69 | 69 | */ |
70 | | -Document.prototype.insertBlockBefore = function( block, before ) { |
| 70 | +es.Document.prototype.insertBlockBefore = function( block, before ) { |
71 | 71 | block.document = this; |
72 | 72 | block.on( 'update', function() { |
73 | 73 | block.document.emit( 'update' ); |
— | — | @@ -79,10 +79,10 @@ |
80 | 80 | }; |
81 | 81 | /** |
82 | 82 | * Adds a block to the document after an existing block. |
83 | | - * @param block {Block} Block to insert |
84 | | - * @param after {Block} Block to insert after, if null then block will be inserted at the end |
| 83 | + * @param block {es.Block} Block to insert |
| 84 | + * @param after {es.Block} Block to insert after, if null then block will be inserted at the end |
85 | 85 | */ |
86 | | -Document.prototype.insertBlockAfter = function( block, after ) { |
| 86 | +es.Document.prototype.insertBlockAfter = function( block, after ) { |
87 | 87 | block.document = this; |
88 | 88 | block.on( 'update', function() { |
89 | 89 | block.document.emit( 'update' ); |
— | — | @@ -97,15 +97,15 @@ |
98 | 98 | /** |
99 | 99 | * Removes a block from the document. |
100 | 100 | * |
101 | | - * @param {Block} Block to remove |
| 101 | + * @param {es.Block} Block to remove |
102 | 102 | */ |
103 | | -Document.prototype.removeBlock = function( block ) { |
| 103 | +es.Document.prototype.removeBlock = function( block ) { |
104 | 104 | block.removeAllListeners( 'update' ); |
105 | 105 | this.blocks.splice( block.getIndex(), 1 ); |
106 | 106 | block.document = null; |
107 | 107 | }; |
108 | 108 | |
109 | | -Document.prototype.renderBlocks = function( offset ) { |
| 109 | +es.Document.prototype.renderBlocks = function( offset ) { |
110 | 110 | // Remember width, to avoid updates when without width changes |
111 | 111 | this.width = this.$.innerWidth(); |
112 | 112 | // Render blocks |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | } |
118 | 118 | }; |
119 | 119 | |
120 | | -Document.prototype.updateBlocks = function( offset ) { |
| 120 | +es.Document.prototype.updateBlocks = function( offset ) { |
121 | 121 | // Bypass rendering when width has not changed |
122 | 122 | var width = this.$.innerWidth(); |
123 | 123 | if ( this.width === width ) { |
— | — | @@ -130,4 +130,4 @@ |
131 | 131 | } ); |
132 | 132 | }; |
133 | 133 | |
134 | | -extend( Document, EventEmitter ); |
| 134 | +es.extend( es.Document, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js |
— | — | @@ -1,22 +1,22 @@ |
2 | 2 | /** |
3 | 3 | * |
4 | | - * @extends {Block} |
| 4 | + * @extends {es.Block} |
5 | 5 | * @param lines {Array} List of line objects |
6 | | - * @returns {ParagraphBlock} |
| 6 | + * @returns {es.ParagraphBlock} |
7 | 7 | */ |
8 | | -function ParagraphBlock( lines ) { |
9 | | - Block.call( this ); |
10 | | - this.content = Content.newFromLines( lines || [] ); |
| 8 | +es.ParagraphBlock = function( lines ) { |
| 9 | + es.Block.call( this ); |
| 10 | + this.content = es.Content.newFromLines( lines || [] ); |
11 | 11 | this.$ = $( '<div class="editSurface-block editSurface-paragraph"></div>' ) |
12 | 12 | .data( 'block', this ); |
13 | | - this.flow = new TextFlow( this.$, this.content ); |
| 13 | + this.flow = new es.TextFlow( this.$, this.content ); |
14 | 14 | var block = this; |
15 | 15 | this.flow.on( 'render', function() { |
16 | 16 | block.emit( 'update' ); |
17 | 17 | } ); |
18 | 18 | } |
19 | 19 | |
20 | | -ParagraphBlock.prototype.getLength = function() { |
| 20 | +es.ParagraphBlock.prototype.getLength = function() { |
21 | 21 | return this.content.getLength(); |
22 | 22 | }; |
23 | 23 | |
— | — | @@ -26,7 +26,7 @@ |
27 | 27 | * @param offset {Integer} Position to insert content at |
28 | 28 | * @param content {Object} Content to insert |
29 | 29 | */ |
30 | | -ParagraphBlock.prototype.insertContent = function( offset, content ) { |
| 30 | +es.ParagraphBlock.prototype.insertContent = function( offset, content ) { |
31 | 31 | this.content.insert( offset, content ); |
32 | 32 | }; |
33 | 33 | |
— | — | @@ -36,7 +36,7 @@ |
37 | 37 | * @param offset {Integer} Offset to start removing content from |
38 | 38 | * @param length {Integer} Offset to start removing content to |
39 | 39 | */ |
40 | | -ParagraphBlock.prototype.deleteContent = function( start, end ) { |
| 40 | +es.ParagraphBlock.prototype.deleteContent = function( start, end ) { |
41 | 41 | // Normalize start/end |
42 | 42 | if ( end < start ) { |
43 | 43 | var tmp = end; |
— | — | @@ -51,7 +51,7 @@ |
52 | 52 | * |
53 | 53 | * @param $container {jQuery Selection} Container to render into |
54 | 54 | */ |
55 | | -ParagraphBlock.prototype.renderContent = function( offset ) { |
| 55 | +es.ParagraphBlock.prototype.renderContent = function( offset ) { |
56 | 56 | this.flow.render( offset ); |
57 | 57 | }; |
58 | 58 | |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | * |
62 | 62 | * @param position {Integer} Offset to translate |
63 | 63 | */ |
64 | | -ParagraphBlock.prototype.getOffset = function( position ) { |
| 64 | +es.ParagraphBlock.prototype.getOffset = function( position ) { |
65 | 65 | return this.flow.getOffset( position ); |
66 | 66 | }; |
67 | 67 | |
— | — | @@ -69,7 +69,7 @@ |
70 | 70 | * |
71 | 71 | * @param offset {Integer} Offset to translate |
72 | 72 | */ |
73 | | -ParagraphBlock.prototype.getPosition = function( offset ) { |
| 73 | +es.ParagraphBlock.prototype.getPosition = function( offset ) { |
74 | 74 | return this.flow.getPosition( offset ); |
75 | 75 | }; |
76 | 76 | |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | * @param start {Integer} Offset to begin annotating from |
85 | 85 | * @param end {Integer} Offset to stop annotating to |
86 | 86 | */ |
87 | | -ParagraphBlock.prototype.annotateContent = function( method, annotation, start, end ) { |
| 87 | +es.ParagraphBlock.prototype.annotateContent = function( method, annotation, start, end ) { |
88 | 88 | this.content.annotate( method, annotation, start, end ); |
89 | 89 | }; |
90 | 90 | |
— | — | @@ -93,7 +93,7 @@ |
94 | 94 | * @param offset {Integer} Offset to find word nearest to |
95 | 95 | * @return {Object} Range object of boundaries |
96 | 96 | */ |
97 | | -Block.prototype.getWordBoundaries = function( offset ) { |
| 97 | +es.Block.prototype.getWordBoundaries = function( offset ) { |
98 | 98 | return this.content.getWordBoundaries( offset ); |
99 | 99 | }; |
100 | 100 | |
— | — | @@ -105,8 +105,8 @@ |
106 | 106 | * @param offset {Integer} Offset to find section nearest to |
107 | 107 | * @return {Object} Range object of boundaries |
108 | 108 | */ |
109 | | -Block.prototype.getSectionBoundaries = function( offset ) { |
110 | | - return new Range( 0, this.content.getLength() ); |
| 109 | +es.Block.prototype.getSectionBoundaries = function( offset ) { |
| 110 | + return new es.Range( 0, this.content.getLength() ); |
111 | 111 | }; |
112 | 112 | |
113 | | -extend( ParagraphBlock, Block ); |
| 113 | +es.extend( es.ParagraphBlock, es.Block ); |
Index: trunk/parsers/wikidom/lib/es/es.js |
— | — | @@ -1,4 +1,11 @@ |
2 | 2 | /** |
| 3 | + * EditSurafce namespace. |
| 4 | + * |
| 5 | + * All classes and functions will be attached to this object to keep the global namespace clean. |
| 6 | + */ |
| 7 | +var es = {}; |
| 8 | + |
| 9 | +/** |
3 | 10 | * Extends a constructor with prototype of another. |
4 | 11 | * |
5 | 12 | * When using this, it's required to include a call to the constructor of the parent class as the |
— | — | @@ -19,7 +26,7 @@ |
20 | 27 | * @param dst {Function} Class to copy prototype members to |
21 | 28 | * @param src {Function} Class to copy prototype members from |
22 | 29 | */ |
23 | | -function extend( dst, src ) { |
| 30 | +es.extend = function( dst, src ) { |
24 | 31 | var base = new src(); |
25 | 32 | var i; // iterator |
26 | 33 | |
— | — | @@ -35,9 +42,9 @@ |
36 | 43 | * |
37 | 44 | * @param start {Integer} Starting point |
38 | 45 | * @param end {Integer} Ending point |
39 | | - * @returns {Range} |
| 46 | + * @returns {es.Range} |
40 | 47 | */ |
41 | | -function Range( start, end ) { |
| 48 | +es.Range = function( start, end ) { |
42 | 49 | this.start = start || null; |
43 | 50 | this.end = end || null; |
44 | 51 | } |
— | — | @@ -50,9 +57,9 @@ |
51 | 58 | * @param left {Integer} Horizontal position |
52 | 59 | * @param top {Integer} Vertical position (of top, if bottom is used) |
53 | 60 | * @param bottom {Integer} Vertical position of bottom (optional) |
54 | | - * @returns {Position} |
| 61 | + * @returns {es.Position} |
55 | 62 | */ |
56 | | -function Position( left, top, bottom ) { |
| 63 | +es.Position = function( left, top, bottom ) { |
57 | 64 | this.left = left || 0; |
58 | 65 | this.top = top || 0; |
59 | 66 | this.bottom = bottom || 0; |
— | — | @@ -61,11 +68,11 @@ |
62 | 69 | /** |
63 | 70 | * Content location, an offset within a block. |
64 | 71 | * |
65 | | - * @param block {Block} Location target |
| 72 | + * @param block {es.Block} Location target |
66 | 73 | * @param offset {Integer} Location offset |
67 | | - * @returns {Location} |
| 74 | + * @returns {es.Location} |
68 | 75 | */ |
69 | | -function Location( block, offset ) { |
| 76 | +es.Location = function( block, offset ) { |
70 | 77 | this.block = block; |
71 | 78 | this.offset = offset || 0; |
72 | 79 | } |
— | — | @@ -73,11 +80,11 @@ |
74 | 81 | /** |
75 | 82 | * Content selection, a pair of locations. |
76 | 83 | * |
77 | | - * @param from {Location} Starting location |
78 | | - * @param to {Location} Ending location |
79 | | - * @returns {Selection} |
| 84 | + * @param from {es.Location} Starting location |
| 85 | + * @param to {es.Location} Ending location |
| 86 | + * @returns {es.Selection} |
80 | 87 | */ |
81 | | -function Selection( from, to ) { |
| 88 | +es.Selection = function( from, to ) { |
82 | 89 | this.from = from; |
83 | 90 | this.to = to; |
84 | 91 | this.start = from; |
— | — | @@ -87,7 +94,7 @@ |
88 | 95 | /** |
89 | 96 | * Ensures that "from" is before "to". |
90 | 97 | */ |
91 | | -Selection.prototype.normalize = function() { |
| 98 | +es.Selection.prototype.normalize = function() { |
92 | 99 | if ( this.from.block.getIndex() < this.to.block.getIndex() |
93 | 100 | || ( this.from.block === this.to.block && this.from.offset < this.to.offset ) ) { |
94 | 101 | this.start = this.from; |
— | — | @@ -105,7 +112,7 @@ |
106 | 113 | * |
107 | 114 | * @returns {Array} List of blocks |
108 | 115 | */ |
109 | | -Selection.prototype.through = function() { |
| 116 | +es.Selection.prototype.through = function() { |
110 | 117 | var through = []; |
111 | 118 | if ( this.from !== this.to && this.from.nextBlock() !== this.to ) { |
112 | 119 | var next = this.from.nextBlock(); |
— | — | @@ -117,11 +124,11 @@ |
118 | 125 | return through; |
119 | 126 | }; |
120 | 127 | |
121 | | -function Content( data ) { |
| 128 | +es.Content = function( data ) { |
122 | 129 | this.setData( data ); |
123 | 130 | } |
124 | 131 | |
125 | | -Content.prototype.setData = function( data ) { |
| 132 | +es.Content.prototype.setData = function( data ) { |
126 | 133 | // Data type detection |
127 | 134 | if ( typeof data === 'string' ) { |
128 | 135 | this.type = 'string'; |
Index: trunk/parsers/wikidom/lib/es/es.Surface.js |
— | — | @@ -4,13 +4,13 @@ |
5 | 5 | * @param doc |
6 | 6 | * @returns {Surface} |
7 | 7 | */ |
8 | | -function Surface( $container, doc ) { |
| 8 | +es.Surface = function( $container, doc ) { |
9 | 9 | var surface = this; |
10 | 10 | |
11 | 11 | this.$ = $container.addClass( 'editSurface' ); |
12 | 12 | this.doc = doc; |
13 | 13 | this.location = null; |
14 | | - this.selection = new Selection(); |
| 14 | + this.selection = new es.Selection(); |
15 | 15 | this.initialHorizontalCursorPosition = null; |
16 | 16 | this.mouse = { |
17 | 17 | 'selecting': false, |
— | — | @@ -39,14 +39,14 @@ |
40 | 40 | this.$rangeEnd = $( '<div class="editSurface-range"></div>' ).appendTo( this.$ranges ); |
41 | 41 | |
42 | 42 | // Cursor |
43 | | - this.cursor = new Cursor(); |
| 43 | + this.cursor = new es.Cursor(); |
44 | 44 | this.$.append( this.cursor.$ ); |
45 | 45 | |
46 | 46 | // Hidden input |
47 | 47 | var $document = $(document); |
48 | 48 | this.$input = $( '<input class="editSurface-input" />' ) |
49 | 49 | .prependTo( this.$ ) |
50 | | - .bind({ |
| 50 | + .bind( { |
51 | 51 | 'focus' : function() { |
52 | 52 | $(document).bind({ |
53 | 53 | 'mousemove.editSurface' : function(e) { |
— | — | @@ -67,7 +67,7 @@ |
68 | 68 | $document.unbind('.editSurface'); |
69 | 69 | surface.cursor.hide(); |
70 | 70 | } |
71 | | - }); |
| 71 | + } ); |
72 | 72 | |
73 | 73 | $(window).resize( function() { |
74 | 74 | surface.cursor.hide(); |
— | — | @@ -88,7 +88,7 @@ |
89 | 89 | this.doc.renderBlocks(); |
90 | 90 | } |
91 | 91 | |
92 | | -Surface.prototype.getLocationFromEvent = function( e ) { |
| 92 | +es.Surface.prototype.getLocationFromEvent = function( e ) { |
93 | 93 | var $target = $( e.target ); |
94 | 94 | $block = $target.is( '.editSurface-block' ) |
95 | 95 | ? $target : $target.closest( '.editSurface-block' ); |
— | — | @@ -106,18 +106,18 @@ |
107 | 107 | } |
108 | 108 | var block = $block.data( 'block' ), |
109 | 109 | blockPosition = $block.offset(), |
110 | | - mousePosition = new Position( e.pageX - blockPosition.left, e.pageY - blockPosition.top ); |
111 | | - return new Location( block, block.getOffset( mousePosition ) ); |
| 110 | + mousePosition = new es.Position( e.pageX - blockPosition.left, e.pageY - blockPosition.top ); |
| 111 | + return new es.Location( block, block.getOffset( mousePosition ) ); |
112 | 112 | }; |
113 | 113 | |
114 | | -Surface.prototype.onKeyDown = function( e ) { |
| 114 | +es.Surface.prototype.onKeyDown = function( e ) { |
115 | 115 | switch ( e.keyCode ) { |
116 | 116 | case 16: // Shift |
117 | 117 | this.shiftDown = true; |
118 | 118 | if ( !this.keyboard.selecting ) { |
119 | 119 | this.keyboard.selecting = true; |
120 | 120 | if ( !this.selection.to ) { |
121 | | - this.selection = new Selection( this.location ); |
| 121 | + this.selection = new es.Selection( this.location ); |
122 | 122 | } |
123 | 123 | this.drawSelection(); |
124 | 124 | } |
— | — | @@ -131,7 +131,7 @@ |
132 | 132 | if ( this.shiftDown && this.keyboard.selecting ) { |
133 | 133 | this.selection.to = this.location; |
134 | 134 | } else { |
135 | | - this.selection = new Selection(); |
| 135 | + this.selection = new es.Selection(); |
136 | 136 | } |
137 | 137 | this.drawSelection(); |
138 | 138 | break; |
— | — | @@ -140,7 +140,7 @@ |
141 | 141 | if ( this.shiftDown && this.keyboard.selecting ) { |
142 | 142 | this.selection.to = this.location; |
143 | 143 | } else { |
144 | | - this.selection = new Selection(); |
| 144 | + this.selection = new es.Selection(); |
145 | 145 | } |
146 | 146 | this.drawSelection(); |
147 | 147 | break; |
— | — | @@ -150,7 +150,7 @@ |
151 | 151 | if ( this.shiftDown && this.keyboard.selecting ) { |
152 | 152 | this.selection.to = this.location; |
153 | 153 | } else { |
154 | | - this.selection = new Selection(); |
| 154 | + this.selection = new es.Selection(); |
155 | 155 | } |
156 | 156 | this.drawSelection(); |
157 | 157 | break; |
— | — | @@ -159,7 +159,7 @@ |
160 | 160 | if ( this.shiftDown && this.keyboard.selecting ) { |
161 | 161 | this.selection.to = this.location; |
162 | 162 | } else { |
163 | | - this.selection = new Selection(); |
| 163 | + this.selection = new es.Selection(); |
164 | 164 | } |
165 | 165 | this.drawSelection(); |
166 | 166 | break; |
— | — | @@ -188,8 +188,8 @@ |
189 | 189 | surface.deleteContent( deleteSelection ); |
190 | 190 | } |
191 | 191 | var insertLocation = surface.location; |
192 | | - surface.selection = new Selection(); |
193 | | - surface.location = new Location( |
| 192 | + surface.selection = new es.Selection(); |
| 193 | + surface.location = new es.Location( |
194 | 194 | surface.location.block, surface.location.offset + val.length |
195 | 195 | ); |
196 | 196 | surface.insertContent( insertLocation, val.split('') ); |
— | — | @@ -200,7 +200,7 @@ |
201 | 201 | return true; |
202 | 202 | }; |
203 | 203 | |
204 | | -Surface.prototype.onKeyUp = function( e ) { |
| 204 | +es.Surface.prototype.onKeyUp = function( e ) { |
205 | 205 | switch ( e.keyCode ) { |
206 | 206 | case 16: // Shift |
207 | 207 | this.shiftDown = false; |
— | — | @@ -221,41 +221,41 @@ |
222 | 222 | return true; |
223 | 223 | }; |
224 | 224 | |
225 | | -Surface.prototype.handleBackspace = function() { |
| 225 | +es.Surface.prototype.handleBackspace = function() { |
226 | 226 | if ( this.selection.from && this.selection.to ) { |
227 | 227 | var deleteSelection = this.selection; |
228 | 228 | deleteSelection.normalize(); |
229 | 229 | this.location = this.selection.start; |
230 | | - this.selection = new Selection(); |
| 230 | + this.selection = new es.Selection(); |
231 | 231 | this.deleteContent( deleteSelection ); |
232 | 232 | } else if ( this.location.offset > 0 ) { |
233 | | - var deleteSelection = new Selection( |
234 | | - new Location( this.location.block, this.location.offset - 1 ), this.location |
| 233 | + var deleteSelection = new es.Selection( |
| 234 | + new es.Location( this.location.block, this.location.offset - 1 ), this.location |
235 | 235 | ); |
236 | | - this.selection = new Selection(); |
| 236 | + this.selection = new es.Selection(); |
237 | 237 | this.location = deleteSelection.from; |
238 | 238 | this.deleteContent( deleteSelection ); |
239 | 239 | } |
240 | 240 | }; |
241 | 241 | |
242 | | -Surface.prototype.handleDelete = function() { |
| 242 | +es.Surface.prototype.handleDelete = function() { |
243 | 243 | if ( this.selection.from && this.selection.to ) { |
244 | 244 | var deleteSelection = this.selection; |
245 | 245 | deleteSelection.normalize(); |
246 | 246 | this.location = this.selection.end; |
247 | | - this.selection = new Selection(); |
| 247 | + this.selection = new es.Selection(); |
248 | 248 | this.deleteContent( deleteSelection ); |
249 | 249 | } else if ( this.location.offset < block.getLength() - 1 ) { |
250 | | - var deleteSelection = new Selection( |
251 | | - new Location( this.location.block, this.location.offset + 1 ), this.location |
| 250 | + var deleteSelection = new es.Selection( |
| 251 | + new es.Location( this.location.block, this.location.offset + 1 ), this.location |
252 | 252 | ); |
253 | | - this.selection = new Selection(); |
| 253 | + this.selection = new es.Selection(); |
254 | 254 | this.location = deleteSelection.from; |
255 | 255 | this.deleteContent( deleteSelection ); |
256 | 256 | } |
257 | 257 | }; |
258 | 258 | |
259 | | -Surface.prototype.onMouseDown = function( e ) { |
| 259 | +es.Surface.prototype.onMouseDown = function( e ) { |
260 | 260 | if ( e.button === 0 ) { |
261 | 261 | clearTimeout( this.mouse.clickTimeout ); |
262 | 262 | if ( this.mouse.clickX === e.pageX && this.mouse.clickY === e.pageY ) { |
— | — | @@ -275,7 +275,7 @@ |
276 | 276 | switch ( this.mouse.clicks ) { |
277 | 277 | case 1: |
278 | 278 | // Clear selection and move cursor to nearest offset |
279 | | - this.selection = new Selection( this.location ); |
| 279 | + this.selection = new es.Selection( this.location ); |
280 | 280 | var cursorPosition = this.location.block.getPosition( this.location.offset ); |
281 | 281 | this.cursor.show( cursorPosition, this.location.block.$.offset() ); |
282 | 282 | this.$input.css( 'top', cursorPosition.top ); |
— | — | @@ -286,7 +286,7 @@ |
287 | 287 | case 2: |
288 | 288 | // Select word offset is within |
289 | 289 | var boundaries = this.location.block.getWordBoundaries( this.location.offset ); |
290 | | - this.selection = new Selection( |
| 290 | + this.selection = new es.Selection( |
291 | 291 | new Location( this.location.block, boundaries.start ), |
292 | 292 | new Location( this.location.block, boundaries.end ) |
293 | 293 | ); |
— | — | @@ -295,7 +295,7 @@ |
296 | 296 | case 3: |
297 | 297 | // Select section within block offset is within |
298 | 298 | var boundaries = this.location.block.getSectionBoundaries( this.location.offset ); |
299 | | - this.selection = new Selection( |
| 299 | + this.selection = new es.Selection( |
300 | 300 | new Location( this.location.block, boundaries.start ), |
301 | 301 | new Location( this.location.block, boundaries.end ) |
302 | 302 | ); |
— | — | @@ -310,7 +310,7 @@ |
311 | 311 | return false; |
312 | 312 | }; |
313 | 313 | |
314 | | -Surface.prototype.onMouseMove = function( e ) { |
| 314 | +es.Surface.prototype.onMouseMove = function( e ) { |
315 | 315 | if ( e.button === 0 && this.mouse.selecting ) { |
316 | 316 | this.cursor.hide(); |
317 | 317 | this.selection.to = this.getLocationFromEvent( e ); |
— | — | @@ -318,7 +318,7 @@ |
319 | 319 | } |
320 | 320 | }; |
321 | 321 | |
322 | | -Surface.prototype.onMouseUp = function( e ) { |
| 322 | +es.Surface.prototype.onMouseUp = function( e ) { |
323 | 323 | if ( e.button === 0 && this.selection.to ) { |
324 | 324 | this.location = this.selection.to; |
325 | 325 | this.drawSelection(); |
— | — | @@ -332,7 +332,7 @@ |
333 | 333 | * |
334 | 334 | * @return {Boolean} If selection is visibly painted |
335 | 335 | */ |
336 | | -Surface.prototype.drawSelection = function() { |
| 336 | +es.Surface.prototype.drawSelection = function() { |
337 | 337 | var blockWidth; |
338 | 338 | |
339 | 339 | if ( this.selection.from && this.selection.to ) { |
— | — | @@ -442,34 +442,34 @@ |
443 | 443 | /** |
444 | 444 | * Sets the selection to a new range. |
445 | 445 | * |
446 | | - * @param from {Selection} Selection to apply |
| 446 | + * @param from {es.Selection} Selection to apply |
447 | 447 | */ |
448 | | -Surface.prototype.setSelection = function( selection ) { |
| 448 | +es.Surface.prototype.setSelection = function( selection ) { |
449 | 449 | this.selection = selection; |
450 | 450 | }; |
451 | 451 | |
452 | 452 | /** |
453 | 453 | * Gets the current document selection. |
454 | 454 | * |
455 | | - * @returns {Selection} |
| 455 | + * @returns {es.Selection} |
456 | 456 | */ |
457 | | -Surface.prototype.getSelection = function() { |
| 457 | +es.Surface.prototype.getSelection = function() { |
458 | 458 | return this.selection; |
459 | 459 | }; |
460 | 460 | |
461 | 461 | /** |
462 | 462 | * Gets the current cursor location. |
463 | 463 | * |
464 | | - * @returns {Location} |
| 464 | + * @returns {es.Location} |
465 | 465 | */ |
466 | | -Surface.prototype.getLocation = function() { |
| 466 | +es.Surface.prototype.getLocation = function() { |
467 | 467 | return this.location; |
468 | 468 | }; |
469 | 469 | |
470 | 470 | /** |
471 | 471 | * Moves the cursor to the nearest location directly above the current flowed line. |
472 | 472 | */ |
473 | | -Surface.prototype.moveCursorUp = function() { |
| 473 | +es.Surface.prototype.moveCursorUp = function() { |
474 | 474 | var block = this.location.block, |
475 | 475 | offset = this.location.offset, |
476 | 476 | position = block.getPosition( offset ); |
— | — | @@ -492,13 +492,13 @@ |
493 | 493 | position = block.getPosition( offset ); |
494 | 494 | this.cursor.show( position, block.$.offset() ); |
495 | 495 | |
496 | | - this.location = new Location( block, offset ); |
| 496 | + this.location = new es.Location( block, offset ); |
497 | 497 | }; |
498 | 498 | |
499 | 499 | /** |
500 | 500 | * Moves the cursor to the nearest location directly below the current flowed line. |
501 | 501 | */ |
502 | | -Surface.prototype.moveCursorDown = function() { |
| 502 | +es.Surface.prototype.moveCursorDown = function() { |
503 | 503 | var block = this.location.block, |
504 | 504 | offset = this.location.offset, |
505 | 505 | position = block.getPosition( offset ); |
— | — | @@ -521,13 +521,13 @@ |
522 | 522 | position = block.getPosition( offset ); |
523 | 523 | this.cursor.show( position, block.$.offset() ); |
524 | 524 | |
525 | | - this.location = new Location( block, offset ); |
| 525 | + this.location = new es.Location( block, offset ); |
526 | 526 | }; |
527 | 527 | |
528 | 528 | /** |
529 | 529 | * Moves the cursor backward of the current position. |
530 | 530 | */ |
531 | | -Surface.prototype.moveCursorRight = function() { |
| 531 | +es.Surface.prototype.moveCursorRight = function() { |
532 | 532 | var block = this.location.block, |
533 | 533 | offset = this.location.offset; |
534 | 534 | |
— | — | @@ -545,13 +545,13 @@ |
546 | 546 | block.$.offset() |
547 | 547 | ); |
548 | 548 | |
549 | | - this.location = new Location( block, offset ); |
| 549 | + this.location = new es.Location( block, offset ); |
550 | 550 | }; |
551 | 551 | |
552 | 552 | /** |
553 | 553 | * Moves the cursor forward of the current position. |
554 | 554 | */ |
555 | | -Surface.prototype.moveCursorLeft = function() { |
| 555 | +es.Surface.prototype.moveCursorLeft = function() { |
556 | 556 | var block = this.location.block, |
557 | 557 | offset = this.location.offset; |
558 | 558 | |
— | — | @@ -569,10 +569,10 @@ |
570 | 570 | block.$.offset() |
571 | 571 | ); |
572 | 572 | |
573 | | - this.location = new Location( block, offset ); |
| 573 | + this.location = new es.Location( block, offset ); |
574 | 574 | }; |
575 | 575 | |
576 | | -Surface.prototype.insertContent = function( location, content ) { |
| 576 | +es.Surface.prototype.insertContent = function( location, content ) { |
577 | 577 | if ( typeof location === 'undefined' ) { |
578 | 578 | location = this.location; |
579 | 579 | } |
— | — | @@ -582,7 +582,7 @@ |
583 | 583 | this.location.block.insertContent( location.offset, content ); |
584 | 584 | }; |
585 | 585 | |
586 | | -Surface.prototype.deleteContent = function( selection ) { |
| 586 | +es.Surface.prototype.deleteContent = function( selection ) { |
587 | 587 | if ( typeof selection === 'undefined' ) { |
588 | 588 | selection = this.selection; |
589 | 589 | } |
— | — | @@ -623,9 +623,9 @@ |
624 | 624 | * |
625 | 625 | * @param method {String} Way to apply annotation ("toggle", "add" or "remove") |
626 | 626 | * @param annotation {Object} Annotation to apply |
627 | | - * @param selection {Selection} Range to apply annotation to |
| 627 | + * @param selection {es.Selection} Range to apply annotation to |
628 | 628 | */ |
629 | | -Surface.prototype.annotateContent = function( method, annotation, selection ) { |
| 629 | +es.Surface.prototype.annotateContent = function( method, annotation, selection ) { |
630 | 630 | if ( typeof selection === 'undefined' ) { |
631 | 631 | selection = this.selection; |
632 | 632 | } |
Index: trunk/parsers/wikidom/lib/es/es.Block.js |
— | — | @@ -1,13 +1,13 @@ |
2 | 2 | /** |
3 | | - * @extends {EventEmitter} |
4 | | - * @returns {Block} |
| 3 | + * @extends {es.EventEmitter} |
| 4 | + * @returns {es.Block} |
5 | 5 | */ |
6 | | -function Block() { |
7 | | - EventEmitter.call( this ); |
| 6 | +es.Block = function() { |
| 7 | + es.EventEmitter.call( this ); |
8 | 8 | this.document = null; |
9 | 9 | } |
10 | 10 | |
11 | | -Block.prototype.getLength = function() { |
| 11 | +es.Block.prototype.getLength = function() { |
12 | 12 | throw 'Block.getLength not implemented in this subclass.'; |
13 | 13 | }; |
14 | 14 | |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | * |
18 | 18 | * @returns {Integer} Index of block |
19 | 19 | */ |
20 | | -Block.prototype.getIndex = function() { |
| 20 | +es.Block.prototype.getIndex = function() { |
21 | 21 | if ( !this.document ) { |
22 | 22 | throw 'Missing document error. Block is not attached to a document.'; |
23 | 23 | } |
— | — | @@ -26,9 +26,9 @@ |
27 | 27 | /** |
28 | 28 | * Gets the next block in the document. |
29 | 29 | * |
30 | | - * @returns {Block|Null} Block directly proceeding this one, or null if none exists |
| 30 | + * @returns {es.Block|Null} Block directly proceeding this one, or null if none exists |
31 | 31 | */ |
32 | | -Block.prototype.nextBlock = function() { |
| 32 | +es.Block.prototype.nextBlock = function() { |
33 | 33 | if ( !this.document ) { |
34 | 34 | throw 'Missing document error. Block is not attached to a document.'; |
35 | 35 | } |
— | — | @@ -39,9 +39,9 @@ |
40 | 40 | /** |
41 | 41 | * Gets the previous block in the document. |
42 | 42 | * |
43 | | - * @returns {Block|Null} Block directly preceding this one, or null if none exists |
| 43 | + * @returns {es.Block|Null} Block directly preceding this one, or null if none exists |
44 | 44 | */ |
45 | | -Block.prototype.previousBlock = function() { |
| 45 | +es.Block.prototype.previousBlock = function() { |
46 | 46 | if ( !this.document ) { |
47 | 47 | throw 'Missing document error. Block is not attached to a document.'; |
48 | 48 | } |
— | — | @@ -55,7 +55,7 @@ |
56 | 56 | * @param offset {Integer} Position to insert content at |
57 | 57 | * @param content {Object} Content to insert |
58 | 58 | */ |
59 | | -Block.prototype.insertContent = function( offset, content ) { |
| 59 | +es.Block.prototype.insertContent = function( offset, content ) { |
60 | 60 | throw 'Block.insertContent not implemented in this subclass.'; |
61 | 61 | }; |
62 | 62 | |
— | — | @@ -65,14 +65,14 @@ |
66 | 66 | * @param offset {Integer} Position to start removing content from |
67 | 67 | * @param length {Integer} Length of content to remove |
68 | 68 | */ |
69 | | -Block.prototype.deleteContent = function( offset, length ) { |
| 69 | +es.Block.prototype.deleteContent = function( offset, length ) { |
70 | 70 | throw 'Block.deleteContent not implemented in this subclass.'; |
71 | 71 | }; |
72 | 72 | |
73 | 73 | /** |
74 | 74 | * Renders content into a container. |
75 | 75 | */ |
76 | | -Block.prototype.renderContent = function() { |
| 76 | +es.Block.prototype.renderContent = function() { |
77 | 77 | throw 'Block.renderContent not implemented in this subclass.'; |
78 | 78 | }; |
79 | 79 | |
— | — | @@ -81,7 +81,7 @@ |
82 | 82 | * |
83 | 83 | * @param position {Integer} Offset to translate |
84 | 84 | */ |
85 | | -Block.prototype.getOffset = function( position ) { |
| 85 | +es.Block.prototype.getOffset = function( position ) { |
86 | 86 | throw 'Block.getOffset not implemented in this subclass.'; |
87 | 87 | }; |
88 | 88 | |
— | — | @@ -90,7 +90,7 @@ |
91 | 91 | * |
92 | 92 | * @param offset {Integer} Offset to translate |
93 | 93 | */ |
94 | | -Block.prototype.getPosition = function( offset ) { |
| 94 | +es.Block.prototype.getPosition = function( offset ) { |
95 | 95 | throw 'Block.getPosition not implemented in this subclass.'; |
96 | 96 | }; |
97 | 97 | |
— | — | @@ -104,7 +104,7 @@ |
105 | 105 | * @param start {Integer} Offset to begin annotating from |
106 | 106 | * @param end {Integer} Offset to stop annotating to |
107 | 107 | */ |
108 | | -Block.prototype.annotateContent = function( method, annotation, start, end ) { |
| 108 | +es.Block.prototype.annotateContent = function( method, annotation, start, end ) { |
109 | 109 | throw 'Block.annotateContent not implemented in this subclass.'; |
110 | 110 | }; |
111 | 111 | |
— | — | @@ -114,7 +114,7 @@ |
115 | 115 | * @param offset {Integer} Offset to find word nearest to |
116 | 116 | * @return {Object} Range object of boundaries |
117 | 117 | */ |
118 | | -Block.prototype.getWordBoundaries = function( offset ) { |
| 118 | +es.Block.prototype.getWordBoundaries = function( offset ) { |
119 | 119 | throw 'Block.getWordBoundaries not implemented in this subclass.'; |
120 | 120 | }; |
121 | 121 | |
— | — | @@ -124,8 +124,8 @@ |
125 | 125 | * @param offset {Integer} Offset to find section nearest to |
126 | 126 | * @return {Object} Range object of boundaries |
127 | 127 | */ |
128 | | -Block.prototype.getSectionBoundaries = function( offset ) { |
| 128 | +es.Block.prototype.getSectionBoundaries = function( offset ) { |
129 | 129 | throw 'Block.getSectionBoundaries not implemented in this subclass.'; |
130 | 130 | }; |
131 | 131 | |
132 | | -extend( Block, EventEmitter ); |
| 132 | +es.extend( es.Block, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/es/es.Content.js |
— | — | @@ -6,12 +6,12 @@ |
7 | 7 | * paired with offset annotation), especially when performing substring operations. Content can be |
8 | 8 | * derived from or converted to one or more WikiDom line objects. |
9 | 9 | * |
10 | | - * @extends {EventEmitter} |
| 10 | + * @extends {es.EventEmitter} |
11 | 11 | * @param content {Array} List of plain or annotated characters |
12 | | - * @returns {Content} |
| 12 | + * @returns {es.Content} |
13 | 13 | */ |
14 | | -function Content( content ) { |
15 | | - EventEmitter.call( this ); |
| 14 | +es.Content = function( content ) { |
| 15 | + es.EventEmitter.call( this ); |
16 | 16 | this.data = content || []; |
17 | 17 | }; |
18 | 18 | |
— | — | @@ -23,7 +23,7 @@ |
24 | 24 | * Each supported annotation renderer must have an open and close property, each either a string or |
25 | 25 | * a function which accepts a data argument. |
26 | 26 | */ |
27 | | -Content.annotationRenderers = { |
| 27 | +es.Content.annotationRenderers = { |
28 | 28 | 'template': { |
29 | 29 | 'open': function( data ) { |
30 | 30 | return '<span class="editSurface-format-object">' + data.html; |
— | — | @@ -58,7 +58,7 @@ |
59 | 59 | } |
60 | 60 | }; |
61 | 61 | |
62 | | -Content.htmlCharacters = { |
| 62 | +es.Content.htmlCharacters = { |
63 | 63 | '&': '&', |
64 | 64 | '<': '<', |
65 | 65 | '>': '>', |
— | — | @@ -83,7 +83,7 @@ |
84 | 84 | * @param asymmetrical {Boolean} Whether to check only that b contains values from a |
85 | 85 | * @return {Boolean} If the objects contain the same values as each other |
86 | 86 | */ |
87 | | -Content.compareObjects = function( a, b, asymmetrical ) { |
| 87 | +es.Content.compareObjects = function( a, b, asymmetrical ) { |
88 | 88 | var aValue, bValue, aType, bType; |
89 | 89 | var k; |
90 | 90 | for ( k in a ) { |
— | — | @@ -93,12 +93,12 @@ |
94 | 94 | bType = typeof bValue; |
95 | 95 | if ( aType !== bType |
96 | 96 | || ( ( aType === 'string' || aType === 'number' ) && aValue !== bValue ) |
97 | | - || ( $.isPlainObject( aValue ) && !Content.compareObjects( aValue, bValue ) ) ) { |
| 97 | + || ( $.isPlainObject( aValue ) && !es.Content.compareObjects( aValue, bValue ) ) ) { |
98 | 98 | return false; |
99 | 99 | } |
100 | 100 | } |
101 | 101 | // If the check is not asymmetrical, recursing with the arguments swapped will verify our result |
102 | | - return asymmetrical ? true : Content.compareObjects( b, a, true ); |
| 102 | + return asymmetrical ? true : es.Content.compareObjects( b, a, true ); |
103 | 103 | }; |
104 | 104 | |
105 | 105 | /** |
— | — | @@ -107,7 +107,7 @@ |
108 | 108 | * @param source {Object} Object to copy |
109 | 109 | * @return {Object} Copy of source object |
110 | 110 | */ |
111 | | -Content.copyObject = function( source ) { |
| 111 | +es.Content.copyObject = function( source ) { |
112 | 112 | var destination = {}; |
113 | 113 | var key; |
114 | 114 | for ( key in source ) { |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | if ( sourceType === 'string' || sourceType === 'number' ) { |
118 | 118 | destination[key] = sourceValue; |
119 | 119 | } else if ( $.isPlainObject( sourceValue ) ) { |
120 | | - destination[key] = Content.copyObject( sourceValue ); |
| 120 | + destination[key] = es.Content.copyObject( sourceValue ); |
121 | 121 | } |
122 | 122 | } |
123 | 123 | return destination; |
— | — | @@ -130,7 +130,7 @@ |
131 | 131 | * properties, the latter of which being an array of annotation objects including range information |
132 | 132 | * @return {Array} List of plain or annotated characters |
133 | 133 | */ |
134 | | -Content.convertLine = function( line ) { |
| 134 | +es.Content.convertLine = function( line ) { |
135 | 135 | // Convert string to array of characters |
136 | 136 | var data = line.text.split(''); |
137 | 137 | var i; |
— | — | @@ -139,7 +139,7 @@ |
140 | 140 | // Build simplified annotation object |
141 | 141 | var dst = { 'type': src.type }; |
142 | 142 | if ( 'data' in src ) { |
143 | | - dst.data = Content.copyObject( src.data ); |
| 143 | + dst.data = es.Content.copyObject( src.data ); |
144 | 144 | } |
145 | 145 | // Apply annotation to range |
146 | 146 | var k; |
— | — | @@ -157,10 +157,10 @@ |
158 | 158 | * Creates a new Content object from a WikiDom line object. |
159 | 159 | * |
160 | 160 | * @param line {Object} WikiDom compatible line object - @see Content.convertLine |
161 | | - * @return {Content} New content object containing data derived from the WikiDom line |
| 161 | + * @return {es.Content} New content object containing data derived from the WikiDom line |
162 | 162 | */ |
163 | | -Content.newFromLine = function( line ) { |
164 | | - return new Content( Content.convertLine( line ) ); |
| 163 | +es.Content.newFromLine = function( line ) { |
| 164 | + return new es.Content( es.Content.convertLine( line ) ); |
165 | 165 | }; |
166 | 166 | |
167 | 167 | /** |
— | — | @@ -172,18 +172,18 @@ |
173 | 173 | * into multiple line objects, thus making a clean round trip possible. |
174 | 174 | * |
175 | 175 | * @param line {Array} List of WikiDom compatible line objects - @see Content.convertLine |
176 | | - * @return {Content} New content object containing data derived from the WikiDom line |
| 176 | + * @return {es.Content} New content object containing data derived from the WikiDom line |
177 | 177 | */ |
178 | | -Content.newFromLines = function( lines ) { |
| 178 | +es.Content.newFromLines = function( lines ) { |
179 | 179 | var data = []; |
180 | 180 | var i; |
181 | 181 | for ( i = 0; i < lines.length; i++ ) { |
182 | | - data = data.concat( Content.convertLine( lines[i] ) ); |
| 182 | + data = data.concat( es.Content.convertLine( lines[i] ) ); |
183 | 183 | if ( i < lines.length - 1 ) { |
184 | 184 | data.push( '\n' ); |
185 | 185 | } |
186 | 186 | } |
187 | | - return new Content( data ); |
| 187 | + return new es.Content( data ); |
188 | 188 | }; |
189 | 189 | |
190 | 190 | /** |
— | — | @@ -197,8 +197,8 @@ |
198 | 198 | * @param stack {Array} List of currently open annotations |
199 | 199 | * @return {String} Rendered annotation |
200 | 200 | */ |
201 | | -Content.renderAnnotation = function( bias, annotation, stack ) { |
202 | | - var renderers = Content.annotationRenderers, |
| 201 | +es.Content.renderAnnotation = function( bias, annotation, stack ) { |
| 202 | + var renderers = es.Content.annotationRenderers, |
203 | 203 | type = annotation.type, |
204 | 204 | out = ''; |
205 | 205 | if ( type in renderers ) { |
— | — | @@ -258,7 +258,7 @@ |
259 | 259 | * @param end {Integer} Optional end of range, if omitted range will end a this.data.length |
260 | 260 | * @return {String} Plain text within given range |
261 | 261 | */ |
262 | | -Content.prototype.substring = function( start, end ) { |
| 262 | +es.Content.prototype.substring = function( start, end ) { |
263 | 263 | // Wrap values |
264 | 264 | start = Math.max( 0, start || 0 ); |
265 | 265 | if ( end === undefined ) { |
— | — | @@ -285,10 +285,10 @@ |
286 | 286 | * |
287 | 287 | * @param start {Integer} Optional beginning of range, if omitted range will begin at 0 |
288 | 288 | * @param end {Integer} Optional end of range, if omitted range will end a this.data.length |
289 | | - * @return {Content} New content object |
| 289 | + * @return {es.Content} New content object |
290 | 290 | */ |
291 | | -Content.prototype.slice = function( start, end ) { |
292 | | - return new Content( this.data.slice( start, end ) ); |
| 291 | +es.Content.prototype.slice = function( start, end ) { |
| 292 | + return new es.Content( this.data.slice( start, end ) ); |
293 | 293 | }; |
294 | 294 | |
295 | 295 | /** |
— | — | @@ -299,7 +299,7 @@ |
300 | 300 | * @param offset {Integer} Position to insert content at |
301 | 301 | * @param content {Array} Content data to insert |
302 | 302 | */ |
303 | | -Content.prototype.insert = function( offset, content ) { |
| 303 | +es.Content.prototype.insert = function( offset, content ) { |
304 | 304 | // TODO: Prefer to not take annotations from a neighbor that's a space character |
305 | 305 | var neighbor = this.data[Math.max( offset - 1, 0 )]; |
306 | 306 | if ( $.isArray( neighbor ) ) { |
— | — | @@ -326,7 +326,7 @@ |
327 | 327 | * @param start {Integer} Beginning of range |
328 | 328 | * @param end {Integer} End of range |
329 | 329 | */ |
330 | | -Content.prototype.remove = function( start, end ) { |
| 330 | +es.Content.prototype.remove = function( start, end ) { |
331 | 331 | this.data.splice( start, end - start ); |
332 | 332 | this.emit( 'remove', { |
333 | 333 | 'start': start, |
— | — | @@ -340,7 +340,7 @@ |
341 | 341 | * |
342 | 342 | * @return {Integer} Length of content data |
343 | 343 | */ |
344 | | -Content.prototype.getLength = function() { |
| 344 | +es.Content.prototype.getLength = function() { |
345 | 345 | return this.data.length; |
346 | 346 | }; |
347 | 347 | |
— | — | @@ -356,14 +356,14 @@ |
357 | 357 | * @param strict {Boolean} Optionally compare annotation data as well as type |
358 | 358 | * @return {Array} List of indexes of covered characters within content data |
359 | 359 | */ |
360 | | -Content.prototype.coverageOfAnnotation = function( start, end, annotation, strict ) { |
| 360 | +es.Content.prototype.coverageOfAnnotation = function( start, end, annotation, strict ) { |
361 | 361 | var coverage = []; |
362 | 362 | var i, index; |
363 | 363 | for ( i = start; i < end; i++ ) { |
364 | 364 | index = this.indexOfAnnotation( i, annotation ); |
365 | 365 | if ( typeof this.data[i] !== 'string' && index !== -1 ) { |
366 | 366 | if ( strict ) { |
367 | | - if ( Content.compareObjects( this.data[i][index].data, annotation.data ) ) { |
| 367 | + if ( es.Content.compareObjects( this.data[i][index].data, annotation.data ) ) { |
368 | 368 | coverage.push( i ); |
369 | 369 | } |
370 | 370 | } else { |
— | — | @@ -385,14 +385,14 @@ |
386 | 386 | * @param annotation {Object} Annotation to compare with |
387 | 387 | * @param strict {Boolean} Optionally compare annotation data as well as type |
388 | 388 | */ |
389 | | -Content.prototype.indexOfAnnotation = function( offset, annotation, strict ) { |
390 | | - var annotatedCharacter = this.data[offset]; |
| 389 | +es.Content.prototype.indexOfAnnotation = function( offset, annotation, strict ) { |
| 390 | + var annotatedChar = this.data[offset]; |
391 | 391 | var i; |
392 | | - if ( typeof annotatedCharacter !== 'string' ) { |
| 392 | + if ( typeof annotatedChar !== 'string' ) { |
393 | 393 | for ( i = 1; i < this.data[offset].length; i++ ) { |
394 | | - if ( annotatedCharacter[i].type === annotation.type ) { |
| 394 | + if ( annotatedChar[i].type === annotation.type ) { |
395 | 395 | if ( strict ) { |
396 | | - if ( Content.compareObjects( annotatedCharacter[i].data, annotation.data ) ) { |
| 396 | + if ( es.Content.compareObjects( annotatedChar[i].data, annotation.data ) ) { |
397 | 397 | return i; |
398 | 398 | } |
399 | 399 | } else { |
— | — | @@ -418,7 +418,7 @@ |
419 | 419 | * @param start {Integer} Offset to begin annotating from |
420 | 420 | * @param end {Integer} Offset to stop annotating to |
421 | 421 | */ |
422 | | -Content.prototype.annotate = function( method, annotation, start, end ) { |
| 422 | +es.Content.prototype.annotate = function( method, annotation, start, end ) { |
423 | 423 | var i; |
424 | 424 | |
425 | 425 | start = Math.max( start, 0 ); |
— | — | @@ -487,7 +487,7 @@ |
488 | 488 | * @param end {Integer} End of range |
489 | 489 | * @param {String} Rendered HTML of content data |
490 | 490 | */ |
491 | | -Content.prototype.render = function( start, end ) { |
| 491 | +es.Content.prototype.render = function( start, end ) { |
492 | 492 | if ( start || end ) { |
493 | 493 | return this.slice( start, end ).render(); |
494 | 494 | } |
— | — | @@ -505,27 +505,28 @@ |
506 | 506 | if ( !leftPlain && rightPlain ) { |
507 | 507 | // [formatted][plain] pair, close any annotations for left |
508 | 508 | for ( j = 1; j < left.length; j++ ) { |
509 | | - out += Content.renderAnnotation( 'close', left[j], stack ); |
| 509 | + out += es.Content.renderAnnotation( 'close', left[j], stack ); |
510 | 510 | } |
511 | 511 | } else if ( leftPlain && !rightPlain ) { |
512 | 512 | // [plain][formatted] pair, open any annotations for right |
513 | 513 | for ( j = 1; j < right.length; j++ ) { |
514 | | - out += Content.renderAnnotation( 'open', right[j], stack ); |
| 514 | + out += es.Content.renderAnnotation( 'open', right[j], stack ); |
515 | 515 | } |
516 | 516 | } else if ( !leftPlain && !rightPlain ) { |
517 | 517 | // [formatted][formatted] pair, open/close any differences |
518 | 518 | for ( j = 1; j < left.length; j++ ) { |
519 | 519 | if ( right.indexOf( left[j] ) === -1 ) { |
520 | | - out += Content.renderAnnotation( 'close', left[j], stack ); |
| 520 | + out += es.Content.renderAnnotation( 'close', left[j], stack ); |
521 | 521 | } |
522 | 522 | } |
523 | 523 | for ( j = 1; j < right.length; j++ ) { |
524 | 524 | if ( left.indexOf( right[j] ) === -1 ) { |
525 | | - out += Content.renderAnnotation( 'open', right[j], stack ); |
| 525 | + out += es.Content.renderAnnotation( 'open', right[j], stack ); |
526 | 526 | } |
527 | 527 | } |
528 | 528 | } |
529 | | - out += right[0] in Content.htmlCharacters ? Content.htmlCharacters[right[0]] : right[0]; |
| 529 | + out += right[0] in es.Content.htmlCharacters |
| 530 | + ? es.Content.htmlCharacters[right[0]] : right[0]; |
530 | 531 | left = right; |
531 | 532 | } |
532 | 533 | return out; |
— | — | @@ -537,7 +538,7 @@ |
538 | 539 | * @param offset {Integer} Offset to find word nearest to |
539 | 540 | * @return {Object} Range object of boundaries |
540 | 541 | */ |
541 | | -Content.prototype.getWordBoundaries = function( offset ) { |
| 542 | +es.Content.prototype.getWordBoundaries = function( offset ) { |
542 | 543 | if ( offset < 0 || offset > this.data.length ) { |
543 | 544 | throw 'Out of bounds error. Offset expected to be >= 0 and <= to ' + this.data.length; |
544 | 545 | } |
— | — | @@ -559,10 +560,10 @@ |
560 | 561 | } |
561 | 562 | end++; |
562 | 563 | } |
563 | | - return new Range( start, end ); |
| 564 | + return new es.Range( start, end ); |
564 | 565 | }; |
565 | 566 | |
566 | | -Content.prototype.getLines = function() { |
| 567 | +es.Content.prototype.getLines = function() { |
567 | 568 | var lines = [], |
568 | 569 | right = '', |
569 | 570 | rightPlain, |
— | — | @@ -597,7 +598,7 @@ |
598 | 599 | for ( j = 1; j < left.length; j++ ) { |
599 | 600 | for ( k = line.annotations.length - 1; k >= 0; k-- ) { |
600 | 601 | if ( left[j].type === line.annotations[k].type ) { |
601 | | - if ( Content.compareObjects( left[j].data, line.annotations[k].data ) ) { |
| 602 | + if ( es.Content.compareObjects( left[j].data, line.annotations[k].data ) ) { |
602 | 603 | line.annotations[k].range.end = i - offset; |
603 | 604 | break; |
604 | 605 | } |
— | — | @@ -609,7 +610,7 @@ |
610 | 611 | if ( !rightPlain ) { |
611 | 612 | for ( j = 1; j < right.length; j++ ) { |
612 | 613 | if ( leftPlain || this.indexOfAnnotation( i - 1, right[j], true ) === -1 ) { |
613 | | - var annotation = Content.copyObject( right[j] ); |
| 614 | + var annotation = es.Content.copyObject( right[j] ); |
614 | 615 | annotation.range = { |
615 | 616 | start : i - offset, |
616 | 617 | end : i + 1 - offset |
— | — | @@ -631,4 +632,4 @@ |
632 | 633 | return lines; |
633 | 634 | }; |
634 | 635 | |
635 | | -extend( Content, EventEmitter ); |
| 636 | +es.extend( es.Content, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/es/es.EventEmitter.js |
— | — | @@ -1,8 +1,8 @@ |
2 | | -function EventEmitter() { |
| 2 | +es.EventEmitter = function() { |
3 | 3 | this.events = {}; |
4 | 4 | } |
5 | 5 | |
6 | | -EventEmitter.prototype.emit = function( type ) { |
| 6 | +es.EventEmitter.prototype.emit = function( type ) { |
7 | 7 | if ( type === 'error' && !( 'error' in this.events ) ) { |
8 | 8 | throw 'Missing error handler error.'; |
9 | 9 | } |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | return true; |
19 | 19 | }; |
20 | 20 | |
21 | | -EventEmitter.prototype.addListener = function( type, listener ) { |
| 21 | +es.EventEmitter.prototype.addListener = function( type, listener ) { |
22 | 22 | if ( typeof listener !== 'function' ) { |
23 | 23 | throw 'Invalid listener error. Function expected.'; |
24 | 24 | } |
— | — | @@ -30,11 +30,11 @@ |
31 | 31 | return this; |
32 | 32 | }; |
33 | 33 | |
34 | | -EventEmitter.prototype.on = function( type, listener ) { |
| 34 | +es.EventEmitter.prototype.on = function( type, listener ) { |
35 | 35 | this.addListener( type, listener ); |
36 | 36 | }; |
37 | 37 | |
38 | | -EventEmitter.prototype.once = function( type, listener ) { |
| 38 | +es.EventEmitter.prototype.once = function( type, listener ) { |
39 | 39 | var that = this; |
40 | 40 | this.addListener( type, function g() { |
41 | 41 | that.removeListener( type, g ); |
— | — | @@ -42,7 +42,7 @@ |
43 | 43 | } ); |
44 | 44 | }; |
45 | 45 | |
46 | | -EventEmitter.prototype.removeListener = function( type, listener ) { |
| 46 | +es.EventEmitter.prototype.removeListener = function( type, listener ) { |
47 | 47 | if ( typeof listener !== 'function' ) { |
48 | 48 | throw 'Invalid listener error. Function expected.'; |
49 | 49 | } |
— | — | @@ -65,13 +65,13 @@ |
66 | 66 | return this; |
67 | 67 | }; |
68 | 68 | |
69 | | -EventEmitter.prototype.removeAllListeners = function( type ) { |
| 69 | +es.EventEmitter.prototype.removeAllListeners = function( type ) { |
70 | 70 | if ( type in this.events ) { |
71 | 71 | delete this.events[type]; |
72 | 72 | } |
73 | 73 | return this; |
74 | 74 | }; |
75 | 75 | |
76 | | -EventEmitter.prototype.listeners = function( type ) { |
| 76 | +es.EventEmitter.prototype.listeners = function( type ) { |
77 | 77 | return type in this.events ? this.events[type] : []; |
78 | 78 | }; |
Index: trunk/parsers/wikidom/lib/es/es.TextFlow.js |
— | — | @@ -1,18 +1,18 @@ |
2 | 2 | /** |
3 | 3 | * Renders and provides access to flowed text. |
4 | 4 | * |
5 | | - * @extends {EventEmitter} |
| 5 | + * @extends {es.EventEmitter} |
6 | 6 | * @param $container {jQuery Selection} Element to render into |
7 | | - * @param content {Content} Initial content to render |
8 | | - * @returns {TextFlow} |
| 7 | + * @param content {es.Content} Initial content to render |
| 8 | + * @returns {es.TextFlow} |
9 | 9 | */ |
10 | | -function TextFlow( $container, content ) { |
| 10 | +es.TextFlow = function( $container, content ) { |
11 | 11 | // Inheritance |
12 | | - EventEmitter.call( this ); |
| 12 | + es.EventEmitter.call( this ); |
13 | 13 | |
14 | 14 | // Members |
15 | 15 | this.$ = $container; |
16 | | - this.content = content || new Content(); |
| 16 | + this.content = content || new es.Content(); |
17 | 17 | this.boundaries = []; |
18 | 18 | this.lines = []; |
19 | 19 | this.width = null; |
— | — | @@ -49,7 +49,7 @@ |
50 | 50 | * @param position.top {Integer} Vertical position in pixels |
51 | 51 | * @return {Integer} Offset within content nearest the given coordinates |
52 | 52 | */ |
53 | | -TextFlow.prototype.getOffset = function( position ) { |
| 53 | +es.TextFlow.prototype.getOffset = function( position ) { |
54 | 54 | /* |
55 | 55 | * Line finding |
56 | 56 | * |
— | — | @@ -116,7 +116,7 @@ |
117 | 117 | * @param offset {Integer} Offset within content |
118 | 118 | * @return {Object} Object containing left, top and bottom properties, each positions in pixels |
119 | 119 | */ |
120 | | -TextFlow.prototype.getPosition = function( offset ) { |
| 120 | +es.TextFlow.prototype.getPosition = function( offset ) { |
121 | 121 | /* |
122 | 122 | * Range validation |
123 | 123 | * |
— | — | @@ -188,7 +188,7 @@ |
189 | 189 | /** |
190 | 190 | * Updates the word boundary cache, which is used for word fitting. |
191 | 191 | */ |
192 | | -TextFlow.prototype.scanBoundaries = function() { |
| 192 | +es.TextFlow.prototype.scanBoundaries = function() { |
193 | 193 | /* |
194 | 194 | * Word boundary scan |
195 | 195 | * |
— | — | @@ -229,7 +229,7 @@ |
230 | 230 | * causing them to be fragmented. Word fragments are rendered on their own lines, except for their |
231 | 231 | * remainder, which is combined with whatever proceeding words can fit on the same line. |
232 | 232 | */ |
233 | | -TextFlow.prototype.renderIteration = function( limit ) { |
| 233 | +es.TextFlow.prototype.renderIteration = function( limit ) { |
234 | 234 | var rs = this.renderState, |
235 | 235 | iteration = 0, |
236 | 236 | fractional = false, |
— | — | @@ -307,7 +307,7 @@ |
308 | 308 | * |
309 | 309 | * @param offset {Integer} Offset to re-render from, if possible (not yet implemented) |
310 | 310 | */ |
311 | | -TextFlow.prototype.render = function( offset ) { |
| 311 | +es.TextFlow.prototype.render = function( offset ) { |
312 | 312 | var rs = this.renderState; |
313 | 313 | |
314 | 314 | // Check if rendering is currently underway |
— | — | @@ -370,7 +370,7 @@ |
371 | 371 | * @param wordOffset {Integer} Index within this.words which the line begins with |
372 | 372 | * @param fractional {Boolean} If the line begins in the middle of a word |
373 | 373 | */ |
374 | | -TextFlow.prototype.appendLine = function( start, end, wordOffset, fractional ) { |
| 374 | +es.TextFlow.prototype.appendLine = function( start, end, wordOffset, fractional ) { |
375 | 375 | var rs = this.renderState, |
376 | 376 | lineCount = rs.lines.length; |
377 | 377 | $line = this.$.find( '.editSurface-line[line-index=' + lineCount + ']' ); |
— | — | @@ -421,7 +421,7 @@ |
422 | 422 | * @param width {Integer} Maximum width to allow the line to extend to |
423 | 423 | * @return {Integer} Last index within "words" that contains a word that fits |
424 | 424 | */ |
425 | | -TextFlow.prototype.fitWords = function( start, end, ruler, width ) { |
| 425 | +es.TextFlow.prototype.fitWords = function( start, end, ruler, width ) { |
426 | 426 | var offset = start, |
427 | 427 | charOffset = this.boundaries[offset], |
428 | 428 | middle, |
— | — | @@ -476,7 +476,7 @@ |
477 | 477 | * @param width {Integer} Maximum width to allow the line to extend to |
478 | 478 | * @return {Integer} Last index within "text" that contains a character that fits |
479 | 479 | */ |
480 | | -TextFlow.prototype.fitCharacters = function( start, end, ruler, width ) { |
| 480 | +es.TextFlow.prototype.fitCharacters = function( start, end, ruler, width ) { |
481 | 481 | var offset = start, |
482 | 482 | middle, |
483 | 483 | lineWidth, |
— | — | @@ -524,4 +524,4 @@ |
525 | 525 | return { 'end': start, 'width': lineWidth }; |
526 | 526 | }; |
527 | 527 | |
528 | | -extend( TextFlow, EventEmitter ); |
| 528 | +es.extend( es.TextFlow, es.EventEmitter ); |
Index: trunk/parsers/wikidom/lib/es/es.Cursor.js |
— | — | @@ -1,8 +1,8 @@ |
2 | 2 | /** |
3 | 3 | * |
4 | | - * @returns {Cursor} |
| 4 | + * @returns {es.Cursor} |
5 | 5 | */ |
6 | | -function Cursor() { |
| 6 | +es.Cursor = function() { |
7 | 7 | this.cursorInterval = null; |
8 | 8 | this.$ = $( '<div class="editSurface-cursor"></div>' ); |
9 | 9 | } |
— | — | @@ -13,7 +13,7 @@ |
14 | 14 | * @param position {Position} Position to show the cursor at |
15 | 15 | * @param offset {Position} Offset to be added to position |
16 | 16 | */ |
17 | | -Cursor.prototype.show = function( position, offset ) { |
| 17 | +es.Cursor.prototype.show = function( position, offset ) { |
18 | 18 | if ( position ) { |
19 | 19 | if ( $.isPlainObject( offset ) ) { |
20 | 20 | position.left += offset.left; |
— | — | @@ -41,7 +41,7 @@ |
42 | 42 | /** |
43 | 43 | * Hides the cursor. |
44 | 44 | */ |
45 | | -Cursor.prototype.hide = function() { |
| 45 | +es.Cursor.prototype.hide = function() { |
46 | 46 | if( this.cursorInterval ) { |
47 | 47 | clearInterval( this.cursorInterval ); |
48 | 48 | } |
Index: trunk/parsers/wikidom/demos/es/index.html |
— | — | @@ -64,8 +64,8 @@ |
65 | 65 | <!-- Demo --> |
66 | 66 | <script> |
67 | 67 | $(document).ready( function() { |
68 | | - var doc = new Document([ |
69 | | - new ParagraphBlock([ |
| 68 | + var doc = new es.Document([ |
| 69 | + new es.ParagraphBlock([ |
70 | 70 | { |
71 | 71 | 'text': "In text display, line wrap is the feature of continuing on a new line when a line is full, such that each line fits in the viewable window, allowing text to be read from top to bottom without any horizontal scrolling.", |
72 | 72 | 'annotations': [ |
— | — | @@ -97,7 +97,7 @@ |
98 | 98 | }, |
99 | 99 | { 'text': "A soft return is the break resulting from line wrap or word wrap, whereas a hard return is an intentional break, creating a new paragraph." }, |
100 | 100 | ]), |
101 | | - new ParagraphBlock([ |
| 101 | + new es.ParagraphBlock([ |
102 | 102 | { 'text': "The soft returns are usually placed after the ends of complete words, or after the punctuation that follows complete words. However, word wrap may also occur following a hyphen." }, |
103 | 103 | { 'text': "Word wrap following hyphens is sometimes not desired, and can be avoided by using a so-called non-breaking hyphen instead of a regular hyphen. On the other hand, when using word processors, invisible hyphens, called soft hyphens, can also be inserted inside words so that word wrap can occur following the soft hyphens." }, |
104 | 104 | { 'text': "Sometimes, word wrap is not desirable between words. In such cases, word wrap can usually be avoided by using a hard space or non-breaking space between the words, instead of regular spaces." }, |
— | — | @@ -105,7 +105,7 @@ |
106 | 106 | { 'text': "Text might have\ttabs\tin it too. Not all text will end in a line breaking character" } |
107 | 107 | ]) |
108 | 108 | ]); |
109 | | - var surface = new Surface( $('#es-editor'), doc ); |
| 109 | + var surface = new es.Surface( $('#es-editor'), doc ); |
110 | 110 | |
111 | 111 | $( '#es-toolbar .es-toolbarTool' ).mousedown( function( e ) { |
112 | 112 | e.preventDefault(); |