Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: WickyNilliams/headroom.js
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.10.3
Choose a base ref
...
head repository: WickyNilliams/headroom.js
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.10.4
Choose a head ref
  • 3 commits
  • 4 files changed
  • 2 contributors

Commits on Jan 9, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    d1388fd View commit details
  2. ensure top/bottom classes are added on page load (#356)

    ensure top/bottom classes are added on page load
    WickyNilliams authored Jan 9, 2020

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    42443b4 View commit details
  3. 0.10.4

    WickyNilliams committed Jan 9, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7956f87 View commit details
Showing with 33 additions and 50 deletions.
  1. +29 −48 cypress/integration/headroom.spec.js
  2. +1 −1 package-lock.json
  3. +1 −1 package.json
  4. +2 −0 src/trackScroll.js
77 changes: 29 additions & 48 deletions cypress/integration/headroom.spec.js
Original file line number Diff line number Diff line change
@@ -24,7 +24,10 @@ describe("Headroom", function() {
it("works!", function() {
initialiseHeadroom();

cy.get("header").should("be.initialised");
cy.get("header")
.should("be.initialised")
.should("be.top")
.should("not.be.bottom");

cy.scrollTo(0, 50);
cy.get("header")
@@ -215,83 +218,61 @@ describe("Headroom", function() {
});

it("fires callbacks", () => {
const flags = {
pin: false,
unpin: false,
top: false,
notTop: false,
bottom: false,
notBottom: false
};
let pinStatus, topStatus, bottomStatus;

initialiseHeadroom({
onPin: () => {
flags.pin = true;
pinStatus = "pinned";
},
onUnpin: () => {
flags.unpin = true;
pinStatus = "unpinned";
},
onTop: () => {
flags.top = true;
topStatus = "top";
},
onNotTop: () => {
flags.notTop = true;
topStatus = "notTop";
},
onBottom: () => {
flags.bottom = true;
bottomStatus = "bottom";
},
onNotBottom: () => {
flags.notBottom = true;
bottomStatus = "notBottom";
}
});

cy.wait(0).should(() => {
expect(topStatus).to.equal("top");
expect(pinStatus).to.equal(undefined);
expect(bottomStatus).to.equal("notBottom");
});

cy.scrollTo(0, 50);
cy.should(() => {
expect(flags).to.deep.equal({
unpin: true,
notTop: true,
notBottom: true,
pin: false,
top: false,
bottom: false
});
expect(topStatus).to.equal("notTop");
expect(pinStatus).to.equal("unpinned");
expect(bottomStatus).to.equal("notBottom");
});

cy.scrollTo(0, 25);
cy.should(() => {
expect(flags).to.deep.equal({
unpin: true,
notTop: true,
notBottom: true,
pin: true,
top: false,
bottom: false
});
expect(topStatus).to.equal("notTop");
expect(pinStatus).to.equal("pinned");
expect(bottomStatus).to.equal("notBottom");
});
cy.wait(20).then(() => {});

cy.scrollTo(0, 0);
cy.should(() => {
expect(flags).to.deep.equal({
unpin: true,
notTop: true,
notBottom: true,
pin: true,
top: true,
bottom: false
});
expect(topStatus).to.equal("top");
expect(pinStatus).to.equal("pinned");
expect(bottomStatus).to.equal("notBottom");
});

cy.scrollTo("bottom");
cy.should(() => {
expect(flags).to.deep.equal({
unpin: true,
notTop: true,
notBottom: true,
pin: true,
top: true,
bottom: true
});
expect(topStatus).to.equal("notTop");
expect(pinStatus).to.equal("unpinned");
expect(bottomStatus).to.equal("bottom");
});
});

2 changes: 1 addition & 1 deletion package-lock.json

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "headroom.js",
"version": "0.10.3",
"version": "0.10.4",
"description": "Give your page some headroom. Hide your header until you need it",
"main": "dist/headroom.js",
"files": [
2 changes: 2 additions & 0 deletions src/trackScroll.js
Original file line number Diff line number Diff line change
@@ -44,7 +44,9 @@ export default function trackScroll(element, options, callback) {
var eventOptions = isPassiveSupported
? { passive: true, capture: false }
: false;

element.addEventListener("scroll", handleScroll, eventOptions);
update();

return {
destroy: function() {