Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find when BlindUp/BlindDown ended 1

Status
Not open for further replies.

Sleidia

Technical User
May 4, 2001
1,284
FR
Hi guys,

I use the functions BlindUp/BlindDown from the effects file of the Prototype/Scriptaculous library (functions that I don't fully understand) :

Code:
Effect.BlindUp = function(element) {
  element = $(element);
  element.makeClipping();
  return new Effect.Scale(element, 0,
    Object.extend({ scaleContent: false,
      scaleX: false,
      restoreAfterFinish: true,
      afterFinishInternal: function(effect) {
        effect.element.hide().undoClipping();
      }
    }, arguments[1] || { })
  );
};

Effect.BlindDown = function(element) {
  element = $(element);
  var elementDimensions = element.getDimensions();
  return new Effect.Scale(element, 100, Object.extend({
    scaleContent: false,
    scaleX: false,
    scaleFrom: 0,
    scaleMode: {originalHeight: elementDimensions.height, originalWidth: elementDimensions.width},
    restoreAfterFinish: true,
    afterSetup: function(effect) {
      effect.element.makeClipping().setStyle({height: '0px'}).show();
    },
    afterFinishInternal: function(effect) {
      effect.element.undoClipping();
    }
  }, arguments[1] || { }));
};

I call those functions from a script of mine as follow :

Code:
    function ad_toggle ( action , num ) {

    var title = document.getElementById( 'ti' + num );
    var content = document.getElementById( 'co' + num );
    var text = document.getElementById( 'te' + num );
    var caption = document.getElementById( 'ca' + num );
    
        if (action == 'open') {

            if (content.style.display != 'none') {
    
            Effect.BlindUp(content);
            title.className = 'closed';
            caption.className = 'on';
            
            } else {
            
            Effect.BlindDown(content);
            title.className = 'open';
            caption.className = 'off';
            
            }
        
        } else {
        
            if (content.style.display == 'none') {
            
                if (action == 'turnon') {
        
                title.className = 'open';
                caption.className = 'hover';
                
                }
                
                if (action == 'turnoff') {
        
                title.className = 'closed';
                caption.className = 'on';
                
                }
            
            }
        
        }
    
    }

The problem is that I want to prevent my function ad_toggle from doing anything before BlindUp/BlindDown have completed their respective task (until a div is fully open/closed).

So, my question is : how do I detect this, and is it possible without changing the code of the Prototype/Effects library?

Thanks a lot for the help :)

 
Every effect can have the following 4 options:

beforeStart: Called before the main effects rendering loop is started.
beforeUpdate: Called on each iteration of the effects rendering loop, before the redraw takes places.
afterUpdate: Called on each iteration of the effects rendering loop, after the redraw takes places.
afterFinish: Called after the last redraw of the effect was made.

So, give your effects an 'afterFinish' option which calls the code you want to run only after the effects have finished. e,g:

Code:
Effect.BlindUp(content, { afterFinish:yourFunc });

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
Thanks a lot Dan :)

But I don't see how the call to another function could prevent ad_toggle from doing anything :(

Any idea?
 
It doesn't... you have to move the code from ad_toggle into a new function which only executes after the effects have finished.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 

Ahhh sorry, I think I failed to make something clear enough : it's the functions BlindUp/BlindDown ALSO that I need to prevent from executing while they already are being executed.
 
You could use a simple global boolean which you set at the top of ad_toggle, and only clear in the 'afterFinish' function...

I'm guessing you don't want to go into queue behaviour with scriptaculous, so that's probably your easiest bet.

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 

Thanks Dan, I managed to do what I wanted thanks to you.
It was easier than I thought ;)

Have a nice day.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top