/* * jQuery UI Multiselect * * Authors: * Michael Aufreiter (quasipartikel.at) * Yanick Rochon (yanick.rochon[at]gmail[dot]com) * * Dual licensed under the MIT (MIT-LICENSE.txt) * and GPL (GPL-LICENSE.txt) licenses. * * http://www.quasipartikel.at/multiselect/ * * * Depends: * ui.core.js * ui.sortable.js * * Optional: * localization (http://plugins.jquery.com/project/localisation) * scrollTo (http://plugins.jquery.com/project/ScrollTo) * * Todo: * Make batch actions faster * Implement dynamic insertion through remote calls */ (function($) { $.widget("ui.multiselect", { options: { sortable: true, dragToAdd: true, searchable: true, doubleClickable: true, animated: 'fast', show: 'slideDown', hide: 'slideUp', dividerLocation: 0.6, selectedContainerOnLeft: true, width: null, height: null, nodeComparator: function(node1,node2) { var text1 = node1.text(), text2 = node2.text(); return text1 == text2 ? 0 : (text1 < text2 ? -1 : 1); }, includeRemoveAll: true, includeAddAll: true, pressEnterKeyToAddAll: false }, _create: function() { this.element.hide(); this.id = this.element.attr("id"); this.container = $('
').insertAfter(this.element); this.count = 0; // number of currently selected options this.selectedContainer = $('
'); if (this.options.selectedContainerOnLeft) { this.selectedContainer.appendTo(this.container); this.availableContainer = $('
').appendTo(this.container); this.availableContainer.addClass('right-column'); } else { this.availableContainer = $('
').appendTo(this.container); this.selectedContainer.appendTo(this.container); this.selectedContainer.addClass('right-column'); } this.selectedActions = $('
0 '+$.ui.multiselect.locale.itemsCount+''+(this.options.includeRemoveAll?''+$.ui.multiselect.locale.removeAll+'':' ')+'
').appendTo(this.selectedContainer); this.availableActions = $('
'+(this.options.includeAddAll?''+$.ui.multiselect.locale.addAll+'':' ')+'
').appendTo(this.availableContainer); this.selectedList = $('').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer); this.availableList = $('').bind('selectstart', function(){return false;}).appendTo(this.availableContainer); var that = this; var width = this.options.width; if (!width) { width = this.element.width(); } var height = this.options.height; if (!height) { height = this.element.height(); } // set dimensions this.container.width(width-2); if (this.options.selectedContainerOnLeft) { this.selectedContainer.width(Math.floor(width*this.options.dividerLocation)-1); this.availableContainer.width(Math.floor(width*(1-this.options.dividerLocation))-2); } else { this.selectedContainer.width(Math.floor(width*this.options.dividerLocation)-2); this.availableContainer.width(Math.floor(width*(1-this.options.dividerLocation))-1); } // fix list height to match