@apicart/vue-components
Version:
Apicart Vue.Js components for simple e-commerce platform development
8 lines (6 loc) • 9.17 kB
JavaScript
/**
* @apicart/vue-components v1.0.0-alpha7
* (c) 2018-2020 Apicart Company
* Released under the MIT License.
*/
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e(require("@apicart/core-sdk"),require("vue"),require("vue-i18n")):"function"==typeof define&&define.amd?define(["@apicart/core-sdk","vue","vue-i18n"],e):(t=t||self).ApicartVueComponentsTranslator=e(t.Apicart,t.Vue,t.VueI18n)}(this,(function(t,e,o){"use strict";function n(t,e,o,n){return new(o||(o=Promise))((function(i,a){function r(t){try{l(n.next(t))}catch(t){a(t)}}function s(t){try{l(n.throw(t))}catch(t){a(t)}}function l(t){var e;t.done?i(t.value):(e=t.value,e instanceof o?e:new o((function(t){t(e)}))).then(r,s)}l((n=n.apply(t,e||[])).next())}))}function i(t,e){var o,n,i,a,r={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return a={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(a[Symbol.iterator]=function(){return this}),a;function s(a){return function(s){return function(a){if(o)throw new TypeError("Generator is already executing.");for(;r;)try{if(o=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return r.label++,{value:a[1],done:!1};case 5:r.label++,n=a[1],a=[0];continue;case 7:a=r.ops.pop(),r.trys.pop();continue;default:if(!(i=r.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){r=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){r.label=a[1];break}if(6===a[0]&&r.label<i[1]){r.label=i[1],i=a;break}if(i&&r.label<i[2]){r.label=i[2],r.ops.push(a);break}i[2]&&r.ops.pop(),r.trys.pop();continue}a=e.call(t,r)}catch(t){a=[6,t],n=0}finally{o=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,s])}}}t=t&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t,e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e,o=o&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o;var a={category:{id:"category",showCategories:"Show categories"},checkout:{title:"Checkout",validation:{title:"Please correct the following error(s):",emptyCart:"Your cart is empty. You cannot create an order without adding any products.",missingPaymentMethod:"You must select payment method.",missingShippingMethod:"You must select shipping method."},steps:{continueShopping:"Continue shopping",cartOverview:"Cart overview",paymentAndDelivery:"Payment & Delivery",contactInformation:"Contact information",finishOrder:"Finish order"},summary:{title:"Order summary",paymentMethod:"Payment method",paymentMethodNotSelected:"Not selected",shippingMethod:"Shipping method",shippingMethodNotSelected:"Not selected",taxBase:"Tax base",vat:"Vat",totalPrice:"Total price"},cartOverview:{id:"cart-overview",title:"Cart Overview",taxBase:"Tax Base",vat:"Vat",totalPrice:"Total Price",emptyCart:"Your cart is empty."},contactInformationForm:{id:"contact-information",billing:{id:"billing-information",title:"Billing Information",email:"E-mail",firstName:"Name",lastName:"Surname",town:"Town",zip:"Zip",streetAndNumber:"Street and number"},shipping:{id:"shipping-information",title:"Shipping Information",email:"E-mail",firstName:"Name",lastName:"Surname",company:"Company",town:"Town",zip:"Zip",streetAndNumber:"Street and number"},validation:{requiredFields:"You must fill all contact information fields with the star (*) symbol."},fillShippingInfoButton:"Fill shipping info",requiredFields:"Fields with <strong>*</strong> are required",finishOrderButton:"Finish order"}},buyButton:"Add to cart",cartDialog:{id:"cart-dialog",title:"Cart updated"},cartDropdown:{id:"cart-dropdown",emptyCart:"Your cart is empty.",toggleButton:"Cart",itemsCount:"Items count",totalPrice:"Total price",button:"Finish order"},dialog:{okButton:"Ok"},loader:{loading:"Loading..."},orderDialog:{id:"order-dialog",order:{success:{title:"Order successfully created!",text:"Your order with variable symbol <strong>{variableSymbol}</strong> and total price <strong>{totalPrice}</strong> has been successfully created.<br>Check your e-mail for recapitulation."},error:{title:"Something terribly wrong happened",text:"We are sorry but your order could not be created.<br>Please contact us."}},payment:{success:{title:"Payment successful!",text:"Your payment for an order with variable symbol <strong>{variableSymbol}</strong> with total amount of <strong>{totalPrice}</strong> was successfully made."},error:{title:"An error occured during payment",text:'Your payment was not made because an error occurred. Please contact us.<br>Error message "{error}".'}},closeButton:{ok:"Ok",close:"Close",pay:"Go to payment"}},paymentMethodsList:{id:"payment-methods",methodsNotFound:"No payment methods found."},shippingMethodsList:{id:"shipping-methods",methodsNotFound:"No shipping methods found."}};return e.use(o),new(function(){function e(){var e=this;this._config={actualLocale:null,fallbackLocale:"en",localization:{},localizationFilesUrl:"https://cdn.jsdelivr.net/npm/@apicart/web-components-localization@1.0.0-alpha7/localization",currencyFormats:{en:{currency:{style:"currency",currency:"EUR",currencyDisplay:"symbol",code:"EUR"}}}},this._i18n=null,this._loadedLanguages=["en"],this._processedLanguageFiles={},this._downloadUrlsWithError=[],this._loadingLanguagePromise=null,this._configurationPromises=null,this.configure(),t.Utils.EventDispatcher.addListener("apicart-vueComponentsTranslator-configure","apicart:configure",(function(){e.configure()}))}return e.prototype.configure=function(e){return void 0===e&&(e=null),n(this,void 0,void 0,(function(){var o,n,a;return i(this,(function(i){switch(i.label){case 0:return[4,this._configurationPromises];case 1:return i.sent(),e=e||t.getConfigParameter("vueComponentsTranslator")||{},this._config=t.Utils.Objects.merge(this._config,e),this._config.actualLocale||(this._config.actualLocale=this.detectLocale()),a=(n=o=[]).push,[4,this.loadLocalizationFiles(this._config.actualLocale)];case 2:return a.apply(n,[i.sent()]),this._config.localization&&o.push(this.addLocalization(this._config.localization)),this._configurationPromises=Promise.all(o),[4,this._configurationPromises];case 3:return i.sent(),this._config.currencyFormats&&this.addNumberFormat(this._config.currencyFormats),[2]}}))}))},e.prototype.getActualCurrencyConfig=function(){var t=void 0===this.getI18n().numberFormats[this.getActualLocale()]?this.getI18n().numberFormats[this.getFallbackLocale()]:this.getI18n().numberFormats[this.getActualLocale()];return void 0===t?{}:t.currency},e.prototype.getActualLocale=function(){return this.getI18n().locale},e.prototype.getFallbackLocale=function(){return this.getI18n().fallbackLocale?this.getI18n().fallbackLocale:this._config.fallbackLocale},e.prototype.getI18n=function(){if(!this._i18n){var e=t.Storage.getItem("apicart-localization")||{};e[this._config.fallbackLocale]=a,this._i18n=new o({locale:this.detectLocale(),fallbackLocale:this._config.fallbackLocale,messages:e,numberFormats:this._config.currencyFormats||this._config.defaultCurrencyFormats})}return this._i18n},e.prototype.loadLocalizationFiles=function(t,e){return void 0===e&&(e=null),n(this,void 0,void 0,(function(){return i(this,(function(o){switch(o.label){case 0:return[4,this._loadingLanguagePromise];case 1:return o.sent(),this._loadingLanguagePromise=this.downloadLocalizationFilesContent(t,e||this._config.localizationFilesUrl+"/"+t+".json"),[4,this._loadingLanguagePromise];case 2:return o.sent(),[2,this.setI18nLanguage(t)]}}))}))},e.prototype.addLocalization=function(e){var o=this;t.Utils.Loops.forEach(e,(function(t,e){"string"==typeof t?o.loadLocalizationFiles(e,t):o.mergeLocaleMessages(e,t)}))},e.prototype.addNumberFormat=function(e){var o=this;t.Utils.Loops.forEach(e,(function(t,e){o.getI18n().mergeNumberFormat(e,t)}))},e.prototype.downloadLocalizationFilesContent=function(e,o){return n(this,void 0,void 0,(function(){var n,a,r;return i(this,(function(i){switch(i.label){case 0:return this._loadedLanguages.includes(e)?[2,!0]:this._downloadUrlsWithError.includes(o)?[2,!1]:(o in this._processedLanguageFiles||(this._processedLanguageFiles[o]=t.Utils.Ajax.get(o)),[4,this._processedLanguageFiles[o]]);case 1:return n=i.sent(),(a=n&&t.Utils.Objects.isObject(n.data))?((r={})[e]=n.data,t.Storage.updateItem("apicart-localization",r),this.mergeLocaleMessages(e,n.data)):(t.Utils.Console.error('Localization file "'+o+'" could not be loaded.'),this._downloadUrlsWithError.push(o)),this._loadedLanguages.push(e),[2,a]}}))}))},e.prototype.setI18nLanguage=function(t){return this.getI18n().locale=t,this.isInBrowser()&&document.querySelector("html").setAttribute("lang",t),t},e.prototype.isInBrowser=function(){return"undefined"!=typeof window&&"undefined"!=typeof document},e.prototype.detectLocale=function(){if(!this.isInBrowser())return this._config.fallbackLocale;var t=document.documentElement.getAttribute("lang");return t||(navigator.language||window.navigator.userLanguage)},e.prototype.mergeLocaleMessages=function(e,o){this.getI18n().mergeLocaleMessage(e,o),t.Utils.EventDispatcher.dispatchEvent("apicart:translations:updated")},e}())}));