├── .gitattributes ├── .gitignore ├── Gruntfile.js ├── MIT and GPL2 licenses.md ├── bower.json ├── composer.json ├── dist ├── html5shiv-printshiv.js ├── html5shiv-printshiv.min.js ├── html5shiv.js └── html5shiv.min.js ├── package.json ├── readme.md ├── src ├── html5shiv-printshiv.js └── html5shiv.js └── test ├── data ├── body-crash.jpg ├── iframed-tests.html ├── inline-mixed-media.css ├── inline-print-media.css ├── no-print.css ├── paramtracer.swf ├── print-styles.css ├── print.css └── screen.css ├── highcharts ├── area-basic.html └── highcharts.js ├── html5shiv.html ├── iframe.1-1.html ├── iframe.1-2.html ├── iframe.1.html ├── index.html ├── jquery-1.7.1 ├── data │ ├── dashboard.xml │ ├── iframe.html │ ├── test.js │ ├── testinit.js │ ├── testrunner.js │ ├── testsuite.css │ └── versioncheck.js ├── index.html └── unit │ ├── core.js │ ├── manipulation.js │ └── traversing.js ├── mixed-test.html ├── object-test.html ├── perf.1.html ├── perf.2.html ├── qunit ├── qunit.css └── qunit.js ├── style.all.css ├── style.css ├── style.print.css └── unit └── tests.js /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules -------------------------------------------------------------------------------- /Gruntfile.js: -------------------------------------------------------------------------------- 1 | /*global module:false*/ 2 | module.exports = function(grunt){ 3 | 4 | 5 | // Project configuration. 6 | grunt.initConfig({ 7 | pkg: grunt.file.readJSON('package.json'), 8 | bower: grunt.file.readJSON('bower.json'), 9 | copy: { 10 | demo: { 11 | files: [ 12 | {expand: true, src: ['src/*'], dest: 'dist/', filter: 'isFile', flatten: true} 13 | ] 14 | } 15 | }, 16 | 17 | uglify: { 18 | options: { 19 | beautify: { 20 | ascii_only : true 21 | }, 22 | preserveComments: 'some' 23 | }, 24 | html5shiv: { 25 | files: [{ 26 | expand: true, // Enable dynamic expansion. 27 | cwd: 'src/', // Src matches are relative to this path. 28 | src: ['**/*.js'], // Actual pattern(s) to match. 29 | dest: 'dist/', // Destination path prefix. 30 | ext: '.min.js' 31 | }] 32 | } 33 | }, 34 | watch: { 35 | js: { 36 | files: ['src/**/*.js'], 37 | tasks: ['copy', 'uglify', 'bytesize'] 38 | } 39 | }, 40 | bytesize: { 41 | all: { 42 | src: [ 43 | 'dist/**.min.js' 44 | ] 45 | } 46 | } 47 | }); 48 | 49 | 50 | // Default task. 51 | 52 | 53 | 54 | grunt.loadNpmTasks('grunt-contrib-copy'); 55 | grunt.loadNpmTasks('grunt-contrib-uglify'); 56 | grunt.loadNpmTasks('grunt-contrib-watch'); 57 | grunt.loadNpmTasks('grunt-bytesize'); 58 | 59 | grunt.registerTask('default', ['copy', 'uglify', 'bytesize', 'watch']); 60 | 61 | }; 62 | -------------------------------------------------------------------------------- /MIT and GPL2 licenses.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Alexander Farkas (aFarkas). 2 | 3 | This software is licensed under a dual license system (MIT or GPL version 2). 4 | This means you are free to choose with which of both licenses (MIT or 5 | GPL version 2) you want to use this library. 6 | 7 | The license texts of the MIT license and the GPL version 2 are as follows: 8 | 9 | 10 | ## MIT License 11 | 12 | Permission is hereby granted, free of charge, to any person obtaining a 13 | copy of this software and associated documentation files (the "Software"), 14 | to deal in the Software without restriction, including without limitation 15 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 16 | and/or sell copies of the Software, and to permit persons to whom the 17 | Software is furnished to do so, subject to the following conditions: 18 | 19 | The above copyright notice and this permission notice shall be included in 20 | all copies or substantial portions of the Software. 21 | 22 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 23 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 24 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 25 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 26 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 27 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 28 | DEALINGS IN THE SOFTWARE. 29 | 30 | 31 | 32 | ## GNU GENERAL PUBLIC LICENSE Version 2, June 1991 33 | 34 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 35 | 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 36 | Everyone is permitted to copy and distribute verbatim copies 37 | of this license document, but changing it is not allowed. 38 | 39 | Preamble 40 | 41 | The licenses for most software are designed to take away your 42 | freedom to share and change it. By contrast, the GNU General Public 43 | License is intended to guarantee your freedom to share and change free 44 | software--to make sure the software is free for all its users. This 45 | General Public License applies to most of the Free Software 46 | Foundation's software and to any other program whose authors commit to 47 | using it. (Some other Free Software Foundation software is covered by 48 | the GNU Library General Public License instead.) You can apply it to 49 | your programs, too. 50 | 51 | When we speak of free software, we are referring to freedom, not 52 | price. Our General Public Licenses are designed to make sure that you 53 | have the freedom to distribute copies of free software (and charge for 54 | this service if you wish), that you receive source code or can get it 55 | if you want it, that you can change the software or use pieces of it 56 | in new free programs; and that you know you can do these things. 57 | 58 | To protect your rights, we need to make restrictions that forbid 59 | anyone to deny you these rights or to ask you to surrender the rights. 60 | These restrictions translate to certain responsibilities for you if you 61 | distribute copies of the software, or if you modify it. 62 | 63 | For example, if you distribute copies of such a program, whether 64 | gratis or for a fee, you must give the recipients all the rights that 65 | you have. You must make sure that they, too, receive or can get the 66 | source code. And you must show them these terms so they know their 67 | rights. 68 | 69 | We protect your rights with two steps: (1) copyright the software, and 70 | (2) offer you this license which gives you legal permission to copy, 71 | distribute and/or modify the software. 72 | 73 | Also, for each author's protection and ours, we want to make certain 74 | that everyone understands that there is no warranty for this free 75 | software. If the software is modified by someone else and passed on, we 76 | want its recipients to know that what they have is not the original, so 77 | that any problems introduced by others will not reflect on the original 78 | authors' reputations. 79 | 80 | Finally, any free program is threatened constantly by software 81 | patents. We wish to avoid the danger that redistributors of a free 82 | program will individually obtain patent licenses, in effect making the 83 | program proprietary. To prevent this, we have made it clear that any 84 | patent must be licensed for everyone's free use or not licensed at all. 85 | 86 | The precise terms and conditions for copying, distribution and 87 | modification follow. 88 | 89 | GNU GENERAL PUBLIC LICENSE 90 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 91 | 92 | 0. This License applies to any program or other work which contains 93 | a notice placed by the copyright holder saying it may be distributed 94 | under the terms of this General Public License. The "Program", below, 95 | refers to any such program or work, and a "work based on the Program" 96 | means either the Program or any derivative work under copyright law: 97 | that is to say, a work containing the Program or a portion of it, 98 | either verbatim or with modifications and/or translated into another 99 | language. (Hereinafter, translation is included without limitation in 100 | the term "modification".) Each licensee is addressed as "you". 101 | 102 | Activities other than copying, distribution and modification are not 103 | covered by this License; they are outside its scope. The act of 104 | running the Program is not restricted, and the output from the Program 105 | is covered only if its contents constitute a work based on the 106 | Program (independent of having been made by running the Program). 107 | Whether that is true depends on what the Program does. 108 | 109 | 1. You may copy and distribute verbatim copies of the Program's 110 | source code as you receive it, in any medium, provided that you 111 | conspicuously and appropriately publish on each copy an appropriate 112 | copyright notice and disclaimer of warranty; keep intact all the 113 | notices that refer to this License and to the absence of any warranty; 114 | and give any other recipients of the Program a copy of this License 115 | along with the Program. 116 | 117 | You may charge a fee for the physical act of transferring a copy, and 118 | you may at your option offer warranty protection in exchange for a fee. 119 | 120 | 2. You may modify your copy or copies of the Program or any portion 121 | of it, thus forming a work based on the Program, and copy and 122 | distribute such modifications or work under the terms of Section 1 123 | above, provided that you also meet all of these conditions: 124 | 125 | a) You must cause the modified files to carry prominent notices 126 | stating that you changed the files and the date of any change. 127 | 128 | b) You must cause any work that you distribute or publish, that in 129 | whole or in part contains or is derived from the Program or any 130 | part thereof, to be licensed as a whole at no charge to all third 131 | parties under the terms of this License. 132 | 133 | c) If the modified program normally reads commands interactively 134 | when run, you must cause it, when started running for such 135 | interactive use in the most ordinary way, to print or display an 136 | announcement including an appropriate copyright notice and a 137 | notice that there is no warranty (or else, saying that you provide 138 | a warranty) and that users may redistribute the program under 139 | these conditions, and telling the user how to view a copy of this 140 | License. (Exception: if the Program itself is interactive but 141 | does not normally print such an announcement, your work based on 142 | the Program is not required to print an announcement.) 143 | 144 | These requirements apply to the modified work as a whole. If 145 | identifiable sections of that work are not derived from the Program, 146 | and can be reasonably considered independent and separate works in 147 | themselves, then this License, and its terms, do not apply to those 148 | sections when you distribute them as separate works. But when you 149 | distribute the same sections as part of a whole which is a work based 150 | on the Program, the distribution of the whole must be on the terms of 151 | this License, whose permissions for other licensees extend to the 152 | entire whole, and thus to each and every part regardless of who wrote it. 153 | 154 | Thus, it is not the intent of this section to claim rights or contest 155 | your rights to work written entirely by you; rather, the intent is to 156 | exercise the right to control the distribution of derivative or 157 | collective works based on the Program. 158 | 159 | In addition, mere aggregation of another work not based on the Program 160 | with the Program (or with a work based on the Program) on a volume of 161 | a storage or distribution medium does not bring the other work under 162 | the scope of this License. 163 | 164 | 3. You may copy and distribute the Program (or a work based on it, 165 | under Section 2) in object code or executable form under the terms of 166 | Sections 1 and 2 above provided that you also do one of the following: 167 | 168 | a) Accompany it with the complete corresponding machine-readable 169 | source code, which must be distributed under the terms of Sections 170 | 1 and 2 above on a medium customarily used for software interchange; or, 171 | 172 | b) Accompany it with a written offer, valid for at least three 173 | years, to give any third party, for a charge no more than your 174 | cost of physically performing source distribution, a complete 175 | machine-readable copy of the corresponding source code, to be 176 | distributed under the terms of Sections 1 and 2 above on a medium 177 | customarily used for software interchange; or, 178 | 179 | c) Accompany it with the information you received as to the offer 180 | to distribute corresponding source code. (This alternative is 181 | allowed only for noncommercial distribution and only if you 182 | received the program in object code or executable form with such 183 | an offer, in accord with Subsection b above.) 184 | 185 | The source code for a work means the preferred form of the work for 186 | making modifications to it. For an executable work, complete source 187 | code means all the source code for all modules it contains, plus any 188 | associated interface definition files, plus the scripts used to 189 | control compilation and installation of the executable. However, as a 190 | special exception, the source code distributed need not include 191 | anything that is normally distributed (in either source or binary 192 | form) with the major components (compiler, kernel, and so on) of the 193 | operating system on which the executable runs, unless that component 194 | itself accompanies the executable. 195 | 196 | If distribution of executable or object code is made by offering 197 | access to copy from a designated place, then offering equivalent 198 | access to copy the source code from the same place counts as 199 | distribution of the source code, even though third parties are not 200 | compelled to copy the source along with the object code. 201 | 202 | 4. You may not copy, modify, sublicense, or distribute the Program 203 | except as expressly provided under this License. Any attempt 204 | otherwise to copy, modify, sublicense or distribute the Program is 205 | void, and will automatically terminate your rights under this License. 206 | However, parties who have received copies, or rights, from you under 207 | this License will not have their licenses terminated so long as such 208 | parties remain in full compliance. 209 | 210 | 5. You are not required to accept this License, since you have not 211 | signed it. However, nothing else grants you permission to modify or 212 | distribute the Program or its derivative works. These actions are 213 | prohibited by law if you do not accept this License. Therefore, by 214 | modifying or distributing the Program (or any work based on the 215 | Program), you indicate your acceptance of this License to do so, and 216 | all its terms and conditions for copying, distributing or modifying 217 | the Program or works based on it. 218 | 219 | 6. Each time you redistribute the Program (or any work based on the 220 | Program), the recipient automatically receives a license from the 221 | original licensor to copy, distribute or modify the Program subject to 222 | these terms and conditions. You may not impose any further 223 | restrictions on the recipients' exercise of the rights granted herein. 224 | You are not responsible for enforcing compliance by third parties to 225 | this License. 226 | 227 | 7. If, as a consequence of a court judgment or allegation of patent 228 | infringement or for any other reason (not limited to patent issues), 229 | conditions are imposed on you (whether by court order, agreement or 230 | otherwise) that contradict the conditions of this License, they do not 231 | excuse you from the conditions of this License. If you cannot 232 | distribute so as to satisfy simultaneously your obligations under this 233 | License and any other pertinent obligations, then as a consequence you 234 | may not distribute the Program at all. For example, if a patent 235 | license would not permit royalty-free redistribution of the Program by 236 | all those who receive copies directly or indirectly through you, then 237 | the only way you could satisfy both it and this License would be to 238 | refrain entirely from distribution of the Program. 239 | 240 | If any portion of this section is held invalid or unenforceable under 241 | any particular circumstance, the balance of the section is intended to 242 | apply and the section as a whole is intended to apply in other 243 | circumstances. 244 | 245 | It is not the purpose of this section to induce you to infringe any 246 | patents or other property right claims or to contest validity of any 247 | such claims; this section has the sole purpose of protecting the 248 | integrity of the free software distribution system, which is 249 | implemented by public license practices. Many people have made 250 | generous contributions to the wide range of software distributed 251 | through that system in reliance on consistent application of that 252 | system; it is up to the author/donor to decide if he or she is willing 253 | to distribute software through any other system and a licensee cannot 254 | impose that choice. 255 | 256 | This section is intended to make thoroughly clear what is believed to 257 | be a consequence of the rest of this License. 258 | 259 | 8. If the distribution and/or use of the Program is restricted in 260 | certain countries either by patents or by copyrighted interfaces, the 261 | original copyright holder who places the Program under this License 262 | may add an explicit geographical distribution limitation excluding 263 | those countries, so that distribution is permitted only in or among 264 | countries not thus excluded. In such case, this License incorporates 265 | the limitation as if written in the body of this License. 266 | 267 | 9. The Free Software Foundation may publish revised and/or new versions 268 | of the General Public License from time to time. Such new versions will 269 | be similar in spirit to the present version, but may differ in detail to 270 | address new problems or concerns. 271 | 272 | Each version is given a distinguishing version number. If the Program 273 | specifies a version number of this License which applies to it and "any 274 | later version", you have the option of following the terms and conditions 275 | either of that version or of any later version published by the Free 276 | Software Foundation. If the Program does not specify a version number of 277 | this License, you may choose any version ever published by the Free Software 278 | Foundation. 279 | 280 | 10. If you wish to incorporate parts of the Program into other free 281 | programs whose distribution conditions are different, write to the author 282 | to ask for permission. For software which is copyrighted by the Free 283 | Software Foundation, write to the Free Software Foundation; we sometimes 284 | make exceptions for this. Our decision will be guided by the two goals 285 | of preserving the free status of all derivatives of our free software and 286 | of promoting the sharing and reuse of software generally. 287 | 288 | NO WARRANTY 289 | 290 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 291 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 292 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 293 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 294 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 295 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 296 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 297 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 298 | REPAIR OR CORRECTION. 299 | 300 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 301 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 302 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 303 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 304 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 305 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 306 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 307 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 308 | POSSIBILITY OF SUCH DAMAGES. 309 | 310 | END OF TERMS AND CONDITIONS 311 | 312 | How to Apply These Terms to Your New Programs 313 | 314 | If you develop a new program, and you want it to be of the greatest 315 | possible use to the public, the best way to achieve this is to make it 316 | free software which everyone can redistribute and change under these terms. 317 | 318 | To do so, attach the following notices to the program. It is safest 319 | to attach them to the start of each source file to most effectively 320 | convey the exclusion of warranty; and each file should have at least 321 | the "copyright" line and a pointer to where the full notice is found. 322 | 323 | 326 | Copyright (C) 2014 Alexander Farkas (aFarkas) 327 | 328 | This program is free software; you can redistribute it and/or modify 329 | it under the terms of the GNU General Public License as published by 330 | the Free Software Foundation; either version 2 of the License, or 331 | (at your option) any later version. 332 | 333 | This program is distributed in the hope that it will be useful, 334 | but WITHOUT ANY WARRANTY; without even the implied warranty of 335 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 336 | GNU General Public License for more details. 337 | 338 | You should have received a copy of the GNU General Public License 339 | along with this program; if not, write to the Free Software 340 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 341 | 342 | 343 | Also add information on how to contact you by electronic and paper mail. 344 | 345 | If the program is interactive, make it output a short notice like this 346 | when it starts in an interactive mode: 347 | 348 | Gnomovision version 69, Copyright (C) 2014 Alexander Farkas (aFarkas) 349 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 350 | This is free software, and you are welcome to redistribute it 351 | under certain conditions; type `show c' for details. 352 | 353 | The hypothetical commands `show w' and `show c' should show the appropriate 354 | parts of the General Public License. Of course, the commands you use may 355 | be called something other than `show w' and `show c'; they could even be 356 | mouse-clicks or menu items--whatever suits your program. 357 | 358 | You should also get your employer (if you work as a programmer) or your 359 | school, if any, to sign a "copyright disclaimer" for the program, if 360 | necessary. Here is a sample; alter the names: 361 | 362 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 363 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 364 | 365 | , 1 April 1989 366 | Ty Coon, President of Vice 367 | 368 | This General Public License does not permit incorporating your program into 369 | proprietary programs. If your program is a subroutine library, you may 370 | consider it more useful to permit linking proprietary applications with the 371 | library. If this is what you want to do, use the GNU Library General 372 | Public License instead of this License. 373 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "html5shiv", 3 | "version": "3.7.3", 4 | "main": [ 5 | "dist/html5shiv.js" 6 | ], 7 | "ignore": [ 8 | "**/.*", 9 | "composer.json", 10 | "test", 11 | "build", 12 | "src", 13 | "build.xml" 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "afarkas/html5shiv", 3 | "description": "Defacto way to enable use of HTML5 sectioning elements in legacy Internet Explorer.", 4 | "type": "component", 5 | "homepage": "http://paulirish.com/2011/the-history-of-the-html5-shiv/", 6 | "license": [ 7 | "MIT", 8 | "GPL-2.0" 9 | ], 10 | "extra": { 11 | "component": { 12 | "scripts": [ 13 | "dist/html5shiv.js" 14 | ] 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /dist/html5shiv-printshiv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | ;(function(window, document) { 5 | /*jshint evil:true */ 6 | /** version */ 7 | var version = '3.7.3'; 8 | 9 | /** Preset options */ 10 | var options = window.html5 || {}; 11 | 12 | /** Used to skip problem elements */ 13 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; 14 | 15 | /** Not all elements can be cloned in IE **/ 16 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i; 17 | 18 | /** Detect whether the browser supports default html5 styles */ 19 | var supportsHtml5Styles; 20 | 21 | /** Name of the expando, to work with multiple documents or to re-shiv one document */ 22 | var expando = '_html5shiv'; 23 | 24 | /** The id for the the documents expando */ 25 | var expanID = 0; 26 | 27 | /** Cached data for each document */ 28 | var expandoData = {}; 29 | 30 | /** Detect whether the browser supports unknown elements */ 31 | var supportsUnknownElements; 32 | 33 | (function() { 34 | try { 35 | var a = document.createElement('a'); 36 | a.innerHTML = ''; 37 | //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles 38 | supportsHtml5Styles = ('hidden' in a); 39 | 40 | supportsUnknownElements = a.childNodes.length == 1 || (function() { 41 | // assign a false positive if unable to shiv 42 | (document.createElement)('a'); 43 | var frag = document.createDocumentFragment(); 44 | return ( 45 | typeof frag.cloneNode == 'undefined' || 46 | typeof frag.createDocumentFragment == 'undefined' || 47 | typeof frag.createElement == 'undefined' 48 | ); 49 | }()); 50 | } catch(e) { 51 | // assign a false positive if detection fails => unable to shiv 52 | supportsHtml5Styles = true; 53 | supportsUnknownElements = true; 54 | } 55 | 56 | }()); 57 | 58 | /*--------------------------------------------------------------------------*/ 59 | 60 | /** 61 | * Creates a style sheet with the given CSS text and adds it to the document. 62 | * @private 63 | * @param {Document} ownerDocument The document. 64 | * @param {String} cssText The CSS text. 65 | * @returns {StyleSheet} The style element. 66 | */ 67 | function addStyleSheet(ownerDocument, cssText) { 68 | var p = ownerDocument.createElement('p'), 69 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; 70 | 71 | p.innerHTML = 'x'; 72 | return parent.insertBefore(p.lastChild, parent.firstChild); 73 | } 74 | 75 | /** 76 | * Returns the value of `html5.elements` as an array. 77 | * @private 78 | * @returns {Array} An array of shived element node names. 79 | */ 80 | function getElements() { 81 | var elements = html5.elements; 82 | return typeof elements == 'string' ? elements.split(' ') : elements; 83 | } 84 | 85 | /** 86 | * Extends the built-in list of html5 elements 87 | * @memberOf html5 88 | * @param {String|Array} newElements whitespace separated list or array of new element names to shiv 89 | * @param {Document} ownerDocument The context document. 90 | */ 91 | function addElements(newElements, ownerDocument) { 92 | var elements = html5.elements; 93 | if(typeof elements != 'string'){ 94 | elements = elements.join(' '); 95 | } 96 | if(typeof newElements != 'string'){ 97 | newElements = newElements.join(' '); 98 | } 99 | html5.elements = elements +' '+ newElements; 100 | shivDocument(ownerDocument); 101 | } 102 | 103 | /** 104 | * Returns the data associated to the given document 105 | * @private 106 | * @param {Document} ownerDocument The document. 107 | * @returns {Object} An object of data. 108 | */ 109 | function getExpandoData(ownerDocument) { 110 | var data = expandoData[ownerDocument[expando]]; 111 | if (!data) { 112 | data = {}; 113 | expanID++; 114 | ownerDocument[expando] = expanID; 115 | expandoData[expanID] = data; 116 | } 117 | return data; 118 | } 119 | 120 | /** 121 | * returns a shived element for the given nodeName and document 122 | * @memberOf html5 123 | * @param {String} nodeName name of the element 124 | * @param {Document} ownerDocument The context document. 125 | * @returns {Object} The shived element. 126 | */ 127 | function createElement(nodeName, ownerDocument, data){ 128 | if (!ownerDocument) { 129 | ownerDocument = document; 130 | } 131 | if(supportsUnknownElements){ 132 | return ownerDocument.createElement(nodeName); 133 | } 134 | if (!data) { 135 | data = getExpandoData(ownerDocument); 136 | } 137 | var node; 138 | 139 | if (data.cache[nodeName]) { 140 | node = data.cache[nodeName].cloneNode(); 141 | } else if (saveClones.test(nodeName)) { 142 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); 143 | } else { 144 | node = data.createElem(nodeName); 145 | } 146 | 147 | // Avoid adding some elements to fragments in IE < 9 because 148 | // * Attributes like `name` or `type` cannot be set/changed once an element 149 | // is inserted into a document/fragment 150 | // * Link elements with `src` attributes that are inaccessible, as with 151 | // a 403 response, will cause the tab/window to crash 152 | // * Script elements appended to fragments will execute when their `src` 153 | // or `text` property is set 154 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node; 155 | } 156 | 157 | /** 158 | * returns a shived DocumentFragment for the given document 159 | * @memberOf html5 160 | * @param {Document} ownerDocument The context document. 161 | * @returns {Object} The shived DocumentFragment. 162 | */ 163 | function createDocumentFragment(ownerDocument, data){ 164 | if (!ownerDocument) { 165 | ownerDocument = document; 166 | } 167 | if(supportsUnknownElements){ 168 | return ownerDocument.createDocumentFragment(); 169 | } 170 | data = data || getExpandoData(ownerDocument); 171 | var clone = data.frag.cloneNode(), 172 | i = 0, 173 | elems = getElements(), 174 | l = elems.length; 175 | for(;i+~])(' + getElements().join('|') + ')(?=[[\\s,>+~#.:]|$)', 'gi'), 402 | replacement = '$1' + shivNamespace + '\\:$2'; 403 | 404 | while (index--) { 405 | pair = parts[index] = parts[index].split('}'); 406 | pair[pair.length - 1] = pair[pair.length - 1].replace(reElements, replacement); 407 | parts[index] = pair.join('}'); 408 | } 409 | return parts.join('{'); 410 | } 411 | 412 | /** 413 | * Removes the given wrappers, leaving the original elements. 414 | * @private 415 | * @params {Array} wrappers An array of printable wrappers. 416 | */ 417 | function removeWrappers(wrappers) { 418 | var index = wrappers.length; 419 | while (index--) { 420 | wrappers[index].removeNode(); 421 | } 422 | } 423 | 424 | /*--------------------------------------------------------------------------*/ 425 | 426 | /** 427 | * Shivs the given document for print. 428 | * @memberOf html5 429 | * @param {Document} ownerDocument The document to shiv. 430 | * @returns {Document} The shived document. 431 | */ 432 | function shivPrint(ownerDocument) { 433 | var shivedSheet, 434 | wrappers, 435 | data = getExpandoData(ownerDocument), 436 | namespaces = ownerDocument.namespaces, 437 | ownerWindow = ownerDocument.parentWindow; 438 | 439 | if (!supportsShivableSheets || ownerDocument.printShived) { 440 | return ownerDocument; 441 | } 442 | if (typeof namespaces[shivNamespace] == 'undefined') { 443 | namespaces.add(shivNamespace); 444 | } 445 | 446 | function removeSheet() { 447 | clearTimeout(data._removeSheetTimer); 448 | if (shivedSheet) { 449 | shivedSheet.removeNode(true); 450 | } 451 | shivedSheet= null; 452 | } 453 | 454 | ownerWindow.attachEvent('onbeforeprint', function() { 455 | 456 | removeSheet(); 457 | 458 | var imports, 459 | length, 460 | sheet, 461 | collection = ownerDocument.styleSheets, 462 | cssText = [], 463 | index = collection.length, 464 | sheets = Array(index); 465 | 466 | // convert styleSheets collection to an array 467 | while (index--) { 468 | sheets[index] = collection[index]; 469 | } 470 | // concat all style sheet CSS text 471 | while ((sheet = sheets.pop())) { 472 | // IE does not enforce a same origin policy for external style sheets... 473 | // but has trouble with some dynamically created stylesheets 474 | if (!sheet.disabled && reMedia.test(sheet.media)) { 475 | 476 | try { 477 | imports = sheet.imports; 478 | length = imports.length; 479 | } catch(er){ 480 | length = 0; 481 | } 482 | 483 | for (index = 0; index < length; index++) { 484 | sheets.push(imports[index]); 485 | } 486 | 487 | try { 488 | cssText.push(sheet.cssText); 489 | } catch(er){} 490 | } 491 | } 492 | 493 | // wrap all HTML5 elements with printable elements and add the shived style sheet 494 | cssText = shivCssText(cssText.reverse().join('')); 495 | wrappers = addWrappers(ownerDocument); 496 | shivedSheet = addStyleSheet(ownerDocument, cssText); 497 | 498 | }); 499 | 500 | ownerWindow.attachEvent('onafterprint', function() { 501 | // remove wrappers, leaving the original elements, and remove the shived style sheet 502 | removeWrappers(wrappers); 503 | clearTimeout(data._removeSheetTimer); 504 | data._removeSheetTimer = setTimeout(removeSheet, 500); 505 | }); 506 | 507 | ownerDocument.printShived = true; 508 | return ownerDocument; 509 | } 510 | 511 | /*--------------------------------------------------------------------------*/ 512 | 513 | // expose API 514 | html5.type += ' print'; 515 | html5.shivPrint = shivPrint; 516 | 517 | // shiv for print 518 | shivPrint(document); 519 | 520 | if(typeof module == 'object' && module.exports){ 521 | module.exports = html5; 522 | } 523 | 524 | }(typeof window !== "undefined" ? window : this, document)); 525 | -------------------------------------------------------------------------------- /dist/html5shiv-printshiv.min.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | !function(a,b){function c(a,b){var c=a.createElement("p"),d=a.getElementsByTagName("head")[0]||a.documentElement;return c.innerHTML="x",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=y.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=y.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),y.elements=c+" "+a,j(b)}function f(a){var b=x[a[v]];return b||(b={},w++,a[v]=w,x[w]=b),b}function g(a,c,d){if(c||(c=b),q)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():u.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||t.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),q)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return y.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(y,b.frag)}function j(a){a||(a=b);var d=f(a);return!y.shivCSS||p||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),q||i(a,d),a}function k(a){for(var b,c=a.getElementsByTagName("*"),e=c.length,f=RegExp("^(?:"+d().join("|")+")$","i"),g=[];e--;)b=c[e],f.test(b.nodeName)&&g.push(b.applyElement(l(b)));return g}function l(a){for(var b,c=a.attributes,d=c.length,e=a.ownerDocument.createElement(A+":"+a.nodeName);d--;)b=c[d],b.specified&&e.setAttribute(b.nodeName,b.nodeValue);return e.style.cssText=a.style.cssText,e}function m(a){for(var b,c=a.split("{"),e=c.length,f=RegExp("(^|[\\s,>+~])("+d().join("|")+")(?=[[\\s,>+~#.:]|$)","gi"),g="$1"+A+"\\:$2";e--;)b=c[e]=c[e].split("}"),b[b.length-1]=b[b.length-1].replace(f,g),c[e]=b.join("}");return c.join("{")}function n(a){for(var b=a.length;b--;)a[b].removeNode()}function o(a){function b(){clearTimeout(g._removeSheetTimer),d&&d.removeNode(!0),d=null}var d,e,g=f(a),h=a.namespaces,i=a.parentWindow;return!B||a.printShived?a:("undefined"==typeof h[A]&&h.add(A),i.attachEvent("onbeforeprint",function(){b();for(var f,g,h,i=a.styleSheets,j=[],l=i.length,n=Array(l);l--;)n[l]=i[l];for(;h=n.pop();)if(!h.disabled&&z.test(h.media)){try{f=h.imports,g=f.length}catch(o){g=0}for(l=0;g>l;l++)n.push(f[l]);try{j.push(h.cssText)}catch(o){}}j=m(j.reverse().join("")),e=k(a),d=c(a,j)}),i.attachEvent("onafterprint",function(){n(e),clearTimeout(g._removeSheetTimer),g._removeSheetTimer=setTimeout(b,500)}),a.printShived=!0,a)}var p,q,r="3.7.3",s=a.html5||{},t=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,u=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,v="_html5shiv",w=0,x={};!function(){try{var a=b.createElement("a");a.innerHTML="",p="hidden"in a,q=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){p=!0,q=!0}}();var y={elements:s.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:r,shivCSS:s.shivCSS!==!1,supportsUnknownElements:q,shivMethods:s.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=y,j(b);var z=/^$|\b(?:all|print)\b/,A="html5shiv",B=!q&&function(){var c=b.documentElement;return!("undefined"==typeof b.namespaces||"undefined"==typeof b.parentWindow||"undefined"==typeof c.applyElement||"undefined"==typeof c.removeNode||"undefined"==typeof a.attachEvent)}();y.type+=" print",y.shivPrint=o,o(b),"object"==typeof module&&module.exports&&(module.exports=y)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /dist/html5shiv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | ;(function(window, document) { 5 | /*jshint evil:true */ 6 | /** version */ 7 | var version = '3.7.3'; 8 | 9 | /** Preset options */ 10 | var options = window.html5 || {}; 11 | 12 | /** Used to skip problem elements */ 13 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; 14 | 15 | /** Not all elements can be cloned in IE **/ 16 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i; 17 | 18 | /** Detect whether the browser supports default html5 styles */ 19 | var supportsHtml5Styles; 20 | 21 | /** Name of the expando, to work with multiple documents or to re-shiv one document */ 22 | var expando = '_html5shiv'; 23 | 24 | /** The id for the the documents expando */ 25 | var expanID = 0; 26 | 27 | /** Cached data for each document */ 28 | var expandoData = {}; 29 | 30 | /** Detect whether the browser supports unknown elements */ 31 | var supportsUnknownElements; 32 | 33 | (function() { 34 | try { 35 | var a = document.createElement('a'); 36 | a.innerHTML = ''; 37 | //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles 38 | supportsHtml5Styles = ('hidden' in a); 39 | 40 | supportsUnknownElements = a.childNodes.length == 1 || (function() { 41 | // assign a false positive if unable to shiv 42 | (document.createElement)('a'); 43 | var frag = document.createDocumentFragment(); 44 | return ( 45 | typeof frag.cloneNode == 'undefined' || 46 | typeof frag.createDocumentFragment == 'undefined' || 47 | typeof frag.createElement == 'undefined' 48 | ); 49 | }()); 50 | } catch(e) { 51 | // assign a false positive if detection fails => unable to shiv 52 | supportsHtml5Styles = true; 53 | supportsUnknownElements = true; 54 | } 55 | 56 | }()); 57 | 58 | /*--------------------------------------------------------------------------*/ 59 | 60 | /** 61 | * Creates a style sheet with the given CSS text and adds it to the document. 62 | * @private 63 | * @param {Document} ownerDocument The document. 64 | * @param {String} cssText The CSS text. 65 | * @returns {StyleSheet} The style element. 66 | */ 67 | function addStyleSheet(ownerDocument, cssText) { 68 | var p = ownerDocument.createElement('p'), 69 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; 70 | 71 | p.innerHTML = 'x'; 72 | return parent.insertBefore(p.lastChild, parent.firstChild); 73 | } 74 | 75 | /** 76 | * Returns the value of `html5.elements` as an array. 77 | * @private 78 | * @returns {Array} An array of shived element node names. 79 | */ 80 | function getElements() { 81 | var elements = html5.elements; 82 | return typeof elements == 'string' ? elements.split(' ') : elements; 83 | } 84 | 85 | /** 86 | * Extends the built-in list of html5 elements 87 | * @memberOf html5 88 | * @param {String|Array} newElements whitespace separated list or array of new element names to shiv 89 | * @param {Document} ownerDocument The context document. 90 | */ 91 | function addElements(newElements, ownerDocument) { 92 | var elements = html5.elements; 93 | if(typeof elements != 'string'){ 94 | elements = elements.join(' '); 95 | } 96 | if(typeof newElements != 'string'){ 97 | newElements = newElements.join(' '); 98 | } 99 | html5.elements = elements +' '+ newElements; 100 | shivDocument(ownerDocument); 101 | } 102 | 103 | /** 104 | * Returns the data associated to the given document 105 | * @private 106 | * @param {Document} ownerDocument The document. 107 | * @returns {Object} An object of data. 108 | */ 109 | function getExpandoData(ownerDocument) { 110 | var data = expandoData[ownerDocument[expando]]; 111 | if (!data) { 112 | data = {}; 113 | expanID++; 114 | ownerDocument[expando] = expanID; 115 | expandoData[expanID] = data; 116 | } 117 | return data; 118 | } 119 | 120 | /** 121 | * returns a shived element for the given nodeName and document 122 | * @memberOf html5 123 | * @param {String} nodeName name of the element 124 | * @param {Document|DocumentFragment} ownerDocument The context document. 125 | * @returns {Object} The shived element. 126 | */ 127 | function createElement(nodeName, ownerDocument, data){ 128 | if (!ownerDocument) { 129 | ownerDocument = document; 130 | } 131 | if(supportsUnknownElements){ 132 | return ownerDocument.createElement(nodeName); 133 | } 134 | if (!data) { 135 | data = getExpandoData(ownerDocument); 136 | } 137 | var node; 138 | 139 | if (data.cache[nodeName]) { 140 | node = data.cache[nodeName].cloneNode(); 141 | } else if (saveClones.test(nodeName)) { 142 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); 143 | } else { 144 | node = data.createElem(nodeName); 145 | } 146 | 147 | // Avoid adding some elements to fragments in IE < 9 because 148 | // * Attributes like `name` or `type` cannot be set/changed once an element 149 | // is inserted into a document/fragment 150 | // * Link elements with `src` attributes that are inaccessible, as with 151 | // a 403 response, will cause the tab/window to crash 152 | // * Script elements appended to fragments will execute when their `src` 153 | // or `text` property is set 154 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node; 155 | } 156 | 157 | /** 158 | * returns a shived DocumentFragment for the given document 159 | * @memberOf html5 160 | * @param {Document} ownerDocument The context document. 161 | * @returns {Object} The shived DocumentFragment. 162 | */ 163 | function createDocumentFragment(ownerDocument, data){ 164 | if (!ownerDocument) { 165 | ownerDocument = document; 166 | } 167 | if(supportsUnknownElements){ 168 | return ownerDocument.createDocumentFragment(); 169 | } 170 | data = data || getExpandoData(ownerDocument); 171 | var clone = data.frag.cloneNode(), 172 | i = 0, 173 | elems = getElements(), 174 | l = elems.length; 175 | for(;i",d.insertBefore(c.lastChild,d.firstChild)}function d(){var a=t.elements;return"string"==typeof a?a.split(" "):a}function e(a,b){var c=t.elements;"string"!=typeof c&&(c=c.join(" ")),"string"!=typeof a&&(a=a.join(" ")),t.elements=c+" "+a,j(b)}function f(a){var b=s[a[q]];return b||(b={},r++,a[q]=r,s[r]=b),b}function g(a,c,d){if(c||(c=b),l)return c.createElement(a);d||(d=f(c));var e;return e=d.cache[a]?d.cache[a].cloneNode():p.test(a)?(d.cache[a]=d.createElem(a)).cloneNode():d.createElem(a),!e.canHaveChildren||o.test(a)||e.tagUrn?e:d.frag.appendChild(e)}function h(a,c){if(a||(a=b),l)return a.createDocumentFragment();c=c||f(a);for(var e=c.frag.cloneNode(),g=0,h=d(),i=h.length;i>g;g++)e.createElement(h[g]);return e}function i(a,b){b.cache||(b.cache={},b.createElem=a.createElement,b.createFrag=a.createDocumentFragment,b.frag=b.createFrag()),a.createElement=function(c){return t.shivMethods?g(c,a,b):b.createElem(c)},a.createDocumentFragment=Function("h,f","return function(){var n=f.cloneNode(),c=n.createElement;h.shivMethods&&("+d().join().replace(/[\w\-:]+/g,function(a){return b.createElem(a),b.frag.createElement(a),'c("'+a+'")'})+");return n}")(t,b.frag)}function j(a){a||(a=b);var d=f(a);return!t.shivCSS||k||d.hasCSS||(d.hasCSS=!!c(a,"article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}mark{background:#FF0;color:#000}template{display:none}")),l||i(a,d),a}var k,l,m="3.7.3",n=a.html5||{},o=/^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i,p=/^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i,q="_html5shiv",r=0,s={};!function(){try{var a=b.createElement("a");a.innerHTML="",k="hidden"in a,l=1==a.childNodes.length||function(){b.createElement("a");var a=b.createDocumentFragment();return"undefined"==typeof a.cloneNode||"undefined"==typeof a.createDocumentFragment||"undefined"==typeof a.createElement}()}catch(c){k=!0,l=!0}}();var t={elements:n.elements||"abbr article aside audio bdi canvas data datalist details dialog figcaption figure footer header hgroup main mark meter nav output picture progress section summary template time video",version:m,shivCSS:n.shivCSS!==!1,supportsUnknownElements:l,shivMethods:n.shivMethods!==!1,type:"default",shivDocument:j,createElement:g,createDocumentFragment:h,addElements:e};a.html5=t,j(b),"object"==typeof module&&module.exports&&(module.exports=t)}("undefined"!=typeof window?window:this,document); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "html5shiv", 3 | "version": "3.7.3", 4 | "repository": { 5 | "type": "git", 6 | "url": "https://github.com/aFarkas/html5shiv.git" 7 | }, 8 | "main": "dist/html5shiv.js", 9 | "devDependencies": { 10 | "grunt-bytesize": ">=0.1.0", 11 | "grunt-contrib-watch": ">=0.3.0", 12 | "grunt-contrib-copy": ">=0.4.0", 13 | "grunt-contrib-uglify": ">=0.2.7", 14 | "grunt": ">=0.4.1" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # The HTML5 Shiv 2 | 3 | The HTML5 Shiv enables use of HTML5 sectioning elements in legacy Internet Explorer and provides basic HTML5 styling for Internet Explorer 6-9, Safari 4.x (and iPhone 3.x), and Firefox 3.x. 4 | 5 | ### What do these files do? 6 | 7 | #### `html5shiv.js` 8 | * This includes the basic `createElement()` shiv technique, along with monkeypatches for `document.createElement` and `document.createDocumentFragment` for IE6-8. It also applies [basic styling](https://github.com/aFarkas/html5shiv/blob/51da98dabd3c537891b7fe6114633fb10de52473/src/html5shiv.js#L216-220) for HTML5 elements for IE6-9, Safari 4.x and FF 3.x. 9 | 10 | #### `html5shiv-printshiv.js` 11 | * This includes all of the above, as well as a mechanism allowing HTML5 elements to be styled and contain children while being printed in IE 6-8. 12 | 13 | ### Who can I get mad at now? 14 | 15 | HTML5 Shiv is maintained by [Alexander Farkas](https://github.com/aFarkas/), [Jonathan Neal](https://twitter.com/jon_neal) and [Paul Irish](https://twitter.com/paul_irish), with many contributions from [John-David Dalton](https://twitter.com/jdalton). It is also distributed with [Modernizr](http://modernizr.com/). 16 | 17 | If you have any issues in these implementations, you can report them here! :) 18 | 19 | For the full story of HTML5 Shiv and all of the people involved in making it, read [The Story of the HTML5 Shiv](http://paulirish.com/2011/the-history-of-the-html5-shiv/). 20 | 21 | ## Installation 22 | 23 | ### Using [Bower](http://bower.io/) 24 | 25 | `bower install html5shiv --save` 26 | 27 | This will clone the latest version of the HTML5 shiv into the `bower_components` directory at the root of your project and also create or update the file `bower.json` which specifies your projects dependencies. 28 | 29 | Include the HTML5 shiv in the `` of your page in a conditional comment and after any stylesheets. 30 | 31 | ```html 32 | 35 | ``` 36 | 37 | ### Manual installation 38 | 39 | Download and extract the [latest zip package](https://github.com/aFarkas/html5shiv/archive/master.zip) from this repositiory and copy the two files `dist/html5shiv.js` and `dist/html5shiv-printshiv.js` into your project. Then include one of them into your `` as above. 40 | 41 | ## HTML5 Shiv API 42 | 43 | HTML5 Shiv works as a simple drop-in solution. In most cases there is no need to configure HTML5 Shiv or use methods provided by HTML5 Shiv. 44 | 45 | ### `html5.elements` option 46 | 47 | The `elements` option is a space separated string or array, which describes the **full** list of the elements to shiv. see also `addElements`. 48 | 49 | **Configuring `elements` before `html5shiv.js` is included.** 50 | 51 | ```js 52 | //create a global html5 options object 53 | window.html5 = { 54 | 'elements': 'mark section customelement' 55 | }; 56 | ``` 57 | **Configuring `elements` after `html5shiv.js` is included.** 58 | 59 | ```js 60 | //change the html5shiv options object 61 | window.html5.elements = 'mark section customelement'; 62 | //and re-invoke the `shivDocument` method 63 | html5.shivDocument(document); 64 | ``` 65 | 66 | ### `html5.shivCSS` 67 | 68 | If `shivCSS` is set to `true` HTML5 Shiv will add basic styles (mostly display: block) to sectioning elements (like section, article). In most cases a webpage author should include those basic styles in his normal stylesheet to ensure older browser support (i.e. Firefox 3.6) without JavaScript. 69 | 70 | The `shivCSS` is true by default and can be set false, only before html5shiv.js is included: 71 | 72 | ```js 73 | //create a global html5 options object 74 | window.html5 = { 75 | 'shivCSS': false 76 | }; 77 | ``` 78 | 79 | ### `html5.shivMethods` 80 | 81 | If the `shivMethods` option is set to `true` (by default) HTML5 Shiv will override `document.createElement`/`document.createDocumentFragment` in Internet Explorer 6-8 to allow dynamic DOM creation of HTML5 elements. 82 | 83 | Known issue: If an element is created using the overridden `createElement` method this element returns a document fragment as its `parentNode`, but should be normally `null`. If a script relies on this behavior, `shivMethods`should be set to `false`. 84 | Note: jQuery 1.7+ has implemented his own HTML5 DOM creation fix for Internet Explorer 6-8. If all your scripts (including Third party scripts) are using jQuery's manipulation and DOM creation methods, you might want to set this option to `false`. 85 | 86 | **Configuring `shivMethods` before `html5shiv.js` is included.** 87 | 88 | ```js 89 | //create a global html5 options object 90 | window.html5 = { 91 | 'shivMethods': false 92 | }; 93 | ``` 94 | **Configuring `elements` after `html5shiv.js` is included.** 95 | 96 | ```js 97 | //change the html5shiv options object 98 | window.html5.shivMethods = false; 99 | ``` 100 | 101 | ### `html5.addElements( newElements [, document] )` 102 | 103 | The `html5.addElements` method extends the list of elements to shiv. The newElements argument can be a whitespace separated list or an array. 104 | 105 | ```js 106 | //extend list of elements to shiv 107 | html5.addElements('element content'); 108 | ``` 109 | 110 | ### `html5.createElement( nodeName [, document] )` 111 | 112 | The `html5.createElement` method creates a shived element, even if `shivMethods` is set to false. 113 | 114 | ```js 115 | var container = html5.createElement('div'); 116 | //container is shived so we can add HTML5 elements using `innerHTML` 117 | container.innerHTML = '
This is a section
'; 118 | ``` 119 | 120 | ### `html5.createDocumentFragment( [document] )` 121 | 122 | The `html5.createDocumentFragment` method creates a shived document fragment, even if `shivMethods` is set to false. 123 | 124 | ```js 125 | var fragment = html5.createDocumentFragment(); 126 | var container = document.createElement('div'); 127 | fragment.appendChild(container); 128 | //fragment is shived so we can add HTML5 elements using `innerHTML` 129 | container.innerHTML = '
This is a section
'; 130 | ``` 131 | 132 | ## HTML5 Shiv Known Issues and Limitations 133 | 134 | - The `shivMethods` option (overriding `document.createElement`) and the `html5.createElement` method create elements, which are not disconnected and have a parentNode (see also issue #64) 135 | - The cloneNode problem is currently not addressed by HTML5 Shiv. HTML5 elements can be dynamically created, but can't be cloned in all cases. 136 | - The printshiv version of HTML5 Shiv has to alter the print styles and the whole DOM for printing. In case of complex websites and or a lot of print styles this might cause performance and/or styling issues. A possible solution could be the [htc-branch](https://github.com/aFarkas/html5shiv/tree/iepp-htc) of HTML5 Shiv, which uses another technique to implement print styles for Internet Explorer 6-8. 137 | 138 | ### What about the other HTML5 element projects? 139 | 140 | - The original conception and community collaboration story of the project is described at [The History of the HTML5 Shiv](http://paulirish.com/2011/the-history-of-the-html5-shiv/). 141 | - [IEPP](https://code.google.com/p/ie-print-protector), by Jon Neal, addressed the printing fault of the original `html5shiv`. It was merged into `html5shiv`. 142 | - **Shimprove**, in April 2010, patched `cloneNode` and `createElement` was later merged into `html5shiv` 143 | - **innerShiv**, introduced in August 2010 by JD Barlett, addressed dynamically adding new HTML5 elements into the DOM. [jQuery added support](http://blog.jquery.com/2011/11/03/jquery-1-7-released/) that made innerShiv redundant and `html5shiv` addressed the same issues as well, so the project was completed. 144 | - The **html5shim** and **html5shiv** sites on Google Code are maintained by Remy Sharp and are identical distribution points of this `html5shiv` project. 145 | - **Modernizr** is developed by the same people as `html5shiv` and can include the latest version in any custom builds created at modernizr.com 146 | - This `html5shiv` repo now contains tests for all the edge cases pursued by the above libraries and has been extensively tested, both in development and production. 147 | 148 | A [detailed changelog of html5shiv](https://github.com/aFarkas/html5shiv/wiki) is available. 149 | 150 | ### Why is it called a *shiv*? 151 | 152 | The term **shiv** [originates](http://ejohn.org/blog/html5-shiv/) from [John Resig](https://github.com/jeresig), who was thought to have used the word for its slang meaning, *a sharp object used as a knife-like weapon*, intended for Internet Explorer. Truth be known, John probably intended to use the word [shim](http://en.wikipedia.org/wiki/Shim_(computing)), which in computing means *an application compatibility workaround*. Rather than correct his mispelling, most developers familiar with Internet Explorer appreciated the visual imagery. And that, kids, is [etymology](https://en.wikipedia.org/wiki/Etymology). 153 | -------------------------------------------------------------------------------- /src/html5shiv-printshiv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | ;(function(window, document) { 5 | /*jshint evil:true */ 6 | /** version */ 7 | var version = '3.7.3'; 8 | 9 | /** Preset options */ 10 | var options = window.html5 || {}; 11 | 12 | /** Used to skip problem elements */ 13 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; 14 | 15 | /** Not all elements can be cloned in IE **/ 16 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i; 17 | 18 | /** Detect whether the browser supports default html5 styles */ 19 | var supportsHtml5Styles; 20 | 21 | /** Name of the expando, to work with multiple documents or to re-shiv one document */ 22 | var expando = '_html5shiv'; 23 | 24 | /** The id for the the documents expando */ 25 | var expanID = 0; 26 | 27 | /** Cached data for each document */ 28 | var expandoData = {}; 29 | 30 | /** Detect whether the browser supports unknown elements */ 31 | var supportsUnknownElements; 32 | 33 | (function() { 34 | try { 35 | var a = document.createElement('a'); 36 | a.innerHTML = ''; 37 | //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles 38 | supportsHtml5Styles = ('hidden' in a); 39 | 40 | supportsUnknownElements = a.childNodes.length == 1 || (function() { 41 | // assign a false positive if unable to shiv 42 | (document.createElement)('a'); 43 | var frag = document.createDocumentFragment(); 44 | return ( 45 | typeof frag.cloneNode == 'undefined' || 46 | typeof frag.createDocumentFragment == 'undefined' || 47 | typeof frag.createElement == 'undefined' 48 | ); 49 | }()); 50 | } catch(e) { 51 | // assign a false positive if detection fails => unable to shiv 52 | supportsHtml5Styles = true; 53 | supportsUnknownElements = true; 54 | } 55 | 56 | }()); 57 | 58 | /*--------------------------------------------------------------------------*/ 59 | 60 | /** 61 | * Creates a style sheet with the given CSS text and adds it to the document. 62 | * @private 63 | * @param {Document} ownerDocument The document. 64 | * @param {String} cssText The CSS text. 65 | * @returns {StyleSheet} The style element. 66 | */ 67 | function addStyleSheet(ownerDocument, cssText) { 68 | var p = ownerDocument.createElement('p'), 69 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; 70 | 71 | p.innerHTML = 'x'; 72 | return parent.insertBefore(p.lastChild, parent.firstChild); 73 | } 74 | 75 | /** 76 | * Returns the value of `html5.elements` as an array. 77 | * @private 78 | * @returns {Array} An array of shived element node names. 79 | */ 80 | function getElements() { 81 | var elements = html5.elements; 82 | return typeof elements == 'string' ? elements.split(' ') : elements; 83 | } 84 | 85 | /** 86 | * Extends the built-in list of html5 elements 87 | * @memberOf html5 88 | * @param {String|Array} newElements whitespace separated list or array of new element names to shiv 89 | * @param {Document} ownerDocument The context document. 90 | */ 91 | function addElements(newElements, ownerDocument) { 92 | var elements = html5.elements; 93 | if(typeof elements != 'string'){ 94 | elements = elements.join(' '); 95 | } 96 | if(typeof newElements != 'string'){ 97 | newElements = newElements.join(' '); 98 | } 99 | html5.elements = elements +' '+ newElements; 100 | shivDocument(ownerDocument); 101 | } 102 | 103 | /** 104 | * Returns the data associated to the given document 105 | * @private 106 | * @param {Document} ownerDocument The document. 107 | * @returns {Object} An object of data. 108 | */ 109 | function getExpandoData(ownerDocument) { 110 | var data = expandoData[ownerDocument[expando]]; 111 | if (!data) { 112 | data = {}; 113 | expanID++; 114 | ownerDocument[expando] = expanID; 115 | expandoData[expanID] = data; 116 | } 117 | return data; 118 | } 119 | 120 | /** 121 | * returns a shived element for the given nodeName and document 122 | * @memberOf html5 123 | * @param {String} nodeName name of the element 124 | * @param {Document} ownerDocument The context document. 125 | * @returns {Object} The shived element. 126 | */ 127 | function createElement(nodeName, ownerDocument, data){ 128 | if (!ownerDocument) { 129 | ownerDocument = document; 130 | } 131 | if(supportsUnknownElements){ 132 | return ownerDocument.createElement(nodeName); 133 | } 134 | if (!data) { 135 | data = getExpandoData(ownerDocument); 136 | } 137 | var node; 138 | 139 | if (data.cache[nodeName]) { 140 | node = data.cache[nodeName].cloneNode(); 141 | } else if (saveClones.test(nodeName)) { 142 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); 143 | } else { 144 | node = data.createElem(nodeName); 145 | } 146 | 147 | // Avoid adding some elements to fragments in IE < 9 because 148 | // * Attributes like `name` or `type` cannot be set/changed once an element 149 | // is inserted into a document/fragment 150 | // * Link elements with `src` attributes that are inaccessible, as with 151 | // a 403 response, will cause the tab/window to crash 152 | // * Script elements appended to fragments will execute when their `src` 153 | // or `text` property is set 154 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node; 155 | } 156 | 157 | /** 158 | * returns a shived DocumentFragment for the given document 159 | * @memberOf html5 160 | * @param {Document} ownerDocument The context document. 161 | * @returns {Object} The shived DocumentFragment. 162 | */ 163 | function createDocumentFragment(ownerDocument, data){ 164 | if (!ownerDocument) { 165 | ownerDocument = document; 166 | } 167 | if(supportsUnknownElements){ 168 | return ownerDocument.createDocumentFragment(); 169 | } 170 | data = data || getExpandoData(ownerDocument); 171 | var clone = data.frag.cloneNode(), 172 | i = 0, 173 | elems = getElements(), 174 | l = elems.length; 175 | for(;i+~])(' + getElements().join('|') + ')(?=[[\\s,>+~#.:]|$)', 'gi'), 402 | replacement = '$1' + shivNamespace + '\\:$2'; 403 | 404 | while (index--) { 405 | pair = parts[index] = parts[index].split('}'); 406 | pair[pair.length - 1] = pair[pair.length - 1].replace(reElements, replacement); 407 | parts[index] = pair.join('}'); 408 | } 409 | return parts.join('{'); 410 | } 411 | 412 | /** 413 | * Removes the given wrappers, leaving the original elements. 414 | * @private 415 | * @params {Array} wrappers An array of printable wrappers. 416 | */ 417 | function removeWrappers(wrappers) { 418 | var index = wrappers.length; 419 | while (index--) { 420 | wrappers[index].removeNode(); 421 | } 422 | } 423 | 424 | /*--------------------------------------------------------------------------*/ 425 | 426 | /** 427 | * Shivs the given document for print. 428 | * @memberOf html5 429 | * @param {Document} ownerDocument The document to shiv. 430 | * @returns {Document} The shived document. 431 | */ 432 | function shivPrint(ownerDocument) { 433 | var shivedSheet, 434 | wrappers, 435 | data = getExpandoData(ownerDocument), 436 | namespaces = ownerDocument.namespaces, 437 | ownerWindow = ownerDocument.parentWindow; 438 | 439 | if (!supportsShivableSheets || ownerDocument.printShived) { 440 | return ownerDocument; 441 | } 442 | if (typeof namespaces[shivNamespace] == 'undefined') { 443 | namespaces.add(shivNamespace); 444 | } 445 | 446 | function removeSheet() { 447 | clearTimeout(data._removeSheetTimer); 448 | if (shivedSheet) { 449 | shivedSheet.removeNode(true); 450 | } 451 | shivedSheet= null; 452 | } 453 | 454 | ownerWindow.attachEvent('onbeforeprint', function() { 455 | 456 | removeSheet(); 457 | 458 | var imports, 459 | length, 460 | sheet, 461 | collection = ownerDocument.styleSheets, 462 | cssText = [], 463 | index = collection.length, 464 | sheets = Array(index); 465 | 466 | // convert styleSheets collection to an array 467 | while (index--) { 468 | sheets[index] = collection[index]; 469 | } 470 | // concat all style sheet CSS text 471 | while ((sheet = sheets.pop())) { 472 | // IE does not enforce a same origin policy for external style sheets... 473 | // but has trouble with some dynamically created stylesheets 474 | if (!sheet.disabled && reMedia.test(sheet.media)) { 475 | 476 | try { 477 | imports = sheet.imports; 478 | length = imports.length; 479 | } catch(er){ 480 | length = 0; 481 | } 482 | 483 | for (index = 0; index < length; index++) { 484 | sheets.push(imports[index]); 485 | } 486 | 487 | try { 488 | cssText.push(sheet.cssText); 489 | } catch(er){} 490 | } 491 | } 492 | 493 | // wrap all HTML5 elements with printable elements and add the shived style sheet 494 | cssText = shivCssText(cssText.reverse().join('')); 495 | wrappers = addWrappers(ownerDocument); 496 | shivedSheet = addStyleSheet(ownerDocument, cssText); 497 | 498 | }); 499 | 500 | ownerWindow.attachEvent('onafterprint', function() { 501 | // remove wrappers, leaving the original elements, and remove the shived style sheet 502 | removeWrappers(wrappers); 503 | clearTimeout(data._removeSheetTimer); 504 | data._removeSheetTimer = setTimeout(removeSheet, 500); 505 | }); 506 | 507 | ownerDocument.printShived = true; 508 | return ownerDocument; 509 | } 510 | 511 | /*--------------------------------------------------------------------------*/ 512 | 513 | // expose API 514 | html5.type += ' print'; 515 | html5.shivPrint = shivPrint; 516 | 517 | // shiv for print 518 | shivPrint(document); 519 | 520 | if(typeof module == 'object' && module.exports){ 521 | module.exports = html5; 522 | } 523 | 524 | }(typeof window !== "undefined" ? window : this, document)); 525 | -------------------------------------------------------------------------------- /src/html5shiv.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @preserve HTML5 Shiv 3.7.3 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed 3 | */ 4 | ;(function(window, document) { 5 | /*jshint evil:true */ 6 | /** version */ 7 | var version = '3.7.3'; 8 | 9 | /** Preset options */ 10 | var options = window.html5 || {}; 11 | 12 | /** Used to skip problem elements */ 13 | var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; 14 | 15 | /** Not all elements can be cloned in IE **/ 16 | var saveClones = /^(?:a|b|code|div|fieldset|h1|h2|h3|h4|h5|h6|i|label|li|ol|p|q|span|strong|style|table|tbody|td|th|tr|ul)$/i; 17 | 18 | /** Detect whether the browser supports default html5 styles */ 19 | var supportsHtml5Styles; 20 | 21 | /** Name of the expando, to work with multiple documents or to re-shiv one document */ 22 | var expando = '_html5shiv'; 23 | 24 | /** The id for the the documents expando */ 25 | var expanID = 0; 26 | 27 | /** Cached data for each document */ 28 | var expandoData = {}; 29 | 30 | /** Detect whether the browser supports unknown elements */ 31 | var supportsUnknownElements; 32 | 33 | (function() { 34 | try { 35 | var a = document.createElement('a'); 36 | a.innerHTML = ''; 37 | //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles 38 | supportsHtml5Styles = ('hidden' in a); 39 | 40 | supportsUnknownElements = a.childNodes.length == 1 || (function() { 41 | // assign a false positive if unable to shiv 42 | (document.createElement)('a'); 43 | var frag = document.createDocumentFragment(); 44 | return ( 45 | typeof frag.cloneNode == 'undefined' || 46 | typeof frag.createDocumentFragment == 'undefined' || 47 | typeof frag.createElement == 'undefined' 48 | ); 49 | }()); 50 | } catch(e) { 51 | // assign a false positive if detection fails => unable to shiv 52 | supportsHtml5Styles = true; 53 | supportsUnknownElements = true; 54 | } 55 | 56 | }()); 57 | 58 | /*--------------------------------------------------------------------------*/ 59 | 60 | /** 61 | * Creates a style sheet with the given CSS text and adds it to the document. 62 | * @private 63 | * @param {Document} ownerDocument The document. 64 | * @param {String} cssText The CSS text. 65 | * @returns {StyleSheet} The style element. 66 | */ 67 | function addStyleSheet(ownerDocument, cssText) { 68 | var p = ownerDocument.createElement('p'), 69 | parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement; 70 | 71 | p.innerHTML = 'x'; 72 | return parent.insertBefore(p.lastChild, parent.firstChild); 73 | } 74 | 75 | /** 76 | * Returns the value of `html5.elements` as an array. 77 | * @private 78 | * @returns {Array} An array of shived element node names. 79 | */ 80 | function getElements() { 81 | var elements = html5.elements; 82 | return typeof elements == 'string' ? elements.split(' ') : elements; 83 | } 84 | 85 | /** 86 | * Extends the built-in list of html5 elements 87 | * @memberOf html5 88 | * @param {String|Array} newElements whitespace separated list or array of new element names to shiv 89 | * @param {Document} ownerDocument The context document. 90 | */ 91 | function addElements(newElements, ownerDocument) { 92 | var elements = html5.elements; 93 | if(typeof elements != 'string'){ 94 | elements = elements.join(' '); 95 | } 96 | if(typeof newElements != 'string'){ 97 | newElements = newElements.join(' '); 98 | } 99 | html5.elements = elements +' '+ newElements; 100 | shivDocument(ownerDocument); 101 | } 102 | 103 | /** 104 | * Returns the data associated to the given document 105 | * @private 106 | * @param {Document} ownerDocument The document. 107 | * @returns {Object} An object of data. 108 | */ 109 | function getExpandoData(ownerDocument) { 110 | var data = expandoData[ownerDocument[expando]]; 111 | if (!data) { 112 | data = {}; 113 | expanID++; 114 | ownerDocument[expando] = expanID; 115 | expandoData[expanID] = data; 116 | } 117 | return data; 118 | } 119 | 120 | /** 121 | * returns a shived element for the given nodeName and document 122 | * @memberOf html5 123 | * @param {String} nodeName name of the element 124 | * @param {Document|DocumentFragment} ownerDocument The context document. 125 | * @returns {Object} The shived element. 126 | */ 127 | function createElement(nodeName, ownerDocument, data){ 128 | if (!ownerDocument) { 129 | ownerDocument = document; 130 | } 131 | if(supportsUnknownElements){ 132 | return ownerDocument.createElement(nodeName); 133 | } 134 | if (!data) { 135 | data = getExpandoData(ownerDocument); 136 | } 137 | var node; 138 | 139 | if (data.cache[nodeName]) { 140 | node = data.cache[nodeName].cloneNode(); 141 | } else if (saveClones.test(nodeName)) { 142 | node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); 143 | } else { 144 | node = data.createElem(nodeName); 145 | } 146 | 147 | // Avoid adding some elements to fragments in IE < 9 because 148 | // * Attributes like `name` or `type` cannot be set/changed once an element 149 | // is inserted into a document/fragment 150 | // * Link elements with `src` attributes that are inaccessible, as with 151 | // a 403 response, will cause the tab/window to crash 152 | // * Script elements appended to fragments will execute when their `src` 153 | // or `text` property is set 154 | return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node; 155 | } 156 | 157 | /** 158 | * returns a shived DocumentFragment for the given document 159 | * @memberOf html5 160 | * @param {Document} ownerDocument The context document. 161 | * @returns {Object} The shived DocumentFragment. 162 | */ 163 | function createDocumentFragment(ownerDocument, data){ 164 | if (!ownerDocument) { 165 | ownerDocument = document; 166 | } 167 | if(supportsUnknownElements){ 168 | return ownerDocument.createDocumentFragment(); 169 | } 170 | data = data || getExpandoData(ownerDocument); 171 | var clone = data.frag.cloneNode(), 172 | i = 0, 173 | elems = getElements(), 174 | l = elems.length; 175 | for(;i 2 | 3 | 4 | 5 | iframe tests 6 | 7 | 8 | 16 | 30 | 55 | 66 | 67 | 68 | 69 |
70 | 71 |
72 |
73 |
74 |
75 |
76 | 79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 | 97 |
98 |
99 |
100 | 101 |
102 | 103 | -------------------------------------------------------------------------------- /test/data/inline-mixed-media.css: -------------------------------------------------------------------------------- 1 | @media screen, handheld { 2 | article.inline-mixed-media { 3 | border: 5px solid #000; 4 | } 5 | } 6 | 7 | @media print { 8 | article.inline-mixed-media { 9 | border: 5px dotted #000; 10 | } 11 | } -------------------------------------------------------------------------------- /test/data/inline-print-media.css: -------------------------------------------------------------------------------- 1 | .inline-print-media form { 2 | border: 5px solid #000; 3 | } 4 | @media print { 5 | .inline-print-media form { 6 | border: 5px dotted #000; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/data/no-print.css: -------------------------------------------------------------------------------- 1 | article:before { 2 | content: "isfnotorprint"; 3 | isfnotorprint: true; 4 | } 5 | article { 6 | content: "isfnotorprint"; 7 | isfnotorprint: true; 8 | } -------------------------------------------------------------------------------- /test/data/paramtracer.swf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aFarkas/html5shiv/daa5fd1169cf8c1b63b0659754b4d13b037c0e54/test/data/paramtracer.swf -------------------------------------------------------------------------------- /test/data/print-styles.css: -------------------------------------------------------------------------------- 1 | .print-styles article { 2 | border: 5px dotted #000; 3 | } 4 | @media print { 5 | article.print-styles-print { 6 | border: 5px dotted #000; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/data/print.css: -------------------------------------------------------------------------------- 1 | article.print { 2 | border: 5px dotted #000; 3 | } -------------------------------------------------------------------------------- /test/data/screen.css: -------------------------------------------------------------------------------- 1 | article.print { 2 | border: 5px solid #000; 3 | } 4 | .print-styles article { 5 | border: 5px solid #000; 6 | } 7 | article.print-styles-print { 8 | border: 5px solid #000; 9 | } -------------------------------------------------------------------------------- /test/highcharts/area-basic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Highcharts Example 6 | 7 | 8 | 9 | 10 | 11 |
12 | 84 | 85 | -------------------------------------------------------------------------------- /test/html5shiv.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | html5shiv Test Suite 6 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 |

html5shiv Test Suite

25 |

26 |
27 |

28 |
    29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 |
    39 | 40 |
    41 |
    42 |
    43 |
    44 |
    45 | 48 |
    49 |
    50 |
    51 |
    52 |
    53 |
    54 |
    55 |
    56 |
    57 |
    58 |
    59 |
    60 |
    61 |
    62 |
    63 | 66 |
    67 |
    68 |
    69 |
    70 | 71 | -------------------------------------------------------------------------------- /test/iframe.1-1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test 1 6 | 7 | 8 | 9 | 10 |
    11 |

    Change to Test Page 2

    12 |
    13 | 14 | -------------------------------------------------------------------------------- /test/iframe.1-2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Test 2 6 | 7 | 8 | 9 |
    10 |

    Change to Test Page 1 ...

    11 |
    12 | 13 | -------------------------------------------------------------------------------- /test/iframe.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML5Shiv 6 | 7 | 13 | 14 | 15 | 18 | 19 | 20 |
    1
    21 |
    2
    22 |
    3
    23 |
    24 | 25 |
    26 | 27 | -------------------------------------------------------------------------------- /test/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IE<9 HTML5 Shiv Tests 6 | 7 | 8 | 9 | 10 |

    11 | HTML5 Shiv Tests 12 |

    13 |

    manual Print tests

    14 | 20 |

    manual Print tests

    21 | 30 |

    additional tests

    31 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/dashboard.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/iframe.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | iframe 4 | 5 | 6 |
    span text
    7 | 8 | 9 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/test.js: -------------------------------------------------------------------------------- 1 | var foobar = "bar"; 2 | jQuery('#ap').html('bar'); 3 | ok( true, "test.js executed"); 4 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/testinit.js: -------------------------------------------------------------------------------- 1 | var jQuery = this.jQuery || "jQuery", // For testing .noConflict() 2 | $ = this.$ || "$", 3 | originaljQuery = jQuery, 4 | original$ = $, 5 | amdDefined; 6 | 7 | /** 8 | * Set up a mock AMD define function for testing AMD registration. 9 | */ 10 | function define(name, dependencies, callback) { 11 | amdDefined = callback(); 12 | } 13 | 14 | define.amd = { 15 | jQuery: true 16 | }; 17 | 18 | /** 19 | * Returns an array of elements with the given IDs, eg. 20 | * @example q("main", "foo", "bar") 21 | * @result [
    , , ] 22 | */ 23 | function q() { 24 | var r = []; 25 | 26 | for ( var i = 0; i < arguments.length; i++ ) { 27 | r.push( document.getElementById( arguments[i] ) ); 28 | } 29 | 30 | return r; 31 | } 32 | 33 | /** 34 | * Asserts that a select matches the given IDs * @example t("Check for something", "//[a]", ["foo", "baar"]); 35 | * @result returns true if "//[a]" return two elements with the IDs 'foo' and 'baar' 36 | */ 37 | function t(a,b,c) { 38 | var f = jQuery(b).get(), s = ""; 39 | 40 | for ( var i = 0; i < f.length; i++ ) { 41 | s += (s && ",") + '"' + f[i].id + '"'; 42 | } 43 | 44 | deepEqual(f, q.apply(q,c), a + " (" + b + ")"); 45 | } 46 | 47 | var fireNative; 48 | if ( document.createEvent ) { 49 | fireNative = function( node, type ) { 50 | var event = document.createEvent('HTMLEvents'); 51 | event.initEvent( type, true, true ); 52 | node.dispatchEvent( event ); 53 | }; 54 | } else { 55 | fireNative = function( node, type ) { 56 | var event = document.createEventObject(); 57 | node.fireEvent( 'on' + type, event ); 58 | }; 59 | } 60 | 61 | /** 62 | * Add random number to url to stop IE from caching 63 | * 64 | * @example url("data/test.html") 65 | * @result "data/test.html?10538358428943" 66 | * 67 | * @example url("data/test.php?foo=bar") 68 | * @result "data/test.php?foo=bar&10538358345554" 69 | */ 70 | function url(value) { 71 | return value + (/\?/.test(value) ? "&" : "?") + new Date().getTime() + "" + parseInt(Math.random()*100000); 72 | } 73 | 74 | (function () { 75 | // Store the old counts so that we only assert on tests that have actually leaked, 76 | // instead of asserting every time a test has leaked sometime in the past 77 | var oldCacheLength = 0, 78 | oldFragmentsLength = 0, 79 | oldTimersLength = 0, 80 | oldActive = 0; 81 | 82 | /** 83 | * Ensures that tests have cleaned up properly after themselves. Should be passed as the 84 | * teardown function on all modules' lifecycle object. 85 | */ 86 | this.moduleTeardown = function () { 87 | var i, fragmentsLength = 0, cacheLength = 0; 88 | 89 | // Allow QUnit.reset to clean up any attached elements before checking for leaks 90 | QUnit.reset(); 91 | 92 | for ( i in jQuery.cache ) { 93 | ++cacheLength; 94 | } 95 | 96 | jQuery.fragments = {}; 97 | 98 | for ( i in jQuery.fragments ) { 99 | ++fragmentsLength; 100 | } 101 | 102 | // Because QUnit doesn't have a mechanism for retrieving the number of expected assertions for a test, 103 | // if we unconditionally assert any of these, the test will fail with too many assertions :| 104 | if ( cacheLength !== oldCacheLength ) { 105 | equal( cacheLength, oldCacheLength, "No unit tests leak memory in jQuery.cache" ); 106 | oldCacheLength = cacheLength; 107 | } 108 | if ( fragmentsLength !== oldFragmentsLength ) { 109 | equal( fragmentsLength, oldFragmentsLength, "No unit tests leak memory in jQuery.fragments" ); 110 | oldFragmentsLength = fragmentsLength; 111 | } 112 | if ( jQuery.timers.length !== oldTimersLength ) { 113 | equal( jQuery.timers.length, oldTimersLength, "No timers are still running" ); 114 | oldTimersLength = jQuery.timers.length; 115 | } 116 | if ( jQuery.active !== oldActive ) { 117 | equal( jQuery.active, 0, "No AJAX requests are still active" ); 118 | oldActive = jQuery.active; 119 | } 120 | } 121 | }()); -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/testrunner.js: -------------------------------------------------------------------------------- 1 | jQuery.noConflict(); // Allow the test to run with other libs or jQuery's. 2 | 3 | // jQuery-specific QUnit.reset 4 | (function() { 5 | var reset = QUnit.reset, 6 | ajaxSettings = jQuery.ajaxSettings; 7 | 8 | QUnit.reset = function() { 9 | reset.apply(this, arguments); 10 | jQuery.event.global = {}; 11 | jQuery.ajaxSettings = jQuery.extend({}, ajaxSettings); 12 | }; 13 | })(); 14 | 15 | // load testswarm agent 16 | (function() { 17 | var url = window.location.search; 18 | url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); 19 | if ( !url || url.indexOf("http") !== 0 ) { 20 | return; 21 | } 22 | 23 | // (Temporarily) Disable Ajax tests to reduce network strain 24 | // isLocal = QUnit.isLocal = true; 25 | 26 | document.write(""); 27 | })(); 28 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/testsuite.css: -------------------------------------------------------------------------------- 1 | /* for testing opacity set in styles in IE */ 2 | ol#empty { opacity: 0; filter:Alpha(opacity=0) progid:DXImageTransform.Microsoft.gradient(startColorStr='#ffff0000', EndColorStr='#ffffffff'); } 3 | 4 | div#fx-tests h4 { 5 | background: red; 6 | } 7 | 8 | div#fx-tests h4.pass { 9 | background: green; 10 | } 11 | 12 | div#fx-tests div.box { 13 | background: red; 14 | overflow: hidden; 15 | border: 2px solid #000; 16 | } 17 | 18 | div#fx-tests div.overflow { 19 | overflow: visible; 20 | } 21 | 22 | div.inline { 23 | display: inline; 24 | } 25 | 26 | div.autoheight { 27 | height: auto; 28 | } 29 | 30 | div.autowidth { 31 | width: auto; 32 | } 33 | 34 | div.autoopacity { 35 | opacity: auto; 36 | } 37 | 38 | div.largewidth { 39 | width: 100px; 40 | } 41 | 42 | div.largeheight { 43 | height: 100px; 44 | } 45 | 46 | div.largeopacity { 47 | filter: progid:DXImageTransform.Microsoft.Alpha(opacity=100); 48 | } 49 | 50 | div.medwidth { 51 | width: 50px; 52 | } 53 | 54 | div.medheight { 55 | height: 50px; 56 | } 57 | 58 | div.medopacity { 59 | opacity: 0.5; 60 | filter: progid:DXImageTransform.Microsoft.Alpha(opacity=50); 61 | } 62 | 63 | div.nowidth { 64 | width: 0px; 65 | } 66 | 67 | div.noheight { 68 | height: 0px; 69 | } 70 | 71 | div.noopacity { 72 | opacity: 0; 73 | filter: progid:DXImageTransform.Microsoft.Alpha(opacity=0); 74 | } 75 | 76 | div.hidden { 77 | display: none; 78 | } 79 | 80 | div#fx-tests div.widewidth { 81 | background-repeat: repeat-x; 82 | } 83 | 84 | div#fx-tests div.wideheight { 85 | background-repeat: repeat-y; 86 | } 87 | 88 | div#fx-tests div.widewidth.wideheight { 89 | background-repeat: repeat; 90 | } 91 | 92 | div#fx-tests div.noback { 93 | background-image: none; 94 | } 95 | 96 | div.chain, div.chain div { width: 100px; height: 20px; position: relative; float: left; } 97 | div.chain div { position: absolute; top: 0px; left: 0px; } 98 | 99 | div.chain.test { background: red; } 100 | div.chain.test div { background: green; } 101 | 102 | div.chain.out { background: green; } 103 | div.chain.out div { background: red; display: none; } 104 | 105 | /* tests to ensure jQuery can determine the native display mode of elements 106 | that have been set as display: none in stylesheets */ 107 | div#show-tests * { display: none; } 108 | 109 | #nothiddendiv { font-size: 16px; } 110 | #nothiddendivchild.em { font-size: 2em; } 111 | #nothiddendivchild.prct { font-size: 150%; } 112 | 113 | /* For testing type on vml in IE #7071 */ 114 | v\:oval { behavior:url(#default#VML); display:inline-block; } 115 | 116 | /* 8099 changes to default styles are read correctly */ 117 | tt { display: none; } 118 | sup { display: none; } 119 | dfn { display: none; } 120 | 121 | /* #9239 Attach a background to the body( avoid crashes in removing the test element in support ) */ 122 | body, div { background: url(http://static.jquery.com/files/rocker/images/logo_jquery_215x53.gif) no-repeat -1000px 0; } 123 | 124 | /* #6652 REMOVE FILTER:ALPHA(OPACITY=100) AFTER ANIMATION */ 125 | #t6652 div { filter: alpha(opacity=50); } 126 | 127 | /* #10501 */ 128 | section { background:#f0f; display:block; } -------------------------------------------------------------------------------- /test/jquery-1.7.1/data/versioncheck.js: -------------------------------------------------------------------------------- 1 | // Run minified source from dist (do make first) 2 | // Should be loaded before QUnit but after src 3 | (function() { 4 | if ( /jquery\=min/.test( window.location.search ) ) { 5 | jQuery.noConflict( true ); 6 | document.write(unescape("%3Cscript%20src%3D%27../dist/jquery.min.js%27%3E%3C/script%3E")); 7 | } 8 | })(); -------------------------------------------------------------------------------- /test/jquery-1.7.1/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | jQuery Test Suite 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 |

    jQuery Test Suite 20 | (minified) 21 |

    22 |

    23 |
    24 |

    25 |
      26 | 27 | 28 |
      29 |
      30 |
      31 | 32 | 33 | 34 |
      35 |
      36 |

      See this blog entry for more information.

      37 |

      38 | Here are some links in a normal paragraph: Google, 39 | Google Groups (Link). 40 | This link has class="blog": 41 | diveintomark 42 |

      43 |
      44 |

      Everything inside the red border is inside a div with id="foo".

      45 |

      This is a normal link: Yahoo

      46 |

      This link has class="blog": Simon Willison's Weblog

      47 |
      48 | 49 |

      Try them out:

      50 |
        51 |
          52 |
          53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 77 | 83 | 90 | 99 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | test element 117 |
          118 | Float test. 119 | 120 |
          121 | 122 | 123 |
          124 |
          125 | 126 |
          127 | 128 | 129 | 130 | 131 |
          132 | 133 |
          134 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 152 | 157 | 160 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 173 | 174 | 175 | 176 | 177 |
          178 |
          179 |
          180 | 186 |
          187 |
          hi there
          188 |
          189 |
          190 |
          191 |
          192 |
          193 |
          194 |
          195 |
          196 | 197 |
          198 |
            199 |
          1. Rice
          2. 200 |
          3. Beans
          4. 201 |
          5. Blinis
          6. 202 |
          7. Tofu
          8. 203 |
          204 |
          I'm hungry. I should...
          205 | ...Eat lots of food... | 206 | ...Eat a little food... | 207 | ...Eat no food... 208 | ...Eat a burger... 209 | ...Eat some funyuns... 210 | ...Eat some funyuns... 211 |
          212 | 213 |
          214 | 215 | 216 |
          217 | 218 |
          219 | 1 220 | 2 221 |
          222 |
          223 |
          224 |
          225 |
          226 |
          fadeIn
          fadeIn
          227 |
          fadeOut
          fadeOut
          228 | 229 |
          show
          show
          230 |
          hide
          hide
          231 | 232 |
          togglein
          togglein
          233 |
          toggleout
          toggleout
          234 | 235 |
          slideUp
          slideUp
          236 |
          slideDown
          slideDown
          237 | 238 |
          slideToggleIn
          slideToggleIn
          239 |
          slideToggleOut
          slideToggleOut
          240 | 241 |
          fadeToggleIn
          fadeToggleIn
          242 |
          fadeToggleOut
          fadeToggleOut
          243 | 244 |
          fadeTo
          fadeTo
          245 |
          246 |
          247 |
          248 | 249 | -------------------------------------------------------------------------------- /test/jquery-1.7.1/unit/traversing.js: -------------------------------------------------------------------------------- 1 | module("traversing", { teardown: moduleTeardown }); 2 | 3 | test("find(String)", function() { 4 | expect(5); 5 | equal( "Yahoo", jQuery("#foo").find(".blogTest").text(), "Check for find" ); 6 | 7 | // using contents will get comments regular, text, and comment nodes 8 | var j = jQuery("#nonnodes").contents(); 9 | equal( j.find("div").length, 0, "Check node,textnode,comment to find zero divs" ); 10 | 11 | deepEqual( jQuery("#qunit-fixture").find("> div").get(), q("foo", "moretests", "tabindex-tests", "liveHandlerOrder", "siblingTest"), "find child elements" ); 12 | deepEqual( jQuery("#qunit-fixture").find("> #foo, > #moretests").get(), q("foo", "moretests"), "find child elements" ); 13 | deepEqual( jQuery("#qunit-fixture").find("> #foo > p").get(), q("sndp", "en", "sap"), "find child elements" ); 14 | }); 15 | 16 | test("find(node|jQuery object)", function() { 17 | expect( 11 ); 18 | 19 | var $foo = jQuery("#foo"), 20 | $blog = jQuery(".blogTest"), 21 | $first = jQuery("#first"), 22 | $two = $blog.add( $first ), 23 | $fooTwo = $foo.add( $blog ); 24 | 25 | equal( $foo.find( $blog ).text(), "Yahoo", "Find with blog jQuery object" ); 26 | equal( $foo.find( $blog[0] ).text(), "Yahoo", "Find with blog node" ); 27 | equal( $foo.find( $first ).length, 0, "#first is not in #foo" ); 28 | equal( $foo.find( $first[0]).length, 0, "#first not in #foo (node)" ); 29 | ok( $foo.find( $two ).is(".blogTest"), "Find returns only nodes within #foo" ); 30 | ok( $fooTwo.find( $blog ).is(".blogTest"), "Blog is part of the collection, but also within foo" ); 31 | ok( $fooTwo.find( $blog[0] ).is(".blogTest"), "Blog is part of the collection, but also within foo(node)" ); 32 | 33 | equal( $two.find( $foo ).length, 0, "Foo is not in two elements" ); 34 | equal( $two.find( $foo[0] ).length, 0, "Foo is not in two elements(node)" ); 35 | equal( $two.find( $first ).length, 0, "first is in the collection and not within two" ); 36 | equal( $two.find( $first ).length, 0, "first is in the collection and not within two(node)" ); 37 | 38 | }); 39 | 40 | test("is(String|undefined)", function() { 41 | expect(29); 42 | ok( jQuery("#form").is("form"), "Check for element: A form must be a form" ); 43 | ok( !jQuery("#form").is("div"), "Check for element: A form is not a div" ); 44 | ok( jQuery("#mark").is(".blog"), "Check for class: Expected class 'blog'" ); 45 | ok( !jQuery("#mark").is(".link"), "Check for class: Did not expect class 'link'" ); 46 | ok( jQuery("#simon").is(".blog.link"), "Check for multiple classes: Expected classes 'blog' and 'link'" ); 47 | ok( !jQuery("#simon").is(".blogTest"), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); 48 | ok( jQuery("#en").is("[lang=\"en\"]"), "Check for attribute: Expected attribute lang to be 'en'" ); 49 | ok( !jQuery("#en").is("[lang=\"de\"]"), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); 50 | ok( jQuery("#text1").is("[type=\"text\"]"), "Check for attribute: Expected attribute type to be 'text'" ); 51 | ok( !jQuery("#text1").is("[type=\"radio\"]"), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); 52 | ok( jQuery("#text2").is(":disabled"), "Check for pseudoclass: Expected to be disabled" ); 53 | ok( !jQuery("#text1").is(":disabled"), "Check for pseudoclass: Expected not disabled" ); 54 | ok( jQuery("#radio2").is(":checked"), "Check for pseudoclass: Expected to be checked" ); 55 | ok( !jQuery("#radio1").is(":checked"), "Check for pseudoclass: Expected not checked" ); 56 | ok( jQuery("#foo").is(":has(p)"), "Check for child: Expected a child 'p' element" ); 57 | ok( !jQuery("#foo").is(":has(ul)"), "Check for child: Did not expect 'ul' element" ); 58 | ok( jQuery("#foo").is(":has(p):has(a):has(code)"), "Check for childs: Expected 'p', 'a' and 'code' child elements" ); 59 | ok( !jQuery("#foo").is(":has(p):has(a):has(code):has(ol)"), "Check for childs: Expected 'p', 'a' and 'code' child elements, but no 'ol'" ); 60 | 61 | ok( !jQuery("#foo").is(0), "Expected false for an invalid expression - 0" ); 62 | ok( !jQuery("#foo").is(null), "Expected false for an invalid expression - null" ); 63 | ok( !jQuery("#foo").is(""), "Expected false for an invalid expression - \"\"" ); 64 | ok( !jQuery("#foo").is(undefined), "Expected false for an invalid expression - undefined" ); 65 | ok( !jQuery("#foo").is({ plain: "object" }), "Check passing invalid object" ); 66 | 67 | // test is() with comma-seperated expressions 68 | ok( jQuery("#en").is("[lang=\"en\"],[lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); 69 | ok( jQuery("#en").is("[lang=\"de\"],[lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); 70 | ok( jQuery("#en").is("[lang=\"en\"] , [lang=\"de\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); 71 | ok( jQuery("#en").is("[lang=\"de\"] , [lang=\"en\"]"), "Comma-seperated; Check for lang attribute: Expect en or de" ); 72 | 73 | ok( !jQuery(window).is('a'), "Checking is on a window does not throw an exception(#10178)" ); 74 | ok( !jQuery(document).is('a'), "Checking is on a document does not throw an exception(#10178)" ); 75 | }); 76 | 77 | test("is(jQuery)", function() { 78 | expect(21); 79 | ok( jQuery("#form").is( jQuery("form") ), "Check for element: A form is a form" ); 80 | ok( !jQuery("#form").is( jQuery("div") ), "Check for element: A form is not a div" ); 81 | ok( jQuery("#mark").is( jQuery(".blog") ), "Check for class: Expected class 'blog'" ); 82 | ok( !jQuery("#mark").is( jQuery(".link") ), "Check for class: Did not expect class 'link'" ); 83 | ok( jQuery("#simon").is( jQuery(".blog.link") ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); 84 | ok( !jQuery("#simon").is( jQuery(".blogTest") ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); 85 | ok( jQuery("#en").is( jQuery("[lang=\"en\"]") ), "Check for attribute: Expected attribute lang to be 'en'" ); 86 | ok( !jQuery("#en").is( jQuery("[lang=\"de\"]") ), "Check for attribute: Expected attribute lang to be 'en', not 'de'" ); 87 | ok( jQuery("#text1").is( jQuery("[type=\"text\"]") ), "Check for attribute: Expected attribute type to be 'text'" ); 88 | ok( !jQuery("#text1").is( jQuery("[type=\"radio\"]") ), "Check for attribute: Expected attribute type to be 'text', not 'radio'" ); 89 | ok( !jQuery("#text1").is( jQuery("input:disabled") ), "Check for pseudoclass: Expected not disabled" ); 90 | ok( jQuery("#radio2").is( jQuery("input:checked") ), "Check for pseudoclass: Expected to be checked" ); 91 | ok( !jQuery("#radio1").is( jQuery("input:checked") ), "Check for pseudoclass: Expected not checked" ); 92 | ok( jQuery("#foo").is( jQuery("div:has(p)") ), "Check for child: Expected a child 'p' element" ); 93 | ok( !jQuery("#foo").is( jQuery("div:has(ul)") ), "Check for child: Did not expect 'ul' element" ); 94 | 95 | // Some raw elements 96 | ok( jQuery("#form").is( jQuery("form")[0] ), "Check for element: A form is a form" ); 97 | ok( !jQuery("#form").is( jQuery("div")[0] ), "Check for element: A form is not a div" ); 98 | ok( jQuery("#mark").is( jQuery(".blog")[0] ), "Check for class: Expected class 'blog'" ); 99 | ok( !jQuery("#mark").is( jQuery(".link")[0] ), "Check for class: Did not expect class 'link'" ); 100 | ok( jQuery("#simon").is( jQuery(".blog.link")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link'" ); 101 | ok( !jQuery("#simon").is( jQuery(".blogTest")[0] ), "Check for multiple classes: Expected classes 'blog' and 'link', but not 'blogTest'" ); 102 | }); 103 | 104 | test("is() with positional selectors", function() { 105 | expect(23); 106 | 107 | var html = jQuery( 108 | '

          firsttest

          ' 109 | ).appendTo( "body" ), 110 | isit = function(sel, match, expect) { 111 | equal( jQuery( sel ).is( match ), expect, "jQuery( " + sel + " ).is( " + match + " )" ); 112 | }; 113 | 114 | isit( "#posp", "#posp:first", true ); 115 | isit( "#posp", "#posp:eq(2)", false ); 116 | isit( "#posp", "#posp a:first", false ); 117 | 118 | isit( "#posp .firsta", "#posp a:first", true ); 119 | isit( "#posp .firsta", "#posp a:last", false ); 120 | isit( "#posp .firsta", "#posp a:even", true ); 121 | isit( "#posp .firsta", "#posp a:odd", false ); 122 | isit( "#posp .firsta", "#posp a:eq(0)", true ); 123 | isit( "#posp .firsta", "#posp a:eq(9)", false ); 124 | isit( "#posp .firsta", "#posp em:eq(0)", false ); 125 | isit( "#posp .firsta", "#posp em:first", false ); 126 | isit( "#posp .firsta", "#posp:first", false ); 127 | 128 | isit( "#posp .seconda", "#posp a:first", false ); 129 | isit( "#posp .seconda", "#posp a:last", true ); 130 | isit( "#posp .seconda", "#posp a:gt(0)", true ); 131 | isit( "#posp .seconda", "#posp a:lt(5)", true ); 132 | isit( "#posp .seconda", "#posp a:lt(1)", false ); 133 | 134 | isit( "#posp em", "#posp a:eq(0) em", true ); 135 | isit( "#posp em", "#posp a:lt(1) em", true ); 136 | isit( "#posp em", "#posp a:gt(1) em", false ); 137 | isit( "#posp em", "#posp a:first em", true ); 138 | isit( "#posp em", "#posp a em:last", true ); 139 | isit( "#posp em", "#posp a em:eq(2)", false ); 140 | 141 | html.remove(); 142 | }); 143 | 144 | test("index()", function() { 145 | expect( 2 ); 146 | 147 | equal( jQuery("#text2").index(), 2, "Returns the index of a child amongst its siblings" ); 148 | 149 | equal( jQuery("
          ").index(), -1, "Node without parent returns -1" ); 150 | }); 151 | 152 | test("index(Object|String|undefined)", function() { 153 | expect(16); 154 | 155 | var elements = jQuery([window, document]), 156 | inputElements = jQuery("#radio1,#radio2,#check1,#check2"); 157 | 158 | // Passing a node 159 | equal( elements.index(window), 0, "Check for index of elements" ); 160 | equal( elements.index(document), 1, "Check for index of elements" ); 161 | equal( inputElements.index(document.getElementById("radio1")), 0, "Check for index of elements" ); 162 | equal( inputElements.index(document.getElementById("radio2")), 1, "Check for index of elements" ); 163 | equal( inputElements.index(document.getElementById("check1")), 2, "Check for index of elements" ); 164 | equal( inputElements.index(document.getElementById("check2")), 3, "Check for index of elements" ); 165 | equal( inputElements.index(window), -1, "Check for not found index" ); 166 | equal( inputElements.index(document), -1, "Check for not found index" ); 167 | 168 | // Passing a jQuery object 169 | // enabled since [5500] 170 | equal( elements.index( elements ), 0, "Pass in a jQuery object" ); 171 | equal( elements.index( elements.eq(1) ), 1, "Pass in a jQuery object" ); 172 | equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Pass in a jQuery object" ); 173 | 174 | // Passing a selector or nothing 175 | // enabled since [6330] 176 | equal( jQuery("#text2").index(), 2, "Check for index amongst siblings" ); 177 | equal( jQuery("#form").children().eq(4).index(), 4, "Check for index amongst siblings" ); 178 | equal( jQuery("#radio2").index("#form :radio") , 1, "Check for index within a selector" ); 179 | equal( jQuery("#form :radio").index( jQuery("#radio2") ), 1, "Check for index within a selector" ); 180 | equal( jQuery("#radio2").index("#form :text") , -1, "Check for index not found within a selector" ); 181 | }); 182 | 183 | test("filter(Selector|undefined)", function() { 184 | expect(9); 185 | deepEqual( jQuery("#form input").filter(":checked").get(), q("radio2", "check1"), "filter(String)" ); 186 | deepEqual( jQuery("p").filter("#ap, #sndp").get(), q("ap", "sndp"), "filter('String, String')" ); 187 | deepEqual( jQuery("p").filter("#ap,#sndp").get(), q("ap", "sndp"), "filter('String,String')" ); 188 | 189 | deepEqual( jQuery("p").filter(null).get(), [], "filter(null) should return an empty jQuery object"); 190 | deepEqual( jQuery("p").filter(undefined).get(), [], "filter(undefined) should return an empty jQuery object"); 191 | deepEqual( jQuery("p").filter(0).get(), [], "filter(0) should return an empty jQuery object"); 192 | deepEqual( jQuery("p").filter("").get(), [], "filter('') should return an empty jQuery object"); 193 | 194 | // using contents will get comments regular, text, and comment nodes 195 | var j = jQuery("#nonnodes").contents(); 196 | equal( j.filter("span").length, 1, "Check node,textnode,comment to filter the one span" ); 197 | equal( j.filter("[name]").length, 0, "Check node,textnode,comment to filter the one span" ); 198 | }); 199 | 200 | test("filter(Function)", function() { 201 | expect(2); 202 | 203 | deepEqual( jQuery("#qunit-fixture p").filter(function() { return !jQuery("a", this).length }).get(), q("sndp", "first"), "filter(Function)" ); 204 | 205 | deepEqual( jQuery("#qunit-fixture p").filter(function(i, elem) { return !jQuery("a", elem).length }).get(), q("sndp", "first"), "filter(Function) using arg" ); 206 | }); 207 | 208 | test("filter(Element)", function() { 209 | expect(1); 210 | 211 | var element = document.getElementById("text1"); 212 | deepEqual( jQuery("#form input").filter(element).get(), q("text1"), "filter(Element)" ); 213 | }); 214 | 215 | test("filter(Array)", function() { 216 | expect(1); 217 | 218 | var elements = [ document.getElementById("text1") ]; 219 | deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); 220 | }); 221 | 222 | test("filter(jQuery)", function() { 223 | expect(1); 224 | 225 | var elements = jQuery("#text1"); 226 | deepEqual( jQuery("#form input").filter(elements).get(), q("text1"), "filter(Element)" ); 227 | }); 228 | 229 | 230 | test("filter() with positional selectors", function() { 231 | expect(19); 232 | 233 | var html = jQuery('' + 234 | '

          ' + 235 | '' + 236 | 'first' + 237 | '' + 238 | '' + 239 | 'test' + 240 | '' + 241 | '' + 242 | '

          ').appendTo( "body" ), 243 | filterit = function(sel, filter, length) { 244 | equal( jQuery( sel ).filter( filter ).length, length, "jQuery( " + sel + " ).filter( " + filter + " )" ); 245 | }; 246 | 247 | filterit( "#posp", "#posp:first", 1); 248 | filterit( "#posp", "#posp:eq(2)", 0 ); 249 | filterit( "#posp", "#posp a:first", 0 ); 250 | 251 | // Keep in mind this is within the selection and 252 | // not in relation to other elements (.is() is a different story) 253 | filterit( "#posp .firsta", "#posp a:first", 1 ); 254 | filterit( "#posp .firsta", "#posp a:last", 1 ); 255 | filterit( "#posp .firsta", "#posp a:last-child", 0 ); 256 | filterit( "#posp .firsta", "#posp a:even", 1 ); 257 | filterit( "#posp .firsta", "#posp a:odd", 0 ); 258 | filterit( "#posp .firsta", "#posp a:eq(0)", 1 ); 259 | filterit( "#posp .firsta", "#posp a:eq(9)", 0 ); 260 | filterit( "#posp .firsta", "#posp em:eq(0)", 0 ); 261 | filterit( "#posp .firsta", "#posp em:first", 0 ); 262 | filterit( "#posp .firsta", "#posp:first", 0 ); 263 | 264 | filterit( "#posp .seconda", "#posp a:first", 1 ); 265 | filterit( "#posp .seconda", "#posp em:first", 0 ); 266 | filterit( "#posp .seconda", "#posp a:last", 1 ); 267 | filterit( "#posp .seconda", "#posp a:gt(0)", 0 ); 268 | filterit( "#posp .seconda", "#posp a:lt(5)", 1 ); 269 | filterit( "#posp .seconda", "#posp a:lt(1)", 1 ); 270 | html.remove(); 271 | }); 272 | 273 | test("closest()", function() { 274 | expect(13); 275 | deepEqual( jQuery("body").closest("body").get(), q("body"), "closest(body)" ); 276 | deepEqual( jQuery("body").closest("html").get(), q("html"), "closest(html)" ); 277 | deepEqual( jQuery("body").closest("div").get(), [], "closest(div)" ); 278 | deepEqual( jQuery("#qunit-fixture").closest("span,#html").get(), q("html"), "closest(span,#html)" ); 279 | 280 | deepEqual( jQuery("div:eq(1)").closest("div:first").get(), [], "closest(div:first)" ); 281 | deepEqual( jQuery("div").closest("body:first div:last").get(), q("fx-tests"), "closest(body:first div:last)" ); 282 | 283 | // Test .closest() limited by the context 284 | var jq = jQuery("#nothiddendivchild"); 285 | deepEqual( jq.closest("html", document.body).get(), [], "Context limited." ); 286 | deepEqual( jq.closest("body", document.body).get(), [], "Context limited." ); 287 | deepEqual( jq.closest("#nothiddendiv", document.body).get(), q("nothiddendiv"), "Context not reached." ); 288 | 289 | //Test that .closest() returns unique'd set 290 | equal( jQuery("#qunit-fixture p").closest("#qunit-fixture").length, 1, "Closest should return a unique set" ); 291 | 292 | // Test on disconnected node 293 | equal( jQuery("

          ").find("p").closest("table").length, 0, "Make sure disconnected closest work." ); 294 | 295 | // Bug #7369 296 | equal( jQuery("
          ").closest("[foo]").length, 1, "Disconnected nodes with attribute selector" ); 297 | equal( jQuery("
          text
          ").closest("[lang]").length, 0, "Disconnected nodes with text and non-existent attribute selector" ); 298 | }); 299 | 300 | test("closest(Array)", function() { 301 | expect(7); 302 | deepEqual( jQuery("body").closest(["body"]), [{selector:"body", elem:document.body, level:1}], "closest([body])" ); 303 | deepEqual( jQuery("body").closest(["html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([html])" ); 304 | deepEqual( jQuery("body").closest(["div"]), [], "closest([div])" ); 305 | deepEqual( jQuery("#yahoo").closest(["div"]), [{"selector":"div", "elem": document.getElementById("foo"), "level": 3}, { "selector": "div", "elem": document.getElementById("qunit-fixture"), "level": 4 }], "closest([div])" ); 306 | deepEqual( jQuery("#qunit-fixture").closest(["span,#html"]), [{selector:"span,#html", elem:document.documentElement, level:4}], "closest([span,#html])" ); 307 | 308 | deepEqual( jQuery("body").closest(["body","html"]), [{selector:"body", elem:document.body, level:1}, {selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); 309 | deepEqual( jQuery("body").closest(["span","html"]), [{selector:"html", elem:document.documentElement, level:2}], "closest([body, html])" ); 310 | }); 311 | 312 | test("closest(jQuery)", function() { 313 | expect(8); 314 | var $child = jQuery("#nothiddendivchild"), 315 | $parent = jQuery("#nothiddendiv"), 316 | $main = jQuery("#qunit-fixture"), 317 | $body = jQuery("body"); 318 | ok( $child.closest( $parent ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') )" ); 319 | ok( $child.closest( $parent[0] ).is("#nothiddendiv"), "closest( jQuery('#nothiddendiv') ) :: node" ); 320 | ok( $child.closest( $child ).is("#nothiddendivchild"), "child is included" ); 321 | ok( $child.closest( $child[0] ).is("#nothiddendivchild"), "child is included :: node" ); 322 | equal( $child.closest( document.createElement("div") ).length, 0, "created element is not related" ); 323 | equal( $child.closest( $main ).length, 0, "Main not a parent of child" ); 324 | equal( $child.closest( $main[0] ).length, 0, "Main not a parent of child :: node" ); 325 | ok( $child.closest( $body.add($parent) ).is("#nothiddendiv"), "Closest ancestor retrieved." ); 326 | }); 327 | 328 | test("not(Selector|undefined)", function() { 329 | expect(11); 330 | equal( jQuery("#qunit-fixture > p#ap > a").not("#google").length, 2, "not('selector')" ); 331 | deepEqual( jQuery("p").not(".result").get(), q("firstp", "ap", "sndp", "en", "sap", "first"), "not('.class')" ); 332 | deepEqual( jQuery("p").not("#ap, #sndp, .result").get(), q("firstp", "en", "sap", "first"), "not('selector, selector')" ); 333 | deepEqual( jQuery("#form option").not("option.emptyopt:contains('Nothing'),[selected],[value='1']").get(), q("option1c", "option1d", "option2c", "option3d", "option3e", "option4e","option5b"), "not('complex selector')"); 334 | 335 | deepEqual( jQuery("#ap *").not("code").get(), q("google", "groups", "anchor1", "mark"), "not('tag selector')" ); 336 | deepEqual( jQuery("#ap *").not("code, #mark").get(), q("google", "groups", "anchor1"), "not('tag, ID selector')" ); 337 | deepEqual( jQuery("#ap *").not("#mark, code").get(), q("google", "groups", "anchor1"), "not('ID, tag selector')"); 338 | 339 | var all = jQuery("p").get(); 340 | deepEqual( jQuery("p").not(null).get(), all, "not(null) should have no effect"); 341 | deepEqual( jQuery("p").not(undefined).get(), all, "not(undefined) should have no effect"); 342 | deepEqual( jQuery("p").not(0).get(), all, "not(0) should have no effect"); 343 | deepEqual( jQuery("p").not("").get(), all, "not('') should have no effect"); 344 | }); 345 | 346 | test("not(Element)", function() { 347 | expect(1); 348 | 349 | var selects = jQuery("#form select"); 350 | deepEqual( selects.not( selects[1] ).get(), q("select1", "select3", "select4", "select5"), "filter out DOM element"); 351 | }); 352 | 353 | test("not(Function)", function() { 354 | deepEqual( jQuery("#qunit-fixture p").not(function() { return jQuery("a", this).length }).get(), q("sndp", "first"), "not(Function)" ); 355 | }); 356 | 357 | test("not(Array)", function() { 358 | expect(2); 359 | 360 | equal( jQuery("#qunit-fixture > p#ap > a").not(document.getElementById("google")).length, 2, "not(DOMElement)" ); 361 | equal( jQuery("p").not(document.getElementsByTagName("p")).length, 0, "not(Array-like DOM collection)" ); 362 | }); 363 | 364 | test("not(jQuery)", function() { 365 | expect(1); 366 | 367 | deepEqual( jQuery("p").not(jQuery("#ap, #sndp, .result")).get(), q("firstp", "en", "sap", "first"), "not(jQuery)" ); 368 | }); 369 | 370 | test("has(Element)", function() { 371 | expect(2); 372 | 373 | var obj = jQuery("#qunit-fixture").has(jQuery("#sndp")[0]); 374 | deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have the element as a descendant" ); 375 | 376 | var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")[0]); 377 | deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); 378 | }); 379 | 380 | test("has(Selector)", function() { 381 | expect(3); 382 | 383 | var obj = jQuery("#qunit-fixture").has("#sndp"); 384 | deepEqual( obj.get(), q("qunit-fixture"), "Keeps elements that have any element matching the selector as a descendant" ); 385 | 386 | var multipleParent = jQuery("#qunit-fixture, #header").has("#sndp"); 387 | deepEqual( obj.get(), q("qunit-fixture"), "Does not include elements that do not have the element as a descendant" ); 388 | 389 | var multipleHas = jQuery("#qunit-fixture").has("#sndp, #first"); 390 | deepEqual( multipleHas.get(), q("qunit-fixture"), "Only adds elements once" ); 391 | }); 392 | 393 | test("has(Arrayish)", function() { 394 | expect(3); 395 | 396 | var simple = jQuery("#qunit-fixture").has(jQuery("#sndp")); 397 | deepEqual( simple.get(), q("qunit-fixture"), "Keeps elements that have any element in the jQuery list as a descendant" ); 398 | 399 | var multipleParent = jQuery("#qunit-fixture, #header").has(jQuery("#sndp")); 400 | deepEqual( multipleParent.get(), q("qunit-fixture"), "Does not include elements that do not have an element in the jQuery list as a descendant" ); 401 | 402 | var multipleHas = jQuery("#qunit-fixture").has(jQuery("#sndp, #first")); 403 | deepEqual( simple.get(), q("qunit-fixture"), "Only adds elements once" ); 404 | }); 405 | 406 | test("andSelf()", function() { 407 | expect(4); 408 | deepEqual( jQuery("#en").siblings().andSelf().get(), q("sndp", "en", "sap"), "Check for siblings and self" ); 409 | deepEqual( jQuery("#foo").children().andSelf().get(), q("foo", "sndp", "en", "sap"), "Check for children and self" ); 410 | deepEqual( jQuery("#sndp, #en").parent().andSelf().get(), q("foo","sndp","en"), "Check for parent and self" ); 411 | deepEqual( jQuery("#groups").parents("p, div").andSelf().get(), q("qunit-fixture", "ap", "groups"), "Check for parents and self" ); 412 | }); 413 | 414 | test("siblings([String])", function() { 415 | expect(6); 416 | deepEqual( jQuery("#en").siblings().get(), q("sndp", "sap"), "Check for siblings" ); 417 | deepEqual( jQuery("#sndp").siblings(":has(code)").get(), q("sap"), "Check for filtered siblings (has code child element)" ); 418 | deepEqual( jQuery("#sndp").siblings(":has(a)").get(), q("en", "sap"), "Check for filtered siblings (has anchor child element)" ); 419 | deepEqual( jQuery("#foo").siblings("form, b").get(), q("form", "floatTest", "lengthtest", "name-tests", "testForm"), "Check for multiple filters" ); 420 | var set = q("sndp", "en", "sap"); 421 | deepEqual( jQuery("#en, #sndp").siblings().get(), set, "Check for unique results from siblings" ); 422 | deepEqual( jQuery("#option5a").siblings("option[data-attr]").get(), q("option5c"), "Has attribute selector in siblings (#9261)" ); 423 | }); 424 | 425 | test("children([String])", function() { 426 | expect(3); 427 | deepEqual( jQuery("#foo").children().get(), q("sndp", "en", "sap"), "Check for children" ); 428 | deepEqual( jQuery("#foo").children(":has(code)").get(), q("sndp", "sap"), "Check for filtered children" ); 429 | deepEqual( jQuery("#foo").children("#en, #sap").get(), q("en", "sap"), "Check for multiple filters" ); 430 | }); 431 | 432 | test("parent([String])", function() { 433 | expect(5); 434 | equal( jQuery("#groups").parent()[0].id, "ap", "Simple parent check" ); 435 | equal( jQuery("#groups").parent("p")[0].id, "ap", "Filtered parent check" ); 436 | equal( jQuery("#groups").parent("div").length, 0, "Filtered parent check, no match" ); 437 | equal( jQuery("#groups").parent("div, p")[0].id, "ap", "Check for multiple filters" ); 438 | deepEqual( jQuery("#en, #sndp").parent().get(), q("foo"), "Check for unique results from parent" ); 439 | }); 440 | 441 | test("parents([String])", function() { 442 | expect(5); 443 | equal( jQuery("#groups").parents()[0].id, "ap", "Simple parents check" ); 444 | equal( jQuery("#groups").parents("p")[0].id, "ap", "Filtered parents check" ); 445 | equal( jQuery("#groups").parents("div")[0].id, "qunit-fixture", "Filtered parents check2" ); 446 | deepEqual( jQuery("#groups").parents("p, div").get(), q("ap", "qunit-fixture"), "Check for multiple filters" ); 447 | deepEqual( jQuery("#en, #sndp").parents().get(), q("foo", "qunit-fixture", "dl", "body", "html"), "Check for unique results from parents" ); 448 | }); 449 | 450 | test("parentsUntil([String])", function() { 451 | expect(9); 452 | 453 | var parents = jQuery("#groups").parents(); 454 | 455 | deepEqual( jQuery("#groups").parentsUntil().get(), parents.get(), "parentsUntil with no selector (nextAll)" ); 456 | deepEqual( jQuery("#groups").parentsUntil(".foo").get(), parents.get(), "parentsUntil with invalid selector (nextAll)" ); 457 | deepEqual( jQuery("#groups").parentsUntil("#html").get(), parents.not(":last").get(), "Simple parentsUntil check" ); 458 | equal( jQuery("#groups").parentsUntil("#ap").length, 0, "Simple parentsUntil check" ); 459 | deepEqual( jQuery("#groups").parentsUntil("#html, #body").get(), parents.slice( 0, 3 ).get(), "Less simple parentsUntil check" ); 460 | deepEqual( jQuery("#groups").parentsUntil("#html", "div").get(), jQuery("#qunit-fixture").get(), "Filtered parentsUntil check" ); 461 | deepEqual( jQuery("#groups").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multiple-filtered parentsUntil check" ); 462 | equal( jQuery("#groups").parentsUntil("#html", "span").length, 0, "Filtered parentsUntil check, no match" ); 463 | deepEqual( jQuery("#groups, #ap").parentsUntil("#html", "p,div,dl").get(), parents.slice( 0, 3 ).get(), "Multi-source, multiple-filtered parentsUntil check" ); 464 | }); 465 | 466 | test("next([String])", function() { 467 | expect(4); 468 | equal( jQuery("#ap").next()[0].id, "foo", "Simple next check" ); 469 | equal( jQuery("#ap").next("div")[0].id, "foo", "Filtered next check" ); 470 | equal( jQuery("#ap").next("p").length, 0, "Filtered next check, no match" ); 471 | equal( jQuery("#ap").next("div, p")[0].id, "foo", "Multiple filters" ); 472 | }); 473 | 474 | test("prev([String])", function() { 475 | expect(4); 476 | equal( jQuery("#foo").prev()[0].id, "ap", "Simple prev check" ); 477 | equal( jQuery("#foo").prev("p")[0].id, "ap", "Filtered prev check" ); 478 | equal( jQuery("#foo").prev("div").length, 0, "Filtered prev check, no match" ); 479 | equal( jQuery("#foo").prev("p, div")[0].id, "ap", "Multiple filters" ); 480 | }); 481 | 482 | test("nextAll([String])", function() { 483 | expect(4); 484 | 485 | var elems = jQuery("#form").children(); 486 | 487 | deepEqual( jQuery("#label-for").nextAll().get(), elems.not(":first").get(), "Simple nextAll check" ); 488 | deepEqual( jQuery("#label-for").nextAll("input").get(), elems.not(":first").filter("input").get(), "Filtered nextAll check" ); 489 | deepEqual( jQuery("#label-for").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multiple-filtered nextAll check" ); 490 | deepEqual( jQuery("#label-for, #hidden1").nextAll("input,select").get(), elems.not(":first").filter("input,select").get(), "Multi-source, multiple-filtered nextAll check" ); 491 | }); 492 | 493 | test("prevAll([String])", function() { 494 | expect(4); 495 | 496 | var elems = jQuery( jQuery("#form").children().slice(0, 12).get().reverse() ); 497 | 498 | deepEqual( jQuery("#area1").prevAll().get(), elems.get(), "Simple prevAll check" ); 499 | deepEqual( jQuery("#area1").prevAll("input").get(), elems.filter("input").get(), "Filtered prevAll check" ); 500 | deepEqual( jQuery("#area1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multiple-filtered prevAll check" ); 501 | deepEqual( jQuery("#area1, #hidden1").prevAll("input,select").get(), elems.filter("input,select").get(), "Multi-source, multiple-filtered prevAll check" ); 502 | }); 503 | 504 | test("nextUntil([String])", function() { 505 | expect(11); 506 | 507 | var elems = jQuery("#form").children().slice( 2, 12 ); 508 | 509 | deepEqual( jQuery("#text1").nextUntil().get(), jQuery("#text1").nextAll().get(), "nextUntil with no selector (nextAll)" ); 510 | deepEqual( jQuery("#text1").nextUntil(".foo").get(), jQuery("#text1").nextAll().get(), "nextUntil with invalid selector (nextAll)" ); 511 | deepEqual( jQuery("#text1").nextUntil("#area1").get(), elems.get(), "Simple nextUntil check" ); 512 | equal( jQuery("#text1").nextUntil("#text2").length, 0, "Simple nextUntil check" ); 513 | deepEqual( jQuery("#text1").nextUntil("#area1, #radio1").get(), jQuery("#text1").next().get(), "Less simple nextUntil check" ); 514 | deepEqual( jQuery("#text1").nextUntil("#area1", "input").get(), elems.not("button").get(), "Filtered nextUntil check" ); 515 | deepEqual( jQuery("#text1").nextUntil("#area1", "button").get(), elems.not("input").get(), "Filtered nextUntil check" ); 516 | deepEqual( jQuery("#text1").nextUntil("#area1", "button,input").get(), elems.get(), "Multiple-filtered nextUntil check" ); 517 | equal( jQuery("#text1").nextUntil("#area1", "div").length, 0, "Filtered nextUntil check, no match" ); 518 | deepEqual( jQuery("#text1, #hidden1").nextUntil("#area1", "button,input").get(), elems.get(), "Multi-source, multiple-filtered nextUntil check" ); 519 | 520 | deepEqual( jQuery("#text1").nextUntil("[class=foo]").get(), jQuery("#text1").nextAll().get(), "Non-element nodes must be skipped, since they have no attributes" ); 521 | }); 522 | 523 | test("prevUntil([String])", function() { 524 | expect(10); 525 | 526 | var elems = jQuery("#area1").prevAll(); 527 | 528 | deepEqual( jQuery("#area1").prevUntil().get(), elems.get(), "prevUntil with no selector (prevAll)" ); 529 | deepEqual( jQuery("#area1").prevUntil(".foo").get(), elems.get(), "prevUntil with invalid selector (prevAll)" ); 530 | deepEqual( jQuery("#area1").prevUntil("label").get(), elems.not(":last").get(), "Simple prevUntil check" ); 531 | equal( jQuery("#area1").prevUntil("#button").length, 0, "Simple prevUntil check" ); 532 | deepEqual( jQuery("#area1").prevUntil("label, #search").get(), jQuery("#area1").prev().get(), "Less simple prevUntil check" ); 533 | deepEqual( jQuery("#area1").prevUntil("label", "input").get(), elems.not(":last").not("button").get(), "Filtered prevUntil check" ); 534 | deepEqual( jQuery("#area1").prevUntil("label", "button").get(), elems.not(":last").not("input").get(), "Filtered prevUntil check" ); 535 | deepEqual( jQuery("#area1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multiple-filtered prevUntil check" ); 536 | equal( jQuery("#area1").prevUntil("label", "div").length, 0, "Filtered prevUntil check, no match" ); 537 | deepEqual( jQuery("#area1, #hidden1").prevUntil("label", "button,input").get(), elems.not(":last").get(), "Multi-source, multiple-filtered prevUntil check" ); 538 | }); 539 | 540 | test("contents()", function() { 541 | expect(12); 542 | equal( jQuery("#ap").contents().length, 9, "Check element contents" ); 543 | ok( jQuery("#iframe").contents()[0], "Check existance of IFrame document" ); 544 | var ibody = jQuery("#loadediframe").contents()[0].body; 545 | ok( ibody, "Check existance of IFrame body" ); 546 | 547 | equal( jQuery("span", ibody).text(), "span text", "Find span in IFrame and check its text" ); 548 | 549 | jQuery(ibody).append("
          init text
          "); 550 | equal( jQuery("div", ibody).length, 2, "Check the original div and the new div are in IFrame" ); 551 | 552 | equal( jQuery("div:last", ibody).text(), "init text", "Add text to div in IFrame" ); 553 | 554 | jQuery("div:last", ibody).text("div text"); 555 | equal( jQuery("div:last", ibody).text(), "div text", "Add text to div in IFrame" ); 556 | 557 | jQuery("div:last", ibody).remove(); 558 | equal( jQuery("div", ibody).length, 1, "Delete the div and check only one div left in IFrame" ); 559 | 560 | equal( jQuery("div", ibody).text(), "span text", "Make sure the correct div is still left after deletion in IFrame" ); 561 | 562 | jQuery("", ibody).append("").appendTo(ibody); 563 | jQuery("table", ibody).remove(); 564 | equal( jQuery("div", ibody).length, 1, "Check for JS error on add and delete of a table in IFrame" ); 565 | 566 | // using contents will get comments regular, text, and comment nodes 567 | var c = jQuery("#nonnodes").contents().contents(); 568 | equal( c.length, 1, "Check node,textnode,comment contents is just one" ); 569 | equal( c[0].nodeValue, "hi", "Check node,textnode,comment contents is just the one from span" ); 570 | }); 571 | 572 | test("add(String|Element|Array|undefined)", function() { 573 | expect(16); 574 | deepEqual( jQuery("#sndp").add("#en").add("#sap").get(), q("sndp", "en", "sap"), "Check elements from document" ); 575 | deepEqual( jQuery("#sndp").add( jQuery("#en")[0] ).add( jQuery("#sap") ).get(), q("sndp", "en", "sap"), "Check elements from document" ); 576 | 577 | // We no longer support .add(form.elements), unfortunately. 578 | // There is no way, in browsers, to reliably determine the difference 579 | // between form.elements and form - and doing .add(form) and having it 580 | // add the form elements is way to unexpected, so this gets the boot. 581 | // ok( jQuery([]).add(jQuery("#form")[0].elements).length >= 13, "Check elements from array" ); 582 | 583 | // For the time being, we're discontinuing support for jQuery(form.elements) since it's ambiguous in IE 584 | // use jQuery([]).add(form.elements) instead. 585 | //equal( jQuery([]).add(jQuery("#form")[0].elements).length, jQuery(jQuery("#form")[0].elements).length, "Array in constructor must equals array in add()" ); 586 | 587 | var divs = jQuery("
          ").add("#sndp"); 588 | ok( !divs[0].parentNode, "Make sure the first element is still the disconnected node." ); 589 | 590 | divs = jQuery("
          test
          ").add("#sndp"); 591 | equal( divs[0].parentNode.nodeType, 11, "Make sure the first element is still the disconnected node." ); 592 | 593 | divs = jQuery("#sndp").add("
          "); 594 | ok( !divs[1].parentNode, "Make sure the first element is still the disconnected node." ); 595 | 596 | var tmp = jQuery("
          "); 597 | 598 | var x = jQuery([]).add(jQuery("

          xxx

          ").appendTo(tmp)).add(jQuery("

          xxx

          ").appendTo(tmp)); 599 | equal( x[0].id, "x1", "Check on-the-fly element1" ); 600 | equal( x[1].id, "x2", "Check on-the-fly element2" ); 601 | 602 | var x = jQuery([]).add(jQuery("

          xxx

          ").appendTo(tmp)[0]).add(jQuery("

          xxx

          ").appendTo(tmp)[0]); 603 | equal( x[0].id, "x1", "Check on-the-fly element1" ); 604 | equal( x[1].id, "x2", "Check on-the-fly element2" ); 605 | 606 | var x = jQuery([]).add(jQuery("

          xxx

          ")).add(jQuery("

          xxx

          ")); 607 | equal( x[0].id, "x1", "Check on-the-fly element1" ); 608 | equal( x[1].id, "x2", "Check on-the-fly element2" ); 609 | 610 | var x = jQuery([]).add("

          xxx

          ").add("

          xxx

          "); 611 | equal( x[0].id, "x1", "Check on-the-fly element1" ); 612 | equal( x[1].id, "x2", "Check on-the-fly element2" ); 613 | 614 | var notDefined; 615 | equal( jQuery([]).add(notDefined).length, 0, "Check that undefined adds nothing" ); 616 | 617 | equal( jQuery([]).add( document.getElementById("form") ).length, 1, "Add a form" ); 618 | equal( jQuery([]).add( document.getElementById("select1") ).length, 1, "Add a select" ); 619 | }); 620 | 621 | test("add(String, Context)", function() { 622 | expect(6); 623 | 624 | deepEqual( jQuery( "#firstp" ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add selector to selector " ); 625 | deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap" ).get(), q( "firstp", "ap" ), "Add gEBId to selector" ); 626 | deepEqual( jQuery( document.getElementById("firstp") ).add( document.getElementById("ap") ).get(), q( "firstp", "ap" ), "Add gEBId to gEBId" ); 627 | 628 | var ctx = document.getElementById("firstp"); 629 | deepEqual( jQuery( "#firstp" ).add( "#ap", ctx ).get(), q( "firstp" ), "Add selector to selector " ); 630 | deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", ctx ).get(), q( "firstp" ), "Add gEBId to selector, not in context" ); 631 | deepEqual( jQuery( document.getElementById("firstp") ).add( "#ap", document.getElementsByTagName("body")[0] ).get(), q( "firstp", "ap" ), "Add gEBId to selector, in context" ); 632 | }); 633 | 634 | test("eq('-1') #10616", function() { 635 | expect(3); 636 | var $divs = jQuery( "div" ); 637 | 638 | equal( $divs.eq( -1 ).length, 1, "The number -1 returns a selection that has length 1" ); 639 | equal( $divs.eq( "-1" ).length, 1, "The string '-1' returns a selection that has length 1" ); 640 | deepEqual( $divs.eq( "-1" ), $divs.eq( -1 ), "String and number -1 match" ); 641 | }); 642 | 643 | -------------------------------------------------------------------------------- /test/mixed-test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IEPP Test Suite 6 | 7 | 8 | 9 | 10 | 11 | 16 | 30 | 44 | 45 | 46 | 47 | 50 | 51 | 52 |

          53 | Print Me in IE! 54 |

          55 |

          You should see dotted broders in print.

          56 |
          57 |

          58 | 1. This text should be underlined in IE7+. 59 |

          60 |
          61 |
          62 |
          63 |
          2. inside print
          64 | 65 |
          66 |
          67 |

          68 | 3. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam non 69 |

          70 |
          71 | 78 | 83 |
          84 |
          85 |
          86 |

          87 | 6. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam non 88 |

          89 | 90 |
          91 |

          92 | 7. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam non 93 |

          94 |
          95 |
          96 |
          97 |
          98 | 99 | -------------------------------------------------------------------------------- /test/object-test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML5 Shiv 6 | 7 | 21 | 22 | 23 | 27 | 28 | 29 |
          This sentence has 3px solid border with these words highlighted.
          30 |

          static swfobject

          31 |
          32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 |
          44 |
          45 | 46 |

          dynamic swfobject

          47 |
          48 |
          49 |
          50 |
          51 |
          52 | 53 |

          innerHTML object

          54 |
          55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
          67 |
          68 | 77 | 78 | -------------------------------------------------------------------------------- /test/perf.1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML5 Shiv 6 | 7 | 8 | 9 | 10 | 11 |
          12 |
          This sentence is in a green box with these words highlighted.
          13 | 40 | 41 | -------------------------------------------------------------------------------- /test/perf.2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | HTML5 Shiv 6 | 7 | 8 | 9 | 10 | 11 |
          12 |
          This sentence is in a green box with these words highlighted.
          13 | 27 | 28 | -------------------------------------------------------------------------------- /test/qunit/qunit.css: -------------------------------------------------------------------------------- 1 | /** 2 | * QUnit v1.2.0 - A JavaScript Unit Testing Framework 3 | * 4 | * http://docs.jquery.com/QUnit 5 | * 6 | * Copyright (c) 2011 John Resig, Jörn Zaefferer 7 | * Dual licensed under the MIT (MIT-LICENSE.txt) 8 | * or GPL (GPL-LICENSE.txt) licenses. 9 | */ 10 | 11 | /** Font Family and Sizes */ 12 | 13 | #qunit-tests, #qunit-header, #qunit-banner, #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult { 14 | font-family: "Helvetica Neue Light", "HelveticaNeue-Light", "Helvetica Neue", Calibri, Helvetica, Arial, sans-serif; 15 | } 16 | 17 | #qunit-testrunner-toolbar, #qunit-userAgent, #qunit-testresult, #qunit-tests li { font-size: small; } 18 | #qunit-tests { font-size: smaller; } 19 | 20 | 21 | /** Resets */ 22 | 23 | #qunit-tests, #qunit-tests ol, #qunit-header, #qunit-banner, #qunit-userAgent, #qunit-testresult { 24 | margin: 0; 25 | padding: 0; 26 | } 27 | 28 | 29 | /** Header */ 30 | 31 | #qunit-header { 32 | padding: 0.5em 0 0.5em 1em; 33 | 34 | color: #8699a4; 35 | background-color: #0d3349; 36 | 37 | font-size: 1.5em; 38 | line-height: 1em; 39 | font-weight: normal; 40 | 41 | border-radius: 15px 15px 0 0; 42 | -moz-border-radius: 15px 15px 0 0; 43 | -webkit-border-top-right-radius: 15px; 44 | -webkit-border-top-left-radius: 15px; 45 | } 46 | 47 | #qunit-header a { 48 | text-decoration: none; 49 | color: #c2ccd1; 50 | } 51 | 52 | #qunit-header a:hover, 53 | #qunit-header a:focus { 54 | color: #fff; 55 | } 56 | 57 | #qunit-banner { 58 | height: 5px; 59 | } 60 | 61 | #qunit-testrunner-toolbar { 62 | padding: 0.5em 0 0.5em 2em; 63 | color: #5E740B; 64 | background-color: #eee; 65 | } 66 | 67 | #qunit-userAgent { 68 | padding: 0.5em 0 0.5em 2.5em; 69 | background-color: #2b81af; 70 | color: #fff; 71 | text-shadow: rgba(0, 0, 0, 0.5) 2px 2px 1px; 72 | } 73 | 74 | 75 | /** Tests: Pass/Fail */ 76 | 77 | #qunit-tests { 78 | list-style-position: inside; 79 | } 80 | 81 | #qunit-tests li { 82 | padding: 0.4em 0.5em 0.4em 2.5em; 83 | border-bottom: 1px solid #fff; 84 | list-style-position: inside; 85 | } 86 | 87 | #qunit-tests.hidepass li.pass, #qunit-tests.hidepass li.running { 88 | display: none; 89 | } 90 | 91 | #qunit-tests li strong { 92 | cursor: pointer; 93 | } 94 | 95 | #qunit-tests li a { 96 | padding: 0.5em; 97 | color: #c2ccd1; 98 | text-decoration: none; 99 | } 100 | #qunit-tests li a:hover, 101 | #qunit-tests li a:focus { 102 | color: #000; 103 | } 104 | 105 | #qunit-tests ol { 106 | margin-top: 0.5em; 107 | padding: 0.5em; 108 | 109 | background-color: #fff; 110 | 111 | border-radius: 15px; 112 | -moz-border-radius: 15px; 113 | -webkit-border-radius: 15px; 114 | 115 | box-shadow: inset 0px 2px 13px #999; 116 | -moz-box-shadow: inset 0px 2px 13px #999; 117 | -webkit-box-shadow: inset 0px 2px 13px #999; 118 | } 119 | 120 | #qunit-tests table { 121 | border-collapse: collapse; 122 | margin-top: .2em; 123 | } 124 | 125 | #qunit-tests th { 126 | text-align: right; 127 | vertical-align: top; 128 | padding: 0 .5em 0 0; 129 | } 130 | 131 | #qunit-tests td { 132 | vertical-align: top; 133 | } 134 | 135 | #qunit-tests pre { 136 | margin: 0; 137 | white-space: pre-wrap; 138 | word-wrap: break-word; 139 | } 140 | 141 | #qunit-tests del { 142 | background-color: #e0f2be; 143 | color: #374e0c; 144 | text-decoration: none; 145 | } 146 | 147 | #qunit-tests ins { 148 | background-color: #ffcaca; 149 | color: #500; 150 | text-decoration: none; 151 | } 152 | 153 | /*** Test Counts */ 154 | 155 | #qunit-tests b.counts { color: black; } 156 | #qunit-tests b.passed { color: #5E740B; } 157 | #qunit-tests b.failed { color: #710909; } 158 | 159 | #qunit-tests li li { 160 | margin: 0.5em; 161 | padding: 0.4em 0.5em 0.4em 0.5em; 162 | background-color: #fff; 163 | border-bottom: none; 164 | list-style-position: inside; 165 | } 166 | 167 | /*** Passing Styles */ 168 | 169 | #qunit-tests li li.pass { 170 | color: #5E740B; 171 | background-color: #fff; 172 | border-left: 26px solid #C6E746; 173 | } 174 | 175 | #qunit-tests .pass { color: #528CE0; background-color: #D2E0E6; } 176 | #qunit-tests .pass .test-name { color: #366097; } 177 | 178 | #qunit-tests .pass .test-actual, 179 | #qunit-tests .pass .test-expected { color: #999999; } 180 | 181 | #qunit-banner.qunit-pass { background-color: #C6E746; } 182 | 183 | /*** Failing Styles */ 184 | 185 | #qunit-tests li li.fail { 186 | color: #710909; 187 | background-color: #fff; 188 | border-left: 26px solid #EE5757; 189 | white-space: pre; 190 | } 191 | 192 | #qunit-tests > li:last-child { 193 | border-radius: 0 0 15px 15px; 194 | -moz-border-radius: 0 0 15px 15px; 195 | -webkit-border-bottom-right-radius: 15px; 196 | -webkit-border-bottom-left-radius: 15px; 197 | } 198 | 199 | #qunit-tests .fail { color: #000000; background-color: #EE5757; } 200 | #qunit-tests .fail .test-name, 201 | #qunit-tests .fail .module-name { color: #000000; } 202 | 203 | #qunit-tests .fail .test-actual { color: #EE5757; } 204 | #qunit-tests .fail .test-expected { color: green; } 205 | 206 | #qunit-banner.qunit-fail { background-color: #EE5757; } 207 | 208 | 209 | /** Result */ 210 | 211 | #qunit-testresult { 212 | padding: 0.5em 0.5em 0.5em 2.5em; 213 | 214 | color: #2b81af; 215 | background-color: #D2E0E6; 216 | 217 | border-bottom: 1px solid white; 218 | } 219 | 220 | /** Fixture */ 221 | 222 | #qunit-fixture { 223 | position: absolute; 224 | top: -10000px; 225 | left: -10000px; 226 | } 227 | -------------------------------------------------------------------------------- /test/style.all.css: -------------------------------------------------------------------------------- 1 | html { font: 75% sans-serif; overflow-y: scroll; } 2 | body { margin: 0; } 3 | pre { margin: 0; padding: 1em 0; } 4 | section { border: 0.5em solid #8C8; margin: 1em; padding: 1em; } 5 | h1 { margin: 1em 2em; } 6 | ul { font: bold 1.5em sans-serif; margin: 1em; padding: 0 0 0 1.5em; } 7 | li { margin: 1em; } 8 | a { color: #66C; text-decoration: none; } 9 | 10 | .pass { color: #090; } 11 | .fail { color: #F00; } -------------------------------------------------------------------------------- /test/style.css: -------------------------------------------------------------------------------- 1 | @import url(style.all.css); 2 | @import url(style.print.css); -------------------------------------------------------------------------------- /test/style.print.css: -------------------------------------------------------------------------------- 1 | @media print { 2 | section { 3 | border-style: dotted; 4 | } 5 | } -------------------------------------------------------------------------------- /test/unit/tests.js: -------------------------------------------------------------------------------- 1 | (function(){ 2 | 3 | module("html5shiv tests"); 4 | var blockElements = "article,aside,figcaption,figure,footer,header,hgroup,nav,section".split(','); 5 | 6 | var testEnv = [ 7 | { 8 | doc: document, 9 | initialShivMethods: html5.shivMethods, 10 | html5: html5, 11 | name: 'default' 12 | } 13 | ]; 14 | 15 | 16 | var shivTests = function(fn, env){ 17 | if(!env){ 18 | env = testEnv[0]; 19 | } 20 | env.html5.shivMethods = true; 21 | fn(); 22 | env.html5.shivMethods = env.initialShivMethods; 23 | }; 24 | 25 | var envTest = function(name, fn, frames){ 26 | if(!frames){ 27 | frames = ['default']; 28 | } 29 | asyncTest(name, function(){ 30 | $.each(testEnv, function(i, env){ 31 | if($.inArray(env.name, frames) != -1){ 32 | fn(env); 33 | } 34 | }); 35 | if(testEnv.length > 1){ 36 | start(); 37 | } else { 38 | initIframes(); 39 | } 40 | }); 41 | 42 | }; 43 | 44 | QUnit.reset = function() { 45 | $.each(testEnv, function(i, env){ 46 | $('#qunit-fixture', env.doc).html(env.fixture); 47 | }); 48 | }; 49 | 50 | 51 | var initIframes = function(){ 52 | if(testEnv.length > 1){return;} 53 | testEnv[0].fixture = $('#qunit-fixture').html(); 54 | 55 | $('iframe.test-frame').each(function(){ 56 | var win = this.contentWindow; 57 | if($('#qunit-fixture', win.document).length){ 58 | testEnv.push({ 59 | doc: win.document, 60 | html5: win.html5, 61 | initialShivMethods: (win.html5 || {}).shivMethods, 62 | fixture: $('#qunit-fixture', win.document).html(), 63 | name: this.src.split('?')[1] 64 | }); 65 | } 66 | }); 67 | if(testEnv.length > 1){ 68 | start(); 69 | } else { 70 | setTimeout(initIframes, 30); 71 | } 72 | }; 73 | 74 | 75 | $(initIframes); 76 | 77 | 78 | envTest("display block tests", function(env){ 79 | $.each(blockElements, function(i, elem){ 80 | equals($(elem, env.doc).css('display'), 'block', elem +" has display: block"); 81 | }); 82 | 83 | }, ['default', 'disableMethodsBefore']); 84 | 85 | envTest("test html5.createElement/html5.createDocumentFragment", function(env){ 86 | var doc5 = html5; 87 | if(env.html5){ 88 | doc5 = env.html5; 89 | env.html5.shivMethods = false; 90 | } 91 | html5.shivMethods = false; 92 | 93 | var fragDiv = doc5.createElement('div', env.doc); 94 | var frag = doc5.createDocumentFragment(env.doc); 95 | var markText = "with these words highlighted"; 96 | var div = $( doc5.createElement('div', env.doc) ).html('
          s
          ?
          ').appendTo(env.doc.getElementById('qunit-fixture')); 97 | 98 | fragDiv.innerHTML = '
          This native javascript sentence is in a green box '+markText+'?
          '; 99 | 100 | frag.appendChild(fragDiv); 101 | fragDiv.innerHTML += '
          This native javascript sentence is also in a green box '+markText+'?
          '; 102 | 103 | env.doc.getElementById('qunit-fixture').appendChild(frag); 104 | 105 | equals($('section article > mark', div).length, 1, "found mark in section > article"); 106 | equals($('section > mark', fragDiv).html(), markText, "innerHTML getter equals innerHTML setter"); 107 | equals($('article', fragDiv).css('borderTopWidth'), '2px', "article has a 2px border"); 108 | 109 | if(env.html5){ 110 | env.html5.shivMethods = env.initialShivMethods; 111 | } 112 | html5.shivMethods = true; 113 | }, ['disableMethodsBefore', 'disableMethodsAfter']); 114 | 115 | 116 | if(!html5.supportsUnknownElements){ 117 | 118 | envTest("config shivMethods test", function(env){ 119 | var div = $('
          ', env.doc).html('
          ?
          ').appendTo(env.doc.getElementById('qunit-fixture')); 120 | equals($('section article > mark', div).length, (env.html5.shivMethods) ? 1 : 0, "found/no found mark in section > article"); 121 | }, ['default', 'disableMethodsBefore', 'disableMethodsAfter']); 122 | 123 | envTest("config shivCSS test", function(env){ 124 | $.each(blockElements, function(i, elem){ 125 | equals($(elem, env.doc).css('display'), 'inline', elem +" has display: inline if unshived"); 126 | }); 127 | env.html5.shivCSS = true; 128 | env.html5.shivDocument(); 129 | $.each(blockElements, function(i, elem){ 130 | equals($(elem, env.doc).css('display'), 'block', elem +" has display: block. after reshiving"); 131 | }); 132 | }, ['disableCSS']); 133 | } 134 | 135 | envTest("config add elements test", function(env){ 136 | var value = $.trim($('abcxyz', env.doc).html()); 137 | ok((html5.supportsUnknownElements || env.html5.elements.indexOf('abcxyz') !== -1) ? value : !value, "unknownelement has one/none div inside: "+ value); 138 | }, ['default', 'disableMethodsBefore', 'addUnknownBefore', 'addUnknownAfter']); 139 | 140 | envTest("parsing tests", function(env){ 141 | $.each(blockElements, function(i, elem){ 142 | equals($(elem +' div.inside', env.doc).length, 1, elem +" has a div inside"); 143 | }); 144 | }, ['default', 'disableMethodsBefore']); 145 | 146 | envTest("style test", function(env){ 147 | var article = $('article', env.doc); 148 | equals(article.css('borderTopWidth'), '2px', "article has a 2px border"); 149 | }, ['default', 'disableMethodsBefore']); 150 | 151 | if (!html5.supportsUnknownElements) { 152 | envTest("shiv different document", function(env){ 153 | var markText = "with these words highlighted3"; 154 | var markup = '
          This jQuery 1.6.4 sentence is in a green box ' + markText + '
          ?
          '; 155 | 156 | var div = $('
          ', env.doc).html(markup).appendTo(env.doc.getElementById('qunit-fixture')); 157 | equals($('section article > mark', div).length, 0, "document is not shived"); 158 | 159 | html5.shivDocument(env.doc); 160 | 161 | div = $('
          ', env.doc).html(markup).appendTo(env.doc.getElementById('qunit-fixture')); 162 | equals($('section article > mark', div).length, 1, "document is shived"); 163 | equals($('article', div).css('borderTopWidth'), '2px', "article has a 2px border"); 164 | 165 | }, ['noEmbed']); 166 | } 167 | 168 | envTest("createElement/innerHTML test", function(env){ 169 | shivTests( 170 | function(){ 171 | var div = env.doc.createElement('div'); 172 | var text = "This native javascript sentence is in a green box with these words highlighted?"; 173 | div.innerHTML = '
          '+ text +'
          '; 174 | env.doc.getElementById('qunit-fixture').appendChild(div); 175 | equals($('#section', env.doc).html(), text, "innerHTML getter equals innerHTML setter"); 176 | equals($('#section mark', env.doc).length, 1, "section has a mark element inside"); 177 | }, 178 | env 179 | ); 180 | }, ['default', 'disableMethodsBefore']); 181 | 182 | envTest("createElement/createDocumentFragment/innerHTML test", function(env){ 183 | shivTests( 184 | function(){ 185 | var div = env.doc.createElement('div'); 186 | var frag = env.doc.createDocumentFragment(); 187 | var markText = "with these words highlighted"; 188 | div.innerHTML = '
          This native javascript sentence is in a green box '+markText+'?
          '; 189 | frag.appendChild(div); 190 | div.innerHTML += '
          This native javascript sentence is also in a green box '+markText+'?
          '; 191 | env.doc.getElementById('qunit-fixture').appendChild(frag); 192 | equals($('section > mark', div).html(), markText, "innerHTML getter equals innerHTML setter"); 193 | equals($('article', div).css('borderTopWidth'), '2px', "article has a 2px border"); 194 | }, 195 | env 196 | ); 197 | }, ['default', 'disableMethodsBefore']); 198 | 199 | 200 | envTest("createDocumentFragment/cloneNode/innerHTML test", function(env){ 201 | shivTests( 202 | function(){ 203 | var frag = env.doc.createDocumentFragment(); 204 | var fragDiv = env.doc.createElement('div'); 205 | 206 | var markText = "with these words highlighted2"; 207 | var fragDivClone; 208 | frag.appendChild(fragDiv); 209 | 210 | fragDiv.innerHTML = '
          This native javascript sentence is also in a green box '+markText+'?
          '; 211 | 212 | fragDivClone = fragDiv.cloneNode(true); 213 | 214 | env.doc.getElementById('qunit-fixture').appendChild(fragDivClone); 215 | equals($('mark', env.doc).html(), markText, "innerHTML getter equals innerHTML setter"); 216 | }, 217 | env 218 | ); 219 | }, ['default', 'addUnknownAfter']); 220 | 221 | test("form test", function() { 222 | shivTests( 223 | function(){ 224 | var form = document.createElement('form'); 225 | var select = document.createElement('select'); 226 | var input = document.createElement('input'); 227 | var button = document.createElement('button'); 228 | var option = document.createElement('option'); 229 | var markText = "with these words highlighted2"; 230 | 231 | form.setAttribute('action', 'some/path'); 232 | form.setAttribute('name', 'formName'); 233 | form.target = '_blank'; 234 | select.name = 'selectName'; 235 | option.value = '1.value'; 236 | button.setAttribute('type', 'submit'); 237 | input.type = 'submit'; 238 | 239 | form.innerHTML = '
          This native javascript sentence is also in a green box '+markText+'?
          '; 240 | 241 | 242 | form.appendChild(select); 243 | form.appendChild(button); 244 | form.appendChild(input); 245 | 246 | 247 | 248 | if(select.add){ 249 | try { 250 | select.add(option); 251 | } catch(er){ 252 | select.appendChild(option); 253 | } 254 | } else { 255 | select.appendChild(option); 256 | } 257 | document.getElementById('qunit-fixture').appendChild(form); 258 | 259 | equals($('select option', form).val(), '1.value', "select has one option with value"); 260 | equals($('article > mark', form).html(), markText, "innerHTML getter equals innerHTML setter"); 261 | equals($('article', form).css('borderTopWidth'), '2px', "article has a 2px border"); 262 | } 263 | ); 264 | }); 265 | 266 | envTest("jQuery test", function(env){ 267 | shivTests( 268 | function(){ 269 | var markText = "with these words highlighted3"; 270 | var div = $('
          ', env.doc).html('
          This jQuery 1.6.4 sentence is in a green box '+markText+'
          ?
          ').appendTo(env.doc.getElementById('qunit-fixture')); 271 | equals($('article > mark', div).html(), markText, "innerHTML getter equals innerHTML setter"); 272 | equals($('article', div).css('borderTopWidth'), '2px', "article has a 2px border"); 273 | }, 274 | env 275 | ); 276 | }); 277 | 278 | 279 | 280 | 281 | })(); 282 | --------------------------------------------------------------------------------
          cell