2 $.fn.orderedSelectMultiple = function(options) {
6 $.extend(settings, options);
8 var input = $(this).hide();
9 var values = input.val().split(',');
11 var container = $('<div></div>').insertAfter($(this));
12 var choicesList = $('<ol class="choices connectedSortable"></ol>').appendTo(container).css({
13 width: 200, float: 'left', minHeight: 200, backgroundColor: '#eee', margin: 0, padding: 0
15 var valuesList = $('<ol class="values connectedSortable"></ol>').appendTo(container).css({
16 width: 200, float: 'left', minHeight: 200, backgroundColor: '#eee', margin: 0, padding: 0
19 $.each(settings.choices, function() {
20 choiceIds.push('' + this.id);
23 function createItem(hash) {
24 return $('<li>' + hash.name + '</li>').css({
25 backgroundColor: '#cff',
27 border: '1px solid #cdd',
30 }).data('obj-id', hash.id);
33 $.each(settings.choices, function() {
34 if ($.inArray('' + this.id, values) == -1) {
35 choicesList.append(createItem(this));
39 $.each(values, function() {
40 var index = $.inArray('' + this, choiceIds); // Why this[0]?
42 valuesList.append(createItem(settings.choices[index]));
46 choicesList.sortable({
47 connectWith: '.connectedSortable'
48 }).disableSelection();
51 connectWith: '.connectedSortable',
54 $('li', valuesList).each(function(index) {
55 values.push($(this).data('obj-id'));
56 console.log($(this).data('obj-id'));
58 console.log('update', values.join(','), input);
59 input.val(values.join(','));
61 }).disableSelection();