Avoid cross browser form styling nightmares - Just drop it in and style the raw output.
- sporeInput
- sporeSelect
- sporeRating
Date: 05/08/2012
Last updated: 04/07/2013
Author: Sean Bullock
Url: BlueSpore.com
Twitter: @bluespore
Replaces native radio and checkbox inputs with anchor elements that can be completely styled as needed and avoid browser specific form styling clashes often present with creating custom form elements.
Replaces native select dropdowns with a fully stylable unordered list appended to the body to ensure it'll never ruin your beautiful layouts.
The script will populate the rating on window load given the element has a data-attribute of 'data-spore-rating' equal to a numeric value within the range of the number of child elements (as declared by 'pointElement'). In addition, you can choose to add 'data-spore-rating-id' to delegate the id of an input element who's value will change on update of the rating.
A callback method is also available for the update of the rating 'onRatingChange'. This is within the callback object when instantiating the plugin and returns the rating element that was affected.
$('input[type="radio"],input[type="checkbox"]').sporeInput({
checkedClass: 'checked',
tag: 'span',
checkboxCharacter: '✓',
radioCharacter: '•',
callback: {
onCheck: function(){}
}
});
$('select').sporeSelect({
//Class applied to list container when open
activeClass: 'active',
//Container of list options
listContainer: 'ul',
//Class for option list container
listClass: 'options-list',
//Tag for each option equivilent
optionElement: 'li',
//Class for highlighted list item
//when using keyboard mode
optionHighlightClass: 'highlighted',
//Element you click
triggerElement: 'span',
//Class on element you click
triggerElementClass: 'select',
//Fallback text for initial prompt label
//Can also be set as an <option value="label">label</option>
//which would be excluded from the generated
//sporeSelect element
promptText: '—Please Select—',
//Desired z-index level for the opened menu
zIndex: 9999,
//Allow navigation with arrow keys, quit with ESC
//and Enter key to make selection
keyboardMode: true,
//Define a function for successful selection
callback: {
onValueChange: function(){}
}
});
$('.selector').sporeRating({
activeClass: 'someClassName',
pointElement: 'li',
callback: {
onRatingChange: function(){
console.log(this);
}
}
});
Style to your hearts content. Why not throw some CSS3 animations on the active states of these badboys.
It'd be rad if you tweeted me!