Skip to content
Browse files

* added 'gritter-light' option for a class_name

* added global $.gritter.options.class_name
  • Loading branch information...
1 parent a927a2c commit 4a94f2e5fc012478e491ef87355174f0ffa7b216 Jordan Boesch committed Dec 8, 2011
Showing with 32 additions and 9 deletions.
  1. +5 −0 README.markdown
  2. BIN images/gritter-light.png
  3. +19 −2 index.html
  4. +5 −4 js/jquery.gritter.js
  5. +3 −3 js/jquery.gritter.min.js
View
5 README.markdown
@@ -5,6 +5,11 @@ A small growl-like notification plugin for jQuery
## Change Log
+### Changes in 1.7.3 (December 8, 2011)
+
+* Added $.gritter.options.class_name option
+* Added 'gritter-light' class_name option to use light messages instead of dark ones
+
### Changes in 1.7.2 (December 2, 2011)
* Added option to return false on "before_open" callback to determine whether or not to show the gritter message (good for setting a max)
View
BIN images/gritter-light.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
21 index.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" type="text/css" href="css/jquery.gritter.css" />
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">google.load('jquery', '1.7.1');</script>
-<script type="text/javascript" src="js/jquery.gritter.min.js"></script>
+<script type="text/javascript" src="js/jquery.gritter.js"></script>
<style type="text/css">
body {
background:#222 url(images/trees.jpg);
@@ -36,11 +36,14 @@
<a href="#" id="add-regular">Add regular notification</a>: Fades out after a certain amount of time, can be set for each notification.
</li>
<li>
- <a href="#" id="add-sticky">Add sticky notification</a>: Doesn't run on a fade timer. Just sits there until the user manually removes it by clicking on the (X)
+ <a href="#" id="add-sticky">Add sticky notification</a>: Doesn't run on a fade timer. Just sits there until the user manually removes it by clicking on the (X).
</li>
<li>
<a href="#" id="add-without-image">Add notification without image</a>
</li>
+ <li>
+ <a href="#" id="add-gritter-light">Add a white notification</a>: has a 'gritter-light' class_name applied to it.
+ </li>
<li>
<a href="#" id="add-with-callbacks">Add notification (with callbacks)</a>
</li>
@@ -66,6 +69,7 @@
// global setting override
/*
$.extend($.gritter.options, {
+ class_name: 'gritter-light', // for light notifications (can be added directly to $.gritter.add too)
position: 'bottom-left', // possibilities: bottom-left, bottom-right, top-left, top-right
fade_in_speed: 100, // how fast notifications fade in (string or int)
fade_out_speed: 100, // how fast the notices fade out
@@ -162,6 +166,19 @@
return false;
});
+ $('#add-gritter-light').click(function(){
+
+ $.gritter.add({
+ // (string | mandatory) the heading of the notification
+ title: 'This is a light notification',
+ // (string | mandatory) the text inside the notification
+ text: 'Just add a "gritter-light" class_name to your $.gritter.add or globally to $.gritter.options.class_name',
+ class_name: 'gritter-light'
+ });
+
+ return false;
+ });
+
$('#add-with-callbacks').click(function(){
$.gritter.add({
View
9 js/jquery.gritter.js
@@ -5,8 +5,8 @@
* Copyright (c) 2011 Jordan Boesch
* Dual licensed under the MIT and GPL licenses.
*
- * Date: December 2, 2011
- * Version: 1.7.2
+ * Date: December 8, 2011
+ * Version: 1.7.3
*/
(function($){
@@ -21,6 +21,7 @@
*/
$.gritter.options = {
position: '',
+ class_name: '', // could be set to 'gritter-light' to use white notifications
fade_in_speed: 'medium', // how fast notifications fade in
fade_out_speed: 1000, // how fast the notices fade out
time: 6000 // hang on the screen for...
@@ -63,7 +64,7 @@
/**
* Big fat Gritter object
- * @constructor (not really since it's object literal)
+ * @constructor (not really since its object literal)
*/
var Gritter = {
@@ -103,7 +104,7 @@
text = params.text,
image = params.image || '',
sticky = params.sticky || false,
- item_class = params.class_name || '',
+ item_class = params.class_name || $.gritter.options.class_name,
position = $.gritter.options.position,
time_alive = params.time || '';
View
6 js/jquery.gritter.min.js
@@ -5,7 +5,7 @@
* Copyright (c) 2011 Jordan Boesch
* Dual licensed under the MIT and GPL licenses.
*
- * Date: December 2, 2011
- * Version: 1.7.2
+ * Date: December 8, 2011
+ * Version: 1.7.3
*/
-(function(a){a.gritter={},a.gritter.options={position:"",fade_in_speed:"medium",fade_out_speed:1e3,time:6e3},a.gritter.add=function(a){try{return b.add(a||{})}catch(c){var d="Gritter Error: "+c;typeof console!="undefined"&&console.error?console.error(d,a):alert(d)}},a.gritter.remove=function(a,c){b.removeSpecific(a,c||{})},a.gritter.removeAll=function(a){b.stop(a||{})};var b={position:"",fade_in_speed:"",fade_out_speed:"",time:"",_custom_timer:0,_item_count:0,_is_setup:0,_tpl_close:'<div class="gritter-close"></div>',_tpl_item:'<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[close]][[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',_tpl_wrap:'<div id="gritter-notice-wrapper"></div>',add:function(c){if(!c.title||!c.text)throw'You need to fill out the first 2 params: "title" and "text"';this._is_setup||this._runSetup();var d=c.title,e=c.text,f=c.image||"",g=c.sticky||!1,h=c.class_name||"",i=a.gritter.options.position,j=c.time||"";this._verifyWrapper(),this._item_count++;var k=this._item_count,l=this._tpl_item;a(["before_open","after_open","before_close","after_close"]).each(function(d,e){b["_"+e+"_"+k]=a.isFunction(c[e])?c[e]:function(){}}),this._custom_timer=0,j&&(this._custom_timer=j);var m=f!=""?'<img src="'+f+'" class="gritter-image" />':"",n=f!=""?"gritter-with-image":"gritter-without-image";l=this._str_replace(["[[username]]","[[text]]","[[close]]","[[image]]","[[number]]","[[class_name]]","[[item_class]]"],[d,e,this._tpl_close,m,this._item_count,n,h],l);if(this["_before_open_"+k]()===!1)return!1;a("#gritter-notice-wrapper").addClass(i).append(l);var o=a("#gritter-item-"+this._item_count);return o.fadeIn(this.fade_in_speed,function(){b["_after_open_"+k](a(this))}),g||this._setFadeTimer(o,k),a(o).bind("mouseenter mouseleave",function(c){c.type=="mouseenter"?g||b._restoreItemIfFading(a(this),k):g||b._setFadeTimer(a(this),k),b._hoverState(a(this),c.type)}),k},_countRemoveWrapper:function(b,c,d){c.remove(),this["_after_close_"+b](c,d),a(".gritter-item-wrapper").length==0&&a("#gritter-notice-wrapper").remove()},_fade:function(a,c,d,e){var d=d||{},f=typeof d.fade!="undefined"?d.fade:!0;fade_out_speed=d.speed||this.fade_out_speed,manual_close=e,this["_before_close_"+c](a,manual_close),e&&a.unbind("mouseenter mouseleave"),f?a.animate({opacity:0},fade_out_speed,function(){a.animate({height:0},300,function(){b._countRemoveWrapper(c,a,manual_close)})}):this._countRemoveWrapper(c,a)},_hoverState:function(a,c){c=="mouseenter"?(a.addClass("hover"),a.find(".gritter-close").show(),a.find(".gritter-close").click(function(){var c=a.attr("id").split("-")[2];b.removeSpecific(c,{},a,!0)})):(a.removeClass("hover"),a.find(".gritter-close").hide())},removeSpecific:function(b,c,d,e){if(!d)var d=a("#gritter-item-"+b);this._fade(d,b,c||{},e)},_restoreItemIfFading:function(a,b){clearTimeout(this["_int_id_"+b]),a.stop().css({opacity:""})},_runSetup:function(){for(opt in a.gritter.options)this[opt]=a.gritter.options[opt];this._is_setup=1},_setFadeTimer:function(a,c){var d=this._custom_timer?this._custom_timer:this.time;this["_int_id_"+c]=setTimeout(function(){b._fade(a,c)},d)},stop:function(b){var c=a.isFunction(b.before_close)?b.before_close:function(){},d=a.isFunction(b.after_close)?b.after_close:function(){},e=a("#gritter-notice-wrapper");c(e),e.fadeOut(function(){a(this).remove(),d()})},_str_replace:function(a,b,c,d){var e=0,f=0,g="",h="",i=0,j=0,k=[].concat(a),l=[].concat(b),m=c,n=l instanceof Array,o=m instanceof Array;m=[].concat(m),d&&(this.window[d]=0);for(e=0,i=m.length;e<i;e++){if(m[e]==="")continue;for(f=0,j=k.length;f<j;f++)g=m[e]+"",h=n?l[f]!==undefined?l[f]:"":l[0],m[e]=g.split(k[f]).join(h),d&&m[e]!==g&&(this.window[d]+=(g.length-m[e].length)/k[f].length)}return o?m:m[0]},_verifyWrapper:function(){a("#gritter-notice-wrapper").length==0&&a("body").append(this._tpl_wrap)}}})(jQuery)
+(function(a){a.gritter={},a.gritter.options={position:"",class_name:"",fade_in_speed:"medium",fade_out_speed:1e3,time:6e3},a.gritter.add=function(a){try{return b.add(a||{})}catch(c){var d="Gritter Error: "+c;typeof console!="undefined"&&console.error?console.error(d,a):alert(d)}},a.gritter.remove=function(a,c){b.removeSpecific(a,c||{})},a.gritter.removeAll=function(a){b.stop(a||{})};var b={position:"",fade_in_speed:"",fade_out_speed:"",time:"",_custom_timer:0,_item_count:0,_is_setup:0,_tpl_close:'<div class="gritter-close"></div>',_tpl_item:'<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none"><div class="gritter-top"></div><div class="gritter-item">[[close]][[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div></div><div class="gritter-bottom"></div></div>',_tpl_wrap:'<div id="gritter-notice-wrapper"></div>',add:function(c){if(!c.title||!c.text)throw'You need to fill out the first 2 params: "title" and "text"';this._is_setup||this._runSetup();var d=c.title,e=c.text,f=c.image||"",g=c.sticky||!1,h=c.class_name||a.gritter.options.class_name,i=a.gritter.options.position,j=c.time||"";this._verifyWrapper(),this._item_count++;var k=this._item_count,l=this._tpl_item;a(["before_open","after_open","before_close","after_close"]).each(function(d,e){b["_"+e+"_"+k]=a.isFunction(c[e])?c[e]:function(){}}),this._custom_timer=0,j&&(this._custom_timer=j);var m=f!=""?'<img src="'+f+'" class="gritter-image" />':"",n=f!=""?"gritter-with-image":"gritter-without-image";l=this._str_replace(["[[username]]","[[text]]","[[close]]","[[image]]","[[number]]","[[class_name]]","[[item_class]]"],[d,e,this._tpl_close,m,this._item_count,n,h],l);if(this["_before_open_"+k]()===!1)return!1;a("#gritter-notice-wrapper").addClass(i).append(l);var o=a("#gritter-item-"+this._item_count);return o.fadeIn(this.fade_in_speed,function(){b["_after_open_"+k](a(this))}),g||this._setFadeTimer(o,k),a(o).bind("mouseenter mouseleave",function(c){c.type=="mouseenter"?g||b._restoreItemIfFading(a(this),k):g||b._setFadeTimer(a(this),k),b._hoverState(a(this),c.type)}),k},_countRemoveWrapper:function(b,c,d){c.remove(),this["_after_close_"+b](c,d),a(".gritter-item-wrapper").length==0&&a("#gritter-notice-wrapper").remove()},_fade:function(a,c,d,e){var d=d||{},f=typeof d.fade!="undefined"?d.fade:!0;fade_out_speed=d.speed||this.fade_out_speed,manual_close=e,this["_before_close_"+c](a,manual_close),e&&a.unbind("mouseenter mouseleave"),f?a.animate({opacity:0},fade_out_speed,function(){a.animate({height:0},300,function(){b._countRemoveWrapper(c,a,manual_close)})}):this._countRemoveWrapper(c,a)},_hoverState:function(a,c){c=="mouseenter"?(a.addClass("hover"),a.find(".gritter-close").show(),a.find(".gritter-close").click(function(){var c=a.attr("id").split("-")[2];b.removeSpecific(c,{},a,!0)})):(a.removeClass("hover"),a.find(".gritter-close").hide())},removeSpecific:function(b,c,d,e){if(!d)var d=a("#gritter-item-"+b);this._fade(d,b,c||{},e)},_restoreItemIfFading:function(a,b){clearTimeout(this["_int_id_"+b]),a.stop().css({opacity:"",height:""})},_runSetup:function(){for(opt in a.gritter.options)this[opt]=a.gritter.options[opt];this._is_setup=1},_setFadeTimer:function(a,c){var d=this._custom_timer?this._custom_timer:this.time;this["_int_id_"+c]=setTimeout(function(){b._fade(a,c)},d)},stop:function(b){var c=a.isFunction(b.before_close)?b.before_close:function(){},d=a.isFunction(b.after_close)?b.after_close:function(){},e=a("#gritter-notice-wrapper");c(e),e.fadeOut(function(){a(this).remove(),d()})},_str_replace:function(a,b,c,d){var e=0,f=0,g="",h="",i=0,j=0,k=[].concat(a),l=[].concat(b),m=c,n=l instanceof Array,o=m instanceof Array;m=[].concat(m),d&&(this.window[d]=0);for(e=0,i=m.length;e<i;e++){if(m[e]==="")continue;for(f=0,j=k.length;f<j;f++)g=m[e]+"",h=n?l[f]!==undefined?l[f]:"":l[0],m[e]=g.split(k[f]).join(h),d&&m[e]!==g&&(this.window[d]+=(g.length-m[e].length)/k[f].length)}return o?m:m[0]},_verifyWrapper:function(){a("#gritter-notice-wrapper").length==0&&a("body").append(this._tpl_wrap)}}})(jQuery)

0 comments on commit 4a94f2e

Please sign in to comment.
Something went wrong with that request. Please try again.