Editing tedtestDom This edit will create a new revision. Your details (optional) Name Email (won’t be displayed; might be used for Gravatar) URL Test case details Title * Published (uncheck if you want to fiddle around before making the page public) Description (in case you feel further explanation is needed)(Markdown syntax is allowed) Test Dom Are you a spammer? (just answer the question) Preparation code Preparation code HTML (this will be inserted in the <body> of a valid HTML5 document in standards mode) (useful when testing DOM operations or including libraries) <div id="popup"> <button id="p"> prev </button> <button id="n"> next </button> <button id="h"> Home </button> <iframe src=""> </iframe> </div> <script src="http://yui.yahooapis.com/3.8.1/build/yui/yui-min.js"> </script> <script src="//ajax.googleapis.com/ajax/libs/yui/2.9.0/build/yuiloader/yuiloader-min.js"> </script> <script src="//cdn.ext/library.js"> </script> Include JavaScript libraries as follows: <script src="//cdn.ext/library.js"></script> Define setup for all tests (variables, functions, arrays or other objects that will be used in the tests) (runs before each clocked test loop, outside of the timed code region) (e.g. define local test variables, reset global variables, clear canvas, etc.) (see FAQ) Define teardown for all tests (runs after each clocked test loop, outside of the timed code region) (see FAQ) Code snippets to compare Test 1 Title Async (check if this is an asynchronous test) Code YUI().use('node', function(Y) { var display, index; var next, prev; var url = ["a.html", "b.html", "c.html", "d.html", "e.html"]; var l = Y.all("iframe").size(); var nifr = document.createElement("iframe"); nifr.setAttribute("src", url[l]); next = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); if (index + 1 < display.length) { Y.all("iframe").item(index + 1).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); } else { Y.one("#popup").appendChild(nifr).siblings("iframe").setStyle("display", "none"); } if (index + 2 === url.length) { Y.one("#n").setStyle("display", "none"); Y.one("#h").setStyle("display", "inline"); } else { Y.one("#p").setStyle("display", "inline"); } }; prev = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); Y.all("iframe").item(index - 1).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); Y.one("#n").setStyle("display", "inline"); if (index - 1 === 0) { Y.one("#p").setStyle("display", "none"); } else { Y.one("#p").setStyle("display", "inline"); Y.one("#h").setStyle("display", "none"); } }; Y.one("#p").on("click", prev); Y.one("#n").on("click", next); }); Test 2 Title Async (check if this is an asynchronous test) Code YUI().use('node', function(Y) { var display, index; var next, prev; var url = ["a.html", "b.html", "c.html", "d.html", "e.html"]; var l = Y.all("iframe").size(); var nifr = document.createElement("iframe"); nifr.setAttribute("src", url[l]); next = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); if (index + 1 < display.length) { Y.all("iframe").item(index + 1).setStyle("display", "inline"); Y.all("iframe").item(index).setStyle("display", "none"); } else { Y.one("#popup").appendChild(nifr).siblings("iframe").setStyle("display", "none"); } if (index + 2 === url.length) { Y.one("#n").setStyle("display", "none"); Y.one("#h").setStyle("display", "inline"); } else { Y.one("#p").setStyle("display", "inline"); } }; prev = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); Y.all("iframe").item(index - 1).setStyle("display", "inline"); Y.all("iframe").item(index).setStyle("display", "none"); Y.one("#n").setStyle("display", "inline"); if (index - 1 === 0) { Y.one("#p").setStyle("display", "none"); } else { Y.one("#p").setStyle("display", "inline"); Y.one("#h").setStyle("display", "none"); } }; Y.one("#p").on("click", prev); Y.one("#n").on("click", next); }); Test 3 Title Async (check if this is an asynchronous test) Code YUI().use('json-parse', 'node', function(Y) { //function var next, prev, data; var display, index; //jsonstring var jsonString = '{"iframe_data":[' + '{"id":1,"url":"a.html"},' + '{"id":2,"url":"b.html"},' + '{"id":3,"url":"c.html"},' + '{"id":4,"url":"d.html"},' + '{"id":5,"url":"e.html"}' + ']}'; //next next = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); Y.log(display.length); Y.log(index + 1); if (index + 1 < display.length) { Y.all("iframe").item(index + 1).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); } else { var l = Y.all("iframe").size(); var link = data.iframe_data[l].url; var new_iframe = document.createElement("iframe"); new_iframe.setAttribute("src", link); Y.one("#popup").appendChild(new_iframe).siblings("iframe").setStyle("display", "none"); } if (data.iframe_data.length === index + 2) { Y.one("#n").setStyle("display", "none"); Y.one("#h").setStyle("display", "inline"); } else { Y.one("#p").setStyle("display", "inline"); } }; //prev prev = function() { display = Y.all("iframe").getStyle("display"); index = display.indexOf("inline"); Y.all("iframe").item(index - 1).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); //next_button show Y.one(".next_button").setStyle("display", "inline"); if (index - 1 === 0) { Y.one("#p").setStyle("display", "none"); } else { Y.one("#p").setStyle("display", "inline"); Y.one("#h").setStyle("display", "none"); } }; //click event Y.one("#p").on("click", prev); Y.one("#n").on("click", next); // JSON.parse throws a SyntaxError when passed invalid JSON try { //var data = Y.JSON.parse(jsonString,reviver); data = Y.JSON.parse(jsonString); } catch (e) { alert("json Error"); } }); Test 4 Title Async (check if this is an asynchronous test) Code YUI().use('json-parse', 'node', function (Y) { //function var next, prev, data; var iframe_display, index_inline; //jsonstring var jsonString = '{"iframe_data":[' + '{"id":1,"url":"a.html"},' + '{"id":2,"url":"b.html"},' + '{"id":3,"url":"c.html"},' + '{"id":4,"url":"d.html"},' + '{"id":5,"url":"e.html"}' + ']}'; //next next = function () { iframe_display = Y.all("iframe").getStyle("display"); index_inline = iframe_display.indexOf("inline"); Y.log(iframe_display.length); Y.log(index_inline + 1); if (index_inline + 1 < iframe_display.length) { Y.all("iframe").item(index_inline + 1).setStyle("display", "inline"); Y.all("iframe").item(index_inline).setStyle("display", "none"); } else { var l = Y.all("iframe").size(); var link = data.iframe_data[l].url; var new_iframe = document.createElement("iframe"); new_iframe.setAttribute("src", link); Y.one("#popup").appendChild(new_iframe).siblings("iframe").setStyle("display", "none"); } if (data.iframe_data.length === index_inline + 2) { Y.one("#n").setStyle("display", "none"); Y.one("#h").setStyle("display", "inline"); } else { Y.one("#p").setStyle("display", "inline"); } }; //prev prev = function () { iframe_display = Y.all("iframe").getStyle("display"); index_inline = iframe_display.indexOf("inline"); Y.all("iframe").item(index_inline - 1).setStyle("display", "inline"); Y.all("iframe").item(index_inline).setStyle("display", "none"); //next_button show Y.one("#n").setStyle("display", "inline"); if (index_inline - 1 === 0) { Y.one("#p").setStyle("display", "none"); } else { Y.one("#p").setStyle("display", "inline"); Y.one("#h").setStyle("display", "none"); } }; //click event Y.one("#p").on("click", prev); Y.one("#n").on("click", next); // JSON.parse throws a SyntaxError when passed invalid JSON try { //var data = Y.JSON.parse(jsonString,reviver); data = Y.JSON.parse(jsonString); } catch (e) { alert("json Error"); } });