Skip to content

Commit

Permalink
Added enableLocationHash option
Browse files Browse the repository at this point in the history
  • Loading branch information
lcdsantos committed Nov 14, 2017
1 parent 5508a42 commit 645f9ea
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 23 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Include MenuSpy

`MenuSpy` will be available in the global scope.

Or install with NPM and require as a module
Or install via NPM/Yarn and require as a module

```
npm install menuspy
Expand Down Expand Up @@ -57,10 +57,11 @@ The `MenuSpy()` constructor accepts two arguments: the container element and an

## Options

| Option | Type | Default | Description |
| ------------------ | -------- | ----------------------------------- | ------------------------------------------------------------------------ |
| `menuItemSelector` | String | `a[href^="#"]` | Menu items selector. |
| `activeClass` | String | `active` | Class applied on menu item relative to the currently visible section. |
| `threshold` | Integer | `15` | Ammount of space between your menu and the next section to be activated. |
| `hashTimeout` | Integer | `600` | Timeout to apply browser's hash location. |
| `callback` | Function | `function(currentItem) {}` | A function to be called every time a new menu item activates. |
| Option | Type | Default | Description |
| ---------------------| -------- | -------------------------- | ------------------------------------------------------------------------ |
| `menuItemSelector` | String | `a[href^="#"]` | Menu items selector. |
| `activeClass` | String | `active` | Class applied on menu item relative to the currently visible section. |
| `threshold` | Integer | `15` | Ammount of space between your menu and the next section to be activated. |
| `enableLocationHash` | Boolean | `true` | Enable or disable browser's hash location change. |
| `hashTimeout` | Integer | `600` | Timeout to apply browser's hash location. |
| `callback` | Function | `function(currentItem) {}` | A function to be called every time a new menu item activates. |
21 changes: 14 additions & 7 deletions dist/menuspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,12 @@ var MenuSpy = function MenuSpy(element, options) {
}

var defaults = {
menuItemSelector: 'a[href^="#"]',
activeClass : 'active',
threshold : 15,
hashTimeout : 600,
callback : null
menuItemSelector : 'a[href^="#"]',
activeClass : 'active',
threshold : 15,
enableLocationHash : true,
hashTimeout : 600,
callback : null
};

this.element = element;
Expand Down Expand Up @@ -138,7 +139,11 @@ MenuSpy.prototype.activateItem = function activateItem (inViewElm) {
if (!inViewElm) {
this.scrollItems.forEach(function (item) { return utils.removeClass(item.elm.parentNode, activeClass); });
this.lastInViewElm = null;
this.debouncedHashFn();

if (this.enableLocationHash) {
this.debouncedHashFn();
}

return;
}

Expand All @@ -155,7 +160,9 @@ MenuSpy.prototype.activateItem = function activateItem (inViewElm) {
callback.call(this$1, item);
}

this$1.debouncedHashFn();
if (this$1.enableLocationHash) {
this$1.debouncedHashFn();
}
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/menuspy.min.js

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

21 changes: 14 additions & 7 deletions src/menuspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ class MenuSpy {
}

const defaults = {
menuItemSelector: 'a[href^="#"]',
activeClass : 'active',
threshold : 15,
hashTimeout : 600,
callback : null
menuItemSelector : 'a[href^="#"]',
activeClass : 'active',
threshold : 15,
enableLocationHash : true,
hashTimeout : 600,
callback : null
};

this.element = element;
Expand Down Expand Up @@ -66,7 +67,11 @@ class MenuSpy {
if (!inViewElm) {
this.scrollItems.forEach((item) => utils.removeClass(item.elm.parentNode, activeClass));
this.lastInViewElm = null;
this.debouncedHashFn();

if (this.enableLocationHash) {
this.debouncedHashFn();
}

return;
}

Expand All @@ -83,7 +88,9 @@ class MenuSpy {
callback.call(this, item);
}

this.debouncedHashFn();
if (this.enableLocationHash) {
this.debouncedHashFn();
}
}
});
}
Expand Down

0 comments on commit 645f9ea

Please sign in to comment.