From 8ac6b7553aff962ed521ca5b58f378744821ae67 Mon Sep 17 00:00:00 2001 From: Oria Date: Wed, 5 Jul 2017 18:08:28 +0300 Subject: [PATCH 1/3] Add missing signature The signature of passing a settings object instead of URL string was added on jQuery 1.12 but not documented. Added the signature and updated the cache related workarounds and examples to reflect the new signature. The example with loading jquery-color was edited to support caching because browser caching is highly recommended when loading a plugin code. --- entries/jQuery.getScript.xml | 62 +++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/entries/jQuery.getScript.xml b/entries/jQuery.getScript.xml index be884042..08d1eda6 100644 --- a/entries/jQuery.getScript.xml +++ b/entries/jQuery.getScript.xml @@ -1,6 +1,18 @@ jQuery.getScript() + + 1.12 + + A set of key/value pairs that configure the Ajax request. All settings are optional except for url. See jQuery.ajax( settings ) for a complete list of all settings. + + + + + + A callback function that is executed if the request succeeds. + + 1.0 @@ -57,42 +69,40 @@ $( "div.log" ).ajaxError(function( e, jqxhr, settings, exception ) { });

Caching Responses

-

By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. You can override this feature by setting the cache property globally using $.ajaxSetup():

+

By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. + To override this feature you can use the settings object signature as of jQuery 1.12: +


+$.getScript({
+  url: "foo.js",
+  cache: true
+});
+    
+ + You can also override this feature by setting the cache property globally using $.ajaxSetup():

 $.ajaxSetup({
   cache: true
 });
+$.getScript("foo.js");
     
-

Alternatively, you could define a new method that uses the more flexible $.ajax() method.

- - - Define a $.cachedScript() method that allows fetching a cached script: - $.ajax() directly: +

+jQuery.ajax({
+  url: "foo.js",
+  dataType: "script", // this part makes the script run
+  cache: true,
+}).done(function( script, textStatus ) {
   console.log( textStatus );
 });
-]]>
-  
+  
+

+ - Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. + Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. Enable browser caching. Date: Wed, 5 Jul 2017 18:43:17 +0300 Subject: [PATCH 2/3] Add missing signature The signature of passing a settings object instead of URL string was added on jQuery 1.12. Added the signature and updated the workarounds and examples to reflect the new signature. The example of loading jquery-color was edited to support caching because browser caching is highly recommended when loading a plugin code. --- entries/jQuery.getScript.xml | 51 ++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/entries/jQuery.getScript.xml b/entries/jQuery.getScript.xml index 08d1eda6..cca22d4c 100644 --- a/entries/jQuery.getScript.xml +++ b/entries/jQuery.getScript.xml @@ -70,7 +70,7 @@ $( "div.log" ).ajaxError(function( e, jqxhr, settings, exception ) {

Caching Responses

By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. - To override this feature you can use the settings object signature as of jQuery 1.12: + You can override this feature by using a settings object, as of jQuery 1.12:


 $.getScript({
   url: "foo.js",
@@ -78,7 +78,7 @@ $.getScript({
 });
     
- You can also override this feature by setting the cache property globally using $.ajaxSetup(): +

You can also override this feature by setting the cache property globally using $.ajaxSetup():


 $.ajaxSetup({
   cache: true
@@ -86,37 +86,32 @@ $.ajaxSetup({
 $.getScript("foo.js");
     
- You can also use $.ajax() directly: -

-jQuery.ajax({
-  url: "foo.js",
-  dataType: "script", // this part makes the script run
-  cache: true,
-}).done(function( script, textStatus ) {
-  console.log( textStatus );
-});
-  

Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. Enable browser caching. Date: Sat, 10 Feb 2018 20:17:53 +0200 Subject: [PATCH 3/3] JavaScript Style Guide --- entries/jQuery.getScript.xml | 237 ++++++++++++++++++----------------- 1 file changed, 120 insertions(+), 117 deletions(-) diff --git a/entries/jQuery.getScript.xml b/entries/jQuery.getScript.xml index cca22d4c..8a425aa1 100644 --- a/entries/jQuery.getScript.xml +++ b/entries/jQuery.getScript.xml @@ -1,133 +1,136 @@ - jQuery.getScript() - - 1.12 - - A set of key/value pairs that configure the Ajax request. All settings are optional except for url. See jQuery.ajax( settings ) for a complete list of all settings. - - - - - - A callback function that is executed if the request succeeds. - - - - 1.0 - - A string containing the URL to which the request is sent. - - - - - - A callback function that is executed if the request succeeds. - - - Load a JavaScript file from the server using a GET HTTP request, then execute it. - -

This is a shorthand Ajax function, which is equivalent to:

-

+	jQuery.getScript()
+	
+		1.12
+		
+				A set of key/value pairs that configure the Ajax request. All settings are optional except for url. See jQuery.ajax( settings ) for a complete list of all settings.
+		
+		
+			
+			
+			
+			A callback function that is executed if the request succeeds.
+		
+	
+	
+		1.0
+		
+			A string containing the URL to which the request is sent.
+		
+		
+			
+			
+			
+			A callback function that is executed if the request succeeds.
+		
+	
+	Load a JavaScript file from the server using a GET HTTP request, then execute it.
+	
+		

This is a shorthand Ajax function, which is equivalent to:

+

 $.ajax({
-  url: url,
-  dataType: "script",
-  success: success
+	url: url,
+	dataType: "script",
+	success: success
 });
-    
-

The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page.

-

- Success Callback -

-

The callback is fired once the script has been loaded but not necessarily executed.

-

Scripts are included and run by referencing the file name:

-

+		
+

The script is executed in the global context, so it can refer to other variables and use jQuery functions. Included scripts can have some impact on the current page.

+

Success Callback

+

The callback is fired once the script has been loaded but not necessarily executed.

+

Scripts are included and run by referencing the file name:

+

 $.getScript( "ajax/test.js", function( data, textStatus, jqxhr ) {
-  console.log( data ); // Data returned
-  console.log( textStatus ); // Success
-  console.log( jqxhr.status ); // 200
-  console.log( "Load was performed." );
+	console.log( data ); // Data returned
+	console.log( textStatus ); // Success
+	console.log( jqxhr.status ); // 200
+	console.log( "Load was performed." );
 });
-    
-

Handling Errors

-

As of jQuery 1.5, you may use .fail() to account for errors:

-

+		
+

Handling Errors

+

As of jQuery 1.5, you may use .fail() to account for errors:

+

 $.getScript( "ajax/test.js" )
-  .done(function( script, textStatus ) {
-    console.log( textStatus );
-  })
-  .fail(function( jqxhr, settings, exception ) {
-    $( "div.log" ).text( "Triggered ajaxError handler." );
-});
-    
-

Prior to jQuery 1.5, the global .ajaxError() callback event had to be used in order to handle $.getScript() errors:

-

-$( "div.log" ).ajaxError(function( e, jqxhr, settings, exception ) {
-  if ( settings.dataType == "script" ) {
-    $( this ).text( "Triggered ajaxError handler." );
-  }
-});
-    
-

Caching Responses

-

By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. - You can override this feature by using a settings object, as of jQuery 1.12:

-

-$.getScript({
-  url: "foo.js",
-  cache: true
-});
-    
- -

You can also override this feature by setting the cache property globally using $.ajaxSetup():

-

-$.ajaxSetup({
-  cache: true
-});
-$.getScript("foo.js");
-    
- -

-
- - Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. Enable browser caching. -
+

Prior to jQuery 1.5, the global .ajaxError() callback event had to be used in order to handle $.getScript() errors:

+

+$( "div.log" )
+	.ajaxError( function( e, jqxhr, settings, exception ) {
+		if ( settings.dataType === "script" ) {
+			$( this ).text( "Triggered ajaxError handler." );
+		}
+	} );
+		
+

Caching Responses

+

By default, $.getScript() sets the cache setting to false. This appends a timestamped query parameter to the request URL to ensure that the browser downloads the script each time it is requested. + You can override this feature by using a settings object, as of jQuery 1.12:

+

+$.getScript( {
+	url: "foo.js",
+	cache: true
+} );
+	
+ +

You can also override this feature by setting the cache property globally using $.ajaxSetup():

+

+$.ajaxSetup( {
+	cache: true
+} );
+$.getScript( "foo.js" );
+	
+ +

+
+ + Load the official jQuery Color Animation plugin dynamically and bind some color animations to occur once the new functionality is loaded. Enable browser caching. + - » Run
]]> - -
- - - +
+ + +