Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.06 KB | None | 0 0
  1. /* ========================================================================
  2. * Bootstrap: collapse.js v3.0.0
  3. * http://twbs.github.com/bootstrap/javascript.html#collapse
  4. * ========================================================================
  5. * Copyright 2012 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ======================================================================== */
  19.  
  20.  
  21. +function ($) { "use strict";
  22. var Collapse = function (element, options) {
  23. this.$element = $(element)
  24. this.options = $.extend({}, Collapse.DEFAULTS, options)
  25. this.transitioning = null
  26.  
  27. if (this.options.parent) this.$parent = $(this.options.parent)
  28. if (this.options.toggle) this.toggle()
  29. }
  30.  
  31. Collapse.DEFAULTS = {
  32. toggle: true
  33. }
  34.  
  35. Collapse.prototype.dimension = function () {
  36. var hasWidth = this.$element.hasClass('width')
  37. return hasWidth ? 'width' : 'height'
  38. }
  39.  
  40. Collapse.prototype.show = function () {
  41. if (this.transitioning || this.$element.hasClass('in')) return
  42.  
  43. var startEvent = $.Event('show.bs.collapse')
  44. this.$element.trigger(startEvent)
  45. if (startEvent.isDefaultPrevented()) return
  46.  
  47. var actives = this.$parent && this.$parent.find('> .panel > .in')
  48.  
  49. if (actives && actives.length) {
  50. var hasData = actives.data('bs.collapse')
  51. if (hasData && hasData.transitioning) return
  52. actives.collapse('hide')
  53. hasData || actives.data('bs.collapse', null)
  54. }
  55.  
  56. var dimension = this.dimension()
  57.  
  58. this.$element
  59. .removeClass('collapse')
  60. .addClass('collapsing')
  61. [dimension](0)
  62.  
  63. this.transitioning = 1
  64.  
  65. var complete = function () {
  66. this.$element
  67. .removeClass('collapsing')
  68. .addClass('in')
  69. [dimension]('auto')
  70. this.transitioning = 0
  71. this.$element.trigger('shown.bs.collapse')
  72. }
  73.  
  74. if (!$.support.transition) return complete.call(this)
  75.  
  76. var scrollSize = $.camelCase(['scroll', dimension].join('-'))
  77.  
  78. this.$element
  79. .one($.support.transition.end, $.proxy(complete, this))
  80. .emulateTransitionEnd(350)
  81. [dimension](this.$element[0][scrollSize])
  82. }
  83.  
  84. Collapse.prototype.hide = function () {
  85. if (this.transitioning || !this.$element.hasClass('in')) return
  86.  
  87. var startEvent = $.Event('hide.bs.collapse')
  88. this.$element.trigger(startEvent)
  89. if (startEvent.isDefaultPrevented()) return
  90.  
  91. var dimension = this.dimension()
  92.  
  93. this.$element
  94. [dimension](this.$element[dimension]())
  95. [0].offsetHeight
  96.  
  97. this.$element
  98. .addClass('collapsing')
  99. .removeClass('collapse')
  100. .removeClass('in')
  101.  
  102. this.transitioning = 1
  103.  
  104. var complete = function () {
  105. this.transitioning = 0
  106. this.$element
  107. .trigger('hidden.bs.collapse')
  108. .removeClass('collapsing')
  109. .addClass('collapse')
  110. }
  111.  
  112. if (!$.support.transition) return complete.call(this)
  113.  
  114. this.$element
  115. [dimension](0)
  116. .one($.support.transition.end, $.proxy(complete, this))
  117. .emulateTransitionEnd(350)
  118. }
  119.  
  120. Collapse.prototype.toggle = function () {
  121. this[this.$element.hasClass('in') ? 'hide' : 'show']()
  122. }
  123. var old = $.fn.collapse
  124.  
  125. $.fn.collapse = function (option) {
  126. return this.each(function () {
  127. var $this = $(this)
  128. var data = $this.data('bs.collapse')
  129. var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
  130.  
  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. $.fn.collapse.noConflict = function () {
  138. $.fn.collapse = old
  139. return this
  140. }
  141. $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
  142. var $this = $(this), href
  143. var target = $this.attr('data-target')
  144. || e.preventDefault()
  145. || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
  146. var $target = $(target)
  147. var data = $target.data('bs.collapse')
  148. var option = data ? 'toggle' : $this.data()
  149. var parent = $this.attr('data-parent')
  150. var $parent = parent && $(parent)
  151.  
  152. if (!data || !data.transitioning) {
  153. if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed')
  154. $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
  155. }
  156.  
  157. $target.collapse(option)
  158. })
  159.  
  160. }(window.jQuery);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement