ng-toaster-rails 0.4.11.0 → 0.4.13.0
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.
- checksums.yaml +4 -4
- data/lib/ng-toaster-rails/version.rb +1 -1
- data/vendor/assets/javascripts/toaster.js +408 -362
- data/vendor/assets/stylesheets/toaster.css +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4442e5603b52a8a0034bd2c39aba87181ef5a7c0
|
4
|
+
data.tar.gz: 014e44b0d6fd9c1c0153cebbaffd4246c04ee4e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2ad739bd961dfeea9c624259e9cfb2534a1cba90aac64fdacd437d5b60e45a954ae02e7c1375718e450229736ba5b57d46d5a7900d87bc666eb1c4c242005f1
|
7
|
+
data.tar.gz: db1f7f8119e52b5125927f6b6d5a561c4fb563140cc66c365b272abd84ecf081465fe4d4afbb2fdd7611acf8d881e076429083a41c04f47c463049175040a0b8
|
@@ -1,373 +1,419 @@
|
|
1
1
|
(function () {
|
2
|
-
'use strict';
|
3
|
-
|
4
|
-
/*
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
angular.module('toaster', ['ngAnimate'])
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
'mouseover-timer-stop': true // stop timeout on mouseover and restart timer on mouseout
|
57
|
-
})
|
58
|
-
.service('toaster', ['$rootScope', 'toasterConfig', function ($rootScope, toasterConfig) {
|
59
|
-
this.pop = function (type, title, body, timeout, bodyOutputType, clickHandler, toasterId, showCloseButton) {
|
60
|
-
if (angular.isObject(type)) {
|
61
|
-
var params = type; // Enable named parameters as pop argument
|
62
|
-
this.toast = {
|
63
|
-
type: params.type,
|
64
|
-
title: params.title,
|
65
|
-
body: params.body,
|
66
|
-
timeout: params.timeout,
|
67
|
-
bodyOutputType: params.bodyOutputType,
|
68
|
-
clickHandler: params.clickHandler,
|
69
|
-
showCloseButton: params.showCloseButton
|
70
|
-
};
|
71
|
-
toasterId = params.toasterId;
|
72
|
-
} else {
|
73
|
-
this.toast = {
|
74
|
-
type: type,
|
75
|
-
title: title,
|
76
|
-
body: body,
|
77
|
-
timeout: timeout,
|
78
|
-
bodyOutputType: bodyOutputType,
|
79
|
-
clickHandler: clickHandler,
|
80
|
-
showCloseButton: showCloseButton
|
81
|
-
};
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
/*
|
5
|
+
* AngularJS Toaster
|
6
|
+
* Version: 0.4.13
|
7
|
+
*
|
8
|
+
* Copyright 2013-2015 Jiri Kavulak.
|
9
|
+
* All Rights Reserved.
|
10
|
+
* Use, reproduction, distribution, and modification of this code is subject to the terms and
|
11
|
+
* conditions of the MIT license, available at http://www.opensource.org/licenses/mit-license.php
|
12
|
+
*
|
13
|
+
* Author: Jiri Kavulak
|
14
|
+
* Related to project of John Papa, Hans Fjällemark and Nguyễn Thiện Hùng (thienhung1989)
|
15
|
+
*/
|
16
|
+
|
17
|
+
angular.module('toaster', ['ngAnimate']).constant(
|
18
|
+
'toasterConfig', {
|
19
|
+
'limit': 0, // limits max number of toasts
|
20
|
+
'tap-to-dismiss': true,
|
21
|
+
|
22
|
+
/* Options:
|
23
|
+
- Boolean false/true
|
24
|
+
'close-button': true
|
25
|
+
- object if not a boolean that allows you to
|
26
|
+
override showing the close button for each
|
27
|
+
icon-class value
|
28
|
+
'close-button': { 'toast-error': true, 'toast-info': false }
|
29
|
+
*/
|
30
|
+
'close-button': false,
|
31
|
+
|
32
|
+
'newest-on-top': true, //'fade-in': 1000, // done in css
|
33
|
+
//'on-fade-in': undefined, // not implemented
|
34
|
+
//'fade-out': 1000, // done in css
|
35
|
+
//'on-fade-out': undefined, // not implemented
|
36
|
+
//'extended-time-out': 1000, // not implemented
|
37
|
+
'time-out': 5000, // Set timeOut and extendedTimeout to 0 to make it sticky
|
38
|
+
'icon-classes': {
|
39
|
+
error: 'toast-error',
|
40
|
+
info: 'toast-info',
|
41
|
+
wait: 'toast-wait',
|
42
|
+
success: 'toast-success',
|
43
|
+
warning: 'toast-warning'
|
44
|
+
},
|
45
|
+
'body-output-type': '', // Options: '', 'trustedHtml', 'template', 'templateWithData'
|
46
|
+
'body-template': 'toasterBodyTmpl.html',
|
47
|
+
'icon-class': 'toast-info',
|
48
|
+
'position-class': 'toast-top-right', // Options (see CSS):
|
49
|
+
// 'toast-top-full-width', 'toast-bottom-full-width', 'toast-center',
|
50
|
+
// 'toast-top-left', 'toast-top-center', 'toast-top-right',
|
51
|
+
// 'toast-bottom-left', 'toast-bottom-center', 'toast-bottom-right',
|
52
|
+
'title-class': 'toast-title',
|
53
|
+
'message-class': 'toast-message',
|
54
|
+
'prevent-duplicates': false,
|
55
|
+
'mouseover-timer-stop': true // stop timeout on mouseover and restart timer on mouseout
|
82
56
|
}
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
if (!deregisterNewToast) {
|
113
|
-
deregisterNewToast = $rootScope.$on('toaster-newToast', function (event, toasterId) {
|
114
|
-
for (var i = 0, len = newToastEventSubscribers.length; i < len; i++) {
|
115
|
-
newToastEventSubscribers[i](event, toasterId);
|
116
|
-
}
|
117
|
-
});
|
118
|
-
}
|
119
|
-
|
120
|
-
if (!deregisterClearToasts) {
|
121
|
-
deregisterClearToasts = $rootScope.$on('toaster-clearToasts', function (event) {
|
122
|
-
for (var i = 0, len = clearToastsEventSubscribers.length; i < len; i++) {
|
123
|
-
clearToastsEventSubscribers[i](event);
|
124
|
-
}
|
125
|
-
});
|
126
|
-
}
|
127
|
-
},
|
128
|
-
|
129
|
-
subscribeToNewToastEvent: function(onNewToast) {
|
130
|
-
newToastEventSubscribers.push(onNewToast);
|
131
|
-
},
|
132
|
-
subscribeToClearToastsEvent: function(onClearToasts) {
|
133
|
-
clearToastsEventSubscribers.push(onClearToasts);
|
134
|
-
},
|
135
|
-
unsubscribeToNewToastEvent: function(onNewToast) {
|
136
|
-
var index = newToastEventSubscribers.indexOf(onNewToast);
|
137
|
-
if (index >= 0)
|
138
|
-
newToastEventSubscribers.splice(index, 1);
|
139
|
-
|
140
|
-
if (newToastEventSubscribers.length === 0) {
|
141
|
-
deregisterNewToast();
|
142
|
-
deregisterNewToast = null;
|
143
|
-
}
|
144
|
-
},
|
145
|
-
unsubscribeToClearToastsEvent: function(onClearToasts) {
|
146
|
-
var index = clearToastsEventSubscribers.indexOf(onClearToasts);
|
147
|
-
if (index >= 0)
|
148
|
-
clearToastsEventSubscribers.splice(index, 1);
|
149
|
-
|
150
|
-
if (clearToastsEventSubscribers.length === 0) {
|
151
|
-
deregisterClearToasts();
|
152
|
-
deregisterClearToasts = null;
|
153
|
-
}
|
154
|
-
}
|
155
|
-
};
|
156
|
-
return {
|
157
|
-
setup: toasterFactory.setup,
|
158
|
-
subscribeToNewToastEvent: toasterFactory.subscribeToNewToastEvent,
|
159
|
-
subscribeToClearToastsEvent: toasterFactory.subscribeToClearToastsEvent,
|
160
|
-
unsubscribeToNewToastEvent: toasterFactory.unsubscribeToNewToastEvent,
|
161
|
-
unsubscribeToClearToastsEvent: toasterFactory.unsubscribeToClearToastsEvent
|
162
|
-
};
|
163
|
-
}])
|
164
|
-
.directive('toasterContainer', ['$parse', '$rootScope', '$interval', '$sce', 'toasterConfig', 'toaster', 'toasterEventRegistry',
|
165
|
-
function ($parse, $rootScope, $interval, $sce, toasterConfig, toaster, toasterEventRegistry) {
|
166
|
-
return {
|
167
|
-
replace: true,
|
168
|
-
restrict: 'EA',
|
169
|
-
scope: true, // creates an internal scope for this directive (one per directive instance)
|
170
|
-
link: function (scope, elm, attrs) {
|
171
|
-
var id = 0,
|
172
|
-
mergedConfig;
|
173
|
-
|
174
|
-
// Merges configuration set in directive with default one
|
175
|
-
mergedConfig = angular.extend({}, toasterConfig, scope.$eval(attrs.toasterOptions));
|
176
|
-
|
177
|
-
scope.config = {
|
178
|
-
toasterId: mergedConfig['toaster-id'],
|
179
|
-
position: mergedConfig['position-class'],
|
180
|
-
title: mergedConfig['title-class'],
|
181
|
-
message: mergedConfig['message-class'],
|
182
|
-
tap: mergedConfig['tap-to-dismiss'],
|
183
|
-
closeButton: mergedConfig['close-button'],
|
184
|
-
animation: mergedConfig['animation-class'],
|
185
|
-
mouseoverTimer: mergedConfig['mouseover-timer-stop']
|
186
|
-
};
|
187
|
-
|
188
|
-
scope.$on("$destroy", function () {
|
189
|
-
toasterEventRegistry.unsubscribeToNewToastEvent(scope._onNewToast);
|
190
|
-
toasterEventRegistry.unsubscribeToClearToastsEvent(scope._onClearToasts);
|
191
|
-
});
|
192
|
-
|
193
|
-
function setTimeout(toast, time) {
|
194
|
-
toast.timeoutPromise = $interval(function () {
|
195
|
-
scope.removeToast(toast.id);
|
196
|
-
}, time, 1);
|
197
|
-
}
|
198
|
-
|
199
|
-
scope.configureTimer = function (toast) {
|
200
|
-
var timeout = angular.isNumber(toast.timeout) ? toast.timeout : mergedConfig['time-out'];
|
201
|
-
if (timeout > 0)
|
202
|
-
setTimeout(toast, timeout);
|
203
|
-
};
|
204
|
-
|
205
|
-
function addToast(toast) {
|
206
|
-
toast.type = mergedConfig['icon-classes'][toast.type];
|
207
|
-
if (!toast.type)
|
208
|
-
toast.type = mergedConfig['icon-class'];
|
209
|
-
|
210
|
-
// Prevent adding duplicate toasts if it's set
|
211
|
-
if (mergedConfig['prevent-duplicates'] === true &&
|
212
|
-
scope.toasters.length > 0 &&
|
213
|
-
scope.toasters[scope.toasters.length - 1].body === toast.body)
|
214
|
-
return;
|
215
|
-
|
216
|
-
toast.id = ++id;
|
217
|
-
|
218
|
-
|
219
|
-
// set the showCloseButton property on the toast so that
|
220
|
-
// each template can bind directly to the property to show/hide
|
221
|
-
// the close button
|
222
|
-
var closeButton = mergedConfig['close-button'];
|
223
|
-
|
224
|
-
// if toast.showCloseButton is a boolean value,
|
225
|
-
// it was specifically overriden in the pop arguments
|
226
|
-
if (typeof toast.showCloseButton === "boolean") {
|
227
|
-
|
228
|
-
} else if (typeof closeButton === "boolean") {
|
229
|
-
toast.showCloseButton = closeButton;
|
230
|
-
} else if (typeof closeButton === "object") {
|
231
|
-
var closeButtonForType = closeButton[toast.type];
|
232
|
-
|
233
|
-
if (typeof closeButtonForType !== "undefined" && closeButtonForType !== null) {
|
234
|
-
toast.showCloseButton = closeButtonForType;
|
57
|
+
).service(
|
58
|
+
'toaster', [
|
59
|
+
'$rootScope', 'toasterConfig', function ($rootScope, toasterConfig) {
|
60
|
+
this.pop = function (type, title, body, timeout, bodyOutputType, clickHandler, toasterId, showCloseButton, toastId) {
|
61
|
+
if (angular.isObject(type)) {
|
62
|
+
var params = type; // Enable named parameters as pop argument
|
63
|
+
this.toast = {
|
64
|
+
type: params.type,
|
65
|
+
title: params.title,
|
66
|
+
body: params.body,
|
67
|
+
timeout: params.timeout,
|
68
|
+
bodyOutputType: params.bodyOutputType,
|
69
|
+
clickHandler: params.clickHandler,
|
70
|
+
showCloseButton: params.showCloseButton,
|
71
|
+
uid: params.toastId
|
72
|
+
};
|
73
|
+
toastId = params.toastId;
|
74
|
+
toasterId = params.toasterId;
|
75
|
+
} else {
|
76
|
+
this.toast = {
|
77
|
+
type: type,
|
78
|
+
title: title,
|
79
|
+
body: body,
|
80
|
+
timeout: timeout,
|
81
|
+
bodyOutputType: bodyOutputType,
|
82
|
+
clickHandler: clickHandler,
|
83
|
+
showCloseButton: showCloseButton,
|
84
|
+
uid: toastId
|
85
|
+
};
|
235
86
|
}
|
236
|
-
|
237
|
-
|
238
|
-
|
87
|
+
$rootScope.$emit('toaster-newToast', toasterId, toastId);
|
88
|
+
};
|
89
|
+
|
90
|
+
this.clear = function (toasterId, toastId) {
|
91
|
+
$rootScope.$emit('toaster-clearToasts', toasterId, toastId);
|
92
|
+
};
|
93
|
+
|
94
|
+
// Create one method per icon class, to allow to call toaster.info() and similar
|
95
|
+
for (var type in toasterConfig['icon-classes']) {
|
96
|
+
this[type] = (function (toasterType) {
|
97
|
+
return function (title, body, timeout, bodyOutputType, clickHandler, toasterId, showCloseButton, toastId) {
|
98
|
+
if (angular.isString(title)) {
|
99
|
+
this.pop(
|
100
|
+
toasterType,
|
101
|
+
title,
|
102
|
+
body,
|
103
|
+
timeout,
|
104
|
+
bodyOutputType,
|
105
|
+
clickHandler,
|
106
|
+
toasterId,
|
107
|
+
showCloseButton,
|
108
|
+
toastId
|
109
|
+
);
|
110
|
+
} else { // 'title' is actually an object with options
|
111
|
+
this.pop(angular.extend(title, {type: toasterType}));
|
112
|
+
}
|
113
|
+
};
|
114
|
+
})(type);
|
239
115
|
}
|
116
|
+
}]
|
117
|
+
).factory(
|
118
|
+
'toasterEventRegistry', [
|
119
|
+
'$rootScope', function ($rootScope) {
|
120
|
+
var deregisterNewToast = null, deregisterClearToasts = null, newToastEventSubscribers = [], clearToastsEventSubscribers = [], toasterFactory;
|
121
|
+
|
122
|
+
toasterFactory = {
|
123
|
+
setup: function () {
|
124
|
+
if (!deregisterNewToast) {
|
125
|
+
deregisterNewToast = $rootScope.$on(
|
126
|
+
'toaster-newToast', function (event, toasterId, toastId) {
|
127
|
+
for (var i = 0, len = newToastEventSubscribers.length; i < len; i++) {
|
128
|
+
newToastEventSubscribers[i](event, toasterId, toastId);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
);
|
132
|
+
}
|
240
133
|
|
134
|
+
if (!deregisterClearToasts) {
|
135
|
+
deregisterClearToasts = $rootScope.$on(
|
136
|
+
'toaster-clearToasts', function (event, toasterId, toastId) {
|
137
|
+
for (var i = 0, len = clearToastsEventSubscribers.length; i < len; i++) {
|
138
|
+
clearToastsEventSubscribers[i](event, toasterId, toastId);
|
139
|
+
}
|
140
|
+
}
|
141
|
+
);
|
142
|
+
}
|
143
|
+
},
|
144
|
+
|
145
|
+
subscribeToNewToastEvent: function (onNewToast) {
|
146
|
+
newToastEventSubscribers.push(onNewToast);
|
147
|
+
},
|
148
|
+
subscribeToClearToastsEvent: function (onClearToasts) {
|
149
|
+
clearToastsEventSubscribers.push(onClearToasts);
|
150
|
+
},
|
151
|
+
unsubscribeToNewToastEvent: function (onNewToast) {
|
152
|
+
var index = newToastEventSubscribers.indexOf(onNewToast);
|
153
|
+
if (index >= 0) {
|
154
|
+
newToastEventSubscribers.splice(index, 1);
|
155
|
+
}
|
241
156
|
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
var fcGet = $parse(toast.body || mergedConfig['body-template']);
|
253
|
-
var templateWithData = fcGet(scope);
|
254
|
-
toast.bodyTemplate = templateWithData.template;
|
255
|
-
toast.data = templateWithData.data;
|
256
|
-
break;
|
257
|
-
}
|
258
|
-
|
259
|
-
scope.configureTimer(toast);
|
157
|
+
if (newToastEventSubscribers.length === 0) {
|
158
|
+
deregisterNewToast();
|
159
|
+
deregisterNewToast = null;
|
160
|
+
}
|
161
|
+
},
|
162
|
+
unsubscribeToClearToastsEvent: function (onClearToasts) {
|
163
|
+
var index = clearToastsEventSubscribers.indexOf(onClearToasts);
|
164
|
+
if (index >= 0) {
|
165
|
+
clearToastsEventSubscribers.splice(index, 1);
|
166
|
+
}
|
260
167
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
}
|
266
|
-
} else {
|
267
|
-
scope.toasters.push(toast);
|
268
|
-
if (mergedConfig['limit'] > 0 && scope.toasters.length > mergedConfig['limit']) {
|
269
|
-
scope.toasters.shift();
|
270
|
-
}
|
271
|
-
}
|
272
|
-
}
|
273
|
-
|
274
|
-
scope.removeToast = function (id) {
|
275
|
-
var i, len, toast;
|
276
|
-
for (i = 0, len = scope.toasters.length; i < len; i++) {
|
277
|
-
if (scope.toasters[i].id === id) {
|
278
|
-
removeToast(i);
|
279
|
-
break;
|
168
|
+
if (clearToastsEventSubscribers.length === 0) {
|
169
|
+
deregisterClearToasts();
|
170
|
+
deregisterClearToasts = null;
|
171
|
+
}
|
280
172
|
}
|
281
|
-
}
|
282
|
-
|
173
|
+
};
|
174
|
+
return {
|
175
|
+
setup: toasterFactory.setup,
|
176
|
+
subscribeToNewToastEvent: toasterFactory.subscribeToNewToastEvent,
|
177
|
+
subscribeToClearToastsEvent: toasterFactory.subscribeToClearToastsEvent,
|
178
|
+
unsubscribeToNewToastEvent: toasterFactory.unsubscribeToNewToastEvent,
|
179
|
+
unsubscribeToClearToastsEvent: toasterFactory.unsubscribeToClearToastsEvent
|
180
|
+
};
|
181
|
+
}]
|
182
|
+
).directive(
|
183
|
+
'toasterContainer', [
|
184
|
+
'$parse', '$rootScope', '$interval', '$sce', 'toasterConfig', 'toaster', 'toasterEventRegistry',
|
185
|
+
function ($parse, $rootScope, $interval, $sce, toasterConfig, toaster, toasterEventRegistry) {
|
186
|
+
return {
|
187
|
+
replace: true,
|
188
|
+
restrict: 'EA',
|
189
|
+
scope: true, // creates an internal scope for this directive (one per directive instance)
|
190
|
+
link: function (scope, elm, attrs) {
|
191
|
+
var id = 0, mergedConfig;
|
192
|
+
|
193
|
+
// Merges configuration set in directive with default one
|
194
|
+
mergedConfig = angular.extend({}, toasterConfig, scope.$eval(attrs.toasterOptions));
|
195
|
+
|
196
|
+
scope.config = {
|
197
|
+
toasterId: mergedConfig['toaster-id'],
|
198
|
+
position: mergedConfig['position-class'],
|
199
|
+
title: mergedConfig['title-class'],
|
200
|
+
message: mergedConfig['message-class'],
|
201
|
+
tap: mergedConfig['tap-to-dismiss'],
|
202
|
+
closeButton: mergedConfig['close-button'],
|
203
|
+
animation: mergedConfig['animation-class'],
|
204
|
+
mouseoverTimer: mergedConfig['mouseover-timer-stop']
|
205
|
+
};
|
206
|
+
|
207
|
+
scope.$on(
|
208
|
+
"$destroy", function () {
|
209
|
+
toasterEventRegistry.unsubscribeToNewToastEvent(scope._onNewToast);
|
210
|
+
toasterEventRegistry.unsubscribeToClearToastsEvent(scope._onClearToasts);
|
211
|
+
}
|
212
|
+
);
|
213
|
+
|
214
|
+
function setTimeout(toast, time) {
|
215
|
+
toast.timeoutPromise = $interval(
|
216
|
+
function () {
|
217
|
+
scope.removeToast(toast.id);
|
218
|
+
}, time, 1
|
219
|
+
);
|
220
|
+
}
|
283
221
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
222
|
+
scope.configureTimer = function (toast) {
|
223
|
+
var timeout = angular.isNumber(toast.timeout) ? toast.timeout : mergedConfig['time-out'];
|
224
|
+
if (timeout > 0) {
|
225
|
+
setTimeout(toast, timeout);
|
226
|
+
}
|
227
|
+
};
|
228
|
+
|
229
|
+
function addToast(toast, toastId) {
|
230
|
+
toast.type = mergedConfig['icon-classes'][toast.type];
|
231
|
+
if (!toast.type) {
|
232
|
+
toast.type = mergedConfig['icon-class'];
|
233
|
+
}
|
234
|
+
|
235
|
+
if (mergedConfig['prevent-duplicates'] === true) {
|
236
|
+
// Prevent adding duplicate toasts if it's set
|
237
|
+
if (isUndefinedOrNull(toastId)) {
|
238
|
+
if (scope.toasters.length > 0 && scope.toasters[scope.toasters.length - 1].body === toast.body) {
|
239
|
+
return;
|
240
|
+
}
|
241
|
+
} else {
|
242
|
+
var i, len;
|
243
|
+
for (i = 0, len = scope.toasters.length; i < len; i++) {
|
244
|
+
if (scope.toasters[i].uid === toastId) {
|
245
|
+
removeToast(i);
|
246
|
+
// update loop
|
247
|
+
i--;
|
248
|
+
len = scope.toasters.length;
|
249
|
+
}
|
250
|
+
}
|
251
|
+
}
|
252
|
+
}
|
253
|
+
|
254
|
+
toast.id = ++id;
|
255
|
+
// Sure uid defined
|
256
|
+
if (!isUndefinedOrNull(toastId)) {
|
257
|
+
toast.uid = toastId;
|
258
|
+
}
|
259
|
+
|
260
|
+
// set the showCloseButton property on the toast so that
|
261
|
+
// each template can bind directly to the property to show/hide
|
262
|
+
// the close button
|
263
|
+
var closeButton = mergedConfig['close-button'];
|
264
|
+
|
265
|
+
// if toast.showCloseButton is a boolean value,
|
266
|
+
// it was specifically overriden in the pop arguments
|
267
|
+
if (typeof toast.showCloseButton === "boolean") {
|
268
|
+
|
269
|
+
} else if (typeof closeButton === "boolean") {
|
270
|
+
toast.showCloseButton = closeButton;
|
271
|
+
} else if (typeof closeButton === "object") {
|
272
|
+
var closeButtonForType = closeButton[toast.type];
|
273
|
+
|
274
|
+
if (typeof closeButtonForType !== "undefined" && closeButtonForType !== null) {
|
275
|
+
toast.showCloseButton = closeButtonForType;
|
276
|
+
}
|
277
|
+
} else {
|
278
|
+
// if an option was not set, default to false.
|
279
|
+
toast.showCloseButton = false;
|
280
|
+
}
|
281
|
+
|
282
|
+
// Set the toast.bodyOutputType to the default if it isn't set
|
283
|
+
toast.bodyOutputType = toast.bodyOutputType || mergedConfig['body-output-type'];
|
284
|
+
switch (toast.bodyOutputType) {
|
285
|
+
case 'trustedHtml':
|
286
|
+
toast.html = $sce.trustAsHtml(toast.body);
|
287
|
+
break;
|
288
|
+
case 'template':
|
289
|
+
toast.bodyTemplate = toast.body || mergedConfig['body-template'];
|
290
|
+
break;
|
291
|
+
case 'templateWithData':
|
292
|
+
var fcGet = $parse(toast.body || mergedConfig['body-template']);
|
293
|
+
var templateWithData = fcGet(scope);
|
294
|
+
toast.bodyTemplate = templateWithData.template;
|
295
|
+
toast.data = templateWithData.data;
|
296
|
+
break;
|
297
|
+
}
|
298
|
+
|
299
|
+
scope.configureTimer(toast);
|
300
|
+
if (mergedConfig['newest-on-top'] === true) {
|
301
|
+
scope.toasters.unshift(toast);
|
302
|
+
if (mergedConfig['limit'] > 0 && scope.toasters.length > mergedConfig['limit']) {
|
303
|
+
scope.toasters.pop();
|
304
|
+
}
|
305
|
+
} else {
|
306
|
+
scope.toasters.push(toast);
|
307
|
+
if (mergedConfig['limit'] > 0 && scope.toasters.length > mergedConfig['limit']) {
|
308
|
+
scope.toasters.shift();
|
309
|
+
}
|
310
|
+
}
|
311
|
+
}
|
293
312
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
};
|
313
|
-
|
314
|
-
toasterEventRegistry.setup();
|
315
|
-
|
316
|
-
toasterEventRegistry.subscribeToNewToastEvent(scope._onNewToast);
|
317
|
-
toasterEventRegistry.subscribeToClearToastsEvent(scope._onClearToasts);
|
318
|
-
},
|
319
|
-
controller: ['$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
|
320
|
-
// Called on mouseover
|
321
|
-
$scope.stopTimer = function (toast) {
|
322
|
-
if ($scope.config.mouseoverTimer === true) {
|
323
|
-
if (toast.timeoutPromise) {
|
324
|
-
$interval.cancel(toast.timeoutPromise);
|
325
|
-
toast.timeoutPromise = null;
|
326
|
-
}
|
327
|
-
}
|
328
|
-
};
|
329
|
-
|
330
|
-
// Called on mouseout
|
331
|
-
$scope.restartTimer = function (toast) {
|
332
|
-
if ($scope.config.mouseoverTimer === true) {
|
333
|
-
if (!toast.timeoutPromise)
|
334
|
-
$scope.configureTimer(toast);
|
335
|
-
} else if (toast.timeoutPromise === null) {
|
336
|
-
$scope.removeToast(toast.id);
|
337
|
-
}
|
338
|
-
};
|
339
|
-
|
340
|
-
$scope.click = function (toast) {
|
341
|
-
if ($scope.config.tap === true || toast.showCloseButton === true) {
|
342
|
-
var removeToast = true;
|
343
|
-
if (toast.clickHandler) {
|
344
|
-
if (angular.isFunction(toast.clickHandler)) {
|
345
|
-
removeToast = toast.clickHandler(toast, toast.showCloseButton);
|
346
|
-
} else if (angular.isFunction($scope.$parent.$eval(toast.clickHandler))) {
|
347
|
-
removeToast = $scope.$parent.$eval(toast.clickHandler)(toast, toast.showCloseButton);
|
348
|
-
} else {
|
349
|
-
console.log("TOAST-NOTE: Your click handler is not inside a parent scope of toaster-container.");
|
313
|
+
scope.removeToast = function (id) {
|
314
|
+
var i, len, toast;
|
315
|
+
for (i = 0, len = scope.toasters.length; i < len; i++) {
|
316
|
+
if (scope.toasters[i].id === id) {
|
317
|
+
removeToast(i);
|
318
|
+
break;
|
319
|
+
}
|
320
|
+
}
|
321
|
+
};
|
322
|
+
|
323
|
+
function removeToast(toastIndex) {
|
324
|
+
var toast = scope.toasters[toastIndex];
|
325
|
+
if (toast) {
|
326
|
+
if (toast.timeoutPromise) {
|
327
|
+
$interval.cancel(toast.timeoutPromise);
|
328
|
+
}
|
329
|
+
scope.toasters.splice(toastIndex, 1);
|
330
|
+
}
|
350
331
|
}
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
332
|
+
|
333
|
+
function removeAllToasts(toastId) {
|
334
|
+
for (var i = scope.toasters.length - 1; i >= 0; i--) {
|
335
|
+
if (isUndefinedOrNull(toastId)) {
|
336
|
+
removeToast(i);
|
337
|
+
} else {
|
338
|
+
if (scope.toasters[i].uid == toastId) {
|
339
|
+
removeToast(i);
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
}
|
344
|
+
|
345
|
+
scope.toasters = [];
|
346
|
+
|
347
|
+
function isUndefinedOrNull(val) {
|
348
|
+
return angular.isUndefined(val) || val === null
|
349
|
+
}
|
350
|
+
|
351
|
+
scope._onNewToast = function (event, toasterId, toastId) {
|
352
|
+
// Compatibility: if toaster has no toasterId defined, and if call to display
|
353
|
+
// hasn't either, then the request is for us
|
354
|
+
|
355
|
+
if ((isUndefinedOrNull(scope.config.toasterId) && isUndefinedOrNull(toasterId)) || (!isUndefinedOrNull(scope.config.toasterId) && !isUndefinedOrNull(toasterId) && scope.config.toasterId == toasterId)) {
|
356
|
+
addToast(toaster.toast, toastId);
|
357
|
+
}
|
358
|
+
};
|
359
|
+
scope._onClearToasts = function (event, toasterId, toastId) {
|
360
|
+
// Compatibility: if toaster has no toasterId defined, and if call to display
|
361
|
+
// hasn't either, then the request is for us
|
362
|
+
if (toasterId == '*' || (isUndefinedOrNull(scope.config.toasterId) && isUndefinedOrNull(toasterId)) || (!isUndefinedOrNull(scope.config.toasterId) && !isUndefinedOrNull(toasterId) && scope.config.toasterId == toasterId)) {
|
363
|
+
removeAllToasts(toastId);
|
364
|
+
}
|
365
|
+
};
|
366
|
+
|
367
|
+
toasterEventRegistry.setup();
|
368
|
+
|
369
|
+
toasterEventRegistry.subscribeToNewToastEvent(scope._onNewToast);
|
370
|
+
toasterEventRegistry.subscribeToClearToastsEvent(scope._onClearToasts);
|
371
|
+
},
|
372
|
+
controller: [
|
373
|
+
'$scope', '$element', '$attrs', function ($scope, $element, $attrs) {
|
374
|
+
// Called on mouseover
|
375
|
+
$scope.stopTimer = function (toast) {
|
376
|
+
if ($scope.config.mouseoverTimer === true) {
|
377
|
+
if (toast.timeoutPromise) {
|
378
|
+
$interval.cancel(toast.timeoutPromise);
|
379
|
+
toast.timeoutPromise = null;
|
380
|
+
}
|
381
|
+
}
|
382
|
+
};
|
383
|
+
|
384
|
+
// Called on mouseout
|
385
|
+
$scope.restartTimer = function (toast) {
|
386
|
+
if ($scope.config.mouseoverTimer === true) {
|
387
|
+
if (!toast.timeoutPromise) {
|
388
|
+
$scope.configureTimer(toast);
|
389
|
+
}
|
390
|
+
} else if (toast.timeoutPromise === null) {
|
391
|
+
$scope.removeToast(toast.id);
|
392
|
+
}
|
393
|
+
};
|
394
|
+
|
395
|
+
$scope.click = function (toast) {
|
396
|
+
if ($scope.config.tap === true || toast.showCloseButton === true) {
|
397
|
+
var removeToast = true;
|
398
|
+
if (toast.clickHandler) {
|
399
|
+
if (angular.isFunction(toast.clickHandler)) {
|
400
|
+
removeToast = toast.clickHandler(toast, toast.showCloseButton);
|
401
|
+
} else if (angular.isFunction($scope.$parent.$eval(toast.clickHandler))) {
|
402
|
+
removeToast = $scope.$parent.$eval(toast.clickHandler)(
|
403
|
+
toast, toast.showCloseButton
|
404
|
+
);
|
405
|
+
} else {
|
406
|
+
console.log("TOAST-NOTE: Your click handler is not inside a parent scope of toaster-container.");
|
407
|
+
}
|
408
|
+
}
|
409
|
+
if (removeToast) {
|
410
|
+
$scope.removeToast(toast.id);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
};
|
414
|
+
}],
|
415
|
+
template: '<div id="toast-container" ng-class="[config.position, config.animation]">' + '<div ng-repeat="toaster in toasters" class="toast" ng-class="toaster.type" ng-click="click(toaster)" ng-mouseover="stopTimer(toaster)" ng-mouseout="restartTimer(toaster)">' + '<button type="button" class="toast-close-button" ng-show="toaster.showCloseButton" ng-click="click(toaster)">×</button>' + '<div ng-class="config.title">{{toaster.title}}</div>' + '<div ng-class="config.message" ng-switch on="toaster.bodyOutputType">' + '<div ng-switch-when="trustedHtml" ng-bind-html="toaster.html"></div>' + '<div ng-switch-when="template"><div ng-include="toaster.bodyTemplate"></div></div>' + '<div ng-switch-when="templateWithData"><div ng-include="toaster.bodyTemplate"></div></div>' + '<div ng-switch-default >{{toaster.body}}</div>' + '</div>' + '</div>' + '</div>'
|
416
|
+
};
|
417
|
+
}]
|
418
|
+
);
|
419
|
+
})(window, document);
|
@@ -113,7 +113,7 @@ button.toast-close-button {
|
|
113
113
|
pointer-events: auto;
|
114
114
|
}
|
115
115
|
#toast-container.toast-center > button,
|
116
|
-
#toast-container.toast-top-
|
116
|
+
#toast-container.toast-top-center > button,
|
117
117
|
#toast-container.toast-bottom-center > button{
|
118
118
|
pointer-events: auto;
|
119
119
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ng-toaster-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.13.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- fdibartolo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'Rails engine for jirikavi/AngularJS-Toaster: "AngularJS Toaster is a
|
14
14
|
customized version of "toastr" non-blocking notification javascript library"'
|