UNPKG

2.68 kBJavaScriptView Raw
1/*!
2 * v-offline v2.2.0
3 * Offline and Online components for Vue
4 * (c) 2021 Vinayak Kulkarni<inbox.vinayak@gmail.com>
5 * Released under the MIT License
6 */
7!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports,require("@vue/composition-api"),require("ping.js")):"function"==typeof define&&define.amd?define(["exports","@vue/composition-api","ping.js"],n):n((e="undefined"!=typeof globalThis?globalThis:e||self).VOffline={},e.vueCompositionApi,e.ping)}(this,(function(e,n,t){"use strict";function o(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var i=o(n),r=o(t);function s(e,n,t,o,i,r,s,a,f,l){"boolean"!=typeof s&&(f=a,a=s,s=!1);const d="function"==typeof t?t.options:t;let u;if(e&&e.render&&(d.render=e.render,d.staticRenderFns=e.staticRenderFns,d._compiled=!0,i&&(d.functional=!0)),o&&(d._scopeId=o),r?(u=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),n&&n.call(this,f(e)),e&&e._registeredComponents&&e._registeredComponents.add(r)},d._ssrRegister=u):n&&(u=s?function(e){n.call(this,l(e,this.$root.$options.shadowRoot))}:function(e){n.call(this,a(e))}),u)if(d.functional){const e=d.render;d.render=function(n,t){return u.call(t),e(n,t)}}else{const e=d.beforeCreate;d.beforeCreate=e?[].concat(e,u):[u]}return t}const a=n.defineComponent({name:"VOffline",props:{onlineClass:{type:String,required:!1,default:""},offlineClass:{type:String,required:!1,default:""},pingUrl:{type:String,required:!1,default:"https://google.com"}},setup(e,{emit:t}){const o=n.ref(navigator.onLine||!1),i=n.ref(["online","offline","load"]),s=n.ref(e.pingUrl||"https://google.com"),a=n.computed((()=>o.value?"string"==typeof e.onlineClass?e.onlineClass:"":"string"==typeof e.offlineClass?e.offlineClass:""));async function f(){const e=new r.default;try{(await e.ping(s.value)||navigator.onLine)&&(o.value=!0,t("detected-condition",o.value))}catch(e){!e&&navigator.onLine||(o.value=!1,t("detected-condition",o.value))}}return i.value.forEach((e=>window.addEventListener(e,f))),n.onBeforeUnmount((()=>{i.value.forEach((e=>window.removeEventListener(e,f)))})),{wrapperClass:a}}});var f=function(){var e=this,n=e.$createElement;return(e._self._c||n)("div",{class:e.wrapperClass},[e._t("default")],2)};f._withStripped=!0;const l=s({render:f,staticRenderFns:[]},undefined,a,undefined,false,undefined,!1,void 0,void 0,void 0);let d=!1;const u={install(e){d||(e.use(i.default),e.component("VOffline",l),d=!0)}};e.VOffline=l,e.default=u,Object.defineProperty(e,"__esModule",{value:!0})}));
8//# sourceMappingURL=v-offline.min.js.map