From 8339bf4d5ccfbcd7745593e422b79e19bf2ad914 Mon Sep 17 00:00:00 2001 From: Georgy Marchuk Date: Tue, 15 May 2018 21:10:55 +0200 Subject: [PATCH] dist --- dist/swup.js | 1261 +++++++++++++++++++++++++++++++++++++++------ dist/swup.min.js | 351 +------------ webpack.config.js | 7 +- 3 files changed, 1107 insertions(+), 512 deletions(-) diff --git a/dist/swup.js b/dist/swup.js index 5a417cb3..d5ca9bcd 100644 --- a/dist/swup.js +++ b/dist/swup.js @@ -80,271 +80,1210 @@ return /******/ (function(modules) { // webpackBootstrap /******/ /******/ /******/ // Load entry module and return exports -/******/ return __webpack_require__(__webpack_require__.s = "./entry.js"); +/******/ return __webpack_require__(__webpack_require__.s = 21); /******/ }) /************************************************************************/ -/******/ ({ - -/***/ "./entry.js": -/*!******************!*\ - !*** ./entry.js ***! - \******************/ -/*! no static exports found */ +/******/ ([ +/* 0 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nvar _index = __webpack_require__(/*! ./src/index.js */ \"./src/index.js\");\n\nvar _index2 = _interopRequireDefault(_index);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nmodule.exports = _index2.default; // this is here for webpack to expose Swup as window.Swup\n\n//# sourceURL=webpack://Swup/./entry.js?"); + + +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 Link = function () { + function Link() { + _classCallCheck(this, Link); + + this.link = document.createElement("a"); + } + + _createClass(Link, [{ + key: 'setPath', + value: function setPath(href) { + this.link.href = href; + } + }, { + key: 'getPath', + value: function getPath() { + var path = this.link.pathname; + if (path[0] != '/') { + path = '/' + path; + } + return path; + } + }, { + key: 'getAddress', + value: function getAddress() { + var path = this.link.pathname + this.link.search; + if (path[0] != '/') { + path = '/' + path; + } + return path; + } + }, { + key: 'getHash', + value: function getHash() { + return this.link.hash; + } + }]); + + return Link; +}(); + +exports.default = Link; /***/ }), +/* 1 */ +/***/ (function(module, exports, __webpack_require__) { -/***/ "./node_modules/delegate/src/closest.js": -/*!**********************************************!*\ - !*** ./node_modules/delegate/src/closest.js ***! - \**********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { +"use strict"; -eval("var DOCUMENT_NODE_TYPE = 9;\n\n/**\n * A polyfill for Element.matches()\n */\nif (typeof Element !== 'undefined' && !Element.prototype.matches) {\n var proto = Element.prototype;\n\n proto.matches = proto.matchesSelector ||\n proto.mozMatchesSelector ||\n proto.msMatchesSelector ||\n proto.oMatchesSelector ||\n proto.webkitMatchesSelector;\n}\n\n/**\n * Finds the closest parent that matches a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @return {Function}\n */\nfunction closest (element, selector) {\n while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {\n if (typeof element.matches === 'function' &&\n element.matches(selector)) {\n return element;\n }\n element = element.parentNode;\n }\n}\n\nmodule.exports = closest;\n\n\n//# sourceURL=webpack://Swup/./node_modules/delegate/src/closest.js?"); -/***/ }), +var _Link = __webpack_require__(0); + +var _Link2 = _interopRequireDefault(_Link); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +module.exports = function (eventName) { + var _this = this; + + if (this.options.preload) { + var preload = function preload(pathname) { + var link = new _Link2.default(); + link.setPath(pathname); + if (link.getAddress() != _this.currentUrl && !_this.cache.exists(link.getAddress()) && _this.preloadPromise == null) { + _this.getPage(link.getAddress(), function (response) { + if (response === null) { + console.warn('Server error.'); + _this.triggerEvent('serverError'); + } else { + // get json data + var page = _this.getDataFromHtml(response); + page.url = link.getAddress(); + _this.cache.cacheUrl(page, _this.options.debugMode); + _this.triggerEvent('pagePreloaded'); + } + }); + } + }; + + document.querySelectorAll('[data-swup-preload]').forEach(function (element) { + preload(element.href); + }); + } +}; -/***/ "./node_modules/delegate/src/delegate.js": -/*!***********************************************!*\ - !*** ./node_modules/delegate/src/delegate.js ***! - \***********************************************/ -/*! no static exports found */ +/***/ }), +/* 2 */ /***/ (function(module, exports, __webpack_require__) { -eval("var closest = __webpack_require__(/*! ./closest */ \"./node_modules/delegate/src/closest.js\");\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction delegate(element, selector, type, callback, useCapture) {\n var listenerFn = listener.apply(this, arguments);\n\n element.addEventListener(type, listenerFn, useCapture);\n\n return {\n destroy: function() {\n element.removeEventListener(type, listenerFn, useCapture);\n }\n }\n}\n\n/**\n * Finds closest match and invokes callback.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Function}\n */\nfunction listener(element, selector, type, callback) {\n return function(e) {\n e.delegateTarget = closest(e.target, selector);\n\n if (e.delegateTarget) {\n callback.call(element, e);\n }\n }\n}\n\nmodule.exports = delegate;\n\n\n//# sourceURL=webpack://Swup/./node_modules/delegate/src/delegate.js?"); +"use strict"; -/***/ }), -/***/ "./node_modules/detectie/detectie.js": -/*!*******************************************!*\ - !*** ./node_modules/detectie/detectie.js ***! - \*******************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { +module.exports = function (from, to, custom) { -eval("/**\n * detect IE\n * returns version of IE or false, if browser is not Internet Explorer\n */\nvar detectie = function() {\n var ua = window.navigator.userAgent;\n\n var msie = ua.indexOf('MSIE ');\n if (msie > 0) {\n // IE 10 or older => return version number\n return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);\n }\n\n var trident = ua.indexOf('Trident/');\n if (trident > 0) {\n // IE 11 => return version number\n var rv = ua.indexOf('rv:');\n return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);\n }\n\n var edge = ua.indexOf('Edge/');\n if (edge > 0) {\n // IE 12 => return version number\n return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);\n }\n // other browser\n return false;\n}\n\nmodule.exports = detectie;\n\n//# sourceURL=webpack://Swup/./node_modules/detectie/detectie.js?"); + // homepage case + if (from == "/") { + from = "/homepage"; + } + if (to == "/") { + to = "/homepage"; + } -/***/ }), + // transition routes + this.transition = { + from: from.replace('/', ''), + to: to.replace('/', '') + }; + + if (custom) { + this.transition.custom = custom; + } +}; -/***/ "./src/Cache.js": -/*!**********************!*\ - !*** ./src/Cache.js ***! - \**********************/ -/*! no static exports found */ +/***/ }), +/* 3 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Cache = function () {\n function Cache() {\n _classCallCheck(this, Cache);\n\n this.pages = {};\n this.count = 0;\n this.last = null;\n }\n\n _createClass(Cache, [{\n key: 'cacheUrl',\n value: function cacheUrl(page, displayCache) {\n this.count++;\n if (page.url in this.pages === false) {\n this.pages[page.url] = page;\n }\n this.last = this.pages[page.url];\n if (displayCache) {\n this.displayCache();\n }\n }\n }, {\n key: 'getPage',\n value: function getPage(url) {\n return this.pages[url];\n }\n }, {\n key: 'displayCache',\n value: function displayCache() {\n console.groupCollapsed('Cache (' + Object.keys(this.pages).length + ')');\n for (var key in this.pages) {\n console.log(this.pages[key]);\n }\n console.groupEnd();\n }\n }, {\n key: 'exists',\n value: function exists(url) {\n if (url in this.pages) return true;\n return false;\n }\n }, {\n key: 'empty',\n value: function empty(showLog) {\n this.pages = {};\n this.count = 0;\n this.last = null;\n if (showLog) {\n console.log('Cache cleared');\n }\n }\n }]);\n\n return Cache;\n}();\n\nexports.default = Cache;\n\n//# sourceURL=webpack://Swup/./src/Cache.js?"); -/***/ }), -/***/ "./src/Link.js": -/*!*********************!*\ - !*** ./src/Link.js ***! - \*********************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { +module.exports = function (element) { + var _this = this; -"use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Link = function () {\n function Link() {\n _classCallCheck(this, Link);\n\n this.link = document.createElement(\"a\");\n }\n\n _createClass(Link, [{\n key: 'setPath',\n value: function setPath(href) {\n this.link.href = href;\n }\n }, {\n key: 'getPath',\n value: function getPath() {\n var path = this.link.pathname;\n if (path[0] != '/') {\n path = '/' + path;\n }\n return path;\n }\n }, {\n key: 'getAddress',\n value: function getAddress() {\n var path = this.link.pathname + this.link.search;\n if (path[0] != '/') {\n path = '/' + path;\n }\n return path;\n }\n }, {\n key: 'getHash',\n value: function getHash() {\n return this.link.hash;\n }\n }]);\n\n return Link;\n}();\n\nexports.default = Link;\n\n//# sourceURL=webpack://Swup/./src/Link.js?"); + var blocks = 0; -/***/ }), + for (var i = 0; i < this.options.elements.length; i++) { + if (element.querySelector(this.options.elements[i]) == null) { + console.warn("Element " + this.options.elements[i] + " is not in current page."); + } else { + [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) { + element.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks; + blocks++; + }); + } + } +}; -/***/ "./src/index.js": -/*!**********************!*\ - !*** ./src/index.js ***! - \**********************/ -/*! no static exports found */ +/***/ }), +/* 4 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _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; }; }();\n\n// helpers\n\n\n// modules\n\n\nvar _delegate = __webpack_require__(/*! delegate */ \"./node_modules/delegate/src/delegate.js\");\n\nvar _delegate2 = _interopRequireDefault(_delegate);\n\nvar _detectie = __webpack_require__(/*! detectie */ \"./node_modules/detectie/detectie.js\");\n\nvar _detectie2 = _interopRequireDefault(_detectie);\n\nvar _Cache = __webpack_require__(/*! ./Cache */ \"./src/Cache.js\");\n\nvar _Cache2 = _interopRequireDefault(_Cache);\n\nvar _Link = __webpack_require__(/*! ./Link */ \"./src/Link.js\");\n\nvar _Link2 = _interopRequireDefault(_Link);\n\nvar _transitionEnd = __webpack_require__(/*! ./transitionEnd */ \"./src/transitionEnd.js\");\n\nvar _transitionEnd2 = _interopRequireDefault(_transitionEnd);\n\nvar _request = __webpack_require__(/*! ./modules/request */ \"./src/modules/request.js\");\n\nvar _request2 = _interopRequireDefault(_request);\n\nvar _getDataFromHtml = __webpack_require__(/*! ./modules/getDataFromHtml */ \"./src/modules/getDataFromHtml.js\");\n\nvar _getDataFromHtml2 = _interopRequireDefault(_getDataFromHtml);\n\nvar _loadPage = __webpack_require__(/*! ./modules/loadPage */ \"./src/modules/loadPage.js\");\n\nvar _loadPage2 = _interopRequireDefault(_loadPage);\n\nvar _renderPage = __webpack_require__(/*! ./modules/renderPage */ \"./src/modules/renderPage.js\");\n\nvar _renderPage2 = _interopRequireDefault(_renderPage);\n\nvar _goBack = __webpack_require__(/*! ./modules/goBack */ \"./src/modules/goBack.js\");\n\nvar _goBack2 = _interopRequireDefault(_goBack);\n\nvar _createState = __webpack_require__(/*! ./modules/createState */ \"./src/modules/createState.js\");\n\nvar _createState2 = _interopRequireDefault(_createState);\n\nvar _triggerEvent = __webpack_require__(/*! ./modules/triggerEvent */ \"./src/modules/triggerEvent.js\");\n\nvar _triggerEvent2 = _interopRequireDefault(_triggerEvent);\n\nvar _getUrl = __webpack_require__(/*! ./modules/getUrl */ \"./src/modules/getUrl.js\");\n\nvar _getUrl2 = _interopRequireDefault(_getUrl);\n\nvar _scrollTo = __webpack_require__(/*! ./modules/scrollTo */ \"./src/modules/scrollTo.js\");\n\nvar _scrollTo2 = _interopRequireDefault(_scrollTo);\n\nvar _classify = __webpack_require__(/*! ./modules/classify */ \"./src/modules/classify.js\");\n\nvar _classify2 = _interopRequireDefault(_classify);\n\nvar _doScrolling = __webpack_require__(/*! ./modules/doScrolling */ \"./src/modules/doScrolling.js\");\n\nvar _doScrolling2 = _interopRequireDefault(_doScrolling);\n\nvar _markSwupElements = __webpack_require__(/*! ./modules/markSwupElements */ \"./src/modules/markSwupElements.js\");\n\nvar _markSwupElements2 = _interopRequireDefault(_markSwupElements);\n\nvar _updateTransition = __webpack_require__(/*! ./modules/updateTransition */ \"./src/modules/updateTransition.js\");\n\nvar _updateTransition2 = _interopRequireDefault(_updateTransition);\n\nvar _preloadPages = __webpack_require__(/*! ./modules/preloadPages */ \"./src/modules/preloadPages.js\");\n\nvar _preloadPages2 = _interopRequireDefault(_preloadPages);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Swup = function () {\n function Swup(setOptions) {\n _classCallCheck(this, Swup);\n\n // default options\n var defaults = {\n cache: true,\n animationSelector: '[class^=\"a-\"]',\n elements: ['#swup'],\n pageClassPrefix: '',\n debugMode: false,\n scroll: true,\n preload: true,\n support: true,\n disableIE: false,\n\n animateScrollToAnchor: false,\n animateScrollOnMobile: false,\n doScrollingRightAway: false,\n scrollDuration: 0,\n\n LINK_SELECTOR: 'a[href^=\"/\"]:not([data-no-swup]), a[href^=\"#\"]:not([data-no-swup]), a[xlink\\\\:href]'\n\n /**\n * current transition object\n */\n };this.transition = {};\n\n var options = _extends({}, defaults, setOptions);\n\n /**\n * helper variables\n */\n // mobile detection variable\n this.mobile = false;\n // id of element to scroll to after render\n this.scrollToElement = null;\n // promise used for preload, so no new loading of the same page starts while page is loading\n this.preloadPromise = null;\n // save options\n this.options = options;\n\n /**\n * make modules accessible in instance\n */\n this.getUrl = _getUrl2.default;\n this.cache = new _Cache2.default();\n this.link = new _Link2.default();\n this.transitionEndEvent = (0, _transitionEnd2.default)();\n this.getDataFromHtml = _getDataFromHtml2.default;\n this.getPage = _request2.default;\n this.scrollTo = _scrollTo2.default;\n this.loadPage = _loadPage2.default;\n this.renderPage = _renderPage2.default;\n this.goBack = _goBack2.default;\n this.createState = _createState2.default;\n this.triggerEvent = _triggerEvent2.default;\n this.classify = _classify2.default;\n this.doScrolling = _doScrolling2.default;\n this.markSwupElements = _markSwupElements2.default;\n this.updateTransition = _updateTransition2.default;\n this.preloadPages = _preloadPages2.default;\n this.detectie = _detectie2.default;\n this.enable = this.enable;\n this.destroy = this.destroy;\n\n /**\n * detect mobile devices\n */\n if (this.options.scroll) {\n if (window.innerWidth <= 767) {\n this.mobile = true;\n }\n }\n\n // attach instance to window in debug mode\n if (this.options.debugMode) {\n window.swup = this;\n }\n\n this.getUrl();\n this.enable();\n }\n\n _createClass(Swup, [{\n key: 'enable',\n value: function enable() {\n /**\n * support check\n */\n if (this.options.support) {\n // check pushState support\n if (!('pushState' in window.history)) {\n console.warn('pushState is not supported');\n return;\n }\n // check transitionEnd support\n if ((0, _transitionEnd2.default)()) {\n this.transitionEndEvent = (0, _transitionEnd2.default)();\n } else {\n console.warn('transitionEnd detection is not supported');\n return;\n }\n // check Promise support\n if (typeof Promise === \"undefined\" || Promise.toString().indexOf(\"[native code]\") === -1) {\n console.warn('Promise is not supported');\n return;\n }\n }\n /**\n * disable IE\n */\n if (this.options.disableIE && this.detectie()) {\n return;\n }\n\n // variable to keep event listeners from \"delegate\"\n this.delegatedListeners = {};\n\n /**\n * link click handler\n */\n this.delegatedListeners.click = (0, _delegate2.default)(document, this.options.LINK_SELECTOR, 'click', this.linkClickHandler.bind(this));\n\n /**\n * link mouseover handler (preload)\n */\n this.delegatedListeners.mouseover = (0, _delegate2.default)(document.body, this.options.LINK_SELECTOR, 'mouseover', this.linkMouseoverHandler.bind(this));\n\n /**\n * popstate handler\n */\n window.addEventListener('popstate', this.popStateHandler.bind(this));\n\n /**\n * initial save to cache\n */\n var page = this.getDataFromHtml(document.documentElement.innerHTML);\n page.url = this.currentUrl;\n if (this.options.cache) {\n this.cache.cacheUrl(page, this.options.debugMode);\n }\n\n /**\n * mark swup blocks in html\n */\n this.markSwupElements(document.documentElement);\n\n /**\n * trigger enabled event\n */\n this.triggerEvent('enabled');\n document.documentElement.classList.add('swup-enabled');\n\n /**\n * trigger page view event\n */\n this.triggerEvent('pageView');\n\n /**\n * preload pages if possible\n */\n this.preloadPages();\n }\n }, {\n key: 'destroy',\n value: function destroy() {\n // remove delegated listeners\n this.delegatedListeners.click.destroy();\n this.delegatedListeners.mouseover.destroy();\n\n // remove popstate listener\n window.removeEventListener('popstate', this.popStateHandler.bind(this));\n\n // empty cache\n this.cache.empty();\n\n // remove swup data atributes from blocks\n document.querySelectorAll('[data-swup]').forEach(function (element) {\n delete element.dataset.swup;\n });\n\n this.triggerEvent('disabled');\n document.documentElement.classList.remove('swup-enabled');\n }\n }, {\n key: 'linkClickHandler',\n value: function linkClickHandler(event) {\n // no control key pressed\n if (!event.metaKey) {\n this.triggerEvent('clickLink');\n var link = new _Link2.default();\n event.preventDefault();\n link.setPath(event.delegateTarget.href);\n if (link.getAddress() == this.currentUrl || link.getAddress() == '') {\n if (link.getHash() != '') {\n this.triggerEvent('samePageWithHash');\n var element = document.querySelector(link.getHash());\n if (element != null) {\n if (this.options.scroll) {\n this.scrollTo(document.body, element.offsetTop, 320);\n }\n history.replaceState(undefined, undefined, link.getHash());\n } else {\n console.warn('Element for offset not found (' + link.getHash() + ')');\n }\n } else {\n this.triggerEvent('samePage');\n if (this.options.scroll) {\n this.scrollTo(document.body, 0, 320);\n }\n }\n } else {\n if (link.getHash() != '') {\n this.scrollToElement = link.getHash();\n }\n // custom class fro dynamic pages\n var swupClass = event.delegateTarget.dataset.swupClass;\n if (swupClass != null) {\n this.updateTransition(window.location.pathname, link.getAddress(), event.delegateTarget.dataset.swupClass);\n document.documentElement.classList.add('to-' + swupClass);\n } else {\n this.updateTransition(window.location.pathname, link.getAddress());\n }\n this.loadPage(link.getAddress(), false);\n }\n } else {\n this.triggerEvent('openPageInNewTab');\n }\n }\n }, {\n key: 'linkMouseoverHandler',\n value: function linkMouseoverHandler(event) {\n var _this = this;\n\n this.triggerEvent('hoverLink');\n if (this.options.preload) {\n var link = new _Link2.default();\n link.setPath(event.delegateTarget.href);\n if (link.getAddress() != this.currentUrl && !this.cache.exists(link.getAddress()) && this.preloadPromise == null) {\n this.preloadPromise = new Promise(function (resolve) {\n _this.getPage(link.getAddress(), function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = link.getAddress();\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pagePreloaded');\n }\n resolve();\n _this.preloadPromise = null;\n });\n });\n this.preloadPromise.route = link.getAddress();\n }\n }\n }\n }, {\n key: 'popStateHandler',\n value: function popStateHandler(event) {\n var link = new _Link2.default();\n link.setPath(event.state ? event.state.url : window.location.pathname);\n if (link.getHash() != '') {\n this.scrollToElement = link.getHash();\n } else {\n event.preventDefault();\n }\n this.triggerEvent('popState');\n this.loadPage(link.getAddress(), event);\n }\n }]);\n\n return Swup;\n}();\n\nexports.default = Swup;\n\n//# sourceURL=webpack://Swup/./src/index.js?"); -/***/ }), -/***/ "./src/modules/classify.js": -/*!*********************************!*\ - !*** ./src/modules/classify.js ***! - \*********************************/ -/*! no static exports found */ +module.exports = function (popstate) { + if (this.options.scroll && !popstate) { + if (this.scrollToElement != null) { + var self = this; + + var element = document.querySelector(self.scrollToElement); + if (element != null) { + if (self.animateScrollToAnchor) { + self.scrollTo(document.body, element.offsetTop, this.options.scrollDuration); + } else { + self.scrollTo(document.body, element.offsetTop, 20); + } + } else { + console.warn("Element for offset not found (" + self.scrollToElement + ")"); + } + self.scrollToElement = null; + } else { + if (this.mobile && !this.options.animateScrollOnMobile) { + this.scrollTo(document.body, 0, 0); + } else if (this.mobile && this.options.animateScrollOnMobile) { + this.scrollTo(document.body, 0, this.options.scrollDuration); + } else { + this.scrollTo(document.body, 0, this.options.scrollDuration); + } + } + } +}; + +/***/ }), +/* 5 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (text) {\n var output = text.toString().toLowerCase().replace(/\\s+/g, '-') // Replace spaces with -\n .replace(/\\//g, '-') // Replace / with -\n .replace(/[^\\w\\-]+/g, '') // Remove all non-word chars\n .replace(/\\-\\-+/g, '-') // Replace multiple - with single -\n .replace(/^-+/, '') // Trim - from start of text\n .replace(/-+$/, ''); // Trim - from end of text\n if (output[0] == \"/\") output = output.splice(1);\n if (output == '') output = 'homepage';\n return output;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/classify.js?"); -/***/ }), -/***/ "./src/modules/createState.js": -/*!************************************!*\ - !*** ./src/modules/createState.js ***! - \************************************/ -/*! no static exports found */ +module.exports = function (text) { + var output = text.toString().toLowerCase().replace(/\s+/g, '-') // Replace spaces with - + .replace(/\//g, '-') // Replace / with - + .replace(/[^\w\-]+/g, '') // Remove all non-word chars + .replace(/\-\-+/g, '-') // Replace multiple - with single - + .replace(/^-+/, '') // Trim - from start of text + .replace(/-+$/, ''); // Trim - from end of text + if (output[0] == "/") output = output.splice(1); + if (output == '') output = 'homepage'; + return output; +}; + +/***/ }), +/* 6 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (url) {\n window.history.pushState({\n url: url || window.location.href.split(window.location.hostname)[1],\n random: Math.random()\n }, document.getElementsByTagName('title')[0].innerText, url || window.location.href.split(window.location.hostname)[1]);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/createState.js?"); -/***/ }), -/***/ "./src/modules/doScrolling.js": -/*!************************************!*\ - !*** ./src/modules/doScrolling.js ***! - \************************************/ -/*! no static exports found */ +module.exports = function (element, to, duration) { + var _this = this; + + var body = document.body; + + var UP = -1; + var DOWN = 1; + + var friction = 0.7; + var acceleration = 0.04; + + var positionY = 100; + var velocityY = 0; + var targetPositionY = 400; + + var raf = null; + + function getScrollTop() { + return document.body.scrollTop || document.documentElement.scrollTop; + } + + var animate = function animate() { + var distance = update(); + render(); + + if (Math.abs(distance) > 0.1) { + raf = requestAnimationFrame(animate); + } else { + _this.triggerEvent('scrollDone'); + } + }; + + function update() { + var distance = targetPositionY - positionY; + var attraction = distance * acceleration; + + applyForce(attraction); + + velocityY *= friction; + positionY += velocityY; + + return distance; + } + + var applyForce = function applyForce(force) { + velocityY += force; + }; + + var render = function render() { + window.scrollTo(0, positionY); + }; + + window.addEventListener('mousewheel', function (event) { + if (raf) { + cancelAnimationFrame(raf); + raf = null; + } + }, { + passive: true + }); + + var scrollTo = function scrollTo(offset, callback) { + positionY = getScrollTop(); + targetPositionY = offset; + velocityY = 0; + animate(); + }; + + this.triggerEvent('scrollStart'); + if (duration == 0) { + window.scrollTo(0, 0); + this.triggerEvent('scrollDone'); + } else { + scrollTo(to); + } +}; + +/***/ }), +/* 7 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (popstate) {\n if (this.options.scroll && !popstate) {\n if (this.scrollToElement != null) {\n var self = this;\n\n var element = document.querySelector(self.scrollToElement);\n if (element != null) {\n if (self.animateScrollToAnchor) {\n self.scrollTo(document.body, element.offsetTop, this.options.scrollDuration);\n } else {\n self.scrollTo(document.body, element.offsetTop, 20);\n }\n } else {\n console.warn(\"Element for offset not found (\" + self.scrollToElement + \")\");\n }\n self.scrollToElement = null;\n } else {\n if (this.mobile && !this.options.animateScrollOnMobile) {\n this.scrollTo(document.body, 0, 0);\n } else if (this.mobile && this.options.animateScrollOnMobile) {\n this.scrollTo(document.body, 0, this.options.scrollDuration);\n } else {\n this.scrollTo(document.body, 0, this.options.scrollDuration);\n }\n }\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/doScrolling.js?"); -/***/ }), -/***/ "./src/modules/getDataFromHtml.js": -/*!****************************************!*\ - !*** ./src/modules/getDataFromHtml.js ***! - \****************************************/ -/*! no static exports found */ +module.exports = function () { + this.currentUrl = window.location.pathname + window.location.search; +}; + +/***/ }), +/* 8 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (html) {\n var _this = this;\n\n var content = html.replace('', '');\n var fakeDom = document.createElement('div');\n fakeDom.innerHTML = content;\n var blocks = [];\n\n for (var i = 0; i < this.options.elements.length; i++) {\n if (fakeDom.querySelector(this.options.elements[i]) == null) {\n console.warn('Element ' + this.options.elements[i] + ' is not found cached page.');\n } else {\n [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) {\n fakeDom.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks.length;\n blocks.push(fakeDom.querySelectorAll(_this.options.elements[i])[index].outerHTML);\n });\n }\n }\n\n var json = {\n title: fakeDom.querySelector('title').innerText,\n pageClass: fakeDom.querySelector('#swupBody').className,\n originalContent: html,\n blocks: blocks\n };\n return json;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/getDataFromHtml.js?"); -/***/ }), -/***/ "./src/modules/getUrl.js": -/*!*******************************!*\ - !*** ./src/modules/getUrl.js ***! - \*******************************/ -/*! no static exports found */ +module.exports = function (eventName) { + if (this.options.debugMode) { + console.log('%cswup:' + '%c' + eventName, 'color: #343434', 'color: #009ACD'); + } + var event = new CustomEvent('swup:' + eventName, { detail: eventName }); + document.dispatchEvent(event); +}; + +/***/ }), +/* 9 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function () {\n this.currentUrl = window.location.pathname + window.location.search;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/getUrl.js?"); -/***/ }), -/***/ "./src/modules/goBack.js": -/*!*******************************!*\ - !*** ./src/modules/goBack.js ***! - \*******************************/ -/*! no static exports found */ +module.exports = function (url) { + window.history.pushState({ + url: url || window.location.href.split(window.location.hostname)[1], + random: Math.random() + }, document.getElementsByTagName('title')[0].innerText, url || window.location.href.split(window.location.hostname)[1]); +}; + +/***/ }), +/* 10 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (page, popstate) {\n setTimeout(function () {\n document.body.classList.remove('is-changing');\n history.back();\n }, 100);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/goBack.js?"); -/***/ }), -/***/ "./src/modules/loadPage.js": -/*!*********************************!*\ - !*** ./src/modules/loadPage.js ***! - \*********************************/ -/*! no static exports found */ +module.exports = function (page, popstate) { + setTimeout(function () { + document.body.classList.remove('is-changing'); + history.back(); + }, 100); +}; + +/***/ }), +/* 11 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nvar forEach = Array.prototype.forEach;\n\n\nmodule.exports = function (url, popstate) {\n var _this = this;\n\n var finalPage = null;\n\n // scrolling\n if (this.options.doScrollingRightAway && !this.scrollToElement) {\n this.doScrolling(popstate);\n }\n\n var animationPromises = [];\n\n if (!popstate) {\n // start animation\n document.documentElement.classList.add('is-changing');\n document.documentElement.classList.add('is-leaving');\n document.documentElement.classList.add('is-animating');\n document.documentElement.classList.add('to-' + this.classify(url));\n\n // detect animation end\n var animatedElements = document.querySelectorAll(this.options.animationSelector);\n forEach.call(animatedElements, function (element) {\n var promise = new Promise(function (resolve) {\n element.addEventListener(_this.transitionEndEvent, resolve);\n });\n animationPromises.push(promise);\n });\n\n Promise.all(animationPromises).then(function () {\n _this.triggerEvent('animationOutDone');\n });\n\n // create pop element with or without anchor\n if (this.scrollToElement != null) {\n var pop = url + this.scrollToElement;\n } else {\n var pop = url;\n }\n this.createState(pop);\n } else {\n // proceed without animating\n this.triggerEvent('animationSkipped');\n }\n\n if (this.cache.exists(url)) {\n var xhrPromise = new Promise(function (resolve) {\n resolve();\n });\n this.triggerEvent('pageRetrievedFromCache');\n } else {\n if (!this.preloadPromise || this.preloadPromise.route != url) {\n var xhrPromise = new Promise(function (resolve) {\n _this.getPage(url, function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n _this.goBack();\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = url;\n // render page\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pageLoaded');\n }\n resolve();\n });\n });\n } else {\n var xhrPromise = this.preloadPromise;\n }\n }\n\n Promise.all(animationPromises.concat([xhrPromise])).then(function () {\n finalPage = _this.cache.getPage(url);\n if (!_this.options.cache) {\n _this.cache.empty(_this.options.debugMode);\n }\n _this.renderPage(finalPage, popstate);\n _this.preloadPromise = null;\n });\n};\n\n//# sourceURL=webpack://Swup/./src/modules/loadPage.js?"); -/***/ }), -/***/ "./src/modules/markSwupElements.js": -/*!*****************************************!*\ - !*** ./src/modules/markSwupElements.js ***! - \*****************************************/ -/*! no static exports found */ +var forEach = Array.prototype.forEach; + + +module.exports = function (page, popstate) { + var _this = this; + + document.documentElement.classList.remove('is-leaving'); + + // only add for non-popstate transitions + if (!popstate) { + document.documentElement.classList.add('is-rendering'); + } + + // replace blocks + for (var i = 0; i < page.blocks.length; i++) { + document.body.querySelector('[data-swup="' + i + '"]').outerHTML = page.blocks[i]; + } + + // set title + document.title = page.title; + + this.triggerEvent('contentReplaced'); + this.triggerEvent('pageView'); + setTimeout(function () { + document.documentElement.classList.remove('is-animating'); + }, 10); + + // handle classes after render + if (this.options.pageClassPrefix !== false) { + document.body.className.split(' ').forEach(function (className) { + // empty string for page class + if (className != "" && className.includes(_this.options.pageClassPrefix)) { + document.body.classList.remove(className); + } + }); + } + + // empty string for page class + if (page.pageClass != "") { + page.pageClass.split(' ').forEach(function (className) { + document.body.classList.add(className); + }); + } + + // scrolling + if (!this.options.doScrollingRightAway || this.scrollToElement) { + this.doScrolling(popstate); + } + + // detect animation end + var animatedElements = document.querySelectorAll(this.options.animationSelector); + var promises = []; + forEach.call(animatedElements, function (element) { + var promise = new Promise(function (resolve) { + element.addEventListener(_this.transitionEndEvent, resolve); + }); + promises.push(promise); + }); + + //preload pages if possible + this.preloadPages(); + + Promise.all(promises).then(function () { + _this.triggerEvent('animationInDone'); + // remove "to-{page}" classes + document.documentElement.classList.forEach(function (classItem) { + if (classItem.startsWith('to-')) { + document.documentElement.classList.remove(classItem); + } + }); + document.documentElement.classList.remove('is-changing'); + document.documentElement.classList.remove('is-rendering'); + }); + + // update current url + this.getUrl(); +}; + +/***/ }), +/* 12 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (element) {\n var _this = this;\n\n var blocks = 0;\n\n for (var i = 0; i < this.options.elements.length; i++) {\n if (element.querySelector(this.options.elements[i]) == null) {\n console.warn(\"Element \" + this.options.elements[i] + \" is not in current page.\");\n } else {\n [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) {\n element.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks;\n blocks++;\n });\n }\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/markSwupElements.js?"); -/***/ }), -/***/ "./src/modules/preloadPages.js": -/*!*************************************!*\ - !*** ./src/modules/preloadPages.js ***! - \*************************************/ -/*! no static exports found */ +var forEach = Array.prototype.forEach; + + +module.exports = function (url, popstate) { + var _this = this; + + var finalPage = null; + + // scrolling + if (this.options.doScrollingRightAway && !this.scrollToElement) { + this.doScrolling(popstate); + } + + var animationPromises = []; + + if (!popstate) { + // start animation + document.documentElement.classList.add('is-changing'); + document.documentElement.classList.add('is-leaving'); + document.documentElement.classList.add('is-animating'); + document.documentElement.classList.add('to-' + this.classify(url)); + + // detect animation end + var animatedElements = document.querySelectorAll(this.options.animationSelector); + forEach.call(animatedElements, function (element) { + var promise = new Promise(function (resolve) { + element.addEventListener(_this.transitionEndEvent, resolve); + }); + animationPromises.push(promise); + }); + + Promise.all(animationPromises).then(function () { + _this.triggerEvent('animationOutDone'); + }); + + // create pop element with or without anchor + if (this.scrollToElement != null) { + var pop = url + this.scrollToElement; + } else { + var pop = url; + } + this.createState(pop); + } else { + // proceed without animating + this.triggerEvent('animationSkipped'); + } + + if (this.cache.exists(url)) { + var xhrPromise = new Promise(function (resolve) { + resolve(); + }); + this.triggerEvent('pageRetrievedFromCache'); + } else { + if (!this.preloadPromise || this.preloadPromise.route != url) { + var xhrPromise = new Promise(function (resolve) { + _this.getPage(url, function (response) { + if (response === null) { + console.warn('Server error.'); + _this.triggerEvent('serverError'); + _this.goBack(); + } else { + // get json data + var page = _this.getDataFromHtml(response); + page.url = url; + // render page + _this.cache.cacheUrl(page, _this.options.debugMode); + _this.triggerEvent('pageLoaded'); + } + resolve(); + }); + }); + } else { + var xhrPromise = this.preloadPromise; + } + } + + Promise.all(animationPromises.concat([xhrPromise])).then(function () { + finalPage = _this.cache.getPage(url); + if (!_this.options.cache) { + _this.cache.empty(_this.options.debugMode); + } + _this.renderPage(finalPage, popstate); + _this.preloadPromise = null; + }); +}; + +/***/ }), +/* 13 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nvar _Link = __webpack_require__(/*! ../Link */ \"./src/Link.js\");\n\nvar _Link2 = _interopRequireDefault(_Link);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nmodule.exports = function (eventName) {\n var _this = this;\n\n if (this.options.preload) {\n var preload = function preload(pathname) {\n var link = new _Link2.default();\n link.setPath(pathname);\n if (link.getAddress() != _this.currentUrl && !_this.cache.exists(link.getAddress()) && _this.preloadPromise == null) {\n _this.getPage(link.getAddress(), function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = link.getAddress();\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pagePreloaded');\n }\n });\n }\n };\n\n document.querySelectorAll('[data-swup-preload]').forEach(function (element) {\n preload(element.href);\n });\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/preloadPages.js?"); -/***/ }), -/***/ "./src/modules/renderPage.js": -/*!***********************************!*\ - !*** ./src/modules/renderPage.js ***! - \***********************************/ -/*! no static exports found */ +module.exports = function (html) { + var _this = this; + + var content = html.replace('', ''); + var fakeDom = document.createElement('div'); + fakeDom.innerHTML = content; + var blocks = []; + + for (var i = 0; i < this.options.elements.length; i++) { + if (fakeDom.querySelector(this.options.elements[i]) == null) { + console.warn('Element ' + this.options.elements[i] + ' is not found cached page.'); + } else { + [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) { + fakeDom.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks.length; + blocks.push(fakeDom.querySelectorAll(_this.options.elements[i])[index].outerHTML); + }); + } + } + + var json = { + title: fakeDom.querySelector('title').innerText, + pageClass: fakeDom.querySelector('#swupBody').className, + originalContent: html, + blocks: blocks + }; + return json; +}; + +/***/ }), +/* 14 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nvar forEach = Array.prototype.forEach;\n\n\nmodule.exports = function (page, popstate) {\n var _this = this;\n\n document.documentElement.classList.remove('is-leaving');\n\n // only add for non-popstate transitions\n if (!popstate) {\n document.documentElement.classList.add('is-rendering');\n }\n\n // replace blocks\n for (var i = 0; i < page.blocks.length; i++) {\n document.body.querySelector('[data-swup=\"' + i + '\"]').outerHTML = page.blocks[i];\n }\n\n // set title\n document.title = page.title;\n\n this.triggerEvent('contentReplaced');\n this.triggerEvent('pageView');\n setTimeout(function () {\n document.documentElement.classList.remove('is-animating');\n }, 10);\n\n // handle classes after render\n if (this.options.pageClassPrefix !== false) {\n document.body.className.split(' ').forEach(function (className) {\n // empty string for page class\n if (className != \"\" && className.includes(_this.options.pageClassPrefix)) {\n document.body.classList.remove(className);\n }\n });\n }\n\n // empty string for page class\n if (page.pageClass != \"\") {\n page.pageClass.split(' ').forEach(function (className) {\n document.body.classList.add(className);\n });\n }\n\n // scrolling\n if (!this.options.doScrollingRightAway || this.scrollToElement) {\n this.doScrolling(popstate);\n }\n\n // detect animation end\n var animatedElements = document.querySelectorAll(this.options.animationSelector);\n var promises = [];\n forEach.call(animatedElements, function (element) {\n var promise = new Promise(function (resolve) {\n element.addEventListener(_this.transitionEndEvent, resolve);\n });\n promises.push(promise);\n });\n\n //preload pages if possible\n this.preloadPages();\n\n Promise.all(promises).then(function () {\n _this.triggerEvent('animationInDone');\n // remove \"to-{page}\" classes\n document.documentElement.classList.forEach(function (classItem) {\n if (classItem.startsWith('to-')) {\n document.documentElement.classList.remove(classItem);\n }\n });\n document.documentElement.classList.remove('is-changing');\n document.documentElement.classList.remove('is-rendering');\n });\n\n // update current url\n this.getUrl();\n};\n\n//# sourceURL=webpack://Swup/./src/modules/renderPage.js?"); -/***/ }), -/***/ "./src/modules/request.js": -/*!********************************!*\ - !*** ./src/modules/request.js ***! - \********************************/ -/*! no static exports found */ +module.exports = function (location, callback) { + var request = new XMLHttpRequest(); + + request.onreadystatechange = function () { + if (request.readyState === 4) { + if (request.status !== 500) { + callback(request.responseText, request); + } else { + callback(null, request); + } + } + }; + + request.open("GET", location, true); + request.setRequestHeader("X-Requested-With", "swup"); + request.send(null); + return request; +}; + +/***/ }), +/* 15 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (location, callback) {\n var request = new XMLHttpRequest();\n\n request.onreadystatechange = function () {\n if (request.readyState === 4) {\n if (request.status !== 500) {\n callback(request.responseText, request);\n } else {\n callback(null, request);\n }\n }\n };\n\n request.open(\"GET\", location, true);\n request.setRequestHeader(\"X-Requested-With\", \"swup\");\n request.send(null);\n return request;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/request.js?"); -/***/ }), -/***/ "./src/modules/scrollTo.js": -/*!*********************************!*\ - !*** ./src/modules/scrollTo.js ***! - \*********************************/ -/*! no static exports found */ +module.exports = function transitionEnd() { + var el = document.createElement('div'); + + var transEndEventNames = { + WebkitTransition: 'webkitTransitionEnd', + MozTransition: 'transitionend', + OTransition: 'oTransitionEnd otransitionend', + transition: 'transitionend' + }; + + for (var name in transEndEventNames) { + if (el.style[name] !== undefined) { + return transEndEventNames[name]; + } + } + + return false; +}; + +/***/ }), +/* 16 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (element, to, duration) {\n var _this = this;\n\n var body = document.body;\n\n var UP = -1;\n var DOWN = 1;\n\n var friction = 0.7;\n var acceleration = 0.04;\n\n var positionY = 100;\n var velocityY = 0;\n var targetPositionY = 400;\n\n var raf = null;\n\n function getScrollTop() {\n return document.body.scrollTop || document.documentElement.scrollTop;\n }\n\n var animate = function animate() {\n var distance = update();\n render();\n\n if (Math.abs(distance) > 0.1) {\n raf = requestAnimationFrame(animate);\n } else {\n _this.triggerEvent('scrollDone');\n }\n };\n\n function update() {\n var distance = targetPositionY - positionY;\n var attraction = distance * acceleration;\n\n applyForce(attraction);\n\n velocityY *= friction;\n positionY += velocityY;\n\n return distance;\n }\n\n var applyForce = function applyForce(force) {\n velocityY += force;\n };\n\n var render = function render() {\n window.scrollTo(0, positionY);\n };\n\n window.addEventListener('mousewheel', function (event) {\n if (raf) {\n cancelAnimationFrame(raf);\n raf = null;\n }\n }, {\n passive: true\n });\n\n var scrollTo = function scrollTo(offset, callback) {\n positionY = getScrollTop();\n targetPositionY = offset;\n velocityY = 0;\n animate();\n };\n\n this.triggerEvent('scrollStart');\n if (duration == 0) {\n window.scrollTo(0, 0);\n this.triggerEvent('scrollDone');\n } else {\n scrollTo(to);\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/scrollTo.js?"); + + +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 Cache = function () { + function Cache() { + _classCallCheck(this, Cache); + + this.pages = {}; + this.count = 0; + this.last = null; + } + + _createClass(Cache, [{ + key: 'cacheUrl', + value: function cacheUrl(page, displayCache) { + this.count++; + if (page.url in this.pages === false) { + this.pages[page.url] = page; + } + this.last = this.pages[page.url]; + if (displayCache) { + this.displayCache(); + } + } + }, { + key: 'getPage', + value: function getPage(url) { + return this.pages[url]; + } + }, { + key: 'displayCache', + value: function displayCache() { + console.groupCollapsed('Cache (' + Object.keys(this.pages).length + ')'); + for (var key in this.pages) { + console.log(this.pages[key]); + } + console.groupEnd(); + } + }, { + key: 'exists', + value: function exists(url) { + if (url in this.pages) return true; + return false; + } + }, { + key: 'empty', + value: function empty(showLog) { + this.pages = {}; + this.count = 0; + this.last = null; + if (showLog) { + console.log('Cache cleared'); + } + } + }]); + + return Cache; +}(); + +exports.default = Cache; /***/ }), +/* 17 */ +/***/ (function(module, exports) { -/***/ "./src/modules/triggerEvent.js": -/*!*************************************!*\ - !*** ./src/modules/triggerEvent.js ***! - \*************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { +/** + * detect IE + * returns version of IE or false, if browser is not Internet Explorer + */ +var detectie = function() { + var ua = window.navigator.userAgent; + + var msie = ua.indexOf('MSIE '); + if (msie > 0) { + // IE 10 or older => return version number + return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10); + } + + var trident = ua.indexOf('Trident/'); + if (trident > 0) { + // IE 11 => return version number + var rv = ua.indexOf('rv:'); + return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10); + } + + var edge = ua.indexOf('Edge/'); + if (edge > 0) { + // IE 12 => return version number + return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10); + } + // other browser + return false; +} + +module.exports = detectie; + +/***/ }), +/* 18 */ +/***/ (function(module, exports) { + +var DOCUMENT_NODE_TYPE = 9; + +/** + * A polyfill for Element.matches() + */ +if (typeof Element !== 'undefined' && !Element.prototype.matches) { + var proto = Element.prototype; + + proto.matches = proto.matchesSelector || + proto.mozMatchesSelector || + proto.msMatchesSelector || + proto.oMatchesSelector || + proto.webkitMatchesSelector; +} + +/** + * Finds the closest parent that matches a selector. + * + * @param {Element} element + * @param {String} selector + * @return {Function} + */ +function closest (element, selector) { + while (element && element.nodeType !== DOCUMENT_NODE_TYPE) { + if (typeof element.matches === 'function' && + element.matches(selector)) { + return element; + } + element = element.parentNode; + } +} + +module.exports = closest; -"use strict"; -eval("\n\nmodule.exports = function (eventName) {\n if (this.options.debugMode) {\n console.log('%cswup:' + '%c' + eventName, 'color: #343434', 'color: #009ACD');\n }\n var event = new CustomEvent('swup:' + eventName, { detail: eventName });\n document.dispatchEvent(event);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/triggerEvent.js?"); /***/ }), +/* 19 */ +/***/ (function(module, exports, __webpack_require__) { + +var closest = __webpack_require__(18); + +/** + * Delegates event to a selector. + * + * @param {Element} element + * @param {String} selector + * @param {String} type + * @param {Function} callback + * @param {Boolean} useCapture + * @return {Object} + */ +function delegate(element, selector, type, callback, useCapture) { + var listenerFn = listener.apply(this, arguments); + + element.addEventListener(type, listenerFn, useCapture); + + return { + destroy: function() { + element.removeEventListener(type, listenerFn, useCapture); + } + } +} + +/** + * Finds closest match and invokes callback. + * + * @param {Element} element + * @param {String} selector + * @param {String} type + * @param {Function} callback + * @return {Function} + */ +function listener(element, selector, type, callback) { + return function(e) { + e.delegateTarget = closest(e.target, selector); + + if (e.delegateTarget) { + callback.call(element, e); + } + } +} + +module.exports = delegate; + -/***/ "./src/modules/updateTransition.js": -/*!*****************************************!*\ - !*** ./src/modules/updateTransition.js ***! - \*****************************************/ -/*! no static exports found */ +/***/ }), +/* 20 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function (from, to, custom) {\n\n // homepage case\n if (from == \"/\") {\n from = \"/homepage\";\n }\n if (to == \"/\") {\n to = \"/homepage\";\n }\n\n // transition routes\n this.transition = {\n from: from.replace('/', ''),\n to: to.replace('/', '')\n };\n\n if (custom) {\n this.transition.custom = custom;\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/updateTransition.js?"); -/***/ }), -/***/ "./src/transitionEnd.js": -/*!******************************!*\ - !*** ./src/transitionEnd.js ***! - \******************************/ -/*! no static exports found */ +Object.defineProperty(exports, "__esModule", { + value: true +}); + +var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; + +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; }; }(); + +// helpers + + +// modules + + +var _delegate = __webpack_require__(19); + +var _delegate2 = _interopRequireDefault(_delegate); + +var _detectie = __webpack_require__(17); + +var _detectie2 = _interopRequireDefault(_detectie); + +var _Cache = __webpack_require__(16); + +var _Cache2 = _interopRequireDefault(_Cache); + +var _Link = __webpack_require__(0); + +var _Link2 = _interopRequireDefault(_Link); + +var _transitionEnd = __webpack_require__(15); + +var _transitionEnd2 = _interopRequireDefault(_transitionEnd); + +var _request = __webpack_require__(14); + +var _request2 = _interopRequireDefault(_request); + +var _getDataFromHtml = __webpack_require__(13); + +var _getDataFromHtml2 = _interopRequireDefault(_getDataFromHtml); + +var _loadPage = __webpack_require__(12); + +var _loadPage2 = _interopRequireDefault(_loadPage); + +var _renderPage = __webpack_require__(11); + +var _renderPage2 = _interopRequireDefault(_renderPage); + +var _goBack = __webpack_require__(10); + +var _goBack2 = _interopRequireDefault(_goBack); + +var _createState = __webpack_require__(9); + +var _createState2 = _interopRequireDefault(_createState); + +var _triggerEvent = __webpack_require__(8); + +var _triggerEvent2 = _interopRequireDefault(_triggerEvent); + +var _getUrl = __webpack_require__(7); + +var _getUrl2 = _interopRequireDefault(_getUrl); + +var _scrollTo = __webpack_require__(6); + +var _scrollTo2 = _interopRequireDefault(_scrollTo); + +var _classify = __webpack_require__(5); + +var _classify2 = _interopRequireDefault(_classify); + +var _doScrolling = __webpack_require__(4); + +var _doScrolling2 = _interopRequireDefault(_doScrolling); + +var _markSwupElements = __webpack_require__(3); + +var _markSwupElements2 = _interopRequireDefault(_markSwupElements); + +var _updateTransition = __webpack_require__(2); + +var _updateTransition2 = _interopRequireDefault(_updateTransition); + +var _preloadPages = __webpack_require__(1); + +var _preloadPages2 = _interopRequireDefault(_preloadPages); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +var Swup = function () { + function Swup(setOptions) { + _classCallCheck(this, Swup); + + // default options + var defaults = { + cache: true, + animationSelector: '[class^="a-"]', + elements: ['#swup'], + pageClassPrefix: '', + debugMode: false, + scroll: true, + preload: true, + support: true, + disableIE: false, + + animateScrollToAnchor: false, + animateScrollOnMobile: false, + doScrollingRightAway: false, + scrollDuration: 0, + + LINK_SELECTOR: 'a[href^="/"]:not([data-no-swup]), a[href^="#"]:not([data-no-swup]), a[xlink\\:href]' + + /** + * current transition object + */ + };this.transition = {}; + + var options = _extends({}, defaults, setOptions); + + /** + * helper variables + */ + // mobile detection variable + this.mobile = false; + // id of element to scroll to after render + this.scrollToElement = null; + // promise used for preload, so no new loading of the same page starts while page is loading + this.preloadPromise = null; + // save options + this.options = options; + + /** + * make modules accessible in instance + */ + this.getUrl = _getUrl2.default; + this.cache = new _Cache2.default(); + this.link = new _Link2.default(); + this.transitionEndEvent = (0, _transitionEnd2.default)(); + this.getDataFromHtml = _getDataFromHtml2.default; + this.getPage = _request2.default; + this.scrollTo = _scrollTo2.default; + this.loadPage = _loadPage2.default; + this.renderPage = _renderPage2.default; + this.goBack = _goBack2.default; + this.createState = _createState2.default; + this.triggerEvent = _triggerEvent2.default; + this.classify = _classify2.default; + this.doScrolling = _doScrolling2.default; + this.markSwupElements = _markSwupElements2.default; + this.updateTransition = _updateTransition2.default; + this.preloadPages = _preloadPages2.default; + this.detectie = _detectie2.default; + this.enable = this.enable; + this.destroy = this.destroy; + + /** + * detect mobile devices + */ + if (this.options.scroll) { + if (window.innerWidth <= 767) { + this.mobile = true; + } + } + + // attach instance to window in debug mode + if (this.options.debugMode) { + window.swup = this; + } + + this.getUrl(); + this.enable(); + } + + _createClass(Swup, [{ + key: 'enable', + value: function enable() { + /** + * support check + */ + if (this.options.support) { + // check pushState support + if (!('pushState' in window.history)) { + console.warn('pushState is not supported'); + return; + } + // check transitionEnd support + if ((0, _transitionEnd2.default)()) { + this.transitionEndEvent = (0, _transitionEnd2.default)(); + } else { + console.warn('transitionEnd detection is not supported'); + return; + } + // check Promise support + if (typeof Promise === "undefined" || Promise.toString().indexOf("[native code]") === -1) { + console.warn('Promise is not supported'); + return; + } + } + /** + * disable IE + */ + if (this.options.disableIE && this.detectie()) { + return; + } + + // variable to keep event listeners from "delegate" + this.delegatedListeners = {}; + + /** + * link click handler + */ + this.delegatedListeners.click = (0, _delegate2.default)(document, this.options.LINK_SELECTOR, 'click', this.linkClickHandler.bind(this)); + + /** + * link mouseover handler (preload) + */ + this.delegatedListeners.mouseover = (0, _delegate2.default)(document.body, this.options.LINK_SELECTOR, 'mouseover', this.linkMouseoverHandler.bind(this)); + + /** + * popstate handler + */ + window.addEventListener('popstate', this.popStateHandler.bind(this)); + + /** + * initial save to cache + */ + var page = this.getDataFromHtml(document.documentElement.innerHTML); + page.url = this.currentUrl; + if (this.options.cache) { + this.cache.cacheUrl(page, this.options.debugMode); + } + + /** + * mark swup blocks in html + */ + this.markSwupElements(document.documentElement); + + /** + * trigger enabled event + */ + this.triggerEvent('enabled'); + document.documentElement.classList.add('swup-enabled'); + + /** + * trigger page view event + */ + this.triggerEvent('pageView'); + + /** + * preload pages if possible + */ + this.preloadPages(); + } + }, { + key: 'destroy', + value: function destroy() { + // remove delegated listeners + this.delegatedListeners.click.destroy(); + this.delegatedListeners.mouseover.destroy(); + + // remove popstate listener + window.removeEventListener('popstate', this.popStateHandler.bind(this)); + + // empty cache + this.cache.empty(); + + // remove swup data atributes from blocks + document.querySelectorAll('[data-swup]').forEach(function (element) { + delete element.dataset.swup; + }); + + this.triggerEvent('disabled'); + document.documentElement.classList.remove('swup-enabled'); + } + }, { + key: 'linkClickHandler', + value: function linkClickHandler(event) { + // no control key pressed + if (!event.metaKey) { + this.triggerEvent('clickLink'); + var link = new _Link2.default(); + event.preventDefault(); + link.setPath(event.delegateTarget.href); + if (link.getAddress() == this.currentUrl || link.getAddress() == '') { + if (link.getHash() != '') { + this.triggerEvent('samePageWithHash'); + var element = document.querySelector(link.getHash()); + if (element != null) { + if (this.options.scroll) { + this.scrollTo(document.body, element.offsetTop, 320); + } + history.replaceState(undefined, undefined, link.getHash()); + } else { + console.warn('Element for offset not found (' + link.getHash() + ')'); + } + } else { + this.triggerEvent('samePage'); + if (this.options.scroll) { + this.scrollTo(document.body, 0, 320); + } + } + } else { + if (link.getHash() != '') { + this.scrollToElement = link.getHash(); + } + // custom class fro dynamic pages + var swupClass = event.delegateTarget.dataset.swupClass; + if (swupClass != null) { + this.updateTransition(window.location.pathname, link.getAddress(), event.delegateTarget.dataset.swupClass); + document.documentElement.classList.add('to-' + swupClass); + } else { + this.updateTransition(window.location.pathname, link.getAddress()); + } + this.loadPage(link.getAddress(), false); + } + } else { + this.triggerEvent('openPageInNewTab'); + } + } + }, { + key: 'linkMouseoverHandler', + value: function linkMouseoverHandler(event) { + var _this = this; + + this.triggerEvent('hoverLink'); + if (this.options.preload) { + var link = new _Link2.default(); + link.setPath(event.delegateTarget.href); + if (link.getAddress() != this.currentUrl && !this.cache.exists(link.getAddress()) && this.preloadPromise == null) { + this.preloadPromise = new Promise(function (resolve) { + _this.getPage(link.getAddress(), function (response) { + if (response === null) { + console.warn('Server error.'); + _this.triggerEvent('serverError'); + } else { + // get json data + var page = _this.getDataFromHtml(response); + page.url = link.getAddress(); + _this.cache.cacheUrl(page, _this.options.debugMode); + _this.triggerEvent('pagePreloaded'); + } + resolve(); + _this.preloadPromise = null; + }); + }); + this.preloadPromise.route = link.getAddress(); + } + } + } + }, { + key: 'popStateHandler', + value: function popStateHandler(event) { + var link = new _Link2.default(); + link.setPath(event.state ? event.state.url : window.location.pathname); + if (link.getHash() != '') { + this.scrollToElement = link.getHash(); + } else { + event.preventDefault(); + } + this.triggerEvent('popState'); + this.loadPage(link.getAddress(), event); + } + }]); + + return Swup; +}(); + +exports.default = Swup; + +/***/ }), +/* 21 */ /***/ (function(module, exports, __webpack_require__) { "use strict"; -eval("\n\nmodule.exports = function transitionEnd() {\n var el = document.createElement('div');\n\n var transEndEventNames = {\n WebkitTransition: 'webkitTransitionEnd',\n MozTransition: 'transitionend',\n OTransition: 'oTransitionEnd otransitionend',\n transition: 'transitionend'\n };\n\n for (var name in transEndEventNames) {\n if (el.style[name] !== undefined) {\n return transEndEventNames[name];\n }\n }\n\n return false;\n};\n\n//# sourceURL=webpack://Swup/./src/transitionEnd.js?"); -/***/ }) -/******/ }); +var _index = __webpack_require__(20); + +var _index2 = _interopRequireDefault(_index); + +function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + +module.exports = _index2.default; // this is here for webpack to expose Swup as window.Swup + +/***/ }) +/******/ ]); }); \ No newline at end of file diff --git a/dist/swup.min.js b/dist/swup.min.js index 5a417cb3..cec4a0c2 100644 --- a/dist/swup.min.js +++ b/dist/swup.min.js @@ -1,350 +1 @@ -(function webpackUniversalModuleDefinition(root, factory) { - //Test Comment - if(typeof exports === 'object' && typeof module === 'object') - module.exports = factory(); - //Test Comment - else if(typeof define === 'function' && define.amd) - define([], factory); - //Test Comment - else if(typeof exports === 'object') - exports["Swup"] = factory(); - //Test Comment - else - root["Swup"] = 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 = "./entry.js"); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ "./entry.js": -/*!******************!*\ - !*** ./entry.js ***! - \******************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nvar _index = __webpack_require__(/*! ./src/index.js */ \"./src/index.js\");\n\nvar _index2 = _interopRequireDefault(_index);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nmodule.exports = _index2.default; // this is here for webpack to expose Swup as window.Swup\n\n//# sourceURL=webpack://Swup/./entry.js?"); - -/***/ }), - -/***/ "./node_modules/delegate/src/closest.js": -/*!**********************************************!*\ - !*** ./node_modules/delegate/src/closest.js ***! - \**********************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -eval("var DOCUMENT_NODE_TYPE = 9;\n\n/**\n * A polyfill for Element.matches()\n */\nif (typeof Element !== 'undefined' && !Element.prototype.matches) {\n var proto = Element.prototype;\n\n proto.matches = proto.matchesSelector ||\n proto.mozMatchesSelector ||\n proto.msMatchesSelector ||\n proto.oMatchesSelector ||\n proto.webkitMatchesSelector;\n}\n\n/**\n * Finds the closest parent that matches a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @return {Function}\n */\nfunction closest (element, selector) {\n while (element && element.nodeType !== DOCUMENT_NODE_TYPE) {\n if (typeof element.matches === 'function' &&\n element.matches(selector)) {\n return element;\n }\n element = element.parentNode;\n }\n}\n\nmodule.exports = closest;\n\n\n//# sourceURL=webpack://Swup/./node_modules/delegate/src/closest.js?"); - -/***/ }), - -/***/ "./node_modules/delegate/src/delegate.js": -/*!***********************************************!*\ - !*** ./node_modules/delegate/src/delegate.js ***! - \***********************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -eval("var closest = __webpack_require__(/*! ./closest */ \"./node_modules/delegate/src/closest.js\");\n\n/**\n * Delegates event to a selector.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @param {Boolean} useCapture\n * @return {Object}\n */\nfunction delegate(element, selector, type, callback, useCapture) {\n var listenerFn = listener.apply(this, arguments);\n\n element.addEventListener(type, listenerFn, useCapture);\n\n return {\n destroy: function() {\n element.removeEventListener(type, listenerFn, useCapture);\n }\n }\n}\n\n/**\n * Finds closest match and invokes callback.\n *\n * @param {Element} element\n * @param {String} selector\n * @param {String} type\n * @param {Function} callback\n * @return {Function}\n */\nfunction listener(element, selector, type, callback) {\n return function(e) {\n e.delegateTarget = closest(e.target, selector);\n\n if (e.delegateTarget) {\n callback.call(element, e);\n }\n }\n}\n\nmodule.exports = delegate;\n\n\n//# sourceURL=webpack://Swup/./node_modules/delegate/src/delegate.js?"); - -/***/ }), - -/***/ "./node_modules/detectie/detectie.js": -/*!*******************************************!*\ - !*** ./node_modules/detectie/detectie.js ***! - \*******************************************/ -/*! no static exports found */ -/***/ (function(module, exports) { - -eval("/**\n * detect IE\n * returns version of IE or false, if browser is not Internet Explorer\n */\nvar detectie = function() {\n var ua = window.navigator.userAgent;\n\n var msie = ua.indexOf('MSIE ');\n if (msie > 0) {\n // IE 10 or older => return version number\n return parseInt(ua.substring(msie + 5, ua.indexOf('.', msie)), 10);\n }\n\n var trident = ua.indexOf('Trident/');\n if (trident > 0) {\n // IE 11 => return version number\n var rv = ua.indexOf('rv:');\n return parseInt(ua.substring(rv + 3, ua.indexOf('.', rv)), 10);\n }\n\n var edge = ua.indexOf('Edge/');\n if (edge > 0) {\n // IE 12 => return version number\n return parseInt(ua.substring(edge + 5, ua.indexOf('.', edge)), 10);\n }\n // other browser\n return false;\n}\n\nmodule.exports = detectie;\n\n//# sourceURL=webpack://Swup/./node_modules/detectie/detectie.js?"); - -/***/ }), - -/***/ "./src/Cache.js": -/*!**********************!*\ - !*** ./src/Cache.js ***! - \**********************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Cache = function () {\n function Cache() {\n _classCallCheck(this, Cache);\n\n this.pages = {};\n this.count = 0;\n this.last = null;\n }\n\n _createClass(Cache, [{\n key: 'cacheUrl',\n value: function cacheUrl(page, displayCache) {\n this.count++;\n if (page.url in this.pages === false) {\n this.pages[page.url] = page;\n }\n this.last = this.pages[page.url];\n if (displayCache) {\n this.displayCache();\n }\n }\n }, {\n key: 'getPage',\n value: function getPage(url) {\n return this.pages[url];\n }\n }, {\n key: 'displayCache',\n value: function displayCache() {\n console.groupCollapsed('Cache (' + Object.keys(this.pages).length + ')');\n for (var key in this.pages) {\n console.log(this.pages[key]);\n }\n console.groupEnd();\n }\n }, {\n key: 'exists',\n value: function exists(url) {\n if (url in this.pages) return true;\n return false;\n }\n }, {\n key: 'empty',\n value: function empty(showLog) {\n this.pages = {};\n this.count = 0;\n this.last = null;\n if (showLog) {\n console.log('Cache cleared');\n }\n }\n }]);\n\n return Cache;\n}();\n\nexports.default = Cache;\n\n//# sourceURL=webpack://Swup/./src/Cache.js?"); - -/***/ }), - -/***/ "./src/Link.js": -/*!*********************!*\ - !*** ./src/Link.js ***! - \*********************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _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; }; }();\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Link = function () {\n function Link() {\n _classCallCheck(this, Link);\n\n this.link = document.createElement(\"a\");\n }\n\n _createClass(Link, [{\n key: 'setPath',\n value: function setPath(href) {\n this.link.href = href;\n }\n }, {\n key: 'getPath',\n value: function getPath() {\n var path = this.link.pathname;\n if (path[0] != '/') {\n path = '/' + path;\n }\n return path;\n }\n }, {\n key: 'getAddress',\n value: function getAddress() {\n var path = this.link.pathname + this.link.search;\n if (path[0] != '/') {\n path = '/' + path;\n }\n return path;\n }\n }, {\n key: 'getHash',\n value: function getHash() {\n return this.link.hash;\n }\n }]);\n\n return Link;\n}();\n\nexports.default = Link;\n\n//# sourceURL=webpack://Swup/./src/Link.js?"); - -/***/ }), - -/***/ "./src/index.js": -/*!**********************!*\ - !*** ./src/index.js ***! - \**********************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nObject.defineProperty(exports, \"__esModule\", {\n value: true\n});\n\nvar _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };\n\nvar _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; }; }();\n\n// helpers\n\n\n// modules\n\n\nvar _delegate = __webpack_require__(/*! delegate */ \"./node_modules/delegate/src/delegate.js\");\n\nvar _delegate2 = _interopRequireDefault(_delegate);\n\nvar _detectie = __webpack_require__(/*! detectie */ \"./node_modules/detectie/detectie.js\");\n\nvar _detectie2 = _interopRequireDefault(_detectie);\n\nvar _Cache = __webpack_require__(/*! ./Cache */ \"./src/Cache.js\");\n\nvar _Cache2 = _interopRequireDefault(_Cache);\n\nvar _Link = __webpack_require__(/*! ./Link */ \"./src/Link.js\");\n\nvar _Link2 = _interopRequireDefault(_Link);\n\nvar _transitionEnd = __webpack_require__(/*! ./transitionEnd */ \"./src/transitionEnd.js\");\n\nvar _transitionEnd2 = _interopRequireDefault(_transitionEnd);\n\nvar _request = __webpack_require__(/*! ./modules/request */ \"./src/modules/request.js\");\n\nvar _request2 = _interopRequireDefault(_request);\n\nvar _getDataFromHtml = __webpack_require__(/*! ./modules/getDataFromHtml */ \"./src/modules/getDataFromHtml.js\");\n\nvar _getDataFromHtml2 = _interopRequireDefault(_getDataFromHtml);\n\nvar _loadPage = __webpack_require__(/*! ./modules/loadPage */ \"./src/modules/loadPage.js\");\n\nvar _loadPage2 = _interopRequireDefault(_loadPage);\n\nvar _renderPage = __webpack_require__(/*! ./modules/renderPage */ \"./src/modules/renderPage.js\");\n\nvar _renderPage2 = _interopRequireDefault(_renderPage);\n\nvar _goBack = __webpack_require__(/*! ./modules/goBack */ \"./src/modules/goBack.js\");\n\nvar _goBack2 = _interopRequireDefault(_goBack);\n\nvar _createState = __webpack_require__(/*! ./modules/createState */ \"./src/modules/createState.js\");\n\nvar _createState2 = _interopRequireDefault(_createState);\n\nvar _triggerEvent = __webpack_require__(/*! ./modules/triggerEvent */ \"./src/modules/triggerEvent.js\");\n\nvar _triggerEvent2 = _interopRequireDefault(_triggerEvent);\n\nvar _getUrl = __webpack_require__(/*! ./modules/getUrl */ \"./src/modules/getUrl.js\");\n\nvar _getUrl2 = _interopRequireDefault(_getUrl);\n\nvar _scrollTo = __webpack_require__(/*! ./modules/scrollTo */ \"./src/modules/scrollTo.js\");\n\nvar _scrollTo2 = _interopRequireDefault(_scrollTo);\n\nvar _classify = __webpack_require__(/*! ./modules/classify */ \"./src/modules/classify.js\");\n\nvar _classify2 = _interopRequireDefault(_classify);\n\nvar _doScrolling = __webpack_require__(/*! ./modules/doScrolling */ \"./src/modules/doScrolling.js\");\n\nvar _doScrolling2 = _interopRequireDefault(_doScrolling);\n\nvar _markSwupElements = __webpack_require__(/*! ./modules/markSwupElements */ \"./src/modules/markSwupElements.js\");\n\nvar _markSwupElements2 = _interopRequireDefault(_markSwupElements);\n\nvar _updateTransition = __webpack_require__(/*! ./modules/updateTransition */ \"./src/modules/updateTransition.js\");\n\nvar _updateTransition2 = _interopRequireDefault(_updateTransition);\n\nvar _preloadPages = __webpack_require__(/*! ./modules/preloadPages */ \"./src/modules/preloadPages.js\");\n\nvar _preloadPages2 = _interopRequireDefault(_preloadPages);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nfunction _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError(\"Cannot call a class as a function\"); } }\n\nvar Swup = function () {\n function Swup(setOptions) {\n _classCallCheck(this, Swup);\n\n // default options\n var defaults = {\n cache: true,\n animationSelector: '[class^=\"a-\"]',\n elements: ['#swup'],\n pageClassPrefix: '',\n debugMode: false,\n scroll: true,\n preload: true,\n support: true,\n disableIE: false,\n\n animateScrollToAnchor: false,\n animateScrollOnMobile: false,\n doScrollingRightAway: false,\n scrollDuration: 0,\n\n LINK_SELECTOR: 'a[href^=\"/\"]:not([data-no-swup]), a[href^=\"#\"]:not([data-no-swup]), a[xlink\\\\:href]'\n\n /**\n * current transition object\n */\n };this.transition = {};\n\n var options = _extends({}, defaults, setOptions);\n\n /**\n * helper variables\n */\n // mobile detection variable\n this.mobile = false;\n // id of element to scroll to after render\n this.scrollToElement = null;\n // promise used for preload, so no new loading of the same page starts while page is loading\n this.preloadPromise = null;\n // save options\n this.options = options;\n\n /**\n * make modules accessible in instance\n */\n this.getUrl = _getUrl2.default;\n this.cache = new _Cache2.default();\n this.link = new _Link2.default();\n this.transitionEndEvent = (0, _transitionEnd2.default)();\n this.getDataFromHtml = _getDataFromHtml2.default;\n this.getPage = _request2.default;\n this.scrollTo = _scrollTo2.default;\n this.loadPage = _loadPage2.default;\n this.renderPage = _renderPage2.default;\n this.goBack = _goBack2.default;\n this.createState = _createState2.default;\n this.triggerEvent = _triggerEvent2.default;\n this.classify = _classify2.default;\n this.doScrolling = _doScrolling2.default;\n this.markSwupElements = _markSwupElements2.default;\n this.updateTransition = _updateTransition2.default;\n this.preloadPages = _preloadPages2.default;\n this.detectie = _detectie2.default;\n this.enable = this.enable;\n this.destroy = this.destroy;\n\n /**\n * detect mobile devices\n */\n if (this.options.scroll) {\n if (window.innerWidth <= 767) {\n this.mobile = true;\n }\n }\n\n // attach instance to window in debug mode\n if (this.options.debugMode) {\n window.swup = this;\n }\n\n this.getUrl();\n this.enable();\n }\n\n _createClass(Swup, [{\n key: 'enable',\n value: function enable() {\n /**\n * support check\n */\n if (this.options.support) {\n // check pushState support\n if (!('pushState' in window.history)) {\n console.warn('pushState is not supported');\n return;\n }\n // check transitionEnd support\n if ((0, _transitionEnd2.default)()) {\n this.transitionEndEvent = (0, _transitionEnd2.default)();\n } else {\n console.warn('transitionEnd detection is not supported');\n return;\n }\n // check Promise support\n if (typeof Promise === \"undefined\" || Promise.toString().indexOf(\"[native code]\") === -1) {\n console.warn('Promise is not supported');\n return;\n }\n }\n /**\n * disable IE\n */\n if (this.options.disableIE && this.detectie()) {\n return;\n }\n\n // variable to keep event listeners from \"delegate\"\n this.delegatedListeners = {};\n\n /**\n * link click handler\n */\n this.delegatedListeners.click = (0, _delegate2.default)(document, this.options.LINK_SELECTOR, 'click', this.linkClickHandler.bind(this));\n\n /**\n * link mouseover handler (preload)\n */\n this.delegatedListeners.mouseover = (0, _delegate2.default)(document.body, this.options.LINK_SELECTOR, 'mouseover', this.linkMouseoverHandler.bind(this));\n\n /**\n * popstate handler\n */\n window.addEventListener('popstate', this.popStateHandler.bind(this));\n\n /**\n * initial save to cache\n */\n var page = this.getDataFromHtml(document.documentElement.innerHTML);\n page.url = this.currentUrl;\n if (this.options.cache) {\n this.cache.cacheUrl(page, this.options.debugMode);\n }\n\n /**\n * mark swup blocks in html\n */\n this.markSwupElements(document.documentElement);\n\n /**\n * trigger enabled event\n */\n this.triggerEvent('enabled');\n document.documentElement.classList.add('swup-enabled');\n\n /**\n * trigger page view event\n */\n this.triggerEvent('pageView');\n\n /**\n * preload pages if possible\n */\n this.preloadPages();\n }\n }, {\n key: 'destroy',\n value: function destroy() {\n // remove delegated listeners\n this.delegatedListeners.click.destroy();\n this.delegatedListeners.mouseover.destroy();\n\n // remove popstate listener\n window.removeEventListener('popstate', this.popStateHandler.bind(this));\n\n // empty cache\n this.cache.empty();\n\n // remove swup data atributes from blocks\n document.querySelectorAll('[data-swup]').forEach(function (element) {\n delete element.dataset.swup;\n });\n\n this.triggerEvent('disabled');\n document.documentElement.classList.remove('swup-enabled');\n }\n }, {\n key: 'linkClickHandler',\n value: function linkClickHandler(event) {\n // no control key pressed\n if (!event.metaKey) {\n this.triggerEvent('clickLink');\n var link = new _Link2.default();\n event.preventDefault();\n link.setPath(event.delegateTarget.href);\n if (link.getAddress() == this.currentUrl || link.getAddress() == '') {\n if (link.getHash() != '') {\n this.triggerEvent('samePageWithHash');\n var element = document.querySelector(link.getHash());\n if (element != null) {\n if (this.options.scroll) {\n this.scrollTo(document.body, element.offsetTop, 320);\n }\n history.replaceState(undefined, undefined, link.getHash());\n } else {\n console.warn('Element for offset not found (' + link.getHash() + ')');\n }\n } else {\n this.triggerEvent('samePage');\n if (this.options.scroll) {\n this.scrollTo(document.body, 0, 320);\n }\n }\n } else {\n if (link.getHash() != '') {\n this.scrollToElement = link.getHash();\n }\n // custom class fro dynamic pages\n var swupClass = event.delegateTarget.dataset.swupClass;\n if (swupClass != null) {\n this.updateTransition(window.location.pathname, link.getAddress(), event.delegateTarget.dataset.swupClass);\n document.documentElement.classList.add('to-' + swupClass);\n } else {\n this.updateTransition(window.location.pathname, link.getAddress());\n }\n this.loadPage(link.getAddress(), false);\n }\n } else {\n this.triggerEvent('openPageInNewTab');\n }\n }\n }, {\n key: 'linkMouseoverHandler',\n value: function linkMouseoverHandler(event) {\n var _this = this;\n\n this.triggerEvent('hoverLink');\n if (this.options.preload) {\n var link = new _Link2.default();\n link.setPath(event.delegateTarget.href);\n if (link.getAddress() != this.currentUrl && !this.cache.exists(link.getAddress()) && this.preloadPromise == null) {\n this.preloadPromise = new Promise(function (resolve) {\n _this.getPage(link.getAddress(), function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = link.getAddress();\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pagePreloaded');\n }\n resolve();\n _this.preloadPromise = null;\n });\n });\n this.preloadPromise.route = link.getAddress();\n }\n }\n }\n }, {\n key: 'popStateHandler',\n value: function popStateHandler(event) {\n var link = new _Link2.default();\n link.setPath(event.state ? event.state.url : window.location.pathname);\n if (link.getHash() != '') {\n this.scrollToElement = link.getHash();\n } else {\n event.preventDefault();\n }\n this.triggerEvent('popState');\n this.loadPage(link.getAddress(), event);\n }\n }]);\n\n return Swup;\n}();\n\nexports.default = Swup;\n\n//# sourceURL=webpack://Swup/./src/index.js?"); - -/***/ }), - -/***/ "./src/modules/classify.js": -/*!*********************************!*\ - !*** ./src/modules/classify.js ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (text) {\n var output = text.toString().toLowerCase().replace(/\\s+/g, '-') // Replace spaces with -\n .replace(/\\//g, '-') // Replace / with -\n .replace(/[^\\w\\-]+/g, '') // Remove all non-word chars\n .replace(/\\-\\-+/g, '-') // Replace multiple - with single -\n .replace(/^-+/, '') // Trim - from start of text\n .replace(/-+$/, ''); // Trim - from end of text\n if (output[0] == \"/\") output = output.splice(1);\n if (output == '') output = 'homepage';\n return output;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/classify.js?"); - -/***/ }), - -/***/ "./src/modules/createState.js": -/*!************************************!*\ - !*** ./src/modules/createState.js ***! - \************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (url) {\n window.history.pushState({\n url: url || window.location.href.split(window.location.hostname)[1],\n random: Math.random()\n }, document.getElementsByTagName('title')[0].innerText, url || window.location.href.split(window.location.hostname)[1]);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/createState.js?"); - -/***/ }), - -/***/ "./src/modules/doScrolling.js": -/*!************************************!*\ - !*** ./src/modules/doScrolling.js ***! - \************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (popstate) {\n if (this.options.scroll && !popstate) {\n if (this.scrollToElement != null) {\n var self = this;\n\n var element = document.querySelector(self.scrollToElement);\n if (element != null) {\n if (self.animateScrollToAnchor) {\n self.scrollTo(document.body, element.offsetTop, this.options.scrollDuration);\n } else {\n self.scrollTo(document.body, element.offsetTop, 20);\n }\n } else {\n console.warn(\"Element for offset not found (\" + self.scrollToElement + \")\");\n }\n self.scrollToElement = null;\n } else {\n if (this.mobile && !this.options.animateScrollOnMobile) {\n this.scrollTo(document.body, 0, 0);\n } else if (this.mobile && this.options.animateScrollOnMobile) {\n this.scrollTo(document.body, 0, this.options.scrollDuration);\n } else {\n this.scrollTo(document.body, 0, this.options.scrollDuration);\n }\n }\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/doScrolling.js?"); - -/***/ }), - -/***/ "./src/modules/getDataFromHtml.js": -/*!****************************************!*\ - !*** ./src/modules/getDataFromHtml.js ***! - \****************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (html) {\n var _this = this;\n\n var content = html.replace('', '');\n var fakeDom = document.createElement('div');\n fakeDom.innerHTML = content;\n var blocks = [];\n\n for (var i = 0; i < this.options.elements.length; i++) {\n if (fakeDom.querySelector(this.options.elements[i]) == null) {\n console.warn('Element ' + this.options.elements[i] + ' is not found cached page.');\n } else {\n [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) {\n fakeDom.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks.length;\n blocks.push(fakeDom.querySelectorAll(_this.options.elements[i])[index].outerHTML);\n });\n }\n }\n\n var json = {\n title: fakeDom.querySelector('title').innerText,\n pageClass: fakeDom.querySelector('#swupBody').className,\n originalContent: html,\n blocks: blocks\n };\n return json;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/getDataFromHtml.js?"); - -/***/ }), - -/***/ "./src/modules/getUrl.js": -/*!*******************************!*\ - !*** ./src/modules/getUrl.js ***! - \*******************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function () {\n this.currentUrl = window.location.pathname + window.location.search;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/getUrl.js?"); - -/***/ }), - -/***/ "./src/modules/goBack.js": -/*!*******************************!*\ - !*** ./src/modules/goBack.js ***! - \*******************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (page, popstate) {\n setTimeout(function () {\n document.body.classList.remove('is-changing');\n history.back();\n }, 100);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/goBack.js?"); - -/***/ }), - -/***/ "./src/modules/loadPage.js": -/*!*********************************!*\ - !*** ./src/modules/loadPage.js ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nvar forEach = Array.prototype.forEach;\n\n\nmodule.exports = function (url, popstate) {\n var _this = this;\n\n var finalPage = null;\n\n // scrolling\n if (this.options.doScrollingRightAway && !this.scrollToElement) {\n this.doScrolling(popstate);\n }\n\n var animationPromises = [];\n\n if (!popstate) {\n // start animation\n document.documentElement.classList.add('is-changing');\n document.documentElement.classList.add('is-leaving');\n document.documentElement.classList.add('is-animating');\n document.documentElement.classList.add('to-' + this.classify(url));\n\n // detect animation end\n var animatedElements = document.querySelectorAll(this.options.animationSelector);\n forEach.call(animatedElements, function (element) {\n var promise = new Promise(function (resolve) {\n element.addEventListener(_this.transitionEndEvent, resolve);\n });\n animationPromises.push(promise);\n });\n\n Promise.all(animationPromises).then(function () {\n _this.triggerEvent('animationOutDone');\n });\n\n // create pop element with or without anchor\n if (this.scrollToElement != null) {\n var pop = url + this.scrollToElement;\n } else {\n var pop = url;\n }\n this.createState(pop);\n } else {\n // proceed without animating\n this.triggerEvent('animationSkipped');\n }\n\n if (this.cache.exists(url)) {\n var xhrPromise = new Promise(function (resolve) {\n resolve();\n });\n this.triggerEvent('pageRetrievedFromCache');\n } else {\n if (!this.preloadPromise || this.preloadPromise.route != url) {\n var xhrPromise = new Promise(function (resolve) {\n _this.getPage(url, function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n _this.goBack();\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = url;\n // render page\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pageLoaded');\n }\n resolve();\n });\n });\n } else {\n var xhrPromise = this.preloadPromise;\n }\n }\n\n Promise.all(animationPromises.concat([xhrPromise])).then(function () {\n finalPage = _this.cache.getPage(url);\n if (!_this.options.cache) {\n _this.cache.empty(_this.options.debugMode);\n }\n _this.renderPage(finalPage, popstate);\n _this.preloadPromise = null;\n });\n};\n\n//# sourceURL=webpack://Swup/./src/modules/loadPage.js?"); - -/***/ }), - -/***/ "./src/modules/markSwupElements.js": -/*!*****************************************!*\ - !*** ./src/modules/markSwupElements.js ***! - \*****************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (element) {\n var _this = this;\n\n var blocks = 0;\n\n for (var i = 0; i < this.options.elements.length; i++) {\n if (element.querySelector(this.options.elements[i]) == null) {\n console.warn(\"Element \" + this.options.elements[i] + \" is not in current page.\");\n } else {\n [].forEach.call(document.body.querySelectorAll(this.options.elements[i]), function (item, index) {\n element.querySelectorAll(_this.options.elements[i])[index].dataset.swup = blocks;\n blocks++;\n });\n }\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/markSwupElements.js?"); - -/***/ }), - -/***/ "./src/modules/preloadPages.js": -/*!*************************************!*\ - !*** ./src/modules/preloadPages.js ***! - \*************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nvar _Link = __webpack_require__(/*! ../Link */ \"./src/Link.js\");\n\nvar _Link2 = _interopRequireDefault(_Link);\n\nfunction _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }\n\nmodule.exports = function (eventName) {\n var _this = this;\n\n if (this.options.preload) {\n var preload = function preload(pathname) {\n var link = new _Link2.default();\n link.setPath(pathname);\n if (link.getAddress() != _this.currentUrl && !_this.cache.exists(link.getAddress()) && _this.preloadPromise == null) {\n _this.getPage(link.getAddress(), function (response) {\n if (response === null) {\n console.warn('Server error.');\n _this.triggerEvent('serverError');\n } else {\n // get json data\n var page = _this.getDataFromHtml(response);\n page.url = link.getAddress();\n _this.cache.cacheUrl(page, _this.options.debugMode);\n _this.triggerEvent('pagePreloaded');\n }\n });\n }\n };\n\n document.querySelectorAll('[data-swup-preload]').forEach(function (element) {\n preload(element.href);\n });\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/preloadPages.js?"); - -/***/ }), - -/***/ "./src/modules/renderPage.js": -/*!***********************************!*\ - !*** ./src/modules/renderPage.js ***! - \***********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nvar forEach = Array.prototype.forEach;\n\n\nmodule.exports = function (page, popstate) {\n var _this = this;\n\n document.documentElement.classList.remove('is-leaving');\n\n // only add for non-popstate transitions\n if (!popstate) {\n document.documentElement.classList.add('is-rendering');\n }\n\n // replace blocks\n for (var i = 0; i < page.blocks.length; i++) {\n document.body.querySelector('[data-swup=\"' + i + '\"]').outerHTML = page.blocks[i];\n }\n\n // set title\n document.title = page.title;\n\n this.triggerEvent('contentReplaced');\n this.triggerEvent('pageView');\n setTimeout(function () {\n document.documentElement.classList.remove('is-animating');\n }, 10);\n\n // handle classes after render\n if (this.options.pageClassPrefix !== false) {\n document.body.className.split(' ').forEach(function (className) {\n // empty string for page class\n if (className != \"\" && className.includes(_this.options.pageClassPrefix)) {\n document.body.classList.remove(className);\n }\n });\n }\n\n // empty string for page class\n if (page.pageClass != \"\") {\n page.pageClass.split(' ').forEach(function (className) {\n document.body.classList.add(className);\n });\n }\n\n // scrolling\n if (!this.options.doScrollingRightAway || this.scrollToElement) {\n this.doScrolling(popstate);\n }\n\n // detect animation end\n var animatedElements = document.querySelectorAll(this.options.animationSelector);\n var promises = [];\n forEach.call(animatedElements, function (element) {\n var promise = new Promise(function (resolve) {\n element.addEventListener(_this.transitionEndEvent, resolve);\n });\n promises.push(promise);\n });\n\n //preload pages if possible\n this.preloadPages();\n\n Promise.all(promises).then(function () {\n _this.triggerEvent('animationInDone');\n // remove \"to-{page}\" classes\n document.documentElement.classList.forEach(function (classItem) {\n if (classItem.startsWith('to-')) {\n document.documentElement.classList.remove(classItem);\n }\n });\n document.documentElement.classList.remove('is-changing');\n document.documentElement.classList.remove('is-rendering');\n });\n\n // update current url\n this.getUrl();\n};\n\n//# sourceURL=webpack://Swup/./src/modules/renderPage.js?"); - -/***/ }), - -/***/ "./src/modules/request.js": -/*!********************************!*\ - !*** ./src/modules/request.js ***! - \********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (location, callback) {\n var request = new XMLHttpRequest();\n\n request.onreadystatechange = function () {\n if (request.readyState === 4) {\n if (request.status !== 500) {\n callback(request.responseText, request);\n } else {\n callback(null, request);\n }\n }\n };\n\n request.open(\"GET\", location, true);\n request.setRequestHeader(\"X-Requested-With\", \"swup\");\n request.send(null);\n return request;\n};\n\n//# sourceURL=webpack://Swup/./src/modules/request.js?"); - -/***/ }), - -/***/ "./src/modules/scrollTo.js": -/*!*********************************!*\ - !*** ./src/modules/scrollTo.js ***! - \*********************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (element, to, duration) {\n var _this = this;\n\n var body = document.body;\n\n var UP = -1;\n var DOWN = 1;\n\n var friction = 0.7;\n var acceleration = 0.04;\n\n var positionY = 100;\n var velocityY = 0;\n var targetPositionY = 400;\n\n var raf = null;\n\n function getScrollTop() {\n return document.body.scrollTop || document.documentElement.scrollTop;\n }\n\n var animate = function animate() {\n var distance = update();\n render();\n\n if (Math.abs(distance) > 0.1) {\n raf = requestAnimationFrame(animate);\n } else {\n _this.triggerEvent('scrollDone');\n }\n };\n\n function update() {\n var distance = targetPositionY - positionY;\n var attraction = distance * acceleration;\n\n applyForce(attraction);\n\n velocityY *= friction;\n positionY += velocityY;\n\n return distance;\n }\n\n var applyForce = function applyForce(force) {\n velocityY += force;\n };\n\n var render = function render() {\n window.scrollTo(0, positionY);\n };\n\n window.addEventListener('mousewheel', function (event) {\n if (raf) {\n cancelAnimationFrame(raf);\n raf = null;\n }\n }, {\n passive: true\n });\n\n var scrollTo = function scrollTo(offset, callback) {\n positionY = getScrollTop();\n targetPositionY = offset;\n velocityY = 0;\n animate();\n };\n\n this.triggerEvent('scrollStart');\n if (duration == 0) {\n window.scrollTo(0, 0);\n this.triggerEvent('scrollDone');\n } else {\n scrollTo(to);\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/scrollTo.js?"); - -/***/ }), - -/***/ "./src/modules/triggerEvent.js": -/*!*************************************!*\ - !*** ./src/modules/triggerEvent.js ***! - \*************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (eventName) {\n if (this.options.debugMode) {\n console.log('%cswup:' + '%c' + eventName, 'color: #343434', 'color: #009ACD');\n }\n var event = new CustomEvent('swup:' + eventName, { detail: eventName });\n document.dispatchEvent(event);\n};\n\n//# sourceURL=webpack://Swup/./src/modules/triggerEvent.js?"); - -/***/ }), - -/***/ "./src/modules/updateTransition.js": -/*!*****************************************!*\ - !*** ./src/modules/updateTransition.js ***! - \*****************************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function (from, to, custom) {\n\n // homepage case\n if (from == \"/\") {\n from = \"/homepage\";\n }\n if (to == \"/\") {\n to = \"/homepage\";\n }\n\n // transition routes\n this.transition = {\n from: from.replace('/', ''),\n to: to.replace('/', '')\n };\n\n if (custom) {\n this.transition.custom = custom;\n }\n};\n\n//# sourceURL=webpack://Swup/./src/modules/updateTransition.js?"); - -/***/ }), - -/***/ "./src/transitionEnd.js": -/*!******************************!*\ - !*** ./src/transitionEnd.js ***! - \******************************/ -/*! no static exports found */ -/***/ (function(module, exports, __webpack_require__) { - -"use strict"; -eval("\n\nmodule.exports = function transitionEnd() {\n var el = document.createElement('div');\n\n var transEndEventNames = {\n WebkitTransition: 'webkitTransitionEnd',\n MozTransition: 'transitionend',\n OTransition: 'oTransitionEnd otransitionend',\n transition: 'transitionend'\n };\n\n for (var name in transEndEventNames) {\n if (el.style[name] !== undefined) {\n return transEndEventNames[name];\n }\n }\n\n return false;\n};\n\n//# sourceURL=webpack://Swup/./src/transitionEnd.js?"); - -/***/ }) - -/******/ }); -}); \ No newline at end of file +(function e(t,n){if(typeof exports==="object"&&typeof module==="object")module.exports=n();else if(typeof define==="function"&&define.amd)define([],n);else if(typeof exports==="object")exports["Swup"]=n();else t["Swup"]=n()})(window,function(){return function(e){var t={};function n(r){if(t[r]){return t[r].exports}var o=t[r]={i:r,l:false,exports:{}};e[r].call(o.exports,o,o.exports,n);o.l=true;return o.exports}n.m=e;n.c=t;n.d=function(e,t,r){if(!n.o(e,t)){Object.defineProperty(e,t,{configurable:false,enumerable:true,get:r})}};n.r=function(e){Object.defineProperty(e,"__esModule",{value:true})};n.n=function(e){var t=e&&e.__esModule?function t(){return e["default"]}:function t(){return e};n.d(t,"a",t);return t};n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)};n.p="";return n(n.s=21)}([function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=function(){function e(e,t){for(var n=0;n.1){f=requestAnimationFrame(e)}else{r.triggerEvent("scrollDone")}};function v(){var e=d-u;var t=e*l;m(t);c*=a;u+=c;return e}var m=function e(t){c+=t};var g=function e(){window.scrollTo(0,u)};window.addEventListener("mousewheel",function(e){if(f){cancelAnimationFrame(f);f=null}},{passive:true});var y=function e(t,n){u=h();d=t;c=0;p()};this.triggerEvent("scrollStart");if(n==0){window.scrollTo(0,0);this.triggerEvent("scrollDone")}else{y(t)}}},function(e,t,n){"use strict";e.exports=function(){this.currentUrl=window.location.pathname+window.location.search}},function(e,t,n){"use strict";e.exports=function(e){if(this.options.debugMode){console.log("%cswup:"+"%c"+e,"color: #343434","color: #009ACD")}var t=new CustomEvent("swup:"+e,{detail:e});document.dispatchEvent(t)}},function(e,t,n){"use strict";e.exports=function(e){window.history.pushState({url:e||window.location.href.split(window.location.hostname)[1],random:Math.random()},document.getElementsByTagName("title")[0].innerText,e||window.location.href.split(window.location.hostname)[1])}},function(e,t,n){"use strict";e.exports=function(e,t){setTimeout(function(){document.body.classList.remove("is-changing");history.back()},100)}},function(e,t,n){"use strict";var r=Array.prototype.forEach;e.exports=function(e,t){var n=this;document.documentElement.classList.remove("is-leaving");if(!t){document.documentElement.classList.add("is-rendering")}for(var o=0;o","");var r=document.createElement("div");r.innerHTML=n;var o=[];for(var i=0;i0){return parseInt(e.substring(t+5,e.indexOf(".",t)),10)}var n=e.indexOf("Trident/");if(n>0){var r=e.indexOf("rv:");return parseInt(e.substring(r+3,e.indexOf(".",r)),10)}var o=e.indexOf("Edge/");if(o>0){return parseInt(e.substring(o+5,e.indexOf(".",o)),10)}return false};e.exports=n},function(e,t){var n=9;if(typeof Element!=="undefined"&&!Element.prototype.matches){var r=Element.prototype;r.matches=r.matchesSelector||r.mozMatchesSelector||r.msMatchesSelector||r.oMatchesSelector||r.webkitMatchesSelector}function o(e,t){while(e&&e.nodeType!==n){if(typeof e.matches==="function"&&e.matches(t)){return e}e=e.parentNode}}e.exports=o},function(e,t,n){var r=n(18);function o(e,t,n,r,o){var s=i.apply(this,arguments);e.addEventListener(n,s,o);return{destroy:function(){e.removeEventListener(n,s,o)}}}function i(e,t,n,o){return function(n){n.delegateTarget=r(n.target,t);if(n.delegateTarget){o.call(e,n)}}}e.exports=o},function(e,t,n){"use strict";Object.defineProperty(t,"__esModule",{value:true});var r=Object.assign||function(e){for(var t=1;t