Created
August 25, 2016 17:53
-
-
Save dregenor/527150b4ce2ab71a49883edd233f3b8b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* this module observe parameters of w object . | |
* screenLeft, screenTop, innerWidth, innerHeight | |
* if one of this parameters was changed module dispatch CustomEvent "moveOrResize" | |
*/ | |
module.exports = function(w){ | |
if(!w._moveOrResizeObserver){ | |
w._moveOrResizeObserver = true; | |
var oldX = w.screenLeft, | |
oldY = w.screenTop, | |
oldWidth = w.innerWidth, | |
oldHeight = w.innerHeight; | |
var interval = setInterval(function(){ | |
if(w.closed && interval){ | |
clearInterval(interval); | |
interval = null; | |
return; | |
} | |
if(oldX !== w.screenLeft || oldY !== w.screenTop || oldWidth !== w.innerWidth || oldHeight !== w.innerHeight){ | |
w.dispatchEvent(new CustomEvent('moveOrResize')); | |
} | |
oldX = w.screenLeft; | |
oldY = w.screenTop; | |
oldWidth = w.innerWidth; | |
oldHeight = w.innerHeight; | |
}, 500); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment