https://github.com/boneskull/jquery.preempt
Takes legacy inline JS (i.e. "onclick" and "href='javascript:...'") and creates event handler(s) to be run around the inlined code.
https://github.com/boneskull/jquery.preempt
Last synced: 8 months ago
JSON representation
Takes legacy inline JS (i.e. "onclick" and "href='javascript:...'") and creates event handler(s) to be run around the inlined code.
- Host: GitHub
- URL: https://github.com/boneskull/jquery.preempt
- Owner: boneskull
- License: mit
- Archived: true
- Created: 2014-02-07T08:50:01.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-02-08T05:57:45.000Z (about 11 years ago)
- Last Synced: 2025-05-16T09:14:39.400Z (9 months ago)
- Language: JavaScript
- Homepage: http://boneskull.github.io/jquery.preempt
- Size: 313 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery.preempt
[](https://travis-ci.org/boneskull/jquery.preempt)
[](https://coveralls.io/r/boneskull/jquery.preempt?branch=master)
[](http://gruntjs.com/)
[jQuery](http://jquery.com) plugin to take legacy inline JS (i.e. `onclick`
and `href="javascript:..."`) and create event handlers to be run before or
after the inlined code (or both!).
> #### (Why would I need this?)
> My use case was that I was writing a [GreaseMonkey](https://addons.mozilla.org/en-US/firefox/addon/greasemonkey/)-like [script](https://github.com/boneskull/fb-bugmonkey-markdown) against a page with inline JS and my
jQuery events were not behaving. Works for me; your mileage may vary.
## Installation
Use the [jsDelivr CDN](http://www.jsdelivr.com/#!jquery.preempt).
## Usage
```javascript
// given do something
// or do something else
// Basic usage:
$('button').preempt({
attr: 'onclick',
event: 'click',
}, function doSomethingBeforeSomething() {
// do something else
});
// Restoring the inline JS:
$('button').preempt({
attr: 'onclick',
event: 'click',
restore: true
});
// Fancy usage:
$('button').preempt({
attr: 'onclick',
event: 'click',
before: function executedBeforeInlineJS(event, data) {
// stuff; return false to halt propagation to inline JS
},
after: function exectedAfterInlineJS(event, data) {
// things; return false to prevent the default action and stop propagation
},
// will execute the after() function even if the inlined JS returned false.
forcePropagation: true,
data: {
before: 'some data to be passed to the before() function',
after: 'some data to be passed to the after() function',
}
});
```
## Author
[Christopher Hiller](http://boneskull.github.io)