943,171 Members | Top Members by Rank

Ad:
Sep 2nd, 2010
0

How has Daniweb made it's pop-up?

Expand Post »
Hi all,

Sorry if this is a common thread. I did a search but couldn't find a solution I was looking for...

You know the popup that appears if you're not logged in about joining Daniweb, I need to put together one very similar for a forum I'm working on. All the functionality I want is an ajax popup showing our latest offer, with a close button, and the ability to set a cookie that expires in a month so it doesn't annoy our users and pop up each time they load a different page.

I figured I would use the jQuery library to display the popup when the page loads, whilst using Klaus Hartl's cookie plugin here:

http://plugins.jquery.com/files/jquery.cookie.js.txt

The problem is I'm a novice to javascript and have no idea how to integrate the two together. Would anyone happen to know where to start?

I know what I want to do, just not how to...

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1.  
  2. $(document).ready(function() {
  3. // Check if cookie exists
  4. // If exists, do nothing
  5. // If it doesn't exist then invoke div later in HTML as modal AJAX popup
  6. // Set cookie to expire in a month
  7. });

Many thanks in advance for all your help

Paul
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
pwgmac is offline Offline
1 posts
since Sep 2010
Sep 2nd, 2010
0
Re: How has Daniweb made it's pop-up?
Ok this is the HTML code about the divs where mask is the div which is blackening the screen:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <div id="boxes">
  2.  
  3. <!-- Start of Login Dialog -->
  4. <div id="dialog1" class="window">
  5. <div class="d-header">
  6. <input type="text" value="username" onclick="this.value=''"/><br/>
  7. <input type="password" value="Password" onclick="this.value=''"/>
  8. </div>
  9. <div class="d-blank"></div>
  10. <div class="d-login"><input type="image" alt="Login" title="Login" src="images/login-button.png"/></div>
  11. </div>
  12. <!-- End of Login Dialog -->
  13. <div id="mask"></div>
  14. </div>
This is the text link trigerring the event:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <p class="lg"><a href="#dialog1" name="modal"><b>Log in</b></a></p>
This is the CSS code
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <style type="text/css">
  2. #mask {
  3. position:absolute;
  4. left:0;
  5. top:0;
  6. z-index:200;
  7. background-color:#000;
  8. display:none;
  9. }
  10.  
  11. #boxes .window {
  12. position:absolute;
  13. left:0;
  14. top:0;
  15. width:440px;
  16. height:200px;
  17. display:none;
  18. z-index:220;
  19. padding:20px;
  20. }
  21.  
  22. #boxes #dialog1 {
  23. width:375px;
  24. height:203px;
  25. }
  26.  
  27. #dialog1 .d-header {
  28. background:url(images/formlog2.png) no-repeat 0 0 transparent;
  29. width:400px;
  30. height:220px;
  31. }
  32.  
  33. #dialog1 .d-header input {
  34. position:relative;
  35. top:60px;
  36. left:100px;
  37. border:3px solid #cccccc;
  38. height:22px;
  39. width:200px;
  40. font-size:15px;
  41. padding:5px;
  42. margin-top:4px;
  43. }
  44.  
  45. #dialog1 .d-blank {
  46. float:left;
  47. background:url(images/login-blank.png) no-repeat 0 0 transparent;
  48. width:267px;
  49. height:53px;
  50. }
  51.  
  52. #dialog1 .d-login {
  53. float:left;
  54. width:108px;
  55. height:53px;
  56. margin-top: -13%;
  57. }
  58. </style>
And this is the script
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <script type="text/javascript" src="http://code.jquery.com/jquery-latest.pack.js"></script>
  2. <script>
  3.  
  4. $(document).ready(function() {
  5.  
  6. //select all the a tag with name equal to modal
  7. $('a[name=modal]').click(function(e) {
  8. //Cancel the link behavior
  9. e.preventDefault();
  10.  
  11. //Get the A tag
  12. var id = $(this).attr('href');
  13.  
  14. //Get the screen height and width
  15. var maskHeight = $(document).height();
  16. var maskWidth = $(window).width();
  17.  
  18. //Set heigth and width to mask to fill up the whole screen
  19. $('#mask').css({'width':maskWidth,'height':maskHeight});
  20.  
  21. //transition effect
  22. $('#mask').fadeIn(1000);
  23. $('#mask').fadeTo("slow",0.8);
  24.  
  25. //Get the window height and width
  26. var winH = $(window).height();
  27. var winW = $(window).width();
  28.  
  29. //Set the popup window to center
  30. $(id).css('top', winH/2-$(id).height()/2);
  31. $(id).css('left', winW/2-$(id).width()/2);
  32.  
  33. //transition effect
  34. $(id).fadeIn(2000);
  35.  
  36. });
  37.  
  38. //if close button is clicked
  39. $('.window .close').click(function (e) {
  40. //Cancel the link behavior
  41. e.preventDefault();
  42.  
  43. $('#mask').hide();
  44. $('.window').hide();
  45. });
  46.  
  47. //if mask is clicked
  48. $('#mask').click(function () {
  49. $(this).hide();
  50. $('.window').hide();
  51. });
  52.  
  53. });
  54.  
  55. </script>
And finally you'll have to make some PNG or JPG images(if you want) with apropriate size to have the popup looking good. You'll see this images in the CSS and HTML code.
Reputation Points: 10
Solved Threads: 6
Junior Poster in Training
george61 is offline Offline
59 posts
since Jul 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Autofilling a text field based on prior input
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Printscreen Help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC