I was under the impression each tab would load once clicked, but it seems that all tabs load once activated, as well as on each tab being activated?

CommentFileSizeAuthor
#9 yh.patch3.35 KByhager

Comments

brenda003’s picture

To be more clear, with Devel on I see that all the queries are happening for all the tabs.

yhager’s picture

The tabs are loaded by the callback function you list when you call magic_tabs_get().

The callback, upon being called, creates the full set of tabs (titles & content, with designation of the active tab) - and that is being sent back to the browser.

This is done mostly for reasons of simplicity - both for this module's code, and for the callback implementation.

brenda003’s picture

Hmm. So it's supposed to be that if I have, let's say, 10 tabs - all tabs are executed at the beginning, and then once I click tab #3, all tabs are executed once again, et cetera?

yhager’s picture

Well, yes, that is how it is implemented now.

The main reason for this is simplicity. I didn't know how this module would develop, and I am open to discussion here. In my case, I found this is an acceptable overhead, YMMV.

Can you please provide more information about your case, why you need individual tab loading, and whether you think this would serve other users as well.

brenda003’s picture

In many cases it is an acceptable overhead, but for a higher traffic site with lots of tabs it could be an issue. Being able to have tabs load individually on each click, or in the background, would be a *huge* improvement for those situations.

What is the benefit of using this over something like JS tools tabs? It seems it's even more overhead since it's loading each tab instead of just the once and hiding them but over and over again on each tab being activated.

For example, I have tabs that are from A - Z and load content based on that. That's a lot of load. :)

I'd be interested in what other people think. Ideally, I think it'd be nice to have options for this sort of thing. I've been looking at possible ways of implementing it.

brenda003’s picture

Category: support » feature
yhager’s picture

I can definitely see your point.

I think I will implement it by adding a paramter for the callback, that will be the active tab number.
your callback will then have to return the same tab structure as before, but only the content of the active tab will be displayed - so you can leave 'content' empty for all other tabs. You will still have to render their titles, as they are still visible regardless of the tab clicked.

If you will not want to implement this optimization, simply ignore this paramter and render all tabs every time.

What do you think?

brenda003’s picture

That sounds great, though I'm a little unclear on a couple things. magic_tabs_get() already has an $active parameter which is the tab number (or first/last), so if you mean adding another parameter to that it might be confusing.

This sounds great, though! Can I have it by tomorrow? Just kidding. :P

yhager’s picture

Status: Active » Needs review
StatusFileSize
new3.35 KB

Allright, I had some spare time and created this patch. I haven't tested it enough, so not committing it yet.
However, you said something about tomorrow, no?

Please test - you can see the change in the example function and learn from that how it works.

brenda003’s picture

This is great! I'd like to go a little further and allow for multiple parameters, though. I think this patch just changes call_user_func to call_user_func_array

This is very very handy!

brenda003’s picture

Oh wait..ignore that last patch. I'm way too sleepy right now, I had this working a minute ago. Will look at it in the morning.

brenda003’s picture

I actually have no idea what I was doing last night (kids, don't try to code on very little sleep). Anyway, I think this is good but does require a lot of handling. What about instead having another parameter on magic_tabs_get to do this automatically? What do you think?

yhager’s picture

Anyway, I think this is good but does require a lot of handling.

Why? Your callback should work thte same as before, only you don't have to render the inactive tabs' content.

What about instead having another parameter on magic_tabs_get to do this automatically?

To do what? Please elaborate.

brenda003’s picture

Hmm, don't you need to check if each one is the active tab, though? Or am I misunderstanding?

brenda003’s picture

Status: Needs review » Reviewed & tested by the community

This patch works well. I'll start a new thread for any additional requests.

yhager’s picture

Assigned: Unassigned » yhager
Status: Reviewed & tested by the community » Fixed

Committed. I updated the README with an additional example.

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.