var positioning = "rel"; var dad = "classic" var mainMode = "match_multi"; var textMaxLength = 0; var textMaxChars = 0; var currentEditor = null; function initApplication() { $( "#tabs" ).tabs(); // fix the classes $( ".tabs-bottom .ui-tabs-nav, .tabs-bottom .ui-tabs-nav > *" ) .removeClass( "ui-corner-all ui-corner-top" ) .addClass( "ui-corner-bottom" ); // move the nav to the bottom $( ".tabs-bottom .ui-tabs-nav" ).appendTo( ".tabs-bottom" ); $("#tabs").on( "tabsactivate", function( event, ui ) { var pid = ui.newPanel.attr("id") if (pid == "tabs-2") generatePreview() if (pid == "tabs-3") generateCode() if (pid == "tabs-4") generateCodeNewDesign() //if (ui.newTab) // } ); $("#dialog-importCode").dialog({ autoOpen: false, height: 400, width: 800, modal: true, resizable: false, buttons: { "Importovat kód": function () { importCode(); $(this).dialog("close"); }, "Zavřít": function () { $(this).dialog("close"); } }, close: function () { $("#import_code").val("").removeClass("ui-state-error"); } }); } function resetAll() { /* $("#editForms section").remove(); addPlainArea(); $(".droparea").remove() $("#dragbase .draggable").remove() document.getElementById("edit_title").innerHTML = "" document.getElementById("edit_task").innerHTML = "" var bgImg = document.querySelector("#img_placeholder img"); if (bgImg) bgImg.parentNode.removeChild(bgImg) var bgInit = document.getElementById("bg-init"); bgInit.style.display = "block"; $( "#tabs" ).tabs( "option", "active", 0 ); deleteMedia(); */ // $("#br-init").html("").click(function() { $('#dialog-setBgImage' ).dialog( 'open' ) }) } function gotoMainSelect() { document.getElementById("main_select").style.display = "block" document.getElementById("edit_panes").style.display = "none" } function setMode(mode) { resetAll() document.getElementById("main_select").style.display = "none" document.getElementById("edit_panes").style.display = "block" mainMode = mode; /* var demo = document.getElementById("demos"); demo.style.display = ( demos[mainMode].length > 0) ? "block" : "none" $("#demos input").remove(); for (var i = 0; i < demos[mainMode].length; i++) { var input = demo.appendChild(document.createElement("input")); input.type = "button"; input.value = (i+1); input.onclick = showDemo; input.className = "ui-button ui-widget ui-state-default ui-corner-all"; input.setAttribute("data-index", i) } */ switch (mode) { case "gap_input": document.getElementById("dragbase").style.display = "none" document.getElementById("browser_warning").style.display = "none" document.getElementById("form_relative").style.display = "block"; CKEDITOR.inline( 'edit_title', configEdit ); CKEDITOR.inline( 'edit_task', configEdit ); document.getElementById("insert_t").style.display = "inline" document.getElementById("insert_n").style.display = "inline" document.getElementById("insert_v").style.display = "inline" document.getElementById("insert_a").style.display = "inline" document.getElementById("replace_t").style.display = "inline" document.getElementById("replace_n").style.display = "inline" document.getElementById("replace_v").style.display = "inline" document.getElementById("form_absolute").style.display = "none" break; case "gap_select": document.getElementById("dragbase").style.display = "none" document.getElementById("browser_warning").style.display = "none" document.getElementById("form_relative").style.display = "block" document.getElementById("insert_t").style.display = "none" document.getElementById("insert_n").style.display = "none" document.getElementById("insert_v").style.display = "inline" document.getElementById("insert_a").style.display = "none" document.getElementById("replace_t").style.display = "none" document.getElementById("replace_n").style.display = "none" document.getElementById("replace_v").style.display = "inline" document.getElementById("form_absolute").style.display = "none" break; case "gap_dad": document.getElementById("browser_warning").style.display = "block" document.getElementById("dragbase").style.display = "none" document.getElementById("form_relative").style.display = "block" document.getElementById("insert_t").style.display = "inline" document.getElementById("insert_n").style.display = "none" document.getElementById("insert_v").style.display = "none" document.getElementById("insert_a").style.display = "none" document.getElementById("replace_t").style.display = "inline" document.getElementById("replace_n").style.display = "none" document.getElementById("replace_v").style.display = "none" document.getElementById("form_absolute").style.display = "none" break; case "desc_input": document.getElementById("browser_warning").style.display = "none" document.getElementById("dragbase").style.display = "none" document.getElementById("form_relative").style.display = "none" document.getElementById("delSelectedDraggable").style.display = "none" document.getElementById("form_absolute").style.display = "block" document.getElementById("insert_t_dad").style.display = "inline" document.getElementById("insert_pic_dad").style.display = "none" document.getElementById("imgSize").style.display = "none" document.getElementById("textValue").style.display = "block" break; case "desc_dad": document.getElementById("browser_warning").style.display = "block" document.getElementById("dragbase").style.display = "none" document.getElementById("form_relative").style.display = "none" document.getElementById("delSelectedDraggable").style.display = "none" document.getElementById("form_absolute").style.display = "block" document.getElementById("insert_t_dad").style.display = "inline" document.getElementById("insert_pic_dad").style.display = "none" document.getElementById("imgSize").style.display = "none" document.getElementById("textValue").style.display = "block" break; case "pic_dad": document.getElementById("browser_warning").style.display = "block" document.getElementById("dragbase").style.display = "block" document.getElementById("form_relative").style.display = "none" document.getElementById("form_absolute").style.display = "block" document.getElementById("insert_t_dad").style.display = "none" document.getElementById("insert_pic_dad").style.display = "inline" document.getElementById("imgSize").style.display = "block" document.getElementById("textValue").style.display = "none" break; case "match_multiple": document.getElementById("dragbase").style.display = "none" document.getElementById("browser_warning").style.display = "none" document.getElementById("form_relative").style.display = "block"; CKEDITOR.inline( 'edit_title', configEdit ); CKEDITOR.inline( 'edit_task', configEdit ); document.getElementById("insert_t").style.display = "none" document.getElementById("insert_n").style.display = "none" document.getElementById("insert_v").style.display = "none" document.getElementById("insert_a").style.display = "none" document.getElementById("replace_t").style.display = "none" document.getElementById("replace_n").style.display = "none" document.getElementById("replace_v").style.display = "none" document.getElementById("form_absolute").style.display = "none" break; default: break; } } function setDad(val) { dad = val; if (val == "dad") { document.getElementById("dragbase").style.display = "block"; } else { document.getElementById("dragbase").style.display = "none"; } } // The instanceReady event is fired, when an instance of CKEditor has finished // its initialization. CKEDITOR.on( 'instanceReady', function( ev ) { // Show the editor name and description in the browser status bar. document.getElementById( 'eMessage' ).innerHTML = 'Instance ' + ev.editor.name + '<\/code> loaded.'; // Show this sample buttons. var eButtons = document.getElementById( 'eButtons' ); if (eButtons) { eButtons.style.display = 'block'; } }); var configEdit = { allowedContent: true, toolbar: [ { name: 'basicstyles', groups: [ 'basicstyles', 'cleanup' ], items: [ 'Bold', 'Italic', 'Underline', 'Strike', 'Subscript', 'Superscript', '-', 'RemoveFormat' ] }, [ 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink' ], [ 'FontSize', 'TextColor', 'BGColor' ] , { name: 'paragraph', groups: [ 'indent', 'blocks', 'align'], items: [ 'Outdent', 'Indent', '-', 'Blockquote', 'CreateDiv', '-', 'JustifyLeft', 'JustifyCenter', 'JustifyRight', 'JustifyBlock' ] }, { name: 'insert', items : [ 'Table','HorizontalRule','SpecialChar'] }, [ 'NewPage'] ], on: { focus: onFocus, blur: onBlur, selectionChange: function(evt) { document.getElementById("testitem_content").style.display = "none"; var selected = evt.editor.getSelection().getStartElement().$ var name = selected.nodeName.toLowerCase() document.getElementById( 'eMessage' ).innerHTML = selected.nodeName + "." + selected.className // document.getElementById("txtArea").value = selected.nodeName.toLocaleLowerCase() + "." + selected.className if (selected.className.indexOf("testitem") > -1) { if (name == "img") { var novy = document.createElement("span"); novy.className = selected.className; var obsah = "text" if (selected.hasAttribute("data-type") && selected.getAttribute("data-type") == "n") obsah = "123" novy.innerHTML = "" + obsah + ""; selected.parentNode.insertBefore(novy, selected); selected.parentNode.removeChild(selected); } } if (name == "span" && selected.className == "option") { actSelected = selected.parentNode; //alert("Option") readTestitem(selected.parentNode); } if (name == "span" && selected.className.indexOf("testitem") > -1) { actSelected = selected; readTestitem(selected); } if (name == "textarea" && selected.className.indexOf("testitem") > -1) { actSelected = selected; readTestitem(selected); } document.getElementById( 'eMessage' ).innerHTML = name + "." + selected.$.className } } }; function InsertHTML(content) { // Get the editor instance that we want to interact with. var editor = CKEDITOR.currentInstance; //instances.editor1; // Check the active editing mode. if ( editor.mode == 'wysiwyg' ) { // Insert HTML code. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml editor.insertHtml( content ); } else alert( 'You must be in WYSIWYG mode!' ); } function addSubquestion(node) { var section = node.parentNode.insertBefore(document.createElement("section"), node); section.className = "subquestion" var task = section.appendChild(document.createElement("h4")) task.setAttribute("contenteditable", "true"); task.innerHTML = "zadání" var div = section.appendChild(document.createElement("div")); div.setAttribute("contenteditable", "true"); div.innerHTML = " "; div.className = "editArea" var toolbar = section.appendChild(document.createElement("fieldset")); toolbar.className = "toolbar" var input = toolbar.appendChild(document.createElement("input")); input.type = "button"; input.value = "Smazat podotĂĄzku"; input.className = "deleter" input.onclick = function () { deleteSubquestion(this) } CKEDITOR.inline(div, configEdit) CKEDITOR.inline(task, configEdit) } function addSubquestionRC(node, type) { var varCount = parseInt(document.getElementById("count_sq" + type).value ); if (varCount == undefined || isNaN(varCount)) varCount = 3; var section = node.parentNode.insertBefore(document.createElement("section"), node); section.className = "subquestion choicer" var task = section.appendChild(document.createElement("h4")) task.setAttribute("contenteditable", "true"); task.innerHTML = "zadání" var list = section.appendChild(document.createElement("ol")); for (var i =0; i < varCount; i++) { list.appendChild(createRCVariant(type)); } var appender = section.appendChild(document.createElement("input")); appender.type = "button"; //appender.src = "design/add_option.png"; appender.value = "Přidat položku"; appender.title = "Přidat položku" appender.className = "itemAppender"; appender.onclick = function () { appendRCVariant(this) } var toolbar = section.appendChild(document.createElement("fieldset")); toolbar.className = "toolbar" var input = toolbar.appendChild(document.createElement("input")); input.type = "button"; input.value = "Smazat podotĂĄzku"; input.className = "deleter" input.onclick = function () { deleteSubquestion(this) } } function appendRCVariant(node) { var list = node.parentNode.querySelector("ol"); var type = list.querySelector(".checker").type list.appendChild(createRCVariant(type.charAt(0))); } function deleteRCVariant(node) { var item = node.parentNode; item.parentNode.removeChild(item); } function createRCVariant(type) { var li = document.createElement("li"); var deleter = li.appendChild(document.createElement("input")); deleter.type = "image"; deleter.value = "x"; deleter.src= "design/delete_option.png" deleter.title = "Smazat poloĹžku" deleter.className = "deleter"; deleter.onclick = function () { deleteRCVariant(this) } var editer = li.appendChild(document.createElement("span")); editer.className = "editer"; var check = editer.appendChild(document.createElement("input")); check.type = (type == "r") ? "radio" : "checkbox"; check.setAttribute("name", type + "c"); check.className = "checker"; var scorer = editer.appendChild(document.createElement("input")); scorer.type = "text"; scorer.placeholder = "body" scorer.size = 3; var editArea = li.appendChild(document.createElement("div")); editArea.setAttribute("contenteditable", "true"); editArea.innerHTML = " "; editArea.className = "editArea" CKEDITOR.inline(editArea, configEdit); return li; } function addPlainArea(node) { if (node == undefined) { node = document.getElementById("editForms").firstChild; } var section = node.parentNode.insertBefore(document.createElement("section"), node); section.className = "subquestion" var div = section.appendChild(document.createElement("div")); div.setAttribute("contenteditable", "true"); div.innerHTML = " "; div.className = "editArea" var toolbar = section.appendChild(document.createElement("fieldset")); toolbar.className = "toolbar" var input = toolbar.appendChild(document.createElement("input")); input.type = "button"; input.value = "Smazat podotĂĄzku"; input.className = "deleter" input.onclick = function () { deleteSubquestion(this) } currentEditor = CKEDITOR.inline(div, configEdit) } function deleteSubquestion(node) { if (confirm("Opravdu smazat podotĂĄzku?")) { var sq = node.parentNode.parentNode; sq.parentNode.removeChild(sq); } } function insertTestItem(itype) { // vlozit testovou polozku //var editor = CKEDITOR.instances.editor1; var editor = CKEDITOR.currentInstance; // Check the active editing mode. if ( editor.mode == 'wysiwyg' ) { // Insert HTML code. // http://docs.ckeditor.com/#!/api/CKEDITOR.editor-method-insertHtml var selection = editor.document.getSelection(); if (selection.getType() == CKEDITOR.SELECTION_ELEMENT ) return; if (selection.getType() == CKEDITOR.SELECTION_TEXT) { var content = (selection.getRanges(true)[0].collapsed) ? "text" : selection.getSelectedText() var opts = content.split(/\s*[|\/]\s*/g) var ti = "" for (var oi =0; oi < opts.length; oi++) { var spravna = "" if (opts[oi].indexOf("*") == 0 && itype == "v") { spravna = " data-correct='ok' "; opts[oi] = opts[oi].substring(opts[oi].indexOf("*") + 1); } ti += "" + opts[oi] + "<\/span>" } ti += "<\/span>" editor.insertHtml(ti) } //if (selection.getType() == CKEDITOR.SELECTION_NONE) else { var content = "text" var ti = editor.insertElement("span"); ti.appendText(content) editor.insertHtml(ti) } } else alert( 'You must be in WYSIWYG mode!' ); getInputMaxLength() } var defaultTI = { a : "", t : "text", n : "12.3", v : "varianta 1varianta 2varianta 3" } function readTestitem(node) { var iform = document.getElementById("edited_testitem"); iform.parentNode.style.display = "block"; iform.innerHTML = ""; var itype = node.className.substring(node.className.indexOf(" ") +1); if (itype == "t" || itype == "n" || itype == "v") { var opts = node.querySelectorAll(".option"); var table = iform.appendChild(document.createElement("table")); var thead = table.appendChild(document.createElement("tr")) var th = thead.appendChild(document.createElement("th")) th = thead.appendChild(document.createElement("th")) th.innerHTML = "OK" th = thead.appendChild(document.createElement("th")) th.innerHTML = "Hodnota" th = thead.appendChild(document.createElement("th")) th.innerHTML = "Body" th = thead.appendChild(document.createElement("th")) th.innerHTML = "Feedback" iform.appendChild(table) for (var i = 0; i < opts.length; i++) { var tr = table.appendChild( document.createElement("tr") ) var td = tr.appendChild(document.createElement("td")) var input = td.appendChild(document.createElement("input")); input.value = "Odstranit variantu"; input.title = "Odstranit variantu"; input.type = "image"; input.src = "design/delete_option.png"; input.onclick = removeTIOption; var isOK = (itype == "t" || itype == "n") ? true : opts[i].hasAttribute("data-correct") td = tr.appendChild(document.createElement("td")) input = td.appendChild(document.createElement("input")); input.value = "Varianta je OK"; input.title = "Varianta je OK"; input.type = "checkbox"; input.checked = isOK; input.onchange = function () { updateTestitem() } if (isOK && itype == "v") tr.className = "correct" td = tr.appendChild(document.createElement("td")) var input1 = document.createElement("input"); input1.value = opts[i].innerHTML; input1.onchange = function () { updateTestitem() } input1.onkeyup = function () { updateTestitem() } td.className = "ti_value" td.appendChild(input1) td = tr.appendChild(document.createElement("td")) var input2 = document.createElement("input"); input2.value = opts[i].getAttribute("data-score"); input2.onchange = function () { updateTestitem() } input2.onkeyup = function () { updateTestitem() } td.className = "ti_score" td.appendChild(input2) td = tr.appendChild(document.createElement("td")) var input3 = document.createElement("input"); input3.value = opts[i].getAttribute("data-feedback"); input3.onchange = function () { updateTestitem() } input3.onkeyup = function () { updateTestitem() } td.className = "ti_feedback" td.appendChild(input3) } var adder = iform.appendChild(document.createElement("input")); adder.type = "image" adder.src = "design/add_option.png" adder.title = "Přidat variantu" adder.value = "Přidat variantu" adder.onclick = function () { addTIOption(); updateTestitem() } var updater = document.createElement("input"); updater.type = "button" updater.title = "UloĹžit změny a zavřít" updater.value = "OK" updater.onclick = function (evt) { updateTestitem(evt); this.parentNode.parentNode.style.display = 'none' } iform.appendChild(updater) } if (itype == "a") { var label = iform.appendChild(document.createElement("label")) label.appendChild(document.createTextNode("Šířka: ")) var input = label.appendChild(document.createElement("input")) input.type = "text" input.value = node.cols input.setAttribute("data-min", "40"); input.setAttribute("data-max", "120"); input.setAttribute("data-target", "cols"); var inc = label.appendChild(document.createElement("input")) inc.type = "button" inc.value = "+" inc.setAttribute("data-change", "10"); inc.onclick = changeValue; var dec = label.appendChild(document.createElement("input")) dec.type = "button" dec.value = "-" dec.setAttribute("data-change", "-10"); dec.onclick = changeValue; label = iform.appendChild(document.createElement("label")) label.appendChild(document.createTextNode("Výťka: ")) input = label.appendChild(document.createElement("input")) input.type = "text" input.value = node.rows input.setAttribute("data-min", "1"); input.setAttribute("data-max", "15"); input.setAttribute("data-target", "rows"); inc = label.appendChild(document.createElement("input")) inc.type = "button" inc.value = "+" inc.setAttribute("data-change", "1"); inc.onclick = changeValue; dec = label.appendChild(document.createElement("input")) dec.type = "button" dec.value = "-" dec.setAttribute("data-change", "-1"); dec.onclick = changeValue; } } function updateTestitem() { if (!actSelected) return; actSelected.innerHTML = ""; var opts = document.querySelectorAll("#edited_testitem tr"); for (var i = 1; i < opts.length; i++) { var fields = opts[i].querySelectorAll("input"); var opt = actSelected.appendChild(document.createElement("span")); opt.className = "option"; if (fields[1].checked) opt.setAttribute("data-correct", "ok"); opt.innerHTML = fields[2].value; opt.setAttribute("data-score", fields[3].value); opt.setAttribute("data-feedback", fields[4].value); } getInputMaxLength() } function addTIOption() { var table = document.querySelector("#edited_testitem table") var tr = table.appendChild(document.createElement("tr")) var td = tr.appendChild(document.createElement("td")) var input = td.appendChild(document.createElement("input")); input.value = "Odstranit variantu"; input.title = "Odstranit variantu"; input.type = "image"; input.src = "design/delete_option.png"; input.onclick = removeTIOption; td = tr.appendChild(document.createElement("td")) input = td.appendChild(document.createElement("input")); input.value = "Varianta je OK"; input.title = "Varianta je OK"; input.type = "checkbox"; input.checked = false; input.onclick = function () { updateTestitem() } input.onchange = function () { updateTestitem() } td = tr.appendChild(document.createElement("td")) var input1 = document.createElement("input"); input1.value = ""; input1.onkeyup = function () { updateTestitem() } input1.onchange = function () { updateTestitem() } td.className = "ti_value" td.appendChild(input1) td = tr.appendChild(document.createElement("td")) var input2 = document.createElement("input"); input2.value = ""; input2.onkeyup = function () { updateTestitem() } input2.onchange = function () { updateTestitem() } td.className = "ti_score" td.appendChild(input2) td = tr.appendChild(document.createElement("td")) var input3 = document.createElement("input"); input3.value = ""; input3.onkeyup = function () { updateTestitem() } input3.onchange = function () { updateTestitem() } td.className = "ti_feedback" td.appendChild(input3) } function removeTIOption(evt) { var tr = evt.currentTarget; if (tr.nodeName.toLowerCase() == "input") tr = tr.parentNode.parentNode; var rodic = tr.parentNode; if (rodic.querySelectorAll("tr").length > 2) { rodic.removeChild(tr); updateTestitem(); } else { alert("V prvku musĂ­ zĹŻstat alespoň jedna varianta"); return; } } var actSelected = null; function changeValue (evt) { var input = evt.currentTarget var change = parseInt(input.getAttribute("data-change")) var cil = input.parentNode.querySelector("input"); var min = parseInt(cil.getAttribute("data-min")); var max = parseInt(cil.getAttribute("data-max")); var target = cil.getAttribute("data-target"); var current = parseInt(cil.value); var newValue = Math.max( min, current + change); newValue = Math.min( max, newValue); actSelected.setAttribute(target, newValue); cil.value = newValue } function generateCode() { var q_content; if (mainMode == "gap_input") q_content = GapInput.getCode() if (mainMode == "gap_select") q_content = getGapSelectCode() if (mainMode == "gap_dad") q_content = getGapDadCode() if (mainMode == "desc_input") q_content = getDescInputCode() if (mainMode == "desc_dad") q_content = getDescDadCode() if (mainMode == "pic_dad") q_content = getPicDadCode() if (mainMode == "match_multi") q_content = MatchMultiple.getCode() var qTitle = document.getElementById("edit_title").innerHTML if (qTitle == "Titulek otázky") qTitle = "" var qTask = document.getElementById("edit_task").innerHTML if (qTask == "zadání otázky") qTask = "" var vystup = "\n