Statistics
| Branch: | Tag: | Revision:

root / cloudcms / static / cloudcms / js / common.js @ 485caba3

History | View | Annotate | Download (4.6 kB)

1
function setContainerMinHeight( applicableDiv){
2
  if ( $(applicableDiv).length > 0 ) {
3
    var f = $('.footer').height();
4
    var w = $(window).height();
5
    var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) );
6
    var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", "")));
7
    var c = w - ( f+pTop+pBottom+36);//36 is header's height.
8
    $(applicableDiv).css('min-height', c);
9
  }
10
}
11

    
12
//equal heights
13
(function($) {
14
        $.fn.equalHeights = function(minHeight, maxHeight) {
15
                tallest = (minHeight) ? minHeight : 0;
16
                this.each(function() {
17
                        if($(this).height() > tallest) {
18
                                tallest = $(this).height();
19
                        }
20
                });
21
                if((maxHeight) && tallest > maxHeight) tallest = maxHeight;
22
                return this.each(function() {
23
                        $(this).height(tallest);
24
                });
25
        }
26
})(jQuery);
27

    
28
// fix for iPhone - iPad orientation bug
29
function isIpadIphone(){
30
  var flag = false;
31
    var isiPhone = navigator.userAgent.toLowerCase().indexOf("iphone");
32
    var isiPad = navigator.userAgent.toLowerCase().indexOf("ipad");
33
    if(isiPhone > -1) { flag = true; }
34
    if(isiPad > -1) { flag = true; }
35
    return flag;
36
}
37

    
38
var metas = document.getElementsByTagName('meta');
39
function resetViewport() {
40
  var i;
41
  if (navigator.userAgent.match(/iPhone/i)) {
42
    for (i=0; i<metas.length; i++) {
43
      if (metas[i].name == "viewport") {
44
        metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";
45
      }
46
    }
47
  }
48
}
49
resetViewport();
50

    
51
window.onorientationchange = function() {
52
    resetViewport();
53
};
54

    
55
function gestureStart() {
56
  for (i=0; i<metas.length; i++) {
57
    if (metas[i].name == "viewport") {
58
      metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";
59
    }
60
  }
61
}
62

    
63
if (navigator.userAgent.match(/iPhone/i)) {
64
        document.addEventListener("gesturestart", gestureStart, false);
65
}
66
//end of fix
67

    
68
$(document).ready(function() {
69

    
70

    
71
  setContainerMinHeight('.container .wrapper');
72

    
73
  $('.show-extra').click(function(e) {
74
      e.preventDefault();
75
      $(this).parents('.bg-wrap').find('.extra').slideToggle(600);
76
  });
77
  $('.hide-extra').click(function(e) {
78
      e.preventDefault();
79
      $(this).parents('.bg-wrap').find('.extra').slideUp(600);
80
  });
81

    
82
        var fixTopMessageHeight = function() {
83
                var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));
84
                $('.mainlogo').css('marginTop','-'+topMargin+'px');
85
        }
86

    
87
  // Uncomment to hide logo upon top message appearance
88

    
89
        // if ($('.mainlogo img').length > 0) {
90
        //         $('.mainlogo img').bind('load', fixTopMessageHeight)
91
        // } else {
92
        //         fixTopMessageHeight();
93
        // }
94

    
95
        $('.top-msg a.close').click(function(e) {
96
                e.preventDefault();
97
        $('.top-msg').animate({
98
            paddingTop:'0',
99
            paddingBottom:'0',
100
            height:'0'
101
        }, 1000, function (){
102
             $('.top-msg').removeClass('active')
103
        });
104
        $('.mainlogo').animate({
105
            marginTop:'0'
106
        }, 1000, function (){
107
             //todo
108
        });
109
    });
110

    
111
  $('.top-msg .success').parents('.top-msg').addClass('success');
112
  $('.top-msg .error').parents('.top-msg').addClass('error');
113
  $('.top-msg .warning').parents('.top-msg').addClass('warning');
114
  $('.top-msg .info').parents('.top-msg').addClass('info');
115

    
116
  // clouds homepage animation
117
  $('#animation a').hover(
118
    function () {
119
      $(this).animate({
120
        top: '+=-5'
121
      }, 300, function() {
122
        if ($(this).find('img').attr('src').indexOf("_top") == -1) {
123
          var src = $(this).find('img').attr('src').replace('.png', '_top.png')
124
          $(this).find('img').attr("src", src);
125
        }
126
      });
127
      $(this).siblings('p').find('img').animate({
128
        width: '60%'
129
      }, 300);
130
    },
131
    function () {
132
      $(this).animate({top: '0'}, 300, function() {
133
        var src = $(this).find('img').attr('src').replace('_top.png', '.png')
134
        $(this).find('img').attr("src", src);
135
      });
136
      $(this).siblings('p').find('img').animate({
137
        width: '65%'
138
      },300);
139
    }
140
  );
141

    
142
  fixEl = $('.details .lt');
143
  if (fixEl.length){ window.fixEloffsetTop = fixEl.offset().top;}
144

    
145
  $(".stats-block li em").equalHeights();
146

    
147
});
148

    
149
$(window).resize(function() {
150
  setContainerMinHeight('.container .wrapper');
151
  $(".stats-block li em").equalHeights();
152
  $(window).scroll(function () {
153
    setFixedLtBar();
154
  });
155
});
156

    
157
/* js for fixed faq/userguide side nav */
158
$(window).scroll(function () {
159
  var diff = ( $(window).height() - $('.footer').outerHeight() ) - $('.details .lt').height();
160
  if ( $('.details .lt').height() < $('.details .rt').height() ) {
161
    if ( ($(window).scrollTop() > window.fixEloffsetTop) && diff>0 ) {
162
      fixEl.addClass('fixed');
163
    } else {
164
      fixEl.removeClass('fixed');
165
    }
166
  }
167
});