Skip to content

Commit 0c26c33

Browse files
author
cfoe
committed
add html5shiv html5 compatibility library
1 parent fab45e0 commit 0c26c33

File tree

3 files changed

+223
-8
lines changed

3 files changed

+223
-8
lines changed

interface/web/themes/default-v2/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,5 @@ source: default $3241 07/06/2012 @ 12:00 UTC+2
1717
- rm css/screen/*
1818
- mv css media-recognition from css-files to <head>-link tag
1919
- change most div-containers to new html5 tags in main.tpl.htm
20-
-
20+
- rm dom elements from main.tpl.htm
21+
- add html5shiv.js
Lines changed: 220 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,220 @@
1+
/*! HTML5 Shiv v3.5 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */
2+
;(function(window, document) {
3+
4+
/** Preset options */
5+
var options = window.html5 || {};
6+
7+
/** Used to skip problem elements */
8+
var reSkip = /^<|^(?:button|form|map|select|textarea|object|iframe|option|optgroup)$/i;
9+
10+
/** Not all elements can be cloned in IE (this list can be shortend) **/
11+
var saveClones = /^<|^(?:a|b|button|code|div|fieldset|form|h1|h2|h3|h4|h5|h6|i|iframe|img|input|label|li|link|ol|option|p|param|q|script|select|span|strong|style|table|tbody|td|textarea|tfoot|th|thead|tr|ul)$/i;
12+
13+
/** Detect whether the browser supports default html5 styles */
14+
var supportsHtml5Styles;
15+
16+
/** Detect whether the browser supports unknown elements */
17+
var supportsUnknownElements;
18+
19+
(function() {
20+
var a = document.createElement('a');
21+
22+
a.innerHTML = '<xyz></xyz>';
23+
24+
//if the hidden property is implemented we can assume, that the browser supports HTML5 Styles | this fails in Chrome 8
25+
supportsHtml5Styles = ('hidden' in a);
26+
//if we are part of Modernizr, we do an additional test to solve the Chrome 8 fail
27+
if(supportsHtml5Styles && typeof injectElementWithStyles == 'function'){
28+
injectElementWithStyles('#modernizr{}', function(node){
29+
node.hidden = true;
30+
supportsHtml5Styles = (window.getComputedStyle ?
31+
getComputedStyle(node, null) :
32+
node.currentStyle).display == 'none';
33+
});
34+
}
35+
36+
supportsUnknownElements = a.childNodes.length == 1 || (function() {
37+
// assign a false positive if unable to shiv
38+
try {
39+
(document.createElement)('a');
40+
} catch(e) {
41+
return true;
42+
}
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+
51+
}());
52+
53+
/*--------------------------------------------------------------------------*/
54+
55+
/**
56+
* Creates a style sheet with the given CSS text and adds it to the document.
57+
* @private
58+
* @param {Document} ownerDocument The document.
59+
* @param {String} cssText The CSS text.
60+
* @returns {StyleSheet} The style element.
61+
*/
62+
function addStyleSheet(ownerDocument, cssText) {
63+
var p = ownerDocument.createElement('p'),
64+
parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;
65+
66+
p.innerHTML = 'x<style>' + cssText + '</style>';
67+
return parent.insertBefore(p.lastChild, parent.firstChild);
68+
}
69+
70+
/**
71+
* Returns the value of `html5.elements` as an array.
72+
* @private
73+
* @returns {Array} An array of shived element node names.
74+
*/
75+
function getElements() {
76+
var elements = html5.elements;
77+
return typeof elements == 'string' ? elements.split(' ') : elements;
78+
}
79+
80+
/**
81+
* Shivs the `createElement` and `createDocumentFragment` methods of the document.
82+
* @private
83+
* @param {Document|DocumentFragment} ownerDocument The document.
84+
*/
85+
function shivMethods(ownerDocument) {
86+
var cache = {},
87+
docCreateElement = ownerDocument.createElement,
88+
docCreateFragment = ownerDocument.createDocumentFragment,
89+
frag = docCreateFragment();
90+
91+
ownerDocument.createElement = function(nodeName) {
92+
//abort shiv
93+
if(!html5.shivMethods){
94+
return docCreateElement(nodeName);
95+
}
96+
97+
var node;
98+
99+
if(cache[nodeName]){
100+
node = cache[nodeName].cloneNode();
101+
} else if(saveClones.test(nodeName)){
102+
node = (cache[nodeName] = docCreateElement(nodeName)).cloneNode();
103+
} else {
104+
node = docCreateElement(nodeName);
105+
}
106+
107+
// Avoid adding some elements to fragments in IE < 9 because
108+
// * Attributes like `name` or `type` cannot be set/changed once an element
109+
// is inserted into a document/fragment
110+
// * Link elements with `src` attributes that are inaccessible, as with
111+
// a 403 response, will cause the tab/window to crash
112+
// * Script elements appended to fragments will execute when their `src`
113+
// or `text` property is set
114+
return node.canHaveChildren && !reSkip.test(nodeName) ? frag.appendChild(node) : node;
115+
};
116+
117+
ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' +
118+
'var n=f.cloneNode(),c=n.createElement;' +
119+
'h.shivMethods&&(' +
120+
// unroll the `createElement` calls
121+
getElements().join().replace(/\w+/g, function(nodeName) {
122+
docCreateElement(nodeName);
123+
frag.createElement(nodeName);
124+
return 'c("' + nodeName + '")';
125+
}) +
126+
');return n}'
127+
)(html5, frag);
128+
}
129+
130+
/*--------------------------------------------------------------------------*/
131+
132+
/**
133+
* Shivs the given document.
134+
* @memberOf html5
135+
* @param {Document} ownerDocument The document to shiv.
136+
* @returns {Document} The shived document.
137+
*/
138+
function shivDocument(ownerDocument) {
139+
var shived;
140+
if (ownerDocument.documentShived) {
141+
return ownerDocument;
142+
}
143+
if (html5.shivCSS && !supportsHtml5Styles) {
144+
shived = !!addStyleSheet(ownerDocument,
145+
// corrects block display not defined in IE6/7/8/9
146+
'article,aside,details,figcaption,figure,footer,header,hgroup,nav,section{display:block}' +
147+
// corrects audio display not defined in IE6/7/8/9
148+
'audio{display:none}' +
149+
// corrects canvas and video display not defined in IE6/7/8/9
150+
'canvas,video{display:inline-block;*display:inline;*zoom:1}' +
151+
// corrects 'hidden' attribute and audio[controls] display not present in IE7/8/9
152+
'[hidden]{display:none}audio[controls]{display:inline-block;*display:inline;*zoom:1}' +
153+
// adds styling not present in IE6/7/8/9
154+
'mark{background:#FF0;color:#000}'
155+
);
156+
}
157+
if (!supportsUnknownElements) {
158+
shived = !shivMethods(ownerDocument);
159+
}
160+
if (shived) {
161+
ownerDocument.documentShived = shived;
162+
}
163+
return ownerDocument;
164+
}
165+
166+
/*--------------------------------------------------------------------------*/
167+
168+
/**
169+
* The `html5` object is exposed so that more elements can be shived and
170+
* existing shiving can be detected on iframes.
171+
* @type Object
172+
* @example
173+
*
174+
* // options can be changed before the script is included
175+
* html5 = { 'elements': 'mark section', 'shivCSS': false, 'shivMethods': false };
176+
*/
177+
var html5 = {
178+
179+
/**
180+
* An array or space separated string of node names of the elements to shiv.
181+
* @memberOf html5
182+
* @type Array|String
183+
*/
184+
'elements': options.elements || 'abbr article aside audio bdi canvas data datalist details figcaption figure footer header hgroup mark meter nav output progress section summary time video',
185+
186+
/**
187+
* A flag to indicate that the HTML5 style sheet should be inserted.
188+
* @memberOf html5
189+
* @type Boolean
190+
*/
191+
'shivCSS': !(options.shivCSS === false),
192+
193+
/**
194+
* A flag to indicate that the document's `createElement` and `createDocumentFragment`
195+
* methods should be overwritten.
196+
* @memberOf html5
197+
* @type Boolean
198+
*/
199+
'shivMethods': !(options.shivMethods === false),
200+
201+
/**
202+
* A string to describe the type of `html5` object ("default" or "default print").
203+
* @memberOf html5
204+
* @type String
205+
*/
206+
'type': 'default',
207+
208+
// shivs the document according to the specified `html5` object options
209+
'shivDocument': shivDocument
210+
};
211+
212+
/*--------------------------------------------------------------------------*/
213+
214+
// expose html5
215+
window.html5 = html5;
216+
217+
// shiv the document
218+
shivDocument(document);
219+
220+
}(this, document));

interface/web/themes/default-v2/templates/main.tpl.htm

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,8 @@
1818
<script type="text/javascript" src="js/uni-form/uni-form.jquery.js"></script>
1919
<script type="text/javascript" src="js/jquery.ispconfigsearch.js"></script>
2020
<script type="text/javascript" src="js/jquery.tipsy.js"></script>
21+
<script type="text/javascript" src="themes/default-v2/js/html5shiv.js"></script>
2122
<script language="JavaScript" type="text/javascript">
22-
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
23-
if(!is_chrome && getInternetExplorerVersion() > 8.0) {
24-
var style = document.createElement('style');
25-
style.innerHTML = '#page_margins { min-width: 980px; max-width: 80%; background: #fff; display: table;}';
26-
document.getElementsByTagName("head")[0].appendChild(style);
27-
}
28-
2923
jQuery(document).ready(function() {
3024
loadInitContent();
3125

0 commit comments

Comments
 (0)