swup 2.0.19 → 3.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/helpers.cjs +2 -0
- package/dist/helpers.cjs.map +1 -0
- package/dist/helpers.modern.js +2 -0
- package/dist/helpers.modern.js.map +1 -0
- package/dist/helpers.module.js +2 -0
- package/dist/helpers.module.js.map +1 -0
- package/dist/index.cjs +2 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.modern.js +2 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/index.module.js +2 -0
- package/dist/index.module.js.map +1 -0
- package/dist/index.umd.js +3 -0
- package/dist/index.umd.js.map +1 -0
- package/dist/src/config/version.d.ts +5 -0
- package/dist/src/helpers/Location.d.ts +31 -0
- package/dist/src/helpers/classify.d.ts +2 -0
- package/dist/src/helpers/cleanupAnimationClasses.d.ts +2 -0
- package/dist/src/helpers/createHistoryRecord.d.ts +2 -0
- package/dist/src/helpers/delegateEvent.d.ts +8 -0
- package/dist/src/helpers/fetch.d.ts +6 -0
- package/dist/src/helpers/getCurrentUrl.d.ts +4 -0
- package/dist/src/helpers/getDataFromHtml.d.ts +8 -0
- package/dist/src/helpers/index.d.ts +11 -0
- package/dist/src/helpers/markSwupElements.d.ts +2 -0
- package/dist/src/helpers/updateHistoryRecord.d.ts +2 -0
- package/dist/src/helpers/versionSatisfies.d.ts +12 -0
- package/dist/src/helpers.d.ts +1 -0
- package/dist/src/index.d.ts +97 -0
- package/dist/src/modules/Cache.d.ts +20 -0
- package/dist/src/modules/enterPage.d.ts +6 -0
- package/dist/src/modules/getAnchorElement.d.ts +2 -0
- package/dist/src/modules/getAnimationPromises.d.ts +7 -0
- package/dist/src/modules/getPageData.d.ts +7 -0
- package/dist/src/modules/leavePage.d.ts +7 -0
- package/dist/src/modules/loadPage.d.ts +4 -0
- package/dist/src/modules/off.d.ts +4 -0
- package/dist/src/modules/on.d.ts +4 -0
- package/dist/src/modules/plugins.d.ts +13 -0
- package/dist/src/modules/renderPage.d.ts +7 -0
- package/dist/src/modules/replaceContent.d.ts +17 -0
- package/dist/src/modules/triggerEvent.d.ts +4 -0
- package/dist/src/modules/updateTransition.d.ts +3 -0
- package/dist/src/src/config/version.d.ts +5 -0
- package/dist/src/src/helpers/Location.d.ts +31 -0
- package/dist/src/src/helpers/classify.d.ts +2 -0
- package/dist/src/src/helpers/cleanupAnimationClasses.d.ts +2 -0
- package/dist/src/src/helpers/createHistoryRecord.d.ts +2 -0
- package/dist/src/src/helpers/delegateEvent.d.ts +8 -0
- package/dist/src/src/helpers/fetch.d.ts +6 -0
- package/dist/src/src/helpers/getCurrentUrl.d.ts +4 -0
- package/dist/src/src/helpers/getDataFromHtml.d.ts +8 -0
- package/dist/src/src/helpers/index.d.ts +11 -0
- package/dist/src/src/helpers/markSwupElements.d.ts +2 -0
- package/dist/src/src/helpers/updateHistoryRecord.d.ts +2 -0
- package/dist/src/src/helpers/versionSatisfies.d.ts +12 -0
- package/dist/src/src/helpers.d.ts +1 -0
- package/dist/src/src/index.d.ts +103 -0
- package/dist/src/src/modules/Cache.d.ts +20 -0
- package/dist/src/src/modules/enterPage.d.ts +6 -0
- package/dist/src/src/modules/getAnchorElement.d.ts +2 -0
- package/dist/src/src/modules/getAnimationPromises.d.ts +7 -0
- package/dist/src/src/modules/getPageData.d.ts +7 -0
- package/dist/src/src/modules/leavePage.d.ts +7 -0
- package/dist/src/src/modules/loadPage.d.ts +7 -0
- package/dist/src/src/modules/off.d.ts +4 -0
- package/dist/src/src/modules/on.d.ts +6 -0
- package/dist/src/src/modules/plugins.d.ts +14 -0
- package/dist/src/src/modules/renderPage.d.ts +7 -0
- package/dist/src/src/modules/replaceContent.d.ts +17 -0
- package/dist/src/src/modules/triggerEvent.d.ts +4 -0
- package/dist/src/src/modules/updateTransition.d.ts +3 -0
- package/dist/src/src/utils/index.d.ts +5 -0
- package/dist/src/src/utils.d.ts +1 -0
- package/dist/src/types.d.ts +12 -0
- package/dist/src/utils/index.d.ts +5 -0
- package/dist/src/utils.d.ts +1 -0
- package/dist/types.cjs +2 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.modern.js +2 -0
- package/dist/types.modern.js.map +1 -0
- package/dist/types.module.js +2 -0
- package/dist/types.module.js.map +1 -0
- package/dist/utils.cjs +2 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.modern.js +2 -0
- package/dist/utils.modern.js.map +1 -0
- package/dist/utils.module.js +2 -0
- package/dist/utils.module.js.map +1 -0
- package/package.json +41 -23
- package/readme.md +52 -36
- package/src/config/version.ts +13 -0
- package/src/helpers/Location.ts +44 -0
- package/src/helpers/classify.ts +13 -0
- package/src/helpers/cleanupAnimationClasses.ts +10 -0
- package/src/helpers/createHistoryRecord.ts +14 -0
- package/src/helpers/delegateEvent.ts +23 -0
- package/src/helpers/fetch.ts +35 -0
- package/src/helpers/getCurrentUrl.ts +5 -0
- package/src/helpers/getDataFromHtml.ts +41 -0
- package/src/helpers/index.ts +11 -0
- package/src/helpers/markSwupElements.ts +18 -0
- package/src/helpers/updateHistoryRecord.ts +18 -0
- package/src/helpers/versionSatisfies.ts +50 -0
- package/src/helpers.ts +4 -0
- package/src/index.ts +369 -0
- package/src/modules/Cache.ts +57 -0
- package/src/modules/enterPage.ts +28 -0
- package/src/modules/fetchPage.ts +35 -0
- package/src/modules/getAnchorElement.ts +19 -0
- package/src/modules/getAnimationPromises.ts +176 -0
- package/src/modules/getPageData.ts +26 -0
- package/src/modules/leavePage.ts +33 -0
- package/src/modules/loadPage.ts +54 -0
- package/src/modules/off.ts +23 -0
- package/src/modules/on.ts +35 -0
- package/src/modules/plugins.ts +58 -0
- package/src/modules/renderPage.ts +52 -0
- package/src/modules/replaceContent.ts +28 -0
- package/src/modules/triggerEvent.ts +23 -0
- package/src/modules/updateTransition.ts +7 -0
- package/src/utils/index.ts +32 -0
- package/src/utils.ts +4 -0
- package/.editorconfig +0 -19
- package/cypress.config.js +0 -14
- package/dist/swup.js +0 -1524
- package/dist/swup.min.js +0 -1
- package/lib/helpers/Link.js +0 -56
- package/lib/helpers/classify.js +0 -18
- package/lib/helpers/cleanupAnimationClasses.js +0 -18
- package/lib/helpers/createHistoryRecord.js +0 -14
- package/lib/helpers/fetch.js +0 -41
- package/lib/helpers/getCurrentUrl.js +0 -10
- package/lib/helpers/getDataFromHtml.js +0 -43
- package/lib/helpers/index.js +0 -64
- package/lib/helpers/markSwupElements.js +0 -24
- package/lib/helpers/normalizeUrl.js +0 -17
- package/lib/helpers/transitionEnd.js +0 -14
- package/lib/helpers/transitionProperty.js +0 -14
- package/lib/index.js +0 -305
- package/lib/modules/Cache.js +0 -66
- package/lib/modules/getAnchorElement.js +0 -25
- package/lib/modules/getAnimationPromises.js +0 -43
- package/lib/modules/getPageData.js +0 -26
- package/lib/modules/loadPage.js +0 -123
- package/lib/modules/off.js +0 -34
- package/lib/modules/on.js +0 -14
- package/lib/modules/plugins.js +0 -54
- package/lib/modules/renderPage.js +0 -76
- package/lib/modules/triggerEvent.js +0 -21
- package/lib/modules/updateTransition.js +0 -15
- package/lib/utils/index.js +0 -32
package/lib/index.js
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
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; };
|
|
8
|
-
|
|
9
|
-
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; }; }();
|
|
10
|
-
|
|
11
|
-
// modules
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _delegateIt = require('delegate-it');
|
|
15
|
-
|
|
16
|
-
var _delegateIt2 = _interopRequireDefault(_delegateIt);
|
|
17
|
-
|
|
18
|
-
var _Cache = require('./modules/Cache');
|
|
19
|
-
|
|
20
|
-
var _Cache2 = _interopRequireDefault(_Cache);
|
|
21
|
-
|
|
22
|
-
var _loadPage = require('./modules/loadPage');
|
|
23
|
-
|
|
24
|
-
var _loadPage2 = _interopRequireDefault(_loadPage);
|
|
25
|
-
|
|
26
|
-
var _renderPage = require('./modules/renderPage');
|
|
27
|
-
|
|
28
|
-
var _renderPage2 = _interopRequireDefault(_renderPage);
|
|
29
|
-
|
|
30
|
-
var _triggerEvent = require('./modules/triggerEvent');
|
|
31
|
-
|
|
32
|
-
var _triggerEvent2 = _interopRequireDefault(_triggerEvent);
|
|
33
|
-
|
|
34
|
-
var _on = require('./modules/on');
|
|
35
|
-
|
|
36
|
-
var _on2 = _interopRequireDefault(_on);
|
|
37
|
-
|
|
38
|
-
var _off = require('./modules/off');
|
|
39
|
-
|
|
40
|
-
var _off2 = _interopRequireDefault(_off);
|
|
41
|
-
|
|
42
|
-
var _updateTransition = require('./modules/updateTransition');
|
|
43
|
-
|
|
44
|
-
var _updateTransition2 = _interopRequireDefault(_updateTransition);
|
|
45
|
-
|
|
46
|
-
var _getAnchorElement = require('./modules/getAnchorElement');
|
|
47
|
-
|
|
48
|
-
var _getAnchorElement2 = _interopRequireDefault(_getAnchorElement);
|
|
49
|
-
|
|
50
|
-
var _getAnimationPromises = require('./modules/getAnimationPromises');
|
|
51
|
-
|
|
52
|
-
var _getAnimationPromises2 = _interopRequireDefault(_getAnimationPromises);
|
|
53
|
-
|
|
54
|
-
var _getPageData = require('./modules/getPageData');
|
|
55
|
-
|
|
56
|
-
var _getPageData2 = _interopRequireDefault(_getPageData);
|
|
57
|
-
|
|
58
|
-
var _plugins = require('./modules/plugins');
|
|
59
|
-
|
|
60
|
-
var _utils = require('./utils');
|
|
61
|
-
|
|
62
|
-
var _helpers = require('./helpers');
|
|
63
|
-
|
|
64
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
65
|
-
|
|
66
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
67
|
-
|
|
68
|
-
var Swup = function () {
|
|
69
|
-
function Swup(setOptions) {
|
|
70
|
-
_classCallCheck(this, Swup);
|
|
71
|
-
|
|
72
|
-
// default options
|
|
73
|
-
var defaults = {
|
|
74
|
-
animateHistoryBrowsing: false,
|
|
75
|
-
animationSelector: '[class*="transition-"]',
|
|
76
|
-
linkSelector: 'a[href^="' + window.location.origin + '"]:not([data-no-swup]), a[href^="/"]:not([data-no-swup]), a[href^="#"]:not([data-no-swup])',
|
|
77
|
-
cache: true,
|
|
78
|
-
containers: ['#swup'],
|
|
79
|
-
requestHeaders: {
|
|
80
|
-
'X-Requested-With': 'swup',
|
|
81
|
-
Accept: 'text/html, application/xhtml+xml'
|
|
82
|
-
},
|
|
83
|
-
plugins: [],
|
|
84
|
-
skipPopStateHandling: function skipPopStateHandling(event) {
|
|
85
|
-
return !(event.state && event.state.source === 'swup');
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// merge options
|
|
90
|
-
var options = _extends({}, defaults, setOptions);
|
|
91
|
-
|
|
92
|
-
// handler arrays
|
|
93
|
-
this._handlers = {
|
|
94
|
-
animationInDone: [],
|
|
95
|
-
animationInStart: [],
|
|
96
|
-
animationOutDone: [],
|
|
97
|
-
animationOutStart: [],
|
|
98
|
-
animationSkipped: [],
|
|
99
|
-
clickLink: [],
|
|
100
|
-
contentReplaced: [],
|
|
101
|
-
disabled: [],
|
|
102
|
-
enabled: [],
|
|
103
|
-
openPageInNewTab: [],
|
|
104
|
-
pageLoaded: [],
|
|
105
|
-
pageRetrievedFromCache: [],
|
|
106
|
-
pageView: [],
|
|
107
|
-
popState: [],
|
|
108
|
-
samePage: [],
|
|
109
|
-
samePageWithHash: [],
|
|
110
|
-
serverError: [],
|
|
111
|
-
transitionStart: [],
|
|
112
|
-
transitionEnd: [],
|
|
113
|
-
willReplaceContent: []
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
// variable for anchor to scroll to after render
|
|
117
|
-
this.scrollToElement = null;
|
|
118
|
-
// variable for promise used for preload, so no new loading of the same page starts while page is loading
|
|
119
|
-
this.preloadPromise = null;
|
|
120
|
-
// variable for save options
|
|
121
|
-
this.options = options;
|
|
122
|
-
// variable for plugins array
|
|
123
|
-
this.plugins = [];
|
|
124
|
-
// variable for current transition object
|
|
125
|
-
this.transition = {};
|
|
126
|
-
// variable for keeping event listeners from "delegate"
|
|
127
|
-
this.delegatedListeners = {};
|
|
128
|
-
// so we are able to remove the listener
|
|
129
|
-
this.boundPopStateHandler = this.popStateHandler.bind(this);
|
|
130
|
-
|
|
131
|
-
// make modules accessible in instance
|
|
132
|
-
this.cache = new _Cache2.default();
|
|
133
|
-
this.cache.swup = this;
|
|
134
|
-
this.loadPage = _loadPage2.default;
|
|
135
|
-
this.renderPage = _renderPage2.default;
|
|
136
|
-
this.triggerEvent = _triggerEvent2.default;
|
|
137
|
-
this.on = _on2.default;
|
|
138
|
-
this.off = _off2.default;
|
|
139
|
-
this.updateTransition = _updateTransition2.default;
|
|
140
|
-
this.getAnimationPromises = _getAnimationPromises2.default;
|
|
141
|
-
this.getPageData = _getPageData2.default;
|
|
142
|
-
this.getAnchorElement = _getAnchorElement2.default;
|
|
143
|
-
this.log = function () {}; // here so it can be used by plugins
|
|
144
|
-
this.use = _plugins.use;
|
|
145
|
-
this.unuse = _plugins.unuse;
|
|
146
|
-
this.findPlugin = _plugins.findPlugin;
|
|
147
|
-
this.getCurrentUrl = _helpers.getCurrentUrl;
|
|
148
|
-
this.cleanupAnimationClasses = _helpers.cleanupAnimationClasses;
|
|
149
|
-
|
|
150
|
-
// enable swup
|
|
151
|
-
this.enable();
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
_createClass(Swup, [{
|
|
155
|
-
key: 'enable',
|
|
156
|
-
value: function enable() {
|
|
157
|
-
var _this = this;
|
|
158
|
-
|
|
159
|
-
// check for Promise support
|
|
160
|
-
if (typeof Promise === 'undefined') {
|
|
161
|
-
console.warn('Promise is not supported');
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
// add event listeners
|
|
166
|
-
this.delegatedListeners.click = (0, _delegateIt2.default)(document, this.options.linkSelector, 'click', this.linkClickHandler.bind(this));
|
|
167
|
-
window.addEventListener('popstate', this.boundPopStateHandler);
|
|
168
|
-
|
|
169
|
-
// initial save to cache
|
|
170
|
-
if (this.options.cache) {}
|
|
171
|
-
// disabled to avoid caching modified dom state
|
|
172
|
-
// https://github.com/swup/swup/issues/475
|
|
173
|
-
// logic moved to preload plugin
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
// mark swup blocks in html
|
|
177
|
-
(0, _helpers.markSwupElements)(document.documentElement, this.options.containers);
|
|
178
|
-
|
|
179
|
-
// mount plugins
|
|
180
|
-
this.options.plugins.forEach(function (plugin) {
|
|
181
|
-
_this.use(plugin);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
// modify initial history record
|
|
185
|
-
window.history.replaceState(Object.assign({}, window.history.state, {
|
|
186
|
-
url: window.location.href,
|
|
187
|
-
random: Math.random(),
|
|
188
|
-
source: 'swup'
|
|
189
|
-
}), document.title, window.location.href);
|
|
190
|
-
|
|
191
|
-
// trigger enabled event
|
|
192
|
-
this.triggerEvent('enabled');
|
|
193
|
-
|
|
194
|
-
// add swup-enabled class to html tag
|
|
195
|
-
document.documentElement.classList.add('swup-enabled');
|
|
196
|
-
|
|
197
|
-
// trigger page view event
|
|
198
|
-
this.triggerEvent('pageView');
|
|
199
|
-
}
|
|
200
|
-
}, {
|
|
201
|
-
key: 'destroy',
|
|
202
|
-
value: function destroy() {
|
|
203
|
-
var _this2 = this;
|
|
204
|
-
|
|
205
|
-
// remove delegated listeners
|
|
206
|
-
this.delegatedListeners.click.destroy();
|
|
207
|
-
|
|
208
|
-
// remove popstate listener
|
|
209
|
-
window.removeEventListener('popstate', this.boundPopStateHandler);
|
|
210
|
-
|
|
211
|
-
// empty cache
|
|
212
|
-
this.cache.empty();
|
|
213
|
-
|
|
214
|
-
// unmount plugins
|
|
215
|
-
this.options.plugins.forEach(function (plugin) {
|
|
216
|
-
_this2.unuse(plugin);
|
|
217
|
-
});
|
|
218
|
-
|
|
219
|
-
// remove swup data atributes from blocks
|
|
220
|
-
(0, _utils.queryAll)('[data-swup]').forEach(function (element) {
|
|
221
|
-
element.removeAttribute('data-swup');
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
// remove handlers
|
|
225
|
-
this.off();
|
|
226
|
-
|
|
227
|
-
// trigger disable event
|
|
228
|
-
this.triggerEvent('disabled');
|
|
229
|
-
|
|
230
|
-
// remove swup-enabled class from html tag
|
|
231
|
-
document.documentElement.classList.remove('swup-enabled');
|
|
232
|
-
}
|
|
233
|
-
}, {
|
|
234
|
-
key: 'linkClickHandler',
|
|
235
|
-
value: function linkClickHandler(event) {
|
|
236
|
-
// no control key pressed
|
|
237
|
-
if (!event.metaKey && !event.ctrlKey && !event.shiftKey && !event.altKey) {
|
|
238
|
-
// index of pressed button needs to be checked because Firefox triggers click on all mouse buttons
|
|
239
|
-
if (event.button === 0) {
|
|
240
|
-
this.triggerEvent('clickLink', event);
|
|
241
|
-
event.preventDefault();
|
|
242
|
-
var link = new _helpers.Link(event.delegateTarget);
|
|
243
|
-
if (link.getAddress() == (0, _helpers.getCurrentUrl)() || link.getAddress() == '') {
|
|
244
|
-
// link to the same URL
|
|
245
|
-
if (link.getHash() != '') {
|
|
246
|
-
// link to the same URL with hash
|
|
247
|
-
this.triggerEvent('samePageWithHash', event);
|
|
248
|
-
var element = (0, _getAnchorElement2.default)(link.getHash());
|
|
249
|
-
if (element != null) {
|
|
250
|
-
history.replaceState({
|
|
251
|
-
url: link.getAddress() + link.getHash(),
|
|
252
|
-
random: Math.random(),
|
|
253
|
-
source: 'swup'
|
|
254
|
-
}, document.title, link.getAddress() + link.getHash());
|
|
255
|
-
} else {
|
|
256
|
-
// referenced element not found
|
|
257
|
-
console.warn('Element for offset not found (' + link.getHash() + ')');
|
|
258
|
-
}
|
|
259
|
-
} else {
|
|
260
|
-
// link to the same URL without hash
|
|
261
|
-
this.triggerEvent('samePage', event);
|
|
262
|
-
}
|
|
263
|
-
} else {
|
|
264
|
-
// link to different url
|
|
265
|
-
if (link.getHash() != '') {
|
|
266
|
-
this.scrollToElement = link.getHash();
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
// get custom transition from data
|
|
270
|
-
var customTransition = event.delegateTarget.getAttribute('data-swup-transition');
|
|
271
|
-
|
|
272
|
-
// load page
|
|
273
|
-
this.loadPage({ url: link.getAddress(), customTransition: customTransition }, false);
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
} else {
|
|
277
|
-
// open in new tab (do nothing)
|
|
278
|
-
this.triggerEvent('openPageInNewTab', event);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
}, {
|
|
282
|
-
key: 'popStateHandler',
|
|
283
|
-
value: function popStateHandler(event) {
|
|
284
|
-
if (this.options.skipPopStateHandling(event)) return;
|
|
285
|
-
var link = new _helpers.Link(event.state ? event.state.url : window.location.pathname);
|
|
286
|
-
if (link.getHash() !== '') {
|
|
287
|
-
this.scrollToElement = link.getHash();
|
|
288
|
-
} else {
|
|
289
|
-
event.preventDefault();
|
|
290
|
-
}
|
|
291
|
-
this.triggerEvent('popState', event);
|
|
292
|
-
|
|
293
|
-
if (!this.options.animateHistoryBrowsing) {
|
|
294
|
-
document.documentElement.classList.remove('is-animating');
|
|
295
|
-
(0, _helpers.cleanupAnimationClasses)();
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
this.loadPage({ url: link.getAddress() }, event);
|
|
299
|
-
}
|
|
300
|
-
}]);
|
|
301
|
-
|
|
302
|
-
return Swup;
|
|
303
|
-
}();
|
|
304
|
-
|
|
305
|
-
exports.default = Swup;
|
package/lib/modules/Cache.js
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.Cache = undefined;
|
|
7
|
-
|
|
8
|
-
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; }; }();
|
|
9
|
-
|
|
10
|
-
var _helpers = require('../helpers');
|
|
11
|
-
|
|
12
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
13
|
-
|
|
14
|
-
var Cache = exports.Cache = function () {
|
|
15
|
-
function Cache() {
|
|
16
|
-
_classCallCheck(this, Cache);
|
|
17
|
-
|
|
18
|
-
this.pages = {};
|
|
19
|
-
this.last = null;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
_createClass(Cache, [{
|
|
23
|
-
key: 'cacheUrl',
|
|
24
|
-
value: function cacheUrl(page) {
|
|
25
|
-
page.url = (0, _helpers.normalizeUrl)(page.url);
|
|
26
|
-
if (page.url in this.pages === false) {
|
|
27
|
-
this.pages[page.url] = page;
|
|
28
|
-
}
|
|
29
|
-
this.last = this.pages[page.url];
|
|
30
|
-
this.swup.log('Cache (' + Object.keys(this.pages).length + ')', this.pages);
|
|
31
|
-
}
|
|
32
|
-
}, {
|
|
33
|
-
key: 'getPage',
|
|
34
|
-
value: function getPage(url) {
|
|
35
|
-
url = (0, _helpers.normalizeUrl)(url);
|
|
36
|
-
return this.pages[url];
|
|
37
|
-
}
|
|
38
|
-
}, {
|
|
39
|
-
key: 'getCurrentPage',
|
|
40
|
-
value: function getCurrentPage() {
|
|
41
|
-
return this.getPage((0, _helpers.getCurrentUrl)());
|
|
42
|
-
}
|
|
43
|
-
}, {
|
|
44
|
-
key: 'exists',
|
|
45
|
-
value: function exists(url) {
|
|
46
|
-
url = (0, _helpers.normalizeUrl)(url);
|
|
47
|
-
return url in this.pages;
|
|
48
|
-
}
|
|
49
|
-
}, {
|
|
50
|
-
key: 'empty',
|
|
51
|
-
value: function empty() {
|
|
52
|
-
this.pages = {};
|
|
53
|
-
this.last = null;
|
|
54
|
-
this.swup.log('Cache cleared');
|
|
55
|
-
}
|
|
56
|
-
}, {
|
|
57
|
-
key: 'remove',
|
|
58
|
-
value: function remove(url) {
|
|
59
|
-
delete this.pages[url];
|
|
60
|
-
}
|
|
61
|
-
}]);
|
|
62
|
-
|
|
63
|
-
return Cache;
|
|
64
|
-
}();
|
|
65
|
-
|
|
66
|
-
exports.default = Cache;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _utils = require('../utils');
|
|
8
|
-
|
|
9
|
-
var getAnchorElement = function getAnchorElement(hash) {
|
|
10
|
-
if (!hash) {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
if (hash.charAt(0) === '#') {
|
|
15
|
-
hash = hash.substring(1);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
hash = decodeURIComponent(hash);
|
|
19
|
-
hash = (0, _utils.escapeCssIdentifier)(hash);
|
|
20
|
-
|
|
21
|
-
// https://html.spec.whatwg.org/#find-a-potential-indicated-element
|
|
22
|
-
return (0, _utils.query)('#' + hash) || (0, _utils.query)('a[name=\'' + hash + '\']');
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
exports.default = getAnchorElement;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _utils = require('../utils');
|
|
8
|
-
|
|
9
|
-
var _helpers = require('../helpers');
|
|
10
|
-
|
|
11
|
-
var getAnimationPromises = function getAnimationPromises() {
|
|
12
|
-
var selector = this.options.animationSelector;
|
|
13
|
-
var durationProperty = (0, _helpers.transitionProperty)() + 'Duration';
|
|
14
|
-
var promises = [];
|
|
15
|
-
var animatedElements = (0, _utils.queryAll)(selector, document.body);
|
|
16
|
-
|
|
17
|
-
if (!animatedElements.length) {
|
|
18
|
-
console.warn('[swup] No animated elements found by selector ' + selector);
|
|
19
|
-
return [Promise.resolve()];
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
animatedElements.forEach(function (element) {
|
|
23
|
-
var transitionDuration = window.getComputedStyle(element)[durationProperty];
|
|
24
|
-
// Resolve immediately if no transition defined
|
|
25
|
-
if (!transitionDuration || transitionDuration == '0s') {
|
|
26
|
-
console.warn('[swup] No CSS transition duration defined for element of selector ' + selector);
|
|
27
|
-
promises.push(Promise.resolve());
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
var promise = new Promise(function (resolve) {
|
|
31
|
-
element.addEventListener((0, _helpers.transitionEnd)(), function (event) {
|
|
32
|
-
if (element == event.target) {
|
|
33
|
-
resolve();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
});
|
|
37
|
-
promises.push(promise);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
return promises;
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
exports.default = getAnimationPromises;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _helpers = require('../helpers');
|
|
8
|
-
|
|
9
|
-
var getPageData = function getPageData(request) {
|
|
10
|
-
// this method can be replaced in case other content than html is expected to be received from server
|
|
11
|
-
// this function should always return {title, pageClass, originalContent, blocks, responseURL}
|
|
12
|
-
// in case page has invalid structure - return null
|
|
13
|
-
var html = request.responseText;
|
|
14
|
-
var pageObject = (0, _helpers.getDataFromHtml)(html, this.options.containers);
|
|
15
|
-
|
|
16
|
-
if (pageObject) {
|
|
17
|
-
pageObject.responseURL = request.responseURL ? request.responseURL : window.location.href;
|
|
18
|
-
} else {
|
|
19
|
-
console.warn('[swup] Received page is invalid.');
|
|
20
|
-
return null;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return pageObject;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.default = getPageData;
|
package/lib/modules/loadPage.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
|
|
7
|
-
var _slicedToArray = function () { function sliceIterator(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"]) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } return function (arr, i) { if (Array.isArray(arr)) { return arr; } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i); } else { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } }; }();
|
|
8
|
-
|
|
9
|
-
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; };
|
|
10
|
-
|
|
11
|
-
var _helpers = require('../helpers');
|
|
12
|
-
|
|
13
|
-
var loadPage = function loadPage(data, popstate) {
|
|
14
|
-
var _this = this;
|
|
15
|
-
|
|
16
|
-
// create array for storing animation promises
|
|
17
|
-
var animationPromises = [],
|
|
18
|
-
xhrPromise = void 0;
|
|
19
|
-
var animateOut = function animateOut() {
|
|
20
|
-
_this.triggerEvent('animationOutStart');
|
|
21
|
-
|
|
22
|
-
// handle classes
|
|
23
|
-
document.documentElement.classList.add('is-changing');
|
|
24
|
-
document.documentElement.classList.add('is-leaving');
|
|
25
|
-
document.documentElement.classList.add('is-animating');
|
|
26
|
-
if (popstate) {
|
|
27
|
-
document.documentElement.classList.add('is-popstate');
|
|
28
|
-
}
|
|
29
|
-
document.documentElement.classList.add('to-' + (0, _helpers.classify)(data.url));
|
|
30
|
-
|
|
31
|
-
// animation promise stuff
|
|
32
|
-
animationPromises = _this.getAnimationPromises('out');
|
|
33
|
-
Promise.all(animationPromises).then(function () {
|
|
34
|
-
_this.triggerEvent('animationOutDone');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
// create history record if this is not a popstate call
|
|
38
|
-
if (!popstate) {
|
|
39
|
-
// create pop element with or without anchor
|
|
40
|
-
var state = void 0;
|
|
41
|
-
if (_this.scrollToElement != null) {
|
|
42
|
-
state = data.url + _this.scrollToElement;
|
|
43
|
-
} else {
|
|
44
|
-
state = data.url;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
(0, _helpers.createHistoryRecord)(state);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
this.triggerEvent('transitionStart', popstate);
|
|
52
|
-
|
|
53
|
-
// set transition object
|
|
54
|
-
if (data.customTransition != null) {
|
|
55
|
-
this.updateTransition(window.location.pathname, data.url, data.customTransition);
|
|
56
|
-
document.documentElement.classList.add('to-' + (0, _helpers.classify)(data.customTransition));
|
|
57
|
-
} else {
|
|
58
|
-
this.updateTransition(window.location.pathname, data.url);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// start/skip animation
|
|
62
|
-
if (!popstate || this.options.animateHistoryBrowsing) {
|
|
63
|
-
animateOut();
|
|
64
|
-
} else {
|
|
65
|
-
this.triggerEvent('animationSkipped');
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// start/skip loading of page
|
|
69
|
-
if (this.cache.exists(data.url)) {
|
|
70
|
-
xhrPromise = new Promise(function (resolve) {
|
|
71
|
-
resolve(_this.cache.getPage(data.url));
|
|
72
|
-
});
|
|
73
|
-
this.triggerEvent('pageRetrievedFromCache');
|
|
74
|
-
} else {
|
|
75
|
-
if (!this.preloadPromise || this.preloadPromise.route != data.url) {
|
|
76
|
-
xhrPromise = new Promise(function (resolve, reject) {
|
|
77
|
-
(0, _helpers.fetch)(_extends({}, data, { headers: _this.options.requestHeaders }), function (response) {
|
|
78
|
-
if (response.status === 500) {
|
|
79
|
-
_this.triggerEvent('serverError');
|
|
80
|
-
reject(data.url);
|
|
81
|
-
return;
|
|
82
|
-
} else {
|
|
83
|
-
// get json data
|
|
84
|
-
var page = _this.getPageData(response);
|
|
85
|
-
if (page != null && page.blocks.length > 0) {
|
|
86
|
-
page.url = data.url;
|
|
87
|
-
} else {
|
|
88
|
-
reject(data.url);
|
|
89
|
-
return;
|
|
90
|
-
}
|
|
91
|
-
// render page
|
|
92
|
-
_this.cache.cacheUrl(page);
|
|
93
|
-
_this.triggerEvent('pageLoaded');
|
|
94
|
-
resolve(page);
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
} else {
|
|
99
|
-
xhrPromise = this.preloadPromise;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
// when everything is ready, handle the outcome
|
|
104
|
-
Promise.all([xhrPromise].concat(animationPromises)).then(function (_ref) {
|
|
105
|
-
var _ref2 = _slicedToArray(_ref, 1),
|
|
106
|
-
pageData = _ref2[0];
|
|
107
|
-
|
|
108
|
-
// render page
|
|
109
|
-
_this.renderPage(pageData, popstate);
|
|
110
|
-
_this.preloadPromise = null;
|
|
111
|
-
}).catch(function (errorUrl) {
|
|
112
|
-
// rewrite the skipPopStateHandling function to redirect manually when the history.go is processed
|
|
113
|
-
_this.options.skipPopStateHandling = function () {
|
|
114
|
-
window.location = errorUrl;
|
|
115
|
-
return true;
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
// go back to the actual page were still at
|
|
119
|
-
window.history.go(-1);
|
|
120
|
-
});
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
exports.default = loadPage;
|
package/lib/modules/off.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var off = function off(event, handler) {
|
|
7
|
-
var _this = this;
|
|
8
|
-
|
|
9
|
-
if (event != null) {
|
|
10
|
-
if (handler != null) {
|
|
11
|
-
if (this._handlers[event] && this._handlers[event].filter(function (savedHandler) {
|
|
12
|
-
return savedHandler === handler;
|
|
13
|
-
}).length) {
|
|
14
|
-
var toRemove = this._handlers[event].filter(function (savedHandler) {
|
|
15
|
-
return savedHandler === handler;
|
|
16
|
-
})[0];
|
|
17
|
-
var index = this._handlers[event].indexOf(toRemove);
|
|
18
|
-
if (index > -1) {
|
|
19
|
-
this._handlers[event].splice(index, 1);
|
|
20
|
-
}
|
|
21
|
-
} else {
|
|
22
|
-
console.warn("Handler for event '" + event + "' no found.");
|
|
23
|
-
}
|
|
24
|
-
} else {
|
|
25
|
-
this._handlers[event] = [];
|
|
26
|
-
}
|
|
27
|
-
} else {
|
|
28
|
-
Object.keys(this._handlers).forEach(function (keys) {
|
|
29
|
-
_this._handlers[keys] = [];
|
|
30
|
-
});
|
|
31
|
-
}
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
exports.default = off;
|
package/lib/modules/on.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var on = function on(event, handler) {
|
|
7
|
-
if (this._handlers[event]) {
|
|
8
|
-
this._handlers[event].push(handler);
|
|
9
|
-
} else {
|
|
10
|
-
console.warn("Unsupported event " + event + ".");
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
exports.default = on;
|
package/lib/modules/plugins.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
var use = exports.use = function use(plugin) {
|
|
7
|
-
if (!plugin.isSwupPlugin) {
|
|
8
|
-
console.warn('Not swup plugin instance ' + plugin + '.');
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
this.plugins.push(plugin);
|
|
13
|
-
plugin.swup = this;
|
|
14
|
-
if (typeof plugin._beforeMount === 'function') {
|
|
15
|
-
plugin._beforeMount();
|
|
16
|
-
}
|
|
17
|
-
plugin.mount();
|
|
18
|
-
|
|
19
|
-
return this.plugins;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
var unuse = exports.unuse = function unuse(plugin) {
|
|
23
|
-
var pluginReference = void 0;
|
|
24
|
-
|
|
25
|
-
if (typeof plugin === 'string') {
|
|
26
|
-
pluginReference = this.plugins.find(function (p) {
|
|
27
|
-
return plugin === p.name;
|
|
28
|
-
});
|
|
29
|
-
} else {
|
|
30
|
-
pluginReference = plugin;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if (!pluginReference) {
|
|
34
|
-
console.warn('No such plugin.');
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
pluginReference.unmount();
|
|
39
|
-
|
|
40
|
-
if (typeof pluginReference._afterUnmount === 'function') {
|
|
41
|
-
pluginReference._afterUnmount();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
var index = this.plugins.indexOf(pluginReference);
|
|
45
|
-
this.plugins.splice(index, 1);
|
|
46
|
-
|
|
47
|
-
return this.plugins;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
var findPlugin = exports.findPlugin = function findPlugin(pluginName) {
|
|
51
|
-
return this.plugins.find(function (p) {
|
|
52
|
-
return pluginName === p.name;
|
|
53
|
-
});
|
|
54
|
-
};
|