Canceling All Timeouts In One?
Oct 7, 2009Is there a simple way to cancel all active timeouts without the need to reference each one individually ?
View 1 RepliesIs there a simple way to cancel all active timeouts without the need to reference each one individually ?
View 1 RepliesBasically what I want to achieve is a timeout on "over" followed by a subsequent timeout when the timeout is being removed....
I have got as far as:
Code:
function toggleMenu(el, over)
{
if (over) {
setTimeout(Element.addClassName(el, 'over'), 200);
[code]...
I'm running into issues while trying to make some simple code to loop through and display different combinations of 3 colours.I want to show 3 boxes on screen and then loop through/increment each possible combination of colours.The problem with timeouts is although I can create a delay until the cycle on one level has finished before executing code to change the layer above it, this isn't enough - each level of loop has to increment just a single step after the layer "below" it completes a cycle. So I think I need some hybrid between nested for loops and timeouts (if such a beast exists).
View 7 Replies View RelatedThe problems with the setTimeout and setInterval functions provided in Javascript are twofold. First, you can't call a local object method without losing your scope, and second, you can't pass objects to the function, since the function call is implemented as a string.
The Timer class solves these difficulties by employing a static array to store the parent object and function arguments until the function is called.
This class is provided as-is and pro bono, so go ahead and muck with it if you see things that could be done better.
Thanks to WA for giving me the idea for this (albeit indirectly)!
Updated 4/18/2003: Footprint decreased, minor code improvements.
Updated 5/3/2003: Minor comment clarification; no code changes.
Updated 5/10/2003: Minor code improvements.
// The constructor should be called with
// the parent object (optional, defaults to window).
function Timer(){
this.obj = (arguments.length)?arguments[0]:window;
return this;
}
// The set functions should be called with:
// - The name of the object method (as a string) (required)
// - The millisecond delay (required)
// - Any number of extra arguments, which will all be
// passed to the method when it is evaluated.
Timer.prototype.setInterval = function(func, msec){
var i = Timer.getNew();
var t = Timer.buildCall(this.obj, i, arguments);
Timer.set[i].timer = window.setInterval(t,msec);
return i;
}
Timer.prototype.setTimeout = function(func, msec){
var i = Timer.getNew();
Timer.buildCall(this.obj, i, arguments);
Timer.set[i].timer = window.setTimeout("Timer.callOnce("+i+");",msec);
return i;
}
// The clear functions should be called with
// the return value from the equivalent set function.
Timer.prototype.clearInterval = function(i){
if(!Timer.set[i]) return;
window.clearInterval(Timer.set[i].timer);
Timer.set[i] = null;
}
Timer.prototype.clearTimeout = function(i){
if(!Timer.set[i]) return;
window.clearTimeout(Timer.set[i].timer);
Timer.set[i] = null;
}
// Private data
Timer.set = new Array();
Timer.buildCall = function(obj, i, args){
var t = "";
Timer.set[i] = new Array();
if(obj != window){
Timer.set[i].obj = obj;
t = "Timer.set["+i+"].obj.";
}
t += args[0]+"(";
if(args.length > 2){
Timer.set[i][0] = args[2];
t += "Timer.set["+i+"][0]";
for(var j=1; (j+2)<args.length; j++){
Timer.set[i][j] = args[j+2];
t += ", Timer.set["+i+"]["+j+"]";
}}
t += ");";
Timer.set[i].call = t;
return t;
}
Timer.callOnce = function(i){
if(!Timer.set[i]) return;
eval(Timer.set[i].call);
Timer.set[i] = null;
}
Timer.getNew = function(){
var i = 0;
while(Timer.set[i]) i++;
return i;
}
Here's an example of the code in action:
function Ticker(){
this.count = 0;
this.timer = new Timer(this);
}
Ticker.prototype.tick = function(d){
this.count+=d;
window.status = ""+this.count;
this.timer.setTimeout("tick", 1000, d);
}
window.onload = function(){
var ticker = new Ticker();
ticker.tick(1);
}
I have code that looks like this:
function setupEventWrapper(obj) {
old_ev_handler = obj.onsubmit;
obj.onsubmit = function () {
do_something();
if (old_ev_handler != undefined) {
old_ev_handler();
}
if (event_cancelled()) {
undo_something();
}}}
it wraps the onsubmit handler (if any) within a new function which
do_something() and then calls the old event handler.
My problem is how can I detect if the event has been canceled by
old_ev_handler(). AFAIK an event can be cancelled in three ways:
* returning false, easy to check for
* setting event.returnValue = false on IE, easy to check for
* calling event.preventDefault() on DOM
How can I check if event.preventDefault() has been called?
i have a form made up of 2 file inputs and a submit button..
the imputs are to upload images, namley jpeg's for a e-greatings thing im
working on.
this only works with jpegs so i have a script that will check the value of
the imput tag to make sure it ends with .jpg, .jpeg.
this works fine on the jubmit button using
onclick="myHandler(this)"
it works fane that it alerts the user that only jpegs are valid but then
when the alert
has been ok'd it continues to submit the form to my php script.
how can i get this to cancle the submit action?
I have two javascript onloads in my form which seem to be cancelling each other out. The first- onload="checkMyBox"- works fine, which means the calendar stays hidden until the ckeckbox is clicked. However the second script that is supposed to show text ("I am an organized person") only after image is clicked does not work. It always shows the text.
I tried playing with it, and realized that if I erase the first <body onload="checkMyBox('c2','div1')"> the second onload works, meaning that the text will stay hidden until I click on image.
Code JavaScript:
<script type="text/javascript">
function checkMyBox(trigger,toggled){
var mcb = document.getElementById(trigger);
var cal = document.getElementById(toggled);
[Code].....
quick example:
function endless(){
$("element").animate({left: '-=100'}, 1500);
$("element").slideToggle(500);
[code]....
I am displaying my own context menu in response to a right-click on control (textbox) in my ASP.NET application. In IE, I can suppress the display of the browser's own context menu by simply returning false from the javascript that displays my context menu.How can I suppress the browser context menus from Chrome or Firefox?
View 2 Replies View RelatedThis is really more a IE issue than jquery but I am using jquery.
Has anyone used this setTimeouts method from the IXMLHttpRequest2 object from IE.
I want to monkey path jquery calls with this call below. I tried this and I still get a property method error even though the method seems to be available. Has anyone experienced this?
With this Javascript code, I get this error "Object does not support this property or method" error. I checked that the methods are available and I do a check that the method is there. Am I sending the wrong number of args? Has anyone used this?
Im writing a small app that will basically be like a wiki for family memebers to go in and make pages using my wysiwyg editor, update pages, ect..
the problem i've run into is trying to ensure they have saved the page.
I have a variable to detect whether or not unsaved changes exist. however the problem is now stopping the close event if the user clicks 'cancel' in the confirmation box.
Examples of when the 'navigation' or 'browser close' should be blocked:
1)i've made a small change on the page then clicked on a link, i should receive a conf message asking me if i want to loose changes.
2)i've made a change on the page then clicked the browser 'X' (close) button by accident. I should get the conf message here as well.
3) i've hit the refresh or reload button without saving. again i want the conf message.
Note, if they want to close, clicking OK should allow them too. furthermore, this function to block the close and produce the confirmation only will be called if there are unsaved changes on the page.
here is what i have so far - and this appears to work fine in IE. Code: