Best JavaScript code snippet using wpt
html5.js
Source:html5.js
1/*!2 * HTML5.js v1.0.0-rc3 * Copyright 2012 John-David Dalton <http://allyoucanleet.com/>4 * Based on HTML5 Shiv vpre3.3 | @afarkas @jon_neal @rem | MIT/GPL2 Licensed5 * Available under MIT/GPL2 license6 */7;(function(window, document) {8 'use strict';9 /** Preset for the install/uninstall methods */10 var allOptions = { 'methods': true, 'print': true, 'styles': true };11 /** Cache of created elements, document methods, and install state */12 var html5Cache = {};13 /** Previous `html5` object */14 var old = window.html5;15 /** List of HTML5 node names to install support for */16 var nodeNames = [17 'abbr', 'article', 'aside', 'audio', 'bdi', 'canvas', 'data', 'datalist',18 'details', 'figcaption', 'figure', 'footer', 'header', 'main',19 'mark', 'meter', 'nav', 'output', 'progress', 'section', 'summary', 'time',20 'video'21 ];22 /** Used to namespace printable elements and define `expando` */23 var namespace = 'html5js';24 /** Used to store an elements `uid` if `element.uniqueNumber` is not supported */25 var expando = namespace + /\d+$/.exec(Math.random());26 /** Used to filter media types */27 var reMedia = /^$|\b(?:all|print)\b/;28 /**29 * Used to skip elements with type attributes because in IE they cannot be30 * set/changed once an element is inserted into a document/fragment.31 * http://msdn.microsoft.com/en-us/library/ie/ms534700(v=vs.85).aspx32 */33 var reSkip = /^(?:button|select)$/i;34 /** Used to detect elements that cannot be cloned correctly */35 var reUnclonable = /^<\?/;36 /** Used as a fallback for `element.uniqueNumber` */37 var uid = 1;38 /** Cache of unclonable element node names */39 var unclonables = {};40 /**41 * An object used to flag features.42 *43 * @static44 * @memberOf html545 * @type Object46 */47 var support = {};48 (function() {49 var p,50 parent,51 sandbox;52 // create a new document used to get untainted styles53 try {54 // avoid https: protocol issues with IE55 sandbox = new ActiveXObject(location.protocol == 'https:' && 'htmlfile');56 } catch(e) {57 // http://xkr.us/articles/dom/iframe-document/58 (sandbox = document.createElement('iframe')).name = expando;59 sandbox.frameBorder = sandbox.height = sandbox.width = 0;60 parent = document.body || document.documentElement;61 parent.insertBefore(sandbox, parent.firstChild);62 sandbox = (sandbox = sandbox.contentWindow || sandbox.contentDocument || frames[expando]).document || sandbox;63 }64 sandbox.write('<!doctype html><title></title><body><script>document.w = this<\/script>');65 sandbox.close();66 p = sandbox.body.appendChild(sandbox.createElement('p'));67 p.innerHTML = '<nav/>';68 /**69 * Detect whether the browser supports default HTML5 styles.70 * @memberOf html5.support71 * @type Boolean72 */73 support.html5Styles = !!p.firstChild &&74 (p.firstChild.currentStyle || sandbox.w.getComputedStyle(p.firstChild, null)).display == 'block';75 /**76 * Detect whether the browser supports unknown elements.77 *78 * @memberOf html5.support79 * @type Boolean80 */81 support.unknownElements = p.childNodes.length == 1 || (function() {82 // assign a false positive if unable to install83 try {84 (document.createElement)('p');85 } catch(e) {86 return true;87 }88 var frag = document.createDocumentFragment();89 return (90 typeof frag.createElement == 'undefined' ||91 typeof p.uniqueNumber == 'undefined'92 );93 }());94 /**95 * Detect whether the browser supports printing html5 elements.96 *97 * @memberOf html5.support98 * @type Boolean99 */100 support.html5Printing = support.unknownElements || (101 // assign a false positive if unable to install102 typeof document.namespaces == 'undefined' ||103 typeof document.parentWindow == 'undefined' ||104 typeof p.applyElement == 'undefined' ||105 typeof p.removeNode == 'undefined' ||106 typeof window.attachEvent == 'undefined'107 );108 parent && destroyElement(sandbox.w.frameElement);109 }());110 /*--------------------------------------------------------------------------*/111 /**112 * Creates a style sheet of modified CSS rules to style the print wrappers.113 * (e.g. the CSS rule "header{}" becomes "html5js\:header{}")114 *115 * @private116 * @param {Document} ownerDocument The document.117 * @param {String} cssText The CSS text.118 * @returns {StyleSheet} The style element.119 */120 function addPrintSheet(ownerDocument, cssText) {121 var pair,122 parts = cssText.split('{'),123 index = parts.length,124 reElements = RegExp('(^|[\\s,>+~])(' + nodeNames.join('|') + ')(?=[[\\s,>+~#.:]|$)', 'gi'),125 replacement = '$1' + namespace + '\\:$2';126 while (index--) {127 pair = parts[index] = parts[index].split('}');128 pair[pair.length - 1] = pair[pair.length - 1].replace(reElements, replacement);129 parts[index] = pair.join('}');130 }131 return addStyleSheet(ownerDocument, parts.join('{'));132 }133 /**134 * Wraps all HTML5 elements in the given document with printable elements.135 * (e.g. the "header" element is wrapped with the "html5js:header" element)136 *137 * @private138 * @param {Document} ownerDocument The document.139 * @returns {Array} An array of added wrappers.140 */141 function addPrintWrappers(ownerDocument) {142 var node,143 nodes = ownerDocument.getElementsByTagName('*'),144 index = nodes.length,145 reElements = RegExp('^(?:' + nodeNames.join('|') + ')$', 'i'),146 result = [];147 while (index--) {148 node = nodes[index];149 if (reElements.test(node.nodeName)) {150 result.push(node.applyElement(createPrintWrapper(node)));151 }152 }153 return result;154 }155 /**156 * Creates a style sheet with the given CSS text and adds it to the document.157 *158 * @private159 * @param {Document} ownerDocument The document.160 * @param {String} cssText The CSS text.161 * @returns {StyleSheet} The style sheet.162 */163 function addStyleSheet(ownerDocument, cssText) {164 // IE8 only respects namespace prefixs when created with `innerHTML`165 var p = ownerDocument.createElement('p'),166 parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;167 p.innerHTML = 'x<style>' + cssText + '</style>';168 return parent.insertBefore(p.lastChild, parent.firstChild);169 }170 /**171 * Creates HTML5 elements using the given document enabling the document to172 * parse them correctly.173 *174 * @private175 * @param {Document|Fragment} ownerDocument The document.176 * @returns {Document|Fragment} The document.177 */178 function createElements(ownerDocument) {179 var index = nodeNames.length,180 create = ownerDocument.createElement;181 while (index--) {182 create(nodeNames[index]);183 }184 return ownerDocument;185 }186 /**187 * Creates a printable wrapper for the given element.188 *189 * @private190 * @param {Element} element The element.191 * @returns {Element} The wrapper.192 */193 function createPrintWrapper(element) {194 var node,195 nodes = element.attributes,196 index = nodes.length,197 wrapper = element.ownerDocument.createElement(namespace + ':' + element.nodeName);198 // copy element attributes to the wrapper199 while (index--) {200 node = nodes[index];201 node.specified && wrapper.setAttribute(node.nodeName, node.nodeValue);202 }203 // copy element styles to the wrapper204 wrapper.style.cssText = element.style.cssText;205 return wrapper;206 }207 /**208 * Destroys the given element.209 *210 * @private211 * @param {Element} element The element to destroy.212 * @param {Object} [cache] The cache object.213 */214 function destroyElement(element, cache) {215 var trash = (cache || getCache(element.ownerDocument)).trash;216 trash.appendChild(element);217 trash.innerHTML = '';218 }219 /**220 * Gets the cache object for the given document.221 *222 * @private223 * @param {Document} ownerDocument The document.224 * @returns {Object} The cache object.225 */226 function getCache(ownerDocument) {227 var docEl = ownerDocument.documentElement,228 id = docEl.uniqueNumber || docEl[expando] || (docEl[expando] = uid++),229 skip = support.unknownElements;230 return html5Cache[id] || (html5Cache[id] = {231 'frag': !skip && createElements(ownerDocument.createDocumentFragment()),232 'nativeCreateElement': !skip && createElements(ownerDocument).createElement,233 'nativeCreateFragment': !skip && ownerDocument.createDocumentFragment,234 'nodes': {},235 'trash': ownerDocument.createElement('div')236 });237 }238 /**239 * Removes the given print wrappers, leaving the original elements.240 *241 * @private242 * @param {Document} ownerDocument The document.243 * @params {Array} wrappers An array of wrappers.244 */245 function removePrintWrappers(ownerDocument, wrappers) {246 var cache = getCache(ownerDocument),247 index = wrappers.length;248 while (index--) {249 destroyElement(wrappers[index].removeNode(), cache);250 }251 }252 /**253 * Resolves an options object from the given value.254 *255 * @private256 * @param {Mixed} value The value to convert to an options object.257 * @returns {Object} The options object.258 */259 function resolveOptions(value) {260 var key;261 value = value ? (value === 'all' || value.all ? allOptions : value) : {};262 if (typeof value == 'string') {263 var object = {};264 value = value.split(/[, ]+/);265 while ((key = value.pop())) {266 object[key] = true;267 }268 value = object;269 }270 return value;271 }272 /**273 * Overwrites the document's `createElement` and `createDocumentFragment` methods274 * with `html5.createElement` and `html5.createDocumentFragment` equivalents.275 *276 * @private277 * @param {Document} ownerDocument The document.278 */279 function setMethods(ownerDocument) {280 var cache = getCache(ownerDocument),281 create = cache.nativeCreateElement,282 frag = cache.frag,283 nodes = cache.nodes;284 // allow a small amount of repeated code for better performance285 ownerDocument.createElement = function(nodeName) {286 var cached = nodes[nodeName],287 node = cached ? cached.cloneNode() : create(nodeName);288 if (!cached && !unclonables[nodeName] &&289 !(unclonables[nodeName] = reUnclonable.test(node.outerHTML))) {290 node = (nodes[nodeName] = node).cloneNode();291 }292 return node.canHaveChildren && !reSkip.test(nodeName) ? frag.appendChild(node) : node;293 };294 // compile unrolled `createElement` calls for better performance295 ownerDocument.createDocumentFragment = Function('frag',296 'return function() {\n' +297 ' var node = frag.cloneNode(), create = node.createElement;\n' +298 (nodeNames + '').replace(/\w+/g, 'create("$&")\n') + ';\n' +299 ' return node\n' +300 '}'301 )(frag);302 }303 /**304 * Adds support for printing HTML5 elements.305 *306 * @private307 * @param {Document} ownerDocument The document.308 */309 function setPrintSupport(ownerDocument) {310 var printSheet,311 wrappers,312 cache = getCache(ownerDocument),313 namespaces = ownerDocument.namespaces,314 ownerWindow = ownerDocument.parentWindow;315 ownerWindow.attachEvent('onbeforeprint', cache.onbeforeprint = function() {316 var imports,317 length,318 sheet,319 collection = ownerDocument.styleSheets,320 cssText = [],321 index = collection.length,322 sheets = [];323 // convert styleSheets collection to an array324 while (index--) {325 sheets[index] = collection[index];326 }327 // concat all style sheet CSS text328 while ((sheet = sheets.pop())) {329 // IE does not enforce a same origin policy for external style sheets...330 if (!sheet.disabled && reMedia.test(sheet.media)) {331 // ...but will throw an "access denied" error when attempting to read332 // the CSS text of a style sheet added by a script from a different origin.333 try {334 cssText.push(sheet.cssText);335 for (imports = sheet.imports, index = 0, length = imports.length; index < length; index++) {336 sheets.push(imports[index]);337 }338 } catch(e) { }339 }340 }341 // wrap all HTML5 elements with printable elements and add print style sheet342 wrappers = addPrintWrappers(ownerDocument);343 printSheet = addPrintSheet(ownerDocument, cssText.reverse().join(''));344 });345 ownerWindow.attachEvent('onafterprint', cache.onafterprint = function() {346 // remove wrappers, leaving the original elements, and remove print style sheet347 removePrintWrappers(ownerDocument, wrappers);348 destroyElement(printSheet, cache);349 });350 if (typeof namespaces[namespace] == 'undefined') {351 namespaces.add(namespace);352 }353 }354 /**355 * Adds minimal default HTML5 element styles to the given document.356 *357 * @private358 * @param {Document} ownerDocument The document.359 * @param {Object} options Options object.360 */361 function setStyles(ownerDocument, options) {362 // for additional default and normalized HTML5 element styles checkout363 // https://github.com/necolas/normalize.css364 getCache(ownerDocument).sheet = addStyleSheet(ownerDocument,365 // corrects block display not defined in IE6/7/8/9 and Firefox 3366 'article, aside, figcaption, figure, footer, header, main, nav, section {' +367 ' display: block' +368 '}' +369 // adds styling not present in IE6/7/8/9370 'mark {' +371 ' background: #ff0;' +372 ' color: #000' +373 '}'374 );375 }376 /**377 * Restores the document's original `createElement` and `createDocumentFragment` methods.378 *379 * @private380 * @param {Document} ownerDocument The document.381 */382 function unsetMethods(ownerDocument) {383 var cache = getCache(ownerDocument),384 fn = cache.nativeCreateElement;385 if (ownerDocument.createElement != fn) {386 ownerDocument.createElement = fn;387 }388 if (ownerDocument.createDocumentFragment != (fn = cache.nativeCreateFragment)) {389 ownerDocument.createDocumentFragment = fn;390 }391 }392 /**393 * Removes support for printing HTML5 elements.394 *395 * @private396 * @param {Document} ownerDocument The document.397 */398 function unsetPrintSupport(ownerDocument) {399 var cache = getCache(ownerDocument),400 ownerWindow = ownerDocument.parentWindow;401 ownerWindow.detachEvent('onbeforeprint', cache.onbeforeprint || unsetPrintSupport);402 ownerWindow.detachEvent('onafterprint', cache.onafterprint || unsetPrintSupport);403 }404 /**405 * Removes default HTML5 element styles.406 *407 * @private408 * @param {Document} ownerDocument The document.409 * @param {Object} options Options object.410 */411 function unsetStyles(ownerDocument, options) {412 var cache = getCache(ownerDocument),413 sheet = cache.sheet;414 if (sheet) {415 cache.sheet = null;416 destroyElement(sheet, cache);417 }418 }419 /*--------------------------------------------------------------------------*/420 /**421 * Creates a shimmed element of the given node name.422 *423 * @memberOf html5424 * @param {Document} [ownerDocument=document] The context document.425 * @param {String} nodeName The node name of the element to create.426 * @returns {Element} The created element.427 * @example428 *429 * // basic usage430 * html5.createElement('div');431 *432 * // from a child iframe433 * parent.html5.createElement(document, 'div');434 */435 function createElement(ownerDocument, nodeName) {436 // juggle arguments437 ownerDocument || (ownerDocument = document);438 if (ownerDocument && !ownerDocument.nodeType) {439 nodeName = ownerDocument;440 ownerDocument = document;441 }442 if (support.unknownElements) {443 return ownerDocument.createElement(nodeName);444 }445 // Avoid adding some elements to fragments in IE because446 // * attributes like `type` cannot be set/changed once an element is inserted447 // into a document/fragment448 // * link elements with `src` attributes that are inaccessible, as with449 // a 403 response, will cause the tab/window to crash450 // * script elements appended to fragments will execute when their `src`451 // or `text` property is set452 var cache = getCache(ownerDocument),453 nodes = cache.nodes,454 cached = nodes[nodeName],455 node = cached ? cached.cloneNode() : cache.nativeCreateElement(nodeName);456 // IE < 9 doesn't clone unknown elements correctly457 if (!cached && !unclonables[nodeName] &&458 !(unclonables[nodeName] = reUnclonable.test(node.outerHTML))) {459 node = (nodes[nodeName] = node).cloneNode();460 }461 return node.canHaveChildren && !reSkip.test(nodeName) ? cache.frag.appendChild(node) : node;462 }463 /**464 * Creates a shimmed document fragment.465 *466 * @memberOf html5467 * @param {Document} [ownerDocument=document] The context document.468 * @returns {Fragment} The created document fragment.469 * @example470 *471 * // basic usage472 * html5.createDocumentFragment();473 *474 * // from a child iframe475 * parent.html5.createDocumentFragment(document);476 */477 function createDocumentFragment(ownerDocument) {478 ownerDocument || (ownerDocument = document);479 return support.unknownElements480 ? ownerDocument.createDocumentFragment()481 : createElements(getCache(ownerDocument).frag.cloneNode());482 }483 /**484 * Installs shims according to the specified options.485 *486 * @memberOf html5487 * @param {Document} [ownerDocument=document] The document.488 * @param {Object} [options={}] Options object.489 * @returns {Document} The document.490 * @example491 *492 * // basic usage493 * // autmatically called on the primary document to allow IE < 9 to494 * // parse HTML5 elements correctly495 * html5.install();496 *497 * // from a child iframe498 * parent.html5.install(document);499 *500 * // with an options object501 * html5.install({502 *503 * // overwrite the document's `createElement` and `createDocumentFragment`504 * // methods with `html5.createElement` and `html5.createDocumentFragment` equivalents.505 * 'methods': true,506 *507 * // add support for printing HTML5 elements508 * 'print': true,509 *510 * // add minimal default HTML5 element styles511 * 'styles': true512 * });513 *514 * // with an options string515 * html5.install('print styles');516 *517 * // from a child iframe with options518 * parent.html5.install(document, options);519 *520 * // using a shortcut to install all support extensions521 * html5.install('all');522 */523 function install(ownerDocument, options) {524 ownerDocument || (ownerDocument = document);525 if (ownerDocument && !ownerDocument.nodeType) {526 options = ownerDocument;527 ownerDocument = document;528 }529 options = resolveOptions(options);530 uninstall(ownerDocument, {531 'methods': options.methods,532 'print': options.print,533 'styles': options.styles534 });535 if (!support.html5Styles && options.styles) {536 setStyles(ownerDocument, options);537 }538 if (!support.html5Printing && options.print) {539 setPrintSupport(ownerDocument);540 }541 if (!support.unknownElements) {542 // if not installing methods then init cache and install support543 // for basic HTML5 element parsing544 options.methods ? setMethods(ownerDocument) : getCache(ownerDocument);545 }546 return ownerDocument;547 }548 /**549 * Restores a previously overwritten `html5` object.550 * @memberOf html5551 * @returns {Object} The current `html5` object.552 */553 function noConflict() {554 window.html5 = old;555 return this;556 }557 /**558 * Uninstalls shims according to the specified options.559 *560 * @memberOf html5561 * @param {Document} [ownerDocument=document] The document.562 * @param {Object} [options={}] Options object.563 * @returns {Document} The document.564 * @example565 *566 * // basic usage with an options object567 * html5.uninstall({568 *569 * // restore the document's original `createElement`570 * // and `createDocumentFragment` methods.571 * 'methods': true,572 *573 * // remove support for printing HTML5 elements574 * 'print': true,575 *576 * // remove minimal default HTML5 element styles577 * 'styles': true578 * });579 *580 * // with an options string581 * html5.uninstall('print styles');582 *583 * // from a child iframe with options584 * parent.html5.uninstall(document, options);585 *586 * // using a shortcut to uninstall all support extensions587 * html5.uninstall('all');588 */589 function uninstall(ownerDocument, options) {590 ownerDocument || (ownerDocument = document);591 if (ownerDocument && !ownerDocument.nodeType) {592 options = ownerDocument;593 ownerDocument = document;594 }595 options = resolveOptions(options);596 if (!support.unknownElements && options.methods) {597 unsetMethods(ownerDocument);598 }599 if (!support.html5Printing && options.print) {600 unsetPrintSupport(ownerDocument);601 }602 if (!support.html5Styles && options.styles) {603 unsetStyles(ownerDocument, options);604 }605 return ownerDocument;606 }607 /*--------------------------------------------------------------------------*/608 /**609 * The `html5` object.610 * @type Object611 */612 var html5 = {613 /**614 * The semantic version number.615 * @static616 * @memberOf html5617 * @type String618 */619 'version': '1.0.0-rc',620 // an object of feature detection flags621 'support': support,622 // creates shimmed document fragments623 'createDocumentFragment': createDocumentFragment,624 // creates shimmed elements625 'createElement': createElement,626 // installs support extensions627 'install': install,628 // avoid `html5` object conflicts629 'noConflict': noConflict,630 // uninstalls support extensions631 'uninstall': uninstall632 };633 /*--------------------------------------------------------------------------*/634 // Expose the `html5` object to the global object even when an AMD loader is635 // present in case html5.js was injected by a third-party script and not636 // intended to be loaded as a module. The global assignment can be reverted in637 // the `html5` module via its `noConflict()` method.638 window.html5 = html5;639 // some AMD build optimizers, like r.js, check for specific condition patterns like the following:640 if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {641 // define as an anonymous module so, through path mapping, it can be aliased642 define(function() {643 return html5;644 });645 }...
autoptimize_single_5ee990907b315027da600eeeaee2e04b.js
Source:autoptimize_single_5ee990907b315027da600eeeaee2e04b.js
1;(function (window, document) {2 var version = '3.7.3';3 var options = window.html5 || {};4 var reSkip = /^<|^(?:button|map|select|textarea|object|iframe|option|optgroup)$/i;5 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;6 var supportsHtml5Styles;7 var expando = '_html5shiv';8 var expanID = 0;9 var expandoData = {};10 var supportsUnknownElements;11 (function () {12 try {13 var a = document.createElement('a');14 a.innerHTML = '<xyz></xyz>';15 supportsHtml5Styles = ('hidden' in a);16 supportsUnknownElements = a.childNodes.length == 1 || (function () {17 (document.createElement)('a');18 var frag = document.createDocumentFragment();19 return (typeof frag.cloneNode == 'undefined' || typeof frag.createDocumentFragment == 'undefined' || typeof frag.createElement == 'undefined');20 }());21 } catch (e) {22 supportsHtml5Styles = true;23 supportsUnknownElements = true;24 }25 }());26 function addStyleSheet(ownerDocument, cssText) {27 var p = ownerDocument.createElement('p'),28 parent = ownerDocument.getElementsByTagName('head')[0] || ownerDocument.documentElement;29 p.innerHTML = 'x<style>' + cssText + '</style>';30 return parent.insertBefore(p.lastChild, parent.firstChild);31 }32 function getElements() {33 var elements = html5.elements;34 return typeof elements == 'string' ? elements.split(' ') : elements;35 }36 function addElements(newElements, ownerDocument) {37 var elements = html5.elements;38 if (typeof elements != 'string') {39 elements = elements.join(' ');40 }41 if (typeof newElements != 'string') {42 newElements = newElements.join(' ');43 }44 html5.elements = elements + ' ' + newElements;45 shivDocument(ownerDocument);46 }47 function getExpandoData(ownerDocument) {48 var data = expandoData[ownerDocument[expando]];49 if (!data) {50 data = {};51 expanID++;52 ownerDocument[expando] = expanID;53 expandoData[expanID] = data;54 }55 return data;56 }57 function createElement(nodeName, ownerDocument, data) {58 if (!ownerDocument) {59 ownerDocument = document;60 }61 if (supportsUnknownElements) {62 return ownerDocument.createElement(nodeName);63 }64 if (!data) {65 data = getExpandoData(ownerDocument);66 }67 var node;68 if (data.cache[nodeName]) {69 node = data.cache[nodeName].cloneNode();70 } else if (saveClones.test(nodeName)) {71 node = (data.cache[nodeName] = data.createElem(nodeName)).cloneNode();72 } else {73 node = data.createElem(nodeName);74 }75 return node.canHaveChildren && !reSkip.test(nodeName) && !node.tagUrn ? data.frag.appendChild(node) : node;76 }77 function createDocumentFragment(ownerDocument, data) {78 if (!ownerDocument) {79 ownerDocument = document;80 }81 if (supportsUnknownElements) {82 return ownerDocument.createDocumentFragment();83 }84 data = data || getExpandoData(ownerDocument);85 var clone = data.frag.cloneNode(), i = 0, elems = getElements(), l = elems.length;86 for (; i < l; i++) {87 clone.createElement(elems[i]);88 }89 return clone;90 }91 function shivMethods(ownerDocument, data) {92 if (!data.cache) {93 data.cache = {};94 data.createElem = ownerDocument.createElement;95 data.createFrag = ownerDocument.createDocumentFragment;96 data.frag = data.createFrag();97 }98 ownerDocument.createElement = function (nodeName) {99 if (!html5.shivMethods) {100 return data.createElem(nodeName);101 }102 return createElement(nodeName, ownerDocument, data);103 };104 ownerDocument.createDocumentFragment = Function('h,f', 'return function(){' + 'var n=f.cloneNode(),c=n.createElement;' + 'h.shivMethods&&(' +105 getElements().join().replace(/[\w\-:]+/g, function (nodeName) {106 data.createElem(nodeName);107 data.frag.createElement(nodeName);108 return 'c("' + nodeName + '")';109 }) + ');return n}')(html5, data.frag);110 }111 function shivDocument(ownerDocument) {112 if (!ownerDocument) {113 ownerDocument = document;114 }115 var data = getExpandoData(ownerDocument);116 if (html5.shivCSS && !supportsHtml5Styles && !data.hasCSS) {117 data.hasCSS = !!addStyleSheet(ownerDocument, 'article,aside,dialog,figcaption,figure,footer,header,hgroup,main,nav,section{display:block}' + 'mark{background:#FF0;color:#000}' + 'template{display:none}');118 }119 if (!supportsUnknownElements) {120 shivMethods(ownerDocument, data);121 }122 return ownerDocument;123 }124 var html5 = {125 'elements': options.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',126 'version': version,127 'shivCSS': (options.shivCSS !== false),128 'supportsUnknownElements': supportsUnknownElements,129 'shivMethods': (options.shivMethods !== false),130 'type': 'default',131 'shivDocument': shivDocument,132 createElement: createElement,133 createDocumentFragment: createDocumentFragment,134 addElements: addElements135 };136 window.html5 = html5;137 shivDocument(document);138 if (typeof module == 'object' && module.exports) {139 module.exports = html5;140 }...
Using AI Code Generation
1function test() {2 var doc = document.implementation.createHTMLDocument("test");3 var div = doc.createElement("div");4 var span = doc.createElement("span");5 var p = doc.createElement("p");6 var text = doc.createTextNode("text");7 div.appendChild(span);8 span.appendChild(p);9 p.appendChild(text);10 var spanOwnerDocument = span.ownerDocument;11 var pOwnerDocument = p.ownerDocument;12 var textOwnerDocument = text.ownerDocument;13 var divOwnerDocument = div.ownerDocument;14 var docOwnerDocument = doc.ownerDocument;15 var docOwnerDocument2 = doc.ownerDocument;16 var docURL = doc.URL;17 var docURL2 = doc.URL;18 var docURL3 = doc.URL;19 var docURL4 = doc.URL;20 var docURL5 = doc.URL;21 var docURL6 = doc.URL;22 var docURL7 = doc.URL;23 var docURL8 = doc.URL;24 var docURL9 = doc.URL;25 var docURL10 = doc.URL;26 var docURL11 = doc.URL;27 var docURL12 = doc.URL;28 var docURL13 = doc.URL;29 var docURL14 = doc.URL;30 var docURL15 = doc.URL;31 var docURL16 = doc.URL;32 var docURL17 = doc.URL;33 var docURL18 = doc.URL;34 var docURL19 = doc.URL;35 var docURL20 = doc.URL;36 var docURL21 = doc.URL;37 var docURL22 = doc.URL;38 var docURL23 = doc.URL;39 var docURL24 = doc.URL;40 var docURL25 = doc.URL;41 var docURL26 = doc.URL;42 var docURL27 = doc.URL;43 var docURL28 = doc.URL;44 var docURL29 = doc.URL;45 var docURL30 = doc.URL;46 var docURL31 = doc.URL;47 var docURL32 = doc.URL;48 var docURL33 = doc.URL;49 var docURL34 = doc.URL;50 var docURL35 = doc.URL;51 var docURL36 = doc.URL;52 var docURL37 = doc.URL;53 var docURL38 = doc.URL;54 var docURL39 = doc.URL;55 var docURL40 = doc.URL;56 var docURL41 = doc.URL;
Using AI Code Generation
1var wpt = document.getElementById("wpt");2var ownerDoc = wpt.ownerDocument;3var ownerDocBody = ownerDoc.body;4var ownerDocTitle = ownerDoc.title;5var ownerDocURL = ownerDoc.URL;6var wpt2 = document.getElementById("wpt2");7var ownerDoc2 = wpt2.ownerDocument;8var ownerDocBody2 = ownerDoc2.body;9var ownerDocTitle2 = ownerDoc2.title;10var ownerDocURL2 = ownerDoc2.URL;11var wpt3 = document.getElementById("wpt3");12var ownerDoc3 = wpt3.ownerDocument;13var ownerDocBody3 = ownerDoc3.body;14var ownerDocTitle3 = ownerDoc3.title;15var ownerDocURL3 = ownerDoc3.URL;16var wpt4 = document.getElementById("wpt4");17var ownerDoc4 = wpt4.ownerDocument;18var ownerDocBody4 = ownerDoc4.body;19var ownerDocTitle4 = ownerDoc4.title;20var ownerDocURL4 = ownerDoc4.URL;21var wpt5 = document.getElementById("wpt5");22var ownerDoc5 = wpt5.ownerDocument;23var ownerDocBody5 = ownerDoc5.body;24var ownerDocTitle5 = ownerDoc5.title;25var ownerDocURL5 = ownerDoc5.URL;26var wpt6 = document.getElementById("wpt6");27var ownerDoc6 = wpt6.ownerDocument;28var ownerDocBody6 = ownerDoc6.body;29var ownerDocTitle6 = ownerDoc6.title;30var ownerDocURL6 = ownerDoc6.URL;31var wpt7 = document.getElementById("wpt7");32var ownerDoc7 = wpt7.ownerDocument;33var ownerDocBody7 = ownerDoc7.body;34var ownerDocTitle7 = ownerDoc7.title;35var ownerDocURL7 = ownerDoc7.URL;36var wpt8 = document.getElementById("wpt8");37var ownerDoc8 = wpt8.ownerDocument;
Using AI Code Generation
1var ownerDoc = wpt.ownerDocument;2var ownerDocName = ownerDoc.nodeName;3var ownerDocType = ownerDoc.nodeType;4var ownerDocValue = ownerDoc.nodeValue;5var ownerDoc1 = wpt1.ownerDocument;6var ownerDocName1 = ownerDoc1.nodeName;7var ownerDocType1 = ownerDoc1.nodeType;8var ownerDocValue1 = ownerDoc1.nodeValue;9var ownerDoc2 = wpt2.ownerDocument;10var ownerDocName2 = ownerDoc2.nodeName;11var ownerDocType2 = ownerDoc2.nodeType;12var ownerDocValue2 = ownerDoc2.nodeValue;13var ownerDoc3 = wpt3.ownerDocument;14var ownerDocName3 = ownerDoc3.nodeName;15var ownerDocType3 = ownerDoc3.nodeType;16var ownerDocValue3 = ownerDoc3.nodeValue;17var ownerDoc4 = wpt4.ownerDocument;18var ownerDocName4 = ownerDoc4.nodeName;19var ownerDocType4 = ownerDoc4.nodeType;20var ownerDocValue4 = ownerDoc4.nodeValue;21var ownerDoc5 = wpt5.ownerDocument;22var ownerDocName5 = ownerDoc5.nodeName;23var ownerDocType5 = ownerDoc5.nodeType;24var ownerDocValue5 = ownerDoc5.nodeValue;25var ownerDoc6 = wpt6.ownerDocument;26var ownerDocName6 = ownerDoc6.nodeName;27var ownerDocType6 = ownerDoc6.nodeType;28var ownerDocValue6 = ownerDoc6.nodeValue;29var ownerDoc7 = wpt7.ownerDocument;30var ownerDocName7 = ownerDoc7.nodeName;31var ownerDocType7 = ownerDoc7.nodeType;32var ownerDocValue7 = ownerDoc7.nodeValue;33var ownerDoc8 = wpt8.ownerDocument;34var ownerDocName8 = ownerDoc8.nodeName;35var ownerDocType8 = ownerDoc8.nodeType;36var ownerDocValue8 = ownerDoc8.nodeValue;
Using AI Code Generation
1var wpt = window.parent.wpt;2var doc = wpt.ownerDocument;3var body = doc.body;4var link = doc.createElement("a");5link.innerHTML = "WebPagetest";6body.appendChild(link);7var p = doc.createElement("p");8p.innerHTML = "The above link is created by the test script";9body.appendChild(p);10var input = doc.createElement("input");11input.type = "text";12input.id = "input1";13input.value = "This is a text input";14body.appendChild(input);15var button = doc.createElement("button");16button.innerHTML = "Click Me";17button.onclick = function() {18 alert("This is an alert");19}20body.appendChild(button);21var select = doc.createElement("select");22select.id = "select1";23var option = doc.createElement("option");24option.innerHTML = "Option 1";25select.appendChild(option);26option = doc.createElement("option");27option.innerHTML = "Option 2";28select.appendChild(option);29option = doc.createElement("option");30option.innerHTML = "Option 3";31select.appendChild(option);32body.appendChild(select);33var textarea = doc.createElement("textarea");34textarea.id = "textarea1";35textarea.value = "This is a text area";36body.appendChild(textarea);37var iframe = doc.createElement("iframe");38body.appendChild(iframe);39var script = doc.createElement("script");40body.appendChild(script);41var img = doc.createElement("img");42body.appendChild(img);43var div = doc.createElement("div");44div.id = "div1";45div.innerHTML = "This is a div";46body.appendChild(div);47var canvas = doc.createElement("canvas");48canvas.id = "canvas1";49body.appendChild(canvas);50var video = doc.createElement("video");51video.id = "video1";52body.appendChild(video);53var audio = doc.createElement("audio");54audio.id = "audio1";55body.appendChild(audio);56var object = doc.createElement("object");57object.id = "object1";58body.appendChild(object);59var embed = doc.createElement("embed");60embed.id = "embed1";61body.appendChild(embed);62var svg = doc.createElement("svg");63svg.id = "svg1";64body.appendChild(svg);65var table = doc.createElement("table");
Using AI Code Generation
1var doc = wpt.ownerDocument;2var win = doc.defaultView;3var wpt2 = win.wpt;4var wpt3 = wpt.ownerDocument.defaultView.wpt;5var doc = wpt.ownerDocument;6var win = doc.defaultView;7var wpt2 = win.wpt;8var wpt3 = wpt.ownerDocument.defaultView.wpt;9var doc = wpt.ownerDocument;10var win = doc.defaultView;11var wpt2 = win.wpt;12var wpt3 = wpt.ownerDocument.defaultView.wpt;13var doc = wpt.ownerDocument;14var win = doc.defaultView;15var wpt2 = win.wpt;16var wpt3 = wpt.ownerDocument.defaultView.wpt;17var doc = wpt.ownerDocument;18var win = doc.defaultView;19var wpt2 = win.wpt;20var wpt3 = wpt.ownerDocument.defaultView.wpt;21var doc = wpt.ownerDocument;22var win = doc.defaultView;23var wpt2 = win.wpt;24var wpt3 = wpt.ownerDocument.defaultView.wpt;25var doc = wpt.ownerDocument;26var win = doc.defaultView;27var wpt2 = win.wpt;28var wpt3 = wpt.ownerDocument.defaultView.wpt;
Using AI Code Generation
1var doc = wpt.ownerDocument;2doc.write("<h1> Hello World!! </h1>");3doc.close();4var loc = wpt.location;5var nav = wpt.navigator;6var appCodeName = nav.appCodeName;7var appName = nav.appName;8var appVersion = nav.appVersion;9var platform = nav.platform;10var userAgent = nav.userAgent;11var scr = wpt.screen;12var availHeight = scr.availHeight;13var availWidth = scr.availWidth;14var colorDepth = scr.colorDepth;15var height = scr.height;16var width = scr.width;17var pixelDepth = scr.pixelDepth;18var doc = wpt.document;19var title = doc.title;20var domain = doc.domain;21var referrer = doc.referrer;22var URL = doc.URL;23var history = wpt.history;24history.back();25history.forward();26history.go(1);27var frames = wpt.frames;28var frame = frames[0];29var frame = wpt.frame;30var frameDoc = frame.document;31frameDoc.write("<h1> Hello World!! </h1>");32frameDoc.close();33var frameElement = wpt.frameElement;34var parent = wpt.parent;35var parentDoc = parent.document;36parentDoc.write("<h1> Hello World!! </h1>");37parentDoc.close();38var opener = wpt.opener;39var openerDoc = opener.document;40openerDoc.write("<h1> Hello World!! </h1>");41openerDoc.close();42var top = wpt.top;43var topDoc = top.document;44topDoc.write("<h1> Hello World!! </h1>");45topDoc.close();46var content = wpt.content;47var contentDoc = content.document;48contentDoc.write("<h1>
Using AI Code Generation
1var doc = wpt.ownerDocument;2var testdiv = doc.getElementById("testdiv");3var testdiv2 = doc.getElementById("testdiv2");4var result = wpt.contains(testdiv);5if(result == true)6{7testdiv2.innerHTML = "Test passed!";8}9{10testdiv2.innerHTML = "Test failed!";11}12var result = document.body.contains(document.getElementById("myelement"));13var result = window.contains(document.getElementById("myelement"));14var result = document.body.contains(document.getElementById("myelement"));15var result = window.contains(document.getElementById("myelement"));16var result = document.body.contains(document.getElementById("myelement"));
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!