Skip to content

Commit

Permalink
fix: jsErb headers and submit-event polyfill (#154)
Browse files Browse the repository at this point in the history
* fix: jsErb headers and submit-event polyfill

* fix: clickCaptured

* submit-event fixes

* linting
  • Loading branch information
KonnorRogers authored Oct 17, 2021
1 parent 401b32d commit a9a7ea0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
8 changes: 8 additions & 0 deletions plugins/src/jsErb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ export function JsErb (): Record<string, unknown> {
const name = 'JsErb'
return {
name,
initialize,
connect,
disconnect
}
}

function initialize (): void {
const { script, any } = window.mrujs.mimeTypes
window.mrujs.registerMimeTypes([
{ shortcut: 'any', header: `${script}, ${any}` }
])
}

function connect (): void {
document.addEventListener('ajax:complete', injectScriptIntoHead as EventListener)
}
Expand Down
16 changes: 9 additions & 7 deletions src/polyfills/submit-event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,21 @@ function clickCaptured (event: Event): void {
}

(function () {
// Polyfill has already been run, do not pass go.
if ('submitter' in Event.prototype) return

let prototype = Event.prototype

// Safari 15 has a bug with submitters, this is a check for that.
const isSafari = navigator.vendor.includes('Apple Computer')

// No need to continue, polyfill not needed.
if ('SubmitEvent' in window && !isSafari) return
if ('SubmitEvent' in window) {
// No need to continue, polyfill not needed. Safari 15 has a bug with submitters.
if (!isSafari) return

// We have to attach to the SubmitEvent prototype in Safari instead of Event prototype.
if (isSafari) prototype = window.SubmitEvent.prototype
// We have to attach to the SubmitEvent prototype in Safari instead of Event prototype.
prototype = window.SubmitEvent.prototype
}

// Polyfill has already been run, do not pass go.
if ('submitter' in prototype) return

addEventListener('click', clickCaptured, true)

Expand Down

0 comments on commit a9a7ea0

Please sign in to comment.