UNPKG

@markusantonwolf/ta-foodtrucks

Version:

TA-Foodtrucks plugin shows the next food truck and street food dates in your area based on Craftplaces API. You can customize the endpoints to get all dates for a specific vendor, for a specific city or just for a location you are interested in. The light

1 lines 5.2 kB
"use strict";function _slicedToArray(t,e){return _arrayWithHoles(t)||_iterableToArrayLimit(t,e)||_unsupportedIterableToArray(t,e)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(t,e){if(t){if("string"==typeof t)return _arrayLikeToArray(t,e);var o=Object.prototype.toString.call(t).slice(8,-1);return"Object"===o&&t.constructor&&(o=t.constructor.name),"Map"===o||"Set"===o?Array.from(t):"Arguments"===o||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(o)?_arrayLikeToArray(t,e):void 0}}function _arrayLikeToArray(t,e){(null==e||e>t.length)&&(e=t.length);for(var o=0,i=new Array(e);o<e;o++)i[o]=t[o];return i}function _iterableToArrayLimit(t,e){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t)){var o=[],i=!0,n=!1,r=void 0;try{for(var a,s=t[Symbol.iterator]();!(i=(a=s.next()).done)&&(o.push(a.value),!e||o.length!==e);i=!0);}catch(t){n=!0,r=t}finally{try{i||null==s.return||s.return()}finally{if(n)throw r}}return o}}function _arrayWithHoles(t){if(Array.isArray(t))return t}function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}window.taFoodtrucks=function(){return{initialized:!1,loading:!0,has_dates:!1,empty:!1,dates:[],options:{endpoint:"",minHeight:"",duration:1e3,today:"Today",tomorrow:"Tomorrow",locale:"de-DE",seperator:" - ",suffix:""},init:function(t){var e=this;if(void 0!==t){("object"!==_typeof(t)||t instanceof Array)&&console.warn("TA-Foodtrucks: Options are in wrong type - should be object - options options been used");for(var o=0,i=Object.entries(t);o<i.length;o++){var n=_slicedToArray(i[o],2),r=n[0],a=n[1];this.options[r]=a}}for(var s=0,d=Object.entries(this.$el.dataset);s<d.length;s++){var l=_slicedToArray(d[s],2),u=l[0],h=l[1];void 0!==this.options[u]&&(this.options[u]=h)}if(""===this.options.endpoint)return console.error("TA-Foodtrucks: No endpoint has been defined"),!1;""!==this.options.minHeight&&this.$el.style.setProperty("--ta-foodtrucks-min-height",this.options.minHeight),this.$el.style.setProperty("--ta-foodtrucks-anim-duration",parseInt(this.options.duration)),this.$watch("initialized",function(t){!0===t&&setTimeout(function(){e.loading=!1},parseInt(e.options.duration))}),fetch(this.options.endpoint).then(function(t){return t.json()}).then(function(t){0!==t.result.length&&(e.dates=t.result,e.initialized=!0,e.has_dates=!0)}).catch(function(t){console.warn(t)})},getStartTime:function(t){return new Date(this.dates[t].date.start.date).toLocaleTimeString(this.options.locale,{timeZone:this.dates[t].date.start.timezone,hour:"2-digit",minute:"2-digit"})},getEndTime:function(t){return new Date(this.dates[t].date.end.date).toLocaleTimeString(this.options.locale,{timeZone:this.dates[t].date.end.timezone,hour:"2-digit",minute:"2-digit"})},getTime:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,i=new Date(this.dates[t].date.start.date),n=new Date(this.dates[t].date.end.date),r={timeZone:this.dates[t].date.start.timezone,hour:"2-digit",minute:"2-digit"};null===e&&(e=this.options.seperator),null===o&&(o=this.options.suffix),""!==o&&(o=" "+o);var a=i.toLocaleTimeString(this.options.locale,r);return this.hasDifferentTimezone(t)&&(r.timeZoneName="short",o=""),a+e+n.toLocaleTimeString(this.options.locale,r)+o},hasDifferentTimezone:function(t){return new Date(this.dates[t].date.start.date).toLocaleString(this.options.locale,{timeZone:this.dates[t].date.start.timezone,timeZoneName:"short"})!==new Date(this.dates[t].date.start.date).toLocaleString(this.options.locale,{timeZoneName:"short"})},getTimezone:function(t){return this.hasDifferentTimezone(t)?new Date(this.dates[t].date.start.date).toLocaleString(this.options.locale,{timeZone:this.dates[t].date.start.timezone,year:"2-digit",timeZoneName:"short"}).substring(4):""},getWeekday:function(t){var e=arguments.length>1&&void 0!==arguments[1]&&arguments[1],o=new Date,i=new Date;i.setDate(i.getDate()+1);var n=new Date(this.dates[t].date.start.date),r={timeZone:this.dates[t].date.timezone,weekday:"long"};return!0!==e?n.toLocaleString(this.options.locale,r):n.getDate()===o.getDate()?this.options.today:n.getDate()===i.getDate()?this.options.tomorrow:n.toLocaleString(this.options.locale,r)},getDay:function(t){return new Date(this.dates[t].date.start.date).toLocaleString(this.options.locale,{timeZone:this.dates[t].date.start.timezone,day:"2-digit",month:"2-digit",year:"2-digit"})},getAddress:function(t){return this.dates[t].location.address.street+" "+this.dates[t].location.address.number+", "+this.dates[t].location.address.city},getWhat3WordsLink:function(t){return"https://w3w.co/"+this.dates[t].location.position.what3words},getGoogleMapsLink:function(t){return"https://www.google.com/maps/search/?api=1&query="+this.dates[t].location.position.latitude+","+this.dates[t].location.position.longitude}}};