vanilla-ujs 1.1.1 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gruntfile.js +1 -0
- data/MAINTAINERS +1 -0
- data/README.md +3 -3
- data/lib/assets/javascripts/vanilla-ujs/form.js +4 -4
- data/lib/assets/javascripts/vanilla-ujs/liteajax.js +8 -8
- data/lib/assets/javascripts/vanilla-ujs/method.js +6 -1
- data/lib/vanilla/ujs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a7dbcec9a5433cfc808e5c1cd1cd162ec531978d
|
4
|
+
data.tar.gz: a955726d6b2fd87b043ed29e545d99139920b575
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 479e52886abc52b6ac13ab5b6dec1d3d7569c1c763e83db5c138d210aa74edb498f609ccdb5a1d494672934fd2f6e7e5578e0923a99d46f5113560c6080edeab
|
7
|
+
data.tar.gz: 652d234263eb499059d2bd7fcb96d19bef8893b2431572db4395b45e7961be751f2f35276c70840f3f0aa3c829991f5352c1f4cf7e9c2326cd13940d4333c535
|
data/.gitignore
CHANGED
data/Gruntfile.js
CHANGED
@@ -30,6 +30,7 @@ module.exports = function (grunt) {
|
|
30
30
|
'lib/assets/javascripts/vanilla-ujs/confirm.js',
|
31
31
|
'lib/assets/javascripts/vanilla-ujs/disable.js',
|
32
32
|
'lib/assets/javascripts/vanilla-ujs/csrf.js',
|
33
|
+
'lib/assets/javascripts/vanilla-ujs/form.js',
|
33
34
|
],
|
34
35
|
dest: 'lib/assets/javascripts/vanilla-ujs.js'
|
35
36
|
}
|
data/MAINTAINERS
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Vanilla UJS
|
2
|
-
[![Build Status][travis-img]][travis-link][![Dependency Status](https://gemnasium.com/hauleth/vanilla-ujs.
|
2
|
+
[![Build Status][travis-img]][travis-link][![Dependency Status](https://gemnasium.com/hauleth/vanilla-ujs.svg)](https://gemnasium.com/hauleth/vanilla-ujs)
|
3
3
|
|
4
4
|
It is implementation of Rails [jQuery UJS][jq-ujs] in pure JavaScript.
|
5
5
|
No extra dependencies.
|
@@ -34,7 +34,7 @@ independent from front-end library.
|
|
34
34
|
|
35
35
|
1. Clone repo
|
36
36
|
|
37
|
-
$ git clone git://github.com/hauleth/vanilla-
|
37
|
+
$ git clone git://github.com/hauleth/vanilla-ujs.git
|
38
38
|
$ cd vanilla-js/
|
39
39
|
|
40
40
|
2. Install dependencies
|
@@ -57,6 +57,6 @@ independent from front-end library.
|
|
57
57
|
|
58
58
|
See [`LICENSE`](LICENSE.txt) file.
|
59
59
|
|
60
|
-
[travis-img]: https://travis-ci.org/hauleth/vanilla-ujs.
|
60
|
+
[travis-img]: https://travis-ci.org/hauleth/vanilla-ujs.svg?branch=master
|
61
61
|
[travis-link]: https://travis-ci.org/hauleth/vanilla-ujs
|
62
62
|
[jq-ujs]: https://github.com/rails/jquery-ujs
|
@@ -3,15 +3,15 @@ document.addEventListener('submit', function(event) {
|
|
3
3
|
var form = event.target;
|
4
4
|
|
5
5
|
if (matches.call(form, 'form[data-remote]')) {
|
6
|
-
url = form.action;
|
7
|
-
method = form.method || form.getAttribute('data-method')
|
8
|
-
data = new FormData(form);
|
6
|
+
var url = form.action;
|
7
|
+
var method = (form.method || form.getAttribute('data-method') || 'POST').toUpperCase();
|
8
|
+
var data = new FormData(form);
|
9
9
|
|
10
10
|
if (CSRF.param() && CSRF.token()) {
|
11
11
|
data[CSRF.param()] = CSRF.token();
|
12
12
|
}
|
13
13
|
|
14
|
-
if (LiteAjax.ajax({ url: url, method: method, data: data })){
|
14
|
+
if (LiteAjax.ajax({ url: url, method: method, data: data, target: form })){
|
15
15
|
event.preventDefault();
|
16
16
|
} else {
|
17
17
|
return true;
|
@@ -13,25 +13,25 @@ var LiteAjax = (function () {
|
|
13
13
|
}
|
14
14
|
|
15
15
|
options = options || {};
|
16
|
-
|
16
|
+
|
17
17
|
if(!options.accepts) {
|
18
|
-
options.accepts = 'text/javascript, application/javascript, ' +
|
18
|
+
options.accepts = 'text/javascript, application/javascript, ' +
|
19
19
|
'application/ecmascript, application/x-ecmascript';
|
20
20
|
}
|
21
21
|
|
22
22
|
url = url || options.url || location.href || '';
|
23
23
|
var data = options.data;
|
24
|
-
|
24
|
+
var target = options.target || document;
|
25
25
|
var xhr = new XMLHttpRequest();
|
26
26
|
|
27
27
|
xhr.addEventListener('load', function () {
|
28
|
-
responseType = xhr.getResponseHeader('content-type');
|
28
|
+
var responseType = xhr.getResponseHeader('content-type');
|
29
29
|
if(responseType === 'text/javascript; charset=utf-8') {
|
30
30
|
eval(xhr.response);
|
31
31
|
}
|
32
32
|
|
33
|
-
var event = new CustomEvent('
|
34
|
-
|
33
|
+
var event = new CustomEvent('ajax:complete', {detail: xhr, bubbles: true});
|
34
|
+
target.dispatchEvent(event);
|
35
35
|
});
|
36
36
|
|
37
37
|
if (typeof options.success == 'function')
|
@@ -59,8 +59,8 @@ var LiteAjax = (function () {
|
|
59
59
|
data = JSON.stringify(data);
|
60
60
|
}
|
61
61
|
|
62
|
-
var beforeSend = new CustomEvent('ajax:before', {detail: xhr});
|
63
|
-
|
62
|
+
var beforeSend = new CustomEvent('ajax:before', {detail: xhr, bubbles: true});
|
63
|
+
target.dispatchEvent(beforeSend);
|
64
64
|
xhr.send(data);
|
65
65
|
|
66
66
|
return xhr;
|
@@ -1,6 +1,11 @@
|
|
1
1
|
document.addEventListener('click', function(event) {
|
2
2
|
var element, url, method, data, handler;
|
3
3
|
|
4
|
+
// Only left click allowed. Firefox triggers click event on right click/contextmenu.
|
5
|
+
if (event.button !== 0) {
|
6
|
+
return;
|
7
|
+
}
|
8
|
+
|
4
9
|
element = event.target;
|
5
10
|
|
6
11
|
if (matches.call(element, 'a[data-method]')) {
|
@@ -18,7 +23,7 @@ document.addEventListener('click', function(event) {
|
|
18
23
|
handler = submit;
|
19
24
|
}
|
20
25
|
|
21
|
-
if (handler({ url: url, method: method, data: data })) {
|
26
|
+
if (handler({ url: url, method: method, data: data, target: element })) {
|
22
27
|
event.preventDefault();
|
23
28
|
} else {
|
24
29
|
return true;
|
data/lib/vanilla/ujs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vanilla-ujs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Łukasz Jan Niemier
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2016-
|
13
|
+
date: 2016-07-19 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: railties
|