root / snf-astakos-app / astakos / im / static / im / js / common.js @ ce43eae7
History | View | Annotate | Download (13.8 kB)
1 |
function setContainerMinHeight(applicableDiv) { |
---|---|
2 |
|
3 |
if ($(applicableDiv).length > 0) { |
4 |
//var h = $('.header').height(); div.header is not found
|
5 |
var f = $('.footer').height(); |
6 |
var w = $(window).height(); |
7 |
var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) ); |
8 |
var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", ""))); |
9 |
|
10 |
var c = w - ( f+pTop+pBottom+36);//36 is header's height. |
11 |
$(applicableDiv).css('min-height', c); |
12 |
} |
13 |
|
14 |
} |
15 |
|
16 |
function tableFixedCols(table, firstColWidth ){ |
17 |
ColsNum = $('table th').size(); |
18 |
var ColWidth = parseFloat( (100 - firstColWidth)/ColsNum ).toFixed(0); |
19 |
var ColWidthPercentage = ColWidth+'%'; |
20 |
var firstColWidthPercentage = firstColWidth+'%'; |
21 |
$('table th, table td').attr('width',ColWidthPercentage ); |
22 |
$('table tr td:first-child, table tr th:first-child').attr('width',firstColWidthPercentage ); |
23 |
|
24 |
} |
25 |
|
26 |
function addClassHover(hoverEl, applicableEl){ |
27 |
$(hoverEl).hover(
|
28 |
function () {
|
29 |
|
30 |
$(applicableEl).addClass('red-border') |
31 |
}, |
32 |
function () {
|
33 |
$(applicableEl).removeClass('red-border'); |
34 |
|
35 |
}); |
36 |
} |
37 |
//equal heights
|
38 |
|
39 |
(function($) { |
40 |
$.fn.equalHeights = function(minHeight, maxHeight) { |
41 |
tallest = (minHeight) ? minHeight : 0;
|
42 |
this.each(function() { |
43 |
if($(this).height() > tallest) { |
44 |
tallest = $(this).height(); |
45 |
} |
46 |
}); |
47 |
if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
|
48 |
return this.each(function() { |
49 |
$(this).height(tallest); |
50 |
}); |
51 |
} |
52 |
})(jQuery); |
53 |
|
54 |
|
55 |
|
56 |
// fix for iPhone - iPad orientation bug
|
57 |
var metas = document.getElementsByTagName('meta'); |
58 |
function resetViewport() { |
59 |
var i;
|
60 |
if (navigator.userAgent.match(/iPhone/i)) { |
61 |
for (i=0; i<metas.length; i++) { |
62 |
if (metas[i].name == "viewport") { |
63 |
metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
|
64 |
} |
65 |
} |
66 |
} |
67 |
} |
68 |
resetViewport(); |
69 |
|
70 |
window.onorientationchange = function() { |
71 |
resetViewport(); |
72 |
}; |
73 |
|
74 |
function gestureStart() { |
75 |
for (i=0; i<metas.length; i++) { |
76 |
if (metas[i].name == "viewport") { |
77 |
metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
|
78 |
} |
79 |
} |
80 |
} |
81 |
|
82 |
if (navigator.userAgent.match(/iPhone/i)) { |
83 |
document.addEventListener("gesturestart", gestureStart, false); |
84 |
} |
85 |
//end of fix
|
86 |
|
87 |
|
88 |
/* project members page js */
|
89 |
function check_form_actions_inactive(){ |
90 |
if ( $('#members-table tbody td.check input:checked').length >0 ) { |
91 |
$('.projects .form-actions').removeClass('inactive'); |
92 |
} else {
|
93 |
$('.projects .form-actions').addClass('inactive'); |
94 |
} |
95 |
|
96 |
// updating form data
|
97 |
var forms = $("form.link-like:has('input.members-batch-action')"); |
98 |
forms.each(function(index, form){
|
99 |
var member_ids, checked;
|
100 |
form = $(form);
|
101 |
form.find("input.member-option").remove();
|
102 |
checked = $('#members-table tbody td.check input:checked'); |
103 |
member_ids = _.map(checked, function(el) {
|
104 |
return parseInt($(el).val()); |
105 |
}); |
106 |
|
107 |
_.each(member_ids, function(id) {
|
108 |
var newel;
|
109 |
newel = $("<input name='members' class='member-option' type='hidden' value='"+id+"'>"); |
110 |
form.append(newel); |
111 |
}); |
112 |
}) |
113 |
} |
114 |
|
115 |
|
116 |
function tableSort(tableEl, iDisplayLength, bFilter) { |
117 |
|
118 |
// bFilter is an optional parameter
|
119 |
// if bFilter is provided, search input will be visible
|
120 |
bFilter = typeof bFilter !== 'undefined' ? bFilter : true; |
121 |
|
122 |
// iDisplayLength is an optional parameter
|
123 |
// iDisplayLength controls the max number of rows visible to each page
|
124 |
iDisplayLength = typeof iDisplayLength !== 'undefined' ? iDisplayLength : 10; |
125 |
|
126 |
// return if table holds no data
|
127 |
if (tableEl.find('tbody').find('tr').length <2 ){ |
128 |
return;
|
129 |
} |
130 |
|
131 |
var dateArr = [];
|
132 |
var numHTMLArr = [];
|
133 |
|
134 |
_.each(tableEl.find('th'),function(value, key, list){ |
135 |
if ( $(value).attr('class').indexOf("date")> -1 ) { |
136 |
dateArr.push(key); |
137 |
} |
138 |
if ( $(value).attr('class').indexOf("members_count")> -1) { |
139 |
numHTMLArr.push(key); |
140 |
}; |
141 |
|
142 |
}); |
143 |
|
144 |
// control pagination & table sorting for projects intro page
|
145 |
tableEl |
146 |
.bind('page', function () { |
147 |
$('#members-table input').attr('checked', false); |
148 |
check_form_actions_inactive(); |
149 |
}) |
150 |
.dataTable({ |
151 |
"bFilter": bFilter,
|
152 |
"iDisplayLength": iDisplayLength,
|
153 |
"bLengthChange": true, |
154 |
"sDom": '<"top">frt<"clearfix"><"bottom"i<"select"l>p>', |
155 |
"bStateSave": true, |
156 |
"aoColumnDefs": [
|
157 |
{ "sType": "num-html", "aTargets": numHTMLArr }, |
158 |
{ "sType": "date-uk", "aTargets": dateArr }, |
159 |
], |
160 |
"oLanguage": {
|
161 |
"sLengthMenu": 'Pagination <select>'+ |
162 |
'<option value="10">10</option>'+
|
163 |
'<option value="25">25</option>'+
|
164 |
'<option value="50">50</option>'+
|
165 |
'<option value="-1">All</option>'+
|
166 |
'</select>'
|
167 |
}, |
168 |
}); |
169 |
|
170 |
$('.dataTables_wrapper').addClass('clearfix'); |
171 |
} |
172 |
|
173 |
$(document).ready(function() { |
174 |
|
175 |
var is_firefox = navigator.userAgent.toLowerCase().indexOf('firefox') > -1; |
176 |
|
177 |
/* api access */
|
178 |
$(".token-view .detail").click(function() { |
179 |
$(this).find("input").select(); |
180 |
}); |
181 |
|
182 |
$('#dummy_auth_token').html( $('.token-view input[name="auth_token"]').val()); |
183 |
$('#dummy_token_url').html( $('.token-view input[name="token_url"]').val()) |
184 |
|
185 |
|
186 |
if (is_firefox ){
|
187 |
$('.dummy-input').css('display','block'); |
188 |
$('.dummy-input').next('input').css('visibility','hidden'); |
189 |
} |
190 |
|
191 |
/* api access test
|
192 |
|
193 |
*/
|
194 |
|
195 |
|
196 |
setContainerMinHeight('.container .wrapper');
|
197 |
//tableFixedCols('my-projects', 25);
|
198 |
|
199 |
$('.show-extra').click(function(e) { |
200 |
e.preventDefault(); |
201 |
$(this).parents('.bg-wrap').find('.extra').slideToggle(600); |
202 |
}); |
203 |
$('.hide-extra').click(function(e) { |
204 |
e.preventDefault(); |
205 |
$(this).parents('.bg-wrap').find('.extra').slideUp(600); |
206 |
}); |
207 |
|
208 |
$('.box-more p').click(function(e) { |
209 |
$(this).siblings('.clearfix').toggle('slow'); |
210 |
$(this).parents('.box-more').toggleClass('border'); |
211 |
}); |
212 |
|
213 |
var fixTopMessageHeight = function() { |
214 |
var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom')); |
215 |
$('.mainlogo').css('marginTop','-'+topMargin+'px'); |
216 |
} |
217 |
|
218 |
if ($('.mainlogo img').length > 0) { |
219 |
$('.mainlogo img').bind('load', fixTopMessageHeight) |
220 |
} else {
|
221 |
fixTopMessageHeight(); |
222 |
} |
223 |
|
224 |
$('.top-msg a.close').click(function(e) { |
225 |
e.preventDefault(); |
226 |
$('.top-msg').animate({ |
227 |
paddingTop:'0', |
228 |
paddingBottom:'0', |
229 |
height:'0' |
230 |
}, 1000, function (){ |
231 |
$('.top-msg').removeClass('active') |
232 |
}); |
233 |
$('.mainlogo').animate({ |
234 |
marginTop:'0' |
235 |
}, 1000, function (){ |
236 |
//todo
|
237 |
}); |
238 |
}); |
239 |
|
240 |
|
241 |
$('select.dropkicked').dropkick({ |
242 |
change: function (value, label) { |
243 |
$(this).parents('form').submit(); |
244 |
|
245 |
} |
246 |
}); |
247 |
|
248 |
$('.with-info select').attr('tabindex','1'); |
249 |
$('.with-info select').dropkick(); |
250 |
|
251 |
$('.top-msg .success').parents('.top-msg').addClass('success'); |
252 |
$('.top-msg .error').parents('.top-msg').addClass('error'); |
253 |
$('.top-msg .warning').parents('.top-msg').addClass('warning'); |
254 |
$('.top-msg .info').parents('.top-msg').addClass('info'); |
255 |
|
256 |
// clouds homepage animation
|
257 |
$('#animation a').hover( |
258 |
function () {
|
259 |
|
260 |
$(this).animate({ |
261 |
top: '+=-10' |
262 |
}, 600, function() { |
263 |
if ($(this).find('img').attr('src').indexOf("_top") == -1) { |
264 |
var src = $(this).find('img').attr('src').replace('.png', '_top.png') |
265 |
$(this).find('img').attr("src", src); |
266 |
} |
267 |
|
268 |
}); |
269 |
$(this).siblings('p').find('img').animate({ |
270 |
width: '60%' |
271 |
}, 600);
|
272 |
}, |
273 |
function () {
|
274 |
|
275 |
$(this).animate({top: '0'}, 600, function() { |
276 |
var src = $(this).find('img').attr('src').replace('_top.png', '.png') |
277 |
$(this).find('img').attr("src", src); |
278 |
}); |
279 |
$(this).siblings('p').find('img').animate({ |
280 |
width: '65%' |
281 |
},600);
|
282 |
} |
283 |
); |
284 |
|
285 |
|
286 |
|
287 |
|
288 |
$(function() { |
289 |
$( "#id_start_date" ).datepicker({ |
290 |
minDate: 0, |
291 |
defaultDate: "+0", |
292 |
dateFormat: "yy-mm-dd", |
293 |
onSelect: function( selectedDate ) { |
294 |
$( "#id_end_date" ).datepicker( "option", "minDate", selectedDate ); |
295 |
} |
296 |
}); |
297 |
|
298 |
$( "#id_end_date" ).datepicker({ |
299 |
defaultDate: "+3w", |
300 |
dateFormat: "yy-mm-dd", |
301 |
onSelect: function( selectedDate ) { |
302 |
$( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate ); |
303 |
} |
304 |
}); |
305 |
}); |
306 |
|
307 |
|
308 |
|
309 |
$('table .more-info').click(function(e){ |
310 |
e.preventDefault(); |
311 |
$(this).toggleClass('open'); |
312 |
if ($(this).hasClass('open')){ |
313 |
$(this).html('- less info ') |
314 |
} else {
|
315 |
$(this).html('+ more info ') |
316 |
} |
317 |
$(this).parents('tr').next('tr').toggle(); |
318 |
|
319 |
}); |
320 |
|
321 |
$('.projects .details .edit').click( function(e){ |
322 |
e.preventDefault(); |
323 |
$(this).parents('.details').children('.data').hide(); |
324 |
$(this).parents('.details').children('.editable').slideDown(500, 'linear'); |
325 |
$(this).hide(); |
326 |
}); |
327 |
|
328 |
$('.editable .form-row').each(function() { |
329 |
if ( $(this).hasClass('with-errors') ){ |
330 |
$('.editable').show(); |
331 |
$('.projects .details a.edit, .projects .details .data').hide(); |
332 |
|
333 |
} |
334 |
}); |
335 |
|
336 |
|
337 |
|
338 |
|
339 |
|
340 |
$("input.leave, input.join").click(function (e) { |
341 |
e.preventDefault(); |
342 |
var form = $(this).parents('form'); |
343 |
var dialog = $(this).parents('.msg-wrap').find('.dialog'); |
344 |
|
345 |
$('.dialog').hide(); |
346 |
if ($(this).parents('.form-actions').hasClass('inactive')) { |
347 |
return false; |
348 |
} |
349 |
$(this).parents('.msg-wrap').find('.dialog').show(); |
350 |
var offset = dialog.offset();
|
351 |
|
352 |
if (offset.left <= 10) { |
353 |
dialog.css({'left': '10px'}) |
354 |
} |
355 |
if (offset.top <= 10) { |
356 |
dialog.css({'top': '10px'}) |
357 |
} |
358 |
|
359 |
if (dialog.find('textarea').length > 0) { |
360 |
dialog.find('textarea').val(''); |
361 |
dialog.find('textarea').focus();
|
362 |
} |
363 |
|
364 |
return false; |
365 |
|
366 |
}); |
367 |
|
368 |
$('.msg-wrap .no').click( function(e){ |
369 |
e.preventDefault(); |
370 |
$(this).parents('.dialog').hide(); |
371 |
e.stopPropagation(); |
372 |
}) |
373 |
|
374 |
$(document).click(function() { |
375 |
$('.msg-wrap .dialog').hide(); |
376 |
}); |
377 |
|
378 |
|
379 |
$('.msg-wrap .yes').click( function(e){ |
380 |
e.preventDefault(); |
381 |
var dialog = $(this).parents('.msg-wrap').find('.dialog'); |
382 |
var form = $(this).parents('.msg-wrap').find('form'); |
383 |
var fields = dialog.find('input, textarea') |
384 |
|
385 |
var toremove = [];
|
386 |
fields.each(function(){
|
387 |
var f = $(this).clone(); |
388 |
f.hide(); |
389 |
form.append(f); |
390 |
f.val($(this).val()); |
391 |
toremove.push(f); |
392 |
}); |
393 |
|
394 |
form.submit(); |
395 |
}) |
396 |
|
397 |
$('.hidden-submit input[readonly!="True"]').focus(function () { |
398 |
$('.hidden-submit .form-row.submit').slideDown(500); |
399 |
}); |
400 |
|
401 |
var innerInputs = $('form.innerlabels input[type="text"], form.innerlabels input[type="password"]'); |
402 |
_.each(innerInputs, function(val, key, list){
|
403 |
var txt = $(val).siblings('label').text(); |
404 |
$(val).attr('placeholder',txt); |
405 |
}); |
406 |
|
407 |
$(function() { |
408 |
$('input, textarea').placeholder(); |
409 |
}); |
410 |
|
411 |
|
412 |
// landing-page initialization
|
413 |
if ($('.landing-page').length > 0) { |
414 |
var wrapper = $(".landing-page"); |
415 |
var services = wrapper.find(".landing-service"); |
416 |
services.hover(function(e) {
|
417 |
var cls, service_cls, cloudbar_li, offset, positionX;
|
418 |
cls = _.filter($(this).attr("class").split(" "), function(cls) { |
419 |
return cls.indexOf("service-") == 0 |
420 |
}); |
421 |
if (!cls.length) { return } |
422 |
service_cls = $.trim(cls[0]); |
423 |
extra = 0;
|
424 |
if (service_cls == 'service-astakos') { |
425 |
cloudbar_li = $(".cloudbar .profile"); |
426 |
extra = 50;
|
427 |
} else {
|
428 |
cloudbar_li = $(".cloudbar ul.services li." + service_cls); |
429 |
if (cloudbar_li.index() != 0) { |
430 |
extra = 20;
|
431 |
} |
432 |
} |
433 |
offset = cloudbar_li.offset(); |
434 |
if (!offset) { return } |
435 |
positionX = offset.left + extra; |
436 |
$('#hand').css('left',positionX + 'px'); |
437 |
$('#hand').show(); |
438 |
}, function (e) {
|
439 |
$('#hand').hide(); |
440 |
}); |
441 |
} |
442 |
|
443 |
$('.pagination a.disabled').click(function(e){ |
444 |
e.preventDefault(); |
445 |
}); |
446 |
|
447 |
// fix for recaptcha fields
|
448 |
$('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide(); |
449 |
|
450 |
check_form_actions_inactive(); |
451 |
|
452 |
|
453 |
|
454 |
$('#members-table td.email').click(function(e){ |
455 |
var that = $(this).parent('tr').find('.check').find('input[type="checkbox"]') |
456 |
if(that.is(":checked")){ |
457 |
that.removeAttr('checked');
|
458 |
} else {
|
459 |
that.attr('checked', 'checked'); |
460 |
} |
461 |
check_form_actions_inactive(); |
462 |
|
463 |
}) |
464 |
|
465 |
$('#members-table tr th.check input').change(function(e){ |
466 |
if($(this).is(":checked")){ |
467 |
$('#members-table tbody td.check input').attr('checked', 'checked'); |
468 |
} else {
|
469 |
$('#members-table tbody td.check input').removeAttr('checked'); |
470 |
} |
471 |
}); |
472 |
|
473 |
$('#members-table tr .check input').click(function(e){ |
474 |
check_form_actions_inactive() |
475 |
}); |
476 |
|
477 |
$('.renew-token a.confirm').click(function(e){ |
478 |
e.preventDefault(); |
479 |
e.stopPropagation(); |
480 |
renewToken(); |
481 |
}); |
482 |
|
483 |
$('.renew-token a.do').click(function(e){ |
484 |
e.preventDefault(); |
485 |
e.stopPropagation(); |
486 |
var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')]; |
487 |
_.each(els, function (el) { el.show();})
|
488 |
}) |
489 |
|
490 |
$('.renew-token a.close').click(function(e){ |
491 |
e.preventDefault(); |
492 |
e.stopPropagation(); |
493 |
var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')]; |
494 |
_.each(els, function (el) { el.hide();})
|
495 |
$('.renew-token a.do').show(); |
496 |
}) |
497 |
|
498 |
tableSort($('.projects-intro').siblings('table#projects-list'), 10, true ); |
499 |
tableSort($('.search-projects').siblings('table#projects-list'), 25, true); |
500 |
tableSort($('#members-table'), 3, true); |
501 |
|
502 |
|
503 |
}); |
504 |
|
505 |
|
506 |
$(window).resize(function() { |
507 |
|
508 |
setContainerMinHeight('.container .wrapper');
|
509 |
|
510 |
}); |