Created
August 6, 2018 16:06
-
-
Save justin-lyon/6d117b5e6f995274e063c488401f31bf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.acumen = (function AppContext(acumen, window) { | |
var hasLightning = function() { | |
return window.$A | |
}; | |
var isMobile = function() { | |
var userAgent = window.navigator.userAgent.toLowerCase(); | |
return (-1 != userAgent.indexOf('mobile')); | |
}; | |
var isSalesforce = function() { | |
return !!window.Sfdc; | |
}; | |
var isLightningForVisualForce = function() { | |
return hasLightning() && isVisualforce(); | |
}; | |
var isSalesforceOne = function() { | |
return hasLightning() && isMobile(); | |
}; | |
var isVisualforce = function() { | |
return isSalesforce() && !window.Sfdc.canvas; | |
}; | |
var isServiceConsole = function() { | |
return window.sforce && window.sforce.console && window.sforce.console.isInConsole(); | |
}; | |
var isLightningExperience = function() { | |
return hasLightning() && !isMobile() && !isVisualforce(); | |
}; | |
var guess = function() { | |
var ctx; | |
if(isServiceConsole()) { | |
ctx = 'console'; | |
} else if(isLightningForVisualForce()) { | |
ctx = 'lc4vf'; | |
} else if(isVisualforce()) { | |
ctx = 'vf'; | |
} else if(isLightningExperience()) { | |
ctx = 'lex'; | |
} else if(isSalesforceOne()) { | |
ctx = 'sf1'; | |
} | |
console.log('acumen.context', ctx); | |
return ctx; | |
}; | |
acumen.context = { | |
guess: guess, | |
isMobile: isMobile, | |
isSalesforce: isSalesforce, | |
isLightningForVisualForce: isLightningForVisualForce, | |
isSalesforceOne: isSalesforceOne, | |
isLightningExperience: isLightningExperience, | |
isVisualforce: isVisualforce, | |
isServiceConsole: isServiceConsole | |
}; | |
return acumen; | |
})(window.acumen || {}, window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment