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 class="prev_button"> prev </button> <button class="next_button"> next </button> <button class="finish_button"> Home </button> <iframe src=""> </iframe> </div> <script src="http://yui.yahooapis.com/3.8.1/build/yui/yui-min.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 id = ["1", "2", "3"]; var l = Y.all("iframe").size(); var nifr = document.createElement("iframe"); nifr.setAttribute("id", id[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 === id.length) { Y.one(".next_button").setStyle("display", "none"); Y.one(".finish_button").setStyle("display", "inline"); } else { Y.one(".prev_button").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(".next_button").setStyle("display", "inline"); if (index - 1 === 0) { Y.one(".prev_button").setStyle("display", "none"); } else { Y.one(".prev_button").setStyle("display", "inline"); Y.one(".finish_button").setStyle("display", "none"); } }; next(); next(); prev(); }); Test 2 Title Async (check if this is an asynchronous test) Code YUI().use('json', 'node', function(Y) { //function var next, prev, data, offset, hasAllRendered, jsonString; //jsonstring offset = 1; hasAllRendered = false; jsonString = [{ id: "0", url: "a.html", hasRendered: true }, { id: "1", url: "b.html", hasRendered: false }, { id: "2", url: "c.html", hasRendered: false }, { id: "3", url: "d.html", hasRendered: false }]; //next next = function() { var id, new_iframe; id= jsonString[offset].id; Y.log(jsonString[offset - 1].hasRendered); Y.log("offset:" + offset); Y.log(id); if (jsonString[offset].hasRendered === true) { //next Y.all("iframe").item(offset).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); } else { //create new_iframe = document.createElement("iframe"); new_iframe.setAttribute("id", id); Y.one("#popup").appendChild(new_iframe).siblings("iframe").setStyle("display", "none"); } //prev_button hide and show home if (offset === jsonString.length - 1) { Y.one(".next_button").setStyle("display", "none"); Y.one(".finish_button").setStyle("display", "inline"); } else { Y.one(".prev_button").setStyle("display", "inline"); } jsonString[offset].hasRendered = true; //counter offset += 1; Y.log("offset_next:" + offset); }; //prev prev = function() { Y.log(jsonString[offset - 1].hasRendered); Y.log("offset:" + offset); //prev Y.all("iframe").item(offset - 2).setStyle("display", "inline").siblings("iframe").setStyle("display", "none"); //counter offset -= 1; Y.log("offset_prev:" + offset); //next_button show Y.one(".next_button").setStyle("display", "inline"); if (offset === 1) { Y.one(".prev_button").setStyle("display", "none"); } else { Y.one(".prev_button").setStyle("display", "inline"); Y.one(".finish_button").setStyle("display", "none"); } }; next(); next(); prev(); }); Test 3 Title Async (check if this is an asynchronous test) Code (function () { var _log; _log = function (msg, type, module) { type = type || "info"; module = module || "iframe-popup"; if (typeof console !== "undefined") { console.log(msg); } } // Constructor function IframePopup(config) { var that = this, i, j; // Provide the default attribute values. that.offset = parseInt(config.offset, 10) || 0; that.width = parseInt(config.width, 10) || 500; that.height = parseInt(config.height, 10) || 500; that.urls = config.urls || null; // The urls attribute is required. if (!that.urls) { _log("The urls attribute is required.", "error"); return; } // Private variables. that._activeEl = null; // The active showed iframe. that._data = []; // The data collection. that._el = null; // The module element. that._rendered = false; // Whether if the instance has rendered. // Get the data collection. for (i = 0, j = that.urls.length; i < j; i++) { that._data[i] = { "id": "iframe-" + i, "url": that.urls[i], "rendered": false }; } } IframePopup.prototype = { render: function (rootEl) { _log("render() is executed."); var that = this, className, data = that._data[that.offset], el; if (that._rendered) { _log("You can only render once.", "error"); return; } // Render the UI. el = document.createElement("div") if (that.offset === 0) { el.className = "iframe-popup iframe-popup-first"; } else if (that.offset === data.length - 1) { el.className = "iframe-popup iframe-popup-last"; } el.innerHTML = [ '<div class="mod-content">', ' <div class="bd">', ' <iframe class="active" src="' + data.url + '" id="' + data.id + '"></iframe>', ' </div>', ' <div class="ft">', ' <a href="javascript:void(0);" id="prev-link">Previous Page</a>', ' <a href="javascript:void(0);" id="next-link">Next Page</a>', ' </div>', '</div>' ].join(""); rootEl = rootEl || document.body; rootEl.appendChild(el); that._el = el; that._activeEl = rootEl.getElementsByTagName("iframe")[0]; // Bind events. document.getElementById("prev-link").onclick = function () { that.prev.call(that); }; document.getElementById("next-link").onclick = function () { that.next.call(that); } }, move: function (isForward) { var that = this, activeEl, // Previous iframe element. bodyEl, // .bd node. boxEl, // Module. data, // Next iframe data. nextEl, // Next iframe element. offset; // Next offset. activeEl = that._activeEl; boxEl = that._el; offset = (isForward) ? that.offset + 1 : that.offset - 1; data = that._data[offset]; if (!data) { return false; } // Create iframe if it doesn't exist. if (!data.rendered) { nextEl = document.createElement("iframe"); nextEl.src = data.url; nextEl.id = data.id; bodyEl = activeEl.parentNode; if (isForward) { nextEl = bodyEl.appendChild(nextEl); } else { nextEl = bodyEl.insertBefore(nextEl, activeEl); } } // Exchange the 'active' class. activeEl.className = ""; nextEl.className = "active"; // Update outbox class. if (isForward && offset === that.urls.length - 1) { boxEl.className = "iframe-popup iframe-popup-last"; } else if (!isForward && offset === 0) { boxEl.className = "iframe-popup iframe-popup-first"; } else { boxEl.className = "iframe-popup"; } that._activeEl = nextEl; that.offset = offset; return true; }, next: function () { _log("next() is executed."); return this.move(true); }, prev: function () { _log("prev() is executed."); return this.move(false); } }; var popup = new IframePopup({ width: 500, offset: 3, urls: [ "http://lab.josephj.com/2013/iframe-popup/content.php?step=1", "http://lab.josephj.com/2013/iframe-popup/content.php?step=2", "http://lab.josephj.com/2013/iframe-popup/content.php?step=3", "http://lab.josephj.com/2013/iframe-popup/content.php?step=4", "http://lab.josephj.com/2013/iframe-popup/content.php?step=5", "http://lab.josephj.com/2013/iframe-popup/content.php?step=6" ] }); popup.render(); }());