bootstrap.js 94.7 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
3001

3002
        $(tip).removeClass(ClassName.IN);
XhmikosR's avatar
XhmikosR committed
3003

3004
        if (Util.supportsTransitionEnd() && $(this.tip).hasClass(ClassName.FADE)) {
Mark Otto's avatar
Mark Otto committed
3005

3006
3007
3008
3009
          $(tip).one(Util.TRANSITION_END, complete).emulateTransitionEnd(TRANSITION_DURATION);
        } else {
          complete();
        }
Mark Otto's avatar
Mark Otto committed
3010

3011
3012
3013
3014
        this._hoverState = '';
      }
    }, {
      key: 'isWithContent',
Mark Otto's avatar
Mark Otto committed
3015

3016
      // protected
Mark Otto's avatar
Mark Otto committed
3017

3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
      value: function isWithContent() {
        return !!this.getTitle();
      }
    }, {
      key: 'getTipElement',
      value: function getTipElement() {
        return this.tip = this.tip || $(this.config.template)[0];
      }
    }, {
      key: 'setContent',
      value: function setContent() {
        var tip = this.getTipElement();
        var title = this.getTitle();
        var method = this.config.html ? 'innerHTML' : 'innerText';
Mark Otto's avatar
Mark Otto committed
3032

3033
        $(tip).find(Selector.TOOLTIP_INNER)[0][method] = title;
Mark Otto's avatar
Mark Otto committed
3034

3035
        $(tip).removeClass(ClassName.FADE).removeClass(ClassName.IN);
Mark Otto's avatar
Mark Otto committed
3036

3037
3038
3039
3040
3041
3042
        this.cleanupTether();
      }
    }, {
      key: 'getTitle',
      value: function getTitle() {
        var title = this.element.getAttribute('data-original-title');
XhmikosR's avatar
XhmikosR committed
3043

3044
3045
3046
        if (!title) {
          title = typeof this.config.title === 'function' ? this.config.title.call(this.element) : this.config.title;
        }
Mark Otto's avatar
Mark Otto committed
3047

3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
        return title;
      }
    }, {
      key: 'cleanupTether',
      value: function cleanupTether() {
        if (this._tether) {
          this._tether.destroy();

          // clean up after tether's junk classes
          // remove after they fix issue
          // (https://github.com/HubSpot/tether/issues/36)
          $(this.element).removeClass(this._removeTetherClasses);
          $(this.tip).removeClass(this._removeTetherClasses);
        }
      }
    }, {
      key: '_getAttachment',
XhmikosR's avatar
XhmikosR committed
3065

3066
      // private
XhmikosR's avatar
XhmikosR committed
3067

3068
3069
3070
3071
3072
3073
3074
      value: function _getAttachment(placement) {
        return AttachmentMap[placement.toUpperCase()];
      }
    }, {
      key: '_setListeners',
      value: function _setListeners() {
        var _this18 = this;
XhmikosR's avatar
XhmikosR committed
3075

3076
        var triggers = this.config.trigger.split(' ');
XhmikosR's avatar
XhmikosR committed
3077

3078
3079
3080
3081
3082
3083
        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) {
            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;
XhmikosR's avatar
XhmikosR committed
3084

3085
3086
3087
            $(_this18.element).on(eventIn, _this18.config.selector, $.proxy(_this18._enter, _this18)).on(eventOut, _this18.config.selector, $.proxy(_this18._leave, _this18));
          }
        });
XhmikosR's avatar
XhmikosR committed
3088

3089
3090
3091
3092
3093
3094
3095
3096
        if (this.config.selector) {
          this.config = $.extend({}, this.config, {
            trigger: 'manual',
            selector: ''
          });
        } else {
          this._fixTitle();
        }
Mark Otto's avatar
Mark Otto committed
3097
      }
3098
3099
3100
3101
    }, {
      key: '_removeTetherClasses',
      value: function _removeTetherClasses(i, css) {
        return ((css.baseVal || css).match(new RegExp('(^|\\s)' + CLASS_PREFIX + '-\\S+', 'g')) || []).join(' ');
Mark Otto's avatar
Mark Otto committed
3102
      }
3103
3104
3105
3106
3107
3108
3109
3110
    }, {
      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', '');
        }
Mark Otto's avatar
Mark Otto committed
3111
      }
3112
3113
3114
3115
    }, {
      key: '_enter',
      value: function _enter(event, context) {
        var dataKey = this.constructor.DATA_KEY;
XhmikosR's avatar
XhmikosR committed
3116

3117
        context = context || $(event.currentTarget).data(dataKey);
XhmikosR's avatar
XhmikosR committed
3118

3119
3120
3121
3122
        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }
XhmikosR's avatar
XhmikosR committed
3123

3124
3125
3126
        if (event) {
          context._activeTrigger[event.type == 'focusin' ? Trigger.FOCUS : Trigger.HOVER] = true;
        }
XhmikosR's avatar
XhmikosR committed
3127

3128
3129
3130
3131
        if ($(context.getTipElement()).hasClass(ClassName.IN) || context._hoverState === HoverState.IN) {
          context._hoverState = HoverState.IN;
          return;
        }
XhmikosR's avatar
XhmikosR committed
3132

3133
        clearTimeout(context._timeout);
XhmikosR's avatar
XhmikosR committed
3134

3135
        context._hoverState = HoverState.IN;
XhmikosR's avatar
XhmikosR committed
3136

3137
3138
3139
3140
        if (!context.config.delay || !context.config.delay.show) {
          context.show();
          return;
        }
XhmikosR's avatar
XhmikosR committed
3141

3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
        context._timeout = setTimeout(function () {
          if (context._hoverState === HoverState.IN) {
            context.show();
          }
        }, context.config.delay.show);
      }
    }, {
      key: '_leave',
      value: function _leave(event, context) {
        var dataKey = this.constructor.DATA_KEY;
XhmikosR's avatar
XhmikosR committed
3152

3153
        context = context || $(event.currentTarget).data(dataKey);
XhmikosR's avatar
XhmikosR committed
3154

3155
3156
3157
3158
        if (!context) {
          context = new this.constructor(event.currentTarget, this._getDelegateConfig());
          $(event.currentTarget).data(dataKey, context);
        }
XhmikosR's avatar
XhmikosR committed
3159

3160
3161
3162
        if (event) {
          context._activeTrigger[event.type == 'focusout' ? Trigger.FOCUS : Trigger.HOVER] = false;
        }
XhmikosR's avatar
XhmikosR committed
3163

3164
3165
3166
        if (context._isWithActiveTrigger()) {
          return;
        }
XhmikosR's avatar
XhmikosR committed
3167

3168
        clearTimeout(context._timeout);
XhmikosR's avatar
XhmikosR committed
3169

3170
        context._hoverState = HoverState.OUT;
XhmikosR's avatar
XhmikosR committed
3171

3172
3173
3174
3175
        if (!context.config.delay || !context.config.delay.hide) {
          context.hide();
          return;
        }
XhmikosR's avatar
XhmikosR committed
3176

3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
        context._timeout = setTimeout(function () {
          if (context._hoverState === HoverState.OUT) {
            context.hide();
          }
        }, context.config.delay.hide);
      }
    }, {
      key: '_isWithActiveTrigger',
      value: function _isWithActiveTrigger() {
        for (var trigger in this._activeTrigger) {
          if (this._activeTrigger[trigger]) {
            return true;
          }
        }
XhmikosR's avatar
XhmikosR committed
3191

3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
        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
          };
        }
XhmikosR's avatar
XhmikosR committed
3205

3206
        Util.typeCheckConfig(NAME, config, this.constructor.DefaultType);
XhmikosR's avatar
XhmikosR committed
3207

3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
        return config;
      }
    }, {
      key: '_getDelegateConfig',
      value: function _getDelegateConfig() {
        var config = {};

        if (this.config) {
          for (var key in this.config) {
            var value = this.config[key];
            if (this.constructor.Default[key] !== value) {
              config[key] = value;
            }
          }
        }
3223

3224
3225
3226
3227
        return config;
      }
    }], [{
      key: 'VERSION',
3228

3229
      // getters
3230

3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
      get: function () {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function () {
        return Default;
      }
    }, {
      key: 'NAME',
      get: function () {
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
      get: function () {
        return DATA_KEY;
      }
    }, {
      key: 'Event',
      get: function () {
        return Event;
      }
    }, {
      key: 'EVENT_KEY',
      get: function () {
        return EVENT_KEY;
      }
    }, {
      key: 'DefaultType',
      get: function () {
        return DefaultType;
      }
    }, {
      key: '_jQueryInterface',
3266

3267
      // static
XhmikosR's avatar
XhmikosR committed
3268

3269
3270
3271
3272
      value: function _jQueryInterface(config) {
        return this.each(function () {
          var data = $(this).data(DATA_KEY);
          var _config = typeof config === 'object' ? config : null;
XhmikosR's avatar
XhmikosR committed
3273

3274
3275
3276
          if (!data && /destroy|hide/.test(config)) {
            return;
          }
XhmikosR's avatar
XhmikosR committed
3277

3278
3279
3280
3281
          if (!data) {
            data = new Tooltip(this, _config);
            $(this).data(DATA_KEY, data);
          }
XhmikosR's avatar
XhmikosR committed
3282

3283
3284
3285
3286
3287
3288
          if (typeof config === 'string') {
            data[config]();
          }
        });
      }
    }]);
XhmikosR's avatar
XhmikosR committed
3289

3290
3291
    return Tooltip;
  })();
XhmikosR's avatar
XhmikosR committed
3292

3293
3294
3295
3296
3297
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
XhmikosR committed
3298

3299
3300
3301
3302
3303
3304
  $.fn[NAME] = Tooltip._jQueryInterface;
  $.fn[NAME].Constructor = Tooltip;
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Tooltip._jQueryInterface;
  };
XhmikosR's avatar
XhmikosR committed
3305

3306
3307
  return Tooltip;
})(jQuery);
XhmikosR's avatar
XhmikosR committed
3308

Mark Otto's avatar
Mark Otto committed
3309
/**
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
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
 * --------------------------------------------------------------------------
 * Bootstrap (v4.0.0): popover.js
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */

var Popover = (function ($) {

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

  var NAME = 'popover';
  var VERSION = '4.0.0';
  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, {
    content: '(string|function)'
  });

  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) {
    function Popover() {
      _classCallCheck(this, Popover);

      if (_Tooltip != null) {
        _Tooltip.apply(this, arguments);
      }
Mark Otto's avatar
Mark Otto committed
3378
    }
XhmikosR's avatar
XhmikosR committed
3379

3380
    _inherits(Popover, _Tooltip);
XhmikosR's avatar
XhmikosR committed
3381

3382
3383
    _createClass(Popover, [{
      key: 'isWithContent',
XhmikosR's avatar
XhmikosR committed
3384

3385
      // overrides
XhmikosR's avatar
XhmikosR committed
3386

3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
      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() {
        var tip = this.getTipElement();
        var title = this.getTitle();
        var content = this._getContent();
        var titleElement = $(tip).find(Selector.TITLE)[0];

        if (titleElement) {
          titleElement[this.config.html ? 'innerHTML' : 'innerText'] = title;
        }
XhmikosR's avatar
XhmikosR committed
3406

3407
3408
        // we use append for html objects to maintain js events
        $(tip).find(Selector.CONTENT).children().detach().end()[this.config.html ? typeof content === 'string' ? 'html' : 'append' : 'text'](content);
XhmikosR's avatar
XhmikosR committed
3409

3410
        $(tip).removeClass(ClassName.FADE).removeClass(ClassName.IN);
XhmikosR's avatar
XhmikosR committed
3411

3412
        this.cleanupTether();
Mark Otto's avatar
Mark Otto committed
3413
      }
3414
3415
    }, {
      key: '_getContent',
XhmikosR's avatar
XhmikosR committed
3416

3417
      // private
XhmikosR's avatar
XhmikosR committed
3418

3419
3420
3421
3422
3423
      value: function _getContent() {
        return this.element.getAttribute('data-content') || (typeof this.config.content == 'function' ? this.config.content.call(this.element) : this.config.content);
      }
    }], [{
      key: 'VERSION',
XhmikosR's avatar
XhmikosR committed
3424

3425
      // getters
XhmikosR's avatar
XhmikosR committed
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
3453
3454
3455
3456
3457
3458
3459
3460
3461
      get: function () {
        return VERSION;
      }
    }, {
      key: 'Default',
      get: function () {
        return Default;
      }
    }, {
      key: 'NAME',
      get: function () {
        return NAME;
      }
    }, {
      key: 'DATA_KEY',
      get: function () {
        return DATA_KEY;
      }
    }, {
      key: 'Event',
      get: function () {
        return Event;
      }
    }, {
      key: 'EVENT_KEY',
      get: function () {
        return EVENT_KEY;
      }
    }, {
      key: 'DefaultType',
      get: function () {
        return DefaultType;
      }
    }, {
      key: '_jQueryInterface',
XhmikosR's avatar
XhmikosR committed
3462

3463
      // static
XhmikosR's avatar
XhmikosR committed
3464

3465
3466
3467
3468
      value: function _jQueryInterface(config) {
        return this.each(function () {
          var data = $(this).data(DATA_KEY);
          var _config = typeof config === 'object' ? config : null;
3469

3470
3471
3472
          if (!data && /destroy|hide/.test(config)) {
            return;
          }
XhmikosR's avatar
XhmikosR committed
3473

3474
3475
3476
3477
          if (!data) {
            data = new Popover(this, _config);
            $(this).data(DATA_KEY, data);
          }
XhmikosR's avatar
XhmikosR committed
3478

3479
3480
3481
3482
3483
3484
          if (typeof config === 'string') {
            data[config]();
          }
        });
      }
    }]);
XhmikosR's avatar
XhmikosR committed
3485

3486
3487
    return Popover;
  })(Tooltip);
XhmikosR's avatar
XhmikosR committed
3488

3489
3490
3491
3492
3493
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
XhmikosR's avatar
XhmikosR committed
3494

3495
3496
3497
3498
3499
3500
  $.fn[NAME] = Popover._jQueryInterface;
  $.fn[NAME].Constructor = Popover;
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Popover._jQueryInterface;
  };
XhmikosR's avatar
XhmikosR committed
3501

3502
3503
  return Popover;
})(jQuery);
XhmikosR's avatar
XhmikosR committed
3504

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