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.4
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.11.0
Choose a head ref
  • 8 commits
  • 9 files changed
  • 3 contributors

Commits on Jan 16, 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
    2b06003 View commit details
  2. Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    1c6a5b5 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    7bc32e5 View commit details
  4. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    1e87eac View commit details
  5. Copy the full SHA
    5579a1c View commit details
  6. Copy the full SHA
    9a62aa4 View commit details
  7. Feature/multiple classes (#357)

    Feature/multiple classes
    WickyNilliams authored Jan 16, 2020
    Copy the full SHA
    34d276d View commit details
  8. 0.11.0

    WickyNilliams committed Jan 16, 2020
    Copy the full SHA
    0e00cb6 View commit details
Showing with 141 additions and 81 deletions.
  1. +2 −2 .eslintrc
  2. +3 −0 cypress/.eslintrc
  3. +0 −16 cypress/integration/.eslintrc
  4. +22 −2 cypress/integration/headroom.spec.js
  5. +2 −2 cypress/plugins/index.js
  6. +90 −55 package-lock.json
  7. +3 −1 package.json
  8. +8 −0 src/.eslintrc
  9. +11 −3 src/Headroom.js
4 changes: 2 additions & 2 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2018,
"sourceType": "module"
},
"env": {
"browser": true,
"node": true
},
"extends": "eslint:recommended",
"extends": ["eslint:recommended"],
"rules": {
"no-unused-expressions": "error",
"no-bitwise": "error",
3 changes: 3 additions & 0 deletions cypress/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": ["plugin:cypress/recommended"]
}
16 changes: 0 additions & 16 deletions cypress/integration/.eslintrc

This file was deleted.

24 changes: 22 additions & 2 deletions cypress/integration/headroom.spec.js
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ describe("Headroom", function() {
win.hr = new win.Headroom(win.document.querySelector("header"), options);
win.hr.init();
});
cy.wait(200);
cy.wait(200); // eslint-disable-line cypress/no-unnecessary-waiting
};

beforeEach(() => {
@@ -241,6 +241,7 @@ describe("Headroom", function() {
}
});

// eslint-disable-next-line cypress/no-unnecessary-waiting
cy.wait(0).should(() => {
expect(topStatus).to.equal("top");
expect(pinStatus).to.equal(undefined);
@@ -287,7 +288,7 @@ describe("Headroom", function() {

cy.window().then(win => {
expect(win.hr.classes).to.deep.contain(classes);
const { initial, pinned, ...defaultClasses } = win.hr.classes;
const { initial, pinned, ...defaultClasses } = win.hr.classes; // eslint-disable-line no-unused-vars
expect(win.hr.classes).to.deep.contain(defaultClasses);
});
});
@@ -307,5 +308,24 @@ describe("Headroom", function() {
expect(win.hr.classes).to.deep.equal(win.Headroom.options.classes);
});
});

it("handles multiple classes", () => {
initialiseHeadroom({
classes: {
pinned: "headroom--pinned foo",
unpinned: "headroom--unpinned bar"
}
});

cy.scrollTo(0, 50);
cy.get("header")
.should("not.be.pinned")
.should("have.class", "bar");

cy.scrollTo(0, 25);
cy.get("header")
.should("be.pinned")
.should("have.class", "foo");
});
});
});
4 changes: 2 additions & 2 deletions cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

module.exports = (on, config) => {
module.exports = (/*on, config*/) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
};
145 changes: 90 additions & 55 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "headroom.js",
"version": "0.10.4",
"version": "0.11.0",
"description": "Give your page some headroom. Hide your header until you need it",
"main": "dist/headroom.js",
"files": [
@@ -31,6 +31,8 @@
},
"devDependencies": {
"cypress": "^3.4.1",
"eslint": "^6.5.0",
"eslint-plugin-cypress": "^2.7.0",
"rollup": "^1.19.4",
"rollup-plugin-eslint": "^7.0.0",
"rollup-plugin-filesize": "^6.2.0",
8 changes: 8 additions & 0 deletions src/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"browser": true
}
}
14 changes: 11 additions & 3 deletions src/Headroom.js
Original file line number Diff line number Diff line change
@@ -168,15 +168,23 @@ Headroom.prototype = {
},

addClass: function(className) {
this.elem.classList.add(this.classes[className]);
this.elem.classList.add.apply(
this.elem.classList,
this.classes[className].split(" ")
);
},

removeClass: function(className) {
this.elem.classList.remove(this.classes[className]);
this.elem.classList.remove.apply(
this.elem.classList,
this.classes[className].split(" ")
);
},

hasClass: function(className) {
return this.elem.classList.contains(this.classes[className]);
return this.classes[className].split(" ").every(function(cls) {
return this.classList.contains(cls);
}, this.elem);
},

update: function(details) {