diff --git a/themes/survey/vanilla/scripts/ajaxify.js b/themes/survey/vanilla/scripts/ajaxify.js index d5ed003fc2f..c5e5306c3bf 100644 --- a/themes/survey/vanilla/scripts/ajaxify.js +++ b/themes/survey/vanilla/scripts/ajaxify.js @@ -23,7 +23,7 @@ var AjaxSubmitObject = function () { var activeSubmit = false; // First we get the value of the button clicked (movenext, submit, prev, etc) - var move = ""; + var move = ''; var startLoadingBar = function () { //Scroll to the top of the page @@ -46,36 +46,36 @@ var AjaxSubmitObject = function () { }; var checkScriptNotLoaded = function(scriptNode){ - if(!!scriptNode.src){ + if(scriptNode.src){ return ($('head').find('script[src="'+scriptNode.src+'"]').length > 0); } return true; - } + }; var appendScript = function(scriptText, scriptPosition, src){ src = src || ''; scriptPosition = scriptPosition || null; var scriptNode = document.createElement('script'); - scriptNode.type = "text/javascript"; + scriptNode.type = 'text/javascript'; if(src != false){ scriptNode.src = src; } scriptNode.text = scriptText; - scriptNode.attributes.class = "toRemoveOnAjax"; + scriptNode.attributes.class = 'toRemoveOnAjax'; switch(scriptPosition) { - case "head": if(checkScriptNotLoaded(scriptNode)){ document.head.appendChild(scriptNode); } break; - case "body": document.body.appendChild(scriptNode); break; - case "beginScripts": document.getElementById('beginScripts').appendChild(scriptNode); break; - case "bottomScripts": //fallthrough - default: document.getElementById('bottomScripts').appendChild(scriptNode); break; + case 'head': if(checkScriptNotLoaded(scriptNode)){ document.head.appendChild(scriptNode); } break; + case 'body': document.body.appendChild(scriptNode); break; + case 'beginScripts': document.getElementById('beginScripts').appendChild(scriptNode); break; + case 'bottomScripts': //fallthrough + default: document.getElementById('bottomScripts').appendChild(scriptNode); break; } }; var bindActions = function () { var globalPjax = new Pjax({ - elements: "#limesurvey", // default is "a[href], form[action]" - selectors: ["#dynamicReloadContainer", "#beginScripts", "#bottomScripts"], + elements: '#limesurvey', // default is "a[href], form[action]" + selectors: ['#dynamicReloadContainer', '#beginScripts', '#bottomScripts'], debug: window.debugState.frontend, forceRedirectOnFail: true, reRenderCSS : true, @@ -83,13 +83,16 @@ var AjaxSubmitObject = function () { scriptloadtimeout: 1500 }); // Always bind to document to not need to bind again - $(document).on("click", ".ls-move-btn",function () { - $("#limesurvey").append(""); + $(document).on('click', '.ls-move-btn',function (e) { + e.preventDefault(); + $('#limesurvey').append(''); + $('#limesurvey').trigger('submit'); + return false; }); // If the user try to submit the form // Always bind to document to not need to bind again - $(document).on("submit", "#limesurvey", function (e) { + $(document).on('submit', '#limesurvey', function (e) { // Prevent multiposting //Check if there is an active submit //If there is -> return immediately @@ -105,10 +108,10 @@ var AjaxSubmitObject = function () { //free submitting again activeSubmit = false; if (/<###begin###>/.test($('#beginScripts').text())) { - $('#beginScripts').text(""); + $('#beginScripts').text(''); } if (/<###end###>/.test($('#bottomScripts').text())){ - $('#bottomScripts').text(""); + $('#bottomScripts').text(''); } $(document).off('pjax:scriptcomplete.onreload'); @@ -124,5 +127,5 @@ var AjaxSubmitObject = function () { endLoadingBar: endLoadingBar, unsetSubmit: function(){activeSubmit = false;}, blockSubmit: function(){activeSubmit = true;} - } -} + }; +};