r101664 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r101663‎ | r101664 | r101665 >
Date:19:30, 2 November 2011
Author:tparscal
Status:deferred
Tags:
Comment:
Added a contentCache to es.ContentView so that it doesn't ask the document for it's content unless something changed
Modified paths:
  • /trunk/parsers/wikidom/lib/hype/views/es.ContentView.js (modified) (history)

Diff [purge]

Index: trunk/parsers/wikidom/lib/hype/views/es.ContentView.js
@@ -35,6 +35,7 @@
3636 this.boundaryTest = /([ \-\t\r\n\f])/g;
3737 this.widthCache = {};
3838 this.renderState = {};
 39+ this.contentCache = null;
3940
4041 if ( model ) {
4142 // Events
@@ -476,7 +477,13 @@
477478 * "boundaries" array. Slices of the "words" array can be joined, producing the escaped HTML of
478479 * the words.
479480 */
480 - var text = this.model.getText();
 481+ // Get and cache a copy of all content, the make a plain-text version of the cached content
 482+ var data = this.contentCache = this.model.getContent(),
 483+ text = '';
 484+ debugger;
 485+ for ( var i = 0, length = data.length; i < length; i++ ) {
 486+ text += typeof data[i] === 'string' ? data[i] : data[i][0];
 487+ }
481488 // Purge "boundaries" and "words" arrays
482489 this.boundaries = [0];
483490 // Reset RegExp object's state
@@ -830,7 +837,12 @@
831838 * @param {String} Rendered HTML of data within content model
832839 */
833840 es.ContentView.prototype.getHtml = function( range, options ) {
834 - var data = this.model.getContent( range ),
 841+ if ( range ) {
 842+ range.normalize();
 843+ } else {
 844+ range = { 'start': 0, 'end': undefined };
 845+ }
 846+ var data = this.contentCache.slice( range.start, range.end ),
835847 render = es.ContentView.renderAnnotation,
836848 htmlChars = es.ContentView.htmlCharacters;
837849 var out = '',

Status & tagging log