1
0
mirror of synced 2024-11-22 21:16:10 +03:00
Commit Graph

36 Commits

Author SHA1 Message Date
Kevin Brown
686f846fa5 Changed how the builds are done
This adds a check that triggers an error if Select2 was not able
to detect a copy of jQuery on the page. This should help users when
they are setting up Select2.

**Breaking change:** The full build no longer includes jQuery.
Previously, the full build included all requirements for Select2,
including jQuery, which meant that anyone looking for the optional
requirements had to possibly include multiple versions of jQuery
on their page. This means that anyone requiring Select2 to also
bundle jQuery will now need to include jQuery on their pages
alongside Select2. A copy of jQuery is included in the repository.

**Breaking change:** The AMD build of Select2 will now correctly
wrap the code in a `define` block. It will still create the named
blocks inside of the code, which should be valid in most AMD build
systems, so now Select2 is compatible with cases where the file
does not have the same name as the Select2 module name.

**Breaking change:** Select2 will re-use the AMD methods if they
are available on the page, but it will not longer leak the included
AMD loader to the global scope. The AMD methods will still be
available on the `jQuery.fn.select2.amd` namespace.

The `mock.js` test file has been renamed to `helpers.js` and will
handle the escalation of the `require` and `define` variables to
the global scope. It should be included in all test files, or the
tests will fail.

This closes https://github.com/select2/select2/issues/2946.
2015-01-22 14:49:39 -05:00
Kevin Brown
d81886e5de Trigger the unselect event when clearing placeholder
In the past, Select2 triggered the `select2-clearing` event when
clearing the placeholder. This has been switched to the `unselect`
event which is now triggered whenever the placeholder is cleared.
The placeholder can also be prevented if the `unselecting` event
is prevented.

This will also trigger the event when deleting every option from
the multiple select, so it is possible for the `unselecting` event
to be triggered multiple times when clearing a multiple select.

This adds tests to ensure that the `allowClear` option always works.

This closes https://github.com/select2/select2/issues/2954.
2015-01-21 19:11:07 -05:00
Kevin Brown
d6a83ea026 Pull query and initSelection out to compat modules
This also adds more documentation and corrects the release notes
for these breaking changes. These modules will now only be included
in the full builds of Select2, which has been noted in a few places.
2015-01-17 20:47:52 -05:00
Kevin Brown
b43656c13c Added basic accessibility tests
This adds basic tests to ensure that the selection is accessible by
all users. This checks for common attributes, ensuring that the
container is always keyboard accessible and follows ARIA guidelines.

This also changes the base selection to create a common element so
we don't need to repeat attributes and such across multiple selection
containers.
2015-01-14 22:54:19 -05:00
Kevin Brown
2a7ae0ea9c Add backwards compatibility with query option
This adds backwards compatibility with the `query` option so it
automatically patches the `DataAdapter.query` function. The only
major difference between the methods is the call signature, which
has now moved the callback out of the parameters and into the second
argument.

This also adds tests that verify that the old query functions should
work as expected.
2015-01-14 21:24:09 -05:00
Kevin Brown
e04188c85a Added backwards compatibility for initSelection
Now if the old `initSelection` method is used, a warning will be
triggered in the console informing the user that it has now been
changed to `DataAdapter.current`, and they should create a custom
data adapter instead. We will still only call `initSelection` once,
and then default back to the old data adapter for calls after that.
This allows for mostly transparent support between versions.

This adds tests to ensure that `initSelection` operates the same as
it previously did, but now patches the `current` method of the
default data adapter.
2015-01-14 21:24:08 -05:00
Zubair
7515fa7f46 only verify when maximumSelectionCount is greater than 0 and add tests 2015-01-13 13:00:16 -05:00
Kevin Brown
584d3b48a2 Added selectOnClose
`selectOnClose` is a new option which works very much like the old
`selectOnBlur` option. When the `close` event is triggered, the
highlighted result is automatically selected. This is useful for
single selects, which is where it is designed to be used, but it
can also be used on multiple selects.

This also adds tests to verify that this works in the future.

During the creation of the test, we noticed that we were missing a
mock container that could be used for triggering events. One was
created and a general mock JS file was created to hold any future
mocks for tests.
2015-01-11 21:47:17 -05:00
Kevin Brown
af1f35176b Added back the width option
In past versions of Select2, the `width` option could be used to
tell Select2 how to determine the width of the container generated
by Select2.

**Breaking change:** The default value for the `width` option has
been changed from `copy` to `resolve.`

**Breaking change:** The old option called `copy` has been renamed
to `style` to better reflect what the width is generated from.

This fixes https://github.com/select2/select2/pull/2090.
This fixes https://github.com/select2/select2/issues/2911.
2015-01-11 18:00:48 -05:00
Kevin Brown
ff596e692e Added a few more tests
This adds a test that makes sure that the inline data attribute
overrides the options that are passed in during initialization.

This also adds a test for the `createTag` option, which is used
when tagging.
2015-01-11 16:30:16 -05:00
Kevin Brown
7f17291932 Fix support for deep nesting
While deep nesting will not work on a standard `<select>`, we can
emulate it through data objects still, and just handle the display
of the data in the results.

This also means that the horrific deep-nested CSS is back to handle
the padding. I hope that will get fixed over time.

This also fixes one of the performance issues with adding array
data, as options are added at the very end instead of one by one.
2015-01-09 20:50:06 -05:00
Kevin Brown
024d41b412 Normalize internal select/unselect events
Also pull the logic for automatically closing the dropdown into the
dropdown adapter, taking it out of the core.

The `selected` and `unselected` events are now `select` and
`unselect`, which is what many of the other adapters were expecting
them to be.

Some tests for placeholders have been added.
2015-01-09 10:05:44 -05:00
Kevin Brown
05cbaf7bf7 Universally use the object query return
There was a plan to universally use an array as the return from
query methods, but now that we've realized pagination and extra
things are impossible without it, we're going back to the return
object. Anyone looking to migrate their data should be returning
an object with the key `results` containing what they previously
returned.

This should fix https://github.com/select2/select2/issues/2898
2015-01-07 21:11:32 -05:00
Kevin Brown
0bc73941fe Support duplicate options
Now that the data objects have the `element` property, we can test
to make sure it's a DOM element and then use it for selecting the
option. This allows us to select multiple options with the same id,
as well as handle cases where that is already happening.

You cannot use `$e.val()` to select two options with the same id,
as jQuery will reject it, but you can set the second option to
`.selected = true`, which is supported.
2014-12-17 20:36:06 -05:00
Kevin Brown
14db3fc801 Support data-* attributes for configuration
The documentation is included, along with a few tests, which
explains the general rules for how it is parsed.
2014-12-10 15:23:39 -05:00
Kevin Brown
e3647051de Added maximumInputLength support 2014-11-26 21:52:49 -05:00
Kevin Brown
43efd43d57 Add tests for the multiple selection container 2014-11-26 20:50:39 -05:00
Kevin Brown
4cab421966 Added tests for the single selection container 2014-11-26 20:25:56 -05:00
Kevin Brown
56d5778590 Finished off tests for tags
This also adds back the ability for tags to return `null` in order
for no tag to be added to the results.
2014-11-26 19:53:15 -05:00
Kevin Brown
76e4ea8340 Added tests for tags 2014-11-25 21:28:16 -05:00
Kevin Brown
16e565e28e Added tests for minimumInputLength 2014-11-25 20:12:17 -05:00
Kevin Brown
217cd4cfd0 Added inline searching for multiple selects
This adds a search box to the main container for multiple select
boxes, similar to the what the old version had. This can still be
swapped out such that the search box displays above the results
like it previously did.

The placeholder for multiple selects will also now use the input
attribute of the search box instead of generating a custom element.

This also changes the selector for the search container to
`.select2-search`, which is consistent with the old class and
reduces the complexity of the selectors.

This fixes an issue with how decorators worked, where the constructor
from the parent class would clobber the custom constructor that is
generated for the new decorated class. This has been fixed by
excluding the constructor from the list of fields which are
transferred when decorating classes.
2014-11-22 19:21:46 -05:00
Kevin Brown
05ddbec1a7 Improve data array speeds
This improves the speeds of creating the `<option>` tags for array
data. By creating the HTML ahead of time and putting it into an
`<option>` element before passing it to jQuery, it cuts down on the
time it takes for jQuery to process the HTML string and convert it
into DOM elements. This proved to be incredibly slow.

This also changes the `item` function to return early when the
data exists. The `$e.data` call has also been switched to a
`$.data` call, which doesn't need to check the DOM to see if the
data attributes already exist. This cuts down on a bit of wasted
time, as the `data` key should never be present in the DOM, and it
should be ignored if it is.
2014-11-07 11:17:37 -05:00
Kevin Brown
8158e151ff Added test to make sure the options are generated 2014-11-06 12:12:43 -05:00
Kevin Brown
8ea23610f1 Convert array data to options immediately
This converts individual objects passed in through the `array`
parameter to `<option>` tags when Select2 is initialized. This
removes a lot of duplicate code from the `ArrayAdapter`, and keeps
everything closer to the native `<select>` element.

This introduces a breaking change from previous versions of Select2,
where the initial value for array data was blank, even if a blank
option was not present in the original array of objects. Now the
first object passed in will be selected by default, following the
behavior of a standard `<select>` element.

This breaking change does not affect `<select multiple="multiple">`
elements, which by default have no selection.
2014-11-06 12:05:12 -05:00
Kevin Brown
9e130956fc Better compatibility with array data
When using array data, and an option is selected, the data that is
attached to the DOM element will be run through `item` and should
have any private, automatically generated attributes added and
merged with it.
2014-10-21 21:44:00 -04:00
Kevin Brown
e018a6f69e Changed tests to not use deepEqual
We should only be checking the option values that matter, such as
`id` and `text`, instead of checking all of the option values. This
will prevent unexpected breaking when new properties are added to
the options.

Existing properties should be covered by tests to avoid regressions.
2014-10-21 21:44:00 -04:00
Kevin Brown
d0fe07f954 Added tests for the query function 2014-10-21 21:43:59 -04:00
Kevin Brown
27ac50a854 Fixed problems with non-string ids
We have to enforce ids being strings as the values of options within
a select will always be an id.  This fixes an issue that we had with
array selections not being highlighted in the results.
2014-10-21 21:43:59 -04:00
Kevin Brown
cbfe23eb52 Added basic tests for select2/data/array 2014-10-21 21:43:58 -04:00
Kevin Brown
5f176b66f2 Add tests for select data adapter 2014-10-21 21:43:58 -04:00
Kevin Brown
0bc56a922b Linted tests 2014-10-21 21:43:57 -04:00
Kevin Brown
114732ec25 Broke out a base data adapter
This should allow us to create a basic interface that all adapters
must follow.
2014-10-21 21:43:57 -04:00
Kevin Brown
08ac13d510 Two spaces indentation for tests 2014-10-21 21:43:57 -04:00
Kevin Brown
94b460f930 Limit the explicit coupling between adapters 2014-10-21 21:43:57 -04:00
Kevin Brown
792133ce5c Added Utils.Decorate and tests
This adds decorator support in a very basic way, but enough that
it doesn't take a lot of effort to get it implemented.

This also starts work on splitting things out for theming.
2014-10-21 21:43:56 -04:00