-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvisibilityChanged.min.js
8 lines (8 loc) · 1.11 KB
/
visibilityChanged.min.js
1
2
3
4
5
6
7
8
/**
* Visible State Change for DOM Elements
* https://iprodev.github.io/jquery.visibilityState/
*
* Copyright (c) 2017 iProDev
* Licensed under the MIT license.
*/
(function(c){var f=[],g=0,d=0,h,b,e,l,p=function(){if(0!==g)for(d=g;d--;)b=f[d],e=b.$element.is(":visible"),e!==b.isVisibile&&(b.event?"visible"===b.event&&e?b.$element.triggerHandler("visible"):"hidden"!==b.event||e||b.$element.triggerHandler("hidden"):b.fn.call(b.$element[0],e)),f[d].isVisibile=e},k=function(a,b,c){return!1===m(a,b,c)?(f.push({$element:a,fn:b,isVisibile:null,event:c}),g=f.length,clearInterval(l),l=setInterval(p,100),!0):!1},n=function(a,b,c){a=m(a,b,c);return!1!==a?(f.splice(a,1),g=f.length,!0):a},m=function(a,c,e){h=!1;for(d=g;d--;)if(b=f[d],a[0]===b.$element[0]&&c===b.fn&&e===b.event){h=d;break}return h};c.fn.visibilityState=function(a){return this.each(function(){k(c(this),a)})};c.event.special.visible={add:function(a){k(c(this),a.handler,"visible")},remove:function(a){n(c(this),a.handler,"visible")}};c.event.special.hidden={add:function(a){k(c(this),a.handler,"hidden")},remove:function(a){n(c(this),a.handler,"hidden")}}})(jQuery);