Skip to content

Commit 4e5f859

Browse files
bobholtajpiano
authored andcommitted
minor fixes in previous codestyle commit and style code-organization examples
1 parent 12437fc commit 4e5f859

File tree

6 files changed

+299
-206
lines changed

6 files changed

+299
-206
lines changed

page/ajax/ajax-and-forms.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,16 +53,16 @@ With that being said, let's jump on in to some examples! First, we'll see how ea
5353
// Using validation to check for the presence of an input
5454
$("#form").submit(function( e ) {
5555
56-
if ( $(".required").val().length === 0 ) { // if .required's value's length is zero
56+
if ( $(".required").val().length === 0 ) { // if .required's value's length is zero
5757
58-
// usually show some kind of error message here
59-
return false; // this prevents the form from submitting
58+
// usually show some kind of error message here
59+
return false; // this prevents the form from submitting
6060
61-
} else {
61+
} else {
6262
63-
// run $.ajax here
63+
// run $.ajax here
6464
65-
}
65+
}
6666
6767
});
6868
```
@@ -73,19 +73,19 @@ Let's see how easy it is to check for invalid characters in a username:
7373
// Validate a phone number field
7474
$("#form").submit(function( e ) {
7575
76-
var inputtedPhoneNumber = $("#phone").val();
76+
var inputtedPhoneNumber = $("#phone").val();
7777
var phoneNumberRegex = ^\d*$/; // match only numbers
7878
79-
if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex
79+
if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex
8080
81-
// usually show some kind of error message ere
82-
return false; // prevent the form from submitting
81+
// usually show some kind of error message ere
82+
return false; // prevent the form from submitting
8383
84-
} else {
84+
} else {
8585
86-
// run $.ajax here
86+
// run $.ajax here
8787
88-
}
88+
}
8989
9090
});
9191
```
@@ -99,13 +99,13 @@ For example, say we would like to modify all crossDomain requests through a prox
9999
// Using a proxy with a prefilter
100100
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {
101101
102-
if ( options.crossDomain ) {
102+
if ( options.crossDomain ) {
103103
104-
options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );
104+
options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );
105105
106-
options.crossDomain = false;
106+
options.crossDomain = false;
107107
108-
}
108+
}
109109
110110
});
111111
```
@@ -116,7 +116,7 @@ You can pass in an optional argument before the callback function that specifies
116116
// Using the optional dataTypes argument">
117117
$.ajaxPrefilter( "json script", function( options, originalOptions, jqXHR ) {
118118
119-
// do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"
119+
// do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"
120120
121121
});
122122
```

page/ajax/ajax-events.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ just like you'd bind other events. For a complete list of Ajax events, visit
1515
// Setting up a loading indicator using Ajax Events
1616
$("#loading_indicator").ajaxStart(function() {
1717
18-
$(this).show();
18+
$( this ).show();
1919
2020
}).ajaxStop(function() {
2121
22-
$(this).hide();
22+
$( this ).hide();
2323
2424
});
2525

page/code-organization/beware-anonymous-functions.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,48 @@ maintain, test, or reuse. Instead, use an object literal to organize and name
1111
your handlers and callbacks.
1212
```
1313
// BAD
14-
$(document).ready(function() {
15-
$('#magic').click(function(e) {
16-
$('#yayeffects').slideUp(function() {
14+
$( document ).ready(function() {
15+
16+
$("#magic").click(function(e) {
17+
18+
$("#yayeffects").slideUp(function() {
19+
1720
// ...
21+
1822
});
23+
1924
});
2025
21-
$('#happiness').load(url + ' #unicorns', function() {
26+
$("#happiness").load( url + " #unicorns", function() {
27+
2228
// ...
29+
2330
});
31+
2432
});
2533
2634
// BETTER
2735
var PI = {
36+
2837
onReady : function() {
29-
$('#magic').click(PI.candyMtn);
30-
$('#happiness').load(PI.url + ' #unicorns', PI.unicornCb);
38+
39+
$("#magic").click( PI.candyMtn );
40+
41+
$("#happiness").load( PI.url + " #unicorns", PI.unicornCb );
42+
3143
},
3244
33-
candyMtn : function(e) {
34-
$('#yayeffects').slideUp(PI.slideCb);
45+
candyMtn : function( e ) {
46+
47+
$("#yayeffects").slideUp( PI.slideCb );
48+
3549
},
3650
3751
slideCb : function() { ... },
3852
3953
unicornCb : function() { ... }
54+
4055
};
4156
42-
$(document).ready(PI.onReady);
57+
$( document ).ready( PI.onReady );
4358
```

0 commit comments

Comments
 (0)