Skip to content

Commit

Permalink
improve performance #1
Browse files Browse the repository at this point in the history
  • Loading branch information
brunjo committed Mar 8, 2014
1 parent d888201 commit bc2ac1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
21 changes: 9 additions & 12 deletions jquery.row-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
options = this.data('grid-options');
var $lastRow = this.children('.' + options.lastRowClass);
var items = $lastRow.nextAll().add($lastRow);
layout(this, options, items);
layout(this[0], options, items);
} else {
options = $.extend( {}, $.fn.rowGrid.defaults, options );
var $container = this;
$container.data('grid-options', options);
layout($container, options);
this.data('grid-options', options);
layout(this[0], options);

if(options.resize) {
$(window).on('resize', {container: $container}, function(event) {
$(window).on('resize', {container: this[0]}, function(event) {
layout(event.data.container, options);
});
}
Expand All @@ -40,27 +39,25 @@
firstItemClass: null
};

function layout($container, options, items) {
function layout(container, options, items) {
var rowWidth = 0,
rowElems = [],
items = items || $container.children(options.itemSelector),
items = items || container.querySelectorAll(options.itemSelector),
itemsSize = items.length;

$container.children('.' + options.lastRowClass).removeClass(options.lastRowClass);

for(var index = 0; index < itemsSize; ++index) {
items[index].removeAttribute('style');
if (items[index].classList) {
items[index].classList.remove(options.firstItemClass);
items[index].classList.remove(options.firstItemClass, options.lastRowClass);
}
else {
// IE <10
items[index].className = items[index].className.replace(new RegExp('(^|\\b)' + options.firstItemClass + '(\\b|$)', 'gi'), ' ');
items[index].className = items[index].className.replace(new RegExp('(^|\\b)' + options.firstItemClass + '|' + options.lastRowClass + '(\\b|$)', 'gi'), ' ');
}
}

// read
var containerWidth = $container[0].clientWidth;
var containerWidth = container.clientWidth;
var itemAttrs = [];
for(var i = 0; i < itemsSize; ++i) {
itemAttrs[i] = {
Expand Down
8 changes: 4 additions & 4 deletions jquery.row-grid.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit bc2ac1c

Please sign in to comment.