UNPKG

begiresh

Version:

A mobile application smart banner for Iranian markets

13 lines (12 loc) 5.8 kB
(function(l){"object"===typeof exports&&"undefined"!==typeof module?module.exports=l():"function"===typeof define&&define.amd?define([],l):("undefined"!==typeof window?window:"undefined"!==typeof global?global:"undefined"!==typeof self?self:this).Begiresh=l()})(function(){return function a(g,e,f){function d(c,k){if(!e[c]){if(!g[c]){var h="function"==typeof require&&require;if(!k&&h)return h(c,!0);if(b)return b(c,!0);h=Error("Cannot find module '"+c+"'");throw h.code="MODULE_NOT_FOUND",h;}h=e[c]={exports:{}}; g[c][0].call(h.exports,function(b){var f=g[c][1][b];return d(f?f:b)},h,h.exports,a,g,e,f)}return e[c].exports}for(var b="function"==typeof require&&require,c=0;c<f.length;c++)d(f[c]);return d}({1:[function(a,g,e){function f(d,b){return b.querySelector(d)}e=g.exports=function(d,b){b=b||document;return f(d,b)};e.all=function(d,b){b=b||document;return b.querySelectorAll(d)};e.engine=function(d){if(!d.one)throw Error(".one callback required");if(!d.all)throw Error(".all callback required");f=d.one;e.all= d.all;return e}},{}],2:[function(a,g,e){e=g.exports=function(f){f||(f={});"string"===typeof f&&(f={cookie:f});void 0===f.cookie&&(f.cookie="");return{get:function(d){for(var b=f.cookie.split(/;\s*/),c=0;c<b.length;c++){var a=b[c].split("=");if(unescape(a[0])===d)return unescape(a[1])}},set:function(d,b,c){c||(c={});d=escape(d)+"="+escape(b);c.expires&&(d+="; expires="+c.expires);c.path&&(d+="; path="+escape(c.path));return f.cookie=d}}};"undefined"!==typeof document&&(a=e(document),e.get=a.get,e.set= a.set)},{}],3:[function(a,g,e){a=a("has-dom");g.exports=a()?document:null},{"has-dom":4}],4:[function(a,g,e){g.exports=function(){return"undefined"!==typeof window&&"undefined"!==typeof document&&"function"===typeof document.createElement}},{}],5:[function(a,g,e){g.exports=function(d){for(var b=1;b<arguments.length;b++){var c=arguments[b],a;for(a in c)f.call(c,a)&&(d[a]=c[a])}return d};var f=Object.prototype.hasOwnProperty},{}],6:[function(a,g,e){g.exports.track=function(a){var d=a.category,b=a.action; a=a.label;ga&&ga("send",{hitType:"event",eventCategory:d,eventAction:b,eventLabel:a})}},{}],7:[function(a,g,e){var f=a("xtend/mutable"),d=a("component-query"),b=a("get-doc"),c=a("cookie-cutter"),m=a("./analytics"),k=navigator.userAgent||navigator.vendor||window.opera,h=(navigator.language||navigator.userLanguage||navigator.browserLanguage).slice(0,2)||"fa",q=Number(new Date),n=b&&b.documentElement,r={googlePlay:{name:"\u06af\u0648\u06af\u0644\u200c\u067e\u0644\u06cc",appMeta:"google-play-app",getStoreLink:function(){return"http://play.google.com/store/apps/details?id="+ this.appId+"&hl="+this.options.storeLang}},cafeBazaar:{name:"\u06a9\u0627\u0641\u0647\u200c\u0628\u0627\u0632\u0627\u0631",appMeta:"cafe-bazaar-app",getStoreLink:function(){return"https://cafebazaar.ir/app/"+this.appId+"/?l="+this.options.storeLang}},myket:{name:"\u0645\u0627\u06cc\u06a9\u062a",appMeta:"myket-app",getStoreLink:function(){return"https://myket.ir/app/"+this.appId+"/?lang="+this.options.storeLang}}},p=["android-touch-icon","apple-touch-icon-precomposed","apple-touch-icon"];a=function(a){this.options= f({},{price:"\u0631\u0627\u06cc\u06af\u0627\u0646",icon:"",daysHidden:15,daysReminder:90,storeLang:h,store:"googlePlay",button:"\u0628\u06af\u06cc\u0631\u0634",theme:"default",force:!1,onDownload:function(){},onClose:function(){},appStoreLanguage:null},a||a||{});null!=this.options.appStoreLanguage&&(this.options.storeLang=this.options.appStoreLanguage);!/windows phone/i.test(k)&&/android/i.test(k)&&(this.type="android");a=!this.type;var b=navigator.standalone,d=c.get("begiresh-closed"),e=c.get("begiresh-installed"); if(this.options.force||!(a||b||d||e))f(this,r[this.options.store]),this.parseAppId()&&(this.create(),this.show())};a.prototype={constructor:a,create:function(){var a=this.getStoreLink(),c=this.options.price+" \u062f\u0631 "+this.name,f;this.options.icon?f=this.options.icon:f=this.getIcon();var e=b.createElement("div");e.className="begiresh";e.classList.add("theme-"+this.options.theme);e.innerHTML='<div class="begiresh-container"><a href="javascript:void(0);" class="begiresh-close"></a><div class="begiresh-info"><span class="begiresh-icon" style="background-image: url('+ f+')"></span><div class="begiresh-meta"><span class="begiresh-title">'+this.options.title+'</span><span class="begiresh-author">'+this.options.author+'</span><span class="begiresh-store">'+c+'</span></div></div><a href="'+a+'" class="begiresh-download"><span class="begiresh-download-text">'+this.options.button+"</span></a></div>";b.body?b.body.appendChild(e):b&&b.addEventListener("DOMContentLoaded",function(){b.body.appendChild(e)});d(".begiresh-download",e).addEventListener("click",this.install.bind(this), !1);d(".begiresh-close",e).addEventListener("click",this.close.bind(this),!1)},hide:function(){n.classList.remove("begiresh-show")},show:function(){n.classList.add("begiresh-show")},close:function(){this.options.onClose.call();this.hide();c.set("begiresh-closed","true",{path:"/",expires:this.getExpirationDate(this.options.daysHidden)});m.track({category:"begiresh",action:"click",label:"close"})},install:function(){this.options.onDownload.call();this.hide();c.set("begiresh-installed","true",{path:"/", expires:this.getExpirationDate(this.options.daysReminder)});m.track({category:"begiresh",action:"click",label:"install"})},parseAppId:function(){var a=d('meta[name="'+this.appMeta+'"]');if(a)return this.appId=/app-id=([^\s,]+)/.exec(a.getAttribute("content"))[1]},getExpirationDate:function(a){return new Date(q+864E5*a)},getIcon:function(){for(var a=0;a<p.length;a++){var b=d('link[rel="'+p[a]+'"]');if(b)return b.getAttribute("href")}}};g.exports=a},{"./analytics":6,"component-query":1,"cookie-cutter":2, "get-doc":3,"xtend/mutable":5}]},{},[7])(7)});