ikSelect helps you stylize selects. Check the plugin's page for more info.
Features
- works in all popular browsers including IE6+
- custom syntax support
- works perfect as an inline-block
- no z-index bugs in IE
- optgroups support
- great API
- add/remove
<option>
s and <optgroup>
s - disable/enable anything (select, optgoup, option)
- optional filter text field
- can be used with hidden parents
- compatible with mobile devices
- behavior is as authentic as possible
- callbacks and event triggers
- automatic calculations
- dropdown position, so it's always visible when opened
- needed width for the select or it's dropdown (can be disabled)
- active option appears in the center of the opened dropdown
- keyboard support
- search by letters/numbers/etc
- navigation
- tab and shift+tab
- fast and easy to use
- built with attention to details
- according to the poll, 100% of people love it of all the five friends I asked
Installation
-
Include jQuery if it's still not included. The easiest way is to use some public CDN.
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
-
Download latest ikSelect script from here
-
Include ikSelect script after jQuery
<script src="ikSelect.min.js"></script>
-
Initialize the script somewhere. Better do it after the DOM is ready.
$(function () {
$('select').ikSelect();
});
-
Add some CSS
.ik_select {
}
.ik_select_link {
}
.ik_select_link_focus {
}
.ik_select_link_disabled {
}
.ik_select_link_text {
}
.ik_select_dropdown {
}
.ik_select_list {
}
.ik_select_optgroup {
}
.ik_select_optgroup_label {
}
.ik_select_option {
}
.ik_select_option_label {
}
.ik_select_hover {
}
.ik_select_active {
}
.ik_select_filter_wrap {
}
.ik_select_filter {
}
.ik_nothing_found {
}
Options
All the options can be set using HTML5 data- attributes or as an object passed to the plugin.
For the data- attibutes use lowercased options!
(data-autowidth="true", data-customclass="someclass", etc)
syntax: '<div class="ik_select_link"><span class="ik_select_link_text"></span></div><div class="ik_select_dropdown"><div class="ik_select_list"></div></div>'
autoWidth: true,
ddFullWidth: true,
equalWidths: true,
dynamicWidth: false,
extractLink: false,
customClass: '',
linkCustomClass: '',
ddCustomClass: '',
ddMaxHeight: 200,
isDisabled: false,
filter: false,
nothingFoundText: 'Nothing found'
Callbacks and events
After each callback there's also an event emitted.
Just replace on with ik and use lowercase.
(ikshow, ikkeydown, etc)
onInit: function (inst) {}
onShow: function (inst) {}
onHide: function (inst) {}
onKeyDown: function (inst) {}
onKeyUp: function (inst) {}
onHoverMove: function (inst) {}
API
$.ikSelect.extendDefaults(settings);
$(selector).ikSelect('reset');
$(selector).ikSelect('redraw');
$(selector).ikSelect('addOptions', optionObject[, optionIndex, optgroupIndex]);
$(selector).ikSelect('addOptions', optionObjectsArray[, optionIndex, optgroupIndex]);
$(selector).ikSelect('addOptgroups', optgroupObject[, optgroupIndex]);
$(selector).ikSelect('addOptgroups', optgroupObjectsArray[, optgroupIndex]);
$(selector).ikSelect('removeOptions', optionIndex[, optgroupIndex]);
$(selector).ikSelect('removeOptions', optionIndexesArray[, optgroupIndex]);
$(selector).ikSelect('removeOptgroups', optgroupIndex);
$(selector).ikSelect('removeOptgroups', optgroupIndexesArray);
$(selector).ikSelect('select', optionValue[, isIndex]);
$(selector).ikSelect('showDropdown');
$(selector).ikSelect('hideDropdown');
$(selector).ikSelect('disable');
$(selector).ikSelect('enable');
$(selector).ikSelect('toggle'[, enableOrDisable]);
$(selector).ikSelect('disableOptions', optionIndexOrValue[, isIndex]);
$(selector).ikSelect('disableOptions', optionIndexesOrValuesArray[, isIndex]);
$(selector).ikSelect('enableOptions', optionIndexOrValue[, isIndex]);
$(selector).ikSelect('enableOptions', optionIndexesOrValuesArray[, isIndex]);
$(selector).ikSelect('toggleOptions', optionIndexOrValue[, isIndex, enableOrDisable]);
$(selector).ikSelect('toggleOptions', optionIndexesOrValuesArray[, isIndex, enableOrDisable]);
$(selector).ikSelect('disableOptgroups', optgroupIndex);
$(selector).ikSelect('disableOptgroups', optgroupIndexesArray);
$(selector).ikSelect('enableOptgroups', optgroupIndex);
$(selector).ikSelect('enableOptgroups', optgroupIndexesArray);
$(selector).ikSelect('toggleOptgroups', optgroupIndex[, enableOrDisable]);
$(selector).ikSelect('toggleOptgroups', optgroupIndexesArray[, enableOrDisable]);
$(selector).ikSelect('detach');
Examples
Check the Examples page.
License
The MIT License (MIT)
Copyright (c) 2013 Igor Kozlov
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
author: http://igorkozlov.me