Static files sync with astakos
[snf-cloudcms] / cloudcms / static / cloudcms / js / common.js
1 function setContainerMinHeight( applicableDiv){\r
2         \r
3     if ( $(applicableDiv).length > 0 ) {\r
4         //var h = $('.header').height(); div.header is not found \r
5         var f = $('.footer').height();\r
6         var w = $(window).height();\r
7         var pTop = parseInt (($(applicableDiv).css('padding-top').replace("px", "")) );\r
8         var pBottom = parseInt (($(applicableDiv).css('padding-bottom').replace("px", "")));\r
9 \r
10         var c = w - ( f+pTop+pBottom+36);//36 is header's height.\r
11         $(applicableDiv).css('min-height', c);\r
12     }    \r
13 \r
14 }\r
15 \r
16 function tableFixedCols(table, firstColWidth ){\r
17         ColsNum = $('table th').size();\r
18         var ColWidth = parseFloat( (100 - firstColWidth)/ColsNum ).toFixed(0);\r
19         var ColWidthPercentage = ColWidth+'%';\r
20         var firstColWidthPercentage = firstColWidth+'%';\r
21         $('table th, table td').attr('width',ColWidthPercentage ); \r
22         $('table tr td:first-child, table tr th:first-child').attr('width',firstColWidthPercentage );\r
23         \r
24 }\r
25 \r
26 \r
27 //equal heights\r
28  \r
29 (function($) {\r
30         $.fn.equalHeights = function(minHeight, maxHeight) {\r
31                 tallest = (minHeight) ? minHeight : 0;\r
32                 this.each(function() {\r
33                         if($(this).height() > tallest) {\r
34                                 tallest = $(this).height();\r
35                         }\r
36                 });\r
37                 if((maxHeight) && tallest > maxHeight) tallest = maxHeight;\r
38                 return this.each(function() {\r
39                         $(this).height(tallest);\r
40                 });\r
41         }\r
42 })(jQuery);\r
43 \r
44 \r
45 \r
46 // fix for iPhone - iPad orientation bug \r
47 var metas = document.getElementsByTagName('meta');\r
48 function resetViewport() {\r
49     var i;\r
50     if (navigator.userAgent.match(/iPhone/i)) {\r
51                 for (i=0; i<metas.length; i++) {\r
52                 if (metas[i].name == "viewport") {\r
53                         metas[i].content = "width=device-width, minimum-scale=1.0, maximum-scale=1.0";\r
54                 }\r
55                 }\r
56         }\r
57 }\r
58 resetViewport();\r
59     \r
60 window.onorientationchange = function() {\r
61     resetViewport();\r
62 };\r
63     \r
64 function gestureStart() {\r
65   for (i=0; i<metas.length; i++) {\r
66     if (metas[i].name == "viewport") {\r
67       metas[i].content = "width=device-width, minimum-scale=0.25, maximum-scale=1.6";\r
68     }\r
69   }\r
70 }\r
71 \r
72 if (navigator.userAgent.match(/iPhone/i)) {\r
73         document.addEventListener("gesturestart", gestureStart, false);\r
74 }\r
75 //end of fix\r
76 \r
77 $(document).ready(function() {\r
78         \r
79          \r
80     setContainerMinHeight('.container .wrapper');\r
81     tableFixedCols('my-projects', 25);\r
82         \r
83     $('.show-extra').click(function(e) {\r
84         e.preventDefault();\r
85         $(this).parents('.bg-wrap').find('.extra').slideToggle(600);\r
86     });\r
87     $('.hide-extra').click(function(e) {\r
88         e.preventDefault();\r
89         $(this).parents('.bg-wrap').find('.extra').slideUp(600);\r
90     });\r
91     \r
92     $('.box-more p').click(function(e) {\r
93         $(this).siblings('.clearfix').toggle('slow');\r
94         $(this).parents('.box-more').toggleClass('border');\r
95     });\r
96         \r
97         var fixTopMessageHeight = function() {\r
98                 var topMargin = parseInt($('.mainlogo img').height())+parseInt($('.top-msg').css('marginBottom'));\r
99                 $('.mainlogo').css('marginTop','-'+topMargin+'px');\r
100         }\r
101         \r
102         if ($('.mainlogo img').length > 0) {\r
103                 $('.mainlogo img').bind('load', fixTopMessageHeight)\r
104         } else {\r
105                 fixTopMessageHeight();\r
106         }\r
107         \r
108         $('.top-msg a.close').click(function(e) {\r
109                 e.preventDefault();\r
110         $('.top-msg').animate({\r
111             paddingTop:'0',\r
112             paddingBottom:'0',\r
113             height:'0'\r
114         }, 1000, function (){\r
115              $('.top-msg').removeClass('active')\r
116         });\r
117         $('.mainlogo').animate({\r
118             marginTop:'0'\r
119         }, 1000, function (){\r
120              //todo\r
121         });\r
122     }); \r
123     \r
124      \r
125         $('select.dropkicked').dropkick({\r
126                 change: function (value, label) {\r
127                     $(this).parents('form').submit();\r
128                     \r
129                 }\r
130         });\r
131         \r
132         $('.with-info select').attr('tabindex','1');\r
133     $('.with-info select').dropkick();\r
134     \r
135     $('.top-msg .success').parents('.top-msg').addClass('success');\r
136     $('.top-msg .error').parents('.top-msg').addClass('error');\r
137     $('.top-msg .warning').parents('.top-msg').addClass('warning');\r
138     $('.top-msg .info').parents('.top-msg').addClass('info');\r
139     \r
140     // clouds homepage animation\r
141     $('#animation a').hover(\r
142       function () {\r
143         \r
144         $(this).animate({\r
145            top: '+=-10'   \r
146            }, 600, function() {\r
147                 if ($(this).find('img').attr('src').indexOf("_top") == -1) {\r
148                         var src = $(this).find('img').attr('src').replace('.png', '_top.png')\r
149                         $(this).find('img').attr("src", src);\r
150                 }\r
151 \r
152                 });\r
153         $(this).siblings('p').find('img').animate({\r
154           width: '60%'       \r
155         }, 600);\r
156       }, \r
157       function () {\r
158 \r
159         $(this).animate({top: '0'}, 600, function() {\r
160                 var src = $(this).find('img').attr('src').replace('_top.png', '.png')\r
161                 $(this).find('img').attr("src", src);\r
162                 });\r
163         $(this).siblings('p').find('img').animate({\r
164           width: '65%'       \r
165         },600);\r
166       }\r
167     );\r
168     \r
169     \r
170     \r
171     \r
172     $(function() {               \r
173                 $( "#id_start_date" ).datepicker({\r
174                         minDate: 0,\r
175                         defaultDate: "+0", \r
176             dateFormat: "yy-mm-dd",\r
177             onSelect: function( selectedDate ) {\r
178                 $( "#id_end_date" ).datepicker( "option", "minDate", selectedDate );\r
179             }\r
180         });\r
181         \r
182         $( "#id_end_date" ).datepicker({\r
183                 defaultDate: "+3w", \r
184             dateFormat: "yy-mm-dd",\r
185             onSelect: function( selectedDate ) {\r
186                 $( "#id_start_date" ).datepicker( "option", "maxDate", selectedDate );\r
187             }\r
188         });\r
189         });\r
190         \r
191          
192         $('table .more-info').click(function(e){\r
193
194                 e.preventDefault();\r
195                 $(this).toggleClass('open');\r
196                 if ($(this).hasClass('open')){\r
197                         $(this).html('- less info ')\r
198                 } else {\r
199                         $(this).html('+ more info ')\r
200                 }\r
201                 $(this).parents('tr').next('tr').toggle();\r
202                  \r
203         });\r
204         \r
205         $('.projects .details .edit').click( function(e){\r
206                 e.preventDefault();\r
207                 $(this).parents('.details').children('.data').hide();\r
208                 $(this).parents('.details').children('.editable').slideDown(500, 'linear');\r
209                 $(this).hide();\r
210         });\r
211         \r
212         $('.editable .form-row').each(function() {\r
213                         if ( $(this).hasClass('with-errors') ){\r
214                                 $('.editable').show();\r
215                                 $('.projects .details a.edit, .projects .details .data').hide();\r
216                                 \r
217                         }\r
218                 });\r
219         \r
220  \r
221         $("input.leave, input.join").click(function () {\r
222                 $('dialog').hide();\r
223                 $(this).parents('.msg-wrap').find('.dialog').show();\r
224                 return false;      \r
225                 \r
226     });\r
227     \r
228      $('.msg-wrap .no').click( function(e){\r
229                 e.preventDefault();\r
230                 $(this).parents('.dialog').hide();\r
231         })\r
232     \r
233     $('.msg-wrap .yes').click( function(e){\r
234                 e.preventDefault();\r
235                 $(this).parents('.dialog').siblings('form').submit();\r
236         })\r
237     \r
238     $('.hidden-submit input[readonly!="True"]').focus(function () {\r
239          $('.hidden-submit .form-row.submit').slideDown(500);\r
240     });\r
241     \r
242     \r
243     \r
244      $('.auth_methods').find('li>a').click(function(e){\r
245         e.preventDefault();\r
246         $(this).siblings('.wrap').toggle('slow');\r
247         $(this).toggleClass('up');\r
248      });\r
249      \r
250      $('.auth_methods a.red').click(function(e){\r
251         e.preventDefault();\r
252         $(this).siblings('.dialog').show();\r
253      })\r
254      \r
255       \r
256      $('.auth_methods .dialog .no').click( function(e){  \r
257         e.preventDefault();\r
258         console.log($(this));\r
259         $(this).parents('.dialog').hide();\r
260      })\r
261     \r
262     setTimeout(function() {\r
263       if ($('input#id_username').val()){ \r
264         $('input#id_username').siblings('label').css('opacity','0');\r
265       };\r
266       if ($('input#id_password').val()){ \r
267         $('input#id_password').siblings('label').css('opacity','0');\r
268       }\r
269         }, 100);\r
270         \r
271          \r
272             \r
273 });\r
274         \r
275 $(window).resize(function() {\r
276     \r
277    setContainerMinHeight('.container .wrapper');\r
278
279 });
280