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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d9a42bc793b3f8bbf22a7009351f62644d6133c
4
- data.tar.gz: a91e191b16e207d9d9fa8f538c74e1ab0042e5dc
3
+ metadata.gz: a7dbcec9a5433cfc808e5c1cd1cd162ec531978d
4
+ data.tar.gz: a955726d6b2fd87b043ed29e545d99139920b575
5
5
  SHA512:
6
- metadata.gz: d33b95e92d7cb81258343a50dfd33dbcd79d9b008a8d070e49ce476a7b38d111cd66b78db1690a414d51a57f82e7685520aadbfdbfe8d4e28bc603bd3bca87c8
7
- data.tar.gz: 1623faae8e29cd06082d9f1a2ce2dbf800a0ecdac8cf993f8cdf3e89a5d39f4f550bda3b51977160038b843b4e04ff7dfa7ab8c5525cd0f88d72a357c95cdc21
6
+ metadata.gz: 479e52886abc52b6ac13ab5b6dec1d3d7569c1c763e83db5c138d210aa74edb498f609ccdb5a1d494672934fd2f6e7e5578e0923a99d46f5113560c6080edeab
7
+ data.tar.gz: 652d234263eb499059d2bd7fcb96d19bef8893b2431572db4395b45e7961be751f2f35276c70840f3f0aa3c829991f5352c1f4cf7e9c2326cd13940d4333c535
data/.gitignore CHANGED
@@ -8,3 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /node_modules
11
+ /*.gem
@@ -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
  }
@@ -1 +1,2 @@
1
1
  Łukasz Jan Niemier <lukasz@niemier.pl> (@hauleth)
2
+ Alex Tsokurov <me@ximik.net> (@Ximik)
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.png)](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-js.git
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.png?branch=master
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').toUpperCase() || 'POST';
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('ajaxComplete', {detail: xhr});
34
- document.dispatchEvent(event);
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
- document.dispatchEvent(beforeSend);
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;
@@ -1,5 +1,5 @@
1
1
  module Vanilla
2
2
  module Ujs
3
- VERSION = '1.1.1'
3
+ VERSION = '1.2.0'.freeze
4
4
  end
5
5
  end
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.1.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-03-28 00:00:00.000000000 Z
13
+ date: 2016-07-19 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties