Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.bower.json
bower.json
47 changes: 29 additions & 18 deletions jquery.hive.pollen.js
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@
ajax: {
_options: {
url: "",
headers: "",
data: "",
dataType: "",
success: Pollen.noop, //$.fn,//
Expand All @@ -595,6 +596,7 @@
/**
* $.ajax.post( request ) -> Implemented. Documention incomplete.
* --> request.url -> url to open
* --> request.headers -> hash
* --> request.data -> params
* --> request.success -> success callback
**/
Expand All @@ -609,8 +611,6 @@
_xhr = options.xhr(),
ajaxSuccess = options.success;



if ( !Pollen.evaluate.isStr(options.data) ) {
options.data = Pollen.data.param(options.data);
}
Expand All @@ -633,15 +633,15 @@
_xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}

Pollen.ajax._setHeader(_xhr, options.headers);

_xhr.send( _type == "post" ? options.data : null );
}
},
_confXHR: function(_cxhr, options, json, ajaxSuccess) {

var data, _xjson;

var onreadystatechange = _cxhr.onreadystatechange = function() {

if (_cxhr.readyState == 4) {

_xjson = Pollen.evaluate.isJson(_cxhr.responseText) ? JSON.parse(_cxhr.responseText) : null;
Expand All @@ -655,13 +655,23 @@
}
};

_cxhr.onerror= function(e) {
console.log(e);
};

// scopify the success callback
function success() {
if ( ajaxSuccess ) {
ajaxSuccess.call( _cxhr, data );
}
}

return _cxhr;
},
_setHeader: function(_cxhr, headers) {
for (var key in headers) {
_cxhr.setRequestHeader(key, headers[key]);
}
return _cxhr;
}
},
Expand All @@ -673,27 +683,28 @@
* $.param( arg ) -> String, Derived and Adapted from, similar in behavior to jQuery.param()
**/
param: function( arg ) {
// Adapted from jQuery.param()
var ret = [];

function add( key, value ) {
// If value is a function, invoke it and return its value
value = Pollen.evaluate.isFn(value) ? value() : value;
ret[ ret.length ] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
// referance: http://stackoverflow.com/a/1714899/2287068
serialize = function(obj, prefix) {
var str = [];
for(var p in obj) {
if (obj.hasOwnProperty(p)) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ?
serialize(v, k) :
encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
}
return str.join("&");
}


// TO DO: THIS each() call needs to be updated
Pollen.array.each( arg, function( key, value ) {
add( key, value );
});
query_string = serialize(arg);

// Enforce Thread Identity
if ( arguments.length == 2 && arguments[1] === true ) {
add( "WORKER_ID", Pollen.identity);
query_string += '&WORKER_ID=' + Pollen.identity;
}

return ret.join("&").replace(/%20/g, "+");
return query_string;
},
/**
basic storage, needs A LOT of work
Expand Down
72 changes: 31 additions & 41 deletions test/qunit.hive.pollen.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ function enumeratedEquals(iterable, expected, message) {
}




/*--------------------------------------------------------*/
module("$.func.*");
test("$.noop()", function () {
Expand Down Expand Up @@ -736,55 +734,52 @@ function enumeratedEquals(iterable, expected, message) {


module("$.ajax.*");
//test("$.ajax.get( request )", function () {
//});

var _ajax_sent_a = { "arg1" : "SN", "arg2" : "AFU" },
_ajax_sent_b = { "arg1" : "FU", "arg2" : "BAR" },
_ajax_sent_c, _ajax_sent_d, _ajax_sent_e, _ajax_sent_f;
test("$.ajax.get( request )", function () {

var _ajax_sent_a = { "arg1" : "SN", "arg2" : "AFU" },
_ajax_sent_b = { "arg1" : "FU", "arg2" : "BAR" },
_ajax_sent_c, _ajax_sent_d, _ajax_sent_e, _ajax_sent_f;

var _ajax_data_a,_ajax_data_b,_ajax_data_c, _ajax_data_d, _ajax_data_e, _ajax_data_f;

var _ajax_data_a,_ajax_data_b,_ajax_data_c, _ajax_data_d, _ajax_data_e, _ajax_data_f;

$.ajax.get({
url: 'xhr_echo_request_json.php',
data: $.param( _ajax_sent_a ),
success: function(data) {

_ajax_data_a = data.text;
//equals( JSON.stringify(_ajax_sent_a), data.text, "JSON.stringify(_ajax_sent_a), data.text returns exactly the object sent" );
}
});
$.ajax.get({
url: 'xhr_echo_request_json.php',
data: $.param( _ajax_sent_a ),
success: function(data) {

_ajax_data_a = data.text;
//equals( JSON.stringify(_ajax_sent_a), data.text, "JSON.stringify(_ajax_sent_a), data.text returns exactly the object sent" );
}
});


$.ajax.get({
url: 'xhr_echo_request_json.php',
dataType: 'json',
data: $.param( _ajax_sent_b ),
success: function(data) {
//same( _ajax_sent_b, data, "dataType: 'json' returns exactly the object sent" );

_ajax_data_b = data;
}
});
$.ajax.get({
url: 'xhr_echo_request_json.php',
dataType: 'json',
data: $.param( _ajax_sent_b ),
success: function(data) {
// //same( _ajax_sent_b, data, "dataType: 'json' returns exactly the object sent" );
_ajax_data_b = data;
}
});



asyncTest("$.ajax.get( request )", function() {
setTimeout(function(){
asyncTest("$.ajax.get( request )", function() {
setTimeout(function(){

equals( _ajax_data_a, JSON.stringify(_ajax_sent_a), "JSON.stringify(_ajax_sent_a) ["+JSON.stringify(_ajax_sent_a)+"], data.text returns exactly the object sent" );
same( _ajax_data_b, _ajax_sent_b , "dataType: 'json' returns exactly the object sent" );
equals( _ajax_data_a, JSON.stringify(_ajax_sent_a), "JSON.stringify(_ajax_sent_a) ["+JSON.stringify(_ajax_sent_a)+"], data.text returns exactly the object sent" );
same( _ajax_data_b, _ajax_sent_b , "dataType: 'json' returns exactly the object sent" );

start();
}, 30);
start();
}, 30);
});
});




test("$.ajax.post( request )", function () {

});
Expand Down Expand Up @@ -838,13 +833,8 @@ function enumeratedEquals(iterable, expected, message) {

equals( $.param( _object_a, true ), 'a=5&b=7&c=foo&d=bar&WORKER_ID=0', 'Object to params, added WORKER_ID' );

var params = {foo:"bar", baz:42, quux:"All your base are belong to us"};
equals( $.param(params), "foo=bar&baz=42&quux=All+your+base+are+belong+to+us", "simple" );

///params = {someName: [1, 2, 3], regularThing: "blah" };
///equals( $.param(params), "someName%5B%5D=1&someName%5B%5D=2&someName%5B%5D=3&regularThing=blah", "with array" );


var _object_d = { a: { b: 1, c: 2 }, d: [ 'string', 4, { e: 'test string' } ] };
equals( $.param( _object_d ), "a%5Bb%5D=1&a%5Bc%5D=2&d%5B0%5D=string&d%5B1%5D=4&d%5B2%5D%5Be%5D=test%20string", 'arg contains array and object' );

});

Expand Down