-
Notifications
You must be signed in to change notification settings - Fork 988
/
template.js
150 lines (139 loc) · 4.71 KB
/
template.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
/*
* 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.
*
*
* Description: Javascript file for templates. Put JS-functions for your template here.
*
*
*/
/**
* 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).
*/
function focusFirst(Event)
{
$('#limesurvey :input:visible:enabled:first').focus();
}
/**
* 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/
*/
$(document).on('ready pjax:complete',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
if($(".input-error").length > 0) {
$('#bootstrap-alert-box-modal').on('hidden.bs.modal', function () {
$firstError = $(".input-error").first();
$pixToScroll = ( $firstError.offset().top - 100 );
$('html, body').animate({
scrollTop: $pixToScroll + 'px'
}, 'fast');
});
}
$('.language-changer').each(function(){
$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 footer
if($('#surveyListFooter').length>0)
{
$surveyListFooter = $('#surveyListFooter');
$('#outerframeContainer').after($surveyListFooter);
}
$(function () {
//$('[data-toggle="tooltip"]').tooltip()
})
});
/**
* Code included inside this will run each time windows is resized
* @see https://api.jquery.com/resize/
*/
$(window).resize(function () {
fixBodyPadding();
});
/**
* Replace all existing alert default javascript function
*/
//~ window.alert = function(message, title) {
//~ $(function() {
//~ $("#bootstrap-alert-box-modal .modal-header .h4").text(title || "");
//~ $("#bootstrap-alert-box-modal .modal-body").html("<p>"+message+"</p>" || "");
//~ $("#bootstrap-alert-box-modal").modal('show');
//~ });
//~ };
/**
* fix padding of body according to navbar-fixed-top
* in endpage and in $(window).resize
*/
function fixBodyPadding(){
/* The 60 px is fixed in template.css */
$("body").css("padding-top",$(".navbar-fixed-top").height()+"px")
}
/**
* Set suffix/prefix clone for little screen (at top)
*/
function sliderSuffixClone(){
$(".numeric-multi .slider-item .slider-right").each(function(){
if($(this).closest(".slider-item").find(".slider-left").length){
var colWidth="6";
}else{
var colWidth="12";
}
$(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
*/
function hideEmptyPart()
{
$(".question-help-container").each(function(){
if($(this).text().trim()==""){/* Only if have only script tag inside or empty tag */
$(this).addClass("hidden");
}
});
$(".group-description").each(function(){
if($(this).text().trim()==""){/* Only if have only script tag inside or empty tag */
$(this).addClass("hidden");
}
});
$(".question-help-container.hidden").on("html:updated",function(){
if($(this).text().trim()!=""){
$(this).removeClass("hidden");
}
});
$(".question-help-container").on("html:updated",function(){ // .question-help-container:not(.hidden) don't work ?
if($(this).text().trim()==""){
$(this).addClass("hidden");
}
});
}