tags:

views:

34

answers:

3

I want to slide up #FriendRequests (a bar) if its the last friend request the user is answering on (confirm/ignore).

When you answer confirm/ignore, it sends ajax call and on success i made this:

$('#FriendRequests:last').slideUp('slow');

But my problem is now, that even if its not the last friend request you are answering on the #FriendRequests bar is sliding up.

How should i do this, so it slides up if its the last request the user is answering on? and what code/information do you need from me, please comment, so i will provide what you need in order to help me

Thank you

My code right now:

<div class="FriendRequests" style=" font-weight: bold; background: #283b43; border-bottom: 1px dashed #719dab;">
<img src="images/NewFriend_small.png" style="float: left; margin-left: 25px; margin-right: 10px;">
Friend Requests
</div> /* i want this to go away if its the last request the user is answering on */
    <?php
        while($showW = mysql_fetch_array($friendsWaiting)){
        ?>
         <div id="friend<?php echo $showW['id'] ?>" style="position: relative; background: #3a5f6e;">
           <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, <?php echo $sid; ?>, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>);" style="margin-right: 45px; color: #FFF;">CONFIRM</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, <?php echo $showW["id"]; ?>, <?php echo $showW["bID"]; ?>, <?php echo $sid; ?>);" style="color: #ccc;">IGNORE</a>
        </div>
        <?php 
        echo "<div style='font-style: italic; font-size: 11px; width: 240px;
        position: absolute; top: 8px; left: 305px;'><a rel='facebox' href='#friendmsg'><strong>\"</strong>".substr($showW[msg], 0, 80) ."<strong>\"</strong></a>
</div>";
        echo "<div style='display: none' id='friendmsg'>$showW[msg]</div>";
        echo $user['showUR']["full_name"] . "<br>
        <span style='font-size: 12px;'> ";
         showStatus($showW["bID"]); 
         showLatestSeen($showW["bID"]);
        echo "</span><br><div class='clearfloat'></div>";
        echo "</div>";
        }
        ?>

HTML:

<div id="FriendRequests" style=" font-weight: bold; background: #283b43; border-bottom: 1px dashed #719dab;">
    <img src="images/NewFriend_small.png" style="float: left; margin-left: 25px; margin-right: 10px;">
    Vänförfrågningar
</div>

<div id="friend99" style="position: relative; background: #3a5f6e;">
    <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, 1, 99, 90);" style="margin-right: 45px; color: #FFF;">Bekräfta</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, 99, 90, 1);" style="color: #ccc;">Ignorera</a>
    </div>
    <div style='font-style: italic; font-size: 11px; width: 240px;
    position: absolute; top: 8px; left: 305px;'>
        <a rel='facebox' href='#friendmsg'><strong>"</strong><strong>"</strong>
        </a>
    </div>
    <div style='display: none' id='friendmsg'></div>
    <div style='margin-top: 5px; margin-left: 45px; margin-bottom: 5px; '>
        <span style='float: left; border: 1px dashed #CCC; margin-right: 5px;'>
            <img src='images/profileimages/noPhoto_thumb.jpg'>
        </span>
        Mads Kluge <br>
        <span style='font-size: 12px;'> 25-08-2010 kl. 20:31</span>
        <br>
        <div class='clearfloat'></div>
    </div>
</div> 

<div id="friend100" style="position: relative; background: #3a5f6e;">
    <div style="position: absolute; top: 15px; right: 105px;">
        <a href='javascript:void(0);' onclick="MeYouFriendNB(true, 1, 100, 3);" style="margin-right: 45px; color: #FFF;">Bekräfta</a>
        <a href="javascript:void(0);" onclick="MeYouFriendNB(false, 100, 3, 1);" style="color: #ccc;">Ignorera</a>
    </div>
    <div style='font-style: italic; font-size: 11px; width: 240px;
    position: absolute; top: 8px; left: 305px;'>
        <a rel='facebox' href='#friendmsg'><strong>"</strong><strong>"</strong></a>
    </div>
    <div style='display: none' id='friendmsg'></div>
    <div style='margin-top: 5px; margin-left: 45px; margin-bottom: 5px; '>
        <span style='float: left; border: 1px dashed #CCC; margin-right: 5px;'>
            <img src='images/profileimages/noPhoto_thumb.jpg'>
        </span>
        Ani Paltian <br>
        <span style='font-size: 12px;'> 17-08-2010 kl. 18:19</span>
        <br>
        <div class='clearfloat'></div>
    </div>
</div>​

function MeYouFriendNB(confirm, uID, fID, bID){
 var c = confirm ? 'confirm' : 'ignore';
    $.ajax({ 
       type: "POST",
       url: "misc/AddFriend.php",
    data: {
    mode: 'ajax',
            friend: c,
            uID: uID,
            fID: fID,
            bID: bID
            },
       success: function(msg){
            $('#friend'+fID).slideUp('slow');
        }
     });
}
+2  A: 

EDIT based on your comments:

Sounds like maybe the slideUp() for #FriendRequests should trigger after the final friend has been hidden.

If so, I'd still add a class to the friend elements and do this:

success: function(msg){
    $('#friend'+fID).slideUp('slow', function() {
        if( $('div.friend:visible').length == 0 ) {
             $('#FriendRequests').slideUp('slow');
        }
    });
}
patrick dw
Its still sliding it up even if its not the last.. Didnt make any difference.
Karem
@Karem - I updated my answer. Hard to tell exactly what is happening without some sample HTML.
patrick dw
@patrick dw, ive updated my question. And your updated answer is hiding the img newFriend_small.png
Karem
@Karem - I updated my answer.
patrick dw
@Patrick, ok, option 1) i did not intend to have the friends inside the friendsrequest. I made the id "FriendRequests" for that div, because i want that to slide up if its the last request the user is answering on. Now your option 2) tried that too, when i press on the first request at top on the list, it slides up all the request and not touching the #FriendRequest bar, and when i press the others request it slides up one after one, like it should, but still not doing what i wanted.
Karem
@Patrick just tried your option 1) again, and when i press at the first one its closing them all requests. What i think its like it doesnt know if its the last one? I mean how could it know that? Because it would need to check if theres any others open and then if no then close the #friendrequest, do you get me? Because i think now when i press at the top and every request close its because it think its the last one somehow
Karem
@Karem - What is triggering the code? Is it a click event that needs to check if it is in the last `friend`?
patrick dw
@Patrick what do you mean? As you can in see on the links there's onclick="MeYouFriendNB" function, and on success i want it to check if its the last one remaining and if it is, close #FriendRequest too. I updated my question now
Karem
And as you can see in the function code, it already slides up the request on success .. but when the last have been slide up and the bar is still remaining thats what i do not want to have, i want it to slide up with the last one remaining..
Karem
@Karem - OK, I had no idea that the `onclick` was triggering that code. Now that you've provided the full information, I should have a solution for you. I'll update in a minute.
patrick dw
@patrick ok tried your new answer, it just slides up like normal. It still doesnt close #FriendRequests on the last
Karem
@patrick I gave it class like this: <div class="friend" id="friend<?php echo $showW['id'] ?>" style="position: relative; background: #3a5f6e;">In case you wonder
Karem
@Karem - Sorry, I had `=` instead of `==`. Also maybe do `console.log( $('div.friend:visible').length )` in the `:success` handler. It should give you the number of visible `.friend` elements each time.
patrick dw
...Also, there's invalid markup on your page. You're reusing the `friendmsg` ID. IDs must be unique.
patrick dw
Where am i reusing friendmsg? Not from what i can find. Thank you that worked awesome!! Thank you for taking your time, big + to you
Karem
@Karem - You're welcome. :o) With regard to `friendmsg`, each `.friend` element has a nested `<div style='display: none' id='friendmsg'></div>`
patrick dw
A: 

This all depends on your code...this is just an assumption. post your code

I think you're misunderstanding :last. Last just returns the last element that matches.

You want something like

// remove row
if ( $("#FriendRequests li").length == 0 ) {
    $('#FriendRequests').slideUp('slow');
} 

again...depends on your code

Galen
A: 

try this working ex:

just add a common class to all ur friendID div.

http://jsfiddle.net/Dhmfq/

Vaibhav Gupta
hmm i want the "Vänförfrågningar" bar to slide up, if its the latest request you answer on (clicking on "Bekräfta"(confirm) ), so the pages gets empty
Karem