Skip to content

Commit

Permalink
Merge pull request #8 from anag0/dev-0.2.0
Browse files Browse the repository at this point in the history
0.2.0 Final
  • Loading branch information
ernestmarcinko committed Jun 13, 2023
2 parents 92b2745 + d863823 commit 8df4b4e
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dist/domini-serialize.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/domini-xhttp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/domini.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "domini",
"version": "0.1.2",
"version": "0.2.0",
"description": "Minimalistic DOM manipulation tool",
"main": "dist/domini.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DoMini
# [DoMini](https://dominijs.com) · ![npm](https://img.shields.io/npm/v/domini) ![npm](https://img.shields.io/npm/dy/domini) ![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)

A minimalistic HTML document manipulation and traversal tool. Syntactically indentical to jQuery, but much smaller with only the essential features.

Expand Down
4 changes: 2 additions & 2 deletions src/modules/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ DoMini.fn.serialize = function() {
}
return q.join("&");
};
DoMini.fn.serializeForAjax = function(obj, prefix) {
DoMini.fn.serializeObject = function(obj, prefix) {
let str = [],
p;
for (p in obj) {
if (obj.hasOwnProperty(p)) {
let k = prefix ? prefix + "[" + p + "]" : p,
v = obj[p];
str.push((v !== null && typeof v === "object") ?
DoMini.fn.serializeForAjax(v, k) :
DoMini.fn.serializeObject(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
Expand Down
1 change: 1 addition & 0 deletions src/modules/viewport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import DoMini from "../base";

// Inspired by: https://github.com/zeusdeux/isInViewport
DoMini.fn.inViewPort = function (tolerance, viewport) {
"use strict";
let element = this.get(0), vw, vh;
Expand Down
6 changes: 3 additions & 3 deletions src/modules/xhttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ DoMini.fn.ajax = function(args) {
args.data.fn = fn;
let script = document.createElement('script');
script.type = 'text/javascript';
script.src = args.url + '?' + this.serializeForAjax(args.data);
script.src = args.url + '?' + this.serializeObject(args.data);
script.onload = function(){this.remove();};
document.body.appendChild(script);
} else {
let xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if ( args.success != null ) {
if ( this.readyState == 4 && this.status == 200 ) {
if ( this.readyState == 4 && (this.status >= 200 && this.status < 400) ) {
args.success(this.responseText);
}
}
Expand All @@ -51,7 +51,7 @@ DoMini.fn.ajax = function(args) {
xhttp.setRequestHeader('Content-type', args.contentType);
xhttp.setRequestHeader('Accept', args.accept);

xhttp.send(this.serializeForAjax(args.data));
xhttp.send(this.serializeObject(args.data));
return xhttp;
}
};
Expand Down
29 changes: 28 additions & 1 deletion test/modules/xhttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ QUnit.module("module: xhttp.js tests", function(hooks) {
f.innerHTML = fixture;
});

QUnit.test('xhttp()', function(assert) {
QUnit.test('xhttp() cors', function(assert) {
const done = assert.async();
let data = {
'options': $('form[name=testform]').serialize()
};
// Cors
$.fn.ajax({
"url": "/request",
"method": "POST",
Expand All @@ -20,4 +21,30 @@ QUnit.module("module: xhttp.js tests", function(hooks) {
}
});
});

QUnit.test('xhttp() no-cors', function(assert) {
const done = assert.async();
// No-Cors
DoMini.fn.ajax({
url: 'https://clients1.google.com/complete/search',
cors: 'no-cors',
data: {
q: 'us',
hl: 'en',
nolabels: 't',
client: 'hp',
ds: ''
},
success: function (data) {
if (data[1].length > 0) {
let response = data[1][0][0].replace(/(<([^>]+)>)/ig, "");
response = DoMini('<textarea />').html(response).text();
console.log(response);
assert.notEqual(response, '');
assert.notEqual(response, 'us');
done();
}
}
});
});
});

0 comments on commit 8df4b4e

Please sign in to comment.