Skip to content

Instantly share code, notes, and snippets.

@MaxPower15
Created September 11, 2012 21:20
Show Gist options
  • Save MaxPower15/3702165 to your computer and use it in GitHub Desktop.
Save MaxPower15/3702165 to your computer and use it in GitHub Desktop.
Code to preserve time and play/pause state when switching tabs
var lastT = 0;
var downT = 0;
var lastState = "unknown";
wistiaEmbed.bind("timechange", function(t) {
lastT = t;
});
wistiaEmbed.bind("down", function() {
downT = lastT;
});
wistiaEmbed.bind("up", function() {
if (downT > 0) {
wistiaEmbed.time(downT);
if (lastState === "playing") {
wistiaEmbed.play();
} else {
wistiaEmbed.pause();
}
}
});
// this line is pseudo-code
$("#my_tab").beforeLoseFocus(function() {
lastState = wistiaEmbed.state();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment