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