tags:

views:

142

answers:

3

I am trying to get and pass a rel attr to tell which tab to select in a nyro pop up function.

function guestlist (selector) {
    $(selector).nyroModal({
        hideContent: newHide,
        endShowContent: function () {
            var getNumbers = $(selector).attr('rel');
            alert(getNumbers);
            specialwater();
            tabs('#manage-guestlist',getNumbers);
        }
    });    
}

guestlist('a.see-all');

How do I get that number into the callback endShowContent?

Update: This is being used on different links with different rel values

HTML These are 2 links in the DOM I need to get the rel values on the above click function which nyro handles.

<a  href="/events/manage_guestlist" class="see-all" rel="1">See All</a>
<a  href="/events/manage_guestlist" class="see-all" rel="0">See All</a>
A: 

Can you not use

$(this).attr('rel');

$(this) should give you the element that the current event was fired from...

Paul
No, nyro does not call `endShowContent` in the context of any element. Check the source yourself: http://nyromodal.nyrodev.com/js/jquery.nyroModal-1.5.2.js
Crescent Fresh
A: 

Now, assuming your tabs function would take just one call for each rel-attribute your could try something like this. The each function will ensure you to access one element at a time.

function guestlist (selector) {
    $(selector).nyroModal({
        hideContent: newHide,
        endShowContent: function () {
             $(selector).each(function()
             {
                 tabs('#manage-guestlist', $(this).attr('rel'));
             });
        }
    });    
}

guestlist('a.see-all');
Morningcoffee
This does not work its gets 0 then 1 immediately because of the each.
matthewb
+3  A: 

Is this right?

  • If the user clicks either link, you want to show it in a modal window with the appropriate tab selected (specified by the rel attribute).
  • When the page loads open a modal window showing /events/manage_guestlist, with the first tab selected (tab 0).

If so, I'd do it like this:

// Pass the tab index in to this function
function showGuestList(tabIndex) {
    $('a.see-all').nyroModalManual({
        hideContent: newHide,
        endShowContent: function() {
            specialwater(); 
            tabs('#manage-guestlist', tabIndex);
        }
    });
}

// On page load, nothing's been selected, so show the default tab
$(document).ready(function() { 
    showGuestList(0);
});

// Attach a click handler to our links that passes the value of 
// the element's rel attribute
$('a.see-all').click(function {
    showGuestList($(this).attr('rel'));
});
Jeff Sternal
+1 This seems to achieve the questioner's intention. However, you've got your parentheses and curly-brackets mixed up inside the `showGuestList` function and you should probably be using `nyroModalManual` method, since the `nyroModal` method only binds click handlers and doesn't actually show the dialog.
brianpeiris
Gah, thanks for correcting my air code, brian!.
Jeff Sternal