rytm-webflow 1.1.5 → 2.0.2
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/README.md +0 -1
- package/package.json +1 -2
- package/scripts/aswap/ASwap.js +16 -19
- package/scripts/aswap/ASwapDispatcher.js +139 -106
- package/scripts/aswap/Controller.js +5 -7
- package/scripts/aswap/ControllerImgLoad.js +2 -2
- package/scripts/aswap/View.js +0 -1
- package/scripts/showup/ShowUp.js +17 -4
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rytm-webflow",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "rytm webflow pack - ASwap, ShowUp",
|
|
5
5
|
"main": "scripts/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,7 +18,6 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"gsap": "^3.5.1",
|
|
20
20
|
"imagesloaded": "^4.1.4",
|
|
21
|
-
"jquery": "^3.1.1",
|
|
22
21
|
"scrollmagic": "^2.0.7",
|
|
23
22
|
"scrollmagic-plugin-gsap": "^1.0.4"
|
|
24
23
|
}
|
package/scripts/aswap/ASwap.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import $ from "jquery"
|
|
2
1
|
|
|
3
2
|
import ASwapDispatcher from "./ASwapDispatcher";
|
|
4
3
|
import Events from "./Events";
|
|
@@ -103,7 +102,7 @@ class ASwap {
|
|
|
103
102
|
this.events.onRequestLoad()
|
|
104
103
|
}
|
|
105
104
|
onRequestLoaded(e) {
|
|
106
|
-
this.getControllersFromContainer(e.target
|
|
105
|
+
this.getControllersFromContainer(e.target.freshContent).forEach( (c, index)=> {
|
|
107
106
|
c.onRequestLoaded(e);
|
|
108
107
|
});
|
|
109
108
|
document.documentElement.classList.remove("as-request-loading");
|
|
@@ -113,7 +112,7 @@ class ASwap {
|
|
|
113
112
|
document.documentElement.classList.add('as-hide');
|
|
114
113
|
this.getActiveControlles().forEach( (c, index)=> {
|
|
115
114
|
// if view is not present in fresh content then call controller hide
|
|
116
|
-
if (!c.getViewContainer(e.target
|
|
115
|
+
if (!c.getViewContainer(e.target.freshContent)) {
|
|
117
116
|
c.onViewHide(e);
|
|
118
117
|
}
|
|
119
118
|
});
|
|
@@ -123,34 +122,34 @@ class ASwap {
|
|
|
123
122
|
document.documentElement.classList.remove('as-hide');
|
|
124
123
|
this.getActiveControlles().forEach( (c, index)=> {
|
|
125
124
|
// if view is not present in fresh content then call controller hidden
|
|
126
|
-
if (!c.getViewContainer(e.target
|
|
125
|
+
if (!c.getViewContainer(e.target.freshContent)) {
|
|
127
126
|
c.onViewHidden(e);
|
|
128
127
|
}
|
|
129
128
|
});
|
|
130
129
|
this.events.onViewHidden()
|
|
131
130
|
}
|
|
132
131
|
onViewSwapStart(e) {
|
|
133
|
-
this.getControllersFromContainer(e.target
|
|
132
|
+
this.getControllersFromContainer(e.target.freshContent).forEach( (c, index)=> {
|
|
134
133
|
c.onViewSwapStart(e);
|
|
135
134
|
});
|
|
136
135
|
this.events.onViewSwapStart()
|
|
137
136
|
}
|
|
138
137
|
onViewSwapComplete(e) {
|
|
139
|
-
this.getControllersFromContainer(e.target
|
|
138
|
+
this.getControllersFromContainer(e.target.freshContent).forEach( (c, index)=> {
|
|
140
139
|
c.onViewSwapComplete(e);
|
|
141
140
|
});
|
|
142
141
|
this.events.onViewSwapComplete()
|
|
143
142
|
}
|
|
144
143
|
onViewShow(e) {
|
|
145
144
|
document.documentElement.classList.add('as-show');
|
|
146
|
-
this.getControllersFromContainer(e.target
|
|
145
|
+
this.getControllersFromContainer(e.target.freshContent).forEach( (c, index)=> {
|
|
147
146
|
c.onViewShow(e);
|
|
148
147
|
});
|
|
149
148
|
this.events.onViewShow()
|
|
150
149
|
}
|
|
151
150
|
onViewShown(e) {
|
|
152
151
|
document.documentElement.classList.add('as-show');
|
|
153
|
-
this.getControllersFromContainer(e.target
|
|
152
|
+
this.getControllersFromContainer(e.target.freshContent).forEach( (c, index)=> {
|
|
154
153
|
c.onViewShown(e);
|
|
155
154
|
});
|
|
156
155
|
document.documentElement.classList.remove('as-in-progress');
|
|
@@ -173,22 +172,20 @@ class ASwap {
|
|
|
173
172
|
}
|
|
174
173
|
/**
|
|
175
174
|
* get controllers from container based on view's included in the container
|
|
176
|
-
* @param
|
|
175
|
+
* @param container
|
|
177
176
|
* @returns {Array}
|
|
178
177
|
**/
|
|
179
|
-
getControllersFromContainer(
|
|
178
|
+
getControllersFromContainer(container) {
|
|
180
179
|
let arr = [];
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
}
|
|
187
|
-
let c = this.getController(name, id);
|
|
180
|
+
const list = [...container.querySelectorAll("*[data-as-view]")]
|
|
181
|
+
list.forEach((el, index) => {
|
|
182
|
+
const name = el.dataset.asView
|
|
183
|
+
const id = el.dataset.asId ? el.dataset.asId : name
|
|
184
|
+
const c = this.getController(name, id)
|
|
188
185
|
if (c) {
|
|
189
|
-
arr.push(c)
|
|
186
|
+
arr.push(c)
|
|
190
187
|
}
|
|
191
|
-
})
|
|
188
|
+
})
|
|
192
189
|
return arr;
|
|
193
190
|
}
|
|
194
191
|
/**
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import $ from "jquery"
|
|
2
1
|
import Events from "./Events"
|
|
3
2
|
import EventDispatcher from "./EventDispatcher"
|
|
4
3
|
|
|
@@ -24,7 +23,7 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
24
23
|
this.prevUrl = null;
|
|
25
24
|
this.ajaxStore = [];
|
|
26
25
|
this.asHistory = [];
|
|
27
|
-
this
|
|
26
|
+
this.freshContent = document.querySelector(this.swapSelector);
|
|
28
27
|
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -65,48 +64,61 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
65
64
|
* @param tag {String} the tag name, eg. body
|
|
66
65
|
* @returns {String|Boolean}
|
|
67
66
|
**/
|
|
68
|
-
getTagFromResult(result, tag) {
|
|
67
|
+
getTagFromResult(result, tag, index = 0) {
|
|
69
68
|
let regex = new RegExp('<' + tag + '[^>]*>((.|[\n\r])*)<\/' + tag + '>');
|
|
70
69
|
let body = regex.exec(result);
|
|
71
|
-
if (body) {
|
|
72
|
-
return body[
|
|
70
|
+
if (body && body[index]) {
|
|
71
|
+
return body[index];
|
|
73
72
|
} else {
|
|
74
|
-
this.warning("AS problem - " + tag + " could not be extracted");
|
|
73
|
+
this.warning("AS problem - " + tag + " could not be extracted, index:", idnex);
|
|
75
74
|
return false;
|
|
76
75
|
}
|
|
77
76
|
}
|
|
77
|
+
/**
|
|
78
|
+
* ###
|
|
79
|
+
*/
|
|
80
|
+
getElementFromResult(result, tagName) {
|
|
81
|
+
let htmlStr = this.getTagFromResult(result, tagName, 1)
|
|
82
|
+
let el = document.createElement(tagName)
|
|
83
|
+
el.innerHTML = htmlStr.trim()
|
|
84
|
+
return el
|
|
85
|
+
}
|
|
78
86
|
|
|
79
87
|
/**
|
|
80
88
|
* swap the meta and title tags in document's <head>
|
|
81
89
|
* @param result {String} the ajax request result
|
|
82
90
|
**/
|
|
83
91
|
swapHeadMeta(result) {
|
|
84
|
-
|
|
85
|
-
if (!
|
|
92
|
+
const freshHead = this.getElementFromResult(result, "head")
|
|
93
|
+
if (!freshHead) {
|
|
86
94
|
this.warning("AS problem - head was not found in result");
|
|
87
95
|
return false;
|
|
88
96
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
// swap
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
97
|
+
const list = [...freshHead.querySelectorAll("*")]
|
|
98
|
+
list.forEach((el, index) => {
|
|
99
|
+
// swap if TITLE or META
|
|
100
|
+
switch (el.nodeName.toLowerCase()) {
|
|
101
|
+
case "title":
|
|
102
|
+
document.title = el.innerHTML
|
|
103
|
+
break;
|
|
104
|
+
case "meta":
|
|
105
|
+
const name = el.getAttribute("name")
|
|
106
|
+
const property = el.getAttribute("property")
|
|
107
|
+
const itemprop = el.getAttribute("itemprop")
|
|
108
|
+
const content = el.getAttribute("content")
|
|
109
|
+
// get the meta query string
|
|
110
|
+
let query = 'html head meta'
|
|
111
|
+
query += (name ? '[name="' + name + '"' : '')
|
|
112
|
+
query += (property ? '[property="' + property + '"' : '')
|
|
113
|
+
query += (itemprop ? '[itemprop="' + itemprop + '"' : '')
|
|
114
|
+
let metaEl = document.querySelector(query)
|
|
115
|
+
if (metaEl && content) {
|
|
116
|
+
metaEl.setAttribute("content", content)
|
|
117
|
+
}
|
|
118
|
+
break;
|
|
108
119
|
}
|
|
109
|
-
})
|
|
120
|
+
})
|
|
121
|
+
|
|
110
122
|
}
|
|
111
123
|
/**
|
|
112
124
|
* swap the HTML class names
|
|
@@ -134,8 +146,7 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
134
146
|
}
|
|
135
147
|
let html = document.createElement('html');
|
|
136
148
|
html.innerHTML = body;
|
|
137
|
-
|
|
138
|
-
return $resultBody.find(this.swapSelector);
|
|
149
|
+
return html.querySelector(this.swapSelector)
|
|
139
150
|
}
|
|
140
151
|
|
|
141
152
|
/**
|
|
@@ -144,8 +155,8 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
144
155
|
**/
|
|
145
156
|
handleResult(result) {
|
|
146
157
|
// store fresh content in public variable
|
|
147
|
-
this
|
|
148
|
-
|
|
158
|
+
this.freshContent = this.getFreshContentFromResult(result);
|
|
159
|
+
const swap = document.querySelector(this.swapSelector)
|
|
149
160
|
// dispatch event
|
|
150
161
|
this.dispatch(Events.NAV_REQUEST_LOADED);
|
|
151
162
|
this.dispatch(Events.NAV_VIEW_HIDE);
|
|
@@ -155,17 +166,17 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
155
166
|
this.asAnimTimeout1 = setTimeout(()=> {
|
|
156
167
|
this.dispatch(Events.NAV_VIEW_HIDDEN);
|
|
157
168
|
this.dispatch(Events.NAV_SWAP_START);
|
|
158
|
-
if (this
|
|
159
|
-
|
|
160
|
-
|
|
169
|
+
if (this.freshContent) {
|
|
170
|
+
// swap stage classes
|
|
171
|
+
swap.setAttribute("class", this.freshContent.getAttribute("class"))
|
|
172
|
+
// swap content
|
|
173
|
+
swap.innerHTML = this.freshContent.innerHTML
|
|
161
174
|
}
|
|
162
175
|
// swap head (meta)
|
|
163
176
|
this.swapHeadMeta(result);
|
|
164
177
|
setTimeout(() => {
|
|
165
178
|
this.swapBodyToHtmlClasses(result);
|
|
166
179
|
}, 10)
|
|
167
|
-
|
|
168
|
-
|
|
169
180
|
// scroll up
|
|
170
181
|
if (!this.currentTrigger || !this.currentTrigger.classList.contains(this.noScrollClassName)) {
|
|
171
182
|
this.resetScrollPosition();
|
|
@@ -179,6 +190,7 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
179
190
|
this.dispatch(Events.NAV_VIEW_SHOWN);
|
|
180
191
|
}, this.animationTimeShow);
|
|
181
192
|
}, this.animationTimeHide);
|
|
193
|
+
|
|
182
194
|
}
|
|
183
195
|
/**
|
|
184
196
|
* get current URL
|
|
@@ -242,6 +254,7 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
242
254
|
document.documentElement.style.scrollBehavior = this.defaultDocumentScrollBehavior ? this.defaultDocumentScrollBehavior : 'smooth';
|
|
243
255
|
}, 5)
|
|
244
256
|
}
|
|
257
|
+
|
|
245
258
|
/**
|
|
246
259
|
* Preload URL
|
|
247
260
|
* @param url {String}
|
|
@@ -254,12 +267,15 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
254
267
|
if (result) {
|
|
255
268
|
return false
|
|
256
269
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
this.
|
|
270
|
+
let xhr = new XMLHttpRequest();
|
|
271
|
+
xhr.onreadystatechange = () => {
|
|
272
|
+
if (xhr.readyState === 4) {
|
|
273
|
+
// this.trace('URL was preloaded', url, xhr.responseText)
|
|
274
|
+
this.storeResult(url, xhr.responseText);
|
|
261
275
|
}
|
|
262
|
-
}
|
|
276
|
+
};
|
|
277
|
+
xhr.open('GET', url);
|
|
278
|
+
xhr.send();
|
|
263
279
|
|
|
264
280
|
}
|
|
265
281
|
/**
|
|
@@ -309,22 +325,19 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
309
325
|
loadURL(url, data = {}, method = 'get', useCache = true) {
|
|
310
326
|
// dispatch event
|
|
311
327
|
this.dispatch(Events.NAV_REQUEST_LOAD);
|
|
312
|
-
this.trace("ASwap load: ", url);
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
}
|
|
322
|
-
this.handleResult(result);
|
|
323
|
-
} else {
|
|
324
|
-
this.warning("AS problem - GET", url, "returned no result");
|
|
325
|
-
}
|
|
328
|
+
this.trace("ASwap load: ", url);
|
|
329
|
+
|
|
330
|
+
let xhr = new XMLHttpRequest();
|
|
331
|
+
xhr.onreadystatechange = () => {
|
|
332
|
+
if (xhr.readyState === 4) {
|
|
333
|
+
if (useCache) {
|
|
334
|
+
this.storeResult(url, xhr.responseText);
|
|
335
|
+
}
|
|
336
|
+
this.handleResult(xhr.responseText);
|
|
326
337
|
}
|
|
327
|
-
}
|
|
338
|
+
};
|
|
339
|
+
xhr.open(method, url);
|
|
340
|
+
xhr.send(data);
|
|
328
341
|
}
|
|
329
342
|
/**
|
|
330
343
|
* history pushState (URL)
|
|
@@ -345,7 +358,9 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
345
358
|
* @param e {Event}
|
|
346
359
|
**/
|
|
347
360
|
onHistoryBack(e) {
|
|
361
|
+
e.preventDefault();
|
|
348
362
|
let url = window.location.pathname + window.location.search;
|
|
363
|
+
console.log("HISTORY BACK", url)
|
|
349
364
|
this.openURL(url, true);
|
|
350
365
|
}
|
|
351
366
|
/**
|
|
@@ -357,76 +372,94 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
357
372
|
this.storeResult(url, result);
|
|
358
373
|
this.currentUrl = url;
|
|
359
374
|
}
|
|
360
|
-
isLinkElementValid(
|
|
375
|
+
isLinkElementValid(a) {
|
|
361
376
|
let result = false
|
|
362
|
-
if (
|
|
363
|
-
if (
|
|
377
|
+
if (a) {
|
|
378
|
+
if (!a.classList.contains(this.noSwapClassName) && a.getAttribute("target") != "_blank") {
|
|
364
379
|
result = true
|
|
365
380
|
}
|
|
366
381
|
}
|
|
367
382
|
return result
|
|
368
383
|
}
|
|
369
|
-
isFormElementValid(
|
|
384
|
+
isFormElementValid(f) {
|
|
370
385
|
let result = false
|
|
371
|
-
if (
|
|
372
|
-
if (
|
|
386
|
+
if (f) {
|
|
387
|
+
if (!f.classList.contains(this.noSwapClassName)) {
|
|
373
388
|
result = true
|
|
374
389
|
}
|
|
375
390
|
}
|
|
376
391
|
return result
|
|
377
392
|
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* ### Event handlers ###
|
|
396
|
+
*/
|
|
397
|
+
onDocumentClick(e) {
|
|
398
|
+
if (e.target.tagName !== 'A') {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const a = e.target
|
|
402
|
+
if (this.isLinkElementValid(a) && !e.metaKey & !e.ctrlKey) {
|
|
403
|
+
const useCache = !a.classList.contains(this.noCacheClassName);
|
|
404
|
+
const url = a.getAttribute("href");
|
|
405
|
+
if (url.indexOf('://') < 0) {
|
|
406
|
+
e.preventDefault()
|
|
407
|
+
this.currentTrigger = a
|
|
408
|
+
this.openURL(url, false, useCache);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
onDocumentMouseover(e) {
|
|
414
|
+
if (e.target.tagName !== 'A') {
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const a = e.target
|
|
418
|
+
if (this.isLinkElementValid(a)) {
|
|
419
|
+
const useCache = !a.classList.contains(this.noCacheClassName);
|
|
420
|
+
if (useCache) {
|
|
421
|
+
const url = a.getAttribute("href");
|
|
422
|
+
this.preloadURL(url)
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
onDocumentSubmit(e) {
|
|
427
|
+
e.preventDefault();
|
|
428
|
+
if (e.target.tagName !== 'FORM') {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
const f = e.target
|
|
432
|
+
if (this.isFormElementValid(f)) {
|
|
433
|
+
const useCache = !f.classList.contains(this.noCacheClassName);
|
|
434
|
+
const url = f.getAttribute("action");
|
|
435
|
+
if (url.indexOf('://') < 0) {
|
|
436
|
+
e.preventDefault()
|
|
437
|
+
this.currentTrigger = f
|
|
438
|
+
const method = f.getAttribute('method') ? f.getAttribute('method') : 'get'
|
|
439
|
+
const dataStr = new URLSearchParams(new FormData(f)).toString()
|
|
440
|
+
const requestUrl = method == 'get' ? (url + '?' + dataStr) : url
|
|
441
|
+
this.submit(requestUrl, dataStr, method, false, useCache)
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
}
|
|
378
447
|
/**
|
|
379
448
|
* add event listeners
|
|
380
449
|
**/
|
|
381
450
|
addEventListeners() {
|
|
382
451
|
// catch all a click events
|
|
383
|
-
|
|
384
|
-
let $a = $(e.currentTarget);
|
|
385
|
-
// check black list, target _blank and if ctrl or cmd is not pressed
|
|
386
|
-
if (this.isLinkElementValid($a) && !e.metaKey & !e.ctrlKey) {
|
|
387
|
-
let useCache = !$a.hasClass(this.noCacheClassName);
|
|
388
|
-
let url = $a.attr("href");
|
|
389
|
-
if (url.indexOf('://') < 0) {
|
|
390
|
-
e.preventDefault();
|
|
391
|
-
this.currentTrigger = e.currentTarget
|
|
392
|
-
this.openURL(url, false, useCache);
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
});
|
|
452
|
+
document.addEventListener('click', this.onDocumentClick.bind(this), false)
|
|
396
453
|
// preload on hover
|
|
397
454
|
if (this.preloadOnHover) {
|
|
398
|
-
|
|
399
|
-
let $a = $(e.currentTarget);
|
|
400
|
-
if (this.isLinkElementValid($a)) {
|
|
401
|
-
let useCache = !$a.hasClass(this.noCacheClassName);
|
|
402
|
-
let url = $a.attr("href");
|
|
403
|
-
if (useCache) {
|
|
404
|
-
this.preloadURL(url)
|
|
405
|
-
}
|
|
406
|
-
}
|
|
407
|
-
})
|
|
455
|
+
document.addEventListener('mouseover', this.onDocumentMouseover.bind(this), false)
|
|
408
456
|
}
|
|
409
457
|
// forms?
|
|
410
458
|
if (this.formsEnabled) {
|
|
411
|
-
|
|
412
|
-
let $f = $(e.currentTarget)
|
|
413
|
-
if (this.isFormElementValid($f)) {
|
|
414
|
-
let useCache = !$f.hasClass(this.noCacheClassName)
|
|
415
|
-
let url = $f.attr('action')
|
|
416
|
-
if (url.indexOf('://') < 0) {
|
|
417
|
-
e.preventDefault()
|
|
418
|
-
this.currentTrigger = e.currentTarget
|
|
419
|
-
const data = $f.serialize()
|
|
420
|
-
const method = $f.attr('method') ? $f.attr('method') : 'get'
|
|
421
|
-
const requestUrl = method == 'get' ? (url + '?' + data) : url
|
|
422
|
-
this.submit(requestUrl, data, method, false, useCache)
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
})
|
|
459
|
+
document.addEventListener('submit', this.onDocumentSubmit.bind(this), false)
|
|
427
460
|
}
|
|
428
|
-
//
|
|
429
|
-
|
|
461
|
+
// browser back button
|
|
462
|
+
window.addEventListener('popstate', this.onHistoryBack.bind(this), false)
|
|
430
463
|
}
|
|
431
464
|
|
|
432
465
|
initialDispatch() {
|
|
@@ -487,8 +520,8 @@ class ASwapDispatcher extends EventDispatcher {
|
|
|
487
520
|
* init
|
|
488
521
|
**/
|
|
489
522
|
init() {
|
|
490
|
-
|
|
491
|
-
if (
|
|
523
|
+
const swap = document.querySelector(this.swapSelector)
|
|
524
|
+
if (!swap) {
|
|
492
525
|
this.warning("AS problem - swap container not found!", this.swapSelector);
|
|
493
526
|
return false;
|
|
494
527
|
}
|
|
@@ -29,12 +29,10 @@ class Controller {
|
|
|
29
29
|
return this.active;
|
|
30
30
|
}
|
|
31
31
|
/**
|
|
32
|
-
* find my
|
|
33
|
-
* @param {jQuery} $wrapper - search within this element
|
|
34
|
-
* @retunrs {jQuery|Boolean} $view | false
|
|
32
|
+
* find my view container in wrapper
|
|
35
33
|
**/
|
|
36
|
-
getViewContainer(
|
|
37
|
-
return
|
|
34
|
+
getViewContainer(wrapper) {
|
|
35
|
+
return wrapper.querySelector('*[data-as-id="' + this.id + '"]');
|
|
38
36
|
}
|
|
39
37
|
|
|
40
38
|
getContainerSelector() {
|
|
@@ -72,13 +70,13 @@ class Controller {
|
|
|
72
70
|
**/
|
|
73
71
|
onRequestLoaded(e) {
|
|
74
72
|
if (!this.active && this.view) {
|
|
75
|
-
this.view.prepare(e.target
|
|
73
|
+
this.view.prepare(e.target.freshContent.get(0));
|
|
76
74
|
}
|
|
77
75
|
}
|
|
78
76
|
/**
|
|
79
77
|
* on view hide - animation out / hide start
|
|
80
78
|
* request is loaded and fresh content is ready to init
|
|
81
|
-
* loaded content available <code>e.target
|
|
79
|
+
* loaded content available <code>e.target.freshContent</code>
|
|
82
80
|
* @param {Event} e
|
|
83
81
|
**/
|
|
84
82
|
onViewHide(e) {
|
|
@@ -24,7 +24,7 @@ class ControllerImgLoad extends Controller {
|
|
|
24
24
|
container.classList.add("as-images-loading")
|
|
25
25
|
this.view.loadImagesStart(container);
|
|
26
26
|
}
|
|
27
|
-
imagesLoaded(this.getContainerSelector(),
|
|
27
|
+
imagesLoaded(this.getContainerSelector(), this.loadImagesComplete.bind(this));
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* load images complete
|
|
@@ -44,7 +44,7 @@ class ControllerImgLoad extends Controller {
|
|
|
44
44
|
/**
|
|
45
45
|
* on view hide - animation out / hide start
|
|
46
46
|
* request is loaded and fresh content is ready to init
|
|
47
|
-
* loaded content available <code>e.target
|
|
47
|
+
* loaded content available <code>e.target.freshContent</code>
|
|
48
48
|
* @param {Event} e
|
|
49
49
|
**/
|
|
50
50
|
onViewHide(e) {
|
package/scripts/aswap/View.js
CHANGED
package/scripts/showup/ShowUp.js
CHANGED
|
@@ -24,19 +24,32 @@ class ShowUp {
|
|
|
24
24
|
this.buildParallaxScenes()
|
|
25
25
|
this.addEventListeners()
|
|
26
26
|
}
|
|
27
|
+
/**
|
|
28
|
+
* Class event handlers
|
|
29
|
+
*/
|
|
30
|
+
handleEvent(e) {
|
|
31
|
+
switch (e.type) {
|
|
32
|
+
case 'resize':
|
|
33
|
+
this.onWindowUpdate(e)
|
|
34
|
+
break;
|
|
35
|
+
case 'DOMContentLoaded':
|
|
36
|
+
this.onWindowUpdate(e)
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
27
40
|
/**
|
|
28
41
|
* Add event listeners
|
|
29
42
|
*/
|
|
30
43
|
addEventListeners() {
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
window.addEventListener('resize', this)
|
|
45
|
+
document.addEventListener('DOMContentLoaded', this)
|
|
33
46
|
}
|
|
34
47
|
/**
|
|
35
48
|
* Remove event listeners
|
|
36
49
|
*/
|
|
37
50
|
removeEventListeners() {
|
|
38
|
-
|
|
39
|
-
|
|
51
|
+
window.removeEventListener('resize', this)
|
|
52
|
+
document.removeEventListener('DOMContentLoaded', this)
|
|
40
53
|
}
|
|
41
54
|
onWindowUpdate(e) {
|
|
42
55
|
if (this.scenes.length > 0) {
|