1 | Unobtrusive scripting adapter for jQuery
|
2 | ========================================
|
3 |
|
4 | This unobtrusive scripting support file is developed for the Ruby on Rails framework, but is not strictly tied to any specific backend. You can drop this into any application to:
|
5 |
|
6 | - force confirmation dialogs for various actions;
|
7 | - make non-GET requests from hyperlinks;
|
8 | - make forms or hyperlinks submit data asynchronously with Ajax;
|
9 | - have submit buttons become automatically disabled on form submit to prevent double-clicking.
|
10 |
|
11 | These features are achieved by adding certain ["data" attributes][data] to your HTML markup. In Rails, they are added by the framework's template helpers.
|
12 |
|
13 | Full [documentation is on the wiki][wiki], including the [list of published Ajax events][events].
|
14 |
|
15 | Requirements
|
16 | ------------
|
17 |
|
18 | - [jQuery 1.8.x or higher][jquery];
|
19 | - HTML5 doctype (optional).
|
20 |
|
21 | If you don't use HTML5, adding "data" attributes to your HTML4 or XHTML pages might make them fail [W3C markup validation][validator]. However, this shouldn't create any issues for web browsers or other user agents.
|
22 |
|
23 | Installation using the jquery-rails gem
|
24 | ------------
|
25 |
|
26 | For automated installation in Rails, use the "jquery-rails" gem. Place this in your Gemfile:
|
27 |
|
28 | ```ruby
|
29 | gem 'jquery-rails'
|
30 | ```
|
31 |
|
32 | And run:
|
33 |
|
34 | ```shell
|
35 | $ bundle install
|
36 | ```
|
37 |
|
38 | Require both `jquery` and `jquery_ujs` into your application.js manifest.
|
39 |
|
40 | ```javascript
|
41 | //= require jquery
|
42 | //= require jquery_ujs
|
43 | ```
|
44 |
|
45 | Installation using Bower
|
46 | ------------
|
47 |
|
48 | Run `bower install jquery-ujs --save` to install the jquery-ujs package.
|
49 |
|
50 | Usage
|
51 | ------------
|
52 |
|
53 | Require both `jquery` and `jquery-ujs` into your application.js manifest.
|
54 |
|
55 | ```javascript
|
56 | //= require jquery
|
57 | //= require jquery-ujs
|
58 | ```
|
59 |
|
60 | How to run tests
|
61 | ------------
|
62 |
|
63 | Follow [this wiki](https://github.com/rails/jquery-ujs/wiki/Running-Tests-and-Contributing) to run tests .
|
64 |
|
65 |
|
66 | [data]: http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes "Embedding custom non-visible data with the data-* attributes"
|
67 | [wiki]: https://github.com/rails/jquery-ujs/wiki
|
68 | [events]: https://github.com/rails/jquery-ujs/wiki/ajax
|
69 | [jquery]: http://docs.jquery.com/Downloading_jQuery
|
70 | [validator]: http://validator.w3.org/
|
71 | [csrf]: http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html
|
72 | [adapter]: https://github.com/rails/jquery-ujs/raw/master/src/rails.js
|