Repository: jimmynotjim/scrollNav Branch: master Commit: 4d78f2d6c560 Files: 70 Total size: 119.4 KB Directory structure: gitextract_xvjymejg/ ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .jestrc.json ├── .prettierrc.json ├── .travis.yml ├── CHANGELOG.md ├── CONTRIBUTING.md ├── LICENSE-MIT ├── README.md ├── bower.json ├── dist/ │ ├── scrollnav.min.mjs │ └── scrollnav.min.umd.js ├── jest.setup.js ├── jest.transform.js ├── package.json ├── src/ │ ├── scrollNav.v2-7-3.js │ ├── scrollTo.js │ ├── scrollnav.js │ ├── setupClickHandlers.js │ ├── setupResizeHandler.js │ ├── setupScrollHandler.js │ ├── teardownClickHandlers.js │ ├── teardownResizeHandler.js │ ├── teardownScrollHandler.js │ └── util/ │ ├── calculateScrollDuration.js │ ├── createList.js │ ├── createNav.js │ ├── easing.js │ ├── extend.js │ ├── getActiveSection.js │ ├── getOrSetID.js │ ├── getTargetYPosition.js │ ├── getYPosition.js │ ├── insertNav.js │ ├── insertVisualDebugger.js │ ├── nextUntil.js │ ├── populateSectionData.js │ ├── updateActiveNavItem.js │ └── updatePositionData.js └── test/ ├── .eslintrc.json ├── fixtures/ │ ├── navMarkup.js │ ├── noSectionsMarkup.js │ ├── pennerEasing.js │ ├── sectionData.js │ └── sectionMarkup.js ├── tests/ │ ├── scrollTo.test.js │ ├── scrollnav.test.js │ ├── setupClickHandlers.test.js │ ├── setupResizeHandler.test.js │ ├── setupScrollHander.test.js │ ├── teardownClickHandlers.test.js │ ├── teardownResizeHandler.test.js │ ├── teardownScrollHander.test.js │ └── util/ │ ├── calculateScrollDuration.test.js │ ├── createList.test.js │ ├── createNav.test.js │ ├── easing.test.js │ ├── extend.test.js │ ├── getActiveSection.test.js │ ├── getOrSetID.test.js │ ├── getTargetYPosition.test.js │ ├── getYPosition.test.js │ ├── insertNav.test.js │ ├── insertVisualDebugger.test.js │ ├── nextUntil.test.js │ ├── populateSectionData.test.js │ ├── updateActiveNavItem.test.js │ └── updatePositionData.test.js └── util/ └── simulateEvent.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .eslintignore ================================================ test/coverage ================================================ FILE: .eslintrc.json ================================================ { "env": { "browser": true, "es6": true }, "plugins": ["prettier"], "extends": ["eslint:recommended", "prettier"], "parserOptions": { "sourceType": "module", "ecmaVersion": 2017 }, "globals": { "module": false }, "rules": { "prettier/prettier": "error", "linebreak-style": ["error", "unix"], "quotes": ["error", "single"], "semi": ["error", "always"] } } ================================================ FILE: .gitignore ================================================ # System Files *.swp .DS_Store # Node Files /node_modules/ npm-debug.log bower_components ## Test Coverage Files test/coverage/ ================================================ FILE: .jestrc.json ================================================ { "collectCoverage": true, "coverageDirectory": "test/coverage", "collectCoverageFrom": ["src/**/*.js"], "coveragePathIgnorePatterns": ["/node_modules", "/src/scrollNav.v2-7-3.js"], "transform": { "^.+\\.js$": "/jest.transform.js" }, "setupFiles": ["/jest.setup.js"] } ================================================ FILE: .prettierrc.json ================================================ { "singleQuote": true } ================================================ FILE: .travis.yml ================================================ language: node_js node_js: - "8" - "10" install: - npm install - npm install codecov - codecov ================================================ FILE: CHANGELOG.md ================================================ # Changelog Releases are be numbered in the semantic versioning format: `..` And constructed with these guidelines: * Breaking backwards compatibility bumps the major * New additions without breaking backwards compatibility bumps the minor * Bug fixes and misc changes bump the patch For more information on semantic versioning, please visit http://semver.org/. ## v3.0.2 - December 25, 2018 Improved the documentation for browser support and removed polyfills covered by polyfills.io. ## v3.0.1 - December 22, 2018 Update file name casing for consistency. ## v3.0.0 - December 22, 2018 Version 3 is a complete re-write of scrollnav to move the project away from jQuery, update to the latest es6 features, and remove all production dependencies. This update also removes a number of user options to simplify the API and reduces the amount of DOM manipulation to reduce likelihood of browser bugs. Includes a full set of test suites for all modules (unless noted). Please read through the [readme](https://github.com/jimmynotjim/scrollnav/blob/master/README.md) for further details. ## v2.7.3 - March 19, 2018 * Added BEM-style active classes ## v2.7.2 - March 18, 2018 * Fixed grunt:jshint error * Fixed readme typo * Replaced andSelf() calls with addBack() * Updated semver version to fix vulnerability ## v2.7.1 - February 18, 2015 * Fixed package.json ## v2.7.0 - February 11, 2015 * Add `activeClass` setting for custom styles * Add `__focused-section` when a section is scrolled to ## v2.6.0 - February 19, 2015 * Added in-view and active logic to sub-sections ## v2.5.0 - January 18, 2015 * Add scrollToHash setting ## v2.4.0 - November 13, 2014 * Adds a new resetPos public function for updating the section positions when the page's content changes. Refer to the Readme for more details. ## v2.3.1 - October 30, 2014 * Patched an active section bug where no sections were active when a section matched the exact pixel offset calculated ## v2.3.0 - October 9, 2014 * Updated min Node to 0.10.\* * Updated all Node plugins to latest ## v2.2.0 - March 14, 2014 * Added option to change the classname used throughout the plugin. * Updated jQuery dep to 1.9.\* ## v2.1.1 - December 13, 2013 Added `scrollnav` namespace to event listeners to avoid crashing in to user defined event listeners. ## v2.1.0 - November 15, 2013 v2.1 adds support for public methods, a new destroy method, custom callbacks for init, render and destroy, and small bugfixes. * Reorganized core to allow for new public methods * Added destroy method to core to allow for breaking down the plugin and it's dom \* changes * Added the option to add callback functions to init, render and destroy * Squashed a bug when wrapping sub-sections in their div * Updated core init in test for easier reuse * Fixed Grunt test:browser task to only run in the browser * Added destroy tests to core module and a new module for the callbacks ## v2.0.2 - October 31, 2013 Double releasing to include changelog and readme updates in Bower. One day I'll figure all this out :) ## v2.0.1 - October 31, 2013 Bugfixes for the following: * package.json now includes semver: Ooops, sorry * Moved jQuery dependency from package.json to bower.json and updated jQuery dep to v1.8.\* * Removed unneeded build dirs from bower install * Updated gitignore to ignore bower_components ## v2.0.0 - October 11, 2013 v2 is a complete re-write of scrollnav and includes better code organization, new options, updated options, grunt integration, and bugfixes. This update will most like break your options and markup from v1, please read through the following changes and reference the [readme](https://github.com/jimmynotjim/scrollnav/blob/master/README.md) for further details. * Updated to wrap each section in a `section` tag and support for sub-sections (as well as an option to change the wrapping element). * Fixed the active state when scrolling, no longer switches to the next nav item as the page finishes scrolling. * There are now two classes added to the nav item when scrolling, `active` and `in-view`. All sections within the view bounds are marked as `in-view` and the topmost section is marked as `active`. * Added grunt workflow. Edits to the plugin should be made in `/src/scrollnav.js` with tests to support them and jshint, qunit, concat and uglify should be run before submitting PRs. * Added parsing of url for an element hash. This fixes inbound urls with a hash not scrolling to the section if plugin loading is delayed. * Added arrow key navigation option. When enabled, users can jump from section to section using the up/down arrow keys. * Added option to change insertion target. * Added Bower support for easy project dependency management. * Updated the class names of scrollnav elements to follow BEM conventions. * Updated existing settings option naming for the following (_this may break your current setups_): * `titleText` -> `headlineText` * `location` -> `insertLocation` ## v1.2.0 Added topLinkText option to customize the top link text (Thanks to [Wizcover][11]). ## v1.1.4 Updated Readme to include new options. ## v1.1.3 Added option for insertion location. ## v1.1.2 Added option to remove Top Link from the nav. ## v1.1.1 Fixed html rather than text being added to nav elements where heading contains nested elems. ## v1.1.0 Added options for showing Headline Text and animation speed. ## v1.0.1 Added ARIA support to nav elem (Thanks to [Jeff Coburn][10]). ## v1.0.0 Initial Release of scrollnav ================================================ FILE: CONTRIBUTING.md ================================================ # Contributing Guideline Thanks for contributing to scrollnav. Without you and the Open Source community this project wouldn't be possible. Before you get started, please familiarize yourself with the project and its standards. ## Issue Reports If you're looking for a way to contribute to this project, your best bet is to [start with the current issues][1]. Whether it's a new feature you'd like added, a bug you've found, or a question about using the plugin, there's always a chance you're not alone. Take a look through both the open and closed issues before creating a new one yourself. ### Improvements/features Before working on a new feature please submit an issue suggesting the feature and ensure that it is greenlighted. I'd hate for you to spend your time building a new feature that doesn't fit the project's scope or intentions. ### Bugs Before submitting a bug report, please create a reproducable test, either as a failing unit test on your own fork, or by forking the starter demo from Codepen and adjusting as necessary. It's a whole lot easier to address issues if I can understand the situation. If it's not obvious what's broken in your demo, include step-by-step instructions on how to reproduce the problem within the issue description. ## Pull Requests You've found a bug or had a feature greenlighted and you're ready to dig in and get to work. Congrats! This project was built and continues to improve from direct contributions from folks like you. Before you get too far, please be sure to read through and understand the steps below. ### Important notes Please don't edit files in the `dist` subdirectory as they are generated via NPM script. You'll find source code in the `src` subdirectory. ### Code style This project utilizes [Prettier][11] to ensure a consistent code style. Write your changes however you prefer but be sure to run `npm run format` prior to submitting a Pull Request. Don't worry about making a lot of small commits, your changes will be squashed within Github when the Pull Request is merged. ### Testing This project uses [Jest][12] for its unit tests. Prior to submitting a Pull Request, please ensure new functionality is tested and adjustments to previous functionality continue to pass. A failing test is better than no test at all and gives me a place to start reviewing. Additionally, it's a good idea to ensure your changes work in actual browsers. Including a demo on [Codepen][13] is a great way to ensure your changes are reviewed and merged in a timely manner. I've [created a base Pen][2] for you to fork and edit. ### Modifying the code First, ensure that you are working with [Node.js][14] version 8 or later and [npm][15] version 5 or later. Older versions of Node are supported but it's best to work with the Long Term Support (LTS), currently version 8. 1. Fork and clone the repo. 1. Run `npm install` to install the development dependencies. 1. Create a new branch that's appropriately named. Please don't work directly in your `master` branch, it makes testing locally difficult. 1. Add failing tests for the change you want to make in the `test/tests` directory. Run `npm test` to see the tests fail. 1. Edit the source files in the `src` directory. 1. Run `npm test` to see if the tests pass. Repeat steps 2-4 until done. 1. Run `npm run build` to generate the transpiled files in the `dist` directory. 1. Update the documentation to reflect any changes in functionality. 1. Commit and push your the branch to Github. 1. Navigate to your branch on Github and then to the `dist/scrollnav.min.js` file. 1. Select the "Raw" button and copy the file URL. 1. Fork the starter demo in Codepen and then click settings. 1. Under "Add External Scripts/Pens" replace the existing `dist/scrollnav.min.js` file URL with your raw file URL. 1. Test the interactions and ensure your intended changes work as expected. 1. Submit a Pull Request making sure to write a descriptive comment and include your forked Codepen URL. **Note: If none of this makes sense, it's ok. Any contribution is a useful one, even if it's not accepted. Please feel free to reach out to me to ask for help or clarification, I'm [@jimmynotim on Twitter][21].** To view all available build tasks run `npm run` without any arguments. [1]: https://github.com/jimmynotjim/scrollnav/issues [2]: https://codepen.io/jimmynotjim/pen/OZKeyd [11]: https://prettier.io/ [12]: https://facebook.github.io/jest/ [13]: https://codepen.io/ [14]: http://nodejs.org/ [15]: http://npmjs.org/ [21]: https://twitter.com/jimmynotjim ================================================ FILE: LICENSE-MIT ================================================ Copyright (c) 2018 James Wilson 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. ================================================ FILE: README.md ================================================ > This project is currently archived. I unfortunately don't have the time to maintain it. Thanks to everyone that contributed along the way, it wouldn't have been possible without you. # [scrollnav.js][1] [![npm](https://img.shields.io/npm/v/scrollnav.svg)](https://www.npmjs.com/package/scrollnav) [![Build Status](https://travis-ci.org/jimmynotjim/scrollnav.svg?branch=master)](https://travis-ci.org/jimmynotjim/scrollnav) [![Codecov](https://img.shields.io/codecov/c/github/codecov/example-python.svg)](https://codecov.io/gh/jimmynotjim/scrollnav) [![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://github.com/jimmynotjim/scrollnav/blob/master/LICENSE-MIT) ## Introduction scrollnav.js is a small (2.4kb gzipped), dependency free JavaScript plugin for auto generating single page navigation with active highlighting. Useful for creating a Table of Contents for a large document (think Wikis), navigation for a single page website, or anything else you might think of. scrollnav works by scanning a block of content for section landmarks (typically heading elements) and generating a list of links from those landmarks. It then tracks the scroll location of the document and highlights the appropriate link. While previous versions injected wrappers within the content, the current version (ver 3) takes a much lighter approach, only changing the DOM as necessary. Visit the live demo at [scrollnav.com][1] to see for yourself. ## Browser Compatibility To keep scrollnav small, default support starts with [ES6 compatible browsers](https://caniuse.com/#feat=arrow-functions). To support [ES5 compatible browsers](https://caniuse.com/#feat=es5) you must provide your own polyfills or rely on a third party library like pollyfills.io. I personally use the following [polyfill.io](https://github.com/Financial-Times/polyfill-service) feature parameters to support scrollnav in IE 10 & 11. ```html ``` To add your own polyfills you will need to build the project from source. ## Getting Started The compiled, production ready plugin is available in the `dist` directory. Please don't use the `src` directory unless you plan to build the entire source. ### Install #### Download [scrollnav@v3.0.2](https://unpkg.com/scrollnav@3.0.2/dist/scrollnav.min.umd.js) ```html ``` #### CDN ```html ``` #### Package manager [Yarn][13]: `yarn add scrollnav` It's the new hotness, it's also better at managing dependencies than all it's predecesors. [NPM][12]: `npm install scrollnav` Good'ol NPM, it's always there, except when it isn't. Things have settled down a bit, but it was dicey there for a while. Even still, there's a reason even Yarn uses the NPM registry. [Bower][11]: `bower install scrollnav --save` The folks from Bower no longer recommend using Bower. Luckily they've provided a guide on [how to migrate to Yarn](https://bower.io/blog/2017/how-to-migrate-away-from-bower/). If you don't want to or can't migrate, scrollnav will continue to be available on Bower as long as it continues to run. ### Usage scrollnav works by scanning the given [HTML Node Element][25] for section landmarks, by default `h2` elements, that it then uses to generate the nav. If we were to look at a typical document, it might look like this: ```html

First section

...

Second section

...

Third section

...
``` #### Initialize First, initialize scrollnav with the HTML Element. In this example we'll use `.querySelector()` but you could also use `.getElementByID()` or `.getElementByClassName()`. ```js const content = document.querySelector('.main-content'); scrollnav.init(content); ``` scrollnav will then loop through the the `h2` elements, add an ID if they don't already have one, build the nav, and then inject it just before the content Node. The result for our example document would look like this: ```html

First Heading

...
``` #### Styles To keep the plugin simple there are no styles added to the navigation, that's all up to you ([view the demo site][1] for exmaples of the most common use cases). The nav structure provides [BEM Methodology][23] class names for each of the elements to provide consistent styling hooks (for a good overview read [MindBEMding - getting your head 'round BEM syntax][24]). As the user scrolls the document, scrollnav adds a `scroll-nav__item--active` modifier for the item's relative section that currently intersects with the activation threshold ([enable `debug` mode](#additional-options) to highlight the threshold). ### Settings and options scrollnav includes some default settings that work for most situations, but if your project requires a bit more customization, scrollnav can most likely meet those. To modify either, pass in a single object (include settings and options as one object) as the second argument like this: ```js scrollnav.init(content, { key: value }); ``` #### Default settings The following settings are editable to overwrite the default. ```js { sections: 'selector', // string // // Sets the querySelector for the content's section landmarks, by default // it's 'h2'. insertTarget: targetNode, // HTML Node // // Sets the target Node for injecting the navigation, by default it's the // content Node passed to scrollnav. insertLocation: 'relativeLocation' // string // // Sets the injection location relative to the insertTarget, by default it's // 'before'. // // available options are 'append', 'prepend', 'after', or 'before' easingStyle: 'easingName', // string // // Sets the easing type for the scroll animation that is triggered by the // click event on a nav item, by default it's 'easeOutQuad'. // // available options are 'linear' 'easeInQuad', 'easeOutQuad', // 'easeInOutQuad', 'easeInCubic', 'easeOutCubic', 'easeInOutCubic', // 'easeInQuart', 'easeOutQuart', 'easeInOutQuart', 'easeInQuint', // 'easeOutQuint', easeInOutQuint updateHistory: true // boolean // // Sets the history behavior when a nav item is clicked, by default it's true } ``` #### Additional options These additional options are editable but are not set by default. ```js { subSections: '...', // string // // Sets the querySelector for the content's sub-section landmarks. onScroll: function() {...}, // function // // Sets the callback to be triggered after the window scrolls when triggered // by the click event on a nav item. onInit: function() {...}, // function // // Sets the callback to be triggered after the .init() method has completed. onUpdatePositions: function() {...}, // function // // Sets the callback to be triggered after the .updatePositions() method // has completed. onDestroy: function() {...}, // function // // Sets the callback to be triggered after the .destroy() method has // completed. debug: false // boolean // // Enables scrollnav's built in debug mode to log errors to the console and // display the active area threshold on screen, helpful for when you've hit a // snag you can't easily identify. } ``` #### Available methods In addition to the `.init()` method scrollnav provides two additional public methods. #### destroy() To remove the current instance of scrollnav call the destroy method. If you need to trigger a callback after scrollnav has been removed, use the `onDestroy` option described above (passed either in the original init or with the destroy method). ```js scrollnav.destroy(); ``` #### updatePositions() scrollnav doesn't track outside DOM changes. If your page's content is dynamic and updates after scrollnav is initialized you'll need to recalcuate the position data with the updatePositions method. If you need to trigger a callback after the position data has been recalculated, use the `onUpdatePositions` option described above (passed either in the original init or with the updatePositions method). ```js scrollnav.updatePositions(); ``` ## Issues Please read and understand the [Contributing Guidelines][4] prior to [opening an issue][2]. Ensuring your issue conforms to the guidelines gives it a better chance I'll be able to help address it. ## Questions For questions about using scrollnav in your own project, your best bet is to post it to [Stack Overflow][21]. The community there is great at lending a hand and can often respond faster than I can, plus it becomes searchable for future developers who may run into the same question. If you're still stuck, please feel free to reach out to me to ask for help or clarification, I'm [@jimmynotim on Twitter][22]. ## Changelog v3.0.2 is the current stable release. For detailed changes in each release please refer to the [release notes][5]. Please be sure you understand the changes before updating, v3 is a complete re-write of the plugin (as is v2 compared to v1 before it). ## Contributions scrollnav is built and maintained by [James Wilson (@jimmynotjim)][31]. I wouldn't be able to continue this project without a lot of help from the Open Source community. I welcome feedback and enhancements, but first, please make sure to read the [Contributing Guide][4]. Thank you to everyone who has already contributed to scrollnav! * [Chris Garcia (@pixelbandito)][43] * [Eric Clemmons (@ericclemmons)][32] * [Felix Borzik (@Borzik)][39] * [Jeff Byrnes (@jeffbyrnes)][33] * [Jeff Coburn (@coburnicus)][34] * [Jen Germann (@germanny)][35] * [Jim Schmid (@sheeep)][44] * [Marc Amos (@marcamos)][38] * [Masud Rahman (@frutiger)][40] * [Meghdad Hadidi (@MeghdadHadidi)][37] * [Michael Benin (@michael-benin-CN)][45] * [Rob Loach (@RobLoach)][41] * [Thomas Guillary @thomasguillory][46] * [Will Moore (@willthemoor)][42] * [Wizcover (@wizcover)][36] ## License scrollnav is Copyright © 2012-2018 James Wilson, released under the [MIT license][3]. This means you can re-create, edit or share the plugin as long as you maintain the same open licensing. [1]: http://scrollnav.com [2]: https://github.com/jimmynotjim/scrollnav/issues [3]: https://github.com/jimmynotjim/scrollnav/blob/master/LICENSE-MIT [4]: https://github.com/jimmynotjim/scrollnav/blob/master/CONTRIBUTING.md [5]: https://github.com/jimmynotjim/scrollnav/blob/master/CHANGELOG.md [11]: https://bower.io/ [12]: https://www.npmjs.com/package/scrollnav [13]: https://yarnpkg.com/en/package/scrollnav [21]: https://stackoverflow.com/questions [22]: https://twitter.com/jimmynotjim [23]: http://bem.info/method/ [24]: http://csswizardry.com/2013/01/mindbemding-getting-your-head-round-bem-syntax/ [25]: https://developer.mozilla.org/en-US/docs/Web/API/Element [31]: http://github.com/jimmynotjim [32]: https://github.com/ericclemmons [33]: https://github.com/jeffbyrnes [34]: https://github.com/coburnicus [35]: https://github.com/germanny [36]: https://github.com/wizcover [37]: https://github.com/MeghdadHadidi [38]: http://github.com/marcamos [39]: http://github.com/borzik [40]: http://github.com/frutiger [41]: http://github.com/RobLoach [42]: http://github.com/willthemoor [43]: http://github.com/pixelbandito [44]: http://github.com/sheeep [45]: http://github.com/michael-benin-CN [46]: http://github.com/thomasguillory ================================================ FILE: bower.json ================================================ { "name": "scrollnav", "version": "3.0.2", "author": { "name": "James Wilson", "email": "jimmynotjim@me.com", "url": "http://jimmynotjim.com" }, "repository": { "type": "git", "url": "https://github.com/jimmynotjim/scrollnav.git" }, "main": ["./dist/scrollnav.min.umd.js"], "dependencies": {}, "ignore": [ "node_modules", "libs", "src", "test", ".*", "*.json", "CONTRIBUTING.md", "*.txt" ], "keywords": [ "scrollnav", "javascript", "es6", "jquery", "navigation", "scrolling", "sticky nav", "scrolling nav" ] } ================================================ FILE: dist/scrollnav.min.mjs ================================================ function f(f,h){var y,w={};for(y in f)Object.prototype.hasOwnProperty.call(f,y)&&(w[y]=f[y]);for(y in h)Object.prototype.hasOwnProperty.call(h,y)&&(w[y]=h[y]);return w}function h(f,h){if("object"!=typeof f)return Promise.reject(new Error("First argument must be an object"));if("object"!=typeof(h=h||document.body))return Promise.reject(new Error("Second argument must be an object"));var y=h.getBoundingClientRect();return f.getBoundingClientRect().top-y.top}function y(f,w,E){void 0===E&&(E="scroll-nav");var L=[];return E+="__",f.forEach(function(f,O){var x=[],j=function(f,h){if("object"!=typeof f)return Promise.reject(new Error("First argument must be an object"));var y=f.id;if(!y){if("string"!=typeof h)return Promise.reject(new Error("Second argument must be a string"));f.id=y=h}return y}(f,E+(O+1));w.subSections&&f.matches(w.sections)&&(x=y(function(f,h,y){var w=[];for(f=f.nextElementSibling;f&&!f.matches(h);)!y||f.matches(y)?(w.push(f),f=f.nextElementSibling):f=f.nextElementSibling;return w}(f,w.sections,w.subSections),w,j));L.push({id:j,text:f.innerText||f.textContent,offsetTop:h(f),subSections:x})}),L}function w(f){var h=document.createElement("nav");return h.className="scroll-nav",h.innerHTML=function f(h,y){void 0===y&&(y=!1);var w="scroll-nav"+(y?"__sub-":"__"),E="\n "+h.map(function(h){return'
  • \n '+h.text+"\n "+(h.subSections&&h.subSections.length?""+f(h.subSections,!0):"")+"\n
  • "}).join("")+"\n ";return'\n
      \n '+E+"\n
    \n "}(f),h}function E(f){return f.forEach(function(f){var y=document.querySelector("#"+f.id);f.offsetTop=h(y),f.subSections.length&&(f.subSections=E(f.subSections))}),f}function L(f,h){var y=f.getAttribute("href");return"#"===y.charAt(0)&&(y=y.substr(1)),function f(h,y){var w;h.forEach(function(h){h.id===y&&(w=h),h.subSections&&void 0===w&&(w=f(h.subSections,y))});return w}(h,y).offsetTop}var O,x,j,_=function(f){return function(h){return Math.pow(h,f)}},I=function(f){return function(h){return 1-Math.abs(Math.pow(h-1,f))}},Q=function(f){return function(h){return h<.5?_(f)(2*h)/2:I(f)(2*h-1)/2+.5}},C={linear:Q(1),easeInQuad:_(2),easeOutQuad:I(2),easeInOutQuad:Q(2),easeInCubic:_(3),easeOutCubic:I(3),easeInOutCubic:Q(3),easeInQuart:_(4),easeOutQuart:I(4),easeInOutQuart:Q(4),easeInQuint:_(5),easeOutQuint:I(5),easeInOutQuint:Q(5)};function M(f,h){return new Promise(function(y,w){if("number"!=typeof f)return w(new Error("First argument must be a number"));if("string"!=typeof(h=h||"linear"))return w(new Error("Second argument must be a string"));var E,L=window.pageYOffset,O=f-L,x=function(f){var h=Math.abs(f/2);return Math.min(Math.max(h,250),1200)}(O),j=20,_=0;!function f(){E=C[h]((_+=j)/x),window.scroll(0,E*O+L),_w?!E&&f.offsetTop\n '+h.text+"\n "+(h.subSections&&h.subSections.length?""+f(h.subSections,!0):"")+"\n "}).join("")+"\n ";return'\n
      \n '+E+"\n
    \n "}(f),h}function E(f){return f.forEach(function(f){var y=document.querySelector("#"+f.id);f.offsetTop=h(y),f.subSections.length&&(f.subSections=E(f.subSections))}),f}function L(f,h){var y=f.getAttribute("href");return"#"===y.charAt(0)&&(y=y.substr(1)),function f(h,y){var w;h.forEach(function(h){h.id===y&&(w=h),h.subSections&&void 0===w&&(w=f(h.subSections,y))});return w}(h,y).offsetTop}var O,x,j,_=function(f){return function(h){return Math.pow(h,f)}},I=function(f){return function(h){return 1-Math.abs(Math.pow(h-1,f))}},Q=function(f){return function(h){return h<.5?_(f)(2*h)/2:I(f)(2*h-1)/2+.5}},C={linear:Q(1),easeInQuad:_(2),easeOutQuad:I(2),easeInOutQuad:Q(2),easeInCubic:_(3),easeOutCubic:I(3),easeInOutCubic:Q(3),easeInQuart:_(4),easeOutQuart:I(4),easeInOutQuart:Q(4),easeInQuint:_(5),easeOutQuint:I(5),easeInOutQuint:Q(5)};function M(f,h){return new Promise(function(y,w){if("number"!=typeof f)return w(new Error("First argument must be a number"));if("string"!=typeof(h=h||"linear"))return w(new Error("Second argument must be a string"));var E,L=window.pageYOffset,O=f-L,x=function(f){var h=Math.abs(f/2);return Math.min(Math.max(h,250),1200)}(O),j=20,_=0;!function f(){E=C[h]((_+=j)/x),window.scroll(0,E*O+L),_w?!E&&f.offsetTop { window.pageXOffset = xVal; window.pageYOffset = yVal; }; window.scrollBy = (xVal, yVal) => { const xStart = window.getPageXOffset; const yStart = window.getPageYOffset; window.pageXOffset = xStart + xVal; window.pageYOffset = yStart + yVal; }; ================================================ FILE: jest.transform.js ================================================ module.exports = require('babel-jest').createTransformer({ presets: ['@babel/preset-env'] }); ================================================ FILE: package.json ================================================ { "name": "scrollnav", "version": "3.0.2", "title": "scrollnav", "author": { "name": "James Wilson", "email": "jimmynotjim@me.com", "url": "http://jimmynotjim.com" }, "description": "A small, dependency free JavaScript plugin for auto generating single page navigation", "keywords": [ "scrollnav", "javascript", "es6", "jquery", "navigation", "scrolling", "sticky nav", "scrolling nav" ], "homepage": "http://scrollnav.com", "repository": { "type": "git", "url": "https://github.com/jimmynotjim/scrollnav.git" }, "files": [ "dist" ], "main": "dist/scrollnav.min.umd.js", "bugs": "https://github.com/jimmynotjim/scrollnav/issues", "license": "MIT", "engines": { "node": ">= 10.0.0" }, "scripts": { "build": "microbundle --compress false --name scrollnav", "format": "npm-run-all format:*", "format:source": "prettier --write 'src/**/*.js'", "format:test": "prettier --write 'test/**/*.js' !/coverage", "lint": "npm-run-all lint:*", "lint:source": "eslint 'src/**/*.js'", "lint:test": "eslint 'test/**/*.js'", "precommit": "npm run format && npm run lint && npm run build", "test": "jest --config .jestrc.json --no-cache", "watch": "microbundle --watch" }, "devDependencies": { "@babel/core": "^7.2.2", "@babel/polyfill": "^7.2.5", "@babel/preset-env": "^7.2.3", "@jarmee/jest-dom-custom-matchers": "^1.0.0", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^23.6.0", "eslint": "^5.10.0", "eslint-config-prettier": "^3.3.0", "eslint-plugin-prettier": "^3.0.0", "husky": "^1.2.1", "jest": "^23.6.0", "microbundle": "^0.9.0", "npm-run-all": "^4.1.5", "prettier": "^1.15.3" }, "source": "src/scrollnav.js", "husky": { "hooks": { "pre-commit": "npm run precommit" } } } ================================================ FILE: src/scrollNav.v2-7-3.js ================================================ /* * scrollNav * http://scrollnav.com * * Copyright (c) 2013-2016 James Wilson * Licensed under the MIT license. */ /* eslint-disable */ (function($) { // Animate scrolling to section location var scroll_to = function(value, speed, offset, animated) { if ($(value).length > 0) { var destination = $(value).offset().top; speed = animated ? speed : 0; // Add a class to the scrolled-to section $('.' + S.settings.className + '__focused-section').removeClass( S.settings.className + '__focused-section' ); $(value).addClass(S.settings.className + '__focused-section'); $('html:not(:animated),body:not(:animated)').animate( { scrollTop: destination - offset }, speed ); } }; // Get url hash if one exists var get_hash = function() { return window.location.hash; }; var S = { classes: { loading: 'sn-loading', failed: 'sn-failed', success: 'sn-active' }, defaults: { sections: 'h2', subSections: false, sectionElem: 'section', className: 'scroll-nav', showHeadline: true, headlineText: 'Scroll To', showTopLink: true, topLinkText: 'Top', fixedMargin: 40, scrollOffset: 40, animated: true, speed: 500, insertLocation: 'insertBefore', arrowKeys: false, scrollToHash: true, onInit: null, onRender: null, onDestroy: null, onResetPos: null }, _set_body_class: function(state) { // Set and swap our loading hooks to the body var $body = $('body'); if (state === 'loading') { $body.addClass(S.classes.loading); } else if (state === 'success') { $body.removeClass(S.classes.loading).addClass(S.classes.success); } else { $body.removeClass(S.classes.loading).addClass(S.classes.failed); } }, _find_sections: function($el) { // Find the html for each section var target_elems = S.settings.sections; var raw_html = []; if (S.settings.showTopLink) { var $firstElem = $el.children().first(); if (!$firstElem.is(target_elems)) { raw_html.push($firstElem.nextUntil(target_elems).addBack()); } } $el.find(target_elems).each(function() { raw_html.push( $(this) .nextUntil(target_elems) .addBack() ); }); S.sections = { raw: raw_html }; }, _setup_sections: function(sections) { // Wrap each section and add it's details to the section array var section_data = []; $(sections).each(function(i) { var sub_data = []; var $this_section = $(this); var section_id = 'scrollNav-' + (i + 1); var isFirst = function() { return i === 0; }; var hasHeading = function() { return !$this_section.eq(0).is(S.settings.sections); }; var text = S.settings.showTopLink && isFirst() && hasHeading() ? S.settings.topLinkText : $this_section.filter(S.settings.sections).text(); $this_section.wrapAll( '<' + S.settings.sectionElem + ' id="' + section_id + '" class="' + S.settings.className + '__section" />' ); if (S.settings.subSections) { var $sub_sections = $this_section.filter(S.settings.subSections); if ($sub_sections.length > 0) { $sub_sections.each(function(i) { var sub_id = section_id + '-' + (i + 1); var sub_text = $(this).text(); var $this_sub = $this_section.filter( $(this) .nextUntil($sub_sections) .addBack() ); $this_sub.wrapAll( '
    ' ); sub_data.push({ id: sub_id, text: sub_text }); }); } } section_data.push({ id: section_id, text: text, sub_sections: sub_data }); }); S.sections.data = section_data; }, _tear_down_sections: function(sections) { $(sections).each(function() { var sub_sections = this.sub_sections; $('#' + this.id) .children() .unwrap(); if (sub_sections.length > 0) { $(sub_sections).each(function() { $('#' + this.id) .children() .unwrap(); }); } }); }, _setup_nav: function(sections) { // Populate an ordered list from the section array we built var $headline = $('', { class: S.settings.className + '__heading', text: S.settings.headlineText }); var $wrapper = $('
    ', { class: S.settings.className + '__wrapper' }); var $nav = $('