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-dev`
|
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 `<head>` of your page in a conditional comment and after any stylesheets.
|
30 |
|
31 | ```html
|
32 | <!--[if lt IE 9]>
|
33 | <script src="bower_components/html5shiv/dist/html5shiv.js"></script>
|
34 | <![endif]-->
|
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 `<head>` 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 = '<section>This is a section</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 = '<section>This is a section</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](http://html5homi.es/), is [etymology](https://en.wikipedia.org/wiki/Etymology).
|