bootstrap.js 98.2 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
3001
3002
3003
3004
3005

          this.setContent();

          if (this.config.animation) {
            $(tip).addClass(ClassName.FADE);
Jacob Thornton's avatar
Jacob Thornton committed
3006
          }
Jacob Thornton's avatar
Jacob Thornton committed
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016

          var placement = typeof this.config.placement === 'function' ? this.config.placement.call(this, tip, this.element) : this.config.placement;

          var attachment = this._getAttachment(placement);

          $(tip).data(this.constructor.DATA_KEY, this).appendTo(document.body);

          $(this.element).trigger(this.constructor.Event.INSERTED);

          this._tether = new Tether({
Jacob Thornton's avatar
Jacob Thornton committed
3017
            attachment: attachment,
Jacob Thornton's avatar
Jacob Thornton committed
3018
3019
3020
3021
3022
            element: tip,
            target: this.element,
            classes: TetherClass,
            classPrefix: CLASS_PREFIX,
            offset: this.config.offset,
3023
3024
            constraints: this.config.constraints,
            addTargetClasses: false
Jacob Thornton's avatar
Jacob Thornton committed
3025
          });
Jacob Thornton's avatar
Jacob Thornton committed
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039

          Util.reflow(tip);
          this._tether.position();

          $(tip).addClass(ClassName.IN);

          var complete = function complete() {
            var prevHoverState = _this16._hoverState;
            _this16._hoverState = null;

            $(_this16.element).trigger(_this16.constructor.Event.SHOWN);

            if (prevHoverState === HoverState.OUT) {
              _this16._leave(null, _this16);
Jacob Thornton's avatar
Jacob Thornton committed
3040
            }
Jacob Thornton's avatar
Jacob Thornton committed
3041
3042
          };

Jacob Thornton's avatar
Jacob Thornton committed
3043
3044
3045
3046
3047
3048
          if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
            $(this.tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(Tooltip._TRANSITION_DURATION);
            return;
          }

          complete();
Jacob Thornton's avatar
Jacob Thornton committed
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
        }
      }
    }, {
      key: 'hide',
      value: function hide(callback) {
        var _this17 = this;

        var tip = this.getTipElement();
        var hideEvent = $.Event(this.constructor.Event.HIDE);
        var complete = function complete() {
          if (_this17._hoverState !== HoverState.IN && tip.parentNode) {
            tip.parentNode.removeChild(tip);
Jacob Thornton's avatar
Jacob Thornton committed
3061
          }
Jacob Thornton's avatar
Jacob Thornton committed
3062
3063
3064
3065
3066
3067
3068

          _this17.element.removeAttribute('aria-describedby');
          $(_this17.element).trigger(_this17.constructor.Event.HIDDEN);
          _this17.cleanupTether();

          if (callback) {
            callback();
Jacob Thornton's avatar
Jacob Thornton committed
3069
          }
Jacob Thornton's avatar
Jacob Thornton committed
3070
3071
3072
3073
3074
        };

        $(this.element).trigger(hideEvent);

        if (hideEvent.isDefaultPrevented()) {
Jacob Thornton's avatar
Jacob Thornton committed
3075
          return;
Jacob Thornton's avatar
Jacob Thornton committed
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
        }

        $(tip).removeClass(ClassName.IN);

        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {

          $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
        } else {
          complete();
        }

        this._hoverState = '';
      }

      // protected

    }, {
      key: 'isWithContent',
      value: function isWithContent() {
Jacob Thornton's avatar
Jacob Thornton committed
3095
        return Boolean(this.getTitle());
Jacob Thornton's avatar
Jacob Thornton committed
3096
3097
3098
3099
3100
3101
3102
3103
3104
      }
    }, {
      key: 'getTipElement',
      value: function getTipElement() {
        return this.tip = this.tip || $(this.config.template)[0];
      }
    }, {
      key: 'setContent',
      value: function setContent() {
XhmikosR's avatar
XhmikosR committed
3105
        var $tip = $(this.getTipElement());
Jacob Thornton's avatar
Jacob Thornton committed
3106

XhmikosR's avatar
XhmikosR committed
3107
        this.setElementContent($tip.find(Selector.TOOLTIP_INNER), this.getTitle());
Jacob Thornton's avatar
Jacob Thornton committed
3108

XhmikosR's avatar
XhmikosR committed
3109
        $tip.removeClass(ClassName.FADE).removeClass(ClassName.IN);
Jacob Thornton's avatar
Jacob Thornton committed
3110
3111
3112

        this.cleanupTether();
      }
XhmikosR's avatar
XhmikosR committed
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
    }, {
      key: 'setElementContent',
      value: function setElementContent($element, content) {
        var html = this.config.html;
        if (typeof content === 'object' && (content.nodeType || content.jquery)) {
          // content is a DOM node or a jQuery
          if (html) {
            if (!$(content).parent().is($element)) {
              $element.empty().append(content);
            }
          } else {
            $element.text($(content).text());
          }
        } else {
          $element[html ? 'html' : 'text'](content);
        }
      }
Jacob Thornton's avatar
Jacob Thornton committed
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
    }, {
      key: 'getTitle',
      value: function getTitle() {
        var title = this.element.getAttribute('data-original-title');

        if (!title) {
          title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
        }

        return title;
      }
    }, {
      key: 'cleanupTether',
      value: function cleanupTether() {
        if (this._tether) {
          this._tether.destroy();
        }
      }

      // private

    }, {
      key: '_getAttachment',
      value: function _getAttachment(placement) {
        return AttachmentMap[placement.toUpperCase()];
      }
    }, {
      key: '_setListeners',
      value: function _setListeners() {
        var _this18 = this;

        var triggers = this.config.trigger.split(' ');

        triggers.forEach(function (trigger) {
          if (trigger === 'click') {
            $(_this18.element).on(_this18.constructor.Event.CLICK, _this18.config.selector, $.proxy(_this18.toggle, _this18));
          } else if (trigger !== Trigger.MANUAL) {
Jacob Thornton's avatar
Jacob Thornton committed
3167
3168
            var eventIn = trigger === Trigger.HOVER ? _this18.constructor.Event.MOUSEENTER : _this18.constructor.Event.FOCUSIN;
            var eventOut = trigger === Trigger.HOVER ? _this18.constructor.Event.MOUSELEAVE : _this18.constructor.Event.FOCUSOUT;
Jacob Thornton's avatar
Jacob Thornton committed
3169
3170

            $(_this18.element).on(eventIn, _this18.config.selector, $.proxy(_this18._enter, _this18)).on(eventOut, _this18.config.selector, $.proxy(_this18._leave, _this18));
Jacob Thornton's avatar
Jacob Thornton committed
3171
          }
Jacob Thornton's avatar
Jacob Thornton committed
3172
        });
Jacob Thornton's avatar
Jacob Thornton committed
3173
3174
3175
3176
3177

        if (this.config.selector) {
          this.config = $.extend({}, this.config, {
            trigger: 'manual',
            selector: ''
Jacob Thornton's avatar
Jacob Thornton committed
3178
          });
Jacob Thornton's avatar
Jacob Thornton committed
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
        } else {
          this._fixTitle();
        }
      }
    }, {
      key: '_fixTitle',
      value: function _fixTitle() {
        var titleType = typeof this.element.getAttribute('data-original-title');
        if (this.element.getAttribute('title') || titleType !== 'string') {
          this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '');
          this.element.setAttribute('title', '');
        }
      }
    }, {
      key: '_enter',
      value: function _enter(event, context) {
        var dataKey = this.constructor.DATA_KEY;

        context = context || $(event.currentTarget).data(dataKey);

        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }

        if (event) {
Jacob Thornton's avatar
Jacob Thornton committed
3205
          context._activeTrigger[event.type === 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
Jacob Thornton's avatar
Jacob Thornton committed
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
        }

        if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
          context._hoverState = HoverState.IN;
          return;
        }

        clearTimeout(context._timeout);

        context._hoverState = HoverState.IN;

        if (!context.config.delay || !context.config.delay.show) {
          context.show();
          return;
        }

        context._timeout = setTimeout(function () {
          if (context._hoverState === HoverState.IN) {
            context.show();
Jacob Thornton's avatar
Jacob Thornton committed
3225
          }
Jacob Thornton's avatar
Jacob Thornton committed
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
        }, context.config.delay.show);
      }
    }, {
      key: '_leave',
      value: function _leave(event, context) {
        var dataKey = this.constructor.DATA_KEY;

        context = context || $(event.currentTarget).data(dataKey);

        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }

        if (event) {
Jacob Thornton's avatar
Jacob Thornton committed
3241
          context._activeTrigger[event.type === 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
Jacob Thornton's avatar
Jacob Thornton committed
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
        }

        if (context._isWithActiveTrigger()) {
          return;
        }

        clearTimeout(context._timeout);

        context._hoverState = HoverState.OUT;

        if (!context.config.delay || !context.config.delay.hide) {
          context.hide();
          return;
        }

        context._timeout = setTimeout(function () {
          if (context._hoverState === HoverState.OUT) {
            context.hide();
Jacob Thornton's avatar
Jacob Thornton committed
3260
          }
Jacob Thornton's avatar
Jacob Thornton committed
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
        }, context.config.delay.hide);
      }
    }, {
      key: '_isWithActiveTrigger',
      value: function _isWithActiveTrigger() {
        for (var trigger in this._activeTrigger) {
          if (this._activeTrigger[trigger]) {
            return true;
          }
        }

        return false;
      }
    }, {
      key: '_getConfig',
      value: function _getConfig(config) {
        config = $.extend({}, this.constructor.Default, $(this.element).data(), config);

        if (config.delay && typeof config.delay === 'number') {
          config.delay = {
            show: config.delay,
            hide: config.delay
          };
        }

        Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);

        return config;
      }
    }, {
      key: '_getDelegateConfig',
      value: function _getDelegateConfig() {
        var config = {};

        if (this.config) {
          for (var key in this.config) {
Jacob Thornton's avatar
Jacob Thornton committed
3297
3298
            if (this.constructor.Default[key] !== this.config[key]) {
              config[key] = this.config[key];
Jacob Thornton's avatar
Jacob Thornton committed
3299
            }
Jacob Thornton's avatar
Jacob Thornton committed
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
          }
        }

        return config;
      }

      // static

    }], [{
      key: '_jQueryInterface',
      value: function _jQueryInterface(config) {
        return this.each(function () {
          var data = $(this).data(DATA_KEY);
          var _config = typeof config === 'object' ? config : null;

          if (!data && /destroy|hide/.test(config)) {
Jacob Thornton's avatar
Jacob Thornton committed
3316
            return;
Jacob Thornton's avatar
Jacob Thornton committed
3317
          }
Jacob Thornton's avatar
Jacob Thornton committed
3318
3319
3320
3321

          if (!data) {
            data = new Tooltip(this, _config);
            $(this).data(DATA_KEY, data);
Jacob Thornton's avatar
Jacob Thornton committed
3322
          }
Jacob Thornton's avatar
Jacob Thornton committed
3323
3324

          if (typeof config === 'string') {
Chris Rebert's avatar
Chris Rebert committed
3325
3326
3327
            if (data[config] === undefined) {
              throw new Error('No method named "' + config + '"');
            }
Jacob Thornton's avatar
Jacob Thornton committed
3328
            data[config]();
Jacob Thornton's avatar
Jacob Thornton committed
3329
          }
Jacob Thornton's avatar
Jacob Thornton committed
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
        });
      }
    }, {
      key: 'VERSION',
      get: function get() {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function get() {
        return Default;
      }
    }, {
      key: 'NAME',
      get: function get() {
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
      get: function get() {
        return DATA_KEY;
      }
    }, {
      key: 'Event',
      get: function get() {
        return Event;
      }
    }, {
      key: 'EVENT_KEY',
      get: function get() {
        return EVENT_KEY;
      }
    }, {
      key: 'DefaultType',
      get: function get() {
        return DefaultType;
      }
    }]);

    return Tooltip;
  })();

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

  return Tooltip;
})(jQuery);

/**
 * --------------------------------------------------------------------------
3384
 * Bootstrap (v4.0.0-alpha.2): popover.js
Jacob Thornton's avatar
Jacob Thornton committed
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

var Popover = (function ($) {

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

  var NAME = 'popover';
XhmikosR's avatar
XhmikosR committed
3398
  var VERSION = '4.0.0-alpha.2';
Jacob Thornton's avatar
Jacob Thornton committed
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
  var DATA_KEY = 'bs.popover';
  var EVENT_KEY = '.' + DATA_KEY;
  var JQUERY_NO_CONFLICT = $.fn[NAME];

  var Default = $.extend({}, Tooltip.Default, {
    placement: 'right',
    trigger: 'click',
    content: '',
    template: '<div class="popover" role="tooltip">' + '<div class="popover-arrow"></div>' + '<h3 class="popover-title"></h3>' + '<div class="popover-content"></div></div>'
  });

  var DefaultType = $.extend({}, Tooltip.DefaultType, {
XhmikosR's avatar
XhmikosR committed
3411
    content: '(string|element|function)'
Jacob Thornton's avatar
Jacob Thornton committed
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
  });

  var ClassName = {
    FADE: 'fade',
    IN: 'in'
  };

  var Selector = {
    TITLE: '.popover-title',
    CONTENT: '.popover-content',
    ARROW: '.popover-arrow'
  };

  var Event = {
    HIDE: 'hide' + EVENT_KEY,
    HIDDEN: 'hidden' + EVENT_KEY,
    SHOW: 'show' + EVENT_KEY,
    SHOWN: 'shown' + EVENT_KEY,
    INSERTED: 'inserted' + EVENT_KEY,
    CLICK: 'click' + EVENT_KEY,
    FOCUSIN: 'focusin' + EVENT_KEY,
    FOCUSOUT: 'focusout' + EVENT_KEY,
    MOUSEENTER: 'mouseenter' + EVENT_KEY,
    MOUSELEAVE: 'mouseleave' + EVENT_KEY
  };

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

  var Popover = (function (_Tooltip) {
    _inherits(Popover, _Tooltip);

    function Popover() {
      _classCallCheck(this, Popover);

      _get(Object.getPrototypeOf(Popover.prototype), 'constructor', this).apply(this, arguments);
    }

Jacob Thornton's avatar
Jacob Thornton committed
3453
    /**
Jacob Thornton's avatar
Jacob Thornton committed
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
     * ------------------------------------------------------------------------
     * jQuery
     * ------------------------------------------------------------------------
     */

    _createClass(Popover, [{
      key: 'isWithContent',

      // overrides

      value: function isWithContent() {
        return this.getTitle() || this._getContent();
      }
    }, {
      key: 'getTipElement',
      value: function getTipElement() {
        return this.tip = this.tip || $(this.config.template)[0];
      }
    }, {
      key: 'setContent',
      value: function setContent() {
XhmikosR's avatar
XhmikosR committed
3475
        var $tip = $(this.getTipElement());
Jacob Thornton's avatar
Jacob Thornton committed
3476
3477

        // we use append for html objects to maintain js events
XhmikosR's avatar
XhmikosR committed
3478
3479
        this.setElementContent($tip.find(Selector.TITLE), this.getTitle());
        this.setElementContent($tip.find(Selector.CONTENT), this._getContent());
Jacob Thornton's avatar
Jacob Thornton committed
3480

XhmikosR's avatar
XhmikosR committed
3481
        $tip.removeClass(ClassName.FADE).removeClass(ClassName.IN);
Jacob Thornton's avatar
Jacob Thornton committed
3482
3483
3484
3485
3486
3487
3488
3489
3490

        this.cleanupTether();
      }

      // private

    }, {
      key: '_getContent',
      value: function _getContent() {
Jacob Thornton's avatar
Jacob Thornton committed
3491
        return this.element.getAttribute('data-content') || (typeof this.config.content === 'function' ? this.config.content.call(this.element) : this.config.content);
Jacob Thornton's avatar
Jacob Thornton committed
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
      }

      // static

    }], [{
      key: '_jQueryInterface',
      value: function _jQueryInterface(config) {
        return this.each(function () {
          var data = $(this).data(DATA_KEY);
          var _config = typeof config === 'object' ? config : null;

          if (!data && /destroy|hide/.test(config)) {
Jacob Thornton's avatar
Jacob Thornton committed
3504
3505
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
3506
3507
3508
3509

          if (!data) {
            data = new Popover(this, _config);
            $(this).data(DATA_KEY, data);
Jacob Thornton's avatar
Jacob Thornton committed
3510
          }
Jacob Thornton's avatar
Jacob Thornton committed
3511
3512

          if (typeof config === 'string') {
Chris Rebert's avatar
Chris Rebert committed
3513
3514
3515
            if (data[config] === undefined) {
              throw new Error('No method named "' + config + '"');
            }
Jacob Thornton's avatar
Jacob Thornton committed
3516
            data[config]();
Mark Otto's avatar
grunt    
Mark Otto committed
3517
          }
Jacob Thornton's avatar
Jacob Thornton committed
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
        });
      }
    }, {
      key: 'VERSION',

      // getters

      get: function get() {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function get() {
        return Default;
      }
    }, {
      key: 'NAME',
      get: function get() {
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
      get: function get() {
        return DATA_KEY;
      }
    }, {
      key: 'Event',
      get: function get() {
        return Event;
      }
    }, {
      key: 'EVENT_KEY',
      get: function get() {
        return EVENT_KEY;
      }
    }, {
      key: 'DefaultType',
      get: function get() {
        return DefaultType;
      }
    }]);

    return Popover;
  })(Tooltip);

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

  return Popover;
3571
})(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
3572
3573

}(jQuery);
For faster browsing, not all history is shown. View entire blame