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