Blame view

app/bower_components/bootstrap/js/modal.js 9.75 KB
f986e111b   TRUONG   add libs
1
  /* ========================================================================
87c93a029   Dang YoungWorld   add modal
2
   * Bootstrap: modal.js v3.3.7
f986e111b   TRUONG   add libs
3
4
   * http://getbootstrap.com/javascript/#modals
   * ========================================================================
87c93a029   Dang YoungWorld   add modal
5
6
   * Copyright 2011-2016 Twitter, Inc.
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
f986e111b   TRUONG   add libs
7
   * ======================================================================== */
87c93a029   Dang YoungWorld   add modal
8
9
  +function ($) {
    'use strict';
f986e111b   TRUONG   add libs
10
11
12
13
14
  
    // MODAL CLASS DEFINITION
    // ======================
  
    var Modal = function (element, options) {
87c93a029   Dang YoungWorld   add modal
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
      this.options             = options
      this.$body               = $(document.body)
      this.$element            = $(element)
      this.$dialog             = this.$element.find('.modal-dialog')
      this.$backdrop           = null
      this.isShown             = null
      this.originalBodyPad     = null
      this.scrollbarWidth      = 0
      this.ignoreBackdropClick = false
  
      if (this.options.remote) {
        this.$element
          .find('.modal-content')
          .load(this.options.remote, $.proxy(function () {
            this.$element.trigger('loaded.bs.modal')
          }, this))
      }
f986e111b   TRUONG   add libs
32
    }
87c93a029   Dang YoungWorld   add modal
33
34
35
36
    Modal.VERSION  = '3.3.7'
  
    Modal.TRANSITION_DURATION = 300
    Modal.BACKDROP_TRANSITION_DURATION = 150
f986e111b   TRUONG   add libs
37
    Modal.DEFAULTS = {
87c93a029   Dang YoungWorld   add modal
38
39
40
      backdrop: true,
      keyboard: true,
      show: true
f986e111b   TRUONG   add libs
41
42
43
    }
  
    Modal.prototype.toggle = function (_relatedTarget) {
87c93a029   Dang YoungWorld   add modal
44
      return this.isShown ? this.hide() : this.show(_relatedTarget)
f986e111b   TRUONG   add libs
45
46
47
48
49
50
51
52
53
54
55
    }
  
    Modal.prototype.show = function (_relatedTarget) {
      var that = this
      var e    = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
  
      this.$element.trigger(e)
  
      if (this.isShown || e.isDefaultPrevented()) return
  
      this.isShown = true
87c93a029   Dang YoungWorld   add modal
56
57
58
      this.checkScrollbar()
      this.setScrollbar()
      this.$body.addClass('modal-open')
f986e111b   TRUONG   add libs
59
      this.escape()
87c93a029   Dang YoungWorld   add modal
60
      this.resize()
f986e111b   TRUONG   add libs
61

87c93a029   Dang YoungWorld   add modal
62
63
64
65
66
67
68
      this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
  
      this.$dialog.on('mousedown.dismiss.bs.modal', function () {
        that.$element.one('mouseup.dismiss.bs.modal', function (e) {
          if ($(e.target).is(that.$element)) that.ignoreBackdropClick = true
        })
      })
f986e111b   TRUONG   add libs
69
70
71
72
73
  
      this.backdrop(function () {
        var transition = $.support.transition && that.$element.hasClass('fade')
  
        if (!that.$element.parent().length) {
87c93a029   Dang YoungWorld   add modal
74
          that.$element.appendTo(that.$body) // don't move modals dom position
f986e111b   TRUONG   add libs
75
        }
87c93a029   Dang YoungWorld   add modal
76
77
78
79
80
        that.$element
          .show()
          .scrollTop(0)
  
        that.adjustDialog()
f986e111b   TRUONG   add libs
81
82
83
84
  
        if (transition) {
          that.$element[0].offsetWidth // force reflow
        }
87c93a029   Dang YoungWorld   add modal
85
        that.$element.addClass('in')
f986e111b   TRUONG   add libs
86
87
88
89
90
91
  
        that.enforceFocus()
  
        var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
  
        transition ?
87c93a029   Dang YoungWorld   add modal
92
93
94
          that.$dialog // wait for modal to slide in
            .one('bsTransitionEnd', function () {
              that.$element.trigger('focus').trigger(e)
f986e111b   TRUONG   add libs
95
            })
87c93a029   Dang YoungWorld   add modal
96
97
            .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
          that.$element.trigger('focus').trigger(e)
f986e111b   TRUONG   add libs
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
      })
    }
  
    Modal.prototype.hide = function (e) {
      if (e) e.preventDefault()
  
      e = $.Event('hide.bs.modal')
  
      this.$element.trigger(e)
  
      if (!this.isShown || e.isDefaultPrevented()) return
  
      this.isShown = false
  
      this.escape()
87c93a029   Dang YoungWorld   add modal
113
      this.resize()
f986e111b   TRUONG   add libs
114
115
116
117
118
  
      $(document).off('focusin.bs.modal')
  
      this.$element
        .removeClass('in')
87c93a029   Dang YoungWorld   add modal
119
120
121
122
        .off('click.dismiss.bs.modal')
        .off('mouseup.dismiss.bs.modal')
  
      this.$dialog.off('mousedown.dismiss.bs.modal')
f986e111b   TRUONG   add libs
123
124
125
  
      $.support.transition && this.$element.hasClass('fade') ?
        this.$element
87c93a029   Dang YoungWorld   add modal
126
127
          .one('bsTransitionEnd', $.proxy(this.hideModal, this))
          .emulateTransitionEnd(Modal.TRANSITION_DURATION) :
f986e111b   TRUONG   add libs
128
129
130
131
132
133
134
        this.hideModal()
    }
  
    Modal.prototype.enforceFocus = function () {
      $(document)
        .off('focusin.bs.modal') // guard against infinite focus loop
        .on('focusin.bs.modal', $.proxy(function (e) {
87c93a029   Dang YoungWorld   add modal
135
136
137
138
          if (document !== e.target &&
              this.$element[0] !== e.target &&
              !this.$element.has(e.target).length) {
            this.$element.trigger('focus')
f986e111b   TRUONG   add libs
139
140
141
142
143
144
          }
        }, this))
    }
  
    Modal.prototype.escape = function () {
      if (this.isShown && this.options.keyboard) {
87c93a029   Dang YoungWorld   add modal
145
        this.$element.on('keydown.dismiss.bs.modal', $.proxy(function (e) {
f986e111b   TRUONG   add libs
146
147
148
          e.which == 27 && this.hide()
        }, this))
      } else if (!this.isShown) {
87c93a029   Dang YoungWorld   add modal
149
150
151
152
153
154
155
156
157
        this.$element.off('keydown.dismiss.bs.modal')
      }
    }
  
    Modal.prototype.resize = function () {
      if (this.isShown) {
        $(window).on('resize.bs.modal', $.proxy(this.handleUpdate, this))
      } else {
        $(window).off('resize.bs.modal')
f986e111b   TRUONG   add libs
158
159
160
161
162
163
164
      }
    }
  
    Modal.prototype.hideModal = function () {
      var that = this
      this.$element.hide()
      this.backdrop(function () {
87c93a029   Dang YoungWorld   add modal
165
166
167
        that.$body.removeClass('modal-open')
        that.resetAdjustments()
        that.resetScrollbar()
f986e111b   TRUONG   add libs
168
169
170
171
172
173
174
175
176
177
        that.$element.trigger('hidden.bs.modal')
      })
    }
  
    Modal.prototype.removeBackdrop = function () {
      this.$backdrop && this.$backdrop.remove()
      this.$backdrop = null
    }
  
    Modal.prototype.backdrop = function (callback) {
87c93a029   Dang YoungWorld   add modal
178
      var that = this
f986e111b   TRUONG   add libs
179
180
181
182
      var animate = this.$element.hasClass('fade') ? 'fade' : ''
  
      if (this.isShown && this.options.backdrop) {
        var doAnimate = $.support.transition && animate
87c93a029   Dang YoungWorld   add modal
183
184
185
        this.$backdrop = $(document.createElement('div'))
          .addClass('modal-backdrop ' + animate)
          .appendTo(this.$body)
f986e111b   TRUONG   add libs
186

87c93a029   Dang YoungWorld   add modal
187
188
189
190
191
        this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
          if (this.ignoreBackdropClick) {
            this.ignoreBackdropClick = false
            return
          }
f986e111b   TRUONG   add libs
192
193
          if (e.target !== e.currentTarget) return
          this.options.backdrop == 'static'
87c93a029   Dang YoungWorld   add modal
194
195
            ? this.$element[0].focus()
            : this.hide()
f986e111b   TRUONG   add libs
196
197
198
199
200
201
202
203
204
205
        }, this))
  
        if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
  
        this.$backdrop.addClass('in')
  
        if (!callback) return
  
        doAnimate ?
          this.$backdrop
87c93a029   Dang YoungWorld   add modal
206
207
            .one('bsTransitionEnd', callback)
            .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
f986e111b   TRUONG   add libs
208
209
210
211
          callback()
  
      } else if (!this.isShown && this.$backdrop) {
        this.$backdrop.removeClass('in')
87c93a029   Dang YoungWorld   add modal
212
213
214
215
216
        var callbackRemove = function () {
          that.removeBackdrop()
          callback && callback()
        }
        $.support.transition && this.$element.hasClass('fade') ?
f986e111b   TRUONG   add libs
217
          this.$backdrop
87c93a029   Dang YoungWorld   add modal
218
219
220
            .one('bsTransitionEnd', callbackRemove)
            .emulateTransitionEnd(Modal.BACKDROP_TRANSITION_DURATION) :
          callbackRemove()
f986e111b   TRUONG   add libs
221
222
223
224
225
  
      } else if (callback) {
        callback()
      }
    }
87c93a029   Dang YoungWorld   add modal
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
    // 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: ''
      })
    }
  
    Modal.prototype.checkScrollbar = function () {
      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
      this.scrollbarWidth = this.measureScrollbar()
    }
  
    Modal.prototype.setScrollbar = function () {
      var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
      this.originalBodyPad = document.body.style.paddingRight || ''
      if (this.bodyIsOverflowing) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
    }
  
    Modal.prototype.resetScrollbar = function () {
      this.$body.css('padding-right', this.originalBodyPad)
    }
  
    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
    }
f986e111b   TRUONG   add libs
276
277
278
  
    // MODAL PLUGIN DEFINITION
    // =======================
87c93a029   Dang YoungWorld   add modal
279
    function Plugin(option, _relatedTarget) {
f986e111b   TRUONG   add libs
280
281
282
283
284
285
286
287
288
289
      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)
      })
    }
87c93a029   Dang YoungWorld   add modal
290
291
292
    var old = $.fn.modal
  
    $.fn.modal             = Plugin
f986e111b   TRUONG   add libs
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
    $.fn.modal.Constructor = Modal
  
  
    // MODAL NO CONFLICT
    // =================
  
    $.fn.modal.noConflict = function () {
      $.fn.modal = old
      return this
    }
  
  
    // MODAL DATA-API
    // ==============
  
    $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
      var $this   = $(this)
      var href    = $this.attr('href')
87c93a029   Dang YoungWorld   add modal
311
312
      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())
f986e111b   TRUONG   add libs
313

87c93a029   Dang YoungWorld   add modal
314
      if ($this.is('a')) e.preventDefault()
f986e111b   TRUONG   add libs
315

87c93a029   Dang YoungWorld   add modal
316
317
318
319
      $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')
f986e111b   TRUONG   add libs
320
        })
87c93a029   Dang YoungWorld   add modal
321
322
      })
      Plugin.call($target, option, this)
f986e111b   TRUONG   add libs
323
    })
f986e111b   TRUONG   add libs
324
  }(jQuery);