From ed8bcea59ce6e2fcae52f8f2ad99510c737e1a4f Mon Sep 17 00:00:00 2001 From: ceofred Date: Fri, 29 Nov 2019 04:10:30 +0100 Subject: [PATCH] add scroll spy --- index.html | 41 +-- scripts/index.js | 3 +- styles/index.css | 12 +- t.html | 89 +++++++ vanillajs-scrollspy-master/.babelrc | 3 + vanillajs-scrollspy-master/.editorconfig | 9 + vanillajs-scrollspy-master/.eslintrc.json | 13 + vanillajs-scrollspy-master/.gitignore | 62 +++++ vanillajs-scrollspy-master/.travis.yml | 14 + vanillajs-scrollspy-master/CONTRIBUTING.md | 12 + vanillajs-scrollspy-master/LICENSE.md | 7 + vanillajs-scrollspy-master/README.md | 197 ++++++++++++++ .../dist/vanillajs-scrollspy.js | 240 ++++++++++++++++++ .../dist/vanillajs-scrollspy.js.map | 1 + .../dist/vanillajs-scrollspy.min.js | 2 + .../dist/vanillajs-scrollspy.min.js.map | 1 + .../examples/index.html | 89 +++++++ vanillajs-scrollspy-master/index.js | 1 + vanillajs-scrollspy-master/lib/index.js | 129 ++++++++++ vanillajs-scrollspy-master/lib/index2.js | 102 ++++++++ vanillajs-scrollspy-master/package.json | 73 ++++++ vanillajs-scrollspy-master/src/index.js | 100 ++++++++ .../tests/index.spec.js | 57 +++++ .../webpack.config.babel.js | 28 ++ 24 files changed, 1265 insertions(+), 20 deletions(-) create mode 100644 t.html create mode 100644 vanillajs-scrollspy-master/.babelrc create mode 100644 vanillajs-scrollspy-master/.editorconfig create mode 100644 vanillajs-scrollspy-master/.eslintrc.json create mode 100644 vanillajs-scrollspy-master/.gitignore create mode 100644 vanillajs-scrollspy-master/.travis.yml create mode 100644 vanillajs-scrollspy-master/CONTRIBUTING.md create mode 100644 vanillajs-scrollspy-master/LICENSE.md create mode 100644 vanillajs-scrollspy-master/README.md create mode 100644 vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js create mode 100644 vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js.map create mode 100644 vanillajs-scrollspy-master/dist/vanillajs-scrollspy.min.js create mode 100644 vanillajs-scrollspy-master/dist/vanillajs-scrollspy.min.js.map create mode 100644 vanillajs-scrollspy-master/examples/index.html create mode 100644 vanillajs-scrollspy-master/index.js create mode 100644 vanillajs-scrollspy-master/lib/index.js create mode 100644 vanillajs-scrollspy-master/lib/index2.js create mode 100644 vanillajs-scrollspy-master/package.json create mode 100644 vanillajs-scrollspy-master/src/index.js create mode 100644 vanillajs-scrollspy-master/tests/index.spec.js create mode 100644 vanillajs-scrollspy-master/webpack.config.babel.js diff --git a/index.html b/index.html index 20986b9..963f628 100644 --- a/index.html +++ b/index.html @@ -21,28 +21,29 @@
- +
-
+

Hello!

@@ -67,7 +68,7 @@

TOBECHUKWU

-
+
@@ -113,7 +114,7 @@

-
+

Resume

@@ -161,7 +162,7 @@

-
+

My Skills

Far far away, behind the word mountains, far from the countries Nigeria and Dubai

@@ -192,7 +193,7 @@

My Skills

-
+
@@ -234,7 +235,7 @@

Our Projects




-
+

Our Blog

A small river named Duden flos by their place and suppies it with the necessary regelialia.

@@ -338,6 +339,12 @@
WEBSITE
+ + diff --git a/scripts/index.js b/scripts/index.js index 14eb7c7..deafdab 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -1,4 +1,5 @@ window.addEventListener('load',function(e){ let preloader = document.getElementById('p_loader'); preloader.style.display = 'none'; -}) \ No newline at end of file +}) + diff --git a/styles/index.css b/styles/index.css index 8343270..4e981d4 100644 --- a/styles/index.css +++ b/styles/index.css @@ -97,8 +97,8 @@ display: inline-block; text-align: right; } - div.navigation{ - opacity: 0.5; + nav.navigation{ + opacity: 0.8; background-color: #000; position: fixed; top:0; @@ -776,3 +776,11 @@ margin-left: 50px left:850px; margin-top: 50px; } + +.nav-list li:active { + border-bottom: 2px solid #ffbd39; +} + +ul.nav-list li{ + transition: border-bottom .26s; +} diff --git a/t.html b/t.html new file mode 100644 index 0000000..c6475f5 --- /dev/null +++ b/t.html @@ -0,0 +1,89 @@ + + + + + + VanillaJS ScrollSpy + + + + + + + +
+
+

Home

+
+
+ +
+
+

Portfolio

+
+
+ +
+
+

About

+
+
+ +
+
+

Contact

+
+
+ + + + + \ No newline at end of file diff --git a/vanillajs-scrollspy-master/.babelrc b/vanillajs-scrollspy-master/.babelrc new file mode 100644 index 0000000..4ddd2ff --- /dev/null +++ b/vanillajs-scrollspy-master/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ['env'], +} diff --git a/vanillajs-scrollspy-master/.editorconfig b/vanillajs-scrollspy-master/.editorconfig new file mode 100644 index 0000000..c6c8b36 --- /dev/null +++ b/vanillajs-scrollspy-master/.editorconfig @@ -0,0 +1,9 @@ +root = true + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/vanillajs-scrollspy-master/.eslintrc.json b/vanillajs-scrollspy-master/.eslintrc.json new file mode 100644 index 0000000..5e8313f --- /dev/null +++ b/vanillajs-scrollspy-master/.eslintrc.json @@ -0,0 +1,13 @@ +{ + "extends": "airbnb-base", + "plugins": [ + "import" + ], + "env": { + "browser": true, + "node": true + }, + "globals": { + "document": false + } +} diff --git a/vanillajs-scrollspy-master/.gitignore b/vanillajs-scrollspy-master/.gitignore new file mode 100644 index 0000000..ebe6911 --- /dev/null +++ b/vanillajs-scrollspy-master/.gitignore @@ -0,0 +1,62 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +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 +package-lock.json +.vscode/ diff --git a/vanillajs-scrollspy-master/.travis.yml b/vanillajs-scrollspy-master/.travis.yml new file mode 100644 index 0000000..fa6a035 --- /dev/null +++ b/vanillajs-scrollspy-master/.travis.yml @@ -0,0 +1,14 @@ +language: node_js + +node_js: + - "7" + +cache: + diretories: + "node_modules" + +before_script: + - npm run build:all + +after_success: + - npm run coveralls diff --git a/vanillajs-scrollspy-master/CONTRIBUTING.md b/vanillajs-scrollspy-master/CONTRIBUTING.md new file mode 100644 index 0000000..e06bd60 --- /dev/null +++ b/vanillajs-scrollspy-master/CONTRIBUTING.md @@ -0,0 +1,12 @@ +# Contributing + +1. Fork it! +2. Create your feature branch: `git checkout -b my-new-feature` +3. Commit your changes: `git commit -m 'Add some feature'` +4. Push to the branch: `git push origin my-new-feature` + +*All commands to build and test are available on [package.json](package.json).* + +*Remember that we have a pre-push hook with steps that analyzes and prevents mistakes.* + +**After your pull request is merged**, you can safely delete your branch. diff --git a/vanillajs-scrollspy-master/LICENSE.md b/vanillajs-scrollspy-master/LICENSE.md new file mode 100644 index 0000000..719583e --- /dev/null +++ b/vanillajs-scrollspy-master/LICENSE.md @@ -0,0 +1,7 @@ +Copyright 2018 - Eder Sampaio + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/vanillajs-scrollspy-master/README.md b/vanillajs-scrollspy-master/README.md new file mode 100644 index 0000000..132711b --- /dev/null +++ b/vanillajs-scrollspy-master/README.md @@ -0,0 +1,197 @@ +# VanillaJS ScrollSpy + +[![Build Status](https://travis-ci.org/ederssouza/vanillajs-scrollspy.svg?branch=master)](https://travis-ci.org/ederssouza/vanillajs-scrollspy) + +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 +$ npm install vanillajs-scrollspy --save +``` + +## How to use + +```javascript +const scrollspy = new VanillaScrollspy(menu, speed, easing); +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'` + +### ES6 + +```javascript +import VanillaScrollspy from 'vanillajs-scrollspy'; + +const navbar = document.querySelector('#navbar'); +const scrollspy = new VanillaScrollspy(navbar); +scrollspy.init(); +``` + +### CommonJS + +```javascript +const VanillaScrollspy = require('vanillajs-scrollspy').default; + +const navbar = document.querySelector('#navbar'); +const scrollspy = new VanillaScrollspy(navbar); +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 = new VanillaScrollspy(navbar); +scrollspy.init(); +``` + +## Examples + +### Basic template + +Available in [`examples/index.html`](examples/index.html). + +``` html + + + + + + VanillaJS ScrollSpy + + + + + + + +
+
+

Home

+
+
+ +
+
+

Portfolio

+
+
+ +
+
+

About

+
+
+ +
+
+

Contact

+
+
+ + + + + +``` + +### Controlling the speed +Choose a number greater than or equal to 1. + +``` javascript +const navbar = document.querySelector('#navbar'); +const scrollspy = new VanillaScrollspy(navbar, 1000); +scrollspy.init(); +``` + +### Changing scroll type + +``` javascript +const navbar = document.querySelector('#navbar'); +const scrollspy = new VanillaScrollspy(navbar, 1000, 'easeInOutQuint'); +scrollspy.init(); +``` + +## Contributing + +Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us. + +## Versioning + +We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/ederssouza/vanillajs-scrollspy/tags). + +## Authors + +See also the list of [contributors](https://github.com/ederssouza/vanillajs-scrollspy/contributors) who participated in this project. + +## License + +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details diff --git a/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js new file mode 100644 index 0000000..bfbfaae --- /dev/null +++ b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js @@ -0,0 +1,240 @@ +(function webpackUniversalModuleDefinition(root, factory) { + if(typeof exports === 'object' && typeof module === 'object') + module.exports = factory(); + else if(typeof define === 'function' && define.amd) + define([], factory); + else if(typeof exports === 'object') + exports["VanillaScrollspy"] = factory(); + else + root["VanillaScrollspy"] = factory(); +})(window, function() { +return /******/ (function(modules) { // webpackBootstrap +/******/ // The module cache +/******/ var installedModules = {}; +/******/ +/******/ // The require function +/******/ function __webpack_require__(moduleId) { +/******/ +/******/ // Check if module is in cache +/******/ if(installedModules[moduleId]) { +/******/ return installedModules[moduleId].exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = installedModules[moduleId] = { +/******/ i: moduleId, +/******/ l: false, +/******/ exports: {} +/******/ }; +/******/ +/******/ // Execute the module function +/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); +/******/ +/******/ // Flag the module as loaded +/******/ module.l = true; +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/******/ +/******/ // expose the modules object (__webpack_modules__) +/******/ __webpack_require__.m = modules; +/******/ +/******/ // expose the module cache +/******/ __webpack_require__.c = installedModules; +/******/ +/******/ // define getter function for harmony exports +/******/ __webpack_require__.d = function(exports, name, getter) { +/******/ if(!__webpack_require__.o(exports, name)) { +/******/ Object.defineProperty(exports, name, { +/******/ configurable: false, +/******/ enumerable: true, +/******/ get: getter +/******/ }); +/******/ } +/******/ }; +/******/ +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; +/******/ }; +/******/ +/******/ // Object.prototype.hasOwnProperty.call +/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; +/******/ +/******/ // __webpack_public_path__ +/******/ __webpack_require__.p = ""; +/******/ +/******/ +/******/ // Load entry module and return exports +/******/ return __webpack_require__(__webpack_require__.s = "./index.js"); +/******/ }) +/************************************************************************/ +/******/ ({ + +/***/ "./index.js": +/*!******************!*\ + !*** ./index.js ***! + \******************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +module.exports = __webpack_require__(/*! ./src/index */ "./src/index.js").default; + +/***/ }), + +/***/ "./src/index.js": +/*!**********************!*\ + !*** ./src/index.js ***! + \**********************/ +/*! no static exports found */ +/***/ (function(module, exports, __webpack_require__) { + +"use strict"; + + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var fncAnimation = function fncAnimation(callback) { + window.setTimeout(callback, 1000 / 60); + return callback; +}; + +window.requestAnimFrame = function () { + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || fncAnimation; +}(); + +var VanillaScrollspy = function () { + function VanillaScrollspy(menu) { + var speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000; + var easing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'easeOutSine'; + + _classCallCheck(this, VanillaScrollspy); + + this.menu = menu; + this.speed = speed; + this.easing = easing; + } + + _createClass(VanillaScrollspy, [{ + key: 'scrollToY', + value: function scrollToY() { + var _this = this; + + var targetY = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + + var scrollTargetY = targetY; + var scrollY = window.scrollY || document.documentElement.scrollTop; + var currentTime = 0; + var time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8)); + + var easingEquations = { + easeOutSine: function easeOutSine(pos) { + return Math.sin(pos * (Math.PI / 2)); + }, + easeInOutSine: function easeInOutSine(pos) { + return -0.5 * (Math.cos(Math.PI * pos) - 1); + }, + easeInOutQuint: function easeInOutQuint(pos) { + /* eslint-disable-next-line */ + if ((pos /= 0.5) < 1) { + return 0.5 * Math.pow(pos, 5); + } + return 0.5 * (Math.pow(pos - 2, 5) + 2); + } + }; + + var tick = function tick() { + currentTime += 1 / 60; + var p = currentTime / time; + var t = easingEquations[_this.easing](p); + + if (p < 1) { + window.requestAnimFrame(tick); + window.scrollTo(0, scrollY + (scrollTargetY - scrollY) * t); + } else { + window.scrollTo(0, scrollTargetY); + } + }; + + tick(); + } + }, { + key: 'menuControl', + value: function menuControl() { + var i = void 0; + var currLink = void 0; + var refElement = void 0; + var links = this.menu.querySelectorAll('a[href^="#"]'); + var scrollPos = window.scrollY || document.documentElement.scrollTop; + + for (i = 0; i < links.length; i += 1) { + currLink = links[i]; + refElement = document.querySelector(currLink.getAttribute('href')); + + if (refElement.offsetTop <= scrollPos && refElement.offsetTop + refElement.clientHeight > scrollPos) { + currLink.classList.add('active'); + } else { + currLink.classList.remove('active'); + } + } + } + }, { + key: 'animated', + value: function animated() { + var self = this; + function control(e) { + e.preventDefault(); + var target = document.querySelector(this.hash); + self.scrollToY(target.offsetTop); + } + + var i = void 0; + var link = void 0; + var links = this.menu.querySelectorAll('a[href^="#"]'); + + for (i = 0; i < links.length; i += 1) { + link = links[i]; + link.addEventListener('click', control); + } + } + }, { + key: 'init', + value: function init() { + var _this2 = this; + + this.animated(); + document.addEventListener('scroll', function () { + _this2.menuControl(); + }); + } + }]); + + return VanillaScrollspy; +}(); + +exports.default = VanillaScrollspy; + +/***/ }) + +/******/ }); +}); +//# sourceMappingURL=vanillajs-scrollspy.js.map \ No newline at end of file diff --git a/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js.map b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js.map new file mode 100644 index 0000000..f016d56 --- /dev/null +++ b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["webpack://VanillaScrollspy/webpack/universalModuleDefinition","webpack://VanillaScrollspy/webpack/bootstrap","webpack://VanillaScrollspy/./index.js","webpack://VanillaScrollspy/./src/index.js"],"names":["module","exports","require","default","fncAnimation","callback","window","setTimeout","requestAnimFrame","requestAnimationFrame","webkitRequestAnimationFrame","mozRequestAnimationFrame","VanillaScrollspy","menu","speed","easing","targetY","scrollTargetY","scrollY","document","documentElement","scrollTop","currentTime","time","Math","max","min","abs","easingEquations","easeOutSine","pos","sin","PI","easeInOutSine","cos","easeInOutQuint","tick","p","t","scrollTo","i","currLink","refElement","links","querySelectorAll","scrollPos","length","querySelector","getAttribute","offsetTop","clientHeight","classList","add","remove","self","control","e","preventDefault","target","hash","scrollToY","link","addEventListener","animated","menuControl"],"mappings":"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","file":"vanillajs-scrollspy.js","sourcesContent":["(function webpackUniversalModuleDefinition(root, factory) {\n\tif(typeof exports === 'object' && typeof module === 'object')\n\t\tmodule.exports = factory();\n\telse if(typeof define === 'function' && define.amd)\n\t\tdefine([], factory);\n\telse if(typeof exports === 'object')\n\t\texports[\"VanillaScrollspy\"] = factory();\n\telse\n\t\troot[\"VanillaScrollspy\"] = factory();\n})(window, function() {\nreturn "," \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, {\n \t\t\t\tconfigurable: false,\n \t\t\t\tenumerable: true,\n \t\t\t\tget: getter\n \t\t\t});\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = \"./index.js\");\n","module.exports = require('./src/index').default;\n","const fncAnimation = (callback) => {\n window.setTimeout(callback, 1000 / 60);\n return callback;\n};\n\nwindow.requestAnimFrame = (() =>\n window.requestAnimationFrame ||\n window.webkitRequestAnimationFrame ||\n window.mozRequestAnimationFrame ||\n fncAnimation\n)();\n\nexport default class VanillaScrollspy {\n constructor(menu, speed = 2000, easing = 'easeOutSine') {\n this.menu = menu;\n this.speed = speed;\n this.easing = easing;\n }\n scrollToY(targetY = 0) {\n const scrollTargetY = targetY;\n const scrollY = window.scrollY || document.documentElement.scrollTop;\n let currentTime = 0;\n const time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8));\n\n const easingEquations = {\n easeOutSine(pos) {\n return Math.sin(pos * (Math.PI / 2));\n },\n easeInOutSine(pos) {\n return (-0.5 * (Math.cos(Math.PI * pos) - 1));\n },\n easeInOutQuint(pos) {\n /* eslint-disable-next-line */\n if ((pos /= 0.5) < 1) {\n return 0.5 * (pos ** 5);\n }\n return 0.5 * (((pos - 2) ** 5) + 2);\n },\n };\n\n const tick = () => {\n currentTime += 1 / 60;\n const p = currentTime / time;\n const t = easingEquations[this.easing](p);\n\n if (p < 1) {\n window.requestAnimFrame(tick);\n window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));\n } else {\n window.scrollTo(0, scrollTargetY);\n }\n };\n\n tick();\n }\n menuControl() {\n let i;\n let currLink;\n let refElement;\n const links = this.menu.querySelectorAll('a[href^=\"#\"]');\n const scrollPos = window.scrollY || document.documentElement.scrollTop;\n\n for (i = 0; i < links.length; i += 1) {\n currLink = links[i];\n refElement = document.querySelector(currLink.getAttribute('href'));\n\n if (\n refElement.offsetTop <= scrollPos &&\n (refElement.offsetTop + refElement.clientHeight) > scrollPos\n ) {\n currLink.classList.add('active');\n } else {\n currLink.classList.remove('active');\n }\n }\n }\n animated() {\n const self = this;\n function control(e) {\n e.preventDefault();\n const target = document.querySelector(this.hash);\n self.scrollToY(target.offsetTop);\n }\n\n let i;\n let link;\n const links = this.menu.querySelectorAll('a[href^=\"#\"]');\n\n for (i = 0; i < links.length; i += 1) {\n link = links[i];\n link.addEventListener('click', control);\n }\n }\n init() {\n this.animated();\n document.addEventListener('scroll', () => {\n this.menuControl();\n });\n }\n}\n"],"sourceRoot":""} \ No newline at end of file diff --git a/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.min.js b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.min.js new file mode 100644 index 0000000..6eee431 --- /dev/null +++ b/vanillajs-scrollspy-master/dist/vanillajs-scrollspy.min.js @@ -0,0 +1,2 @@ +!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.VanillaScrollspy=t():e.VanillaScrollspy=t()}(window,function(){return function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}return n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{configurable:!1,enumerable:!0,get:o})},n.r=function(e){Object.defineProperty(e,"__esModule",{value:!0})},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:!0});var o=function(){function e(e,t){for(var n=0;n1&&void 0!==arguments[1]?arguments[1]:2e3,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"easeOutSine";!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.menu=t,this.speed=n,this.easing=o}return o(e,[{key:"scrollToY",value:function(){var e=this,t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0,n=window.scrollY||document.documentElement.scrollTop,o=0,r=Math.max(.1,Math.min(Math.abs(n-t)/this.speed,.8)),i={easeOutSine:function(e){return Math.sin(e*(Math.PI/2))},easeInOutSine:function(e){return-.5*(Math.cos(Math.PI*e)-1)},easeInOutQuint:function(e){return(e/=.5)<1?.5*Math.pow(e,5):.5*(Math.pow(e-2,5)+2)}};!function u(){var a=(o+=1/60)/r,c=i[e.easing](a);a<1?(window.requestAnimFrame(u),window.scrollTo(0,n+(t-n)*c)):window.scrollTo(0,t)}()}},{key:"menuControl",value:function(){var e=void 0,t=void 0,n=void 0,o=this.menu.querySelectorAll('a[href^="#"]'),r=window.scrollY||document.documentElement.scrollTop;for(e=0;er?t.classList.add("active"):t.classList.remove("active")}},{key:"animated",value:function(){var e=this;function t(t){t.preventDefault();var n=document.querySelector(this.hash);e.scrollToY(n.offsetTop)}var n=void 0,o=this.menu.querySelectorAll('a[href^="#"]');for(n=0;n {\n window.setTimeout(callback, 1000 / 60);\n return callback;\n};\n\nwindow.requestAnimFrame = (() =>\n window.requestAnimationFrame ||\n window.webkitRequestAnimationFrame ||\n window.mozRequestAnimationFrame ||\n fncAnimation\n)();\n\nexport default class VanillaScrollspy {\n constructor(menu, speed = 2000, easing = 'easeOutSine') {\n this.menu = menu;\n this.speed = speed;\n this.easing = easing;\n }\n scrollToY(targetY = 0) {\n const scrollTargetY = targetY;\n const scrollY = window.scrollY || document.documentElement.scrollTop;\n let currentTime = 0;\n const time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8));\n\n const easingEquations = {\n easeOutSine(pos) {\n return Math.sin(pos * (Math.PI / 2));\n },\n easeInOutSine(pos) {\n return (-0.5 * (Math.cos(Math.PI * pos) - 1));\n },\n easeInOutQuint(pos) {\n /* eslint-disable-next-line */\n if ((pos /= 0.5) < 1) {\n return 0.5 * (pos ** 5);\n }\n return 0.5 * (((pos - 2) ** 5) + 2);\n },\n };\n\n const tick = () => {\n currentTime += 1 / 60;\n const p = currentTime / time;\n const t = easingEquations[this.easing](p);\n\n if (p < 1) {\n window.requestAnimFrame(tick);\n window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t));\n } else {\n window.scrollTo(0, scrollTargetY);\n }\n };\n\n tick();\n }\n menuControl() {\n let i;\n let currLink;\n let refElement;\n const links = this.menu.querySelectorAll('a[href^=\"#\"]');\n const scrollPos = window.scrollY || document.documentElement.scrollTop;\n\n for (i = 0; i < links.length; i += 1) {\n currLink = links[i];\n refElement = document.querySelector(currLink.getAttribute('href'));\n\n if (\n refElement.offsetTop <= scrollPos &&\n (refElement.offsetTop + refElement.clientHeight) > scrollPos\n ) {\n currLink.classList.add('active');\n } else {\n currLink.classList.remove('active');\n }\n }\n }\n animated() {\n const self = this;\n function control(e) {\n e.preventDefault();\n const target = document.querySelector(this.hash);\n self.scrollToY(target.offsetTop);\n }\n\n let i;\n let link;\n const links = this.menu.querySelectorAll('a[href^=\"#\"]');\n\n for (i = 0; i < links.length; i += 1) {\n link = links[i];\n link.addEventListener('click', control);\n }\n }\n init() {\n this.animated();\n document.addEventListener('scroll', () => {\n this.menuControl();\n });\n }\n}\n","module.exports = require('./src/index').default;\n"],"sourceRoot":""} \ No newline at end of file diff --git a/vanillajs-scrollspy-master/examples/index.html b/vanillajs-scrollspy-master/examples/index.html new file mode 100644 index 0000000..169547f --- /dev/null +++ b/vanillajs-scrollspy-master/examples/index.html @@ -0,0 +1,89 @@ + + + + + + VanillaJS ScrollSpy + + + + + + + +
+
+

Home

+
+
+ +
+
+

Portfolio

+
+
+ +
+
+

About

+
+
+ +
+
+

Contact

+
+
+ + + + + diff --git a/vanillajs-scrollspy-master/index.js b/vanillajs-scrollspy-master/index.js new file mode 100644 index 0000000..8f59cdf --- /dev/null +++ b/vanillajs-scrollspy-master/index.js @@ -0,0 +1 @@ +module.exports = require('./src/index').default; diff --git a/vanillajs-scrollspy-master/lib/index.js b/vanillajs-scrollspy-master/lib/index.js new file mode 100644 index 0000000..283a643 --- /dev/null +++ b/vanillajs-scrollspy-master/lib/index.js @@ -0,0 +1,129 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var fncAnimation = function fncAnimation(callback) { + window.setTimeout(callback, 1000 / 60); + return callback; +}; + +window.requestAnimFrame = function () { + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || fncAnimation; +}(); + +var VanillaScrollspy = function () { + function VanillaScrollspy(menu) { + var speed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000; + var easing = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'easeOutSine'; + + _classCallCheck(this, VanillaScrollspy); + + this.menu = menu; + this.speed = speed; + this.easing = easing; + } + + _createClass(VanillaScrollspy, [{ + key: 'scrollToY', + value: function scrollToY() { + var _this = this; + + var targetY = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + + var scrollTargetY = targetY; + var scrollY = window.scrollY || document.documentElement.scrollTop; + var currentTime = 0; + var time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8)); + + var easingEquations = { + easeOutSine: function easeOutSine(pos) { + return Math.sin(pos * (Math.PI / 2)); + }, + easeInOutSine: function easeInOutSine(pos) { + return -0.5 * (Math.cos(Math.PI * pos) - 1); + }, + easeInOutQuint: function easeInOutQuint(pos) { + /* eslint-disable-next-line */ + if ((pos /= 0.5) < 1) { + return 0.5 * Math.pow(pos, 5); + } + return 0.5 * (Math.pow(pos - 2, 5) + 2); + } + }; + + var tick = function tick() { + currentTime += 1 / 60; + var p = currentTime / time; + var t = easingEquations[_this.easing](p); + + if (p < 1) { + window.requestAnimFrame(tick); + window.scrollTo(0, scrollY + (scrollTargetY - scrollY) * t); + } else { + window.scrollTo(0, scrollTargetY); + } + }; + + tick(); + } + }, { + key: 'menuControl', + value: function menuControl() { + var i = void 0; + var currLink = void 0; + var refElement = void 0; + var links = this.menu.querySelectorAll('a[href^="#"]'); + var scrollPos = window.scrollY || document.documentElement.scrollTop; + + for (i = 0; i < links.length; i += 1) { + currLink = links[i]; + refElement = document.querySelector(currLink.getAttribute('href')); + + if (refElement.offsetTop <= scrollPos && refElement.offsetTop + refElement.clientHeight > scrollPos) { + currLink.classList.add('active'); + } else { + currLink.classList.remove('active'); + } + } + } + }, { + key: 'animated', + value: function animated() { + var self = this; + function control(e) { + e.preventDefault(); + var target = document.querySelector(this.hash); + self.scrollToY(target.offsetTop); + } + + var i = void 0; + var link = void 0; + var links = this.menu.querySelectorAll('a[href^="#"]'); + + for (i = 0; i < links.length; i += 1) { + link = links[i]; + link.addEventListener('click', control); + } + } + }, { + key: 'init', + value: function init() { + var _this2 = this; + + this.animated(); + document.addEventListener('scroll', function () { + _this2.menuControl(); + }); + } + }]); + + return VanillaScrollspy; +}(); + +exports.default = VanillaScrollspy; \ No newline at end of file diff --git a/vanillajs-scrollspy-master/lib/index2.js b/vanillajs-scrollspy-master/lib/index2.js new file mode 100644 index 0000000..062a49d --- /dev/null +++ b/vanillajs-scrollspy-master/lib/index2.js @@ -0,0 +1,102 @@ +'use strict'; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +var fncAnimation = function fncAnimation(callback) { + window.setTimeout(callback, 1000 / 60); +}; + +window.requestAnimFrame = function () { + return window.requestAnimationFrame || window.webkitRequestAnimationFrame || window.mozRequestAnimationFrame || fncAnimation; +}(); + +var scrollToY = function scrollToY() { + var targetY = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; + var scrollSpeed = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 2000; + var easingScroll = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'easeOutSine'; + + var scrollTargetY = targetY; + var speed = scrollSpeed; + var easing = easingScroll; + + var scrollY = window.scrollY || document.documentElement.scrollTop; + var currentTime = 0; + var time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / speed, 0.8)); + + var easingEquations = { + easeOutSine: function easeOutSine(pos) { + return Math.sin(pos * (Math.PI / 2)); + }, + easeInOutSine: function easeInOutSine(pos) { + return -0.5 * (Math.cos(Math.PI * pos) - 1); + }, + easeInOutQuint: function easeInOutQuint(pos) { + /* eslint-disable-next-line */ + if ((pos /= 0.5) < 1) { + return 0.5 * Math.pow(pos, 5); + } + return 0.5 * (Math.pow(pos - 2, 5) + 2); + } + }; + + function tick() { + currentTime += 1 / 60; + var p = currentTime / time; + var t = easingEquations[easing](p); + + if (p < 1) { + window.requestAnimFrame(tick); + window.scrollTo(0, scrollY + (scrollTargetY - scrollY) * t); + } else { + window.scrollTo(0, scrollTargetY); + } + } + + tick(); +}; + +var menuControl = function menuControl(menu) { + var i = void 0; + var currLink = void 0; + var refElement = void 0; + var links = menu.querySelectorAll('a[href^="#"]'); + var scrollPos = window.scrollY || document.documentElement.scrollTop; + + for (i = 0; i < links.length; i += 1) { + currLink = links[i]; + refElement = document.querySelector(currLink.getAttribute('href')); + + if (refElement.offsetTop <= scrollPos && refElement.offsetTop + refElement.clientHeight > scrollPos) { + currLink.classList.add('active'); + } else { + currLink.classList.remove('active'); + } + } +}; + +var animated = function animated(menu, speed, easing) { + function control(e) { + e.preventDefault(); + var target = document.querySelector(this.hash); + scrollToY(target.offsetTop, speed, easing); + } + + var i = void 0; + var link = void 0; + var links = menu.querySelectorAll('a[href^="#"]'); + + for (i = 0; i < links.length; i += 1) { + link = links[i]; + link.addEventListener('click', control); + } +}; + +var vanillaScrollspy = function vanillaScrollspy(menu, speed, easing) { + animated(menu, speed, easing); + document.addEventListener('scroll', function () { + menuControl(menu); + }); +}; + +exports.default = vanillaScrollspy; \ No newline at end of file diff --git a/vanillajs-scrollspy-master/package.json b/vanillajs-scrollspy-master/package.json new file mode 100644 index 0000000..360f068 --- /dev/null +++ b/vanillajs-scrollspy-master/package.json @@ -0,0 +1,73 @@ +{ + "name": "vanillajs-scrollspy", + "version": "2.0.3", + "description": "ScrollSpy in pure JavaScript", + "main": "lib/index.js", + "scripts": { + "clear": "rimraf lib dist", + "build": "npm run clear && ./node_modules/.bin/babel --out-dir lib src", + "build:watch": "npm run build -- --watch", + "build:umd": "./node_modules/.bin/webpack --output-filename vanillajs-scrollspy.js", + "build:umd:min": "./node_modules/.bin/webpack --output-filename vanillajs-scrollspy.min.js -p", + "build:all": "npm run build && npm run build:umd && npm run build:umd:min", + "lint": "./node_modules/.bin/eslint src/*.js", + "lint:watch": "./node_modules/eslint-watch/bin/esw src/*.js -w", + "prepush": "npm run lint", + "test": "./node_modules/.bin/mocha tests/**/*.spec.js --require babel-register", + "test:tdd": "./node_modules/.bin/mocha tests/**/*.spec.js --require babel-register --watch", + "test:coverage": "nyc npm test", + "coveralls": "npm run test:coverage && nyc report --reporter=text-lcov | coveralls" + }, + "files": [ + "dist", + "lib" + ], + "nyc": { + "reporter": [ + "text", + "html" + ], + "exclude": [ + "tests/**" + ] + }, + "repository": { + "type": "git", + "url": "git+https://github.com/ederssouza/vanillajs-scrollspy.git" + }, + "keywords": [ + "js", + "tdd", + "library" + ], + "author": "Eder Sampaio ", + "license": "MIT", + "bugs": { + "url": "https://github.com/ederssouza/vanillajs-scrollspy/issues" + }, + "homepage": "https://github.com/ederssouza/vanillajs-scrollspy#readme", + "devDependencies": { + "babel-cli": "^6.26.0", + "babel-loader": "^7.1.4", + "babel-preset-env": "^1.6.1", + "babel-register": "^6.26.0", + "chai": "^4.1.2", + "coveralls": "^3.0.1", + "eslint": "^4.15.0", + "eslint-config-airbnb-base": "^12.1.0", + "eslint-plugin-import": "^2.8.0", + "eslint-watch": "^3.1.5", + "husky": "^0.14.3", + "jsdom": "^11.11.0", + "jsdom-global": "^3.0.2", + "mocha": "^5.0.5", + "node-fetch": "^2.1.2", + "nyc": "^11.6.0", + "rimraf": "^2.6.2", + "sinon": "^4.5.0", + "sinon-chai": "^3.0.0", + "sinon-stub-promise": "^4.0.0", + "webpack": "^4.7.0", + "webpack-cli": "^2.1.2" + } +} diff --git a/vanillajs-scrollspy-master/src/index.js b/vanillajs-scrollspy-master/src/index.js new file mode 100644 index 0000000..fa6ea60 --- /dev/null +++ b/vanillajs-scrollspy-master/src/index.js @@ -0,0 +1,100 @@ +const fncAnimation = (callback) => { + window.setTimeout(callback, 1000 / 60); + return callback; +}; + +window.requestAnimFrame = (() => + window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + fncAnimation +)(); + +export default class VanillaScrollspy { + constructor(menu, speed = 2000, easing = 'easeOutSine') { + this.menu = menu; + this.speed = speed; + this.easing = easing; + } + scrollToY(targetY = 0) { + const scrollTargetY = targetY; + const scrollY = window.scrollY || document.documentElement.scrollTop; + let currentTime = 0; + const time = Math.max(0.1, Math.min(Math.abs(scrollY - scrollTargetY) / this.speed, 0.8)); + + const easingEquations = { + easeOutSine(pos) { + return Math.sin(pos * (Math.PI / 2)); + }, + easeInOutSine(pos) { + return (-0.5 * (Math.cos(Math.PI * pos) - 1)); + }, + easeInOutQuint(pos) { + /* eslint-disable-next-line */ + if ((pos /= 0.5) < 1) { + return 0.5 * (pos ** 5); + } + return 0.5 * (((pos - 2) ** 5) + 2); + }, + }; + + const tick = () => { + currentTime += 1 / 60; + const p = currentTime / time; + const t = easingEquations[this.easing](p); + + if (p < 1) { + window.requestAnimFrame(tick); + window.scrollTo(0, scrollY + ((scrollTargetY - scrollY) * t)); + } else { + window.scrollTo(0, scrollTargetY); + } + }; + + tick(); + } + menuControl() { + let i; + let currLink; + let refElement; + const links = this.menu.querySelectorAll('a[href^="#"]'); + const scrollPos = window.scrollY || document.documentElement.scrollTop; + + for (i = 0; i < links.length; i += 1) { + currLink = links[i]; + refElement = document.querySelector(currLink.getAttribute('href')); + + if ( + refElement.offsetTop <= scrollPos && + (refElement.offsetTop + refElement.clientHeight) > scrollPos + ) { + currLink.classList.add('active'); + } else { + currLink.classList.remove('active'); + } + } + } + animated() { + const self = this; + function control(e) { + e.preventDefault(); + const target = document.querySelector(this.hash); + self.scrollToY(target.offsetTop); + } + + let i; + let link; + const links = this.menu.querySelectorAll('a[href^="#"]'); + + for (i = 0; i < links.length; i += 1) { + link = links[i]; + link.addEventListener('click', control); + } + } + init() { + this.animated(); + document.addEventListener('scroll', () => { + this.menuControl(); + }); + } +} diff --git a/vanillajs-scrollspy-master/tests/index.spec.js b/vanillajs-scrollspy-master/tests/index.spec.js new file mode 100644 index 0000000..fbeb96d --- /dev/null +++ b/vanillajs-scrollspy-master/tests/index.spec.js @@ -0,0 +1,57 @@ +/* eslint-disable */ +import 'jsdom-global/register'; +import { expect } from 'chai'; +import VanillaScrollspy from '../src/index'; + +describe('vanillaScrollspy', () => { + let scrollspy; + let obj; + const navbar = document.createElement('div'); + navbar.setAttribute('id', 'navbar') + + beforeEach(() => { + scrollspy = new VanillaScrollspy(); + }); + + describe('smoke tests', () => { + it('should have scrollToY method', () => { + expect(scrollspy.scrollToY).to.exist; + }); + + it('should have `menuControl` method', () => { + expect(scrollspy.menuControl).to.exist; + }); + + it('should have `animated` method', () => { + expect(scrollspy.animated).to.exist; + }); + + it('should have `init` method', () => { + expect(scrollspy.init).to.exist; + }); + + it('should return default params when creating an instance', () => { + scrollspy = new VanillaScrollspy(navbar); + scrollspy.init() + + obj = { menu: navbar, speed: 2000, easing: 'easeOutSine' } + expect(scrollspy).to.be.eql(obj); + }); + + it('should return `speed: 1000` when overwriting the `speed` param', () => { + scrollspy = new VanillaScrollspy(navbar, 1000); + scrollspy.init() + + obj = { menu: navbar, speed: 1000, easing: 'easeOutSine' } + expect(scrollspy).to.be.eql(obj); + }); + + it('should return `speed: 1500` and `easing: easeInOutQuint` when overwriting the `speed` and `easing` params', () => { + scrollspy = new VanillaScrollspy(navbar, 1500, 'easeInOutQuint'); + scrollspy.init() + + obj = { menu: navbar, speed: 1500, easing: 'easeInOutQuint' } + expect(scrollspy).to.be.eql(obj); + }); + }); +}); diff --git a/vanillajs-scrollspy-master/webpack.config.babel.js b/vanillajs-scrollspy-master/webpack.config.babel.js new file mode 100644 index 0000000..7c47308 --- /dev/null +++ b/vanillajs-scrollspy-master/webpack.config.babel.js @@ -0,0 +1,28 @@ +import { join } from 'path'; + +const include = join(__dirname, 'src'); + +export default { + mode: 'development', + entry: './index', + output: { + path: join(__dirname, 'dist'), + libraryTarget: 'umd', + library: 'VanillaScrollspy', + }, + devtool: 'source-map', + module: { + rules: [ + { + test: /\.js$/, + exclude: /node_modules/, + loader: 'babel-loader', + query: { + presets: [ + ['es2015', { modules: false }] + ], + }, + }, + ], + }, +};