Skip to content

Commit

Permalink
Merge pull request #53 from asheshv/ESLINT
Browse files Browse the repository at this point in the history
  • Loading branch information
cheton committed Dec 10, 2019
2 parents 246f01d + 557c834 commit 7bf037e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"build": "babel --out-dir ./lib ./src",
"build-examples": "cd examples; NODE_ENV=production webpack-cli",
"pack-examples": "npm run build-examples && zip -r examples.zip examples/{dist,vendor,*.html,*.css}",
"test": "tap test/*.js --no-timeout --node-arg=--require --node-arg=@babel/register --node-arg=--require --node-arg=@babel/polyfill",
"test": "tap test/*.js --no-timeout --node-arg=--require --node-arg=@babel/register --node-arg=--require --node-arg=@babel/polyfill --reporter classic",
"dist": "webpack-cli; BUILD_ENV=dist webpack-cli",
"release": "mkdir -p releases; rm -f releases/*; cp -f dist/infinite-tree.css releases/infinite-tree-${npm_package_version}.css; cp -f dist/infinite-tree.js releases/infinite-tree-${npm_package_version}.js; cp -f dist/infinite-tree.min.js releases/infinite-tree-${npm_package_version}.min.js",
"lint": "npm run eslint && npm run stylint",
Expand Down
16 changes: 16 additions & 0 deletions src/clusterize.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ class Clusterize extends EventEmitter {
};

scrollElement = null;

contentElement = null;

rows = [];

cache = {};

scrollEventListener = (() => {
Expand Down Expand Up @@ -128,13 +131,15 @@ class Clusterize extends EventEmitter {
addEventListener(this.scrollElement, 'scroll', this.scrollEventListener);
addEventListener(window, 'resize', this.resizeEventListener);
}

destroy(clean) {
removeEventListener(this.scrollElement, 'scroll', this.scrollEventListener);
removeEventListener(window, 'resize', this.resizeEventListener);

const rows = clean ? this.generateEmptyRow() : this.rows();
this.setContent(rows.join(''));
}

update(rows) {
this.rows = ensureArray(rows);

Expand All @@ -150,10 +155,12 @@ class Clusterize extends EventEmitter {
// Restore scroll position
this.scrollElement.scrollTop = scrollTop;
}

clear() {
this.rows = [];
this.update();
}

append(rows) {
rows = ensureArray(rows);
if (!rows.length) {
Expand All @@ -162,6 +169,7 @@ class Clusterize extends EventEmitter {
this.rows = this.rows.concat(rows);
this.changeDOM();
}

prepend(rows) {
rows = ensureArray(rows);
if (!rows.length) {
Expand All @@ -170,6 +178,7 @@ class Clusterize extends EventEmitter {
this.rows = rows.concat(this.rows);
this.changeDOM();
}

computeHeight() {
if (!this.rows.length) {
return {
Expand Down Expand Up @@ -203,13 +212,15 @@ class Clusterize extends EventEmitter {
};
}
}

getCurrentClusterIndex() {
const { blockHeight, clusterHeight } = this.state;
if (!blockHeight || !clusterHeight) {
return 0;
}
return Math.floor(this.scrollElement.scrollTop / (clusterHeight - blockHeight)) || 0;
}

generateEmptyRow() {
const { tag, emptyText, emptyClass } = this.options;

Expand All @@ -231,6 +242,7 @@ class Clusterize extends EventEmitter {

return [emptyRow.outerHTML];
}

renderExtraTag(className, height) {
const tag = document.createElement(this.options.tag);
const prefix = 'infinite-tree-';
Expand All @@ -246,6 +258,7 @@ class Clusterize extends EventEmitter {

return tag.outerHTML;
}

changeDOM() {
if (!this.state.clusterHeight && this.rows.length > 0) {
if (ie && ie <= 9 && !this.options.tag) {
Expand Down Expand Up @@ -312,6 +325,7 @@ class Clusterize extends EventEmitter {
this.contentElement.lastChild.style.height = bottomOffset + 'px';
}
}

setContent(content) {
// For IE 9 and older versions
if (ie && ie <= 9 && this.options.tag === 'tr') {
Expand All @@ -332,6 +346,7 @@ class Clusterize extends EventEmitter {
this.contentElement.innerHTML = content;
}
}

getChildNodes(tag) {
const childNodes = tag.children;
const nodes = [];
Expand All @@ -343,6 +358,7 @@ class Clusterize extends EventEmitter {

return nodes;
}

checkChanges(type, value) {
const changed = (value !== this.cache[type]);
this.cache[type] = value;
Expand Down
Loading

0 comments on commit 7bf037e

Please sign in to comment.