Search Results

Search found 541 results on 22 pages for 'settimeout'.

Page 1/22 | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Mock the window.setTimeout in a Jasmine test to avoid waiting

    - by Aligned
    Originally posted on: http://geekswithblogs.net/Aligned/archive/2014/08/21/mock-the-window.settimeout-in-a-jasmine-test-to-avoid-waiting.aspxJasmine has a clock mocking feature, but I was unable to make it work in a function that I’m calling and want to test. The example only shows using clock for a setTimeout in the spec tests and I couldn’t find a good example. Here is my current and slightly limited approach.   If we have a method we want to test: var test = function(){ var self = this; self.timeoutWasCalled = false; self.testWithTimeout = function(){ window.setTimeout(function(){ self.timeoutWasCalled = true; }, 6000); }; }; Here’s my testing code: var realWindowSetTimeout = window.setTimeout; describe('test a method that uses setTimeout', function(){ var testObject; beforeEach(function () { // force setTimeout to be called right away, no matter what time they specify jasmine.getGlobal().setTimeout = function (funcToCall, millis) { funcToCall(); }; testObject = new test(); }); afterEach(function() { jasmine.getGlobal().setTimeout = realWindowSetTimeout; }); it('should call the method right away', function(){ testObject.testWithTimeout(); expect(testObject.timeoutWasCalled).toBeTruthy(); }); }); I got a good pointer from Andreas in this StackOverflow question. This would also work for window.setInterval. Other possible approaches: create a wrapper module of setTimeout and setInterval methods that can be mocked. This can be mocked with RequireJS or passed into the constructor. pass the window.setTimeout function into the method (this could get messy)

    Read the article

  • How to pause a setTimeout call ?

    - by Pablo
    Im using jQuery and working on a notification system for my site. The notifications automatically fadeout using the setTimeout function. How can i stop the timer of the setTimeout call? For example i would like to pause the setTimeout call while the mouse is over the notification and continue the count down mouseout... I googled "pause setTimeout" with no luck. Im currently clearing the setTimeout call with clearTimeout and at same time fading out the notification on mouseout but it would be nice to have that pause effect. Any ideas?

    Read the article

  • Use of "setTimeout()" in my jQuery Expression

    - by Aaron Salazar
    I'm trying to add the JavaScript function setTimeout() to my jQuery expression. Without the setTimeout() my function loads a partial view with updated information when I enter text into my textbox. But, it loads the information with every keystroke. My logic is that if I can put in a timer then when the user stops typing, a second later the data is updated. As you can see I tried to put a setTimer() in but it doesn't seem to be working. $(function() { $('#DocId').live('keyup', function() { setTimeout(var styleValue = $(this).val(); $('#tableContent').load( '/CurReport/TableResults', { style: $(this).val()}), 1000); }), }); Thank you, Aaron

    Read the article

  • setTimeout(fun) with a single argument

    - by Elazar Leibovich
    The HTML5 specifications states that setTimeout can be run without the additional "timeout" argument which is supposed to say after how many milliseconds will the function "handler" be scheduled. handle = window . setTimeout( handler [, timeout [, arguments ] ] ) Schedules a timeout to run handler after timeout milliseconds. Any arguments are passed straight through to the handler. However, I failed to find anywhere which explains what happens when no "timeout" time period is set. An example usage is, the animation implementation int the Raphael library. animationElements[length] && win.setTimeout(animation);

    Read the article

  • document.onclick settimeout function javascript help

    - by Jamex
    Hi, I have a document.onclick function that I would like to have a delay. I can't seem to get the syntax right. my original code is <script type="text/javascript"> document.onclick=check; function check(e){do something} I tried the below, but that code is incorrect, the function did not execute and nothing happened. <script type="text/javascript"> document.onclick=setTimeout("check", 1000); function check(e){do something} I tried the next set, the function got executed, but no delay. <script type="text/javascript"> setTimeout(document.onclick=check, 1000); function check(e){do something} what is the correct syntax for this code. TIA Edit: The solutions were all good, my problem was that I use the function check to obtain the id of the element being clicked on. But after the delay, there is no "memory" of what was being clicked on, so the rest of the function does not get executed. Jimr wrote the short code to preserve clicked event. The code that is working is // Delay execution of event handler function "f" by "time" ms. document.onclick = makeDelayedHandler(check, 250); function makeDelayedHandler( f, time) { return function( e ) {setTimeout(function() {f( e );}, time ); }; } function check(e){ var click = (e && e.target) || (event && event.srcElement); . . . Thank you all.

    Read the article

  • setTimeout in javascript not giving browser 'breathing room'

    - by C Bauer
    Alright, I thought I had this whole setTimeout thing perfect but I seem to be horribly mistaken. I'm using excanvas and javascript to draw a map of my home state, however the drawing procedure chokes the browser. Right now I'm forced to pander to IE6 because I'm in a big organisation, which is probably a large part of the slowness. So what I thought I'd do is build a procedure called distributedDrawPolys (I'm probably using the wrong word there, so don't focus on the word distributed) which basically pops the polygons off of a global array in order to draw 50 of them at a time. This is the method that pushes the polygons on to the global array and runs the setTimeout: for (var x = 0; x < polygon.length; x++) { coordsObject.push(polygon[x]); fifty++; if (fifty > 49) { timeOutID = setTimeout(distributedDrawPolys, 5000); fifty = 0; } } I put an alert at the end of that method, it runs in practically a second. The distributed method looks like: function distributedDrawPolys() { if (coordsObject.length > 0) { for (x = 0; x < 50; x++) { //Only do 50 polygons var polygon = coordsObject.pop(); var coordinate = polygon.selectNodes("Coordinates/point"); var zip = polygon.selectNodes("ZipCode"); var rating = polygon.selectNodes("Score"); if (zip[0].text.indexOf("HH") == -1) { var lastOriginCoord = []; for (var y = 0; y < coordinate.length; y++) { var point = coordinate[y]; latitude = shiftLat(point.getAttribute("lat")); longitude = shiftLong(point.getAttribute("long")); if (y == 0) { lastOriginCoord[0] = point.getAttribute("long"); lastOriginCoord[1] = point.getAttribute("lat"); } if (y == 1) { beginPoly(longitude, latitude); } if (y > 0) { if (translateLongToX(longitude) > 0 && translateLongToX(longitude) < 800 && translateLatToY(latitude) > 0 && translateLatToY(latitude) < 600) { drawPolyPoint(longitude, latitude); } } } y = 0; if (zip[0].text != targetZipCode) { if (rating[0] != null) { if (rating[0].text == "Excellent") { endPoly("rgb(0,153,0)"); } else if (rating[0].text == "Good") { endPoly("rgb(153,204,102)"); } else if (rating[0].text == "Average") { endPoly("rgb(255,255,153)"); } } else { endPoly("rgb(255,255,255)"); } } else { endPoly("rgb(255,0,0)"); } } } } Ugh I don't know if that is properly formatted, I ended up with an extra bracket < So I thought the setTimeout method would allow the site to draw the polygons in groups so the users would be able to interact with the page while it was still drawing. What am I doing wrong here?

    Read the article

  • javascript setTimeout() first argument: expression error

    - by Jonah
    function Timer() { this.initialTime = 0; this.timeStart = null; this.getTotalTime = function() { timeEnd = new Date(); diff = timeEnd.getTime() - this.timeStart.getTime(); return diff+this.initialTime; }; this.formatTime = function() { interval = new Date(this.getTotalTime()); return interval.getHours() + ":" + interval.getMinutes() + ":" + interval.getSeconds(); }; this.start = function() { this.timeStart = new Date(); setTimeout("this.updateTime()", 1000); }; this.updateTime = function() { alert(this.formatTime()); setTimeout("this.updateTime()", 1000); }; } timer = new Timer(); timer.start(); I am getting an error: this.updateTime is not a function Any ideas? Thanks

    Read the article

  • Simple nested setTimeout() only runs once (JavaScript)

    - by danielfaraday
    For some reason my galleryScroll() function only runs once, even though the function calls itself using setTimeout(). I'm thinking the issue may be related to scope, but I'm not sure: http://jsfiddle.net/CYEBC/2/ $(document).ready(function() { var x = $('#box').offset().left; var y = $('#box').offset().top; galleryScroll(); function galleryScroll() { x = x + 1; y = y + 1; $('#box').offset({ left: x, top: y }); setTimeout('galleryScroll()', 100); } });? The HTML: <html> <head> </head> <body> <div id="box"> </div> </body> </html>

    Read the article

  • HTML5 audio object doesn't play on iPad (when called from a setTimeout)

    - by Dan Halliday
    I have a page with a hidden <audio> object which is being started and stopped using a custom button via javascript. (The reason being I want to customise the button, and that drawing an audio player seems to destroy rendering performance on iPad anyway). A simplified example (in coffeescript): // Works fine on all browsers constructor: (@_button, @_audio) -> @_button.on 'click', @_play // Bind button's click event with jQuery _play: (e) => @_audio[0].play() // Call play() on audio element The audio plays fine when triggered from a function bound to a click event, but I actually want an animation to complete before the file plays so I put .play() inside a setTimeout. However I just can't get this to work: // Will not play on iPad constructor: (@_button, @_audio) -> @_button.on 'click', @_play // Bind button's click event with jQuery _play: (e) => setTimeout (=> // Declare a 300ms timeout @_audio[0].play() // Call play() on audio element ), 300 I've checked that @_audio (this._audio) is in scope and that its play() method exists. Why doesn't this work on iPad?

    Read the article

  • setTimeout() not executing

    - by Ben Shelock
    I've got this simple function which displays a message to the user. If I add the timeout parameter it will slide back up automatically if not the user has to click it to get rid. But the timeout bit isn't working. function feedback(text, timeout){ $('#feedback').text(text).slideDown('fast'); $('#feedback').click(function(){ $(this).slideUp(); }); if(timeout){ setTimeout(function(){ $('#feedback').slideup(); }, timeout); } }

    Read the article

  • simple jquery dropdown - clearTimeout, setTimeout issues

    - by user210757
    HTML: <ul class="topnav"> <li><a href="#"><span>One</span></a></li> <li><a href="#"><span>Two</span></a></li> <li> <li><a href="#"><span>Three</span></a></li> <ul class="subnav"> <li><a href="#">A</a></li> <li><a href="#">B</a></li> <li><a href="#">C</a></li> </ul> </li> </ul> jquery: var timeout = null; $(document).ready(function() { $("ul.topnav li").mouseover(function() { if (timeout) clearTimeout(timeout); $(this).find("ul.subnav").slideDown('fast').show(); }).mouseout(function() { timeout = setTimeout(closemenu, 500); }); // sub menu mouseovers keep dropdown open $("ul.subnav li").mouseover(function() { if (timeout) clearTimeout(timeout); } ).mouseout(function() { timeout = setTimeout(closemenu, 500); // alert(timeout); }); // any click closes $(document).click(closemenu); }); // Closes all open menus function closemenu() { $('ul.subnav:visible').hide(); if (timeout) clearTimeout(timeout); } I'm having issues with timeout. In use, if i mouseover "Three", the dropdown stays out forever. if i mouseover "A", dropdown will stay out forever, but if I mouseover "B" or anything lower, the menu will close on me. if you uncomment "// alert(timeout);" it gets there for B, (and A) but timeout will have a value. why is this? i thought clearTimeout would null the timeout variable?

    Read the article

  • OnmouseMove not work with SetTimeOut and Alerts in Chome

    - by Diogo Fernandes
    What's wrong with this code? It works in IE and FireFox, but Chrome does not work. The idea is that the function fnTimeOut will be triggered in 5 seconds after onmousemove. It´s ok. But when, in Chrome, I click on the button "ok" to function fnAlert is triggered instantly. It should be shot just 5 seconds after I move the mouse ... help me please. <input type="button" onclick="alert(1);" value="ok"> <script> document.onmousemove = fnTimeOut; var t = null; function fnAlert() { alert(2); } function fnTimeOut() { clearTimeout( t ); t = setTimeout( fnAlert, 5000 ); } </script>

    Read the article

  • SetTimeout() and ClearTimeout() to stop freezing of IE8 and dialog aobut scripts overruning

    - by igl00
    I have some 3rd party software where i can open nsites and run javascript. Because some sites make me stack overflow i ussed the trick wih Registry to modify Styles WRAD to FFFFFF. Still some sites may do stack overflow due to DOM. I thought on start of running each site i would do javascript: setTimeout("window.status='one';",10000); then on then end i would like to clear it - my question is how to if this doesnt have any actual id? Will the usual clearTimeout() without anything inside do it fine?

    Read the article

  • using javascript setTimeout to see if div has loaded

    - by Matt
    I'm loading remote data using dynamic script tags and JSON. the remote page that I'm displaying on my website has a div in it that I use to load content into. The problem is the javascript functions do not see the div as the page loads because it is remote data. if I set a timeout of about 300 it usually works and my javascipt can see the div. But sometimes it takes longer and it breaks the javascript. I'm tring this: function load_content() { if(document.getElementById('remote_div')==null) { setTimeout('load_content()', 300); } else { document.getElementById('remote_div').innerHTML = 'Content goes here' } } but it just doesn't seem to work... what is wrong with it?

    Read the article

  • setTimeout doesn't work with window.location?

    - by Syom
    i try to rich flash like effect when changing window location, but there is a small problem, i can't solve. look at the script please $(document).ready(function(){ $('a.flash').click(function(e) { e.preventDefault(); $('body').fadeOut(1500); setTimeout("", 1500); window.location=this.href; }); }); window.location=this.href must be done after 1500ms, but it doesn't happen. could you explain why? what is strange, when i try to write alert("something"); instead of window.location=this.href, it works fine. Could you explain why? Thanks

    Read the article

  • (jQuery) javascript setTimeout clearTimeout

    - by Tillebeck
    Hi I try to make a page to go to the startpage after eg. 10sec of inactivity (user not clicking anywhere). I use jQuery for the rest but the set/clear in my test function are pure javascript. In my frustation I ended up with something like this function that I hoped I could call on any click on the page. The timer starts fine, but is not reset on a click. If the function is called 5 times within the first 10 seconds, then 5 alerts will apear... no clearTimeout... function endAndStartTimer() { window.clearTimeout(timer); var timer; //var millisecBeforeRedirect = 10000; timer = window.setTimeout(function(){alert('Hello!');},10000); } Any one got some lines of code that will do the trick? - on any click stop, reset and start the timer. - When timer hits eg. 10sec do something. BR. Anders

    Read the article

  • How to use setTimeout / .delay() to wait for typing between characters

    - by Darcy
    Hi all, I am creating a simple listbox filter that takes the user input and returns the matching results in a listbox via javascript/jquery (roughly 5000+ items in listbox). Here is the code snippet: var Listbox1 = $('#Listbox1'); var commands = document.getElementById('DatabaseCommandsHidden'); //using js for speed $('#CommandsFilter').bind('keyup', function() { Listbox1.children().remove(); for (var i = 0; i < commands.options.length; i++) { if (commands.options[i].text.toLowerCase().match($(this).val().toLowerCase())) { Listbox1.append($('<option></option>').val(i).html(commands.options[i].text)); } } }); This works pretty well, but slows down somewhat when the 1st/2nd char's are being typed since there are so many items. I thought a solution I could use would be to add a delay to the textbox that prevents the 'keyup' event from being called until the user stops typing. The problem is, I'm not sure how to do that, or if its even a good idea or not. Any suggestions/help is greatly appreciated.

    Read the article

  • Avoid multiple autocomplete calls by wrapping it with SetTimeOut

    - by pixelboy
    Here's my issue : using an autocomplete jQuery plugin, I'd like to avoid multiple ajax requests when user strikes his keynoard by surrounding the $('#query1').autocomplete({ serviceUrl:'/actions/autocomplete?population=salon', minChars:3, maxHeight:300, width:200, clearCache:true, onSelect: function(suggestions,data){ $(".btn1").attr("href", "${pageContext.request.contextPath}/actions/espaceClients?participantId=" + data) } }); with something like var search = false; $('#query1, #query2, #query3').keyup(function(){ if (!search){ search = true; } if (search) { search = false; autocompleteThem(); } }); A you can see, above code is stupid, but it kinda shows what i'm trying to do. In simple words, if user dosen't type anything else in a certain period of time, then you can call autocomplete. I hope i'm being clear, as my brains are a mess...

    Read the article

  • jQuery setTimeout delay for an element

    - by Trouble
    Is there an easier way to wait for an element to load ( by independant script/mootools/other ). For example: I am waiting for a google map to load, but I don't want to use its API for checks. So I made two functions: function checkIfexist() { if(jQuery('#container').length) return 0; else reload(1); } function reload(mode) { setTimeout(function(){ do stuff . . . if(mode==1) checkIfexist(); }, 400); } I am starting it with reload(1); Is there an easier way to use setTimeout in such a way? I don't want to use delay, wait or whatever.

    Read the article

  • Jasmine testing coffeescript expect(setTimeout).toHaveBeenCalledWith

    - by Lee Quarella
    In the process of learning Jasmine, I've come to this issue. I want a basic function to run, then set a timeout to call itself again... simple stuff. class @LoopObj constructor: -> loop: (interval) -> #do some stuff setTimeout((=>@loop(interval)), interval) But I want to test to make sure the setTimeout was called with the proper args describe "loop", -> xit "does nifty things", -> it "loops at a given interval", -> my_nifty_loop = new LoopObj interval = 10 spyOn(window, "setTimeout") my_nifty_loop.loop(interval) expect(setTimeout).toHaveBeenCalledWith((-> my_nifty_loop.loop(interval)), interval) I get this error: Expected spy setTimeout to have been called with [ Function, 10 ] but was called with [ [ Function, 10 ] ] Is this because the (-> my_nifty_loop.loop(interval)) function does not equal the (=>@loop(interval)) function? Or does it have something to do with the extra square brackets around the second [ [ Function, 10 ] ]? Something else altogther? Where have I gone wrong?

    Read the article

  • setTimeout is acting weird

    - by mnish
    I am trying to make a simple setTimeout, to make a div tag invisible after 2 seconds. The setTimeout function makes the div invisible but irregularly, sometimes immediately and sometimes after 1 sec, and so on. Here is my code: function beginTimeOut(){ t = setTimeout(function(){hideSubMenu()},2000); } function hideSubMenu(){ var elem; elem = document.getElementById("ul_navlist1"); elem.style.visibility="hidden"; clearTimeout(t); } By the way, t is a global variable. I have tried this too: t = setTimeout("hideSubMenu()",2000); but with the same irregular results.

    Read the article

  • Timer vs setTimeout

    - by Christophe Herreman
    The docs for flash.utils.setTimeout() state: Instead of using this method, consider creating a Timer object, with the specified interval, using 1 as the repeatCount parameter (which sets the timer to run only once). Does anyone know if there is a (significant) advantage in doing so? Using setTimeout is a lot easier when you only need to delay 1 call.

    Read the article

1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >