Statistics
| Branch: | Tag: | Revision:

root / snf-astakos-app / astakos / im / static / im / js / common.js @ dc868498

History | View | Annotate | Download (11.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
 
88
$(document).ready(function() {
89
        
90
    /* api access */
91
    $(".token-view .detail").click(function() { 
92
      $(this).find("input").select();
93
    });
94
            
95
         
96
    setContainerMinHeight('.container .wrapper');
97
    //tableFixedCols('my-projects', 25);
98
        
99
    $('.show-extra').click(function(e) {
100
        e.preventDefault();
101
        $(this).parents('.bg-wrap').find('.extra').slideToggle(600);
102
    });
103
    $('.hide-extra').click(function(e) {
104
        e.preventDefault();
105
        $(this).parents('.bg-wrap').find('.extra').slideUp(600);
106
    });
107
    
108
    $('.box-more p').click(function(e) {
109
        $(this).siblings('.clearfix').toggle('slow');
110
        $(this).parents('.box-more').toggleClass('border');
111
    });
112
        
113
        var fixTopMessageHeight = function() {
114
                var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));
115
                $('.mainlogo').css('marginTop','-'+topMargin+'px');
116
        }
117
        
118
        if ($('.mainlogo img').length > 0) {
119
                $('.mainlogo img').bind('load', fixTopMessageHeight)
120
        } else {
121
                fixTopMessageHeight();
122
        }
123
        
124
        $('.top-msg a.close').click(function(e) {
125
                e.preventDefault();
126
        $('.top-msg').animate({
127
            paddingTop:'0',
128
            paddingBottom:'0',
129
            height:'0'
130
        }, 1000, function (){
131
             $('.top-msg').removeClass('active')
132
        });
133
        $('.mainlogo').animate({
134
            marginTop:'0'
135
        }, 1000, function (){
136
             //todo
137
        });
138
    });        
139
    
140
     
141
        $('select.dropkicked').dropkick({
142
                change: function (value, label) {
143
                    $(this).parents('form').submit();
144
                    
145
                }
146
        });
147
        
148
        $('.with-info select').attr('tabindex','1');
149
    $('.with-info select').dropkick();
150
    
151
    $('.top-msg .success').parents('.top-msg').addClass('success');
152
    $('.top-msg .error').parents('.top-msg').addClass('error');
153
    $('.top-msg .warning').parents('.top-msg').addClass('warning');
154
    $('.top-msg .info').parents('.top-msg').addClass('info');
155
    
156
    // clouds homepage animation
157
    $('#animation a').hover(
158
      function () {
159
              
160
        $(this).animate({
161
           top: '+=-10'   
162
           }, 600, function() {
163
                   if ($(this).find('img').attr('src').indexOf("_top") == -1) {
164
                           var src = $(this).find('img').attr('src').replace('.png', '_top.png')
165
                        $(this).find('img').attr("src", src);
166
                   }
167

    
168
                });
169
        $(this).siblings('p').find('img').animate({
170
          width: '60%'       
171
        }, 600);
172
      }, 
173
      function () {
174

    
175
        $(this).animate({top: '0'}, 600, function() {
176
                var src = $(this).find('img').attr('src').replace('_top.png', '.png')
177
                       $(this).find('img').attr("src", src);
178
                });
179
        $(this).siblings('p').find('img').animate({
180
          width: '65%'       
181
        },600);
182
      }
183
    );
184
    
185
    
186
    
187
    
188
    $(function() {                 
189
                $( "#id_start_date" ).datepicker({
190
                        minDate: 0,
191
                        defaultDate: "+0", 
192
            dateFormat: "yy-mm-dd",
193
            onSelect: function( selectedDate ) {
194
                $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );
195
            }
196
        });
197
        
198
        $( "#id_end_date" ).datepicker({
199
                defaultDate: "+3w", 
200
            dateFormat: "yy-mm-dd",
201
            onSelect: function( selectedDate ) {
202
                $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );
203
            }
204
        });
205
        });
206
        
207
         
208
        
209
        $('table .more-info').click(function(e){
210
                e.preventDefault();
211
                $(this).toggleClass('open');
212
                if ($(this).hasClass('open')){
213
                        $(this).html('- less info ')
214
                } else {
215
                        $(this).html('+ more info ')
216
                }
217
                $(this).parents('tr').next('tr').toggle();
218
                 
219
        });
220
        
221
        $('.projects .details .edit').click( function(e){
222
                e.preventDefault();
223
                $(this).parents('.details').children('.data').hide();
224
                $(this).parents('.details').children('.editable').slideDown(500, 'linear');
225
                $(this).hide();
226
        });
227
        
228
        $('.editable .form-row').each(function() {
229
                        if ( $(this).hasClass('with-errors') ){
230
                                $('.editable').show();
231
                                $('.projects .details a.edit, .projects .details .data').hide();
232
                                
233
                        }
234
                });
235
        
236

    
237

    
238

    
239
 
240
        $("input.leave, input.join").click(function (e) {
241
        e.preventDefault();
242
        var form = $(this).parents('form');
243
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
244

    
245
                $('.dialog').hide();
246
    if ($(this).parents('.form-actions').hasClass('inactive')) {
247
      return false;
248
    }
249
                $(this).parents('.msg-wrap').find('.dialog').show();
250
        var offset = dialog.offset();
251

    
252
        if (offset.left <= 10) {
253
          dialog.css({'left': '10px'})
254
        }
255
        if (offset.top <= 10) {
256
          dialog.css({'top': '10px'})
257
        }
258

    
259
        if (dialog.find('textarea').length > 0) {
260
          dialog.find('textarea').val('');
261
          dialog.find('textarea').focus();
262
        }
263

    
264
                return false;      
265
                
266
    });
267
    
268
     $('.msg-wrap .no').click( function(e){
269
                    e.preventDefault();
270
                    $(this).parents('.dialog').hide();
271
        e.stopPropagation();
272
            })
273

    
274
      $(document).click(function() {
275
        $('.msg-wrap .dialog').hide();
276
      });
277

    
278
     
279
    $('.msg-wrap .yes').click( function(e){
280
                e.preventDefault();
281
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
282
        var form = $(this).parents('.msg-wrap').find('form');
283
        var fields = dialog.find('input, textarea')
284
        
285
        var toremove = [];
286
        fields.each(function(){
287
          var f = $(this).clone();
288
          f.hide();
289
          form.append(f);
290
          f.val($(this).val());
291
          toremove.push(f);
292
        });
293
        
294
        form.submit();
295
        })
296
    
297
    $('.hidden-submit input[readonly!="True"]').focus(function () {
298
         $('.hidden-submit .form-row.submit').slideDown(500);
299
    });
300
    
301
    
302
    
303
   
304
      
305
    
306
    setTimeout(function() {
307
      if ($('input#id_username').val()){ 
308
              $('input#id_username').siblings('label').css('opacity','0');
309
      };
310
      if ($('input#id_password').val()){ 
311
              $('input#id_password').siblings('label').css('opacity','0');
312
      }
313
        }, 100);
314
        
315
        
316
        
317
        // landing-page initialization
318
    if ($('.landing-page').length > 0) {
319
      var wrapper = $(".landing-page");
320
      var services = wrapper.find(".landing-service");
321
      services.hover(function(e) {
322
        var cls, service_cls, cloudbar_li, offset, positionX;
323
        cls = _.filter($(this).attr("class").split(" "), function(cls) {
324
          return cls.indexOf("service-") == 0
325
        });
326
        if (!cls.length) { return }
327
        service_cls = $.trim(cls[0]);
328
        extra = 0;
329
        if (service_cls == 'service-astakos') {
330
          cloudbar_li = $(".cloudbar .profile");
331
          extra = 50;
332
        } else {
333
          cloudbar_li = $(".cloudbar ul.services li." + service_cls);
334
          if (cloudbar_li.index() != 0) {
335
            extra = 20;
336
          }
337
        }
338
              offset = cloudbar_li.offset();
339
        if (!offset) { return }
340
              positionX = offset.left + extra;
341
              $('#hand').css('left',positionX + 'px');
342
        $('#hand').show();
343
      }, function (e) {
344
              $('#hand').hide();
345
      });
346
    }
347

    
348
    $('.pagination a.disabled').click(function(e){
349
            e.preventDefault();
350
    });
351
          
352
        // fix for recaptcha fields
353
        $('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide();          
354
   
355
   check_form_actions_inactive();  
356
/* project members page js */         
357
function check_form_actions_inactive(){
358
   if ( $('#members-table tbody td.check input:checked').length >0 ) {
359
    $('.projects .form-actions').removeClass('inactive');
360
  } else {
361
    $('.projects .form-actions').addClass('inactive');
362
  }
363

    
364
  // updating form data
365
  var forms = $("form.link-like:has('input.members-batch-action')");
366
  forms.each(function(index, form){
367
    var member_ids, checked;
368
    form = $(form);
369
    form.find("input.member-option").remove();
370
    checked = $('#members-table tbody td.check input:checked');
371
    member_ids = _.map(checked, function(el) {
372
      return parseInt($(el).val());
373
    });
374
    
375
    _.each(member_ids, function(id) {
376
      var newel;
377
      newel = $("<input name='members' class='member-option' type='hidden' value='"+id+"'>");
378
      form.append(newel);
379
    });
380
  })
381
}
382

    
383
$('#members-table td.email').click(function(e){
384
  var that = $(this).parent('tr').find('.check').find('input[type="checkbox"]')
385
  if(that.is(":checked")){
386
    that.removeAttr('checked');
387
  } else {
388
    that.attr('checked', 'checked');
389
  }
390
  check_form_actions_inactive();
391

    
392
})
393

    
394

    
395

    
396

    
397
$('#members-table tr th.check input').click(function(e){
398
  if($(this).is(":checked")){
399
    $('#members-table tbody td.check input').attr('checked', 'checked');
400
  } else {
401
    $('#members-table tbody td.check input').removeAttr('checked');
402
  } 
403
});
404

    
405
$('#members-table tr .check input').click(function(e){
406
  check_form_actions_inactive()
407
});
408

    
409
/* end of project members page js */
410

    
411
  $('.renew-token a.do').click(function(e){
412
    e.preventDefault();
413
    var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')];
414
    _.each(els, function (el) { el.show();})
415
  })
416

    
417
  $('.renew-token a.close').click(function(e){
418
    e.preventDefault();
419
    var els = [$(".renew-token .sub"),$('.renew-token .confirm'), $('.renew-token .close')];
420
    _.each(els, function (el) { el.hide();})
421
  })
422

    
423

    
424
});
425
        
426
$(window).resize(function() {
427
    
428
   setContainerMinHeight('.container .wrapper');
429
    
430

    
431
});