-
Notifications
You must be signed in to change notification settings - Fork 43
/
deeplink-to-native-app.min.js
executable file
·1 lines (1 loc) · 5.38 KB
/
deeplink-to-native-app.min.js
1
var NativeAppLauncher=function(a){"use strict";function b(a,b){console.log(a+":"+JSON.stringify(b,null,4))}var c={},d={getAppUri:function(){return"#"},getAppLauncherEl:function(){if(!c.appLauncherElId)throw new Error("Settings does not have valid appLauncherElId");return a("#"+c.appLauncherElId)},getNotSupportedMessage:function(){if(!c.appLauncherElId)throw new Error("Settings does not have valid NotSupportedMessage");return c.notSupportedMessage},getCampaignValue:function(){return c.campaignCode},getAppStoreURI:function(){return"#"}},e=a.extend({},d,{getIntentURI:function(){return"intent://m/#Intent;scheme="+c.appUri+";package="+c.androidAppId+";end"},getAppUri:function(){return c.appUri},getAppStoreURI:function(){var a=this.getCampaignValue()?"&referrer=utm_source%3Dother%26utm_campaign%3D"+this.getCampaignValue():"";return"https://play.google.com/store/apps/details?id="+c.androidAppId+a}}),f=a.extend({},d,{getAppStoreURI:function(){return this.getCampaignValue()?s.appendQueryParameter(c.iOsAppStore,"ct",this.getCampaignValue()):c.iOsAppStore},getUniversalLinkingUrl:function(){return c.universalLinkUrl},getAppUri:function(){if(!c.appUri)throw new Error("Settings does not have valid AppURI");return c.appUri}}),g=function(a){this.strategyParameters=a,this.init=function(){}},h=function(a){this.init=function(){var b=a.getAppLauncherEl(),c=a.getAppUri();b.click(function(a){a.preventDefault(),window.location.reload()}),window.location=c}},i=function(b){g.call(this,b);var c=["pagehide","blur","beforeunload"],d=null,e=function(){clearTimeout(d),d=null,a(window).unbind(c.join(" "))},f=b.getAppLauncherEl();this.init=function(){h(),f.unbind("click").on("click",function(a){a.preventDefault(),h()})};var h=function(){window.location=b.getAppUri(),a(window).bind(c.join(" "),e),d=setTimeout(function(){window.top.location=b.getAppStoreURI()},1500)}},j=function(b){g.call(this,b),this.init=function(){var c=new i(b),d=b.getAppLauncherEl(),e=d.attr("id");a("body").on("click","#"+e,function(a){a.preventDefault(),c.init()})}},k=function(a){g.call(this,a),this.init=function(){var b=a.getAppLauncherEl();b.attr("id");b.attr("href",a.getIntentURI())}},l=function(b){g.call(this,b),this.init=function(){var c=b.getAppLauncherEl().attr("id");a("body").on("click","#"+c,function(a){a.preventDefault();var c=b.getNotSupportedMessage()?b.getNotSupportedMessage():"Not Supported";alert(c)})}},m=function(b){function c(a,b,c){var d=new Date;d.setTime(d.getTime()+1e3*c);var e="; expires="+d.toGMTString();document.cookie=a+"="+b+e+"; path=/"}function d(a){for(var b=a+"=",c=document.cookie.split(";"),d=0;d<c.length;d++){for(var e=c[d];" "==e.charAt(0);)e=e.substring(1,e.length);if(0==e.indexOf(b))return e.substring(b.length,e.length)}return null}function e(a){c(a,"",-1)}g.call(this,b),this.init=function(){function f(){return d(i)>1}function g(){var a=d(i);!a||isNaN(a)?c(i,1,60):c(i,2,60)}b.getUniversalLinkingUrl()||console.log("Error: Universal Linking: Invalid url provided: "+b.getUniversalLinkingUrl());var h=b.getAppLauncherEl(),i="ul-app-detection-flag",j=b.getUniversalLinkingUrl();f()&&(window.location=b.getAppStoreURI(),e()),h.attr("href",j),a(window).on("blur",function(){e(i)}),g(),h.click(function(){g()})}},n=function(){var a,g=d;return p().isIOS?(a="ios",g=f):p().isAndroid?(a="android",g=e):(a="desktop or default",g=d),c.debug&&g&&b("AppLaunchParameter",a),g},o=function(a){var d,e=n();if("cta"==a||void 0==a)d=new j(e);else if("direct"==a)d=new i(e);else if("ul"==a)d=new m(e);else if("notsupported"==a)d=new l(e);else if("directapponly"==a)d=new h(e);else{if("intent_cta"!=a)throw new Error("Deeplinking: Unsupported deeplinking strategy type");d=new k(e)}return c.debug&&d&&b("AppLaunchStrategyType",a),d},p=function(){var a=window.navigator.userAgent.toLowerCase(),b=function(){return c()?parseInt(a.match(/os\s+(\d+)_/)[1],10):!1},c=function(){return/(?:i(?:phone|p(?:o|a)d))/.test(a)},d=function(){return!!a.match(/FBAV/i)},e=function(){return a.indexOf("chrome")>-1},f=function(){var b=a.match(/chrom(e|ium)\/([0-9]+)\./);return b?parseInt(b[2],10):!1},g=function(){return a.indexOf("twitter")>-1},h=function(){return a.indexOf("android")>-1},i=function(){var b=a.match(/android\s([0-9\.]*)/);return b?parseFloat(b[1]):!1},j=function(){return h()&&e()&&l()&&!d()},k=function(){return!d()&&(h()&&m()&&m()<537||f()&&f()<37)},l=function(){return a.indexOf("version")>-1},m=function(){var b=a.match(/AppleWebKit\/([\d.]+)/);return b?parseFloat(b[1]):!1};return{isIOS:c(),iOSVersion:b(),isAndroid:h(),androidVersion:i(),isAndroidStockBrowser:j(),isAndroidNativeBrowser:k(),isFacebook:d(),isChrome:e(),isTwitter:g()}},q=function(){var a=p(),d=new o("cta");return a.isIOS?a.iOSVersion<9?(d=new o("direct"),a.isTwitter&&(d=new o("directapponly"))):(d=new o("direct"),a.isFacebook&&(d=new o("ul"))):a.isAndroid&&(d=new o("intent_cta"),(a.isAndroidNativeBrowser||a.isAndroidStockBrowser)&&(d=new o("notsupported"))),1==c.debug&&b("browser",a),d},r=function(a){c=a,setTimeout(function(){return q().init()},1e3)},s={getQueryString:function(a){void 0==a&&(a=window.location.search),a=a.split("+").join(" ");for(var b,c={},d=/[?&]?([^=]+)=([^&]*)/g;b=d.exec(a);)c[decodeURIComponent(b[1])]=decodeURIComponent(b[2]);return c},appendQueryParameter:function(a,b,c){var d=new RegExp("([?&])"+b+"=.*?(&|$)","i"),e=-1!==a.indexOf("?")?"&":"?";return a.match(d)?a.replace(d,"$1"+b+"="+c+"$2"):a+e+b+"="+c}};return{init:r,browserChecker:p,util:s,androidParameters:e,iOSParameters:f}}(jQuery);