Skip to content

Commit ad18d21

Browse files
committed
Cleanup.
1 parent 278a81a commit ad18d21

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+903
-802
lines changed

Diff for: README.md

+9-2
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ To build and deploy your changes for previewing in a [jquery-wp-content](https:/
2727
* **No**: The `load`, `scroll` and `error` events (e.g., on an `<img>` element) do not bubble
2828

2929
#### Spelling
30+
3031
* The documentation standardizes on American English spelling. For example:
3132
* **Yes**: color, while, among, customize, argument
3233
* **No**: colour, whilst, amongst, customise, arguement
3334

3435
#### Pronoun Usage
36+
3537
* Use second-person pronoun ("you") when necessary, but try to avoid it.
3638
* Favor the definite article ("the") over second-person possesive ("your").
3739
* **Yes**: Insert the paragraph after the unordered list.
@@ -41,27 +43,32 @@ To build and deploy your changes for previewing in a [jquery-wp-content](https:/
4143
* **No**: And now we have our paragraph beneath the unordered list.
4244

4345
#### "Voice"
46+
4447
* Prefer active voice over passive.
4548
* **Active**: Calling `.click()` binds a click handler to the elements in the collection
4649
* **Passive**: Click handlers are bound to elements in the collection when `.click()` is called
4750

4851
### Code Style
49-
Code in the API documentation should follow the [jQuery Core Style Guide](http://docs.jquery.com/JQuery_Core_Style_Guidelines) with the following addition:
52+
53+
Code in the API documentation should follow the [jQuery Core Style Guide](http://contribute.jquery.org/style-guide/) with the following addition:
5054

5155
* **Document ready syntax**: Use `$( document ).ready(function() {` instead of `$(function() {` as it's harder for new users to distinguish the difference between the latter and an IIFE.
5256

5357
#### Code within prose content (paragraphs and the like):
54-
* Methods: use a dot, followed by the method name, followed by parentheses: e.g. The `.focus()` method is a shortcut for `.bind('focus', handler)` in the first and second variations, and `.trigger('focus')` in the third.
58+
59+
* Methods: use a dot, followed by the method name, followed by parentheses: e.g. The `.focus()` method is a shortcut for `.on( "focus", handler )` in the first and second variations, and `.trigger( "focus" )` in the third.
5560
* Properties: use a dot, followed by the property name: e.g. `.length`.
5661
* Functions: use the function name, followed by parentheses: `myFunction()`.
5762

5863
#### Examples
64+
5965
* Examples should indicate what the expected result will be before presenting the code. This makes code clearer and skimming easier, especially for newer coders who may not understand what is supposed to be happening from reading the code itself.
6066
* **Yes**: Find all p elements that are children of a div element and apply a border to them.
6167
* **No**: Find all p elements that are children of a div element.
6268
* Make your example easy to follow with good comments so that the explanation isn't necessary.
6369

6470
### Rhetorical Context
71+
6572
* Subject
6673
* The entirety of jQuery's public API
6774
* Audience

Diff for: entries/add.xml

+18-17
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,17 @@
3737
<desc>Add elements to the set of matched elements.</desc>
3838
<longdesc>
3939
<p>Given a jQuery object that represents a set of DOM elements, the <code>.add()</code> method constructs a new jQuery object from the union of those elements and the ones passed into the method. The argument to <code>.add()</code> can be pretty much anything that <code>$()</code> accepts, including a jQuery selector expression, references to DOM elements, or an HTML snippet.</p>
40-
<p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order, use the <code>$(array_of_DOM_elements)</code> signature.</p>
40+
<p>Do not assume that this method appends the elements to the existing collection in the order they are passed to the <code>.add()</code> method. When all elements are members of the same document, the resulting collection from <code>.add()</code> will be sorted in document order; that is, in order of each element's appearance in the document. If the collection consists of elements from different documents or ones not in any document, the sort order is undefined. To create a jQuery object with elements in a well-defined order, use the <code>$(array_of_DOM_elements)</code> signature.</p>
4141
<p>The updated set of elements can be used in a following (chained) method, or assigned to a variable for later use. For example:</p>
4242
<pre><code>
4343
$( "p" ).add( "div" ).addClass( "widget" );
4444
var pdiv = $( "p" ).add( "div" );
45-
</code></pre>
45+
</code></pre>
4646
<p>The following will <em>not</em> save the added elements, because the <code>.add()</code> method creates a new set and leaves the original set in pdiv unchanged:</p>
4747
<pre><code>
4848
var pdiv = $( "p" );
4949
pdiv.add( "div" ); // WRONG, pdiv will not change
50-
</code></pre>
50+
</code></pre>
5151
<p>Consider a page with a simple list and a paragraph following it:</p>
5252
<pre><code>
5353
&lt;ul&gt;
@@ -56,9 +56,11 @@ pdiv.add( "div" ); // WRONG, pdiv will not change
5656
&lt;li&gt;list item 3&lt;/li&gt;
5757
&lt;/ul&gt;
5858
&lt;p&gt;a paragraph&lt;/p&gt;
59-
</code></pre>
59+
</code></pre>
6060
<p>We can select the list items and then the paragraph by using either a selector or a reference to the DOM element itself as the <code>.add()</code> method's argument:</p>
61-
<pre><code>$( "li" ).add( "p" ).css( "background-color", "red" );</code></pre>
61+
<pre><code>
62+
$( "li" ).add( "p" ).css( "background-color", "red" );
63+
</code></pre>
6264
<p>Or:</p>
6365
<pre><code>
6466
$( "li" ).add( document.getElementsByTagName( "p" )[ 0 ] )
@@ -82,24 +84,23 @@ $( "div" ).css( "border", "2px solid red" )
8284
.css( "background", "yellow" );
8385
]]></code>
8486
<css><![CDATA[
85-
div {
86-
width: 60px;
87-
height: 60px;
88-
margin: 10px;
87+
div {
88+
width: 60px;
89+
height: 60px;
90+
margin: 10px;
8991
float: left;
9092
}
91-
p {
92-
clear: left;
93-
font-weight: bold;
93+
p {
94+
clear: left;
95+
font-weight: bold;
9496
font-size: 16px;
9597
color: blue;
96-
margin: 0 10px;
97-
padding: 2px;
98+
margin: 0 10px;
99+
padding: 2px;
98100
}
99-
]]></css>
101+
]]></css>
100102
<html><![CDATA[
101103
<div></div>
102-
103104
<div></div>
104105
<div></div>
105106
<div></div>
@@ -142,7 +143,7 @@ $( "p" ).add( document.getElementById( "a" ) ).css( "background", "yellow" );
142143
<desc>Demonstrates how to add (or push) elements to an existing collection</desc>
143144
<code><![CDATA[
144145
var collection = $( "p" );
145-
// capture the new collection
146+
// Capture the new collection
146147
collection = collection.add( document.getElementById( "a" ) );
147148
collection.css( "background", "yellow" );
148149
]]></code>

Diff for: entries/addBack.xml

+7-6
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@
2121
&lt;/ul&gt;
2222
</code></pre>
2323
<p>The result of the following code is a red background behind items 3, 4 and 5:</p>
24-
<pre><code>$( "li.third-item" ).nextAll().addBack()
24+
<pre><code>
25+
$( "li.third-item" ).nextAll().addBack()
2526
.css( "background-color", "red" );
26-
</code></pre>
27+
</code></pre>
2728
<p>First, the initial selector locates item 3, initializing the stack with the set containing just this item. The call to <code>.nextAll()</code> then pushes the set of items 4 and 5 onto the stack. Finally, the <code>.addBack()</code> invocation merges these two sets together, creating a jQuery object that points to all three items in document order: <code>{[&lt;li.third-item&gt;,&lt;li&gt;,&lt;li&gt; ]}</code>.</p>
2829
</longdesc>
2930
<example>
@@ -39,8 +40,8 @@ $( "div.after-addback" ).find( "p" ).addBack().addClass( "background" );
3940
]]></code>
4041
<css><![CDATA[
4142
p, div {
42-
margin: 5px;
43-
padding: 5px;
43+
margin: 5px;
44+
padding: 5px;
4445
}
4546
.border {
4647
border: 2px solid red;
@@ -49,13 +50,13 @@ $( "div.after-addback" ).find( "p" ).addBack().addClass( "background" );
4950
background: yellow;
5051
}
5152
.left, .right {
52-
width: 45%;
53+
width: 45%;
5354
float: left;
5455
}
5556
.right {
5657
margin-left: 3%;
5758
}
58-
]]></css>
59+
]]></css>
5960
<html><![CDATA[
6061
<div class="left">
6162
<p><strong>Before <code>addBack()</code></strong></p>

Diff for: entries/addClass.xml

+14-14
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ $( "p" ).last().addClass( "selected" );
4141
<css><![CDATA[
4242
p {
4343
margin: 8px;
44-
font-size:16px;
44+
font-size: 16px;
4545
}
4646
.selected {
47-
color:blue;
47+
color: blue;
4848
}
4949
.highlight {
50-
background:yellow;
50+
background: yellow;
5151
}
52-
]]></css>
52+
]]></css>
5353
<html><![CDATA[
5454
<p>Hello</p>
5555
<p>and</p>
@@ -62,17 +62,17 @@ $( "p" ).last().addClass( "selected" );
6262
$( "p:last" ).addClass( "selected highlight" );
6363
]]></code>
6464
<css><![CDATA[
65-
p {
66-
margin: 8px;
67-
font-size: 16px;
65+
p {
66+
margin: 8px;
67+
font-size: 16px;
6868
}
69-
.selected {
70-
color: red;
69+
.selected {
70+
color: red;
7171
}
72-
.highlight {
73-
background: yellow;
72+
.highlight {
73+
background: yellow;
7474
}
75-
]]></css>
75+
]]></css>
7676
<html><![CDATA[
7777
<p>Hello</p>
7878
<p>and</p>
@@ -94,7 +94,7 @@ $( "div" ).addClass(function( index, currentClass ) {
9494
});
9595
]]></code>
9696
<css><![CDATA[
97-
div {
97+
div {
9898
background: white;
9999
}
100100
.red {
@@ -103,7 +103,7 @@ $( "div" ).addClass(function( index, currentClass ) {
103103
.red.green {
104104
background: green;
105105
}
106-
]]></css>
106+
]]></css>
107107
<html><![CDATA[
108108
<div>This div should be white</div>
109109
<div class="red">This div will be green because it now has the "green" and "red" classes.

Diff for: entries/after.xml

+25-17
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,20 @@
2727
<longdesc>
2828
<p>The <code>.after()</code> and <code><a href="/insertAfter">.insertAfter()</a></code> methods perform the same task. The major difference is in the syntax&#x2014;specifically, in the placement of the content and target. With <code>.after()</code>, the selector expression preceding the method is the container after which the content is inserted. With <code>.insertAfter()</code>, on the other hand, the content precedes the method, either as a selector expression or as markup created on the fly, and it is inserted after the target container.</p>
2929
<p>Using the following HTML:</p>
30-
<pre><code>&lt;div class="container"&gt;
30+
<pre><code>
31+
&lt;div class="container"&gt;
3132
&lt;h2&gt;Greetings&lt;/h2&gt;
3233
&lt;div class="inner"&gt;Hello&lt;/div&gt;
3334
&lt;div class="inner"&gt;Goodbye&lt;/div&gt;
34-
&lt;/div&gt;</code></pre>
35+
&lt;/div&gt;
36+
</code></pre>
3537
<p>Content can be created and then inserted after several elements at once:</p>
3638
<pre><code>
3739
$( ".inner" ).after( "&lt;p&gt;Test&lt;/p&gt;" );
3840
</code></pre>
3941
<p>Each inner <code>&lt;div&gt;</code> element gets this new content:</p>
40-
<pre><code>&lt;div class="container"&gt;
42+
<pre><code>
43+
&lt;div class="container"&gt;
4144
&lt;h2&gt;Greetings&lt;/h2&gt;
4245
&lt;div class="inner"&gt;Hello&lt;/div&gt;
4346
&lt;p&gt;Test&lt;/p&gt;
@@ -62,16 +65,20 @@ $( ".container" ).after( $( "h2" ) );
6265
<pre><code>$( "&lt;div&gt;&lt;/div&gt;" ).after( "&lt;p&gt;&lt;/p&gt;" );</code></pre>
6366
<p>The result is a jQuery set containing a div and a paragraph, in that order. That set can be further manipulated, even before it is inserted in the document.</p>
6467
<pre><code>
65-
$( "&lt;div&gt;&lt;/div&gt;" ).after( "&lt;p&gt;&lt;/p&gt;" ).addClass( "foo" )
66-
.filter( "p" ).attr( "id", "bar" ).html( "hello" )
68+
$( "&lt;div&gt;&lt;/div&gt;" )
69+
.after( "&lt;p&gt;&lt;/p&gt;" )
70+
.addClass( "foo" )
71+
.filter( "p" )
72+
.attr( "id", "bar" )
73+
.html( "hello" )
6774
.end()
6875
.appendTo( "body" );
6976
</code></pre>
7077
<p>This results in the following elements inserted just before the closing <code>&lt;/body&gt;</code> tag:</p>
7178
<pre><code>
7279
&lt;div class="foo"&gt;&lt;/div&gt;
7380
&lt;p class="foo" id="bar"&gt;hello&lt;/p&gt;
74-
</code></pre>
81+
</code></pre>
7582
<h4 id="passing-a-function">Passing a Function</h4>
7683
<p>As of jQuery 1.4, <code>.after()</code> supports passing a function that returns the elements to insert.</p>
7784
<pre><code>
@@ -85,11 +92,11 @@ $( "p" ).after(function() {
8592
<p>For example, the following will insert two new <code>&lt;div&gt;</code>s and an existing <code>&lt;div&gt;</code> after the first paragraph:</p>
8693
<pre><code>
8794
var $newdiv1 = $( "&lt;div id='object1'/&gt;" ),
88-
newdiv2 = document.createElement( "div" ),
89-
existingdiv1 = document.getElementById( "foo" );
95+
newdiv2 = document.createElement( "div" ),
96+
existingdiv1 = document.getElementById( "foo" );
9097

9198
$( "p" ).first().after( $newdiv1, [ newdiv2, existingdiv1 ] );
92-
</code></pre>
99+
</code></pre>
93100
<p>Since <code>.after()</code> can accept any number of additional arguments, the same result can be achieved by passing in the three <code>&lt;div&gt;</code>s as three separate arguments, like so: <code>$( "p" ).first().after( $newdiv1, newdiv2, existingdiv1 )</code>. The type and number of arguments will largely depend on the elements that are collected in the code.</p>
94101
</longdesc>
95102
<example>
@@ -99,9 +106,9 @@ $( "p" ).after( "<b>Hello</b>" );
99106
]]></code>
100107
<css><![CDATA[
101108
p {
102-
background: yellow;
109+
background: yellow;
103110
}
104-
]]></css>
111+
]]></css>
105112
<html><![CDATA[
106113
<p>I would like to say: </p>
107114
]]></html>
@@ -112,10 +119,10 @@ $( "p" ).after( "<b>Hello</b>" );
112119
$( "p" ).after( document.createTextNode( "Hello" ) );
113120
]]></code>
114121
<css><![CDATA[
115-
p {
116-
background: yellow;
122+
p {
123+
background: yellow;
117124
}
118-
]]></css>
125+
]]></css>
119126
<html><![CDATA[
120127
<p>I would like to say: </p>
121128
]]></html>
@@ -127,11 +134,12 @@ $( "p" ).after( $( "b" ) );
127134
]]></code>
128135
<css><![CDATA[
129136
p {
130-
background: yellow;
137+
background: yellow;
131138
}
132-
]]></css>
139+
]]></css>
133140
<html><![CDATA[
134-
<b>Hello</b><p>I would like to say: </p>
141+
<b>Hello</b>
142+
<p>I would like to say: </p>
135143
]]></html>
136144
</example>
137145
<category slug="manipulation/dom-insertion-outside"/>

Diff for: entries/ajaxComplete.xml

+20-12
Original file line numberDiff line numberDiff line change
@@ -11,36 +11,44 @@
1111
<longdesc>
1212
<p>Whenever an Ajax request completes, jQuery triggers the <code>ajaxComplete</code> event. Any and all handlers that have been registered with the <code>.ajaxComplete()</code> method are executed at this time.</p>
1313
<p>To observe this method in action, set up a basic Ajax load request:</p>
14-
<pre><code>&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
14+
<pre><code>
15+
&lt;div class="trigger"&gt;Trigger&lt;/div&gt;
1516
&lt;div class="result"&gt;&lt;/div&gt;
1617
&lt;div class="log"&gt;&lt;/div&gt;
17-
</code></pre>
18+
</code></pre>
1819
<p>Attach the event handler to the document:</p>
19-
<pre><code>$(document).ajaxComplete(function() {
20+
<pre><code>
21+
$( document ).ajaxComplete(function() {
2022
$( ".log" ).text( "Triggered ajaxComplete handler." );
2123
});
22-
</code></pre>
24+
</code></pre>
2325
<p>Now, make an Ajax request using any jQuery method:</p>
24-
<pre><code>$( ".trigger" ).click(function() {
26+
<pre><code>
27+
$( ".trigger" ).click(function() {
2528
$( ".result" ).load( "ajax/test.html" );
26-
});</code></pre>
29+
});
30+
</code></pre>
2731
<p>When the user clicks the element with class <code>trigger</code> and the Ajax request completes, the log message is displayed.</p>
2832
<p><strong>As of jQuery 1.8, the <code>.ajaxComplete()</code> method should only be attached to <code>document</code>.</strong></p>
2933
<p>All <code>ajaxComplete</code> handlers are invoked, regardless of what Ajax request was completed. If you must differentiate between the requests, use the parameters passed to the handler. Each time an <code>ajaxComplete</code> handler is executed, it is passed the event object, the <code>XMLHttpRequest</code> object, and the settings object that was used in the creation of the request. For example, you can restrict the callback to only handling events dealing with a particular URL:</p>
30-
<pre><code>$(document).ajaxComplete(function(event, xhr, settings) {
34+
<pre><code>
35+
$( document ).ajaxComplete(function( event, xhr, settings ) {
3136
if ( settings.url === "ajax/test.html" ) {
3237
$( ".log" ).text( "Triggered ajaxComplete handler. The result is " +
33-
xhr.responseHTML );
38+
xhr.responseHTML );
3439
}
35-
});</code></pre>
40+
});
41+
</code></pre>
3642
<p><strong>Note:</strong> You can get the returned ajax contents by looking at <code>xhr.responseXML</code> or <code>xhr.responseHTML</code> for xml and html respectively.</p>
3743
</longdesc>
3844
<note id="ajax-global-false" type="additional" data-title=".ajaxComplete()"/>
3945
<example>
4046
<desc>Show a message when an Ajax request completes.</desc>
41-
<code><![CDATA[$(document).ajaxComplete(function(event,request, settings) {
42-
$( "#msg" ).append( "<li>Request Complete.</li>" );
43-
});]]></code>
47+
<code><![CDATA[
48+
$( document ).ajaxComplete(function( event,request, settings ) {
49+
$( "#msg" ).append( "<li>Request Complete.</li>" );
50+
});
51+
]]></code>
4452
</example>
4553
<category slug="ajax/global-ajax-event-handlers"/>
4654
<category slug="version/1.0"/>

0 commit comments

Comments
 (0)