github.com/kayoticsully/syncthing@v0.8.9-0.20140724133906-c45a2fdc03f8/assets/bootstrap-3.1.1/js/collapse.js (about)

     1  /* ========================================================================
     2   * Bootstrap: collapse.js v3.1.1
     3   * http://getbootstrap.com/javascript/#collapse
     4   * ========================================================================
     5   * Copyright 2011-2014 Twitter, Inc.
     6   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
     7   * ======================================================================== */
     8  
     9  
    10  +function ($) {
    11    'use strict';
    12  
    13    // COLLAPSE PUBLIC CLASS DEFINITION
    14    // ================================
    15  
    16    var Collapse = function (element, options) {
    17      this.$element      = $(element)
    18      this.options       = $.extend({}, Collapse.DEFAULTS, options)
    19      this.transitioning = null
    20  
    21      if (this.options.parent) this.$parent = $(this.options.parent)
    22      if (this.options.toggle) this.toggle()
    23    }
    24  
    25    Collapse.DEFAULTS = {
    26      toggle: true
    27    }
    28  
    29    Collapse.prototype.dimension = function () {
    30      var hasWidth = this.$element.hasClass('width')
    31      return hasWidth ? 'width' : 'height'
    32    }
    33  
    34    Collapse.prototype.show = function () {
    35      if (this.transitioning || this.$element.hasClass('in')) return
    36  
    37      var startEvent = $.Event('show.bs.collapse')
    38      this.$element.trigger(startEvent)
    39      if (startEvent.isDefaultPrevented()) return
    40  
    41      var actives = this.$parent && this.$parent.find('> .panel > .in')
    42  
    43      if (actives && actives.length) {
    44        var hasData = actives.data('bs.collapse')
    45        if (hasData && hasData.transitioning) return
    46        actives.collapse('hide')
    47        hasData || actives.data('bs.collapse', null)
    48      }
    49  
    50      var dimension = this.dimension()
    51  
    52      this.$element
    53        .removeClass('collapse')
    54        .addClass('collapsing')
    55        [dimension](0)
    56  
    57      this.transitioning = 1
    58  
    59      var complete = function () {
    60        this.$element
    61          .removeClass('collapsing')
    62          .addClass('collapse in')
    63          [dimension]('auto')
    64        this.transitioning = 0
    65        this.$element.trigger('shown.bs.collapse')
    66      }
    67  
    68      if (!$.support.transition) return complete.call(this)
    69  
    70      var scrollSize = $.camelCase(['scroll', dimension].join('-'))
    71  
    72      this.$element
    73        .one($.support.transition.end, $.proxy(complete, this))
    74        .emulateTransitionEnd(350)
    75        [dimension](this.$element[0][scrollSize])
    76    }
    77  
    78    Collapse.prototype.hide = function () {
    79      if (this.transitioning || !this.$element.hasClass('in')) return
    80  
    81      var startEvent = $.Event('hide.bs.collapse')
    82      this.$element.trigger(startEvent)
    83      if (startEvent.isDefaultPrevented()) return
    84  
    85      var dimension = this.dimension()
    86  
    87      this.$element
    88        [dimension](this.$element[dimension]())
    89        [0].offsetHeight
    90  
    91      this.$element
    92        .addClass('collapsing')
    93        .removeClass('collapse')
    94        .removeClass('in')
    95  
    96      this.transitioning = 1
    97  
    98      var complete = function () {
    99        this.transitioning = 0
   100        this.$element
   101          .trigger('hidden.bs.collapse')
   102          .removeClass('collapsing')
   103          .addClass('collapse')
   104      }
   105  
   106      if (!$.support.transition) return complete.call(this)
   107  
   108      this.$element
   109        [dimension](0)
   110        .one($.support.transition.end, $.proxy(complete, this))
   111        .emulateTransitionEnd(350)
   112    }
   113  
   114    Collapse.prototype.toggle = function () {
   115      this[this.$element.hasClass('in') ? 'hide' : 'show']()
   116    }
   117  
   118  
   119    // COLLAPSE PLUGIN DEFINITION
   120    // ==========================
   121  
   122    var old = $.fn.collapse
   123  
   124    $.fn.collapse = function (option) {
   125      return this.each(function () {
   126        var $this   = $(this)
   127        var data    = $this.data('bs.collapse')
   128        var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
   129  
   130        if (!data && options.toggle && option == 'show') option = !option
   131        if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
   132        if (typeof option == 'string') data[option]()
   133      })
   134    }
   135  
   136    $.fn.collapse.Constructor = Collapse
   137  
   138  
   139    // COLLAPSE NO CONFLICT
   140    // ====================
   141  
   142    $.fn.collapse.noConflict = function () {
   143      $.fn.collapse = old
   144      return this
   145    }
   146  
   147  
   148    // COLLAPSE DATA-API
   149    // =================
   150  
   151    $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
   152      var $this   = $(this), href
   153      var target  = $this.attr('data-target')
   154          || e.preventDefault()
   155          || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
   156      var $target = $(target)
   157      var data    = $target.data('bs.collapse')
   158      var option  = data ? 'toggle' : $this.data()
   159      var parent  = $this.attr('data-parent')
   160      var $parent = parent && $(parent)
   161  
   162      if (!data || !data.transitioning) {
   163        if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed')
   164        $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
   165      }
   166  
   167      $target.collapse(option)
   168    })
   169  
   170  }(jQuery);