vanilla-ujs 0.1.1 → 0.1.2

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: 19fc8b7fed4191579e3470edff79f673e1ca50b7
4
- data.tar.gz: 46d027b35b3132dcd45ed13afbfd3e88707e9b40
3
+ metadata.gz: 35391c52899afd088a8cdac42198e3de52d3a520
4
+ data.tar.gz: 770eb30a0399cbb97951c15632ba35490ac6290f
5
5
  SHA512:
6
- metadata.gz: d0467d38e7eb42108bd019429767df979663c14dc529a97e00d73d1283c0ed004bc1d4b67f66e26716722da39413305c7362638e2299f68cc1679544fc731718
7
- data.tar.gz: 279ca95cea0c444d65fd89a899bc21ede487f13792709df9984979cb4b9bed743b2207c0e49705f596e3a3be423874bd7b55a9de57fd6816a61540d7f75ded4d
6
+ metadata.gz: 28b838f0b51d2a7bee8c04cf844b447059e287b64bf3285e0fc9a6547d18e37d171f84c5be994f4cc1efa3afb8fe8175ed586164bd0488ad59a1f824f007a950
7
+ data.tar.gz: 06a9dbfdd0746ee473e67688f6fa4c0cf6f0ff4ddc78fd6cbf497676abf282bb1187a1b157ba5f6b801c69a62e6a3c49d17a12ba6f349370439a4a648f04aa04
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "vanilla-ujs"
5
- s.version = "0.1.1"
5
+ s.version = "0.1.2"
6
6
  s.platform = Gem::Platform::RUBY
7
7
  s.authors = ["Alex Tsokurov", "Łukasz Niemier"]
8
8
  s.email = ["me@ximik.net"]
@@ -3,7 +3,7 @@ document.addEventListener('click', function (event) {
3
3
 
4
4
  element = event.target;
5
5
 
6
- if (matches.call(element, 'a[data-confirm], button[data-confirm]')) {
6
+ if (matches.call(element, 'a[data-confirm], button[data-confirm], input[data-confirm]')) {
7
7
  message = element.getAttribute('data-confirm');
8
8
  if (!confirm(message)) {
9
9
  event.stopPropagation();
@@ -0,0 +1,20 @@
1
+ document.addEventListener('submit', function(event) {
2
+
3
+ var form = event.target;
4
+
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);
9
+
10
+ if (CSRF.param() && CSRF.token()) {
11
+ data[CSRF.param()] = CSRF.token();
12
+ }
13
+
14
+ if (LiteAjax.ajax({ url: url, method: method, data: data })){
15
+ event.preventDefault();
16
+ } else {
17
+ return true;
18
+ }
19
+ }
20
+ });
@@ -3,8 +3,7 @@ var LiteAjax = (function () {
3
3
 
4
4
  LiteAjax.options = {
5
5
  method: 'GET',
6
- url: window.location.href,
7
- async: true,
6
+ url: window.location.href
8
7
  };
9
8
 
10
9
  LiteAjax.ajax = function (url, options) {
@@ -15,12 +14,18 @@ var LiteAjax = (function () {
15
14
 
16
15
  options = options || {};
17
16
  url = url || options.url || location.href || '';
17
+ data = options.data;
18
18
 
19
19
  var xhr;
20
20
 
21
21
  xhr = new XMLHttpRequest();
22
22
 
23
23
  xhr.addEventListener('load', function () {
24
+ responseType = xhr.getResponseHeader('content-type');
25
+ if(responseType === 'text/javascript; charset=utf-8') {
26
+ eval(xhr.response);
27
+ }
28
+
24
29
  var event = new CustomEvent('ajaxComplete', {detail: xhr});
25
30
  document.dispatchEvent(event);
26
31
  });
@@ -41,10 +46,17 @@ var LiteAjax = (function () {
41
46
  });
42
47
  }
43
48
 
44
- xhr.open(options.method || 'GET', url, options.async);
49
+ xhr.open(options.method || 'GET', url);
50
+ xhr.setRequestHeader('X-Requested-With', 'XmlHttpRequest');
51
+
52
+ if(options.json) {
53
+ xhr.setRequestHeader('Content-type', 'application/json');
54
+ data = JSON.stringify(data)
55
+ }
56
+
45
57
  var beforeSend = new CustomEvent('ajax:before', {detail: xhr});
46
58
  document.dispatchEvent(beforeSend);
47
- xhr.send(options.data);
59
+ xhr.send(data);
48
60
 
49
61
  return xhr;
50
62
  };
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanilla-ujs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Tsokurov
8
- - Łukasz Niemier
8
+ - "Łukasz Niemier"
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-10 00:00:00.000000000 Z
12
+ date: 2015-09-21 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: This gem provides Rails UJS features without jQuery library.
15
15
  email:
@@ -24,6 +24,7 @@ files:
24
24
  - vanilla-ujs.gemspec
25
25
  - vendor/assets/javascripts/src/confirm.js
26
26
  - vendor/assets/javascripts/src/csrf.js
27
+ - vendor/assets/javascripts/src/form.js
27
28
  - vendor/assets/javascripts/src/liteajax.js
28
29
  - vendor/assets/javascripts/src/method.js
29
30
  - vendor/assets/javascripts/src/polyfills.js
@@ -38,17 +39,17 @@ require_paths:
38
39
  - lib
39
40
  required_ruby_version: !ruby/object:Gem::Requirement
40
41
  requirements:
41
- - - '>='
42
+ - - ">="
42
43
  - !ruby/object:Gem::Version
43
44
  version: '0'
44
45
  required_rubygems_version: !ruby/object:Gem::Requirement
45
46
  requirements:
46
- - - '>='
47
+ - - ">="
47
48
  - !ruby/object:Gem::Version
48
49
  version: 1.3.6
49
50
  requirements: []
50
51
  rubyforge_project:
51
- rubygems_version: 2.2.2
52
+ rubygems_version: 2.2.5
52
53
  signing_key:
53
54
  specification_version: 4
54
55
  summary: UJS without jQuery dependency