mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 18:39:52 +00:00
Merge "Performance improvement for getRenderedContents"
This commit is contained in:
commit
13710a1ed4
|
@ -78,9 +78,18 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
||||||
annotationStack = new ve.dm.AnnotationSet( store ),
|
annotationStack = new ve.dm.AnnotationSet( store ),
|
||||||
annotatedHtml = [],
|
annotatedHtml = [],
|
||||||
$wrapper = $( '<div>' ),
|
$wrapper = $( '<div>' ),
|
||||||
$current = $wrapper;
|
$current = $wrapper,
|
||||||
|
buffer = '';
|
||||||
|
|
||||||
|
function flushBuffer() {
|
||||||
|
if ( buffer !== '' ) {
|
||||||
|
$current.append( buffer );
|
||||||
|
buffer = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function openAnnotation( annotation ) {
|
function openAnnotation( annotation ) {
|
||||||
|
flushBuffer();
|
||||||
// Create a new DOM node and descend into it
|
// Create a new DOM node and descend into it
|
||||||
$ann = ve.ce.annotationFactory.create( annotation.getType(), annotation ).$;
|
$ann = ve.ce.annotationFactory.create( annotation.getType(), annotation ).$;
|
||||||
$current.append( $ann );
|
$current.append( $ann );
|
||||||
|
@ -88,6 +97,7 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
function closeAnnotation() {
|
function closeAnnotation() {
|
||||||
|
flushBuffer();
|
||||||
// Traverse up
|
// Traverse up
|
||||||
$current = $current.parent();
|
$current = $current.parent();
|
||||||
}
|
}
|
||||||
|
@ -111,10 +121,15 @@ ve.ce.ContentBranchNode.prototype.getRenderedContents = function () {
|
||||||
openAnnotation, closeAnnotation
|
openAnnotation, closeAnnotation
|
||||||
);
|
);
|
||||||
|
|
||||||
// Output the actual HTML
|
// Handle the actual HTML
|
||||||
$current.append( itemHtml );
|
if ( typeof itemHtml === 'string' ) {
|
||||||
|
buffer += itemHtml;
|
||||||
|
} else {
|
||||||
|
flushBuffer();
|
||||||
|
$current.append( itemHtml );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
flushBuffer();
|
||||||
return $wrapper.contents();
|
return $wrapper.contents();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue