gritter 0.6.3 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +80 -81
- data/app/assets/images/gritter-close.png +0 -0
- data/app/assets/images/gritter.png +0 -0
- data/app/assets/images/ie-spacer.gif +0 -0
- data/app/assets/javascripts/gritter.js +475 -19
- data/app/assets/stylesheets/gritter.css.scss +119 -0
- data/lib/generators/gritter/USAGE +7 -0
- data/lib/generators/gritter/locale_generator.rb +9 -0
- data/lib/{gritter/assets → generators/gritter/templates}/gflash.en.yml +1 -1
- data/lib/gritter.rb +0 -42
- data/lib/gritter/gflash.rb +32 -10
- data/lib/gritter/helpers.rb +6 -18
- data/lib/gritter/railtie.rb +0 -4
- data/lib/gritter/version.rb +1 -1
- metadata +11 -20
- data/app/assets/images/gritter-close-ie6.gif +0 -0
- data/app/assets/images/gritter-long.png +0 -0
- data/app/assets/stylesheets/gritter.css.erb +0 -94
- 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 +0 -19
- data/lib/gritter/assets/stylesheets/jquery.gritter.css +0 -94
- data/lib/tasks/gritter.rake +0 -6
data/README.md
CHANGED
@@ -1,30 +1,27 @@
|
|
1
1
|
# gritter
|
2
2
|
|
3
|
-
version 0.
|
3
|
+
version 1.0.0
|
4
4
|
Robin Brouwer
|
5
5
|
Daniël Zwijnenburg
|
6
6
|
45north
|
7
7
|
|
8
8
|
This Ruby on Rails gem allows you to easily add Growl-like notifications to your application using a jQuery plugin called 'gritter'.
|
9
9
|
|
10
|
-
##
|
11
|
-
|
12
|
-
You can use this gem by putting the following inside your Gemfile:
|
10
|
+
## Note
|
13
11
|
|
14
|
-
|
12
|
+
This is a Rails 3.1 gem. Are you using Rails 3.0 or lower? Check out [the 'old' branch on Github](https://github.com/RobinBrouwer/gritter/tree/old). Want support for IE6?
|
13
|
+
Also check out that branch, because the newer version of gritter inside this gem dropped support for it.
|
15
14
|
|
16
|
-
You can also install this as a plugin with the following command:
|
17
15
|
|
18
|
-
|
16
|
+
## Installation
|
19
17
|
|
20
|
-
|
18
|
+
You can use this gem by putting the following inside your Gemfile:
|
21
19
|
|
22
|
-
|
20
|
+
gem "gritter", "1.0.0"
|
23
21
|
|
24
|
-
|
22
|
+
Now generate the locale for gritter:
|
25
23
|
|
26
|
-
|
27
|
-
Adding the JavaScript and CSS files is accomplished in a different way, because of the new 'assets' folder inside /app.
|
24
|
+
rails g gritter:locale
|
28
25
|
|
29
26
|
Add the following to `/app/assets/javascripts/application.js`:
|
30
27
|
|
@@ -34,64 +31,23 @@ And the following to `/app/assets/stylesheets/application.css`:
|
|
34
31
|
|
35
32
|
*= require gritter
|
36
33
|
|
37
|
-
And that's it!
|
38
|
-
|
39
|
-
## Rails 3.0 installation
|
40
|
-
|
41
|
-
Start your server and you'll see that three folders are added to your /javascripts, /stylesheets and /images folders.
|
42
|
-
Now you can use gritter inside your Rails 3.0 application.
|
43
|
-
|
44
|
-
Now add the following to your head-tag inside the layout:
|
45
|
-
|
46
|
-
<%= include_gritter %>
|
47
|
-
|
48
|
-
If you also want to add jQuery together with gritter (from googleapis.com) you can use the following helper:
|
49
|
-
|
50
|
-
<%= include_gritter_and_jquery %>
|
51
|
-
|
52
|
-
You can pass extra arguments to these functions to set the default options for gritter.
|
53
|
-
|
54
|
-
:fade_in_speed => "medium" # => Allows you to set the fade-in-speed. Can be String or Integer (in ms).
|
55
|
-
:fade_out_speed => 1000 # => Allows you to set the fade-out-speed. Can be String or Integer (in ms).
|
56
|
-
:time => 8000 # => Allows you to set the time the notification stays. Must be an Integer (in ms).
|
57
|
-
|
58
|
-
The :fade_in_speed and :fade_out_speed options accept the following Strings:
|
59
|
-
|
60
|
-
"slow"
|
61
|
-
"medium"
|
62
|
-
"fast"
|
63
|
-
|
64
|
-
Now you can use gritter inside your Rails application.
|
65
|
-
You should really check out the gflash helper. It's really handy!
|
66
|
-
|
34
|
+
And that's it!
|
67
35
|
|
68
36
|
## Changes
|
69
37
|
|
70
|
-
Version 0.
|
38
|
+
Version 1.0.0 changes (17/11/2011):
|
71
39
|
|
72
|
-
-
|
73
|
-
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
-
|
78
|
-
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
-
|
83
|
-
- README changes.
|
84
|
-
|
85
|
-
Version 0.5 changes:
|
86
|
-
|
87
|
-
- Works with Ruby 1.9 now (the Array.to_s was causing problems);
|
88
|
-
- Refactored a lot of code to make everything a bit more logical;
|
89
|
-
- The js helper doesn't add a semicolon (;) after the script anymore;
|
90
|
-
- The js helper accepts several scripts as options;
|
91
|
-
- Changed the way linebreaks (\n) are created;
|
92
|
-
- Added an 'e' variable for all the callbacks;
|
93
|
-
- Added String support for :fade_out_speed;
|
94
|
-
- Changed the README.
|
40
|
+
- Gritter now only works in Rails 3.1. You should check out the 'old' branch for other Rails versions.
|
41
|
+
- Removed everything that isn't needed for Rails 3.1.
|
42
|
+
- Added new version for the gritter jQuery plugin (1.7.1).
|
43
|
+
- Added position option for your gritter messages.
|
44
|
+
- Locale isn't automatically generated. You need to use the gritter:locale generator.
|
45
|
+
- Adding locale-based gflash messages got a bit easier.
|
46
|
+
- You can now use a :gflash option inside the redirect_to method.
|
47
|
+
- Using SCSS image_path instead of ERB image_path inside the CSS.
|
48
|
+
- Added CSS3 support for gritter.
|
49
|
+
- Refactored some parts of the gem.
|
50
|
+
- Changed the README quite a bit.
|
95
51
|
|
96
52
|
|
97
53
|
## Usage
|
@@ -105,7 +61,8 @@ There are several helpers you can use with gritter. All of them print out Javasc
|
|
105
61
|
To add the script-tags we added another function called `js`. It allows you to easily add script-tags around your javascript.
|
106
62
|
It can be used in combination with gritter, but also other Javascript you want to run.
|
107
63
|
|
108
|
-
|
64
|
+
The most popular feature of this gem is `gflash`. This replaces the regular flash messages in Rails and
|
65
|
+
automatically puts these in gritter boxes. Read further to learn more about gflash.
|
109
66
|
|
110
67
|
|
111
68
|
### add_gritter
|
@@ -171,8 +128,29 @@ You can also use the `js` helper to add script-tags around this helper.
|
|
171
128
|
|
172
129
|
### extend_gritter
|
173
130
|
|
174
|
-
The `extend_gritter` helper allows you to set the default gritter options
|
175
|
-
|
131
|
+
The `extend_gritter` helper allows you to set the default gritter options.
|
132
|
+
|
133
|
+
<%= extend_gritter :time => 1000 %>
|
134
|
+
|
135
|
+
These are the options you can pass to `extend_gritter`:
|
136
|
+
|
137
|
+
:fade_in_speed => "medium" # => Allows you to set the fade-in-speed. Can be String or Integer (in ms).
|
138
|
+
:fade_out_speed => 1000 # => Allows you to set the fade-out-speed. Can be String or Integer (in ms).
|
139
|
+
:time => 8000 # => Allows you to set the time the notification stays. Must be an Integer (in ms).
|
140
|
+
:position => :bottom_left # => Allows you to set the position for all gritter messages.
|
141
|
+
|
142
|
+
The :fade_in_speed and :fade_out_speed options accept the following Strings:
|
143
|
+
|
144
|
+
"slow"
|
145
|
+
"medium"
|
146
|
+
"fast"
|
147
|
+
|
148
|
+
The :position option accepts four different Symbols:
|
149
|
+
|
150
|
+
:top_left
|
151
|
+
:top_right # Default
|
152
|
+
:bottom_left
|
153
|
+
:bottom_right
|
176
154
|
|
177
155
|
You can also use the `js` helper to add script-tags around this helper.
|
178
156
|
|
@@ -189,13 +167,17 @@ It uses a session to remember the flash messages. Add the following inside your
|
|
189
167
|
Now you can add the following to your layout view inside the body-tag:
|
190
168
|
|
191
169
|
<%= gflash %>
|
192
|
-
|
170
|
+
|
193
171
|
The flash-message will be shown with 'success.png' as the image and 'Success' as the title.
|
194
172
|
To change the title you can add the following to the `gflash` helper inside the layout:
|
195
173
|
|
196
174
|
<%= gflash :success => "It has been successful!" %>
|
197
|
-
|
198
|
-
Now the default title will be overwritten. You can use
|
175
|
+
|
176
|
+
Now the default title will be overwritten. You can also use gflash inside `js.erb` files:
|
177
|
+
|
178
|
+
<%= gflash :js => true %>
|
179
|
+
|
180
|
+
The :success key isn't the only option supported by gflash. You can use the following gflash options:
|
199
181
|
|
200
182
|
:success
|
201
183
|
:warning
|
@@ -231,23 +213,40 @@ Now you can do the following inside your Controller:
|
|
231
213
|
gflash :notice => true
|
232
214
|
end
|
233
215
|
|
234
|
-
The locales for the `:notice` title and message will now be used. You can still pass a `String` to
|
235
|
-
|
236
|
-
You can also use gflash inside `js.erb` files:
|
216
|
+
The locales for the `:notice` title and message will now be used. You can still pass a `String` to override a locale.
|
217
|
+
Since gritter version 1.0 you can also do the following to add the gritter messages:
|
237
218
|
|
238
|
-
|
219
|
+
def create
|
220
|
+
gflash :notice, :success, :error
|
221
|
+
end
|
239
222
|
|
240
|
-
|
241
|
-
Just remember that you can only set which gflash message you want shown inside the controller.
|
242
|
-
The gflash helper inside the views will show the notification and change the title when you pass extra arguments.
|
243
|
-
It will not change the message.
|
223
|
+
No need to pass `true` to each key.
|
244
224
|
|
245
|
-
|
225
|
+
You can change the default time, sticky and class_name options for each gritter message.
|
246
226
|
This is done inside the Controller and works like this:
|
247
227
|
|
228
|
+
gflash :success => { :time => 2000, :class_name => "my_class", :sticky => true }
|
248
229
|
gflash :success => { :value => true, :time => 2000, :class_name => "my_class", :sticky => true }
|
249
230
|
gflash :error => { :value => "Custom error", :time => 3000, :class_name => "my_error_class", :sticky => false }
|
250
231
|
|
232
|
+
When you don't pass a `:value` it uses the locale. Same goes for when you pass `true` to `:value`.
|
233
|
+
|
234
|
+
You can also use gflash directly inside the `redirect_to` method.
|
235
|
+
|
236
|
+
def create
|
237
|
+
redirect_to @post, :gflash => [:notice, :success]
|
238
|
+
end
|
239
|
+
|
240
|
+
def destroy
|
241
|
+
redirect_to :posts, :gflash => { :warning => "You just deleted something important." }
|
242
|
+
end
|
243
|
+
|
244
|
+
def logged_in?
|
245
|
+
redirect_to :login, :gflash => { :error => { :value => "You are not logged in!", :sticky => true } }
|
246
|
+
end
|
247
|
+
|
248
|
+
And that's how you add gflash to your Rails application!
|
249
|
+
|
251
250
|
|
252
251
|
## Special Thanks
|
253
252
|
|
Binary file
|
File without changes
|
Binary file
|
@@ -1,19 +1,475 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
/*
|
2
|
+
* Gritter for jQuery
|
3
|
+
* http://www.boedesign.com/
|
4
|
+
*
|
5
|
+
* Copyright (c) 2011 Jordan Boesch
|
6
|
+
* Dual licensed under the MIT and GPL licenses.
|
7
|
+
*
|
8
|
+
* Date: March 29, 2011
|
9
|
+
* Version: 1.7.1
|
10
|
+
*/
|
11
|
+
|
12
|
+
// Modernizr for CSS3 support check.
|
13
|
+
window.Modernizr = function (a, b, c) {
|
14
|
+
function A(a, b) {
|
15
|
+
var c = a.charAt(0).toUpperCase() + a.substr(1),
|
16
|
+
d = (a + " " + m.join(c + " ") + c).split(" ");
|
17
|
+
return z(d, b)
|
18
|
+
}
|
19
|
+
function z(a, b) {
|
20
|
+
for (var d in a) if (j[a[d]] !== c) return b == "pfx" ? a[d] : !0;
|
21
|
+
return !1
|
22
|
+
}
|
23
|
+
function y(a, b) {
|
24
|
+
return !!~ ("" + a).indexOf(b)
|
25
|
+
}
|
26
|
+
function x(a, b) {
|
27
|
+
return typeof a === b
|
28
|
+
}
|
29
|
+
function w(a, b) {
|
30
|
+
return v(prefixes.join(a + ";") + (b || ""))
|
31
|
+
}
|
32
|
+
function v(a) {
|
33
|
+
j.cssText = a
|
34
|
+
}
|
35
|
+
var d = "2.0.6",
|
36
|
+
e = {},
|
37
|
+
f = b.documentElement,
|
38
|
+
g = b.head || b.getElementsByTagName("head")[0],
|
39
|
+
h = "modernizr",
|
40
|
+
i = b.createElement(h),
|
41
|
+
j = i.style,
|
42
|
+
k, l = Object.prototype.toString,
|
43
|
+
m = "Webkit Moz O ms Khtml".split(" "),
|
44
|
+
n = {},
|
45
|
+
o = {},
|
46
|
+
p = {},
|
47
|
+
q = [],
|
48
|
+
r = function (a, c, d, e) {
|
49
|
+
var g, i, j, k = b.createElement("div");
|
50
|
+
if (parseInt(d, 10)) while (d--) j = b.createElement("div"), j.id = e ? e[d] : h + (d + 1), k.appendChild(j);
|
51
|
+
g = ["­", "<style>", a, "</style>"].join(""), k.id = h, k.innerHTML += g, f.appendChild(k), i = c(k, a), k.parentNode.removeChild(k);
|
52
|
+
return !!i
|
53
|
+
},
|
54
|
+
s, t = {}.hasOwnProperty,
|
55
|
+
u;
|
56
|
+
!x(t, c) && !x(t.call, c) ? u = function (a, b) {
|
57
|
+
return t.call(a, b)
|
58
|
+
} : u = function (a, b) {
|
59
|
+
return b in a && x(a.constructor.prototype[b], c)
|
60
|
+
}, n.rgba = function () {
|
61
|
+
v("background-color:rgba(150,255,150,.5)");
|
62
|
+
return y(j.backgroundColor, "rgba")
|
63
|
+
}, n.borderradius = function () {
|
64
|
+
return A("borderRadius")
|
65
|
+
};
|
66
|
+
for (var B in n) u(n, B) && (s = B.toLowerCase(), e[s] = n[B](), q.push((e[s] ? "" : "no-") + s));
|
67
|
+
v(""), i = k = null, e._version = d, e._domPrefixes = m, e.testProp = function (a) {
|
68
|
+
return z([a])
|
69
|
+
}, e.testAllProps = A, e.testStyles = r;
|
70
|
+
return e
|
71
|
+
}(this, this.document);
|
72
|
+
|
73
|
+
(function($){
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Set it up as an object under the jQuery namespace
|
77
|
+
*/
|
78
|
+
$.gritter = {};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Set up global options that the user can over-ride
|
82
|
+
*/
|
83
|
+
$.gritter.options = {
|
84
|
+
position: '',
|
85
|
+
fade_in_speed: 'medium', // how fast notifications fade in
|
86
|
+
fade_out_speed: 1000, // how fast the notices fade out
|
87
|
+
time: 6000 // hang on the screen for...
|
88
|
+
}
|
89
|
+
|
90
|
+
/**
|
91
|
+
* Add a gritter notification to the screen
|
92
|
+
* @see Gritter#add();
|
93
|
+
*/
|
94
|
+
$.gritter.add = function(params){
|
95
|
+
|
96
|
+
try {
|
97
|
+
return Gritter.add(params || {});
|
98
|
+
} catch(e) {
|
99
|
+
|
100
|
+
var err = 'Gritter Error: ' + e;
|
101
|
+
(typeof(console) != 'undefined' && console.error) ?
|
102
|
+
console.error(err, params) :
|
103
|
+
alert(err);
|
104
|
+
|
105
|
+
}
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
/**
|
110
|
+
* Remove a gritter notification from the screen
|
111
|
+
* @see Gritter#removeSpecific();
|
112
|
+
*/
|
113
|
+
$.gritter.remove = function(id, params){
|
114
|
+
Gritter.removeSpecific(id, params || {});
|
115
|
+
}
|
116
|
+
|
117
|
+
/**
|
118
|
+
* Remove all notifications
|
119
|
+
* @see Gritter#stop();
|
120
|
+
*/
|
121
|
+
$.gritter.removeAll = function(params){
|
122
|
+
Gritter.stop(params || {});
|
123
|
+
}
|
124
|
+
|
125
|
+
/**
|
126
|
+
* CSS3 check
|
127
|
+
*/
|
128
|
+
var gritter_item;
|
129
|
+
var gritter_content = '[[close]][[image]]<div class="[[class_name]]"><span class="gritter-title">[[username]]</span><p>[[text]]</p></div><div style="clear:both"></div>';
|
130
|
+
if(Modernizr.borderradius && Modernizr.rgba) {
|
131
|
+
gritter_item = '<div class="gritter-item gritter-css3">'+ gritter_content +'</div>';
|
132
|
+
} else {
|
133
|
+
gritter_item = '<div class="gritter-top"></div><div class="gritter-item gritter-css2">'+ gritter_content +'</div><div class="gritter-bottom"></div>';
|
134
|
+
}
|
135
|
+
|
136
|
+
/**
|
137
|
+
* Big fat Gritter object
|
138
|
+
* @constructor (not really since it's object literal)
|
139
|
+
*/
|
140
|
+
var Gritter = {
|
141
|
+
|
142
|
+
// Public - options to over-ride with $.gritter.options in "add"
|
143
|
+
position: '',
|
144
|
+
fade_in_speed: '',
|
145
|
+
fade_out_speed: '',
|
146
|
+
time: '',
|
147
|
+
|
148
|
+
// Private - no touchy the private parts
|
149
|
+
_custom_timer: 0,
|
150
|
+
_item_count: 0,
|
151
|
+
_is_setup: 0,
|
152
|
+
_tpl_close: '<div class="gritter-close"></div>',
|
153
|
+
_tpl_item: '<div id="gritter-item-[[number]]" class="gritter-item-wrapper [[item_class]]" style="display:none">'+ gritter_item +'</div>',
|
154
|
+
_tpl_wrap: '<div id="gritter-notice-wrapper"></div>',
|
155
|
+
|
156
|
+
/**
|
157
|
+
* Add a gritter notification to the screen
|
158
|
+
* @param {Object} params The object that contains all the options for drawing the notification
|
159
|
+
* @return {Integer} The specific numeric id to that gritter notification
|
160
|
+
*/
|
161
|
+
add: function(params){
|
162
|
+
|
163
|
+
// We might have some issues if we don't have a title or text!
|
164
|
+
if(!params.title || !params.text){
|
165
|
+
throw 'You need to fill out the first 2 params: "title" and "text"';
|
166
|
+
}
|
167
|
+
|
168
|
+
// Check the options and set them once
|
169
|
+
if(!this._is_setup){
|
170
|
+
this._runSetup();
|
171
|
+
}
|
172
|
+
|
173
|
+
// Basics
|
174
|
+
var user = params.title,
|
175
|
+
text = params.text,
|
176
|
+
image = params.image || '',
|
177
|
+
sticky = params.sticky || false,
|
178
|
+
item_class = params.class_name || '',
|
179
|
+
position = $.gritter.options.position,
|
180
|
+
time_alive = params.time || '';
|
181
|
+
|
182
|
+
this._verifyWrapper();
|
183
|
+
|
184
|
+
this._item_count++;
|
185
|
+
var number = this._item_count,
|
186
|
+
tmp = this._tpl_item;
|
187
|
+
|
188
|
+
// Assign callbacks
|
189
|
+
$(['before_open', 'after_open', 'before_close', 'after_close']).each(function(i, val){
|
190
|
+
Gritter['_' + val + '_' + number] = ($.isFunction(params[val])) ? params[val] : function(){}
|
191
|
+
});
|
192
|
+
|
193
|
+
// Reset
|
194
|
+
this._custom_timer = 0;
|
195
|
+
|
196
|
+
// A custom fade time set
|
197
|
+
if(time_alive){
|
198
|
+
this._custom_timer = time_alive;
|
199
|
+
}
|
200
|
+
|
201
|
+
var image_str = (image != '') ? '<img src="' + image + '" class="gritter-image" />' : '',
|
202
|
+
class_name = (image != '') ? 'gritter-with-image' : 'gritter-without-image';
|
203
|
+
|
204
|
+
// String replacements on the template
|
205
|
+
tmp = this._str_replace(
|
206
|
+
['[[username]]', '[[text]]', '[[close]]', '[[image]]', '[[number]]', '[[class_name]]', '[[item_class]]'],
|
207
|
+
[user, text, this._tpl_close, image_str, this._item_count, class_name, item_class], tmp
|
208
|
+
);
|
209
|
+
|
210
|
+
this['_before_open_' + number]();
|
211
|
+
$('#gritter-notice-wrapper').addClass(position).append(tmp);
|
212
|
+
|
213
|
+
var item = $('#gritter-item-' + this._item_count);
|
214
|
+
|
215
|
+
item.fadeIn(this.fade_in_speed, function(){
|
216
|
+
Gritter['_after_open_' + number]($(this));
|
217
|
+
});
|
218
|
+
|
219
|
+
if(!sticky){
|
220
|
+
this._setFadeTimer(item, number);
|
221
|
+
}
|
222
|
+
|
223
|
+
// Bind the hover/unhover states
|
224
|
+
$(item).bind('mouseenter mouseleave', function(event){
|
225
|
+
if(event.type == 'mouseenter'){
|
226
|
+
if(!sticky){
|
227
|
+
Gritter._restoreItemIfFading($(this), number);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
else {
|
231
|
+
if(!sticky){
|
232
|
+
Gritter._setFadeTimer($(this), number);
|
233
|
+
}
|
234
|
+
}
|
235
|
+
Gritter._hoverState($(this), event.type);
|
236
|
+
});
|
237
|
+
|
238
|
+
return number;
|
239
|
+
|
240
|
+
},
|
241
|
+
|
242
|
+
/**
|
243
|
+
* If we don't have any more gritter notifications, get rid of the wrapper using this check
|
244
|
+
* @private
|
245
|
+
* @param {Integer} unique_id The ID of the element that was just deleted, use it for a callback
|
246
|
+
* @param {Object} e The jQuery element that we're going to perform the remove() action on
|
247
|
+
* @param {Boolean} manual_close Did we close the gritter dialog with the (X) button
|
248
|
+
*/
|
249
|
+
_countRemoveWrapper: function(unique_id, e, manual_close){
|
250
|
+
|
251
|
+
// Remove it then run the callback function
|
252
|
+
e.remove();
|
253
|
+
this['_after_close_' + unique_id](e, manual_close);
|
254
|
+
|
255
|
+
// Check if the wrapper is empty, if it is.. remove the wrapper
|
256
|
+
if($('.gritter-item-wrapper').length == 0){
|
257
|
+
$('#gritter-notice-wrapper').remove();
|
258
|
+
}
|
259
|
+
|
260
|
+
},
|
261
|
+
|
262
|
+
/**
|
263
|
+
* Fade out an element after it's been on the screen for x amount of time
|
264
|
+
* @private
|
265
|
+
* @param {Object} e The jQuery element to get rid of
|
266
|
+
* @param {Integer} unique_id The id of the element to remove
|
267
|
+
* @param {Object} params An optional list of params to set fade speeds etc.
|
268
|
+
* @param {Boolean} unbind_events Unbind the mouseenter/mouseleave events if they click (X)
|
269
|
+
*/
|
270
|
+
_fade: function(e, unique_id, params, unbind_events){
|
271
|
+
|
272
|
+
var params = params || {},
|
273
|
+
fade = (typeof(params.fade) != 'undefined') ? params.fade : true;
|
274
|
+
fade_out_speed = params.speed || this.fade_out_speed,
|
275
|
+
manual_close = unbind_events;
|
276
|
+
|
277
|
+
this['_before_close_' + unique_id](e, manual_close);
|
278
|
+
|
279
|
+
// If this is true, then we are coming from clicking the (X)
|
280
|
+
if(unbind_events){
|
281
|
+
e.unbind('mouseenter mouseleave');
|
282
|
+
}
|
283
|
+
|
284
|
+
// Fade it out or remove it
|
285
|
+
if(fade){
|
286
|
+
|
287
|
+
e.fadeOut(fade_out_speed, function(){
|
288
|
+
e.animate({ height: 0 }, 300, function(){
|
289
|
+
Gritter._countRemoveWrapper(unique_id, e, manual_close);
|
290
|
+
})
|
291
|
+
})
|
292
|
+
|
293
|
+
}
|
294
|
+
else {
|
295
|
+
|
296
|
+
this._countRemoveWrapper(unique_id, e);
|
297
|
+
|
298
|
+
}
|
299
|
+
|
300
|
+
},
|
301
|
+
|
302
|
+
/**
|
303
|
+
* Perform actions based on the type of bind (mouseenter, mouseleave)
|
304
|
+
* @private
|
305
|
+
* @param {Object} e The jQuery element
|
306
|
+
* @param {String} type The type of action we're performing: mouseenter or mouseleave
|
307
|
+
*/
|
308
|
+
_hoverState: function(e, type){
|
309
|
+
|
310
|
+
// Change the border styles and add the (X) close button when you hover
|
311
|
+
if(type == 'mouseenter'){
|
312
|
+
|
313
|
+
e.addClass('hover');
|
314
|
+
|
315
|
+
// Show close button
|
316
|
+
e.find('.gritter-close').show();
|
317
|
+
|
318
|
+
// Clicking (X) makes the perdy thing close
|
319
|
+
e.find('.gritter-close').click(function(){
|
320
|
+
|
321
|
+
var unique_id = e.attr('id').split('-')[2];
|
322
|
+
Gritter.removeSpecific(unique_id, {}, e, true);
|
323
|
+
|
324
|
+
});
|
325
|
+
|
326
|
+
}
|
327
|
+
// Remove the border styles and hide (X) close button when you mouse out
|
328
|
+
else {
|
329
|
+
|
330
|
+
e.removeClass('hover');
|
331
|
+
|
332
|
+
// Hide close button
|
333
|
+
e.find('.gritter-close').hide();
|
334
|
+
|
335
|
+
}
|
336
|
+
|
337
|
+
},
|
338
|
+
|
339
|
+
/**
|
340
|
+
* Remove a specific notification based on an ID
|
341
|
+
* @param {Integer} unique_id The ID used to delete a specific notification
|
342
|
+
* @param {Object} params A set of options passed in to determine how to get rid of it
|
343
|
+
* @param {Object} e The jQuery element that we're "fading" then removing
|
344
|
+
* @param {Boolean} unbind_events If we clicked on the (X) we set this to true to unbind mouseenter/mouseleave
|
345
|
+
*/
|
346
|
+
removeSpecific: function(unique_id, params, e, unbind_events){
|
347
|
+
|
348
|
+
if(!e){
|
349
|
+
var e = $('#gritter-item-' + unique_id);
|
350
|
+
}
|
351
|
+
|
352
|
+
// We set the fourth param to let the _fade function know to
|
353
|
+
// unbind the "mouseleave" event. Once you click (X) there's no going back!
|
354
|
+
this._fade(e, unique_id, params || {}, unbind_events);
|
355
|
+
|
356
|
+
},
|
357
|
+
|
358
|
+
/**
|
359
|
+
* If the item is fading out and we hover over it, restore it!
|
360
|
+
* @private
|
361
|
+
* @param {Object} e The HTML element to remove
|
362
|
+
* @param {Integer} unique_id The ID of the element
|
363
|
+
*/
|
364
|
+
_restoreItemIfFading: function(e, unique_id){
|
365
|
+
|
366
|
+
clearTimeout(this['_int_id_' + unique_id]);
|
367
|
+
e.stop().css({ opacity: '' });
|
368
|
+
|
369
|
+
},
|
370
|
+
|
371
|
+
/**
|
372
|
+
* Setup the global options - only once
|
373
|
+
* @private
|
374
|
+
*/
|
375
|
+
_runSetup: function(){
|
376
|
+
|
377
|
+
for(opt in $.gritter.options){
|
378
|
+
this[opt] = $.gritter.options[opt];
|
379
|
+
}
|
380
|
+
this._is_setup = 1;
|
381
|
+
|
382
|
+
},
|
383
|
+
|
384
|
+
/**
|
385
|
+
* Set the notification to fade out after a certain amount of time
|
386
|
+
* @private
|
387
|
+
* @param {Object} item The HTML element we're dealing with
|
388
|
+
* @param {Integer} unique_id The ID of the element
|
389
|
+
*/
|
390
|
+
_setFadeTimer: function(e, unique_id){
|
391
|
+
|
392
|
+
var timer_str = (this._custom_timer) ? this._custom_timer : this.time;
|
393
|
+
this['_int_id_' + unique_id] = setTimeout(function(){
|
394
|
+
Gritter._fade(e, unique_id);
|
395
|
+
}, timer_str);
|
396
|
+
|
397
|
+
},
|
398
|
+
|
399
|
+
/**
|
400
|
+
* Bring everything to a halt
|
401
|
+
* @param {Object} params A list of callback functions to pass when all notifications are removed
|
402
|
+
*/
|
403
|
+
stop: function(params){
|
404
|
+
|
405
|
+
// callbacks (if passed)
|
406
|
+
var before_close = ($.isFunction(params.before_close)) ? params.before_close : function(){};
|
407
|
+
var after_close = ($.isFunction(params.after_close)) ? params.after_close : function(){};
|
408
|
+
|
409
|
+
var wrap = $('#gritter-notice-wrapper');
|
410
|
+
before_close(wrap);
|
411
|
+
wrap.fadeOut(function(){
|
412
|
+
$(this).remove();
|
413
|
+
after_close();
|
414
|
+
});
|
415
|
+
|
416
|
+
},
|
417
|
+
|
418
|
+
/**
|
419
|
+
* An extremely handy PHP function ported to JS, works well for templating
|
420
|
+
* @private
|
421
|
+
* @param {String/Array} search A list of things to search for
|
422
|
+
* @param {String/Array} replace A list of things to replace the searches with
|
423
|
+
* @return {String} sa The output
|
424
|
+
*/
|
425
|
+
_str_replace: function(search, replace, subject, count){
|
426
|
+
|
427
|
+
var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
|
428
|
+
f = [].concat(search),
|
429
|
+
r = [].concat(replace),
|
430
|
+
s = subject,
|
431
|
+
ra = r instanceof Array, sa = s instanceof Array;
|
432
|
+
s = [].concat(s);
|
433
|
+
|
434
|
+
if(count){
|
435
|
+
this.window[count] = 0;
|
436
|
+
}
|
437
|
+
|
438
|
+
for(i = 0, sl = s.length; i < sl; i++){
|
439
|
+
|
440
|
+
if(s[i] === ''){
|
441
|
+
continue;
|
442
|
+
}
|
443
|
+
|
444
|
+
for (j = 0, fl = f.length; j < fl; j++){
|
445
|
+
|
446
|
+
temp = s[i] + '';
|
447
|
+
repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
|
448
|
+
s[i] = (temp).split(f[j]).join(repl);
|
449
|
+
|
450
|
+
if(count && s[i] !== temp){
|
451
|
+
this.window[count] += (temp.length-s[i].length) / f[j].length;
|
452
|
+
}
|
453
|
+
|
454
|
+
}
|
455
|
+
}
|
456
|
+
|
457
|
+
return sa ? s : s[0];
|
458
|
+
|
459
|
+
},
|
460
|
+
|
461
|
+
/**
|
462
|
+
* A check to make sure we have something to wrap our notices with
|
463
|
+
* @private
|
464
|
+
*/
|
465
|
+
_verifyWrapper: function(){
|
466
|
+
|
467
|
+
if($('#gritter-notice-wrapper').length == 0){
|
468
|
+
$('body').append(this._tpl_wrap);
|
469
|
+
}
|
470
|
+
|
471
|
+
}
|
472
|
+
|
473
|
+
}
|
474
|
+
|
475
|
+
})(jQuery);
|