Permalink
Browse files

Finally done. Need to be tested !

  • Loading branch information...
1 parent 784655e commit 1ecb3d6bed4f134384edd7cd76e17013d9170106 @lou committed Jun 29, 2012
Showing with 15 additions and 9 deletions.
  1. +1 −0 .gitignore
  2. +14 −9 js/jquery.multi-select.js
View
@@ -0,0 +1 @@
+.DS_Store
View
@@ -1,5 +1,5 @@
/*
-* MultiSelect v0.5
+* MultiSelect v0.6
* Copyright (c) 2012 Louis Cuny
*
* Dual licensed under the MIT and GPL licenses:
@@ -34,7 +34,6 @@
ms.data('settings', multiSelects.settings);
-
var optgroupLabel = null,
optgroupId = null,
optgroupCpt = 0,
@@ -80,11 +79,15 @@
ms.multiSelect('select', $(this).val(), 'init');
});
- $('.ms-elem-selectable', container).on('hover', function(){
+ $('.ms-elem-selectable', container).on('mouseenter', function(){
$('li', container).removeClass('ms-hover');
$(this).addClass('ms-hover');
+ }).on('mouseout', function(){
+ $('li', container).removeClass('ms-hover');
});
+
+
selectableContainer.on('focusin', function(){
$(this).addClass('ms-focused');
selectedContainer.focusout();
@@ -111,11 +114,10 @@
});
ms.onKeyDown = function(e, keyContainer){
-
var selectables = $('.'+keyContainer+' li:visible', container),
selectablesLength = selectables.length,
selectableFocused = $('.'+keyContainer+' li.ms-hover', container),
- selectableFocusedIndex = selectableFocused.index('.'+keyContainer+' li:visible'),
+ selectableFocusedIndex = $('.'+keyContainer+' li:visible', container).index(selectableFocused),
liHeight = selectables.first().outerHeight(),
numberOfItemsDisplayed = Math.ceil(container.outerHeight()/liHeight),
scrollStart = Math.ceil(numberOfItemsDisplayed/4);
@@ -128,13 +130,14 @@
} else if (e.keyCode == 40){ // Down
var nextIndex = (selectableFocusedIndex+1 != selectablesLength) ? selectableFocusedIndex+1 : 0,
nextSelectableLi = selectables.eq(nextIndex);
+
nextSelectableLi.addClass('ms-hover');
if (nextIndex > scrollStart){
scroll += liHeight;
} else if (nextIndex == 0){
scroll = 0;
}
- $('.'+keyContainer+' ul').scrollTop(scroll);
+ $('.'+keyContainer+' ul', container).scrollTop(scroll);
} else if (e.keyCode == 38){ // Up
var prevIndex = (selectableFocusedIndex-1 >= 0) ? selectableFocusedIndex-1 : selectablesLength-1,
prevSelectableLi = selectables.eq(prevIndex);
@@ -232,10 +235,12 @@
} else {
selectedUl.append(selectedLi);
}
- selectedLi.on('hover', function(){
+ selectedLi.on('mouseenter', function(){
$('li', selectedUl).removeClass('ms-hover');
$(this).addClass('ms-hover');
- })
+ }).on('mouseout', function(){
+ $('li', selectedUl).removeClass('ms-hover');
+ });
if (ms.find("option[value='']")){
ms.find("option[value='']").removeAttr('selected');
}
@@ -317,4 +322,4 @@
}
return false;
};
-})(jQuery);
+})(jQuery);

0 comments on commit 1ecb3d6

Please sign in to comment.