From 3631792046947cad66ea2b7cb172d63ae64c576c Mon Sep 17 00:00:00 2001 From: aFarkas Date: Sun, 24 Jun 2012 16:17:46 +0200 Subject: [PATCH] defineProperty approach for IE8 fixes Issue #70 --- src/html5shiv-printshiv.js | 147 +++++-------------- src/html5shiv.js | 147 +++++-------------- test/data/iframed-tests.html | 103 ------------- test/html5shiv.html | 71 --------- test/unit/tests.js | 277 ----------------------------------- 5 files changed, 78 insertions(+), 667 deletions(-) delete mode 100644 test/data/iframed-tests.html delete mode 100644 test/html5shiv.html delete mode 100644 test/unit/tests.js diff --git a/src/html5shiv-printshiv.js b/src/html5shiv-printshiv.js index ef76808..4ffe22f 100644 --- a/src/html5shiv-printshiv.js +++ b/src/html5shiv-printshiv.js @@ -1,15 +1,9 @@ -/*! HTML5 Shiv v3.6RC1 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */ +/*! HTML5 Shiv v3.6IE8specialRC1 | @afarkas @jdalton @jon_neal @rem | MIT/GPL2 Licensed */ ;(function(window, document) { /*jshint evil:true */ /** Preset options */ var options = window.html5 || {}; - /** Used to skip problem elements */ - var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i; - - /** Not all elements can be cloned in IE (this list can be shortend) **/ - 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; - /** Detect whether the browser supports default html5 styles */ var supportsHtml5Styles; @@ -31,17 +25,8 @@ a.innerHTML = ''; //if the hidden property is implemented we can assume, that the browser supports basic HTML5 Styles supportsHtml5Styles = ('hidden' in a); - - supportsUnknownElements = a.childNodes.length == 1 || (function() { - // assign a false positive if unable to shiv - (document.createElement)('a'); - var frag = document.createDocumentFragment(); - return ( - typeof frag.cloneNode == 'undefined' || - typeof frag.createDocumentFragment == 'undefined' || - typeof frag.createElement == 'undefined' - ); - }()); + // assign a false positive if unable to shiv + supportsUnknownElements = a.childNodes.length == 1 || !a.document || !Object.defineProperty; } catch(e) { supportsHtml5Styles = true; supportsUnknownElements = true; @@ -93,65 +78,14 @@ return data; } - /** - * returns a shived element for the given nodeName and document - * @memberOf html5 - * @param {String} nodeName name of the element - * @param {Document} ownerDocument The context document. - * @returns {Object} The shived element. - */ - function createElement(nodeName, ownerDocument, data){ - if (!ownerDocument) { - ownerDocument = document; - } - if(supportsUnknownElements){ - return ownerDocument.createElement(nodeName); - } - if (!data) { - data = getExpandoData(ownerDocument); - } - var node; - - if (data.cache[nodeName]) { - node = data.cache[nodeName].cloneNode(); - } else if (saveClones.test(nodeName)) { - node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode(); - } else { - node = data.createElem(nodeName); - } - - // Avoid adding some elements to fragments in IE < 9 because - // * Attributes like `name` or `type` cannot be set/changed once an element - // is inserted into a document/fragment - // * Link elements with `src` attributes that are inaccessible, as with - // a 403 response, will cause the tab/window to crash - // * Script elements appended to fragments will execute when their `src` - // or `text` property is set - return node.canHaveChildren && !reSkip.test(nodeName) ? data.frag.appendChild(node) : node; - } - /** - * returns a shived DocumentFragment for the given document - * @memberOf html5 - * @param {Document} ownerDocument The context document. - * @returns {Object} The shived DocumentFragment. - */ - function createDocumentFragment(ownerDocument, data){ - if (!ownerDocument) { - ownerDocument = document; - } - if(supportsUnknownElements){ - return ownerDocument.createDocumentFragment(); - } - data = data || getExpandoData(ownerDocument); - var clone = data.frag.cloneNode(), - i = 0, - elems = getElements(), - l = elems.length; - for(;i