dijon 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dad0ec75b2183d45c4f5480e5417f487b511ed46
4
- data.tar.gz: 510329f64683eb90816c05e42d07055e5e6ea402
3
+ metadata.gz: 7452b0992a592f644a87ad6808f200c87b4f5a9a
4
+ data.tar.gz: a304396ad9083e41f100fa7c0b14e7d8e0435467
5
5
  SHA512:
6
- metadata.gz: 279bd5607a694476cd919a1a6f9966c8f607e9f15e9a1e7996e9555a1658079a866a83803b5267ba5a13f089a1e847b9e987b06e7c884fcaab5e6dd3ac9b27f1
7
- data.tar.gz: 4a0592fb65594a48b0338b703a5e2246d42e139702500c2561db04a7c6dc43d157cdfc924c0000a37582e977e703b554af83dd74d496735d58efd6ed01ed1a4b
6
+ metadata.gz: 2129f91ba2d027fb8c54e5940d26e3a8c29f923062e23f77f5af3740ca35ea9407ef1c2607f74d9a87de385614d30eddbeaeaea577c759853c3cd880caa29c29
7
+ data.tar.gz: 08b090d60f8f8bde4ebf6144383303dc0511c66b393d7a0b1c344c0bb4f5f3bc01b1b3e851e321739849967deaddf58267cdad144e97a96ca235e2b30686ed8d
data/README.md CHANGED
@@ -4,11 +4,11 @@ dijon.js
4
4
  Simple performance-focused Javascript DOM extensions and utilities. For those times when jQuery is too much.
5
5
 
6
6
  ### Browser Support
7
- Chrome 38+
8
- Firefox 33+
9
- Internet Explorer 10+
10
- Opera 25+
11
- Safari 8+
7
+ Chrome 38+
8
+ Firefox 33+
9
+ Internet Explorer 11+
10
+ Opera 25+
11
+ Safari 8+
12
12
 
13
13
  ### Helper Functions
14
14
  ```javascript
@@ -36,3 +36,8 @@ Element.prev() // returns previous sibling or null
36
36
  Element.siblings() // returns NodeList of siblings excluding self
37
37
  Element.index() // returns index of element in its parent container
38
38
  ```
39
+
40
+ ### AJAX Functions
41
+ ```javascript
42
+ ajax(method, url, data, callback) // sends an XMLHttpRequest with the data urlencoded for GET requests or serialized into JSON otherwise
43
+ ```
@@ -1,5 +1,5 @@
1
1
  module Dijon
2
2
  module Rails
3
- VERSION = "0.0.1"
3
+ VERSION = "0.0.2"
4
4
  end
5
5
  end
@@ -1,20 +1,26 @@
1
- /* dijon.js ~ created by Dylan Waits ~ https://github.com/waits/dijon ~ updated 2015-04-1 */
1
+ /* dijon.js ~ created by Dylan Waits ~ https://github.com/waits/dijon ~ updated 2015-04-2 */
2
2
 
3
3
  function ajax(method, url, data, callback) {
4
+ method = method.toUpperCase();
4
5
  var request = new XMLHttpRequest();
5
- var fdata = '';
6
- if (data)
7
- for (var p in data) fdata += p + '=' + encodeURIComponent(data[p]) + '&';
8
- if (method == 'get') {
9
- url += '?' + fdata;
10
- fdata = null;
6
+ if (data) {
7
+ if (method == 'get' && data) {
8
+ url += '?';
9
+ for (var p in data) url += p + '=' + encodeURIComponent(data[p]) + '&';
10
+ }
11
+ else {
12
+ data = JSON.stringify(data);
13
+ }
11
14
  }
12
15
  request.open(method, url, true);
13
- request.onload = function() {callback.call(this);};
14
- request.onerror = function() {};
15
- if (method != 'get' && method != 'delete')
16
- request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
17
- request.send(fdata);
16
+ if (callback) request.onload = function() {callback.call(this);};
17
+ if (method == 'get' || method == 'delete' || !data) {
18
+ request.send();
19
+ }
20
+ else {
21
+ request.setRequestHeader("Content-Type", "application/json");
22
+ request.send(data);
23
+ }
18
24
  }
19
25
  function get(id) {return document.getElementById(id) || document.createDocumentFragment().childNodes;}
20
26
  function getClass(name) {return document.getElementsByClassName(name);}
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dijon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Waits