if (wysihtml5.browser.supported()) { module("wysihtml5.Editor", { setup: function() { wysihtml5.dom.insertCSS([ "#wysihtml5-test-textarea { width: 50%; height: 100px; margin-top: 5px; font-style: italic; border: 2px solid red; border-radius: 2px; }", "#wysihtml5-test-textarea:focus { margin-top: 10px; }", "#wysihtml5-test-textarea:disabled { margin-top: 20px; }" ]).into(document); this.textareaElement = document.createElement("textarea"); this.textareaElement.id = "wysihtml5-test-textarea"; this.textareaElement.title = "Please enter your foo"; this.textareaElement.value = "hey tiff, what's up?"; this.form = document.createElement("form"); this.form.onsubmit = function() { return false; }; this.form.appendChild(this.textareaElement); this.originalBodyClassName = document.body.className; document.body.appendChild(this.form); }, teardown: function() { var leftover; while (leftover = document.querySelector("iframe.wysihtml5-sandbox, input[name='_wysihtml5_mode']")) { leftover.parentNode.removeChild(leftover); } this.form.parentNode.removeChild(this.form); document.body.className = this.originalBodyClassName; }, getComposerElement: function() { return this.getIframeElement().contentWindow.document.body; }, getIframeElement: function() { var iframes = document.querySelectorAll("iframe.wysihtml5-sandbox"); return iframes[iframes.length - 1]; } }); asyncTest("Basic test", function() { expect(18); var that = this; var editor = new wysihtml5.Editor(this.textareaElement); editor.on("load", function() { var iframeElement = that.getIframeElement(), composerElement = that.getComposerElement(), textareaElement = that.textareaElement; ok(true, "Load callback triggered"); ok(wysihtml5.dom.hasClass(document.body, "wysihtml5-supported"), "
received correct class name"); equal(textareaElement.style.display, "none", "Textarea not visible"); ok(iframeElement.style.display, "", "Editor iFrame is visible"); equal(editor.currentView.name, "composer", "Current view is 'composer'"); // Make textarea visible for a short amount of time, in order to calculate dimensions properly textareaElement.style.display = "block"; deepEqual( [iframeElement.offsetHeight, iframeElement.offsetWidth], [textareaElement.offsetHeight, textareaElement.offsetWidth], "Editor has the same dimensions as the original textarea" ); textareaElement.style.display = "none"; var hiddenField = textareaElement.nextSibling; equal(hiddenField.name, "_wysihtml5_mode", "Hidden field has correct name"); equal(hiddenField.value, "1", "Hidden field has correct value"); equal(hiddenField.type, "hidden", "Hidden field is actually hidden"); equal(textareaElement.nextSibling.nextSibling, iframeElement, "Editor iframe is inserted after the textarea"); equal(composerElement.getAttribute("contentEditable"), "true", "Body element in iframe is editable"); equal(editor.textarea.element, textareaElement, "Textarea correctly available on editor instance"); equal(editor.composer.element, composerElement, "contentEditable element available on editor instance"); equal(wysihtml5.dom.getStyle("font-style").from(composerElement), "italic", "Correct font-style applied to editor element"); equal(wysihtml5.dom.getStyle("width").from(iframeElement), "50%", "Correct width applied to iframe"); equal(wysihtml5.dom.getStyle("height").from(iframeElement), "100px", "Correct height applied to iframe"); if ("borderRadius" in document.createElement("div").style) { expect(19); ok(wysihtml5.dom.getStyle("border-top-right-radius").from(iframeElement).indexOf("2px") !== -1, "border-radius correctly copied"); } equal(composerElement.innerHTML.toLowerCase(), "hey tiff, what's up?", "Copied the initial textarea value to the editor"); ok(wysihtml5.dom.hasClass(composerElement, "wysihtml5-editor"), "Editor element has correct class name"); start(); }); }); asyncTest("Check setting of name as class name on iframe and iframe's body", function() { expect(4); this.textareaElement.className = "death-star"; var that = this, name = "star-wars-input", editor = new wysihtml5.Editor(this.textareaElement, { name: "star-wars-input" }); editor.on("load", function() { var iframeElement = that.getIframeElement(), composerElement = that.getComposerElement(), textareaElement = that.textareaElement; ok(wysihtml5.dom.hasClass(iframeElement, name), "iFrame has adopted name as className"); ok(wysihtml5.dom.hasClass(composerElement, name), "iFrame's body has adopted name as className"); ok(wysihtml5.dom.hasClass(composerElement, "death-star"), "iFrame's body has adopted the textarea className"); ok(!wysihtml5.dom.hasClass(textareaElement, name), "Textarea has not adopted name as className"); start(); }); }); asyncTest("Check textarea with box-sizing: border-box;", function() { expect(1); var that = this; wysihtml5.dom.setStyles({ MozBoxSizing: "border-box", WebkitBoxSizing: "border-box", MsBoxSizing: "border-box", boxSizing: "border-box" }).on(this.textareaElement); var editor = new wysihtml5.Editor(this.textareaElement); editor.on("load", function() { // Make textarea visible for a short amount of time, in order to calculate dimensions properly that.textareaElement.style.display = "block"; deepEqual( [that.getIframeElement().offsetWidth, that.getIframeElement().offsetHeight], [that.textareaElement.offsetWidth, that.textareaElement.offsetHeight], "Editor has the same dimensions as the original textarea" ); that.textareaElement.style.display = "none"; start(); }); }); asyncTest("Check whether cols and rows attribute is correctly handled", function() { expect(2); var that = this; // Remove styles this.textareaElement.removeAttribute("id"); // And set dimensions of