foundation.smoothScroll.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. (function webpackUniversalModuleDefinition(root, factory) {
  2. if(typeof exports === 'object' && typeof module === 'object')
  3. module.exports = factory(require("./foundation.core"), require("jquery"));
  4. else if(typeof define === 'function' && define.amd)
  5. define(["./foundation.core", "jquery"], factory);
  6. else if(typeof exports === 'object')
  7. exports["foundation.smoothScroll"] = factory(require("./foundation.core"), require("jquery"));
  8. else
  9. root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.smoothScroll"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"]);
  10. })(window, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__) {
  11. return /******/ (function(modules) { // webpackBootstrap
  12. /******/ // The module cache
  13. /******/ var installedModules = {};
  14. /******/
  15. /******/ // The require function
  16. /******/ function __webpack_require__(moduleId) {
  17. /******/
  18. /******/ // Check if module is in cache
  19. /******/ if(installedModules[moduleId]) {
  20. /******/ return installedModules[moduleId].exports;
  21. /******/ }
  22. /******/ // Create a new module (and put it into the cache)
  23. /******/ var module = installedModules[moduleId] = {
  24. /******/ i: moduleId,
  25. /******/ l: false,
  26. /******/ exports: {}
  27. /******/ };
  28. /******/
  29. /******/ // Execute the module function
  30. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  31. /******/
  32. /******/ // Flag the module as loaded
  33. /******/ module.l = true;
  34. /******/
  35. /******/ // Return the exports of the module
  36. /******/ return module.exports;
  37. /******/ }
  38. /******/
  39. /******/
  40. /******/ // expose the modules object (__webpack_modules__)
  41. /******/ __webpack_require__.m = modules;
  42. /******/
  43. /******/ // expose the module cache
  44. /******/ __webpack_require__.c = installedModules;
  45. /******/
  46. /******/ // define getter function for harmony exports
  47. /******/ __webpack_require__.d = function(exports, name, getter) {
  48. /******/ if(!__webpack_require__.o(exports, name)) {
  49. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  50. /******/ }
  51. /******/ };
  52. /******/
  53. /******/ // define __esModule on exports
  54. /******/ __webpack_require__.r = function(exports) {
  55. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  56. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  57. /******/ }
  58. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  59. /******/ };
  60. /******/
  61. /******/ // create a fake namespace object
  62. /******/ // mode & 1: value is a module id, require it
  63. /******/ // mode & 2: merge all properties of value into the ns
  64. /******/ // mode & 4: return value when already ns object
  65. /******/ // mode & 8|1: behave like require
  66. /******/ __webpack_require__.t = function(value, mode) {
  67. /******/ if(mode & 1) value = __webpack_require__(value);
  68. /******/ if(mode & 8) return value;
  69. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  70. /******/ var ns = Object.create(null);
  71. /******/ __webpack_require__.r(ns);
  72. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  73. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  74. /******/ return ns;
  75. /******/ };
  76. /******/
  77. /******/ // getDefaultExport function for compatibility with non-harmony modules
  78. /******/ __webpack_require__.n = function(module) {
  79. /******/ var getter = module && module.__esModule ?
  80. /******/ function getDefault() { return module['default']; } :
  81. /******/ function getModuleExports() { return module; };
  82. /******/ __webpack_require__.d(getter, 'a', getter);
  83. /******/ return getter;
  84. /******/ };
  85. /******/
  86. /******/ // Object.prototype.hasOwnProperty.call
  87. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  88. /******/
  89. /******/ // __webpack_public_path__
  90. /******/ __webpack_require__.p = "";
  91. /******/
  92. /******/
  93. /******/ // Load entry module and return exports
  94. /******/ return __webpack_require__(__webpack_require__.s = 16);
  95. /******/ })
  96. /************************************************************************/
  97. /******/ ({
  98. /***/ "./foundation.core":
  99. /*!****************************************************************************************************************************************************************!*\
  100. !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***!
  101. \****************************************************************************************************************************************************************/
  102. /*! no static exports found */
  103. /***/ (function(module, exports) {
  104. module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__;
  105. /***/ }),
  106. /***/ "./js/entries/plugins/foundation.smoothScroll.js":
  107. /*!*******************************************************!*\
  108. !*** ./js/entries/plugins/foundation.smoothScroll.js ***!
  109. \*******************************************************/
  110. /*! exports provided: Foundation, SmoothScroll */
  111. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  112. "use strict";
  113. __webpack_require__.r(__webpack_exports__);
  114. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core");
  115. /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__);
  116. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "Foundation", function() { return _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"]; });
  117. /* harmony import */ var _foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.smoothScroll */ "./js/foundation.smoothScroll.js");
  118. /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SmoothScroll", function() { return _foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__["SmoothScroll"]; });
  119. _foundation_core__WEBPACK_IMPORTED_MODULE_0__["Foundation"].plugin(_foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__["SmoothScroll"], 'SmoothScroll');
  120. /***/ }),
  121. /***/ "./js/foundation.smoothScroll.js":
  122. /*!***************************************!*\
  123. !*** ./js/foundation.smoothScroll.js ***!
  124. \***************************************/
  125. /*! exports provided: SmoothScroll */
  126. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  127. "use strict";
  128. __webpack_require__.r(__webpack_exports__);
  129. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "SmoothScroll", function() { return SmoothScroll; });
  130. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery");
  131. /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__);
  132. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.utils */ "./foundation.core");
  133. /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__);
  134. function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  135. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  136. 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); } }
  137. function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  138. function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  139. function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  140. function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  141. function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  142. function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  143. /**
  144. * SmoothScroll module.
  145. * @module foundation.smoothScroll
  146. */
  147. var SmoothScroll =
  148. /*#__PURE__*/
  149. function (_Plugin) {
  150. _inherits(SmoothScroll, _Plugin);
  151. function SmoothScroll() {
  152. _classCallCheck(this, SmoothScroll);
  153. return _possibleConstructorReturn(this, _getPrototypeOf(SmoothScroll).apply(this, arguments));
  154. }
  155. _createClass(SmoothScroll, [{
  156. key: "_setup",
  157. /**
  158. * Creates a new instance of SmoothScroll.
  159. * @class
  160. * @name SmoothScroll
  161. * @fires SmoothScroll#init
  162. * @param {Object} element - jQuery object to add the trigger to.
  163. * @param {Object} options - Overrides to the default plugin settings.
  164. */
  165. value: function _setup(element, options) {
  166. this.$element = element;
  167. this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default.a.extend({}, SmoothScroll.defaults, this.$element.data(), options);
  168. this.className = 'SmoothScroll'; // ie9 back compat
  169. this._init();
  170. }
  171. /**
  172. * Initialize the SmoothScroll plugin
  173. * @private
  174. */
  175. }, {
  176. key: "_init",
  177. value: function _init() {
  178. var id = this.$element[0].id || Object(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["GetYoDigits"])(6, 'smooth-scroll');
  179. this.$element.attr({
  180. id: id
  181. });
  182. this._events();
  183. }
  184. /**
  185. * Initializes events for SmoothScroll.
  186. * @private
  187. */
  188. }, {
  189. key: "_events",
  190. value: function _events() {
  191. this._linkClickListener = this._handleLinkClick.bind(this);
  192. this.$element.on('click.zf.smoothScroll', this._linkClickListener);
  193. this.$element.on('click.zf.smoothScroll', 'a[href^="#"]', this._linkClickListener);
  194. }
  195. /**
  196. * Handle the given event to smoothly scroll to the anchor pointed by the event target.
  197. * @param {*} e - event
  198. * @function
  199. * @private
  200. */
  201. }, {
  202. key: "_handleLinkClick",
  203. value: function _handleLinkClick(e) {
  204. var _this = this;
  205. // Follow the link if it does not point to an anchor.
  206. if (!jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.currentTarget).is('a[href^="#"]')) return;
  207. var arrival = e.currentTarget.getAttribute('href');
  208. this._inTransition = true;
  209. SmoothScroll.scrollToLoc(arrival, this.options, function () {
  210. _this._inTransition = false;
  211. });
  212. e.preventDefault();
  213. }
  214. }, {
  215. key: "_destroy",
  216. /**
  217. * Destroys the SmoothScroll instance.
  218. * @function
  219. */
  220. value: function _destroy() {
  221. this.$element.off('click.zf.smoothScroll', this._linkClickListener);
  222. this.$element.off('click.zf.smoothScroll', 'a[href^="#"]', this._linkClickListener);
  223. }
  224. }], [{
  225. key: "scrollToLoc",
  226. /**
  227. * Function to scroll to a given location on the page.
  228. * @param {String} loc - A properly formatted jQuery id selector. Example: '#foo'
  229. * @param {Object} options - The options to use.
  230. * @param {Function} callback - The callback function.
  231. * @static
  232. * @function
  233. */
  234. value: function scrollToLoc(loc) {
  235. var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SmoothScroll.defaults;
  236. var callback = arguments.length > 2 ? arguments[2] : undefined;
  237. var $loc = jquery__WEBPACK_IMPORTED_MODULE_0___default()(loc); // Do nothing if target does not exist to prevent errors
  238. if (!$loc.length) return false;
  239. var scrollPos = Math.round($loc.offset().top - options.threshold / 2 - options.offset);
  240. jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').stop(true).animate({
  241. scrollTop: scrollPos
  242. }, options.animationDuration, options.animationEasing, function () {
  243. if (typeof callback === 'function') {
  244. callback();
  245. }
  246. });
  247. }
  248. }]);
  249. return SmoothScroll;
  250. }(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__["Plugin"]);
  251. /**
  252. * Default settings for plugin.
  253. */
  254. SmoothScroll.defaults = {
  255. /**
  256. * Amount of time, in ms, the animated scrolling should take between locations.
  257. * @option
  258. * @type {number}
  259. * @default 500
  260. */
  261. animationDuration: 500,
  262. /**
  263. * Animation style to use when scrolling between locations. Can be `'swing'` or `'linear'`.
  264. * @option
  265. * @type {string}
  266. * @default 'linear'
  267. * @see {@link https://api.jquery.com/animate|Jquery animate}
  268. */
  269. animationEasing: 'linear',
  270. /**
  271. * Number of pixels to use as a marker for location changes.
  272. * @option
  273. * @type {number}
  274. * @default 50
  275. */
  276. threshold: 50,
  277. /**
  278. * Number of pixels to offset the scroll of the page on item click if using a sticky nav bar.
  279. * @option
  280. * @type {number}
  281. * @default 0
  282. */
  283. offset: 0
  284. };
  285. /***/ }),
  286. /***/ 16:
  287. /*!*************************************************************!*\
  288. !*** multi ./js/entries/plugins/foundation.smoothScroll.js ***!
  289. \*************************************************************/
  290. /*! no static exports found */
  291. /***/ (function(module, exports, __webpack_require__) {
  292. module.exports = __webpack_require__(/*! /Users/joeworkman/Development/foundation-sites/js/entries/plugins/foundation.smoothScroll.js */"./js/entries/plugins/foundation.smoothScroll.js");
  293. /***/ }),
  294. /***/ "jquery":
  295. /*!********************************************************************************************!*\
  296. !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***!
  297. \********************************************************************************************/
  298. /*! no static exports found */
  299. /***/ (function(module, exports) {
  300. module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__;
  301. /***/ })
  302. /******/ });
  303. });
  304. //# sourceMappingURL=foundation.smoothScroll.js.map