Revision 98f71c73 cloudcms/static/cloudcms/js/common.js

b/cloudcms/static/cloudcms/js/common.js
1
function isIpadIphone(){
2
  var flag = false;
3
    var isiPhone = navigator.userAgent.toLowerCase().indexOf("iphone");
4
    var isiPad = navigator.userAgent.toLowerCase().indexOf("ipad");
5
    if(isiPhone > -1) { flag = true; }
6
    if(isiPad > -1) { flag = true; }
7
    return flag;
8
}
9

  
10
function setContainerMinHeight( applicableDiv){
11
	
12
    if ( $(applicableDiv).length > 0 ) {
13
        //var h = $('.header').height(); div.header is not found 
14
        var f = $('.footer').height();
15
        var w = $(window).height();
16
        var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) );
17
        var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", "")));
18

  
19
        var c = w - ( f+pTop+pBottom+36);//36 is header's height.
20
        $(applicableDiv).css('min-height', c);
21
    }    
22

  
23
}
24

  
25
function tableFixedCols(table, firstColWidth ){
26
	ColsNum = $('table th').size();
27
	var ColWidth = parseFloat( (100 - firstColWidth)/ColsNum ).toFixed(0);
28
	var ColWidthPercentage = ColWidth+'%';
29
	var firstColWidthPercentage = firstColWidth+'%';
30
	$('.projects table th, .projects  table td').attr('width',ColWidthPercentage ); 
31
	$('.projects table tr td:first-child,.projects  table tr th:first-child').attr('width',firstColWidthPercentage );
32
	
33
}
34

  
35
function addClassHover(hoverEl, applicableEl){ 
36
	$(hoverEl).hover(
37
      function () {
38
      	 
39
         $(applicableEl).addClass('red-border')
40
      }, 
41
      function () {
42
      	$(applicableEl).removeClass('red-border');
43
    
44
    });
45
}
46
//equal heights
47
 
48
(function($) {
49
	$.fn.equalHeights = function(minHeight, maxHeight) {
50
		tallest = (minHeight) ? minHeight : 0;
51
		this.each(function() {
52
			if($(this).height() > tallest) {
53
				tallest = $(this).height();
54
			}
55
		});
56
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
57
		return this.each(function() {
58
			$(this).height(tallest);
59
		});
60
	}
61
})(jQuery);
62

  
63

  
64

  
65
// fix for iPhone - iPad orientation bug 
66
var metas = document.getElementsByTagName('meta');
67
function resetViewport() {
68
    var i;
69
    if (navigator.userAgent.match(/iPhone/i)) {
70
  		for (i=0; i<metas.length; i++) {
71
    		if (metas[i].name == "viewport") {
72
      			metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
73
    		}
74
  		}
75
  	}
76
}
77
resetViewport();
78
    
79
window.onorientationchange = function() {
80
    resetViewport();
81
};
82
    
83
function gestureStart() {
84
  for (i=0; i<metas.length; i++) {
85
    if (metas[i].name == "viewport") {
86
      metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
87
    }
88
  }
89
}
90

  
91
if (navigator.userAgent.match(/iPhone/i)) {
92
	document.addEventListener("gesturestart", gestureStart, false);
93
}
94
//end of fix
95

  
96
  
97
$(document).ready(function() {
98
   
99

  
100

  
101
    setContainerMinHeight('.container .wrapper');
102
    tableFixedCols('my-projects', 25);
103
	
104
    $('.show-extra').click(function(e) {
105
        e.preventDefault();
106
        $(this).parents('.bg-wrap').find('.extra').slideToggle(600);
107
    });
108
    $('.hide-extra').click(function(e) {
109
        e.preventDefault();
110
        $(this).parents('.bg-wrap').find('.extra').slideUp(600);
111
    });
112
    
113
    $('.box-more p').click(function(e) {
114
        $(this).siblings('.clearfix').toggle('slow');
115
        $(this).parents('.box-more').toggleClass('border');
116
    });
117
	
118
	var fixTopMessageHeight = function() {
119
		var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));
120
		$('.mainlogo').css('marginTop','-'+topMargin+'px');
121
	}
122
	
123
  // Uncomment to hide logo upon top message appearance
124

  
125
	// if ($('.mainlogo img').length > 0) {
126
	// 	$('.mainlogo img').bind('load', fixTopMessageHeight)
127
	// } else {
128
	// 	fixTopMessageHeight();
129
	// }
130
	
131
	$('.top-msg a.close').click(function(e) {
132
		e.preventDefault();
133
        $('.top-msg').animate({
134
            paddingTop:'0',
135
            paddingBottom:'0',
136
            height:'0'
137
        }, 1000, function (){
138
             $('.top-msg').removeClass('active')
139
        });
140
        $('.mainlogo').animate({
141
            marginTop:'0'
142
        }, 1000, function (){
143
             //todo
144
        });
145
    });	
146
    
147
     
148
	$('select.dropkicked').dropkick({
149
		change: function (value, label) {
150
		    $(this).parents('form').submit();
151
		    
152
		}
153
	});
154
	
155
	$('.with-info select').attr('tabindex','1');
156
    $('.with-info select').dropkick();
157
    
158
    $('.top-msg .success').parents('.top-msg').addClass('success');
159
    $('.top-msg .error').parents('.top-msg').addClass('error');
160
    $('.top-msg .warning').parents('.top-msg').addClass('warning');
161
    $('.top-msg .info').parents('.top-msg').addClass('info');
162
    
163
    // clouds homepage animation
164
    $('#animation a').hover(
165
      function () {
166
      	
167
        $(this).animate({
168
           top: '+=-5'   
169
           }, 300, function() {
170
           	if ($(this).find('img').attr('src').indexOf("_top") == -1) {
171
           		var src = $(this).find('img').attr('src').replace('.png', '_top.png')
172
        		$(this).find('img').attr("src", src);
173
           	}
174

  
175
		});
176
        $(this).siblings('p').find('img').animate({
177
          width: '60%'       
178
        }, 300);
179
      }, 
180
      function () {
181

  
182
        $(this).animate({top: '0'}, 300, function() {
183
        	var src = $(this).find('img').attr('src').replace('_top.png', '.png')
184
       		$(this).find('img').attr("src", src);
185
		});
186
        $(this).siblings('p').find('img').animate({
187
          width: '65%'       
188
        },300);
189
      }
190
    );
191
    
192
    
193
    
194
    
195
    $(function() {		 
196
		$( "#id_start_date" ).datepicker({
197
			minDate: 0,
198
			defaultDate: "+0", 
199
            dateFormat: "yy-mm-dd",
200
            onSelect: function( selectedDate ) {
201
                $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );
202
            }
203
        });
204
        
205
        $( "#id_end_date" ).datepicker({
206
        	defaultDate: "+3w", 
207
            dateFormat: "yy-mm-dd",
208
            onSelect: function( selectedDate ) {
209
                $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );
210
            }
211
        });
212
	});
213
	
214
	 
215
	
216
	$('table .more-info').click(function(e){
217
		e.preventDefault();
218
		$(this).toggleClass('open');
219
		if ($(this).hasClass('open')){
220
			$(this).html('- less info ')
221
		} else {
222
			$(this).html('+ more info ')
223
		}
224
		$(this).parents('tr').next('tr').toggle();
225
		 
226
	});
227
	
228
	$('.projects .details .edit').click( function(e){
229
		e.preventDefault();
230
		$(this).parents('.details').children('.data').hide();
231
		$(this).parents('.details').children('.editable').slideDown(500, 'linear');
232
		$(this).hide();
233
	});
234
	
235
	$('.editable .form-row').each(function() {
236
			if ( $(this).hasClass('with-errors') ){
237
				$('.editable').show();
238
				$('.projects .details a.edit, .projects .details .data').hide();
239
				
240
			}
241
		});
242
	
243
 
244
	$("input.leave, input.join").click(function () {
245
		$('dialog').hide();
246
		$(this).parents('.msg-wrap').find('.dialog').show();
247
		return false;      
248
		
249
    });
250
    
251
     $('.msg-wrap .no').click( function(e){
252
		e.preventDefault();
253
		$(this).parents('.dialog').hide();
254
	})
255
    
256
    $('.msg-wrap .yes').click( function(e){
257
		e.preventDefault();
258
		$(this).parents('.dialog').siblings('form').submit();
259
	})
260
    
261
    $('.hidden-submit input[readonly!="True"]').focus(function () {
262
         $('.hidden-submit .form-row.submit').slideDown(500);
263
    });
264
    
265
    
266
    
267
   
268
      
269
    
270
    setTimeout(function() {
271
      if ($('input#id_username').val()){ 
272
      	$('input#id_username').siblings('label').css('opacity','0');
273
      };
274
      if ($('input#id_password').val()){ 
275
      	$('input#id_password').siblings('label').css('opacity','0');
276
      }
277
	}, 100);
278
	
279
	
280
	
281
	
282
	$('.landing-page .cms').hover(
283
      function () {
284
      	 el = $('.cloudbar ul.services li').first();
285
      	 var offset = el.offset();
286
      	 positionX = offset.left;
287
      	 $('#hand').css('left',positionX);  		 
288
         $('#hand').show();
289
      }, 
290
      function () {
291
      	$('#hand').hide();
292
    
293
    });  
294
    
295
    $('.landing-page .pithos').hover(
296
      function () {
297
      	 el = $('.cloudbar ul.services li:nth-child(3)');
298
      	 var offset = el.offset();
299
      	 positionX = offset.left;
300
      	 left = parseInt(positionX) +20;
301
      	 $('#hand').css('left',left+'px');  		 
302
         $('#hand').show();
303
      }, 
304
      function () {
305
      	$('#hand').hide();
306
    
307
    });  
308
    
309
    $('.landing-page .cyclades').hover(
310
      function () {
311
      	 el = $('.cloudbar ul.services li:nth-child(2)').first();
312
      	 var offset = el.offset();
313
      	 positionX = offset.left;
314
      	 left = parseInt(positionX) +20;
315
      	 $('#hand').css('left',left+'px');  		 
316
         $('#hand').show();
317
      }, 
318
      function () {
319
      	$('#hand').hide();
320
    
321
    });  
322
    
323
    
324
    $('.landing-page .dashboard').hover(
325
      function () {
326
      	 el = $('.cloudbar .profile');
327
      	 var offset = el.offset();
328
      	 positionX = offset.left +50;
329
      	 $('#hand').css('left',positionX);  		 
330
         $('#hand').show();
331
      }, 
332
      function () {
333
      	$('#hand').hide();
334
    
335
    });  
336
    
337
    $('.pagination a.disabled').click(function(e){
338
    	e.preventDefault();
339
    });
340
	  
341
	// fix for recaptcha fields
342
	$('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide();
343

  
344
  fixEl = $('.details .lt');
345
  if (fixEl.length){ window.fixEloffsetTop = fixEl.offset().top;} 
346
  
347

  
348
  $(".stats-block li em").equalHeights();
349

  
350
 
351
});
352
	
353
$(window).resize(function() {
354
    
355
   setContainerMinHeight('.container .wrapper'); 
356
   $(".stats-block li em").equalHeights();
357
    
358

  
359
});
360

  
361

  
362
/* js for fixed faq/userguide side nav */
363
$(window).scroll(function () {
364

  
365
  if ( $('.details .lt').height() < $('.details .rt').height() ) {
366
    if ($(window).scrollTop() > window.fixEloffsetTop){ 
367
      fixEl.addClass('fixed');
368
    } else {
369
      fixEl.removeClass('fixed');
370
    }
371
  }
372

  
373

  
374

  
375
});
1
function isIpadIphone(){
2
  var flag = false;
3
    var isiPhone = navigator.userAgent.toLowerCase().indexOf("iphone");
4
    var isiPad = navigator.userAgent.toLowerCase().indexOf("ipad");
5
    if(isiPhone > -1) { flag = true; }
6
    if(isiPad > -1) { flag = true; }
7
    return flag;
8
}
9

  
10
function setContainerMinHeight( applicableDiv){
11

  
12
  if ( $(applicableDiv).length > 0 ) {
13
    //var h = $('.header').height(); div.header is not found
14
    var f = $('.footer').height();
15
    var w = $(window).height();
16
    var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) );
17
    var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", "")));
18
    var c = w - ( f+pTop+pBottom+36);//36 is header's height.
19
    $(applicableDiv).css('min-height', c);
20
  }
21
}
22

  
23
function tableFixedCols(table, firstColWidth ){
24
	ColsNum = $('table th').size();
25
	var ColWidth = parseFloat( (100 - firstColWidth)/ColsNum ).toFixed(0);
26
	var ColWidthPercentage = ColWidth+'%';
27
	var firstColWidthPercentage = firstColWidth+'%';
28
	$('.projects table th, .projects  table td').attr('width',ColWidthPercentage );
29
	$('.projects table tr td:first-child,.projects  table tr th:first-child').attr('width',firstColWidthPercentage );
30
}
31

  
32
function addClassHover(hoverEl, applicableEl){
33
	$(hoverEl).hover(
34
      function () {
35
        $(applicableEl).addClass('red-border')
36
      },
37
      function () {
38
        $(applicableEl).removeClass('red-border');
39
    });
40
}
41

  
42
//equal heights
43
(function($) {
44
	$.fn.equalHeights = function(minHeight, maxHeight) {
45
		tallest = (minHeight) ? minHeight : 0;
46
		this.each(function() {
47
			if($(this).height() > tallest) {
48
				tallest = $(this).height();
49
			}
50
		});
51
		if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
52
		return this.each(function() {
53
			$(this).height(tallest);
54
		});
55
	}
56
})(jQuery);
57

  
58

  
59

  
60
// fix for iPhone - iPad orientation bug
61
var metas = document.getElementsByTagName('meta');
62
function resetViewport() {
63
  var i;
64
  if (navigator.userAgent.match(/iPhone/i)) {
65
    for (i=0; i<metas.length; i++) {
66
      if (metas[i].name == "viewport") {
67
        metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
68
      }
69
    }
70
  }
71
}
72
resetViewport();
73

  
74
window.onorientationchange = function() {
75
    resetViewport();
76
};
77

  
78
function gestureStart() {
79
  for (i=0; i<metas.length; i++) {
80
    if (metas[i].name == "viewport") {
81
      metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
82
    }
83
  }
84
}
85

  
86
if (navigator.userAgent.match(/iPhone/i)) {
87
	document.addEventListener("gesturestart", gestureStart, false);
88
}
89
//end of fix
90

  
91
function setFixedLtBar(){
92
  var diff = ( $(window).height() - $('.footer').outerHeight() ) - $('.details .lt').height();
93
  if ( $('.details .lt').height() < $('.details .rt').height() ) {
94
    if ( ($(window).scrollTop() > window.fixEloffsetTop) && diff>0 ) {
95
      fixEl.addClass('fixed');
96
    } else {
97
      fixEl.removeClass('fixed');
98
    }
99
  }
100
  console.log(diff,'diff');
101
}
102

  
103
$(document).ready(function() {
104

  
105

  
106
  setContainerMinHeight('.container .wrapper');
107
  tableFixedCols('my-projects', 25);
108

  
109
  $('.show-extra').click(function(e) {
110
      e.preventDefault();
111
      $(this).parents('.bg-wrap').find('.extra').slideToggle(600);
112
  });
113
  $('.hide-extra').click(function(e) {
114
      e.preventDefault();
115
      $(this).parents('.bg-wrap').find('.extra').slideUp(600);
116
  });
117

  
118
  $('.box-more p').click(function(e) {
119
      $(this).siblings('.clearfix').toggle('slow');
120
      $(this).parents('.box-more').toggleClass('border');
121
  });
122

  
123
	var fixTopMessageHeight = function() {
124
		var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));
125
		$('.mainlogo').css('marginTop','-'+topMargin+'px');
126
	}
127

  
128
  // Uncomment to hide logo upon top message appearance
129

  
130
	// if ($('.mainlogo img').length > 0) {
131
	// 	$('.mainlogo img').bind('load', fixTopMessageHeight)
132
	// } else {
133
	// 	fixTopMessageHeight();
134
	// }
135

  
136
	$('.top-msg a.close').click(function(e) {
137
		e.preventDefault();
138
        $('.top-msg').animate({
139
            paddingTop:'0',
140
            paddingBottom:'0',
141
            height:'0'
142
        }, 1000, function (){
143
             $('.top-msg').removeClass('active')
144
        });
145
        $('.mainlogo').animate({
146
            marginTop:'0'
147
        }, 1000, function (){
148
             //todo
149
        });
150
    });
151

  
152
	$('select.dropkicked').dropkick({
153
		change: function (value, label) {
154
		    $(this).parents('form').submit();
155
		}
156
	});
157

  
158
  $('.with-info select').attr('tabindex','1');
159
  $('.with-info select').dropkick();
160
  $('.top-msg .success').parents('.top-msg').addClass('success');
161
  $('.top-msg .error').parents('.top-msg').addClass('error');
162
  $('.top-msg .warning').parents('.top-msg').addClass('warning');
163
  $('.top-msg .info').parents('.top-msg').addClass('info');
164

  
165
  // clouds homepage animation
166
  $('#animation a').hover(
167
    function () {
168
      $(this).animate({
169
        top: '+=-5'
170
      }, 300, function() {
171
        if ($(this).find('img').attr('src').indexOf("_top") == -1) {
172
          var src = $(this).find('img').attr('src').replace('.png', '_top.png')
173
          $(this).find('img').attr("src", src);
174
        }
175
      });
176
      $(this).siblings('p').find('img').animate({
177
        width: '60%'
178
      }, 300);
179
    },
180
    function () {
181
      $(this).animate({top: '0'}, 300, function() {
182
        var src = $(this).find('img').attr('src').replace('_top.png', '.png')
183
        $(this).find('img').attr("src", src);
184
      });
185
      $(this).siblings('p').find('img').animate({
186
        width: '65%'
187
      },300);
188
    }
189
  );
190

  
191
  $(function() {
192
    $( "#id_start_date" ).datepicker({
193
      minDate: 0,
194
      defaultDate: "+0",
195
      dateFormat: "yy-mm-dd",
196
      onSelect: function( selectedDate ) {
197
        $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );
198
      }
199
    });
200
    $( "#id_end_date" ).datepicker({
201
      defaultDate: "+3w",
202
      dateFormat: "yy-mm-dd",
203
      onSelect: function( selectedDate ) {
204
        $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );
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
	$('.projects .details .edit').click( function(e){
221
		e.preventDefault();
222
		$(this).parents('.details').children('.data').hide();
223
		$(this).parents('.details').children('.editable').slideDown(500, 'linear');
224
		$(this).hide();
225
	});
226

  
227
	$('.editable .form-row').each(function() {
228
		if ( $(this).hasClass('with-errors') ){
229
			$('.editable').show();
230
			$('.projects .details a.edit, .projects .details .data').hide();
231
		}
232
	});
233

  
234
	$("input.leave, input.join").click(function () {
235
		$('dialog').hide();
236
		$(this).parents('.msg-wrap').find('.dialog').show();
237
		return false;
238
  });
239

  
240
  $('.msg-wrap .no').click( function(e){
241
    e.preventDefault();
242
    $(this).parents('.dialog').hide();
243
  });
244

  
245
  $('.msg-wrap .yes').click( function(e){
246
    e.preventDefault();
247
    $(this).parents('.dialog').siblings('form').submit();
248
	});
249

  
250
  $('.hidden-submit input[readonly!="True"]').focus(function () {
251
    $('.hidden-submit .form-row.submit').slideDown(500);
252
  });
253

  
254
  setTimeout(function() {
255
    if ($('input#id_username').val()){
256
      $('input#id_username').siblings('label').css('opacity','0');
257
    };
258
    if ($('input#id_password').val()){
259
      $('input#id_password').siblings('label').css('opacity','0');
260
    }
261
  }, 100);
262

  
263
	$('.landing-page .cms').hover(
264
    function () {
265
      el = $('.cloudbar ul.services li').first();
266
      var offset = el.offset();
267
      positionX = offset.left;
268
      $('#hand').css('left',positionX);
269
      $('#hand').show();
270
    },
271
    function () {
272
      $('#hand').hide();
273
    }
274
  );
275

  
276
  $('.landing-page .pithos').hover(
277
    function () {
278
      el = $('.cloudbar ul.services li:nth-child(3)');
279
      var offset = el.offset();
280
      positionX = offset.left;
281
      left = parseInt(positionX) +20;
282
      $('#hand').css('left',left+'px');
283
      $('#hand').show();
284
    }, 
285
    function () {
286
      $('#hand').hide();
287
    }
288
  );
289

  
290
  $('.landing-page .cyclades').hover(
291
    function () {
292
      el = $('.cloudbar ul.services li:nth-child(2)').first();
293
      var offset = el.offset();
294
      positionX = offset.left;
295
      left = parseInt(positionX) +20;
296
      $('#hand').css('left',left+'px');
297
      $('#hand').show();
298
    },
299
    function () {
300
      $('#hand').hide();
301
    }
302
  );
303
  $('.landing-page .dashboard').hover(
304
    function () {
305
      el = $('.cloudbar .profile');
306
      var offset = el.offset();
307
      positionX = offset.left +50;
308
      $('#hand').css('left',positionX);
309
      $('#hand').show();
310
    },
311
    function () {
312
      $('#hand').hide();
313
    }
314
  );
315
  $('.pagination a.disabled').click(function(e){
316
    e.preventDefault();
317
  });
318

  
319
	// fix for recaptcha fields
320
	$('#okeanos_recaptcha').parents('.form-row').find('.extra-img').hide();
321

  
322
  fixEl = $('.details .lt');
323
  if (fixEl.length){ window.fixEloffsetTop = fixEl.offset().top;}
324

  
325
  $(".stats-block li em").equalHeights();
326

  
327
});
328

  
329
$(window).resize(function() {
330
  setContainerMinHeight('.container .wrapper');
331
  $(".stats-block li em").equalHeights();
332
});
333

  
334
/* js for fixed faq/userguide side nav */
335
$(window).scroll(function () {
336
  setFixedLtBar();
337
});

Also available in: Unified diff