6056 |
efrain |
1 |
/*!
|
|
|
2 |
* Bootstrap Confirmation (v4.1.0)
|
|
|
3 |
* @copyright 2013 Nimit Suwannagate <ethaizone@hotmail.com>
|
|
|
4 |
* @copyright 2014-2018 Damien "Mistic" Sorel <contact@git.strangeplanet.fr>
|
|
|
5 |
* @licence Apache License, Version 2.0
|
|
|
6 |
*/
|
|
|
7 |
(function (global, factory) {
|
|
|
8 |
typeof exports === 'object' && typeof module !== 'undefined' ? factory(require('jquery'), require('bootstrap')) :
|
|
|
9 |
typeof define === 'function' && define.amd ? define(['jquery', 'bootstrap'], factory) :
|
|
|
10 |
(global = global || self, factory(global.jQuery));
|
|
|
11 |
}(this, function ($) { 'use strict';
|
|
|
12 |
|
|
|
13 |
$ = $ && $.hasOwnProperty('default') ? $['default'] : $;
|
|
|
14 |
|
|
|
15 |
function _defineProperties(target, props) {
|
|
|
16 |
for (var i = 0; i < props.length; i++) {
|
|
|
17 |
var descriptor = props[i];
|
|
|
18 |
descriptor.enumerable = descriptor.enumerable || false;
|
|
|
19 |
descriptor.configurable = true;
|
|
|
20 |
if ("value" in descriptor) descriptor.writable = true;
|
|
|
21 |
Object.defineProperty(target, descriptor.key, descriptor);
|
|
|
22 |
}
|
|
|
23 |
}
|
|
|
24 |
|
|
|
25 |
function _createClass(Constructor, protoProps, staticProps) {
|
|
|
26 |
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
|
27 |
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
|
28 |
return Constructor;
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
function _defineProperty(obj, key, value) {
|
|
|
32 |
if (key in obj) {
|
|
|
33 |
Object.defineProperty(obj, key, {
|
|
|
34 |
value: value,
|
|
|
35 |
enumerable: true,
|
|
|
36 |
configurable: true,
|
|
|
37 |
writable: true
|
|
|
38 |
});
|
|
|
39 |
} else {
|
|
|
40 |
obj[key] = value;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
return obj;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
function _objectSpread(target) {
|
|
|
47 |
for (var i = 1; i < arguments.length; i++) {
|
|
|
48 |
var source = arguments[i] != null ? arguments[i] : {};
|
|
|
49 |
var ownKeys = Object.keys(source);
|
|
|
50 |
|
|
|
51 |
if (typeof Object.getOwnPropertySymbols === 'function') {
|
|
|
52 |
ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
|
|
|
53 |
return Object.getOwnPropertyDescriptor(source, sym).enumerable;
|
|
|
54 |
}));
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
ownKeys.forEach(function (key) {
|
|
|
58 |
_defineProperty(target, key, source[key]);
|
|
|
59 |
});
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
return target;
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
function _inheritsLoose(subClass, superClass) {
|
|
|
66 |
subClass.prototype = Object.create(superClass.prototype);
|
|
|
67 |
subClass.prototype.constructor = subClass;
|
|
|
68 |
subClass.__proto__ = superClass;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
if (typeof $.fn.popover === 'undefined' || $.fn.popover.Constructor.VERSION.split('.').shift() !== '4') {
|
|
|
72 |
throw new Error('Bootstrap Confirmation 4 requires Bootstrap Popover 4');
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
var Popover = $.fn.popover.Constructor;
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* ------------------------------------------------------------------------
|
|
|
79 |
* Constants
|
|
|
80 |
* ------------------------------------------------------------------------
|
|
|
81 |
*/
|
|
|
82 |
|
|
|
83 |
var NAME = 'confirmation';
|
|
|
84 |
var VERSION = '4.1.0';
|
|
|
85 |
var DATA_KEY = "bs." + NAME;
|
|
|
86 |
var EVENT_KEY = "." + DATA_KEY;
|
|
|
87 |
var JQUERY_NO_CONFLICT = $.fn[NAME];
|
|
|
88 |
var BTN_CLASS_BASE = 'h-100 d-flex align-items-center';
|
|
|
89 |
var BTN_CLASS_DEFAULT = 'btn btn-sm';
|
|
|
90 |
|
|
|
91 |
var DefaultType = _objectSpread({}, Popover.DefaultType, {
|
|
|
92 |
singleton: 'boolean',
|
|
|
93 |
popout: 'boolean',
|
|
|
94 |
copyAttributes: '(string|array)',
|
|
|
95 |
onConfirm: 'function',
|
|
|
96 |
onCancel: 'function',
|
|
|
97 |
btnOkClass: 'string',
|
|
|
98 |
btnOkLabel: 'string',
|
|
|
99 |
btnOkIconClass: 'string',
|
|
|
100 |
btnOkIconContent: 'string',
|
|
|
101 |
btnCancelClass: 'string',
|
|
|
102 |
btnCancelLabel: 'string',
|
|
|
103 |
btnCancelIconClass: 'string',
|
|
|
104 |
btnCancelIconContent: 'string',
|
|
|
105 |
buttons: 'array'
|
|
|
106 |
});
|
|
|
107 |
|
|
|
108 |
var Default = _objectSpread({}, Popover.Default, {
|
|
|
109 |
_attributes: {},
|
|
|
110 |
_selector: null,
|
|
|
111 |
placement: 'top',
|
|
|
112 |
title: 'Are you sure?',
|
|
|
113 |
trigger: 'click',
|
|
|
114 |
confirmationEvent: undefined,
|
|
|
115 |
content: '',
|
|
|
116 |
singleton: false,
|
|
|
117 |
popout: false,
|
|
|
118 |
copyAttributes: 'href target',
|
|
|
119 |
onConfirm: $.noop,
|
|
|
120 |
onCancel: $.noop,
|
|
|
121 |
btnOkClass: BTN_CLASS_DEFAULT + " btn-primary",
|
|
|
122 |
btnOkLabel: 'Yes',
|
|
|
123 |
btnOkIconClass: '',
|
|
|
124 |
btnOkIconContent: '',
|
|
|
125 |
btnCancelClass: BTN_CLASS_DEFAULT + " btn-secondary",
|
|
|
126 |
btnCancelLabel: 'No',
|
|
|
127 |
btnCancelIconClass: '',
|
|
|
128 |
btnCancelIconContent: '',
|
|
|
129 |
buttons: [],
|
|
|
130 |
// @formatter:off
|
|
|
131 |
template: "\n<div class=\"popover confirmation\">\n <div class=\"arrow\"></div>\n <h3 class=\"popover-header\"></h3>\n <div class=\"popover-body\">\n <p class=\"confirmation-content\"></p>\n <div class=\"confirmation-buttons text-center\">\n <div class=\"btn-group\"></div>\n </div>\n </div>\n</div>" // @formatter:on
|
|
|
132 |
|
|
|
133 |
});
|
|
|
134 |
|
|
|
135 |
if (Default.whiteList) {
|
|
|
136 |
Default.whiteList['*'].push('data-apply', 'data-dismiss');
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
var ClassName = {
|
|
|
140 |
FADE: 'fade',
|
|
|
141 |
SHOW: 'show'
|
|
|
142 |
};
|
|
|
143 |
var Selector = {
|
|
|
144 |
TITLE: '.popover-header',
|
|
|
145 |
CONTENT: '.confirmation-content',
|
|
|
146 |
BUTTONS: '.confirmation-buttons .btn-group'
|
|
|
147 |
};
|
|
|
148 |
var Keymap = {
|
|
|
149 |
13: 'Enter',
|
|
|
150 |
27: 'Escape',
|
|
|
151 |
39: 'ArrowRight',
|
|
|
152 |
40: 'ArrowDown'
|
|
|
153 |
};
|
|
|
154 |
var Event = {
|
|
|
155 |
HIDE: "hide" + EVENT_KEY,
|
|
|
156 |
HIDDEN: "hidden" + EVENT_KEY,
|
|
|
157 |
SHOW: "show" + EVENT_KEY,
|
|
|
158 |
SHOWN: "shown" + EVENT_KEY,
|
|
|
159 |
INSERTED: "inserted" + EVENT_KEY,
|
|
|
160 |
CLICK: "click" + EVENT_KEY,
|
|
|
161 |
FOCUSIN: "focusin" + EVENT_KEY,
|
|
|
162 |
FOCUSOUT: "focusout" + EVENT_KEY,
|
|
|
163 |
MOUSEENTER: "mouseenter" + EVENT_KEY,
|
|
|
164 |
MOUSELEAVE: "mouseleave" + EVENT_KEY,
|
|
|
165 |
CONFIRMED: "confirmed" + EVENT_KEY,
|
|
|
166 |
CANCELED: "canceled" + EVENT_KEY,
|
|
|
167 |
KEYUP: "keyup" + EVENT_KEY
|
|
|
168 |
};
|
|
|
169 |
/**
|
|
|
170 |
* ------------------------------------------------------------------------
|
|
|
171 |
* Class Definition
|
|
|
172 |
* ------------------------------------------------------------------------
|
|
|
173 |
*/
|
|
|
174 |
// keep track of the last openned confirmation for keyboard navigation
|
|
|
175 |
|
|
|
176 |
var activeConfirmation;
|
|
|
177 |
|
|
|
178 |
var Confirmation =
|
|
|
179 |
/*#__PURE__*/
|
|
|
180 |
function (_Popover) {
|
|
|
181 |
_inheritsLoose(Confirmation, _Popover);
|
|
|
182 |
|
|
|
183 |
_createClass(Confirmation, null, [{
|
|
|
184 |
key: "VERSION",
|
|
|
185 |
// Getters
|
|
|
186 |
get: function get() {
|
|
|
187 |
return VERSION;
|
|
|
188 |
}
|
|
|
189 |
}, {
|
|
|
190 |
key: "Default",
|
|
|
191 |
get: function get() {
|
|
|
192 |
return Default;
|
|
|
193 |
}
|
|
|
194 |
}, {
|
|
|
195 |
key: "NAME",
|
|
|
196 |
get: function get() {
|
|
|
197 |
return NAME;
|
|
|
198 |
}
|
|
|
199 |
}, {
|
|
|
200 |
key: "DATA_KEY",
|
|
|
201 |
get: function get() {
|
|
|
202 |
return DATA_KEY;
|
|
|
203 |
}
|
|
|
204 |
}, {
|
|
|
205 |
key: "Event",
|
|
|
206 |
get: function get() {
|
|
|
207 |
return Event;
|
|
|
208 |
}
|
|
|
209 |
}, {
|
|
|
210 |
key: "EVENT_KEY",
|
|
|
211 |
get: function get() {
|
|
|
212 |
return EVENT_KEY;
|
|
|
213 |
}
|
|
|
214 |
}, {
|
|
|
215 |
key: "DefaultType",
|
|
|
216 |
get: function get() {
|
|
|
217 |
return DefaultType;
|
|
|
218 |
} // Constructor
|
|
|
219 |
|
|
|
220 |
}]);
|
|
|
221 |
|
|
|
222 |
function Confirmation(element, config) {
|
|
|
223 |
var _this;
|
|
|
224 |
|
|
|
225 |
_this = _Popover.call(this, element, config) || this;
|
|
|
226 |
|
|
|
227 |
if ((_this.config.popout || _this.config.singleton) && !_this.config.rootSelector) {
|
|
|
228 |
throw new Error('The rootSelector option is required to use popout and singleton features since jQuery 3.');
|
|
|
229 |
} // keep trace of selectors
|
|
|
230 |
|
|
|
231 |
|
|
|
232 |
_this._isDelegate = false;
|
|
|
233 |
|
|
|
234 |
if (config.selector) {
|
|
|
235 |
// container of buttons
|
|
|
236 |
config._selector = config.rootSelector + " " + config.selector;
|
|
|
237 |
_this.config._selector = config._selector;
|
|
|
238 |
} else if (config._selector) {
|
|
|
239 |
// children of container
|
|
|
240 |
_this.config._selector = config._selector;
|
|
|
241 |
_this._isDelegate = true;
|
|
|
242 |
} else {
|
|
|
243 |
// standalone
|
|
|
244 |
_this.config._selector = config.rootSelector;
|
|
|
245 |
}
|
|
|
246 |
|
|
|
247 |
if (_this.config.confirmationEvent === undefined) {
|
|
|
248 |
_this.config.confirmationEvent = _this.config.trigger;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
if (!_this.config.selector) {
|
|
|
252 |
_this._copyAttributes();
|
|
|
253 |
}
|
|
|
254 |
|
|
|
255 |
_this._setConfirmationListeners();
|
|
|
256 |
|
|
|
257 |
return _this;
|
|
|
258 |
} // Overrides
|
|
|
259 |
|
|
|
260 |
|
|
|
261 |
var _proto = Confirmation.prototype;
|
|
|
262 |
|
|
|
263 |
_proto.isWithContent = function isWithContent() {
|
|
|
264 |
return true;
|
|
|
265 |
};
|
|
|
266 |
|
|
|
267 |
_proto.setContent = function setContent() {
|
|
|
268 |
var $tip = $(this.getTipElement());
|
|
|
269 |
|
|
|
270 |
var content = this._getContent();
|
|
|
271 |
|
|
|
272 |
if (typeof content === 'function') {
|
|
|
273 |
content = content.call(this.element);
|
|
|
274 |
}
|
|
|
275 |
|
|
|
276 |
this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
|
|
|
277 |
$tip.find(Selector.CONTENT).toggle(!!content);
|
|
|
278 |
|
|
|
279 |
if (content) {
|
|
|
280 |
this.setElementContent($tip.find(Selector.CONTENT), content);
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
if (this.config.buttons.length > 0) {
|
|
|
284 |
this._setButtons($tip, this.config.buttons);
|
|
|
285 |
} else {
|
|
|
286 |
this._setStandardButtons($tip);
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
$tip.removeClass(ClassName.FADE + " " + ClassName.SHOW);
|
|
|
290 |
|
|
|
291 |
this._setupKeyupEvent();
|
|
|
292 |
};
|
|
|
293 |
|
|
|
294 |
_proto.dispose = function dispose() {
|
|
|
295 |
$('body').off(Event.CLICK + "." + this.uid);
|
|
|
296 |
this.eventBody = false;
|
|
|
297 |
|
|
|
298 |
this._cleanKeyupEvent();
|
|
|
299 |
|
|
|
300 |
_Popover.prototype.dispose.call(this);
|
|
|
301 |
};
|
|
|
302 |
|
|
|
303 |
_proto.hide = function hide(callback) {
|
|
|
304 |
this._cleanKeyupEvent();
|
|
|
305 |
|
|
|
306 |
_Popover.prototype.hide.call(this, callback);
|
|
|
307 |
} // Private
|
|
|
308 |
|
|
|
309 |
/**
|
|
|
310 |
* Copy the value of `copyAttributes` on the config object
|
|
|
311 |
* @private
|
|
|
312 |
*/
|
|
|
313 |
;
|
|
|
314 |
|
|
|
315 |
_proto._copyAttributes = function _copyAttributes() {
|
|
|
316 |
var _this2 = this;
|
|
|
317 |
|
|
|
318 |
this.config._attributes = {};
|
|
|
319 |
|
|
|
320 |
if (this.config.copyAttributes) {
|
|
|
321 |
if (typeof this.config.copyAttributes === 'string') {
|
|
|
322 |
this.config.copyAttributes = this.config.copyAttributes.split(' ');
|
|
|
323 |
}
|
|
|
324 |
} else {
|
|
|
325 |
this.config.copyAttributes = [];
|
|
|
326 |
}
|
|
|
327 |
|
|
|
328 |
this.config.copyAttributes.forEach(function (attr) {
|
|
|
329 |
_this2.config._attributes[attr] = $(_this2.element).attr(attr);
|
|
|
330 |
});
|
|
|
331 |
}
|
|
|
332 |
/**
|
|
|
333 |
* Custom event listeners for popouts and singletons
|
|
|
334 |
* @private
|
|
|
335 |
*/
|
|
|
336 |
;
|
|
|
337 |
|
|
|
338 |
_proto._setConfirmationListeners = function _setConfirmationListeners() {
|
|
|
339 |
var self = this;
|
|
|
340 |
|
|
|
341 |
if (!this.config.selector) {
|
|
|
342 |
// cancel original event
|
|
|
343 |
$(this.element).on(this.config.trigger, function (e, ack) {
|
|
|
344 |
if (!ack) {
|
|
|
345 |
e.preventDefault();
|
|
|
346 |
e.stopPropagation();
|
|
|
347 |
e.stopImmediatePropagation();
|
|
|
348 |
}
|
|
|
349 |
}); // manage singleton
|
|
|
350 |
|
|
|
351 |
$(this.element).on(Event.SHOWN, function () {
|
|
|
352 |
if (self.config.singleton) {
|
|
|
353 |
// close all other popover already initialized
|
|
|
354 |
$(self.config._selector).not($(this)).filter(function () {
|
|
|
355 |
return $(this).data(DATA_KEY) !== undefined;
|
|
|
356 |
}).confirmation('hide');
|
|
|
357 |
}
|
|
|
358 |
});
|
|
|
359 |
} else {
|
|
|
360 |
// cancel original event
|
|
|
361 |
$(this.element).on(this.config.trigger, this.config.selector, function (e, ack) {
|
|
|
362 |
if (!ack) {
|
|
|
363 |
e.preventDefault();
|
|
|
364 |
e.stopPropagation();
|
|
|
365 |
e.stopImmediatePropagation();
|
|
|
366 |
}
|
|
|
367 |
});
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
if (!this._isDelegate) {
|
|
|
371 |
// manage popout
|
|
|
372 |
this.eventBody = false;
|
|
|
373 |
this.uid = this.element.id || Confirmation.getUID(NAME + "_group");
|
|
|
374 |
$(this.element).on(Event.SHOWN, function () {
|
|
|
375 |
if (self.config.popout && !self.eventBody) {
|
|
|
376 |
self.eventBody = $('body').on(Event.CLICK + "." + self.uid, function (e) {
|
|
|
377 |
if ($(self.config._selector).is(e.target) || $(self.config._selector).has(e.target).length > 0) {
|
|
|
378 |
return;
|
|
|
379 |
} // close all popover already initialized
|
|
|
380 |
|
|
|
381 |
|
|
|
382 |
$(self.config._selector).filter(function () {
|
|
|
383 |
return $(this).data(DATA_KEY) !== undefined;
|
|
|
384 |
}).confirmation('hide');
|
|
|
385 |
$('body').off(Event.CLICK + "." + self.uid);
|
|
|
386 |
self.eventBody = false;
|
|
|
387 |
});
|
|
|
388 |
}
|
|
|
389 |
});
|
|
|
390 |
}
|
|
|
391 |
}
|
|
|
392 |
/**
|
|
|
393 |
* Init the standard ok/cancel buttons
|
|
|
394 |
* @param $tip
|
|
|
395 |
* @private
|
|
|
396 |
*/
|
|
|
397 |
;
|
|
|
398 |
|
|
|
399 |
_proto._setStandardButtons = function _setStandardButtons($tip) {
|
|
|
400 |
var buttons = [{
|
|
|
401 |
class: this.config.btnOkClass,
|
|
|
402 |
label: this.config.btnOkLabel,
|
|
|
403 |
iconClass: this.config.btnOkIconClass,
|
|
|
404 |
iconContent: this.config.btnOkIconContent,
|
|
|
405 |
attr: this.config._attributes
|
|
|
406 |
}, {
|
|
|
407 |
class: this.config.btnCancelClass,
|
|
|
408 |
label: this.config.btnCancelLabel,
|
|
|
409 |
iconClass: this.config.btnCancelIconClass,
|
|
|
410 |
iconContent: this.config.btnCancelIconContent,
|
|
|
411 |
cancel: true
|
|
|
412 |
}];
|
|
|
413 |
|
|
|
414 |
this._setButtons($tip, buttons);
|
|
|
415 |
}
|
|
|
416 |
/**
|
|
|
417 |
* Init the buttons
|
|
|
418 |
* @param $tip
|
|
|
419 |
* @param buttons
|
|
|
420 |
* @private
|
|
|
421 |
*/
|
|
|
422 |
;
|
|
|
423 |
|
|
|
424 |
_proto._setButtons = function _setButtons($tip, buttons) {
|
|
|
425 |
var self = this;
|
|
|
426 |
var $group = $tip.find(Selector.BUTTONS).empty();
|
|
|
427 |
buttons.forEach(function (button) {
|
|
|
428 |
var btn = $('<a href="#"></a>').addClass(BTN_CLASS_BASE).addClass(button.class || BTN_CLASS_DEFAULT + " btn-secondary").html(button.label || '').attr(button.attr || {});
|
|
|
429 |
|
|
|
430 |
if (button.iconClass || button.iconContent) {
|
|
|
431 |
btn.prepend($('<i></i>').addClass(button.iconClass || '').text(button.iconContent || ''));
|
|
|
432 |
}
|
|
|
433 |
|
|
|
434 |
btn.one('click', function (e) {
|
|
|
435 |
if ($(this).attr('href') === '#') {
|
|
|
436 |
e.preventDefault();
|
|
|
437 |
}
|
|
|
438 |
|
|
|
439 |
if (button.onClick) {
|
|
|
440 |
button.onClick.call($(self.element));
|
|
|
441 |
}
|
|
|
442 |
|
|
|
443 |
if (button.cancel) {
|
|
|
444 |
self.config.onCancel.call(self.element, button.value);
|
|
|
445 |
$(self.element).trigger(Event.CANCELED, [button.value]);
|
|
|
446 |
} else {
|
|
|
447 |
self.config.onConfirm.call(self.element, button.value);
|
|
|
448 |
$(self.element).trigger(Event.CONFIRMED, [button.value]);
|
|
|
449 |
$(self.element).trigger(self.config.confirmationEvent, [true]);
|
|
|
450 |
}
|
|
|
451 |
|
|
|
452 |
self.hide();
|
|
|
453 |
});
|
|
|
454 |
$group.append(btn);
|
|
|
455 |
});
|
|
|
456 |
}
|
|
|
457 |
/**
|
|
|
458 |
* Install the keyboatd event handler
|
|
|
459 |
* @private
|
|
|
460 |
*/
|
|
|
461 |
;
|
|
|
462 |
|
|
|
463 |
_proto._setupKeyupEvent = function _setupKeyupEvent() {
|
|
|
464 |
activeConfirmation = this;
|
|
|
465 |
$(window).off(Event.KEYUP).on(Event.KEYUP, this._onKeyup.bind(this));
|
|
|
466 |
}
|
|
|
467 |
/**
|
|
|
468 |
* Remove the keyboard event handler
|
|
|
469 |
* @private
|
|
|
470 |
*/
|
|
|
471 |
;
|
|
|
472 |
|
|
|
473 |
_proto._cleanKeyupEvent = function _cleanKeyupEvent() {
|
|
|
474 |
if (activeConfirmation === this) {
|
|
|
475 |
activeConfirmation = undefined;
|
|
|
476 |
$(window).off(Event.KEYUP);
|
|
|
477 |
}
|
|
|
478 |
}
|
|
|
479 |
/**
|
|
|
480 |
* Event handler for keyboard navigation
|
|
|
481 |
* @param event
|
|
|
482 |
* @private
|
|
|
483 |
*/
|
|
|
484 |
;
|
|
|
485 |
|
|
|
486 |
_proto._onKeyup = function _onKeyup(event) {
|
|
|
487 |
if (!this.tip) {
|
|
|
488 |
this._cleanKeyupEvent();
|
|
|
489 |
|
|
|
490 |
return;
|
|
|
491 |
}
|
|
|
492 |
|
|
|
493 |
var $tip = $(this.getTipElement());
|
|
|
494 |
var key = event.key || Keymap[event.keyCode || event.which];
|
|
|
495 |
var $group = $tip.find(Selector.BUTTONS);
|
|
|
496 |
var $active = $group.find('.active');
|
|
|
497 |
var $next;
|
|
|
498 |
|
|
|
499 |
switch (key) {
|
|
|
500 |
case 'Escape':
|
|
|
501 |
this.hide();
|
|
|
502 |
break;
|
|
|
503 |
|
|
|
504 |
case 'ArrowRight':
|
|
|
505 |
if ($active.length && $active.next().length) {
|
|
|
506 |
$next = $active.next();
|
|
|
507 |
} else {
|
|
|
508 |
$next = $group.children().first();
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
$active.removeClass('active');
|
|
|
512 |
$next.addClass('active').focus();
|
|
|
513 |
break;
|
|
|
514 |
|
|
|
515 |
case 'ArrowLeft':
|
|
|
516 |
if ($active.length && $active.prev().length) {
|
|
|
517 |
$next = $active.prev();
|
|
|
518 |
} else {
|
|
|
519 |
$next = $group.children().last();
|
|
|
520 |
}
|
|
|
521 |
|
|
|
522 |
$active.removeClass('active');
|
|
|
523 |
$next.addClass('active').focus();
|
|
|
524 |
break;
|
|
|
525 |
|
|
|
526 |
default:
|
|
|
527 |
break;
|
|
|
528 |
}
|
|
|
529 |
} // Static
|
|
|
530 |
|
|
|
531 |
/**
|
|
|
532 |
* Generates an uui, copied from Bootrap's utils
|
|
|
533 |
* @param {string} prefix
|
|
|
534 |
* @returns {string}
|
|
|
535 |
*/
|
|
|
536 |
;
|
|
|
537 |
|
|
|
538 |
Confirmation.getUID = function getUID(prefix) {
|
|
|
539 |
var uid = prefix;
|
|
|
540 |
|
|
|
541 |
do {
|
|
|
542 |
// eslint-disable-next-line no-bitwise
|
|
|
543 |
uid += ~~(Math.random() * 1000000); // "~~" acts like a faster Math.floor() here
|
|
|
544 |
} while (document.getElementById(uid));
|
|
|
545 |
|
|
|
546 |
return uid;
|
|
|
547 |
};
|
|
|
548 |
|
|
|
549 |
Confirmation._jQueryInterface = function _jQueryInterface(config) {
|
|
|
550 |
return this.each(function () {
|
|
|
551 |
var data = $(this).data(DATA_KEY);
|
|
|
552 |
|
|
|
553 |
var _config = typeof config === 'object' ? config : {};
|
|
|
554 |
|
|
|
555 |
_config.rootSelector = $(this).selector || _config.rootSelector; // this.selector removed in jQuery > 3
|
|
|
556 |
|
|
|
557 |
if (!data && /destroy|hide/.test(config)) {
|
|
|
558 |
return;
|
|
|
559 |
}
|
|
|
560 |
|
|
|
561 |
if (!data) {
|
|
|
562 |
data = new Confirmation(this, _config);
|
|
|
563 |
$(this).data(DATA_KEY, data);
|
|
|
564 |
}
|
|
|
565 |
|
|
|
566 |
if (typeof config === 'string') {
|
|
|
567 |
if (typeof data[config] === 'undefined') {
|
|
|
568 |
throw new TypeError("No method named \"" + config + "\"");
|
|
|
569 |
}
|
|
|
570 |
|
|
|
571 |
data[config]();
|
|
|
572 |
}
|
|
|
573 |
});
|
|
|
574 |
};
|
|
|
575 |
|
|
|
576 |
return Confirmation;
|
|
|
577 |
}(Popover);
|
|
|
578 |
/**
|
|
|
579 |
* ------------------------------------------------------------------------
|
|
|
580 |
* jQuery
|
|
|
581 |
* ------------------------------------------------------------------------
|
|
|
582 |
*/
|
|
|
583 |
|
|
|
584 |
|
|
|
585 |
$.fn[NAME] = Confirmation._jQueryInterface;
|
|
|
586 |
$.fn[NAME].Constructor = Confirmation;
|
|
|
587 |
|
|
|
588 |
$.fn[NAME].noConflict = function () {
|
|
|
589 |
$.fn[NAME] = JQUERY_NO_CONFLICT;
|
|
|
590 |
return Confirmation._jQueryInterface;
|
|
|
591 |
};
|
|
|
592 |
|
|
|
593 |
}));
|
|
|
594 |
//# sourceMappingURL=bootstrap-confirmation.js.map
|