Skip to content

Commit

Permalink
test(InfiniteGrid): test LayoutManger and Infinite
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Jul 3, 2018
1 parent aa16a16 commit f30dd39
Show file tree
Hide file tree
Showing 14 changed files with 730 additions and 389 deletions.
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
"./node_modules/babel-polyfill/dist/polyfill.js",
"./node_modules/lite-fixture/index.js",
"./test/unit/**/*.spec.js",
'test/unit/image/*.jpg',
Expand Down
37 changes: 36 additions & 1 deletion package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
"babel-plugin-transform-es3-member-expression-literals": "^6.22.0",
"babel-plugin-transform-es3-property-literals": "^6.22.0",
"babel-plugin-transform-object-assign": "^6.22.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"chai": "^4.1.2",
"chalk": "^2.3.0",
Expand Down
1 change: 0 additions & 1 deletion src/InfiniteGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -942,7 +942,6 @@ ig.on("imageError", e => {
* @ko 그리드 레이아웃에 사용한 엘리먼트와 속성, 이벤트를 해제한다
*/
destroy() {
this.off();
this._infinite.clear();
this._watcher.destroy();
this._layout.destroy();
Expand Down
21 changes: 12 additions & 9 deletions src/LayoutManager.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import AutoSizer from "./AutoSizer";
import ImageLoaded, {CHECK_ALL, CHECK_ONLY_ERROR} from "./ImageLoaded";
import ItemManager from "./ItemManager";
import {matchHTML} from "./utils";
import {matchHTML, $} from "./utils";
import {DUMMY_POSITION} from "./consts";
import DOMRenderer from "./DOMRenderer";

function hasTarget(...targets) {
return targets.every(target => ~target[0].indexOf(target[1]));
function hasTarget(target, value) {
return ~target.indexOf(value);
}

export default class LayoutMananger {
Expand Down Expand Up @@ -70,7 +70,7 @@ export default class LayoutMananger {

// remove item
const removeItem = () => {
if (hasTarget([removeTarget, element])) {
if (hasTarget(removeTarget, element)) {
return;
}
removeTarget.push(element);
Expand All @@ -84,19 +84,19 @@ export default class LayoutMananger {
removeItem();
return;
}
if (hasTarget([removeTarget, element])) {
if (hasTarget(removeTarget, element)) {
return;
}
target.parentNode.removeChild(target);
item.content = element.outerHTML;
if (hasTarget([replaceTarget, errorIndex])) {
if (hasTarget(replaceTarget, errorIndex)) {
return;
}
replaceTarget.push(errorIndex);
};
// replace image
const replace = src => {
if (hasTarget([removeTarget, element])) {
if (hasTarget(removeTarget, element)) {
return;
}
if (src) {
Expand All @@ -116,18 +116,21 @@ export default class LayoutMananger {
}
}
item.content = element.outerHTML;
if (hasTarget([replaceTarget, errorIndex])) {
if (hasTarget(replaceTarget, errorIndex)) {
return;
}
replaceTarget.push(errorIndex);
};
// replace item
const replaceItem = content => {
if (hasTarget([removeTarget, element], [replaceTarget, errorIndex])) {
if (hasTarget(removeTarget, element)) {
return;
}
element.innerHTML = content;
item.content = element.outerHTML;
if (hasTarget(replaceTarget, errorIndex)) {
return;
}
replaceTarget.push(errorIndex);
};

Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import DOMRenderer from "./DOMRenderer";
import Watcher from "./Watcher";
import ItemManager from "./ItemManager";
import Infinite from "./Infinite";
import LayoutManger from "./LayoutManager";

export {
GridLayout,
Expand All @@ -27,5 +28,6 @@ export {
DOMRenderer,
Watcher,
ItemManager,
LayoutManger,
};
export default InfiniteGrid;
8 changes: 4 additions & 4 deletions test/manual/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
<button class="layout_false">layout(false)</button>
<button class="getStatus">getStatus</button>
<button class="setStatus">setStatus</button>
<button class="enableParallax">enable Parallax</button>
<button class="disableParallax">disable Parallax</button>
<button class="vertical">vertical</button>
<button class="horizontal">horizontal</button>
<button class="toggleParallax">enable Parallax</button>
<button class="toggleDirection">horizontal</button>
<button class="toggleFit">disable useFit</button>
<button class="toggleOverflow">disable overflow</button>
</div>
<style>

Expand Down
40 changes: 17 additions & 23 deletions test/manual/js/basic.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ var isParallax = false;
var _overflow = true;
var _layout;
var _horizontal;
var _useFit = true;

var grid = document.querySelector("#grid");
$(grid).click(function (e) {
Expand All @@ -33,6 +34,7 @@ function createGrid() {
horizontal: _horizontal,
threshold: 50,
isOverflowScroll: _overflow,
useFit: _useFit,
// useRecycle: false,
});
ig.setLoadingBar("<div class=\"loading_bar\">LOADING</div>");
Expand Down Expand Up @@ -172,40 +174,32 @@ function setStatus() {
groups = _groups;
ig.setStatus(_status);
}
function enableParallax() {
isParallax = true;
parallax.refresh(ig.getItems(), document.body.scrollTop);
}
function disableParallax() {
isParallax = false;
}
function getStatus() {
_status = ig.getStatus();
_groups = groups;
}
function vertical() {
_horizontal = false;
createGrid();
$("#grid").attr("data-direction", "vertical");
window[_layout]();
function toggleParallax(target) {
isParallax = !isParallax;
isParallax && parallax.refresh(ig.getItems(), document.body.scrollTop);
target.innerHTML = isParallax ? "disable Parallax" : "enable Parallax";
}
function horizontal() {
_horizontal = true;
function toggleDirection(target) {
_horizontal = !_horizontal;
createGrid();
$("#grid").attr("data-direction", "horizontal");
$("#grid").attr("data-direction", _horizontal ? "horizontal" : "vertical");
target.innerHTML = _horizontal ? "vertical" : "horizontal";
window[_layout]();
}
function overflow() {
_overflow = true;
function toggleOverflow(target) {
_overflow = !_overflow;
createGrid();
$("#grid").attr("data-overflow", "true");
target.innerHTML = _overflow ? "disable overflow" : "enable overflow";
window[_layout]();
}
function overflow_false() {
_overflow = false;
function toggleFit(target) {
_useFit = !_useFit;
createGrid();
$("#grid").attr("data-overflow", "false");
target.innerHTML = _useFit ? "disable useFit" : "enable useFit";
window[_layout]();
}


}
2 changes: 1 addition & 1 deletion test/manual/js/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $("#controller").click(function(e) {
}
var className = $(target).attr("class");

window[className]();
window[className](target);

});

Loading

0 comments on commit f30dd39

Please sign in to comment.