-
Notifications
You must be signed in to change notification settings - Fork 171
/
browser-deeplink.min.js
10 lines (9 loc) · 1.9 KB
/
browser-deeplink.min.js
1
2
3
4
5
6
7
8
9
10
/**
* browser-deeplink v0.1
*
* Author: Hampus Ohlsson, Nov 2014
* GitHub: http://github.com/hampusohlsson/browser-deeplink
*
* MIT License
*/
!function(n,e){"function"==typeof define&&define.amd?define("deeplink",e(n)):"object"==typeof exports?module.exports=e(n):n.deeplink=e(n)}(window||this,function(n){"use strict";if(n.document&&n.navigator){var e,t={},a={iOS:{},android:{},androidDisabled:!1,fallback:!0,fallbackToWeb:!1,delay:1e3,delta:500},r=function(n,e){var t={};for(var a in n)t[a]=n[a];for(var a in e)t[a]=e[a];return t},o=function(){var n="itms-apps://itunes.apple.com/app/",e=t.iOS.appName,a=t.iOS.appId;return a&&e?n+e+"/id"+a+"?mt=8":null},i=function(){var n="market://details?id=",e=t.android.appId;return e?n+e:null},d=function(){var n={ios:t.iOS.storeUrl||o(),android:t.android.storeUrl||i()};return n[t.platform]},l=function(){var n={ios:t.iOS.fallbackWebUrl||location.href,android:t.android.fallbackWebUrl||location.href};return n[t.platform]},f=function(){return navigator.userAgent.match("Android")},u=function(){return navigator.userAgent.match("iPad")||navigator.userAgent.match("iPhone")||navigator.userAgent.match("iPod")},c=function(){return f()||u()},p=function(n){return function(){var e=t.fallbackToWeb?l():d(),a=t.delay+t.delta;"string"==typeof e&&Date.now()-n<a&&(window.location.href=e)}},s=function(n){t=r(a,n),f()&&(t.platform="android"),u()&&(t.platform="ios")},m=function(n){if(!c())return!1;if(!f()||!t.androidDisabled){if(f()&&!navigator.userAgent.match(/Firefox/)){var a=n.match(/([^:]+):\/\/(.+)$/i);n="intent://"+a[2]+"#Intent;scheme="+a[1],n+=";package="+t.android.appId+";end"}(t.fallback||t.fallbackToWeb)&&(e=setTimeout(p(Date.now()),t.delay));var r=document.createElement("iframe");return r.onload=function(){clearTimeout(e),r.parentNode.removeChild(r),window.location.href=n},r.src=n,r.setAttribute("style","display:none;"),document.body.appendChild(r),!0}};return{setup:s,open:m}}});