Skip to content

Commit

Permalink
fix(DOMRenderer): defense browser for webkit below 537
Browse files Browse the repository at this point in the history
  • Loading branch information
Younkue committed Nov 30, 2017
1 parent 50e0136 commit 177600b
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 85 deletions.
2 changes: 1 addition & 1 deletion dist/infinitegrid.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/infinitegrid.min.js.map

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions dist/infinitegrid.pkgd.js

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

2 changes: 1 addition & 1 deletion dist/infinitegrid.pkgd.js.map

Large diffs are not rendered by default.

49 changes: 24 additions & 25 deletions dist/infinitegrid.pkgd.min.js

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

2 changes: 1 addition & 1 deletion dist/infinitegrid.pkgd.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/parallax.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/parallax.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/parallax.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/parallax.min.js.map

Large diffs are not rendered by default.

41 changes: 21 additions & 20 deletions src/DOMRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
MULTI,
GROUPKEY_ATT,
CONTAINER_CLASSNAME,
// DEFENSE_BROWSER,
DEFENSE_BROWSER,
} from "./consts";
import {
$,
Expand All @@ -15,6 +15,23 @@ import {
getStyles,
} from "./utils";


function _defense(element) {
const container = document.createElement("div");

container.className = CONTAINER_CLASSNAME;
container.style.height = "100%";

const children = element.children;
const length = children.length; // for IE8

for (let i = 0; i < length; i++) {
container.appendChild(children[0]);
}

element.appendChild(container);
return container;
}
export default class DOMRenderer {
static renderItem(item, styles) {
if (item.el) {
Expand Down Expand Up @@ -125,29 +142,13 @@ export default class DOMRenderer {
element.style[`overflow${target[0]}`] = "scroll";
element.style[`overflow${target[1]}`] = "hidden";
this.view = element;
this.container = element; // DEFENSE_BROWSER ? this._defense(element) : element;
// defense code for android < 4.4 or webkit < 537
this.container = !this.options.isVertical && DEFENSE_BROWSER ? _defense(element) : element;
} else {
this.view = window;
this.container = element;
}
}
_defense(element) {
const container = document.createElement("div");

container.className = CONTAINER_CLASSNAME;

const children = element.children;
const length = children.length; // for IE8
const target = this.options.isVertical ? ["Y", "X"] : ["X", "Y"];

for (let i = 0; i < length; i++) {
container.appendChild(children[0]);
}
element.style[`overflow${target[0]}`] = "scroll";
element.style[`overflow${target[1]}`] = "hidden";
element.appendChild(container);
return container;
}
append(items) {
this._insert(items, APPEND, {
top: DUMMY_POSITION,
Expand Down Expand Up @@ -206,7 +207,7 @@ export default class DOMRenderer {
return this._size.viewport;
}
setContainerSize(size) {
if (!this.options.isOverflowScroll) {
if (!this.options.isOverflowScroll || (!this.options.isVertical && DEFENSE_BROWSER)) {
this.container.style[this.options.isVertical ? "height" : "width"] = `${size}px`;
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/consts.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export const ALIGN = {
export const LOADING_APPEND = 1;
export const LOADING_PREPEND = 2;
export const PROCESSING = 4;
export const DEFENSE_BROWSER = /android/.test(agent);

alert(agent);
/*
"Mozilla/5.0 (Linux; Android 4.3; SHV-E250S Build/JSS15J) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.84 Mobile Safari/537.36"
*/

const webkit = /applewebkit\/([\d|.]*)/g.exec(agent);
const webkitVersion = (webkit && parseInt(webkit[1], 10)) || 0;

export const DEFENSE_BROWSER = webkitVersion < 537;

0 comments on commit 177600b

Please sign in to comment.