Skip to content

Commit 5a1d7b1

Browse files
author
Eric Hynds
committed
better codes, better docs
1 parent 0caeb25 commit 5a1d7b1

File tree

5 files changed

+111
-31
lines changed

5 files changed

+111
-31
lines changed

README.markdown

+47-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
# jQuery UI Notify Widget
22

3-
Create Growl/Ubuntu-like notifications. Uses RGBA, border-radius, and box-shadow, so they're not as pretty in IE as they could be right now.
3+
Create Growl/Ubuntu-like notifications.
4+
5+
Uses RGBA, border-radius, and box-shadow, so they're not as pretty as they could be in IE at the moment.
46

57
## Features
68

79
- No images, all CSS
8-
- Less than 100 lines of code
9-
- Built on jQuery UI widget factory
10+
- Roughly 100 lines of code
11+
- Built on top of the jQuery UI widget factory
1012
- Templating system: include whatever you want inside notifications (images, links, etc.)
11-
- beforeopen, open, and close callbacks
13+
- beforeopen, open, close, and click events
1214
- Show completely different notifications in different containers
1315
- Ability to customize options on a notification-by-notification basis
1416
- Ability to programatically call `open` and `close` methods
@@ -86,3 +88,44 @@ instance.close();
8688
instance.open();
8789
</pre>
8890

91+
## Options
92+
93+
Two options are available:
94+
95+
### speed
96+
The amount of time in MS to fade in/out notifications.
97+
98+
### expires
99+
The notification will automatically close after this amount of time, in MS. Set to `0` or `false` to create "sticky" notifications.
100+
101+
## Events
102+
103+
Four events are available to you:
104+
105+
### beforeopen
106+
Fires before the notification opens. If `false` is returned inside this callback, the notification will not open.
107+
108+
### open
109+
Fires after the notifcation opens.
110+
111+
### close
112+
Fires after the notification closes.
113+
114+
### click
115+
Fires if the user clicks anywhere in the notification itself (not on the close link(s), if present). Useful
116+
if you want to close the notification or perform some other action once the user has acknowledged the notice.
117+
118+
An example here:
119+
120+
$("#container").notify("create", {
121+
title: 'Clickable Notification',
122+
text: 'Click on me to fire a callback'
123+
},{
124+
click: function(e,instance){
125+
// close the notice if the user clicks anywhere inside it
126+
instance.close();
127+
}
128+
});
129+
130+
131+

alert.png

3.01 KB
Loading

index.htm

+52-17
Original file line numberDiff line numberDiff line change
@@ -6,34 +6,61 @@
66
<link type="text/css" rel="stylesheet" href="http://www.erichynds.com/examples/style.css" />
77
<link type="text/css" rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/redmond/jquery-ui.css" />
88
<link type="text/css" rel="stylesheet" href="ui.notify.css" />
9+
<style type="text/css">form input { display:block; width:250px; margin-bottom:5px }</style>
910
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.js" type="text/javascript"></script>
1011
<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js" type="text/javascript"></script>
11-
<script src="http://jqueryui.com/themeroller/themeswitchertool/" type="text/javascript"></script>
1212
<script src="src/jquery.notify.js" type="text/javascript"></script>
1313
<script type="text/javascript">
14-
$(function(){
14+
// create a test notification
15+
function basic(){
16+
$container.notify("create", {
17+
title: 'Default Notification',
18+
text: 'This is an example of the default config. I will disappear up after five seconds.'
19+
});
20+
}
21+
22+
function sticky(){
23+
$container.notify("create", {
24+
title: 'Sticky Notification',
25+
text: 'This is an example of a "sticky" notification. The only way to close me is to click on the X above.'
26+
},{ expires:false });
27+
}
28+
29+
function warning(){
30+
$container.notify("create", {
31+
title: 'Warning!',
32+
text: 'OMG the quick brown fox jumped over the lazy dog. You\'ve been warned. <a href="#" class="ui-notify-close">Close me.</a>',
33+
icon: '<img src="alert.png" style="margin:0 10px 0 0" />'
34+
},{ expires:false });
35+
}
36+
37+
function clickable(){
38+
$container.notify("create", {
39+
title: 'Clickable Notification',
40+
text: 'Click on me to fire a callback. Do it quick though because I will fade out after 5 seconds.'
41+
}, {
42+
click: function(e,instance){
43+
alert("Click triggered!\n\nTwo options are passed into the click callback: the original event obj and the instance object.");
44+
}
45+
});
46+
}
1547

48+
$(function(){
1649
// initialize widget on a container, passing in all the defaults.
1750
// the defaults will apply to any notification created within this
1851
// container, but can be overwritten on notification-by-notification
1952
// basis.
2053
$container = $("#container").notify();
2154

22-
// create a test notification
23-
$container.notify("create", {
24-
title: 'Test Notification',
25-
text: 'This is an example of the default config, and will slide up after five seconds.'
26-
});
27-
28-
// create another, and save the obj into the var instance.
29-
instance = $container.notify("create", {
30-
title: 'Sticky Notification',
31-
text: 'This is an example of a "sticky" notification. The only way to close me is to click on the X above.'
32-
},{
33-
expires:false
34-
});
55+
// create two when the pg loads
56+
basic();
57+
sticky();
3558

36-
// since the above instance is "sticky", it can be manually closed by calling instance.close();
59+
// bindings
60+
$("#default").click( basic );
61+
$("#sticky").click( sticky );
62+
$("#warning").click( warning );
63+
$("#clickable").click( clickable );
3764
});
3865
</script>
3966

@@ -46,10 +73,18 @@ <h1>jQuery UI Notify Widget</h1>
4673
<p>This is a growl/ubuntu-like notification system built on top of jQuery UI.</p>
4774
<p>Download &amp; docs @ <a href="http://github.com/ehynds/jquery-notify">http://github.com/ehynds/jquery-notify</a>.</p>
4875

76+
<form style="margin:20px 0">
77+
<input type="button" id="default" value="Open with default configuration" />
78+
<input type="button" id="sticky" value="Create a &quot;sticky&quot; notification" />
79+
<input type="button" id="warning" value="A more custom template" />
80+
<input type="button" id="clickable" value="The entire notification can be clicked on" />
81+
</form>
82+
4983
<!--- container to hold notifications --->
5084
<div id="container">
5185
<div>
52-
<a class="ui-notify-close" href="#">x</a>
86+
<div class="icon" style="float:left">#{icon}</div>
87+
<a class="ui-notify-close ui-notify-cross" href="#">x</a>
5388
<h1>#{title}</h1>
5489
<p>#{text}</p>
5590
</div>

src/jquery.notify.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ $.extend($.ui.notify, {
2929
$.extend($.ui.notify.instance.prototype, {
3030
_create: function(params, options){
3131
this.options = options;
32-
3332
var self = this,
3433

3534
// build html template
@@ -38,7 +37,9 @@ $.extend($.ui.notify.instance.prototype, {
3837
}),
3938

4039
// the actual message
41-
m = (this.element = $(html)),
40+
m = (this.element = $(html).bind("click", function(e){
41+
self._trigger("click", e, self);
42+
})),
4243

4344
// close link
4445
closelink = m.find("a.ui-notify-close");
@@ -58,11 +59,10 @@ $.extend($.ui.notify.instance.prototype, {
5859
});
5960
}
6061

61-
// open plz
6262
this.open();
6363

6464
// auto expire?
65-
if(typeof this.options.expires === "number"){
65+
if(typeof options.expires === "number"){
6666
window.setTimeout(function(){
6767
self.close();
6868
}, options.expires);
@@ -94,8 +94,8 @@ $.extend($.ui.notify.instance.prototype, {
9494

9595
return this;
9696
},
97-
_trigger: function(type){
98-
return this.widget._trigger.call( this, type );
97+
_trigger: function(type, e, instance){
98+
return this.widget._trigger.call( this, type, e, instance );
9999
}
100100
});
101101

ui.notify.css

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
.ui-notify-padding { padding:10px }
33
.ui-notify-message:last-child { margin-bottom:0 }
44
.ui-notify-message h1 { color:#fff; font-size:14px; font-weight:bold; margin:0; padding:0 }
5-
.ui-notify-message p { color:#fff; margin:5px 0; padding:0; line-height:18px }
6-
.ui-notify-close { margin-top:-4px; float:right; color:#fff; cursor:pointer; font-size:12px; font-weight:bold; text-shadow:0 1px 1px #fff; padding:2px }
7-
.ui-notify-close:hover { text-decoration:none; color:#ffffab }
8-
.ui-notify-close:active { position:relative; top:1px }
5+
.ui-notify-message p { color:#fff; margin:3px 0; padding:0; line-height:18px }
6+
.ui-notify-close { color:#fff; text-decoration:underline }
7+
.ui-notify-cross { margin-top:-4px; float:right; cursor:pointer; text-decoration:none; font-size:12px; font-weight:bold; text-shadow:0 1px 1px #fff; padding:2px }
8+
.ui-notify-cross:hover { color:#ffffab }
9+
.ui-notify-cross:active { position:relative; top:1px }
10+
911

1012
.ui-notify-message {
1113
margin-bottom:15px;

0 commit comments

Comments
 (0)