-1

My question is clear, but i am somewhat very confused. I am using IPB, in my IP Downloads any member can download the files easily and that is not a problem. But I want to hide that download button until the like button is clicked. Or, for example to put a sample hover text on the download button telling please like. But the like button is in another page, Each download or each file has a support topic and the like button is in every support topic how can i code this?

Thanks in advance. I know it will be very simple jquery but what i cant do is calling the other page?

Pete
  • 57,112
  • 28
  • 117
  • 166
  • If the like button page is opened by the download page? If so, you can refresh the opener page via the child page that would recheck the condition for enabling download button. – Khadim Ali May 17 '13 at 08:02
  • No, the like button is in opened by the download page, The like butting is in another page which is called Support topic. I want to recall that page and see if it is clicked the download appears!? – Abdallah Abdalaziz May 17 '13 at 08:11

2 Answers2

0

Hi you can add a script that will store a session cookie when clicked on the like. (not very fond of the idea of forcing your user though)

But when the cookie is set, another script checks if the cookie equals your cookie value, then you can display that button example:

$('.like-button').on('click', function(){
    // set cookie
})

your other page for example would. or remove property disabled

if(cookie === value) {
    $('.download-button').css({'display':'block'})
}
Matthias Wegtun
  • 1,231
  • 1
  • 9
  • 13
  • Mmm both of the buttons are in different pages will they still call each other? and I dont know how to use cookies? – Abdallah Abdalaziz May 17 '13 at 08:12
  • 1
    mhm... What if the user has liked yesterday and want to download today ? Or What if he has liked on an other machine ? How do you know he has or not liked ? is there data stored serverside ? – TCHdvlp May 17 '13 at 08:15
  • maybe using jQuery cookie will help you and yes the cookie is something the browser saves till you want it to stop and set the cookie to null. so even if you are on another page you can still achieve what u want. @TCHdvlp good thinking, haven't thought of it yet. Does a like button change state when it is liked? any property that can be read out? – Matthias Wegtun May 17 '13 at 08:17
  • Ofcourse, The like button i stored in the user account so not worry about this,even if we cleared the cookies its will always be stored. and ya when the like button is clicked this class will show"ipsLikeButton ipsLikeButton_disabled rep_down" so i want to show the download button when this class is shown as this class will be hidden is the like button is not clicked. BUt the prob is both of the button in different pages! – Abdallah Abdalaziz May 17 '13 at 08:23
  • So, you just make an ajax call to get the value of ipsLikeButton. Set your button to diseable. On dom ready, make your ajax call (or get or getJSON...). If he has liked, make your button enable.http://api.jquery.com/jQuery.ajax/ http://api.jquery.com/jQuery.get/ http://api.jquery.com/jQuery.getJSON/ – TCHdvlp May 17 '13 at 08:30
  • Mm here is my classes: Download button: download_button rounded right in another page: Like button not clicked: ipsLikeButton ipsLikeButton_enabled rep_up Like button clicked: ipsLikeButton ipsLikeButton_disabled rep_down Hope if you can provide example code – Abdallah Abdalaziz May 17 '13 at 08:32
0

Here is an example code as said in comments :

<html>
<button id="DownLoadButton" disabled="disabled" title="You must have liked first">Download</button>

<script>$(document).ready(function{

    $.ajax({
        url:"urlToCheckIpsLikeButton",
        data:{"pageName":pageName, "foo":foo, "bar":bar, ....}
    }).success(function(data) { 
        var myAnswer = data;
        //you can test (typeof myAnswer != "undefined") if you like
        if(myAnswer == "true"){
            //He has liked
            $("#DownLoadButton").prop('disabled',false);
            $("#DownLoadButton").prop('title',"click to download");
        }
    });

});

The only thing you have to do here is to send true or false with your code at 'urlToCheckIpsLikeButton'

TCHdvlp
  • 1,334
  • 1
  • 9
  • 15
  • Mm thanks but its not a good idea to send true or false as the other pages are very general thats why i dont want to miss the codes in it. I just want to put the code in one page which is the download page and it will call the other page for the class which i commented it! Hope you can check the classes and help me out and am thanks a lot bro! – Abdallah Abdalaziz May 17 '13 at 08:45
  • No, the `urlToCheckLikeButton` must be server side ! In a php or java or asp file (or whatever...). – TCHdvlp May 17 '13 at 08:53
  • If you mean 'css' classes, I don't know if it's possible to check it from server. I mean, "page1 ask to server if elements on page2 have this or this css class".... oO – TCHdvlp May 17 '13 at 09:03
  • ya! if this css class is on or visible let the download visible! – Abdallah Abdalaziz May 17 '13 at 09:14
  • If think you can't do this, if you can, I don't know how to. If you have a database, the best would be to save the status of the 'like' button for this user (liked or not). So you'd just have to check the value in the DB when you are loading the page with the download button. To check the value, use the code above with `.ajax()` – TCHdvlp May 17 '13 at 10:30