Skip to content

Commit

Permalink
Refreshing row height after window resize. Added .refresh() method to…
Browse files Browse the repository at this point in the history
… call it manually when necessary. Fixes #29 #31
  • Loading branch information
NeXTs committed Jul 1, 2015
1 parent df737ce commit 2c93792
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 17 deletions.
31 changes: 25 additions & 6 deletions clusterize.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Clusterize.js - v0.7.1 - 2015-06-04
/*! Clusterize.js - v0.8.0 - 2015-07-01
* http://NeXTs.github.com/Clusterize.js/
* Copyright (c) 2015 Denis Lukov; Licensed MIT */

Expand Down Expand Up @@ -82,17 +82,27 @@

// adding scroll handler
var last_cluster = false,
scrollEv = function () {
scrollEv = function(e) {
if (last_cluster != (last_cluster = self.getClusterNum()))
self.insertToDOM(rows, cache);
},
resize_debounce = 0,
resizeEv = function(e) {
clearTimeout(resize_debounce);
resize_debounce = setTimeout(self.refresh, 100);
}
on('scroll', self.scroll_elem, scrollEv);
on('resize', window, resizeEv);

// public methods
self.destroy = function(clean) {
off('scroll', self.scroll_elem, scrollEv);
off('resize', window, resizeEv);
self.html((clean ? self.generateEmptyRow() : rows).join(''));
}
self.refresh = function() {
self.getRowsHeight(rows) && self.update(rows);
}
self.update = function(new_rows) {
rows = isArray(new_rows)
? new_rows
Expand Down Expand Up @@ -139,17 +149,26 @@
exploreEnvironment: function(rows) {
var opts = this.options;
opts.content_tag = this.content_elem.tagName.toLowerCase();
if( ! opts.item_height || ! opts.tag) {
if( ! rows.length) return;
if(ie && ie <= 9) opts.tag = rows[0].split('<')[1].split(' ')[0].split('>')[0];
if( ! rows.length) return;
if(ie && ie <= 9 && ! opts.tag) opts.tag = rows[0].split('<')[1].split(' ')[0].split('>')[0].toLowerCase();
if(this.content_elem.children.length <= 1) {
this.html(rows[0] + rows[0] + rows[0]);
var node = this.content_elem.children[1];
if( ! opts.tag) opts.tag = node.tagName.toLowerCase();
opts.item_height = node.offsetHeight;
}
this.getRowsHeight(rows);
},
getRowsHeight: function(rows) {
var opts = this.options,
prev_item_height = opts.item_height;
opts.cluster_height = 0
if( ! rows.length) return;
var nodes = this.content_elem.children;
opts.item_height = nodes[Math.ceil(nodes.length / 2)].offsetHeight;
opts.block_height = opts.item_height * opts.rows_in_block;
opts.rows_in_cluster = opts.blocks_in_cluster * opts.rows_in_block;
opts.cluster_height = opts.blocks_in_cluster * opts.block_height;
return prev_item_height != opts.item_height;
},
// get current cluster number
getClusterNum: function () {
Expand Down
22 changes: 11 additions & 11 deletions clusterize.min.js

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

0 comments on commit 2c93792

Please sign in to comment.