Permalink
Browse files

Refactor the http/ajax component

  • Loading branch information...
nicksagona committed Feb 28, 2017
1 parent 8a2adf7 commit bd51327549ebe09b559612e3e4b54173e34f4f21
Showing with 662 additions and 591 deletions.
  1. +2 −2 bin/jax.json
  2. +319 −284 build/jax.5.5.0.js
  3. +2 −2 build/jax.5.5.0.min.js
  4. +0 −95 src/ajax.js
  5. +0 −14 src/ajax/get.js
  6. +0 −41 src/ajax/http.js
  7. +0 −14 src/ajax/post.js
  8. +0 −105 src/core.js
  9. +200 −0 src/http.js
  10. +110 −0 src/http/query.js
  11. +29 −34 src/{ajax → http}/response.js
View
@@ -2,8 +2,8 @@
"version" : "5.5.0",
"include" : [
"core.js",
"ajax.js",
"ajax",
"http.js",
"http",
"browser.js",
"cookie.js",
"json.js",
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View

This file was deleted.

Oops, something went wrong.
View
@@ -67,111 +67,6 @@
}
};
/** Function to build a query */
window.jax.buildQuery = function(data) {
if (data.constructor != FormData) {
var query = '';
var chkCount = [];
// Loop through the elements to assemble the query string.
// If it's a form element object
if (data.elements != undefined) {
for (var i = 0; i < data.elements.length; i++) {
if (data.elements[i].value != undefined) {
var name = (data.elements[i].name.indexOf('[') != -1) ?
data.elements[i].name.substring(0, data.elements[i].name.indexOf('[')) : data.elements[i].name;
// If the element is a checkbox or radio element that's checked
if ((data.elements[i].type == 'checkbox') || (data.elements[i].type == 'radio')) {
if (data.elements[i].checked) {
if (chkCount[name] != undefined) {
chkCount[name]++;
} else {
chkCount[name] = 0;
}
if (i != 0) {
query += '&';
}
if (data.elements[i].type == 'checkbox') {
query += encodeURIComponent(name + '[' + chkCount[name] + ']') + '=' +
encodeURIComponent(data.elements[i].value);
} else {
query += encodeURIComponent(name) + '=' + encodeURIComponent(data.elements[i].value);
}
}
// Else, if the element is a multiple select element
} else if ((data.elements[i].type.indexOf('select') != -1) && (data.elements[i].multiple)) {
for (var j = 0; j < data.elements[i].options.length; j++) {
if (data.elements[i].options[j].selected) {
if (chkCount[name] != undefined) {
chkCount[name]++;
} else {
chkCount[name] = 0;
}
if (i != 0) {
query += '&';
}
query += encodeURIComponent(name + '[' + chkCount[name] + ']') + '=' +
encodeURIComponent(data.elements[i].options[j].value);
}
}
// Else a normal element
} else {
if (i != 0) {
query += '&';
}
query += encodeURIComponent(name) + '=' + encodeURIComponent(data.elements[i].value);
}
}
}
// If it's an object
} else if (data.constructor == Object) {
var i = 0;
for (var name in data) {
if (i != 0) {
query += '&';
}
if (data[name].constructor == Array) {
var aryVals = '';
for (var j = 0; j < data[name].length; j++) {
if (j != 0) {
aryVals += '&';
}
aryVals += encodeURIComponent(name + '[' + j + ']') + '=' + encodeURIComponent(data[name][j]);
}
query += aryVals;
} else {
query += encodeURIComponent(name) + '=' + encodeURIComponent(data[name]);
}
i++;
}
// If it's a basic array with a set of arrays with name/value pairs
} else if (data.constructor == Array) {
for (var i = 0; i < data.length; i++) {
if (i != 0) {
query += '&';
}
if (data[i][1].constructor == Array) {
var aryVals = '';
for (var j = 0; j < data[i][1].length; j++) {
if (j != 0) {
aryVals += '&';
}
aryVals += encodeURIComponent(data[i][0] + '[' + j + ']') + '=' + encodeURIComponent(data[i][1][j]);
}
query += aryVals;
} else {
query += encodeURIComponent(data[i][0]) + '=' + encodeURIComponent(data[i][1]);
}
}
}
} else {
query = data;
}
return query;
};
/** Function to return the target identifier of the document's URI */
window.jax.target = function(u) {
var url = (u != null) ? u : location.href;
Oops, something went wrong.

0 comments on commit bd51327

Please sign in to comment.