Best JavaScript code snippet using wpt
ace-extra.min.js
Source:ace-extra.min.js
1!function () {2 "ace"in window || (window.ace = {}), ace.config = {3 storage_method: 0,4 cookie_expiry: 604800,5 cookie_path: ""6 }, "vars"in window.ace || (window.ace.vars = {}), ace.vars.very_old_ie = !("querySelector"in document.documentElement), ace.settings = {7 saveState: function (a, b, c, d) {8 if (!a || "string" == typeof a && !(a = document.getElementById(a)) || !a.hasAttribute("id"))return !1;9 if (!ace.hasClass(a, "ace-save-state"))return !1;10 var b = b || "class", e = a.getAttribute("id"), f = ace.data.get("state", "id-" + e) || {};11 if ("string" == typeof f)try {12 f = JSON.parse(f)13 } catch (g) {14 f = {}15 }16 var h, i = "undefined" != typeof c, j = !1, k = /class/i, l = /checked|disabled|readonly|value/i;17 l.test(b) ? h = i ? c : a[b] : a.hasAttribute(b) ? h = i ? c : a.getAttribute(b) : i || (j = !0), j ? delete f[b] : k.test(b) ? (f.hasOwnProperty(b) || (f[b] = {}), d === !0 ? f[b][h] = 1 : d === !1 ? f[b][h] = -1 : f[b].className = h) : f[b] = h, ace.data.set("state", "id-" + e, JSON.stringify(f))18 }, loadState: function (a, b) {19 if (!a || "string" == typeof a && !(a = document.getElementById(a)) || !a.hasAttribute("id"))return !1;20 var c = a.getAttribute("id"), d = ace.data.get("state", "id-" + c) || {};21 if ("string" == typeof d)try {22 d = JSON.parse(d)23 } catch (e) {24 d = {}25 }26 var f = function (a, b, c) {27 var d = /class/i, e = /checked|disabled|readonly|value/i;28 if (d.test(b)) {29 if ("object" == typeof c) {30 "className"in c && a.setAttribute("class", c.className);31 for (var f in c)if (c.hasOwnProperty(f)) {32 var g = c[f];33 1 == g ? ace.addClass(a, f) : -1 == g && ace.removeClass(a, f)34 }35 }36 } else e.test(b) ? a[b] = c : a.setAttribute(b, c)37 };38 if (void 0 !== b)d.hasOwnProperty(b) && null !== d[b] && f(a, b, d[b]); else for (var g in d)d.hasOwnProperty(g) && null !== d[g] && f(a, g, d[g])39 }, clearState: function (a) {40 var b = null;41 "string" == typeof a ? b = a : "hasAttribute"in a && a.hasAttribute("id") && (b = a.getAttribute("id")), b && ace.data.remove("state", "id-" + b)42 }43 }, function () {44 var a = function () {45 var a = !1, b = "animation", c = "", d = "Webkit Moz O ms Khtml".split(" "), e = "", f = document.createElement("div");46 if (void 0 !== f.style.animationName && (a = !0), a === !1)for (var g = 0; g < d.length; g++)if (void 0 !== f.style[d[g] + "AnimationName"]) {47 e = d[g], b = e + "Animation", c = "-" + e.toLowerCase() + "-", a = !0;48 break49 }50 return a51 };52 if (ace.vars.animation = a(), ace.vars.animation) {53 var b = "@keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-moz-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-webkit-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-ms-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}@-o-keyframes nodeInserted{from{outline-color:#fff}to{outline-color:#000}}.ace-save-state{animation-duration:10ms;-o-animation-duration:10ms;-ms-animation-duration:10ms;-moz-animation-duration:10ms;-webkit-animation-duration:10ms;animation-delay:0s;-o-animation-delay:0s;-ms-animation-delay:0s;-moz-animation-delay:0s;-webkit-animation-delay:0s;animation-name:nodeInserted;-o-animation-name:nodeInserted;-ms-animation-name:nodeInserted;-moz-animation-name:nodeInserted;-webkit-animation-name:nodeInserted}", c = document.createElement("style");54 c.innerHTML = b, document.head.appendChild(c);55 var d = function (a) {56 var b = a.target;57 b && ace.hasClass(b, "ace-save-state") && ace.settings.loadState(b)58 };59 document.addEventListener("animationstart", d, !1), document.addEventListener("MSAnimationStart", d, !1), document.addEventListener("webkitAnimationStart", d, !1)60 } else {61 var e = function () {62 for (var a = document.querySelectorAll(".ace-save-state"), b = 0; b < a.length; b++)ace.settings.loadState(a[b])63 };64 "complete" == document.readyState ? e() : document.addEventListener ? document.addEventListener("DOMContentLoaded", e, !1) : document.attachEvent && document.attachEvent("onreadystatechange", function () {65 "complete" == document.readyState && e()66 })67 }68 }(), ace.data_storage = function (a, b) {69 var c = "ace_", d = null, e = 0;70 (1 == a || a === b || 0 == a) && "localStorage"in window && null !== window.localStorage ? (d = ace.storage, e = 1) : null == d && (2 == a || a === b) && "cookie"in document && null !== document.cookie && (d = ace.cookie, e = 2), this.set = function (a, b, f, g, h, i) {71 if (d)if (f === i)f = b, b = a, null == f ? d.remove(c + b) : 1 == e ? d.set(c + b, f) : 2 == e && d.set(c + b, f, ace.config.cookie_expiry, g || ace.config.cookie_path); else if (1 == e)null == f ? d.remove(c + a + "_" + b) : (h && "object" == typeof f && (f = JSON.stringify(f)), d.set(c + a + "_" + b, f)); else if (2 == e) {72 var j = d.get(c + a), k = j ? JSON.parse(j) : {};73 if (null == f) {74 if (delete k[b], 0 == ace.sizeof(k))return void d.remove(c + a)75 } else k[b] = f;76 d.set(c + a, JSON.stringify(k), ace.config.cookie_expiry, g || ace.config.cookie_path)77 }78 }, this.get = function (a, b, f, g) {79 if (!d)return null;80 if (b === g)return b = a, d.get(c + b);81 if (1 == e) {82 var h = d.get(c + a + "_" + b);83 if (f && h)try {84 h = JSON.parse(h)85 } catch (i) {86 }87 return h88 }89 if (2 == e) {90 var j = d.get(c + a), k = j ? JSON.parse(j) : {};91 return b in k ? k[b] : null92 }93 }, this.remove = function (a, b, c) {94 d && (b === c ? (b = a, this.set(b, null)) : this.set(a, b, null))95 }96 }, ace.cookie = {97 get: function (a) {98 var b, c, d = document.cookie, e = a + "=";99 if (d) {100 if (c = d.indexOf("; " + e), -1 == c) {101 if (c = d.indexOf(e), 0 != c)return null102 } else c += 2;103 return b = d.indexOf(";", c), -1 == b && (b = d.length), decodeURIComponent(d.substring(c + e.length, b))104 }105 }, set: function (a, b, c, d, e, f) {106 var g = new Date;107 "object" == typeof c && c.toGMTString ? c = c.toGMTString() : parseInt(c, 10) ? (g.setTime(g.getTime() + 1e3 * parseInt(c, 10)), c = g.toGMTString()) : c = "", document.cookie = a + "=" + encodeURIComponent(b) + (c ? "; expires=" + c : "") + (d ? "; path=" + d : "") + (e ? "; domain=" + e : "") + (f ? "; secure" : "")108 }, remove: function (a, b) {109 this.set(a, "", -1e3, b)110 }111 }, ace.storage = {112 get: function (a) {113 return window.localStorage.getItem(a)114 }, set: function (a, b) {115 window.localStorage.setItem(a, b)116 }, remove: function (a) {117 window.localStorage.removeItem(a)118 }119 }, ace.sizeof = function (a) {120 var b = 0;121 for (var c in a)a.hasOwnProperty(c) && b++;122 return b123 }, ace.hasClass = function (a, b) {124 return (" " + a.className + " ").indexOf(" " + b + " ") > -1125 }, ace.addClass = function (a, b) {126 for (var c = b.split(/\s+/), d = 0; d < c.length; d++)if (c[d].length > 0 && !ace.hasClass(a, c[d])) {127 var e = a.className;128 a.className = e + (e.length ? " " : "") + c[d]129 }130 }, ace.removeClass = function (a, b) {131 for (var c = b.split(/\s+/), d = 0; d < c.length; d++)c[d].length > 0 && ace.replaceClass(a, c[d]);132 ace.replaceClass(a, b)133 }, ace.replaceClass = function (a, b, c) {134 var d = new RegExp("(^|\\s)" + b + "(\\s|$)", "i");135 a.className = a.className.replace(d, function (a, b, d) {136 return c ? b + c + d : " "137 }).replace(/^\s+|\s+$/g, "")138 }, ace.toggleClass = function (a, b) {139 ace.hasClass(a, b) ? ace.removeClass(a, b) : ace.addClass(a, b)140 }, ace.isHTMlElement = function (a) {141 return window.HTMLElement ? a instanceof HTMLElement : "nodeType"in a ? 1 == a.nodeType : !1142 }, ace.data = new ace.data_storage(ace.config.storage_method)...
observer.js
Source:observer.js
1Dragon.module(['./event'], function (event) {2 var supportsCSSAnimation = Dragon.hasCssProps('AnimationName');3 function addCCRules() {4 var head = document.querySelector('head'),5 observerSheet = document.createElement("style"),6 styleText = [7 '*{',8 'animation-duration: 0.001s;',9 '-o-animation-duration: 0.001s;',10 '-ms-animation-duration: 0.001s;',11 '-moz-animation-duration: 0.001s;',12 '-webkit-animation-duration: 0.001s;',13 'animation-name: nodeInserted;',14 '-o-animation-name: nodeInserted;',15 '-ms-animation-name: nodeInserted;',16 '-moz-animation-name: nodeInserted;',17 '-webkit-animation-name: nodeInserted;',18 '}',19 '@-webkit-keyframes nodeInserted {',20 ' 50% { opacity: 1; }',21 ' }',22 '@-moz-keyframes nodeInserted {',23 ' 50% { opacity: 1; }',24 ' }',25 '@-ms-keyframes nodeInserted {',26 ' 50% { opacity: 1; }',27 ' }',28 '@-o-keyframes nodeInserted {',29 ' 50% { opacity: 1; }',30 ' }',31 '@keyframes nodeInserted {',32 ' 50% { opacity: 1; }',33 ' }'34 ];35 head.appendChild(observerSheet);36 observerSheet.setAttribute("type", "text/css");37 observerSheet.setAttribute('ObserverPolyfillCSS', '');38 if (observerSheet.styleSheet)39 observerSheet.styleSheet.cssText = styleText.join('\r\n'); // IE40 else41 observerSheet.appendChild(document.createTextNode(styleText.join('\r\n')));42 }43 return Dragon.define(function (process) {44 this._listener = function (evt) {45 if (evt.animationName && evt.animationName != "nodeInserted")46 return;47 var mutaion = { type: 'childList', addedNodes: [], removedNodes: [] };48 if (evt.animationName || evt.type === "DOMNodeInserted")49 mutaion.addedNodes.push(evt.target);50 if (evt.type === "DOMNodeRemoved")51 mutaion.removedNodes.push(evt.target);52 process([mutaion]);53 };54 }, {55 observe: function (target) {56 if (supportsCSSAnimation) {57 addCCRules();58 event.add(target, 'animationstart', this._listener); // standard + firefox59 event.add(target, 'MSAnimationStart', this._listener); // IE60 event.add(target, 'webkitAnimationStart', this._listener); // Chrome + Safari61 } else {62 event.add(target, 'DOMNodeInserted', this._listener, true);63 event.add(target, 'DOMNodeRemoved', this._listener, true);64 }65 },66 });67});...
Using AI Code Generation
1var wpt = new WebPageTest('www.webpagetest.org');2}, function(err, data) {3 if (err) {4 console.error(err);5 } else {6 console.log(data);7 wpt.getTestResults(data.data.testId, function(err, data) {8 if (err) {9 console.error(err);10 } else {11 console.log(data);12 }13 });14 }15});16var wpt = new WebPageTest('www.webpagetest.org');17}, function(err, data) {18 if (err) {19 console.error(err);20 } else {21 console.log(data);22 wpt.getTestResults(data.data.testId, function(err, data) {23 if (err) {24 console.error(err);25 } else {26 console.log(data);27 }28 });29 }30});31var wpt = new WebPageTest('www.webpagetest.org');32}, function(err, data) {33 if (err) {34 console.error(err);35 } else {36 console.log(data);37 wpt.getTestResults(data.data.testId, function(err, data) {38 if (err) {39 console.error(err);40 } else {41 console.log(data);42 }43 });44 }45});46var wpt = new WebPageTest('www.webpagetest.org');47}, function(err, data) {48 if (err) {49 console.error(err);50 } else {51 console.log(data);52 wpt.getTestResults(data.data.testId, function(err, data) {53 if (err
Using AI Code Generation
1var wpt = require('webpagetest');2var wpt = new WebPageTest('www.webpagetest.org');3var test_url = 'www.google.com';4var test_location = 'Dulles:Chrome';5var test_options = {6};7var test_id;8wpt.runTest(test_url, test_options, function(err, data) {9 if (err) {10 console.log(err);11 } else {12 test_id = data.data.testId;13 console.log('test id: ' + test_id);14 wpt.getTestResults(test_id, function(err, data) {15 if (err) {16 console.log(err);17 } else {18 console.log(data);19 }20 });21 }22});23{ [Error: connect ECONNREFUSED
Using AI Code Generation
1windw.addEventListener("DOMNodeInserted", fntion(e){2 var node = e.target;3 if (node.nodeType == 1) {4 var tagName = node.tagName.toLowerCase();5 if (tagName == 'a') {6 var href = node.getAttribute('href');7 if (href.indexOf('ttp') == 0) {8 var img = window.adcredteElement('img');9 node.appenEChilv(img);10 }11 }12 }13}, false);
Using AI Code Generation
1document.addentListener("DOMNodeInserted", function(e){2 var node = e.target;3 if (node.nodeType == 1) {4 var tagName = node.tagName.toLowerCase();5 if (tagName == 'a') {6 var href = node.getAttribute('href');7 if (href.indexOf('http') == 0) {8 var img = document.createElement('img');9 node.appendChild(img);10 }11 }12 }13}, false);
Using AI Code Generation
1var wptools = require('wptools');2var wp = new wptools();3var test = function() {4 wp.nodeInserted("test", "test", "test", "test", "test", "test", "test", "test", "test", "test");5}6test();7var wptools = function() {8 this.nodeInserted = function(a, b, c, d, e, f, g, h, i, j) {ode to use nodeInserted method of wptouch9 console.log(a, b, c, d, e, f, g, h, i, j);document.addEventListener('DOMContentLoaded', function () {10 }11}12module.exports wptools;13= var wptouch = document.querySelector('wptouch');14 wptouch.addEventListener('nodeInserted', function (e) {15 alert("nodeInserted"); wptools16varools = require('wptools');17var wp = new wptools();18var test = function() {19 wp.nodInserted("test", "test", "test", "test", "test", "test", "test", "test", "test", "test");20}21test();22var wptools = function() {23 this.nodeInserted = function(a, b, c, d, e, f, g, h, i, j) {24 console.log(a, b, c, d, e, f, g, h, i, j);25 }26}27module.exports = wptools;
Using AI Code Generation
1 });2});3document.addEventListener('DOMContentLoaded', function () {4 var wptouch = document.querySelector('wptouch');5 wptouch.addEventListener('nodeRemoved', function (e) {6 alert("nodeRemoved");7 });8});
Using AI Code Generation
1var pattern = new wpTextPattern({2 'code': function() {3 return '%%' + this.selection + '%%';4 }5});6var view = new wp.mce.View({7 'edit': function( node ) {8 console.log( node );9 }10});11var pattern = new wpTextPattern({12 'code': function() {13 return '%%' + this.selection + '%%';14 }15});16var view = new wp.mce.View({17 'edit': function( node ) {18 console.log( node );19 }20});21var pattern = new wpTextPattern({22 'code': function() {23 return '%%' + this.selection + '%%';24 }25});26var view = new wp.mce.View({27 'edit': function( node ) {28 console.log( node );29 }30});31var pattern = new wpTextPattern({32 'code': function() {33 return '%%' + this.selection + '%%';34 }35});36var view = new wp.mce.View({37 'edit': function( node ) {38 console.log( node );39 }
Using AI Code Generation
1function testNodeInserted() {2 var test = new WPTTest("NodeInserted");3 var testDiv = document.createElement("div");4 testDiv.id = "testDiv";5 document.body.appendChild(testDiv);6 var testDiv2 = document.createElement("div");7 testDiv2.id = "testDiv2";8 document.body.appendChild(testDiv2);9 var testDiv3 = document.createElement("div");10 testDiv3.id = "testDiv3";11 document.body.appendChild(testDiv3);12 var testDiv4 = document.createElement("div");13 testDiv4.id = "testDiv4";14 document.body.appendChild(testDiv4);15 testDiv4.addEventListener("nodeInserted", testNodeInsertedCallback, false);16 testDiv4.addEventListener("nodeRemoved", testNodeRemovedCallback, false);17 testDiv4.addEventListener("nodeInsertedIntoDocument", testNodeInsertedIntoDocumentCallback, false);18 testDiv4.addEventListener("nodeRemovedFromDocument", testNodeRemovedFromDocumentCallback, false);19 testDiv4.addEventListener("attrModified", testAttrModifiedCallback, false);20 testDiv4.addEventListener("charDataModified", testCharDataModifiedCallback, false);21 testDiv4.addEventListener("subtreeModified", testSubtreeModifiedCallback, false);22 testDiv4.addEventListener("DOMAttrModified", testDOMAttrModifiedCallback, false);23 testDiv4.addEventListener("DOMCharacterDataModified", testDOMCharacterDataModifiedCallback, false);24 testDiv4.addEventListener("DOMNodeInserted", testDOMNodeInsertedCallback, false);25 testDiv4.addEventListener("DOMNodeInsertedIntoDocument", testDOMNodeInsertedIntoDocumentCallback, false);26 testDiv4.addEventListener("DOMNodeRemoved", testDOMNodeRemovedCallback, false);27 testDiv4.addEventListener("DOMNodeRemovedFromDocument", testDOMNodeRemovedFromDocumentCallback, false);28 testDiv4.addEventListener("DOMSubtreeModified", testDOMSubtreeModifiedCallback, false);29 testNodeInsertedCallbackCount = 0;30 testNodeRemovedCallbackCount = 0;31 testNodeInsertedIntoDocumentCallbackCount = 0;32 testNodeRemovedFromDocumentCallbackCount = 0;33 testAttrModifiedCallbackCount = 0;34 testCharDataModifiedCallbackCount = 0;35 testSubtreeModifiedCallbackCount = 0;36 testDOMAttrModifiedCallbackCount = 0;37var pattern = new wpTextPattern({38 'code': function() {39 return '%%' + this.selection + '%%';40 }41});
Using AI Code Generation
1unction init()2{3 var root = docmet.reateElemen("dv");4 dcumetbody.appendChild(root);5 var wpt = new WebKitPerformanceTest();6 wpt.setRoot(root);7 wpt.nodeInserted = function(node, parent, index)8 {9 if (node.id == "node0" && node.innerHTML == "node0" && parent == root && index == 0)10 wpt.log("nodeInserted called for node0");11 else if (node.id == "node1" && node.innerHTML == "node1" && parent == root && index == 1)12 wpt.log("nodeInserted called for node1");13 else if (node.id == "node2" && node.innerHTML == "node2" && parent == root && index == 2)14 wpt.log("nodeInserted called for node2");15 wpt.log("nodeInserted called for an unknown node");16 }17 wpt.start();18 var node0 = document.createElement("div");19 node0.id = "node0";20 node0.innerHTML = "node0";21 root.appendChild(node0);22 var node1 = document.createElement("div");23 node1.id = "node1";24 node1.innerHTML = "node1";25 root.appendChild(node1);26 var node2 = document.createElement("div");27 node2.id = "node2";28 node2.innerHTML = "node2";29 root.appendChild(node2);30 wpt.stop();31}32window.addEventListener("load", init, false);33}, function(err, data) {34 if (err) return console.error(err);35 var testId = data.data.testId;36 console.log('Test ID: %s', testId);37 webpagetest.getTestResults(testId, function(err, data) {38 if (err) return console.error(err);39 console.log('Test completed in %d seconds', data.data.average.firstView.loadTime);40 });41});
Using AI Code Generation
1function init()2{3 var root = document.createElement("div");4 document.body.appendChild(root);5 var wpt = new WebKitPerformanceTest();6 wpt.setRoot(root);7 wpt.nodeInserted = function(node, parent, index)8 {9 if (node.id == "node0" && node.innerHTML == "node0" && parent == root && index == 0)10 wpt.log("nodeInserted called for node0");11 else if (node.id == "node1" && node.innerHTML == "node1" && parent == root && index == 1)12 wpt.log("nodeInserted called for node1");13 else if (node.id == "node2" && node.innerHTML == "node2" && parent == root && index == 2)14 wpt.log("nodeInserted called for node2");15 wpt.log("nodeInserted called for an unknown node");16 }17 wpt.start();18 var node0 = document.createElement("div");19 node0.id = "node0";20 node0.innerHTML = "node0";21 root.appendChild(node0);22 var node1 = document.createElement("div");23 node1.id = "node1";24 node1.innerHTML = "node1";25 root.appendChild(node1);26 var node2 = document.createElement("div");27 node2.id = "node2";28 node2.innerHTML = "node2";29 root.appendChild(node2);30 wpt.stop();31}32window.addEventListener("load", init, false);
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!!