simple_form-bootstrap 1.2.0 → 1.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26489ef93ca2d29986f6fc2d779623da2c704f43
4
- data.tar.gz: a454186a41d7d02312d8112171226a86eae7ce2d
3
+ metadata.gz: a661ed8effde4d148bc4742b5830e7d3ad159424
4
+ data.tar.gz: 6f46a48bfc692ef807c69c0efa0c3b367e911405
5
5
  SHA512:
6
- metadata.gz: 07fa325718226174d0578ee1a50e63303ef02496a428c848a6eade551e3f10e3692af548120d27ff0157778d5ac09c7513dc81d229f98fc1d1f91e693eb22634
7
- data.tar.gz: da29bb5246335fa3a0133618bf87932e7c1db353ff949393b07d3a77eb8b2fcc92bd3bf8c0a36d2309e69677a62e436c42f85292bc56a33947cf011557f296e0
6
+ metadata.gz: 261fdb832ac3350e5f14354c3e1713b98ae529a7db33e61162f090b36a58a748b86cff640f8d3970f5a94f80fe5990e8e20799535c85dfe3212381ca7dda66ed
7
+ data.tar.gz: 5a36a3a2245b91af251ed9c8716f4caa94c1fda3513e1a0c7ae45cfdc5d9b45e1b08d3839df7af59c76f8dcd06eecac15ff03909236c8ed3668e8a85be9257ea
data/.gitignore CHANGED
@@ -1,34 +1,34 @@
1
- *.gem
2
- *.rbc
3
- /.config
4
- /coverage/
5
- /InstalledFiles
6
- /pkg/
7
- /spec/reports/
8
- /test/tmp/
9
- /test/version_tmp/
10
- /tmp/
11
-
12
- ## Specific to RubyMotion:
13
- .dat*
14
- .repl_history
15
- build/
16
-
17
- ## Documentation cache and generated files:
18
- /.yardoc/
19
- /_yardoc/
20
- /doc/
21
- /rdoc/
22
-
23
- ## Environment normalisation:
24
- /.bundle/
25
- /lib/bundler/man/
26
-
27
- # for a library or gem, you might want to ignore these files since the code is
28
- # intended to run in multiple environments; otherwise, check them in:
29
- # Gemfile.lock
30
- # .ruby-version
31
- # .ruby-gemset
32
-
33
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
- .rvmrc
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
- --color
2
- --require spec_helper
1
+ --color
2
+ --require spec_helper
@@ -4,6 +4,16 @@
4
4
 
5
5
  ### bug fixes
6
6
 
7
+ ## 1.3.0
8
+
9
+ ### enhancements
10
+ * Implement support for token fields. Use the `as: :token` on a Simple Form input field.
11
+
12
+ ### bug fixes
13
+ * Do not change selects to the Bootstrap select class unless they are explicitly select fields.
14
+ Other types of controls also give select fields -- typeaheads and the like.
15
+ * Fix compatibility layer for Bootstrap selects when the `bootstrap-select-rails` is not installed.
16
+
7
17
  ## 1.2.0
8
18
 
9
19
  ### enhancements
data/Gemfile CHANGED
@@ -1,3 +1,3 @@
1
- source 'https://rubygems.org'
2
-
3
- gemspec
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE CHANGED
@@ -1,22 +1,22 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 Joel Low
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Joel Low
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md CHANGED
@@ -14,6 +14,20 @@ Integrating Bootstrap-looking form controls with Simple Form.
14
14
  1. If you want to use Date/Time pickers, install the `bootstrap3-datetimepicker-rails` gem.
15
15
  2. If you want to use the nicely styled Bootstrap Select picker, install the
16
16
  `bootstrap-select-rails` gem.
17
+ 3. If you want to use the Token picker, you need to
18
+ a. Install the `bootstrap_tokenfield_rails` and `twitter-typeahead-rails` gems.
19
+ b. Require `twitter/typeahead` and `bootstrap-tokenfield` in that order in `application.js`.
20
+ c. Require `tokenfield-typeahead` and `bootstrap-tokenfield` in that order in
21
+ `application.css`.
22
+ d. These extra `@extend`s are needed for Typeahead.js 0.11:
23
+ ```scss
24
+ .tt-menu {
25
+ @extend .tt-dropdown-menu;
26
+ }
27
+ .tt-suggestion.tt-selectable:hover {
28
+ @extend .tt-suggestion.tt-cursor;
29
+ }
30
+ ```
17
31
 
18
32
  2. Add to your application's javascript: `//= require simple_form-bootstrap`
19
33
  3. Empty the Simple Form initializer:
data/Rakefile CHANGED
@@ -1,12 +1,12 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- require "rspec/core/rake_task"
8
-
9
- RSpec::Core::RakeTask.new
10
-
11
- task :default => :spec
12
- task :test => :spec
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require "rspec/core/rake_task"
8
+
9
+ RSpec::Core::RakeTask.new
10
+
11
+ task :default => :spec
12
+ task :test => :spec
@@ -1,24 +1,30 @@
1
- //= require simple_form-bootstrap/date_time_input
2
-
3
- (function($) {
4
- 'use strict';
5
- function initializeComponents(node) {
6
- // Enable our date/time pickers
7
- var datePickers = $('input.bootstrap-datepicker', node);
8
- datePickers.datetimepicker();
9
-
10
- // Enable our styled Bootstrap select controls, except Twitter Typeahead controls.
11
- var selects = $('select.form-control:not(.typeahead)', node);
12
- selects.selectpicker();
13
- }
14
-
15
- $(document).on('ready', function(e) {
16
- initializeComponents(document);
17
- });
18
- $(document).on('DOMNodeInserted', function(e) {
19
- initializeComponents(e.target);
20
- });
21
- $(document).on('nested:fieldAdded', function(e) {
22
- initializeComponents(e.field);
23
- });
24
- })(jQuery);
1
+ //= require simple_form-bootstrap/date_time_input
2
+ //= require simple_form-bootstrap/select_input
3
+ //= require simple_form-bootstrap/token_input
4
+
5
+ (function($) {
6
+ 'use strict';
7
+ function initializeComponents(node) {
8
+ // Enable our date/time pickers
9
+ var datePickers = $('input.bootstrap-datepicker', node);
10
+ datePickers.datetimepicker();
11
+
12
+ // Enable our styled Bootstrap select controls, only when using the default select collection.
13
+ var selects = $('select.select.form-control', node);
14
+ selects.selectpicker();
15
+
16
+ // Token fields for select inputs.
17
+ var tokenfields = $('.token select.token', node);
18
+ tokenfields.tokenfield();
19
+ }
20
+
21
+ $(document).on('ready', function(e) {
22
+ initializeComponents(document);
23
+ });
24
+ $(document).on('DOMNodeInserted', function(e) {
25
+ initializeComponents(e.target);
26
+ });
27
+ $(document).on('nested:fieldAdded', function(e) {
28
+ initializeComponents(e.field);
29
+ });
30
+ })(jQuery);
@@ -1,12 +1,12 @@
1
- // Hijacks the default Bootstrap date-time picker to always format dates in the specified format
2
- // through the use of a hidden field.
3
- (function($) {
4
- 'use strict';
5
- if ($.fn.selectpicker) {
6
- return;
7
- }
8
-
9
- $.fn.selectpicker = function(arg) {
10
- return methods.initialise.call(this, arg);
11
- };
12
- }(jQuery));
1
+ // Hijacks the default Bootstrap date-time picker to always format dates in the specified format
2
+ // through the use of a hidden field.
3
+ (function($) {
4
+ 'use strict';
5
+ if ($.fn.selectpicker) {
6
+ return;
7
+ }
8
+
9
+ $.fn.selectpicker = function() {
10
+ return this;
11
+ };
12
+ }(jQuery));
@@ -0,0 +1,170 @@
1
+ (function($) {
2
+ 'use strict';
3
+ /* global Bloodhound */
4
+
5
+ var oldTokenField = $.fn.tokenfield;
6
+ if (!oldTokenField) {
7
+ $.fn.tokenfield = function() {};
8
+ return;
9
+ }
10
+
11
+ /**
12
+ * Gets the selected options matching the given selector from the given select field.
13
+ *
14
+ * The return array of objects use 'value' for the displayed text. This is because Token field
15
+ * uses the value field when editing tokens, so we stick to its convention. The Select option
16
+ * is in optionValue.
17
+ *
18
+ * @param {Object} $select The select field to query.
19
+ * @param {String|null} selector The selector to filter the options by, if any.
20
+ * @returns {Array} The array of values which match the selector.
21
+ */
22
+ function getSelectOptions($select, selector) {
23
+ var $options = $select.find('option');
24
+ if (selector) {
25
+ $options = $options.filter(selector);
26
+ }
27
+
28
+ return $options.map(function() {
29
+ var text = this.text;
30
+ return {
31
+ optionValue: this.value || text,
32
+ value: text
33
+ };
34
+ }).get();
35
+ }
36
+
37
+ /**
38
+ * Finds the given value in the given select field.
39
+ *
40
+ * @param {Object} $select The select field.
41
+ * @param {String} value The value to search in the select.
42
+ */
43
+ function findOption($select, value) {
44
+ return $select.find('option[value="' + value + '"]');
45
+ }
46
+
47
+ /**
48
+ * Handles the pre-selection of a value.
49
+ *
50
+ * This blocks the addition if there is no option by that name.
51
+ *
52
+ * @param {Object} $select The select field.
53
+ * @param e The event triggering the selection.
54
+ * @returns {boolean} Return false to block the change.
55
+ */
56
+ function beforeSelectValue($select, e) {
57
+ var $option = findOption($select, e.attrs.optionValue);
58
+ if ($option.length === 0) {
59
+ return false;
60
+ }
61
+ }
62
+
63
+ /**
64
+ * Generates a before-selection event handler for the given select field.
65
+ * @param {HTMLSelectElement} select The select field to change.
66
+ * @returns {Function} The handler for the given select field.
67
+ */
68
+ function generateBeforeSelectValueHandler(select) {
69
+ return function(e) {
70
+ return beforeSelectValue($(select), e);
71
+ };
72
+ }
73
+
74
+ /**
75
+ * Handles the selection of a value.
76
+ *
77
+ * @param {Object} $select The select field.
78
+ * @param e The event triggering the selection.
79
+ * @returns {boolean} Return false to block the change.
80
+ */
81
+ function onSelectValue($select, e) {
82
+ var $option = findOption($select, e.attrs.optionValue);
83
+ $option.prop('selected', true);
84
+ }
85
+
86
+ /**
87
+ * Generates a on-selected event handler for the given select field.
88
+ * @param {HTMLSelectElement} select The select field to change.
89
+ * @returns {Function} The handler for the given select field.
90
+ */
91
+ function generateOnSelectValueHandler(select) {
92
+ return function(e) {
93
+ return onSelectValue($(select), e);
94
+ };
95
+ }
96
+
97
+ /**
98
+ * Handles the removal of a value.
99
+ *
100
+ * @param {Object} $select The select field.
101
+ * @param e The event triggering the selection.
102
+ * @returns {boolean} Return false to block the change.
103
+ */
104
+ function onRemoveValue($select, e) {
105
+ var $option = findOption($select, e.attrs.optionValue);
106
+ if ($option.length !== 0) {
107
+ $option.prop('selected', false);
108
+ }
109
+ }
110
+
111
+ /**
112
+ * Generates a value-removed event handler for the given select field.
113
+ * @param {HTMLSelectElement} select The select field to change.
114
+ * @returns {Function} The handler for the given select field.
115
+ */
116
+ function generateOnRemoveValueHandler(select) {
117
+ return function(e) {
118
+ return onRemoveValue($(select), e);
119
+ };
120
+ }
121
+
122
+ function initialiseTokenField() {
123
+ var select = this;
124
+
125
+ $(select).hide();
126
+ var $text = $('<input type="text" />').insertAfter(select);
127
+ var options = getSelectOptions($(select));
128
+
129
+ var bloodhound = new Bloodhound({
130
+ local: options,
131
+ datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
132
+ queryTokenizer: Bloodhound.tokenizers.whitespace
133
+ });
134
+ bloodhound.initialize();
135
+
136
+ var $result = oldTokenField.call($text, {
137
+ typeahead: [null, { displayKey: 'value', source: bloodhound.ttAdapter() }]
138
+ });
139
+
140
+ oldTokenField.call($result, 'setTokens', getSelectOptions($(select), ':selected'));
141
+
142
+ $result.on('tokenfield:createtoken', generateBeforeSelectValueHandler(select));
143
+ $result.on('tokenfield:createdtoken', generateOnSelectValueHandler(select));
144
+ $result.on('tokenfield:edittoken', generateBeforeSelectValueHandler(select));
145
+ $result.on('tokenfield:editedtoken', generateOnSelectValueHandler(select));
146
+ $result.on('tokenfield:removedtoken', generateOnRemoveValueHandler(select));
147
+
148
+ return $result;
149
+ }
150
+
151
+ $.fn.tokenfield = function() {
152
+ if (arguments.length === 0 || typeof arguments[0] === 'object') {
153
+ return this.addClass('tokenfield').removeClass('token').map(function() {
154
+ if ($(this).data('bs.tokenfield')) {
155
+ return this;
156
+ }
157
+
158
+ return initialiseTokenField.call(this);
159
+ });
160
+ } else {
161
+ return oldTokenField.apply(this, arguments);
162
+ }
163
+ };
164
+
165
+ for (var i in oldTokenField) {
166
+ if (oldTokenField.hasOwnProperty(i)) {
167
+ $.fn.tokenfield[i] = oldTokenField[i];
168
+ }
169
+ }
170
+ })(jQuery);