My favorites | Sign in
Project Logo
                
Search
for
Updated Feb 01, 2009 by tbenniks
Labels: Featured, Phase-Implementation, Phase-Design
Implementation  

This page illustrates the very simple implementation of jQuery Notice

How it works

This plugin extends jQuery. That means that you can call it like this: jQuery.noticeAdd() or jQuery.noticeRemove(). The fact that it is not bound to an html object makes this plugin very easy to use. It is callable or removable from any function. For example: it could be initiated as callback from a function or on a success or failure after an Ajax request.

The html

<button class="add">Add sticky notice</button>
<button class="add2">Add normal notice</button>
<button class="remove">Revome all notices</button>

The javascript

$(document).ready(function()
{
	$('button.add').click(function()
	{
		jQuery.noticeAdd({
			text: 'This is a notification that you have to remove',
			stay: true
		});
	});
	
	$('button.add2').click(function()
	{
		jQuery.noticeAdd({
			text: 'This is a notification that does not stay',
			stay: false
		});
	});
	
	$('button.remove').click(function()
	{
		jQuery.noticeRemove($('.notice-item-wrapper'), 400);
	});
});

These are the defaults settings for the noticeAdd function

var defaults = {
	inEffect: 		{opacity: 'show'},	// in effect
	inEffectDuration: 	600,			// in effect duration in miliseconds
	stayTime: 		3000,			// time in miliseconds before the item has to disappear
	text: 			'',			// content of the item
	stay:			false,			// should the notice item stay or not?
	type:			'notice' 		// could also be error, succes
}

You can overwrite these defaults like this:

jQuery.noticeAdd({
	text: 'This is a notification that you have to remove',
	stay: true
});

Comment by dmindesigns, Feb 09, 2009

simple and elegant.. :o) like it

Comment by tbenniks, Feb 11, 2009

Thanks! I hope it works for you.

Comment by JRBenning, Feb 13, 2009

This is awesome. I like it far better than jGrowl. Question: I tried setting type to 'error' and 'success' and it didn't seem to change the look of the notice. Am I doing something wrong?

Comment by tbenniks, Feb 13, 2009

Hi, Thanks for the great reply. If you change the type setting a class gets added to the notification item. Just add a css class like: .notice, .error or .success and off you go.

Comment by JRBenning, Feb 16, 2009

You da man! Thanks. Any thoughts. on how I could keep the notices in the upper right side, but have the errors and success come up in the middle of the screen?

Thanks again... love this plug-in/extension :-)

Comment by ilruffo, Feb 19, 2009

This is exactly what I was looking for. Thanks for your precious time.

Comment by tbenniks, Feb 19, 2009

Hey ilruffo, thanks for you great comment. I spend the time enjoying the build!

Comment by mamboen, Feb 27, 2009

I tried two other plugins but found them not meeting my criteria of small and easy to implement. This one is brilliant... thanks and I appreciate your time and effort!

Comment by mamboen, Mar 10, 2009

I may be using this incorrectly but if I issue a jQuery.noticeRemove (to remove any sticky notices) then issue jQuery.noticeAdd, my new notice is also removed.

Comment by tbenniks, Mar 10, 2009

Hi mamboen,

You can give an jQuery object to the remove notice function. Can you maybe show me your code? I cannot see why you last (new) notice gets removed.

Comment by mamboen, Mar 10, 2009

Tim, here's the code, I've removed the unecessary code.

   function getData2() {
      // First, drop any "notices" that might be currently raised.
      jQuery.noticeRemove($('.notice-item-wrapper'));

      var inputContents = $('#part_number').val() + $('#customer').val() + $('#date_code').val() + $('#lot_number').val();

      if ($.trim(inputContents) == '') {
         // Raise notice to alert user.
         jQuery.noticeAdd({
           text: 'Please enter query parameter(s).',
           stay: true,
           type: 'error'
         });
      }	  	  	  	  
   }      	     

You can also duplicate it on your demo page... 1) click Add sticky notice 2) click Remove all notices, then quickly 3) click Add normal notice.

hth!

Comment by silfreed, Mar 20, 2009

I'm experiencing the same thing as mamboen; I'll file an issue for it.

Comment by 7331h4x0r, Apr 03, 2009

Awesome! I've found a perfect situation where I can use this. :D

Just one question… Is it possible to add a sound to the notification?

Comment by luigimarco, Jun 06, 2009

Hi. maybe the problem can be the time effect of removeNotice... I set 600 and 300 to 0 and now there isn't the problem.

Comment by luigimarco, Jun 07, 2009

I solve editing noticeRemove

noticeRemove: function(obj)
{
  obj.animate({opacity: '0'}, 600, function()
  {
    obj.parent().animate({height: '0px'}, 300, function()
    {
      $(obj).find('.notice-item').remove();
    });
  });
}
Comment by jose.gosende, Jul 14, 2009

Is it possible to place the notice box somewhere else besides on the upper right hand corner?

Comment by scy...@hotmail.com, Aug 08, 2009

Suppose i append <div class="notice_text">The text</div> on the notice more than once and insert a code e.g $('.notice_text').click(function(){ alert('Alerted'); }); it would alert only with the first div that i had appended, and the other div(s) seems to have no function at all , is there any way to fix this where the function could be applied to ever div(s) that i had appended??? Trying to create a download package with this script and i am facing this problem to remove the div(s) and call ajax function.

Comment by haryx8, Sep 11, 2009

cool man... it can be my next feature on my webpage....

Comment by tbenniks, Sep 12, 2009

@haryx8, sound great! Post the link here when you write about the plugin! :-)


Sign in to add a comment
Hosted by Google Code