/
template.js
224 lines (192 loc) · 6.46 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
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
/*
* LimeSurvey
* Copyright (C) 2007 The LimeSurvey Project Team / Carsten Schmitz
* All rights reserved.
* License: GNU/GPL License v2 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.
*
*
* $Id:$
*/
/*
* 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();
}
/*
* The focusFirst function is added to the eventlistener, when the page is loaded.
*
* This can be used to start other functions on pageload as well. Just put it inside the 'ready' function block
*/
/* Uncomment below if you want to use the focusFirst function */
/*
$(document).ready(function(){
focusFirst();
});
*/
function correctPNG() // correctly handle PNG transparency in Win IE 5.5 & 6.
{
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])
if ((version >= 5.5) && (version<7) && (document.body.filters))
{
for(var i=0; i<document.images.length; i++)
{
var img = document.images[i]
var imgName = img.src.toUpperCase()
if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
{
var imgID = (img.id) ? "id='" + img.id + "' " : "";
var imgClass = (img.className) ? "class='" + img.className + "' " : "";
var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' ";
var imgStyle = "display:inline-block;" + img.style.cssText;
if (img.align == "left") imgStyle = "float:left;" + imgStyle;
if (img.align == "right") imgStyle = "float:right;" + imgStyle;
if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle;
var strNewHTML = "<span " + imgID + imgClass + imgTitle
+ " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
+ "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
+ "(src='" + img.src + "', sizingMethod='scale');\"></span>"
img.outerHTML = strNewHTML
i = i-1
}
}
}
}
$(document).ready(function(){
if($(window).width() < 800)
{
if($('.no-more-tables').length > 0)
{
$('.no-more-tables').find('td').each(function(){
$that = $(this);
//$content = '<td>'+$that.data('title')+'</td>';
$label = $that.data('title');
$input = $that.find('input');
//$that.empty().prepend($content);
$that.find('label').prepend($label);
});
}
}
var outerframeDistanceFromTop = 50;
// Manage top container
if(!$.trim($('#topContainer .container').html()))
{
$('#topContainer').hide();
}
else
{
$topContainerHeight = $('#topContainer').height();
outerframeDistanceFromTop += $topContainerHeight;
}
if(!$.trim($('#surveynametitle').html()))
{
if(!$.trim($('#surveydescription').html()))
{
$('#survey-header').hide();
}
}
$('#outerframeContainer').css({marginTop:outerframeDistanceFromTop+'px'});
$('.language-changer').each(function(){
$that = $(this);
if(!$.trim($that.children('div').html()))
{
$that.hide();
}
});
$('.group-description-container').each(function(){
$that = $(this);
if(!$.trim($that.children('div').html()))
{
$that.hide();
}
});
$('.questionhelp').each(function(){
$that = $(this);
if(!$.trim($that.html()))
{
$that.hide();
}
});
// Load survey button
if ($('#loadallbtnlink').length > 0){
$('#loadallbtnlink').on('click', function()
{
$('#loadallbtn').trigger('click');
});
}
// Save survey button
if ($('#saveallbtnlink').length > 0){
$('#saveallbtnlink').on('click', function()
{
$('#saveallbtn').trigger('click');
});
}
// clearall
if ($('#clearallbtnlink').length > 0){
$('#clearallbtnlink').on('click', function()
{
$('#clearall').trigger('click');
});
}
// Question index
if($('.linkToButton').length > 0){
$('.linkToButton').on('click', function()
{
$btnToClick = $($(this).attr('data-button-to-click'));
$btnToClick.trigger('click');
return false;
});
}
if($('.emtip').length>0)
{
// On Document Load
$('.emtip').each(function(){
if($(this).hasClass('error'))
{
$(this).parents('div.alert.questionhelp').removeClass('alert-info').addClass('alert-danger');
$(this).addClass('strong');
}
});
// On em change
$('.emtip').each(function(){
$(this).on('classChangeError', function() {
$parent = $(this).parent('div.alert.questionhelp');
$parent.removeClass('alert').removeClass('alert-info',1);
$parent.addClass('alert-danger',1).addClass('alert');
if ($parent.hasClass('hide-tip'))
{
$parent.removeClass('hide-tip',1);
$parent.addClass('tip-was-hidden',1);
}
$(this).addClass('strong');
});
$(this).on('classChangeGood', function() {
$parent = $(this).parents('div.alert.questionhelp');
$parent.removeClass('alert-danger');
$(this).removeClass('strong');
$parent.addClass('alert-info');
if ($parent.hasClass('tip-was-hidden'))
{
$parent.removeClass('tip-was-hidden').addClass('hide-tip');
}
});
});
}
// Hide the menu buttons at the end of the Survey
if($(".hidemenubutton").length>0)
{
$('.navbar-right').hide();
}
});