We've set up a separate document for our contribution guidelines.
We could have named it 'Yet Another Custom select jQuery plugin'
$('select').rsSelect();
$('select').rsSelect({optionKey:optionVal});
$.fn.rsSelect.defaults.selectedClass = 'active';
$.fn.rsSelect.defaults.autoClose = false;
$('select.header-select').rsSelect();
$('select.form-select').rsSelect();
Sets CSS class name which is added to wrap (or dropdown item) when it is disabled.
default: 'disabled'
Sets CSS class name for selected dropdown item
default: 'selected'
Sets CSS class name for open (expanded) dropdown
default: 'expanded'
Sets CSS class name for select with "multiple" attribute
default: 'multiple'
Speed of animations for slideDown/slideUp [ms]
default: 400
Easing for slideDown/slideUp animation
default: ''
Set whether to close the dropdown if user clicks outside of active element
default: true
Sets the name of CSS class which is added in situation where there is no space in current window to open the dropdown in down direction. If this property is set to false, nothing happens in this situation.
default: 'dropdown-up'
Object holding settings and values of dropdown element:
Type of dropdown html element
default: '<div>'
Object with html attributes which are added to dropdown wrap element
CSS class which is added to dropdown element
default: 'dropdown'
If this property is set to true, all classes from select element are copied to created dropdown. The only exception are options (selected, expanded, disabled),
default: true
This featured uses jQuery wrapInner method in order to add wrap elements around dropdown
default: ''
Object holding dropdown list elements
Type of dropdown html list element
default: '<div>'
Object with html attributes which are added to dropdown list element
CSS class which is added to dropdown list item element
default: 'dd-options'
This featured uses jQuery wrapInner method in order to add wrap elements around dropdown items
default: ''
Object holding dropdown header toggle settings
Type of header toggle html list element
default: '<div>'
Object with html attributes which are added to header toggle element
CSS class which is added to dropdown header toggle element
default: 'dd-btn'
Method which generates header toggle html structure together with dynamic text (selected item 1, selected item 2...)
default:
function (toggleText, toggle) {
if (!toggleText) {
toggleText = ' '
}
return '<span class="dd-current">' + toggleText + '</span><span class="dd-arrow"></span>'
}
separator for selected elements inside toggleText
default: ', '
object holding settings for list item element
Type of list item html element
default: '<div>'
Object with html attributes which are added to list item element
CSS class which is added to list item element
default: 'dd-item'
Method which generates header list item html structure together with dynamic text
default:
function (itemText, item) {
if (!itemText) {
itemText = ' '
}
return '<span class="dd-item-text">' + itemText + '</span>'
}
If this property is set to true, all classes from select option are copied to matching list item
default: true
function (dropdown, select) { }
function (dropdown, select, item) { }
function (dropdown, select, item, isChanged) { }
function (dropdown, select) { }
function (dropdown, select) { }
function (dropdown, select) { }
function (dropdown, select) { }
beforeChange, beforeOpen, beforeClose methods: if exiting with return false, they will abort current change, open or close
####Usage:
$('select').rsSelect({
beforeChange: function(dropdown, select, item){
var selectedOptions = select.find('option').filter('[selected]');
if(selectedOptions.length >= 3 && !item.hasClass('selected')){
alert('max 3 items can be selected');
return false; // break change
}
}
});
Plugin contains the following triggers for events:
Notice: afterInit must be set up before calling init method.
$('select').on('rsSelect.afterInit', function(evt, dropdown, select){
console.log('afterInit');
});
$('.custom-select').rsSelect();
####Usage:
$('select').filter(':last').on('rsSelect.afterChange', function(evt, dropdown, select, item, isChanged){
if(isChanged){
alert('Thank you!!!');
}
});
$('select').rsSelect('destroy');
Any DOM change needs reinitialization to generate new HTML.
$('select').rsSelect('reinit');
$.fn.rsSelect.defaults = {
disabledClass: 'is-disabled',
selectedClass: 'is-selected',
expandedClass: 'is-expanded',
multipleClass: 'is-multiple',
speed: 400,
easing: '',
autoClose: true,
upClass: 'direction-up',
wrap: {
element: '<div>',
attrs: {
class: 'rs-select'
},
copyClasses: true,
wrapInner: ''
},
toggle: {
element: '<div>',
attrs: {
class: 'rs-select-button'
},
content: function (toggleText) {
if (!toggleText) {
toggleText = ' '
}
return toggleText
},
separator: ', '
},
list: {
element: '<ul>',
attrs: {
class: 'rs-select-options'
},
wrapInner: ''
},
item: {
element: '<li>',
attrs: {
class: 'rs-select-option'
},
content: function (itemText) {
if (!itemText) {
itemText = ' '
}
return itemText
},
copyClasses: true
}
}