summaryrefslogtreecommitdiffstats
path: root/main/survey/js/customizeImageView4Respondent.js
blob: 2b2c2d37171243a695232b658dc2dfb4804c5dbb (plain) (blame)
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
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
//funkcije za gladko delovanje prikazovanja visjih blokov odgovorov @ rangiranje (razvrščanja) (tip = 17)


function customizeImageView4Respondent(tip, spremenljivka, vre_id, ajax, anketa, site_url, usr_id, other, mobile, quick_view, preview_spremenljivka){

		if(quick_view || preview_spremenljivka){	//ce je le predogled
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).draggable( "option", "disabled", true );	//disable-anje drag and drop
		}
			
		//ureditev visine kategorije (div) glede na prisotnost slike ali vecvrsticnega teksta **************************************************
		var default_cat_height = 15;
		var final_height = 0;
		//var cat_text_length = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).text().length;	//hrani stevilo znakov, ki so vpisani v trenutni kategoriji odgovora
		var content = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html();
		content = content.replace(/<img[^>]*>/gi,"");	//odstranit tekst med img tag-i
		
		var cat_text_length = content.length;	//hrani stevilo znakov, ki so vpisani v trenutni kategoriji odgovora
		//console.log('Število znakov v kategoriji: '+cat_text_length);
		
		var num_of_br = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' br').length;	//hrani stevilo br oz. ročnih vnosov novih vrstic
		//console.log('Število br v kategoriji: '+num_of_br);
		
		var num_imgs = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').length; //hrani stevilo img v interesiranem div-u
		//console.log('Število slik v kategoriji: '+num_imgs);
		
		var max_cat_text_length = 30; //hrani max stevilo dolzine teksta za eno vrstico
		
		var oneLineHeight = 20;

		if( (cat_text_length >  max_cat_text_length) ){//ce je tekst daljsi od 30 znakov
			var kvocient = Math.ceil(cat_text_length/max_cat_text_length);
			final_height = final_height + kvocient*oneLineHeight;
		}		

		if (num_imgs != 0){	// ce imamo sliko
			
			var img_height = 0;
			//var max_width = $('.ranking').width();
			var max_width = 230;
			var img = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img');
			var img_width = img.width();
			//console.log("img_width: "+img_width);
			
			var img_height = img.height();
			//console.log("img_height: "+img_height);
			
			if (img_width > max_width){
				img_height = (img_height / img_width) * max_width;
				img.css({width: max_width});
				img.css({height: img_height});
				//$('#vre_id_'+vre_id).css({height: height});
				//console.log("Vecji od max width");
			}
			
			//ureditev mobilne različice prikazovanja slik znotraj kategorij odgovorov
/* 			if (mobile == 1){	//ce je mobilnik				
				img_height = (img_height / img_width) * 100;
				img_width = 100;
				$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').attr('style', 'margin: auto !important');	//dodaj atribut
				$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').css({'height':img_height,'width':img_width});	//ustrezno spremeni visino in sirino slike
			} */			
			//ureditev mobilne različice prikazovanja - konec
				
			//console.log("img_height: "+img_height);
			if(img_height > 25){	//ce je visina slike vecja od default visine kategorije
				final_height = final_height + img_height;		
			}	



			//ureditev visine variable_holder, ki je znotraj okvirja !!!!!!!!!!
			//$('#spremenljivka_'+spremenljivka+' div.variable_holder.clr').css({'height':(final_height + img_height)+'px'});
		}
		
		if(num_of_br != 0){	//ce imamo vnesene rocne skoke v novo vrstico </br>
			var br_height = num_of_br*oneLineHeight;
			final_height = final_height + br_height;
		}
		
		if (final_height != 0){
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).css({'height':final_height});	//dodaj style atributu še novo višino za levi blok
		}
		//ureditev visine kategorije (div) glede na prisotnost slike ali vecvrsticnega teksta - konec********************************************
		
		//ureditev visine celotnega vprasanja****************************************************************************************************
		
		//dynamic_question_height_ranking(spremenljivka, num_grids);
		
		//ureditev visine celotnega vprasanja - konec*******************************************************************************************
}



//function customizeImageView4Respondent(tip, spremenljivka, vre_id, ajax, anketa, site_url, usr_id, other, mobile, num_grids, quick_view, preview_spremenljivka){
function customizeImageView4RespondentOld(tip, spremenljivka, vre_id, ajax, anketa, site_url, usr_id, other, mobile, quick_view, preview_spremenljivka){
	var top_cat = -1;
	var left_cat = -1;
	if (mobile == 0 || mobile == 2){
		top_cat = -6;
		left_cat = -6;
	}

		if(quick_view || preview_spremenljivka){	//ce je le predogled
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).draggable( "option", "disabled", true );	//disable-anje drag and drop
		}
	
		//ureditev visine kategorije (div) glede na prisotnost slike ali vecvrsticnega teksta **************************************************
		var default_cat_height = 15;
		var final_height = 0;
		//var cat_text_length = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).text().length;	//hrani stevilo znakov, ki so vpisani v trenutni kategoriji odgovora
		var cat_text_length = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html().length;	//hrani stevilo znakov, ki so vpisani v trenutni kategoriji odgovora
		//console.log('Število znakov v kategoriji: '+cat_text_length);
		
		var num_of_br = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' br').length;	//hrani stevilo br oz. ročnih vnosov novih vrstic
		//console.log('Število br v kategoriji: '+num_of_br);
		
		var num_imgs = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').length; //hrani stevilo img v interesiranem div-u
		//console.log('Število slik v kategoriji: '+num_imgs);
		
		var max_cat_text_length = 30; //hrani max stevilo dolzine teksta do katerega ni potrebno samodejno dodati <br>
		
		
		if( (cat_text_length >  max_cat_text_length) && (num_of_br == 0) && (num_imgs == 0) ){//ce je tekst daljsi od 30 znakov, nima breakov ali slik dodaj <br>
		//if( (cat_text_length >  max_cat_text_length) ){//ce je tekst daljsi od 35 znakov dodaj <br>
			//console.log('Tekst je daljši od '+max_cat_text_length+' znakov');
			//var txt2 = txt1.slice(0, 3) + "bar" + txt1.slice(3);
			//var txt = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).text();
/* 			var txt = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html();
			//console.log(txt);
			var txt_alt = txt.slice(0, max_cat_text_length) + "<br>" + txt.slice(max_cat_text_length);
			//console.log(txt_alt);
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html(txt_alt); */
			final_height = final_height + default_cat_height + 25;
			final_height = (cat_text_length/max_cat_text_length)*30;
			//console.log(final_height);
		}
		/* 	else if( (cat_text_length >  max_cat_text_length) && (num_of_br == 0) && (num_imgs != 0) ){//ce je tekst daljsi od 35 znakov, nima breakov, ima pa sliko dodaj <br>
			
			var txt = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html();
			console.log(txt);
			var n_img_start = txt.search("<img"); //var n = str.search("W3Schools");	//hrani index, kjer se začne html za sliko
			var n_img_end = txt.indexOf(">");
			console.log(n_img_start);
			console.log(n_img_end);
			//var txt_alt = txt.slice(0, max_cat_text_length) + "<br>" + txt.slice(max_cat_text_length);
			//console.log(txt_alt);
			//$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).html(txt_alt);
			//final_height = final_height + default_cat_height + 25;
			//console.log(final_height);
			
		} */
		

		if (num_imgs != 0){	// ce imamo sliko
			
			var img_height = 0;
			//var max_width = $('.ranking').width();
			var max_width = 230;
			var img = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img');
			var img_width = img.width();
			//console.log("img_width: "+img_width);
			
			var img_height = img.height();
			//console.log("img_height: "+img_height);
			
			if (img_width > max_width){
				img_height = (img_height / img_width) * max_width;
				img.css({width: max_width});
				img.css({height: img_height});
				//$('#vre_id_'+vre_id).css({height: height});
				//console.log("Vecji od max width");
			}
			
			//ureditev mobilne različice prikazovanja slik znotraj kategorij odgovorov
/* 			if (mobile == 1){	//ce je mobilnik				
				img_height = (img_height / img_width) * 100;
				img_width = 100;
				$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').attr('style', 'margin: auto !important');	//dodaj atribut
				$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img').css({'height':img_height,'width':img_width});	//ustrezno spremeni visino in sirino slike
			} */			
			//ureditev mobilne različice prikazovanja - konec
				
			//console.log("img_height: "+img_height);
			if(img_height > 25){	//ce je visina slike vecja od default visine kategorije
				final_height = final_height + img_height;		
			}	



			//ureditev visine variable_holder, ki je znotraj okvirja !!!!!!!!!!
			//$('#spremenljivka_'+spremenljivka+' div.variable_holder.clr').css({'height':(final_height + img_height)+'px'});
		}
		if(num_of_br != 0){
			var br_height = num_of_br*25;
			
			if (num_imgs == 0){
				final_height = final_height + default_cat_height + br_height;
			}
			else{
				final_height = final_height + br_height;
			}
			
			
			//console.log(final_height);
			if( (img_height < 25) && (img_height != 0) ){			
				final_height = final_height + img_height;
			}
		}
		if (final_height != 0){
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).css({'height':final_height});	//dodaj style atributu še novo višino za levi blok
		}
		//ureditev visine kategorije (div) glede na prisotnost slike ali vecvrsticnega teksta - konec********************************************
		
		//ureditev visine celotnega vprasanja****************************************************************************************************
		
		//dynamic_question_height_ranking(spremenljivka, num_grids);
		
		//ureditev visine celotnega vprasanja - konec*******************************************************************************************
}

//funkcija, ki ureja visina celotnega vprasanja glede na skupno visino kategorij v okvirjih
function question_height_ranking(spremenljivka){	
	var final_height_kategorije_left = final_height_kategorije_right = final_height = tmp_height_kategorije_left = tmp_height_kategorije_right =  naslov_height = 0;
	var i = 1;
	var j = 1;
	
	var default_var_height_now = $('#spremenljivka_'+spremenljivka).height();
	
	$('#half_'+spremenljivka).children('div').each(function(){	//preleti leve kategorije
		//tmp_height_kategorije_left = $(this).height() + 10;
		tmp_height_kategorije_left = $(this).outerHeight( true );
		//console.log("tmp_height_kategorije_left "+i+": "+tmp_height_kategorije_left);
		i++;
		final_height_kategorije_left = final_height_kategorije_left + tmp_height_kategorije_left;
	});
	
	$('#half2_'+spremenljivka).children('div').each(function(){	//preleti desne kategorije
		//tmp_height_kategorije_right = $(this).height() + 10;
		tmp_height_kategorije_right = $(this).outerHeight( true );
		//console.log("tmp_height_kategorije_right "+j+": "+tmp_height_kategorije_right);
		j++;
		final_height_kategorije_right = final_height_kategorije_right + tmp_height_kategorije_right;
	});
	
	if(final_height_kategorije_left > final_height_kategorije_right){
		final_height_kategorije = final_height_kategorije_left;
	}else{
		final_height_kategorije = final_height_kategorije_right;
	}
	
	//console.log("final_height_kategorij: "+final_height_kategorije);
	
	naslov_height = $('#spremenljivka_'+spremenljivka+' .naslov').height();
	//console.log("naslov_height: "+naslov_height);
	
	final_height = naslov_height + final_height_kategorije + 120;
	
	//ureditev pozicije komentarjev
	if($('#spremenljivka_'+spremenljivka+' .comment').length > 0) {	//ali je kakšen komentar pri vprasanju z razvrscanjem?
		//$('#prestavljanje_'+spremenljivka).height(final_height);
		//final_height = final_height + 200;	//koncni visini vprasanja dodamo se default visino komentarja
	}		
	//ureditev pozicije komentarjev - konec	
	
	
	if(final_height > default_var_height_now){	//ce je nova visina vecja od default zacetne
		$('#spremenljivka_'+spremenljivka).height(final_height);
		//console.log(final_height);
		//$('#spremenljivka_'+spremenljivka+' div.variable_holder.clr').height(final_height + 25);
		$('#spremenljivka_'+spremenljivka+' div.variable_holder.clr').height(final_height - naslov_height + 10);
	}
	//console.log("default_var_height_now: "+default_var_height_now);
	//console.log("final_height: "+final_height);
	
}



function frame_height_ranking (ui, spremenljivka){
	var trenutna_visina_prenesenega = ui.item.height();
	//console.log(trenutna_visina_prenesenega);
	var trenutni_okvir = $('#half2_'+spremenljivka);
	var stevilo_prisotnih = trenutni_okvir.children('div').length;
	//console.log(stevilo_prisotnih);
	var i = 0;
	trenutni_okvir.siblings().children('li').children('div').each(function(){	//preleti prazne okvirje
		i = i + 1;
		if(stevilo_prisotnih == i){
			$(this).height(trenutna_visina_prenesenega);
			//console.log(i);
		}
	});
}

function frame_height_ranking_premikanje_dyn (ui, spremenljivka){
	
	var trenutna_visina_prenesenega = ui.item.height();
	var trenutni_okvir = $('#sortzone_'+spremenljivka);
	var stevilo_prisotnih = trenutni_okvir.children('div').length;
	var iscem = 'vrednost_';
	var tmp = ui.item.attr('id');
	//var pos = tmp.search(iscem);
	//var vre_id = tmp.slice(pos);
	var vre_id = tmp.slice(tmp.search(iscem));
	vre_id = vre_id.replace(iscem, '');
	//console.log("Trenutni indeks: "+ui.item.index());
	var sortedID = trenutni_okvir.sortable( "toArray" );	//trenutni vrstni red odgovorov v polje
	
	var i = 0;
	trenutni_okvir.siblings().children('li').children('div').each(function(){	//preleti okvirje
		var visina = $('#'+sortedID[i]).height();	//visina i-tega odgovora
		//console.log("Visina odgovora "+i+" : "+$('#'+sortedID[i]).height());		
		$(this).height(visina);	//visina trenutnega okvirja naj bo enaka visini ustreznega odgovora
		i = i + 1;
	});
}

function frame_height_ranking_premikanje (spremenljivka, vre_id, vrstni_red){
	var trenutna_visina_prenesenega = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).height();
	var i = 0;
	$('#sortzone_'+spremenljivka).siblings().children('li').children('div').each(function(){	//preleti prazne okvirje
		i = i + 1;
		if(vrstni_red == i){
			$(this).height(trenutna_visina_prenesenega);
			//console.log(i);
		}
	});
}


//************ za pravilno velikost slik
//*********** funkcija za resize slik, ko so te vecje od max_width
function ranking_image_resize(spremenljivka, vre_id){
	//console.log("ranking_image_resize");
 	//var max_width = 220;
 	var max_width = $('.ranking').width();
 	
	//spremenljivka_4582_vrednost_24243
	
	var img = $('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id+' img');
	var num_imgs = img.length; //hrani stevilo img v interesiranem div-u
	if(num_imgs != 0){
		var width = img.width();
		var height = img.height();		
		if (width > max_width){
			height = (height / width) * max_width;
			img.css({width: max_width});	//sirina slike
			img.css({height: height});	//visina slike
			$('#spremenljivka_'+spremenljivka+'_vrednost_'+vre_id).css({height: height}); //visina okvirja
		}
	}
}
//*********** konec - funkcija za resize slik, ko so te vecje od max_width

//*************************************** za pravilno velikost slik - konec