All Projects → tristanjahier → Chosen Order

tristanjahier / Chosen Order

Licence: other
Chosen Order is a plugin for Chosen which provides functions to handle the order of the selection

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Chosen Order

Validate
A simple jQuery plugin to validate forms.
Stars: ✭ 298 (+520.83%)
Mutual labels:  plugin, jquery
Hideseek
A simple, mobile-friendly, yet customizable quick/live search jQuery plugin.
Stars: ✭ 430 (+795.83%)
Mutual labels:  plugin, jquery
Jquery Match Height
a responsive equal heights plugin
Stars: ✭ 3,100 (+6358.33%)
Mutual labels:  plugin, jquery
Jqueryrotate
jQueryRotate - plugin to rotate images by any angle cross-browse with animation support
Stars: ✭ 157 (+227.08%)
Mutual labels:  plugin, jquery
Jquery Selectric
jQuery plugin for easy manipulation and customization of HTML selects
Stars: ✭ 724 (+1408.33%)
Mutual labels:  dropdown, jquery
Jquery.timeline
You can easily create the horizontal timeline with two types by using this jQuery plugin.
Stars: ✭ 179 (+272.92%)
Mutual labels:  plugin, jquery
Gijgo
Gijgo - Free Javascript Controls
Stars: ✭ 424 (+783.33%)
Mutual labels:  plugin, jquery
Mapit
An easy way to embed google maps in your site.
Stars: ✭ 54 (+12.5%)
Mutual labels:  plugin, jquery
Slinky
A light-weight, responsive, mobile-like navigation menu plugin
Stars: ✭ 649 (+1252.08%)
Mutual labels:  plugin, jquery
Jquery.localscroll
Animated anchor navigation made easy with jQuery
Stars: ✭ 624 (+1200%)
Mutual labels:  plugin, jquery
Convform
A jQuery plugin that transforms a form into an interactive chat.
Stars: ✭ 141 (+193.75%)
Mutual labels:  plugin, jquery
Jquery Dropdown
Bootstrap-style dropdowns with some added features and no dependencies.
Stars: ✭ 788 (+1541.67%)
Mutual labels:  dropdown, jquery
Footer Reveal
A jQuery plugin for easy implementation of the 'fixed/reveal' footer effect. Demo here:
Stars: ✭ 111 (+131.25%)
Mutual labels:  plugin, jquery
Sidr
Sidr is a jQuery plugin for creating side menus and the easiest way for doing your menu responsive.
Stars: ✭ 2,924 (+5991.67%)
Mutual labels:  plugin, jquery
Pg Calendar
📆 beautiful and eidetic date picker
Stars: ✭ 109 (+127.08%)
Mutual labels:  plugin, jquery
Zoomove
🔍 🎆 Enlarges the image with the mouse hover and move
Stars: ✭ 339 (+606.25%)
Mutual labels:  plugin, jquery
Dropdown
a lightweight dropdown of jQuery plugins
Stars: ✭ 105 (+118.75%)
Mutual labels:  dropdown, jquery
Involt
Inject hardware interactions directly into HTML layout.
Stars: ✭ 128 (+166.67%)
Mutual labels:  prototype, jquery
Paroller.js
Parallax scrolling jQuery plugin
Stars: ✭ 535 (+1014.58%)
Mutual labels:  plugin, jquery
Jquery.print
Easy to use, Element Printing Plugin for jQuery
Stars: ✭ 772 (+1508.33%)
Mutual labels:  plugin, jquery

Chosen order plugin

Chosen Order is a plugin for Chosen which aims to provide functions to handle the order of the selection.

Typically, you may want to retrieve the order in which the elements were selected with Chosen. You also may want to force the order in which Chosen displays the selected options. Unfortunately, Chosen does not handle that, because DOM Multiple Select elements do not have any notion of order of selection.

Created by Tristan Jahier.


THIS SOFTWARE IS NOT ASSOCIATED WITH HARVEST IN ANY WAY.

Chosen is a library originally created by Patrick Filler for Harvest.


Compatibility

  • jQuery : 1.4+
  • Prototype : 1.7.1+
  • Chosen : 1.0.0+

Internet Explorer 8

Chosen Order is now compatible with IE8, but you'll still need to add the es5-shim script to your page in order to make it work.

<!--[if lte IE 8]>
    <script type="text/javascript" src="workingdirectory/vendor/es5-shim.min.js"></script>
<![endif]-->

Demo

You can see a demonstration of the plugin at : http://labo.tristan-jahier.fr/chosen_order

Hey! Demo in the public/ directory does not work!!!

Use the grunt command to compile the project, and a task will fill this directory with the freshly built Javascript files.

If you have no idea what I'm talking about, just copy chosen.order.jquery.min.js and chosen.order.proto.min.js from dist/ to public/.

JsFiddle

For demonstration purpose, there is also 2 live demonstrations on JsFiddle:

Usage

Download the compiled Javascript files (development and minified versions are available) from the dist/ directory, or compile the project yourself.

Import the Javascript file in your HTML document. Choose the version which corresponds to the framework of your choice: jQuery or Prototype.

<script type="text/javascript" src="chosen.order.jquery.min.js"></script>

or

<script type="text/javascript" src="chosen.order.proto.min.js"></script>

Let's say you have a select element into your page, which is handled by Chosen:

<select id="my-list" multiple>
	<option value="fianle" selected>Fianle</option>
	<option value="plop" selected>Plop</option>
	<option value="zorp">Zorp</option>
	<option value="catakt">Catakt</option>
	<option value="cacatac">Cacatac</option>
	<option value="nioup" selected>Nioup</option>
	<option value="ratacat-mic">Ratacat-mic</option>
</select>

So, you have 3 values selected : Fianle, Plop and Nioup. Chosen UI displays them in the order they are declared into the DOM:

Chosen unordered elements

Chosen Order provides two public functions, in two flavors each.

  • Functional flavor is a direct call to ChosenOrder static functions.

     ChosenOrder.theFreakingFunction(element, params);
    
  • Object-oriented flavor is another approach that extends the objects.

     $(element).theFreakingFunction(params);
    

Retrieving the order

// Functional flavor
var selection = ChosenOrder.getSelectionOrder(document.getElementById('my-list'));

// Object-oriented flavor, example for jQuery plugin
var selection = $('#my-list').getSelectionOrder();

getSelectionOrder() takes no argument and returns an array of the selected values in the order they appear in Chosen UI. For the above example, it should return ["fianle", "plop", "nioup"].

Setting the order

var order = ['nioup', 'plop', 'fianle']; // Ordered options values

// Functional flavor
ChosenOrder.setSelectionOrder($('#my-list'), order);

// Object-oriented flavor, example for jQuery plugin
$('#my-list').setSelectionOrder(order);

setSelectionOrder() takes an array of ordered values.

It also takes an optional argument : force, which is a boolean. Default value is false. Set it to true if you plan to pass an array of ordered values that are not necessarily all selected yet.

For example, let's introduce Cacatac and Ratacat-mic and get rid of Zorp:

var order = ['cacatac', 'plop', 'ratacat-mic', 'fianle'];
$('#my-list').setSelectionOrder(order, true);

It forces the selection of the values for the Select element and Chosen UI before ordering them.

Chosen ordered elements

Technical aspects

Chosen Order does several precaution checks on the arguments. It checks if the element is a correct multiple select element, with a matching Chosen UI. If this is not the case, it outputs an error in the console:

ChosenOrder::getSelectionOrder: first argument must be a valid HTML Multiple Select element that has been Chosenified!

It also checks if the order array is a true Array object, else, it screams:

ChosenOrder::setSelectionOrder: second argument must be an Array!

Chosen Order handles both DOM raw elements and jQuery objects. For example, these 2 lines will work:

ChosenOrder.getSelectionOrder(document.getElementById('my-list'));
ChosenOrder.getSelectionOrder($('#my-list'));

setSelectionOrder() trims the values of the order array.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].