-
-
Notifications
You must be signed in to change notification settings - Fork 677
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
2,462 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ | ||
"ignore": [ | ||
"node_modules/**" | ||
], | ||
"env": { | ||
"test": { | ||
"presets": [ | ||
"es2015" | ||
], | ||
"plugins": ["transform-object-assign"] | ||
}, | ||
"release": { | ||
"presets": [ | ||
["es2015", { | ||
"modules": false | ||
}] | ||
], | ||
"sourceMap": false, | ||
"plugins": ["transform-object-assign"] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# CHANGELOG | ||
|
||
## Version 9 | ||
|
||
#### 9.0.1 | ||
|
||
- Restored tests using Jest | ||
- Squashed a bug which didn't make images inside `picture` load correctly | ||
|
||
#### 9.0.0 | ||
|
||
LazyLoad is now _faster_ thanks to the [Intersection Observer API](https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API). | ||
|
||
**IMPORTANT!** Browser support changed. Find more information in the [README](README.md) file. | ||
|
||
#### 8.1.0 | ||
|
||
Updated from grunt to gulp (run with gulp scripts) | ||
|
||
#### 8.0.3 | ||
|
||
Added quotes in background image URLs, as suggested in #114 (thanks to @vseva) | ||
|
||
#### 8.0.2 | ||
|
||
Fixed a bug that affected performance | ||
|
||
#### 8.0.1 | ||
|
||
Fixed reference to old names in demo files | ||
|
||
#### 8.0.0 | ||
|
||
- The main file to include is now **`dist/lazyload.min.js`** as you would expect, and no longer `dist/lazyload.transpiled.min.js`. | ||
- The non-transpiled version is now named lazyload.es2015.js. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
import {setSources, setSourcesForPicture} from "../src/lazyLoad.setSources"; | ||
|
||
const lazyloadSettings = { | ||
data_src: "original", | ||
data_srcset: "originalSet" | ||
}; | ||
|
||
expect.extend({ | ||
toHaveAttributeValue: (element, attributeName, valueToVerify) => { | ||
const actualValue = element.getAttribute(attributeName); | ||
const pass = actualValue === valueToVerify; | ||
return pass ? { | ||
message: () => `${element.tagName} has attribute "${attributeName}" set to "${valueToVerify}"`, | ||
pass: true | ||
} : { | ||
message: () => `expected ${element.tagName} to have attribute "${attributeName}" set to "${valueToVerify}", received "${actualValue}"`, | ||
pass: false | ||
} | ||
} | ||
}); | ||
|
||
test("setSources is defined", () => { | ||
expect(typeof setSources).toBe("function"); | ||
}); | ||
|
||
describe("setSources for image", () => { | ||
let img; | ||
let img1 = "http://placehold.it/1x1"; | ||
let img200 = "http://placehold.it/200x200"; | ||
let img400 = "http://placehold.it/400x400"; | ||
|
||
beforeEach(() => { | ||
// Parent is a div | ||
let div = document.createElement("div"); | ||
div.appendChild(img = document.createElement("img")); | ||
}); | ||
|
||
test("...with initially empty src and srcset", () => { | ||
img.dataset = { | ||
"original": img200, | ||
"originalSet": img400 | ||
}; | ||
setSources(img, lazyloadSettings); | ||
expect(img).toHaveAttributeValue("src", img200); | ||
expect(img).toHaveAttributeValue("srcset", img400); | ||
}); | ||
|
||
test("...with initial values in src and srcset", () => { | ||
img.dataset = { | ||
"original": img200, | ||
"originalSet": img400 | ||
}; | ||
img.setAttribute("src", img1); | ||
img.setAttribute("srcset", img1); | ||
setSources(img, lazyloadSettings); | ||
expect(img).toHaveAttributeValue("src", img200); | ||
expect(img).toHaveAttributeValue("srcset", img400); | ||
}); | ||
test("...with initial values in src and srcset and empty data-*", () => { | ||
img.dataset = { | ||
"original": "", | ||
"originalSet": "" | ||
}; | ||
img.setAttribute("src", img200); | ||
img.setAttribute("srcset", img400); | ||
setSources(img, lazyloadSettings); | ||
expect(img).toHaveAttributeValue("src", img200); | ||
expect(img).toHaveAttributeValue("srcset", img400); | ||
}); | ||
}); | ||
|
||
describe("_setSources for iframe", () => { | ||
let iframe; | ||
let srcToLoad = "http://www.google.it"; | ||
let preloadedSrc = srcToLoad + "/doodle"; | ||
|
||
beforeEach(() => { | ||
iframe = document.createElement("iframe"); | ||
}); | ||
test("...with initially empty src", () => { | ||
iframe.dataset = { | ||
"original": srcToLoad | ||
}; | ||
setSources(iframe, lazyloadSettings); | ||
expect(iframe).toHaveAttributeValue("src", srcToLoad); | ||
}); | ||
test("...with initial value in src", () => { | ||
iframe.dataset = { | ||
"original": srcToLoad | ||
}; | ||
iframe.setAttribute("src", preloadedSrc); | ||
setSources(iframe, lazyloadSettings); | ||
expect(iframe).toHaveAttributeValue("src", srcToLoad); | ||
}); | ||
test("...with initial value in src and empty data-original", () => { | ||
iframe.dataset = { | ||
"original": "" | ||
}; | ||
iframe.setAttribute("src", preloadedSrc); | ||
setSources(iframe, lazyloadSettings); | ||
expect(iframe).toHaveAttributeValue("src", preloadedSrc); | ||
}); | ||
}); | ||
|
||
describe("_setSources for background image", () => { | ||
let element; | ||
let img100 = "http://placehold.it/100x100"; | ||
let img200 = "http://placehold.it/200x200"; | ||
|
||
beforeEach(() => { | ||
element = document.createElement("div"); | ||
}); | ||
|
||
test("...with initially empty style attribute", () => { | ||
element.dataset = { | ||
"original": img200 | ||
}; | ||
setSources(element, lazyloadSettings); | ||
// Test cheating: bug in JsDOM doesn't return the url("") with quotes inside | ||
expect(element.style.backgroundImage).toBe(`url(${img200})`); | ||
}); | ||
test("...with initially present style attribute", () => { | ||
element.dataset = { | ||
"original": img100 | ||
}; | ||
element.style = { | ||
padding: "1px" | ||
}; | ||
setSources(element, lazyloadSettings); | ||
// Test cheating: bug in JsDOM doesn't return the url("") with quotes inside | ||
expect(element.style.backgroundImage).toBe(`url(${img100})`); | ||
}); | ||
test("...with initially present style and background", () => { | ||
element.dataset = { | ||
"original": img200 | ||
}; | ||
element.style = { | ||
padding: "1px", | ||
backgroundImage: "url(" + img100 + ")" | ||
}; | ||
setSources(element, lazyloadSettings); | ||
// Test cheating: bug in JsDOM doesn't return the url("") with quotes inside | ||
expect(element.style.backgroundImage).toBe(`url(${img200})`); | ||
}); | ||
}); | ||
|
||
describe("setSourcesForPicture", () => { | ||
let picture, source1, source2, img; | ||
let img1 = "http://placehold.it/1x1"; | ||
let img100 = "http://placehold.it/100x100"; | ||
let img200 = "http://placehold.it/200x200"; | ||
let img400 = "http://placehold.it/400x400"; | ||
|
||
beforeEach(() => { | ||
// Parent is a picture | ||
picture = document.createElement("picture"); | ||
picture.appendChild(source1 = document.createElement("source")); | ||
picture.appendChild(source2 = document.createElement("source")); | ||
picture.appendChild(img = document.createElement("img")); | ||
}); | ||
|
||
test("...with initially empty srcset", () => { | ||
source1.dataset = {"originalSet": img200}; | ||
source2.dataset = {"originalSet": img400}; | ||
setSourcesForPicture(img, lazyloadSettings); | ||
expect(source1).toHaveAttributeValue("srcset", img200); | ||
expect(source2).toHaveAttributeValue("srcset", img400); | ||
}); | ||
|
||
test("...with initial value in srcset", () => { | ||
source1.dataset = {"originalSet": img200}; | ||
source2.dataset = {"originalSet": img400}; | ||
source1.setAttribute("srcset", img1); | ||
source2.setAttribute("srcset", img1); | ||
setSourcesForPicture(img, lazyloadSettings); | ||
expect(source1).toHaveAttributeValue("srcset", img200); | ||
expect(source2).toHaveAttributeValue("srcset", img400); | ||
}); | ||
|
||
test("...with initial value in srcset and empty data-srcset", () => { | ||
source1.dataset = {"originalSet": ""}; | ||
source2.dataset = {"originalSet": ""}; | ||
source1.setAttribute("srcset", img200); | ||
source2.setAttribute("srcset", img400); | ||
setSourcesForPicture(img, lazyloadSettings); | ||
expect(source1).toHaveAttributeValue("srcset", img200); | ||
expect(source2).toHaveAttributeValue("srcset", img400); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.