UNPKG

foundation-sites

Version:

The most advanced responsive front-end framework in the world.

309 lines (286 loc) 14.7 kB
(function webpackUniversalModuleDefinition(root, factory) { if(typeof exports === 'object' && typeof module === 'object') module.exports = factory(require("./foundation.core"), require("jquery")); else if(typeof define === 'function' && define.amd) define(["./foundation.core", "jquery"], factory); else if(typeof exports === 'object') exports["__FOUNDATION_EXTERNAL__"] = factory(require("./foundation.core"), require("jquery")); else root["__FOUNDATION_EXTERNAL__"] = root["__FOUNDATION_EXTERNAL__"] || {}, root["__FOUNDATION_EXTERNAL__"]["foundation.smoothScroll"] = factory(root["__FOUNDATION_EXTERNAL__"]["foundation.core"], root["jQuery"]); })(self, function(__WEBPACK_EXTERNAL_MODULE__foundation_core__, __WEBPACK_EXTERNAL_MODULE_jquery__) { return /******/ (function() { // webpackBootstrap /******/ "use strict"; /******/ var __webpack_modules__ = ({ /***/ "./js/foundation.smoothScroll.js": /*!***************************************!*\ !*** ./js/foundation.smoothScroll.js ***! \***************************************/ /***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) { __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ SmoothScroll: function() { return /* binding */ SmoothScroll; } /* harmony export */ }); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! jquery */ "jquery"); /* harmony import */ var jquery__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(jquery__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./foundation.core.plugin */ "./foundation.core"); /* harmony import */ var _foundation_core_utils__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__); function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _classCallCheck(a, n) { if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function"); } function _defineProperties(e, r) { for (var t = 0; t < r.length; t++) { var o = r[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o); } } function _createClass(e, r, t) { return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", { writable: !1 }), e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); } function _possibleConstructorReturn(t, e) { if (e && ("object" == _typeof(e) || "function" == typeof e)) return e; if (void 0 !== e) throw new TypeError("Derived constructors may only return object or undefined"); return _assertThisInitialized(t); } function _assertThisInitialized(e) { if (void 0 === e) throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); return e; } function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); } function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); } function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); } function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); } /** * SmoothScroll module. * @module foundation.smoothScroll */ var SmoothScroll = /*#__PURE__*/function (_Plugin) { function SmoothScroll() { _classCallCheck(this, SmoothScroll); return _callSuper(this, SmoothScroll, arguments); } _inherits(SmoothScroll, _Plugin); return _createClass(SmoothScroll, [{ key: "_setup", value: /** * Creates a new instance of SmoothScroll. * @class * @name SmoothScroll * @fires SmoothScroll#init * @param {Object} element - jQuery object to add the trigger to. * @param {Object} options - Overrides to the default plugin settings. */ function _setup(element, options) { this.$element = element; this.options = jquery__WEBPACK_IMPORTED_MODULE_0___default().extend({}, SmoothScroll.defaults, this.$element.data(), options); this.className = 'SmoothScroll'; // ie9 back compat this._init(); } /** * Initialize the SmoothScroll plugin * @private */ }, { key: "_init", value: function _init() { var id = this.$element[0].id || (0,_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__.GetYoDigits)(6, 'smooth-scroll'); this.$element.attr({ id: id }); this._events(); } /** * Initializes events for SmoothScroll. * @private */ }, { key: "_events", value: function _events() { this._linkClickListener = this._handleLinkClick.bind(this); this.$element.on('click.zf.smoothScroll', this._linkClickListener); this.$element.on('click.zf.smoothScroll', 'a[href^="#"]', this._linkClickListener); } /** * Handle the given event to smoothly scroll to the anchor pointed by the event target. * @param {*} e - event * @function * @private */ }, { key: "_handleLinkClick", value: function _handleLinkClick(e) { var _this = this; // Follow the link if it does not point to an anchor. if (!jquery__WEBPACK_IMPORTED_MODULE_0___default()(e.currentTarget).is('a[href^="#"]')) return; var arrival = e.currentTarget.getAttribute('href'); this._inTransition = true; SmoothScroll.scrollToLoc(arrival, this.options, function () { _this._inTransition = false; }); e.preventDefault(); } }, { key: "_destroy", value: /** * Destroys the SmoothScroll instance. * @function */ function _destroy() { this.$element.off('click.zf.smoothScroll', this._linkClickListener); this.$element.off('click.zf.smoothScroll', 'a[href^="#"]', this._linkClickListener); } }], [{ key: "scrollToLoc", value: /** * Function to scroll to a given location on the page. * @param {String} loc - A properly formatted jQuery id selector. Example: '#foo' * @param {Object} options - The options to use. * @param {Function} callback - The callback function. * @static * @function */ function scrollToLoc(loc) { var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SmoothScroll.defaults; var callback = arguments.length > 2 ? arguments[2] : undefined; var $loc = jquery__WEBPACK_IMPORTED_MODULE_0___default()(loc); // Do nothing if target does not exist to prevent errors if (!$loc.length) return false; var scrollPos = Math.round($loc.offset().top - options.threshold / 2 - options.offset); jquery__WEBPACK_IMPORTED_MODULE_0___default()('html, body').stop(true).animate({ scrollTop: scrollPos }, options.animationDuration, options.animationEasing, function () { if (typeof callback === 'function') { callback(); } }); } }]); }(_foundation_core_utils__WEBPACK_IMPORTED_MODULE_1__.Plugin); /** * Default settings for plugin. */ SmoothScroll.defaults = { /** * Amount of time, in ms, the animated scrolling should take between locations. * @option * @type {number} * @default 500 */ animationDuration: 500, /** * Animation style to use when scrolling between locations. Can be `'swing'` or `'linear'`. * @option * @type {string} * @default 'linear' * @see {@link https://api.jquery.com/animate|Jquery animate} */ animationEasing: 'linear', /** * Number of pixels to use as a marker for location changes. * @option * @type {number} * @default 50 */ threshold: 50, /** * Number of pixels to offset the scroll of the page on item click if using a sticky nav bar. * @option * @type {number} * @default 0 */ offset: 0 }; /***/ }), /***/ "./foundation.core": /*!****************************************************************************************************************************************************************!*\ !*** external {"root":["__FOUNDATION_EXTERNAL__","foundation.core"],"amd":"./foundation.core","commonjs":"./foundation.core","commonjs2":"./foundation.core"} ***! \****************************************************************************************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE__foundation_core__; /***/ }), /***/ "jquery": /*!********************************************************************************************!*\ !*** external {"root":["jQuery"],"amd":"jquery","commonjs":"jquery","commonjs2":"jquery"} ***! \********************************************************************************************/ /***/ (function(module) { module.exports = __WEBPACK_EXTERNAL_MODULE_jquery__; /***/ }) /******/ }); /************************************************************************/ /******/ // The module cache /******/ var __webpack_module_cache__ = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ var cachedModule = __webpack_module_cache__[moduleId]; /******/ if (cachedModule !== undefined) { /******/ return cachedModule.exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { /******/ // no module.id needed /******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__); /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ /******/ /* webpack/runtime/compat get default export */ /******/ !function() { /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function() { return module['default']; } : /******/ function() { return module; }; /******/ __webpack_require__.d(getter, { a: getter }); /******/ return getter; /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/define property getters */ /******/ !function() { /******/ // define getter functions for harmony exports /******/ __webpack_require__.d = function(exports, definition) { /******/ for(var key in definition) { /******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) { /******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); /******/ } /******/ } /******/ }; /******/ }(); /******/ /******/ /* webpack/runtime/hasOwnProperty shorthand */ /******/ !function() { /******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); } /******/ }(); /******/ /******/ /* webpack/runtime/make namespace object */ /******/ !function() { /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ }(); /******/ /************************************************************************/ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. !function() { /*!*******************************************************!*\ !*** ./js/entries/plugins/foundation.smoothScroll.js ***! \*******************************************************/ __webpack_require__.r(__webpack_exports__); /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Foundation: function() { return /* reexport safe */ _foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation; }, /* harmony export */ SmoothScroll: function() { return /* reexport safe */ _foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__.SmoothScroll; } /* harmony export */ }); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./foundation.core */ "./foundation.core"); /* harmony import */ var _foundation_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_foundation_core__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../../foundation.smoothScroll */ "./js/foundation.smoothScroll.js"); _foundation_core__WEBPACK_IMPORTED_MODULE_0__.Foundation.plugin(_foundation_smoothScroll__WEBPACK_IMPORTED_MODULE_1__.SmoothScroll, 'SmoothScroll'); }(); /******/ return __webpack_exports__; /******/ })() ; }); //# sourceMappingURL=foundation.smoothScroll.js.map