Tab change does not trigger Drupal.attachBehaviors

cap60552 - November 15, 2008 - 05:42
Project:Magic Tabs
Version:6.x-1.0
Component:User interface
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

I was attempting to use magic_tabs in combination with collapse.js. It worked fine on the initially loaded tab, but when the tab is switched to a new tab the collapse functionality is lost. From what I can tell this is because the tab change doesn't call Drupal.attachBehaviors. Is this something that magic_tabs should do or do I need to do this myself somehow?

#1

ciberligre - February 13, 2009 - 11:24

Having the same problem with collapse.js and lightbox.js

Does anybody have more info about how to call the attachBehaviours function?

#2

ciberligre - February 17, 2009 - 18:22

I think I got it working... I had to dive a bit into unknown territory: http://drupal.org/node/114774#javascript-behaviors

I just added the attachBehaviors to the onclick event (I had to hack the module, which I did not want to, but don't know any other way):
Around line 140:

'onclick' => "
            $('#$callback .magic_content').addClass('hidden');
            $('#$callback .loading').removeClass('hidden');
            $('#$callback').load('$cb_path');
            Drupal.attachBehaviors(#$callback);
            return false;",

#3

ciberligre - February 18, 2009 - 10:24

Uuups!

Just realized that this solution is not loading the section by ajax, but reloading the whole page... any better solution?

#4

ciberligre - February 20, 2009 - 09:58

OK! I think I got it now. I launch the attachBehaviors funtion as a callback functions (defined for the jquery command $.load)

'onclick' => "
            $('#$callback .magic_content').addClass('hidden');
            $('#$callback .loading').removeClass('hidden');
            $('#$callback').load('$cb_path', function(){
                    Drupal.attachBehaviors(this);
  }
            );
            return false;",

 
 

Drupal is a registered trademark of Dries Buytaert.