您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

261 行
6.3 KiB

  1. /* =========================================================
  2. * bootstrap-modal.js v1.4.0
  3. * http://twitter.github.com/bootstrap/javascript.html#modal
  4. * =========================================================
  5. * Copyright 2011 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. !function( $ ){
  20. "use strict"
  21. /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
  22. * ======================================================= */
  23. var transitionEnd
  24. $(document).ready(function () {
  25. $.support.transition = (function () {
  26. var thisBody = document.body || document.documentElement
  27. , thisStyle = thisBody.style
  28. , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
  29. return support
  30. })()
  31. // set CSS transition event type
  32. if ( $.support.transition ) {
  33. transitionEnd = "TransitionEnd"
  34. if ( $.browser.webkit ) {
  35. transitionEnd = "webkitTransitionEnd"
  36. } else if ( $.browser.mozilla ) {
  37. transitionEnd = "transitionend"
  38. } else if ( $.browser.opera ) {
  39. transitionEnd = "oTransitionEnd"
  40. }
  41. }
  42. })
  43. /* MODAL PUBLIC CLASS DEFINITION
  44. * ============================= */
  45. var Modal = function ( content, options ) {
  46. this.settings = $.extend({}, $.fn.modal.defaults, options)
  47. this.$element = $(content)
  48. .delegate('.close', 'click.modal', $.proxy(this.hide, this))
  49. if ( this.settings.show ) {
  50. this.show()
  51. }
  52. return this
  53. }
  54. Modal.prototype = {
  55. toggle: function () {
  56. return this[!this.isShown ? 'show' : 'hide']()
  57. }
  58. , show: function () {
  59. var that = this
  60. this.isShown = true
  61. this.$element.trigger('show')
  62. escape.call(this)
  63. backdrop.call(this, function () {
  64. var transition = $.support.transition && that.$element.hasClass('fade')
  65. that.$element
  66. .appendTo(document.body)
  67. .show()
  68. if (transition) {
  69. that.$element[0].offsetWidth // force reflow
  70. }
  71. that.$element.addClass('in')
  72. transition ?
  73. that.$element.one(transitionEnd, function () { that.$element.trigger('shown') }) :
  74. that.$element.trigger('shown')
  75. })
  76. return this
  77. }
  78. , hide: function (e) {
  79. e && e.preventDefault()
  80. if ( !this.isShown ) {
  81. return this
  82. }
  83. var that = this
  84. this.isShown = false
  85. escape.call(this)
  86. this.$element
  87. .trigger('hide')
  88. .removeClass('in')
  89. $.support.transition && this.$element.hasClass('fade') ?
  90. hideWithTransition.call(this) :
  91. hideModal.call(this)
  92. return this
  93. }
  94. }
  95. /* MODAL PRIVATE METHODS
  96. * ===================== */
  97. function hideWithTransition() {
  98. // firefox drops transitionEnd events :{o
  99. var that = this
  100. , timeout = setTimeout(function () {
  101. that.$element.unbind(transitionEnd)
  102. hideModal.call(that)
  103. }, 500)
  104. this.$element.one(transitionEnd, function () {
  105. clearTimeout(timeout)
  106. hideModal.call(that)
  107. })
  108. }
  109. function hideModal (that) {
  110. this.$element
  111. .hide()
  112. .trigger('hidden')
  113. backdrop.call(this)
  114. }
  115. function backdrop ( callback ) {
  116. var that = this
  117. , animate = this.$element.hasClass('fade') ? 'fade' : ''
  118. if ( this.isShown && this.settings.backdrop ) {
  119. var doAnimate = $.support.transition && animate
  120. this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
  121. .appendTo(document.body)
  122. if ( this.settings.backdrop != 'static' ) {
  123. this.$backdrop.click($.proxy(this.hide, this))
  124. }
  125. if ( doAnimate ) {
  126. this.$backdrop[0].offsetWidth // force reflow
  127. }
  128. this.$backdrop.addClass('in')
  129. doAnimate ?
  130. this.$backdrop.one(transitionEnd, callback) :
  131. callback()
  132. } else if ( !this.isShown && this.$backdrop ) {
  133. this.$backdrop.removeClass('in')
  134. $.support.transition && this.$element.hasClass('fade')?
  135. this.$backdrop.one(transitionEnd, $.proxy(removeBackdrop, this)) :
  136. removeBackdrop.call(this)
  137. } else if ( callback ) {
  138. callback()
  139. }
  140. }
  141. function removeBackdrop() {
  142. this.$backdrop.remove()
  143. this.$backdrop = null
  144. }
  145. function escape() {
  146. var that = this
  147. if ( this.isShown && this.settings.keyboard ) {
  148. $(document).bind('keyup.modal', function ( e ) {
  149. if ( e.which == 27 ) {
  150. that.hide()
  151. }
  152. })
  153. } else if ( !this.isShown ) {
  154. $(document).unbind('keyup.modal')
  155. }
  156. }
  157. /* MODAL PLUGIN DEFINITION
  158. * ======================= */
  159. $.fn.modal = function ( options ) {
  160. var modal = this.data('modal')
  161. if (!modal) {
  162. if (typeof options == 'string') {
  163. options = {
  164. show: /show|toggle/.test(options)
  165. }
  166. }
  167. return this.each(function () {
  168. $(this).data('modal', new Modal(this, options))
  169. })
  170. }
  171. if ( options === true ) {
  172. return modal
  173. }
  174. if ( typeof options == 'string' ) {
  175. modal[options]()
  176. } else if ( modal ) {
  177. modal.toggle()
  178. }
  179. return this
  180. }
  181. $.fn.modal.Modal = Modal
  182. $.fn.modal.defaults = {
  183. backdrop: false
  184. , keyboard: false
  185. , show: false
  186. }
  187. /* MODAL DATA- IMPLEMENTATION
  188. * ========================== */
  189. $(document).ready(function () {
  190. $('body').delegate('[data-controls-modal]', 'click', function (e) {
  191. e.preventDefault()
  192. var $this = $(this).data('show', true)
  193. $('#' + $this.attr('data-controls-modal')).modal( $this.data() )
  194. })
  195. })
  196. }( window.jQuery || window.ender );