Statistics
| Branch: | Tag: | Revision:

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

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

    
163
                });
164
        $(this).siblings('p').find('img').animate({
165
          width: '60%'       
166
        }, 600);
167
      }, 
168
      function () {
169

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

    
232

    
233

    
234
 
235
        $("input.leave, input.join").click(function (e) {
236
        e.preventDefault();
237
        var form = $(this).parents('form');
238
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
239

    
240
                $('.dialog').hide();
241
    if ($(this).parents('.form-actions').hasClass('inactive')) {
242
      return false;
243
    }
244
                $(this).parents('.msg-wrap').find('.dialog').show();
245
        var offset = dialog.offset();
246

    
247
        if (offset.left <= 10) {
248
          dialog.css({'left': '10px'})
249
        }
250
        if (offset.top <= 10) {
251
          dialog.css({'top': '10px'})
252
        }
253

    
254
        if (dialog.find('textarea').length > 0) {
255
          dialog.find('textarea').val('');
256
          dialog.find('textarea').focus();
257
        }
258

    
259
                return false;      
260
                
261
    });
262
    
263
     $('.msg-wrap .no').click( function(e){
264
                    e.preventDefault();
265
                    $(this).parents('.dialog').hide();
266
        e.stopPropagation();
267
            })
268

    
269
      $(document).click(function() {
270
        $('.msg-wrap .dialog').hide();
271
      });
272

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

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

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

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

    
387
})
388

    
389

    
390

    
391

    
392
$('#members-table tr th.check input').click(function(e){
393
  if($(this).is(":checked")){
394
    $('#members-table tbody td.check input').attr('checked', 'checked');
395
  } else {
396
    $('#members-table tbody td.check input').removeAttr('checked');
397
  } 
398
});
399

    
400
$('#members-table tr .check input').click(function(e){
401
  check_form_actions_inactive()
402
});
403

    
404
/* end of project members page js */
405

    
406

    
407

    
408
            
409
});
410
        
411
$(window).resize(function() {
412
    
413
   setContainerMinHeight('.container .wrapper');
414
    
415

    
416
});