summaryrefslogtreecommitdiffstats
path: root/js/jquery.multi-select.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/jquery.multi-select.js')
-rw-r--r--js/jquery.multi-select.js35
1 files changed, 19 insertions, 16 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js
index fbeec76..c9ed0a7 100644
--- a/js/jquery.multi-select.js
+++ b/js/jquery.multi-select.js
@@ -1,5 +1,5 @@
(function($){
-
+
var msMethods = {
'init' : function(options){
this.settings = {
@@ -7,12 +7,12 @@
if(options) {
this.settings = $.extend(this.settings, options);
}
-
+
var multiSelects = this;
multiSelects.hide();
-
+
multiSelects.each(function(){
-
+
var ms = $(this);
ms.attr('id', ms.attr('id') != undefined ? ms.attr('id') : 'select'+((new Date()).getTime()));
var container = $('<div id="ms-'+ms.attr('id')+'" class="ms-container"></div>').detach(),
@@ -20,11 +20,12 @@
selectedContainer = $('<div class="ms-selection"></div>').detach(),
selectableUl = $('<ul></ul>').detach(),
selectedUl = $('<ul></ul>').detach();
-
+
ms.data('settings', multiSelects.settings);
ms.children('option').each(function(){
- var selectableLi = $('<li ms-value="'+$(this).val()+'">'+$(this).text()+'</li>').detach();
-
+
+ var selectableLi = $('<li ms-value="'+$(this).val()+'" title="' + $(this).attr('title') + '">'+$(this).text()+'</li>').detach();
+
selectableLi.click(function(){
ms.multiSelect('select', $(this).attr('ms-value'));
});
@@ -51,14 +52,15 @@
msValues = (ms.val() ? ms.val() : []),
alreadyPresent = $.inArray(value, msValues),
text = ms.find('option[value="'+value+'"]').text();
-
+ title_attr = ms.find('option[value="'+value+'"]').attr('title');
+
if(alreadyPresent == -1 || method == 'init'){
- var selectedLi = $('<li ms-value="'+value+'">'+text+'</li>').detach(),
+ var selectedLi = $('<li ms-value="'+value+'" title="' + title_attr + '">'+text+'</li>').detach(),
newValues = $.merge(msValues, [value]),
selectableUl = $('#ms-'+ms.attr('id')+' .ms-selectable ul'),
selectedUl = $('#ms-'+ms.attr('id')+' .ms-selection ul'),
selectableLi = selectableUl.children('li[ms-value="'+value+'"]');
-
+
selectableLi.hide();
ms.val(newValues);
selectedLi.click(function(){
@@ -74,14 +76,14 @@
var ms = this,
msValues = (ms.val() ? ms.val() : []),
present = false,
- newValues = $.map(msValues, function(e){ if(e != value){ return e; }else{ present = true}});
-
+ newValues = $.map(msValues, function(e){ if(e != value){ return e; }else{ present = true} return false;});
+
if(present){
var selectableUl = $('#ms-'+ms.attr('id')+' .ms-selectable ul'),
selectedUl = $('#ms-'+ms.attr('id')+' .ms-selection ul'),
selectableLi = selectableUl.children('li[ms-value="'+value+'"]'),
selectedLi = selectedUl.children('li[ms-value="'+value+'"]').detach();
-
+
ms.val(newValues);
selectableLi.show();
selectedLi.remove();
@@ -102,8 +104,8 @@
ms.multiSelect('deselect', $(this).val(), 'deselect_all');
});
}
- }
-
+ };
+
$.fn.multiSelect = function(method){
if ( msMethods[method] ) {
return msMethods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
@@ -112,5 +114,6 @@
} else {
if(console.log) console.log( 'Method ' + method + ' does not exist on jquery.multiSelect' );
}
- }
+ return false;
+ };
})(jQuery); \ No newline at end of file