diff options
author | Louis Cuny <louiscuny@gmail.com> | 2012-06-29 15:20:03 +0200 |
---|---|---|
committer | Louis Cuny <louiscuny@gmail.com> | 2012-06-29 15:20:03 +0200 |
commit | 1ecb3d6bed4f134384edd7cd76e17013d9170106 (patch) | |
tree | 98d98e1e3a106a398109d025991dabc56f28f0f3 /js | |
parent | 784655e360c52fbc527fe5f3464de3360d77a776 (diff) | |
download | multi-select-origin/keyboard.zip multi-select-origin/keyboard.tar.gz multi-select-origin/keyboard.tar.bz2 |
Finally done. Need to be tested !origin/keyboard
Diffstat (limited to 'js')
-rw-r--r-- | js/jquery.multi-select.js | 23 |
1 files changed, 14 insertions, 9 deletions
diff --git a/js/jquery.multi-select.js b/js/jquery.multi-select.js index e9ead2a..f4eaff7 100644 --- a/js/jquery.multi-select.js +++ b/js/jquery.multi-select.js @@ -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);
\ No newline at end of file |