1/* 2 LimeSurvey 3 4 Copyright (C) 2007-2017 The LimeSurvey Project Team / Louis Gac 5 All rights reserved. 6 7 License: GNU/GPL License v2 or later, see LICENSE.php 8 LimeSurvey is free software. This version may have been modified pursuant 9 to the GNU General Public License, and as distributed it includes or 10 is derivative of works licensed under the GNU General Public License or 11 other free or open source software licenses. 12 See COPYRIGHT.php for copyright notices and details. 13 14 15 (¯`·._.·(¯`·._.· Ajax Mode ·._.·´¯)·._.·´¯) 16 17 This script deal with the new optional ajax system. 18 19 20*/ 21 22//Check if we have to work on IE10 *sigh* 23var isIE10 = false; 24/*@cc_on 25 if (/^10/.test(@_jscript_version)) { 26 isIE10 = true; 27 } 28@*/ 29console.ls.log("isIE10: ", isIE10); 30 31// Submit the form with Ajax 32var AjaxSubmitObject = function () { 33 var activeSubmit = false; 34 // First we get the value of the button clicked (movenext, submit, prev, etc) 35 var move = ''; 36 37 var startLoadingBar = function () { 38 //Scroll to the top of the page 39 window.scrollTo(0, 0); 40 $('#ajax_loading_indicator').css('display', 'block').find('#ajax_loading_indicator_bar').css({ 41 'width': '20%', 42 'display': 'block' 43 }); 44 }; 45 46 47 var endLoadingBar = function () { 48 $('#ajax_loading_indicator').css('opacity', '0').find('#ajax_loading_indicator_bar').css('width', '100%'); 49 setTimeout(function () { 50 $('#ajax_loading_indicator').css({ 51 'display': 'none', 52 'opacity': 1 53 }).find('#ajax_loading_indicator_bar').css({ 54 'width': '0%', 55 'display': 'none' 56 }); 57 }, 1800); 58 }; 59 60 var checkScriptNotLoaded = function (scriptNode) { 61 if (scriptNode.src) { 62 return ($('head').find('script[src="' + scriptNode.src + '"]').length > 0); 63 } 64 return true; 65 }; 66 67 var bindActions = function () { 68 var logFunction = new ConsoleShim('PJAX-LOG', (LSvar.debugMode < 1)); 69 70 var pjaxErrorHandler = function (href, options, requestData) { 71 logFunction.log('requestData', requestData); 72 if (requestData.status >= 500) { 73 document.getElementsByTagName('html')[0].innerHTML = requestData.responseText; 74 throw new Error(JSON.stringify({ 75 state: requestData.status, 76 message: 'Error in PHP!', 77 data: requestData 78 })); 79 } 80 81 if (requestData.status >= 404) { 82 window.location.href = href; 83 return false; 84 } 85 if (requestData.status >= 300 || requestData.status == 0) { 86 logFunction.log('responseURL', requestData.responseURL); 87 var responseHeaders = requestData.getAllResponseHeaders().trim().split(/[\r\n]+/); 88 var headerMap = {}; 89 responseHeaders.forEach(function (line) { 90 var parts = line.split(': '); 91 var header = parts.shift(); 92 var value = parts.join(': '); 93 headerMap[header.toLowerCase()] = value; 94 }); 95 window.location = headerMap['x-redirect'] || headerMap.location || href; 96 return false; 97 } 98 }; 99 100 var globalPjax = new Pjax({ 101 elements: ['form#limesurvey'], // default is "a[href], form[action]" 102 selectors: ['#dynamicReloadContainer', '#beginScripts', '#bottomScripts'], 103 debug: true, 104 forceRedirectOnFail: true, 105 pjaxErrorHandler: pjaxErrorHandler, 106 reRenderCSS: true, 107 logObject: logFunction, 108 scriptloadtimeout: 1500, 109 }); 110 // Always bind to document to not need to bind again 111 // Restrict to [type=submit]:not([data-confirmedby]) 112 // - :submit is the default if button don't have type (reset button on slider for example), 113 // - confirmedby have their own javascript system 114 $(document).on('click', '.action--ls-button-submit, .action--ls-button-previous', function (e) { 115 $('#limesurvey').append('<input id="onsubmitbuttoninput" name=\'' + $(this).attr('name') + '\' value=\'' + $(this).attr('value') + '\' type=\'hidden\' />'); 116 if (isIE10 || /Edge\/\d+\.\d+/.test(navigator.userAgent)) { 117 e.preventDefault(); 118 $('#limesurvey').trigger('submit'); 119 return false;
120 } 121 }); 122 123 // If the user try to submit the form 124 // Always bind to document to not need to bind again 125 $(document).on('submit', '#limesurvey', function (e) { 126 // Prevent multiposting 127 //Check if there is an active submit 128 //If there is -> return immediately 129 if (activeSubmit) { 130 e.preventDefault(); 131 return false; 132 } 133 //block further submissions 134 activeSubmit = true; 135 $('.action--ls-button-submit, .action--ls-button-previous').prop('disabled', true).addClass('btn-disabled'); 136 if ($('#onsubmitbuttoninput').length == 0) { 137 $('#limesurvey').append('<input id="onsubmitbuttoninput" name=\'' + $('#limesurvey [type=submit]:not([data-confirmedby])').attr('name') + '\' value=\'' + $('#limesurvey [type=submit]:not([data-confirmedby])').attr('value') + '\' type=\'hidden\' />'); 138 } 139 //start the loading animation 140 startLoadingBar(); 141 142 $(document).on('pjax:scriptcomplete.onreload', function () { 143 // We end the loading animation 144 endLoadingBar(); 145 //free submitting again 146 activeSubmit = false; 147 $('.action--ls-button-submit, .action--ls-button-previous').prop('disabled', false).removeClass('btn-disabled'); 148 149 if (/<###begin###>/.test($('#beginScripts').text())) { 150 $('#beginScripts').text(''); 151 } 152 if (/<###end###>/.test($('#bottomScripts').text())) { 153 $('#bottomScripts').text(''); 154 } 155 156 $(document).off('pjax:scriptcomplete.onreload'); 157 }); 158 159 }); 160 return globalPjax; 161 }; 162 163 return { 164 bindActions: bindActions, 165 startLoadingBar: startLoadingBar, 166 endLoadingBar: endLoadingBar, 167 unsetSubmit: function () { 168 activeSubmit = false; 169 }, 170 blockSubmit: function () { 171 activeSubmit = true; 172 } 173 }; 174};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.