priority-nav 1.0.12 → 1.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
1
  /*
2
- * priority-nav - v1.0.12 | (c) 2016 @gijsroge | MIT license
2
+ * priority-nav - v1.0.13 | (c) 2025 @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/
6
6
  */
7
- !function(a,b){"function"==typeof define&&define.amd?define("priorityNav",b(a)):"object"==typeof exports?module.exports=b(a):a.priorityNav=b(a)}(window||this,function(a){"use strict";function b(a,b,c){var d;return function(){var e=this,f=arguments,g=function(){d=null,c||a.apply(e,f)},h=c&&!d;clearTimeout(d),d=setTimeout(g,b),h&&a.apply(e,f)}}var c,d,e,f,g,h,i,j,k={},l=[],m=!!document.querySelector&&!!a.addEventListener,n={},o=0,p=0,q=0,r={initClass:"js-priorityNav",mainNavWrapper:"nav",mainNav:"ul",navDropdownClassName:"nav__dropdown",navDropdownToggleClassName:"nav__dropdown-toggle",navDropdownLabel:"more",navDropdownBreakpointLabel:"menu",breakPoint:500,throttleDelay:50,offsetPixels:0,count:!0,moved:function(){},movedBack:function(){}},s=function(a,b,c){if("[object Object]"===Object.prototype.toString.call(a))for(var d in a)Object.prototype.hasOwnProperty.call(a,d)&&b.call(c,a[d],d,a);else for(var e=0,f=a.length;f>e;e++)b.call(c,a[e],e,a)},t=function(a,b){for(var c=b.charAt(0);a&&a!==document;a=a.parentNode)if("."===c){if(a.classList.contains(b.substr(1)))return a}else if("#"===c){if(a.id===b.substr(1))return a}else if("["===c&&a.hasAttribute(b.substr(1,b.length-2)))return a;return!1},u=function(a,b){var c={};return s(a,function(b,d){c[d]=a[d]}),s(b,function(a,d){c[d]=b[d]}),c},v=function(a,b){if(a.classList)a.classList.toggle(b);else{var c=a.className.split(" "),d=c.indexOf(b);d>=0?c.splice(d,1):c.push(b),a.className=c.join(" ")}},w=function(a,b){return j=document.createElement("span"),g=document.createElement("ul"),h=document.createElement("button"),h.innerHTML=b.navDropdownLabel,h.setAttribute("aria-controls","menu"),h.setAttribute("type","button"),g.setAttribute("aria-hidden","true"),a.querySelector(f).parentNode!==a?void console.warn("mainNav is not a direct child of mainNavWrapper, double check please"):(a.insertAfter(j,a.querySelector(f)),j.appendChild(h),j.appendChild(g),g.classList.add(b.navDropdownClassName),g.classList.add("priority-nav__dropdown"),h.classList.add(b.navDropdownToggleClassName),h.classList.add("priority-nav__dropdown-toggle"),j.classList.add(b.navDropdownClassName+"-wrapper"),j.classList.add("priority-nav__wrapper"),void a.classList.add("priority-nav"))},x=function(a){var b=window.getComputedStyle(a),c=parseFloat(b.paddingLeft)+parseFloat(b.paddingRight);return a.clientWidth-c},y=function(){var a=document,b=window,c=a.compatMode&&"CSS1Compat"===a.compatMode?a.documentElement:a.body,d=c.clientWidth,e=c.clientHeight;return b.innerWidth&&d>b.innerWidth&&(d=b.innerWidth,e=b.innerHeight),{width:d,height:e}},z=function(a){d=x(a),i=a.querySelector(g).parentNode===a?a.querySelector(g).offsetWidth:0,e=D(a)+n.offsetPixels,q=y().width};k.doesItFit=function(a){var c=0===a.getAttribute("instance")?c:n.throttleDelay;o++,b(function(){var b=a.getAttribute("instance");for(z(a);e>=d&&a.querySelector(f).children.length>0||q<n.breakPoint&&a.querySelector(f).children.length>0;)k.toDropdown(a,b),z(a,b),q<n.breakPoint&&C(a,b,n.navDropdownBreakpointLabel);for(;d>=l[b][l[b].length-1]&&q>n.breakPoint;)k.toMenu(a,b),q>n.breakPoint&&C(a,b,n.navDropdownLabel);l[b].length<1&&(a.querySelector(g).classList.remove("show"),C(a,b,n.navDropdownLabel)),a.querySelector(f).children.length<1?(a.classList.add("is-empty"),C(a,b,n.navDropdownBreakpointLabel)):a.classList.remove("is-empty"),A(a,b)},c)()};var A=function(a,b){l[b].length<1?(a.querySelector(h).classList.add("priority-nav-is-hidden"),a.querySelector(h).classList.remove("priority-nav-is-visible"),a.classList.remove("priority-nav-has-dropdown"),a.querySelector(".priority-nav__wrapper").setAttribute("aria-haspopup","false")):(a.querySelector(h).classList.add("priority-nav-is-visible"),a.querySelector(h).classList.remove("priority-nav-is-hidden"),a.classList.add("priority-nav-has-dropdown"),a.querySelector(".priority-nav__wrapper").setAttribute("aria-haspopup","true"))},B=function(a,b){a.querySelector(h).setAttribute("priorityNav-count",l[b].length)},C=function(a,b,c){a.querySelector(h).innerHTML=c};k.toDropdown=function(a,b){a.querySelector(g).firstChild&&a.querySelector(f).children.length>0?a.querySelector(g).insertBefore(a.querySelector(f).lastElementChild,a.querySelector(g).firstChild):a.querySelector(f).children.length>0&&a.querySelector(g).appendChild(a.querySelector(f).lastElementChild),l[b].push(e),A(a,b),a.querySelector(f).children.length>0&&n.count&&B(a,b),n.moved()},k.toMenu=function(a,b){a.querySelector(g).children.length>0&&a.querySelector(f).appendChild(a.querySelector(g).firstElementChild),l[b].pop(),A(a,b),a.querySelector(f).children.length>0&&n.count&&B(a,b),n.movedBack()};var D=function(a){for(var b=a.childNodes,c=0,d=0;d<b.length;d++)3!==b[d].nodeType&&(isNaN(b[d].offsetWidth)||(c+=b[d].offsetWidth));return c},E=function(a,b){window.attachEvent?window.attachEvent("onresize",function(){k.doesItFit&&k.doesItFit(a)}):window.addEventListener&&window.addEventListener("resize",function(){k.doesItFit&&k.doesItFit(a)},!0),a.querySelector(h).addEventListener("click",function(){v(a.querySelector(g),"show"),v(this,"is-open"),v(a,"is-open"),-1!==a.className.indexOf("is-open")?a.querySelector(g).setAttribute("aria-hidden","false"):(a.querySelector(g).setAttribute("aria-hidden","true"),a.querySelector(g).blur())}),document.addEventListener("click",function(c){t(c.target,"."+b.navDropdownClassName)||c.target===a.querySelector(h)||(a.querySelector(g).classList.remove("show"),a.querySelector(h).classList.remove("is-open"),a.classList.remove("is-open"))}),document.onkeydown=function(a){a=a||window.event,27===a.keyCode&&(document.querySelector(g).classList.remove("show"),document.querySelector(h).classList.remove("is-open"),c.classList.remove("is-open"))}};Element.prototype.remove=function(){this.parentElement.removeChild(this)},NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var a=0,b=this.length;b>a;a++)this[a]&&this[a].parentElement&&this[a].parentElement.removeChild(this[a])},k.destroy=function(){n&&(document.documentElement.classList.remove(n.initClass),j.remove(),n=null,delete k.init,delete k.doesItFit)},m&&"undefined"!=typeof Node&&(Node.prototype.insertAfter=function(a,b){this.insertBefore(a,b.nextSibling)});var F=function(a){var b=a.charAt(0);return"."===b||"#"===b?!1:!0};return k.init=function(a){if(n=u(r,a||{}),!m&&"undefined"==typeof Node)return void console.warn("This browser doesn't support priorityNav");if(!F(n.navDropdownClassName)||!F(n.navDropdownToggleClassName))return void console.warn("No symbols allowed in navDropdownClassName & navDropdownToggleClassName. These are not selectors.");var b=document.querySelectorAll(n.mainNavWrapper);s(b,function(a){return l[p]=[],a.setAttribute("instance",p++),(c=a)?(f=n.mainNav,a.querySelector(f)?(w(a,n),g="."+n.navDropdownClassName,a.querySelector(g)?(h="."+n.navDropdownToggleClassName,a.querySelector(h)?(E(a,n),void k.doesItFit(a)):void console.warn("couldn't find the specified navDropdownToggle element")):void console.warn("couldn't find the specified navDropdown element")):void console.warn("couldn't find the specified mainNav element")):void console.warn("couldn't find the specified mainNavWrapper element")}),o++,document.documentElement.classList.add(n.initClass)},k});
7
+
8
+ !function(e,t){"function"==typeof define&&define.amd?define("priorityNav",t(e)):"object"==typeof exports?module.exports=t(e):e.priorityNav=t(e)}(window||this,function(e){"use strict";var i,d,c,s,u,a,l,p={},v=[],h=!!document.querySelector&&!!e.addEventListener,f={},m=0,y=0,w={initClass:"js-priorityNav",mainNavWrapper:"nav",mainNav:"ul",navDropdownClassName:"nav__dropdown",navDropdownToggleClassName:"nav__dropdown-toggle",navDropdownLabel:"more",navDropdownBreakpointLabel:"menu",breakPoint:500,throttleDelay:50,offsetPixels:0,count:!0,moved:function(){},movedBack:function(){}},S=function(e,t,n){if("[object Object]"===Object.prototype.toString.call(e))for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.call(n,e[o],o,e);else for(var r=0,i=e.length;r<i;r++)t.call(n,e[r],r,e)};var o=function(e,t){if(e.classList)e.classList.toggle(t);else{var n=e.className.split(" "),o=n.indexOf(t);0<=o?n.splice(o,1):n.push(t),e.className=n.join(" ")}},n=function(e){var t,n,o,r,i,a,s,l;t=e,n=window.getComputedStyle(t),o=parseFloat(n.paddingLeft)+parseFloat(n.paddingRight),d=t.clientWidth-o,e.querySelector(u).parentNode===e?e.querySelector(u).offsetWidth:0,c=q(e)+f.offsetPixels,y=(r=document,i=window,a=r.compatMode&&"CSS1Compat"===r.compatMode?r.documentElement:r.body,s=a.clientWidth,l=a.clientHeight,i.innerWidth&&s>i.innerWidth&&(s=i.innerWidth,l=i.innerHeight),{width:s,height:l}).width};p.doesItFit=function(t){var o,r,i,a,e=0===t.getAttribute("instance")?e:f.throttleDelay;0,o=function(){var e=t.getAttribute("instance");for(n(t);d<=c&&0<t.querySelector(s).children.length||y<f.breakPoint&&0<t.querySelector(s).children.length;)p.toDropdown(t,e),n(t),y<f.breakPoint&&b(t,e,f.navDropdownBreakpointLabel);for(;d>=v[e][v[e].length-1]&&y>f.breakPoint;)p.toMenu(t,e),y>f.breakPoint&&b(t,e,f.navDropdownLabel);v[e].length<1&&(t.querySelector(u).classList.remove("show"),b(t,e,f.navDropdownLabel)),t.querySelector(s).children.length<1?(t.classList.add("is-empty"),b(t,e,f.navDropdownBreakpointLabel)):t.classList.remove("is-empty"),g(t,e)},r=e,function(){var e=this,t=arguments,n=i&&!a;clearTimeout(a),a=setTimeout(function(){a=null,i||o.apply(e,t)},r),n&&o.apply(e,t)}()};var g=function(e,t){v[t].length<1?(e.querySelector(a).classList.add("priority-nav-is-hidden"),e.querySelector(a).classList.remove("priority-nav-is-visible"),e.classList.remove("priority-nav-has-dropdown"),e.querySelector(".priority-nav__wrapper").setAttribute("aria-haspopup","false")):(e.querySelector(a).classList.add("priority-nav-is-visible"),e.querySelector(a).classList.remove("priority-nav-is-hidden"),e.classList.add("priority-nav-has-dropdown"),e.querySelector(".priority-nav__wrapper").setAttribute("aria-haspopup","true"))},r=function(e,t){e.querySelector(a).setAttribute("priorityNav-count",v[t].length)},b=function(e,t,n){e.querySelector(a).innerHTML=n};p.toDropdown=function(e,t){e.querySelector(u).firstChild&&0<e.querySelector(s).children.length?e.querySelector(u).insertBefore(e.querySelector(s).lastElementChild,e.querySelector(u).firstChild):0<e.querySelector(s).children.length&&e.querySelector(u).appendChild(e.querySelector(s).lastElementChild),v[t].push(c),g(e,t),0<e.querySelector(s).children.length&&f.count&&r(e,t),f.moved()},p.toMenu=function(e,t){0<e.querySelector(u).children.length&&e.querySelector(s).appendChild(e.querySelector(u).firstElementChild),v[t].pop(),g(e,t),0<e.querySelector(s).children.length&&f.count&&r(e,t),f.movedBack()};var q=function(e){for(var t=e.childNodes,n=0,o=0;o<t.length;o++)3!==t[o].nodeType&&(isNaN(t[o].offsetWidth)||(n+=t[o].offsetWidth));return n},L=function(t,n){window.attachEvent?window.attachEvent("onresize",function(){p.doesItFit&&p.doesItFit(t)}):window.addEventListener&&window.addEventListener("resize",function(){p.doesItFit&&p.doesItFit(t)},!0),t.querySelector(a).addEventListener("click",function(){o(t.querySelector(u),"show"),o(this,"is-open"),o(t,"is-open"),-1!==t.className.indexOf("is-open")?t.querySelector(u).setAttribute("aria-hidden","false"):(t.querySelector(u).setAttribute("aria-hidden","true"),t.querySelector(u).blur())}),document.addEventListener("click",function(e){(function(e,t){for(var n=t.charAt(0);e&&e!==document;e=e.parentNode)if("."===n){if(e.classList.contains(t.substr(1)))return e}else if("#"===n){if(e.id===t.substr(1))return e}else if("["===n&&e.hasAttribute(t.substr(1,t.length-2)))return e;return!1})(e.target,"."+n.navDropdownClassName)||e.target===t.querySelector(a)||(t.querySelector(u).classList.remove("show"),t.querySelector(a).classList.remove("is-open"),t.classList.remove("is-open"))}),document.onkeydown=function(e){27===(e=e||window.event).keyCode&&(document.querySelector(u).classList.remove("show"),document.querySelector(a).classList.remove("is-open"),i.classList.remove("is-open"))}};NodeList.prototype.remove=HTMLCollection.prototype.remove=function(){for(var e=0,t=this.length;e<t;e++)this[e]&&this[e].parentElement&&this[e].parentElement.removeChild(this[e])},p.destroy=function(){f&&(document.documentElement.classList.remove(f.initClass),l.remove(),f=null,delete p.init,delete p.doesItFit)},h&&"undefined"!=typeof Node&&(Node.prototype.insertAfter=function(e,t){this.insertBefore(e,t.nextSibling)});var N=function(e){var t=e.charAt(0);return"."!==t&&"#"!==t};return p.init=function(e){var n,o,r;if(o=e||{},r={},S(n=w,function(e,t){r[t]=n[t]}),S(o,function(e,t){r[t]=o[t]}),f=r,h||"undefined"!=typeof Node)if(N(f.navDropdownClassName)&&N(f.navDropdownToggleClassName)){var t=document.querySelectorAll(f.mainNavWrapper);S(t,function(e){var t,n;(v[m]=[],e.setAttribute("instance",m++),i=e)?(s=f.mainNav,e.querySelector(s)?(t=e,n=f,l=document.createElement("span"),u=document.createElement("ul"),(a=document.createElement("button")).innerHTML=n.navDropdownLabel,a.setAttribute("aria-controls","menu"),a.setAttribute("type","button"),u.setAttribute("aria-hidden","true"),t.querySelector(s).parentNode===t?(t.insertAfter(l,t.querySelector(s)),l.appendChild(a),l.appendChild(u),u.classList.add(n.navDropdownClassName),u.classList.add("priority-nav__dropdown"),a.classList.add(n.navDropdownToggleClassName),a.classList.add("priority-nav__dropdown-toggle"),a.setAttribute("type","button"),l.classList.add(n.navDropdownClassName+"-wrapper"),l.classList.add("priority-nav__wrapper"),t.classList.add("priority-nav")):console.warn("mainNav is not a direct child of mainNavWrapper, double check please"),u="."+f.navDropdownClassName,e.querySelector(u)?(a="."+f.navDropdownToggleClassName,e.querySelector(a)?(L(e,f),p.doesItFit(e)):console.warn("couldn't find the specified navDropdownToggle element")):console.warn("couldn't find the specified navDropdown element")):console.warn("couldn't find the specified mainNav element")):console.warn("couldn't find the specified mainNavWrapper element")}),0,document.documentElement.classList.add(f.initClass)}else console.warn("No symbols allowed in navDropdownClassName & navDropdownToggleClassName. These are not selectors.");else console.warn("This browser doesn't support priorityNav")},p});
package/package.json CHANGED
@@ -1,46 +1,46 @@
1
- {
2
- "name": "priority-nav",
3
- "title": "priority-nav",
4
- "version": "1.0.12",
5
- "main": "dist/priority-nav.js",
6
- "description": "Priority+ pattern navigation that hides menu items if they don't fit on screen.",
7
- "homepage": "http://gijsroge.github.io/priority-nav.js/",
8
- "author": {
9
- "name": "Gijs Rogé",
10
- "url": "http://twitter.com/gijsroge"
11
- },
12
- "repository": {
13
- "type": "git",
14
- "url": "https://github.com/gijsroge/priority-navigation.git"
15
- },
16
- "keywords": [
17
- "priority+",
18
- "responsive",
19
- "navigation"
20
- ],
21
- "license": {
22
- "type": "MIT",
23
- "url": "https://github.com/gijsroge/priority-navigation/blob/master/LICENSE"
24
- },
25
- "bugs": {
26
- "url": "https://github.com/gijsroge/priority-navigation/issues"
27
- },
28
- "engines": {
29
- "node": ">=0.8.0"
30
- },
31
- "devDependencies": {
32
- "load-grunt-tasks": "3.2.0",
33
- "crayola": "0.0.1",
34
- "grunt": "0.4.5",
35
- "grunt-bump": "0.3.1",
36
- "grunt-contrib-concat": "0.5.1",
37
- "grunt-contrib-jshint": "0.11.2",
38
- "grunt-contrib-uglify": "0.9.1",
39
- "grunt-contrib-watch": "0.6.1",
40
- "jshint-stylish": "2.0.1",
41
- "grunt-sass": "1.0.0"
42
- },
43
- "scripts": {
44
- "test": "grunt jshint"
45
- }
46
- }
1
+ {
2
+ "name": "priority-nav",
3
+ "title": "priority-nav",
4
+ "version": "1.0.14",
5
+ "main": "dist/priority-nav.js",
6
+ "description": "Priority+ pattern navigation that hides menu items if they don't fit on screen.",
7
+ "homepage": "http://gijsroge.github.io/priority-nav.js/",
8
+ "author": {
9
+ "name": "Gijs Rogé",
10
+ "url": "http://twitter.com/gijsroge"
11
+ },
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/gijsroge/priority-navigation.git"
15
+ },
16
+ "keywords": [
17
+ "priority+",
18
+ "responsive",
19
+ "navigation"
20
+ ],
21
+ "license": {
22
+ "type": "MIT",
23
+ "url": "https://github.com/gijsroge/priority-navigation/blob/master/LICENSE"
24
+ },
25
+ "bugs": {
26
+ "url": "https://github.com/gijsroge/priority-navigation/issues"
27
+ },
28
+ "engines": {
29
+ "node": ">=0.8.0"
30
+ },
31
+ "devDependencies": {
32
+ "load-grunt-tasks": "3.5.2",
33
+ "crayola": "0.0.1",
34
+ "grunt": "1.0.2",
35
+ "grunt-bump": "0.8.0",
36
+ "grunt-contrib-concat": "1.0.1",
37
+ "grunt-contrib-jshint": "1.1.0",
38
+ "grunt-contrib-uglify": "3.3.0",
39
+ "grunt-contrib-watch": "1.0.1",
40
+ "jshint-stylish": "2.2.1",
41
+ "grunt-sass": "2.1.0"
42
+ },
43
+ "scripts": {
44
+ "test": "grunt jshint"
45
+ }
46
+ }