bootstrap.js 66.5 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1001
      that.enforceFocus()
1002

XhmikosR's avatar
XhmikosR committed
1003
      var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
1004

XhmikosR's avatar
XhmikosR committed
1005
      transition ?
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1006
        that.$dialog // wait for modal to slide in
XhmikosR's avatar
XhmikosR committed
1007
1008
1009
          .one('bsTransitionEnd', function () {
            that.$element.trigger('focus').trigger(e)
          })
1010
          .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1011
1012
1013
        that.$element.trigger('focus').trigger(e)
    })
  }
1014

XhmikosR's avatar
XhmikosR committed
1015
1016
  Modal.prototype.hide = function (e) {
    if (e) e.preventDefault()
1017

XhmikosR's avatar
XhmikosR committed
1018
    e = $.Event('hide.bs.modal')
fat's avatar
build    
fat committed
1019

XhmikosR's avatar
XhmikosR committed
1020
    this.$element.trigger(e)
1021

XhmikosR's avatar
XhmikosR committed
1022
    if (!this.isShown || e.isDefaultPrevented()) return
1023

XhmikosR's avatar
XhmikosR committed
1024
    this.isShown = false
1025

XhmikosR's avatar
XhmikosR committed
1026
    this.escape()
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1027
    this.resize()
Chris Rebert's avatar
Chris Rebert committed
1028

XhmikosR's avatar
XhmikosR committed
1029
    $(document).off('focusin.bs.modal')
Chris Rebert's avatar
Chris Rebert committed
1030

XhmikosR's avatar
XhmikosR committed
1031
1032
1033
    this.$element
      .removeClass('in')
      .off('click.dismiss.bs.modal')
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1034
1035
1036
      .off('mouseup.dismiss.bs.modal')

    this.$dialog.off('mousedown.dismiss.bs.modal')
1037

XhmikosR's avatar
XhmikosR committed
1038
1039
1040
    $.support.transition && this.$element.hasClass('fade') ?
      this.$element
        .one('bsTransitionEnd', $.proxy(this.hideModal, this))
1041
        .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1042
1043
      this.hideModal()
  }
1044

XhmikosR's avatar
XhmikosR committed
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
  Modal.prototype.enforceFocus = function () {
    $(document)
      .off('focusin.bs.modal') // guard against infinite focus loop
      .on('focusin.bs.modal', $.proxy(function (e) {
        if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
          this.$element.trigger('focus')
        }
      }, this))
  }

  Modal.prototype.escape = function () {
    if (this.isShown && this.options.keyboard) {
Mark Otto's avatar
grunt    
Mark Otto committed
1057
      this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
XhmikosR's avatar
XhmikosR committed
1058
1059
1060
        e.which == 27 && this.hide()
      }, this))
    } else if (!this.isShown) {
Mark Otto's avatar
grunt    
Mark Otto committed
1061
      this.$element.off('keydown.dismiss.bs.modal')
XhmikosR's avatar
XhmikosR committed
1062
1063
1064
    }
  }

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1065
1066
  Modal.prototype.resize = function () {
    if (this.isShown) {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1067
      $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this))
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1068
1069
1070
1071
1072
    } else {
      $(window).off('resize.bs.modal')
    }
  }

XhmikosR's avatar
XhmikosR committed
1073
1074
1075
1076
  Modal.prototype.hideModal = function () {
    var that = this
    this.$element.hide()
    this.backdrop(function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1077
      that.$body.removeClass('modal-open')
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1078
      that.resetAdjustments()
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1079
      that.resetScrollbar()
XhmikosR's avatar
XhmikosR committed
1080
1081
1082
      that.$element.trigger('hidden.bs.modal')
    })
  }
1083

XhmikosR's avatar
XhmikosR committed
1084
1085
1086
1087
  Modal.prototype.removeBackdrop = function () {
    this.$backdrop && this.$backdrop.remove()
    this.$backdrop = null
  }
1088

XhmikosR's avatar
XhmikosR committed
1089
1090
1091
  Modal.prototype.backdrop = function (callback) {
    var that = this
    var animate = this.$element.hasClass('fade') ? 'fade' : ''
1092

XhmikosR's avatar
XhmikosR committed
1093
1094
    if (this.isShown && this.options.backdrop) {
      var doAnimate = $.support.transition && animate
1095

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1096
1097
      this.$backdrop = $(document.createElement('div'))
        .addClass('modal-backdrop ' + animate)
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
        .appendTo(this.$body)

      this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
        if (this.ignoreBackdropClick) {
          this.ignoreBackdropClick = false
          return
        }
        if (e.target !== e.currentTarget) return
        this.options.backdrop == 'static'
          ? this.$element[0].focus()
          : this.hide()
      }, this))
1110

XhmikosR's avatar
XhmikosR committed
1111
      if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
1112

XhmikosR's avatar
XhmikosR committed
1113
      this.$backdrop.addClass('in')
1114

XhmikosR's avatar
XhmikosR committed
1115
      if (!callback) return
1116

XhmikosR's avatar
XhmikosR committed
1117
1118
1119
      doAnimate ?
        this.$backdrop
          .one('bsTransitionEnd', callback)
1120
          .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1121
        callback()
1122

XhmikosR's avatar
XhmikosR committed
1123
1124
    } else if (!this.isShown && this.$backdrop) {
      this.$backdrop.removeClass('in')
Chris Rebert's avatar
Chris Rebert committed
1125

XhmikosR's avatar
XhmikosR committed
1126
1127
1128
      var callbackRemove = function () {
        that.removeBackdrop()
        callback && callback()
Chris Rebert's avatar
Chris Rebert committed
1129
      }
XhmikosR's avatar
XhmikosR committed
1130
1131
1132
      $.support.transition && this.$element.hasClass('fade') ?
        this.$backdrop
          .one('bsTransitionEnd', callbackRemove)
1133
          .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1134
        callbackRemove()
1135

XhmikosR's avatar
XhmikosR committed
1136
1137
    } else if (callback) {
      callback()
Chris Rebert's avatar
Chris Rebert committed
1138
    }
XhmikosR's avatar
XhmikosR committed
1139
  }
1140

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
  // these following methods are used to handle overflowing modals

  Modal.prototype.handleUpdate = function () {
    this.adjustDialog()
  }

  Modal.prototype.adjustDialog = function () {
    var modalIsOverflowing = this.$element[0].scrollHeight > document.documentElement.clientHeight

    this.$element.css({
      paddingLeft:  !this.bodyIsOverflowing && modalIsOverflowing ? this.scrollbarWidth : '',
      paddingRight: this.bodyIsOverflowing && !modalIsOverflowing ? this.scrollbarWidth : ''
    })
  }

  Modal.prototype.resetAdjustments = function () {
    this.$element.css({
      paddingLeft: '',
      paddingRight: ''
    })
  }

XhmikosR's avatar
XhmikosR committed
1163
  Modal.prototype.checkScrollbar = function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1164
1165
1166
1167
1168
1169
    var fullWindowWidth = window.innerWidth
    if (!fullWindowWidth) { // workaround for missing window.innerWidth in IE8
      var documentElementRect = document.documentElement.getBoundingClientRect()
      fullWindowWidth = documentElementRect.right - Math.abs(documentElementRect.left)
    }
    this.bodyIsOverflowing = document.body.clientWidth < fullWindowWidth
Mark Otto's avatar
grunt    
Mark Otto committed
1170
    this.scrollbarWidth = this.measureScrollbar()
XhmikosR's avatar
XhmikosR committed
1171
  }
fat's avatar
build    
fat committed
1172

XhmikosR's avatar
XhmikosR committed
1173
1174
  Modal.prototype.setScrollbar = function () {
    var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1175
    this.originalBodyPad = document.body.style.paddingRight || ''
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1176
    if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
XhmikosR's avatar
XhmikosR committed
1177
  }
fat's avatar
build    
fat committed
1178

XhmikosR's avatar
XhmikosR committed
1179
  Modal.prototype.resetScrollbar = function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1180
    this.$body.css('padding-right', this.originalBodyPad)
XhmikosR's avatar
XhmikosR committed
1181
  }
fat's avatar
build    
fat committed
1182

XhmikosR's avatar
XhmikosR committed
1183
1184
1185
1186
1187
1188
1189
1190
  Modal.prototype.measureScrollbar = function () { // thx walsh
    var scrollDiv = document.createElement('div')
    scrollDiv.className = 'modal-scrollbar-measure'
    this.$body.append(scrollDiv)
    var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
    this.$body[0].removeChild(scrollDiv)
    return scrollbarWidth
  }
1191
1192


XhmikosR's avatar
XhmikosR committed
1193
1194
  // MODAL PLUGIN DEFINITION
  // =======================
fat's avatar
fat committed
1195

XhmikosR's avatar
XhmikosR committed
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
  function Plugin(option, _relatedTarget) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.modal')
      var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)

      if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
      if (typeof option == 'string') data[option](_relatedTarget)
      else if (options.show) data.show(_relatedTarget)
    })
  }
1207

XhmikosR's avatar
XhmikosR committed
1208
  var old = $.fn.modal
Mark Otto's avatar
Mark Otto committed
1209

XhmikosR's avatar
XhmikosR committed
1210
1211
  $.fn.modal             = Plugin
  $.fn.modal.Constructor = Modal
1212
1213


XhmikosR's avatar
XhmikosR committed
1214
1215
  // MODAL NO CONFLICT
  // =================
1216

XhmikosR's avatar
XhmikosR committed
1217
1218
1219
1220
  $.fn.modal.noConflict = function () {
    $.fn.modal = old
    return this
  }
1221
1222


XhmikosR's avatar
XhmikosR committed
1223
1224
  // MODAL DATA-API
  // ==============
1225

XhmikosR's avatar
XhmikosR committed
1226
1227
1228
1229
1230
  $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
    var $this   = $(this)
    var href    = $this.attr('href')
    var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
    var option  = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
1231

XhmikosR's avatar
XhmikosR committed
1232
    if ($this.is('a')) e.preventDefault()
1233

XhmikosR's avatar
XhmikosR committed
1234
1235
1236
1237
    $target.one('show.bs.modal', function (showEvent) {
      if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
      $target.one('hidden.bs.modal', function () {
        $this.is(':visible') && $this.trigger('focus')
Mark Otto's avatar
grunt    
Mark Otto committed
1238
      })
Mark Otto's avatar
Mark Otto committed
1239
    })
XhmikosR's avatar
XhmikosR committed
1240
    Plugin.call($target, option, this)
Jacob Thornton's avatar
Jacob Thornton committed
1241
  })
1242

XhmikosR's avatar
XhmikosR committed
1243
}(jQuery);
1244

1245
/* ========================================================================
Chris Rebert's avatar
Chris Rebert committed
1246
 * Bootstrap: tooltip.js v3.3.4
Mark Otto's avatar
Mark Otto committed
1247
 * http://getbootstrap.com/javascript/#tooltip
1248
 * Inspired by the original jQuery.tipsy by Jason Frame
1249
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1250
 * Copyright 2011-2015 Twitter, Inc.
1251
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1252
 * ======================================================================== */
1253
1254


XhmikosR's avatar
XhmikosR committed
1255
1256
1257
1258
1259
1260
1261
+function ($) {
  'use strict';

  // TOOLTIP PUBLIC CLASS DEFINITION
  // ===============================

  var Tooltip = function (element, options) {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1262
1263
1264
1265
1266
    this.type       = null
    this.options    = null
    this.enabled    = null
    this.timeout    = null
    this.hoverState = null
XhmikosR's avatar
XhmikosR committed
1267
1268
1269
1270
1271
    this.$element   = null

    this.init('tooltip', element, options)
  }

Chris Rebert's avatar
Chris Rebert committed
1272
  Tooltip.VERSION  = '3.3.4'
XhmikosR's avatar
XhmikosR committed
1273

1274
1275
  Tooltip.TRANSITION_DURATION = 150

XhmikosR's avatar
XhmikosR committed
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
  Tooltip.DEFAULTS = {
    animation: true,
    placement: 'top',
    selector: false,
    template: '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
    trigger: 'hover focus',
    title: '',
    delay: 0,
    html: false,
    container: false,
    viewport: {
      selector: 'body',
      padding: 0
    }
  }

  Tooltip.prototype.init = function (type, element, options) {
    this.enabled   = true
    this.type      = type
    this.$element  = $(element)
    this.options   = this.getOptions(options)
1297
    this.$viewport = this.options.viewport && $($.isFunction(this.options.viewport) ? this.options.viewport.call(this, this.$element) : (this.options.viewport.selector || this.options.viewport))
XhmikosR's avatar
XhmikosR committed
1298

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1299
    if (this.$element[0] instanceof document.constructor && !this.options.selector) {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1300
      throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!')
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1301
1302
    }

XhmikosR's avatar
XhmikosR committed
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
    var triggers = this.options.trigger.split(' ')

    for (var i = triggers.length; i--;) {
      var trigger = triggers[i]

      if (trigger == 'click') {
        this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
      } else if (trigger != 'manual') {
        var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin'
        var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'

        this.$element.on(eventIn  + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
        this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
      }
    }
1318

XhmikosR's avatar
XhmikosR committed
1319
1320
1321
1322
    this.options.selector ?
      (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
      this.fixTitle()
  }
1323

XhmikosR's avatar
XhmikosR committed
1324
1325
1326
  Tooltip.prototype.getDefaults = function () {
    return Tooltip.DEFAULTS
  }
1327

XhmikosR's avatar
XhmikosR committed
1328
1329
  Tooltip.prototype.getOptions = function (options) {
    options = $.extend({}, this.getDefaults(), this.$element.data(), options)
1330

XhmikosR's avatar
XhmikosR committed
1331
1332
1333
1334
    if (options.delay && typeof options.delay == 'number') {
      options.delay = {
        show: options.delay,
        hide: options.delay
1335
1336
      }
    }
1337

XhmikosR's avatar
XhmikosR committed
1338
1339
    return options
  }
Jacob Thornton's avatar
Jacob Thornton committed
1340

XhmikosR's avatar
XhmikosR committed
1341
1342
1343
  Tooltip.prototype.getDelegateOptions = function () {
    var options  = {}
    var defaults = this.getDefaults()
1344

XhmikosR's avatar
XhmikosR committed
1345
1346
1347
    this._options && $.each(this._options, function (key, value) {
      if (defaults[key] != value) options[key] = value
    })
fat's avatar
rebuild    
fat committed
1348

XhmikosR's avatar
XhmikosR committed
1349
1350
    return options
  }
Jacob Thornton's avatar
Jacob Thornton committed
1351

XhmikosR's avatar
XhmikosR committed
1352
1353
1354
  Tooltip.prototype.enter = function (obj) {
    var self = obj instanceof this.constructor ?
      obj : $(obj.currentTarget).data('bs.' + this.type)
Mark Otto's avatar
Mark Otto committed
1355

XhmikosR's avatar
XhmikosR committed
1356
1357
1358
1359
1360
    if (self && self.$tip && self.$tip.is(':visible')) {
      self.hoverState = 'in'
      return
    }

XhmikosR's avatar
XhmikosR committed
1361
1362
1363
    if (!self) {
      self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
      $(obj.currentTarget).data('bs.' + this.type, self)
Mark Otto's avatar
Mark Otto committed
1364
    }
1365

XhmikosR's avatar
XhmikosR committed
1366
    clearTimeout(self.timeout)
1367

XhmikosR's avatar
XhmikosR committed
1368
    self.hoverState = 'in'
1369

XhmikosR's avatar
XhmikosR committed
1370
    if (!self.options.delay || !self.options.delay.show) return self.show()
1371

XhmikosR's avatar
XhmikosR committed
1372
1373
1374
1375
    self.timeout = setTimeout(function () {
      if (self.hoverState == 'in') self.show()
    }, self.options.delay.show)
  }
1376

XhmikosR's avatar
XhmikosR committed
1377
1378
1379
  Tooltip.prototype.leave = function (obj) {
    var self = obj instanceof this.constructor ?
      obj : $(obj.currentTarget).data('bs.' + this.type)
Mark Otto's avatar
Mark Otto committed
1380

XhmikosR's avatar
XhmikosR committed
1381
1382
1383
    if (!self) {
      self = new this.constructor(obj.currentTarget, this.getDelegateOptions())
      $(obj.currentTarget).data('bs.' + this.type, self)
Mark Otto's avatar
Mark Otto committed
1384
    }
1385

XhmikosR's avatar
XhmikosR committed
1386
    clearTimeout(self.timeout)
fat's avatar
fat committed
1387

XhmikosR's avatar
XhmikosR committed
1388
    self.hoverState = 'out'
1389

XhmikosR's avatar
XhmikosR committed
1390
    if (!self.options.delay || !self.options.delay.hide) return self.hide()
1391

XhmikosR's avatar
XhmikosR committed
1392
1393
1394
1395
    self.timeout = setTimeout(function () {
      if (self.hoverState == 'out') self.hide()
    }, self.options.delay.hide)
  }
1396

XhmikosR's avatar
XhmikosR committed
1397
1398
  Tooltip.prototype.show = function () {
    var e = $.Event('show.bs.' + this.type)
Chris Rebert's avatar
Chris Rebert committed
1399

XhmikosR's avatar
XhmikosR committed
1400
1401
    if (this.hasContent() && this.enabled) {
      this.$element.trigger(e)
fat's avatar
fat committed
1402

Heinrich Fenkart's avatar
Heinrich Fenkart committed
1403
      var inDom = $.contains(this.$element[0].ownerDocument.documentElement, this.$element[0])
XhmikosR's avatar
XhmikosR committed
1404
1405
      if (e.isDefaultPrevented() || !inDom) return
      var that = this
1406

XhmikosR's avatar
XhmikosR committed
1407
      var $tip = this.tip()
fat's avatar
fat committed
1408

XhmikosR's avatar
XhmikosR committed
1409
      var tipId = this.getUID(this.type)
fat's avatar
fat committed
1410

XhmikosR's avatar
XhmikosR committed
1411
1412
1413
      this.setContent()
      $tip.attr('id', tipId)
      this.$element.attr('aria-describedby', tipId)
1414

XhmikosR's avatar
XhmikosR committed
1415
      if (this.options.animation) $tip.addClass('fade')
1416

XhmikosR's avatar
XhmikosR committed
1417
1418
1419
      var placement = typeof this.options.placement == 'function' ?
        this.options.placement.call(this, $tip[0], this.$element[0]) :
        this.options.placement
1420

XhmikosR's avatar
XhmikosR committed
1421
1422
1423
      var autoToken = /\s?auto?\s?/i
      var autoPlace = autoToken.test(placement)
      if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
1424

XhmikosR's avatar
XhmikosR committed
1425
1426
1427
1428
1429
      $tip
        .detach()
        .css({ top: 0, left: 0, display: 'block' })
        .addClass(placement)
        .data('bs.' + this.type, this)
fat's avatar
fat committed
1430

XhmikosR's avatar
XhmikosR committed
1431
      this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
1432
      this.$element.trigger('inserted.bs.' + this.type)
1433

XhmikosR's avatar
XhmikosR committed
1434
1435
1436
      var pos          = this.getPosition()
      var actualWidth  = $tip[0].offsetWidth
      var actualHeight = $tip[0].offsetHeight
Chris Rebert's avatar
Chris Rebert committed
1437

XhmikosR's avatar
XhmikosR committed
1438
1439
      if (autoPlace) {
        var orgPlacement = placement
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1440
1441
        var $container   = this.options.container ? $(this.options.container) : this.$element.parent()
        var containerDim = this.getPosition($container)
Chris Rebert's avatar
Chris Rebert committed
1442

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1443
1444
1445
1446
        placement = placement == 'bottom' && pos.bottom + actualHeight > containerDim.bottom ? 'top'    :
                    placement == 'top'    && pos.top    - actualHeight < containerDim.top    ? 'bottom' :
                    placement == 'right'  && pos.right  + actualWidth  > containerDim.width  ? 'left'   :
                    placement == 'left'   && pos.left   - actualWidth  < containerDim.left   ? 'right'  :
XhmikosR's avatar
XhmikosR committed
1447
                    placement
fat's avatar
fat committed
1448

1449
        $tip
XhmikosR's avatar
XhmikosR committed
1450
          .removeClass(orgPlacement)
1451
          .addClass(placement)
XhmikosR's avatar
XhmikosR committed
1452
      }
1453

XhmikosR's avatar
XhmikosR committed
1454
      var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
1455

XhmikosR's avatar
XhmikosR committed
1456
      this.applyPlacement(calculatedOffset, placement)
fat's avatar
fat committed
1457

XhmikosR's avatar
XhmikosR committed
1458
      var complete = function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1459
        var prevHoverState = that.hoverState
XhmikosR's avatar
XhmikosR committed
1460
1461
        that.$element.trigger('shown.bs.' + that.type)
        that.hoverState = null
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1462
1463

        if (prevHoverState == 'out') that.leave(that)
XhmikosR's avatar
XhmikosR committed
1464
      }
fat's avatar
fat committed
1465

XhmikosR's avatar
XhmikosR committed
1466
1467
1468
      $.support.transition && this.$tip.hasClass('fade') ?
        $tip
          .one('bsTransitionEnd', complete)
1469
          .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1470
1471
1472
        complete()
    }
  }
fat's avatar
fat committed
1473

XhmikosR's avatar
XhmikosR committed
1474
1475
1476
1477
  Tooltip.prototype.applyPlacement = function (offset, placement) {
    var $tip   = this.tip()
    var width  = $tip[0].offsetWidth
    var height = $tip[0].offsetHeight
fat's avatar
fat committed
1478

XhmikosR's avatar
XhmikosR committed
1479
1480
1481
    // manually read margins because getBoundingClientRect includes difference
    var marginTop = parseInt($tip.css('margin-top'), 10)
    var marginLeft = parseInt($tip.css('margin-left'), 10)
fat's avatar
fat committed
1482

XhmikosR's avatar
XhmikosR committed
1483
1484
1485
    // we must check for NaN for ie 8/9
    if (isNaN(marginTop))  marginTop  = 0
    if (isNaN(marginLeft)) marginLeft = 0
fat's avatar
fat committed
1486

XhmikosR's avatar
XhmikosR committed
1487
1488
    offset.top  = offset.top  + marginTop
    offset.left = offset.left + marginLeft
fat's avatar
fat committed
1489

XhmikosR's avatar
XhmikosR committed
1490
1491
1492
1493
1494
1495
1496
1497
    // $.fn.offset doesn't round pixel values
    // so we use setOffset directly with our own function B-0
    $.offset.setOffset($tip[0], $.extend({
      using: function (props) {
        $tip.css({
          top: Math.round(props.top),
          left: Math.round(props.left)
        })
1498
      }
XhmikosR's avatar
XhmikosR committed
1499
    }, offset), 0)
1500

XhmikosR's avatar
XhmikosR committed
1501
    $tip.addClass('in')
fat's avatar
fat committed
1502

XhmikosR's avatar
XhmikosR committed
1503
1504
1505
    // check to see if placing tip in new offset caused the tip to resize itself
    var actualWidth  = $tip[0].offsetWidth
    var actualHeight = $tip[0].offsetHeight
fat's avatar
fat committed
1506

XhmikosR's avatar
XhmikosR committed
1507
1508
1509
    if (placement == 'top' && actualHeight != height) {
      offset.top = offset.top + height - actualHeight
    }
fat's avatar
fat committed
1510

XhmikosR's avatar
XhmikosR committed
1511
    var delta = this.getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
fat's avatar
fat committed
1512

XhmikosR's avatar
XhmikosR committed
1513
1514
    if (delta.left) offset.left += delta.left
    else offset.top += delta.top
1515

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1516
1517
1518
    var isVertical          = /top|bottom/.test(placement)
    var arrowDelta          = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
    var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
1519

XhmikosR's avatar
XhmikosR committed
1520
    $tip.offset(offset)
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1521
    this.replaceArrow(arrowDelta, $tip[0][arrowOffsetPosition], isVertical)
XhmikosR's avatar
XhmikosR committed
1522
  }
1523

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1524
  Tooltip.prototype.replaceArrow = function (delta, dimension, isVertical) {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1525
    this.arrow()
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1526
1527
      .css(isVertical ? 'left' : 'top', 50 * (1 - delta / dimension) + '%')
      .css(isVertical ? 'top' : 'left', '')
XhmikosR's avatar
XhmikosR committed
1528
  }
1529

XhmikosR's avatar
XhmikosR committed
1530
1531
1532
  Tooltip.prototype.setContent = function () {
    var $tip  = this.tip()
    var title = this.getTitle()
1533

XhmikosR's avatar
XhmikosR committed
1534
1535
1536
    $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
    $tip.removeClass('fade in top bottom left right')
  }
1537

Heinrich Fenkart's avatar
Heinrich Fenkart committed
1538
  Tooltip.prototype.hide = function (callback) {
XhmikosR's avatar
XhmikosR committed
1539
    var that = this
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1540
    var $tip = $(this.$tip)
XhmikosR's avatar
XhmikosR committed
1541
    var e    = $.Event('hide.bs.' + this.type)
1542

XhmikosR's avatar
XhmikosR committed
1543
1544
    function complete() {
      if (that.hoverState != 'in') $tip.detach()
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1545
1546
1547
      that.$element
        .removeAttr('aria-describedby')
        .trigger('hidden.bs.' + that.type)
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1548
      callback && callback()
XhmikosR's avatar
XhmikosR committed
1549
    }
Jacob Thornton's avatar
Jacob Thornton committed
1550

XhmikosR's avatar
XhmikosR committed
1551
    this.$element.trigger(e)
1552

XhmikosR's avatar
XhmikosR committed
1553
    if (e.isDefaultPrevented()) return
1554

XhmikosR's avatar
XhmikosR committed
1555
    $tip.removeClass('in')
1556

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1557
    $.support.transition && $tip.hasClass('fade') ?
XhmikosR's avatar
XhmikosR committed
1558
1559
      $tip
        .one('bsTransitionEnd', complete)
1560
        .emulateTransitionEnd(Tooltip.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
1561
      complete()
1562

XhmikosR's avatar
XhmikosR committed
1563
    this.hoverState = null
1564

XhmikosR's avatar
XhmikosR committed
1565
1566
    return this
  }
1567

XhmikosR's avatar
XhmikosR committed
1568
1569
1570
1571
  Tooltip.prototype.fixTitle = function () {
    var $e = this.$element
    if ($e.attr('title') || typeof ($e.attr('data-original-title')) != 'string') {
      $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
1572
    }
XhmikosR's avatar
XhmikosR committed
1573
  }
1574

XhmikosR's avatar
XhmikosR committed
1575
1576
1577
  Tooltip.prototype.hasContent = function () {
    return this.getTitle()
  }
1578

XhmikosR's avatar
XhmikosR committed
1579
1580
  Tooltip.prototype.getPosition = function ($element) {
    $element   = $element || this.$element
Mark Otto's avatar
grunt    
Mark Otto committed
1581

XhmikosR's avatar
XhmikosR committed
1582
1583
    var el     = $element[0]
    var isBody = el.tagName == 'BODY'
Mark Otto's avatar
grunt    
Mark Otto committed
1584

Mark Otto's avatar
grunt    
Mark Otto committed
1585
    var elRect    = el.getBoundingClientRect()
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1586
1587
1588
1589
    if (elRect.width == null) {
      // width and height are missing in IE8, so compute them manually; see https://github.com/twbs/bootstrap/issues/14093
      elRect = $.extend({}, elRect, { width: elRect.right - elRect.left, height: elRect.bottom - elRect.top })
    }
Mark Otto's avatar
grunt    
Mark Otto committed
1590
1591
    var elOffset  = isBody ? { top: 0, left: 0 } : $element.offset()
    var scroll    = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : $element.scrollTop() }
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1592
    var outerDims = isBody ? { width: $(window).width(), height: $(window).height() } : null
Mark Otto's avatar
grunt    
Mark Otto committed
1593
1594

    return $.extend({}, elRect, scroll, outerDims, elOffset)
XhmikosR's avatar
XhmikosR committed
1595
  }
1596

XhmikosR's avatar
XhmikosR committed
1597
  Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1598
1599
    return placement == 'bottom' ? { top: pos.top + pos.height,   left: pos.left + pos.width / 2 - actualWidth / 2 } :
           placement == 'top'    ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2 } :
XhmikosR's avatar
XhmikosR committed
1600
           placement == 'left'   ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1601
        /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width }
1602

XhmikosR's avatar
XhmikosR committed
1603
  }
1604

XhmikosR's avatar
XhmikosR committed
1605
1606
1607
  Tooltip.prototype.getViewportAdjustedDelta = function (placement, pos, actualWidth, actualHeight) {
    var delta = { top: 0, left: 0 }
    if (!this.$viewport) return delta
1608

XhmikosR's avatar
XhmikosR committed
1609
1610
    var viewportPadding = this.options.viewport && this.options.viewport.padding || 0
    var viewportDimensions = this.getPosition(this.$viewport)
1611

XhmikosR's avatar
XhmikosR committed
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
    if (/right|left/.test(placement)) {
      var topEdgeOffset    = pos.top - viewportPadding - viewportDimensions.scroll
      var bottomEdgeOffset = pos.top + viewportPadding - viewportDimensions.scroll + actualHeight
      if (topEdgeOffset < viewportDimensions.top) { // top overflow
        delta.top = viewportDimensions.top - topEdgeOffset
      } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
        delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
      }
    } else {
      var leftEdgeOffset  = pos.left - viewportPadding
      var rightEdgeOffset = pos.left + viewportPadding + actualWidth
      if (leftEdgeOffset < viewportDimensions.left) { // left overflow
        delta.left = viewportDimensions.left - leftEdgeOffset
1625
      } else if (rightEdgeOffset > viewportDimensions.right) { // right overflow
XhmikosR's avatar
XhmikosR committed
1626
        delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
1627
      }
Chris Rebert's avatar
Chris Rebert committed
1628
    }
fat's avatar
fat committed
1629

XhmikosR's avatar
XhmikosR committed
1630
1631
    return delta
  }
1632

XhmikosR's avatar
XhmikosR committed
1633
1634
1635
1636
  Tooltip.prototype.getTitle = function () {
    var title
    var $e = this.$element
    var o  = this.options
1637

XhmikosR's avatar
XhmikosR committed
1638
1639
    title = $e.attr('data-original-title')
      || (typeof o.title == 'function' ? o.title.call($e[0]) :  o.title)
1640

XhmikosR's avatar
XhmikosR committed
1641
1642
    return title
  }
1643

XhmikosR's avatar
XhmikosR committed
1644
1645
1646
1647
1648
  Tooltip.prototype.getUID = function (prefix) {
    do prefix += ~~(Math.random() * 1000000)
    while (document.getElementById(prefix))
    return prefix
  }
1649

XhmikosR's avatar
XhmikosR committed
1650
  Tooltip.prototype.tip = function () {
1651
1652
1653
1654
1655
1656
1657
    if (!this.$tip) {
      this.$tip = $(this.options.template)
      if (this.$tip.length != 1) {
        throw new Error(this.type + ' `template` option must consist of exactly 1 top-level element!')
      }
    }
    return this.$tip
XhmikosR's avatar
XhmikosR committed
1658
  }
1659

XhmikosR's avatar
XhmikosR committed
1660
1661
1662
  Tooltip.prototype.arrow = function () {
    return (this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow'))
  }
1663

XhmikosR's avatar
XhmikosR committed
1664
1665
1666
  Tooltip.prototype.enable = function () {
    this.enabled = true
  }
1667

XhmikosR's avatar
XhmikosR committed
1668
1669
1670
  Tooltip.prototype.disable = function () {
    this.enabled = false
  }
Mark Otto's avatar
Mark Otto committed
1671

XhmikosR's avatar
XhmikosR committed
1672
1673
1674
  Tooltip.prototype.toggleEnabled = function () {
    this.enabled = !this.enabled
  }
Chris Rebert's avatar
Chris Rebert committed
1675

XhmikosR's avatar
XhmikosR committed
1676
1677
1678
1679
1680
1681
1682
1683
  Tooltip.prototype.toggle = function (e) {
    var self = this
    if (e) {
      self = $(e.currentTarget).data('bs.' + this.type)
      if (!self) {
        self = new this.constructor(e.currentTarget, this.getDelegateOptions())
        $(e.currentTarget).data('bs.' + this.type, self)
      }
Mark Otto's avatar
Mark Otto committed
1684
1685
    }

XhmikosR's avatar
XhmikosR committed
1686
1687
    self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
  }
1688

XhmikosR's avatar
XhmikosR committed
1689
  Tooltip.prototype.destroy = function () {
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1690
    var that = this
XhmikosR's avatar
XhmikosR committed
1691
    clearTimeout(this.timeout)
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1692
1693
    this.hide(function () {
      that.$element.off('.' + that.type).removeData('bs.' + that.type)
1694
1695
1696
1697
1698
1699
      if (that.$tip) {
        that.$tip.detach()
      }
      that.$tip = null
      that.$arrow = null
      that.$viewport = null
Heinrich Fenkart's avatar
Heinrich Fenkart committed
1700
    })
XhmikosR's avatar
XhmikosR committed
1701
  }
1702
1703


XhmikosR's avatar
XhmikosR committed
1704
1705
  // TOOLTIP PLUGIN DEFINITION
  // =========================
1706

XhmikosR's avatar
XhmikosR committed
1707
1708
  function Plugin(option) {
    return this.each(function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1709
1710
1711
      var $this   = $(this)
      var data    = $this.data('bs.tooltip')
      var options = typeof option == 'object' && option
fat's avatar
fat committed
1712

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1713
      if (!data && /destroy|hide/.test(option)) return
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1714
      if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
XhmikosR's avatar
XhmikosR committed
1715
1716
1717
      if (typeof option == 'string') data[option]()
    })
  }
1718

XhmikosR's avatar
XhmikosR committed
1719
  var old = $.fn.tooltip
Mark Otto's avatar
Mark Otto committed
1720

XhmikosR's avatar
XhmikosR committed
1721
1722
  $.fn.tooltip             = Plugin
  $.fn.tooltip.Constructor = Tooltip
1723

1724

XhmikosR's avatar
XhmikosR committed
1725
1726
  // TOOLTIP NO CONFLICT
  // ===================
1727

XhmikosR's avatar
XhmikosR committed
1728
1729
1730
1731
  $.fn.tooltip.noConflict = function () {
    $.fn.tooltip = old
    return this
  }
1732

XhmikosR's avatar
XhmikosR committed
1733
}(jQuery);
1734

1735
/* ========================================================================
Chris Rebert's avatar
Chris Rebert committed
1736
 * Bootstrap: popover.js v3.3.4
Mark Otto's avatar
Mark Otto committed
1737
 * http://getbootstrap.com/javascript/#popovers
1738
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1739
 * Copyright 2011-2015 Twitter, Inc.
1740
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1741
 * ======================================================================== */
1742
1743


XhmikosR's avatar
XhmikosR committed
1744
1745
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
1746

XhmikosR's avatar
XhmikosR committed
1747
1748
  // POPOVER PUBLIC CLASS DEFINITION
  // ===============================
1749

XhmikosR's avatar
XhmikosR committed
1750
1751
1752
  var Popover = function (element, options) {
    this.init('popover', element, options)
  }
fat's avatar
fat committed
1753

XhmikosR's avatar
XhmikosR committed
1754
  if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
1755

Chris Rebert's avatar
Chris Rebert committed
1756
  Popover.VERSION  = '3.3.4'
1757

XhmikosR's avatar
XhmikosR committed
1758
1759
1760
1761
1762
1763
  Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
    placement: 'right',
    trigger: 'click',
    content: '',
    template: '<div class="popover" role="tooltip"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
  })
fat's avatar
fat committed
1764
1765


XhmikosR's avatar
XhmikosR committed
1766
1767
  // NOTE: POPOVER EXTENDS tooltip.js
  // ================================
1768

XhmikosR's avatar
XhmikosR committed
1769
  Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
fat's avatar
fat committed
1770

XhmikosR's avatar
XhmikosR committed
1771
  Popover.prototype.constructor = Popover
1772

XhmikosR's avatar
XhmikosR committed
1773
1774
1775
  Popover.prototype.getDefaults = function () {
    return Popover.DEFAULTS
  }
1776

XhmikosR's avatar
XhmikosR committed
1777
1778
1779
1780
  Popover.prototype.setContent = function () {
    var $tip    = this.tip()
    var title   = this.getTitle()
    var content = this.getContent()
1781

XhmikosR's avatar
XhmikosR committed
1782
    $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
Mark Otto's avatar
grunt    
Mark Otto committed
1783
    $tip.find('.popover-content').children().detach().end()[ // we use append for html objects to maintain js events
XhmikosR's avatar
XhmikosR committed
1784
1785
      this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
    ](content)
1786

XhmikosR's avatar
XhmikosR committed
1787
    $tip.removeClass('fade top bottom left right in')
1788

XhmikosR's avatar
XhmikosR committed
1789
1790
1791
1792
    // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
    // this manually by checking the contents.
    if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
  }
1793

XhmikosR's avatar
XhmikosR committed
1794
1795
1796
  Popover.prototype.hasContent = function () {
    return this.getTitle() || this.getContent()
  }
1797

XhmikosR's avatar
XhmikosR committed
1798
1799
1800
  Popover.prototype.getContent = function () {
    var $e = this.$element
    var o  = this.options
1801

XhmikosR's avatar
XhmikosR committed
1802
1803
1804
1805
1806
    return $e.attr('data-content')
      || (typeof o.content == 'function' ?
            o.content.call($e[0]) :
            o.content)
  }
fat's avatar
fat committed
1807

XhmikosR's avatar
XhmikosR committed
1808
1809
1810
  Popover.prototype.arrow = function () {
    return (this.$arrow = this.$arrow || this.tip().find('.arrow'))
  }
1811
1812


XhmikosR's avatar
XhmikosR committed
1813
1814
  // POPOVER PLUGIN DEFINITION
  // =========================
1815

XhmikosR's avatar
XhmikosR committed
1816
1817
  function Plugin(option) {
    return this.each(function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1818
1819
1820
      var $this   = $(this)
      var data    = $this.data('bs.popover')
      var options = typeof option == 'object' && option
Chris Rebert's avatar
Chris Rebert committed
1821

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1822
      if (!data && /destroy|hide/.test(option)) return
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1823
      if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
XhmikosR's avatar
XhmikosR committed
1824
1825
1826
      if (typeof option == 'string') data[option]()
    })
  }
1827

XhmikosR's avatar
XhmikosR committed
1828
  var old = $.fn.popover
Mark Otto's avatar
Mark Otto committed
1829

XhmikosR's avatar
XhmikosR committed
1830
1831
  $.fn.popover             = Plugin
  $.fn.popover.Constructor = Popover
fat's avatar
fat committed
1832

1833

XhmikosR's avatar
XhmikosR committed
1834
1835
  // POPOVER NO CONFLICT
  // ===================
1836

XhmikosR's avatar
XhmikosR committed
1837
1838
1839
1840
  $.fn.popover.noConflict = function () {
    $.fn.popover = old
    return this
  }
1841

XhmikosR's avatar
XhmikosR committed
1842
}(jQuery);
1843

1844
/* ========================================================================
Chris Rebert's avatar
Chris Rebert committed
1845
 * Bootstrap: scrollspy.js v3.3.4
Mark Otto's avatar
Mark Otto committed
1846
 * http://getbootstrap.com/javascript/#scrollspy
1847
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1848
 * Copyright 2011-2015 Twitter, Inc.
1849
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1850
 * ======================================================================== */
1851
1852


XhmikosR's avatar
XhmikosR committed
1853
1854
+function ($) {
  'use strict';
1855

XhmikosR's avatar
XhmikosR committed
1856
1857
  // SCROLLSPY CLASS DEFINITION
  // ==========================
1858

XhmikosR's avatar
XhmikosR committed
1859
  function ScrollSpy(element, options) {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1860
1861
    this.$body          = $(document.body)
    this.$scrollElement = $(element).is(document.body) ? $(window) : $(element)
XhmikosR's avatar
XhmikosR committed
1862
1863
1864
1865
1866
1867
    this.options        = $.extend({}, ScrollSpy.DEFAULTS, options)
    this.selector       = (this.options.target || '') + ' .nav li > a'
    this.offsets        = []
    this.targets        = []
    this.activeTarget   = null
    this.scrollHeight   = 0
1868

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1869
    this.$scrollElement.on('scroll.bs.scrollspy', $.proxy(this.process, this))
XhmikosR's avatar
XhmikosR committed
1870
1871
1872
    this.refresh()
    this.process()
  }
1873

Chris Rebert's avatar
Chris Rebert committed
1874
  ScrollSpy.VERSION  = '3.3.4'
Mark Otto's avatar
grunt    
Mark Otto committed
1875

XhmikosR's avatar
XhmikosR committed
1876
1877
1878
  ScrollSpy.DEFAULTS = {
    offset: 10
  }
1879

XhmikosR's avatar
XhmikosR committed
1880
1881
1882
  ScrollSpy.prototype.getScrollHeight = function () {
    return this.$scrollElement[0].scrollHeight || Math.max(this.$body[0].scrollHeight, document.documentElement.scrollHeight)
  }
Mark Otto's avatar
grunt    
Mark Otto committed
1883

XhmikosR's avatar
XhmikosR committed
1884
  ScrollSpy.prototype.refresh = function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1885
1886
1887
1888
1889
1890
1891
    var that          = this
    var offsetMethod  = 'offset'
    var offsetBase    = 0

    this.offsets      = []
    this.targets      = []
    this.scrollHeight = this.getScrollHeight()
Mark Otto's avatar
grunt    
Mark Otto committed
1892

XhmikosR's avatar
XhmikosR committed
1893
1894
1895
1896
    if (!$.isWindow(this.$scrollElement[0])) {
      offsetMethod = 'position'
      offsetBase   = this.$scrollElement.scrollTop()
    }
Mark Otto's avatar
grunt    
Mark Otto committed
1897

XhmikosR's avatar
XhmikosR committed
1898
1899
1900
1901
1902
1903
    this.$body
      .find(this.selector)
      .map(function () {
        var $el   = $(this)
        var href  = $el.data('target') || $el.attr('href')
        var $href = /^#./.test(href) && $(href)
1904

XhmikosR's avatar
XhmikosR committed
1905
1906
1907
1908
1909
1910
1911
        return ($href
          && $href.length
          && $href.is(':visible')
          && [[$href[offsetMethod]().top + offsetBase, href]]) || null
      })
      .sort(function (a, b) { return a[0] - b[0] })
      .each(function () {
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1912
1913
        that.offsets.push(this[0])
        that.targets.push(this[1])
XhmikosR's avatar
XhmikosR committed
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
      })
  }

  ScrollSpy.prototype.process = function () {
    var scrollTop    = this.$scrollElement.scrollTop() + this.options.offset
    var scrollHeight = this.getScrollHeight()
    var maxScroll    = this.options.offset + scrollHeight - this.$scrollElement.height()
    var offsets      = this.offsets
    var targets      = this.targets
    var activeTarget = this.activeTarget
    var i

    if (this.scrollHeight != scrollHeight) {
      this.refresh()
Mark Otto's avatar
grunt    
Mark Otto committed
1928
1929
    }

XhmikosR's avatar
XhmikosR committed
1930
1931
1932
    if (scrollTop >= maxScroll) {
      return activeTarget != (i = targets[targets.length - 1]) && this.activate(i)
    }
1933

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1934
1935
1936
    if (activeTarget && scrollTop < offsets[0]) {
      this.activeTarget = null
      return this.clear()
Chris Rebert's avatar
Chris Rebert committed
1937
    }
1938

XhmikosR's avatar
XhmikosR committed
1939
1940
1941
    for (i = offsets.length; i--;) {
      activeTarget != targets[i]
        && scrollTop >= offsets[i]
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1942
        && (offsets[i + 1] === undefined || scrollTop < offsets[i + 1])
XhmikosR's avatar
XhmikosR committed
1943
1944
1945
        && this.activate(targets[i])
    }
  }
1946

XhmikosR's avatar
XhmikosR committed
1947
1948
  ScrollSpy.prototype.activate = function (target) {
    this.activeTarget = target
1949

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1950
    this.clear()
1951

XhmikosR's avatar
XhmikosR committed
1952
    var selector = this.selector +
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
1953
1954
      '[data-target="' + target + '"],' +
      this.selector + '[href="' + target + '"]'
1955

XhmikosR's avatar
XhmikosR committed
1956
1957
1958
    var active = $(selector)
      .parents('li')
      .addClass('active')
1959

XhmikosR's avatar
XhmikosR committed
1960
1961
1962
1963
    if (active.parent('.dropdown-menu').length) {
      active = active
        .closest('li.dropdown')
        .addClass('active')
Chris Rebert's avatar
Chris Rebert committed
1964
    }
1965

XhmikosR's avatar
XhmikosR committed
1966
1967
    active.trigger('activate.bs.scrollspy')
  }
1968

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1969
1970
1971
1972
1973
1974
  ScrollSpy.prototype.clear = function () {
    $(this.selector)
      .parentsUntil(this.options.target, '.active')
      .removeClass('active')
  }

1975

XhmikosR's avatar
XhmikosR committed
1976
1977
  // SCROLLSPY PLUGIN DEFINITION
  // ===========================
1978

XhmikosR's avatar
XhmikosR committed
1979
1980
1981
1982
1983
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.scrollspy')
      var options = typeof option == 'object' && option
Mark Otto's avatar
Mark Otto committed
1984

XhmikosR's avatar
XhmikosR committed
1985
1986
1987
1988
      if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
1989

XhmikosR's avatar
XhmikosR committed
1990
  var old = $.fn.scrollspy
1991

XhmikosR's avatar
XhmikosR committed
1992
1993
  $.fn.scrollspy             = Plugin
  $.fn.scrollspy.Constructor = ScrollSpy
1994

1995

XhmikosR's avatar
XhmikosR committed
1996
1997
  // SCROLLSPY NO CONFLICT
  // =====================
1998

XhmikosR's avatar
XhmikosR committed
1999
2000
  $.fn.scrollspy.noConflict = function () {
    $.fn.scrollspy = old
For faster browsing, not all history is shown. View entire blame