gorg_slack_chat 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,518 @@
1
+ /*SlackChat*/
2
+ /* v1.5.5 */
3
+ (function( $ ) {
4
+
5
+ var mainOptions = {};
6
+ var userList;
7
+
8
+ window.slackChat = false;
9
+
10
+ var methods = {
11
+ init: function (options) {
12
+ this._defaults = {
13
+ apiToken: '', //#Slack token
14
+ channelId: '', //#Slack channel ID
15
+ user: '', //name of the user
16
+ userLink: '', //link to the user in the application - shown in #Slack
17
+ userImg: '', //image of the user
18
+ userId: '', //id of the user in the application
19
+ defaultSysImg: '', //image to show when the support team replies
20
+ defaultSysUser: '',
21
+ queryInterval: 3000,
22
+ chatBoxHeader: "Need help? Talk to our support team right here",
23
+ slackColor: "#36a64f",
24
+ messageFetchCount: 100,
25
+ botUser: '', //username to post to #Slack
26
+ sendOnEnter: true,
27
+ disableIfAway: false,
28
+ elementToDisable: null,
29
+ heightOffset: 75,
30
+ debug: false,
31
+ defaultUserImg: '',
32
+ webCache: false,
33
+ privateChannel: false,
34
+ privateChannelId: false,
35
+ isOpen: false,
36
+ badgeElement: false,
37
+ serverApiGateway: "/server/php/server.php",
38
+ useUserDetails: false,
39
+ defaultInvitedUsers: [],
40
+ defaultUserImg: '/img/user-icon-small.jpg',
41
+ };
42
+
43
+ this._options = $.extend(true, {}, this._defaults, options);
44
+
45
+ this._options.queryIntElem = null;
46
+ this._options.latest = null;
47
+
48
+ if(this._options.debug) console.log('This object :', this);
49
+
50
+ window.slackChat._options = mainOptions = this._options;
51
+
52
+ //validate the params
53
+ if(this._options.apiToken == '') methods.validationError('Parameter apiToken is required.');
54
+ if(this._options.channelId == '' && !this._options.privateChannel) methods.validationError('Parameter channelId is required.');
55
+ if(this._options.user == '') methods.validationError('Parameter user is required.');
56
+ if(this._options.defaultSysUser == '') methods.validationError('Parameter defaultSysUser is required.');
57
+ if(this._options.botUser == '') methods.validationError('Parameter botUser is required.');
58
+ if(typeof moment == 'undefined') methods.validationError('MomentJS is not available. Get it from http://momentjs.com');
59
+
60
+ //if disabling is set, then first hide the element and show only if users are online
61
+ if(this._options.disableIfAway && this._options.elementToDisable !== null) this._options.elementToDisable.hide();
62
+
63
+ //create the chat box
64
+ var html = '<div class="slackchat slack-chat-box">';
65
+ html += '<div class="slack-chat-header">';
66
+ html += '<button class="close slack-chat-close">&times;</button>';
67
+ html += this._options.chatBoxHeader;
68
+ html += "<div class='presence'><div class='presence-icon'>&#8226;</div><div class='presence-text'></div></div>";
69
+ html += '</div>';
70
+ html += '<div class="slack-message-box">';
71
+ html += '</div>';
72
+ html += '<div class="send-area">';
73
+ html += '<textarea class="form-control slack-new-message" disabled="disabled" type="text" placeholder="Hang tight while we connect..."></textarea>';
74
+ html += '<div class="slack-post-message"><i class="fa fa-fw fa-chevron-right"></i></div>';
75
+ html += '</div>';
76
+ html += '</div>';
77
+
78
+ $('body').append(html);
79
+
80
+ var $this = window.slackChat = this;
81
+
82
+ //register events on the chatbox
83
+ //1. query Slack on open
84
+ $(this).on('click', function () {
85
+
86
+ //reset the badgeElement
87
+ if(window.slackChat._options.badgeElement)
88
+ $(window.slackChat._options.badgeElement).html('').hide();
89
+
90
+ //if the private channel functionality is used, set the isOpen flag to true.
91
+ if(window.slackChat._options.privateChannel) window.slackChat._options.isOpen = true;
92
+ //set the height of the messages box
93
+ $('.slack-chat-box').show();
94
+ $('.slack-chat-box').addClass('open');
95
+ $('.slack-message-box').height($('.slack-chat-box').height() - $('.desc').height() - $('.send-area').height() - parseInt(window.slackChat._options.heightOffset));
96
+
97
+ !function querySlackChannel(){
98
+ if($('.slack-chat-box').hasClass('open') || window.slackChat._options.privateChannel) {
99
+ methods.querySlack($this);
100
+ setTimeout(querySlackChannel, window.slackChat._options.queryInterval);
101
+ }
102
+
103
+ }();
104
+
105
+ $('.slackchat .slack-new-message').focus();
106
+
107
+ if(window.slackChat._options.webCache) {
108
+ //store the values in the webcache
109
+ var scParams = {
110
+ apiToken: window.slackChat._options.apiToken
111
+ ,channelId: window.slackChat._options.channelId
112
+ ,user: window.slackChat._options.user
113
+ ,defaultSysUser: window.slackChat._options.defaultSysUser
114
+ ,botUser: window.slackChat._options.botUser
115
+ ,serverApiGateway: window.slackChat._options.serverApiGateway
116
+ ,defaultInvitedUsers: window.slackChat._options.defaultInvitedUsers
117
+ };
118
+
119
+ localStorage.scParams = JSON.stringify(scParams);
120
+ }
121
+
122
+ });
123
+
124
+ //2. close the chat box
125
+ $('.slackchat .slack-chat-close').on('click', function () {
126
+ $('.slack-chat-box').slideUp();
127
+ $('.slack-chat-box').removeClass('open');
128
+
129
+ //clear the interval if the private channel feature is off
130
+ if(!window.slackChat._options.privateChannel)
131
+ clearInterval(window.slackChat._options.queryIntElem);
132
+ //do not clear the interval if the private Channel feature is on. This allows the user to be shown notifications if there are new replies from the support team.
133
+ else {
134
+ window.slackChat._options.isOpen = false;
135
+ }
136
+ });
137
+
138
+
139
+ //3. post message to slack
140
+ $('.slackchat .slack-post-message').click(function () {
141
+ methods.postMessage(window.slackChat, window.slackChat._options);
142
+ });
143
+
144
+ //4. bind the enter key to the text box
145
+ $('.slackchat .slack-new-message').keyup(function(e) {
146
+ if(window.slackChat._options.sendOnEnter)
147
+ {
148
+ var code = (e.keyCode ? e.keyCode : e.which);
149
+ if(code == 13)
150
+ {
151
+ methods.postMessage(window.slackChat, window.slackChat._options);
152
+ e.preventDefault();
153
+ }
154
+ }
155
+ });
156
+
157
+ //get user online/offline status
158
+ methods.getUserPresence(window.slackChat, window.slackChat._options);
159
+
160
+ $(window).resize(function () {
161
+ methods.resizeWindow();
162
+ });
163
+ },
164
+
165
+ querySlack: function ($elem) {
166
+ options = window.slackChat._options;
167
+
168
+ methods.createChannel($elem, function (channel) {
169
+ window.slackChat._options.channelId = channel.id;
170
+
171
+ $('.slack-new-message').prop('disabled', false).prop('placeholder', 'Write a message...');
172
+
173
+ $.ajax({
174
+ url: 'https://slack.com/api/channels.history'
175
+ ,type: "POST"
176
+ ,dataType: 'json'
177
+ ,data: {
178
+ token: options.apiToken
179
+ ,channel: mainOptions.channelId
180
+ ,oldest: mainOptions.latest
181
+ ,count: options.messageFetchCount
182
+ }
183
+ ,success: function (resp) {
184
+
185
+ if(options.debug && resp.messages && resp.messages.length) console.log(resp.messages);
186
+
187
+ if(resp.ok && resp.messages.length) {
188
+ var html = '';
189
+ window.slackChat._options.latest = resp.messages[0].ts;
190
+ resp.messages = resp.messages.reverse();
191
+
192
+ var repliesExist = 0;
193
+
194
+ for(var i=0; i< resp.messages.length; i++)
195
+ {
196
+
197
+ if(resp.messages[i].subtype == 'bot_message' && resp.messages[i].text !== "") {
198
+
199
+ message = resp.messages[i];
200
+ var userName = '';
201
+ var userImg = '';
202
+ var msgUserId = '';
203
+
204
+ if(message.attachments)
205
+ {
206
+ userName = message.attachments[0].author_name;
207
+ userImg = message.attachments[0].author_icon;
208
+ }
209
+
210
+ if(message.fields)
211
+ msgUserId = message.fields[0].value;
212
+
213
+ var messageText = methods.formatMessage(message.text.trim());
214
+
215
+ //var messageText = methods.checkforLinks(message);
216
+
217
+ html += "<div class='message-item'>";
218
+ if(userImg !== '' && typeof userImg !== 'undefined')
219
+ html += "<div class='userImg'><img src='" + userImg + "' /></div>";
220
+ else if(options.defaultUserImg !== '')
221
+ html += "<div class='userImg'><img src='" + options.defaultUserImg + "' /></div>";
222
+ html += "<div class='msgBox'>";
223
+ if(msgUserId !== '')
224
+ html += "<div class='username'>" + (msgUserId == options.userId? "You":userName) + "</div>";
225
+ else
226
+ html += "<div class='username'>" + userName + "</div>";
227
+ html += "<div class='message'>" + messageText + "</div>";
228
+ if(typeof moment !== 'undefined')
229
+ html += "<div class='timestamp'>" + moment.unix(resp.messages[i].ts).fromNow() + "</div>";
230
+ html += "</div>";
231
+ html += "</div>";
232
+ }
233
+ else if(typeof resp.messages[i].subtype == 'undefined') {
234
+
235
+ //support replies exist
236
+ repliesExist++;
237
+
238
+ messageText = methods.formatMessage(resp.messages[i].text.trim());
239
+
240
+ var userId = resp.messages[i].user;
241
+ var userName = options.defaultSysUser;
242
+ var userImg = options.defaultSysImg;
243
+
244
+ if (options.useUserDetails && userList.length) {
245
+ for (var uL = 0; uL < userList.length; uL++) {
246
+ var currentUser = userList[uL];
247
+ if (currentUser.id == userId) {
248
+ if (currentUser.real_name != undefined && currentUser.real_name.length > 0)
249
+ userName = currentUser.real_name;
250
+ else
251
+ userName = currentUser.name;
252
+
253
+ userImg = currentUser.profile.image_48;
254
+
255
+ break;
256
+ }
257
+ }
258
+ }
259
+
260
+ html += "<div class='message-item'>";
261
+ if(userImg !== '')
262
+ html += "<div class='userImg'><img src='" + userImg + "' /></div>";
263
+ html += "<div class='msgBox'>"
264
+ html += "<div class='username main'>" + userName + "</div>";
265
+ html += "<div class='message'>" + messageText + "</div>";
266
+ if(typeof moment !== 'undefined')
267
+ html += "<div class='timestamp'>" + moment.unix(resp.messages[i].ts).fromNow() + "</div>";
268
+ html += "</div>";
269
+ html += "</div>";
270
+ }
271
+ }
272
+
273
+ $('.slack-message-box').append(html);
274
+
275
+ //scroll to the bottom
276
+ $('.slack-message-box').stop().animate({
277
+ scrollTop: $(".slack-message-box")[0].scrollHeight
278
+ }, 800);
279
+
280
+ //support team has replied and the chat box is closed
281
+ if(repliesExist > 0 && window.slackChat._options.isOpen === false && window.slackChat._options.badgeElement) {
282
+ $(window.slackChat._options.badgeElement).html(repliesExist).show();
283
+
284
+ }
285
+ }
286
+ else if(!resp.ok)
287
+ {
288
+ console.log('[SlackChat] Query failed with errors: ');
289
+ console.log(resp);
290
+ }
291
+ }
292
+ });
293
+ });
294
+
295
+
296
+ },
297
+
298
+ postMessage: function ($elem) {
299
+
300
+ var options = $elem._options;
301
+
302
+ var attachment = {};
303
+
304
+ attachment.fallback = "View " + options.user + "'s profile";
305
+ attachment.color = options.slackColor;
306
+ attachment.author_name = options.user;
307
+
308
+ if(options.userLink !== '') attachment.author_link = options.userLink;
309
+ if(options.userImg !== '') attachment.author_icon = options.userImg;
310
+ if(options.userId !== '') attachment.fields = [
311
+ {
312
+ "title": "ID",
313
+ "value": options.userId,
314
+ "short": true
315
+ }
316
+ ];
317
+
318
+ //do not send the message if the value is empty
319
+ if($('.slack-new-message').val().trim() === '') return false;
320
+
321
+ message = $('.slack-new-message').val();
322
+ $('.slack-new-message').val('');
323
+
324
+ if(options.debug) {
325
+ console.log('Posting Message:');
326
+ console.log({ message: message, attachment: attachment, options: options});
327
+ }
328
+
329
+ $.ajax({
330
+ url: 'https://slack.com/api/chat.postMessage'
331
+ ,type: "POST"
332
+ ,dataType: 'json'
333
+ ,data: {
334
+ token: options.apiToken
335
+ ,channel: window.slackChat._options.channelId
336
+ ,text: message
337
+ ,username: options.botUser
338
+ ,attachments: JSON.stringify([attachment])
339
+ }
340
+ ,success: function (resp) {
341
+ if(!resp.ok) {
342
+ $('.slack-new-message').val(message);
343
+ console.log('[SlackChat] Post Message failed with errors: ');
344
+ console.log(resp);
345
+ }
346
+ }
347
+ });
348
+ },
349
+
350
+ validationError: function (errorTxt) {
351
+ console.log('[SlackChat Error] ' + errorTxt);
352
+ return false;
353
+ },
354
+
355
+ getUserPresence: function ($elem) {
356
+ var options = $elem._options;
357
+ var active = false;
358
+ userList = [];
359
+
360
+ $.ajax({
361
+ url: 'https://slack.com/api/users.list'
362
+ ,type: "POST"
363
+ ,dataType: 'json'
364
+ ,data: {
365
+ token: options.apiToken
366
+ }
367
+ ,success: function (resp) {
368
+ if(resp.ok) {
369
+ userList = resp.members;
370
+
371
+ if(userList.length) {
372
+ for(var i=0; i<userList.length; i++) {
373
+ if(active) break;
374
+ if(userList[i].is_bot) continue;
375
+
376
+ $.ajax({
377
+ url: 'https://slack.com/api/users.getPresence'
378
+ ,dataType: 'json'
379
+ ,type: "POST"
380
+ ,data: {
381
+ token: options.apiToken
382
+ ,user: userList[i].id
383
+ }
384
+ ,success: function (resp) {
385
+ if(resp.ok) {
386
+ if(resp.presence === 'active')
387
+ {
388
+ $('.slackchat .presence').addClass('active');
389
+ $('.slackchat .presence .presence-text').text('Available');
390
+ if(options.disableIfAway && options.elementToDisable !== null) options.elementToDisable.show();
391
+ active = true;
392
+ return true;
393
+ }
394
+ else if(!active) {
395
+ $('.slackchat .presence').removeClass('active');
396
+ $('.slackchat .presence .presence-text').text('Away');
397
+ }
398
+ }
399
+ }
400
+ });
401
+ }
402
+ }
403
+ }
404
+ }
405
+ });
406
+ },
407
+
408
+ destroy: function ($elem) {
409
+ $($elem).unbind('click');
410
+
411
+ //added code for safely unbinding the element. thanks to @Jflinchum.
412
+ $(window.slackChat).unbind('click');
413
+
414
+ $('.slackchat').remove();
415
+ },
416
+
417
+ formatMessage: function (text) {
418
+
419
+ //hack for converting to html entities
420
+ var formattedText = $("<textarea/>").html(text).text();
421
+
422
+ return unescape(formattedText)
423
+ // <URL>
424
+ .replace(/<(.+?)(\|(.*?))?>/g, function(match, url, _text, text) {
425
+ if (!text) text = url;
426
+ return $('<a>')
427
+ .attr({
428
+ href: url,
429
+ target: '_blank'
430
+ })
431
+ .text(text)
432
+ .prop('outerHTML');
433
+ })
434
+ // `code block`
435
+ .replace(/(?:[`]{3,3})(?:\n)?([a-zA-Z0-9<>\\\.\*\n\r\-_ ]+)(?:\n)?(?:[`]{3,3})/g, function(match, code) {
436
+ return $('<code>').text(code).prop('outerHTML');
437
+ })
438
+ // `code`
439
+ .replace(/(?:[`]{1,1})([a-zA-Z0-9<>\\\.\*\n\r\-_ ]+)(?:[`]{1,1})/g, function(match, code) {
440
+ return $('<code>').text(code).prop('outerHTML');
441
+ })
442
+ // new line character
443
+ .replace(/\n/g, "<br />");
444
+ },
445
+
446
+ createChannel: function($elem, callback) {
447
+
448
+ var options = $elem._options;
449
+
450
+ if(!options.privateChannel) {
451
+ var channel = {
452
+ id: options.channelId
453
+ };
454
+
455
+ callback(channel);
456
+
457
+ return false;
458
+ }
459
+
460
+ if(options.privateChannelId) {
461
+
462
+ var channel = {
463
+ id: options.privateChannelId
464
+ };
465
+
466
+ callback(channel);
467
+
468
+ return false;
469
+ }
470
+
471
+ var privateChannelName = options.user + '-' + (options.userId?options.userId:(Math.random()*100000));
472
+
473
+ var payLoad = {
474
+ channelName: privateChannelName
475
+ };
476
+
477
+ if(options.defaultInvitedUsers.length > 0) {
478
+ payLoad.invitedUsers = JSON.stringify($.trim(options.defaultInvitedUsers));
479
+ }
480
+
481
+ $.ajax({
482
+ url: options.serverApiGateway
483
+ ,dataType: 'json'
484
+ ,type: "POST"
485
+ ,data: payLoad
486
+ ,success: function (resp) {
487
+ if(resp.ok) {
488
+ options.privateChannelId = window.slackChat._options.privateChannelId = resp.data.id;
489
+ callback(resp.data);
490
+ }
491
+
492
+ return false;
493
+ }
494
+ ,error: function () {
495
+ return false;
496
+ }
497
+ });
498
+ },
499
+
500
+ resizeWindow: function () {
501
+ $('.slack-message-box').height($('.slack-chat-box').height() - $('.desc').height() - $('.send-area').height() - parseInt(window.slackChat._options.heightOffset));
502
+ }
503
+ };
504
+
505
+ $.fn.slackChat = function( methodOrOptions ) {
506
+
507
+ if(methods[methodOrOptions]) {
508
+ return methods[ methodOrOptions ].apply( this, Array.prototype.slice.call( arguments, 1 ));
509
+ }
510
+ else if ( typeof methodOrOptions === 'object' || ! methodOrOptions ) {
511
+ methods.init.apply( this, arguments );
512
+ }
513
+ else {
514
+ $.error( 'Method ' + methodOrOptions + ' does not exist on jQuery.slackChat' );
515
+ }
516
+ };
517
+
518
+ }( jQuery ));
@@ -0,0 +1 @@
1
+ !function(e,t,n){"use strict";!function o(e,t,n){function a(s,l){if(!t[s]){if(!e[s]){var i="function"==typeof require&&require;if(!l&&i)return i(s,!0);if(r)return r(s,!0);var u=new Error("Cannot find module '"+s+"'");throw u.code="MODULE_NOT_FOUND",u}var c=t[s]={exports:{}};e[s][0].call(c.exports,function(t){var n=e[s][1][t];return a(n?n:t)},c,c.exports,o,e,t,n)}return t[s].exports}for(var r="function"==typeof require&&require,s=0;s<n.length;s++)a(n[s]);return a}({1:[function(o,a,r){function s(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(r,"__esModule",{value:!0});var l,i,u,c,d=o("./modules/handle-dom"),f=o("./modules/utils"),p=o("./modules/handle-swal-dom"),m=o("./modules/handle-click"),v=o("./modules/handle-key"),y=s(v),b=o("./modules/default-params"),h=s(b),g=o("./modules/set-params"),w=s(g);r["default"]=u=c=function(){function o(e){var t=a;return t[e]===n?h["default"][e]:t[e]}var a=arguments[0];if((0,d.addClass)(t.body,"stop-scrolling"),(0,p.resetInput)(),a===n)return(0,f.logStr)("SweetAlert expects at least 1 attribute!"),!1;var r=(0,f.extend)({},h["default"]);switch(typeof a){case"string":r.title=a,r.text=arguments[1]||"",r.type=arguments[2]||"";break;case"object":if(a.title===n)return(0,f.logStr)('Missing "title" argument!'),!1;r.title=a.title;for(var s in h["default"])r[s]=o(s);r.confirmButtonText=r.showCancelButton?"Confirm":h["default"].confirmButtonText,r.confirmButtonText=o("confirmButtonText"),r.doneFunction=arguments[1]||null;break;default:return(0,f.logStr)('Unexpected type of argument! Expected "string" or "object", got '+typeof a),!1}(0,w["default"])(r),(0,p.fixVerticalPosition)(),(0,p.openModal)(arguments[1]);for(var u=(0,p.getModal)(),v=u.querySelectorAll("button"),b=["onclick","onmouseover","onmouseout","onmousedown","onmouseup","onfocus"],g=function(e){return(0,m.handleButton)(e,r,u)},C=0;C<v.length;C++)for(var S=0;S<b.length;S++){var x=b[S];v[C][x]=g}(0,p.getOverlay)().onclick=g,l=e.onkeydown;var k=function(e){return(0,y["default"])(e,r,u)};e.onkeydown=k,e.onfocus=function(){setTimeout(function(){i!==n&&(i.focus(),i=n)},0)},c.enableButtons()},u.setDefaults=c.setDefaults=function(e){if(!e)throw new Error("userParams is required");if("object"!=typeof e)throw new Error("userParams has to be a object");(0,f.extend)(h["default"],e)},u.close=c.close=function(){var o=(0,p.getModal)();(0,d.fadeOut)((0,p.getOverlay)(),5),(0,d.fadeOut)(o,5),(0,d.removeClass)(o,"showSweetAlert"),(0,d.addClass)(o,"hideSweetAlert"),(0,d.removeClass)(o,"visible");var a=o.querySelector(".sa-icon.sa-success");(0,d.removeClass)(a,"animate"),(0,d.removeClass)(a.querySelector(".sa-tip"),"animateSuccessTip"),(0,d.removeClass)(a.querySelector(".sa-long"),"animateSuccessLong");var r=o.querySelector(".sa-icon.sa-error");(0,d.removeClass)(r,"animateErrorIcon"),(0,d.removeClass)(r.querySelector(".sa-x-mark"),"animateXMark");var s=o.querySelector(".sa-icon.sa-warning");return(0,d.removeClass)(s,"pulseWarning"),(0,d.removeClass)(s.querySelector(".sa-body"),"pulseWarningIns"),(0,d.removeClass)(s.querySelector(".sa-dot"),"pulseWarningIns"),setTimeout(function(){var e=o.getAttribute("data-custom-class");(0,d.removeClass)(o,e)},300),(0,d.removeClass)(t.body,"stop-scrolling"),e.onkeydown=l,e.previousActiveElement&&e.previousActiveElement.focus(),i=n,clearTimeout(o.timeout),!0},u.showInputError=c.showInputError=function(e){var t=(0,p.getModal)(),n=t.querySelector(".sa-input-error");(0,d.addClass)(n,"show");var o=t.querySelector(".sa-error-container");(0,d.addClass)(o,"show"),o.querySelector("p").innerHTML=e,setTimeout(function(){u.enableButtons()},1),t.querySelector("input").focus()},u.resetInputError=c.resetInputError=function(e){if(e&&13===e.keyCode)return!1;var t=(0,p.getModal)(),n=t.querySelector(".sa-input-error");(0,d.removeClass)(n,"show");var o=t.querySelector(".sa-error-container");(0,d.removeClass)(o,"show")},u.disableButtons=c.disableButtons=function(e){var t=(0,p.getModal)(),n=t.querySelector("button.confirm"),o=t.querySelector("button.cancel");n.disabled=!0,o.disabled=!0},u.enableButtons=c.enableButtons=function(e){var t=(0,p.getModal)(),n=t.querySelector("button.confirm"),o=t.querySelector("button.cancel");n.disabled=!1,o.disabled=!1},"undefined"!=typeof e?e.sweetAlert=e.swal=u:(0,f.logStr)("SweetAlert is a frontend module!"),a.exports=r["default"]},{"./modules/default-params":2,"./modules/handle-click":3,"./modules/handle-dom":4,"./modules/handle-key":5,"./modules/handle-swal-dom":6,"./modules/set-params":8,"./modules/utils":9}],2:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var o={title:"",text:"",type:null,allowOutsideClick:!1,showConfirmButton:!0,showCancelButton:!1,closeOnConfirm:!0,closeOnCancel:!0,confirmButtonText:"OK",confirmButtonColor:"#8CD4F5",cancelButtonText:"Cancel",imageUrl:null,imageSize:null,timer:null,customClass:"",html:!1,animation:!0,allowEscapeKey:!0,inputType:"text",inputPlaceholder:"",inputValue:"",showLoaderOnConfirm:!1};n["default"]=o,t.exports=n["default"]},{}],3:[function(t,n,o){Object.defineProperty(o,"__esModule",{value:!0});var a=t("./utils"),r=(t("./handle-swal-dom"),t("./handle-dom")),s=function(t,n,o){function s(e){m&&n.confirmButtonColor&&(p.style.backgroundColor=e)}var u,c,d,f=t||e.event,p=f.target||f.srcElement,m=-1!==p.className.indexOf("confirm"),v=-1!==p.className.indexOf("sweet-overlay"),y=(0,r.hasClass)(o,"visible"),b=n.doneFunction&&"true"===o.getAttribute("data-has-done-function");switch(m&&n.confirmButtonColor&&(u=n.confirmButtonColor,c=(0,a.colorLuminance)(u,-.04),d=(0,a.colorLuminance)(u,-.14)),f.type){case"mouseover":s(c);break;case"mouseout":s(u);break;case"mousedown":s(d);break;case"mouseup":s(c);break;case"focus":var h=o.querySelector("button.confirm"),g=o.querySelector("button.cancel");m?g.style.boxShadow="none":h.style.boxShadow="none";break;case"click":var w=o===p,C=(0,r.isDescendant)(o,p);if(!w&&!C&&y&&!n.allowOutsideClick)break;m&&b&&y?l(o,n):b&&y||v?i(o,n):(0,r.isDescendant)(o,p)&&"BUTTON"===p.tagName&&sweetAlert.close()}},l=function(e,t){var n=!0;(0,r.hasClass)(e,"show-input")&&(n=e.querySelector("input").value,n||(n="")),t.doneFunction(n),t.closeOnConfirm&&sweetAlert.close(),t.showLoaderOnConfirm&&sweetAlert.disableButtons()},i=function(e,t){var n=String(t.doneFunction).replace(/\s/g,""),o="function("===n.substring(0,9)&&")"!==n.substring(9,10);o&&t.doneFunction(!1),t.closeOnCancel&&sweetAlert.close()};o["default"]={handleButton:s,handleConfirm:l,handleCancel:i},n.exports=o["default"]},{"./handle-dom":4,"./handle-swal-dom":6,"./utils":9}],4:[function(n,o,a){Object.defineProperty(a,"__esModule",{value:!0});var r=function(e,t){return new RegExp(" "+t+" ").test(" "+e.className+" ")},s=function(e,t){r(e,t)||(e.className+=" "+t)},l=function(e,t){var n=" "+e.className.replace(/[\t\r\n]/g," ")+" ";if(r(e,t)){for(;n.indexOf(" "+t+" ")>=0;)n=n.replace(" "+t+" "," ");e.className=n.replace(/^\s+|\s+$/g,"")}},i=function(e){var n=t.createElement("div");return n.appendChild(t.createTextNode(e)),n.innerHTML},u=function(e){e.style.opacity="",e.style.display="block"},c=function(e){if(e&&!e.length)return u(e);for(var t=0;t<e.length;++t)u(e[t])},d=function(e){e.style.opacity="",e.style.display="none"},f=function(e){if(e&&!e.length)return d(e);for(var t=0;t<e.length;++t)d(e[t])},p=function(e,t){for(var n=t.parentNode;null!==n;){if(n===e)return!0;n=n.parentNode}return!1},m=function(e){e.style.left="-9999px",e.style.display="block";var t,n=e.clientHeight;return t="undefined"!=typeof getComputedStyle?parseInt(getComputedStyle(e).getPropertyValue("padding-top"),10):parseInt(e.currentStyle.padding),e.style.left="",e.style.display="none","-"+parseInt((n+t)/2)+"px"},v=function(e,t){if(+e.style.opacity<1){t=t||16,e.style.opacity=0,e.style.display="block";var n=+new Date,o=function a(){e.style.opacity=+e.style.opacity+(new Date-n)/100,n=+new Date,+e.style.opacity<1&&setTimeout(a,t)};o()}e.style.display="block"},y=function(e,t){t=t||16,e.style.opacity=1;var n=+new Date,o=function a(){e.style.opacity=+e.style.opacity-(new Date-n)/100,n=+new Date,+e.style.opacity>0?setTimeout(a,t):e.style.display="none"};o()},b=function(n){if("function"==typeof MouseEvent){var o=new MouseEvent("click",{view:e,bubbles:!1,cancelable:!0});n.dispatchEvent(o)}else if(t.createEvent){var a=t.createEvent("MouseEvents");a.initEvent("click",!1,!1),n.dispatchEvent(a)}else t.createEventObject?n.fireEvent("onclick"):"function"==typeof n.onclick&&n.onclick()},h=function(t){"function"==typeof t.stopPropagation?(t.stopPropagation(),t.preventDefault()):e.event&&e.event.hasOwnProperty("cancelBubble")&&(e.event.cancelBubble=!0)};a.hasClass=r,a.addClass=s,a.removeClass=l,a.escapeHtml=i,a._show=u,a.show=c,a._hide=d,a.hide=f,a.isDescendant=p,a.getTopMargin=m,a.fadeIn=v,a.fadeOut=y,a.fireClick=b,a.stopEventPropagation=h},{}],5:[function(t,o,a){Object.defineProperty(a,"__esModule",{value:!0});var r=t("./handle-dom"),s=t("./handle-swal-dom"),l=function(t,o,a){var l=t||e.event,i=l.keyCode||l.which,u=a.querySelector("button.confirm"),c=a.querySelector("button.cancel"),d=a.querySelectorAll("button[tabindex]");if(-1!==[9,13,32,27].indexOf(i)){for(var f=l.target||l.srcElement,p=-1,m=0;m<d.length;m++)if(f===d[m]){p=m;break}9===i?(f=-1===p?u:p===d.length-1?d[0]:d[p+1],(0,r.stopEventPropagation)(l),f.focus(),o.confirmButtonColor&&(0,s.setFocusStyle)(f,o.confirmButtonColor)):13===i?("INPUT"===f.tagName&&(f=u,u.focus()),f=-1===p?u:n):27===i&&o.allowEscapeKey===!0?(f=c,(0,r.fireClick)(f,l)):f=n}};a["default"]=l,o.exports=a["default"]},{"./handle-dom":4,"./handle-swal-dom":6}],6:[function(n,o,a){function r(e){return e&&e.__esModule?e:{"default":e}}Object.defineProperty(a,"__esModule",{value:!0});var s=n("./utils"),l=n("./handle-dom"),i=n("./default-params"),u=r(i),c=n("./injected-html"),d=r(c),f=".sweet-alert",p=".sweet-overlay",m=function(){var e=t.createElement("div");for(e.innerHTML=d["default"];e.firstChild;)t.body.appendChild(e.firstChild)},v=function x(){var e=t.querySelector(f);return e||(m(),e=x()),e},y=function(){var e=v();return e?e.querySelector("input"):void 0},b=function(){return t.querySelector(p)},h=function(e,t){var n=(0,s.hexToRgb)(t);e.style.boxShadow="0 0 2px rgba("+n+", 0.8), inset 0 0 0 1px rgba(0, 0, 0, 0.05)"},g=function(n){var o=v();(0,l.fadeIn)(b(),10),(0,l.show)(o),(0,l.addClass)(o,"showSweetAlert"),(0,l.removeClass)(o,"hideSweetAlert"),e.previousActiveElement=t.activeElement;var a=o.querySelector("button.confirm");a.focus(),setTimeout(function(){(0,l.addClass)(o,"visible")},500);var r=o.getAttribute("data-timer");if("null"!==r&&""!==r){var s=n;o.timeout=setTimeout(function(){var e=(s||null)&&"true"===o.getAttribute("data-has-done-function");e?s(null):sweetAlert.close()},r)}},w=function(){var e=v(),t=y();(0,l.removeClass)(e,"show-input"),t.value=u["default"].inputValue,t.setAttribute("type",u["default"].inputType),t.setAttribute("placeholder",u["default"].inputPlaceholder),C()},C=function(e){if(e&&13===e.keyCode)return!1;var t=v(),n=t.querySelector(".sa-input-error");(0,l.removeClass)(n,"show");var o=t.querySelector(".sa-error-container");(0,l.removeClass)(o,"show")},S=function(){var e=v();e.style.marginTop=(0,l.getTopMargin)(v())};a.sweetAlertInitialize=m,a.getModal=v,a.getOverlay=b,a.getInput=y,a.setFocusStyle=h,a.openModal=g,a.resetInput=w,a.resetInputError=C,a.fixVerticalPosition=S},{"./default-params":2,"./handle-dom":4,"./injected-html":7,"./utils":9}],7:[function(e,t,n){Object.defineProperty(n,"__esModule",{value:!0});var o='<div class="sweet-overlay" tabIndex="-1"></div><div class="sweet-alert"><div class="sa-icon sa-error">\n <span class="sa-x-mark">\n <span class="sa-line sa-left"></span>\n <span class="sa-line sa-right"></span>\n </span>\n </div><div class="sa-icon sa-warning">\n <span class="sa-body"></span>\n <span class="sa-dot"></span>\n </div><div class="sa-icon sa-info"></div><div class="sa-icon sa-success">\n <span class="sa-line sa-tip"></span>\n <span class="sa-line sa-long"></span>\n\n <div class="sa-placeholder"></div>\n <div class="sa-fix"></div>\n </div><div class="sa-icon sa-custom"></div><h2>Title</h2>\n <p>Text</p>\n <fieldset>\n <input type="text" tabIndex="3" />\n <div class="sa-input-error"></div>\n </fieldset><div class="sa-error-container">\n <div class="icon">!</div>\n <p>Not valid!</p>\n </div><div class="sa-button-container">\n <button class="cancel" tabIndex="2">Cancel</button>\n <div class="sa-confirm-button-container">\n <button class="confirm" tabIndex="1">OK</button><div class="la-ball-fall">\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div>\n </div></div>';n["default"]=o,t.exports=n["default"]},{}],8:[function(e,t,o){Object.defineProperty(o,"__esModule",{value:!0});var a=e("./utils"),r=e("./handle-swal-dom"),s=e("./handle-dom"),l=["error","warning","info","success","input","prompt"],i=function(e){var t=(0,r.getModal)(),o=t.querySelector("h2"),i=t.querySelector("p"),u=t.querySelector("button.cancel"),c=t.querySelector("button.confirm");if(o.innerHTML=e.html?e.title:(0,s.escapeHtml)(e.title).split("\n").join("<br>"),i.innerHTML=e.html?e.text:(0,s.escapeHtml)(e.text||"").split("\n").join("<br>"),e.text&&(0,s.show)(i),e.customClass)(0,s.addClass)(t,e.customClass),t.setAttribute("data-custom-class",e.customClass);else{var d=t.getAttribute("data-custom-class");(0,s.removeClass)(t,d),t.setAttribute("data-custom-class","")}if((0,s.hide)(t.querySelectorAll(".sa-icon")),e.type&&!(0,a.isIE8)()){var f=function(){for(var o=!1,a=0;a<l.length;a++)if(e.type===l[a]){o=!0;break}if(!o)return logStr("Unknown alert type: "+e.type),{v:!1};var i=["success","error","warning","info"],u=n;-1!==i.indexOf(e.type)&&(u=t.querySelector(".sa-icon.sa-"+e.type),(0,s.show)(u));var c=(0,r.getInput)();switch(e.type){case"success":(0,s.addClass)(u,"animate"),(0,s.addClass)(u.querySelector(".sa-tip"),"animateSuccessTip"),(0,s.addClass)(u.querySelector(".sa-long"),"animateSuccessLong");break;case"error":(0,s.addClass)(u,"animateErrorIcon"),(0,s.addClass)(u.querySelector(".sa-x-mark"),"animateXMark");break;case"warning":(0,s.addClass)(u,"pulseWarning"),(0,s.addClass)(u.querySelector(".sa-body"),"pulseWarningIns"),(0,s.addClass)(u.querySelector(".sa-dot"),"pulseWarningIns");break;case"input":case"prompt":c.setAttribute("type",e.inputType),c.value=e.inputValue,c.setAttribute("placeholder",e.inputPlaceholder),(0,s.addClass)(t,"show-input"),setTimeout(function(){c.focus(),c.addEventListener("keyup",swal.resetInputError)},400)}}();if("object"==typeof f)return f.v}if(e.imageUrl){var p=t.querySelector(".sa-icon.sa-custom");p.style.backgroundImage="url("+e.imageUrl+")",(0,s.show)(p);var m=80,v=80;if(e.imageSize){var y=e.imageSize.toString().split("x"),b=y[0],h=y[1];b&&h?(m=b,v=h):logStr("Parameter imageSize expects value with format WIDTHxHEIGHT, got "+e.imageSize)}p.setAttribute("style",p.getAttribute("style")+"width:"+m+"px; height:"+v+"px")}t.setAttribute("data-has-cancel-button",e.showCancelButton),e.showCancelButton?u.style.display="inline-block":(0,s.hide)(u),t.setAttribute("data-has-confirm-button",e.showConfirmButton),e.showConfirmButton?c.style.display="inline-block":(0,s.hide)(c),e.cancelButtonText&&(u.innerHTML=(0,s.escapeHtml)(e.cancelButtonText)),e.confirmButtonText&&(c.innerHTML=(0,s.escapeHtml)(e.confirmButtonText)),e.confirmButtonColor&&(c.style.backgroundColor=e.confirmButtonColor,c.style.borderLeftColor=e.confirmLoadingButtonColor,c.style.borderRightColor=e.confirmLoadingButtonColor,(0,r.setFocusStyle)(c,e.confirmButtonColor)),t.setAttribute("data-allow-outside-click",e.allowOutsideClick);var g=!!e.doneFunction;t.setAttribute("data-has-done-function",g),e.animation?"string"==typeof e.animation?t.setAttribute("data-animation",e.animation):t.setAttribute("data-animation","pop"):t.setAttribute("data-animation","none"),t.setAttribute("data-timer",e.timer)};o["default"]=i,t.exports=o["default"]},{"./handle-dom":4,"./handle-swal-dom":6,"./utils":9}],9:[function(t,n,o){Object.defineProperty(o,"__esModule",{value:!0});var a=function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n]);return e},r=function(e){var t=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(e);return t?parseInt(t[1],16)+", "+parseInt(t[2],16)+", "+parseInt(t[3],16):null},s=function(){return e.attachEvent&&!e.addEventListener},l=function(t){"undefined"!=typeof e&&e.console&&e.console.log("SweetAlert: "+t)},i=function(e,t){e=String(e).replace(/[^0-9a-f]/gi,""),e.length<6&&(e=e[0]+e[0]+e[1]+e[1]+e[2]+e[2]),t=t||0;var n,o,a="#";for(o=0;3>o;o++)n=parseInt(e.substr(2*o,2),16),n=Math.round(Math.min(Math.max(0,n+n*t),255)).toString(16),a+=("00"+n).substr(n.length);return a};o.extend=a,o.hexToRgb=r,o.isIE8=s,o.logStr=l,o.colorLuminance=i},{}]},{},[1]),"function"==typeof define&&define.amd?define(function(){return sweetAlert}):"undefined"!=typeof module&&module.exports&&(module.exports=sweetAlert)}(window,document);