-
Notifications
You must be signed in to change notification settings - Fork 4
/
angular-openweathermap.min.js
1 lines (1 loc) · 3.35 KB
/
angular-openweathermap.min.js
1
"use strict";angular.module("angular-openweathermap",[]).directive("angularOpenweathermap",["$http",function(a){return{restrict:"EA",template:'<i class="wi" ng-class="weatherClass" tooltip="{{weatherDescription}}" style="padding-right:5px;"></i><span ng-bind-html="cityName"></span> | <span ng-bind-html="temperature"></span>',transclude:!0,scope:{cityName:"@",offsetHours:"@",offsetMinutes:"@"},link:function(b,c,d){a.get("http://api.openweathermap.org/data/2.5/weather?units=metric&q="+b.cityName).success(function(a){b.weather=a;var c=a.main.temp,d=Math.round(1.8*c+32);c=Math.round(c),b.temperature=c+"°C / "+d+"°F";var e=new Date(1e3*a.dt+36e5*b.offsetHours+6e4*b.offsetMinutes),f=new Date(1e3*a.sys.sunrise+36e5*b.offsetHours+6e4*b.offsetMinutes),g=new Date(1e3*a.sys.sunset+36e5*b.offsetHours+6e4*b.offsetMinutes),h=e.getUTCHours(),i=f.getUTCHours(),j=g.getUTCHours(),k=!1;if((h>=j||i>=h)&&(k=!0),b.weatherDescription=a.weather[0].description.charAt(0).toUpperCase()+a.weather[0].description.slice(1),k)switch(a.weather[0].id){case 200:case 201:case 202:case 210:case 211:case 212:case 221:b.weatherClass="wi-night-alt-thunderstorm";break;case 230:case 231:case 232:case 901:b.weatherClass="wi-night-alt-storm-showers";break;case 300:case 301:case 302:case 310:case 311:case 312:case 313:case 314:case 321:case 621:case 622:b.weatherClass="wi-night-alt-showers";break;case 500:case 501:case 502:case 503:case 504:case 511:case 520:case 521:case 522:case 531:b.weatherClass="wi-night-alt-rain";break;case 600:case 601:case 602:case 611:case 612:b.weatherClass="wi-night-alt-snow";break;case 615:case 616:case 620:case 611:case 612:b.weatherClass="wi-night-alt-rain-mix";break;case 701:case 721:case 741:b.weatherClass="wi-night-fog";break;case 800:case 951:b.weatherClass="wi-night-clear";break;case 801:case 802:case 803:case 804:b.weatherClass="wi-night-alt-cloudy";break;case 906:b.weatherClass="wi-night-alt-hail";break;case 906:b.weatherClass="wi-night-alt-cloudy-windy"}else switch(a.weather[0].id){case 200:case 201:case 202:case 210:case 211:case 212:case 221:b.weatherClass="wi-day-thunderstorm";break;case 230:case 231:case 232:case 901:b.weatherClass="wi-day-storm-showers";break;case 300:case 301:case 302:case 310:case 311:case 312:case 313:case 314:case 321:case 621:case 622:b.weatherClass="wi-day-showers";break;case 500:case 501:case 502:case 503:case 504:case 511:case 520:case 521:case 522:case 531:b.weatherClass="wi-day-rain";break;case 600:case 601:case 602:case 611:case 612:b.weatherClass="wi-day-snow";break;case 615:case 616:case 620:case 611:case 612:b.weatherClass="wi-day-rain-mix";break;case 701:case 721:case 741:b.weatherClass="wi-day-fog";break;case 800:case 951:b.weatherClass="wi-day-sunny";break;case 801:case 802:case 803:case 804:b.weatherClass="wi-day-cloudy";break;case 906:b.weatherClass="wi-day-hail";break;case 906:b.weatherClass="wi-day-cloudy-windy"}switch(a.weather[0].id){case 731:case 751:case 761:case 762:b.weatherClass="wi-dust";break;case 711:b.weatherClass="wi-smoke";break;case 771:case 957:case 958:case 959:case 960:b.weatherClass="wi-strong-wind";break;case 781:case 900:b.weatherClass="wi-tornado";break;case 902:case 961:case 962:b.weatherClass="wi-hurricane";break;case 903:b.weatherClass="wi-snowflake-cold";break;case 904:b.weatherClass="wi-hot";break;case 905:case 951:case 952:case 953:case 954:case 955:case 956:b.weatherClass="wi-windy"}})}}}]);