Created
June 16, 2015 12:13
-
-
Save robflaherty/fc677b61ac717c13563b to your computer and use it in GitHub Desktop.
Detect iOS 9 iPad Multitask Mode
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
var detectIOSMultitask = function(callback) { | |
var inMultitask; | |
function report(event) { | |
callback({ event: event, width: document.documentElement.clientWidth, height: document.documentElement.clientHeight }); | |
} | |
if (navigator.userAgent.match(/iPad/i) == null) { | |
return; | |
} | |
if (document.documentElement.clientWidth < 768) { | |
inMultitask = true; | |
report('load'); | |
} | |
window.onresize = function() { | |
if (document.visibilityState != 'visible') { | |
inMultitask = false; | |
return; | |
} | |
if (document.documentElement.clientWidth < 768) { | |
if (inMultitask) { | |
report('resize'); | |
} else { | |
inMultitask = true; | |
report('enter'); | |
} | |
} else { | |
inMultitask = false; | |
report('exit'); | |
} | |
} | |
/* | |
* For when Safari is the secondary app and is brought into view in Slide Over mode, which doesn't | |
* always trigger a resize. | |
*/ | |
document.addEventListener('visibilitychange', function() { | |
if (document.visibilityState == 'visible' && document.documentElement.clientWidth == 320) { | |
inMultitask = true; | |
report('enter') | |
} | |
}, false); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment