diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 0000000..29f4434 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +coverage +dist diff --git a/.eslintrc.json b/.eslintrc.json index 5e8313f..7d23f4a 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,13 +1,17 @@ { - "extends": "airbnb-base", - "plugins": [ - "import" - ], "env": { "browser": true, - "node": true + "es2021": true, + "node": true, + "jest": true + }, + "extends": ["eslint:recommended", "plugin:prettier/recommended"], + "overrides": [ + ], + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" }, - "globals": { - "document": false + "rules": { } } diff --git a/.gitignore b/.gitignore index 1bb729a..bb10ce0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,58 +4,24 @@ logs npm-debug.log* yarn-debug.log* yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +dist-ssr +*.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? -# Runtime data -pids -*.pid -*.seed -*.pid.lock - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul +# jest coverage - -# nyc test coverage -.nyc_output - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# Bower dependency directory (https://bower.io/) -bower_components - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (https://nodejs.org/api/addons.html) -build/Release - -# Dependency directories -node_modules/ -jspm_packages/ - -# Typescript v1 declaration files -typings/ - -# Optional npm cache directory -.npm - -# Optional eslint cache -.eslintcache - -# Optional REPL history -.node_repl_history - -# Output of 'npm pack' -*.tgz - -# Yarn Integrity file -.yarn-integrity - -# dotenv environment variables file -.env - -.DS_Store -.vscode diff --git a/.npmignore b/.npmignore new file mode 100644 index 0000000..96bac92 --- /dev/null +++ b/.npmignore @@ -0,0 +1,14 @@ +public +src +.editorconfig +.eslintignore +.eslintrc.json +.gitignore +.prettierrc +.travis.yml +CONTRIBUTING.md +LICENSE.md +README.md +babel.config.cjs +jest.config.cjs +rollup.config.js diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..0e5c1db --- /dev/null +++ b/.prettierrc @@ -0,0 +1,5 @@ +{ + "trailingComma": "none", + "semi": false, + "singleQuote": true +} diff --git a/.travis.yml b/.travis.yml index fa6a035..fb5e403 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,7 +8,7 @@ cache: "node_modules" before_script: - - npm run build:all + - npm run build after_success: - npm run coveralls diff --git a/README.md b/README.md index d77ff0e..c0c07c9 100644 --- a/README.md +++ b/README.md @@ -4,72 +4,63 @@ ScrollSpy in pure JavaScript. -## Browser Support - -![IE](https://cloud.githubusercontent.com/assets/398893/3528325/20373e76-078e-11e4-8e3a-1cb86cf506f0.png) | ![Chrome](https://cloud.githubusercontent.com/assets/398893/3528328/23bc7bc4-078e-11e4-8752-ba2809bf5cce.png) | ![Firefox](https://cloud.githubusercontent.com/assets/398893/3528329/26283ab0-078e-11e4-84d4-db2cf1009953.png) | ![Opera](https://cloud.githubusercontent.com/assets/398893/3528330/27ec9fa8-078e-11e4-95cb-709fd11dac16.png) | ![Safari](https://cloud.githubusercontent.com/assets/398893/3528331/29df8618-078e-11e4-8e3e-ed8ac738693f.png) ---- | --- | --- | --- | --- -IE 10+ ✔ | Latest ✔ | Latest ✔ | Latest ✔ | Latest ✔ - ## Installation -```bash +```bash $ npm install vanillajs-scrollspy --save ``` ## How to use ```javascript -const scrollspy = VanillaScrollspy(menu, speed, easing); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` - **menu:** menu selector (#id, .class, ...) - **speed (optional):** scroll speed, default value `2000` -- **easing (optional):** scroll type `'easeOutSine'`, `'easeInOutSine'` or `'easeInOutQuint'`, default value `'easeInOutQuint'` +- **easing (optional):** scroll type `'easeOutSine'`, `'easeInOutSine'` or `'easeInOutQuint'`, default value `'easeOutSine'` ### ES6 ```javascript -import VanillaScrollspy from 'vanillajs-scrollspy'; +import VanillaScrollspy from 'vanillajs-scrollspy' -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ### CommonJS ```javascript -const VanillaScrollspy = require('vanillajs-scrollspy').default; +const VanillaScrollspy = require('vanillajs-scrollspy').default -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ### UMD in Browser ```html - - - - ``` After that the library will be available to the Global as `VanillaScrollspy`. Follow an example: ``` javascript -const navbar = document.querySelector('#navbar'); -const scrollspy = VanillaScrollspy(navbar); -scrollspy.init(); +const menu = document.querySelector('#navbar') +const scrollspy = VanillaScrollspy({ menu }) +scrollspy.init() ``` ## Examples ### Basic template -Available in [`examples/index.html`](examples/index.html). +Available in [`public/index.html`](public/index.html). ``` html @@ -78,86 +69,67 @@ Available in [`examples/index.html`](examples/index.html). VanillaJS ScrollSpy - -