views:

108

answers:

3

I'm sure most of you have seen the CNN type alerts, the ones that flash at the top of the screen when the administrators want to. Is this already done in Drupal?

I am thinking you would need some kind of jQuery for the animation, simple enough, but what mechanism would you need to allow the user to X the alert away, and not show it again?

A: 

I cant answer as to the specifics of drupal but in most cases something like that would be attained using cookies. If you wanted to handle the cookies in jQuery the easiest solution is this plugin - http://plugins.jquery.com/project/cookie.

Hope that helps somewhat!

HurnsMobile
+2  A: 

If the messages are only set by administrator users, then you can be interested to Admin message that is described as:

Provides an easy way to show short messages to users. The messages can be individually closed by logged in users. Examples could be "Welcome to this site...", "Temporary downtime...", "Important security announcement...", "New feature...", etc.

By default messages that are created before a user registered is not shown to that user, something that can be overridden by an "Always show this message"-option. Also, a PHP visibility option, similar to the display option used for blocks, is available for each message. This can be used for example to only show a message for users of a specific role, show a message if a user has not filled a profile field, etc.

kiamlaluno
Hmm, I will have to try this out.
Kevin
This only seems to work for auth users. It also needs to work for anonymous users. The only way I see this happening is using a relationship table with node id, user id, session id, and a closed status, so you can track what users have seen what messages and if they closed it or not.
Kevin
As far as I remember, Drupal doesn't handle a session for anonymous users.
kiamlaluno
I saw. I used session_id() php function to track anonymous identities. Will contrib back when done, works pretty well.
Kevin
There are some modules that deal with anonymous users; in example, Fivestar (http://drupal.org/project/fivestar) allows anonymous users to vote. It could be interesting to see how that module deals with anonymous users, and if it uses particular code.
kiamlaluno
A: 

Another option would be to setup a custom region in your theme. Then move blocks, etc into that theme when you want them to be displayed. Context works well with this.

Eric M
Not sure why this was downvoted, but it wasn't me. Doesn't sound dynamic enough though, I am not sure.
Kevin
I can guess that the down vote is caused by the fact that adding a block to a top theme region would not make the messages disappear when the user clicks on the message, or after X seconds are passed; you should still find a module that rotates the messages shown in a block, which than you move on the top theme region.
kiamlaluno
using jquery, you could easily hide the block in whatever manner someone wanted. Sometimes people just don't want to think for themselves.
Eric M