$.fn.clearForm = function() { return this.each(function() { var type = this.type, tag = this.tagName.toLowerCase(); if (tag == 'form') return $(':input:not(.PROMPT-NO)',this).clearForm(); if (type == 'text' || type == 'password' || tag == 'textarea') this.value = ''; else if (type == 'checkbox' || type == 'radio') this.checked = false; else if (tag == 'select') this.selectedIndex = 0; // ...... (-1 for selecting really nothing) }); }; var $item_status = 'update'; //------------------------------------------------------------------------------------------------- $(document).ready(function() { $(document).on('keydown',function(e) { var $target = $(e.target||e.srcElement); if(e.keyCode == 8 && !$target.is('input,[contenteditable="true"],textarea')) { e.preventDefault(); } }); $(document).on('click', "#end_task", function() { $(document).html(""); }); $(document).delegate("#finish_and_show_report","click",function() { $.post("show.php", { finish_and_show_report: "finish_and_show_report"}, function(data) { if(data == "OK") window.location.href = "user_results1.php"; }); }); $(document).delegate("#finish_and_show_lassi","click",function() { $.post("show.php", { finish_and_show_lassi: "finish_and_show_lassi"}, function(data) { if(data == "OK") window.location.href = "lassi_feedback.php"; }); }); $(document).delegate("#finish_and_show_instrumentaal","click",function() { $.post("show.php", { finish_and_show_instrumentaal: "finish_and_show_instrumentaal"}, function(data) { if(data == "OK") window.location.href = "taal_feedback.php"; }); }); $(document).on("click","#reset_answers", function() { $("#response_changed").val("yes"); reset_answers(); }); }); //------------------------------------------------------------------------------------------------- function monitor_item_change() { $("#item_form > :checkbox, :radio, :text, option, input, select, textarea").change(function() { $("#response_changed").val("yes"); }); } //------------------------------------------------------------------------------------------------- function init_task($button) { var params = $($button).attr("id")+'=1'; $("input:hidden").each( function() { params += '&' + $(this).attr("id") + '=' + $(this).val(); }); $.ajax({ type: "POST", url: "show.php", data: params, success: function(data) { $("#curios_main").html(data); $("#reset_answers").click(function () {reset_answers();}); //$('.audioFullPlayer').audioPlayer(); scroll_to_navigator($('#current_linkrefid').attr("value")); } }); } //------------------------------------------------------------------------------------------------- function get(obj, page, dest) { //$("#response_changed").val("yes"); var $hotspots = $('#HotSpot').length; if($hotspots > 0) $("#split_points_hotspot").val(document.HotSpot.getShapes()); var fields = $(obj).serializeArray(); var $msg = ""; $.each(fields, function(i, field) { $msg = $msg + field.name + " => " + field.value.replace('"','\\"') + " \n"; }); //alert(JSON.stringify(fields)); $('#Antwoorden').prop("disabled",true); $('#reset_answers').prop("disabled",true); $.ajax({ type: "POST", url: page, timeout: 3000, retryLimit : 3, data: fields, success: function(data) { $("#"+dest).html(data); $("#reset_answers").click(function () {reset_answers();}); scroll_to_navigator($('#current_linkrefid').attr("value")); $("html, body").animate({ scrollTop:0 },"fast"); }, error: function(xmlhttprequest, textstatus, message) { if(textstatus==="timeout") { this.retryLimit--; if (this.retryLimit >= 0) { console.log("Herstarten ajax call"); //try again $.ajax(this); return; } } else { console.log(textstatus); } } }); } //------------------------------------------------------------------------------------------------- function disable_previous_nav_buttons() { $("li.current").prevAll().unbind("click"); $("li.current").prevAll().addClass("unclickable"); } //------------------------------------------------------------------------------------------------- function handle_navigater_item_click() { nav_to($(this).attr('item_id')); } //------------------------------------------------------------------------------------------------- function scroll_to_navigator(linkrefid) { /*let audios = $(".audioFullPlayer").length; if($(".audioFullPlayer").parent().hasClass('audioplayer')) console.log('player OK'); else { console.log('player NOK'); $(".audioFullPlayer").audioPlayer(); }*/ //$(".audioFullPlayer").audioPlayer(); if(linkrefid == "finish") return; if($("#current_linkrefid").val() == "feedback") return; var $i=$("li[item_id="+linkrefid+"]"); if($i) { $numberlist.stop().scrollTo( $("li[item_id="+linkrefid+"]"), 300, { axis:'x'} ); $(".current").removeClass("current"); $("li[item_id="+linkrefid+"]").addClass("current"); } } //------------------------------------------------------------------------------------------------- function nav_to(linkrefid) { //scroll_to_navigator(linkrefid); goto_item(linkrefid); } //------------------------------------------------------------------------------------------------- function goto_item(linkrefid) { var id=document.getElementById("linkrefid"); if(id) id.value=linkrefid; //alert(skey); if(skey) get_proctor_status(); get($("#item_form"), "show.php?skey="+skey, "questions") ; //document.item_form.submit(); } //------------------------------------------------------------------------------------------------- function reset_answers() { $(":checkbox").prop('checked', false); $(":radio").prop('checked', false); $(":text").attr('value',''); $("option").prop("selected",false); $("textarea").text(""); } //------------------------------------------------------------------------------------------------- function getViewportHeight() { if (window.innerHeight!=window.undefined) return window.innerHeight; if (document.compatMode=='CSS1Compat') return document.documentElement.clientHeight; if (document.body) return document.body.clientHeight; return window.undefined; } //------------------------------------------------------------------------------------------------- function getViewportWidth() { if (window.innerWidth!=window.undefined) return window.innerWidth; if (document.compatMode=='CSS1Compat') return document.documentElement.clientWidth; if (document.body) return document.body.clientWidth; return window.undefined; } //------------------------------------------------------------------------------------------------- function center_div(id) { var el=document.getElementById(id); if(el) { var left=(getViewportWidth() / 2) - (size2int(el.style.width) / 2); var top=(getViewportHeight() / 2) - (size2int(el.style.height) / 2); el.style.left=left+"px"; el.style.top=top+"px"; } } //------------------------------------------------------------------------------------------------- function size2int(s) { var y=s.split("p"); return Number(y[0]); } //------------------------------------------------------------------------------------------------- function loading(id) { var el=document.getElementById(id); if(el) { var left=(getViewportWidth() / 2) - 50; var top=(getViewportHeight() / 2) - 50; el.style.visibility="hidden"; el.innerHTML='
'; el.style.visibility="visible"; } } //------------------------------------------------------------------------------------------------- function toggle_debug() { var el=document.getElementById('debug'); if(el) { if(el.style.visibility == "") el.style.visibility = "visible"; else { if(el.style.visibility == "hidden") el.style.visibility = "visible"; else el.style.visibility = "hidden"; } } } //-------------------------------------------------------------------------------------------------- function fill_debug(s) { $("#debug").html(s); } //------------------------------------------------------------------------------------------------- // Hotspot stuff function get_tmp_points($p) { if(document.HotSpot.isActive) document.HotSpot.setPoints($p); } //------------------------------------------------------------------------------------------------- // Hotspot stuff function _getValue() { document.form1.split_points_hotspot.value = document.HotSpot.getShapes(); return true; } function left_over(tekst,leftid,max_chars) { var indicator=document.getElementById(leftid); var remaining=max_chars - tekst.value.length; var response_changed=document.getElementById('response_changed'); indicator.innerHTML = remaining; if ( remaining < 1 ) { tekst.value = tekst.value.substring( 0, max_chars ); indicator.innerHTML = 0; response_changed.value = "yes"; return false; } }