Skip to content

Instantly share code, notes, and snippets.

@dobleuber
Created April 18, 2019 16:26
Show Gist options
  • Save dobleuber/f096733f61c64cf4c1fdf49569982cfb to your computer and use it in GitHub Desktop.
Save dobleuber/f096733f61c64cf4c1fdf49569982cfb to your computer and use it in GitHub Desktop.
var QueryString = function () {
var query_string = {};
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
query_string[pair[0]] = pair[1];
}
return query_string;
} ();
var ua = navigator.userAgent;
var isAndroid = !!ua.match(/android/gi);
var isiOS = !!ua.match(/iphone|ipad|ipod/gi);
var isWindows = !!ua.match(/windows/gi);
var androidMarket = 'https://play.google.com/store/apps/details?id=com.signnow.android';
var iTunesStore = 'http://itunes.apple.com/us/app/signnow/id489262811?mt=8';
var isAppliance = !(/(signnow\.com$)|(cudasign\.com$)/i.test(window.location.hostname));
var isSignNowProduction = (/(^signnow\.com$)|(^cudasign\.com$)/i.test(window.location.hostname));
function deviceNotSupported() {
alert('Sorry! It appears your device currently isn\'t supported.');
}
function androidNotSupportedForAppliance() {
alert('Sorry! Signing Links from appliances are currently not supported on Android devices.');
}
function downloadTheApp(){
if(isiOS){
window.location = iTunesStore;
}else if (isAndroid){
if(!isAppliance){
window.location = androidMarket;
}else{
androidNotSupportedForAppliance();
}
}else{
deviceNotSupported();
}
}
function getMiddlewareDomain() {
var host = 'https://mw-eval.signnow.com';
return host;
}
function redirectToMobileWeb() {
var documentID = QueryString.document_id;
if (!documentID) return SNError(oldURL, 'We were unable to find the document you\'re trying to access. Feel free to contact [email protected]');
var accessToken = QueryString.access_token;
if (!accessToken) return SNError(accessToken, 'We were unable to verify your account information. Feel free to contact [email protected]');
var redirect_uri = QueryString.redirect_uri;
if (redirect_uri) {
redirect_uri = '&redirect_uri=' + redirect_uri;
} else {
redirect_uri = "";
}
window.location = getMiddlewareDomain() + '/mobileweb/startsigning?document_id=' + documentID + '&access_token=' + accessToken + redirect_uri;
}
function redirectToApp(){
if(isiOS){
if(isSignNowProduction){
window.location = "signnow-private://nologin-signing-link-v2?document_id=" + QueryString.document_id + "&access_token=" + QueryString.access_token + "&redirect_uri=" + QueryString.redirect_uri;
}else{
window.location = "signnow-private://nologin-signing-link-v2?document_id=" + QueryString.document_id + "&access_token=" + QueryString.access_token + "&redirect_uri=" + QueryString.redirect_uri + "&hostname=" + window.location.hostname;
}
}else if(isAndroid){
if(!isAppliance){
window.location = "signnow-private://nologin-signing-link?document_id=" + QueryString.document_id + "&access_token=" + QueryString.access_token + "&redirect_uri=" + QueryString.redirect_uri;
}else{
androidNotSupportedForAppliance();
}
}else{
deviceNotSupported();
}
}
var mobileweb_setting = QueryString.mobileweb;
if (!mobileweb_setting) mobileweb_setting = 'app_only';
if (!isiOS) { //android goes here for the time being
redirectToMobileWeb();
}
if(mobileweb_setting === 'mobileweb_only'){
redirectToMobileWeb();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment