Skip to content

Commit 278a81a

Browse files
agcolomscottgonzalez
authored andcommitted
Code indentation and formatting (d entries).
1 parent 0683cb2 commit 278a81a

12 files changed

+285
-195
lines changed

entries/data.xml

+70-52
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,12 @@
2323
<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks.</p>
2424
<p> We can set several distinct values for a single element and retrieve them later:</p>
2525
<pre><code>
26-
$("body").data("foo", 52);
27-
$("body").data("bar", { myType: "test", count: 40 });
28-
$("body").data({ baz: [ 1, 2, 3 ] });
29-
30-
$("body").data("foo"); // 52
31-
$("body").data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }
32-
</code></pre>
26+
$( "body" ).data( "foo", 52 );
27+
$( "body" ).data( "bar", { myType: "test", count: 40 } );
28+
$( "body" ).data( { baz: [ 1, 2, 3 ] } );
29+
$( "body" ).data( "foo" ); // 52
30+
$( "body" ).data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2, 3 ] }
31+
</code></pre>
3332
<p>In jQuery 1.4.3 setting an element's data object with <code>.data(obj)</code> extends the data previously stored with that element. jQuery itself uses the <code>.data()</code> method to save information under the names 'events' and 'handle', and also reserves any data name starting with an underscore ('_') for internal use.</p>
3433
<p>Prior to jQuery 1.4.3 (starting in jQuery 1.4) the .data() method completely replaced all data, instead of just extending the data object. If you are using third-party plugins it may not be advisable to completely replace the element's data object, since plugins may have also set data.</p>
3534
<p>Due to the way browsers interact with plugins and external code, the <code>.data()</code> method cannot be used on <code>&lt;object&gt;</code> (unless it's a Flash plugin), <code>&lt;applet&gt;</code> or <code>&lt;embed&gt;</code> elements.</p>
@@ -38,20 +37,26 @@ $("body").data(); // { foo: 52, bar: { myType: "test", count: 40 }, baz: [ 1, 2,
3837
<example>
3938
<desc>Store then retrieve a value from the div element.</desc>
4039
<code><![CDATA[
41-
$("div").data("test", { first: 16, last: "pizza!" });
42-
$("span:first").text($("div").data("test").first);
43-
$("span:last").text($("div").data("test").last);
40+
$( "div" ).data( "test", { first: 16, last: "pizza!" } );
41+
$( "span:first" ).text( $( "div" ).data( "test" ).first );
42+
$( "span:last" ).text( $( "div" ).data( "test" ).last );
4443
]]></code>
4544
<css><![CDATA[
46-
div { color:blue; }
47-
span { color:red; }
45+
div {
46+
color: blue;
47+
}
48+
span {
49+
color: red;
50+
}
4851
]]></css>
49-
<html><![CDATA[<div>
50-
The values stored were
51-
<span></span>
52-
and
53-
<span></span>
54-
</div>]]></html>
52+
<html><![CDATA[
53+
<div>
54+
The values stored were
55+
<span></span>
56+
and
57+
<span></span>
58+
</div>
59+
]]></html>
5560
</example>
5661
<category slug="data"/>
5762
<category slug="miscellaneous/data-storage"/>
@@ -73,81 +78,94 @@ $("span:last").text($("div").data("test").last);
7378
<longdesc>
7479
<p>The <code>.data()</code> method allows us to attach data of any type to DOM elements in a way that is safe from circular references and therefore from memory leaks. We can retrieve several distinct values for a single element one at a time, or as a set:</p>
7580
<pre><code>
76-
alert($('body').data('foo'));
77-
alert($('body').data());
78-
</code></pre>
81+
alert( $( "body" ).data( "foo" ) );
82+
alert( $( "body" ).data() );
83+
</code></pre>
7984
<p>The above lines alert the data values that were set on the <code>body</code> element. If no data at all was set on that element, <code>undefined</code> is returned.</p>
8085
<pre><code>
81-
alert( $("body").data("foo")); //undefined
82-
$("body").data("bar", "foobar");
83-
alert( $("body").data("bar")); //foobar
84-
</code></pre>
86+
alert( $( "body" ).data( "foo" ) ); //undefined
87+
$( "body" ).data( "bar", "foobar" );
88+
alert( $( "body" ).data( "bar" ) ); //foobar
89+
</code></pre>
8590
<h4 id="data-html5">
8691
<a href="#data-html5">HTML5 data-* Attributes</a>
8792
</h4>
8893
<p>As of jQuery 1.4.3 <a href="http://ejohn.org/blog/html-5-data-attributes/">HTML 5 data- attributes</a> will be automatically pulled in to jQuery's data object. The treatment of attributes with embedded dashes was changed in jQuery 1.6 to conform to the <a href="http://www.w3.org/TR/html5/dom.html#embedding-custom-non-visible-data-with-the-data-*-attributes">W3C HTML5 specification</a>.</p>
8994
<p>For example, given the following HTML:</p>
9095
<pre><code>&lt;div data-role="page" data-last-value="43" data-hidden="true" data-options='{"name":"John"}'&gt;&lt;/div&gt;</code></pre>
9196
<p>All of the following jQuery code will work.</p>
92-
<pre><code>$("div").data("role") === "page";
93-
$("div").data("lastValue") === 43;
94-
$("div").data("hidden") === true;
95-
$("div").data("options").name === "John";</code></pre>
97+
<pre><code>
98+
$( "div" ).data( "role" ) === "page";
99+
$( "div" ).data( "lastValue" ) === 43;
100+
$( "div" ).data( "hidden" ) === true;
101+
$( "div" ).data( "options" ).name === "John";
102+
</code></pre>
96103
<p>Every attempt is made to convert the string to a JavaScript value (this includes booleans, numbers, objects, arrays, and null). A value is only converted to a number if doing so doesn't change the value's representation. For example, "1E02" and "100.000" are equivalent as numbers (numeric value 100) but converting them would alter their representation so they are left as strings. The string value "100" is converted to the number 100.</p>
97104
<p>When the data attribute is an object (starts with '{') or array (starts with '[') then <code>jQuery.parseJSON</code> is used to parse the string; it must follow <a href="http://en.wikipedia.org/wiki/JSON#Data_types.2C_syntax_and_example">valid JSON syntax</a> <em>including quoted property names</em>. If the value isn't parseable as a JavaScript value, it is left as a string.</p>
98105
<p>To retrieve the value's attribute as a string without any attempt to convert it, use the <code><a href="/attr/">attr()</a></code> method.</p>
99106
<p>The data- attributes are pulled in the first time the data property is accessed and then are no longer accessed or mutated (all data values are then stored internally in jQuery).</p>
100107
<p>Calling <code>.data()</code> with no parameters retrieves all of the values as a JavaScript object. This object can be safely cached in a variable as long as a new object is not set with <code>.data(obj)</code>. Using the object directly to get or set values is faster than making individual calls to <code>.data()</code> to get or set each value:</p>
101108
<pre><code>
102-
var mydata = $("#mydiv").data();
109+
var mydata = $( "#mydiv" ).data();
103110
if ( mydata.count &lt; 9 ) {
104-
mydata.count = 43;
105-
mydata.status = "embiggened";
111+
mydata.count = 43;
112+
mydata.status = "embiggened";
106113
}
107-
</code></pre>
114+
</code></pre>
108115
</longdesc>
109116
<note id="no-data-on-xml" type="additional"/>
110117
<example>
111118
<desc>Get the data named "blah" stored at for an element.</desc>
112119
<code><![CDATA[
113-
$("button").click(function(e) {
120+
$( "button" ).click(function( e ) {
114121
var value;
115122
116-
switch ($("button").index(this)) {
123+
switch ( $( "button" ).index( this ) ) {
117124
case 0 :
118-
value = $("div").data("blah");
125+
value = $( "div" ).data( "blah" );
119126
break;
120127
case 1 :
121-
$("div").data("blah", "hello");
128+
$( "div" ).data( "blah", "hello" );
122129
value = "Stored!";
123130
break;
124131
case 2 :
125-
$("div").data("blah", 86);
132+
$( "div" ).data( "blah", 86 );
126133
value = "Stored!";
127134
break;
128135
case 3 :
129-
$("div").removeData("blah");
136+
$( "div" ).removeData( "blah" );
130137
value = "Removed!";
131138
break;
132139
}
133140
134-
$("span").text("" + value);
141+
$( "span" ).text( "" + value );
135142
});
136-
137143
]]></code>
138144
<css><![CDATA[
139-
div { margin:5px; background:yellow; }
140-
button { margin:5px; font-size:14px; }
141-
p { margin:5px; color:blue; }
142-
span { color:red; }
145+
div {
146+
margin: 5px;
147+
background: yellow;
148+
}
149+
button {
150+
margin: 5px;
151+
font-size: 14px;
152+
}
153+
p {
154+
margin: 5px;
155+
color: blue;
156+
}
157+
span {
158+
color: red;
159+
}
143160
]]></css>
144-
<html><![CDATA[<div>A div</div>
145-
<button>Get "blah" from the div</button>
146-
<button>Set "blah" to "hello"</button>
147-
148-
<button>Set "blah" to 86</button>
149-
<button>Remove "blah" from the div</button>
150-
<p>The "blah" value of this div is <span>?</span></p>]]></html>
161+
<html><![CDATA[
162+
<div>A div</div>
163+
<button>Get "blah" from the div</button>
164+
<button>Set "blah" to "hello"</button>
165+
<button>Set "blah" to 86</button>
166+
<button>Remove "blah" from the div</button>
167+
<p>The "blah" value of this div is <span>?</span></p>
168+
]]></html>
151169
</example>
152170
<category slug="data"/>
153171
<category slug="miscellaneous/data-storage"/>

entries/dblclick.xml

+36-20
Original file line numberDiff line numberDiff line change
@@ -21,30 +21,36 @@
2121
<added>1.0</added>
2222
</signature>
2323
<longdesc>
24-
<p>This method is a shortcut for <code>.on('dblclick', handler)</code> in the first two variations, and <code>.trigger('dblclick')</code> in the third.
24+
<p>This method is a shortcut for <code>.on( "dblclick", handler)</code> in the first two variations, and <code>.trigger( "dblclick" )</code> in the third.
2525
The <code>dblclick</code> event is sent to an element when the element is double-clicked. Any HTML element can receive this event.
2626
For example, consider the HTML:</p>
27-
<pre><code>&lt;div id="target"&gt;
27+
<pre><code>
28+
&lt;div id="target"&gt;
2829
Double-click here
2930
&lt;/div&gt;
3031
&lt;div id="other"&gt;
3132
Trigger the handler
32-
&lt;/div&gt;</code></pre>
33+
&lt;/div&gt;
34+
</code></pre>
3335
<p class="image">
3436
<img src="/resources/0042_05_04.png" alt=""/>
3537
</p>
3638
<p>The event handler can be bound to any <code>&lt;div&gt;</code>:</p>
37-
<pre><code>$('#target').dblclick(function() {
38-
alert('Handler for .dblclick() called.');
39-
});</code></pre>
39+
<pre><code>
40+
$( "#target" ).dblclick(function() {
41+
alert( "Handler for .dblclick() called." );
42+
});
43+
</code></pre>
4044
<p>Now double-clicking on this element displays the alert:</p>
4145
<p>
4246
<samp>Handler for .dblclick() called.</samp>
4347
</p>
4448
<p>To trigger the event manually, apply <code>.dblclick()</code> without an argument:</p>
45-
<pre><code>$('#other').click(function() {
46-
$('#target').dblclick();
47-
});</code></pre>
49+
<pre><code>
50+
$( "#other" ).click(function() {
51+
$( "#target" ).dblclick();
52+
});
53+
</code></pre>
4854
<p>After this code executes, (single) clicks on <samp>Trigger the handler</samp> will also alert the message.</p>
4955
<p>The <code>dblclick</code> event is only triggered after this exact series of events:</p>
5056
<ul>
@@ -58,25 +64,35 @@
5864
</longdesc>
5965
<example>
6066
<desc>To bind a "Hello World!" alert box the dblclick event on every paragraph on the page:</desc>
61-
<code><![CDATA[$("p").dblclick( function () { alert("Hello World!"); });]]></code>
67+
<code><![CDATA[
68+
$( "p" ).dblclick( function () {
69+
alert( "Hello World!" );
70+
});
71+
]]></code>
6272
</example>
6373
<example>
6474
<desc>Double click to toggle background color.</desc>
6575
<code><![CDATA[
66-
var divdbl = $("div:first");
67-
divdbl.dblclick(function () {
68-
divdbl.toggleClass('dbl');
69-
});
76+
var divdbl = $( "div:first" );
77+
divdbl.dblclick(function () {
78+
divdbl.toggleClass( "dbl" );
79+
});
7080
]]></code>
7181
<css><![CDATA[
72-
div { background:blue;
73-
color:white;
74-
height:100px;
75-
width:150px;
82+
div {
83+
background: blue;
84+
color: white;
85+
height: 100px;
86+
width: 150px;
7687
}
77-
div.dbl { background:yellow;color:black; }
88+
div.dbl {
89+
background: yellow;
90+
color: black;
91+
}
7892
]]></css>
79-
<html><![CDATA[<div></div><span>Double click the block</span>]]></html>
93+
<html><![CDATA[
94+
<div></div><span>Double click the block</span>
95+
]]></html>
8096
</example>
8197
<category slug="events/mouse-events"/>
8298
<category slug="version/1.0"/>

entries/deferred.always.xml

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
<example>
2222
<desc>Since the <a href="http://api.jquery.com/jQuery.get/"><code>jQuery.get()</code></a> method returns a <code>jqXHR</code> object, which is derived from a Deferred object, we can attach a callback for both success and error using the <code>deferred.always()</code> method.</desc>
2323
<code><![CDATA[
24-
$.get("test.php").always( function() {
25-
alert("$.get completed with success or error callback arguments");
26-
} );
24+
$.get( "test.php" ).always(function() {
25+
alert( "$.get completed with success or error callback arguments" );
26+
});
2727
]]></code>
2828
</example>
2929
<category slug="deferred-object"/>

entries/deferred.done.xml

+14-14
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
<example>
2222
<desc>Since the <a href="/jQuery.get"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred object, we can attach a success callback using the <code>.done()</code> method.</desc>
2323
<code><![CDATA[
24-
$.get("test.php").done(function() {
25-
alert("$.get succeeded");
24+
$.get( "test.php" ).done(function() {
25+
alert( "$.get succeeded" );
2626
});
2727
]]></code>
2828
</example>
@@ -31,13 +31,13 @@ $.get("test.php").done(function() {
3131
<code><![CDATA[
3232
/* 3 functions to call when the Deferred object is resolved */
3333
function fn1() {
34-
$("p").append(" 1 ");
34+
$( "p" ).append( " 1 " );
3535
}
3636
function fn2() {
37-
$("p").append(" 2 ");
37+
$( "p" ).append( " 2 " );
3838
}
39-
function fn3(n) {
40-
$("p").append(n + " 3 " + n);
39+
function fn3( n ) {
40+
$( "p" ).append( n + " 3 " + n );
4141
}
4242
4343
/* create a deferred object */
@@ -46,20 +46,20 @@ var dfd = $.Deferred();
4646
/* add handlers to be called when dfd is resolved */
4747
dfd
4848
/* .done() can take any number of functions or arrays of functions */
49-
.done( [fn1, fn2], fn3, [fn2, fn1] )
49+
.done( [ fn1, fn2 ], fn3, [ fn2, fn1 ] )
5050
/* we can chain done methods, too */
51-
.done(function(n) {
52-
$("p").append(n + " we're done.");
53-
});
51+
.done(function( n ) {
52+
$( "p" ).append( n + " we're done." );
53+
});
5454
5555
/* resolve the Deferred object when the button is clicked */
56-
$("button").on("click", function() {
57-
dfd.resolve("and");
56+
$( "button" ).on( "click", function() {
57+
dfd.resolve( "and" );
5858
});
5959
]]></code>
6060
<html><![CDATA[
61-
<button>Go</button>
62-
<p>Ready...</p>
61+
<button>Go</button>
62+
<p>Ready...</p>
6363
]]></html>
6464
</example>
6565
<category slug="deferred-object"/>

entries/deferred.fail.xml

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
<example>
2222
<desc>Since the <a href="http://api.jquery.com/jQuery.get/"><code>jQuery.get</code></a> method returns a jqXHR object, which is derived from a Deferred, you can attach a success and failure callback using the <code>deferred.done()</code> and <code>deferred.fail()</code> methods.</desc>
2323
<code><![CDATA[
24-
$.get("test.php")
25-
.done(function(){ alert("$.get succeeded"); })
26-
.fail(function(){ alert("$.get failed!"); });
24+
$.get( "test.php" )
25+
.done(function(){
26+
alert( "$.get succeeded" );
27+
})
28+
.fail(function(){
29+
alert( "$.get failed!" );
30+
});
2731
]]></code>
2832
</example>
2933
<category slug="deferred-object"/>

entries/deferred.pipe.xml

-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ var request = $.ajax( url, { dataType: "json" } ),
7676
chained.done(function( data ) {
7777
// data retrieved from url2 as provided by the first request
7878
});
79-
8079
]]></code>
8180
</example>
8281
<category slug="deferred-object"/>

0 commit comments

Comments
 (0)