modal.js 16 KB
Newer Older
Mark Otto's avatar
grunt    
Mark Otto committed
1
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; };
2

Mark Otto's avatar
grunt    
Mark Otto committed
3
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; }; }();
4

Mark Otto's avatar
grunt    
Mark Otto committed
5
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7
8

/**
 * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
9
 * Bootstrap (v4.0.0-alpha.6): modal.js
10
11
12
13
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

Mark Otto's avatar
grunt    
Mark Otto committed
14
var Modal = function ($) {
15
16
17
18
19
20
21
22

  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'modal';
Mark Otto's avatar
Mark Otto committed
23
  var VERSION = '4.0.0-alpha.6';
24
  var DATA_KEY = 'bs.modal';
fat's avatar
fat committed
25
26
  var EVENT_KEY = '.' + DATA_KEY;
  var DATA_API_KEY = '.data-api';
27
28
29
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  var TRANSITION_DURATION = 300;
  var BACKDROP_TRANSITION_DURATION = 150;
Chris Rebert's avatar
grunt    
Chris Rebert committed
30
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
31
32
33
34

  var Default = {
    backdrop: true,
    keyboard: true,
fat's avatar
fat committed
35
    focus: true,
36
37
38
    show: true
  };

fat's avatar
fat committed
39
40
41
42
43
44
45
  var DefaultType = {
    backdrop: '(boolean|string)',
    keyboard: 'boolean',
    focus: 'boolean',
    show: 'boolean'
  };

46
  var Event = {
fat's avatar
fat committed
47
48
49
50
51
52
53
54
55
56
    HIDE: 'hide' + EVENT_KEY,
    HIDDEN: 'hidden' + EVENT_KEY,
    SHOW: 'show' + EVENT_KEY,
    SHOWN: 'shown' + EVENT_KEY,
    FOCUSIN: 'focusin' + EVENT_KEY,
    RESIZE: 'resize' + EVENT_KEY,
    CLICK_DISMISS: 'click.dismiss' + EVENT_KEY,
    KEYDOWN_DISMISS: 'keydown.dismiss' + EVENT_KEY,
    MOUSEUP_DISMISS: 'mouseup.dismiss' + EVENT_KEY,
    MOUSEDOWN_DISMISS: 'mousedown.dismiss' + EVENT_KEY,
Jacob Thornton's avatar
Jacob Thornton committed
57
    CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
58
59
60
  };

  var ClassName = {
61
    SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
62
63
64
    BACKDROP: 'modal-backdrop',
    OPEN: 'modal-open',
    FADE: 'fade',
Mark Otto's avatar
grunt    
Mark Otto committed
65
    SHOW: 'show'
66
67
68
69
70
71
  };

  var Selector = {
    DIALOG: '.modal-dialog',
    DATA_TOGGLE: '[data-toggle="modal"]',
    DATA_DISMISS: '[data-dismiss="modal"]',
Mark Otto's avatar
grunt    
Mark Otto committed
72
    FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
73
74
75
76
77
78
79
80
  };

  /**
   * ------------------------------------------------------------------------
   * Class Definition
   * ------------------------------------------------------------------------
   */

Mark Otto's avatar
grunt    
Mark Otto committed
81
  var Modal = function () {
82
83
84
    function Modal(element, config) {
      _classCallCheck(this, Modal);

fat's avatar
fat committed
85
      this._config = this._getConfig(config);
86
87
88
89
90
91
      this._element = element;
      this._dialog = $(element).find(Selector.DIALOG)[0];
      this._backdrop = null;
      this._isShown = false;
      this._isBodyOverflowing = false;
      this._ignoreBackdropClick = false;
Mark Otto's avatar
grunt    
Mark Otto committed
92
      this._isTransitioning = false;
93
94
95
96
      this._originalBodyPadding = 0;
      this._scrollbarWidth = 0;
    }

Jacob Thornton's avatar
Jacob Thornton committed
97
98
    // getters

Mark Otto's avatar
grunt    
Mark Otto committed
99
    // public
100

Mark Otto's avatar
grunt    
Mark Otto committed
101
102
103
    Modal.prototype.toggle = function toggle(relatedTarget) {
      return this._isShown ? this.hide() : this.show(relatedTarget);
    };
104

Mark Otto's avatar
grunt    
Mark Otto committed
105
106
    Modal.prototype.show = function show(relatedTarget) {
      var _this = this;
107

Mark Otto's avatar
grunt    
Mark Otto committed
108
109
110
111
112
113
114
      if (this._isTransitioning) {
        throw new Error('Modal is transitioning');
      }

      if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
        this._isTransitioning = true;
      }
Mark Otto's avatar
grunt    
Mark Otto committed
115
116
117
      var showEvent = $.Event(Event.SHOW, {
        relatedTarget: relatedTarget
      });
118

Mark Otto's avatar
grunt    
Mark Otto committed
119
      $(this._element).trigger(showEvent);
120

Mark Otto's avatar
grunt    
Mark Otto committed
121
122
123
      if (this._isShown || showEvent.isDefaultPrevented()) {
        return;
      }
124

Mark Otto's avatar
grunt    
Mark Otto committed
125
      this._isShown = true;
126

Mark Otto's avatar
grunt    
Mark Otto committed
127
128
      this._checkScrollbar();
      this._setScrollbar();
129

Mark Otto's avatar
grunt    
Mark Otto committed
130
      $(document.body).addClass(ClassName.OPEN);
131

Mark Otto's avatar
grunt    
Mark Otto committed
132
133
      this._setEscapeEvent();
      this._setResizeEvent();
134

Mark Otto's avatar
grunt    
Mark Otto committed
135
136
137
      $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) {
        return _this.hide(event);
      });
138

Mark Otto's avatar
grunt    
Mark Otto committed
139
140
141
142
143
      $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () {
        $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) {
          if ($(event.target).is(_this._element)) {
            _this._ignoreBackdropClick = true;
          }
144
        });
Mark Otto's avatar
grunt    
Mark Otto committed
145
146
      });

Mark Otto's avatar
grunt    
Mark Otto committed
147
148
149
      this._showBackdrop(function () {
        return _this._showElement(relatedTarget);
      });
Mark Otto's avatar
grunt    
Mark Otto committed
150
    };
151

Mark Otto's avatar
grunt    
Mark Otto committed
152
    Modal.prototype.hide = function hide(event) {
Mark Otto's avatar
grunt    
Mark Otto committed
153
154
      var _this2 = this;

Mark Otto's avatar
grunt    
Mark Otto committed
155
156
      if (event) {
        event.preventDefault();
157
158
      }

Mark Otto's avatar
grunt    
Mark Otto committed
159
160
161
162
163
164
165
166
      if (this._isTransitioning) {
        throw new Error('Modal is transitioning');
      }

      var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE);
      if (transition) {
        this._isTransitioning = true;
      }
167

Mark Otto's avatar
grunt    
Mark Otto committed
168
      var hideEvent = $.Event(Event.HIDE);
Mark Otto's avatar
grunt    
Mark Otto committed
169
      $(this._element).trigger(hideEvent);
170

Mark Otto's avatar
grunt    
Mark Otto committed
171
172
173
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
        return;
      }
174

Mark Otto's avatar
grunt    
Mark Otto committed
175
      this._isShown = false;
176

Mark Otto's avatar
grunt    
Mark Otto committed
177
178
      this._setEscapeEvent();
      this._setResizeEvent();
179

Mark Otto's avatar
grunt    
Mark Otto committed
180
      $(document).off(Event.FOCUSIN);
181

Mark Otto's avatar
grunt    
Mark Otto committed
182
      $(this._element).removeClass(ClassName.SHOW);
183

Mark Otto's avatar
grunt    
Mark Otto committed
184
185
      $(this._element).off(Event.CLICK_DISMISS);
      $(this._dialog).off(Event.MOUSEDOWN_DISMISS);
186

Mark Otto's avatar
grunt    
Mark Otto committed
187
      if (transition) {
Mark Otto's avatar
grunt    
Mark Otto committed
188
189
190
        $(this._element).one(Util.TRANSITION_END, function (event) {
          return _this2._hideModal(event);
        }).emulateTransitionEnd(TRANSITION_DURATION);
Mark Otto's avatar
grunt    
Mark Otto committed
191
192
      } else {
        this._hideModal();
fat's avatar
fat committed
193
      }
Mark Otto's avatar
grunt    
Mark Otto committed
194
    };
195

Mark Otto's avatar
grunt    
Mark Otto committed
196
197
    Modal.prototype.dispose = function dispose() {
      $.removeData(this._element, DATA_KEY);
198

Mark Otto's avatar
grunt    
Mark Otto committed
199
      $(window, document, this._element, this._backdrop).off(EVENT_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220

      this._config = null;
      this._element = null;
      this._dialog = null;
      this._backdrop = null;
      this._isShown = null;
      this._isBodyOverflowing = null;
      this._ignoreBackdropClick = null;
      this._originalBodyPadding = null;
      this._scrollbarWidth = null;
    };

    // private

    Modal.prototype._getConfig = function _getConfig(config) {
      config = $.extend({}, Default, config);
      Util.typeCheckConfig(NAME, config, DefaultType);
      return config;
    };

    Modal.prototype._showElement = function _showElement(relatedTarget) {
Mark Otto's avatar
grunt    
Mark Otto committed
221
      var _this3 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
222
223
224
225
226
227

      var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE);

      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
        // don't move modals dom position
        document.body.appendChild(this._element);
fat's avatar
fat committed
228
      }
229

Mark Otto's avatar
grunt    
Mark Otto committed
230
231
232
      this._element.style.display = 'block';
      this._element.removeAttribute('aria-hidden');
      this._element.scrollTop = 0;
233

Mark Otto's avatar
grunt    
Mark Otto committed
234
235
236
      if (transition) {
        Util.reflow(this._element);
      }
237

Mark Otto's avatar
grunt    
Mark Otto committed
238
      $(this._element).addClass(ClassName.SHOW);
239

Mark Otto's avatar
grunt    
Mark Otto committed
240
241
242
      if (this._config.focus) {
        this._enforceFocus();
      }
243

Mark Otto's avatar
grunt    
Mark Otto committed
244
245
246
      var shownEvent = $.Event(Event.SHOWN, {
        relatedTarget: relatedTarget
      });
247

Mark Otto's avatar
grunt    
Mark Otto committed
248
      var transitionComplete = function transitionComplete() {
Mark Otto's avatar
grunt    
Mark Otto committed
249
250
        if (_this3._config.focus) {
          _this3._element.focus();
Mark Otto's avatar
Mark Otto committed
251
        }
Mark Otto's avatar
grunt    
Mark Otto committed
252
        _this3._isTransitioning = false;
Mark Otto's avatar
grunt    
Mark Otto committed
253
        $(_this3._element).trigger(shownEvent);
Mark Otto's avatar
grunt    
Mark Otto committed
254
      };
255

Mark Otto's avatar
grunt    
Mark Otto committed
256
257
258
259
260
261
      if (transition) {
        $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(TRANSITION_DURATION);
      } else {
        transitionComplete();
      }
    };
262

Mark Otto's avatar
grunt    
Mark Otto committed
263
    Modal.prototype._enforceFocus = function _enforceFocus() {
Mark Otto's avatar
grunt    
Mark Otto committed
264
      var _this4 = this;
265

Mark Otto's avatar
grunt    
Mark Otto committed
266
267
      $(document).off(Event.FOCUSIN) // guard against infinite focus loop
      .on(Event.FOCUSIN, function (event) {
Mark Otto's avatar
grunt    
Mark Otto committed
268
269
        if (document !== event.target && _this4._element !== event.target && !$(_this4._element).has(event.target).length) {
          _this4._element.focus();
270
        }
Mark Otto's avatar
grunt    
Mark Otto committed
271
272
273
274
      });
    };

    Modal.prototype._setEscapeEvent = function _setEscapeEvent() {
Mark Otto's avatar
grunt    
Mark Otto committed
275
      var _this5 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
276
277
278
279

      if (this._isShown && this._config.keyboard) {
        $(this._element).on(Event.KEYDOWN_DISMISS, function (event) {
          if (event.which === ESCAPE_KEYCODE) {
Mark Otto's avatar
grunt    
Mark Otto committed
280
            _this5.hide();
281
282
          }
        });
Mark Otto's avatar
grunt    
Mark Otto committed
283
284
      } else if (!this._isShown) {
        $(this._element).off(Event.KEYDOWN_DISMISS);
285
      }
Mark Otto's avatar
grunt    
Mark Otto committed
286
287
288
    };

    Modal.prototype._setResizeEvent = function _setResizeEvent() {
Mark Otto's avatar
grunt    
Mark Otto committed
289
290
      var _this6 = this;

Mark Otto's avatar
grunt    
Mark Otto committed
291
      if (this._isShown) {
Mark Otto's avatar
grunt    
Mark Otto committed
292
293
294
        $(window).on(Event.RESIZE, function (event) {
          return _this6._handleUpdate(event);
        });
Mark Otto's avatar
grunt    
Mark Otto committed
295
296
      } else {
        $(window).off(Event.RESIZE);
297
      }
Mark Otto's avatar
grunt    
Mark Otto committed
298
299
300
    };

    Modal.prototype._hideModal = function _hideModal() {
Mark Otto's avatar
grunt    
Mark Otto committed
301
      var _this7 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
302
303

      this._element.style.display = 'none';
Mark Otto's avatar
grunt    
Mark Otto committed
304
305
      this._element.setAttribute('aria-hidden', 'true');
      this._isTransitioning = false;
Mark Otto's avatar
grunt    
Mark Otto committed
306
307
      this._showBackdrop(function () {
        $(document.body).removeClass(ClassName.OPEN);
Mark Otto's avatar
grunt    
Mark Otto committed
308
309
310
        _this7._resetAdjustments();
        _this7._resetScrollbar();
        $(_this7._element).trigger(Event.HIDDEN);
Mark Otto's avatar
grunt    
Mark Otto committed
311
312
313
314
315
316
317
      });
    };

    Modal.prototype._removeBackdrop = function _removeBackdrop() {
      if (this._backdrop) {
        $(this._backdrop).remove();
        this._backdrop = null;
318
      }
Mark Otto's avatar
grunt    
Mark Otto committed
319
    };
320

Mark Otto's avatar
grunt    
Mark Otto committed
321
    Modal.prototype._showBackdrop = function _showBackdrop(callback) {
Mark Otto's avatar
grunt    
Mark Otto committed
322
      var _this8 = this;
323

Mark Otto's avatar
grunt    
Mark Otto committed
324
      var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : '';
325

Mark Otto's avatar
grunt    
Mark Otto committed
326
327
      if (this._isShown && this._config.backdrop) {
        var doAnimate = Util.supportsTransitionEnd() && animate;
328

Mark Otto's avatar
grunt    
Mark Otto committed
329
330
        this._backdrop = document.createElement('div');
        this._backdrop.className = ClassName.BACKDROP;
331

Mark Otto's avatar
grunt    
Mark Otto committed
332
333
334
        if (animate) {
          $(this._backdrop).addClass(animate);
        }
335

Mark Otto's avatar
grunt    
Mark Otto committed
336
        $(this._backdrop).appendTo(document.body);
337

Mark Otto's avatar
grunt    
Mark Otto committed
338
        $(this._element).on(Event.CLICK_DISMISS, function (event) {
Mark Otto's avatar
grunt    
Mark Otto committed
339
340
          if (_this8._ignoreBackdropClick) {
            _this8._ignoreBackdropClick = false;
341
342
            return;
          }
Mark Otto's avatar
grunt    
Mark Otto committed
343
          if (event.target !== event.currentTarget) {
344
345
            return;
          }
Mark Otto's avatar
grunt    
Mark Otto committed
346
347
          if (_this8._config.backdrop === 'static') {
            _this8._element.focus();
348
          } else {
Mark Otto's avatar
grunt    
Mark Otto committed
349
            _this8.hide();
350
          }
Mark Otto's avatar
grunt    
Mark Otto committed
351
        });
352

Mark Otto's avatar
grunt    
Mark Otto committed
353
354
355
        if (doAnimate) {
          Util.reflow(this._backdrop);
        }
356

Mark Otto's avatar
grunt    
Mark Otto committed
357
        $(this._backdrop).addClass(ClassName.SHOW);
358

Mark Otto's avatar
grunt    
Mark Otto committed
359
360
        if (!callback) {
          return;
361
362
        }

Mark Otto's avatar
grunt    
Mark Otto committed
363
364
365
        if (!doAnimate) {
          callback();
          return;
366
367
        }

Mark Otto's avatar
grunt    
Mark Otto committed
368
369
        $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
      } else if (!this._isShown && this._backdrop) {
Mark Otto's avatar
grunt    
Mark Otto committed
370
        $(this._backdrop).removeClass(ClassName.SHOW);
371

Mark Otto's avatar
grunt    
Mark Otto committed
372
        var callbackRemove = function callbackRemove() {
Mark Otto's avatar
grunt    
Mark Otto committed
373
          _this8._removeBackdrop();
Mark Otto's avatar
grunt    
Mark Otto committed
374
375
376
377
378
379
380
381
382
          if (callback) {
            callback();
          }
        };

        if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
          $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
        } else {
          callbackRemove();
383
        }
Mark Otto's avatar
grunt    
Mark Otto committed
384
385
      } else if (callback) {
        callback();
386
      }
Mark Otto's avatar
grunt    
Mark Otto committed
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
    };

    // ----------------------------------------------------------------------
    // the following methods are used to handle overflowing modals
    // todo (fat): these should probably be refactored out of modal.js
    // ----------------------------------------------------------------------

    Modal.prototype._handleUpdate = function _handleUpdate() {
      this._adjustDialog();
    };

    Modal.prototype._adjustDialog = function _adjustDialog() {
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;

      if (!this._isBodyOverflowing && isModalOverflowing) {
        this._element.style.paddingLeft = this._scrollbarWidth + 'px';
403
      }
Mark Otto's avatar
grunt    
Mark Otto committed
404
405
406

      if (this._isBodyOverflowing && !isModalOverflowing) {
        this._element.style.paddingRight = this._scrollbarWidth + 'px';
407
      }
Mark Otto's avatar
grunt    
Mark Otto committed
408
    };
409

Mark Otto's avatar
grunt    
Mark Otto committed
410
411
412
413
    Modal.prototype._resetAdjustments = function _resetAdjustments() {
      this._element.style.paddingLeft = '';
      this._element.style.paddingRight = '';
    };
414

Mark Otto's avatar
grunt    
Mark Otto committed
415
416
417
418
    Modal.prototype._checkScrollbar = function _checkScrollbar() {
      this._isBodyOverflowing = document.body.clientWidth < window.innerWidth;
      this._scrollbarWidth = this._getScrollbarWidth();
    };
419

Mark Otto's avatar
grunt    
Mark Otto committed
420
421
    Modal.prototype._setScrollbar = function _setScrollbar() {
      var bodyPadding = parseInt($(Selector.FIXED_CONTENT).css('padding-right') || 0, 10);
422

Mark Otto's avatar
grunt    
Mark Otto committed
423
424
425
426
      this._originalBodyPadding = document.body.style.paddingRight || '';

      if (this._isBodyOverflowing) {
        document.body.style.paddingRight = bodyPadding + this._scrollbarWidth + 'px';
427
      }
Mark Otto's avatar
grunt    
Mark Otto committed
428
429
430
431
432
433
434
435
436
437
438
    };

    Modal.prototype._resetScrollbar = function _resetScrollbar() {
      document.body.style.paddingRight = this._originalBodyPadding;
    };

    Modal.prototype._getScrollbarWidth = function _getScrollbarWidth() {
      // thx d.walsh
      var scrollDiv = document.createElement('div');
      scrollDiv.className = ClassName.SCROLLBAR_MEASURER;
      document.body.appendChild(scrollDiv);
Mark Otto's avatar
grunt    
Mark Otto committed
439
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
Mark Otto's avatar
grunt    
Mark Otto committed
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
      document.body.removeChild(scrollDiv);
      return scrollbarWidth;
    };

    // static

    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
        var _config = $.extend({}, Modal.Default, $(this).data(), (typeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config);

        if (!data) {
          data = new Modal(this, _config);
          $(this).data(DATA_KEY, data);
        }

        if (typeof config === 'string') {
          if (data[config] === undefined) {
            throw new Error('No method named "' + config + '"');
          }
          data[config](relatedTarget);
        } else if (_config.show) {
          data.show(relatedTarget);
        }
      });
    };

    _createClass(Modal, null, [{
Jacob Thornton's avatar
Jacob Thornton committed
468
469
470
471
472
473
474
475
476
      key: 'VERSION',
      get: function get() {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function get() {
        return Default;
      }
477
478
479
    }]);

    return Modal;
Mark Otto's avatar
grunt    
Mark Otto committed
480
481
482
483
484
485
486
  }();

  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
487

fat's avatar
fat committed
488
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
Mark Otto's avatar
grunt    
Mark Otto committed
489
    var _this9 = this;
490

Mark Otto's avatar
grunt    
Mark Otto committed
491
    var target = void 0;
492
493
494
495
496
497
498
499
    var selector = Util.getSelectorFromElement(this);

    if (selector) {
      target = $(selector)[0];
    }

    var config = $(target).data(DATA_KEY) ? 'toggle' : $.extend({}, $(target).data(), $(this).data());

Mark Otto's avatar
grunt    
Mark Otto committed
500
    if (this.tagName === 'A' || this.tagName === 'AREA') {
501
502
503
504
505
506
507
508
509
510
      event.preventDefault();
    }

    var $target = $(target).one(Event.SHOW, function (showEvent) {
      if (showEvent.isDefaultPrevented()) {
        // only register focus restorer if modal will actually get shown
        return;
      }

      $target.one(Event.HIDDEN, function () {
Mark Otto's avatar
grunt    
Mark Otto committed
511
512
        if ($(_this9).is(':visible')) {
          _this9.focus();
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
        }
      });
    });

    Modal._jQueryInterface.call($(target), config, this);
  });

  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */

  $.fn[NAME] = Modal._jQueryInterface;
  $.fn[NAME].Constructor = Modal;
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Modal._jQueryInterface;
  };

  return Modal;
Mark Otto's avatar
grunt    
Mark Otto committed
534
}(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
535
//# sourceMappingURL=modal.js.map