Permalink
Browse files

Close button is added

  • Loading branch information...
1 parent dece0ab commit 7b8126f11ae97e9269fb9b41b51785d63c30b883 @dknight dknight committed Mar 18, 2010
Showing with 43 additions and 11 deletions.
  1. +11 −1 index.html
  2. +5 −0 jquery.notifyBar.css
  3. +27 −10 jquery.notifyBar.js
View
12 index.html
@@ -83,6 +83,12 @@
<td>String</td>
<td></td>
</tr>
+ <tr>
+ <td>close</td>
+ <td>If set to true close button will be displayed</td>
+ <td>Boolean</td>
+ <td>false</td>
+ </tr>
</table>
<h3>Check different styles</h3>
@@ -95,13 +101,14 @@
<button id="error">Error style bar</button>
<button id="success">Success style bar</button>
<button id="custom">Custom styling</button>
+ <button id="close">With close button</button>
<p>
<a href="http://www.dmitri.me/blog/notify-bar">Project home</a> |
<a href="http://github.com/dknight/jQuery-Notify-bar">download source</a>
</p>
- <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
+ <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" src="jquery.notifyBar.js"></script>
<script type="text/javascript">
$(function() {
@@ -134,6 +141,9 @@
$("#custom").click(function(){
$.notifyBar({ cls: "custom", html: "Your data has been changed!" });
});
+ $("#close").click(function(){
+ $.notifyBar({ html: "Click 'close' to hide notify bar", close: true, delay: 1000000 });
+ });
});
View
5 jquery.notifyBar.css
@@ -33,4 +33,9 @@
.jquery-notify-bar.success {
color:#060;
background-color:#BBFFB6;
+}
+.notify-bar-close {
+ position:absolute;
+ left:95%;
+ font-size:11px;
}
View
37 jquery.notifyBar.js
@@ -6,7 +6,7 @@
* Licensed under the MIT license:
* http://www.opensource.org/licenses/mit-license.php
*
-* Version: 1.2.1
+* Version: 1.2.2
*
* Project home:
* http://www.dmitri.me/blog/notify-bar
@@ -16,9 +16,9 @@
* param Object
*/
jQuery.notifyBar = function(settings) {
-
+
(function($) {
-
+
var bar = notifyBarNS = {};
notifyBarNS.shown = false;
@@ -39,17 +39,20 @@ jQuery.notifyBar = function(settings) {
//Set up own class
notifyBarNS.cls = settings.cls || "";
-
+
+ //close button
+ notifyBarNS.close = settings.close || false;
+
if( notifyBarNS.jqObject) {
bar = notifyBarNS.jqObject;
notifyBarNS.html = bar.html();
} else {
- bar = $("<div></div>")
+ bar = jQuery("<div></div>")
.addClass("jquery-notify-bar")
.addClass(notifyBarNS.cls)
.attr("id", "__notifyBar");
}
-
+
bar.html(notifyBarNS.html).hide();
var id = bar.attr("id");
switch (notifyBarNS.animationSpeed) {
@@ -66,15 +69,29 @@ jQuery.notifyBar = function(settings) {
asTime = notifyBarNS.animationSpeed;
}
if( bar != 'object'); {
- $("body").prepend(bar);
+ jQuery("body").prepend(bar);
}
+
+ // Style close button in CSS file
+ if( notifyBarNS.close) {
+ bar.append(jQuery("<a href='#' class='notify-bar-close'>Close [X]</a>"));
+ jQuery(".notify-bar-close").click(function() {
+ if( bar.attr("id") == "__notifyBar") {
+ jQuery("#" + id).slideUp(asTime, function() { jQuery("#" + id).remove() });
+ } else {
+ jQuery("#" + id).slideUp(asTime);
+ }
+ return false;
+ });
+ }
+
bar.slideDown(asTime);
// If taken from DOM dot not remove just hide
if( bar.attr("id") == "__notifyBar") {
- setTimeout("$('#" + id + "').slideUp(" + asTime +", function() {$('#" + id + "').remove()});", notifyBarNS.delay + asTime);
+ setTimeout("jQuery('#" + id + "').slideUp(" + asTime +", function() {jQuery('#" + id + "').remove()});", notifyBarNS.delay + asTime);
} else {
- setTimeout("$('#" + id + "').slideUp(" + asTime +", function() {$('#" + id + "')});", notifyBarNS.delay + asTime);
+ setTimeout("jQuery('#" + id + "').slideUp(" + asTime +", function() {jQuery('#" + id + "')});", notifyBarNS.delay + asTime);
}
-
+
})(jQuery) };

0 comments on commit 7b8126f

Please sign in to comment.