flash_notifier 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +95 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/flash_notifier.gemspec +29 -0
- data/lib/flash_notifier/flash_helper.rb +29 -0
- data/lib/flash_notifier/railtie.rb +12 -0
- data/lib/flash_notifier/version.rb +3 -0
- data/lib/flash_notifier.rb +6 -0
- data/vendor/assets/javascripts/common.coffee +11 -0
- data/vendor/assets/javascripts/noty.js +3077 -0
- data/vendor/assets/javascripts/noty_flash.coffee +18 -0
- data/vendor/assets/javascripts/noty_lib.js +3 -0
- data/vendor/assets/javascripts/toastr.min.js +2 -0
- data/vendor/assets/javascripts/toastr_flash.coffee +11 -0
- data/vendor/assets/javascripts/toastr_lib.js +3 -0
- data/vendor/assets/stylesheets/noty.css +697 -0
- data/vendor/assets/stylesheets/toastr.min.css +1 -0
- metadata +95 -0
@@ -0,0 +1,3077 @@
|
|
1
|
+
/*
|
2
|
+
@package NOTY - Dependency-free notification library
|
3
|
+
@version version: 3.1.4
|
4
|
+
@contributors https://github.com/needim/noty/graphs/contributors
|
5
|
+
@documentation Examples and Documentation - http://needim.github.com/noty
|
6
|
+
@license Licensed under the MIT licenses: http://www.opensource.org/licenses/mit-license.php
|
7
|
+
*/
|
8
|
+
|
9
|
+
(function webpackUniversalModuleDefinition(root, factory) {
|
10
|
+
if(typeof exports === 'object' && typeof module === 'object')
|
11
|
+
module.exports = factory();
|
12
|
+
else if(typeof define === 'function' && define.amd)
|
13
|
+
define("Noty", [], factory);
|
14
|
+
else if(typeof exports === 'object')
|
15
|
+
exports["Noty"] = factory();
|
16
|
+
else
|
17
|
+
root["Noty"] = factory();
|
18
|
+
})(this, function() {
|
19
|
+
return /******/ (function(modules) { // webpackBootstrap
|
20
|
+
/******/ // The module cache
|
21
|
+
/******/ var installedModules = {};
|
22
|
+
/******/
|
23
|
+
/******/ // The require function
|
24
|
+
/******/ function __webpack_require__(moduleId) {
|
25
|
+
/******/
|
26
|
+
/******/ // Check if module is in cache
|
27
|
+
/******/ if(installedModules[moduleId]) {
|
28
|
+
/******/ return installedModules[moduleId].exports;
|
29
|
+
/******/ }
|
30
|
+
/******/ // Create a new module (and put it into the cache)
|
31
|
+
/******/ var module = installedModules[moduleId] = {
|
32
|
+
/******/ i: moduleId,
|
33
|
+
/******/ l: false,
|
34
|
+
/******/ exports: {}
|
35
|
+
/******/ };
|
36
|
+
/******/
|
37
|
+
/******/ // Execute the module function
|
38
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
39
|
+
/******/
|
40
|
+
/******/ // Flag the module as loaded
|
41
|
+
/******/ module.l = true;
|
42
|
+
/******/
|
43
|
+
/******/ // Return the exports of the module
|
44
|
+
/******/ return module.exports;
|
45
|
+
/******/ }
|
46
|
+
/******/
|
47
|
+
/******/
|
48
|
+
/******/ // expose the modules object (__webpack_modules__)
|
49
|
+
/******/ __webpack_require__.m = modules;
|
50
|
+
/******/
|
51
|
+
/******/ // expose the module cache
|
52
|
+
/******/ __webpack_require__.c = installedModules;
|
53
|
+
/******/
|
54
|
+
/******/ // identity function for calling harmony imports with the correct context
|
55
|
+
/******/ __webpack_require__.i = function(value) { return value; };
|
56
|
+
/******/
|
57
|
+
/******/ // define getter function for harmony exports
|
58
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
59
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
60
|
+
/******/ Object.defineProperty(exports, name, {
|
61
|
+
/******/ configurable: false,
|
62
|
+
/******/ enumerable: true,
|
63
|
+
/******/ get: getter
|
64
|
+
/******/ });
|
65
|
+
/******/ }
|
66
|
+
/******/ };
|
67
|
+
/******/
|
68
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
69
|
+
/******/ __webpack_require__.n = function(module) {
|
70
|
+
/******/ var getter = module && module.__esModule ?
|
71
|
+
/******/ function getDefault() { return module['default']; } :
|
72
|
+
/******/ function getModuleExports() { return module; };
|
73
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
74
|
+
/******/ return getter;
|
75
|
+
/******/ };
|
76
|
+
/******/
|
77
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
78
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
79
|
+
/******/
|
80
|
+
/******/ // __webpack_public_path__
|
81
|
+
/******/ __webpack_require__.p = "";
|
82
|
+
/******/
|
83
|
+
/******/ // Load entry module and return exports
|
84
|
+
/******/ return __webpack_require__(__webpack_require__.s = 6);
|
85
|
+
/******/ })
|
86
|
+
/************************************************************************/
|
87
|
+
/******/ ([
|
88
|
+
/* 0 */
|
89
|
+
/***/ (function(module, exports, __webpack_require__) {
|
90
|
+
|
91
|
+
"use strict";
|
92
|
+
|
93
|
+
|
94
|
+
Object.defineProperty(exports, "__esModule", {
|
95
|
+
value: true
|
96
|
+
});
|
97
|
+
exports.css = exports.deepExtend = exports.animationEndEvents = undefined;
|
98
|
+
|
99
|
+
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
|
100
|
+
|
101
|
+
exports.inArray = inArray;
|
102
|
+
exports.stopPropagation = stopPropagation;
|
103
|
+
exports.generateID = generateID;
|
104
|
+
exports.outerHeight = outerHeight;
|
105
|
+
exports.addListener = addListener;
|
106
|
+
exports.hasClass = hasClass;
|
107
|
+
exports.addClass = addClass;
|
108
|
+
exports.removeClass = removeClass;
|
109
|
+
exports.remove = remove;
|
110
|
+
exports.classList = classList;
|
111
|
+
exports.visibilityChangeFlow = visibilityChangeFlow;
|
112
|
+
exports.createAudioElements = createAudioElements;
|
113
|
+
|
114
|
+
var _api = __webpack_require__(1);
|
115
|
+
|
116
|
+
var API = _interopRequireWildcard(_api);
|
117
|
+
|
118
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
119
|
+
|
120
|
+
var animationEndEvents = exports.animationEndEvents = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
|
121
|
+
|
122
|
+
function inArray(needle, haystack, argStrict) {
|
123
|
+
var key = void 0;
|
124
|
+
var strict = !!argStrict;
|
125
|
+
|
126
|
+
if (strict) {
|
127
|
+
for (key in haystack) {
|
128
|
+
if (haystack.hasOwnProperty(key) && haystack[key] === needle) {
|
129
|
+
return true;
|
130
|
+
}
|
131
|
+
}
|
132
|
+
} else {
|
133
|
+
for (key in haystack) {
|
134
|
+
if (haystack.hasOwnProperty(key) && haystack[key] === needle) {
|
135
|
+
return true;
|
136
|
+
}
|
137
|
+
}
|
138
|
+
}
|
139
|
+
return false;
|
140
|
+
}
|
141
|
+
|
142
|
+
function stopPropagation(evt) {
|
143
|
+
evt = evt || window.event;
|
144
|
+
|
145
|
+
if (typeof evt.stopPropagation !== 'undefined') {
|
146
|
+
evt.stopPropagation();
|
147
|
+
} else {
|
148
|
+
evt.cancelBubble = true;
|
149
|
+
}
|
150
|
+
}
|
151
|
+
|
152
|
+
var deepExtend = exports.deepExtend = function deepExtend(out) {
|
153
|
+
out = out || {};
|
154
|
+
|
155
|
+
for (var i = 1; i < arguments.length; i++) {
|
156
|
+
var obj = arguments[i];
|
157
|
+
|
158
|
+
if (!obj) continue;
|
159
|
+
|
160
|
+
for (var key in obj) {
|
161
|
+
if (obj.hasOwnProperty(key)) {
|
162
|
+
if (Array.isArray(obj[key])) {
|
163
|
+
out[key] = obj[key];
|
164
|
+
} else if (_typeof(obj[key]) === 'object' && obj[key] !== null) {
|
165
|
+
out[key] = deepExtend(out[key], obj[key]);
|
166
|
+
} else {
|
167
|
+
out[key] = obj[key];
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
}
|
172
|
+
|
173
|
+
return out;
|
174
|
+
};
|
175
|
+
|
176
|
+
function generateID() {
|
177
|
+
var prefix = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
178
|
+
|
179
|
+
var id = 'noty_' + prefix + '_';
|
180
|
+
|
181
|
+
id += 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
|
182
|
+
var r = Math.random() * 16 | 0;
|
183
|
+
var v = c === 'x' ? r : r & 0x3 | 0x8;
|
184
|
+
return v.toString(16);
|
185
|
+
});
|
186
|
+
|
187
|
+
return id;
|
188
|
+
}
|
189
|
+
|
190
|
+
function outerHeight(el) {
|
191
|
+
var height = el.offsetHeight;
|
192
|
+
var style = window.getComputedStyle(el);
|
193
|
+
|
194
|
+
height += parseInt(style.marginTop) + parseInt(style.marginBottom);
|
195
|
+
return height;
|
196
|
+
}
|
197
|
+
|
198
|
+
var css = exports.css = function () {
|
199
|
+
var cssPrefixes = ['Webkit', 'O', 'Moz', 'ms'];
|
200
|
+
var cssProps = {};
|
201
|
+
|
202
|
+
function camelCase(string) {
|
203
|
+
return string.replace(/^-ms-/, 'ms-').replace(/-([\da-z])/gi, function (match, letter) {
|
204
|
+
return letter.toUpperCase();
|
205
|
+
});
|
206
|
+
}
|
207
|
+
|
208
|
+
function getVendorProp(name) {
|
209
|
+
var style = document.body.style;
|
210
|
+
if (name in style) return name;
|
211
|
+
|
212
|
+
var i = cssPrefixes.length;
|
213
|
+
var capName = name.charAt(0).toUpperCase() + name.slice(1);
|
214
|
+
var vendorName = void 0;
|
215
|
+
|
216
|
+
while (i--) {
|
217
|
+
vendorName = cssPrefixes[i] + capName;
|
218
|
+
if (vendorName in style) return vendorName;
|
219
|
+
}
|
220
|
+
|
221
|
+
return name;
|
222
|
+
}
|
223
|
+
|
224
|
+
function getStyleProp(name) {
|
225
|
+
name = camelCase(name);
|
226
|
+
return cssProps[name] || (cssProps[name] = getVendorProp(name));
|
227
|
+
}
|
228
|
+
|
229
|
+
function applyCss(element, prop, value) {
|
230
|
+
prop = getStyleProp(prop);
|
231
|
+
element.style[prop] = value;
|
232
|
+
}
|
233
|
+
|
234
|
+
return function (element, properties) {
|
235
|
+
var args = arguments;
|
236
|
+
var prop = void 0;
|
237
|
+
var value = void 0;
|
238
|
+
|
239
|
+
if (args.length === 2) {
|
240
|
+
for (prop in properties) {
|
241
|
+
if (properties.hasOwnProperty(prop)) {
|
242
|
+
value = properties[prop];
|
243
|
+
if (value !== undefined && properties.hasOwnProperty(prop)) {
|
244
|
+
applyCss(element, prop, value);
|
245
|
+
}
|
246
|
+
}
|
247
|
+
}
|
248
|
+
} else {
|
249
|
+
applyCss(element, args[1], args[2]);
|
250
|
+
}
|
251
|
+
};
|
252
|
+
}();
|
253
|
+
|
254
|
+
function addListener(el, events, cb) {
|
255
|
+
var useCapture = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
256
|
+
|
257
|
+
events = events.split(' ');
|
258
|
+
for (var i = 0; i < events.length; i++) {
|
259
|
+
if (document.addEventListener) {
|
260
|
+
el.addEventListener(events[i], cb, useCapture);
|
261
|
+
} else if (document.attachEvent) {
|
262
|
+
el.attachEvent('on' + events[i], cb);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
}
|
266
|
+
|
267
|
+
function hasClass(element, name) {
|
268
|
+
var list = typeof element === 'string' ? element : classList(element);
|
269
|
+
return list.indexOf(' ' + name + ' ') >= 0;
|
270
|
+
}
|
271
|
+
|
272
|
+
function addClass(element, name) {
|
273
|
+
var oldList = classList(element);
|
274
|
+
var newList = oldList + name;
|
275
|
+
|
276
|
+
if (hasClass(oldList, name)) return;
|
277
|
+
|
278
|
+
// Trim the opening space.
|
279
|
+
element.className = newList.substring(1);
|
280
|
+
}
|
281
|
+
|
282
|
+
function removeClass(element, name) {
|
283
|
+
var oldList = classList(element);
|
284
|
+
var newList = void 0;
|
285
|
+
|
286
|
+
if (!hasClass(element, name)) return;
|
287
|
+
|
288
|
+
// Replace the class name.
|
289
|
+
newList = oldList.replace(' ' + name + ' ', ' ');
|
290
|
+
|
291
|
+
// Trim the opening and closing spaces.
|
292
|
+
element.className = newList.substring(1, newList.length - 1);
|
293
|
+
}
|
294
|
+
|
295
|
+
function remove(element) {
|
296
|
+
if (element.parentNode) {
|
297
|
+
element.parentNode.removeChild(element);
|
298
|
+
}
|
299
|
+
}
|
300
|
+
|
301
|
+
function classList(element) {
|
302
|
+
return (' ' + (element && element.className || '') + ' ').replace(/\s+/gi, ' ');
|
303
|
+
}
|
304
|
+
|
305
|
+
function visibilityChangeFlow() {
|
306
|
+
var hidden = void 0;
|
307
|
+
var visibilityChange = void 0;
|
308
|
+
if (typeof document.hidden !== 'undefined') {
|
309
|
+
// Opera 12.10 and Firefox 18 and later support
|
310
|
+
hidden = 'hidden';
|
311
|
+
visibilityChange = 'visibilitychange';
|
312
|
+
} else if (typeof document.msHidden !== 'undefined') {
|
313
|
+
hidden = 'msHidden';
|
314
|
+
visibilityChange = 'msvisibilitychange';
|
315
|
+
} else if (typeof document.webkitHidden !== 'undefined') {
|
316
|
+
hidden = 'webkitHidden';
|
317
|
+
visibilityChange = 'webkitvisibilitychange';
|
318
|
+
}
|
319
|
+
|
320
|
+
function onVisibilityChange() {
|
321
|
+
API.PageHidden = document[hidden];
|
322
|
+
handleVisibilityChange();
|
323
|
+
}
|
324
|
+
|
325
|
+
function onBlur() {
|
326
|
+
API.PageHidden = true;
|
327
|
+
handleVisibilityChange();
|
328
|
+
}
|
329
|
+
|
330
|
+
function onFocus() {
|
331
|
+
API.PageHidden = false;
|
332
|
+
handleVisibilityChange();
|
333
|
+
}
|
334
|
+
|
335
|
+
function handleVisibilityChange() {
|
336
|
+
if (API.PageHidden) stopAll();else resumeAll();
|
337
|
+
}
|
338
|
+
|
339
|
+
function stopAll() {
|
340
|
+
setTimeout(function () {
|
341
|
+
Object.keys(API.Store).forEach(function (id) {
|
342
|
+
if (API.Store.hasOwnProperty(id)) {
|
343
|
+
if (API.Store[id].options.visibilityControl) {
|
344
|
+
API.Store[id].stop();
|
345
|
+
}
|
346
|
+
}
|
347
|
+
});
|
348
|
+
}, 100);
|
349
|
+
}
|
350
|
+
|
351
|
+
function resumeAll() {
|
352
|
+
setTimeout(function () {
|
353
|
+
Object.keys(API.Store).forEach(function (id) {
|
354
|
+
if (API.Store.hasOwnProperty(id)) {
|
355
|
+
if (API.Store[id].options.visibilityControl) {
|
356
|
+
API.Store[id].resume();
|
357
|
+
}
|
358
|
+
}
|
359
|
+
});
|
360
|
+
API.queueRenderAll();
|
361
|
+
}, 100);
|
362
|
+
}
|
363
|
+
|
364
|
+
if (visibilityChange) {
|
365
|
+
addListener(document, visibilityChange, onVisibilityChange);
|
366
|
+
}
|
367
|
+
|
368
|
+
addListener(window, 'blur', onBlur);
|
369
|
+
addListener(window, 'focus', onFocus);
|
370
|
+
}
|
371
|
+
|
372
|
+
function createAudioElements(ref) {
|
373
|
+
if (ref.hasSound) {
|
374
|
+
var audioElement = document.createElement('audio');
|
375
|
+
|
376
|
+
ref.options.sounds.sources.forEach(function (s) {
|
377
|
+
var source = document.createElement('source');
|
378
|
+
source.src = s;
|
379
|
+
source.type = 'audio/' + getExtension(s);
|
380
|
+
audioElement.appendChild(source);
|
381
|
+
});
|
382
|
+
|
383
|
+
if (ref.barDom) {
|
384
|
+
ref.barDom.appendChild(audioElement);
|
385
|
+
} else {
|
386
|
+
document.querySelector('body').appendChild(audioElement);
|
387
|
+
}
|
388
|
+
|
389
|
+
audioElement.volume = ref.options.sounds.volume;
|
390
|
+
|
391
|
+
if (!ref.soundPlayed) {
|
392
|
+
audioElement.play();
|
393
|
+
ref.soundPlayed = true;
|
394
|
+
}
|
395
|
+
|
396
|
+
audioElement.onended = function () {
|
397
|
+
remove(audioElement);
|
398
|
+
};
|
399
|
+
}
|
400
|
+
}
|
401
|
+
|
402
|
+
function getExtension(fileName) {
|
403
|
+
return fileName.match(/\.([^.]+)$/)[1];
|
404
|
+
}
|
405
|
+
|
406
|
+
/***/ }),
|
407
|
+
/* 1 */
|
408
|
+
/***/ (function(module, exports, __webpack_require__) {
|
409
|
+
|
410
|
+
"use strict";
|
411
|
+
|
412
|
+
|
413
|
+
Object.defineProperty(exports, "__esModule", {
|
414
|
+
value: true
|
415
|
+
});
|
416
|
+
exports.Defaults = exports.Store = exports.Queues = exports.DefaultMaxVisible = exports.docTitle = exports.DocModalCount = exports.PageHidden = undefined;
|
417
|
+
exports.getQueueCounts = getQueueCounts;
|
418
|
+
exports.addToQueue = addToQueue;
|
419
|
+
exports.removeFromQueue = removeFromQueue;
|
420
|
+
exports.queueRender = queueRender;
|
421
|
+
exports.queueRenderAll = queueRenderAll;
|
422
|
+
exports.ghostFix = ghostFix;
|
423
|
+
exports.build = build;
|
424
|
+
exports.hasButtons = hasButtons;
|
425
|
+
exports.handleModal = handleModal;
|
426
|
+
exports.handleModalClose = handleModalClose;
|
427
|
+
exports.queueClose = queueClose;
|
428
|
+
exports.dequeueClose = dequeueClose;
|
429
|
+
exports.fire = fire;
|
430
|
+
exports.openFlow = openFlow;
|
431
|
+
exports.closeFlow = closeFlow;
|
432
|
+
|
433
|
+
var _utils = __webpack_require__(0);
|
434
|
+
|
435
|
+
var Utils = _interopRequireWildcard(_utils);
|
436
|
+
|
437
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
438
|
+
|
439
|
+
var PageHidden = exports.PageHidden = false;
|
440
|
+
var DocModalCount = exports.DocModalCount = 0;
|
441
|
+
|
442
|
+
var DocTitleProps = {
|
443
|
+
originalTitle: null,
|
444
|
+
count: 0,
|
445
|
+
changed: false,
|
446
|
+
timer: -1
|
447
|
+
};
|
448
|
+
|
449
|
+
var docTitle = exports.docTitle = {
|
450
|
+
increment: function increment() {
|
451
|
+
DocTitleProps.count++;
|
452
|
+
|
453
|
+
docTitle._update();
|
454
|
+
},
|
455
|
+
|
456
|
+
decrement: function decrement() {
|
457
|
+
DocTitleProps.count--;
|
458
|
+
|
459
|
+
if (DocTitleProps.count <= 0) {
|
460
|
+
docTitle._clear();
|
461
|
+
return;
|
462
|
+
}
|
463
|
+
|
464
|
+
docTitle._update();
|
465
|
+
},
|
466
|
+
|
467
|
+
_update: function _update() {
|
468
|
+
var title = document.title;
|
469
|
+
|
470
|
+
if (!DocTitleProps.changed) {
|
471
|
+
DocTitleProps.originalTitle = title;
|
472
|
+
document.title = '(' + DocTitleProps.count + ') ' + title;
|
473
|
+
DocTitleProps.changed = true;
|
474
|
+
} else {
|
475
|
+
document.title = '(' + DocTitleProps.count + ') ' + DocTitleProps.originalTitle;
|
476
|
+
}
|
477
|
+
},
|
478
|
+
|
479
|
+
_clear: function _clear() {
|
480
|
+
if (DocTitleProps.changed) {
|
481
|
+
DocTitleProps.count = 0;
|
482
|
+
document.title = DocTitleProps.originalTitle;
|
483
|
+
DocTitleProps.changed = false;
|
484
|
+
}
|
485
|
+
}
|
486
|
+
};
|
487
|
+
|
488
|
+
var DefaultMaxVisible = exports.DefaultMaxVisible = 5;
|
489
|
+
|
490
|
+
var Queues = exports.Queues = {
|
491
|
+
global: {
|
492
|
+
maxVisible: DefaultMaxVisible,
|
493
|
+
queue: []
|
494
|
+
}
|
495
|
+
};
|
496
|
+
|
497
|
+
var Store = exports.Store = {};
|
498
|
+
|
499
|
+
var Defaults = exports.Defaults = {
|
500
|
+
type: 'alert',
|
501
|
+
layout: 'topRight',
|
502
|
+
theme: 'mint',
|
503
|
+
text: '',
|
504
|
+
timeout: false,
|
505
|
+
progressBar: true,
|
506
|
+
closeWith: ['click'],
|
507
|
+
animation: {
|
508
|
+
open: 'noty_effects_open',
|
509
|
+
close: 'noty_effects_close'
|
510
|
+
},
|
511
|
+
id: false,
|
512
|
+
force: false,
|
513
|
+
killer: false,
|
514
|
+
queue: 'global',
|
515
|
+
container: false,
|
516
|
+
buttons: [],
|
517
|
+
callbacks: {
|
518
|
+
beforeShow: null,
|
519
|
+
onShow: null,
|
520
|
+
afterShow: null,
|
521
|
+
onClose: null,
|
522
|
+
afterClose: null,
|
523
|
+
onClick: null,
|
524
|
+
onHover: null,
|
525
|
+
onTemplate: null
|
526
|
+
},
|
527
|
+
sounds: {
|
528
|
+
sources: [],
|
529
|
+
volume: 1,
|
530
|
+
conditions: []
|
531
|
+
},
|
532
|
+
titleCount: {
|
533
|
+
conditions: []
|
534
|
+
},
|
535
|
+
modal: false,
|
536
|
+
visibilityControl: false
|
537
|
+
|
538
|
+
/**
|
539
|
+
* @param {string} queueName
|
540
|
+
* @return {object}
|
541
|
+
*/
|
542
|
+
};function getQueueCounts() {
|
543
|
+
var queueName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'global';
|
544
|
+
|
545
|
+
var count = 0;
|
546
|
+
var max = DefaultMaxVisible;
|
547
|
+
|
548
|
+
if (Queues.hasOwnProperty(queueName)) {
|
549
|
+
max = Queues[queueName].maxVisible;
|
550
|
+
Object.keys(Store).forEach(function (i) {
|
551
|
+
if (Store[i].options.queue === queueName && !Store[i].closed) count++;
|
552
|
+
});
|
553
|
+
}
|
554
|
+
|
555
|
+
return {
|
556
|
+
current: count,
|
557
|
+
maxVisible: max
|
558
|
+
};
|
559
|
+
}
|
560
|
+
|
561
|
+
/**
|
562
|
+
* @param {Noty} ref
|
563
|
+
* @return {void}
|
564
|
+
*/
|
565
|
+
function addToQueue(ref) {
|
566
|
+
if (!Queues.hasOwnProperty(ref.options.queue)) {
|
567
|
+
Queues[ref.options.queue] = { maxVisible: DefaultMaxVisible, queue: [] };
|
568
|
+
}
|
569
|
+
|
570
|
+
Queues[ref.options.queue].queue.push(ref);
|
571
|
+
}
|
572
|
+
|
573
|
+
/**
|
574
|
+
* @param {Noty} ref
|
575
|
+
* @return {void}
|
576
|
+
*/
|
577
|
+
function removeFromQueue(ref) {
|
578
|
+
if (Queues.hasOwnProperty(ref.options.queue)) {
|
579
|
+
var queue = [];
|
580
|
+
Object.keys(Queues[ref.options.queue].queue).forEach(function (i) {
|
581
|
+
if (Queues[ref.options.queue].queue[i].id !== ref.id) {
|
582
|
+
queue.push(Queues[ref.options.queue].queue[i]);
|
583
|
+
}
|
584
|
+
});
|
585
|
+
Queues[ref.options.queue].queue = queue;
|
586
|
+
}
|
587
|
+
}
|
588
|
+
|
589
|
+
/**
|
590
|
+
* @param {string} queueName
|
591
|
+
* @return {void}
|
592
|
+
*/
|
593
|
+
function queueRender() {
|
594
|
+
var queueName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'global';
|
595
|
+
|
596
|
+
if (Queues.hasOwnProperty(queueName)) {
|
597
|
+
var noty = Queues[queueName].queue.shift();
|
598
|
+
|
599
|
+
if (noty) noty.show();
|
600
|
+
}
|
601
|
+
}
|
602
|
+
|
603
|
+
/**
|
604
|
+
* @return {void}
|
605
|
+
*/
|
606
|
+
function queueRenderAll() {
|
607
|
+
Object.keys(Queues).forEach(function (queueName) {
|
608
|
+
queueRender(queueName);
|
609
|
+
});
|
610
|
+
}
|
611
|
+
|
612
|
+
/**
|
613
|
+
* @param {Noty} ref
|
614
|
+
* @return {void}
|
615
|
+
*/
|
616
|
+
function ghostFix(ref) {
|
617
|
+
var ghostID = Utils.generateID('ghost');
|
618
|
+
var ghost = document.createElement('div');
|
619
|
+
ghost.setAttribute('id', ghostID);
|
620
|
+
Utils.css(ghost, {
|
621
|
+
height: Utils.outerHeight(ref.barDom) + 'px'
|
622
|
+
});
|
623
|
+
|
624
|
+
ref.barDom.insertAdjacentHTML('afterend', ghost.outerHTML);
|
625
|
+
|
626
|
+
Utils.remove(ref.barDom);
|
627
|
+
ghost = document.getElementById(ghostID);
|
628
|
+
Utils.addClass(ghost, 'noty_fix_effects_height');
|
629
|
+
Utils.addListener(ghost, Utils.animationEndEvents, function () {
|
630
|
+
Utils.remove(ghost);
|
631
|
+
});
|
632
|
+
}
|
633
|
+
|
634
|
+
/**
|
635
|
+
* @param {Noty} ref
|
636
|
+
* @return {void}
|
637
|
+
*/
|
638
|
+
function build(ref) {
|
639
|
+
findOrCreateContainer(ref);
|
640
|
+
|
641
|
+
var markup = '<div class="noty_body">' + ref.options.text + '</div>' + buildButtons(ref) + '<div class="noty_progressbar"></div>';
|
642
|
+
|
643
|
+
ref.barDom = document.createElement('div');
|
644
|
+
ref.barDom.setAttribute('id', ref.id);
|
645
|
+
Utils.addClass(ref.barDom, 'noty_bar noty_type__' + ref.options.type + ' noty_theme__' + ref.options.theme);
|
646
|
+
|
647
|
+
ref.barDom.innerHTML = markup;
|
648
|
+
|
649
|
+
fire(ref, 'onTemplate');
|
650
|
+
}
|
651
|
+
|
652
|
+
/**
|
653
|
+
* @param {Noty} ref
|
654
|
+
* @return {boolean}
|
655
|
+
*/
|
656
|
+
function hasButtons(ref) {
|
657
|
+
return !!(ref.options.buttons && Object.keys(ref.options.buttons).length);
|
658
|
+
}
|
659
|
+
|
660
|
+
/**
|
661
|
+
* @param {Noty} ref
|
662
|
+
* @return {string}
|
663
|
+
*/
|
664
|
+
function buildButtons(ref) {
|
665
|
+
if (hasButtons(ref)) {
|
666
|
+
var buttons = document.createElement('div');
|
667
|
+
Utils.addClass(buttons, 'noty_buttons');
|
668
|
+
|
669
|
+
Object.keys(ref.options.buttons).forEach(function (key) {
|
670
|
+
buttons.appendChild(ref.options.buttons[key].dom);
|
671
|
+
});
|
672
|
+
|
673
|
+
ref.options.buttons.forEach(function (btn) {
|
674
|
+
buttons.appendChild(btn.dom);
|
675
|
+
});
|
676
|
+
return buttons.outerHTML;
|
677
|
+
}
|
678
|
+
return '';
|
679
|
+
}
|
680
|
+
|
681
|
+
/**
|
682
|
+
* @param {Noty} ref
|
683
|
+
* @return {void}
|
684
|
+
*/
|
685
|
+
function handleModal(ref) {
|
686
|
+
if (ref.options.modal) {
|
687
|
+
if (DocModalCount === 0) {
|
688
|
+
createModal(ref);
|
689
|
+
}
|
690
|
+
|
691
|
+
exports.DocModalCount = DocModalCount += 1;
|
692
|
+
}
|
693
|
+
}
|
694
|
+
|
695
|
+
/**
|
696
|
+
* @param {Noty} ref
|
697
|
+
* @return {void}
|
698
|
+
*/
|
699
|
+
function handleModalClose(ref) {
|
700
|
+
if (ref.options.modal && DocModalCount > 0) {
|
701
|
+
exports.DocModalCount = DocModalCount -= 1;
|
702
|
+
|
703
|
+
if (DocModalCount <= 0) {
|
704
|
+
var modal = document.querySelector('.noty_modal');
|
705
|
+
|
706
|
+
if (modal) {
|
707
|
+
Utils.removeClass(modal, 'noty_modal_open');
|
708
|
+
Utils.addClass(modal, 'noty_modal_close');
|
709
|
+
Utils.addListener(modal, Utils.animationEndEvents, function () {
|
710
|
+
Utils.remove(modal);
|
711
|
+
});
|
712
|
+
}
|
713
|
+
}
|
714
|
+
}
|
715
|
+
}
|
716
|
+
|
717
|
+
/**
|
718
|
+
* @return {void}
|
719
|
+
*/
|
720
|
+
function createModal() {
|
721
|
+
var body = document.querySelector('body');
|
722
|
+
var modal = document.createElement('div');
|
723
|
+
Utils.addClass(modal, 'noty_modal');
|
724
|
+
body.insertBefore(modal, body.firstChild);
|
725
|
+
Utils.addClass(modal, 'noty_modal_open');
|
726
|
+
|
727
|
+
Utils.addListener(modal, Utils.animationEndEvents, function () {
|
728
|
+
Utils.removeClass(modal, 'noty_modal_open');
|
729
|
+
});
|
730
|
+
}
|
731
|
+
|
732
|
+
/**
|
733
|
+
* @param {Noty} ref
|
734
|
+
* @return {void}
|
735
|
+
*/
|
736
|
+
function findOrCreateContainer(ref) {
|
737
|
+
if (ref.options.container) {
|
738
|
+
ref.layoutDom = document.querySelector(ref.options.container);
|
739
|
+
return;
|
740
|
+
}
|
741
|
+
|
742
|
+
var layoutID = 'noty_layout__' + ref.options.layout;
|
743
|
+
ref.layoutDom = document.querySelector('div#' + layoutID);
|
744
|
+
|
745
|
+
if (!ref.layoutDom) {
|
746
|
+
ref.layoutDom = document.createElement('div');
|
747
|
+
ref.layoutDom.setAttribute('id', layoutID);
|
748
|
+
ref.layoutDom.setAttribute('role', 'alert');
|
749
|
+
ref.layoutDom.setAttribute('aria-live', 'polite');
|
750
|
+
Utils.addClass(ref.layoutDom, 'noty_layout');
|
751
|
+
document.querySelector('body').appendChild(ref.layoutDom);
|
752
|
+
}
|
753
|
+
}
|
754
|
+
|
755
|
+
/**
|
756
|
+
* @param {Noty} ref
|
757
|
+
* @return {void}
|
758
|
+
*/
|
759
|
+
function queueClose(ref) {
|
760
|
+
if (ref.options.timeout) {
|
761
|
+
if (ref.options.progressBar && ref.progressDom) {
|
762
|
+
Utils.css(ref.progressDom, {
|
763
|
+
transition: 'width ' + ref.options.timeout + 'ms linear',
|
764
|
+
width: '0%'
|
765
|
+
});
|
766
|
+
}
|
767
|
+
|
768
|
+
clearTimeout(ref.closeTimer);
|
769
|
+
|
770
|
+
ref.closeTimer = setTimeout(function () {
|
771
|
+
ref.close();
|
772
|
+
}, ref.options.timeout);
|
773
|
+
}
|
774
|
+
}
|
775
|
+
|
776
|
+
/**
|
777
|
+
* @param {Noty} ref
|
778
|
+
* @return {void}
|
779
|
+
*/
|
780
|
+
function dequeueClose(ref) {
|
781
|
+
if (ref.options.timeout && ref.closeTimer) {
|
782
|
+
clearTimeout(ref.closeTimer);
|
783
|
+
ref.closeTimer = -1;
|
784
|
+
|
785
|
+
if (ref.options.progressBar && ref.progressDom) {
|
786
|
+
Utils.css(ref.progressDom, {
|
787
|
+
transition: 'width 0ms linear',
|
788
|
+
width: '100%'
|
789
|
+
});
|
790
|
+
}
|
791
|
+
}
|
792
|
+
}
|
793
|
+
|
794
|
+
/**
|
795
|
+
* @param {Noty} ref
|
796
|
+
* @param {string} eventName
|
797
|
+
* @return {void}
|
798
|
+
*/
|
799
|
+
function fire(ref, eventName) {
|
800
|
+
if (ref.listeners.hasOwnProperty(eventName)) {
|
801
|
+
ref.listeners[eventName].forEach(function (cb) {
|
802
|
+
if (typeof cb === 'function') {
|
803
|
+
cb.apply(ref);
|
804
|
+
}
|
805
|
+
});
|
806
|
+
}
|
807
|
+
}
|
808
|
+
|
809
|
+
/**
|
810
|
+
* @param {Noty} ref
|
811
|
+
* @return {void}
|
812
|
+
*/
|
813
|
+
function openFlow(ref) {
|
814
|
+
fire(ref, 'afterShow');
|
815
|
+
queueClose(ref);
|
816
|
+
|
817
|
+
Utils.addListener(ref.barDom, 'mouseenter', function () {
|
818
|
+
dequeueClose(ref);
|
819
|
+
});
|
820
|
+
|
821
|
+
Utils.addListener(ref.barDom, 'mouseleave', function () {
|
822
|
+
queueClose(ref);
|
823
|
+
});
|
824
|
+
}
|
825
|
+
|
826
|
+
/**
|
827
|
+
* @param {Noty} ref
|
828
|
+
* @return {void}
|
829
|
+
*/
|
830
|
+
function closeFlow(ref) {
|
831
|
+
delete Store[ref.id];
|
832
|
+
ref.closing = false;
|
833
|
+
fire(ref, 'afterClose');
|
834
|
+
|
835
|
+
Utils.remove(ref.barDom);
|
836
|
+
|
837
|
+
if (ref.layoutDom.querySelectorAll('.noty_bar').length === 0 && !ref.options.container) {
|
838
|
+
Utils.remove(ref.layoutDom);
|
839
|
+
}
|
840
|
+
|
841
|
+
if (Utils.inArray('docVisible', ref.options.titleCount.conditions) || Utils.inArray('docHidden', ref.options.titleCount.conditions)) {
|
842
|
+
docTitle.decrement();
|
843
|
+
}
|
844
|
+
|
845
|
+
queueRender(ref.options.queue);
|
846
|
+
}
|
847
|
+
|
848
|
+
/***/ }),
|
849
|
+
/* 2 */
|
850
|
+
/***/ (function(module, exports, __webpack_require__) {
|
851
|
+
|
852
|
+
"use strict";
|
853
|
+
|
854
|
+
|
855
|
+
Object.defineProperty(exports, "__esModule", {
|
856
|
+
value: true
|
857
|
+
});
|
858
|
+
exports.NotyButton = undefined;
|
859
|
+
|
860
|
+
var _utils = __webpack_require__(0);
|
861
|
+
|
862
|
+
var Utils = _interopRequireWildcard(_utils);
|
863
|
+
|
864
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
865
|
+
|
866
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
867
|
+
|
868
|
+
var NotyButton = exports.NotyButton = function NotyButton(html, classes, cb) {
|
869
|
+
var _this = this;
|
870
|
+
|
871
|
+
var attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
872
|
+
|
873
|
+
_classCallCheck(this, NotyButton);
|
874
|
+
|
875
|
+
this.dom = document.createElement('button');
|
876
|
+
this.dom.innerHTML = html;
|
877
|
+
this.id = attributes.id = attributes.id || Utils.generateID('button');
|
878
|
+
this.cb = cb;
|
879
|
+
Object.keys(attributes).forEach(function (propertyName) {
|
880
|
+
_this.dom.setAttribute(propertyName, attributes[propertyName]);
|
881
|
+
});
|
882
|
+
Utils.addClass(this.dom, classes || 'noty_btn');
|
883
|
+
|
884
|
+
return this;
|
885
|
+
};
|
886
|
+
|
887
|
+
/***/ }),
|
888
|
+
/* 3 */
|
889
|
+
/***/ (function(module, exports, __webpack_require__) {
|
890
|
+
|
891
|
+
"use strict";
|
892
|
+
|
893
|
+
|
894
|
+
Object.defineProperty(exports, "__esModule", {
|
895
|
+
value: true
|
896
|
+
});
|
897
|
+
|
898
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
|
899
|
+
|
900
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
901
|
+
|
902
|
+
var Push = exports.Push = function () {
|
903
|
+
function Push() {
|
904
|
+
var workerPath = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '/service-worker.js';
|
905
|
+
|
906
|
+
_classCallCheck(this, Push);
|
907
|
+
|
908
|
+
this.subData = {};
|
909
|
+
this.workerPath = workerPath;
|
910
|
+
this.listeners = {
|
911
|
+
onPermissionGranted: [],
|
912
|
+
onPermissionDenied: [],
|
913
|
+
onSubscriptionSuccess: [],
|
914
|
+
onSubscriptionCancel: [],
|
915
|
+
onWorkerError: [],
|
916
|
+
onWorkerSuccess: [],
|
917
|
+
onWorkerNotSupported: []
|
918
|
+
};
|
919
|
+
return this;
|
920
|
+
}
|
921
|
+
|
922
|
+
/**
|
923
|
+
* @param {string} eventName
|
924
|
+
* @param {function} cb
|
925
|
+
* @return {Push}
|
926
|
+
*/
|
927
|
+
|
928
|
+
|
929
|
+
_createClass(Push, [{
|
930
|
+
key: 'on',
|
931
|
+
value: function on(eventName) {
|
932
|
+
var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
|
933
|
+
|
934
|
+
if (typeof cb === 'function' && this.listeners.hasOwnProperty(eventName)) {
|
935
|
+
this.listeners[eventName].push(cb);
|
936
|
+
}
|
937
|
+
|
938
|
+
return this;
|
939
|
+
}
|
940
|
+
}, {
|
941
|
+
key: 'fire',
|
942
|
+
value: function fire(eventName) {
|
943
|
+
var _this = this;
|
944
|
+
|
945
|
+
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
946
|
+
|
947
|
+
if (this.listeners.hasOwnProperty(eventName)) {
|
948
|
+
this.listeners[eventName].forEach(function (cb) {
|
949
|
+
if (typeof cb === 'function') {
|
950
|
+
cb.apply(_this, params);
|
951
|
+
}
|
952
|
+
});
|
953
|
+
}
|
954
|
+
}
|
955
|
+
}, {
|
956
|
+
key: 'create',
|
957
|
+
value: function create() {
|
958
|
+
console.log('NOT IMPLEMENTED YET');
|
959
|
+
}
|
960
|
+
|
961
|
+
/**
|
962
|
+
* @return {boolean}
|
963
|
+
*/
|
964
|
+
|
965
|
+
}, {
|
966
|
+
key: 'isSupported',
|
967
|
+
value: function isSupported() {
|
968
|
+
var result = false;
|
969
|
+
|
970
|
+
try {
|
971
|
+
result = window.Notification || window.webkitNotifications || navigator.mozNotification || window.external && window.external.msIsSiteMode() !== undefined;
|
972
|
+
} catch (e) {}
|
973
|
+
|
974
|
+
return result;
|
975
|
+
}
|
976
|
+
|
977
|
+
/**
|
978
|
+
* @return {string}
|
979
|
+
*/
|
980
|
+
|
981
|
+
}, {
|
982
|
+
key: 'getPermissionStatus',
|
983
|
+
value: function getPermissionStatus() {
|
984
|
+
var perm = 'default';
|
985
|
+
|
986
|
+
if (window.Notification && window.Notification.permissionLevel) {
|
987
|
+
perm = window.Notification.permissionLevel;
|
988
|
+
} else if (window.webkitNotifications && window.webkitNotifications.checkPermission) {
|
989
|
+
switch (window.webkitNotifications.checkPermission()) {
|
990
|
+
case 1:
|
991
|
+
perm = 'default';
|
992
|
+
break;
|
993
|
+
case 0:
|
994
|
+
perm = 'granted';
|
995
|
+
break;
|
996
|
+
default:
|
997
|
+
perm = 'denied';
|
998
|
+
}
|
999
|
+
} else if (window.Notification && window.Notification.permission) {
|
1000
|
+
perm = window.Notification.permission;
|
1001
|
+
} else if (navigator.mozNotification) {
|
1002
|
+
perm = 'granted';
|
1003
|
+
} else if (window.external && window.external.msIsSiteMode() !== undefined) {
|
1004
|
+
perm = window.external.msIsSiteMode() ? 'granted' : 'default';
|
1005
|
+
}
|
1006
|
+
|
1007
|
+
return perm.toString().toLowerCase();
|
1008
|
+
}
|
1009
|
+
|
1010
|
+
/**
|
1011
|
+
* @return {string}
|
1012
|
+
*/
|
1013
|
+
|
1014
|
+
}, {
|
1015
|
+
key: 'getEndpoint',
|
1016
|
+
value: function getEndpoint(subscription) {
|
1017
|
+
var endpoint = subscription.endpoint;
|
1018
|
+
var subscriptionId = subscription.subscriptionId;
|
1019
|
+
|
1020
|
+
// fix for Chrome < 45
|
1021
|
+
if (subscriptionId && endpoint.indexOf(subscriptionId) === -1) {
|
1022
|
+
endpoint += '/' + subscriptionId;
|
1023
|
+
}
|
1024
|
+
|
1025
|
+
return endpoint;
|
1026
|
+
}
|
1027
|
+
|
1028
|
+
/**
|
1029
|
+
* @return {boolean}
|
1030
|
+
*/
|
1031
|
+
|
1032
|
+
}, {
|
1033
|
+
key: 'isSWRegistered',
|
1034
|
+
value: function isSWRegistered() {
|
1035
|
+
try {
|
1036
|
+
return navigator.serviceWorker.controller.state === 'activated';
|
1037
|
+
} catch (e) {
|
1038
|
+
return false;
|
1039
|
+
}
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
/**
|
1043
|
+
* @return {void}
|
1044
|
+
*/
|
1045
|
+
|
1046
|
+
}, {
|
1047
|
+
key: 'unregisterWorker',
|
1048
|
+
value: function unregisterWorker() {
|
1049
|
+
var self = this;
|
1050
|
+
if ('serviceWorker' in navigator) {
|
1051
|
+
navigator.serviceWorker.getRegistrations().then(function (registrations) {
|
1052
|
+
var _iteratorNormalCompletion = true;
|
1053
|
+
var _didIteratorError = false;
|
1054
|
+
var _iteratorError = undefined;
|
1055
|
+
|
1056
|
+
try {
|
1057
|
+
for (var _iterator = registrations[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
1058
|
+
var registration = _step.value;
|
1059
|
+
|
1060
|
+
registration.unregister();
|
1061
|
+
self.fire('onSubscriptionCancel');
|
1062
|
+
}
|
1063
|
+
} catch (err) {
|
1064
|
+
_didIteratorError = true;
|
1065
|
+
_iteratorError = err;
|
1066
|
+
} finally {
|
1067
|
+
try {
|
1068
|
+
if (!_iteratorNormalCompletion && _iterator.return) {
|
1069
|
+
_iterator.return();
|
1070
|
+
}
|
1071
|
+
} finally {
|
1072
|
+
if (_didIteratorError) {
|
1073
|
+
throw _iteratorError;
|
1074
|
+
}
|
1075
|
+
}
|
1076
|
+
}
|
1077
|
+
});
|
1078
|
+
}
|
1079
|
+
}
|
1080
|
+
|
1081
|
+
/**
|
1082
|
+
* @return {void}
|
1083
|
+
*/
|
1084
|
+
|
1085
|
+
}, {
|
1086
|
+
key: 'requestSubscription',
|
1087
|
+
value: function requestSubscription() {
|
1088
|
+
var _this2 = this;
|
1089
|
+
|
1090
|
+
var userVisibleOnly = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
1091
|
+
|
1092
|
+
var self = this;
|
1093
|
+
var current = this.getPermissionStatus();
|
1094
|
+
var cb = function cb(result) {
|
1095
|
+
if (result === 'granted') {
|
1096
|
+
_this2.fire('onPermissionGranted');
|
1097
|
+
|
1098
|
+
if ('serviceWorker' in navigator) {
|
1099
|
+
navigator.serviceWorker.register(_this2.workerPath).then(function () {
|
1100
|
+
navigator.serviceWorker.ready.then(function (serviceWorkerRegistration) {
|
1101
|
+
self.fire('onWorkerSuccess');
|
1102
|
+
serviceWorkerRegistration.pushManager.subscribe({
|
1103
|
+
userVisibleOnly: userVisibleOnly
|
1104
|
+
}).then(function (subscription) {
|
1105
|
+
var key = subscription.getKey('p256dh');
|
1106
|
+
var token = subscription.getKey('auth');
|
1107
|
+
|
1108
|
+
self.subData = {
|
1109
|
+
endpoint: self.getEndpoint(subscription),
|
1110
|
+
p256dh: key ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(key))) : null,
|
1111
|
+
auth: token ? window.btoa(String.fromCharCode.apply(null, new Uint8Array(token))) : null
|
1112
|
+
};
|
1113
|
+
|
1114
|
+
self.fire('onSubscriptionSuccess', [self.subData]);
|
1115
|
+
}).catch(function (err) {
|
1116
|
+
self.fire('onWorkerError', [err]);
|
1117
|
+
});
|
1118
|
+
});
|
1119
|
+
});
|
1120
|
+
} else {
|
1121
|
+
self.fire('onWorkerNotSupported');
|
1122
|
+
}
|
1123
|
+
} else if (result === 'denied') {
|
1124
|
+
_this2.fire('onPermissionDenied');
|
1125
|
+
_this2.unregisterWorker();
|
1126
|
+
}
|
1127
|
+
};
|
1128
|
+
|
1129
|
+
if (current === 'default') {
|
1130
|
+
if (window.Notification && window.Notification.requestPermission) {
|
1131
|
+
window.Notification.requestPermission(cb);
|
1132
|
+
} else if (window.webkitNotifications && window.webkitNotifications.checkPermission) {
|
1133
|
+
window.webkitNotifications.requestPermission(cb);
|
1134
|
+
}
|
1135
|
+
} else {
|
1136
|
+
cb(current);
|
1137
|
+
}
|
1138
|
+
}
|
1139
|
+
}]);
|
1140
|
+
|
1141
|
+
return Push;
|
1142
|
+
}();
|
1143
|
+
|
1144
|
+
/***/ }),
|
1145
|
+
/* 4 */
|
1146
|
+
/***/ (function(module, exports, __webpack_require__) {
|
1147
|
+
|
1148
|
+
/* WEBPACK VAR INJECTION */(function(process, global) {var require;/*!
|
1149
|
+
* @overview es6-promise - a tiny implementation of Promises/A+.
|
1150
|
+
* @copyright Copyright (c) 2014 Yehuda Katz, Tom Dale, Stefan Penner and contributors (Conversion to ES6 API by Jake Archibald)
|
1151
|
+
* @license Licensed under MIT license
|
1152
|
+
* See https://raw.githubusercontent.com/stefanpenner/es6-promise/master/LICENSE
|
1153
|
+
* @version 4.1.1
|
1154
|
+
*/
|
1155
|
+
|
1156
|
+
(function (global, factory) {
|
1157
|
+
true ? module.exports = factory() :
|
1158
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
1159
|
+
(global.ES6Promise = factory());
|
1160
|
+
}(this, (function () { 'use strict';
|
1161
|
+
|
1162
|
+
function objectOrFunction(x) {
|
1163
|
+
var type = typeof x;
|
1164
|
+
return x !== null && (type === 'object' || type === 'function');
|
1165
|
+
}
|
1166
|
+
|
1167
|
+
function isFunction(x) {
|
1168
|
+
return typeof x === 'function';
|
1169
|
+
}
|
1170
|
+
|
1171
|
+
var _isArray = undefined;
|
1172
|
+
if (Array.isArray) {
|
1173
|
+
_isArray = Array.isArray;
|
1174
|
+
} else {
|
1175
|
+
_isArray = function (x) {
|
1176
|
+
return Object.prototype.toString.call(x) === '[object Array]';
|
1177
|
+
};
|
1178
|
+
}
|
1179
|
+
|
1180
|
+
var isArray = _isArray;
|
1181
|
+
|
1182
|
+
var len = 0;
|
1183
|
+
var vertxNext = undefined;
|
1184
|
+
var customSchedulerFn = undefined;
|
1185
|
+
|
1186
|
+
var asap = function asap(callback, arg) {
|
1187
|
+
queue[len] = callback;
|
1188
|
+
queue[len + 1] = arg;
|
1189
|
+
len += 2;
|
1190
|
+
if (len === 2) {
|
1191
|
+
// If len is 2, that means that we need to schedule an async flush.
|
1192
|
+
// If additional callbacks are queued before the queue is flushed, they
|
1193
|
+
// will be processed by this flush that we are scheduling.
|
1194
|
+
if (customSchedulerFn) {
|
1195
|
+
customSchedulerFn(flush);
|
1196
|
+
} else {
|
1197
|
+
scheduleFlush();
|
1198
|
+
}
|
1199
|
+
}
|
1200
|
+
};
|
1201
|
+
|
1202
|
+
function setScheduler(scheduleFn) {
|
1203
|
+
customSchedulerFn = scheduleFn;
|
1204
|
+
}
|
1205
|
+
|
1206
|
+
function setAsap(asapFn) {
|
1207
|
+
asap = asapFn;
|
1208
|
+
}
|
1209
|
+
|
1210
|
+
var browserWindow = typeof window !== 'undefined' ? window : undefined;
|
1211
|
+
var browserGlobal = browserWindow || {};
|
1212
|
+
var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver;
|
1213
|
+
var isNode = typeof self === 'undefined' && typeof process !== 'undefined' && ({}).toString.call(process) === '[object process]';
|
1214
|
+
|
1215
|
+
// test for web worker but not in IE10
|
1216
|
+
var isWorker = typeof Uint8ClampedArray !== 'undefined' && typeof importScripts !== 'undefined' && typeof MessageChannel !== 'undefined';
|
1217
|
+
|
1218
|
+
// node
|
1219
|
+
function useNextTick() {
|
1220
|
+
// node version 0.10.x displays a deprecation warning when nextTick is used recursively
|
1221
|
+
// see https://github.com/cujojs/when/issues/410 for details
|
1222
|
+
return function () {
|
1223
|
+
return process.nextTick(flush);
|
1224
|
+
};
|
1225
|
+
}
|
1226
|
+
|
1227
|
+
// vertx
|
1228
|
+
function useVertxTimer() {
|
1229
|
+
if (typeof vertxNext !== 'undefined') {
|
1230
|
+
return function () {
|
1231
|
+
vertxNext(flush);
|
1232
|
+
};
|
1233
|
+
}
|
1234
|
+
|
1235
|
+
return useSetTimeout();
|
1236
|
+
}
|
1237
|
+
|
1238
|
+
function useMutationObserver() {
|
1239
|
+
var iterations = 0;
|
1240
|
+
var observer = new BrowserMutationObserver(flush);
|
1241
|
+
var node = document.createTextNode('');
|
1242
|
+
observer.observe(node, { characterData: true });
|
1243
|
+
|
1244
|
+
return function () {
|
1245
|
+
node.data = iterations = ++iterations % 2;
|
1246
|
+
};
|
1247
|
+
}
|
1248
|
+
|
1249
|
+
// web worker
|
1250
|
+
function useMessageChannel() {
|
1251
|
+
var channel = new MessageChannel();
|
1252
|
+
channel.port1.onmessage = flush;
|
1253
|
+
return function () {
|
1254
|
+
return channel.port2.postMessage(0);
|
1255
|
+
};
|
1256
|
+
}
|
1257
|
+
|
1258
|
+
function useSetTimeout() {
|
1259
|
+
// Store setTimeout reference so es6-promise will be unaffected by
|
1260
|
+
// other code modifying setTimeout (like sinon.useFakeTimers())
|
1261
|
+
var globalSetTimeout = setTimeout;
|
1262
|
+
return function () {
|
1263
|
+
return globalSetTimeout(flush, 1);
|
1264
|
+
};
|
1265
|
+
}
|
1266
|
+
|
1267
|
+
var queue = new Array(1000);
|
1268
|
+
function flush() {
|
1269
|
+
for (var i = 0; i < len; i += 2) {
|
1270
|
+
var callback = queue[i];
|
1271
|
+
var arg = queue[i + 1];
|
1272
|
+
|
1273
|
+
callback(arg);
|
1274
|
+
|
1275
|
+
queue[i] = undefined;
|
1276
|
+
queue[i + 1] = undefined;
|
1277
|
+
}
|
1278
|
+
|
1279
|
+
len = 0;
|
1280
|
+
}
|
1281
|
+
|
1282
|
+
function attemptVertx() {
|
1283
|
+
try {
|
1284
|
+
var r = require;
|
1285
|
+
var vertx = __webpack_require__(9);
|
1286
|
+
vertxNext = vertx.runOnLoop || vertx.runOnContext;
|
1287
|
+
return useVertxTimer();
|
1288
|
+
} catch (e) {
|
1289
|
+
return useSetTimeout();
|
1290
|
+
}
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
var scheduleFlush = undefined;
|
1294
|
+
// Decide what async method to use to triggering processing of queued callbacks:
|
1295
|
+
if (isNode) {
|
1296
|
+
scheduleFlush = useNextTick();
|
1297
|
+
} else if (BrowserMutationObserver) {
|
1298
|
+
scheduleFlush = useMutationObserver();
|
1299
|
+
} else if (isWorker) {
|
1300
|
+
scheduleFlush = useMessageChannel();
|
1301
|
+
} else if (browserWindow === undefined && "function" === 'function') {
|
1302
|
+
scheduleFlush = attemptVertx();
|
1303
|
+
} else {
|
1304
|
+
scheduleFlush = useSetTimeout();
|
1305
|
+
}
|
1306
|
+
|
1307
|
+
function then(onFulfillment, onRejection) {
|
1308
|
+
var _arguments = arguments;
|
1309
|
+
|
1310
|
+
var parent = this;
|
1311
|
+
|
1312
|
+
var child = new this.constructor(noop);
|
1313
|
+
|
1314
|
+
if (child[PROMISE_ID] === undefined) {
|
1315
|
+
makePromise(child);
|
1316
|
+
}
|
1317
|
+
|
1318
|
+
var _state = parent._state;
|
1319
|
+
|
1320
|
+
if (_state) {
|
1321
|
+
(function () {
|
1322
|
+
var callback = _arguments[_state - 1];
|
1323
|
+
asap(function () {
|
1324
|
+
return invokeCallback(_state, child, callback, parent._result);
|
1325
|
+
});
|
1326
|
+
})();
|
1327
|
+
} else {
|
1328
|
+
subscribe(parent, child, onFulfillment, onRejection);
|
1329
|
+
}
|
1330
|
+
|
1331
|
+
return child;
|
1332
|
+
}
|
1333
|
+
|
1334
|
+
/**
|
1335
|
+
`Promise.resolve` returns a promise that will become resolved with the
|
1336
|
+
passed `value`. It is shorthand for the following:
|
1337
|
+
|
1338
|
+
```javascript
|
1339
|
+
let promise = new Promise(function(resolve, reject){
|
1340
|
+
resolve(1);
|
1341
|
+
});
|
1342
|
+
|
1343
|
+
promise.then(function(value){
|
1344
|
+
// value === 1
|
1345
|
+
});
|
1346
|
+
```
|
1347
|
+
|
1348
|
+
Instead of writing the above, your code now simply becomes the following:
|
1349
|
+
|
1350
|
+
```javascript
|
1351
|
+
let promise = Promise.resolve(1);
|
1352
|
+
|
1353
|
+
promise.then(function(value){
|
1354
|
+
// value === 1
|
1355
|
+
});
|
1356
|
+
```
|
1357
|
+
|
1358
|
+
@method resolve
|
1359
|
+
@static
|
1360
|
+
@param {Any} value value that the returned promise will be resolved with
|
1361
|
+
Useful for tooling.
|
1362
|
+
@return {Promise} a promise that will become fulfilled with the given
|
1363
|
+
`value`
|
1364
|
+
*/
|
1365
|
+
function resolve$1(object) {
|
1366
|
+
/*jshint validthis:true */
|
1367
|
+
var Constructor = this;
|
1368
|
+
|
1369
|
+
if (object && typeof object === 'object' && object.constructor === Constructor) {
|
1370
|
+
return object;
|
1371
|
+
}
|
1372
|
+
|
1373
|
+
var promise = new Constructor(noop);
|
1374
|
+
resolve(promise, object);
|
1375
|
+
return promise;
|
1376
|
+
}
|
1377
|
+
|
1378
|
+
var PROMISE_ID = Math.random().toString(36).substring(16);
|
1379
|
+
|
1380
|
+
function noop() {}
|
1381
|
+
|
1382
|
+
var PENDING = void 0;
|
1383
|
+
var FULFILLED = 1;
|
1384
|
+
var REJECTED = 2;
|
1385
|
+
|
1386
|
+
var GET_THEN_ERROR = new ErrorObject();
|
1387
|
+
|
1388
|
+
function selfFulfillment() {
|
1389
|
+
return new TypeError("You cannot resolve a promise with itself");
|
1390
|
+
}
|
1391
|
+
|
1392
|
+
function cannotReturnOwn() {
|
1393
|
+
return new TypeError('A promises callback cannot return that same promise.');
|
1394
|
+
}
|
1395
|
+
|
1396
|
+
function getThen(promise) {
|
1397
|
+
try {
|
1398
|
+
return promise.then;
|
1399
|
+
} catch (error) {
|
1400
|
+
GET_THEN_ERROR.error = error;
|
1401
|
+
return GET_THEN_ERROR;
|
1402
|
+
}
|
1403
|
+
}
|
1404
|
+
|
1405
|
+
function tryThen(then$$1, value, fulfillmentHandler, rejectionHandler) {
|
1406
|
+
try {
|
1407
|
+
then$$1.call(value, fulfillmentHandler, rejectionHandler);
|
1408
|
+
} catch (e) {
|
1409
|
+
return e;
|
1410
|
+
}
|
1411
|
+
}
|
1412
|
+
|
1413
|
+
function handleForeignThenable(promise, thenable, then$$1) {
|
1414
|
+
asap(function (promise) {
|
1415
|
+
var sealed = false;
|
1416
|
+
var error = tryThen(then$$1, thenable, function (value) {
|
1417
|
+
if (sealed) {
|
1418
|
+
return;
|
1419
|
+
}
|
1420
|
+
sealed = true;
|
1421
|
+
if (thenable !== value) {
|
1422
|
+
resolve(promise, value);
|
1423
|
+
} else {
|
1424
|
+
fulfill(promise, value);
|
1425
|
+
}
|
1426
|
+
}, function (reason) {
|
1427
|
+
if (sealed) {
|
1428
|
+
return;
|
1429
|
+
}
|
1430
|
+
sealed = true;
|
1431
|
+
|
1432
|
+
reject(promise, reason);
|
1433
|
+
}, 'Settle: ' + (promise._label || ' unknown promise'));
|
1434
|
+
|
1435
|
+
if (!sealed && error) {
|
1436
|
+
sealed = true;
|
1437
|
+
reject(promise, error);
|
1438
|
+
}
|
1439
|
+
}, promise);
|
1440
|
+
}
|
1441
|
+
|
1442
|
+
function handleOwnThenable(promise, thenable) {
|
1443
|
+
if (thenable._state === FULFILLED) {
|
1444
|
+
fulfill(promise, thenable._result);
|
1445
|
+
} else if (thenable._state === REJECTED) {
|
1446
|
+
reject(promise, thenable._result);
|
1447
|
+
} else {
|
1448
|
+
subscribe(thenable, undefined, function (value) {
|
1449
|
+
return resolve(promise, value);
|
1450
|
+
}, function (reason) {
|
1451
|
+
return reject(promise, reason);
|
1452
|
+
});
|
1453
|
+
}
|
1454
|
+
}
|
1455
|
+
|
1456
|
+
function handleMaybeThenable(promise, maybeThenable, then$$1) {
|
1457
|
+
if (maybeThenable.constructor === promise.constructor && then$$1 === then && maybeThenable.constructor.resolve === resolve$1) {
|
1458
|
+
handleOwnThenable(promise, maybeThenable);
|
1459
|
+
} else {
|
1460
|
+
if (then$$1 === GET_THEN_ERROR) {
|
1461
|
+
reject(promise, GET_THEN_ERROR.error);
|
1462
|
+
GET_THEN_ERROR.error = null;
|
1463
|
+
} else if (then$$1 === undefined) {
|
1464
|
+
fulfill(promise, maybeThenable);
|
1465
|
+
} else if (isFunction(then$$1)) {
|
1466
|
+
handleForeignThenable(promise, maybeThenable, then$$1);
|
1467
|
+
} else {
|
1468
|
+
fulfill(promise, maybeThenable);
|
1469
|
+
}
|
1470
|
+
}
|
1471
|
+
}
|
1472
|
+
|
1473
|
+
function resolve(promise, value) {
|
1474
|
+
if (promise === value) {
|
1475
|
+
reject(promise, selfFulfillment());
|
1476
|
+
} else if (objectOrFunction(value)) {
|
1477
|
+
handleMaybeThenable(promise, value, getThen(value));
|
1478
|
+
} else {
|
1479
|
+
fulfill(promise, value);
|
1480
|
+
}
|
1481
|
+
}
|
1482
|
+
|
1483
|
+
function publishRejection(promise) {
|
1484
|
+
if (promise._onerror) {
|
1485
|
+
promise._onerror(promise._result);
|
1486
|
+
}
|
1487
|
+
|
1488
|
+
publish(promise);
|
1489
|
+
}
|
1490
|
+
|
1491
|
+
function fulfill(promise, value) {
|
1492
|
+
if (promise._state !== PENDING) {
|
1493
|
+
return;
|
1494
|
+
}
|
1495
|
+
|
1496
|
+
promise._result = value;
|
1497
|
+
promise._state = FULFILLED;
|
1498
|
+
|
1499
|
+
if (promise._subscribers.length !== 0) {
|
1500
|
+
asap(publish, promise);
|
1501
|
+
}
|
1502
|
+
}
|
1503
|
+
|
1504
|
+
function reject(promise, reason) {
|
1505
|
+
if (promise._state !== PENDING) {
|
1506
|
+
return;
|
1507
|
+
}
|
1508
|
+
promise._state = REJECTED;
|
1509
|
+
promise._result = reason;
|
1510
|
+
|
1511
|
+
asap(publishRejection, promise);
|
1512
|
+
}
|
1513
|
+
|
1514
|
+
function subscribe(parent, child, onFulfillment, onRejection) {
|
1515
|
+
var _subscribers = parent._subscribers;
|
1516
|
+
var length = _subscribers.length;
|
1517
|
+
|
1518
|
+
parent._onerror = null;
|
1519
|
+
|
1520
|
+
_subscribers[length] = child;
|
1521
|
+
_subscribers[length + FULFILLED] = onFulfillment;
|
1522
|
+
_subscribers[length + REJECTED] = onRejection;
|
1523
|
+
|
1524
|
+
if (length === 0 && parent._state) {
|
1525
|
+
asap(publish, parent);
|
1526
|
+
}
|
1527
|
+
}
|
1528
|
+
|
1529
|
+
function publish(promise) {
|
1530
|
+
var subscribers = promise._subscribers;
|
1531
|
+
var settled = promise._state;
|
1532
|
+
|
1533
|
+
if (subscribers.length === 0) {
|
1534
|
+
return;
|
1535
|
+
}
|
1536
|
+
|
1537
|
+
var child = undefined,
|
1538
|
+
callback = undefined,
|
1539
|
+
detail = promise._result;
|
1540
|
+
|
1541
|
+
for (var i = 0; i < subscribers.length; i += 3) {
|
1542
|
+
child = subscribers[i];
|
1543
|
+
callback = subscribers[i + settled];
|
1544
|
+
|
1545
|
+
if (child) {
|
1546
|
+
invokeCallback(settled, child, callback, detail);
|
1547
|
+
} else {
|
1548
|
+
callback(detail);
|
1549
|
+
}
|
1550
|
+
}
|
1551
|
+
|
1552
|
+
promise._subscribers.length = 0;
|
1553
|
+
}
|
1554
|
+
|
1555
|
+
function ErrorObject() {
|
1556
|
+
this.error = null;
|
1557
|
+
}
|
1558
|
+
|
1559
|
+
var TRY_CATCH_ERROR = new ErrorObject();
|
1560
|
+
|
1561
|
+
function tryCatch(callback, detail) {
|
1562
|
+
try {
|
1563
|
+
return callback(detail);
|
1564
|
+
} catch (e) {
|
1565
|
+
TRY_CATCH_ERROR.error = e;
|
1566
|
+
return TRY_CATCH_ERROR;
|
1567
|
+
}
|
1568
|
+
}
|
1569
|
+
|
1570
|
+
function invokeCallback(settled, promise, callback, detail) {
|
1571
|
+
var hasCallback = isFunction(callback),
|
1572
|
+
value = undefined,
|
1573
|
+
error = undefined,
|
1574
|
+
succeeded = undefined,
|
1575
|
+
failed = undefined;
|
1576
|
+
|
1577
|
+
if (hasCallback) {
|
1578
|
+
value = tryCatch(callback, detail);
|
1579
|
+
|
1580
|
+
if (value === TRY_CATCH_ERROR) {
|
1581
|
+
failed = true;
|
1582
|
+
error = value.error;
|
1583
|
+
value.error = null;
|
1584
|
+
} else {
|
1585
|
+
succeeded = true;
|
1586
|
+
}
|
1587
|
+
|
1588
|
+
if (promise === value) {
|
1589
|
+
reject(promise, cannotReturnOwn());
|
1590
|
+
return;
|
1591
|
+
}
|
1592
|
+
} else {
|
1593
|
+
value = detail;
|
1594
|
+
succeeded = true;
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
if (promise._state !== PENDING) {
|
1598
|
+
// noop
|
1599
|
+
} else if (hasCallback && succeeded) {
|
1600
|
+
resolve(promise, value);
|
1601
|
+
} else if (failed) {
|
1602
|
+
reject(promise, error);
|
1603
|
+
} else if (settled === FULFILLED) {
|
1604
|
+
fulfill(promise, value);
|
1605
|
+
} else if (settled === REJECTED) {
|
1606
|
+
reject(promise, value);
|
1607
|
+
}
|
1608
|
+
}
|
1609
|
+
|
1610
|
+
function initializePromise(promise, resolver) {
|
1611
|
+
try {
|
1612
|
+
resolver(function resolvePromise(value) {
|
1613
|
+
resolve(promise, value);
|
1614
|
+
}, function rejectPromise(reason) {
|
1615
|
+
reject(promise, reason);
|
1616
|
+
});
|
1617
|
+
} catch (e) {
|
1618
|
+
reject(promise, e);
|
1619
|
+
}
|
1620
|
+
}
|
1621
|
+
|
1622
|
+
var id = 0;
|
1623
|
+
function nextId() {
|
1624
|
+
return id++;
|
1625
|
+
}
|
1626
|
+
|
1627
|
+
function makePromise(promise) {
|
1628
|
+
promise[PROMISE_ID] = id++;
|
1629
|
+
promise._state = undefined;
|
1630
|
+
promise._result = undefined;
|
1631
|
+
promise._subscribers = [];
|
1632
|
+
}
|
1633
|
+
|
1634
|
+
function Enumerator$1(Constructor, input) {
|
1635
|
+
this._instanceConstructor = Constructor;
|
1636
|
+
this.promise = new Constructor(noop);
|
1637
|
+
|
1638
|
+
if (!this.promise[PROMISE_ID]) {
|
1639
|
+
makePromise(this.promise);
|
1640
|
+
}
|
1641
|
+
|
1642
|
+
if (isArray(input)) {
|
1643
|
+
this.length = input.length;
|
1644
|
+
this._remaining = input.length;
|
1645
|
+
|
1646
|
+
this._result = new Array(this.length);
|
1647
|
+
|
1648
|
+
if (this.length === 0) {
|
1649
|
+
fulfill(this.promise, this._result);
|
1650
|
+
} else {
|
1651
|
+
this.length = this.length || 0;
|
1652
|
+
this._enumerate(input);
|
1653
|
+
if (this._remaining === 0) {
|
1654
|
+
fulfill(this.promise, this._result);
|
1655
|
+
}
|
1656
|
+
}
|
1657
|
+
} else {
|
1658
|
+
reject(this.promise, validationError());
|
1659
|
+
}
|
1660
|
+
}
|
1661
|
+
|
1662
|
+
function validationError() {
|
1663
|
+
return new Error('Array Methods must be provided an Array');
|
1664
|
+
}
|
1665
|
+
|
1666
|
+
Enumerator$1.prototype._enumerate = function (input) {
|
1667
|
+
for (var i = 0; this._state === PENDING && i < input.length; i++) {
|
1668
|
+
this._eachEntry(input[i], i);
|
1669
|
+
}
|
1670
|
+
};
|
1671
|
+
|
1672
|
+
Enumerator$1.prototype._eachEntry = function (entry, i) {
|
1673
|
+
var c = this._instanceConstructor;
|
1674
|
+
var resolve$$1 = c.resolve;
|
1675
|
+
|
1676
|
+
if (resolve$$1 === resolve$1) {
|
1677
|
+
var _then = getThen(entry);
|
1678
|
+
|
1679
|
+
if (_then === then && entry._state !== PENDING) {
|
1680
|
+
this._settledAt(entry._state, i, entry._result);
|
1681
|
+
} else if (typeof _then !== 'function') {
|
1682
|
+
this._remaining--;
|
1683
|
+
this._result[i] = entry;
|
1684
|
+
} else if (c === Promise$2) {
|
1685
|
+
var promise = new c(noop);
|
1686
|
+
handleMaybeThenable(promise, entry, _then);
|
1687
|
+
this._willSettleAt(promise, i);
|
1688
|
+
} else {
|
1689
|
+
this._willSettleAt(new c(function (resolve$$1) {
|
1690
|
+
return resolve$$1(entry);
|
1691
|
+
}), i);
|
1692
|
+
}
|
1693
|
+
} else {
|
1694
|
+
this._willSettleAt(resolve$$1(entry), i);
|
1695
|
+
}
|
1696
|
+
};
|
1697
|
+
|
1698
|
+
Enumerator$1.prototype._settledAt = function (state, i, value) {
|
1699
|
+
var promise = this.promise;
|
1700
|
+
|
1701
|
+
if (promise._state === PENDING) {
|
1702
|
+
this._remaining--;
|
1703
|
+
|
1704
|
+
if (state === REJECTED) {
|
1705
|
+
reject(promise, value);
|
1706
|
+
} else {
|
1707
|
+
this._result[i] = value;
|
1708
|
+
}
|
1709
|
+
}
|
1710
|
+
|
1711
|
+
if (this._remaining === 0) {
|
1712
|
+
fulfill(promise, this._result);
|
1713
|
+
}
|
1714
|
+
};
|
1715
|
+
|
1716
|
+
Enumerator$1.prototype._willSettleAt = function (promise, i) {
|
1717
|
+
var enumerator = this;
|
1718
|
+
|
1719
|
+
subscribe(promise, undefined, function (value) {
|
1720
|
+
return enumerator._settledAt(FULFILLED, i, value);
|
1721
|
+
}, function (reason) {
|
1722
|
+
return enumerator._settledAt(REJECTED, i, reason);
|
1723
|
+
});
|
1724
|
+
};
|
1725
|
+
|
1726
|
+
/**
|
1727
|
+
`Promise.all` accepts an array of promises, and returns a new promise which
|
1728
|
+
is fulfilled with an array of fulfillment values for the passed promises, or
|
1729
|
+
rejected with the reason of the first passed promise to be rejected. It casts all
|
1730
|
+
elements of the passed iterable to promises as it runs this algorithm.
|
1731
|
+
|
1732
|
+
Example:
|
1733
|
+
|
1734
|
+
```javascript
|
1735
|
+
let promise1 = resolve(1);
|
1736
|
+
let promise2 = resolve(2);
|
1737
|
+
let promise3 = resolve(3);
|
1738
|
+
let promises = [ promise1, promise2, promise3 ];
|
1739
|
+
|
1740
|
+
Promise.all(promises).then(function(array){
|
1741
|
+
// The array here would be [ 1, 2, 3 ];
|
1742
|
+
});
|
1743
|
+
```
|
1744
|
+
|
1745
|
+
If any of the `promises` given to `all` are rejected, the first promise
|
1746
|
+
that is rejected will be given as an argument to the returned promises's
|
1747
|
+
rejection handler. For example:
|
1748
|
+
|
1749
|
+
Example:
|
1750
|
+
|
1751
|
+
```javascript
|
1752
|
+
let promise1 = resolve(1);
|
1753
|
+
let promise2 = reject(new Error("2"));
|
1754
|
+
let promise3 = reject(new Error("3"));
|
1755
|
+
let promises = [ promise1, promise2, promise3 ];
|
1756
|
+
|
1757
|
+
Promise.all(promises).then(function(array){
|
1758
|
+
// Code here never runs because there are rejected promises!
|
1759
|
+
}, function(error) {
|
1760
|
+
// error.message === "2"
|
1761
|
+
});
|
1762
|
+
```
|
1763
|
+
|
1764
|
+
@method all
|
1765
|
+
@static
|
1766
|
+
@param {Array} entries array of promises
|
1767
|
+
@param {String} label optional string for labeling the promise.
|
1768
|
+
Useful for tooling.
|
1769
|
+
@return {Promise} promise that is fulfilled when all `promises` have been
|
1770
|
+
fulfilled, or rejected if any of them become rejected.
|
1771
|
+
@static
|
1772
|
+
*/
|
1773
|
+
function all$1(entries) {
|
1774
|
+
return new Enumerator$1(this, entries).promise;
|
1775
|
+
}
|
1776
|
+
|
1777
|
+
/**
|
1778
|
+
`Promise.race` returns a new promise which is settled in the same way as the
|
1779
|
+
first passed promise to settle.
|
1780
|
+
|
1781
|
+
Example:
|
1782
|
+
|
1783
|
+
```javascript
|
1784
|
+
let promise1 = new Promise(function(resolve, reject){
|
1785
|
+
setTimeout(function(){
|
1786
|
+
resolve('promise 1');
|
1787
|
+
}, 200);
|
1788
|
+
});
|
1789
|
+
|
1790
|
+
let promise2 = new Promise(function(resolve, reject){
|
1791
|
+
setTimeout(function(){
|
1792
|
+
resolve('promise 2');
|
1793
|
+
}, 100);
|
1794
|
+
});
|
1795
|
+
|
1796
|
+
Promise.race([promise1, promise2]).then(function(result){
|
1797
|
+
// result === 'promise 2' because it was resolved before promise1
|
1798
|
+
// was resolved.
|
1799
|
+
});
|
1800
|
+
```
|
1801
|
+
|
1802
|
+
`Promise.race` is deterministic in that only the state of the first
|
1803
|
+
settled promise matters. For example, even if other promises given to the
|
1804
|
+
`promises` array argument are resolved, but the first settled promise has
|
1805
|
+
become rejected before the other promises became fulfilled, the returned
|
1806
|
+
promise will become rejected:
|
1807
|
+
|
1808
|
+
```javascript
|
1809
|
+
let promise1 = new Promise(function(resolve, reject){
|
1810
|
+
setTimeout(function(){
|
1811
|
+
resolve('promise 1');
|
1812
|
+
}, 200);
|
1813
|
+
});
|
1814
|
+
|
1815
|
+
let promise2 = new Promise(function(resolve, reject){
|
1816
|
+
setTimeout(function(){
|
1817
|
+
reject(new Error('promise 2'));
|
1818
|
+
}, 100);
|
1819
|
+
});
|
1820
|
+
|
1821
|
+
Promise.race([promise1, promise2]).then(function(result){
|
1822
|
+
// Code here never runs
|
1823
|
+
}, function(reason){
|
1824
|
+
// reason.message === 'promise 2' because promise 2 became rejected before
|
1825
|
+
// promise 1 became fulfilled
|
1826
|
+
});
|
1827
|
+
```
|
1828
|
+
|
1829
|
+
An example real-world use case is implementing timeouts:
|
1830
|
+
|
1831
|
+
```javascript
|
1832
|
+
Promise.race([ajax('foo.json'), timeout(5000)])
|
1833
|
+
```
|
1834
|
+
|
1835
|
+
@method race
|
1836
|
+
@static
|
1837
|
+
@param {Array} promises array of promises to observe
|
1838
|
+
Useful for tooling.
|
1839
|
+
@return {Promise} a promise which settles in the same way as the first passed
|
1840
|
+
promise to settle.
|
1841
|
+
*/
|
1842
|
+
function race$1(entries) {
|
1843
|
+
/*jshint validthis:true */
|
1844
|
+
var Constructor = this;
|
1845
|
+
|
1846
|
+
if (!isArray(entries)) {
|
1847
|
+
return new Constructor(function (_, reject) {
|
1848
|
+
return reject(new TypeError('You must pass an array to race.'));
|
1849
|
+
});
|
1850
|
+
} else {
|
1851
|
+
return new Constructor(function (resolve, reject) {
|
1852
|
+
var length = entries.length;
|
1853
|
+
for (var i = 0; i < length; i++) {
|
1854
|
+
Constructor.resolve(entries[i]).then(resolve, reject);
|
1855
|
+
}
|
1856
|
+
});
|
1857
|
+
}
|
1858
|
+
}
|
1859
|
+
|
1860
|
+
/**
|
1861
|
+
`Promise.reject` returns a promise rejected with the passed `reason`.
|
1862
|
+
It is shorthand for the following:
|
1863
|
+
|
1864
|
+
```javascript
|
1865
|
+
let promise = new Promise(function(resolve, reject){
|
1866
|
+
reject(new Error('WHOOPS'));
|
1867
|
+
});
|
1868
|
+
|
1869
|
+
promise.then(function(value){
|
1870
|
+
// Code here doesn't run because the promise is rejected!
|
1871
|
+
}, function(reason){
|
1872
|
+
// reason.message === 'WHOOPS'
|
1873
|
+
});
|
1874
|
+
```
|
1875
|
+
|
1876
|
+
Instead of writing the above, your code now simply becomes the following:
|
1877
|
+
|
1878
|
+
```javascript
|
1879
|
+
let promise = Promise.reject(new Error('WHOOPS'));
|
1880
|
+
|
1881
|
+
promise.then(function(value){
|
1882
|
+
// Code here doesn't run because the promise is rejected!
|
1883
|
+
}, function(reason){
|
1884
|
+
// reason.message === 'WHOOPS'
|
1885
|
+
});
|
1886
|
+
```
|
1887
|
+
|
1888
|
+
@method reject
|
1889
|
+
@static
|
1890
|
+
@param {Any} reason value that the returned promise will be rejected with.
|
1891
|
+
Useful for tooling.
|
1892
|
+
@return {Promise} a promise rejected with the given `reason`.
|
1893
|
+
*/
|
1894
|
+
function reject$1(reason) {
|
1895
|
+
/*jshint validthis:true */
|
1896
|
+
var Constructor = this;
|
1897
|
+
var promise = new Constructor(noop);
|
1898
|
+
reject(promise, reason);
|
1899
|
+
return promise;
|
1900
|
+
}
|
1901
|
+
|
1902
|
+
function needsResolver() {
|
1903
|
+
throw new TypeError('You must pass a resolver function as the first argument to the promise constructor');
|
1904
|
+
}
|
1905
|
+
|
1906
|
+
function needsNew() {
|
1907
|
+
throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.");
|
1908
|
+
}
|
1909
|
+
|
1910
|
+
/**
|
1911
|
+
Promise objects represent the eventual result of an asynchronous operation. The
|
1912
|
+
primary way of interacting with a promise is through its `then` method, which
|
1913
|
+
registers callbacks to receive either a promise's eventual value or the reason
|
1914
|
+
why the promise cannot be fulfilled.
|
1915
|
+
|
1916
|
+
Terminology
|
1917
|
+
-----------
|
1918
|
+
|
1919
|
+
- `promise` is an object or function with a `then` method whose behavior conforms to this specification.
|
1920
|
+
- `thenable` is an object or function that defines a `then` method.
|
1921
|
+
- `value` is any legal JavaScript value (including undefined, a thenable, or a promise).
|
1922
|
+
- `exception` is a value that is thrown using the throw statement.
|
1923
|
+
- `reason` is a value that indicates why a promise was rejected.
|
1924
|
+
- `settled` the final resting state of a promise, fulfilled or rejected.
|
1925
|
+
|
1926
|
+
A promise can be in one of three states: pending, fulfilled, or rejected.
|
1927
|
+
|
1928
|
+
Promises that are fulfilled have a fulfillment value and are in the fulfilled
|
1929
|
+
state. Promises that are rejected have a rejection reason and are in the
|
1930
|
+
rejected state. A fulfillment value is never a thenable.
|
1931
|
+
|
1932
|
+
Promises can also be said to *resolve* a value. If this value is also a
|
1933
|
+
promise, then the original promise's settled state will match the value's
|
1934
|
+
settled state. So a promise that *resolves* a promise that rejects will
|
1935
|
+
itself reject, and a promise that *resolves* a promise that fulfills will
|
1936
|
+
itself fulfill.
|
1937
|
+
|
1938
|
+
|
1939
|
+
Basic Usage:
|
1940
|
+
------------
|
1941
|
+
|
1942
|
+
```js
|
1943
|
+
let promise = new Promise(function(resolve, reject) {
|
1944
|
+
// on success
|
1945
|
+
resolve(value);
|
1946
|
+
|
1947
|
+
// on failure
|
1948
|
+
reject(reason);
|
1949
|
+
});
|
1950
|
+
|
1951
|
+
promise.then(function(value) {
|
1952
|
+
// on fulfillment
|
1953
|
+
}, function(reason) {
|
1954
|
+
// on rejection
|
1955
|
+
});
|
1956
|
+
```
|
1957
|
+
|
1958
|
+
Advanced Usage:
|
1959
|
+
---------------
|
1960
|
+
|
1961
|
+
Promises shine when abstracting away asynchronous interactions such as
|
1962
|
+
`XMLHttpRequest`s.
|
1963
|
+
|
1964
|
+
```js
|
1965
|
+
function getJSON(url) {
|
1966
|
+
return new Promise(function(resolve, reject){
|
1967
|
+
let xhr = new XMLHttpRequest();
|
1968
|
+
|
1969
|
+
xhr.open('GET', url);
|
1970
|
+
xhr.onreadystatechange = handler;
|
1971
|
+
xhr.responseType = 'json';
|
1972
|
+
xhr.setRequestHeader('Accept', 'application/json');
|
1973
|
+
xhr.send();
|
1974
|
+
|
1975
|
+
function handler() {
|
1976
|
+
if (this.readyState === this.DONE) {
|
1977
|
+
if (this.status === 200) {
|
1978
|
+
resolve(this.response);
|
1979
|
+
} else {
|
1980
|
+
reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']'));
|
1981
|
+
}
|
1982
|
+
}
|
1983
|
+
};
|
1984
|
+
});
|
1985
|
+
}
|
1986
|
+
|
1987
|
+
getJSON('/posts.json').then(function(json) {
|
1988
|
+
// on fulfillment
|
1989
|
+
}, function(reason) {
|
1990
|
+
// on rejection
|
1991
|
+
});
|
1992
|
+
```
|
1993
|
+
|
1994
|
+
Unlike callbacks, promises are great composable primitives.
|
1995
|
+
|
1996
|
+
```js
|
1997
|
+
Promise.all([
|
1998
|
+
getJSON('/posts'),
|
1999
|
+
getJSON('/comments')
|
2000
|
+
]).then(function(values){
|
2001
|
+
values[0] // => postsJSON
|
2002
|
+
values[1] // => commentsJSON
|
2003
|
+
|
2004
|
+
return values;
|
2005
|
+
});
|
2006
|
+
```
|
2007
|
+
|
2008
|
+
@class Promise
|
2009
|
+
@param {function} resolver
|
2010
|
+
Useful for tooling.
|
2011
|
+
@constructor
|
2012
|
+
*/
|
2013
|
+
function Promise$2(resolver) {
|
2014
|
+
this[PROMISE_ID] = nextId();
|
2015
|
+
this._result = this._state = undefined;
|
2016
|
+
this._subscribers = [];
|
2017
|
+
|
2018
|
+
if (noop !== resolver) {
|
2019
|
+
typeof resolver !== 'function' && needsResolver();
|
2020
|
+
this instanceof Promise$2 ? initializePromise(this, resolver) : needsNew();
|
2021
|
+
}
|
2022
|
+
}
|
2023
|
+
|
2024
|
+
Promise$2.all = all$1;
|
2025
|
+
Promise$2.race = race$1;
|
2026
|
+
Promise$2.resolve = resolve$1;
|
2027
|
+
Promise$2.reject = reject$1;
|
2028
|
+
Promise$2._setScheduler = setScheduler;
|
2029
|
+
Promise$2._setAsap = setAsap;
|
2030
|
+
Promise$2._asap = asap;
|
2031
|
+
|
2032
|
+
Promise$2.prototype = {
|
2033
|
+
constructor: Promise$2,
|
2034
|
+
|
2035
|
+
/**
|
2036
|
+
The primary way of interacting with a promise is through its `then` method,
|
2037
|
+
which registers callbacks to receive either a promise's eventual value or the
|
2038
|
+
reason why the promise cannot be fulfilled.
|
2039
|
+
|
2040
|
+
```js
|
2041
|
+
findUser().then(function(user){
|
2042
|
+
// user is available
|
2043
|
+
}, function(reason){
|
2044
|
+
// user is unavailable, and you are given the reason why
|
2045
|
+
});
|
2046
|
+
```
|
2047
|
+
|
2048
|
+
Chaining
|
2049
|
+
--------
|
2050
|
+
|
2051
|
+
The return value of `then` is itself a promise. This second, 'downstream'
|
2052
|
+
promise is resolved with the return value of the first promise's fulfillment
|
2053
|
+
or rejection handler, or rejected if the handler throws an exception.
|
2054
|
+
|
2055
|
+
```js
|
2056
|
+
findUser().then(function (user) {
|
2057
|
+
return user.name;
|
2058
|
+
}, function (reason) {
|
2059
|
+
return 'default name';
|
2060
|
+
}).then(function (userName) {
|
2061
|
+
// If `findUser` fulfilled, `userName` will be the user's name, otherwise it
|
2062
|
+
// will be `'default name'`
|
2063
|
+
});
|
2064
|
+
|
2065
|
+
findUser().then(function (user) {
|
2066
|
+
throw new Error('Found user, but still unhappy');
|
2067
|
+
}, function (reason) {
|
2068
|
+
throw new Error('`findUser` rejected and we're unhappy');
|
2069
|
+
}).then(function (value) {
|
2070
|
+
// never reached
|
2071
|
+
}, function (reason) {
|
2072
|
+
// if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'.
|
2073
|
+
// If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'.
|
2074
|
+
});
|
2075
|
+
```
|
2076
|
+
If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream.
|
2077
|
+
|
2078
|
+
```js
|
2079
|
+
findUser().then(function (user) {
|
2080
|
+
throw new PedagogicalException('Upstream error');
|
2081
|
+
}).then(function (value) {
|
2082
|
+
// never reached
|
2083
|
+
}).then(function (value) {
|
2084
|
+
// never reached
|
2085
|
+
}, function (reason) {
|
2086
|
+
// The `PedgagocialException` is propagated all the way down to here
|
2087
|
+
});
|
2088
|
+
```
|
2089
|
+
|
2090
|
+
Assimilation
|
2091
|
+
------------
|
2092
|
+
|
2093
|
+
Sometimes the value you want to propagate to a downstream promise can only be
|
2094
|
+
retrieved asynchronously. This can be achieved by returning a promise in the
|
2095
|
+
fulfillment or rejection handler. The downstream promise will then be pending
|
2096
|
+
until the returned promise is settled. This is called *assimilation*.
|
2097
|
+
|
2098
|
+
```js
|
2099
|
+
findUser().then(function (user) {
|
2100
|
+
return findCommentsByAuthor(user);
|
2101
|
+
}).then(function (comments) {
|
2102
|
+
// The user's comments are now available
|
2103
|
+
});
|
2104
|
+
```
|
2105
|
+
|
2106
|
+
If the assimliated promise rejects, then the downstream promise will also reject.
|
2107
|
+
|
2108
|
+
```js
|
2109
|
+
findUser().then(function (user) {
|
2110
|
+
return findCommentsByAuthor(user);
|
2111
|
+
}).then(function (comments) {
|
2112
|
+
// If `findCommentsByAuthor` fulfills, we'll have the value here
|
2113
|
+
}, function (reason) {
|
2114
|
+
// If `findCommentsByAuthor` rejects, we'll have the reason here
|
2115
|
+
});
|
2116
|
+
```
|
2117
|
+
|
2118
|
+
Simple Example
|
2119
|
+
--------------
|
2120
|
+
|
2121
|
+
Synchronous Example
|
2122
|
+
|
2123
|
+
```javascript
|
2124
|
+
let result;
|
2125
|
+
|
2126
|
+
try {
|
2127
|
+
result = findResult();
|
2128
|
+
// success
|
2129
|
+
} catch(reason) {
|
2130
|
+
// failure
|
2131
|
+
}
|
2132
|
+
```
|
2133
|
+
|
2134
|
+
Errback Example
|
2135
|
+
|
2136
|
+
```js
|
2137
|
+
findResult(function(result, err){
|
2138
|
+
if (err) {
|
2139
|
+
// failure
|
2140
|
+
} else {
|
2141
|
+
// success
|
2142
|
+
}
|
2143
|
+
});
|
2144
|
+
```
|
2145
|
+
|
2146
|
+
Promise Example;
|
2147
|
+
|
2148
|
+
```javascript
|
2149
|
+
findResult().then(function(result){
|
2150
|
+
// success
|
2151
|
+
}, function(reason){
|
2152
|
+
// failure
|
2153
|
+
});
|
2154
|
+
```
|
2155
|
+
|
2156
|
+
Advanced Example
|
2157
|
+
--------------
|
2158
|
+
|
2159
|
+
Synchronous Example
|
2160
|
+
|
2161
|
+
```javascript
|
2162
|
+
let author, books;
|
2163
|
+
|
2164
|
+
try {
|
2165
|
+
author = findAuthor();
|
2166
|
+
books = findBooksByAuthor(author);
|
2167
|
+
// success
|
2168
|
+
} catch(reason) {
|
2169
|
+
// failure
|
2170
|
+
}
|
2171
|
+
```
|
2172
|
+
|
2173
|
+
Errback Example
|
2174
|
+
|
2175
|
+
```js
|
2176
|
+
|
2177
|
+
function foundBooks(books) {
|
2178
|
+
|
2179
|
+
}
|
2180
|
+
|
2181
|
+
function failure(reason) {
|
2182
|
+
|
2183
|
+
}
|
2184
|
+
|
2185
|
+
findAuthor(function(author, err){
|
2186
|
+
if (err) {
|
2187
|
+
failure(err);
|
2188
|
+
// failure
|
2189
|
+
} else {
|
2190
|
+
try {
|
2191
|
+
findBoooksByAuthor(author, function(books, err) {
|
2192
|
+
if (err) {
|
2193
|
+
failure(err);
|
2194
|
+
} else {
|
2195
|
+
try {
|
2196
|
+
foundBooks(books);
|
2197
|
+
} catch(reason) {
|
2198
|
+
failure(reason);
|
2199
|
+
}
|
2200
|
+
}
|
2201
|
+
});
|
2202
|
+
} catch(error) {
|
2203
|
+
failure(err);
|
2204
|
+
}
|
2205
|
+
// success
|
2206
|
+
}
|
2207
|
+
});
|
2208
|
+
```
|
2209
|
+
|
2210
|
+
Promise Example;
|
2211
|
+
|
2212
|
+
```javascript
|
2213
|
+
findAuthor().
|
2214
|
+
then(findBooksByAuthor).
|
2215
|
+
then(function(books){
|
2216
|
+
// found books
|
2217
|
+
}).catch(function(reason){
|
2218
|
+
// something went wrong
|
2219
|
+
});
|
2220
|
+
```
|
2221
|
+
|
2222
|
+
@method then
|
2223
|
+
@param {Function} onFulfilled
|
2224
|
+
@param {Function} onRejected
|
2225
|
+
Useful for tooling.
|
2226
|
+
@return {Promise}
|
2227
|
+
*/
|
2228
|
+
then: then,
|
2229
|
+
|
2230
|
+
/**
|
2231
|
+
`catch` is simply sugar for `then(undefined, onRejection)` which makes it the same
|
2232
|
+
as the catch block of a try/catch statement.
|
2233
|
+
|
2234
|
+
```js
|
2235
|
+
function findAuthor(){
|
2236
|
+
throw new Error('couldn't find that author');
|
2237
|
+
}
|
2238
|
+
|
2239
|
+
// synchronous
|
2240
|
+
try {
|
2241
|
+
findAuthor();
|
2242
|
+
} catch(reason) {
|
2243
|
+
// something went wrong
|
2244
|
+
}
|
2245
|
+
|
2246
|
+
// async with promises
|
2247
|
+
findAuthor().catch(function(reason){
|
2248
|
+
// something went wrong
|
2249
|
+
});
|
2250
|
+
```
|
2251
|
+
|
2252
|
+
@method catch
|
2253
|
+
@param {Function} onRejection
|
2254
|
+
Useful for tooling.
|
2255
|
+
@return {Promise}
|
2256
|
+
*/
|
2257
|
+
'catch': function _catch(onRejection) {
|
2258
|
+
return this.then(null, onRejection);
|
2259
|
+
}
|
2260
|
+
};
|
2261
|
+
|
2262
|
+
/*global self*/
|
2263
|
+
function polyfill$1() {
|
2264
|
+
var local = undefined;
|
2265
|
+
|
2266
|
+
if (typeof global !== 'undefined') {
|
2267
|
+
local = global;
|
2268
|
+
} else if (typeof self !== 'undefined') {
|
2269
|
+
local = self;
|
2270
|
+
} else {
|
2271
|
+
try {
|
2272
|
+
local = Function('return this')();
|
2273
|
+
} catch (e) {
|
2274
|
+
throw new Error('polyfill failed because global object is unavailable in this environment');
|
2275
|
+
}
|
2276
|
+
}
|
2277
|
+
|
2278
|
+
var P = local.Promise;
|
2279
|
+
|
2280
|
+
if (P) {
|
2281
|
+
var promiseToString = null;
|
2282
|
+
try {
|
2283
|
+
promiseToString = Object.prototype.toString.call(P.resolve());
|
2284
|
+
} catch (e) {
|
2285
|
+
// silently ignored
|
2286
|
+
}
|
2287
|
+
|
2288
|
+
if (promiseToString === '[object Promise]' && !P.cast) {
|
2289
|
+
return;
|
2290
|
+
}
|
2291
|
+
}
|
2292
|
+
|
2293
|
+
local.Promise = Promise$2;
|
2294
|
+
}
|
2295
|
+
|
2296
|
+
// Strange compat..
|
2297
|
+
Promise$2.polyfill = polyfill$1;
|
2298
|
+
Promise$2.Promise = Promise$2;
|
2299
|
+
|
2300
|
+
return Promise$2;
|
2301
|
+
|
2302
|
+
})));
|
2303
|
+
|
2304
|
+
//# sourceMappingURL=es6-promise.map
|
2305
|
+
|
2306
|
+
/* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(7), __webpack_require__(8)))
|
2307
|
+
|
2308
|
+
/***/ }),
|
2309
|
+
/* 5 */
|
2310
|
+
/***/ (function(module, exports) {
|
2311
|
+
|
2312
|
+
// removed by extract-text-webpack-plugin
|
2313
|
+
|
2314
|
+
/***/ }),
|
2315
|
+
/* 6 */
|
2316
|
+
/***/ (function(module, exports, __webpack_require__) {
|
2317
|
+
|
2318
|
+
"use strict";
|
2319
|
+
|
2320
|
+
|
2321
|
+
Object.defineProperty(exports, "__esModule", {
|
2322
|
+
value: true
|
2323
|
+
});
|
2324
|
+
|
2325
|
+
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); /* global VERSION */
|
2326
|
+
|
2327
|
+
__webpack_require__(5);
|
2328
|
+
|
2329
|
+
var _es6Promise = __webpack_require__(4);
|
2330
|
+
|
2331
|
+
var _es6Promise2 = _interopRequireDefault(_es6Promise);
|
2332
|
+
|
2333
|
+
var _utils = __webpack_require__(0);
|
2334
|
+
|
2335
|
+
var Utils = _interopRequireWildcard(_utils);
|
2336
|
+
|
2337
|
+
var _api = __webpack_require__(1);
|
2338
|
+
|
2339
|
+
var API = _interopRequireWildcard(_api);
|
2340
|
+
|
2341
|
+
var _button = __webpack_require__(2);
|
2342
|
+
|
2343
|
+
var _push = __webpack_require__(3);
|
2344
|
+
|
2345
|
+
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } }
|
2346
|
+
|
2347
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
2348
|
+
|
2349
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
2350
|
+
|
2351
|
+
var Noty = function () {
|
2352
|
+
/**
|
2353
|
+
* @param {object} options
|
2354
|
+
* @return {Noty}
|
2355
|
+
*/
|
2356
|
+
function Noty() {
|
2357
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
2358
|
+
|
2359
|
+
_classCallCheck(this, Noty);
|
2360
|
+
|
2361
|
+
this.options = Utils.deepExtend({}, API.Defaults, options);
|
2362
|
+
this.id = this.options.id || Utils.generateID('bar');
|
2363
|
+
this.closeTimer = -1;
|
2364
|
+
this.barDom = null;
|
2365
|
+
this.layoutDom = null;
|
2366
|
+
this.progressDom = null;
|
2367
|
+
this.showing = false;
|
2368
|
+
this.shown = false;
|
2369
|
+
this.closed = false;
|
2370
|
+
this.closing = false;
|
2371
|
+
this.killable = this.options.timeout || this.options.closeWith.length > 0;
|
2372
|
+
this.hasSound = this.options.sounds.sources.length > 0;
|
2373
|
+
this.soundPlayed = false;
|
2374
|
+
this.listeners = {
|
2375
|
+
beforeShow: [],
|
2376
|
+
onShow: [],
|
2377
|
+
afterShow: [],
|
2378
|
+
onClose: [],
|
2379
|
+
afterClose: [],
|
2380
|
+
onClick: [],
|
2381
|
+
onHover: [],
|
2382
|
+
onTemplate: []
|
2383
|
+
};
|
2384
|
+
this.promises = {
|
2385
|
+
show: null,
|
2386
|
+
close: null
|
2387
|
+
};
|
2388
|
+
this.on('beforeShow', this.options.callbacks.beforeShow);
|
2389
|
+
this.on('onShow', this.options.callbacks.onShow);
|
2390
|
+
this.on('afterShow', this.options.callbacks.afterShow);
|
2391
|
+
this.on('onClose', this.options.callbacks.onClose);
|
2392
|
+
this.on('afterClose', this.options.callbacks.afterClose);
|
2393
|
+
this.on('onClick', this.options.callbacks.onClick);
|
2394
|
+
this.on('onHover', this.options.callbacks.onHover);
|
2395
|
+
this.on('onTemplate', this.options.callbacks.onTemplate);
|
2396
|
+
|
2397
|
+
return this;
|
2398
|
+
}
|
2399
|
+
|
2400
|
+
/**
|
2401
|
+
* @param {string} eventName
|
2402
|
+
* @param {function} cb
|
2403
|
+
* @return {Noty}
|
2404
|
+
*/
|
2405
|
+
|
2406
|
+
|
2407
|
+
_createClass(Noty, [{
|
2408
|
+
key: 'on',
|
2409
|
+
value: function on(eventName) {
|
2410
|
+
var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
|
2411
|
+
|
2412
|
+
if (typeof cb === 'function' && this.listeners.hasOwnProperty(eventName)) {
|
2413
|
+
this.listeners[eventName].push(cb);
|
2414
|
+
}
|
2415
|
+
|
2416
|
+
return this;
|
2417
|
+
}
|
2418
|
+
|
2419
|
+
/**
|
2420
|
+
* @return {Noty}
|
2421
|
+
*/
|
2422
|
+
|
2423
|
+
}, {
|
2424
|
+
key: 'show',
|
2425
|
+
value: function show() {
|
2426
|
+
var _this = this;
|
2427
|
+
|
2428
|
+
if (this.options.killer === true) {
|
2429
|
+
Noty.closeAll();
|
2430
|
+
} else if (typeof this.options.killer === 'string') {
|
2431
|
+
Noty.closeAll(this.options.killer);
|
2432
|
+
}
|
2433
|
+
|
2434
|
+
var queueCounts = API.getQueueCounts(this.options.queue);
|
2435
|
+
|
2436
|
+
if (queueCounts.current >= queueCounts.maxVisible || API.PageHidden && this.options.visibilityControl) {
|
2437
|
+
API.addToQueue(this);
|
2438
|
+
|
2439
|
+
if (API.PageHidden && this.hasSound && Utils.inArray('docHidden', this.options.sounds.conditions)) {
|
2440
|
+
Utils.createAudioElements(this);
|
2441
|
+
}
|
2442
|
+
|
2443
|
+
if (API.PageHidden && Utils.inArray('docHidden', this.options.titleCount.conditions)) {
|
2444
|
+
API.docTitle.increment();
|
2445
|
+
}
|
2446
|
+
|
2447
|
+
return this;
|
2448
|
+
}
|
2449
|
+
|
2450
|
+
API.Store[this.id] = this;
|
2451
|
+
|
2452
|
+
API.fire(this, 'beforeShow');
|
2453
|
+
|
2454
|
+
this.showing = true;
|
2455
|
+
|
2456
|
+
if (this.closing) {
|
2457
|
+
this.showing = false;
|
2458
|
+
return this;
|
2459
|
+
}
|
2460
|
+
|
2461
|
+
API.build(this);
|
2462
|
+
API.handleModal(this);
|
2463
|
+
|
2464
|
+
if (this.options.force) {
|
2465
|
+
this.layoutDom.insertBefore(this.barDom, this.layoutDom.firstChild);
|
2466
|
+
} else {
|
2467
|
+
this.layoutDom.appendChild(this.barDom);
|
2468
|
+
}
|
2469
|
+
|
2470
|
+
if (this.hasSound && !this.soundPlayed && Utils.inArray('docVisible', this.options.sounds.conditions)) {
|
2471
|
+
Utils.createAudioElements(this);
|
2472
|
+
}
|
2473
|
+
|
2474
|
+
if (Utils.inArray('docVisible', this.options.titleCount.conditions)) {
|
2475
|
+
API.docTitle.increment();
|
2476
|
+
}
|
2477
|
+
|
2478
|
+
this.shown = true;
|
2479
|
+
this.closed = false;
|
2480
|
+
|
2481
|
+
// bind button events if any
|
2482
|
+
if (API.hasButtons(this)) {
|
2483
|
+
Object.keys(this.options.buttons).forEach(function (key) {
|
2484
|
+
var btn = _this.barDom.querySelector('#' + _this.options.buttons[key].id);
|
2485
|
+
Utils.addListener(btn, 'click', function (e) {
|
2486
|
+
Utils.stopPropagation(e);
|
2487
|
+
_this.options.buttons[key].cb();
|
2488
|
+
});
|
2489
|
+
});
|
2490
|
+
}
|
2491
|
+
|
2492
|
+
this.progressDom = this.barDom.querySelector('.noty_progressbar');
|
2493
|
+
|
2494
|
+
if (Utils.inArray('click', this.options.closeWith)) {
|
2495
|
+
Utils.addClass(this.barDom, 'noty_close_with_click');
|
2496
|
+
Utils.addListener(this.barDom, 'click', function (e) {
|
2497
|
+
Utils.stopPropagation(e);
|
2498
|
+
API.fire(_this, 'onClick');
|
2499
|
+
_this.close();
|
2500
|
+
}, false);
|
2501
|
+
}
|
2502
|
+
|
2503
|
+
Utils.addListener(this.barDom, 'mouseenter', function () {
|
2504
|
+
API.fire(_this, 'onHover');
|
2505
|
+
}, false);
|
2506
|
+
|
2507
|
+
if (this.options.timeout) Utils.addClass(this.barDom, 'noty_has_timeout');
|
2508
|
+
if (this.options.progressBar) {
|
2509
|
+
Utils.addClass(this.barDom, 'noty_has_progressbar');
|
2510
|
+
}
|
2511
|
+
|
2512
|
+
if (Utils.inArray('button', this.options.closeWith)) {
|
2513
|
+
Utils.addClass(this.barDom, 'noty_close_with_button');
|
2514
|
+
|
2515
|
+
var closeButton = document.createElement('div');
|
2516
|
+
Utils.addClass(closeButton, 'noty_close_button');
|
2517
|
+
closeButton.innerHTML = '×';
|
2518
|
+
this.barDom.appendChild(closeButton);
|
2519
|
+
|
2520
|
+
Utils.addListener(closeButton, 'click', function (e) {
|
2521
|
+
Utils.stopPropagation(e);
|
2522
|
+
_this.close();
|
2523
|
+
}, false);
|
2524
|
+
}
|
2525
|
+
|
2526
|
+
API.fire(this, 'onShow');
|
2527
|
+
|
2528
|
+
if (this.options.animation.open === null) {
|
2529
|
+
this.promises.show = new _es6Promise2.default(function (resolve) {
|
2530
|
+
resolve();
|
2531
|
+
});
|
2532
|
+
} else if (typeof this.options.animation.open === 'function') {
|
2533
|
+
this.promises.show = new _es6Promise2.default(this.options.animation.open.bind(this));
|
2534
|
+
} else {
|
2535
|
+
Utils.addClass(this.barDom, this.options.animation.open);
|
2536
|
+
this.promises.show = new _es6Promise2.default(function (resolve) {
|
2537
|
+
Utils.addListener(_this.barDom, Utils.animationEndEvents, function () {
|
2538
|
+
Utils.removeClass(_this.barDom, _this.options.animation.open);
|
2539
|
+
resolve();
|
2540
|
+
});
|
2541
|
+
});
|
2542
|
+
}
|
2543
|
+
|
2544
|
+
this.promises.show.then(function () {
|
2545
|
+
var _t = _this;
|
2546
|
+
setTimeout(function () {
|
2547
|
+
API.openFlow(_t);
|
2548
|
+
}, 100);
|
2549
|
+
});
|
2550
|
+
|
2551
|
+
return this;
|
2552
|
+
}
|
2553
|
+
|
2554
|
+
/**
|
2555
|
+
* @return {Noty}
|
2556
|
+
*/
|
2557
|
+
|
2558
|
+
}, {
|
2559
|
+
key: 'stop',
|
2560
|
+
value: function stop() {
|
2561
|
+
API.dequeueClose(this);
|
2562
|
+
return this;
|
2563
|
+
}
|
2564
|
+
|
2565
|
+
/**
|
2566
|
+
* @return {Noty}
|
2567
|
+
*/
|
2568
|
+
|
2569
|
+
}, {
|
2570
|
+
key: 'resume',
|
2571
|
+
value: function resume() {
|
2572
|
+
API.queueClose(this);
|
2573
|
+
return this;
|
2574
|
+
}
|
2575
|
+
|
2576
|
+
/**
|
2577
|
+
* @param {int|boolean} ms
|
2578
|
+
* @return {Noty}
|
2579
|
+
*/
|
2580
|
+
|
2581
|
+
}, {
|
2582
|
+
key: 'setTimeout',
|
2583
|
+
value: function (_setTimeout) {
|
2584
|
+
function setTimeout(_x) {
|
2585
|
+
return _setTimeout.apply(this, arguments);
|
2586
|
+
}
|
2587
|
+
|
2588
|
+
setTimeout.toString = function () {
|
2589
|
+
return _setTimeout.toString();
|
2590
|
+
};
|
2591
|
+
|
2592
|
+
return setTimeout;
|
2593
|
+
}(function (ms) {
|
2594
|
+
this.stop();
|
2595
|
+
this.options.timeout = ms;
|
2596
|
+
|
2597
|
+
if (this.barDom) {
|
2598
|
+
if (this.options.timeout) {
|
2599
|
+
Utils.addClass(this.barDom, 'noty_has_timeout');
|
2600
|
+
} else {
|
2601
|
+
Utils.removeClass(this.barDom, 'noty_has_timeout');
|
2602
|
+
}
|
2603
|
+
|
2604
|
+
var _t = this;
|
2605
|
+
setTimeout(function () {
|
2606
|
+
// ugly fix for progressbar display bug
|
2607
|
+
_t.resume();
|
2608
|
+
}, 100);
|
2609
|
+
}
|
2610
|
+
|
2611
|
+
return this;
|
2612
|
+
})
|
2613
|
+
|
2614
|
+
/**
|
2615
|
+
* @param {string} html
|
2616
|
+
* @param {boolean} optionsOverride
|
2617
|
+
* @return {Noty}
|
2618
|
+
*/
|
2619
|
+
|
2620
|
+
}, {
|
2621
|
+
key: 'setText',
|
2622
|
+
value: function setText(html) {
|
2623
|
+
var optionsOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2624
|
+
|
2625
|
+
if (this.barDom) {
|
2626
|
+
this.barDom.querySelector('.noty_body').innerHTML = html;
|
2627
|
+
}
|
2628
|
+
|
2629
|
+
if (optionsOverride) this.options.text = html;
|
2630
|
+
|
2631
|
+
return this;
|
2632
|
+
}
|
2633
|
+
|
2634
|
+
/**
|
2635
|
+
* @param {string} type
|
2636
|
+
* @param {boolean} optionsOverride
|
2637
|
+
* @return {Noty}
|
2638
|
+
*/
|
2639
|
+
|
2640
|
+
}, {
|
2641
|
+
key: 'setType',
|
2642
|
+
value: function setType(type) {
|
2643
|
+
var _this2 = this;
|
2644
|
+
|
2645
|
+
var optionsOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2646
|
+
|
2647
|
+
if (this.barDom) {
|
2648
|
+
var classList = Utils.classList(this.barDom).split(' ');
|
2649
|
+
|
2650
|
+
classList.forEach(function (c) {
|
2651
|
+
if (c.substring(0, 11) === 'noty_type__') {
|
2652
|
+
Utils.removeClass(_this2.barDom, c);
|
2653
|
+
}
|
2654
|
+
});
|
2655
|
+
|
2656
|
+
Utils.addClass(this.barDom, 'noty_type__' + type);
|
2657
|
+
}
|
2658
|
+
|
2659
|
+
if (optionsOverride) this.options.type = type;
|
2660
|
+
|
2661
|
+
return this;
|
2662
|
+
}
|
2663
|
+
|
2664
|
+
/**
|
2665
|
+
* @param {string} theme
|
2666
|
+
* @param {boolean} optionsOverride
|
2667
|
+
* @return {Noty}
|
2668
|
+
*/
|
2669
|
+
|
2670
|
+
}, {
|
2671
|
+
key: 'setTheme',
|
2672
|
+
value: function setTheme(theme) {
|
2673
|
+
var _this3 = this;
|
2674
|
+
|
2675
|
+
var optionsOverride = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
2676
|
+
|
2677
|
+
if (this.barDom) {
|
2678
|
+
var classList = Utils.classList(this.barDom).split(' ');
|
2679
|
+
|
2680
|
+
classList.forEach(function (c) {
|
2681
|
+
if (c.substring(0, 12) === 'noty_theme__') {
|
2682
|
+
Utils.removeClass(_this3.barDom, c);
|
2683
|
+
}
|
2684
|
+
});
|
2685
|
+
|
2686
|
+
Utils.addClass(this.barDom, 'noty_theme__' + theme);
|
2687
|
+
}
|
2688
|
+
|
2689
|
+
if (optionsOverride) this.options.theme = theme;
|
2690
|
+
|
2691
|
+
return this;
|
2692
|
+
}
|
2693
|
+
|
2694
|
+
/**
|
2695
|
+
* @return {Noty}
|
2696
|
+
*/
|
2697
|
+
|
2698
|
+
}, {
|
2699
|
+
key: 'close',
|
2700
|
+
value: function close() {
|
2701
|
+
var _this4 = this;
|
2702
|
+
|
2703
|
+
if (this.closed) return this;
|
2704
|
+
|
2705
|
+
if (!this.shown) {
|
2706
|
+
// it's in the queue
|
2707
|
+
API.removeFromQueue(this);
|
2708
|
+
return this;
|
2709
|
+
}
|
2710
|
+
|
2711
|
+
API.fire(this, 'onClose');
|
2712
|
+
|
2713
|
+
this.closing = true;
|
2714
|
+
|
2715
|
+
if (this.options.animation.close === null) {
|
2716
|
+
this.promises.close = new _es6Promise2.default(function (resolve) {
|
2717
|
+
resolve();
|
2718
|
+
});
|
2719
|
+
} else if (typeof this.options.animation.close === 'function') {
|
2720
|
+
this.promises.close = new _es6Promise2.default(this.options.animation.close.bind(this));
|
2721
|
+
} else {
|
2722
|
+
Utils.addClass(this.barDom, this.options.animation.close);
|
2723
|
+
this.promises.close = new _es6Promise2.default(function (resolve) {
|
2724
|
+
Utils.addListener(_this4.barDom, Utils.animationEndEvents, function () {
|
2725
|
+
if (_this4.options.force) {
|
2726
|
+
Utils.remove(_this4.barDom);
|
2727
|
+
} else {
|
2728
|
+
API.ghostFix(_this4);
|
2729
|
+
}
|
2730
|
+
resolve();
|
2731
|
+
});
|
2732
|
+
});
|
2733
|
+
}
|
2734
|
+
|
2735
|
+
this.promises.close.then(function () {
|
2736
|
+
API.closeFlow(_this4);
|
2737
|
+
API.handleModalClose(_this4);
|
2738
|
+
});
|
2739
|
+
|
2740
|
+
this.closed = true;
|
2741
|
+
|
2742
|
+
return this;
|
2743
|
+
}
|
2744
|
+
|
2745
|
+
// API functions
|
2746
|
+
|
2747
|
+
/**
|
2748
|
+
* @param {boolean|string} queueName
|
2749
|
+
* @return {Noty}
|
2750
|
+
*/
|
2751
|
+
|
2752
|
+
}], [{
|
2753
|
+
key: 'closeAll',
|
2754
|
+
value: function closeAll() {
|
2755
|
+
var queueName = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
|
2756
|
+
|
2757
|
+
Object.keys(API.Store).forEach(function (id) {
|
2758
|
+
if (queueName) {
|
2759
|
+
if (API.Store[id].options.queue === queueName && API.Store[id].killable) {
|
2760
|
+
API.Store[id].close();
|
2761
|
+
}
|
2762
|
+
} else if (API.Store[id].killable) {
|
2763
|
+
API.Store[id].close();
|
2764
|
+
}
|
2765
|
+
});
|
2766
|
+
return this;
|
2767
|
+
}
|
2768
|
+
|
2769
|
+
/**
|
2770
|
+
* @param {Object} obj
|
2771
|
+
* @return {Noty}
|
2772
|
+
*/
|
2773
|
+
|
2774
|
+
}, {
|
2775
|
+
key: 'overrideDefaults',
|
2776
|
+
value: function overrideDefaults(obj) {
|
2777
|
+
API.Defaults = Utils.deepExtend({}, API.Defaults, obj);
|
2778
|
+
return this;
|
2779
|
+
}
|
2780
|
+
|
2781
|
+
/**
|
2782
|
+
* @param {int} amount
|
2783
|
+
* @param {string} queueName
|
2784
|
+
* @return {Noty}
|
2785
|
+
*/
|
2786
|
+
|
2787
|
+
}, {
|
2788
|
+
key: 'setMaxVisible',
|
2789
|
+
value: function setMaxVisible() {
|
2790
|
+
var amount = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : API.DefaultMaxVisible;
|
2791
|
+
var queueName = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'global';
|
2792
|
+
|
2793
|
+
if (!API.Queues.hasOwnProperty(queueName)) {
|
2794
|
+
API.Queues[queueName] = { maxVisible: amount, queue: [] };
|
2795
|
+
}
|
2796
|
+
|
2797
|
+
API.Queues[queueName].maxVisible = amount;
|
2798
|
+
return this;
|
2799
|
+
}
|
2800
|
+
|
2801
|
+
/**
|
2802
|
+
* @param {string} innerHtml
|
2803
|
+
* @param {String} classes
|
2804
|
+
* @param {Function} cb
|
2805
|
+
* @param {Object} attributes
|
2806
|
+
* @return {NotyButton}
|
2807
|
+
*/
|
2808
|
+
|
2809
|
+
}, {
|
2810
|
+
key: 'button',
|
2811
|
+
value: function button(innerHtml) {
|
2812
|
+
var classes = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
|
2813
|
+
var cb = arguments[2];
|
2814
|
+
var attributes = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
2815
|
+
|
2816
|
+
return new _button.NotyButton(innerHtml, classes, cb, attributes);
|
2817
|
+
}
|
2818
|
+
|
2819
|
+
/**
|
2820
|
+
* @return {string}
|
2821
|
+
*/
|
2822
|
+
|
2823
|
+
}, {
|
2824
|
+
key: 'version',
|
2825
|
+
value: function version() {
|
2826
|
+
return "3.1.4";
|
2827
|
+
}
|
2828
|
+
|
2829
|
+
/**
|
2830
|
+
* @param {String} workerPath
|
2831
|
+
* @return {Push}
|
2832
|
+
*/
|
2833
|
+
|
2834
|
+
}, {
|
2835
|
+
key: 'Push',
|
2836
|
+
value: function Push(workerPath) {
|
2837
|
+
return new _push.Push(workerPath);
|
2838
|
+
}
|
2839
|
+
}]);
|
2840
|
+
|
2841
|
+
return Noty;
|
2842
|
+
}();
|
2843
|
+
|
2844
|
+
// Document visibility change controller
|
2845
|
+
|
2846
|
+
|
2847
|
+
exports.default = Noty;
|
2848
|
+
Utils.visibilityChangeFlow();
|
2849
|
+
module.exports = exports['default'];
|
2850
|
+
|
2851
|
+
/***/ }),
|
2852
|
+
/* 7 */
|
2853
|
+
/***/ (function(module, exports) {
|
2854
|
+
|
2855
|
+
// shim for using process in browser
|
2856
|
+
var process = module.exports = {};
|
2857
|
+
|
2858
|
+
// cached from whatever global is present so that test runners that stub it
|
2859
|
+
// don't break things. But we need to wrap it in a try catch in case it is
|
2860
|
+
// wrapped in strict mode code which doesn't define any globals. It's inside a
|
2861
|
+
// function because try/catches deoptimize in certain engines.
|
2862
|
+
|
2863
|
+
var cachedSetTimeout;
|
2864
|
+
var cachedClearTimeout;
|
2865
|
+
|
2866
|
+
function defaultSetTimout() {
|
2867
|
+
throw new Error('setTimeout has not been defined');
|
2868
|
+
}
|
2869
|
+
function defaultClearTimeout () {
|
2870
|
+
throw new Error('clearTimeout has not been defined');
|
2871
|
+
}
|
2872
|
+
(function () {
|
2873
|
+
try {
|
2874
|
+
if (typeof setTimeout === 'function') {
|
2875
|
+
cachedSetTimeout = setTimeout;
|
2876
|
+
} else {
|
2877
|
+
cachedSetTimeout = defaultSetTimout;
|
2878
|
+
}
|
2879
|
+
} catch (e) {
|
2880
|
+
cachedSetTimeout = defaultSetTimout;
|
2881
|
+
}
|
2882
|
+
try {
|
2883
|
+
if (typeof clearTimeout === 'function') {
|
2884
|
+
cachedClearTimeout = clearTimeout;
|
2885
|
+
} else {
|
2886
|
+
cachedClearTimeout = defaultClearTimeout;
|
2887
|
+
}
|
2888
|
+
} catch (e) {
|
2889
|
+
cachedClearTimeout = defaultClearTimeout;
|
2890
|
+
}
|
2891
|
+
} ())
|
2892
|
+
function runTimeout(fun) {
|
2893
|
+
if (cachedSetTimeout === setTimeout) {
|
2894
|
+
//normal enviroments in sane situations
|
2895
|
+
return setTimeout(fun, 0);
|
2896
|
+
}
|
2897
|
+
// if setTimeout wasn't available but was latter defined
|
2898
|
+
if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
|
2899
|
+
cachedSetTimeout = setTimeout;
|
2900
|
+
return setTimeout(fun, 0);
|
2901
|
+
}
|
2902
|
+
try {
|
2903
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
2904
|
+
return cachedSetTimeout(fun, 0);
|
2905
|
+
} catch(e){
|
2906
|
+
try {
|
2907
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
2908
|
+
return cachedSetTimeout.call(null, fun, 0);
|
2909
|
+
} catch(e){
|
2910
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
|
2911
|
+
return cachedSetTimeout.call(this, fun, 0);
|
2912
|
+
}
|
2913
|
+
}
|
2914
|
+
|
2915
|
+
|
2916
|
+
}
|
2917
|
+
function runClearTimeout(marker) {
|
2918
|
+
if (cachedClearTimeout === clearTimeout) {
|
2919
|
+
//normal enviroments in sane situations
|
2920
|
+
return clearTimeout(marker);
|
2921
|
+
}
|
2922
|
+
// if clearTimeout wasn't available but was latter defined
|
2923
|
+
if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
|
2924
|
+
cachedClearTimeout = clearTimeout;
|
2925
|
+
return clearTimeout(marker);
|
2926
|
+
}
|
2927
|
+
try {
|
2928
|
+
// when when somebody has screwed with setTimeout but no I.E. maddness
|
2929
|
+
return cachedClearTimeout(marker);
|
2930
|
+
} catch (e){
|
2931
|
+
try {
|
2932
|
+
// When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
|
2933
|
+
return cachedClearTimeout.call(null, marker);
|
2934
|
+
} catch (e){
|
2935
|
+
// same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
|
2936
|
+
// Some versions of I.E. have different rules for clearTimeout vs setTimeout
|
2937
|
+
return cachedClearTimeout.call(this, marker);
|
2938
|
+
}
|
2939
|
+
}
|
2940
|
+
|
2941
|
+
|
2942
|
+
|
2943
|
+
}
|
2944
|
+
var queue = [];
|
2945
|
+
var draining = false;
|
2946
|
+
var currentQueue;
|
2947
|
+
var queueIndex = -1;
|
2948
|
+
|
2949
|
+
function cleanUpNextTick() {
|
2950
|
+
if (!draining || !currentQueue) {
|
2951
|
+
return;
|
2952
|
+
}
|
2953
|
+
draining = false;
|
2954
|
+
if (currentQueue.length) {
|
2955
|
+
queue = currentQueue.concat(queue);
|
2956
|
+
} else {
|
2957
|
+
queueIndex = -1;
|
2958
|
+
}
|
2959
|
+
if (queue.length) {
|
2960
|
+
drainQueue();
|
2961
|
+
}
|
2962
|
+
}
|
2963
|
+
|
2964
|
+
function drainQueue() {
|
2965
|
+
if (draining) {
|
2966
|
+
return;
|
2967
|
+
}
|
2968
|
+
var timeout = runTimeout(cleanUpNextTick);
|
2969
|
+
draining = true;
|
2970
|
+
|
2971
|
+
var len = queue.length;
|
2972
|
+
while(len) {
|
2973
|
+
currentQueue = queue;
|
2974
|
+
queue = [];
|
2975
|
+
while (++queueIndex < len) {
|
2976
|
+
if (currentQueue) {
|
2977
|
+
currentQueue[queueIndex].run();
|
2978
|
+
}
|
2979
|
+
}
|
2980
|
+
queueIndex = -1;
|
2981
|
+
len = queue.length;
|
2982
|
+
}
|
2983
|
+
currentQueue = null;
|
2984
|
+
draining = false;
|
2985
|
+
runClearTimeout(timeout);
|
2986
|
+
}
|
2987
|
+
|
2988
|
+
process.nextTick = function (fun) {
|
2989
|
+
var args = new Array(arguments.length - 1);
|
2990
|
+
if (arguments.length > 1) {
|
2991
|
+
for (var i = 1; i < arguments.length; i++) {
|
2992
|
+
args[i - 1] = arguments[i];
|
2993
|
+
}
|
2994
|
+
}
|
2995
|
+
queue.push(new Item(fun, args));
|
2996
|
+
if (queue.length === 1 && !draining) {
|
2997
|
+
runTimeout(drainQueue);
|
2998
|
+
}
|
2999
|
+
};
|
3000
|
+
|
3001
|
+
// v8 likes predictible objects
|
3002
|
+
function Item(fun, array) {
|
3003
|
+
this.fun = fun;
|
3004
|
+
this.array = array;
|
3005
|
+
}
|
3006
|
+
Item.prototype.run = function () {
|
3007
|
+
this.fun.apply(null, this.array);
|
3008
|
+
};
|
3009
|
+
process.title = 'browser';
|
3010
|
+
process.browser = true;
|
3011
|
+
process.env = {};
|
3012
|
+
process.argv = [];
|
3013
|
+
process.version = ''; // empty string to avoid regexp issues
|
3014
|
+
process.versions = {};
|
3015
|
+
|
3016
|
+
function noop() {}
|
3017
|
+
|
3018
|
+
process.on = noop;
|
3019
|
+
process.addListener = noop;
|
3020
|
+
process.once = noop;
|
3021
|
+
process.off = noop;
|
3022
|
+
process.removeListener = noop;
|
3023
|
+
process.removeAllListeners = noop;
|
3024
|
+
process.emit = noop;
|
3025
|
+
process.prependListener = noop;
|
3026
|
+
process.prependOnceListener = noop;
|
3027
|
+
|
3028
|
+
process.listeners = function (name) { return [] }
|
3029
|
+
|
3030
|
+
process.binding = function (name) {
|
3031
|
+
throw new Error('process.binding is not supported');
|
3032
|
+
};
|
3033
|
+
|
3034
|
+
process.cwd = function () { return '/' };
|
3035
|
+
process.chdir = function (dir) {
|
3036
|
+
throw new Error('process.chdir is not supported');
|
3037
|
+
};
|
3038
|
+
process.umask = function() { return 0; };
|
3039
|
+
|
3040
|
+
|
3041
|
+
/***/ }),
|
3042
|
+
/* 8 */
|
3043
|
+
/***/ (function(module, exports) {
|
3044
|
+
|
3045
|
+
var g;
|
3046
|
+
|
3047
|
+
// This works in non-strict mode
|
3048
|
+
g = (function() {
|
3049
|
+
return this;
|
3050
|
+
})();
|
3051
|
+
|
3052
|
+
try {
|
3053
|
+
// This works if eval is allowed (see CSP)
|
3054
|
+
g = g || Function("return this")() || (1,eval)("this");
|
3055
|
+
} catch(e) {
|
3056
|
+
// This works if the window reference is available
|
3057
|
+
if(typeof window === "object")
|
3058
|
+
g = window;
|
3059
|
+
}
|
3060
|
+
|
3061
|
+
// g can still be undefined, but nothing to do about it...
|
3062
|
+
// We return undefined, instead of nothing here, so it's
|
3063
|
+
// easier to handle this case. if(!global) { ...}
|
3064
|
+
|
3065
|
+
module.exports = g;
|
3066
|
+
|
3067
|
+
|
3068
|
+
/***/ }),
|
3069
|
+
/* 9 */
|
3070
|
+
/***/ (function(module, exports) {
|
3071
|
+
|
3072
|
+
/* (ignored) */
|
3073
|
+
|
3074
|
+
/***/ })
|
3075
|
+
/******/ ]);
|
3076
|
+
});
|
3077
|
+
//# sourceMappingURL=noty.js.map
|