Skip to content

Instantly share code, notes, and snippets.

@johnyb
Created August 30, 2013 09:39
Show Gist options
  • Save johnyb/6388133 to your computer and use it in GitHub Desktop.
Save johnyb/6388133 to your computer and use it in GitHub Desktop.
tricky performance fix
// reloop to get proper height
return $.when.apply($, defs).pipe(function () {
var i, obj, node, top,
//isVisible is only needed in for loop; visible selectors are slow, avoid them if possible
isVisible = $i > 0 ? container.is(':visible') : undefined,
height;
for (i = 0; i < $i; i++) {
obj = labels.list[i];
obj.top = cumulatedLabelHeight + obj.pos * itemHeight;
node = labels.nodes.eq(i);
node.css({ top: obj.top + 'px' });
height = (isVisible && node.outerHeight(true)) || labelHeight;
cumulatedLabelHeight += (obj.height = height);
}
// add tail?
if (options.tail) {
tail = options.tail.call(self, all.slice()) || $();
top = all.length * itemHeight + cumulatedLabelHeight;
container.append(tail.css({ top: top + 'px' }));
cumulatedLabelHeight += tail.outerHeight(true);
}
node = clone = defs = null;
return cumulatedLabelHeight;
});
diff --git a/ui/apps/io.ox/core/tk/vgrid.js b/ui/apps/io.ox/core/tk/vgrid.js
index 217d7ec..2f6ba4d 100644
--- a/ui/apps/io.ox/core/tk/vgrid.js
+++ b/ui/apps/io.ox/core/tk/vgrid.js
@@ -463,7 +463,10 @@ define('io.ox/core/tk/vgrid',
}
// reloop to get proper height
return $.when.apply($, defs).pipe(function () {
- var i, obj, node, top, isVisible = container.is(':visible'), height;
+ var i, obj, node, top,
+ //isVisible is only needed in for loop; visible selectors are slow, avoid them if possible
+ isVisible = $i > 0 ? container.is(':visible') : undefined,
+ height;
for (i = 0; i < $i; i++) {
obj = labels.list[i];
obj.top = cumulatedLabelHeight + obj.pos * itemHeight;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment