34

I am in love with stackoverflow's single-color "click-to-close' hovering dialog boxes that greet a user when they try to vote and aren't logged in or use the site incorrectly. Any idea how and/or what technology Jeff used to implement these neat little devices?

EDIT: I'm specifically talking about the SQUARE dialog boxes that say "Click To Close" on them. I know how to implement the rectangular strip on the top of the screen.

rene
  • 41,474
  • 78
  • 114
  • 152
CodingWithoutComments
  • 35,598
  • 21
  • 73
  • 86
  • look at the source code? they don't seem too complicated – matt b Apr 17 '09 at 03:40
  • 1
    I'm having a hard time finding the actual code for the dialog boxes I'm referring to, could you post the code? – CodingWithoutComments Apr 17 '09 at 03:48
  • SO's JavaScript is all minimized, so it'd take some effort just to decode the original source anyways. – Dan Lew Apr 17 '09 at 03:51
  • Reading the source is tough with all the minification, but you can get some clues. For example, the flag link for your question is an anchor with id "flag-post-758906". I suggest searching question.min.js for the string "flag-post" and seeing what you'll find (as I don't have room in this comment) – Kyle Cronin Apr 17 '09 at 03:52
  • 1
    http://stackoverflow.com/questions/659199/how-to-show-popup-message-like-in-stackoverflow, http://stackoverflow.com/questions/604577/how-to-display-a-message-on-screen-without-refreshing-like-so-does – Paolo Bergantino Apr 17 '09 at 04:10
  • Hey Paolo. I wasn't asking about the messages that get shown on the top of the screen. I know how to do that. I was asking about the messages that appear when a user tries to vote and is not logged in, etc. – CodingWithoutComments Apr 17 '09 at 04:23
  • you can un-minify the script by using this tool http://elfz.laacz.lv/beautify/ – redsquare Apr 17 '09 at 07:23

2 Answers2

51

Although I was under the impression they used jQuery's UI Dialog for this, I am not too sure anymore. However, it is not too difficult to whip this up yourself. Try this code:

$('.showme').click(function() {
    $('.error-notification').remove();
    var $err = $('<div>').addClass('error-notification')
                         .html('<h2>Paolo is awesome</h2>(click on this box to close)')
                         .css('left', $(this).position().left);
    $(this).after($err);
    $err.fadeIn('fast');
});
$('.error-notification').live('click', function() {
    $(this).fadeOut('fast', function() { $(this).remove(); });
});

With these styles:

.error-notification {
    background-color:#AE0000;
    color:white;
    cursor:pointer;
    display: none;
    padding:15px;
    padding-top: 0;
    position:absolute;
    z-index:1;
    font-size: 100%;
}

.error-notification h2 {
    font-family:Trebuchet MS,Helvetica,sans-serif;
    font-size:140%;
    font-weight:bold;
    margin-bottom:7px;
}

And click here to see it in action.

However, I think you'd still need to tweak it a little bit to give it the right positions depending on the situation in which you are using it. I took care of this for the left position because it is working for the top, but I think there may be some situations in which it won't. All things considered, this should get you started. If you want a more robust implementation, you should check out jQuery BeautyTips which is really awesome and would make this trivial to implement.

Paolo Bergantino
  • 480,997
  • 81
  • 517
  • 436
2

You can use the jQuery library in conjunction with jQuery UI to create dialogs.

cletus
  • 616,129
  • 168
  • 910
  • 942
  • If you haven't checked out JQuery yet, it is so good, MS may use it instead of fixing Microsoft Ajax LOL. MS Ajax has three ways of working: Declaratively (aspx), JavaScript, and in XMLscript. Ajax 4 should have a Client Side ListView Javascript function with {data tag} replacement like a repeater. – Zachary Scott Apr 17 '09 at 03:46