Created
July 31, 2013 14:42
-
-
Save sansb/6122588 to your computer and use it in GitHub Desktop.
Plugin for making videojs controls hide when user is "idle"
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
(function(){ | |
function timeUpdate(){ | |
if(window.mouseIdleTime !== undefined && | |
window.mouseIdleTime > 2 && | |
!this.idleMouseHide.mouseIdleActive){ | |
this.trigger('mouseidle') | |
} | |
if(this.idleMouseHide.mouseIdleActive && | |
window.mouseIdleTime !== undefined && | |
window.mouseIdleTime < 2){ | |
this.trigger('mouseawake') | |
} | |
} | |
function mouseIdle(){ | |
this.controlBar && this.controlBar.fadeOut() | |
this.shareTools && this.shareTools.fadeOut() | |
this.idleMouseHide.mouseIdleActive = true | |
} | |
function mouseAwake(){ | |
if(this.idleMouseHide.mouseInPlayer){ | |
this.controlBar && this.controlBar.fadeIn() | |
this.shareTools && this.shareTools.fadeIn() | |
this.idleMouseHide.mouseIdleActive = false | |
} | |
} | |
function mouseOver(){ | |
this.idleMouseHide.mouseInPlayer = true | |
} | |
function mouseOut(){ | |
this.idleMouseHide.mouseInPlayer = false | |
} | |
videojs.plugin('idleMouseHide', function(options){ | |
this.on("timeupdate", timeUpdate) | |
this.on("mouseidle", mouseIdle) | |
this.on("mouseawake", mouseAwake) | |
this.on("mouseover", mouseOver) | |
this.on("vjs-mouseout", mouseOut) | |
var player = this; | |
this.controlBar.el().onmouseover = function(){ | |
player.controlBar.addClass('vjs-lock-showing'); | |
} | |
this.controlBar.el().onmouseout = function(){ | |
player.controlBar.removeClass('vjs-lock-showing'); | |
} | |
window.mouseIdleTime = 0; | |
setInterval(function(){ window.mouseIdleTime++ }, 250) | |
window.onmousemove = function(){ window.mouseIdleTime = 0; } | |
this.idleMouseHide.mouseIdleActive = false; | |
this.idleMouseHide.mouseInPlayer = false; | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment