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