guff-compass 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. checksums.yaml +7 -0
  2. data/.editorconfig +21 -0
  3. data/.gitignore +6 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +21 -0
  6. data/demo/bower_components/jquery/.bower.json +21 -0
  7. data/demo/bower_components/jquery/.editorconfig +43 -0
  8. data/demo/bower_components/jquery/.gitattributes +2 -0
  9. data/demo/bower_components/jquery/.gitignore +14 -0
  10. data/demo/bower_components/jquery/.gitmodules +6 -0
  11. data/demo/bower_components/jquery/.jshintrc +17 -0
  12. data/demo/bower_components/jquery/.mailmap +94 -0
  13. data/demo/bower_components/jquery/AUTHORS.txt +170 -0
  14. data/demo/bower_components/jquery/CONTRIBUTING.md +216 -0
  15. data/demo/bower_components/jquery/Gruntfile.js +594 -0
  16. data/demo/bower_components/jquery/MIT-LICENSE.txt +21 -0
  17. data/demo/bower_components/jquery/README.md +398 -0
  18. data/demo/bower_components/jquery/bower.json +11 -0
  19. data/demo/bower_components/jquery/build/release-notes.js +59 -0
  20. data/demo/bower_components/jquery/build/release.js +316 -0
  21. data/demo/bower_components/jquery/component.json +15 -0
  22. data/demo/bower_components/jquery/composer.json +35 -0
  23. data/demo/bower_components/jquery/jquery-migrate.js +511 -0
  24. data/demo/bower_components/jquery/jquery-migrate.min.js +3 -0
  25. data/demo/bower_components/jquery/jquery.js +9789 -0
  26. data/demo/bower_components/jquery/jquery.min.js +6 -0
  27. data/demo/bower_components/jquery/jquery.min.map +1 -0
  28. data/demo/bower_components/jquery/package.json +38 -0
  29. data/demo/bower_components/jquery/speed/benchmark.js +15 -0
  30. data/demo/bower_components/jquery/speed/benchmarker.css +65 -0
  31. data/demo/bower_components/jquery/speed/benchmarker.js +181 -0
  32. data/demo/bower_components/jquery/speed/closest.html +39 -0
  33. data/demo/bower_components/jquery/speed/css.html +82 -0
  34. data/demo/bower_components/jquery/speed/event.html +58 -0
  35. data/demo/bower_components/jquery/speed/filter.html +183 -0
  36. data/demo/bower_components/jquery/speed/find.html +179 -0
  37. data/demo/bower_components/jquery/speed/index.html +72 -0
  38. data/demo/bower_components/jquery/speed/jquery-basis.js +6238 -0
  39. data/demo/bower_components/jquery/speed/slice.vs.concat.html +47 -0
  40. data/demo/bower_components/jquery/src/.jshintrc +27 -0
  41. data/demo/bower_components/jquery/src/ajax.js +855 -0
  42. data/demo/bower_components/jquery/src/ajax/jsonp.js +80 -0
  43. data/demo/bower_components/jquery/src/ajax/script.js +86 -0
  44. data/demo/bower_components/jquery/src/ajax/xhr.js +207 -0
  45. data/demo/bower_components/jquery/src/attributes.js +659 -0
  46. data/demo/bower_components/jquery/src/callbacks.js +197 -0
  47. data/demo/bower_components/jquery/src/core.js +981 -0
  48. data/demo/bower_components/jquery/src/css.js +661 -0
  49. data/demo/bower_components/jquery/src/data.js +336 -0
  50. data/demo/bower_components/jquery/src/deferred.js +141 -0
  51. data/demo/bower_components/jquery/src/deprecated.js +11 -0
  52. data/demo/bower_components/jquery/src/dimensions.js +41 -0
  53. data/demo/bower_components/jquery/src/effects.js +732 -0
  54. data/demo/bower_components/jquery/src/event-alias.js +32 -0
  55. data/demo/bower_components/jquery/src/event.js +995 -0
  56. data/demo/bower_components/jquery/src/exports.js +21 -0
  57. data/demo/bower_components/jquery/src/intro.js +20 -0
  58. data/demo/bower_components/jquery/src/manipulation.js +744 -0
  59. data/demo/bower_components/jquery/src/offset.js +169 -0
  60. data/demo/bower_components/jquery/src/outro.js +2 -0
  61. data/demo/bower_components/jquery/src/queue.js +146 -0
  62. data/demo/bower_components/jquery/src/serialize.js +99 -0
  63. data/demo/bower_components/jquery/src/sizzle-jquery.js +7 -0
  64. data/demo/bower_components/jquery/src/support.js +246 -0
  65. data/demo/bower_components/jquery/src/traversing.js +283 -0
  66. data/demo/bower_components/jquery/src/wrap.js +66 -0
  67. data/demo/bower_components/jquery/test/.jshintignore +3 -0
  68. data/demo/bower_components/jquery/test/.jshintrc +60 -0
  69. data/demo/bower_components/jquery/test/data/1x1.jpg +0 -0
  70. data/demo/bower_components/jquery/test/data/ajax/unreleasedXHR.html +25 -0
  71. data/demo/bower_components/jquery/test/data/atom+xml.php +4 -0
  72. data/demo/bower_components/jquery/test/data/badcall.js +1 -0
  73. data/demo/bower_components/jquery/test/data/badjson.js +1 -0
  74. data/demo/bower_components/jquery/test/data/cleanScript.html +10 -0
  75. data/demo/bower_components/jquery/test/data/core/cc_on.html +22 -0
  76. data/demo/bower_components/jquery/test/data/dashboard.xml +11 -0
  77. data/demo/bower_components/jquery/test/data/dimensions/documentLarge.html +17 -0
  78. data/demo/bower_components/jquery/test/data/dimensions/documentSmall.html +21 -0
  79. data/demo/bower_components/jquery/test/data/echoData.php +1 -0
  80. data/demo/bower_components/jquery/test/data/echoQuery.php +1 -0
  81. data/demo/bower_components/jquery/test/data/errorWithJSON.php +6 -0
  82. data/demo/bower_components/jquery/test/data/errorWithText.php +5 -0
  83. data/demo/bower_components/jquery/test/data/etag.php +21 -0
  84. data/demo/bower_components/jquery/test/data/evalScript.php +1 -0
  85. data/demo/bower_components/jquery/test/data/event/focusElem.html +16 -0
  86. data/demo/bower_components/jquery/test/data/event/longLoadScript.php +4 -0
  87. data/demo/bower_components/jquery/test/data/event/promiseReady.html +17 -0
  88. data/demo/bower_components/jquery/test/data/event/syncReady.html +23 -0
  89. data/demo/bower_components/jquery/test/data/headers.php +18 -0
  90. data/demo/bower_components/jquery/test/data/if_modified_since.php +20 -0
  91. data/demo/bower_components/jquery/test/data/iframe.html +8 -0
  92. data/demo/bower_components/jquery/test/data/jquery-1.9.1.ajax_xhr.min.js +5 -0
  93. data/demo/bower_components/jquery/test/data/json.php +13 -0
  94. data/demo/bower_components/jquery/test/data/json_obj.js +1 -0
  95. data/demo/bower_components/jquery/test/data/jsonp.php +14 -0
  96. data/demo/bower_components/jquery/test/data/manipulation/iframe-denied.html +36 -0
  97. data/demo/bower_components/jquery/test/data/name.html +1 -0
  98. data/demo/bower_components/jquery/test/data/name.php +24 -0
  99. data/demo/bower_components/jquery/test/data/nocontent.php +5 -0
  100. data/demo/bower_components/jquery/test/data/offset/absolute.html +41 -0
  101. data/demo/bower_components/jquery/test/data/offset/body.html +26 -0
  102. data/demo/bower_components/jquery/test/data/offset/fixed.html +34 -0
  103. data/demo/bower_components/jquery/test/data/offset/relative.html +31 -0
  104. data/demo/bower_components/jquery/test/data/offset/scroll.html +39 -0
  105. data/demo/bower_components/jquery/test/data/offset/static.html +31 -0
  106. data/demo/bower_components/jquery/test/data/offset/table.html +43 -0
  107. data/demo/bower_components/jquery/test/data/params_html.php +12 -0
  108. data/demo/bower_components/jquery/test/data/readywaitasset.js +1 -0
  109. data/demo/bower_components/jquery/test/data/readywaitloader.js +25 -0
  110. data/demo/bower_components/jquery/test/data/script.php +11 -0
  111. data/demo/bower_components/jquery/test/data/selector/html5_selector.html +114 -0
  112. data/demo/bower_components/jquery/test/data/selector/sizzle_cache.html +21 -0
  113. data/demo/bower_components/jquery/test/data/statusText.php +5 -0
  114. data/demo/bower_components/jquery/test/data/support/bodyBackground.html +28 -0
  115. data/demo/bower_components/jquery/test/data/support/boxSizing.html +19 -0
  116. data/demo/bower_components/jquery/test/data/support/csp.js +3 -0
  117. data/demo/bower_components/jquery/test/data/support/csp.php +22 -0
  118. data/demo/bower_components/jquery/test/data/support/shrinkWrapBlocks.html +23 -0
  119. data/demo/bower_components/jquery/test/data/support/testElementCrash.html +17 -0
  120. data/demo/bower_components/jquery/test/data/test.html +7 -0
  121. data/demo/bower_components/jquery/test/data/test.js +3 -0
  122. data/demo/bower_components/jquery/test/data/test.php +7 -0
  123. data/demo/bower_components/jquery/test/data/test2.html +5 -0
  124. data/demo/bower_components/jquery/test/data/test3.html +3 -0
  125. data/demo/bower_components/jquery/test/data/testinit.js +264 -0
  126. data/demo/bower_components/jquery/test/data/testrunner.js +371 -0
  127. data/demo/bower_components/jquery/test/data/testsuite.css +155 -0
  128. data/demo/bower_components/jquery/test/data/text.php +12 -0
  129. data/demo/bower_components/jquery/test/data/ua.txt +272 -0
  130. data/demo/bower_components/jquery/test/data/with_fries.xml +25 -0
  131. data/demo/bower_components/jquery/test/data/with_fries_over_jsonp.php +7 -0
  132. data/demo/bower_components/jquery/test/delegatetest.html +228 -0
  133. data/demo/bower_components/jquery/test/hovertest.html +158 -0
  134. data/demo/bower_components/jquery/test/index.html +337 -0
  135. data/demo/bower_components/jquery/test/jquery.js +5 -0
  136. data/demo/bower_components/jquery/test/localfile.html +75 -0
  137. data/demo/bower_components/jquery/test/networkerror.html +84 -0
  138. data/demo/bower_components/jquery/test/readywait.html +70 -0
  139. data/demo/bower_components/jquery/test/unit/ajax.js +2016 -0
  140. data/demo/bower_components/jquery/test/unit/attributes.js +1388 -0
  141. data/demo/bower_components/jquery/test/unit/callbacks.js +342 -0
  142. data/demo/bower_components/jquery/test/unit/core.js +1360 -0
  143. data/demo/bower_components/jquery/test/unit/css.js +1056 -0
  144. data/demo/bower_components/jquery/test/unit/data.js +645 -0
  145. data/demo/bower_components/jquery/test/unit/deferred.js +436 -0
  146. data/demo/bower_components/jquery/test/unit/deprecated.js +8 -0
  147. data/demo/bower_components/jquery/test/unit/dimensions.js +472 -0
  148. data/demo/bower_components/jquery/test/unit/effects.js +2242 -0
  149. data/demo/bower_components/jquery/test/unit/event.js +2755 -0
  150. data/demo/bower_components/jquery/test/unit/exports.js +7 -0
  151. data/demo/bower_components/jquery/test/unit/manipulation.js +2120 -0
  152. data/demo/bower_components/jquery/test/unit/offset.js +559 -0
  153. data/demo/bower_components/jquery/test/unit/queue.js +314 -0
  154. data/demo/bower_components/jquery/test/unit/selector.js +172 -0
  155. data/demo/bower_components/jquery/test/unit/serialize.js +148 -0
  156. data/demo/bower_components/jquery/test/unit/support.js +370 -0
  157. data/demo/bower_components/jquery/test/unit/traversing.js +797 -0
  158. data/demo/bower_components/jquery/test/unit/wrap.js +265 -0
  159. data/demo/bower_components/jquery/test/xhtml.php +5 -0
  160. data/demo/index.html +347 -0
  161. data/demo/styles/main.css +208 -0
  162. data/demo/styles/main.scss +138 -0
  163. data/docs/docco.css +506 -0
  164. data/docs/guff.html +1127 -0
  165. data/docs/public/fonts/aller-bold.eot +0 -0
  166. data/docs/public/fonts/aller-bold.ttf +0 -0
  167. data/docs/public/fonts/aller-bold.woff +0 -0
  168. data/docs/public/fonts/aller-light.eot +0 -0
  169. data/docs/public/fonts/aller-light.ttf +0 -0
  170. data/docs/public/fonts/aller-light.woff +0 -0
  171. data/docs/public/fonts/novecento-bold.eot +0 -0
  172. data/docs/public/fonts/novecento-bold.ttf +0 -0
  173. data/docs/public/fonts/novecento-bold.woff +0 -0
  174. data/docs/public/stylesheets/normalize.css +375 -0
  175. data/guff.gemspec +16 -0
  176. data/guff.scss +514 -0
  177. data/gulpfile.js +67 -0
  178. data/lib/guff.rb +4 -0
  179. data/lib/stylesheets/_guff.scss +514 -0
  180. data/package.json +19 -0
  181. data/src/_functions.scss +57 -0
  182. data/src/_mixins.scss +301 -0
  183. data/src/_reset.scss +67 -0
  184. data/src/_settings.scss +22 -0
  185. data/src/_typography.scss +67 -0
  186. metadata +259 -0
@@ -0,0 +1,1388 @@
1
+ module( "attributes", {
2
+ teardown: moduleTeardown
3
+ });
4
+
5
+ function bareObj( value ) {
6
+ return value;
7
+ }
8
+
9
+ function functionReturningObj( value ) {
10
+ return function() {
11
+ return value;
12
+ };
13
+ }
14
+
15
+ /*
16
+ ======== local reference =======
17
+ bareObj and functionReturningObj can be used to test passing functions to setters
18
+ See testVal below for an example
19
+
20
+ bareObj( value );
21
+ This function returns whatever value is passed in
22
+
23
+ functionReturningObj( value );
24
+ Returns a function that returns the value
25
+ */
26
+
27
+ test( "jQuery.propFix integrity test", function() {
28
+ expect( 1 );
29
+
30
+ // This must be maintained and equal jQuery.attrFix when appropriate
31
+ // Ensure that accidental or erroneous property
32
+ // overwrites don't occur
33
+ // This is simply for better code coverage and future proofing.
34
+ var props = {
35
+ "tabindex": "tabIndex",
36
+ "readonly": "readOnly",
37
+ "for": "htmlFor",
38
+ "class": "className",
39
+ "maxlength": "maxLength",
40
+ "cellspacing": "cellSpacing",
41
+ "cellpadding": "cellPadding",
42
+ "rowspan": "rowSpan",
43
+ "colspan": "colSpan",
44
+ "usemap": "useMap",
45
+ "frameborder": "frameBorder",
46
+ "contenteditable": "contentEditable"
47
+ };
48
+
49
+ if ( !jQuery.support.enctype ) {
50
+ props.enctype = "encoding";
51
+ }
52
+
53
+ deepEqual( props, jQuery.propFix, "jQuery.propFix passes integrity check" );
54
+ });
55
+
56
+ test( "attr(String)", function() {
57
+ expect( 50 );
58
+
59
+ var extras, body, $body,
60
+ select, optgroup, option, $img, styleElem,
61
+ $button, $form, $a;
62
+
63
+ equal( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
64
+ equal( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
65
+ equal( jQuery("#check1").attr("type"), "checkbox", "Check for type attribute" );
66
+ equal( jQuery("#simon1").attr("rel"), "bookmark", "Check for rel attribute" );
67
+ equal( jQuery("#google").attr("title"), "Google!", "Check for title attribute" );
68
+ equal( jQuery("#mark").attr("hreflang"), "en", "Check for hreflang attribute" );
69
+ equal( jQuery("#en").attr("lang"), "en", "Check for lang attribute" );
70
+ equal( jQuery("#simon").attr("class"), "blog link", "Check for class attribute" );
71
+ equal( jQuery("#name").attr("name"), "name", "Check for name attribute" );
72
+ equal( jQuery("#text1").attr("name"), "action", "Check for name attribute" );
73
+ ok( jQuery("#form").attr("action").indexOf("formaction") >= 0, "Check for action attribute" );
74
+ equal( jQuery("#text1").attr("value", "t").attr("value"), "t", "Check setting the value attribute" );
75
+ equal( jQuery("#text1").attr("value", "").attr("value"), "", "Check setting the value attribute to empty string" );
76
+ equal( jQuery("<div value='t'></div>").attr("value"), "t", "Check setting custom attr named 'value' on a div" );
77
+ equal( jQuery("#form").attr("blah", "blah").attr("blah"), "blah", "Set non-existent attribute on a form" );
78
+ equal( jQuery("#foo").attr("height"), undefined, "Non existent height attribute should return undefined" );
79
+
80
+ // [7472] & [3113] (form contains an input with name="action" or name="id")
81
+ extras = jQuery("<input id='id' name='id' /><input id='name' name='name' /><input id='target' name='target' />").appendTo("#testForm");
82
+ equal( jQuery("#form").attr("action","newformaction").attr("action"), "newformaction", "Check that action attribute was changed" );
83
+ equal( jQuery("#testForm").attr("target"), undefined, "Retrieving target does not equal the input with name=target" );
84
+ equal( jQuery("#testForm").attr("target", "newTarget").attr("target"), "newTarget", "Set target successfully on a form" );
85
+ equal( jQuery("#testForm").removeAttr("id").attr("id"), undefined, "Retrieving id does not equal the input with name=id after id is removed [#7472]" );
86
+ // Bug #3685 (form contains input with name="name")
87
+ equal( jQuery("#testForm").attr("name"), undefined, "Retrieving name does not retrieve input with name=name" );
88
+ extras.remove();
89
+
90
+ equal( jQuery("#text1").attr("maxlength"), "30", "Check for maxlength attribute" );
91
+ equal( jQuery("#text1").attr("maxLength"), "30", "Check for maxLength attribute" );
92
+ equal( jQuery("#area1").attr("maxLength"), "30", "Check for maxLength attribute" );
93
+
94
+ // using innerHTML in IE causes href attribute to be serialized to the full path
95
+ jQuery("<a/>").attr({
96
+ "id": "tAnchor5",
97
+ "href": "#5"
98
+ }).appendTo("#qunit-fixture");
99
+ equal( jQuery("#tAnchor5").attr("href"), "#5", "Check for non-absolute href (an anchor)" );
100
+ jQuery("<a id='tAnchor6' href='#5' />").appendTo("#qunit-fixture");
101
+ equal( jQuery("#tAnchor5").prop("href"), jQuery("#tAnchor6").prop("href"), "Check for absolute href prop on an anchor" );
102
+
103
+ $("<script type='jquery/test' src='#5' id='scriptSrc'></script>").appendTo("#qunit-fixture");
104
+ equal( jQuery("#tAnchor5").prop("href"), jQuery("#scriptSrc").prop("src"), "Check for absolute src prop on a script" );
105
+
106
+ // list attribute is readonly by default in browsers that support it
107
+ jQuery("#list-test").attr( "list", "datalist" );
108
+ equal( jQuery("#list-test").attr("list"), "datalist", "Check setting list attribute" );
109
+
110
+ // Related to [5574] and [5683]
111
+ body = document.body;
112
+ $body = jQuery( body );
113
+
114
+ strictEqual( $body.attr("foo"), undefined, "Make sure that a non existent attribute returns undefined" );
115
+
116
+ body.setAttribute( "foo", "baz" );
117
+ equal( $body.attr("foo"), "baz", "Make sure the dom attribute is retrieved when no expando is found" );
118
+
119
+ $body.attr( "foo","cool" );
120
+ equal( $body.attr("foo"), "cool", "Make sure that setting works well when both expando and dom attribute are available" );
121
+
122
+ body.removeAttribute("foo"); // Cleanup
123
+
124
+ select = document.createElement("select");
125
+ optgroup = document.createElement("optgroup");
126
+ option = document.createElement("option");
127
+
128
+ optgroup.appendChild( option );
129
+ select.appendChild( optgroup );
130
+
131
+ equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
132
+
133
+ $img = jQuery("<img style='display:none' width='215' height='53' src='data/1x1.jpg'/>").appendTo("body");
134
+ equal( $img.attr("width"), "215", "Retrieve width attribute an an element with display:none." );
135
+ equal( $img.attr("height"), "53", "Retrieve height attribute an an element with display:none." );
136
+
137
+ // Check for style support
138
+ styleElem = jQuery("<div/>").appendTo("#qunit-fixture").css({
139
+ background: "url(UPPERlower.gif)"
140
+ });
141
+ ok( !!~styleElem.attr("style").indexOf("UPPERlower.gif"), "Check style attribute getter" );
142
+ ok( !!~styleElem.attr("style", "position:absolute;").attr("style").indexOf("absolute"), "Check style setter" );
143
+
144
+ // Check value on button element (#1954)
145
+ $button = jQuery("<button>text</button>").insertAfter("#button");
146
+ strictEqual( $button.attr("value"), undefined, "Absence of value attribute on a button" );
147
+ equal( $button.attr( "value", "foobar" ).attr("value"), "foobar", "Value attribute on a button does not return innerHTML" );
148
+ equal( $button.attr("value", "baz").html(), "text", "Setting the value attribute does not change innerHTML" );
149
+
150
+ // Attributes with a colon on a table element (#1591)
151
+ equal( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
152
+ equal( jQuery("#table").attr( "test:attrib", "foobar" ).attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
153
+
154
+ $form = jQuery("<form class='something'></form>").appendTo("#qunit-fixture");
155
+ equal( $form.attr("class"), "something", "Retrieve the class attribute on a form." );
156
+
157
+ $a = jQuery("<a href='#' onclick='something()'>Click</a>").appendTo("#qunit-fixture");
158
+ equal( $a.attr("onclick"), "something()", "Retrieve ^on attribute without anonymous function wrapper." );
159
+
160
+ ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
161
+ ok( jQuery("<div/>").attr("title") === undefined, "Make sure undefined is returned when no attribute is found." );
162
+ equal( jQuery("<div/>").attr( "title", "something" ).attr("title"), "something", "Set the title attribute." );
163
+ ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
164
+ equal( jQuery("<div/>").attr("value"), undefined, "An unset value on a div returns undefined." );
165
+ strictEqual( jQuery("<select><option value='property'></option></select>").attr("value"), undefined, "An unset value on a select returns undefined." );
166
+
167
+ $form = jQuery("#form").attr( "enctype", "multipart/form-data" );
168
+ equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
169
+
170
+ });
171
+
172
+ test( "attr(String) on cloned elements, #9646", function() {
173
+ expect( 4 );
174
+
175
+ var div,
176
+ input = jQuery("<input name='tester' />");
177
+
178
+ input.attr("name");
179
+
180
+ strictEqual( input.clone( true ).attr( "name", "test" )[ 0 ].name, "test", "Name attribute should be changed on cloned element" );
181
+
182
+ div = jQuery("<div id='tester' />");
183
+ div.attr("id");
184
+
185
+ strictEqual( div.clone( true ).attr( "id", "test" )[ 0 ].id, "test", "Id attribute should be changed on cloned element" );
186
+
187
+ input = jQuery("<input value='tester' />");
188
+ input.attr("value");
189
+
190
+ strictEqual( input.clone( true ).attr( "value", "test" )[ 0 ].value, "test", "Value attribute should be changed on cloned element" );
191
+
192
+ strictEqual( input.clone( true ).attr( "value", 42 )[ 0 ].value, "42", "Value attribute should be changed on cloned element" );
193
+ });
194
+
195
+ test( "attr(String) in XML Files", function() {
196
+ expect( 3 );
197
+ var xml = createDashboardXML();
198
+ equal( jQuery( "locations", xml ).attr("class"), "foo", "Check class attribute in XML document" );
199
+ equal( jQuery( "location", xml ).attr("for"), "bar", "Check for attribute in XML document" );
200
+ equal( jQuery( "location", xml ).attr("checked"), "different", "Check that hooks are not attached in XML document" );
201
+ });
202
+
203
+ test( "attr(String, Function)", function() {
204
+ expect( 2 );
205
+
206
+ equal(
207
+ jQuery("#text1").attr( "value", function() {
208
+ return this.id;
209
+ }).attr("value"),
210
+ "text1",
211
+ "Set value from id"
212
+ );
213
+
214
+ equal(
215
+ jQuery("#text1").attr( "title", function(i) {
216
+ return i;
217
+ }).attr("title"),
218
+ "0",
219
+ "Set value with an index"
220
+ );
221
+ });
222
+
223
+ test( "attr(Hash)", function() {
224
+ expect( 3 );
225
+ var pass = true;
226
+ jQuery("div").attr({
227
+ "foo": "baz",
228
+ "zoo": "ping"
229
+ }).each(function() {
230
+ if ( this.getAttribute("foo") !== "baz" && this.getAttribute("zoo") !== "ping" ) {
231
+ pass = false;
232
+ }
233
+ });
234
+
235
+ ok( pass, "Set Multiple Attributes" );
236
+
237
+ equal(
238
+ jQuery("#text1").attr({
239
+ "value": function() {
240
+ return this["id"];
241
+ }}).attr("value"),
242
+ "text1",
243
+ "Set attribute to computed value #1"
244
+ );
245
+
246
+ equal(
247
+ jQuery("#text1").attr({
248
+ "title": function(i) {
249
+ return i;
250
+ }
251
+ }).attr("title"),
252
+ "0",
253
+ "Set attribute to computed value #2"
254
+ );
255
+ });
256
+
257
+ test( "attr(String, Object)", function() {
258
+ expect( 71 );
259
+
260
+ var $input, $text, $details,
261
+ attributeNode, commentNode, textNode, obj,
262
+ table, td, j, type,
263
+ check, thrown, button, $radio, $radios, $svg,
264
+ div = jQuery("div").attr("foo", "bar"),
265
+ i = 0,
266
+ fail = false;
267
+
268
+ for ( ; i < div.length; i++ ) {
269
+ if ( div[ i ].getAttribute("foo") !== "bar" ) {
270
+ fail = i;
271
+ break;
272
+ }
273
+ }
274
+
275
+ equal( fail, false, "Set Attribute, the #" + fail + " element didn't get the attribute 'foo'" );
276
+
277
+ ok(
278
+ jQuery("#foo").attr({
279
+ "width": null
280
+ }),
281
+ "Try to set an attribute to nothing"
282
+ );
283
+
284
+ jQuery("#name").attr( "name", "something" );
285
+ equal( jQuery("#name").attr("name"), "something", "Set name attribute" );
286
+ jQuery("#name").attr( "name", null );
287
+ equal( jQuery("#name").attr("name"), undefined, "Remove name attribute" );
288
+
289
+ $input = jQuery( "<input>", {
290
+ name: "something",
291
+ id: "specified"
292
+ });
293
+ equal( $input.attr("name"), "something", "Check element creation gets/sets the name attribute." );
294
+ equal( $input.attr("id"), "specified", "Check element creation gets/sets the id attribute." );
295
+
296
+ // As of fixing #11115, we only guarantee boolean property update for checked and selected
297
+ $input = jQuery("<input type='checkbox'/>").attr( "checked", true );
298
+ equal( $input.prop("checked"), true, "Setting checked updates property (verified by .prop)" );
299
+ equal( $input[0].checked, true, "Setting checked updates property (verified by native property)" );
300
+ $input = jQuery("<option/>").attr( "selected", true );
301
+ equal( $input.prop("selected"), true, "Setting selected updates property (verified by .prop)" );
302
+ equal( $input[0].selected, true, "Setting selected updates property (verified by native property)" );
303
+
304
+ $input = jQuery("#check2");
305
+ $input.prop( "checked", true ).prop( "checked", false ).attr( "checked", true );
306
+ equal( $input.attr("checked"), "checked", "Set checked (verified by .attr)" );
307
+ $input.prop( "checked", false ).prop( "checked", true ).attr( "checked", false );
308
+ equal( $input.attr("checked"), undefined, "Remove checked (verified by .attr)" );
309
+
310
+ $input = jQuery("#text1").prop( "readOnly", true ).prop( "readOnly", false ).attr( "readonly", true );
311
+ equal( $input.attr("readonly"), "readonly", "Set readonly (verified by .attr)" );
312
+ $input.prop( "readOnly", false ).prop( "readOnly", true ).attr( "readonly", false );
313
+ equal( $input.attr("readonly"), undefined, "Remove readonly (verified by .attr)" );
314
+
315
+ $input = jQuery("#check2").attr( "checked", true ).attr( "checked", false ).prop( "checked", true );
316
+ equal( $input[0].checked, true, "Set checked property (verified by native property)" );
317
+ equal( $input.prop("checked"), true, "Set checked property (verified by .prop)" );
318
+ equal( $input.attr("checked"), undefined, "Setting checked property doesn't affect checked attribute" );
319
+ $input.attr( "checked", false ).attr( "checked", true ).prop( "checked", false );
320
+ equal( $input[0].checked, false, "Clear checked property (verified by native property)" );
321
+ equal( $input.prop("checked"), false, "Clear checked property (verified by .prop)" );
322
+ equal( $input.attr("checked"), "checked", "Clearing checked property doesn't affect checked attribute" );
323
+
324
+ $input = jQuery("#check2").attr( "checked", false ).attr( "checked", "checked" );
325
+ equal( $input.attr("checked"), "checked", "Set checked to 'checked' (verified by .attr)" );
326
+
327
+ $radios = jQuery("#checkedtest").find("input[type='radio']");
328
+ $radios.eq( 1 ).trigger("click");
329
+ equal( $radios.eq( 1 ).prop("checked"), true, "Second radio was checked when clicked" );
330
+ equal( $radios.eq( 0 ).attr("checked"), "checked", "First radio is still [checked]" );
331
+
332
+ $input = jQuery("#text1").attr( "readonly", false ).prop( "readOnly", true );
333
+ equal( $input[0].readOnly, true, "Set readonly property (verified by native property)" );
334
+ equal( $input.prop("readOnly"), true, "Set readonly property (verified by .prop)" );
335
+ $input.attr( "readonly", true ).prop( "readOnly", false );
336
+ equal( $input[0].readOnly, false, "Clear readonly property (verified by native property)" );
337
+ equal( $input.prop("readOnly"), false, "Clear readonly property (verified by .prop)" );
338
+
339
+ $input = jQuery("#name").attr( "maxlength", "5" );
340
+ equal( $input[0].maxLength, 5, "Set maxlength (verified by native property)" );
341
+ $input.attr( "maxLength", "10" );
342
+ equal( $input[0].maxLength, 10, "Set maxlength (verified by native property)" );
343
+
344
+ // HTML5 boolean attributes
345
+ $text = jQuery("#text1").attr({
346
+ "autofocus": true,
347
+ "required": true
348
+ });
349
+ equal( $text.attr("autofocus"), "autofocus", "Reading autofocus attribute yields 'autofocus'" );
350
+ equal( $text.attr( "autofocus", false ).attr("autofocus"), undefined, "Setting autofocus to false removes it" );
351
+ equal( $text.attr("required"), "required", "Reading required attribute yields 'required'" );
352
+ equal( $text.attr( "required", false ).attr("required"), undefined, "Setting required attribute to false removes it" );
353
+
354
+ $details = jQuery("<details open></details>").appendTo("#qunit-fixture");
355
+ equal( $details.attr("open"), "open", "open attribute presence indicates true" );
356
+ equal( $details.attr( "open", false ).attr("open"), undefined, "Setting open attribute to false removes it" );
357
+
358
+ $text.attr( "data-something", true );
359
+ equal( $text.attr("data-something"), "true", "Set data attributes");
360
+ equal( $text.data("something"), true, "Setting data attributes are not affected by boolean settings");
361
+ $text.attr( "data-another", false );
362
+ equal( $text.attr("data-another"), "false", "Set data attributes");
363
+ equal( $text.data("another"), false, "Setting data attributes are not affected by boolean settings" );
364
+ equal( $text.attr( "aria-disabled", false ).attr("aria-disabled"), "false", "Setting aria attributes are not affected by boolean settings" );
365
+ $text.removeData("something").removeData("another").removeAttr("aria-disabled");
366
+
367
+ jQuery("#foo").attr("contenteditable", true);
368
+ equal( jQuery("#foo").attr("contenteditable"), "true", "Enumerated attributes are set properly" );
369
+
370
+ attributeNode = document.createAttribute("irrelevant");
371
+ commentNode = document.createComment("some comment");
372
+ textNode = document.createTextNode("some text");
373
+ obj = {};
374
+
375
+ jQuery.each( [ commentNode, textNode, attributeNode ], function( i, elem ) {
376
+ var $elem = jQuery( elem );
377
+ $elem.attr( "nonexisting", "foo" );
378
+ strictEqual( $elem.attr("nonexisting"), undefined, "attr(name, value) works correctly on comment and text nodes (bug #7500)." );
379
+ });
380
+
381
+ // Register the property name to avoid generating a new global when testing window
382
+ Globals.register("nonexisting");
383
+ jQuery.each( [ window, document, obj, "#firstp" ], function( i, elem ) {
384
+ var oldVal = elem.nonexisting,
385
+ $elem = jQuery( elem );
386
+ strictEqual( $elem.attr("nonexisting"), undefined, "attr works correctly for non existing attributes (bug #7500)." );
387
+ equal( $elem.attr( "nonexisting", "foo" ).attr("nonexisting"), "foo", "attr falls back to prop on unsupported arguments" );
388
+ elem.nonexisting = oldVal;
389
+ });
390
+
391
+ table = jQuery("#table").append("<tr><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr><tr><td>cell</td><td>cell</td></tr>");
392
+ td = table.find("td").eq(0);
393
+ td.attr( "rowspan", "2" );
394
+ equal( td[ 0 ]["rowSpan"], 2, "Check rowspan is correctly set" );
395
+ td.attr( "colspan", "2" );
396
+ equal( td[ 0 ]["colSpan"], 2, "Check colspan is correctly set" );
397
+ table.attr("cellspacing", "2");
398
+ equal( table[ 0 ]["cellSpacing"], "2", "Check cellspacing is correctly set" );
399
+
400
+ equal( jQuery("#area1").attr("value"), undefined, "Value attribute is distinct from value property." );
401
+
402
+ // for #1070
403
+ jQuery("#name").attr( "someAttr", "0" );
404
+ equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to a string of '0'" );
405
+ jQuery("#name").attr( "someAttr", 0 );
406
+ equal( jQuery("#name").attr("someAttr"), "0", "Set attribute to the number 0" );
407
+ jQuery("#name").attr( "someAttr", 1 );
408
+ equal( jQuery("#name").attr("someAttr"), "1", "Set attribute to the number 1" );
409
+
410
+ // using contents will get comments regular, text, and comment nodes
411
+ j = jQuery("#nonnodes").contents();
412
+
413
+ j.attr( "name", "attrvalue" );
414
+ equal( j.attr("name"), "attrvalue", "Check node,textnode,comment for attr" );
415
+ j.removeAttr("name");
416
+
417
+ // Type
418
+ type = jQuery("#check2").attr("type");
419
+ try {
420
+ jQuery("#check2").attr( "type", "hidden" );
421
+ ok( true, "No exception thrown on input type change" );
422
+ } catch( e ) {
423
+ ok( true, "Exception thrown on input type change: " + e );
424
+ }
425
+
426
+ check = document.createElement("input");
427
+ thrown = true;
428
+ try {
429
+ jQuery( check ).attr( "type", "checkbox" );
430
+ } catch( e ) {
431
+ thrown = false;
432
+ }
433
+ ok( thrown, "Exception thrown when trying to change type property" );
434
+ equal( "checkbox", jQuery( check ).attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
435
+
436
+ check = jQuery("<input />");
437
+ thrown = true;
438
+ try {
439
+ check.attr( "type", "checkbox" );
440
+ } catch( e ) {
441
+ thrown = false;
442
+ }
443
+ ok( thrown, "Exception thrown when trying to change type property" );
444
+ equal( "checkbox", check.attr("type"), "Verify that you can change the type of an input element that isn't in the DOM" );
445
+
446
+ button = jQuery("#button");
447
+ try {
448
+ button.attr( "type", "submit" );
449
+ ok( true, "No exception thrown on button type change" );
450
+ } catch( e ) {
451
+ ok( true, "Exception thrown on button type change: " + e );
452
+ }
453
+
454
+ $radio = jQuery( "<input>", {
455
+ "value": "sup",
456
+ "type": "radio"
457
+ }).appendTo("#testForm");
458
+ equal( $radio.val(), "sup", "Value is not reset when type is set after value on a radio" );
459
+
460
+ // Setting attributes on svg elements (bug #3116)
461
+ $svg = jQuery(
462
+ "<svg xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' version='1.1' baseProfile='full' width='200' height='200'>" +
463
+ "<circle cx='200' cy='200' r='150' />" +
464
+ "</svg>"
465
+ ).appendTo("body");
466
+ equal( $svg.attr( "cx", 100 ).attr("cx"), "100", "Set attribute on svg element" );
467
+ $svg.remove();
468
+
469
+ // undefined values are chainable
470
+ jQuery("#name").attr( "maxlength", "5" ).removeAttr("nonexisting");
471
+ equal( typeof jQuery("#name").attr( "maxlength", undefined ), "object", ".attr('attribute', undefined) is chainable (#5571)" );
472
+ equal( jQuery("#name").attr( "maxlength", undefined ).attr("maxlength"), "5", ".attr('attribute', undefined) does not change value (#5571)" );
473
+ equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
474
+ });
475
+
476
+ test( "attr(String, Object) - Loaded via XML document", function() {
477
+ expect( 2 );
478
+ var xml = createDashboardXML(),
479
+ titles = [];
480
+ jQuery( "tab", xml ).each(function() {
481
+ titles.push( jQuery( this ).attr("title") );
482
+ });
483
+ equal( titles[ 0 ], "Location", "attr() in XML context: Check first title" );
484
+ equal( titles[ 1 ], "Users", "attr() in XML context: Check second title" );
485
+ });
486
+
487
+ test( "attr(String, Object) - Loaded via XML fragment", function() {
488
+ expect( 2 );
489
+ var frag = createXMLFragment(),
490
+ $frag = jQuery( frag );
491
+
492
+ $frag.attr( "test", "some value" );
493
+ equal( $frag.attr("test"), "some value", "set attribute" );
494
+ $frag.attr( "test", null );
495
+ equal( $frag.attr("test"), undefined, "remove attribute" );
496
+ });
497
+
498
+ test( "attr('tabindex')", function() {
499
+ expect( 8 );
500
+
501
+ // elements not natively tabbable
502
+ equal( jQuery("#listWithTabIndex").attr("tabindex"), "5", "not natively tabbable, with tabindex set to 0" );
503
+ equal( jQuery("#divWithNoTabIndex").attr("tabindex"), undefined, "not natively tabbable, no tabindex set" );
504
+
505
+ // anchor with href
506
+ equal( jQuery("#linkWithNoTabIndex").attr("tabindex"), undefined, "anchor with href, no tabindex set" );
507
+ equal( jQuery("#linkWithTabIndex").attr("tabindex"), "2", "anchor with href, tabindex set to 2" );
508
+ equal( jQuery("#linkWithNegativeTabIndex").attr("tabindex"), "-1", "anchor with href, tabindex set to -1" );
509
+
510
+ // anchor without href
511
+ equal( jQuery("#linkWithNoHrefWithNoTabIndex").attr("tabindex"), undefined, "anchor without href, no tabindex set" );
512
+ equal( jQuery("#linkWithNoHrefWithTabIndex").attr("tabindex"), "1", "anchor without href, tabindex set to 2" );
513
+ equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").attr("tabindex"), "-1", "anchor without href, no tabindex set" );
514
+ });
515
+
516
+ test( "attr('tabindex', value)", function() {
517
+ expect( 9 );
518
+
519
+ var element = jQuery("#divWithNoTabIndex");
520
+ equal( element.attr("tabindex"), undefined, "start with no tabindex" );
521
+
522
+ // set a positive string
523
+ element.attr( "tabindex", "1" );
524
+ equal( element.attr("tabindex"), "1", "set tabindex to 1 (string)" );
525
+
526
+ // set a zero string
527
+ element.attr( "tabindex", "0" );
528
+ equal( element.attr("tabindex"), "0", "set tabindex to 0 (string)" );
529
+
530
+ // set a negative string
531
+ element.attr( "tabindex", "-1" );
532
+ equal( element.attr("tabindex"), "-1", "set tabindex to -1 (string)" );
533
+
534
+ // set a positive number
535
+ element.attr( "tabindex", 1 );
536
+ equal( element.attr("tabindex"), "1", "set tabindex to 1 (number)" );
537
+
538
+ // set a zero number
539
+ element.attr( "tabindex", 0 );
540
+ equal(element.attr("tabindex"), "0", "set tabindex to 0 (number)");
541
+
542
+ // set a negative number
543
+ element.attr( "tabindex", -1 );
544
+ equal( element.attr("tabindex"), "-1", "set tabindex to -1 (number)" );
545
+
546
+ element = jQuery("#linkWithTabIndex");
547
+ equal( element.attr("tabindex"), "2", "start with tabindex 2" );
548
+
549
+ element.attr( "tabindex", -1 );
550
+ equal( element.attr("tabindex"), "-1", "set negative tabindex" );
551
+ });
552
+
553
+ test( "removeAttr(String)", function() {
554
+ expect( 12 );
555
+ var $first;
556
+
557
+ equal( jQuery("#mark").removeAttr("class").attr("class"), undefined, "remove class" );
558
+ equal( jQuery("#form").removeAttr("id").attr("id"), undefined, "Remove id" );
559
+ equal( jQuery("#foo").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute" );
560
+ equal( jQuery("#form").attr( "style", "position:absolute;" ).removeAttr("style").attr("style"), undefined, "Check removing style attribute on a form" );
561
+ equal( jQuery("<div style='position: absolute'></div>").appendTo("#foo").removeAttr("style").prop("style").cssText, "", "Check removing style attribute (#9699 Webkit)" );
562
+ equal( jQuery("#fx-test-group").attr( "height", "3px" ).removeAttr("height").get( 0 ).style.height, "1px", "Removing height attribute has no effect on height set with style attribute" );
563
+
564
+ jQuery("#check1").removeAttr("checked").prop( "checked", true ).removeAttr("checked");
565
+ equal( document.getElementById("check1").checked, false, "removeAttr sets boolean properties to false" );
566
+ jQuery("#text1").prop( "readOnly", true ).removeAttr("readonly");
567
+ equal( document.getElementById("text1").readOnly, false, "removeAttr sets boolean properties to false" );
568
+
569
+ jQuery("#option2c").removeAttr("selected");
570
+ equal( jQuery("#option2d").attr("selected"), "selected", "Removing `selected` from an option that is not selected does not remove selected from the currently selected option (#10870)" );
571
+
572
+ try {
573
+ $first = jQuery("#first").attr( "contenteditable", "true" ).removeAttr("contenteditable");
574
+ equal( $first.attr("contenteditable"), undefined, "Remove the contenteditable attribute" );
575
+ } catch( e ) {
576
+ ok( false, "Removing contenteditable threw an error (#10429)" );
577
+ }
578
+
579
+ $first = jQuery("<div Case='mixed'></div>");
580
+ equal( $first.attr("Case"), "mixed", "case of attribute doesn't matter" );
581
+ $first.removeAttr("Case");
582
+ // IE 6/7 return empty string here, not undefined
583
+ ok( !$first.attr("Case"), "mixed-case attribute was removed" );
584
+ });
585
+
586
+ test( "removeAttr(String) in XML", function() {
587
+ expect( 7 );
588
+ var xml = createDashboardXML(),
589
+ iwt = jQuery( "infowindowtab", xml );
590
+
591
+ equal( iwt.attr("normal"), "ab", "Check initial value" );
592
+ iwt.removeAttr("Normal");
593
+ equal( iwt.attr("normal"), "ab", "Should still be there" );
594
+ iwt.removeAttr("normal");
595
+ equal( iwt.attr("normal"), undefined, "Removed" );
596
+
597
+ equal( iwt.attr("mixedCase"), "yes", "Check initial value" );
598
+ equal( iwt.attr("mixedcase"), undefined, "toLowerCase not work good" );
599
+ iwt.removeAttr("mixedcase");
600
+ equal( iwt.attr("mixedCase"), "yes", "Should still be there" );
601
+ iwt.removeAttr("mixedCase");
602
+ equal( iwt.attr("mixedCase"), undefined, "Removed" );
603
+ });
604
+
605
+ test( "removeAttr(Multi String, variable space width)", function() {
606
+ expect( 8 );
607
+
608
+ var div = jQuery("<div id='a' alt='b' title='c' rel='d'></div>"),
609
+ tests = {
610
+ id: "a",
611
+ alt: "b",
612
+ title: "c",
613
+ rel: "d"
614
+ };
615
+
616
+ jQuery.each( tests, function( key, val ) {
617
+ equal( div.attr( key ), val, "Attribute `" + key + "` exists, and has a value of `" + val + "`" );
618
+ });
619
+
620
+ div.removeAttr( "id alt title rel " );
621
+
622
+ jQuery.each( tests, function( key ) {
623
+ equal( div.attr( key ), undefined, "Attribute `" + key + "` was removed" );
624
+ });
625
+ });
626
+
627
+ test( "prop(String, Object)", function() {
628
+ expect( 31 );
629
+
630
+ equal( jQuery("#text1").prop("value"), "Test", "Check for value attribute" );
631
+ equal( jQuery("#text1").prop( "value", "Test2" ).prop("defaultValue"), "Test", "Check for defaultValue attribute" );
632
+ equal( jQuery("#select2").prop("selectedIndex"), 3, "Check for selectedIndex attribute" );
633
+ equal( jQuery("#foo").prop("nodeName").toUpperCase(), "DIV", "Check for nodeName attribute" );
634
+ equal( jQuery("#foo").prop("tagName").toUpperCase(), "DIV", "Check for tagName attribute" );
635
+ equal( jQuery("<option/>").prop("selected"), false, "Check selected attribute on disconnected element." );
636
+
637
+ equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "Check retrieving tabindex" );
638
+ jQuery("#text1").prop( "readonly", true );
639
+ equal( document.getElementById("text1").readOnly, true, "Check setting readOnly property with 'readonly'" );
640
+ equal( jQuery("#label-for").prop("for"), "action", "Check retrieving htmlFor" );
641
+ jQuery("#text1").prop("class", "test");
642
+ equal( document.getElementById("text1").className, "test", "Check setting className with 'class'" );
643
+ equal( jQuery("#text1").prop("maxlength"), 30, "Check retrieving maxLength" );
644
+ jQuery("#table").prop( "cellspacing", 1 );
645
+ equal( jQuery("#table").prop("cellSpacing"), "1", "Check setting and retrieving cellSpacing" );
646
+ jQuery("#table").prop( "cellpadding", 1 );
647
+ equal( jQuery("#table").prop("cellPadding"), "1", "Check setting and retrieving cellPadding" );
648
+ jQuery("#table").prop( "rowspan", 1 );
649
+ equal( jQuery("#table").prop("rowSpan"), 1, "Check setting and retrieving rowSpan" );
650
+ jQuery("#table").prop( "colspan", 1 );
651
+ equal( jQuery("#table").prop("colSpan"), 1, "Check setting and retrieving colSpan" );
652
+ jQuery("#table").prop( "usemap", 1 );
653
+ equal( jQuery("#table").prop("useMap"), 1, "Check setting and retrieving useMap" );
654
+ jQuery("#table").prop( "frameborder", 1 );
655
+ equal( jQuery("#table").prop("frameBorder"), 1, "Check setting and retrieving frameBorder" );
656
+ QUnit.reset();
657
+
658
+ var select, optgroup, option, attributeNode, commentNode, textNode, obj, $form,
659
+ body = document.body,
660
+ $body = jQuery( body );
661
+
662
+ ok( $body.prop("nextSibling") === null, "Make sure a null expando returns null" );
663
+ body["foo"] = "bar";
664
+ equal( $body.prop("foo"), "bar", "Make sure the expando is preferred over the dom attribute" );
665
+ body["foo"] = undefined;
666
+ ok( $body.prop("foo") === undefined, "Make sure the expando is preferred over the dom attribute, even if undefined" );
667
+
668
+ select = document.createElement("select");
669
+ optgroup = document.createElement("optgroup");
670
+ option = document.createElement("option");
671
+
672
+ optgroup.appendChild( option );
673
+ select.appendChild( optgroup );
674
+
675
+ equal( jQuery( option ).prop("selected"), true, "Make sure that a single option is selected, even when in an optgroup." );
676
+ equal( jQuery( document ).prop("nodeName"), "#document", "prop works correctly on document nodes (bug #7451)." );
677
+
678
+ attributeNode = document.createAttribute("irrelevant");
679
+ commentNode = document.createComment("some comment");
680
+ textNode = document.createTextNode("some text");
681
+ obj = {};
682
+ jQuery.each( [ document, attributeNode, commentNode, textNode, obj, "#firstp" ], function( i, ele ) {
683
+ strictEqual( jQuery( ele ).prop("nonexisting"), undefined, "prop works correctly for non existing attributes (bug #7500)." );
684
+ });
685
+
686
+ obj = {};
687
+ jQuery.each( [ document, obj ], function( i, ele ) {
688
+ var $ele = jQuery( ele );
689
+ $ele.prop( "nonexisting", "foo" );
690
+ equal( $ele.prop("nonexisting"), "foo", "prop(name, value) works correctly for non existing attributes (bug #7500)." );
691
+ });
692
+ jQuery( document ).removeProp("nonexisting");
693
+
694
+ $form = jQuery("#form").prop( "enctype", "multipart/form-data" );
695
+ equal( $form.prop("enctype"), "multipart/form-data", "Set the enctype of a form (encoding in IE6/7 #6743)" );
696
+ });
697
+
698
+ test( "prop('tabindex')", function() {
699
+ expect( 11 );
700
+
701
+ // inputs without tabIndex attribute
702
+ equal( jQuery("#inputWithoutTabIndex").prop("tabindex"), 0, "input without tabindex" );
703
+ equal( jQuery("#buttonWithoutTabIndex").prop("tabindex"), 0, "button without tabindex" );
704
+ equal( jQuery("#textareaWithoutTabIndex").prop("tabindex"), 0, "textarea without tabindex" );
705
+
706
+ // elements not natively tabbable
707
+ equal( jQuery("#listWithTabIndex").prop("tabindex"), 5, "not natively tabbable, with tabindex set to 0" );
708
+ equal( jQuery("#divWithNoTabIndex").prop("tabindex"), -1, "not natively tabbable, no tabindex set" );
709
+
710
+ // anchor with href
711
+ equal( jQuery("#linkWithNoTabIndex").prop("tabindex"), 0, "anchor with href, no tabindex set" );
712
+ equal( jQuery("#linkWithTabIndex").prop("tabindex"), 2, "anchor with href, tabindex set to 2" );
713
+ equal( jQuery("#linkWithNegativeTabIndex").prop("tabindex"), -1, "anchor with href, tabindex set to -1" );
714
+
715
+ // anchor without href
716
+ equal( jQuery("#linkWithNoHrefWithNoTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
717
+ equal( jQuery("#linkWithNoHrefWithTabIndex").prop("tabindex"), 1, "anchor without href, tabindex set to 2" );
718
+ equal( jQuery("#linkWithNoHrefWithNegativeTabIndex").prop("tabindex"), -1, "anchor without href, no tabindex set" );
719
+ });
720
+
721
+ test( "prop('tabindex', value)", 10, function() {
722
+
723
+ var clone,
724
+ element = jQuery("#divWithNoTabIndex");
725
+
726
+ equal( element.prop("tabindex"), -1, "start with no tabindex" );
727
+
728
+ // set a positive string
729
+ element.prop( "tabindex", "1" );
730
+ equal( element.prop("tabindex"), 1, "set tabindex to 1 (string)" );
731
+
732
+ // set a zero string
733
+ element.prop( "tabindex", "0" );
734
+ equal( element.prop("tabindex"), 0, "set tabindex to 0 (string)" );
735
+
736
+ // set a negative string
737
+ element.prop( "tabindex", "-1" );
738
+ equal( element.prop("tabindex"), -1, "set tabindex to -1 (string)" );
739
+
740
+ // set a positive number
741
+ element.prop( "tabindex", 1 );
742
+ equal( element.prop("tabindex"), 1, "set tabindex to 1 (number)" );
743
+
744
+ // set a zero number
745
+ element.prop( "tabindex", 0 );
746
+ equal( element.prop("tabindex"), 0, "set tabindex to 0 (number)" );
747
+
748
+ // set a negative number
749
+ element.prop( "tabindex", -1 );
750
+ equal( element.prop("tabindex"), -1, "set tabindex to -1 (number)" );
751
+
752
+ element = jQuery("#linkWithTabIndex");
753
+ equal( element.prop("tabindex"), 2, "start with tabindex 2" );
754
+
755
+ element.prop( "tabindex", -1 );
756
+ equal( element.prop("tabindex"), -1, "set negative tabindex" );
757
+
758
+ clone = element.clone();
759
+ clone.prop( "tabindex", 1 );
760
+ equal( clone[ 0 ].getAttribute("tabindex"), "1", "set tabindex on cloned element" );
761
+ });
762
+
763
+ test( "removeProp(String)", function() {
764
+ expect( 6 );
765
+ var attributeNode = document.createAttribute("irrelevant"),
766
+ commentNode = document.createComment("some comment"),
767
+ textNode = document.createTextNode("some text"),
768
+ obj = {};
769
+
770
+ strictEqual(
771
+ jQuery( "#firstp" ).prop( "nonexisting", "foo" ).removeProp( "nonexisting" )[ 0 ]["nonexisting"],
772
+ undefined,
773
+ "removeprop works correctly on DOM element nodes"
774
+ );
775
+
776
+ jQuery.each( [ document, obj ], function( i, ele ) {
777
+ var $ele = jQuery( ele );
778
+ $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
779
+ strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
780
+ });
781
+ jQuery.each( [ commentNode, textNode, attributeNode ], function( i, ele ) {
782
+ var $ele = jQuery( ele );
783
+ $ele.prop( "nonexisting", "foo" ).removeProp("nonexisting");
784
+ strictEqual( ele["nonexisting"], undefined, "removeProp works correctly on non DOM element nodes (bug #7500)." );
785
+ });
786
+ });
787
+
788
+ test( "val()", function() {
789
+ expect( 21 + ( jQuery.fn.serialize ? 6 : 0 ) );
790
+
791
+ var checks, $button;
792
+
793
+ document.getElementById("text1").value = "bla";
794
+ equal( jQuery("#text1").val(), "bla", "Check for modified value of input element" );
795
+
796
+ QUnit.reset();
797
+
798
+ equal( jQuery("#text1").val(), "Test", "Check for value of input element" );
799
+ // ticket #1714 this caused a JS error in IE
800
+ equal( jQuery("#first").val(), "", "Check a paragraph element to see if it has a value" );
801
+ ok( jQuery([]).val() === undefined, "Check an empty jQuery object will return undefined from val" );
802
+
803
+ equal( jQuery("#select2").val(), "3", "Call val() on a single='single' select" );
804
+
805
+ deepEqual( jQuery("#select3").val(), [ "1", "2" ], "Call val() on a multiple='multiple' select" );
806
+
807
+ equal( jQuery("#option3c").val(), "2", "Call val() on a option element with value" );
808
+
809
+ equal( jQuery("#option3a").val(), "", "Call val() on a option element with empty value" );
810
+
811
+ equal( jQuery("#option3e").val(), "no value", "Call val() on a option element with no value attribute" );
812
+
813
+ equal( jQuery("#option3a").val(), "", "Call val() on a option element with no value attribute" );
814
+
815
+ jQuery("#select3").val("");
816
+ deepEqual( jQuery("#select3").val(), [""], "Call val() on a multiple='multiple' select" );
817
+
818
+ deepEqual( jQuery("#select4").val(), [], "Call val() on multiple='multiple' select with all disabled options" );
819
+
820
+ jQuery("#select4 optgroup").add("#select4 > [disabled]").attr( "disabled", false );
821
+ deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on multiple='multiple' select with some disabled options" );
822
+
823
+ jQuery("#select4").attr( "disabled", true );
824
+ deepEqual( jQuery("#select4").val(), [ "2", "3" ], "Call val() on disabled multiple='multiple' select" );
825
+
826
+ equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
827
+
828
+ jQuery("#select5").val( 1 );
829
+ equal( jQuery("#select5").val(), "1", "Check value on ambiguous select." );
830
+
831
+ jQuery("#select5").val( 3 );
832
+ equal( jQuery("#select5").val(), "3", "Check value on ambiguous select." );
833
+
834
+ strictEqual(
835
+ jQuery("<select name='select12584' id='select12584'><option value='1' disabled='disabled'>1</option></select>").val(),
836
+ null,
837
+ "Select-one with only option disabled (#12584)"
838
+ );
839
+
840
+ if ( jQuery.fn.serialize ) {
841
+ checks = jQuery("<input type='checkbox' name='test' value='1'/><input type='checkbox' name='test' value='2'/><input type='checkbox' name='test' value=''/><input type='checkbox' name='test'/>").appendTo("#form");
842
+
843
+ deepEqual( checks.serialize(), "", "Get unchecked values." );
844
+
845
+ equal( checks.eq( 3 ).val(), "on", "Make sure a value of 'on' is provided if none is specified." );
846
+
847
+ checks.val([ "2" ]);
848
+ deepEqual( checks.serialize(), "test=2", "Get a single checked value." );
849
+
850
+ checks.val([ "1", "" ]);
851
+ deepEqual( checks.serialize(), "test=1&test=", "Get multiple checked values." );
852
+
853
+ checks.val([ "", "2" ]);
854
+ deepEqual( checks.serialize(), "test=2&test=", "Get multiple checked values." );
855
+
856
+ checks.val([ "1", "on" ]);
857
+ deepEqual( checks.serialize(), "test=1&test=on", "Get multiple checked values." );
858
+
859
+ checks.remove();
860
+ }
861
+
862
+ $button = jQuery("<button value='foobar'>text</button>").insertAfter("#button");
863
+ equal( $button.val(), "foobar", "Value retrieval on a button does not return innerHTML" );
864
+ equal( $button.val("baz").html(), "text", "Setting the value does not change innerHTML" );
865
+
866
+ equal( jQuery("<option/>").val("test").attr("value"), "test", "Setting value sets the value attribute" );
867
+ });
868
+
869
+ test("val() with non-matching values on dropdown list", function() {
870
+ expect( 3 );
871
+
872
+ jQuery("#select5").val( "" );
873
+ equal( jQuery("#select5").val(), null, "Non-matching set on select-one" );
874
+
875
+ var select6 = jQuery("<select multiple id=\"select6\"><option value=\"1\">A</option><option value=\"2\">B</option></select>").appendTo("#form");
876
+ jQuery(select6).val( "nothing" );
877
+ equal( jQuery(select6).val(), null, "Non-matching set (single value) on select-multiple" );
878
+
879
+ jQuery(select6).val( ["nothing1", "nothing2"] );
880
+ equal( jQuery(select6).val(), null, "Non-matching set (array of values) on select-multiple" );
881
+
882
+ select6.remove();
883
+ });
884
+
885
+ if ( "value" in document.createElement("meter") &&
886
+ "value" in document.createElement("progress") ) {
887
+
888
+ test( "val() respects numbers without exception (Bug #9319)", function() {
889
+
890
+ expect( 4 );
891
+
892
+ var $meter = jQuery("<meter min='0' max='10' value='5.6'></meter>"),
893
+ $progress = jQuery("<progress max='10' value='1.5'></progress>");
894
+
895
+ try {
896
+ equal( typeof $meter.val(), "number", "meter, returns a number and does not throw exception" );
897
+ equal( $meter.val(), $meter[ 0 ].value, "meter, api matches host and does not throw exception" );
898
+
899
+ equal( typeof $progress.val(), "number", "progress, returns a number and does not throw exception" );
900
+ equal( $progress.val(), $progress[ 0 ].value, "progress, api matches host and does not throw exception" );
901
+
902
+ } catch( e ) {}
903
+
904
+ $meter.remove();
905
+ $progress.remove();
906
+ });
907
+ }
908
+
909
+ var testVal = function( valueObj ) {
910
+ expect( 8 );
911
+
912
+ QUnit.reset();
913
+ jQuery("#text1").val( valueObj("test") );
914
+ equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
915
+
916
+ jQuery("#text1").val( valueObj( undefined ) );
917
+ equal( document.getElementById("text1").value, "", "Check for modified (via val(undefined)) value of input element" );
918
+
919
+ jQuery("#text1").val( valueObj( 67 ) );
920
+ equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
921
+
922
+ jQuery("#text1").val( valueObj( null ) );
923
+ equal( document.getElementById("text1").value, "", "Check for modified (via val(null)) value of input element" );
924
+
925
+ var j,
926
+ $select1 = jQuery("#select1");
927
+ $select1.val( valueObj("3") );
928
+ equal( $select1.val(), "3", "Check for modified (via val(String)) value of select element" );
929
+
930
+ $select1.val( valueObj( 2 ) );
931
+ equal( $select1.val(), "2", "Check for modified (via val(Number)) value of select element" );
932
+
933
+ $select1.append("<option value='4'>four</option>");
934
+ $select1.val( valueObj( 4 ) );
935
+ equal( $select1.val(), "4", "Should be possible to set the val() to a newly created option" );
936
+
937
+ // using contents will get comments regular, text, and comment nodes
938
+ j = jQuery("#nonnodes").contents();
939
+ j.val( valueObj( "asdf" ) );
940
+ equal( j.val(), "asdf", "Check node,textnode,comment with val()" );
941
+ j.removeAttr("value");
942
+ };
943
+
944
+ test( "val(String/Number)", function() {
945
+ testVal( bareObj );
946
+ });
947
+
948
+ test( "val(Function)", function() {
949
+ testVal( functionReturningObj );
950
+ });
951
+
952
+ test( "val(Array of Numbers) (Bug #7123)", function() {
953
+ expect( 4 );
954
+ jQuery("#form").append("<input type='checkbox' name='arrayTest' value='1' /><input type='checkbox' name='arrayTest' value='2' /><input type='checkbox' name='arrayTest' value='3' checked='checked' /><input type='checkbox' name='arrayTest' value='4' />");
955
+ var elements = jQuery("input[name=arrayTest]").val([ 1, 2 ]);
956
+ ok( elements[ 0 ].checked, "First element was checked" );
957
+ ok( elements[ 1 ].checked, "Second element was checked" );
958
+ ok( !elements[ 2 ].checked, "Third element was unchecked" );
959
+ ok( !elements[ 3 ].checked, "Fourth element remained unchecked" );
960
+
961
+ elements.remove();
962
+ });
963
+
964
+ test( "val(Function) with incoming value", function() {
965
+ expect( 10 );
966
+
967
+ QUnit.reset();
968
+ var oldVal = jQuery("#text1").val();
969
+
970
+ jQuery("#text1").val(function( i, val ) {
971
+ equal( val, oldVal, "Make sure the incoming value is correct." );
972
+ return "test";
973
+ });
974
+
975
+ equal( document.getElementById("text1").value, "test", "Check for modified (via val(String)) value of input element" );
976
+
977
+ oldVal = jQuery("#text1").val();
978
+
979
+ jQuery("#text1").val(function( i, val ) {
980
+ equal( val, oldVal, "Make sure the incoming value is correct." );
981
+ return 67;
982
+ });
983
+
984
+ equal( document.getElementById("text1").value, "67", "Check for modified (via val(Number)) value of input element" );
985
+
986
+ oldVal = jQuery("#select1").val();
987
+
988
+ jQuery("#select1").val(function( i, val ) {
989
+ equal( val, oldVal, "Make sure the incoming value is correct." );
990
+ return "3";
991
+ });
992
+
993
+ equal( jQuery("#select1").val(), "3", "Check for modified (via val(String)) value of select element" );
994
+
995
+ oldVal = jQuery("#select1").val();
996
+
997
+ jQuery("#select1").val(function( i, val ) {
998
+ equal( val, oldVal, "Make sure the incoming value is correct." );
999
+ return 2;
1000
+ });
1001
+
1002
+ equal( jQuery("#select1").val(), "2", "Check for modified (via val(Number)) value of select element" );
1003
+
1004
+ jQuery("#select1").append("<option value='4'>four</option>");
1005
+
1006
+ oldVal = jQuery("#select1").val();
1007
+
1008
+ jQuery("#select1").val(function( i, val ) {
1009
+ equal( val, oldVal, "Make sure the incoming value is correct." );
1010
+ return 4;
1011
+ });
1012
+
1013
+ equal( jQuery("#select1").val(), "4", "Should be possible to set the val() to a newly created option" );
1014
+ });
1015
+
1016
+ // testing if a form.reset() breaks a subsequent call to a select element's .val() (in IE only)
1017
+ test( "val(select) after form.reset() (Bug #2551)", function() {
1018
+ expect( 3 );
1019
+
1020
+ jQuery("<form id='kk' name='kk'><select id='kkk'><option value='cf'>cf</option><option value='gf'>gf</option></select></form>").appendTo("#qunit-fixture");
1021
+
1022
+ jQuery("#kkk").val("gf");
1023
+
1024
+ document["kk"].reset();
1025
+
1026
+ equal( jQuery("#kkk")[ 0 ].value, "cf", "Check value of select after form reset." );
1027
+ equal( jQuery("#kkk").val(), "cf", "Check value of select after form reset." );
1028
+
1029
+ // re-verify the multi-select is not broken (after form.reset) by our fix for single-select
1030
+ deepEqual( jQuery("#select3").val(), ["1", "2"], "Call val() on a multiple='multiple' select" );
1031
+
1032
+ jQuery("#kk").remove();
1033
+ });
1034
+
1035
+ var testAddClass = function( valueObj ) {
1036
+ expect( 9 );
1037
+
1038
+ var pass, j, i,
1039
+ div = jQuery("#qunit-fixture div");
1040
+
1041
+ div.addClass( valueObj("test") );
1042
+ pass = true;
1043
+ for ( i = 0; i < div.length; i++ ) {
1044
+ if ( !~div.get( i ).className.indexOf("test") ) {
1045
+ pass = false;
1046
+ }
1047
+ }
1048
+ ok( pass, "Add Class" );
1049
+
1050
+ // using contents will get regular, text, and comment nodes
1051
+ j = jQuery("#nonnodes").contents();
1052
+ j.addClass( valueObj("asdf") );
1053
+ ok( j.hasClass("asdf"), "Check node,textnode,comment for addClass" );
1054
+
1055
+ div = jQuery("<div/>");
1056
+
1057
+ div.addClass( valueObj("test") );
1058
+ equal( div.attr("class"), "test", "Make sure there's no extra whitespace." );
1059
+
1060
+ div.attr( "class", " foo" );
1061
+ div.addClass( valueObj("test") );
1062
+ equal( div.attr("class"), "foo test", "Make sure there's no extra whitespace." );
1063
+
1064
+ div.attr( "class", "foo" );
1065
+ div.addClass( valueObj("bar baz") );
1066
+ equal( div.attr("class"), "foo bar baz", "Make sure there isn't too much trimming." );
1067
+
1068
+ div.removeClass();
1069
+ div.addClass( valueObj("foo") ).addClass( valueObj("foo") );
1070
+ equal( div.attr("class"), "foo", "Do not add the same class twice in separate calls." );
1071
+
1072
+ div.addClass( valueObj("fo") );
1073
+ equal( div.attr("class"), "foo fo", "Adding a similar class does not get interrupted." );
1074
+ div.removeClass().addClass("wrap2");
1075
+ ok( div.addClass("wrap").hasClass("wrap"), "Can add similarly named classes");
1076
+
1077
+ div.removeClass();
1078
+ div.addClass( valueObj("bar bar") );
1079
+ equal( div.attr("class"), "bar", "Do not add the same class twice in the same call." );
1080
+ };
1081
+
1082
+ test( "addClass(String)", function() {
1083
+ testAddClass( bareObj );
1084
+ });
1085
+
1086
+ test( "addClass(Function)", function() {
1087
+ testAddClass( functionReturningObj );
1088
+ });
1089
+
1090
+ test( "addClass(Function) with incoming value", function() {
1091
+ expect( 52 );
1092
+ var pass, i,
1093
+ div = jQuery("#qunit-fixture div"),
1094
+ old = div.map(function() {
1095
+ return jQuery(this).attr("class") || "";
1096
+ });
1097
+
1098
+ div.addClass(function( i, val ) {
1099
+ if ( this.id !== "_firebugConsole" ) {
1100
+ equal( val, old[ i ], "Make sure the incoming value is correct." );
1101
+ return "test";
1102
+ }
1103
+ });
1104
+
1105
+ pass = true;
1106
+ for ( i = 0; i < div.length; i++ ) {
1107
+ if ( div.get(i).className.indexOf("test") === -1 ) {
1108
+ pass = false;
1109
+ }
1110
+ }
1111
+ ok( pass, "Add Class" );
1112
+ });
1113
+
1114
+ var testRemoveClass = function(valueObj) {
1115
+ expect( 8 );
1116
+
1117
+ var $set = jQuery("#qunit-fixture div"),
1118
+ div = document.createElement("div");
1119
+
1120
+ $set.addClass("test").removeClass( valueObj("test") );
1121
+
1122
+ ok( !$set.is(".test"), "Remove Class" );
1123
+
1124
+ $set.addClass("test").addClass("foo").addClass("bar");
1125
+ $set.removeClass( valueObj("test") ).removeClass( valueObj("bar") ).removeClass( valueObj("foo") );
1126
+
1127
+ ok( !$set.is(".test,.bar,.foo"), "Remove multiple classes" );
1128
+
1129
+ // Make sure that a null value doesn't cause problems
1130
+ $set.eq( 0 ).addClass("expected").removeClass( valueObj( null ) );
1131
+ ok( $set.eq( 0 ).is(".expected"), "Null value passed to removeClass" );
1132
+
1133
+ $set.eq( 0 ).addClass("expected").removeClass( valueObj("") );
1134
+ ok( $set.eq( 0 ).is(".expected"), "Empty string passed to removeClass" );
1135
+
1136
+ // using contents will get regular, text, and comment nodes
1137
+ $set = jQuery("#nonnodes").contents();
1138
+ $set.removeClass( valueObj("asdf") );
1139
+ ok( !$set.hasClass("asdf"), "Check node,textnode,comment for removeClass" );
1140
+
1141
+
1142
+ jQuery( div ).removeClass( valueObj("foo") );
1143
+ strictEqual( jQuery( div ).attr("class"), undefined, "removeClass doesn't create a class attribute" );
1144
+
1145
+ div.className = " test foo ";
1146
+
1147
+ jQuery( div ).removeClass( valueObj("foo") );
1148
+ equal( div.className, "test", "Make sure remaining className is trimmed." );
1149
+
1150
+ div.className = " test ";
1151
+
1152
+ jQuery( div ).removeClass( valueObj("test") );
1153
+ equal( div.className, "", "Make sure there is nothing left after everything is removed." );
1154
+ };
1155
+
1156
+ test( "removeClass(String) - simple", function() {
1157
+ testRemoveClass( bareObj );
1158
+ });
1159
+
1160
+ test( "removeClass(Function) - simple", function() {
1161
+ testRemoveClass( functionReturningObj );
1162
+ });
1163
+
1164
+ test( "removeClass(Function) with incoming value", function() {
1165
+ expect( 52 );
1166
+
1167
+ var $divs = jQuery("#qunit-fixture div").addClass("test"), old = $divs.map(function() {
1168
+ return jQuery( this ).attr("class");
1169
+ });
1170
+
1171
+ $divs.removeClass(function( i, val ) {
1172
+ if ( this.id !== "_firebugConsole" ) {
1173
+ equal( val, old[ i ], "Make sure the incoming value is correct." );
1174
+ return "test";
1175
+ }
1176
+ });
1177
+
1178
+ ok( !$divs.is(".test"), "Remove Class" );
1179
+ });
1180
+
1181
+ test( "removeClass() removes duplicates", function() {
1182
+ expect( 1 );
1183
+
1184
+ var $div = jQuery( jQuery.parseHTML("<div class='x x x'></div>") );
1185
+
1186
+ $div.removeClass("x");
1187
+
1188
+ ok( !$div.hasClass("x"), "Element with multiple same classes does not escape the wrath of removeClass()" );
1189
+ });
1190
+
1191
+ test("removeClass(undefined) is a no-op", function() {
1192
+ expect( 1 );
1193
+
1194
+ var $div = jQuery("<div class='base second'></div>");
1195
+ $div.removeClass( undefined );
1196
+
1197
+ ok( $div.hasClass("base") && $div.hasClass("second"), "Element still has classes after removeClass(undefined)" );
1198
+ });
1199
+
1200
+ var testToggleClass = function(valueObj) {
1201
+ expect( 17 );
1202
+
1203
+ var e = jQuery("#firstp");
1204
+ ok( !e.is(".test"), "Assert class not present" );
1205
+ e.toggleClass( valueObj("test") );
1206
+ ok( e.is(".test"), "Assert class present" );
1207
+ e.toggleClass( valueObj("test") );
1208
+ ok( !e.is(".test"), "Assert class not present" );
1209
+
1210
+ // class name with a boolean
1211
+ e.toggleClass( valueObj("test"), false );
1212
+ ok( !e.is(".test"), "Assert class not present" );
1213
+ e.toggleClass( valueObj("test"), true );
1214
+ ok( e.is(".test"), "Assert class present" );
1215
+ e.toggleClass( valueObj("test"), false );
1216
+ ok( !e.is(".test"), "Assert class not present" );
1217
+
1218
+ // multiple class names
1219
+ e.addClass("testA testB");
1220
+ ok( e.is(".testA.testB"), "Assert 2 different classes present" );
1221
+ e.toggleClass( valueObj("testB testC") );
1222
+ ok( (e.is(".testA.testC") && !e.is(".testB")), "Assert 1 class added, 1 class removed, and 1 class kept" );
1223
+ e.toggleClass( valueObj("testA testC") );
1224
+ ok( (!e.is(".testA") && !e.is(".testB") && !e.is(".testC")), "Assert no class present" );
1225
+
1226
+ // toggleClass storage
1227
+ e.toggleClass( true );
1228
+ ok( e[ 0 ].className === "", "Assert class is empty (data was empty)" );
1229
+ e.addClass("testD testE");
1230
+ ok( e.is(".testD.testE"), "Assert class present" );
1231
+ e.toggleClass();
1232
+ ok( !e.is(".testD.testE"), "Assert class not present" );
1233
+ ok( jQuery._data(e[ 0 ], "__className__") === "testD testE", "Assert data was stored" );
1234
+ e.toggleClass();
1235
+ ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
1236
+ e.toggleClass( false );
1237
+ ok( !e.is(".testD.testE"), "Assert class not present" );
1238
+ e.toggleClass( true );
1239
+ ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
1240
+ e.toggleClass();
1241
+ e.toggleClass( false );
1242
+ e.toggleClass();
1243
+ ok( e.is(".testD.testE"), "Assert class present (restored from data)" );
1244
+
1245
+ // Cleanup
1246
+ e.removeClass("testD");
1247
+ QUnit.expectJqData( e[ 0 ], "__className__" );
1248
+ };
1249
+
1250
+ test( "toggleClass(String|boolean|undefined[, boolean])", function() {
1251
+ testToggleClass( bareObj );
1252
+ });
1253
+
1254
+ test( "toggleClass(Function[, boolean])", function() {
1255
+ testToggleClass( functionReturningObj );
1256
+ });
1257
+
1258
+ test( "toggleClass(Function[, boolean]) with incoming value", function() {
1259
+ expect( 14 );
1260
+
1261
+ var e = jQuery("#firstp"),
1262
+ old = e.attr("class") || "";
1263
+
1264
+ ok( !e.is(".test"), "Assert class not present" );
1265
+
1266
+ e.toggleClass(function( i, val ) {
1267
+ equal( old, val, "Make sure the incoming value is correct." );
1268
+ return "test";
1269
+ });
1270
+ ok( e.is(".test"), "Assert class present" );
1271
+
1272
+ old = e.attr("class");
1273
+
1274
+ e.toggleClass(function( i, val ) {
1275
+ equal( old, val, "Make sure the incoming value is correct." );
1276
+ return "test";
1277
+ });
1278
+ ok( !e.is(".test"), "Assert class not present" );
1279
+
1280
+ old = e.attr("class") || "";
1281
+
1282
+ // class name with a boolean
1283
+ e.toggleClass(function( i, val, state ) {
1284
+ equal( old, val, "Make sure the incoming value is correct." );
1285
+ equal( state, false, "Make sure that the state is passed in." );
1286
+ return "test";
1287
+ }, false );
1288
+ ok( !e.is(".test"), "Assert class not present" );
1289
+
1290
+ old = e.attr("class") || "";
1291
+
1292
+ e.toggleClass(function( i, val, state ) {
1293
+ equal( old, val, "Make sure the incoming value is correct." );
1294
+ equal( state, true, "Make sure that the state is passed in." );
1295
+ return "test";
1296
+ }, true );
1297
+ ok( e.is(".test"), "Assert class present" );
1298
+
1299
+ old = e.attr("class");
1300
+
1301
+ e.toggleClass(function( i, val, state ) {
1302
+ equal( old, val, "Make sure the incoming value is correct." );
1303
+ equal( state, false, "Make sure that the state is passed in." );
1304
+ return "test";
1305
+ }, false );
1306
+ ok( !e.is(".test"), "Assert class not present" );
1307
+ });
1308
+
1309
+ test( "addClass, removeClass, hasClass", function() {
1310
+ expect( 17 );
1311
+
1312
+ var jq = jQuery("<p>Hi</p>"), x = jq[ 0 ];
1313
+
1314
+ jq.addClass("hi");
1315
+ equal( x.className, "hi", "Check single added class" );
1316
+
1317
+ jq.addClass("foo bar");
1318
+ equal( x.className, "hi foo bar", "Check more added classes" );
1319
+
1320
+ jq.removeClass();
1321
+ equal( x.className, "", "Remove all classes" );
1322
+
1323
+ jq.addClass("hi foo bar");
1324
+ jq.removeClass("foo");
1325
+ equal( x.className, "hi bar", "Check removal of one class" );
1326
+
1327
+ ok( jq.hasClass("hi"), "Check has1" );
1328
+ ok( jq.hasClass("bar"), "Check has2" );
1329
+
1330
+ jq = jQuery("<p class='class1\nclass2\tcla.ss3\n\rclass4'></p>");
1331
+
1332
+ ok( jq.hasClass("class1"), "Check hasClass with line feed" );
1333
+ ok( jq.is(".class1"), "Check is with line feed" );
1334
+ ok( jq.hasClass("class2"), "Check hasClass with tab" );
1335
+ ok( jq.is(".class2"), "Check is with tab" );
1336
+ ok( jq.hasClass("cla.ss3"), "Check hasClass with dot" );
1337
+ ok( jq.hasClass("class4"), "Check hasClass with carriage return" );
1338
+ ok( jq.is(".class4"), "Check is with carriage return" );
1339
+
1340
+ jq.removeClass("class2");
1341
+ ok( jq.hasClass("class2") === false, "Check the class has been properly removed" );
1342
+ jq.removeClass("cla");
1343
+ ok( jq.hasClass("cla.ss3"), "Check the dotted class has not been removed" );
1344
+ jq.removeClass("cla.ss3");
1345
+ ok( jq.hasClass("cla.ss3") === false, "Check the dotted class has been removed" );
1346
+ jq.removeClass("class4");
1347
+ ok( jq.hasClass("class4") === false, "Check the class has been properly removed" );
1348
+ });
1349
+
1350
+ test( "contents().hasClass() returns correct values", function() {
1351
+ expect( 2 );
1352
+
1353
+ var $div = jQuery("<div><span class='foo'></span><!-- comment -->text</div>"),
1354
+ $contents = $div.contents();
1355
+
1356
+ ok( $contents.hasClass("foo"), "Found 'foo' in $contents" );
1357
+ ok( !$contents.hasClass("undefined"), "Did not find 'undefined' in $contents (correctly)" );
1358
+ });
1359
+
1360
+ test( "hasClass correctly interprets non-space separators (#13835)", function() {
1361
+ expect( 4 );
1362
+
1363
+ var
1364
+ map = {
1365
+ tab: "&#9;",
1366
+ "line-feed": "&#10;",
1367
+ "form-feed": "&#12;",
1368
+ "carriage-return": "&#13;"
1369
+ },
1370
+ classes = jQuery.map( map, function( separator, label ) {
1371
+ return " " + separator + label + separator + " ";
1372
+ }),
1373
+ $div = jQuery( "<div class='" + classes + "'></div>" );
1374
+
1375
+ jQuery.each( map, function( label ) {
1376
+ ok( $div.hasClass( label ), label.replace( "-", " " ) );
1377
+ });
1378
+ });
1379
+
1380
+ test( "coords returns correct values in IE6/IE7, see #10828", function() {
1381
+ expect( 1 );
1382
+
1383
+ var area,
1384
+ map = jQuery("<map />");
1385
+
1386
+ area = map.html("<area shape='rect' coords='0,0,0,0' href='#' alt='a' />").find("area");
1387
+ equal( area.attr("coords"), "0,0,0,0", "did not retrieve coords correctly" );
1388
+ });