Index: trunk/parsers/wikidom/lib/es/es.ListBlock.js |
— | — | @@ -252,6 +252,78 @@ |
253 | 253 | } |
254 | 254 | }; |
255 | 255 | |
| 256 | +/** |
| 257 | + * Applies an annotation to a given range. |
| 258 | + * |
| 259 | + * If a range arguments are not provided, all content will be annotated. |
| 260 | + * |
| 261 | + * @method |
| 262 | + * @param method {String} Way to apply annotation ("toggle", "add" or "remove") |
| 263 | + * @param annotation {Object} Annotation to apply |
| 264 | + * @param range {es.Range} Range of content to annotate |
| 265 | + */ |
| 266 | +es.ListBlock.prototype.annotateContent = function( method, annotation, range ) { |
| 267 | + range.normalize(); |
| 268 | + |
| 269 | + var locationStart = this.getLocationFromOffset( range.start ), |
| 270 | + locationEnd = this.getLocationFromOffset( range.end ); |
| 271 | + |
| 272 | + if ( locationStart.item == locationEnd.item ) { |
| 273 | + // annotate content within one item |
| 274 | + locationStart.item.content.annotate( |
| 275 | + method, |
| 276 | + annotation, |
| 277 | + new es.Range( |
| 278 | + locationStart.offset, |
| 279 | + locationStart.offset + range.end - range.start |
| 280 | + ) |
| 281 | + ); |
| 282 | + } else { |
| 283 | + // annotate content across multiple items |
| 284 | + |
| 285 | + // annotate content in the first item - from offset to end |
| 286 | + locationStart.item.content.annotate( |
| 287 | + method, |
| 288 | + annotation, |
| 289 | + new es.Range( |
| 290 | + locationStart.offset, |
| 291 | + locationStart.item.content.getLength() |
| 292 | + ) |
| 293 | + ); |
| 294 | + |
| 295 | + // annotate content in the last item - from beginning to offset |
| 296 | + locationEnd.item.content.annotate( |
| 297 | + method, |
| 298 | + annotation, |
| 299 | + new es.Range( |
| 300 | + 0, |
| 301 | + locationEnd.offset |
| 302 | + ) |
| 303 | + ); |
| 304 | + |
| 305 | + // annotate all content in selected items except first and last one |
| 306 | + var annotating = false; |
| 307 | + for ( var i = 0; i < this.list.items.length; i++ ) { |
| 308 | + if ( this.list.items[i] === locationStart.item ) { |
| 309 | + annotating = true; |
| 310 | + continue; |
| 311 | + } else if ( this.list.items[i] === locationEnd.item ) { |
| 312 | + break; |
| 313 | + } |
| 314 | + if ( annotating ) { |
| 315 | + this.list.items[i].content.annotate( |
| 316 | + method, |
| 317 | + annotation, |
| 318 | + new es.Range( |
| 319 | + 0, |
| 320 | + this.list.items[i].content.getLength() |
| 321 | + ) |
| 322 | + ); |
| 323 | + } |
| 324 | + } |
| 325 | + } |
| 326 | +}; |
| 327 | + |
256 | 328 | es.ListBlock.prototype.getText = function( range, render ) { |
257 | 329 | return ""; |
258 | 330 | }; |