bootstrap-generators 1.4.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (101) hide show
  1. data/README.md +238 -21
  2. data/bootstrap-generators.gemspec +3 -3
  3. data/lib/bootstrap-generators.rb +0 -1
  4. data/lib/bootstrap/generators/version.rb +1 -1
  5. data/lib/generators/bootstrap/install/install_generator.rb +5 -12
  6. data/lib/generators/bootstrap/install/templates/assets/stylesheets/fluid.css +5 -5
  7. data/lib/generators/bootstrap/install/templates/assets/stylesheets/fluid.css.less +119 -0
  8. data/lib/generators/bootstrap/install/templates/assets/stylesheets/fluid.css.scss +5 -5
  9. data/lib/generators/bootstrap/install/templates/assets/stylesheets/hero.css +0 -5
  10. data/lib/generators/bootstrap/install/templates/assets/stylesheets/hero.css.less +114 -0
  11. data/lib/generators/bootstrap/install/templates/assets/stylesheets/hero.css.scss +0 -5
  12. data/lib/generators/bootstrap/install/templates/config/initializers/simple_form.rb +118 -40
  13. data/lib/generators/bootstrap/install/templates/config/locales/simple_form.en.yml +24 -0
  14. data/lib/generators/bootstrap/install/templates/form_builders/form_builder/_form.html.erb +9 -8
  15. data/lib/generators/bootstrap/install/templates/form_builders/form_builder/_form.html.haml +8 -7
  16. data/lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.erb +5 -7
  17. data/lib/generators/bootstrap/install/templates/form_builders/simple_form/_form.html.haml +6 -7
  18. data/lib/generators/bootstrap/install/templates/layouts/fluid.html.erb +50 -47
  19. data/lib/generators/bootstrap/install/templates/layouts/fluid.html.haml +75 -55
  20. data/lib/generators/bootstrap/install/templates/layouts/hero.html.erb +11 -14
  21. data/lib/generators/bootstrap/install/templates/layouts/hero.html.haml +9 -11
  22. data/lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/edit.html.erb +8 -2
  23. data/lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/index.html.erb +5 -2
  24. data/lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/new.html.erb +4 -1
  25. data/lib/generators/bootstrap/install/templates/lib/templates/erb/scaffold/show.html.erb +8 -2
  26. data/lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/edit.html.haml +6 -2
  27. data/lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/index.html.haml +4 -2
  28. data/lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/new.html.haml +3 -1
  29. data/lib/generators/bootstrap/install/templates/lib/templates/haml/scaffold/show.html.haml +6 -2
  30. data/test/lib/generators/bootstrap/install_generator_test.rb +6 -20
  31. data/test/test_helper.rb +1 -1
  32. data/vendor/assets/images/glyphicons-halflings-white.png +0 -0
  33. data/vendor/assets/images/glyphicons-halflings.png +0 -0
  34. data/vendor/assets/javascripts/bootstrap-alert.js +91 -0
  35. data/vendor/assets/javascripts/bootstrap-button.js +98 -0
  36. data/vendor/assets/javascripts/bootstrap-carousel.js +154 -0
  37. data/vendor/assets/javascripts/bootstrap-collapse.js +136 -0
  38. data/vendor/assets/javascripts/bootstrap-dropdown.js +58 -21
  39. data/vendor/assets/javascripts/bootstrap-modal.js +63 -114
  40. data/vendor/assets/javascripts/bootstrap-popover.js +38 -33
  41. data/vendor/assets/javascripts/bootstrap-scrollspy.js +62 -44
  42. data/vendor/assets/javascripts/bootstrap-tab.js +130 -0
  43. data/vendor/assets/javascripts/bootstrap-tooltip.js +270 -0
  44. data/vendor/assets/javascripts/bootstrap-transition.js +51 -0
  45. data/vendor/assets/javascripts/bootstrap-typeahead.js +271 -0
  46. data/vendor/assets/javascripts/bootstrap.js +11 -6
  47. data/vendor/assets/stylesheets/bootstrap.css +2497 -1602
  48. data/vendor/assets/stylesheets/less/accordion.less +28 -0
  49. data/vendor/assets/stylesheets/less/alerts.less +70 -0
  50. data/vendor/assets/stylesheets/less/bootstrap.less +62 -0
  51. data/vendor/assets/stylesheets/less/breadcrumbs.less +22 -0
  52. data/vendor/assets/stylesheets/less/button-groups.less +147 -0
  53. data/vendor/assets/stylesheets/less/buttons.less +165 -0
  54. data/vendor/assets/stylesheets/less/carousel.less +121 -0
  55. data/vendor/assets/stylesheets/less/close.less +18 -0
  56. data/vendor/assets/stylesheets/less/code.less +44 -0
  57. data/vendor/assets/stylesheets/less/component-animations.less +18 -0
  58. data/vendor/assets/stylesheets/less/dropdowns.less +131 -0
  59. data/vendor/assets/stylesheets/less/forms.less +515 -0
  60. data/vendor/assets/stylesheets/less/grid.less +8 -0
  61. data/vendor/assets/stylesheets/less/hero-unit.less +20 -0
  62. data/vendor/assets/stylesheets/less/labels.less +16 -0
  63. data/vendor/assets/stylesheets/less/layouts.less +17 -0
  64. data/vendor/assets/stylesheets/less/mixins.less +537 -0
  65. data/vendor/assets/stylesheets/less/modals.less +72 -0
  66. data/vendor/assets/stylesheets/less/navbar.less +292 -0
  67. data/vendor/assets/stylesheets/less/navs.less +344 -0
  68. data/vendor/assets/stylesheets/less/pager.less +30 -0
  69. data/vendor/assets/stylesheets/less/pagination.less +55 -0
  70. data/vendor/assets/stylesheets/less/popovers.less +49 -0
  71. data/vendor/assets/stylesheets/less/progress-bars.less +95 -0
  72. data/vendor/assets/stylesheets/less/reset.less +126 -0
  73. data/vendor/assets/stylesheets/less/responsive.less +323 -0
  74. data/vendor/assets/stylesheets/less/scaffolding.less +29 -0
  75. data/vendor/assets/stylesheets/less/sprites.less +156 -0
  76. data/vendor/assets/stylesheets/less/tables.less +139 -0
  77. data/vendor/assets/stylesheets/less/thumbnails.less +35 -0
  78. data/vendor/assets/stylesheets/less/tooltip.less +35 -0
  79. data/vendor/assets/stylesheets/less/type.less +217 -0
  80. data/vendor/assets/stylesheets/less/utilities.less +23 -0
  81. data/vendor/assets/stylesheets/less/variables.less +99 -0
  82. data/vendor/assets/stylesheets/less/wells.less +17 -0
  83. metadata +62 -33
  84. data/lib/bootstrap/helpers/form_builder.rb +0 -26
  85. data/lib/generators/bootstrap/install/templates/app/inputs/boolean_input.rb +0 -12
  86. data/lib/generators/bootstrap/install/templates/app/inputs/collection_input.rb +0 -12
  87. data/lib/generators/bootstrap/install/templates/app/inputs/date_time_input.rb +0 -16
  88. data/lib/generators/bootstrap/install/templates/app/inputs/file_input.rb +0 -16
  89. data/lib/generators/bootstrap/install/templates/app/inputs/numeric_input.rb +0 -16
  90. data/lib/generators/bootstrap/install/templates/app/inputs/password_input.rb +0 -16
  91. data/lib/generators/bootstrap/install/templates/app/inputs/string_input.rb +0 -16
  92. data/lib/generators/bootstrap/install/templates/app/inputs/text_input.rb +0 -16
  93. data/lib/generators/bootstrap/install/templates/assets/stylesheets/container-app.css +0 -53
  94. data/lib/generators/bootstrap/install/templates/assets/stylesheets/container-app.css.scss +0 -55
  95. data/lib/generators/bootstrap/install/templates/layouts/container-app.html.erb +0 -58
  96. data/lib/generators/bootstrap/install/templates/layouts/container-app.html.haml +0 -46
  97. data/vendor/assets/javascripts/bootstrap-alerts.js +0 -113
  98. data/vendor/assets/javascripts/bootstrap-buttons.js +0 -62
  99. data/vendor/assets/javascripts/bootstrap-tabs.js +0 -80
  100. data/vendor/assets/javascripts/bootstrap-twipsy.js +0 -321
  101. data/vendor/assets/stylesheets/bootstrap.min.css +0 -356
@@ -1,5 +1,7 @@
1
1
  .page-header
2
- = link_to 'Back', <%= index_helper %>_path, :class => 'btn'
2
+ = link_to <%= index_helper %>_path, :class => 'btn' do
3
+ %i.icon-list-alt
4
+ Back
3
5
  %h1 New <%= singular_table_name %>
4
6
 
5
7
  = render 'form'
@@ -1,6 +1,10 @@
1
1
  .page-header
2
- = link_to 'Back', <%= index_helper %>_path, :class => 'btn'
3
- = link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => 'btn primary'
2
+ = link_to <%= index_helper %>_path, :class => 'btn' do
3
+ %i.icon-list-alt
4
+ Back
5
+ = link_to edit_<%= singular_table_name %>_path(@<%= singular_table_name %>), :class => 'btn btn-primary' do
6
+ %i.icon-pencil.icon-white
7
+ Edit
4
8
  %h1 Listing <%= plural_table_name %>
5
9
 
6
10
  %dl
@@ -58,6 +58,12 @@ class Bootstrap::Generators::InstallGeneratorTest < ::Rails::Generators::TestCas
58
58
  assert_file "app/assets/stylesheets/bootstrap-generators.css.scss"
59
59
  end
60
60
 
61
+ test "should copy less files" do
62
+ run_generator %w(--stylesheet-engine less)
63
+
64
+ assert_file "app/assets/stylesheets/bootstrap-generators.css.less"
65
+ end
66
+
61
67
  test "should create erb layout" do
62
68
  run_generator
63
69
 
@@ -76,24 +82,12 @@ class Bootstrap::Generators::InstallGeneratorTest < ::Rails::Generators::TestCas
76
82
  assert_file "app/views/layouts/application.html.erb"
77
83
  end
78
84
 
79
- test "should create container-app erb layout" do
80
- run_generator %w(--layout container-app)
81
-
82
- assert_file "app/views/layouts/application.html.erb"
83
- end
84
-
85
85
  test "should create fluid haml layout" do
86
86
  run_generator %w(--template-engine haml --layout fluid)
87
87
 
88
88
  assert_file "app/views/layouts/application.html.haml"
89
89
  end
90
90
 
91
- test "should create container-app haml layout" do
92
- run_generator %w(--template-engine haml --layout container-app)
93
-
94
- assert_file "app/views/layouts/application.html.haml"
95
- end
96
-
97
91
  test "should create erb form partial with simple_form form builder" do
98
92
  run_generator %w(--form-builder simple_form)
99
93
 
@@ -106,14 +100,6 @@ class Bootstrap::Generators::InstallGeneratorTest < ::Rails::Generators::TestCas
106
100
  assert_file "lib/templates/haml/scaffold/_form.html.haml"
107
101
  end
108
102
 
109
- test "should copy inputs when simple_form form builder selected" do
110
- run_generator %w(--form-builder simple_form)
111
-
112
- %w(boolean collection date_time file numeric password string text).each { |input|
113
- assert_file "app/inputs/#{input}_input.rb"
114
- }
115
- end
116
-
117
103
  test "should copy config when simple_form form builder selected" do
118
104
  run_generator %w(--form-builder simple_form)
119
105
 
data/test/test_helper.rb CHANGED
@@ -20,7 +20,7 @@ Rails.application.config.root = Rails.root
20
20
 
21
21
  # Call configure to load the settings from
22
22
  # Rails.application.config.generators to Rails::Generators
23
- Rails::Generators.configure!
23
+ # Rails::Generators.configure!
24
24
 
25
25
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
26
26
 
@@ -0,0 +1,91 @@
1
+ /* ==========================================================
2
+ * bootstrap-alert.js v2.0.0
3
+ * http://twitter.github.com/bootstrap/javascript.html#alerts
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"
24
+
25
+ /* ALERT CLASS DEFINITION
26
+ * ====================== */
27
+
28
+ var dismiss = '[data-dismiss="alert"]'
29
+ , Alert = function ( el ) {
30
+ $(el).on('click', dismiss, this.close)
31
+ }
32
+
33
+ Alert.prototype = {
34
+
35
+ constructor: Alert
36
+
37
+ , close: function ( e ) {
38
+ var $this = $(this)
39
+ , selector = $this.attr('data-target')
40
+ , $parent
41
+
42
+ if (!selector) {
43
+ selector = $this.attr('href')
44
+ selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
45
+ }
46
+
47
+ $parent = $(selector)
48
+ $parent.trigger('close')
49
+
50
+ e && e.preventDefault()
51
+
52
+ $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
53
+
54
+ $parent.removeClass('in')
55
+
56
+ function removeElement() {
57
+ $parent.remove()
58
+ $parent.trigger('closed')
59
+ }
60
+
61
+ $.support.transition && $parent.hasClass('fade') ?
62
+ $parent.on($.support.transition.end, removeElement) :
63
+ removeElement()
64
+ }
65
+
66
+ }
67
+
68
+
69
+ /* ALERT PLUGIN DEFINITION
70
+ * ======================= */
71
+
72
+ $.fn.alert = function ( option ) {
73
+ return this.each(function () {
74
+ var $this = $(this)
75
+ , data = $this.data('alert')
76
+ if (!data) $this.data('alert', (data = new Alert(this)))
77
+ if (typeof option == 'string') data[option].call($this)
78
+ })
79
+ }
80
+
81
+ $.fn.alert.Constructor = Alert
82
+
83
+
84
+ /* ALERT DATA-API
85
+ * ============== */
86
+
87
+ $(function () {
88
+ $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
89
+ })
90
+
91
+ }( window.jQuery )
@@ -0,0 +1,98 @@
1
+ /* ============================================================
2
+ * bootstrap-button.js v2.0.0
3
+ * http://twitter.github.com/bootstrap/javascript.html#buttons
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
+ !function( $ ){
21
+
22
+ "use strict"
23
+
24
+ /* BUTTON PUBLIC CLASS DEFINITION
25
+ * ============================== */
26
+
27
+ var Button = function ( element, options ) {
28
+ this.$element = $(element)
29
+ this.options = $.extend({}, $.fn.button.defaults, options)
30
+ }
31
+
32
+ Button.prototype = {
33
+
34
+ constructor: Button
35
+
36
+ , setState: function ( state ) {
37
+ var d = 'disabled'
38
+ , $el = this.$element
39
+ , data = $el.data()
40
+ , val = $el.is('input') ? 'val' : 'html'
41
+
42
+ state = state + 'Text'
43
+ data.resetText || $el.data('resetText', $el[val]())
44
+
45
+ $el[val](data[state] || this.options[state])
46
+
47
+ // push to event loop to allow forms to submit
48
+ setTimeout(function () {
49
+ state == 'loadingText' ?
50
+ $el.addClass(d).attr(d, d) :
51
+ $el.removeClass(d).removeAttr(d)
52
+ }, 0)
53
+ }
54
+
55
+ , toggle: function () {
56
+ var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
57
+
58
+ $parent && $parent
59
+ .find('.active')
60
+ .removeClass('active')
61
+
62
+ this.$element.toggleClass('active')
63
+ }
64
+
65
+ }
66
+
67
+
68
+ /* BUTTON PLUGIN DEFINITION
69
+ * ======================== */
70
+
71
+ $.fn.button = function ( option ) {
72
+ return this.each(function () {
73
+ var $this = $(this)
74
+ , data = $this.data('button')
75
+ , options = typeof option == 'object' && option
76
+ if (!data) $this.data('button', (data = new Button(this, options)))
77
+ if (option == 'toggle') data.toggle()
78
+ else if (option) data.setState(option)
79
+ })
80
+ }
81
+
82
+ $.fn.button.defaults = {
83
+ loadingText: 'loading...'
84
+ }
85
+
86
+ $.fn.button.Constructor = Button
87
+
88
+
89
+ /* BUTTON DATA-API
90
+ * =============== */
91
+
92
+ $(function () {
93
+ $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
94
+ $(e.target).button('toggle')
95
+ })
96
+ })
97
+
98
+ }( window.jQuery )
@@ -0,0 +1,154 @@
1
+ /* ==========================================================
2
+ * bootstrap-carousel.js v2.0.0
3
+ * http://twitter.github.com/bootstrap/javascript.html#carousel
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"
24
+
25
+ /* CAROUSEL CLASS DEFINITION
26
+ * ========================= */
27
+
28
+ var Carousel = function (element, options) {
29
+ this.$element = $(element)
30
+ this.options = $.extend({}, $.fn.carousel.defaults, options)
31
+ this.options.slide && this.slide(this.options.slide)
32
+ }
33
+
34
+ Carousel.prototype = {
35
+
36
+ cycle: function () {
37
+ this.interval = setInterval($.proxy(this.next, this), this.options.interval)
38
+ return this
39
+ }
40
+
41
+ , to: function (pos) {
42
+ var $active = this.$element.find('.active')
43
+ , children = $active.parent().children()
44
+ , activePos = children.index($active)
45
+ , that = this
46
+
47
+ if (pos > (children.length - 1) || pos < 0) return
48
+
49
+ if (this.sliding) {
50
+ return this.$element.one('slid', function () {
51
+ that.to(pos)
52
+ })
53
+ }
54
+
55
+ if (activePos == pos) {
56
+ return this.pause().cycle()
57
+ }
58
+
59
+ return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
60
+ }
61
+
62
+ , pause: function () {
63
+ clearInterval(this.interval)
64
+ return this
65
+ }
66
+
67
+ , next: function () {
68
+ if (this.sliding) return
69
+ return this.slide('next')
70
+ }
71
+
72
+ , prev: function () {
73
+ if (this.sliding) return
74
+ return this.slide('prev')
75
+ }
76
+
77
+ , slide: function (type, next) {
78
+ var $active = this.$element.find('.active')
79
+ , $next = next || $active[type]()
80
+ , isCycling = this.interval
81
+ , direction = type == 'next' ? 'left' : 'right'
82
+ , fallback = type == 'next' ? 'first' : 'last'
83
+ , that = this
84
+
85
+ this.sliding = true
86
+
87
+ isCycling && this.pause()
88
+
89
+ $next = $next.length ? $next : this.$element.find('.item')[fallback]()
90
+
91
+ if (!$.support.transition && this.$element.hasClass('slide')) {
92
+ this.$element.trigger('slide')
93
+ $active.removeClass('active')
94
+ $next.addClass('active')
95
+ this.sliding = false
96
+ this.$element.trigger('slid')
97
+ } else {
98
+ $next.addClass(type)
99
+ $next[0].offsetWidth // force reflow
100
+ $active.addClass(direction)
101
+ $next.addClass(direction)
102
+ this.$element.trigger('slide')
103
+ this.$element.one($.support.transition.end, function () {
104
+ $next.removeClass([type, direction].join(' ')).addClass('active')
105
+ $active.removeClass(['active', direction].join(' '))
106
+ that.sliding = false
107
+ setTimeout(function () { that.$element.trigger('slid') }, 0)
108
+ })
109
+ }
110
+
111
+ isCycling && this.cycle()
112
+
113
+ return this
114
+ }
115
+
116
+ }
117
+
118
+
119
+ /* CAROUSEL PLUGIN DEFINITION
120
+ * ========================== */
121
+
122
+ $.fn.carousel = function ( option ) {
123
+ return this.each(function () {
124
+ var $this = $(this)
125
+ , data = $this.data('carousel')
126
+ , options = typeof option == 'object' && option
127
+ if (!data) $this.data('carousel', (data = new Carousel(this, options)))
128
+ if (typeof option == 'number') data.to(option)
129
+ else if (typeof option == 'string' || (option = options.slide)) data[option]()
130
+ else data.cycle()
131
+ })
132
+ }
133
+
134
+ $.fn.carousel.defaults = {
135
+ interval: 5000
136
+ }
137
+
138
+ $.fn.carousel.Constructor = Carousel
139
+
140
+
141
+ /* CAROUSEL DATA-API
142
+ * ================= */
143
+
144
+ $(function () {
145
+ $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
146
+ var $this = $(this), href
147
+ , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
148
+ , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
149
+ $target.carousel(options)
150
+ e.preventDefault()
151
+ })
152
+ })
153
+
154
+ }( window.jQuery )
@@ -0,0 +1,136 @@
1
+ /* =============================================================
2
+ * bootstrap-collapse.js v2.0.0
3
+ * http://twitter.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
+ !function( $ ){
21
+
22
+ "use strict"
23
+
24
+ var Collapse = function ( element, options ) {
25
+ this.$element = $(element)
26
+ this.options = $.extend({}, $.fn.collapse.defaults, options)
27
+
28
+ if (this.options["parent"]) {
29
+ this.$parent = $(this.options["parent"])
30
+ }
31
+
32
+ this.options.toggle && this.toggle()
33
+ }
34
+
35
+ Collapse.prototype = {
36
+
37
+ constructor: Collapse
38
+
39
+ , dimension: function () {
40
+ var hasWidth = this.$element.hasClass('width')
41
+ return hasWidth ? 'width' : 'height'
42
+ }
43
+
44
+ , show: function () {
45
+ var dimension = this.dimension()
46
+ , scroll = $.camelCase(['scroll', dimension].join('-'))
47
+ , actives = this.$parent && this.$parent.find('.in')
48
+ , hasData
49
+
50
+ if (actives && actives.length) {
51
+ hasData = actives.data('collapse')
52
+ actives.collapse('hide')
53
+ hasData || actives.data('collapse', null)
54
+ }
55
+
56
+ this.$element[dimension](0)
57
+ this.transition('addClass', 'show', 'shown')
58
+ this.$element[dimension](this.$element[0][scroll])
59
+
60
+ }
61
+
62
+ , hide: function () {
63
+ var dimension = this.dimension()
64
+ this.reset(this.$element[dimension]())
65
+ this.transition('removeClass', 'hide', 'hidden')
66
+ this.$element[dimension](0)
67
+ }
68
+
69
+ , reset: function ( size ) {
70
+ var dimension = this.dimension()
71
+
72
+ this.$element
73
+ .removeClass('collapse')
74
+ [dimension](size || 'auto')
75
+ [0].offsetWidth
76
+
77
+ this.$element.addClass('collapse')
78
+ }
79
+
80
+ , transition: function ( method, startEvent, completeEvent ) {
81
+ var that = this
82
+ , complete = function () {
83
+ if (startEvent == 'show') that.reset()
84
+ that.$element.trigger(completeEvent)
85
+ }
86
+
87
+ this.$element
88
+ .trigger(startEvent)
89
+ [method]('in')
90
+
91
+ $.support.transition && this.$element.hasClass('collapse') ?
92
+ this.$element.one($.support.transition.end, complete) :
93
+ complete()
94
+ }
95
+
96
+ , toggle: function () {
97
+ this[this.$element.hasClass('in') ? 'hide' : 'show']()
98
+ }
99
+
100
+ }
101
+
102
+ /* COLLAPSIBLE PLUGIN DEFINITION
103
+ * ============================== */
104
+
105
+ $.fn.collapse = function ( option ) {
106
+ return this.each(function () {
107
+ var $this = $(this)
108
+ , data = $this.data('collapse')
109
+ , options = typeof option == 'object' && option
110
+ if (!data) $this.data('collapse', (data = new Collapse(this, options)))
111
+ if (typeof option == 'string') data[option]()
112
+ })
113
+ }
114
+
115
+ $.fn.collapse.defaults = {
116
+ toggle: true
117
+ }
118
+
119
+ $.fn.collapse.Constructor = Collapse
120
+
121
+
122
+ /* COLLAPSIBLE DATA-API
123
+ * ==================== */
124
+
125
+ $(function () {
126
+ $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
127
+ var $this = $(this), href
128
+ , target = $this.attr('data-target')
129
+ || e.preventDefault()
130
+ || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
131
+ , option = $(target).data('collapse') ? 'toggle' : $this.data()
132
+ $(target).collapse(option)
133
+ })
134
+ })
135
+
136
+ }( window.jQuery )