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.0
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.2
Choose a head ref
  • 3 commits
  • 5 files changed
  • 2 contributors

Commits on Sep 13, 2019

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    884a0c1 View commit details
  2. properly merge classes from options object. fixes #335 (#337)

    properly merge classes from options object. fixes #335
    WickyNilliams authored Sep 13, 2019

    Verified

    This commit was signed with the committer’s verified signature.
    crazy-max CrazyMax
    Copy the full SHA
    8e9616d View commit details
  3. 0.10.2

    WickyNilliams committed Sep 13, 2019

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    04eec74 View commit details
Showing with 39 additions and 3 deletions.
  1. +3 −0 cypress/integration/.eslintrc
  2. +33 −0 cypress/integration/headroom.spec.js
  3. +1 −1 package-lock.json
  4. +1 −1 package.json
  5. +1 −1 src/Headroom.js
3 changes: 3 additions & 0 deletions cypress/integration/.eslintrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"parserOptions": {
"ecmaVersion": 2018
},
"env": {
"browser": false
},
33 changes: 33 additions & 0 deletions cypress/integration/headroom.spec.js
Original file line number Diff line number Diff line change
@@ -288,4 +288,37 @@ describe("Headroom", function() {
});
});
});

describe("handling options and defaults", () => {
it("merges our own classes and preserves other defaults", () => {
const classes = {
initial: "foo",
pinned: "foo--pinned"
};

initialiseHeadroom({ classes });

cy.window().then(win => {
expect(win.hr.classes).to.deep.contain(classes);
const { initial, pinned, ...defaultClasses } = win.hr.classes;
expect(win.hr.classes).to.deep.contain(defaultClasses);
});
});

it("assigns default classes if no options supplied", () => {
initialiseHeadroom();

cy.window().then(win => {
expect(win.hr.classes).to.deep.equal(win.Headroom.options.classes);
});
});

it("assigns default classes if no no classes supplied", () => {
initialiseHeadroom({ tolerance: 5 });

cy.window().then(win => {
expect(win.hr.classes).to.deep.equal(win.Headroom.options.classes);
});
});
});
});
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.0",
"version": "0.10.2",
"description": "Give your page some headroom. Hide your header until you need it",
"main": "dist/headroom.js",
"files": [
2 changes: 1 addition & 1 deletion src/Headroom.js
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ function normalizeTolerance(t) {
function Headroom(elem, options) {
options = options || {};
Object.assign(this, Headroom.options, options);
Object.assign(this.classes, Headroom.options.classes, options.classes);
this.classes = Object.assign({}, Headroom.options.classes, options.classes);

this.elem = elem;
this.tolerance = normalizeTolerance(this.tolerance);