Statistics
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (10.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

    
27
//equal heights
28
 
29
(function($) {
30
        $.fn.equalHeights = function(minHeight, maxHeight) {
31
                tallest = (minHeight) ? minHeight : 0;
32
                this.each(function() {
33
                        if($(this).height() > tallest) {
34
                                tallest = $(this).height();
35
                        }
36
                });
37
                if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
38
                return this.each(function() {
39
                        $(this).height(tallest);
40
                });
41
        }
42
})(jQuery);
43

    
44

    
45

    
46
// fix for iPhone - iPad orientation bug 
47
var metas = document.getElementsByTagName('meta');
48
function resetViewport() {
49
    var i;
50
    if (navigator.userAgent.match(/iPhone/i)) {
51
                  for (i=0; i<metas.length; i++) {
52
                    if (metas[i].name == "viewport") {
53
                              metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
54
                    }
55
                  }
56
          }
57
}
58
resetViewport();
59
    
60
window.onorientationchange = function() {
61
    resetViewport();
62
};
63
    
64
function gestureStart() {
65
  for (i=0; i<metas.length; i++) {
66
    if (metas[i].name == "viewport") {
67
      metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
68
    }
69
  }
70
}
71

    
72
if (navigator.userAgent.match(/iPhone/i)) {
73
        document.addEventListener("gesturestart", gestureStart, false);
74
}
75
//end of fix
76

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

    
152
                });
153
        $(this).siblings('p').find('img').animate({
154
          width: '60%'       
155
        }, 600);
156
      }, 
157
      function () {
158

    
159
        $(this).animate({top: '0'}, 600, function() {
160
                var src = $(this).find('img').attr('src').replace('_top.png', '.png')
161
                       $(this).find('img').attr("src", src);
162
                });
163
        $(this).siblings('p').find('img').animate({
164
          width: '65%'       
165
        },600);
166
      }
167
    );
168
    
169
    
170
    
171
    
172
    $(function() {                 
173
                $( "#id_start_date" ).datepicker({
174
                        minDate: 0,
175
                        defaultDate: "+0", 
176
            dateFormat: "yy-mm-dd",
177
            onSelect: function( selectedDate ) {
178
                $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );
179
            }
180
        });
181
        
182
        $( "#id_end_date" ).datepicker({
183
                defaultDate: "+3w", 
184
            dateFormat: "yy-mm-dd",
185
            onSelect: function( selectedDate ) {
186
                $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );
187
            }
188
        });
189
        });
190
        
191
         
192
        
193
        $('table .more-info').click(function(e){
194
                e.preventDefault();
195
                $(this).toggleClass('open');
196
                if ($(this).hasClass('open')){
197
                        $(this).html('- less info ')
198
                } else {
199
                        $(this).html('+ more info ')
200
                }
201
                $(this).parents('tr').next('tr').toggle();
202
                 
203
        });
204
        
205
        $('.projects .details .edit').click( function(e){
206
                e.preventDefault();
207
                $(this).parents('.details').children('.data').hide();
208
                $(this).parents('.details').children('.editable').slideDown(500, 'linear');
209
                $(this).hide();
210
        });
211
        
212
        $('.editable .form-row').each(function() {
213
                        if ( $(this).hasClass('with-errors') ){
214
                                $('.editable').show();
215
                                $('.projects .details a.edit, .projects .details .data').hide();
216
                                
217
                        }
218
                });
219
        
220
 
221
        $("input.leave, input.join").click(function () {
222
                $('dialog').hide();
223
                $(this).parents('.msg-wrap').find('.dialog').show();
224
                return false;      
225
                
226
    });
227
    
228
     $('.msg-wrap .no').click( function(e){
229
                e.preventDefault();
230
                $(this).parents('.dialog').hide();
231
        })
232
    
233
    $('.msg-wrap .yes').click( function(e){
234
                e.preventDefault();
235
                $(this).parents('.dialog').siblings('form').submit();
236
        })
237
    
238
    $('.hidden-submit input[readonly!="True"]').focus(function () {
239
         $('.hidden-submit .form-row.submit').slideDown(500);
240
    });
241
    
242
    
243
    
244
    $('.auth_methods .canremove').click( function(e) {
245
            e.preventDefault(e);
246
            $(this).addClass('remove');
247
            $(this).siblings('.dialog-wrap').slideDown('slow');
248
    })  
249
    
250
    $('.auth_methods .no').click( function(e) {
251
            e.preventDefault(e);
252
            $(this).parents('.dialog-wrap').siblings('.canremove').removeClass('remove');
253
            $(this).parents('.dialog-wrap').slideUp('slow');
254
    })  
255
      
256
    
257
    setTimeout(function() {
258
      if ($('input#id_username').val()){ 
259
              $('input#id_username').siblings('label').css('opacity','0');
260
      };
261
      if ($('input#id_password').val()){ 
262
              $('input#id_password').siblings('label').css('opacity','0');
263
      }
264
        }, 100);
265
        
266
        
267
        /* complex form js */
268
        
269
        // Intresting divs
270
        
271
        emailDiv = $('#id_email').parents('.form-row');
272
        newEmailDiv = $('#id_new_email_address').parents('.form-row');
273
        oldPasswordDiv = $('#id_old_password').parents('.form-row');
274
        newPassword1Div = $('#id_new_password1').parents('.form-row');
275
        newPassword2Div = $('#id_new_password2').parents('.form-row');
276
        emailCheck = $('#id_change_email').parents('.form-row');
277
        passwordCheck = $('#id_change_password').parents('.form-row');
278
        authTokenDiv = $('#id_auth_token').parents('.form-row');
279
        
280
        if ( newEmailDiv.length>0  ){ 
281
                emailDiv.addClass('form-following');
282
        }
283
        
284
        oldPasswordDiv.addClass('form-following');
285
        
286
        
287
        // Intresting img spans
288
        
289
        emailDiv.find('span.extra-img').attr('id','email-span');
290
        oldPasswordDiv.find('span.extra-img').attr('id','password-span');
291
        authTokenDiv.find('span.extra-img').attr('id','token-span');
292
        // Default hidden fields
293
        
294
        newEmailDiv.hide();
295
        newPassword1Div.hide();
296
        newPassword2Div.hide();
297
        emailCheck.hide();
298
        passwordCheck.hide();
299
        
300
        
301
        
302
        newEmailDiv.addClass('email-span');
303
        newPassword1Div.addClass('password-span');
304
        newPassword2Div.addClass('password-span');
305
        
306
        // If errors show fields
307
        
308
        
309
        if ($('input#id_change_password:checkbox').attr('checked')) {
310
                oldPasswordDiv.find('input').focus();
311
                newPassword1Div.show();
312
                newPassword2Div.show();
313
                $('.form-following #password-span').parents('.form-row').addClass('open');
314
        }; 
315
        
316
        
317
        
318
        if ($('input#id_change_password:checkbox').attr('checked')) {
319
                newEmailDiv.show();
320
                
321
                $('.form-following #email-span').parents('.form-row').addClass('open');
322
        }; 
323
        
324
        // Email, Password forms
325
        
326
        $('.form-following .extra-img').click(function(e){
327
                
328
                $(this).parents('.form-row').toggleClass('open');
329
                id = $(this).attr('id');
330
                $('.form-row').each(function() {
331
                        if( $(this).hasClass(id) ) {
332
                                $(this).toggle();
333
                        }
334
                }); 
335
         
336
                 
337
                 if ( !($(this).parents('.form-row').hasClass('open')) ){
338
                         $('.form-row').each(function() {
339
                                if( $(this).hasClass(id) ) {
340
                                        console.info($(this).find('input[type="text"]'));
341
                                        $(this).find('input').val('');
342
                                        $(this).removeClass('with-errors');
343
                                        $(this).find('.form-error').hide();
344
                                }
345
                        }); 
346
                 }         else {
347
                         // focus on first input
348
                         if ( id == 'email-span') { newEmailDiv.find('input').focus(); } 
349
                         if ( id == 'password-span') { oldPasswordDiv.find('input').focus(); }
350
                 }
351
        });
352
        
353
        //  check uncheck checkbox
354
        $('#email-span').click(function(){ 
355
       var $checkbox = $('input#id_change_email:checkbox');
356
       $checkbox.attr('checked', !$checkbox.attr('checked'));
357
         });
358
        
359
        //  check uncheck checkbox
360
        $('#password-span').click(function(){ 
361
       var $checkbox = $('input#id_change_password:checkbox');
362
       $checkbox.attr('checked', !$checkbox.attr('checked'));
363
         });
364
        
365
        // refresh token
366
        authTokenDiv.addClass('refresh');
367
        $('#token-span').click(function(e){
368
                renewToken();
369
        })
370
        
371
        
372
        
373
        /* end of complex form js */
374
        
375
         
376
            
377
});
378
        
379
$(window).resize(function() {
380
    
381
   setContainerMinHeight('.container .wrapper');
382
    
383

    
384
});