Popcorn.xhr = function ( options ) {
++<<<<<<< HEAD
+ if ( ( options.dataType || "" ).toLowerCase() === "jsonp" ) {
++=======
+ if ( options.dataType && options.dataType.toLowerCase() === "jsonp" ) {
++>>>>>>> 742ed140bbafc94a08a0024346c62eeff8407d07
Popcorn.xhr.getJSONP(
options.url,
script = document.createElement("script"),
paramStr = url.split("?")[1],
fired = false,
++<<<<<<< HEAD
+ params, callback;
+
+ script.src = url;
+
+ params = paramStr.split("&");
+
+ callback = params.length ? params[ params.length - 1 ].split("=")[1] : Popcorn.guid("jsonp");
++=======
+ params = [],
+ callback;
+
+ if ( paramStr ) {
+ params = paramStr.split("&");
+ }
+
+
+ callback = params.length ? params[ params.length - 1 ].split("=")[1] : "jsonp";
+
+
+ if ( !paramStr ) {
+ url += "?callback=" + callback;
+ }
+
+ script.src = url;
+
++>>>>>>> 742ed140bbafc94a08a0024346c62eeff8407d07
if ( callback ) {
// define the jsonp success callback globally
head.insertBefore( script, head.firstChild );
++<<<<<<< HEAD
+ }
++=======
+ };
++>>>>>>> 742ed140bbafc94a08a0024346c62eeff8407d07
// Exposes Popcorn to global context
});
-
+ test("dataType: JSON Response", function () {
+
+ var expects = 2,
+ count = 0;
+
+ function plus() {
+ if ( ++count === expects ) {
+ start();
+ }
+ }
+
+ expect(expects);
+
+ stop()
+
+
+ var testObj = { "data": {"lang": "en", "length": 25} };
+
+ Popcorn.xhr({
+ url: 'data/test.js',
+ dataType: "json",
+ success: function( data ) {
+
+ ok(data, "xhr returns data");
+ plus();
+
+
+ ok( QUnit.equiv(data, testObj) , "dataType: 'json', data returns an object of data");
+ plus();
+
+ }
+ });
+
+ });
+
test("JSONP Response", function () {
- var expects = 4,
+ var expects = 6,
count = 0;
function plus() {
plus();
- console.log(data);
-
ok( QUnit.equiv(data, testObj) , "Popcorn.xhr({}) data.json returns an object of data");
plus();
);
-
+ Popcorn.xhr.getJSONP(
+ 'data/jsonp.json',
+
+ function( data ) {
+
+ ok(data, "xhr returns data");
+ plus();
+
+
+
+ ok( QUnit.equiv(data, testObj) , "Popcorn.xhr.getJSONP data.json returns an object of data");
+ plus();
+
+ }
+ );
});
test("XML Response", function () {