Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (9.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
        $("input.leave, input.join").click(function (e) {
233
        e.preventDefault();
234
        var form = $(this).parents('form');
235
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
236

    
237
                $('.dialog').hide();
238
                $(this).parents('.msg-wrap').find('.dialog').show();
239
        var offset = dialog.offset();
240

    
241
        if (offset.left <= 10) {
242
          dialog.css({'left': '10px'})
243
        }
244
        if (offset.top <= 10) {
245
          dialog.css({'top': '10px'})
246
        }
247

    
248
        if (dialog.find('textarea').length > 0) {
249
          dialog.find('textarea').val('');
250
          dialog.find('textarea').focus();
251
        }
252

    
253
                return false;      
254
                
255
    });
256
    
257
     $('.msg-wrap .no').click( function(e){
258
                e.preventDefault();
259
                $(this).parents('.dialog').hide();
260
        })
261
    
262
    $('.msg-wrap .yes').click( function(e){
263
                e.preventDefault();
264
        var dialog = $(this).parents('.msg-wrap').find('.dialog');
265
        var form = $(this).parents('.msg-wrap').find('form');
266
        var fields = dialog.find('input, textarea')
267
        
268
        var toremove = [];
269
        fields.each(function(){
270
          var f = $(this).clone();
271
          f.hide();
272
          form.append(f);
273
          f.val($(this).val());
274
          toremove.push(f);
275
        });
276
        
277
        form.submit();
278
        })
279
    
280
    $('.hidden-submit input[readonly!="True"]').focus(function () {
281
         $('.hidden-submit .form-row.submit').slideDown(500);
282
    });
283
    
284
    
285
    
286
   
287
      
288
    
289
    setTimeout(function() {
290
      if ($('input#id_username').val()){ 
291
              $('input#id_username').siblings('label').css('opacity','0');
292
      };
293
      if ($('input#id_password').val()){ 
294
              $('input#id_password').siblings('label').css('opacity','0');
295
      }
296
        }, 100);
297
        
298
        
299
        
300
        
301
        $('.landing-page .cms').hover(
302
      function () {
303
               el = $('.cloudbar ul.services li').first();
304
               var offset = el.offset();
305
               positionX = offset.left;
306
               $('#hand').css('left',positionX);                   
307
         $('#hand').show();
308
      }, 
309
      function () {
310
              $('#hand').hide();
311
    
312
    });  
313
    
314
    $('.landing-page .pithos').hover(
315
      function () {
316
               el = $('.cloudbar ul.services li:nth-child(3)');
317
               var offset = el.offset();
318
               positionX = offset.left;
319
               left = parseInt(positionX) +20;
320
               $('#hand').css('left',left+'px');                   
321
         $('#hand').show();
322
      }, 
323
      function () {
324
              $('#hand').hide();
325
    
326
    });  
327
    
328
    $('.landing-page .cyclades').hover(
329
      function () {
330
               el = $('.cloudbar ul.services li:nth-child(2)').first();
331
               var offset = el.offset();
332
               positionX = offset.left;
333
               left = parseInt(positionX) +20;
334
               $('#hand').css('left',left+'px');                   
335
         $('#hand').show();
336
      }, 
337
      function () {
338
              $('#hand').hide();
339
    
340
    });  
341
    
342
    
343
    $('.landing-page .dashboard').hover(
344
      function () {
345
               el = $('.cloudbar .profile');
346
               var offset = el.offset();
347
               positionX = offset.left +50;
348
               $('#hand').css('left',positionX);                   
349
         $('#hand').show();
350
      }, 
351
      function () {
352
              $('#hand').hide();
353
    
354
    });  
355
    
356
    $('.pagination a.disabled').click(function(e){
357
            e.preventDefault();
358
    });
359
          
360
        // fix for recaptcha fields
361
        $('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide();          
362
     
363
         
364
            
365
});
366
        
367
$(window).resize(function() {
368
    
369
   setContainerMinHeight('.container .wrapper');
370
    
371

    
372
});