|
@@ -19,6 +19,7 @@ function get(url){
|
|
|
xhr.send();
|
|
|
});
|
|
|
}
|
|
|
+
|
|
|
function show(obj){
|
|
|
var weather = obj.query.results.channel.item.description;
|
|
|
var resWeather = weather.replace(/href|CDATA|[\!]|[\[]|[\]]/g,"");
|
|
@@ -29,41 +30,55 @@ function show(obj){
|
|
|
}
|
|
|
|
|
|
function* myGenerator(){
|
|
|
- var object = yield get('https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json');
|
|
|
- var keys = Object.keys(object);
|
|
|
- var select = document.createElement("select");
|
|
|
- for (var i = 0; i < keys.length; i++) {
|
|
|
- var option = document.createElement("option");
|
|
|
- option.innerHTML = keys[i];
|
|
|
- option.value = keys[i];
|
|
|
- select.appendChild(option);
|
|
|
- }
|
|
|
-
|
|
|
- select.onchange = function(){
|
|
|
- run(onchange1);
|
|
|
- }
|
|
|
- function* onchange1(e){
|
|
|
- var select = document.createElement("select");
|
|
|
- for (var i = 0; i < object[document.getElementById("main").value].length; i++) {
|
|
|
- var option = document.createElement("option")
|
|
|
- option.innerHTML = object[document.getElementById("main").value][i];
|
|
|
- select.appendChild(option);
|
|
|
- }
|
|
|
- if(selects.children.length > 1){
|
|
|
- selects.replaceChild(select, document.getElementById("main").nextElementSibling);
|
|
|
- }
|
|
|
- else
|
|
|
- selects.appendChild(select);
|
|
|
- var obj = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + select.value + "\') and u='c'") + '&format=json');
|
|
|
- show(obj);
|
|
|
- select.onchange = function(){
|
|
|
- get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + this.value + "\') and u='c'") + '&format=json').then(function(obj){
|
|
|
- show(obj);
|
|
|
- })
|
|
|
- }
|
|
|
+ try{
|
|
|
+ var object = yield get('https://raw.githubusercontent.com/David-Haim/CountriesToCitiesJSON/master/countriesToCities.json');
|
|
|
+ var keys = Object.keys(object);
|
|
|
+ var select = document.createElement("select");
|
|
|
+ for (var i = 0; i < keys.length; i++) {
|
|
|
+ var option = document.createElement("option");
|
|
|
+ option.innerHTML = keys[i];
|
|
|
+ option.value = keys[i];
|
|
|
+ select.appendChild(option);
|
|
|
+ }
|
|
|
+ select.onchange = function(){
|
|
|
+ run(onchange1);
|
|
|
+ }
|
|
|
+ function* onchange1(e){
|
|
|
+ try{
|
|
|
+ var mainSelect = document.getElementById("main")
|
|
|
+ var select = document.createElement("select");
|
|
|
+ for (var i = 0; i < object[mainSelect.value].length; i++) {
|
|
|
+ var option = document.createElement("option")
|
|
|
+ option.innerHTML = object[mainSelect.value][i];
|
|
|
+ select.appendChild(option);
|
|
|
+ }
|
|
|
+ if(selects.children.length > 1){
|
|
|
+ selects.replaceChild(select,mainSelect.nextElementSibling);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ selects.appendChild(select);
|
|
|
+ var obj = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + select.value + "\') and u='c'") + '&format=json');
|
|
|
+ show(obj);
|
|
|
+ select.onchange = function(){
|
|
|
+ run(onchange2);
|
|
|
+ }
|
|
|
+ function* onchange2(){
|
|
|
+ try{
|
|
|
+ var obj2 = yield get("https://query.yahooapis.com/v1/public/yql?" + 'q=' + encodeURIComponent("select * from weather.forecast where woeid in (select woeid from geo.places(1) where text=\'" + select.value + "\') and u='c'") + '&format=json');
|
|
|
+ show(obj2);
|
|
|
+ }catch(error){
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }catch(error){
|
|
|
+ throw error;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ selects.appendChild(select);
|
|
|
+ select.id = "main"
|
|
|
+ }catch(error){
|
|
|
+ throw error;
|
|
|
}
|
|
|
- selects.appendChild(select);
|
|
|
- select.id = "main"
|
|
|
|
|
|
}
|
|
|
|
|
@@ -72,10 +87,10 @@ function run(g){
|
|
|
function handle(result){
|
|
|
if(!result.done){
|
|
|
result.value.then(function(data){
|
|
|
- return handle(gen.next(data));
|
|
|
+ handle(gen.next(data));
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
- return handle(gen.next());
|
|
|
+ handle(gen.next());
|
|
|
}
|
|
|
run(myGenerator);
|