|
1 | 1 | /* |
2 | | - * priority-nav - v1.0.8 | (c) 2015 @gijsroge | MIT license |
| 2 | + * priority-nav - v1.0.9 | (c) 2015 @gijsroge | MIT license |
3 | 3 | * Repository: https://github.com/gijsroge/priority-navigation.git |
4 | 4 | * Description: Priority+ pattern navigation that hides menu items if they don't fit on screen. |
5 | 5 | * Demo: http://gijsroge.github.io/priority-nav.js/ |
|
169 | 169 | * Check if dropdown menu is already on page before creating it |
170 | 170 | * @param mainNavWrapper |
171 | 171 | */ |
172 | | - var prepareHtml = function (_this) { |
| 172 | + var prepareHtml = function (_this, settings) { |
| 173 | + |
173 | 174 | /** |
174 | 175 | * Create dropdow menu |
175 | 176 | * @type {HTMLElement} |
|
189 | 190 | * Move elements to the right spot |
190 | 191 | */ |
191 | 192 | _this.insertAfter(toggleWrapper, _this.querySelector(mainNav)); |
| 193 | + |
192 | 194 | toggleWrapper.appendChild(navDropdown); |
193 | 195 | toggleWrapper.appendChild(navDropdownToggle); |
194 | 196 |
|
|
266 | 268 | * Move item to array |
267 | 269 | * @param item |
268 | 270 | */ |
269 | | - priorityNav.doesItFit = function (_this) { |
| 271 | + priorityNav.doesItFit = function (_this, settings) { |
270 | 272 |
|
271 | 273 | /** |
272 | 274 | * Check if it is the first run |
|
465 | 467 | /** |
466 | 468 | * Bind eventlisteners |
467 | 469 | */ |
468 | | - var listeners = function (_this) { |
| 470 | + var listeners = function (_this, settings) { |
469 | 471 |
|
470 | 472 | // Check if an item needs to move |
471 | 473 | if(window.attachEvent) { |
472 | 474 | window.attachEvent("onresize", function() { |
473 | | - if(priorityNav.doesItFit)priorityNav.doesItFit(_this); |
| 475 | + if(priorityNav.doesItFit)priorityNav.doesItFit(_this, settings); |
474 | 476 | }); |
475 | 477 | } |
476 | 478 | else if(window.addEventListener) { |
477 | 479 | window.addEventListener("resize", function() { |
478 | | - if(priorityNav.doesItFit)priorityNav.doesItFit(_this); |
| 480 | + if(priorityNav.doesItFit)priorityNav.doesItFit(_this, settings); |
479 | 481 | }, true); |
480 | 482 | } |
481 | 483 |
|
|
551 | 553 | * @param n |
552 | 554 | * @param r |
553 | 555 | */ |
554 | | - Node.prototype.insertAfter = function(n,r) {this.insertBefore(n,r.nextSibling);}; |
| 556 | + if (supports && typeof Node !== "undefined"){ |
| 557 | + Node.prototype.insertAfter = function(n,r) {this.insertBefore(n,r.nextSibling);}; |
| 558 | + } |
555 | 559 |
|
556 | 560 |
|
557 | 561 | /** |
|
561 | 565 | */ |
562 | 566 | priorityNav.init = function (options) { |
563 | 567 |
|
| 568 | + |
564 | 569 | // Feature test. |
565 | | - if (!supports){ |
| 570 | + if (!supports && typeof Node === "undefined"){ |
566 | 571 | console.warn("This browser doesn't support priorityNav"); |
567 | 572 | return; |
568 | 573 | } |
|
616 | 621 | /** |
617 | 622 | * Check if we need to create the dropdown elements |
618 | 623 | */ |
619 | | - prepareHtml(_this); |
| 624 | + prepareHtml(_this, settings); |
620 | 625 |
|
621 | 626 | /** |
622 | 627 | * Store the dropdown element |
|
639 | 644 | /** |
640 | 645 | * Event listeners |
641 | 646 | */ |
642 | | - listeners(_this); |
| 647 | + listeners(_this, settings); |
643 | 648 |
|
644 | 649 | /** |
645 | 650 | * Start first check |
646 | 651 | */ |
647 | | - priorityNav.doesItFit(_this); |
| 652 | + priorityNav.doesItFit(_this, settings); |
648 | 653 |
|
649 | 654 | }); |
650 | 655 |
|
|
0 commit comments