Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some additional functionality #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion src/javascripts/nav-priority.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@
'</li>',
containerSelector: 'ul',
containerWidthOffset: 10,
threshold: 4
threshold: 4,
menuItemOverflow: null
}

/*
Expand Down Expand Up @@ -189,6 +190,9 @@
NavPriority.prototype.addToOverflow = function (item, breakpoint) {
this.overflowList.insertBefore(item, this.overflowList.firstChild)

if (typeof (this.options.menuItemOverflow) === 'function')
this.options.menuItemOverflow(item, true)

// ADD: link to overflow menu items
this.overflowBreakpoints.unshift(breakpoint)

Expand All @@ -215,6 +219,9 @@
// Note: AppendChild is buggy with nested submenu
this.navList.insertBefore(item, this.overflowDropdown.parentNode)

if (typeof (this.options.menuItemOverflow) === 'function')
this.options.menuItemOverflow(item, false)

return this.overflowBreakpoints
}

Expand Down Expand Up @@ -305,6 +312,20 @@
return this.element
}

NavPriority.prototype.recalculateBreakpoints = function () {
// Remove items, which can be added back to the menu
while (this.overflowList.children.length) {
this.removeFromOverflow(this.overflowList.children[0], this.overflowBreakpoints[0])
}
// Calculate navigation breakpoints
var newBreakpoints = this.getBreakpoints()
// Check against current breakpoints to determine whether anything has changed
if (newBreakpoints.length !== this.breakpoints || this.breakpoints.some(function (b, idx) { return newBreakpoints[idx] !== b })) {
this.breakpoints = newBreakpoints
}
this.reflowNavigation()
}

/*
* Priority navigation plugin method
*/
Expand Down