-
Notifications
You must be signed in to change notification settings - Fork 1
/
weather.js
60 lines (49 loc) · 1.77 KB
/
weather.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
function showCityWeather(cityId){
var data = {'city': cityId};
if (cityId !== undefined){
$.ajax({type: 'GET',
url: portal_url + '/@@update-weather',
async : true,
data: data,
success: function(results) {
$.ajax({type: 'GET',
url: portal_url + '/@@current-weather',
async : true,
data: data,
success: function(results){
$("#top-weather-viewlet .current-weather").parent().html(results);
createCookie("collective.weather.current_city", cityId, 30);
}
});
}
});
}
}
function bindSelectCityEvents() {
$("#current-city").parent().next('.actionMenuContent').mouseleave(function() {
$(this).hide();
});
$("#current-city").live("click", function(e) {
e.preventDefault();
$(this).parent().next('.actionMenuContent').toggle();
});
$(".weather-choose-city").live("click", function(e) {
e.preventDefault();
var city = $(this).parent().attr('data-city-id');
showCityWeather(city);
$(this).parent().parent().parent().toggle();
});
}
function getCurrentCityFromCookie() {
var cityId = readCookie("collective.weather.current_city");
return cityId;
}
$(document).ready(function() {
bindSelectCityEvents();
var cityId = getCurrentCityFromCookie();
if (cityId === undefined || cityId === null){
var elem = document.getElementById('current-city');
cityId = $(elem).attr('data-city-id');
}
showCityWeather(cityId);
});