UNPKG

easy-weather-npm

Version:

A JavaScript plugin for getting Weather information

9 lines 37.1 kB
/** * Easy Weather is a A JavaScript plugin for getting Weather information * @version 1.0.0 * @author Amit Chauhan * @email chauhanammy@gmail.com * @license The MIT License (MIT) */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).EasyWeather=e()}(this,(function(){"use strict";function t(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function e(t,e){return t(e={exports:{}},e.exports),e.exports}var n=e((function(t){function e(t,e,n,i,a,r,s){try{var o=t[r](s),c=o.value}catch(t){return void n(t)}o.done?e(c):Promise.resolve(c).then(i,a)}t.exports=function(t){return function(){var n=this,i=arguments;return new Promise((function(a,r){var s=t.apply(n,i);function o(t){e(s,a,r,o,c,"next",t)}function c(t){e(s,a,r,o,c,"throw",t)}o(void 0)}))}},t.exports.default=t.exports,t.exports.__esModule=!0})),i=t(n),a=t(e((function(t){t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports.default=t.exports,t.exports.__esModule=!0}))),r=t(e((function(t){function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}t.exports=function(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t},t.exports.default=t.exports,t.exports.__esModule=!0}))),s=e((function(t){function e(n,i){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports.default=t.exports,t.exports.__esModule=!0,e(n,i)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0}));t(s);var o=t(e((function(t){t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&s(t,e)},t.exports.default=t.exports,t.exports.__esModule=!0}))),c=e((function(t){function e(n){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports.default=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports.default=t.exports,t.exports.__esModule=!0),e(n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),l=t(c),u=e((function(t){t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports.default=t.exports,t.exports.__esModule=!0})),h=t(u),p=e((function(t){var e=c.default;t.exports=function(t,n){if(n&&("object"===e(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return u(t)},t.exports.default=t.exports,t.exports.__esModule=!0})),f=t(p),d=e((function(t){function e(n){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports.default=t.exports,t.exports.__esModule=!0,e(n)}t.exports=e,t.exports.default=t.exports,t.exports.__esModule=!0})),m=t(d),v=e((function(t){var e=function(t){var e,n=Object.prototype,i=n.hasOwnProperty,a="function"==typeof Symbol?Symbol:{},r=a.iterator||"@@iterator",s=a.asyncIterator||"@@asyncIterator",o=a.toStringTag||"@@toStringTag";function c(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(t){c=function(t,e,n){return t[e]=n}}function l(t,e,n,i){var a=e&&e.prototype instanceof v?e:v,r=Object.create(a.prototype),s=new F(i||[]);return r._invoke=function(t,e,n){var i=h;return function(a,r){if(i===f)throw new Error("Generator is already running");if(i===d){if("throw"===a)throw r;return E()}for(n.method=a,n.arg=r;;){var s=n.delegate;if(s){var o=D(s,n);if(o){if(o===m)continue;return o}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===h)throw i=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=f;var c=u(t,e,n);if("normal"===c.type){if(i=n.done?d:p,c.arg===m)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(i=d,n.method="throw",n.arg=c.arg)}}}(t,n,s),r}function u(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=l;var h="suspendedStart",p="suspendedYield",f="executing",d="completed",m={};function v(){}function y(){}function x(){}var _={};c(_,r,(function(){return this}));var g=Object.getPrototypeOf,w=g&&g(g(M([])));w&&w!==n&&i.call(w,r)&&(_=w);var b=x.prototype=v.prototype=Object.create(_);function T(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function k(t,e){function n(a,r,s,o){var c=u(t[a],t,r);if("throw"!==c.type){var l=c.arg,h=l.value;return h&&"object"==typeof h&&i.call(h,"__await")?e.resolve(h.__await).then((function(t){n("next",t,s,o)}),(function(t){n("throw",t,s,o)})):e.resolve(h).then((function(t){l.value=t,s(l)}),(function(t){return n("throw",t,s,o)}))}o(c.arg)}var a;this._invoke=function(t,i){function r(){return new e((function(e,a){n(t,i,e,a)}))}return a=a?a.then(r,r):r()}}function D(t,n){var i=t.iterator[n.method];if(i===e){if(n.delegate=null,"throw"===n.method){if(t.iterator.return&&(n.method="return",n.arg=e,D(t,n),"throw"===n.method))return m;n.method="throw",n.arg=new TypeError("The iterator does not provide a 'throw' method")}return m}var a=u(i,t.iterator,n.arg);if("throw"===a.type)return n.method="throw",n.arg=a.arg,n.delegate=null,m;var r=a.arg;return r?r.done?(n[t.resultName]=r.value,n.next=t.nextLoc,"return"!==n.method&&(n.method="next",n.arg=e),n.delegate=null,m):r:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,m)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function L(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function F(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function M(t){if(t){var n=t[r];if(n)return n.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var a=-1,s=function n(){for(;++a<t.length;)if(i.call(t,a))return n.value=t[a],n.done=!1,n;return n.value=e,n.done=!0,n};return s.next=s}}return{next:E}}function E(){return{value:e,done:!0}}return y.prototype=x,c(b,"constructor",x),c(x,"constructor",y),y.displayName=c(x,o,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===y||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,c(t,o,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},T(k.prototype),c(k.prototype,s,(function(){return this})),t.AsyncIterator=k,t.async=function(e,n,i,a,r){void 0===r&&(r=Promise);var s=new k(l(e,n,i,a),r);return t.isGeneratorFunction(n)?s:s.next().then((function(t){return t.done?t.value:s.next()}))},T(b),c(b,o,"Generator"),c(b,r,(function(){return this})),c(b,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var i=e.pop();if(i in t)return n.value=i,n.done=!1,n}return n.done=!0,n}},t.values=M,F.prototype={constructor:F,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(L),!t)for(var n in this)"t"===n.charAt(0)&&i.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var n=this;function a(i,a){return o.type="throw",o.arg=t,n.next=i,a&&(n.method="next",n.arg=e),!!a}for(var r=this.tryEntries.length-1;r>=0;--r){var s=this.tryEntries[r],o=s.completion;if("root"===s.tryLoc)return a("end");if(s.tryLoc<=this.prev){var c=i.call(s,"catchLoc"),l=i.call(s,"finallyLoc");if(c&&l){if(this.prev<s.catchLoc)return a(s.catchLoc,!0);if(this.prev<s.finallyLoc)return a(s.finallyLoc)}else if(c){if(this.prev<s.catchLoc)return a(s.catchLoc,!0)}else{if(!l)throw new Error("try statement without catch or finally");if(this.prev<s.finallyLoc)return a(s.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var a=this.tryEntries[n];if(a.tryLoc<=this.prev&&i.call(a,"finallyLoc")&&this.prev<a.finallyLoc){var r=a;break}}r&&("break"===t||"continue"===t)&&r.tryLoc<=e&&e<=r.finallyLoc&&(r=null);var s=r?r.completion:{};return s.type=t,s.arg=e,r?(this.method="next",this.next=r.finallyLoc,m):this.complete(s)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),L(n),m}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var i=n.completion;if("throw"===i.type){var a=i.arg;L(n)}return a}}throw new Error("illegal catch attempt")},delegateYield:function(t,n,i){return this.delegate={iterator:M(t),resultName:n,nextLoc:i},"next"===this.method&&(this.arg=e),m}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}})),y={key:null,lang:"en",code:null,location:null,lat:null,lng:null,template:null,iconStyle:"flat",description:!1,icon:!0,iconPath:"images/icons/",iconAnimation:!1,sunTime:!1,today:!0,details:!1,forecast:!1,quarterly:!1,units:{temp:"c",wind:"mps",visibility:"km"},title:{maxTemp:"Max",minTemp:"Min",forecast:"Forecast",quarterly:"Quarterly",details:"Details"},customTemplate:function(t,e){}},x=t(e((function(t){t.exports=function(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t},t.exports.default=t.exports,t.exports.__esModule=!0})));function _(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var g=function(t){o(n,t);var e=_(n);function n(){var t;a(this,n);for(var i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];return t=e.call.apply(e,[this].concat(r)),x(h(t),"apiWeatherData",{}),x(h(t),"apiUrl",""),x(h(t),"successCode",200),x(h(t),"options",{}),x(h(t),"weather",{}),x(h(t),"element",void 0),x(h(t),"days",["Sun","Mon","Tue","Wed","Thu","Fri","Sat"]),x(h(t),"months",["January","February","March","April","May","June","July","August","September","October","November","December"]),x(h(t),"iconIds",{day:"d",night:"n",one:"01",two:"02",three:"03",four:"04",nine:"09",ten:"10",eleven:"11",thirteen:"13",fifty:"50"}),x(h(t),"iconDirectories",{common:"common",day:"day",night:"night"}),x(h(t),"iconFiles",{clear:"clear",cloud:"cloud",mist:"mist",rain:"rain",snow:"snow",storm:"storm"}),t}return r(n,[{key:"weatherTemp",value:function(t){return{current:this.tempFormat(t.temp),min:this.tempFormat(t.temp_min),max:this.tempFormat(t.temp_max)}}},{key:"tempFormat",value:function(t){return"f"===this.options.units.temp.toLowerCase()?Math.round(1.8*(t-273.15)+32)+"°F":"c"===this.options.units.temp.toLowerCase()?Math.round(t-273.15)+"°C":Math.round(t)+"K"}},{key:"windFormat",value:function(t){return"km/h"===this.options.units.wind.toLowerCase()?"".concat(3.6*t.speed," ").concat(this.options.units.wind):"".concat(t.speed," ").concat(this.options.units.wind)}},{key:"visibilityFormat",value:function(t){var e="km"===this.options.units.visibility.toLowerCase()?t/1e3:62137e-8*t;return e=this.isFloat(e)?e.toFixed(2):e,"".concat(e," ").concat(this.options.units.visibility)}},{key:"isFloat",value:function(t){return Number(t)===t&&t%1!=0}},{key:"getToday",value:function(){var t=new Date,e=this.months[t.getMonth()].substring(0,3),n=this.numberSuffix(t.getDate());return"".concat(e," ").concat(n)}},{key:"dateFormat",value:function(t){var e=new Date,n=new Date(t);return e.getDate()===n.getDate()?"Today":this.days[n.getDay()]}},{key:"numberSuffix",value:function(t){var e=t%10,n=t%100;return"".concat(t,1===e&&11===n?"st":2===e&&12===n?"nd":3===e&&13===n?"rd":"th")}},{key:"timeFormat",value:function(t){if("string"==typeof t||t instanceof String){var e=parseInt(t.split(":")[0]);return 0===e?"12 AM":12===e?"12 PM":12<e?"".concat(("0"+(e-12)).slice(-2)," PM"):"".concat(("0"+e).slice(-2)," AM")}var n=new Date(1e3*t),i=n.getHours();i>12&&(i=12-(24-i));var a=n.getMinutes();return a=a.toString(),i=("0"+i).slice(-2),a=("0"+a).slice(-2),"".concat(i,":").concat(a)}},{key:"isRightTime",value:function(t){var e=(new Date).getTime();if(new Date(t).getTime()>=e)return!0}},{key:"indexOfTime",value:function(t){for(var e=0;e<t.length;e++)if(this.isRightTime(t[e].dt_txt))return e}}]),n}((function t(){var e=this;a(this,t),x(this,"isElement",(function(t){return!(!t||"object"!==l(t))&&(void 0!==t.jquery&&(t=t[0]),void 0!==t.nodeType)})),x(this,"getElement",(function(t){return e.isElement(t)?t.jquery?t[0]:t:"string"==typeof t&&t.length>0?document.querySelector(t):null}))}));function w(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var b=function(t){o(n,t);var e=w(n);function n(){var t;a(this,n);for(var i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];return t=e.call.apply(e,[this].concat(r)),x(h(t),"path",""),t}return r(n,[{key:"getSvgCode",value:function(){return fetch(this.path).then((function(t){return t.text()})).then((function(t){return t}))}},{key:"getIcon",value:function(t){return this.path="",this.path+=this.options.iconPath+this.options.iconStyle+"/",-1!==t.indexOf(this.iconIds.eleven)||-1!==t.indexOf(this.iconIds.fifty)?(this.path+=this.iconDirectories.common+"/",-1!==t.indexOf(this.iconIds.eleven)?this.path+=this.iconFiles.storm:this.path+=this.iconFiles.mist):-1!==t.indexOf(this.iconIds.day)?this.path+=this.iconDirectories.day+"/":this.path+=this.iconDirectories.night+"/",-1!==t.indexOf(this.iconIds.one)?this.path+=this.iconFiles.clear:-1!==t.indexOf(this.iconIds.two)||-1!==t.indexOf(this.iconIds.three)||-1!==t.indexOf(this.iconIds.four)?this.path+=this.iconFiles.cloud:-1!==t.indexOf(this.iconIds.nine)||-1!==t.indexOf(this.iconIds.ten)?this.path+=this.iconFiles.rain:-1!==t.indexOf(this.iconIds.thirteen)&&(this.path+=this.iconFiles.snow),this.path+=".svg",this.getSvgCode().then((function(t){return t}))}}]),n}(g),T="ew";function k(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(!n){if(Array.isArray(t)||(n=function(t,e){if(!t)return;if("string"==typeof t)return D(t,e);var n=Object.prototype.toString.call(t).slice(8,-1);"Object"===n&&t.constructor&&(n=t.constructor.name);if("Map"===n||"Set"===n)return Array.from(t);if("Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))return D(t,e)}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var i=0,a=function(){};return{s:a,n:function(){return i>=t.length?{done:!0}:{done:!1,value:t[i++]}},e:function(t){throw t},f:a}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var r,s=!0,o=!1;return{s:function(){n=n.call(t)},n:function(){var t=n.next();return s=t.done,t},e:function(t){o=!0,r=t},f:function(){try{s||null==n.return||n.return()}finally{if(o)throw r}}}}function D(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,i=new Array(e);n<e;n++)i[n]=t[n];return i}function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var L=function(t){o(n,t);var e=O(n);function n(){var t;a(this,n);for(var i=arguments.length,r=new Array(i),s=0;s<i;s++)r[s]=arguments[s];return t=e.call.apply(e,[this].concat(r)),x(h(t),"weatherHTML",void 0),x(h(t),"prefix",T+"-"),x(h(t),"templates",{card:"card",classic:"classic",compact:"compact",full:"full",minimal:"minimal"}),x(h(t),"classes",{flat:t.prefix+"flat-icon",animate:t.prefix+"animate",content:t.prefix+"content",weather:t.prefix+"weather",card:t.prefix+t.templates.card,classic:t.prefix+t.templates.classic,compact:t.prefix+t.templates.compact,full:t.prefix+t.templates.full,minimal:t.prefix+t.templates.minimal}),t}return r(n,[{key:"getTemplate",value:function(){var t=document.createElement("div"),e=this.classes.weather;switch(e+=this.options.iconAnimation?" "+this.classes.animate:"",e+="flat"===this.options.iconStyle?" "+this.classes.flat:"",this.options.template){case this.templates.card:e+=" "+this.classes.card+this.getBgClass(),t.innerHTML=this.cardTemplate();break;case this.templates.classic:e+=" "+this.classes.classic+this.getBgClass(),t.innerHTML=this.classicTemplate();break;case this.templates.compact:e+=" "+this.classes.compact,t.innerHTML=this.compactTemplate();break;case this.templates.full:e+=" "+this.classes.full+this.getBgClass(),t.innerHTML=this.fullTemplate();break;case this.templates.minimal:e+=" "+this.classes.minimal,t.innerHTML=this.minimalTemplate();break;default:e+=" "+this.classes.content,t.innerHTML=this.defaultTemplate()}t.classList=e,this.element.appendChild(t),this.tabClickEvent()}},{key:"cardTemplate",value:function(){var t='<div class="'.concat(this.classes.card,"__item ").concat(this.classes.card,'__item--main">\n <div class="').concat(this.classes.card,'__col">\n ').concat(this.getIconTemplate(),"\n ").concat(this.getTempDescription(),'\n </div>\n <div class="').concat(this.classes.card,'__col">\n ').concat(this.getTempLocDate(),"\n </div>\n </div>");return this.options.quarterly&&(t+='<div class="'.concat(this.classes.card,'__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.quarterly,"</span>\n ").concat(this.getQuarterlyTemplate(),"\n </div>")),this.options.forecast&&(t+='<div class="'.concat(this.classes.card,'__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.forecast,"</span>\n ").concat(this.getForecastTemplate(),"\n </div>")),this.options.details&&(t+='<div class="'.concat(this.classes.card,'__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.details,"</span>\n ").concat(this.getTempTemplate(),"\n ").concat(this.getDetailsTemplate(),"\n </div>")),t}},{key:"classicTemplate",value:function(){var t='<div class="'.concat(this.classes.classic,'__body">\n ').concat(this.getIconTemplate(),"\n ").concat(this.getTempDescription(),'\n <div class="').concat(this.classes.classic,'__body__date">').concat(this.getTempLocDate(),"</div>\n ").concat(this.getTempTemplate());return this.options.details?t+="".concat(this.getDetailsTemplate(),"</div>"):t+="</div>",(this.options.quarterly||this.options.forecast)&&(t+='<div class="'.concat(this.classes.classic,'__foot">\n ').concat(this.getTempTabs(),"\n </div>")),t}},{key:"compactTemplate",value:function(){var t='<div class="'.concat(this.classes.compact,'__main">\n <div class="').concat(this.classes.compact,'__main__head">\n <span class="').concat(this.prefix,'date">').concat(this.weather.today,"</span>\n ").concat(this.getIconTemplate(),"\n </div>\n ").concat(this.getTempDescription(),"\n ").concat(this.getTempTemplate());return this.options.details?t+="".concat(this.getDetailsTemplate(),"</div>"):t+="</div>",(this.options.quarterly||this.options.forecast)&&(t+='<div class="'.concat(this.classes.compact,'__details">\n ').concat(this.getTempTabs(),"\n </div>")),t}},{key:"fullTemplate",value:function(){var t='<div class="'.concat(this.classes.full,'__main">\n ').concat(this.getIconTemplate(),"\n ").concat(this.getTempDescription(),"\n ").concat(this.getTempTemplate(),'\n <div class="').concat(this.classes.full,'__main__date">').concat(this.getTempLocDate(),"</div>\n </div>");return(this.options.quarterly||this.options.forecast||this.options.details)&&(t+='<div class="'.concat(this.classes.full,'__details">'),this.options.quarterly&&(t+='<div class="'.concat(this.classes.full,'__details__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.quarterly,"</span>\n ").concat(this.getQuarterlyTemplate(),"\n </div>")),this.options.forecast&&(t+='<div class="'.concat(this.classes.full,'__details__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.forecast,"</span>\n ").concat(this.getForecastTemplate(),"\n </div>")),this.options.details&&(t+='<div class="'.concat(this.classes.full,'__details__item">\n <span class="').concat(this.prefix,'title">').concat(this.options.title.details,"</span>\n ").concat(this.getDetailsTemplate(),"\n </div>")),t+="</div>"),t}},{key:"minimalTemplate",value:function(){var t='<div class="'.concat(this.classes.minimal,'__main">\n <span class="').concat(this.prefix,'date">').concat(this.weather.today,'</span>\n <span class="').concat(this.prefix,'temp">').concat(this.weather.temp.current,"</span>\n ").concat(this.getTempDescription(),"\n ").concat(this.getTempTemplate(),"\n ").concat(this.getDetailsTemplate(),"\n </div>");return(this.options.quarterly||this.options.forecast)&&(t+='<div class="'.concat(this.classes.minimal,'__details">\n ').concat(this.getTempTabs(),"\n </div>")),t}},{key:"defaultTemplate",value:function(){var t="<span>".concat(this.weather.today,"</span>");return t+=this.options.icon?"&nbsp;".concat(this.weather.icon):"&nbsp;,",t+="&nbsp;<span>".concat(this.weather.temp.current," ").concat(this.weather.location,"</span>")}},{key:"getTempDescription",value:function(){return this.options.description?'<span class="'.concat(this.prefix,'description">').concat(this.weather.description,"</span>"):""}},{key:"getTempLocDate",value:function(){return'<span class="'.concat(this.prefix,'date">').concat(this.weather.today,'</span>\n <span class="').concat(this.prefix,'location">').concat(this.weather.location,"</span>")}},{key:"getIconTemplate",value:function(){return'<div class="'.concat(this.prefix,'main-icon">\n <span class="').concat(this.prefix,'temp">').concat(this.weather.temp.current,"</span>\n ").concat(this.options.icon?'<span class="'.concat(this.prefix,'icon">').concat(this.weather.icon,"</span>"):"","\n </div>")}},{key:"getTempTemplate",value:function(){return'<div class="'.concat(this.prefix,'temp-list">\n <div class="').concat(this.prefix,'temp-list__item">\n <span class="').concat(this.prefix,'temp-list__item__text">').concat(this.options.title.maxTemp,'</span>\n <span class="').concat(this.prefix,'temp-list__item__title">').concat(this.weather.temp.max,'</span>\n </div>\n <div class="').concat(this.prefix,'temp-list__item">\n <span class="').concat(this.prefix,'temp-list__item__text">').concat(this.options.title.minTemp,'</span>\n <span class="').concat(this.prefix,'temp-list__item__title">').concat(this.weather.temp.min,"</span>\n </div>\n </div>")}},{key:"getTempTabs",value:function(){var t='<div class="'.concat(this.prefix,'tab">');return t+=this.options.quarterly?'<a href="javascript:void(0);" class="'.concat(this.prefix,'tab__link" data-tab="').concat(T,'_quarterly">').concat(this.options.title.quarterly,"</a>"):"",t+=this.options.forecast?'<a href="javascript:void(0);" class="'.concat(this.prefix,'tab__link" data-tab="').concat(T,'_forecast">').concat(this.options.title.forecast,"</a>"):"",t+='</div>\n <div class="'.concat(this.prefix,'tab-content">'),t+=this.options.quarterly?'<div id="'.concat(T,'_quarterly" class="').concat(this.prefix,'tab-data">\n ').concat(this.getQuarterlyTemplate(),"\n </div>"):"",t+=this.options.forecast?'<div id="'.concat(T,'_forecast" class="').concat(this.prefix,'tab-data">\n ').concat(this.getForecastTemplate(),"\n </div>\n </div>"):""}},{key:"getQuarterlyTemplate",value:function(){var t,e='<div class="'.concat(this.prefix,'temp-data">'),n=k(this.weather.quarterly);try{for(n.s();!(t=n.n()).done;){var i=t.value;e+='<div class="'.concat(this.prefix,'temp-data__item">\n <div class="').concat(this.prefix,'temp-data__card">\n <span class="').concat(this.prefix,'temp-data__time">').concat(i.time,'</span>\n <span class="').concat(this.prefix,'temp-data__icon">').concat(i.icon,'</span>\n <span class="').concat(this.prefix,'temp-data__temp">').concat(i.temp.current,"</span>\n </div>\n </div>")}}catch(t){n.e(t)}finally{n.f()}return e+="</div>"}},{key:"getForecastTemplate",value:function(){var t,e='<div class="'.concat(this.prefix,'temp-data">'),n=k(this.weather.forecast);try{for(n.s();!(t=n.n()).done;){var i=t.value;e+='<div class="'.concat(this.prefix,'temp-data__item">\n <div class="').concat(this.prefix,'temp-data__card">\n <span class="').concat(this.prefix,'temp-data__day">').concat(i.day,'</span>\n <span class="').concat(this.prefix,'temp-data__icon">').concat(i.icon,'</span>\n <span class="').concat(this.prefix,'temp-data__temp">').concat(i.temp.current,"</span>\n </div>\n </div>")}}catch(t){n.e(t)}finally{n.f()}return e+="</div>"}},{key:"getDetailsTemplate",value:function(){var t='<div class="'.concat(this.prefix,'temp-detail">');return this.options.sunTime&&(t+='<div class="'.concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Sunrise</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.sunrise,'</span>\n </div>\n <div class="').concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Sunset</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.sunset,"</span>\n </div>")),t+='<div class="'.concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Wind speed</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.wind,'</span>\n </div>\n <div class="').concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Humidity</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.humidity,'</span>\n </div>\n <div class="').concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Visibility</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.visibility,'</span>\n </div>\n <div class="').concat(this.prefix,'temp-detail__item">\n <span class="').concat(this.prefix,'temp-detail__title">Pressure</span>\n <span class="').concat(this.prefix,'temp-detail__text">').concat(this.weather.pressure,"</span>\n </div>\n </div>")}},{key:"getBgClass",value:function(){var t=this.apiWeatherData.weather[0].icon,e=" "+this.prefix;return-1!==t.indexOf(this.iconIds.eleven)?e+=this.iconFiles.storm:-1!==t.indexOf(this.iconIds.fifty)?e+=this.iconFiles.mist:-1!==t.indexOf(this.iconIds.day)?e+=this.iconDirectories.day+"-":e+=this.iconDirectories.night+"-",-1!==t.indexOf(this.iconIds.one)?e+=this.iconFiles.clear:-1!==t.indexOf(this.iconIds.two)||-1!==t.indexOf(this.iconIds.three)||-1!==t.indexOf(this.iconIds.four)?e+=this.iconFiles.cloud:-1!==t.indexOf(this.iconIds.nine)||-1!==t.indexOf(this.iconIds.ten)?e+=this.iconFiles.rain:-1!==t.indexOf(this.iconIds.thirteen)&&(e+=this.iconFiles.snow),e}},{key:"tabClickEvent",value:function(){var t=document.querySelectorAll("."+this.prefix+"tab__link"),e=document.querySelectorAll("."+this.prefix+"tab-data"),n="active",i="show";if(t.length){var a=t[0].getAttribute("data-tab"),r=document.querySelector("#"+a);t[0].classList.add(n),r.classList.add(i),t.forEach((function(a){a.addEventListener("click",(function(){if(!a.classList.contains(n)){t.forEach((function(t){t.classList.remove(n)})),e.forEach((function(t){t.classList.remove(i)}));var r=a.getAttribute("data-tab"),s=document.querySelector("#"+r);a.classList.add(n),s.classList.add(i)}}))}))}}}]),n}(b);function F(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var M=function(t){o(h,t);var e,n,s,c,l,u=F(h);function h(){return a(this,h),u.apply(this,arguments)}return r(h,[{key:"initWeatherDate",value:(l=i(v.mark((function t(){return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.todayWeatherData();case 2:if(!this.apiWeatherData.list){t.next=9;break}if(!this.options.forecast){t.next=6;break}return t.next=6,this.forecastWeatherData();case 6:if(!this.options.quarterly){t.next=9;break}return t.next=9,this.quarterlyWeatherData();case 9:this.options.template?this.getTemplate():this.options.customTemplate(this.element,this.weather);case 10:case"end":return t.stop()}}),t,this)}))),function(){return l.apply(this,arguments)})},{key:"todayWeatherData",value:(c=i(v.mark((function t(){return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.weatherData(this.apiWeatherData);case 2:this.weather=t.sent,this.weather.location="".concat(this.apiWeatherData.name,", ").concat(this.apiWeatherData.sys.country),this.options.today&&(this.weather.today=this.getToday()),this.options.sunTime&&this.apiWeatherData.sys.sunrise&&this.apiWeatherData.sys.sunset&&(this.weather.sunrise="".concat(this.timeFormat(this.apiWeatherData.sys.sunrise)," AM"),this.weather.sunset="".concat(this.timeFormat(this.apiWeatherData.sys.sunset)," PM")),this.options.details&&(this.weather.wind=this.windFormat(this.apiWeatherData.wind),this.weather.humidity="".concat(this.apiWeatherData.main.humidity,"%"),this.weather.pressure="".concat(this.apiWeatherData.main.pressure," hPa"),this.weather.visibility=this.visibilityFormat(this.apiWeatherData.visibility));case 7:case"end":return t.stop()}}),t,this)}))),function(){return c.apply(this,arguments)})},{key:"forecastWeatherData",value:(s=i(v.mark((function t(){var e,n,i,a,r;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.apiWeatherData.list,n=this.indexOfTime(e),this.weather.forecast=[],i=n;case 4:if(!(i<e.length)){t.next=14;break}return t.next=7,this.weatherData(e[i]);case 7:a=t.sent,r=e[i].dt_txt.split(" ")[0],a.day=this.dateFormat(r),this.weather.forecast.push(a);case 11:i+=8,t.next=4;break;case 14:case"end":return t.stop()}}),t,this)}))),function(){return s.apply(this,arguments)})},{key:"quarterlyWeatherData",value:(n=i(v.mark((function t(){var e,n,i,a,r,s;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:e=this.apiWeatherData.list,n=this.indexOfTime(e),i=n+8,this.weather.quarterly=[],a=n;case 5:if(!(a<i)){t.next=15;break}return t.next=8,this.weatherData(e[a]);case 8:r=t.sent,s=e[a].dt_txt.split(" ")[1],r.time=this.timeFormat(s),this.weather.quarterly.push(r);case 12:a++,t.next=5;break;case 15:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"weatherData",value:(e=i(v.mark((function t(e){var n;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if((n={}).temp=this.weatherTemp(e.main),this.options.description&&(n.description="".concat(e.weather[0].description.charAt(0).toUpperCase()).concat(e.weather[0].description.slice(1))),!this.options.icon){t.next=6;break}return t.next=6,this.getIcon(e.weather[0].icon).then((function(t){n.icon=t}));case 6:return t.abrupt("return",n);case 7:case"end":return t.stop()}}),t,this)}))),function(t){return e.apply(this,arguments)})}]),h}(L);function E(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var I=function(t){o(c,t);var e,n,s=E(c);function c(){return a(this,c),s.apply(this,arguments)}return r(c,[{key:"weatherApiUrl",value:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0];this.apiUrl="https://api.openweathermap.org/data/2.5/",this.apiUrl+=t?"forecast":"weather",this.apiUrl+="?lang="+this.options.lang,this.options.code?this.apiUrl+="&id="+this.options.code:this.options.location?this.apiUrl+="&q="+this.options.location:this.options.lat&&this.options.lng&&(this.apiURL+="&lat="+this.options.lat+"&lon="+this.options.lng),this.options.key&&(this.apiUrl+="&appid="+this.options.key)}},{key:"getTodayWeather",value:(n=i(v.mark((function t(){var e=this;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.weatherApiUrl(),fetch(this.apiUrl).then((function(t){return t.json()})).then((function(t){parseInt(t.cod)===e.successCode?(e.apiWeatherData=t,e.options.forecast||e.options.quarterly?e.getForecastWeather():e.initWeatherDate()):alert("Message: ",t.message)}));case 2:case"end":return t.stop()}}),t,this)}))),function(){return n.apply(this,arguments)})},{key:"getForecastWeather",value:(e=i(v.mark((function t(){var e=this;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:this.weatherApiUrl(!0),fetch(this.apiUrl).then((function(t){return t.json()})).then((function(t){parseInt(t.cod)===e.successCode?(e.apiWeatherData.list=t.list,e.initWeatherDate()):alert("Message: ",t.message)}));case 2:case"end":return t.stop()}}),t,this)}))),function(){return e.apply(this,arguments)})}]),c}(M);function R(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var n,i=m(t);if(e){var a=m(this).constructor;n=Reflect.construct(i,arguments,a)}else n=i.apply(this,arguments);return f(this,n)}}var S=function(t){o(s,t);var e,n=R(s);function s(t){var e,i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};return a(this,s),(e=n.call(this)).element=e.getElement(t),e.element?(e.options=s.extend(y,i),e.init(),e):f(e,!1)}return r(s,[{key:"init",value:(e=i(v.mark((function t(){return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.getTodayWeather();case 2:case"end":return t.stop()}}),t,this)}))),function(){return e.apply(this,arguments)})}],[{key:"extend",value:function(t,e){var n={};for(var i in t)void 0!==e[i]?n[i]=e[i]:n[i]=t[i];return n}}]),s}(I);return S})); //# sourceMappingURL=easy-weather.min.js.map