Index: trunk/parsers/wikidom/lib/es/es.ParagraphBlock.js |
— | — | @@ -47,46 +47,47 @@ |
48 | 48 | /** |
49 | 49 | * Deletes content in a block within a range. |
50 | 50 | * |
51 | | - * @param offset {Integer} Position to start removing content from |
52 | | - * @param length {Integer} Length of content to remove |
| 51 | + * @param offset {Integer} Offset to start removing content from |
| 52 | + * @param length {Integer} Offset to start removing content to |
53 | 53 | */ |
54 | | -ParagraphBlock.prototype.deleteContent = function( offset, length ) { |
55 | | - var start, |
56 | | - end, |
| 54 | +ParagraphBlock.prototype.deleteContent = function( start, end ) { |
| 55 | + // Normalize start/end |
| 56 | + if ( end < start ) { |
| 57 | + var tmp = end; |
| 58 | + end = start; |
| 59 | + start = tmp; |
| 60 | + } |
| 61 | + var line, |
| 62 | + length, |
57 | 63 | from, |
58 | | - to, |
59 | | - line, |
60 | | - lineOffset; |
61 | | - for ( var i = 0; i < this.lines.length; i++ ) { |
| 64 | + to; |
| 65 | + for ( var i = 0; i < this.lines.length || !(from && to); i++ ) { |
62 | 66 | line = this.lines[i]; |
63 | | - start = offset - lineOffset; |
64 | | - end = start + length; |
65 | | - if ( start >= 0 && start < line.text.length) { |
| 67 | + length = line.text.length; |
| 68 | + if ( !from && start < length) { |
66 | 69 | from = { |
67 | 70 | 'line': line, |
68 | 71 | 'index': i, |
69 | 72 | 'offset': start |
70 | 73 | }; |
71 | 74 | } |
72 | | - if ( end >= 0 && end < line.text.length) { |
| 75 | + if ( !to && end < length) { |
73 | 76 | to = { |
74 | 77 | 'line': line, |
75 | 78 | 'index': i, |
76 | 79 | 'offset': end |
77 | 80 | }; |
78 | 81 | } |
79 | | - lineOffset += line.text.length; |
| 82 | + start -= length; |
| 83 | + end -= length; |
80 | 84 | } |
81 | | - if ( !( from && to ) ) { |
82 | | - throw 'FAIL'; |
83 | | - } |
84 | 85 | if ( from.index === to.index ) { |
85 | | - from.line.text = from.line.text.substring( 0, from.line.offset ) |
86 | | - + from.line.text.substring( to.line.offset ); |
| 86 | + from.line.text = from.line.text.substring( 0, from.offset ) |
| 87 | + + from.line.text.substring( to.offset ); |
87 | 88 | } else { |
88 | 89 | // Replace "from" line with remaining content of "from" and "to" lines |
89 | | - from.line.text = from.line.text.substring( 0, from.line.offset ) |
90 | | - + to.line.text.substring( to.line.offset ); |
| 90 | + from.line.text = from.line.text.substring( 0, from.offset ) |
| 91 | + + to.line.text.substring( to.offset ); |
91 | 92 | // Remove lines after "from" up to and including "to" |
92 | 93 | this.lines = this.lines.splice( from.index + 1, to.index - from.index ); |
93 | 94 | } |
Index: trunk/parsers/wikidom/lib/es/es.js |
— | — | @@ -95,3 +95,21 @@ |
96 | 96 | } |
97 | 97 | return through; |
98 | 98 | }; |
| 99 | + |
| 100 | +function Content( data ) { |
| 101 | + this.setData( data ); |
| 102 | +} |
| 103 | + |
| 104 | +Content.prototype.setData = function( data ) { |
| 105 | + // Data type detection |
| 106 | + if ( typeof data === 'string' ) { |
| 107 | + this.type = 'string'; |
| 108 | + } else if ( $.isArray( data ) ) { |
| 109 | + |
| 110 | + } else if ( $.isPlainObject( data ) ) { |
| 111 | + if ( 'type' in data && '' ) { |
| 112 | + |
| 113 | + } |
| 114 | + } |
| 115 | + this.data = data; |
| 116 | +}; |