rytm-webflow 2.2.0 → 2.2.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 CHANGED
@@ -149,6 +149,7 @@ RytmWebflow.aswap.init({
149
149
  | ```historyFallback``` | ```true``` | Fallback if browser dosn't support history push state |
150
150
  | ```cacheOn``` | ```true``` | By default all requests are being cached. Set to ```false``` to turn cache off |
151
151
  | ```noCacheClassName``` | ```'no-as-cache'``` | By default all requests are being cached. Links with this class name don't use ajax cache |
152
+ | ```resetScrollOn``` | ```true``` | By default on each view swap the window is scrolled back up. This should be disabled if using ```lenis``` |
152
153
  | ```noScrollClassName``` | ```'no-as-scroll'``` | By default each page transformation is reseting the window scroll. Links with this class don't scroll window back up |
153
154
  | ```noSwapClassName``` | ```'no-as'``` | Links with this class or ```target=_blank``` don't load using ASwap |
154
155
  | ```oldschoolBrowserFallback``` | ```true``` | If set to ```true``` IE 11 or lower is not supported |
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rytm-webflow",
3
- "version": "2.2.0",
3
+ "version": "2.2.2",
4
4
  "description": "rytm webflow pack - ASwap, ShowUp",
5
5
  "main": "scripts/index.js",
6
6
  "scripts": {
@@ -19,6 +19,7 @@ class ASwap {
19
19
  historyFallback: true, // fallback of browser dosn't support history push state
20
20
  cacheOn: true, // use Aswap Cache?
21
21
  noCacheClassName: 'no-as-cache', // links with this class don't use ajax cache
22
+ resetScrollOn: true, // reset scroll position on view swap
22
23
  noScrollClassName: 'no-as-scroll', // links with this class don't scroll window back up
23
24
  noSwapClassName: 'no-as', // links with this class or target=_blank don't use ajax swap
24
25
  oldschoolBrowserFallback: true, // IE11 or lower is not supported
@@ -197,7 +197,7 @@ class ASwapDispatcher extends EventDispatcher {
197
197
  this.swapBodyToHtmlClasses(result);
198
198
  }, 10)
199
199
  // scroll up
200
- if (!this.currentTrigger || !this.currentTrigger.classList.contains(this.noScrollClassName)) {
200
+ if (this.resetScrollOn && (!this.currentTrigger || !this.currentTrigger.classList.contains(this.noScrollClassName))) {
201
201
  this.resetScrollPosition();
202
202
  }
203
203
  // dispatch swap event
@@ -302,15 +302,18 @@ class ASwapDispatcher extends EventDispatcher {
302
302
  */
303
303
  formSubmit(form) {
304
304
  const useCache = !form.classList.contains(this.noCacheClassName);
305
- const url = form.getAttribute("action");
305
+ let url = form.getAttribute("action");
306
306
  if (url.indexOf('://') < 0) {
307
307
  this.currentTrigger = form
308
- const method = form.getAttribute('method') ? form.getAttribute('method') : 'get'
308
+ const method = form.getAttribute('method') ? form.getAttribute('method').toLowerCase() : 'get'
309
309
  const formData = new FormData(form);
310
+ if (method == 'get') {
311
+ // for GET add data string to URL
312
+ const dataStr = new URLSearchParams(formData).toString();
313
+ const dataSep = url.indexOf('?') > -1 ? '&' : '?';
314
+ url = dataStr && method == 'get' ? (url + dataSep + dataStr) : url;
315
+ }
310
316
  this.submit(url, formData, method, false, useCache);
311
- // const dataStr = new URLSearchParams(formData).toString();
312
- // const requestUrl = method == 'get' ? (url + '?' + dataStr) : url;
313
- // this.submit(requestUrl, formData, method, false, useCache);
314
317
  }
315
318
  }
316
319
  /**
@@ -335,9 +338,7 @@ class ASwapDispatcher extends EventDispatcher {
335
338
  this.loadURL(url, formData, method, false);
336
339
  break;
337
340
  default:
338
- // GET
339
- const dataStr = new URLSearchParams(formData).toString();
340
- url = method == 'get' ? (url + '?' + dataStr) : url;
341
+ // GET / PUT / PATCH / DELETE
341
342
  let result = useCache ? this.getStoredResult(url) : null;
342
343
  if (result) {
343
344
  this.handleResult(result);