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

83 Commits

Author SHA1 Message Date
Kevin Brown
cee8c18c23 Change how the results are highlighted
Previously, a result was no longer highlighted when the mouse was
no longer over it. While this was useful for resetting the
highlight automatically, we started doing this when a new result
was highlighted to make sure that we never had multiple options
highlighted.

Now, a result will always be highlighted until the highlight is
removed when the next result is highlighted. While this shouldn't
affect many users, it is closer to how native select boxes work.
This also allows users using keyboard navigation to jump between
mouse and keyboard navigation without the highlight reseting to
the top of the results.
2014-11-19 14:29:28 -05:00
Kevin Brown
849a9c7a32 Started work on the classic theme
Some people like the old theme, so we're going to also include that
one as well as the easier-to-extend flat theme.
2014-11-19 14:26:52 -05:00
Kevin Brown
a2766b7ed6 Added destroy method
Now Select2 supports destroying itself, and all elements that it
creates.
2014-11-13 18:36:40 -05:00
Kevin Brown
10536370de Add support for initializing tags
This adds backwards compatibility for the old tags.
2014-11-07 20:31:27 -05:00
Kevin Brown
5535f072e1 Focus the search upon opening 2014-11-07 20:16:59 -05:00
Kevin Brown
07e82d6be8 Automatically create options on select 2014-11-07 20:13:59 -05:00
Kevin Brown
d411a0fa76 Fixed default selections for arrays 2014-11-07 19:53:50 -05:00
Kevin Brown
e3deb3ae03 Remove jQuery from building the options
This fixes many of the speed issues the results had when working
with large data sets. jQuery has been completely dropped, with the
exception of setting the data, which does not require a jQuery
object but instead works directly with the DOM. This does not
include options with children, which still uses jQuery to deal
with the nested objects.

This only works with IE 8+, which is fine.
2014-11-07 19:37:07 -05:00
Kevin Brown
8ecc35d504 Fix caching when querying
This fixes caching when querying, so the data object no longer
needs to be completely regenerated whenever the `<option>` is
queried.

While this does not fix the speed issues on the first opening of
the instance, it does fix the speed issues during searching.
2014-11-07 19:07:01 -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
56dbbf8cdb Improve option generate speed
Now the options are mostly generated by hand before being passed
off to jQuery for templating. This fixes much of the speed issues
we had when they were entirely being generated through jQuery.
2014-11-06 13:40:36 -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
c7e8f81595 Added Spanish translation and fixed the example 2014-11-05 11:25:41 -05:00
Kevin Brown
ed98443d47 Added matcher example and reworked compat
The matcher example now matches the old matcher example, and the
compatibility module has been turned into a function decorator
instead of a class decorator.
2014-11-05 11:03:53 -05:00
Kevin Brown
0bc4832995 Better infinite scroll
Only show the "No results found" message when there are no results
visible in the list. This avoid issues when loading more data, and
it returns no results.

Only try to see if the load more button is visible if it is present
in the DOM. This prevents making continuous requests when there are
no more results.
2014-11-03 19:24:29 -05:00
Kevin Brown
5e3b63289c Added infinite scrolling support for AJAX 2014-11-03 19:10:36 -05:00
Kevin Brown
91cecd55ed Handle minimumInputLength 2014-11-01 22:59:59 -04:00
Kevin Brown
8b7924fc72 Templating for selections 2014-11-01 22:12:21 -04:00
Kevin Brown
a3fa516761 Added basic templating to results 2014-11-01 21:57:14 -04:00
Kevin Brown
be4d091451 Working on remote data sets
This starts work on the example, which currently uses the GitHub
API.

The `ajax.delay` option has been added that allows for debouncing
requests made within a certain number of milliseconds.
2014-11-01 21:36:36 -04:00
Kevin Brown
6d2b462e2b Better key event handling 2014-11-01 21:04:31 -04:00
Kevin Brown
e16c505c25 Move to a central key handler
This allows for any control to emit key events, and for the Select2
instance to handle them. So now the search box will allow for
results to be scrolled and selected, bringing back the old expected
functionality. This also stops triggering new queries when the
arrow keys are pressed.

The container will also be automatically focused when the dropdown
is closed, which is consistent with the old Select2.

The results will no longer be queried on initialization, but
instead will be queried when the dropdown is opened. This is more
consistent with the previous version of Select2.

The search box will now be cleared when the dropdown is closed.
2014-11-01 20:35:23 -04:00
Kevin Brown
3b575ad92f Register the click handler in the container
This shouldn't be in the core, it's much easier to override things
in the container.
2014-11-01 19:36:02 -04:00
Kevin Brown
130358e8ae Set up the click handler for closing
Now the dropdown will automatically be closed when the user clicks
outside of it.
2014-11-01 19:29:07 -04:00
Kevin Brown
f8ca597f02 Move all of the event binding into separate methods
This should make it easier to override in subclasses.
2014-11-01 19:05:08 -04:00
Kevin Brown
47d0bc4fe1 Allow the position of the tag to be customized. 2014-11-01 18:40:06 -04:00
Kevin Brown
8bdd83c44f Better support for tagging
This removes the special case for `<select>` elements and instead
handles everything tagging related within the `Tags` decorator.
2014-11-01 17:49:53 -04:00
Kevin Brown
b87a4a55e4 Fix automatically hiding the placeholder
The placeholder will not only be automatically hidden if the
results adapter was not already overridden. This will allow users
to override the results adapter to now hide the placeholder, if
they do not want that functionality.
2014-11-01 17:27:30 -04:00
Kevin Brown
e57e0b1870 Added decorator to remove the placeholder object
This will remove the placeholder object from the results list.
2014-11-01 17:21:46 -04:00
Kevin Brown
09a0bb89b8 Move placing the sections into methods
This allows them to be overridden, allowing for things like
attaching the dropdown to a different part of the DOM.

The id is also now generated in a function that can be overridden.
2014-11-01 17:08:59 -04:00
Kevin Brown
959b96eca6 Started work on the "No results found" message 2014-11-01 14:20:51 -04:00
Kevin Brown
9bb993cee9 Added Translation object
This continues the work to get translations built into Select2.
2014-10-31 23:03:03 -04:00
Kevin Brown
20fcaa4449 Start working on translations
This adds a custom r.js build for i18n, which processes each JS
file in the `select2/i18n` directory and builds it.

So far only the "No results found" translation has been added.
2014-10-31 22:24:59 -04:00
Kevin Brown
65875bf8e7 Better handle AMD across files
Now that `define` and `require` are never made public, we have to
build everything to support `$.fn.select2.amd` while also working
with other AMD loaders.
2014-10-31 21:13:43 -04:00
Kevin Brown
afbf30d09a Wrap JS
This will prevent leaking variables, and will remove the possibility
of Select2 not working well with other plugins which support
AMD loaders. The `define` and `require` methods are now aliased
under `$.Select2.amd` for use inside additional files, such as
translations.
2014-10-31 20:15:17 -04:00
Kevin Brown
8e70642b87 Lint the Gruntfile 2014-10-31 19:12:27 -04:00
Kevin Brown
5dd7df33bb Allow programmatic access of Select2 2014-10-21 21:44:01 -04:00
Kevin Brown
5dd5ad93a6 Ensure that the highlighted result is visible
When opening the dropdown, the highlighted result will not always
be scrolled into view if it isn't already.
2014-10-21 21:44:01 -04:00
Kevin Brown
559a93bcb6 Added basic implementation of tags
Tags no longer takes an array, as pre-existing tags should already
exist as options in the data adapter.  A compatibility module will
later be added to convert tag data that is passed in to array data.

Tags allow for users to enter their own options, which will be
added to the beginning of the results list.
2014-10-21 21:44:01 -04: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
72ae0da879 Only generate result ids when the container has an id 2014-10-21 21:44:00 -04:00
Kevin Brown
cdfa0499f4 Accessibility matches better
Now the accessibility for the single select box better matches what
is picked up for a native select.

This fixes an issue with us always setting `aria-activedescendant`,
which caused Orca to always say the full path to the selected
result, instead of saying that the box was a combobox with a
selection. This means that the `aria-activedescendant` attribute
will now only be set when the dropdown is open.

This also switches the results list from a listbox to a tree, which
is what Firefox tells screen readers that a standard select is.
Combined with a change to use `role=group` and `aria-label` for
option group labels, screen readers will now announce the group
that they are in as well.
2014-10-21 21:44:00 -04:00
Kevin Brown
7c8601d33b Better accessibility for results
Options are correctly called out as focus moves around the results
list.
2014-10-21 21:44:00 -04:00
Kevin Brown
00a31df47a Generate more consistent ids
A global id is generated for the container, and each further id
builds off of the global id.
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
9102cf9473 Fixed keyboard scrolling
Now when scrolling through results with the keyboard, the
highlighted option will always be visible.
2014-10-21 21:44:00 -04:00
Kevin Brown
9ada3712f7 Single select accessibility
Now the Select2 instance is correctly recognized as a combobox, and
the selected option is read aloud when it is focused, just like in
a standard select box.

This works by generating semi-random ids that are used for the
ARIA attributes.  These are not intended to be consistent by any
means, they are just generated to make the instance accessible by
screen readers.
2014-10-21 21:44:00 -04:00
Kevin Brown
8dfd6d6960 Add more keyboard support
When the main container is focused, you can now move the highlighted
result by using the up and down arrows on the keyboard.

This does not yet keep the highlighted result visible at all times,
and it only is implemented on single selects, but that will come in
the future.
2014-10-21 21:44:00 -04:00
Kevin Brown
cc9419928e Working on accessibility
This makes quite a few changes, one of the major ones being the
removal of classes for marking options as selected or selectable,
and instead using the ARIA attributes which should already be
present.
2014-10-21 21:44:00 -04:00