Code Monkey home page Code Monkey logo

selectator's Introduction

Selectator

Selectator is a jQuery-based replacement for select boxes. It supports searching, and affects the original select box directly, which is used as the data container. You can see a demo here.

Usage

include in head:
<link rel="stylesheet" href="fm.selectator.jquery.css"/>
<script src="jquery-1.11.0.min.js"></script>
<script src="fm.selectator.jquery.js"></script>
to activate replacement:
$('#selectBox').selectator();

If you don't wan't to meddle with scripting, there is an alternative to activate replacement, by using inline markup.

<select multiple class="selectator" data-selectator-keep-open="true">
if you want to change settings:
$('#selectBox').selectator({
    prefix: 'selectator_',             // CSS class prefix
    height: 'auto',                    // auto or element
    useDimmer: false,                  // dims the screen when option list is visible
    useSearch: true,                   // if false, the search boxes are removed and 
                                       //   `showAllOptionsOnFocus` is forced to true
    keepOpen: false,                   // if true, then the dropdown will not close when 
                                       //   selecting options, but stay open until losing focus
    showAllOptionsOnFocus: false,      // shows all options if input box is empty
    selectFirstOptionOnSearch: true,   // selects the topmost option on every search
    searchCallback: function(value){}, // Callback function when enter is pressed and 
                                       //   no option is active in multi select box
    labels: {
        search: 'Search...'            // Placeholder text in search box in single select box
    }
});
Extra attributes for option tags

By using data-left, data-right and data-subtitle attributes you can extend the information shown in the options. These can be styled through css, and are named prefix_title, prefix_left, prefix_right and prefix_subtitle. The data in the attributes is pure html, so you can even put images here. The class attributes from the original option and optgroup elements are also added to the genererated elements

<select id="selectBox">
    <!-- Normal option tag -->
    <option value="1">This is the title</option>
    <!-- Extended option tag -->
    <option value="2" data-left="This is the left section" data-right="This is the right section" data-subtitle="This is the section under the title">This is the title</option>
</select>

It will be displayed something like this this:

Left Title Right
Subtitle

CSS classes

Here is a list of all the css classes

Class Description
prefix_element This is the new select box. It has some extra classes called single and multiple, which tell if it is a multiple selection or single selection select box. And also options-visible and options-hidden which tell if the options list is visible or not.
prefix_chosen_items The holder for the chosen items.
prefix_chosen_item The holder for the chosen item.
prefix_chosen_item_title The title of the chosen item.
prefix_chosen_item_left The left section of the chosen item.
prefix_chosen_item_right The right section of the chosen item.
prefix_chosen_item_subtitle The bottom section of the chosen item.
prefix_chosen_item_remove The remove button for the chosen item.
prefix_input This is the input box for the selectator. This is used together with options-visible or options-hidden to show and style it differently if it is a multiple selection box or a single selection box.
prefix_textlength This is used to calculate the size of the input box for the multiple selection box.
prefix_options The options list holder. This is used together with options-visible or options-hidden to show or hide the options.
prefix_group_header This is the group title option.
prefix_group This is the group options holder.
prefix_option This is a result option. It has an extra class called active which tells if the option is the active one.
prefix_option_title The title of the result option.
prefix_option_left The left section of the result option.
prefix_option_right The right section of the result option.
prefix_option_subtitle The bottom section of the result option.
prefix_dimmer This is the dimmer

DOM Structure

  • dimmer
  • element: containing the single|multiple class and the options-visible|options-hidden class
    • textlength
    • chosen_items
      • chosen_item
        • chosen_item_left
        • chosen_item_right
        • chosen_item_title
        • chosen_item_subtitle
        • chosen_item_remove
      • chosen_item...
    • input
    • options
      • group_header
      • group
        • option: containing the active class
          • option_left
          • option_right
          • option_title
          • option_subtitle
        • option...
      • option: containing the active class
        • option_left
        • option_right
        • option_title
        • option_subtitle
      • option...

jQuery methods

Method Description
refresh This method is used to refresh the plugin. A scenario where this would be useful is if the data in the original select box is changed by some other script.
destroy This method is used to remove the instance of the plugin from the select box and restore it to its original state.
Method usage
$('#selectBox').selectator('refresh');

or

$('#selectBox').selectator('destroy');

Browser compatibility

  • IE 8+
  • Chrome 2+
  • Firefox 3.5+
  • Safari 4+
  • Opera 11+

Internationalization

Selectator supports language by setting labels through the plugin options.

Copyright and license

The MIT License (MIT)

Copyright (c) 2013 Faroe Media

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.

selectator's People

Contributors

alex-lomov avatar andrepl avatar ingipingi avatar rewna avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.