From 08d967adf2b753800fd3700146e845ffaeeeeb67 Mon Sep 17 00:00:00 2001 From: basos9 Date: Fri, 10 Aug 2012 16:42:22 +0300 Subject: [PATCH 01/15] MOD remove throwError, always throw cb syntax errors (rebased) ADD tests for throwError cb --- src/jquery.jsonp.js | 9 ++------- test/unit.js | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index 5414f64..3f93fdb 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -22,13 +22,8 @@ } // Call if defined - function callIfDefined( method , object , parameters , returnFlag ) { - try { - returnFlag = method && method.apply( object.context || object , parameters ); - } catch( _ ) { - returnFlag = !1; - } - return returnFlag; + function callIfDefined( method , object , parameters ) { + return method && method.apply && method.apply( object.context || object , parameters ); } // Give joining character given url diff --git a/test/unit.js b/test/unit.js index c0b6c30..170f878 100644 --- a/test/unit.js +++ b/test/unit.js @@ -96,3 +96,26 @@ test( "stress test", function() { }); } }); + + +test( "callback error", function() { + expect(2); + + $.jsonp({ + url: "http://gdata.youtube.com/feeds/api/users/julianaubourg?callback=?", + cache: true, + success: function() { + try { + return eval("var j = 7 + // syntax error"); + } + catch(e) { + ok( true, "Syntax error thrown"); + } + }, + complete: function() { + start(); + } + }); + stop(); + ok(true, "done"); // to resume tests +}); From c13b9227c2dfabbf880e5b1ca66e914593c43d34 Mon Sep 17 00:00:00 2001 From: basos9 Date: Wed, 8 Aug 2012 20:08:40 +0300 Subject: [PATCH 02/15] MOD success callback to return xObjects as 3rd arg Support fot custom data storage --- src/jquery.jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index 5414f64..fb3da5d 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -172,7 +172,7 @@ // Apply the data filter if provided dataFilter && ( json = dataFilter.apply( xOptions , [ json ] ) ); // Call success then complete - callIfDefined( successCallback , xOptions , [ json , STR_SUCCESS ] ); + callIfDefined( successCallback , xOptions , [ json , STR_SUCCESS, xOptions ] ); callIfDefined( completeCallback , xOptions , [ xOptions , STR_SUCCESS ] ); } From 5e2b265e5871b43661191c91b0bc75f287a536a0 Mon Sep 17 00:00:00 2001 From: basos9 Date: Tue, 21 Aug 2012 14:37:45 +0300 Subject: [PATCH 03/15] DOC success cb api --- doc/API.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/API.md b/doc/API.md index 80bc3f0..bb68e98 100644 --- a/doc/API.md +++ b/doc/API.md @@ -125,10 +125,10 @@ Lifetime of this cache is page-based which means it gets erased at each page rel #### success - `function` (`undefined`) -A function to be called if the request succeeds. The function gets passed two arguments: The JSON object returned from the server and a string describing the status (always `"success"`). +A function to be called if the request succeeds. The function gets passed three arguments: The JSON object returned from the server, a string describing the status (always `"success"`) and the `xOptions` object. ```js -function (json, textStatus) { +function (json, textStatus, xOptions) { this; // the xOptions object or xOptions.context if provided } ``` @@ -155,4 +155,4 @@ Setup global settings for JSONP requests. ### Options -See $.jsonp for a description of all available options. \ No newline at end of file +See $.jsonp for a description of all available options. From 5ce732186d46b0f3f0c5fccead4ebd3ea16a099e Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 14:00:36 +0200 Subject: [PATCH 04/15] And IE10 requires sniffing too. Thank you for all those years of fun, Internet Explorer! --- src/jquery.jsonp.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index 5414f64..20a016a 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -87,7 +87,10 @@ }, // opera demands sniffing :/ - opera = win.opera; + opera = win.opera, + + // IE < 10 + oldIE = !!$( "
" ).html( "" ).find("i").length; // ###################### MAIN FUNCTION ## function jsonp( xOptions ) { @@ -225,8 +228,7 @@ ; // Internet Explorer: event/htmlFor trick - if ( STR_ON_READY_STATE_CHANGE in script ) { - + if ( oldIE ) { script.htmlFor = script.id; script.event = STR_ON_CLICK; } From 41583486cde277e990a61e6017324aca456ae405 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 14:00:55 +0200 Subject: [PATCH 05/15] Less stupid flag creation. --- test/unit.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit.js b/test/unit.js index c0b6c30..546382a 100644 --- a/test/unit.js +++ b/test/unit.js @@ -1,6 +1,6 @@ module( "main", { teardown: moduleTeardown } ); -var hasDeferred = $.Deferred ? 1 : 0; +var hasDeferred = !!$.Deferred; function testJSONP( name, outcome, options ) { test( name, function() { From 1d40327630b0d8c6ac947d271e155984df73d39a Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 14:08:16 +0200 Subject: [PATCH 06/15] Minor spacing fix. --- src/jquery.jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index c19bef7..a6b4f3d 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -144,7 +144,7 @@ }; // Call beforeSend if provided (early abort if false returned) - if ( callIfDefined( xOptions.beforeSend, xOptions , [ xOptions ] ) === !1 || done ) { + if ( callIfDefined( xOptions.beforeSend , xOptions , [ xOptions ] ) === !1 || done ) { return xOptions; } From fd87b596dbf4a7f5815ed7c0297bf521eae643fc Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 15:10:47 +0200 Subject: [PATCH 07/15] Adds proper unit test for exceptions thrown from within a callback. --- test/unit.js | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/test/unit.js b/test/unit.js index 22153f3..273bc25 100644 --- a/test/unit.js +++ b/test/unit.js @@ -44,7 +44,7 @@ testJSONP( "error (HTTP Code)", "error", { } }); -if ( window.opera && window.opera.version() < 11.60 ) { +if ( !window.opera || window.opera.version() < 11.60 ) { testJSONP( "error (Syntax Error)", "error", { expect: window.opera ? 0 : 1, url: "data/syntax-error.js", @@ -61,6 +61,31 @@ if ( window.opera && window.opera.version() < 11.60 ) { }); } +if ( !window.opera ) { + test( "error (Exception)", function() { + stop(); + expect( 2 ); + $.jsonp({ + url: "http://gdata.youtube.com/feeds/api/users/julianaubourg?callback=?", + beforeSend: function() { + var oldOnError = window.onerror; + window.onerror = function( flag ) { + ok( flag !== undefined, "Exception Thrown" ); + window.onerror = oldOnError; + start(); + }; + }, + success: function() { + ok( true, "success" ); + throw "an exception"; + }, + complete: function() { + window.onerror(); + } + }); + }); +} + testJSONP( "error (callback not called)", "error", { expect: 1, url: "data/no-callback.js", @@ -96,26 +121,3 @@ test( "stress test", function() { }); } }); - - -test( "callback error", function() { - expect(2); - - $.jsonp({ - url: "http://gdata.youtube.com/feeds/api/users/julianaubourg?callback=?", - cache: true, - success: function() { - try { - return eval("var j = 7 + // syntax error"); - } - catch(e) { - ok( true, "Syntax error thrown"); - } - }, - complete: function() { - start(); - } - }); - stop(); - ok(true, "done"); // to resume tests -}); From 3aa6ba958aeac4f25fba074ba5eb44f15f0c6886 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 15:12:46 +0200 Subject: [PATCH 08/15] Updates version to 2.4.0. --- src/jquery.jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index 33b3c4e..7400751 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -1,5 +1,5 @@ /* - * jQuery JSONP Core Plugin 2.3.1 (2012-05-16) + * jQuery JSONP Core Plugin 2.4.0 (2012-08-21) * * https://github.com/jaubourg/jquery-jsonp * From 623c4996b665af9ebb41ec6abc5e6232fd2cb98a Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 15:13:12 +0200 Subject: [PATCH 09/15] Makes it clear the xOptions object is only accessible in the arguments of the success callbacks as of 2.4.0. --- doc/API.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/API.md b/doc/API.md index bb68e98..2c25eee 100644 --- a/doc/API.md +++ b/doc/API.md @@ -125,7 +125,7 @@ Lifetime of this cache is page-based which means it gets erased at each page rel #### success - `function` (`undefined`) -A function to be called if the request succeeds. The function gets passed three arguments: The JSON object returned from the server, a string describing the status (always `"success"`) and the `xOptions` object. +A function to be called if the request succeeds. The function gets passed three arguments: The JSON object returned from the server, a string describing the status (always `"success"`) and, *_as of version 2.4.0_* the `xOptions` object. ```js function (json, textStatus, xOptions) { From 09b2e0a6d64604eae6fe85303b4c23a7bf7a5800 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Tue, 21 Aug 2012 15:18:54 +0200 Subject: [PATCH 10/15] Removes unnecessary test for apply, if it's not a function, it'll break and that's fine. --- src/jquery.jsonp.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.jsonp.js b/src/jquery.jsonp.js index 7400751..2abeef7 100644 --- a/src/jquery.jsonp.js +++ b/src/jquery.jsonp.js @@ -23,7 +23,7 @@ // Call if defined function callIfDefined( method , object , parameters ) { - return method && method.apply && method.apply( object.context || object , parameters ); + return method && method.apply( object.context || object , parameters ); } // Give joining character given url From cce6ae5fdd82362b274f7576eb96702f441c33c5 Mon Sep 17 00:00:00 2001 From: jaubourg Date: Wed, 24 Oct 2012 00:56:31 +0200 Subject: [PATCH 11/15] adds licensing information. Fixes #17 --- MIT-LICENSE.txt | 20 ++++++++++++++++++++ README.md | 4 ++++ 2 files changed, 24 insertions(+) create mode 100644 MIT-LICENSE.txt diff --git a/MIT-LICENSE.txt b/MIT-LICENSE.txt new file mode 100644 index 0000000..b4943b0 --- /dev/null +++ b/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright 2012 Julian Aubourg + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md index 3b769fb..aebaac6 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ jQuery-JSONP is a compact (1.8kB minified), yet feature-packed, alternative solution to jQuery's implementation of JSONP. +## Licensing + +jQuery-JSONP is released under the [MIT license](/jaubourg/jquery-jsonp/blob/master/MIT-LICENSE.txt). + ## Download You can download jQuery-JSONP [here](/jaubourg/jquery-jsonp/downloads) (full text and minified versions available). From 830397ee5495f52134d46a531c70550a695cfdf0 Mon Sep 17 00:00:00 2001 From: Julian Aubourg Date: Tue, 19 Feb 2013 16:44:48 +0100 Subject: [PATCH 12/15] Fix doc links Seems like github no longer handles urls with a leading slash properly. Fixes #26. --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aebaac6..be70ad9 100644 --- a/README.md +++ b/README.md @@ -37,5 +37,5 @@ jQuery-JSONP has also been tested with jQuery 1.3.x up to 1.7.x ## Documentation -* [API Documentation](/jaubourg/jquery-jsonp/blob/master/doc/API.md) -* [Tips & Tricks](/jaubourg/jquery-jsonp/blob/master/doc/TipsAndTricks.md) +* [API Documentation](https://github.com/jaubourg/jquery-jsonp/blob/master/doc/API.md) +* [Tips & Tricks](https://github.com/jaubourg/jquery-jsonp/blob/master/doc/TipsAndTricks.md) From c62ffea9f6dab7a9ec0f9934867bdafa6795bc1e Mon Sep 17 00:00:00 2001 From: chandranshu12 Date: Thu, 28 Feb 2013 14:32:26 +0530 Subject: [PATCH 13/15] Update README.md Fixes the links to the License and Download pages in the README --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index be70ad9..6fddaa8 100644 --- a/README.md +++ b/README.md @@ -4,11 +4,11 @@ jQuery-JSONP is a compact (1.8kB minified), yet feature-packed, alternative solu ## Licensing -jQuery-JSONP is released under the [MIT license](/jaubourg/jquery-jsonp/blob/master/MIT-LICENSE.txt). +jQuery-JSONP is released under the [MIT license](https://github.com/jaubourg/jquery-jsonp/blob/master/MIT-LICENSE.txt). ## Download -You can download jQuery-JSONP [here](/jaubourg/jquery-jsonp/downloads) (full text and minified versions available). +You can download jQuery-JSONP [here](https://github.com/jaubourg/jquery-jsonp/downloads) (full text and minified versions available). ## Features From 65dec63177f16b8bd7f09b2e065380b1588b3b2f Mon Sep 17 00:00:00 2001 From: LboAnn Date: Mon, 23 Jan 2017 21:56:23 +0100 Subject: [PATCH 14/15] add CDNJS version badge in README.md This badge will show the library version on CDNJS! --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 6fddaa8..4ce22fc 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # jQuery-JSONP +[![CDNJS](https://img.shields.io/cdnjs/v/jQuery-JSONP.svg)](https://cdnjs.com/libraries/jQuery-JSONP) + jQuery-JSONP is a compact (1.8kB minified), yet feature-packed, alternative solution to jQuery's implementation of JSONP. ## Licensing From 9175d2cdd12fcf4b6567eab63448b3578cecefbe Mon Sep 17 00:00:00 2001 From: Eugene Fidelin Date: Thu, 28 Jan 2016 15:40:31 +0100 Subject: [PATCH 15/15] Add package.json --- package.json | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 package.json diff --git a/package.json b/package.json new file mode 100644 index 0000000..d59c727 --- /dev/null +++ b/package.json @@ -0,0 +1,27 @@ +{ + "name": "jquery-jsonp", + "version": "2.4.0", + "description": "Alternative solution to jQuery's implementation of JSONP", + "main": "src/jquery.jsonp.js", + "directories": { + "doc": "doc", + "test": "test" + }, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "https://github.com/jaubourg/jquery-jsonp.git" + }, + "keywords": [ + "JSONP", + "jQuery" + ], + "author": "Julian Aubourg", + "license": "MIT", + "bugs": { + "url": "https://github.com/jaubourg/jquery-jsonp/issues" + }, + "homepage": "https://github.com/jaubourg/jquery-jsonp" +}