summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Calviño Sánchez <danxuliu@gmail.com>2018-11-13 16:00:00 +0100
committerDaniel Calviño Sánchez <danxuliu@gmail.com>2018-11-20 12:18:15 +0100
commitcad9d89517150c1db4cc69ba364e93c7e3dc25b2 (patch)
tree2c3c05b4bbe58d069fc4044fc50f1bcdd1f08e48
parent68194dcdac38462a4d810fb46a2835f7dba1cfee (diff)
Extract the load of next elements to its own method
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
-rw-r--r--js/views/virtuallist.js33
1 files changed, 22 insertions, 11 deletions
diff --git a/js/views/virtuallist.js b/js/views/virtuallist.js
index 55adae454..e2f0a017a 100644
--- a/js/views/virtuallist.js
+++ b/js/views/virtuallist.js
@@ -172,6 +172,7 @@
this._appendedElementsBuffer = document.createDocumentFragment();
delete this._$firstAppendedElement;
+ delete this._$lastAppendedElement;
},
prependElement: function($element) {
@@ -212,6 +213,7 @@
if (!this._$firstAppendedElement) {
this._$firstAppendedElement = $element;
}
+ this._$lastAppendedElement = $element;
},
prependElementEnd: function() {
@@ -294,24 +296,35 @@
},
appendElementEnd: function() {
+ this._loadNextElements(
+ this._$firstAppendedElement,
+ this._$lastAppendedElement,
+ this._appendedElementsBuffer
+ );
+
+ delete this._appendedElementsBuffer;
+
+ this.updateVisibleElements();
+ },
+
+ _loadNextElements: function($firstElementToLoad, $lastElementToLoad, elementsBuffer) {
var $wrapper = $('<div class="wrapper"></div>');
$wrapper._top = 0;
- if (this._$firstAppendedElement._previous) {
- $wrapper.css('top', this._$firstAppendedElement._previous._topRaw);
- $wrapper._top = this._$firstAppendedElement._previous._topRaw;
+ if ($firstElementToLoad._previous) {
+ $wrapper.css('top', $firstElementToLoad._previous._topRaw);
+ $wrapper._top = $firstElementToLoad._previous._topRaw;
// Include the previous element, as it may change the
// position of the newest element due to collapsing margins
- $wrapper.append(this._$firstAppendedElement._previous.clone());
+ $wrapper.append($firstElementToLoad._previous.clone());
}
this._$container.append($wrapper);
var previousWrapperHeight = this._getElementHeight($wrapper);
- $wrapper.append(this._appendedElementsBuffer);
- delete this._appendedElementsBuffer;
+ $wrapper.append(elementsBuffer);
var wrapperHeightDifference = this._getElementHeight($wrapper) - previousWrapperHeight;
@@ -320,10 +333,10 @@
// number.
this._$wrapperBackground.height(this._getElementHeight(this._$wrapperBackground) + wrapperHeightDifference);
- while (this._$firstAppendedElement) {
- this._updateCache(this._$firstAppendedElement, $wrapper);
+ while ($firstElementToLoad !== $lastElementToLoad._next) {
+ this._updateCache($firstElementToLoad, $wrapper);
- this._$firstAppendedElement = this._$firstAppendedElement._next;
+ $firstElementToLoad = $firstElementToLoad._next;
}
// Remove the temporal wrapper used to layout and get the height of
@@ -331,8 +344,6 @@
$wrapper.detach();
$wrapper.children().detach();
$wrapper.remove();
-
- this.updateVisibleElements();
},
/**