1/* 2 LimeSurvey 3 Copyright (C) 2007-2016 The LimeSurvey Project Team / Carsten Schmitz 4 All rights reserved. 5 License: GNU/GPL License v3 or later, see LICENSE.php 6 LimeSurvey is free software. This version may have been modified pursuant 7 to the GNU General Public License, and as distributed it includes or 8 is derivative of works licensed under the GNU General Public License or 9 other free or open source software licenses. 10 See COPYRIGHT.php for copyright notices and details. 11 12 13 (¯`·._.·(¯`·._.· Theme main JavaScript ·._.·´¯)·._.·´¯) 14 15 Javascript file for this template. 16 17 You'd rather not touch it. This file can be overwritten by an update. 18 19 20 âââââââ âââââââ ââââ âââ âââââââ âââââââââ âââââââââ âââââââ âââ âââ ââââââââââ âââ âââ 21 âââââââââââââââââ âââââ âââââââââââââââââââââ âââââââââââââââââââââ ââââââââââââââ âââ âââ 22 âââ ââââââ âââ ââââââ ââââââ âââ âââ âââ âââ ââââââ ââââââ ââââââââ âââ 23 âââ ââââââ âââ âââââââââââââ âââ âââ âââ âââ ââââââ ââââââ ââââââââ âââ 24 âââââââââââââââââ âââ âââââââââââââââ âââ âââ âââââââââââââââââââââââââââââ âââ âââ 25 âââââââ âââââââ âââ âââââ âââââââ âââ âââ âââââââ âââââââ ââââââââââ âââ âââ 26 27 Please, use custom.js 28 29*/ 30 31 32/** 33 * The general Template closure. 34 * This is to capsule eventual errors inside of the template function, so the general script all run as the should 35 */ 36// Global constructor, used in multiple twig files 37// eslint-disable-next-line no-unused-vars 38var ThemeScripts = function(){ 39 // defining the console object once. Also filtered by the global setting 40 // eslint-disable-next-line no-console 41 var logObject = console.ls ? (window.debugState.frontend ? console.ls : console.ls.silent) : console; 42 /** 43 * The function focusFirst puts the Focus on the first non-hidden element in the Survey. 44 * Normally this is the first input field (the first answer). 45 */ 46 var focusFirst = function focusFirst() 47 { 48 $('#limesurvey :input:visible:enabled:first').focus(); 49 }; 50 51 /** 52 * fix padding of body according to navbar-fixed-top 53 * in endpage and in $(window).resize 54 */ 55 var fixBodyPadding = function fixBodyPadding(){ 56 /* The 60 px is fixed in template.css */ 57 $('body').css('padding-top', Math.round($('.navbar-fixed-top').height()) +'px'); 58 }; 59 /** 60 * Set suffix/prefix clone for little screen (at top) 61 */ 62 var sliderSuffixClone = function sliderSuffixClone(){ 63 $('.numeric-multi .slider-item .slider-right').each(function(){ 64 var colWidth='12'; 65 66 if($(this).closest('.slider-item').find('.slider-left').length){ 67 colWidth = '6'; 68 } 69 70 $(this).clone().removeClass('col-xs-12').addClass('visible-xs-block col-xs-'+colWidth).prop('aria-hidden',true).insertBefore($(this).prev('.slider-container')); 71 $(this).addClass('hidden-xs'); 72 $(this).closest('.slider-item').find('.slider-left').removeClass('col-xs-12').addClass('col-xs-6'); 73 }); 74 75 }; 76 77 /** 78 * Hide some part if empty 79 * Some can be needed if contain only js 80 * Some are not really needed : little margin only is shown 81 * Allowed content -> <script> and <img/> 82 */ 83 var hideEmptyPart = function hideEmptyPart() 84 { 85 $('.question-help-container').each(function(){ 86 /* Only if have only script tag inside or empty tag */ 87 if($(this).text().trim()=='' && !/<img/.test($(this).html())){ 88 $(this).addClass('hidden'); 89 } 90 }); 91 $('.group-description').each(function(){ 92 /* Only if have only script tag inside or empty tag */ 93 if($(this).text().trim()=='' && !/<img/.test($(this).html())){ 94 $(this).addClass('hidden'); 95 } 96 }); 97 $('.question-help-container.hidden').on('html:updated',function(){ 98 if($(this).text().trim()!='' && !/<img/.test($(this).html())){ 99 $(this).removeClass('hidden'); 100 } 101 }); 102 // .question-help-container:not(.hidden) don't work ? 103 $('.question-help-container').on('html:updated',function(){ 104 if($(this).text().trim()=='' && !/<img/.test($(this).html())){ 105 $(this).addClass('hidden'); 106 } 107 }); 108 }; 109 110 var initTopMenuLanguageChanger = function(selectorItem, selectorGlobalForm){ 111 // $(selectorContainer).height($('#main-row').height()); 112 $(selectorItem).on('click', function(){ 113 var lang = $(this).data('limesurvey-lang'); 114 /* The limesurvey form exist in document, move select and button inside and click */ 115 $(selectorGlobalForm+' [name=\'lang\']').remove(); // Remove existing lang selector 116 $('<input type=\'hidden\'>').attr('name','lang').val(lang).appendTo($(selectorGlobalForm)); 117 }); 118 }; 119 120 var init = function(){ 121 122 /** 123 * Code included inside this will only run once the page Document Object Model (DOM) is ready for JavaScript code to execute 124 * @see https://learn.jquery.com/using-jquery-core/document-ready/ 125 * Also it will run on a complete pageload via the internal pjax system 126 */
127 $(document).on('ready pjax:scriptcomplete',function() 128 { 129 /* Uncomment below if you want to use the focusFirst function */ 130 //focusFirst(); 131 /* Some function are launched in endpage.pstpl */ 132 hideEmptyPart(); 133 // If list of nav-bar action is empty: remove it (else .navbar-toggle is shown on small screen) // 134 if(!$('#navbar li').length){ 135 $('#navbar').remove(); 136 $('[data-target=\'#navbar\']').remove(); 137 } 138 139 // Scroll to first error - After user close modal - 140 if($('.input-error').length > 0 || $('.ls-em-error').length > 0 ) { 141 $('#bootstrap-alert-box-modal').on('hidden.bs.modal', function () { 142 143 var $firstError = ($('.input-error').length > 0 ) ? $('.input-error').first() : $('.ls-em-error').first(); 144 145 var $pixToScroll = ( $firstError.offset().top - 100 ); 146 $('html, body').animate({ 147 scrollTop: $pixToScroll + 'px' 148 }, 'fast'); 149 }); 150 } 151 152 $('.language-changer').each(function(){ 153 var $that = $(this); 154 if(!$.trim($that.children('div').html())) 155 { 156 $that.hide(); 157 } 158 }); 159 160 // Hide the menu buttons at the end of the Survey 161 if($('.hidemenubutton').length>0) 162 { 163 $('.navbar-right').hide(); 164 } 165 166 //Survey list container 167 if($('#surveys-list-container').length > 0){ 168 var footerHeight = $('#surveyListFooter').outerHeight(); 169 var headerHeight = 2*$('#navbar').outerHeight(); 170 var bodyHeight = $(document).height()-(footerHeight+headerHeight); 171 logObject.log({ 172 footerHeight : footerHeight, 173 headerHeight : headerHeight, 174 bodyHeight : bodyHeight 175 }); 176 $('#surveys-list-container').css('min-height', bodyHeight+'px'); 177 } 178 179 // Captcha action 180 if($('#reloadCaptcha').length>0) 181 { 182 $('#reloadCaptcha').on('click', function(e){ 183 e.preventDefault(); 184 window.location.reload(); 185 }); 186 } 187 188 // Survey list footer 189 if($('#surveyListFooter').length>0) 190 { 191 var $surveyListFooter = $('#surveyListFooter'); 192 $('#outerframeContainer').after($surveyListFooter); 193 } 194 195 $(function () { 196 $('[data-toggle="tooltip"]').tooltip(); 197 }); 198 199 // Bind language changer onclick event. 200 // This function is defined in assets/packages/limesurvey/survey.js 201 // eslint-disable-next-line no-undef 202 activateLanguageChanger(); 203 204 //Fix the navigation overflow 205 fixBodyPadding(); 206 }); 207 208 /** 209 * Code included inside this will run each time windows is resized 210 * @see https://api.jquery.com/resize/ 211 */ 212 $(window).resize(function () { 213 fixBodyPadding(); 214 }); 215 var onkeyEventInput = function(e){ 216 var code = (e.keyCode ? e.keyCode : e.which); 217 if (code==13 && e.ctrlKey != true) { 218 e.preventDefault(); 219 if($(this).closest('.question-container').hasClass('multiple-short-txt')){ 220 if($(this).closest('.question-item').next('.question-item').length > 0) { 221 $(this).closest('.question-item').next('.question-item').find('input, textarea').first().focus(); 222 return; 223 } 224 } 225 $(this).closest('.question-container').next('.question-container').find('input, textarea').first().focus(); 226 } else if (code==13 && e.ctrlKey == true) { 227 $('.action--ls-button-submit').trigger('click'); 228 } 229 }; 230 231 var onkeyEventTextarea = function(e){ 232 var code = (e.keyCode ? e.keyCode : e.which); 233 if (code==13 && e.altKey == true) { 234 e.preventDefault(); 235 if($(this).closest('.question-container').hasClass('multiple-short-txt')){ 236 if($(this).closest('.question-item').next('.question-item').length > 0) { 237 $(this).closest('.question-item').next('.question-item').find('input, textarea').first().focus(); 238 return; 239 } 240 } 241 $(this).closest('.question-container').next('.question-container').find('input, textarea').first().focus(); 242 } else if (code==13 && e.ctrlKey == true) { 243 $('.action--ls-button-submit').trigger('click'); 244 } 245 }; 246 247 $(document).on('keydown', '.answer-container input', onkeyEventInput); 248 $(document).on('keydown', '.answer-container textarea', onkeyEventTextarea); 249 }; 250 251 var initUserForms = function(){ 252 sliderSuffixClone(); 253 fixBodyPadding(); 254 hideEmptyPart(); 255 }; 256 var initGlobal = function(){ 257 sliderSuffixClone(); 258 fixBodyPadding(); 259 if(jQuery.isFunction(window.templateCore.hideQuestionWithRelevanceSubQuestion)) { 260 window.templateCore.hideQuestionWithRelevanceSubQuestion(); 261 } 262 if(jQuery.isFunction(window.templateCore.hideMultipleColumn)) { 263 window.templateCore.hideMultipleColumn(); 264 } 265 hideEmptyPart(); 266 }; 267 268 var initWelcomePage = function(){ 269 logObject.log('Starting up for first page'); 270 if($('#datasecurity_accepted').length >0) { 271 $('#ls-button-submit').prop('disabled', true); 272 /* 273 * #### Animation function doesn't work on IE -> Deactivate until now. 274 * $('#ls-button-submit').prop('disabled', true).parent().on('mouseenter', function(e){ 275 * logObject.log('starting animation'); 276 * if(!$('#datasecurity_accepted').prop('checked') && $(this).data('moving') != 1){ 277 * e.preventDefault(); 278 * var self = this; 279 * $(self).data('moving', 1);
280 * $('label[for=datasecurity_accepted]').animate({'zoom': '1.05'}, 500, function(){ 281 * $('label[for=datasecurity_accepted]').animate({'zoom': '1'}, 500, function(){ 282 * $(self).data('moving', 0); 283 * }); 284 * }); 285 * return false; 286 * } 287 * }); 288 */ 289 $('#datasecurity_accepted').on('change', function(){ 290 $('#ls-button-submit').prop('disabled', !$(this).prop('checked')); 291 }); 292 293 } 294 }; 295 296 return { 297 init: init, 298 initUserForms: initUserForms, 299 initGlobal: initGlobal, 300 initWelcomePage: initWelcomePage, 301 focusFirst: focusFirst, 302 sliderSuffixClone : sliderSuffixClone, 303 fixBodyPadding : fixBodyPadding, 304 hideQuestionWithRelevanceSubQuestion : window.templateCore.hideQuestionWithRelevanceSubQuestion, 305 hideEmptyPart : hideEmptyPart, 306 initTopMenuLanguageChanger: initTopMenuLanguageChanger, 307 log: logObject 308 }; 309 310};
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.