Nitobi User Forums Forum Index

    (RSS)
Nitobi User Forums
Nitobi Support Forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Attach tab onload event through API?

 
Post new topic   Reply to topic    Nitobi User Forums Forum Index -> Tabstrip
View previous topic :: View next topic  
Author Message
racecar789



Joined: 21 Sep 2006
Posts: 28

PostPosted: Fri Sep 21, 2007 7:47 pm    Post subject: Attach tab onload event through API? Reply with quote

Is there a way to attach an onload event attribute via API rather than html tab tags?

Was thinking something along these lines but not having any luck.

Code:
var tabstrip = nitobi.loadComponent('tabstrip1'); //load strip
tabstrip.tab[1].onload.subscribe(someEventFunction); //attach onload function

Thanks


Last edited by racecar789 on Sun Sep 23, 2007 6:14 pm; edited 1 time in total
Back to top
View user's profile Send private message
racecar789



Joined: 21 Sep 2006
Posts: 28

PostPosted: Sat Sep 22, 2007 7:53 pm    Post subject: Reply with quote

Including this patch works for now, pending a better way. Include Prototype library when using.

Code:
   //Execute function when tab document has fully loaded and all of its DOM elements are ready
   //Example:
      //1. get tab object: "var tab = tabstrip.getTabs().get(0);" //get first tab (or can get tab when creating it via API ex: "var tab = new nitobi.tabstrip.Tab()")
      //2. run method: "tab.executeFunctionOnLoad(customFunction);" //will execute customFunction when tab's DOM is fully loaded
   nitobi.tabstrip.Tab.prototype.executeFunctionOnLoad=function(customFunction)
   {
      //If page fully loaded, execute function
      if (this.getContentLoaded())
      {
         customFunction();
      }
      else
      {
         //Else, wait for one second then try again
         setTimeout(function(){this.executeFunctionOnLoad(customFunction)}.bind(this), 1000);
      }
   };
Back to top
View user's profile Send private message
jake



Joined: 18 Oct 2007
Posts: 6

PostPosted: Sat Oct 20, 2007 5:16 am    Post subject: Reply with quote

Ohh you were so close!

You can try:
Code:

tab.onLoad.subscribe(myFunc);

(the only difference being the capital L)

Incidentally, no need to include Prototype to use bind. The nitobi toolkit includes a function called nitobi.lang.close() that does the same thing:
Code:

tab.onLoad.subscribe(nitobi.lang.close(myObj.myFunc, myObj));

"close" because the result is a "closure"
Back to top
View user's profile Send private message
racecar789



Joined: 21 Sep 2006
Posts: 28

PostPosted: Sat Oct 20, 2007 1:32 pm    Post subject: Reply with quote

Thanks Jake, I'll use that from now on.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Nitobi User Forums Forum Index -> Tabstrip All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group