gritter 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.markdown +199 -0
- data/Rakefile +2 -0
- data/gritter.gemspec +21 -0
- data/init.rb +2 -0
- data/lib/gritter.rb +49 -0
- data/lib/gritter/assets/images/error.png +0 -0
- data/lib/gritter/assets/images/gritter-close-ie6.gif +0 -0
- data/lib/gritter/assets/images/gritter-long.png +0 -0
- data/lib/gritter/assets/images/gritter.png +0 -0
- data/lib/gritter/assets/images/notice.png +0 -0
- data/lib/gritter/assets/images/progress.gif +0 -0
- data/lib/gritter/assets/images/success.png +0 -0
- data/lib/gritter/assets/images/warning.png +0 -0
- data/lib/gritter/assets/javascripts/jquery.gritter.min.js +19 -0
- data/lib/gritter/assets/stylesheets/jquery.gritter.css +94 -0
- data/lib/gritter/gflash.rb +11 -0
- data/lib/gritter/helpers.rb +80 -0
- data/lib/gritter/railtie.rb +13 -0
- data/lib/gritter/version.rb +3 -0
- data/lib/tasks/gritter.rake +6 -0
- metadata +85 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,199 @@
|
|
1
|
+
# gritter
|
2
|
+
|
3
|
+
version 0.5.1
|
4
|
+
Robin Brouwer
|
5
|
+
Daniël Zwijnenburg
|
6
|
+
45north
|
7
|
+
|
8
|
+
This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'.
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
You can use this gem by putting the following inside your Gemfile:
|
13
|
+
|
14
|
+
gem "gritter"
|
15
|
+
|
16
|
+
You can also install this as a plugin with the following command:
|
17
|
+
|
18
|
+
rails plugin install git://github.com/RobinBrouwer/gritter.git
|
19
|
+
|
20
|
+
This is a Rails 3 gem. When you're using Rails 2 you should use version 0.3 (this is a plugin):
|
21
|
+
|
22
|
+
script/plugin install git://github.com/RobinBrouwer/gritter.git -r 'tag v0.3'
|
23
|
+
|
24
|
+
Start your server and you'll see that three folders are added to your /javascripts, /stylesheets and /images folders.
|
25
|
+
Now you can use gritter inside your Rails application.
|
26
|
+
|
27
|
+
Now add the following to your head-tag inside the layout:
|
28
|
+
|
29
|
+
<%= include_gritter %>
|
30
|
+
|
31
|
+
If you also want to add jQuery together with gritter (from googleapis.com) you can use the following helper:
|
32
|
+
|
33
|
+
<%= include_gritter_and_jquery %>
|
34
|
+
|
35
|
+
You can pass extra arguments to these functions to set the default options for gritter.
|
36
|
+
|
37
|
+
:fade_in_speed => "medium" # => Allows you to set the fade-in-speed. Can be String or Integer (in ms).
|
38
|
+
:fade_out_speed => 1000 # => Allows you to set the fade-out-speed. Can be String or Integer (in ms).
|
39
|
+
:time => 8000 # => Allows you to set the time the notification stays. Must be an Integer (in ms).
|
40
|
+
|
41
|
+
The :fade_in_speed and :fade_out_speed options accept the following Strings:
|
42
|
+
|
43
|
+
"slow"
|
44
|
+
"medium"
|
45
|
+
"fast"
|
46
|
+
|
47
|
+
|
48
|
+
## v0.5 changes
|
49
|
+
|
50
|
+
I have made several changes in version 0.5:
|
51
|
+
|
52
|
+
- Works with Ruby 1.9 now (the Array.to_s was causing problems);
|
53
|
+
- Refactored a lot of code to make everything a bit more logical;
|
54
|
+
- The js helper doesn't add a semicolon (;) after the script anymore;
|
55
|
+
- The js helper accepts several scripts as options;
|
56
|
+
- Changed the way linebreaks (\n) are created;
|
57
|
+
- Added an 'e' variable for all the callbacks;
|
58
|
+
- Added String support for :fade_out_speed;
|
59
|
+
- Changed the README.
|
60
|
+
|
61
|
+
|
62
|
+
## Upcoming changes
|
63
|
+
|
64
|
+
One of the features I have in mind for the following release will be locales support for gflash.
|
65
|
+
The only thing you need to add in the Controller is what error should be shown and the locales will do the rest.
|
66
|
+
|
67
|
+
|
68
|
+
## Usage
|
69
|
+
|
70
|
+
There are several helpers you can use with gritter. All of them print out Javascript code without script-tags.
|
71
|
+
|
72
|
+
add_gritter
|
73
|
+
remove_gritter
|
74
|
+
extend_gritter
|
75
|
+
|
76
|
+
To add the script-tags we added another function called 'js'. It allows you to easily add script-tags around your javascript.
|
77
|
+
It can be used in combination with gritter, but also other Javascript you want to run.
|
78
|
+
|
79
|
+
Since version 0.3 we also added a gflash helper. You can read more about this helper below.
|
80
|
+
|
81
|
+
|
82
|
+
### add_gritter
|
83
|
+
|
84
|
+
The add_gritter helper allows you to add a gritter notification to your application.
|
85
|
+
It outputs Javascript directly into your template. It works like this inside a js.erb file:
|
86
|
+
|
87
|
+
<%= add_gritter("This is a notification just for you!") %>
|
88
|
+
|
89
|
+
The add_gritter helper allows you to easily set the text for the notification.
|
90
|
+
When you want to change the title, just pass the :title argument to the helper:
|
91
|
+
|
92
|
+
<%= add_gritter("This is a notification just for you!", :title => "Please pay attention!") %>
|
93
|
+
|
94
|
+
There are many more arguments you can pass to the helper:
|
95
|
+
|
96
|
+
:title => "This is a title" # => Allows you to set the title for the notification.
|
97
|
+
:image => "/images/rails.png" # => Allows you to add an image to the notification.
|
98
|
+
:sticky => true # => Allows you to make the notification sticky.
|
99
|
+
:time => 4000 # => Allows you to set the time when the notification disappears (in ms).
|
100
|
+
:class_name => "gritter" # => Allows you to set a different classname.
|
101
|
+
:before_open => "alert('Opening!');" # => Execute javascript before opening.
|
102
|
+
:after_open => "alert('Opened!');" # => Execute javascript after opening.
|
103
|
+
:before_close => "alert('Closing!');" # => Execute javascript before closing.
|
104
|
+
:after_close => "alert('Closed!');" # => Execute javascript after closing.
|
105
|
+
|
106
|
+
The :image argument also allows you to easily set five different images:
|
107
|
+
|
108
|
+
:success
|
109
|
+
:warning
|
110
|
+
:notice
|
111
|
+
:error
|
112
|
+
:progress
|
113
|
+
|
114
|
+
It works like this in combination with flash[:notice] and the 'js' helper:
|
115
|
+
|
116
|
+
<%= js add_gritter(flash[:notice], :image => :notice, :title => "Pay attention!", :sticky => true) %>
|
117
|
+
|
118
|
+
The js helper is almost the same as the javascript_tag helper. The difference is that you can pass several scripts at once.
|
119
|
+
You don't need to pass these scripts as an Array. The helper also adds a linebreak (\n) after each script.
|
120
|
+
|
121
|
+
<%= js add_gritter("See my notification"), add_gritter("Another one") %>
|
122
|
+
|
123
|
+
It puts all the scripts inside a single script-tag.
|
124
|
+
|
125
|
+
And that's it! You just added Growl-like notifications to your Rails application.
|
126
|
+
It's great for all kinds of notifications, including the flash notifications you want to show to your users.
|
127
|
+
|
128
|
+
|
129
|
+
### remove_gritter
|
130
|
+
|
131
|
+
The remove_gritter helper removes all gritter notifications from the screen. You can use it inside a js.erb file:
|
132
|
+
|
133
|
+
<%= remove_gritter %>
|
134
|
+
|
135
|
+
You can pass two extra arguments to this helper.
|
136
|
+
|
137
|
+
:before_close => "alert('Closing!');" # => Execute javascript before closing.
|
138
|
+
:after_close => "alert('Closed!');" # => Execute javascript after closing.
|
139
|
+
|
140
|
+
You can also use the 'js' helper to add script-tags around this helper.
|
141
|
+
|
142
|
+
|
143
|
+
### extend_gritter
|
144
|
+
|
145
|
+
The extend_gritter helper allows you to set the default gritter options, just like you can do with the include_gritter helpers.
|
146
|
+
To see what arguments you can pass to this helper just check the include_gritter helper.
|
147
|
+
|
148
|
+
You can also use the 'js' helper to add script-tags around this helper.
|
149
|
+
|
150
|
+
|
151
|
+
### gflash
|
152
|
+
|
153
|
+
The gflash helper is a different kind of flash[:notice] message. It uses the add_gritter helper and the default images used in this plugin.
|
154
|
+
It uses a session to remember the flash messages. Add the following inside your controller action:
|
155
|
+
|
156
|
+
def create
|
157
|
+
...
|
158
|
+
gflash :success => "The product has been created successfully!"
|
159
|
+
...
|
160
|
+
end
|
161
|
+
|
162
|
+
Now you can add the following to your layout view inside the body-tag:
|
163
|
+
|
164
|
+
<%= gflash %>
|
165
|
+
|
166
|
+
The flash-message will be shown with 'success.png' as the image and 'Success' as the title.
|
167
|
+
To change the title you can add the following to the gflash helper inside the layout:
|
168
|
+
|
169
|
+
<%= gflash :success => "It has been successful!" %>
|
170
|
+
|
171
|
+
Now the default title will be overwritten. You can use the following gflash options:
|
172
|
+
|
173
|
+
:success
|
174
|
+
:warning
|
175
|
+
:notice
|
176
|
+
:error
|
177
|
+
:progress
|
178
|
+
|
179
|
+
Each uses the corresponding image and title. You can also add multiple gritter notifications at once:
|
180
|
+
|
181
|
+
def create
|
182
|
+
...
|
183
|
+
gflash :success => "The product has been created successfully!", :notify => "This product doesn't have a category."
|
184
|
+
...
|
185
|
+
end
|
186
|
+
|
187
|
+
Just remember that you can only set the gflash message inside the controller.
|
188
|
+
The gflash helper inside the views will show the notification and change the title. It will not change the message.
|
189
|
+
|
190
|
+
|
191
|
+
## Special Thanks
|
192
|
+
|
193
|
+
We'd like to express our gratitude to the following people:
|
194
|
+
|
195
|
+
Many thanks to Jordan Boesch, creator of the AWESOME jQuery plugin gritter.
|
196
|
+
http://boedesign.com/blog/2009/07/11/growl-for-jquery-gritter/
|
197
|
+
|
198
|
+
Also special thanks to Liam McKay for creating the awesome icons!
|
199
|
+
http://wefunction.com/2008/07/function-free-icon-set/
|
data/Rakefile
ADDED
data/gritter.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "gritter/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "gritter"
|
7
|
+
s.version = Gritter::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Robin Brouwer", "Daniël Zwijnenburg"]
|
10
|
+
s.email = ["robin@45north.nl"]
|
11
|
+
s.homepage = "http://www.45north.nl"
|
12
|
+
s.summary = %q{Growl notifications for your Rails application.}
|
13
|
+
s.description = %q{This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a JQuery plugin called 'gritter'.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "nowarning"
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
data/init.rb
ADDED
data/lib/gritter.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'gritter/helpers'
|
2
|
+
require 'gritter/gflash'
|
3
|
+
|
4
|
+
module Gritter
|
5
|
+
def self.initialize
|
6
|
+
return if @initialized
|
7
|
+
raise "ActionController is not available yet." unless defined?(ActionController)
|
8
|
+
ActionController::Base.send(:helper, Gritter::Helpers)
|
9
|
+
ActionController::Base.send(:include, Gritter::Gflash)
|
10
|
+
Gritter.install_gritter
|
11
|
+
@initialized = true
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.install_gritter
|
15
|
+
require 'fileutils'
|
16
|
+
orig_javascripts = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'javascripts')
|
17
|
+
orig_stylesheets = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'stylesheets')
|
18
|
+
orig_images = File.join(File.dirname(__FILE__), 'gritter', 'assets', 'images')
|
19
|
+
dest_javascripts = File.join(Rails.root, 'public', 'javascripts', 'gritter')
|
20
|
+
dest_stylesheets = File.join(Rails.root, 'public', 'stylesheets', 'gritter')
|
21
|
+
dest_images = File.join(Rails.root, 'public', 'images', 'gritter')
|
22
|
+
|
23
|
+
gritter = File.join(dest_javascripts, 'jquery.gritter.min.js')
|
24
|
+
|
25
|
+
unless File.exists?(gritter) && FileUtils.identical?(File.join(orig_javascripts, 'jquery.gritter.min.js'), gritter)
|
26
|
+
begin
|
27
|
+
puts "Creating directory #{dest_javascripts}..."
|
28
|
+
FileUtils.mkdir_p dest_javascripts
|
29
|
+
puts "Creating directory #{dest_stylesheets}..."
|
30
|
+
FileUtils.mkdir_p dest_stylesheets
|
31
|
+
puts "Creating directory #{dest_images}..."
|
32
|
+
FileUtils.mkdir_p dest_images
|
33
|
+
puts "Copying gritter to #{dest_javascripts}..."
|
34
|
+
FileUtils.cp_r "#{orig_javascripts}/.", dest_javascripts
|
35
|
+
puts "Copying gritter to #{dest_stylesheets}..."
|
36
|
+
FileUtils.cp_r "#{orig_stylesheets}/.", dest_stylesheets
|
37
|
+
puts "Copying gritter to #{dest_images}..."
|
38
|
+
FileUtils.cp_r "#{orig_images}/.", dest_images
|
39
|
+
puts "Successfully installed gritter."
|
40
|
+
rescue
|
41
|
+
puts "ERROR: Problem installing gritter. Please copy the files manually."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
if defined?(Rails::Railtie)
|
48
|
+
require 'gritter/railtie'
|
49
|
+
end
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,19 @@
|
|
1
|
+
(function($){$.gritter={};$.gritter.options={fade_in_speed:'medium',fade_out_speed:1000,time:6000}
|
2
|
+
$.gritter.add=function(params){try{return Gritter.add(params||{});}catch(e){var err='Gritter Error: '+e;(typeof(console)!='undefined'&&console.error)?console.error(err,params):alert(err);}}
|
3
|
+
$.gritter.remove=function(id,params){Gritter.removeSpecific(id,params||{});}
|
4
|
+
$.gritter.removeAll=function(params){Gritter.stop(params||{});}
|
5
|
+
var Gritter={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">[[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(params){if(!params.title||!params.text){throw'You need to fill out the first 2 params: "title" and "text"';}
|
6
|
+
if(!this._is_setup){this._runSetup();}
|
7
|
+
var user=params.title,text=params.text,image=params.image||'',sticky=params.sticky||false,item_class=params.class_name||'',time_alive=params.time||'';this._verifyWrapper();this._item_count++;var number=this._item_count,tmp=this._tpl_item;$(['before_open','after_open','before_close','after_close']).each(function(i,val){Gritter['_'+val+'_'+number]=($.isFunction(params[val]))?params[val]:function(){}});this._custom_timer=0;if(time_alive){this._custom_timer=time_alive;}
|
8
|
+
var image_str=(image!='')?'<img src="'+image+'" class="gritter-image" />':'',class_name=(image!='')?'gritter-with-image':'gritter-without-image';tmp=this._str_replace(['[[username]]','[[text]]','[[image]]','[[number]]','[[class_name]]','[[item_class]]'],[user,text,image_str,this._item_count,class_name,item_class],tmp);this['_before_open_'+number]();$('#gritter-notice-wrapper').append(tmp);var item=$('#gritter-item-'+this._item_count);item.fadeIn(this.fade_in_speed,function(){Gritter['_after_open_'+number]($(this));});if(!sticky){this._setFadeTimer(item,number);}
|
9
|
+
$(item).bind('mouseenter mouseleave',function(event){if(event.type=='mouseenter'){if(!sticky){Gritter._restoreItemIfFading($(this),number);}}
|
10
|
+
else{if(!sticky){Gritter._setFadeTimer($(this),number);}}
|
11
|
+
Gritter._hoverState($(this),event.type);});return number;},_countRemoveWrapper:function(unique_id,e){e.remove();this['_after_close_'+unique_id](e);if($('.gritter-item-wrapper').length==0){$('#gritter-notice-wrapper').remove();}},_fade:function(e,unique_id,params,unbind_events){var params=params||{},fade=(typeof(params.fade)!='undefined')?params.fade:true;fade_out_speed=params.speed||this.fade_out_speed;this['_before_close_'+unique_id](e);if(unbind_events){e.unbind('mouseenter mouseleave');}
|
12
|
+
if(fade){e.animate({opacity:0},fade_out_speed,function(){e.animate({height:0},300,function(){Gritter._countRemoveWrapper(unique_id,e);})})}
|
13
|
+
else{this._countRemoveWrapper(unique_id,e);}},_hoverState:function(e,type){if(type=='mouseenter'){e.addClass('hover');var find_img=e.find('img');(find_img.length)?find_img.before(this._tpl_close):e.find('span').before(this._tpl_close);e.find('.gritter-close').click(function(){var unique_id=e.attr('id').split('-')[2];Gritter.removeSpecific(unique_id,{},e,true);});}
|
14
|
+
else{e.removeClass('hover');e.find('.gritter-close').remove();}},removeSpecific:function(unique_id,params,e,unbind_events){if(!e){var e=$('#gritter-item-'+unique_id);}
|
15
|
+
this._fade(e,unique_id,params||{},unbind_events);},_restoreItemIfFading:function(e,unique_id){clearTimeout(this['_int_id_'+unique_id]);e.stop().css({opacity:''});},_runSetup:function(){for(opt in $.gritter.options){this[opt]=$.gritter.options[opt];}
|
16
|
+
this._is_setup=1;},_setFadeTimer:function(e,unique_id){var timer_str=(this._custom_timer)?this._custom_timer:this.time;this['_int_id_'+unique_id]=setTimeout(function(){Gritter._fade(e,unique_id);},timer_str);},stop:function(params){var before_close=($.isFunction(params.before_close))?params.before_close:function(){};var after_close=($.isFunction(params.after_close))?params.after_close:function(){};var wrap=$('#gritter-notice-wrapper');before_close(wrap);wrap.fadeOut(function(){$(this).remove();after_close();});},_str_replace:function(search,replace,subject,count){var i=0,j=0,temp='',repl='',sl=0,fl=0,f=[].concat(search),r=[].concat(replace),s=subject,ra=r instanceof Array,sa=s instanceof Array;s=[].concat(s);if(count){this.window[count]=0;}
|
17
|
+
for(i=0,sl=s.length;i<sl;i++){if(s[i]===''){continue;}
|
18
|
+
for(j=0,fl=f.length;j<fl;j++){temp=s[i]+'';repl=ra?(r[j]!==undefined?r[j]:''):r[0];s[i]=(temp).split(f[j]).join(repl);if(count&&s[i]!==temp){this.window[count]+=(temp.length-s[i].length)/f[j].length;}}}
|
19
|
+
return sa?s:s[0];},_verifyWrapper:function(){if($('#gritter-notice-wrapper').length==0){$('body').append(this._tpl_wrap);}}}})(jQuery);
|
@@ -0,0 +1,94 @@
|
|
1
|
+
/* ie6 trash */
|
2
|
+
* html #gritter-notice-wrapper {
|
3
|
+
position:absolute;
|
4
|
+
}
|
5
|
+
* html .gritter-top {
|
6
|
+
margin-bottom:-10px;
|
7
|
+
}
|
8
|
+
* html .gritter-item {
|
9
|
+
padding-bottom:0;
|
10
|
+
}
|
11
|
+
* html .gritter-bottom {
|
12
|
+
margin-bottom:0;
|
13
|
+
}
|
14
|
+
* html .gritter-close {
|
15
|
+
background:url(../../images/gritter/gritter-close-ie6.gif);
|
16
|
+
width:22px;
|
17
|
+
height:22px;
|
18
|
+
top:7px;
|
19
|
+
left:7px;
|
20
|
+
}
|
21
|
+
|
22
|
+
/* the norm */
|
23
|
+
#gritter-notice-wrapper {
|
24
|
+
position:fixed;
|
25
|
+
text-align:left;
|
26
|
+
top:20px;
|
27
|
+
right:20px;
|
28
|
+
width:301px;
|
29
|
+
z-index:9999;
|
30
|
+
}
|
31
|
+
.gritter-item-wrapper {
|
32
|
+
position:relative;
|
33
|
+
margin:0 0 10px 0;
|
34
|
+
/* background:url('.'); /* ie7/8 fix */
|
35
|
+
}
|
36
|
+
.gritter-top {
|
37
|
+
background:url(../../images/gritter/gritter.png) no-repeat left -30px;
|
38
|
+
height:10px;
|
39
|
+
}
|
40
|
+
.hover .gritter-top {
|
41
|
+
background-position:right -30px;
|
42
|
+
}
|
43
|
+
.gritter-bottom {
|
44
|
+
background:url(../../images/gritter/gritter.png) no-repeat left bottom;
|
45
|
+
height:8px;
|
46
|
+
margin:0;
|
47
|
+
}
|
48
|
+
.hover .gritter-bottom {
|
49
|
+
background-position: bottom right;
|
50
|
+
}
|
51
|
+
.gritter-item {
|
52
|
+
display:block;
|
53
|
+
background:url(../../images/gritter/gritter.png) no-repeat left -40px;
|
54
|
+
color:#eee;
|
55
|
+
padding:2px 11px 8px 11px;
|
56
|
+
font-size: 11px;
|
57
|
+
font-family:verdana;
|
58
|
+
}
|
59
|
+
.hover .gritter-item {
|
60
|
+
background-position:right -40px;
|
61
|
+
}
|
62
|
+
.gritter-item p {
|
63
|
+
padding:0;
|
64
|
+
margin:0;
|
65
|
+
}
|
66
|
+
.gritter-close {
|
67
|
+
position:absolute;
|
68
|
+
top:5px;
|
69
|
+
left:3px;
|
70
|
+
background:url(../../images/gritter/gritter.png) no-repeat left top;
|
71
|
+
cursor:pointer;
|
72
|
+
width:30px;
|
73
|
+
height:30px;
|
74
|
+
}
|
75
|
+
.gritter-title {
|
76
|
+
font-size:14px;
|
77
|
+
font-weight:bold;
|
78
|
+
padding:0 0 7px 0;
|
79
|
+
display:block;
|
80
|
+
text-shadow:1px 1px #000; /* Not supported by IE :( */
|
81
|
+
}
|
82
|
+
.gritter-image {
|
83
|
+
width:48px;
|
84
|
+
height:48px;
|
85
|
+
float:left;
|
86
|
+
}
|
87
|
+
.gritter-with-image,
|
88
|
+
.gritter-without-image {
|
89
|
+
padding:0 0 5px 0;
|
90
|
+
}
|
91
|
+
.gritter-with-image {
|
92
|
+
width:220px;
|
93
|
+
float:right;
|
94
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
module Gritter
|
2
|
+
module Helpers
|
3
|
+
def include_gritter *args
|
4
|
+
options = args.extract_options!
|
5
|
+
includes = [stylesheet_link_tag("gritter/jquery.gritter.css"), javascript_include_tag("gritter/jquery.gritter.min.js")]
|
6
|
+
includes.push(js(extend_gritter(options))) if options.present?
|
7
|
+
includes.join("\n").html_safe
|
8
|
+
end
|
9
|
+
|
10
|
+
def include_gritter_and_jquery *args
|
11
|
+
includes = [javascript_include_tag("http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"), include_gritter(*args)]
|
12
|
+
includes.join("\n").html_safe
|
13
|
+
end
|
14
|
+
|
15
|
+
def add_gritter text, *args
|
16
|
+
options = args.extract_options!
|
17
|
+
options[:title] = "Notification" if options[:title].blank?
|
18
|
+
options[:image] = "/images/gritter/#{options[:image]}.png" if %w(success warning error notice progress).include?(options[:image].to_s)
|
19
|
+
notification = ["$.gritter.add({"]
|
20
|
+
notification.push("image:'#{options[:image]}',") if options[:image].present?
|
21
|
+
notification.push("sticky:#{options[:sticky]},") if options[:sticky].present?
|
22
|
+
notification.push("time:#{options[:time]},") if options[:time].present?
|
23
|
+
notification.push("class_name:'#{options[:class_name]}',") if options[:class_name].present?
|
24
|
+
notification.push("before_open:function(e){#{options[:before_open]}},") if options[:before_open].present?
|
25
|
+
notification.push("after_open:function(e){#{options[:after_open]}},") if options[:after_open].present?
|
26
|
+
notification.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
|
27
|
+
notification.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
|
28
|
+
notification.push("title:'#{escape_javascript(options[:title])}',")
|
29
|
+
notification.push("text:'#{escape_javascript(text)}'")
|
30
|
+
notification.push("});")
|
31
|
+
text.present? ? notification.join.html_safe : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def remove_gritter *args
|
35
|
+
options = args.extract_options!
|
36
|
+
removed = ["$.gritter.removeAll({"]
|
37
|
+
removed.push("before_close:function(e){#{options[:before_close]}},") if options[:before_close].present?
|
38
|
+
removed.push("after_close:function(e){#{options[:after_close]}},") if options[:after_close].present?
|
39
|
+
removed.push("});")
|
40
|
+
removed.join.html_safe
|
41
|
+
end
|
42
|
+
|
43
|
+
def extend_gritter *args
|
44
|
+
options = args.extract_options!
|
45
|
+
options[:fade_in_speed] = "'#{options[:fade_in_speed]}'" if options[:fade_in_speed].is_a?(String)
|
46
|
+
options[:fade_out_speed] = "'#{options[:fade_out_speed]}'" if options[:fade_out_speed].is_a?(String)
|
47
|
+
extended = ["$.extend($.gritter.options,{"]
|
48
|
+
extended.push("fade_in_speed:#{options[:fade_in_speed]},") if options[:fade_in_speed].present?
|
49
|
+
extended.push("fade_out_speed:#{options[:fade_out_speed]},") if options[:fade_out_speed].present?
|
50
|
+
extended.push("time:#{options[:time]}") if options[:time].present?
|
51
|
+
extended.push("});")
|
52
|
+
extended.join.html_safe
|
53
|
+
end
|
54
|
+
|
55
|
+
def gflash *args
|
56
|
+
if session[:gflash].present?
|
57
|
+
options = args.extract_options!
|
58
|
+
titles = gflash_titles(options)
|
59
|
+
flashes = session[:gflash].map { |key, value| add_gritter(value, :image => key, :title => titles[key]) }
|
60
|
+
session[:gflash] = nil
|
61
|
+
js(flashes).html_safe
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def js *args
|
66
|
+
javascript_tag(args.join("\n"))
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
|
71
|
+
def gflash_titles *args
|
72
|
+
options = args.extract_options!
|
73
|
+
titles = { :success => "Success", :warning => "Warning", :error => "Error", :notice => "Notice", :progress => "Progress" }
|
74
|
+
options.each do |key, value|
|
75
|
+
titles[key] = value if titles.has_key?(key)
|
76
|
+
end
|
77
|
+
titles
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
metadata
ADDED
@@ -0,0 +1,85 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gritter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 5
|
8
|
+
- 1
|
9
|
+
version: 0.5.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robin Brouwer
|
13
|
+
- "Dani\xC3\xABl Zwijnenburg"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-02 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a JQuery plugin called 'gritter'.
|
23
|
+
email:
|
24
|
+
- robin@45north.nl
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- Gemfile
|
34
|
+
- README.markdown
|
35
|
+
- Rakefile
|
36
|
+
- gritter.gemspec
|
37
|
+
- init.rb
|
38
|
+
- lib/gritter.rb
|
39
|
+
- lib/gritter/assets/images/error.png
|
40
|
+
- lib/gritter/assets/images/gritter-close-ie6.gif
|
41
|
+
- lib/gritter/assets/images/gritter-long.png
|
42
|
+
- lib/gritter/assets/images/gritter.png
|
43
|
+
- lib/gritter/assets/images/notice.png
|
44
|
+
- lib/gritter/assets/images/progress.gif
|
45
|
+
- lib/gritter/assets/images/success.png
|
46
|
+
- lib/gritter/assets/images/warning.png
|
47
|
+
- lib/gritter/assets/javascripts/jquery.gritter.min.js
|
48
|
+
- lib/gritter/assets/stylesheets/jquery.gritter.css
|
49
|
+
- lib/gritter/gflash.rb
|
50
|
+
- lib/gritter/helpers.rb
|
51
|
+
- lib/gritter/railtie.rb
|
52
|
+
- lib/gritter/version.rb
|
53
|
+
- lib/tasks/gritter.rake
|
54
|
+
has_rdoc: true
|
55
|
+
homepage: http://www.45north.nl
|
56
|
+
licenses: []
|
57
|
+
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
|
61
|
+
require_paths:
|
62
|
+
- lib
|
63
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
version: "0"
|
77
|
+
requirements: []
|
78
|
+
|
79
|
+
rubyforge_project: nowarning
|
80
|
+
rubygems_version: 1.3.6
|
81
|
+
signing_key:
|
82
|
+
specification_version: 3
|
83
|
+
summary: Growl notifications for your Rails application.
|
84
|
+
test_files: []
|
85
|
+
|