matthewhall / matt-tabs

A simple jQuery plugin for creating tabbed interfaces.
Do What The F*ck You Want To Public License
6 stars 4 forks source link

Add onCreate / onShow event? #5

Closed zathrus-writer closed 11 years ago

zathrus-writer commented 11 years ago

Hi,

I just came across an interesting case, when 2 concurrent scripts tried to mtabs() the same element. Naturally, only one of the succeeded, and there was no knowing which one that was.

What I'd love to see in this plugin is an event that fires when tabs are built, so I could subscribe to that event in the second script and do what is needed to be done once it's fired.

Martin

matthewhall commented 11 years ago

Hi Martin,

The plugin will check to see if mtabs has already been applied, so I think if two different scripts are applying mtabs() to the same element then the one that is executed first should be the one that is successfully applied.

I haven't tested this, however. Probably worth writing a specific test for this perhaps...

An onCreate event to subscribe to could be handy though. I'll take a look at implementing this.

Thanks for the input.

zathrus-writer commented 11 years ago

Nice :)

You are right in that there is no duplicate tabs creation if they were already initialized. I didn't check what mTabs() call actually returns. If it returned false in case of an existing instance on the element in question, that would help as well. Otherwise, a onCreate event would be very welcome :)

Martin

zathrus-writer commented 11 years ago

amazing stuff, will give this a test tomorrow for sure - thank you!

matthewhall commented 11 years ago

Cool thanks. Hopefully that helps.

zathrus-writer commented 11 years ago

Been testing this and it seems to work quite well :) The only thing I'm missing there is probably a reference of the element from which tabs were created. This is so I could determine which container was activated when I subscribe do the onReady event.

But that shouldn't be too hard on my side here. Thanks again!

matthewhall commented 11 years ago

Interesting idea. Perhaps I could pass a jQuery element of the tab set as an argument to the onReady function for you? Would be useful if you were applying .mtabs to multiple elements at once, like this:

$('.set-1, .set-2').mtabs({
    onReady: function ($set) {
        // $set will be either '.set-1' or '.set-2'
    }
});

Then again, you might just be able to use $(this) within the callback...

I'll investigate.

matthewhall commented 11 years ago

Actually, you probably won't be able to use $(this) as the callback will be invoked with a different context. Let me look at adjusting this.

Thanks man.

zathrus-writer commented 11 years ago

hmm, didn't think about the context consequence... will wait and see what you'll be able to come with then :) and thanks to you, mate

matthewhall commented 11 years ago

Hey Martin,

I'm now passing in the element that .mtabs was invoked on as the context for the .onReady callback, so this should allow you to use $(this) within the function for whatever you need.

Let me know if that helps.

Thanks.

zathrus-writer commented 11 years ago

This is most helpful, thank you!

matthewhall commented 11 years ago

Cool man. I'll create a proper release for this later on then.

Thanks.