Skip to content

Commit aa6355d

Browse files
committed
Second pass - less double spacing, console log outputs directly after the code that generates it
1 parent 4a71fa8 commit aa6355d

23 files changed

+169
-620
lines changed

page/ajax/jquery-ajax-methods.md

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,7 @@ $.ajax({
3636
// the data to send
3737
// (will be converted to a query string)
3838
data : {
39-
4039
id : 123
41-
4240
},
4341
4442
// whether this is a POST or GET request
@@ -50,27 +48,20 @@ $.ajax({
5048
// code to run if the request succeeds;
5149
// the response is passed to the function
5250
success : function( json ) {
53-
54-
$("<h1/>").text( json.title ).appendTo("body");
55-
56-
$("<div class=\"content\"/>").html( json.html ).appendTo("body");
57-
51+
$("<h1/>").text( json.title ).appendTo("body");
52+
$("<div class=\"content\"/>").html( json.html ).appendTo("body");
5853
},
5954
6055
// code to run if the request fails;
6156
// the raw request and status codes are
6257
// passed to the function
6358
error : function( xhr, status ) {
64-
65-
alert("Sorry, there was a problem!");
66-
59+
alert("Sorry, there was a problem!");
6760
},
6861
6962
// code to run regardless of success or failure
7063
complete : function( xhr, status ) {
71-
7264
alert("The request is complete!");
73-
7465
}
7566
7667
});
@@ -234,13 +225,9 @@ type in their name. </div>
234225
// Using jQuery's Ajax convenience methods
235226
// get plain text or html
236227
$.get( "/users.php", {
237-
238-
userId : 1234
239-
240-
}, function( resp ) {
241-
242-
console.log( resp );
243-
228+
userId : 1234
229+
}, function( resp ) {
230+
console.log( resp ); // server response
244231
});
245232
246233
// add a script to the page, then run a function defined in it
@@ -253,10 +240,9 @@ $.getScript( "/static/js/myScript.js", function() {
253240
// get JSON-formatted data from the server
254241
$.getJSON( "/details.php", function( resp ) {
255242
256-
$.each( resp, function( k, v ) {
257-
258-
console.log( k + " : " + v );
259-
243+
// log each key in the response data
244+
$.each( resp, function( key, value ) {
245+
console.log( key + " : " + value );
260246
});
261247
262248
});
@@ -278,8 +264,6 @@ $("#newContent").load("/foo.html");
278264
```
279265
// Using $.fn.load to populate an element based on a selector
280266
$("#newContent").load( "/foo.html #myDiv h1:first:", function( html ) {
281-
282267
alert("Content updated!"");
283-
284268
});
285269
```

page/ajax/key-concepts.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ $.get( "foo.php", function( r ) {
8686
8787
});
8888
89-
console.log( response ); // undefined!
89+
console.log( response ); // undefined
9090
```
9191

9292
Instead, we need to pass a callback function to our request; this callback will
@@ -95,9 +95,7 @@ returned, if any.
9595

9696
```
9797
$.get( "foo.php", function( response ) {
98-
99-
console.log( response );
100-
98+
console.log( response ); // server response
10199
});
102100
```
103101

page/ajax/working-with-jsonp.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,13 @@ $.ajax({
2727
2828
// tell YQL what we want and that we want JSON
2929
data : {
30-
3130
q : "select title,abstract,url from search.news where query=\"cat\"",
3231
format : "json"
33-
3432
},
3533
3634
// work with the response
3735
success : function( response ) {
38-
39-
console.log( response );
40-
36+
console.log( response ); // server response
4137
}
4238
4339
});

page/code-organization/concepts.md

Lines changed: 13 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -51,43 +51,27 @@ options, and easing the path to reuse and refactoring.
5151
```
5252
// An object literal
5353
var myFeature = {
54-
55-
myProperty : "hello",
56-
57-
myMethod : function() {
58-
54+
myProperty: "hello",
55+
myMethod: function() {
5956
console.log( myFeature.myProperty );
60-
6157
},
62-
63-
init : function( settings ) {
64-
58+
init: function( settings ) {
6559
myFeature.settings = settings;
66-
6760
},
68-
6961
readSettings : function() {
70-
7162
console.log( myFeature.settings );
72-
7363
}
74-
7564
};
7665
77-
// "hello"
78-
myFeature.myProperty;
66+
myFeature.myProperty === "hello"; // true
7967
80-
// logs "hello"
81-
myFeature.myMethod();
68+
myFeature.myMethod(); // "hello"
8269
8370
myFeature.init({
84-
85-
foo : "bar"
86-
71+
foo: "bar"
8772
});
8873
89-
// logs { foo : "bar" }
90-
myFeature.readSettings();
74+
myFeature.readSettings(); // { foo: "bar" }
9175
```
9276

9377
The object literal above is simply an object assigned to a variable. The object
@@ -245,33 +229,26 @@ var feature = (function() {
245229
246230
// private variables and functions
247231
var privateThing = "secret";
248-
249232
var publicThing = "not secret";
250-
251233
var changePrivateThing = function() {
252-
253234
privateThing = "super secret";
254-
255235
};
256236
257237
var sayPrivateThing = function() {
258-
259238
console.log( privateThing );
260-
261239
changePrivateThing();
262-
263240
};
264241
265242
// public API
266243
return {
267-
publicThing : publicThing,
268-
sayPrivateThing : sayPrivateThing
269-
}
244+
publicThing: publicThing,
245+
sayPrivateThing: sayPrivateThing
246+
};
270247
271248
})();
272249
273-
// "not secret"
274-
feature.publicThing;
250+
feature.publicThing; // "not secret"
251+
275252
276253
// logs "secret" and changes the value
277254
// of privateThing
@@ -302,67 +279,36 @@ $( document ).ready(function() {
302279
var feature = (function() {
303280
304281
var $items = $("#myFeature li");
305-
306282
var $container = $("<div class='container'></div>");
307-
308283
var $currentItem = null;
309-
310284
var urlBase = "/foo.php?item=";
311-
312285
var createContainer = function() {
313-
314286
var $i = $( this );
315-
316287
var $c = $container.clone().appendTo( $i );
317-
318288
$i.data( "container", $c );
319-
320289
},
321-
322290
buildUrl = function() {
323-
324291
return urlBase + $currentItem.attr("id");
325-
326292
},
327-
328293
showItem = function() {
329-
330294
var $currentItem = $( this );
331-
332295
getContent( showContent );
333-
334296
},
335-
336297
showItemByIndex = function( idx ) {
337-
338298
$.proxy( showItem, $items.get( idx ) );
339-
340299
},
341-
342300
getContent = function( callback ) {
343-
344301
$currentItem.data("container").load( buildUrl(), callback );
345-
346302
},
347-
348303
showContent = function() {
349-
350304
$currentItem.data("container").show();
351-
352305
hideContent();
353-
354306
},
355-
356307
hideContent = function() {
357-
358308
$currentItem.siblings().each(function() {
359-
360-
$( this ).data("container").hide();
361-
309+
$( this ).data("container").hide();
362310
});
363-
364311
};
365-
366312
$items.each( createContainer ).click( showItem );
367313
368314
return {
@@ -372,6 +318,5 @@ $( document ).ready(function() {
372318
})();
373319
374320
feature.showItemByIndex( 0 );
375-
376321
});
377322
```

page/effects/custom-effects.md

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,14 @@ value, or to a value relative to the current value.
1212
```
1313
// Custom effects with `$.fn.animate`">
1414
$("div.funtimes").animate({
15-
1615
left : "+=50",
1716
opacity : 0.25
18-
1917
},
2018
// duration:
2119
300,
20+
// callback:
2221
function() {
23-
24-
console.log("done!"); // callback
25-
22+
console.log("done!");
2623
}
2724
});
2825
```
@@ -47,13 +44,9 @@ As of jQuery 1.4, it is possible to do per-property easing when using the
4744
```
4845
// Per-property easing">
4946
$("div.funtimes").animate({
50-
51-
left : [ "+=50", "swing" ],
52-
opacity : [ 0.25, "linear" ]
53-
54-
},
55-
300
56-
);
47+
left: [ "+=50", "swing" ],
48+
opacity: [ 0.25, "linear" ]
49+
}, 300 );
5750
```
5851

5952
For more details on easing options, see

page/effects/intro-to-effects.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ testing whether your selection returned any elements; if not, you can just run t
137137
var $someElement = $("#nonexistent");
138138
139139
var cb = function() {
140-
console.log("done!"");
140+
console.log("done!");
141141
};
142142
143143
if ( $someElement.length ) {
@@ -159,8 +159,8 @@ end-users control over page animations by rigging a button they can click to sto
159159
```
160160
// Create a button to stop all animations on the page:
161161
$("input").attr({
162-
type : "button",
163-
value : "Stop All Animations"
162+
type: "button",
163+
value: "Stop All Animations"
164164
}).on( "click", function() {
165165
$("body *").filter(":animated").stop();
166166
}).appendTo( document.body );

page/events/event-delegation.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,8 @@ We can attach a direct bind click event to each `<li>` using the `.on()` method,
3737
```
3838
// attach a directly bound event
3939
$("#list a").on( "click", function( event ) {
40-
4140
event.preventDefault();
42-
4341
console.log( $( this ).text() );
44-
4542
});
4643
```
4744

@@ -69,11 +66,8 @@ Since we know how events bubble we can created a delegated event that listens fo
6966
```
7067
// attach a delegated event
7168
$("#list").on( "click", "a", function( event ) {
72-
7369
event.preventDefault();
74-
7570
console.log( $( this ).text() );
76-
7771
});
7872
```
7973
Notice for the second parameter to the `.on()` method we are telling it which selector to listen for. Now when a *click* event is triggered on our `<ul>`, our delegated event will check to see if the triggering element matches our selector (`"a"`). If it does, our anonymous function will execute. We have now attached a single *click* event listener to our `<ul>` instead of an unknown number of directly bound events on our `<a>`"s.

0 commit comments

Comments
 (0)