• Caden Lovelace's avatar
    Handle multiple zero-offset Scrollspy elements. · a1aa0f8a
    Caden Lovelace authored
    When the first two elements in a scrollspy content block have a document
    offset of zero (i.e. they're hard against the top of the page),
    Scrollspy would switch between them on every scroll event.
    
    This could happen, for example, in a system of nested sections:
    
    ```
    <section id="animals">
      <section id="dogs">
    	Content
      </section>
    </section>
    ```
    
    This ocurred because Scrollspy's check to see if it's at the end of the
    array of sections uses `!arr[index]`. This misses the case where
    `arr[index]` does exist and is zero.
    
    This commit explicitly checks the array bounds.
    a1aa0f8a
util.js 4.01 KiB
/**
 * --------------------------------------------------------------------------
 * Bootstrap (v4.0.0-alpha): util.js
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * --------------------------------------------------------------------------
 */
'use strict';
var Util = (function ($) {
  /**
   * ------------------------------------------------------------------------
   * Private TransitionEnd Helpers
   * ------------------------------------------------------------------------
  var transition = false;
  var TransitionEndEvent = {
    WebkitTransition: 'webkitTransitionEnd',
    MozTransition: 'transitionend',
    OTransition: 'oTransitionEnd otransitionend',
    transition: 'transitionend'
  // shoutout AngusCroll (https://goo.gl/pxwQGp)
  function toType(obj) {
    return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
  function isElement(obj) {
    return (obj[0] || obj).nodeType;
  function getSpecialTransitionEndEvent() {
    return {
      bindType: transition.end,
      delegateType: transition.end,
      handle: function handle(event) {
        if ($(event.target).is(this)) {
          return event.handleObj.handler.apply(this, arguments);
  function transitionEndTest() {
    if (window.QUnit) {
      return false;
    var el = document.createElement('bootstrap');
    for (var _name in TransitionEndEvent) {
      if (el.style[_name] !== undefined) {
        return { end: TransitionEndEvent[_name] };
    return false;
  function transitionEndEmulator(duration) {
    var _this = this;
    var called = false;
    $(this).one(Util.TRANSITION_END, function () {
      called = true;