@contentpilot/sticky-navigation 1.7.2 → 1.7.3
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.
- package/.nvmrc +1 -1
- package/eslint.config.js +23 -0
- package/index.js +17 -4
- package/package.json +4 -3
- package/.eslintignore +0 -1
- package/.eslintrc.js +0 -12
package/.nvmrc
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
24
|
package/eslint.config.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const globals = require('globals');
|
|
2
|
+
const jsdoc = require('eslint-plugin-jsdoc');
|
|
3
|
+
|
|
4
|
+
module.exports = [
|
|
5
|
+
{
|
|
6
|
+
ignores: ['node_modules/**'],
|
|
7
|
+
},
|
|
8
|
+
jsdoc.configs['flat/recommended'],
|
|
9
|
+
{
|
|
10
|
+
files: ['**/*.js'],
|
|
11
|
+
languageOptions: {
|
|
12
|
+
sourceType: 'commonjs',
|
|
13
|
+
globals: {
|
|
14
|
+
...globals.browser,
|
|
15
|
+
},
|
|
16
|
+
},
|
|
17
|
+
rules: {
|
|
18
|
+
quotes: ['error', 'single'],
|
|
19
|
+
semi: ['error', 'always'],
|
|
20
|
+
camelcase: ['off', { ignoreGlobals: true }],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
];
|
package/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Add identifiers and activate the anchors that have these identifier
|
|
3
3
|
* and are intercepted with the scroll. It needs the proper markup.
|
|
4
|
-
* @version 1.7.
|
|
4
|
+
* @version 1.7.3
|
|
5
5
|
* @package
|
|
6
6
|
* @author Content Pilot, Dallas, Texas
|
|
7
7
|
* @copyright Copyright © 2018 Content Pilot
|
|
@@ -178,7 +178,7 @@ function _getElements(input) {
|
|
|
178
178
|
}
|
|
179
179
|
|
|
180
180
|
/**
|
|
181
|
-
* Get the element full height including margins.
|
|
181
|
+
* Get the element full height including margins.
|
|
182
182
|
* @param {string} selector - A CSS selector string.
|
|
183
183
|
* @returns {number} - The element height including margins.
|
|
184
184
|
*/
|
|
@@ -192,7 +192,7 @@ function _getElementFullHeight(selector) {
|
|
|
192
192
|
const height = element.offsetHeight;
|
|
193
193
|
const styles = window.getComputedStyle(element);
|
|
194
194
|
const margin = parseInt(styles.getPropertyValue('margin-top')) + parseInt(styles.getPropertyValue('margin-bottom'));
|
|
195
|
-
|
|
195
|
+
|
|
196
196
|
return (height + margin);
|
|
197
197
|
}
|
|
198
198
|
|
|
@@ -207,7 +207,8 @@ function _addScrollBehavior(offsetFixed, offsetElement) {
|
|
|
207
207
|
e.preventDefault();
|
|
208
208
|
|
|
209
209
|
const id = this.getAttribute('href').replace('#', '');
|
|
210
|
-
const
|
|
210
|
+
const target = document.getElementById(id);
|
|
211
|
+
const rect = target.getBoundingClientRect();
|
|
211
212
|
|
|
212
213
|
// Position of element relative to screen + Window scrolling position.
|
|
213
214
|
const top = rect.top + window.scrollY;
|
|
@@ -222,6 +223,13 @@ function _addScrollBehavior(offsetFixed, offsetElement) {
|
|
|
222
223
|
left: 0,
|
|
223
224
|
behavior: 'smooth',
|
|
224
225
|
});
|
|
226
|
+
|
|
227
|
+
if (target.tabIndex < 0 && !target.hasAttribute('tabindex')) {
|
|
228
|
+
target.setAttribute('tabindex', '-1');
|
|
229
|
+
target.style.outline = 'none';
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
target.focus({ preventScroll: true });
|
|
225
233
|
});
|
|
226
234
|
});
|
|
227
235
|
}
|
|
@@ -304,9 +312,13 @@ function _addActiveClass(node) {
|
|
|
304
312
|
|
|
305
313
|
activeElements.forEach(function (element) {
|
|
306
314
|
element.classList.remove('current-menu-item');
|
|
315
|
+
element.querySelectorAll('a[aria-current]').forEach(function (anchor) {
|
|
316
|
+
anchor.removeAttribute('aria-current');
|
|
317
|
+
});
|
|
307
318
|
});
|
|
308
319
|
|
|
309
320
|
node.parentElement.classList.add('current-menu-item');
|
|
321
|
+
node.setAttribute('aria-current', 'location');
|
|
310
322
|
}
|
|
311
323
|
}
|
|
312
324
|
|
|
@@ -317,5 +329,6 @@ function _addActiveClass(node) {
|
|
|
317
329
|
function _removeActiveClass(node) {
|
|
318
330
|
if (node) {
|
|
319
331
|
node.parentElement.classList.remove('current-menu-item');
|
|
332
|
+
node.removeAttribute('aria-current');
|
|
320
333
|
}
|
|
321
334
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentpilot/sticky-navigation",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
4
4
|
"description": "Add identifiers and activate the anchors that have these identifier and are intercepted with the scroll.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"publishConfig": {
|
|
@@ -19,8 +19,9 @@
|
|
|
19
19
|
"author": "Content Pilot",
|
|
20
20
|
"license": "MIT",
|
|
21
21
|
"devDependencies": {
|
|
22
|
-
"eslint": "^
|
|
23
|
-
"eslint-plugin-jsdoc": "^
|
|
22
|
+
"eslint": "^10.11.0",
|
|
23
|
+
"eslint-plugin-jsdoc": "^65.0.1",
|
|
24
|
+
"globals": "^17.13.0"
|
|
24
25
|
},
|
|
25
26
|
"scripts": {
|
|
26
27
|
"lint": "eslint *.js --fix"
|
package/.eslintignore
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
/node_modules/**
|
package/.eslintrc.js
DELETED