Index: trunk/parsers/wikidom/tests/annotations/test.js |
— | — | @@ -50,7 +50,6 @@ |
51 | 51 | ] |
52 | 52 | } |
53 | 53 | ]; |
54 | | - |
55 | 54 | var content = es.Content.newFromWikiDomLines( lines ); |
56 | 55 | |
57 | 56 | /* Tests */ |
— | — | @@ -318,4 +317,27 @@ |
319 | 318 | ], |
320 | 319 | 'Content.slice returns all data when called without arguments' |
321 | 320 | ); |
322 | | -} ); |
\ No newline at end of file |
| 321 | +} ); |
| 322 | + |
| 323 | +var floating = es.Content.newFromWikiDomLines( [ |
| 324 | + { |
| 325 | + "text": "Look, a floating image!", |
| 326 | + "annotations": [ |
| 327 | + { |
| 328 | + "type": "template", |
| 329 | + "data": { |
| 330 | + "html": "<div style=\"float: right\">[image goes here]</div>" |
| 331 | + }, |
| 332 | + "range": { |
| 333 | + "start": 6, |
| 334 | + "end": 7 |
| 335 | + } |
| 336 | + } |
| 337 | + ] |
| 338 | + } |
| 339 | +] ); |
| 340 | + |
| 341 | +test( 'Floating objects in Content', 2, function() { |
| 342 | + ok( !content.hasFloatingObjects(), 'Without floating objects' ); |
| 343 | + ok( floating.hasFloatingObjects(), 'With floating objects' ); |
| 344 | +} ); |
Index: trunk/parsers/wikidom/lib/es/es.Content.js |
— | — | @@ -35,38 +35,48 @@ |
36 | 36 | return '<span class="editSurface-format-object">' + data.html; |
37 | 37 | }, |
38 | 38 | 'close': '</span>', |
| 39 | + 'float': function( data ) { |
| 40 | + console.log( data.html ); |
| 41 | + return $( data.html ).css( 'float' ); |
| 42 | + } |
39 | 43 | }, |
40 | 44 | 'bold': { |
41 | 45 | 'open': '<span class="editSurface-format-bold">', |
42 | 46 | 'close': '</span>', |
| 47 | + 'float': false |
43 | 48 | }, |
44 | 49 | 'italic': { |
45 | 50 | 'open': '<span class="editSurface-format-italic">', |
46 | 51 | 'close': '</span>', |
| 52 | + 'float': false |
47 | 53 | }, |
48 | 54 | 'size': { |
49 | 55 | 'open': function( data ) { |
50 | 56 | return '<span class="editSurface-format-' + data.type + '">'; |
51 | 57 | }, |
52 | 58 | 'close': '</span>', |
| 59 | + 'float': false |
53 | 60 | }, |
54 | 61 | 'script': { |
55 | 62 | 'open': function( data ) { |
56 | 63 | return '<span class="editSurface-format-' + data.type + '">'; |
57 | 64 | }, |
58 | 65 | 'close': '</span>', |
| 66 | + 'float': false |
59 | 67 | }, |
60 | 68 | 'xlink': { |
61 | 69 | 'open': function( data ) { |
62 | 70 | return '<span class="editSurface-format-link" data-href="' + data.href + '">'; |
63 | 71 | }, |
64 | | - 'close': '</span>' |
| 72 | + 'close': '</span>', |
| 73 | + 'float': false |
65 | 74 | }, |
66 | 75 | 'ilink': { |
67 | 76 | 'open': function( data ) { |
68 | 77 | return '<span class="editSurface-format-link" data-title="' + data.title + '">'; |
69 | 78 | }, |
70 | | - 'close': '</span>' |
| 79 | + 'close': '</span>', |
| 80 | + 'float': false |
71 | 81 | } |
72 | 82 | }; |
73 | 83 | |
— | — | @@ -346,6 +356,34 @@ |
347 | 357 | }; |
348 | 358 | |
349 | 359 | /** |
| 360 | + * Checks if a range of content contains any floating objects. |
| 361 | + * |
| 362 | + * @method |
| 363 | + * @param range {es.Range} Range of content to check |
| 364 | + * @returns {Boolean} If there's any floating objects in range |
| 365 | + */ |
| 366 | +es.Content.prototype.hasFloatingObjects = function( range ) { |
| 367 | + if ( !range ) { |
| 368 | + range = new es.Range( 0, this.data.length ); |
| 369 | + } |
| 370 | + range.normalize(); |
| 371 | + for ( var i = 0; i < this.data.length; i++ ) { |
| 372 | + if ( this.data[i].length > 1 ) { |
| 373 | + for ( var j = 1; j < this.data[i].length; j++ ) { |
| 374 | + var float = es.Content.annotationRenderers[this.data[i][j].type].float; |
| 375 | + if ( float && typeof float === 'function' ) { |
| 376 | + float = float( this.data[i][j].data ); |
| 377 | + } |
| 378 | + if ( float ) { |
| 379 | + return true; |
| 380 | + } |
| 381 | + } |
| 382 | + } |
| 383 | + } |
| 384 | + return false; |
| 385 | +}; |
| 386 | + |
| 387 | +/** |
350 | 388 | * Inserts content data at a specific position. |
351 | 389 | * |
352 | 390 | * Inserted content will inherit annotations from neighboring content. |