rails_admin 0.6.5 → 0.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-affix.js +99 -74
  3. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-alert.js +48 -55
  4. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-button.js +70 -65
  5. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-carousel.js +163 -147
  6. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-collapse.js +117 -114
  7. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-dropdown.js +89 -107
  8. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-modal.js +208 -175
  9. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-popover.js +77 -78
  10. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-scrollspy.js +137 -129
  11. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-tab.js +85 -101
  12. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-tooltip.js +364 -268
  13. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-transition.js +51 -52
  14. data/app/assets/javascripts/rails_admin/bootstrap/bootstrap-typeahead.js +1782 -335
  15. data/app/assets/javascripts/rails_admin/ra.filter-box.js +1 -1
  16. data/app/assets/javascripts/rails_admin/ra.filtering-multiselect.js +3 -3
  17. data/app/assets/javascripts/rails_admin/ra.filtering-select.js +1 -1
  18. data/app/assets/javascripts/rails_admin/ra.remote-form.js +6 -2
  19. data/app/assets/stylesheets/rails_admin/base/theming.scss +34 -14
  20. data/app/assets/stylesheets/rails_admin/bootstrap/_alerts.scss +47 -58
  21. data/app/assets/stylesheets/rails_admin/bootstrap/_badges.scss +57 -0
  22. data/app/assets/stylesheets/rails_admin/bootstrap/_breadcrumbs.scss +12 -10
  23. data/app/assets/stylesheets/rails_admin/bootstrap/_button-groups.scss +163 -152
  24. data/app/assets/stylesheets/rails_admin/bootstrap/_buttons.scss +98 -169
  25. data/app/assets/stylesheets/rails_admin/bootstrap/_carousel.scss +151 -66
  26. data/app/assets/stylesheets/rails_admin/bootstrap/_close.scss +11 -8
  27. data/app/assets/stylesheets/rails_admin/bootstrap/_code.scss +36 -29
  28. data/app/assets/stylesheets/rails_admin/bootstrap/_component-animations.scss +16 -3
  29. data/app/assets/stylesheets/rails_admin/bootstrap/_dropdowns.scss +115 -148
  30. data/app/assets/stylesheets/rails_admin/bootstrap/_forms.scss +396 -547
  31. data/app/assets/stylesheets/rails_admin/bootstrap/_glyphicons.scss +237 -0
  32. data/app/assets/stylesheets/rails_admin/bootstrap/_grid.scss +74 -11
  33. data/app/assets/stylesheets/rails_admin/bootstrap/_input-groups.scss +166 -0
  34. data/app/assets/stylesheets/rails_admin/bootstrap/_jumbotron.scss +48 -0
  35. data/app/assets/stylesheets/rails_admin/bootstrap/_labels.scss +66 -0
  36. data/app/assets/stylesheets/rails_admin/bootstrap/_list-group.scss +131 -0
  37. data/app/assets/stylesheets/rails_admin/bootstrap/_media.scss +8 -7
  38. data/app/assets/stylesheets/rails_admin/bootstrap/_mixins.scss +36 -693
  39. data/app/assets/stylesheets/rails_admin/bootstrap/_modals.scss +108 -53
  40. data/app/assets/stylesheets/rails_admin/bootstrap/_navbar.scss +545 -383
  41. data/app/assets/stylesheets/rails_admin/bootstrap/_navs.scss +191 -358
  42. data/app/assets/stylesheets/rails_admin/bootstrap/_normalize.scss +425 -0
  43. data/app/assets/stylesheets/rails_admin/bootstrap/_pager.scss +45 -33
  44. data/app/assets/stylesheets/rails_admin/bootstrap/_pagination.scss +70 -105
  45. data/app/assets/stylesheets/rails_admin/bootstrap/_panels.scss +243 -0
  46. data/app/assets/stylesheets/rails_admin/bootstrap/_popovers.scss +61 -61
  47. data/app/assets/stylesheets/rails_admin/bootstrap/_print.scss +101 -0
  48. data/app/assets/stylesheets/rails_admin/bootstrap/_progress-bars.scss +56 -73
  49. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-embed.scss +34 -0
  50. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-utilities.scss +150 -50
  51. data/app/assets/stylesheets/rails_admin/bootstrap/_scaffolding.scss +120 -23
  52. data/app/assets/stylesheets/rails_admin/bootstrap/_tables.scss +168 -170
  53. data/app/assets/stylesheets/rails_admin/bootstrap/_theme.scss +258 -0
  54. data/app/assets/stylesheets/rails_admin/bootstrap/_thumbnails.scss +27 -42
  55. data/app/assets/stylesheets/rails_admin/bootstrap/_tooltip.scss +49 -24
  56. data/app/assets/stylesheets/rails_admin/bootstrap/_type.scss +200 -143
  57. data/app/assets/stylesheets/rails_admin/bootstrap/_utilities.scss +33 -21
  58. data/app/assets/stylesheets/rails_admin/bootstrap/_variables.scss +764 -215
  59. data/app/assets/stylesheets/rails_admin/bootstrap/_wells.scss +7 -7
  60. data/app/assets/stylesheets/rails_admin/bootstrap/bootstrap.scss +47 -60
  61. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_alerts.scss +14 -0
  62. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_background-variant.scss +11 -0
  63. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_border-radius.scss +18 -0
  64. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_buttons.scss +50 -0
  65. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_center-block.scss +7 -0
  66. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_clearfix.scss +22 -0
  67. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_forms.scss +84 -0
  68. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_gradients.scss +58 -0
  69. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_grid-framework.scss +81 -0
  70. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_grid.scss +122 -0
  71. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_hide-text.scss +21 -0
  72. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_image.scss +34 -0
  73. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_labels.scss +12 -0
  74. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_list-group.scss +31 -0
  75. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_nav-divider.scss +10 -0
  76. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_nav-vertical-align.scss +9 -0
  77. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_opacity.scss +8 -0
  78. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_pagination.scss +23 -0
  79. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_panels.scss +24 -0
  80. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_progress-bar.scss +10 -0
  81. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_reset-filter.scss +8 -0
  82. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_resize.scss +6 -0
  83. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_responsive-visibility.scss +21 -0
  84. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_size.scss +10 -0
  85. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_tab-focus.scss +9 -0
  86. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_table-row.scss +28 -0
  87. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_text-emphasis.scss +11 -0
  88. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_text-overflow.scss +8 -0
  89. data/app/assets/stylesheets/rails_admin/bootstrap/mixins/_vendor-prefixes.scss +219 -0
  90. data/app/assets/stylesheets/rails_admin/ra.calendar-additions.scss +17 -0
  91. data/app/assets/stylesheets/rails_admin/rails_admin.scss.erb +9 -5
  92. data/app/helpers/rails_admin/application_helper.rb +20 -19
  93. data/app/helpers/rails_admin/form_builder.rb +14 -11
  94. data/app/views/kaminari/twitter-bootstrap/_paginator.html.haml +8 -9
  95. data/app/views/layouts/rails_admin/_navigation.html.haml +5 -5
  96. data/app/views/layouts/rails_admin/_secondary_navigation.html.haml +1 -1
  97. data/app/views/layouts/rails_admin/application.html.haml +9 -8
  98. data/app/views/layouts/rails_admin/pjax.html.haml +4 -3
  99. data/app/views/rails_admin/main/_form_datetime.html.haml +2 -1
  100. data/app/views/rails_admin/main/_form_field.html.haml +1 -1
  101. data/app/views/rails_admin/main/_form_text.html.haml +1 -1
  102. data/app/views/rails_admin/main/_submit_buttons.html.haml +1 -0
  103. data/app/views/rails_admin/main/dashboard.html.haml +1 -1
  104. data/app/views/rails_admin/main/export.html.haml +19 -16
  105. data/app/views/rails_admin/main/index.html.haml +11 -7
  106. data/app/views/rails_admin/main/show.html.haml +1 -1
  107. data/lib/rails_admin/adapters/active_record.rb +2 -2
  108. data/lib/rails_admin/adapters/mongoid/property.rb +1 -1
  109. data/lib/rails_admin/config/actions/bulk_delete.rb +0 -1
  110. data/lib/rails_admin/config/actions/edit.rb +0 -2
  111. data/lib/rails_admin/config/actions/export.rb +0 -2
  112. data/lib/rails_admin/config/actions/index.rb +0 -3
  113. data/lib/rails_admin/config/actions/new.rb +0 -2
  114. data/lib/rails_admin/config/configurable.rb +1 -1
  115. data/lib/rails_admin/config/fields/base.rb +9 -0
  116. data/lib/rails_admin/config/fields/factories/enum.rb +2 -3
  117. data/lib/rails_admin/config/fields/types/polymorphic_association.rb +4 -0
  118. data/lib/rails_admin/config/model.rb +2 -1
  119. data/lib/rails_admin/extensions/paper_trail/auditing_adapter.rb +2 -2
  120. data/lib/rails_admin/support/csv_converter.rb +22 -42
  121. data/lib/rails_admin/version.rb +1 -1
  122. metadata +59 -18
  123. data/app/assets/stylesheets/rails_admin/bootstrap/_accordion.scss +0 -34
  124. data/app/assets/stylesheets/rails_admin/bootstrap/_hero-unit.scss +0 -25
  125. data/app/assets/stylesheets/rails_admin/bootstrap/_labels-badges.scss +0 -83
  126. data/app/assets/stylesheets/rails_admin/bootstrap/_layouts.scss +0 -16
  127. data/app/assets/stylesheets/rails_admin/bootstrap/_reset.scss +0 -216
  128. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-1200px-min.scss +0 -28
  129. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-767px-max.scss +0 -193
  130. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-768px-979px.scss +0 -19
  131. data/app/assets/stylesheets/rails_admin/bootstrap/_responsive-navbar.scss +0 -189
  132. data/app/assets/stylesheets/rails_admin/bootstrap/_sprites.scss +0 -197
  133. data/app/assets/stylesheets/rails_admin/bootstrap/responsive.scss +0 -48
@@ -1,155 +1,137 @@
1
- /* ============================================================
2
- * bootstrap-dropdown.js v2.3.2
3
- * http://getbootstrap.com/2.3.2/javascript.html#dropdowns
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 ($) {
22
-
23
- "use strict"; // jshint ;_;
24
-
25
-
26
- /* DROPDOWN CLASS DEFINITION
27
- * ========================= */
28
-
29
- var toggle = '[data-toggle=dropdown]'
30
- , Dropdown = function (element) {
31
- var $el = $(element).on('click.dropdown.data-api', this.toggle)
32
- $('html').on('click.dropdown.data-api', function () {
33
- $el.parent().removeClass('open')
34
- })
35
- }
1
+ /* ========================================================================
2
+ * Bootstrap: dropdown.js v3.2.0
3
+ * http://getbootstrap.com/javascript/#dropdowns
4
+ * ========================================================================
5
+ * Copyright 2011-2014 Twitter, Inc.
6
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
7
+ * ======================================================================== */
36
8
 
37
- Dropdown.prototype = {
38
9
 
39
- constructor: Dropdown
10
+ +function ($) {
11
+ 'use strict';
40
12
 
41
- , toggle: function (e) {
42
- var $this = $(this)
43
- , $parent
44
- , isActive
13
+ // DROPDOWN CLASS DEFINITION
14
+ // =========================
15
+
16
+ var backdrop = '.dropdown-backdrop'
17
+ var toggle = '[data-toggle="dropdown"]'
18
+ var Dropdown = function (element) {
19
+ $(element).on('click.bs.dropdown', this.toggle)
20
+ }
21
+
22
+ Dropdown.VERSION = '3.2.0'
45
23
 
46
- if ($this.is('.disabled, :disabled')) return
24
+ Dropdown.prototype.toggle = function (e) {
25
+ var $this = $(this)
47
26
 
48
- $parent = getParent($this)
27
+ if ($this.is('.disabled, :disabled')) return
49
28
 
50
- isActive = $parent.hasClass('open')
29
+ var $parent = getParent($this)
30
+ var isActive = $parent.hasClass('open')
51
31
 
52
- clearMenus()
32
+ clearMenus()
53
33
 
54
- if (!isActive) {
55
- if ('ontouchstart' in document.documentElement) {
56
- // if mobile we we use a backdrop because click events don't delegate
57
- $('<div class="dropdown-backdrop"/>').insertBefore($(this)).on('click', clearMenus)
58
- }
59
- $parent.toggleClass('open')
34
+ if (!isActive) {
35
+ if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
36
+ // if mobile we use a backdrop because click events don't delegate
37
+ $('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus)
60
38
  }
61
39
 
62
- $this.focus()
40
+ var relatedTarget = { relatedTarget: this }
41
+ $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))
63
42
 
64
- return false
65
- }
43
+ if (e.isDefaultPrevented()) return
66
44
 
67
- , keydown: function (e) {
68
- var $this
69
- , $items
70
- , $active
71
- , $parent
72
- , isActive
73
- , index
45
+ $this.trigger('focus')
74
46
 
75
- if (!/(38|40|27)/.test(e.keyCode)) return
47
+ $parent
48
+ .toggleClass('open')
49
+ .trigger('shown.bs.dropdown', relatedTarget)
50
+ }
76
51
 
77
- $this = $(this)
52
+ return false
53
+ }
78
54
 
79
- e.preventDefault()
80
- e.stopPropagation()
55
+ Dropdown.prototype.keydown = function (e) {
56
+ if (!/(38|40|27)/.test(e.keyCode)) return
81
57
 
82
- if ($this.is('.disabled, :disabled')) return
58
+ var $this = $(this)
83
59
 
84
- $parent = getParent($this)
60
+ e.preventDefault()
61
+ e.stopPropagation()
85
62
 
86
- isActive = $parent.hasClass('open')
63
+ if ($this.is('.disabled, :disabled')) return
87
64
 
88
- if (!isActive || (isActive && e.keyCode == 27)) {
89
- if (e.which == 27) $parent.find(toggle).focus()
90
- return $this.click()
91
- }
65
+ var $parent = getParent($this)
66
+ var isActive = $parent.hasClass('open')
92
67
 
93
- $items = $('[role=menu] li:not(.divider):visible a', $parent)
68
+ if (!isActive || (isActive && e.keyCode == 27)) {
69
+ if (e.which == 27) $parent.find(toggle).trigger('focus')
70
+ return $this.trigger('click')
71
+ }
94
72
 
95
- if (!$items.length) return
73
+ var desc = ' li:not(.divider):visible a'
74
+ var $items = $parent.find('[role="menu"]' + desc + ', [role="listbox"]' + desc)
96
75
 
97
- index = $items.index($items.filter(':focus'))
76
+ if (!$items.length) return
98
77
 
99
- if (e.keyCode == 38 && index > 0) index-- // up
100
- if (e.keyCode == 40 && index < $items.length - 1) index++ // down
101
- if (!~index) index = 0
78
+ var index = $items.index($items.filter(':focus'))
102
79
 
103
- $items
104
- .eq(index)
105
- .focus()
106
- }
80
+ if (e.keyCode == 38 && index > 0) index-- // up
81
+ if (e.keyCode == 40 && index < $items.length - 1) index++ // down
82
+ if (!~index) index = 0
107
83
 
84
+ $items.eq(index).trigger('focus')
108
85
  }
109
86
 
110
- function clearMenus() {
111
- $('.dropdown-backdrop').remove()
87
+ function clearMenus(e) {
88
+ if (e && e.which === 3) return
89
+ $(backdrop).remove()
112
90
  $(toggle).each(function () {
113
- getParent($(this)).removeClass('open')
91
+ var $parent = getParent($(this))
92
+ var relatedTarget = { relatedTarget: this }
93
+ if (!$parent.hasClass('open')) return
94
+ $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
95
+ if (e.isDefaultPrevented()) return
96
+ $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
114
97
  })
115
98
  }
116
99
 
117
100
  function getParent($this) {
118
101
  var selector = $this.attr('data-target')
119
- , $parent
120
102
 
121
103
  if (!selector) {
122
104
  selector = $this.attr('href')
123
- selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
105
+ selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
124
106
  }
125
107
 
126
- $parent = selector && $(selector)
108
+ var $parent = selector && $(selector)
127
109
 
128
- if (!$parent || !$parent.length) $parent = $this.parent()
129
-
130
- return $parent
110
+ return $parent && $parent.length ? $parent : $this.parent()
131
111
  }
132
112
 
133
113
 
134
- /* DROPDOWN PLUGIN DEFINITION
135
- * ========================== */
136
-
137
- var old = $.fn.dropdown
114
+ // DROPDOWN PLUGIN DEFINITION
115
+ // ==========================
138
116
 
139
- $.fn.dropdown = function (option) {
117
+ function Plugin(option) {
140
118
  return this.each(function () {
141
119
  var $this = $(this)
142
- , data = $this.data('dropdown')
143
- if (!data) $this.data('dropdown', (data = new Dropdown(this)))
120
+ var data = $this.data('bs.dropdown')
121
+
122
+ if (!data) $this.data('bs.dropdown', (data = new Dropdown(this)))
144
123
  if (typeof option == 'string') data[option].call($this)
145
124
  })
146
125
  }
147
126
 
127
+ var old = $.fn.dropdown
128
+
129
+ $.fn.dropdown = Plugin
148
130
  $.fn.dropdown.Constructor = Dropdown
149
131
 
150
132
 
151
- /* DROPDOWN NO CONFLICT
152
- * ==================== */
133
+ // DROPDOWN NO CONFLICT
134
+ // ====================
153
135
 
154
136
  $.fn.dropdown.noConflict = function () {
155
137
  $.fn.dropdown = old
@@ -157,13 +139,13 @@
157
139
  }
158
140
 
159
141
 
160
- /* APPLY TO STANDARD DROPDOWN ELEMENTS
161
- * =================================== */
142
+ // APPLY TO STANDARD DROPDOWN ELEMENTS
143
+ // ===================================
162
144
 
163
145
  $(document)
164
- .on('click.dropdown.data-api', clearMenus)
165
- .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
166
- .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
167
- .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
146
+ .on('click.bs.dropdown.data-api', clearMenus)
147
+ .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
148
+ .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
149
+ .on('keydown.bs.dropdown.data-api', toggle + ', [role="menu"], [role="listbox"]', Dropdown.prototype.keydown)
168
150
 
169
- }(window.jQuery);
151
+ }(jQuery);
@@ -1,224 +1,255 @@
1
- /* =========================================================
2
- * bootstrap-modal.js v2.3.2
3
- * http://getbootstrap.com/2.3.2/javascript.html#modals
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 ($) {
22
-
23
- "use strict"; // jshint ;_;
24
-
25
-
26
- /* MODAL CLASS DEFINITION
27
- * ====================== */
1
+ /* ========================================================================
2
+ * Bootstrap: modal.js v3.2.0
3
+ * http://getbootstrap.com/javascript/#modals
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
+ // MODAL CLASS DEFINITION
14
+ // ======================
28
15
 
29
16
  var Modal = function (element, options) {
30
- this.options = options
31
- this.$element = $(element)
32
- .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
33
- this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
17
+ this.options = options
18
+ this.$body = $(document.body)
19
+ this.$element = $(element)
20
+ this.$backdrop =
21
+ this.isShown = null
22
+ this.scrollbarWidth = 0
23
+
24
+ if (this.options.remote) {
25
+ this.$element
26
+ .find('.modal-content')
27
+ .load(this.options.remote, $.proxy(function () {
28
+ this.$element.trigger('loaded.bs.modal')
29
+ }, this))
30
+ }
34
31
  }
35
32
 
36
- Modal.prototype = {
33
+ Modal.VERSION = '3.2.0'
37
34
 
38
- constructor: Modal
35
+ Modal.DEFAULTS = {
36
+ backdrop: true,
37
+ keyboard: true,
38
+ show: true
39
+ }
39
40
 
40
- , toggle: function () {
41
- return this[!this.isShown ? 'show' : 'hide']()
42
- }
41
+ Modal.prototype.toggle = function (_relatedTarget) {
42
+ return this.isShown ? this.hide() : this.show(_relatedTarget)
43
+ }
43
44
 
44
- , show: function () {
45
- var that = this
46
- , e = $.Event('show')
45
+ Modal.prototype.show = function (_relatedTarget) {
46
+ var that = this
47
+ var e = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
47
48
 
48
- this.$element.trigger(e)
49
+ this.$element.trigger(e)
49
50
 
50
- if (this.isShown || e.isDefaultPrevented()) return
51
+ if (this.isShown || e.isDefaultPrevented()) return
51
52
 
52
- this.isShown = true
53
+ this.isShown = true
53
54
 
54
- this.escape()
55
+ this.checkScrollbar()
56
+ this.$body.addClass('modal-open')
55
57
 
56
- this.backdrop(function () {
57
- var transition = $.support.transition && that.$element.hasClass('fade')
58
+ this.setScrollbar()
59
+ this.escape()
58
60
 
59
- if (!that.$element.parent().length) {
60
- that.$element.appendTo(document.body) //don't move modals dom position
61
- }
61
+ this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
62
62
 
63
- that.$element.show()
63
+ this.backdrop(function () {
64
+ var transition = $.support.transition && that.$element.hasClass('fade')
64
65
 
65
- if (transition) {
66
- that.$element[0].offsetWidth // force reflow
67
- }
66
+ if (!that.$element.parent().length) {
67
+ that.$element.appendTo(that.$body) // don't move modals dom position
68
+ }
68
69
 
69
- that.$element
70
- .addClass('in')
71
- .attr('aria-hidden', false)
70
+ that.$element
71
+ .show()
72
+ .scrollTop(0)
72
73
 
73
- that.enforceFocus()
74
+ if (transition) {
75
+ that.$element[0].offsetWidth // force reflow
76
+ }
74
77
 
75
- transition ?
76
- that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) :
77
- that.$element.focus().trigger('shown')
78
+ that.$element
79
+ .addClass('in')
80
+ .attr('aria-hidden', false)
78
81
 
79
- })
80
- }
82
+ that.enforceFocus()
83
+
84
+ var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
81
85
 
82
- , hide: function (e) {
83
- e && e.preventDefault()
86
+ transition ?
87
+ that.$element.find('.modal-dialog') // wait for modal to slide in
88
+ .one('bsTransitionEnd', function () {
89
+ that.$element.trigger('focus').trigger(e)
90
+ })
91
+ .emulateTransitionEnd(300) :
92
+ that.$element.trigger('focus').trigger(e)
93
+ })
94
+ }
84
95
 
85
- var that = this
96
+ Modal.prototype.hide = function (e) {
97
+ if (e) e.preventDefault()
86
98
 
87
- e = $.Event('hide')
99
+ e = $.Event('hide.bs.modal')
88
100
 
89
- this.$element.trigger(e)
101
+ this.$element.trigger(e)
90
102
 
91
- if (!this.isShown || e.isDefaultPrevented()) return
103
+ if (!this.isShown || e.isDefaultPrevented()) return
92
104
 
93
- this.isShown = false
105
+ this.isShown = false
94
106
 
95
- this.escape()
107
+ this.$body.removeClass('modal-open')
96
108
 
97
- $(document).off('focusin.modal')
109
+ this.resetScrollbar()
110
+ this.escape()
98
111
 
99
- this.$element
100
- .removeClass('in')
101
- .attr('aria-hidden', true)
112
+ $(document).off('focusin.bs.modal')
102
113
 
103
- $.support.transition && this.$element.hasClass('fade') ?
104
- this.hideWithTransition() :
105
- this.hideModal()
106
- }
114
+ this.$element
115
+ .removeClass('in')
116
+ .attr('aria-hidden', true)
117
+ .off('click.dismiss.bs.modal')
107
118
 
108
- , enforceFocus: function () {
109
- var that = this
110
- $(document).on('focusin.modal', function (e) {
111
- if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
112
- that.$element.focus()
113
- }
114
- })
115
- }
119
+ $.support.transition && this.$element.hasClass('fade') ?
120
+ this.$element
121
+ .one('bsTransitionEnd', $.proxy(this.hideModal, this))
122
+ .emulateTransitionEnd(300) :
123
+ this.hideModal()
124
+ }
116
125
 
117
- , escape: function () {
118
- var that = this
119
- if (this.isShown && this.options.keyboard) {
120
- this.$element.on('keyup.dismiss.modal', function ( e ) {
121
- e.which == 27 && that.hide()
122
- })
123
- } else if (!this.isShown) {
124
- this.$element.off('keyup.dismiss.modal')
126
+ Modal.prototype.enforceFocus = function () {
127
+ $(document)
128
+ .off('focusin.bs.modal') // guard against infinite focus loop
129
+ .on('focusin.bs.modal', $.proxy(function (e) {
130
+ if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
131
+ this.$element.trigger('focus')
125
132
  }
126
- }
127
-
128
- , hideWithTransition: function () {
129
- var that = this
130
- , timeout = setTimeout(function () {
131
- that.$element.off($.support.transition.end)
132
- that.hideModal()
133
- }, 500)
134
-
135
- this.$element.one($.support.transition.end, function () {
136
- clearTimeout(timeout)
137
- that.hideModal()
138
- })
139
- }
133
+ }, this))
134
+ }
140
135
 
141
- , hideModal: function () {
142
- var that = this
143
- this.$element.hide()
144
- this.backdrop(function () {
145
- that.removeBackdrop()
146
- that.$element.trigger('hidden')
147
- })
148
- }
136
+ Modal.prototype.escape = function () {
137
+ if (this.isShown && this.options.keyboard) {
138
+ this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) {
139
+ e.which == 27 && this.hide()
140
+ }, this))
141
+ } else if (!this.isShown) {
142
+ this.$element.off('keyup.dismiss.bs.modal')
143
+ }
144
+ }
149
145
 
150
- , removeBackdrop: function () {
151
- this.$backdrop && this.$backdrop.remove()
152
- this.$backdrop = null
153
- }
146
+ Modal.prototype.hideModal = function () {
147
+ var that = this
148
+ this.$element.hide()
149
+ this.backdrop(function () {
150
+ that.$element.trigger('hidden.bs.modal')
151
+ })
152
+ }
154
153
 
155
- , backdrop: function (callback) {
156
- var that = this
157
- , animate = this.$element.hasClass('fade') ? 'fade' : ''
154
+ Modal.prototype.removeBackdrop = function () {
155
+ this.$backdrop && this.$backdrop.remove()
156
+ this.$backdrop = null
157
+ }
158
158
 
159
- if (this.isShown && this.options.backdrop) {
160
- var doAnimate = $.support.transition && animate
159
+ Modal.prototype.backdrop = function (callback) {
160
+ var that = this
161
+ var animate = this.$element.hasClass('fade') ? 'fade' : ''
161
162
 
162
- this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
163
- .appendTo(document.body)
163
+ if (this.isShown && this.options.backdrop) {
164
+ var doAnimate = $.support.transition && animate
164
165
 
165
- this.$backdrop.click(
166
- this.options.backdrop == 'static' ?
167
- $.proxy(this.$element[0].focus, this.$element[0])
168
- : $.proxy(this.hide, this)
169
- )
166
+ this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
167
+ .appendTo(this.$body)
170
168
 
171
- if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
169
+ this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
170
+ if (e.target !== e.currentTarget) return
171
+ this.options.backdrop == 'static'
172
+ ? this.$element[0].focus.call(this.$element[0])
173
+ : this.hide.call(this)
174
+ }, this))
172
175
 
173
- this.$backdrop.addClass('in')
176
+ if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
174
177
 
175
- if (!callback) return
178
+ this.$backdrop.addClass('in')
176
179
 
177
- doAnimate ?
178
- this.$backdrop.one($.support.transition.end, callback) :
179
- callback()
180
+ if (!callback) return
180
181
 
181
- } else if (!this.isShown && this.$backdrop) {
182
- this.$backdrop.removeClass('in')
182
+ doAnimate ?
183
+ this.$backdrop
184
+ .one('bsTransitionEnd', callback)
185
+ .emulateTransitionEnd(150) :
186
+ callback()
183
187
 
184
- $.support.transition && this.$element.hasClass('fade')?
185
- this.$backdrop.one($.support.transition.end, callback) :
186
- callback()
188
+ } else if (!this.isShown && this.$backdrop) {
189
+ this.$backdrop.removeClass('in')
187
190
 
188
- } else if (callback) {
189
- callback()
190
- }
191
+ var callbackRemove = function () {
192
+ that.removeBackdrop()
193
+ callback && callback()
191
194
  }
195
+ $.support.transition && this.$element.hasClass('fade') ?
196
+ this.$backdrop
197
+ .one('bsTransitionEnd', callbackRemove)
198
+ .emulateTransitionEnd(150) :
199
+ callbackRemove()
200
+
201
+ } else if (callback) {
202
+ callback()
203
+ }
204
+ }
205
+
206
+ Modal.prototype.checkScrollbar = function () {
207
+ if (document.body.clientWidth >= window.innerWidth) return
208
+ this.scrollbarWidth = this.scrollbarWidth || this.measureScrollbar()
192
209
  }
193
210
 
211
+ Modal.prototype.setScrollbar = function () {
212
+ var bodyPad = parseInt((this.$body.css('padding-right') || 0), 10)
213
+ if (this.scrollbarWidth) this.$body.css('padding-right', bodyPad + this.scrollbarWidth)
214
+ }
194
215
 
195
- /* MODAL PLUGIN DEFINITION
196
- * ======================= */
216
+ Modal.prototype.resetScrollbar = function () {
217
+ this.$body.css('padding-right', '')
218
+ }
219
+
220
+ Modal.prototype.measureScrollbar = function () { // thx walsh
221
+ var scrollDiv = document.createElement('div')
222
+ scrollDiv.className = 'modal-scrollbar-measure'
223
+ this.$body.append(scrollDiv)
224
+ var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
225
+ this.$body[0].removeChild(scrollDiv)
226
+ return scrollbarWidth
227
+ }
197
228
 
198
- var old = $.fn.modal
199
229
 
200
- $.fn.modal = function (option) {
230
+ // MODAL PLUGIN DEFINITION
231
+ // =======================
232
+
233
+ function Plugin(option, _relatedTarget) {
201
234
  return this.each(function () {
202
- var $this = $(this)
203
- , data = $this.data('modal')
204
- , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
205
- if (!data) $this.data('modal', (data = new Modal(this, options)))
206
- if (typeof option == 'string') data[option]()
207
- else if (options.show) data.show()
235
+ var $this = $(this)
236
+ var data = $this.data('bs.modal')
237
+ var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
238
+
239
+ if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
240
+ if (typeof option == 'string') data[option](_relatedTarget)
241
+ else if (options.show) data.show(_relatedTarget)
208
242
  })
209
243
  }
210
244
 
211
- $.fn.modal.defaults = {
212
- backdrop: true
213
- , keyboard: true
214
- , show: true
215
- }
245
+ var old = $.fn.modal
216
246
 
247
+ $.fn.modal = Plugin
217
248
  $.fn.modal.Constructor = Modal
218
249
 
219
250
 
220
- /* MODAL NO CONFLICT
221
- * ================= */
251
+ // MODAL NO CONFLICT
252
+ // =================
222
253
 
223
254
  $.fn.modal.noConflict = function () {
224
255
  $.fn.modal = old
@@ -226,22 +257,24 @@
226
257
  }
227
258
 
228
259
 
229
- /* MODAL DATA-API
230
- * ============== */
260
+ // MODAL DATA-API
261
+ // ==============
231
262
 
232
- $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
233
- var $this = $(this)
234
- , href = $this.attr('href')
235
- , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
236
- , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())
263
+ $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
264
+ var $this = $(this)
265
+ var href = $this.attr('href')
266
+ var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7
267
+ var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
237
268
 
238
- e.preventDefault()
269
+ if ($this.is('a')) e.preventDefault()
239
270
 
240
- $target
241
- .modal(option)
242
- .one('hide', function () {
243
- $this.focus()
271
+ $target.one('show.bs.modal', function (showEvent) {
272
+ if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown
273
+ $target.one('hidden.bs.modal', function () {
274
+ $this.is(':visible') && $this.trigger('focus')
244
275
  })
276
+ })
277
+ Plugin.call($target, option, this)
245
278
  })
246
279
 
247
- }(window.jQuery);
280
+ }(jQuery);