Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/konnorrogers/mrujs
Browse files Browse the repository at this point in the history
  • Loading branch information
KonnorRogers committed Aug 12, 2024
2 parents 24f5abf + 7aea28b commit be2f022
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ cd mrujs
2. Install packages

```bash
yarn install
pnpm install
```

### View Dev Server

```bash
yarn start
pnpm run start
```

### Run tests

```bash
yarn test
pnpm test
```

## Rails
Expand Down Expand Up @@ -65,5 +65,5 @@ Docs are located in `/docs` and use Bridgetown + Netlify.

To start the docs server do the following:

`cd docs && yarn install && bundle install && yarn start`
`cd docs && bundle install && bin/bridgetown start`

5 changes: 4 additions & 1 deletion src/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AJAX_EVENTS, dispatch } from './utils/events'
import { EventQueryInterface, MrujsPluginInterface } from '../types'
import { addListeners, removeListeners, attachObserverCallback } from './utils/dom'
import { MethodSubmission } from './methodSubmission'
import { isInsignificantClick } from './utils/misc'

/**
* Handles `data-method="method"` submissions.
Expand Down Expand Up @@ -46,9 +47,11 @@ export function Method (): MrujsPluginInterface {
* // Implemented!
* <a href="/users/5" data-method="delete" rel="nofollow">Delete</a>
*/
export function handleMethod (event: Event): void {
export function handleMethod (event: MouseEvent | Event): void {
const element = event.currentTarget as HTMLElement

// Make sure we dont fire on ctrl clicks.
if (event instanceof MouseEvent && isInsignificantClick(event)) { return }
if (element.dataset.remote === 'false') return
if (element.dataset.method == null && element.dataset.remote !== 'true') return

Expand Down
3 changes: 3 additions & 0 deletions src/utils/misc.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { stopEverything } from '../utils/events'
import { $ } from './dom'

/**
* Any click that we shouldn't handle.
*/
export function isInsignificantClick (event: MouseEvent): boolean {
return (
((event.target != null) && (event.target as HTMLElement).isContentEditable) ||
Expand Down

0 comments on commit be2f022

Please sign in to comment.