-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.htm
186 lines (145 loc) · 6.95 KB
/
index.htm
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>how is the weatehr</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.5.0/css/all.css" integrity="sha384-B4dIYHKNBt8Bc12p+WXckhzcICo0wtJAoU8YZTY5qE0Id1GSseTk6S+L3BlXeVIU" crossorigin="anonymous"> -->
<link rel="stylesheet" type="text/css" media="screen" href="style.css" />
<link rel="stylesheet" type="text/css" media="screen" href="bootstrap-grid.css" />
<script src="js/jquery.js"></script>
<script src="js/jquery_cookie_plugin.js"></script>
</head>
<body>
<div class="mask" onclick="hidden_modal()" >
<div class="modal_error col-lg-6 col-md-6 col-sm-6 col-xs-6">
<h2> شهر مورد نظر پیدا نشد. مجدد تلاش کنید... </h2>
</div>
</div>
<script>
function hidden_modal(){
$(".mask").removeClass("show").addClass("hide");
}
</script>
<div class="col-lg-12 con">
<h1 class="col-lg-12"> هوای امروز چطوره؟</h1>
<div class="col-lg-12 search_box">
<input type="text" id="search_input" class="col-lg-10 search" placeholder="نام شهر مورد نظر را وارد کنید"> <input type="button" id="search_butt" class="search_butt" id = "getIt" onclick = "gettingJSON()">
</div>
<div class="col-lg-10 row">
<div class="items col-lg-3 col-md-4 col-sm-6">
<div class="item">
<img src="pics/01d.png">
<h2> بابل </h2>
<img class="icon" src="pics/temp_icon.png">
<h1>15°c</h1>
<!-- <i class="fas fa-thermometer-half temp_icon"></i> -->
<span>توضیحات بیشتر و یا نمودار مربوط به پیش بینی هوای روز های آینده </span>
</div>
</div>
</div>
</div>
</body>
</html>
<script>
$(".con > .row ").html("");
$(".search").val("");
var city_counter = 1;
$(window).load(function() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
str=cookies[i];
index=str.lastIndexOf("=");
var city_inCookie = str.substring(index+1 , cookies[i].length);
//alert(city_inCookie);
url = "https://api.openweathermap.org/data/2.5/weather?q="+city_inCookie+"&units=metric&APPID=7ea8f559ec5f1f0899b61c89d728a8b9";
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/loader.gif') no-repeat 50%","background-size": "35%"});
$.getJSON(url,function (json,status){
temp=Math.round(json.main.temp);
weather_icon = json.weather[0].icon;
weather_desc = json.weather[0].description;
items = $("<div>").addClass("items col-lg-3 col-md-4 col-sm-6");
item = $("<div>").addClass("item");
im = $("<img>").attr({src: "pics/"+weather_icon+".png"});
//alert(city_inCookie);
h2 = $("<h2>").html(json.name);
h1 = $("<h1>").html(temp+"°c");
icon = $("<img>").addClass("icon").attr({src: "pics/temp_icon.png"});
sp = $("<span>").html(weather_desc);
item.append(im).append(h2).append(icon).append(h1).append(sp);
items.append(item);
$(".con > .row.error").removeClass("error").html(" ");
$(".con > .row ").append(items);
$(".search").val("");
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/search_icon.png') no-repeat 50%","background-size": "35%"});
}).fail(function() {
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/search_icon.png') no-repeat 50%","background-size": "35%"});
});
}
});
function gettingJSON(){
city = $(".search").val();
//set cookies
if(city != ""){
if(city_counter>4) city_counter=1;
url = "https://api.openweathermap.org/data/2.5/weather?q="+city+"&units=metric&APPID=7ea8f559ec5f1f0899b61c89d728a8b9";
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/loader.gif') no-repeat 50%","background-size": "35%"});
$.getJSON(url,function (json,status){
temp=Math.round(json.main.temp);
weather_icon = json.weather[0].icon;
weather_desc = json.weather[0].description;
$.cookie("city_"+city_counter , city, { expires : 2 } );
city_counter++;
items = $("<div>").addClass("items col-lg-3 col-md-4 col-sm-6");
item = $("<div>").addClass("item");
im = $("<img>").attr({src: "pics/"+weather_icon+".png"});
h2 = $("<h2>").html(city);
h1 = $("<h1>").html(temp+"°c");
icon = $("<img>").addClass("icon").attr({src: "pics/temp_icon.png"});
sp = $("<span>").html(weather_desc);
item.append(im).append(h2).append(icon).append(h1).append(sp);
items.append(item);
$(".con > .row.error").removeClass("error").html(" ");
$(".con > .row ").append(items);
$(".search").val("");
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/search_icon.png') no-repeat 50%","background-size": "35%"});
}).fail(function() {
$(".search").val("");
$(".mask").removeClass("hide").addClass("show"); //404 not found handle
$(".con > .search_box > .search_butt").css({"background":"#233260 url('pics/search_icon.png') no-repeat 50%","background-size": "35%"});
});
}
else{
$(".search").val("");
$(".mask").removeClass("hide").addClass("show"); //404 not found handle
}
}
</script>
<script>
// Get the input field************************************************************
var input = document.getElementById("search_input");
// Execute a function when the user releases a key on the keyboard
input.addEventListener("keyup", function(event) {
// Cancel the default action, if needed
event.preventDefault();
// Number 13 is the "Enter" key on the keyboard
if (event.keyCode === 13) {
// Trigger the button element with a click
document.getElementById("search_butt").click();
}
});
</script>
<script>
//delete all cookies **************************************************************
function deleteAllCookies() {
var cookies = document.cookie.split(";");
for (var i = 0; i < cookies.length; i++) {
var cookie = cookies[i];
var eqPos = cookie.indexOf("=");
var name = eqPos > -1 ? cookie.substr(0, eqPos) : cookie;
document.cookie = name + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}
}
//deleteAllCookies();
</script>