Last active
August 29, 2015 13:57
Revisions
-
uhtred revised this gist
Mar 25, 2014 . 1 changed file with 5 additions and 3 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -4,13 +4,13 @@ function waitFor ( options ) { options = $.extend( {}, { callback: function(){}, condition: function(){ return true }, interval: 100 }, options); options.intervalId = setInterval(function() { if( options.condition() ) { clearInterval( options.intervalId ); options.callback(); @@ -21,7 +21,9 @@ function waitFor ( options ) { @Sample waitFor({ condition: function(){ return $( '#id' ).length }, callback: function(){ $( '#id' ).text( 'test' ); }, -
uhtred created this gist
Mar 24, 2014 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ @Problem: When I have no control on some ajax or generated html and I need to wait for them. @Solution: Set an interval to check my conditions and them execute a callback. function waitFor ( options ) { options = $.extend( {}, { callback: function(){}, condition: true, interval: 100 }, options); options.intervalId = setInterval(function() { if( options.condition ) { clearInterval( options.intervalId ); options.callback(); } }, options.interval ); } @Sample waitFor({ condition: $( '#id' ).length, callback: function(){ $( '#id' ).text( 'test' ); }, interval: 200 }); Suggestions??