Use timeout for window resize, to prevent js spam

This commit is contained in:
Jay Wood
2014-12-08 10:19:48 -05:00
parent 513dfeb777
commit f2b2d8d2e6
2 changed files with 8 additions and 4 deletions

View File

@ -21,6 +21,7 @@ window.cwv3 = ( function( window, document, $ ){
max_percent_width : 50,
max_percent_height : 50,
};
app.timeout = '';
};
app.init = function(){
@ -29,9 +30,12 @@ window.cwv3 = ( function( window, document, $ ){
// Register handlers
$( 'body' ).on( 'click', '.cwv3_enter', app.enter_handler );
$( 'body' ).on( 'click', '.cwv3_exit', app.exit_handler );
$( window ).resize( app.center_dialog );
// Don't resize EVERY time, set it to an interval of half a second
$( window ).resize( function(){
clearTimeout( app.timeout );
app.timeout = setTimeout( app.center_dialog, 500 );
});
if( app.cookie_name ){
// We need to set a cookie, so show the dialog.