Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core style #178

Closed
wants to merge 10 commits into from
4 changes: 2 additions & 2 deletions order.yml
Expand Up @@ -33,6 +33,7 @@
- feature-browser-detection
- utility-methods
- iterating
- understanding-index
- events:
- events-to-elements
- inside-event-handling-function
Expand All @@ -59,8 +60,7 @@
- plugins:
- finding-evaluating-plugins
- basic-plugin-creation
- a_plugin_development_pattern
- making_a_jquery_plugin_truly_customizable
- advanced-plugin-concepts
- stateful-plugins-with-widget-factory
- performance:
- append-outside-loop
Expand Down
6 changes: 3 additions & 3 deletions page/about-jquery/how-jquery-works.md
Expand Up @@ -57,7 +57,7 @@ $( document ).ready( function() {
Inside the ready event, add a click handler to the link:

```
$( document ).ready(function(){
$( document ).ready(function() {

$("a").click(function( event ) {

Expand Down Expand Up @@ -106,7 +106,7 @@ element's src attribute
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script>

$(document).ready(function() {
$( document ).ready(function() {

$("a").click(function( event ) {

Expand Down Expand Up @@ -197,7 +197,7 @@ $.get( "myhtmlpage.html", myCallBack );
The Wrong Way (will ***not*** work!)

```
$.get( "myhtmlpage.html", myCallBack( param1, param2 ) );
$.get( "myhtmlpage.html", myCallBack(param1, param2) );
```


Expand Down
36 changes: 18 additions & 18 deletions page/ajax/ajax-and-forms.md
Expand Up @@ -50,16 +50,16 @@ With that being said, let's jump on in to some examples! First, we'll see how ea
// Using validation to check for the presence of an input
$("#form").submit(function( e ) {

if ( $(".required").val().length === 0 ) { // if .required's value's length is zero
if ( $(".required").val().length === 0 ) { // if .required's value's length is zero

// usually show some kind of error message here
return false; // this prevents the form from submitting
// usually show some kind of error message here
return false; // this prevents the form from submitting

} else {
} else {

// run $.ajax here
// run $.ajax here

}
}

});
```
Expand All @@ -70,19 +70,19 @@ Let's see how easy it is to check for invalid characters in a username:
// Validate a phone number field
$("#form").submit(function( e ) {

var inputtedPhoneNumber = $("#phone").val();
var inputtedPhoneNumber = $("#phone").val();
var phoneNumberRegex = ^\d*$/; // match only numbers

if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex
if ( !phoneNumberRegex.test( inputtedPhoneNumber ) ) { // if the phone number doesn't match the regex

// usually show some kind of error message ere
return false; // prevent the form from submitting
// usually show some kind of error message ere
return false; // prevent the form from submitting

} else {
} else {

// run $.ajax here
// run $.ajax here

}
}

});
```
Expand All @@ -96,13 +96,13 @@ For example, say we would like to modify all crossDomain requests through a prox
// Using a proxy with a prefilter
$.ajaxPrefilter(function( options, originalOptions, jqXHR ) {

if ( options.crossDomain ) {
if ( options.crossDomain ) {

options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );
options.url = "http://mydomain.net/proxy/" + encodeURIComponent(options.url );

options.crossDomain = false;
options.crossDomain = false;

}
}

});
```
Expand All @@ -113,7 +113,7 @@ You can pass in an optional argument before the callback function that specifies
// Using the optional dataTypes argument">
$.ajaxPrefilter( "json script", function( options, originalOptions, jqXHR ) {

// do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"
// do all of the prefiltering here, but only for requests that indicate a dataType of "JSON" or "script"

});
```
4 changes: 2 additions & 2 deletions page/ajax/ajax-events.md
Expand Up @@ -12,11 +12,11 @@ just like you'd bind other events. For a complete list of Ajax events, visit
// Setting up a loading indicator using Ajax Events
$("#loading_indicator").ajaxStart(function() {

$(this).show();
$( this ).show();

}).ajaxStop(function() {

$(this).hide();
$( this ).hide();

});

Expand Down
33 changes: 24 additions & 9 deletions page/code-organization/beware-anonymous-functions.md
Expand Up @@ -8,33 +8,48 @@ maintain, test, or reuse. Instead, use an object literal to organize and name
your handlers and callbacks.
```
// BAD
$(document).ready(function() {
$('#magic').click(function(e) {
$('#yayeffects').slideUp(function() {
$( document ).ready(function() {

$("#magic").click(function(e) {

$("#yayeffects").slideUp(function() {

// ...

});

});

$('#happiness').load(url + ' #unicorns', function() {
$("#happiness").load( url + " #unicorns", function() {

// ...

});

});

// BETTER
var PI = {

onReady : function() {
$('#magic').click(PI.candyMtn);
$('#happiness').load(PI.url + ' #unicorns', PI.unicornCb);

$("#magic").click( PI.candyMtn );

$("#happiness").load( PI.url + " #unicorns", PI.unicornCb );

},

candyMtn : function(e) {
$('#yayeffects').slideUp(PI.slideCb);
candyMtn : function( e ) {

$("#yayeffects").slideUp( PI.slideCb );

},

slideCb : function() { ... },

unicornCb : function() { ... }

};

$(document).ready(PI.onReady);
$( document ).ready( PI.onReady );
```