noty-rails 2.0.3

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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .idea/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in underscore-rails.gemspec
4
+ gemspec
@@ -0,0 +1,25 @@
1
+ Rails asset-pipeline gem to provide [Noty](http://needim.github.com/noty/)
2
+
3
+ # Install
4
+ ```ruby
5
+ gem 'noty-rails'
6
+ ```
7
+
8
+ # Usage
9
+
10
+ Look at the [official installation instructions](http://needim.github.com/noty/#installation)
11
+
12
+ ## Where to put require statement
13
+ Since you can set some default config of Noty including layout
14
+ I think it is more sensible to put the require statements in the same file (As you have to require the layout and theme files you need)
15
+ ```coffeescript
16
+ # app/assets/javascripts/shared/flashes/noty-config.js.coffee
17
+ #= require noty/jquery.noty
18
+ #= require noty/layouts/bottom
19
+ #= require noty/themes/default
20
+
21
+ $ = jQuery
22
+
23
+ $.noty.defaults.timeout = 8000
24
+ $.noty.defaults.layout = 'bottom'
25
+ ```
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,11 @@
1
+ require "noty-rails/version"
2
+
3
+ module Noty
4
+ module Rails
5
+ if defined?(::Rails) and ::Rails.version >= "3.1"
6
+ class Rails::Engine < ::Rails::Engine
7
+ # this class enables the asset pipeline
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Noty
2
+ module Rails
3
+ VERSION = "2.0.3"
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "noty-rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "noty-rails"
7
+ s.version = Noty::Rails::VERSION
8
+ s.authors = ["PikachuEXE"]
9
+ s.email = ["pikachuexe@gmail.com"]
10
+ s.homepage = "https://github.com/noty/noty-rails"
11
+ s.summary = "Noty asset pipeline provider/wrapper"
12
+ s.description = "This gem provides Noty, a jQuery Notification Plugin, for your Rails application."
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ end
@@ -0,0 +1,471 @@
1
+ /**
2
+ * noty - jQuery Notification Plugin v2.0.3
3
+ * Contributors: https://github.com/needim/noty/graphs/contributors
4
+ *
5
+ * Examples and Documentation - http://needim.github.com/noty/
6
+ *
7
+ * Licensed under the MIT licenses:
8
+ * http://www.opensource.org/licenses/mit-license.php
9
+ *
10
+ **/
11
+
12
+ if (typeof Object.create !== 'function') {
13
+ Object.create = function (o) {
14
+ function F() {};
15
+ F.prototype = o;
16
+ return new F();
17
+ };
18
+ };
19
+
20
+ ;(function($) {
21
+
22
+ var NotyObject = {
23
+
24
+ init: function(options) {
25
+
26
+ // Mix in the passed in options with the default options
27
+ this.options = $.extend({}, $.noty.defaults, options);
28
+
29
+ this.options.layout = (this.options.custom) ? $.noty.layouts['inline'] : $.noty.layouts[this.options.layout];
30
+ this.options.theme = $.noty.themes[this.options.theme];
31
+
32
+ delete options.layout, delete options.theme;
33
+
34
+ this.options = $.extend({}, this.options, this.options.layout.options);
35
+ this.options.id = 'noty_' + (new Date().getTime() * Math.floor(Math.random()* 1000000));
36
+
37
+ this.options = $.extend({}, this.options, options);
38
+
39
+ // Build the noty dom initial structure
40
+ this._build();
41
+
42
+ // return this so we can chain/use the bridge with less code.
43
+ return this;
44
+ }, // end init
45
+
46
+ _build: function() {
47
+
48
+ // Generating noty bar
49
+ var $bar = $('<div class="noty_bar"/>').attr('id', this.options.id);
50
+ $bar.append(this.options.template).find('.noty_text').html(this.options.text);
51
+
52
+ this.$bar = (this.options.layout.parent.object !== null) ? $(this.options.layout.parent.object).css(this.options.layout.parent.css).append($bar) : $bar;
53
+
54
+ // Set buttons if available
55
+ if (this.options.buttons) {
56
+
57
+ // If we have button disable closeWith & timeout options
58
+ this.options.closeWith = [], this.options.timeout = false;
59
+
60
+ var $buttons = $('<div/>').addClass('noty_buttons');
61
+
62
+ (this.options.layout.parent.object !== null) ? this.$bar.find('.noty_bar').append($buttons) : this.$bar.append($buttons);
63
+
64
+ var self = this;
65
+
66
+ $.each(this.options.buttons, function(i, button) {
67
+ var $button = $('<button/>').addClass((button.addClass) ? button.addClass : 'gray').html(button.text)
68
+ .appendTo(self.$bar.find('.noty_buttons'))
69
+ .bind('click', function(e) { if ($.isFunction(button.onClick)) { button.onClick.call($button, self); } });
70
+ });
71
+ }
72
+
73
+ // For easy access
74
+ this.$message = this.$bar.find('.noty_message');
75
+ this.$closeButton = this.$bar.find('.noty_close');
76
+ this.$buttons = this.$bar.find('.noty_buttons');
77
+
78
+ $.noty.store[this.options.id] = this; // store noty for api
79
+
80
+ }, // end _build
81
+
82
+ show: function() {
83
+
84
+ var self = this;
85
+
86
+ $(self.options.layout.container.selector).append(self.$bar);
87
+
88
+ self.options.theme.style.apply(self);
89
+
90
+ ($.type(self.options.layout.css) === 'function') ? this.options.layout.css.apply(self.$bar) : self.$bar.css(this.options.layout.css || {});
91
+
92
+ self.$bar.addClass(self.options.layout.addClass);
93
+
94
+ self.options.layout.container.style.apply($(self.options.layout.container.selector));
95
+
96
+ self.options.theme.callback.onShow.apply(this);
97
+
98
+ if ($.inArray('click', self.options.closeWith) > -1)
99
+ self.$bar.css('cursor', 'pointer').one('click', function() { self.close(); });
100
+
101
+ if ($.inArray('hover', self.options.closeWith) > -1)
102
+ self.$bar.one('mouseenter', function() { self.close(); });
103
+
104
+ if ($.inArray('button', self.options.closeWith) > -1)
105
+ self.$closeButton.one('click', function() { self.close(); });
106
+
107
+ if ($.inArray('button', self.options.closeWith) == -1)
108
+ self.$closeButton.remove();
109
+
110
+ if (self.options.callback.onShow)
111
+ self.options.callback.onShow.apply(self);
112
+
113
+ self.$bar.animate(
114
+ self.options.animation.open,
115
+ self.options.animation.speed,
116
+ self.options.animation.easing,
117
+ function() {
118
+ if (self.options.callback.afterShow) self.options.callback.afterShow.apply(self);
119
+ self.shown = true;
120
+ });
121
+
122
+ // If noty is have a timeout option
123
+ if (self.options.timeout)
124
+ self.$bar.delay(self.options.timeout).promise().done(function() { self.close(); });
125
+
126
+ return this;
127
+
128
+ }, // end show
129
+
130
+ close: function() {
131
+
132
+ if (this.closed) return;
133
+
134
+ var self = this;
135
+
136
+ if (!this.shown) { // If we are still waiting in the queue just delete from queue
137
+ $.each($.noty.queue, function(i, n) {
138
+ if (n.options.id == self.options.id) {
139
+ $.noty.queue.splice(i, 1);
140
+ }
141
+ });
142
+ return;
143
+ }
144
+
145
+ self.$bar.addClass('i-am-closing-now');
146
+
147
+ if (self.options.callback.onClose) { self.options.callback.onClose.apply(self); }
148
+
149
+ self.$bar.clearQueue().stop().animate(
150
+ self.options.animation.close,
151
+ self.options.animation.speed,
152
+ self.options.animation.easing,
153
+ function() { if (self.options.callback.afterClose) self.options.callback.afterClose.apply(self); })
154
+ .promise().done(function() {
155
+
156
+ // Modal Cleaning
157
+ if (self.options.modal) {
158
+ $.notyRenderer.setModalCount(-1);
159
+ if ($.notyRenderer.getModalCount() == 0) $('.noty_modal').fadeOut('fast', function() { $(this).remove(); });
160
+ }
161
+
162
+ // Layout Cleaning
163
+ $.notyRenderer.setLayoutCountFor(self, -1);
164
+ if ($.notyRenderer.getLayoutCountFor(self) == 0) $(self.options.layout.container.selector).remove();
165
+
166
+ self.$bar.remove();
167
+ self.$bar = null;
168
+ self.closed = true;
169
+
170
+ delete $.noty.store[self.options.id]; // deleting noty from store
171
+
172
+ if (!self.options.dismissQueue) {
173
+ // Queue render
174
+ $.noty.ontap = true;
175
+
176
+ $.notyRenderer.render();
177
+ }
178
+
179
+ });
180
+
181
+ }, // end close
182
+
183
+ setText: function(text) {
184
+ if (!this.closed) {
185
+ this.options.text = text;
186
+ this.$bar.find('.noty_text').html(text);
187
+ }
188
+ return this;
189
+ },
190
+
191
+ setType: function(type) {
192
+ if (!this.closed) {
193
+ this.options.type = type;
194
+ this.options.theme.style.apply(this);
195
+ this.options.theme.callback.onShow.apply(this);
196
+ }
197
+ return this;
198
+ },
199
+
200
+ closed: false,
201
+ shown: false
202
+
203
+ }; // end NotyObject
204
+
205
+ $.notyRenderer = {};
206
+
207
+ $.notyRenderer.init = function(options) {
208
+
209
+ // Renderer creates a new noty
210
+ var notification = Object.create(NotyObject).init(options);
211
+
212
+ (notification.options.force) ? $.noty.queue.unshift(notification) : $.noty.queue.push(notification);
213
+
214
+ $.notyRenderer.render();
215
+
216
+ return ($.noty.returns == 'object') ? notification : notification.options.id;
217
+ };
218
+
219
+ $.notyRenderer.render = function() {
220
+
221
+ var instance = $.noty.queue[0];
222
+
223
+ if ($.type(instance) === 'object') {
224
+ if (instance.options.dismissQueue) {
225
+ $.notyRenderer.show($.noty.queue.shift());
226
+ } else {
227
+ if ($.noty.ontap) {
228
+ $.notyRenderer.show($.noty.queue.shift());
229
+ $.noty.ontap = false;
230
+ }
231
+ }
232
+ } else {
233
+ $.noty.ontap = true; // Queue is over
234
+ }
235
+
236
+ };
237
+
238
+ $.notyRenderer.show = function(notification) {
239
+
240
+ if (notification.options.modal) {
241
+ $.notyRenderer.createModalFor(notification);
242
+ $.notyRenderer.setModalCount(+1);
243
+ }
244
+
245
+ // Where is the container?
246
+ if ($(notification.options.layout.container.selector).length == 0) {
247
+ if (notification.options.custom) {
248
+ notification.options.custom.append($(notification.options.layout.container.object).addClass('i-am-new'));
249
+ } else {
250
+ $('body').append($(notification.options.layout.container.object).addClass('i-am-new'));
251
+ }
252
+ } else {
253
+ $(notification.options.layout.container.selector).removeClass('i-am-new');
254
+ }
255
+
256
+ $.notyRenderer.setLayoutCountFor(notification, +1);
257
+
258
+ notification.show();
259
+ };
260
+
261
+ $.notyRenderer.createModalFor = function(notification) {
262
+ if ($('.noty_modal').length == 0)
263
+ $('<div/>').addClass('noty_modal').data('noty_modal_count', 0).css(notification.options.theme.modal.css).prependTo($('body')).fadeIn('fast');
264
+ };
265
+
266
+ $.notyRenderer.getLayoutCountFor = function(notification) {
267
+ return $(notification.options.layout.container.selector).data('noty_layout_count') || 0;
268
+ };
269
+
270
+ $.notyRenderer.setLayoutCountFor = function(notification, arg) {
271
+ return $(notification.options.layout.container.selector).data('noty_layout_count', $.notyRenderer.getLayoutCountFor(notification) + arg);
272
+ };
273
+
274
+ $.notyRenderer.getModalCount = function() {
275
+ return $('.noty_modal').data('noty_modal_count') || 0;
276
+ };
277
+
278
+ $.notyRenderer.setModalCount = function(arg) {
279
+ return $('.noty_modal').data('noty_modal_count', $.notyRenderer.getModalCount() + arg);
280
+ };
281
+
282
+ // This is for custom container
283
+ $.fn.noty = function(options) {
284
+ options.custom = $(this);
285
+ return $.notyRenderer.init(options);
286
+ };
287
+
288
+ $.noty = {};
289
+ $.noty.queue = [];
290
+ $.noty.ontap = true;
291
+ $.noty.layouts = {};
292
+ $.noty.themes = {};
293
+ $.noty.returns = 'object';
294
+ $.noty.store = {};
295
+
296
+ $.noty.get = function(id) {
297
+ return $.noty.store.hasOwnProperty(id) ? $.noty.store[id] : false;
298
+ };
299
+
300
+ $.noty.close = function(id) {
301
+ return $.noty.get(id) ? $.noty.get(id).close() : false;
302
+ };
303
+
304
+ $.noty.setText = function(id, text) {
305
+ return $.noty.get(id) ? $.noty.get(id).setText(text) : false;
306
+ };
307
+
308
+ $.noty.setType = function(id, type) {
309
+ return $.noty.get(id) ? $.noty.get(id).setType(type) : false;
310
+ };
311
+
312
+ $.noty.clearQueue = function() {
313
+ $.noty.queue = [];
314
+ };
315
+
316
+ $.noty.closeAll = function() {
317
+ $.noty.clearQueue();
318
+ $.each($.noty.store, function(id, noty) {
319
+ noty.close();
320
+ });
321
+ };
322
+
323
+ var windowAlert = window.alert;
324
+
325
+ $.noty.consumeAlert = function(options) {
326
+ window.alert = function(text) {
327
+ if (options)
328
+ options.text = text;
329
+ else
330
+ options = {text:text};
331
+
332
+ $.notyRenderer.init(options);
333
+ };
334
+ };
335
+
336
+ $.noty.stopConsumeAlert = function(){
337
+ window.alert = windowAlert;
338
+ };
339
+
340
+ $.noty.defaults = {
341
+ layout: 'top',
342
+ theme: 'default',
343
+ type: 'alert',
344
+ text: '',
345
+ dismissQueue: true,
346
+ template: '<div class="noty_message"><span class="noty_text"></span><div class="noty_close"></div></div>',
347
+ animation: {
348
+ open: {height: 'toggle'},
349
+ close: {height: 'toggle'},
350
+ easing: 'swing',
351
+ speed: 500
352
+ },
353
+ timeout: false,
354
+ force: false,
355
+ modal: false,
356
+ closeWith: ['click'],
357
+ callback: {
358
+ onShow: function() {},
359
+ afterShow: function() {},
360
+ onClose: function() {},
361
+ afterClose: function() {}
362
+ },
363
+ buttons: false
364
+ };
365
+
366
+ $(window).resize(function() {
367
+ $.each($.noty.layouts, function(index, layout) {
368
+ layout.container.style.apply($(layout.container.selector));
369
+ });
370
+ });
371
+
372
+ })(jQuery);
373
+
374
+ // Helpers
375
+ function noty(options) {
376
+
377
+ // This is for BC - Will be deleted on v2.2.0
378
+ var using_old = 0
379
+ , old_to_new = {
380
+ 'animateOpen': 'animation.open',
381
+ 'animateClose': 'animation.close',
382
+ 'easing': 'animation.easing',
383
+ 'speed': 'animation.speed',
384
+ 'onShow': 'callback.onShow',
385
+ 'onShown': 'callback.afterShow',
386
+ 'onClose': 'callback.onClose',
387
+ 'onClosed': 'callback.afterClose'
388
+ }
389
+
390
+ jQuery.each(options, function(key, value) {
391
+ if (old_to_new[key]) {
392
+ using_old++;
393
+ var _new = old_to_new[key].split('.');
394
+
395
+ if (!options[_new[0]]) options[_new[0]] = {};
396
+
397
+ options[_new[0]][_new[1]] = (value) ? value : function() {};
398
+ delete options[key];
399
+ }
400
+ });
401
+
402
+ if (!options.closeWith) {
403
+ options.closeWith = jQuery.noty.defaults.closeWith;
404
+ }
405
+
406
+ if (options.hasOwnProperty('closeButton')) {
407
+ using_old++;
408
+ if (options.closeButton) options.closeWith.push('button');
409
+ delete options.closeButton;
410
+ }
411
+
412
+ if (options.hasOwnProperty('closeOnSelfClick')) {
413
+ using_old++;
414
+ if (options.closeOnSelfClick) options.closeWith.push('click');
415
+ delete options.closeOnSelfClick;
416
+ }
417
+
418
+ if (options.hasOwnProperty('closeOnSelfOver')) {
419
+ using_old++;
420
+ if (options.closeOnSelfOver) options.closeWith.push('hover');
421
+ delete options.closeOnSelfOver;
422
+ }
423
+
424
+ if (options.hasOwnProperty('custom')) {
425
+ using_old++;
426
+ if (options.custom.container != 'null') options.custom = options.custom.container;
427
+ }
428
+
429
+ if (options.hasOwnProperty('cssPrefix')) {
430
+ using_old++;
431
+ delete options.cssPrefix;
432
+ }
433
+
434
+ if (options.theme == 'noty_theme_default') {
435
+ using_old++;
436
+ options.theme = 'default';
437
+ }
438
+
439
+ if (!options.hasOwnProperty('dismissQueue')) {
440
+ if (options.layout == 'topLeft'
441
+ || options.layout == 'topRight'
442
+ || options.layout == 'bottomLeft'
443
+ || options.layout == 'bottomRight') {
444
+ options.dismissQueue = true;
445
+ } else {
446
+ options.dismissQueue = false;
447
+ }
448
+ }
449
+
450
+ if (options.buttons) {
451
+ jQuery.each(options.buttons, function(i, button) {
452
+ if (button.click) {
453
+ using_old++;
454
+ button.onClick = button.click;
455
+ delete button.click;
456
+ }
457
+ if (button.type) {
458
+ using_old++;
459
+ button.addClass = button.type;
460
+ delete button.type;
461
+ }
462
+ });
463
+ }
464
+
465
+ if (using_old) console.warn('You are using noty v2 with v1.x.x options. @deprecated until v2.2.0 - Please update your options.');
466
+
467
+ // console.log(options);
468
+ // End of the BC
469
+
470
+ return jQuery.notyRenderer.init(options);
471
+ }