|
|
@ -360,6 +360,13 @@ $.fn.dropdown = function(parameters) { |
|
|
|
}, |
|
|
|
mouseEvents: function() { |
|
|
|
module.verbose('Mouse detected binding mouse events'); |
|
|
|
if(module.is.multiple()) { |
|
|
|
$module |
|
|
|
.on('click' + eventNamespace, module.event.click) |
|
|
|
.on('click' + eventNamespace, selector.label, module.event.label.click) |
|
|
|
.on('click' + eventNamespace, selector.remove, module.event.remove.click) |
|
|
|
; |
|
|
|
} |
|
|
|
if( module.is.searchSelection() ) { |
|
|
|
$module |
|
|
|
.on('mousedown' + eventNamespace, selector.menu, module.event.menu.mousedown) |
|
|
@ -372,8 +379,6 @@ $.fn.dropdown = function(parameters) { |
|
|
|
if(module.is.multiple()) { |
|
|
|
$module |
|
|
|
.on('click' + eventNamespace, module.event.click) |
|
|
|
.on('click' + eventNamespace, selector.label, module.event.label.click) |
|
|
|
.on('click' + eventNamespace, selector.remove, module.event.remove.click) |
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
@ -496,9 +501,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
|
|
|
|
focusSearch: function() { |
|
|
|
if( module.is.search() && !module.is.focusedOnSearch() ) { |
|
|
|
$search |
|
|
|
.focus() |
|
|
|
; |
|
|
|
$search[0].focus(); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
@ -541,6 +544,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
pageLostFocus = (document.activeElement === this) |
|
|
|
; |
|
|
|
if(!activated && !pageLostFocus) { |
|
|
|
module.remove.activeLabel(); |
|
|
|
module.hide(); |
|
|
|
} |
|
|
|
}, |
|
|
@ -610,7 +614,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
$activeLabels.removeClass(className.active); |
|
|
|
$label.addClass(className.active); |
|
|
|
} |
|
|
|
settings.onLabelClick.apply(this, $labels.filter('.' + className.active)); |
|
|
|
settings.onLabelSelect.apply(this, $labels.filter('.' + className.active)); |
|
|
|
} |
|
|
|
}, |
|
|
|
remove: { |
|
|
@ -630,12 +634,12 @@ $.fn.dropdown = function(parameters) { |
|
|
|
}, |
|
|
|
test: { |
|
|
|
toggle: function(event) { |
|
|
|
if( module.determine.eventInMenu(event, module.toggle) ) { |
|
|
|
if( module.determine.eventOnElement(event, module.toggle) ) { |
|
|
|
event.preventDefault(); |
|
|
|
} |
|
|
|
}, |
|
|
|
touch: function(event) { |
|
|
|
module.determine.eventInMenu(event, function() { |
|
|
|
module.determine.eventOnElement(event, function() { |
|
|
|
if(event.type == 'touchstart') { |
|
|
|
module.timer = setTimeout(module.hide, settings.delay.touch); |
|
|
|
} |
|
|
@ -696,15 +700,12 @@ $.fn.dropdown = function(parameters) { |
|
|
|
$subMenu = $choice.find(selector.menu), |
|
|
|
text = module.get.choiceText($choice), |
|
|
|
value = module.get.choiceValue($choice, text), |
|
|
|
callback = function() { |
|
|
|
module.remove.searchTerm(); |
|
|
|
module.determine.selectAction(text, value); |
|
|
|
}, |
|
|
|
hasSubMenu = ($subMenu.length > 0), |
|
|
|
isBubbledEvent = ($subMenu.find($target).length > 0) |
|
|
|
; |
|
|
|
if(!isBubbledEvent && (!hasSubMenu || settings.allowCategorySelection)) { |
|
|
|
callback(); |
|
|
|
module.remove.searchTerm(); |
|
|
|
module.determine.selectAction.call(this, text, value); |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
@ -728,6 +729,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
isFirstLabel = (labelIndex == 0), |
|
|
|
isLastLabel = (labelIndex + 1 == labelCount), |
|
|
|
isFocusedOnSearch = module.is.focusedOnSearch(), |
|
|
|
isFocused = module.is.focused(), |
|
|
|
caretAtStart = (isFocusedOnSearch && module.get.caretPosition() == 0) |
|
|
|
; |
|
|
|
if(isFocusedOnSearch && (pressedKey == keys.delimiter)) { |
|
|
@ -739,7 +741,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
else if(pressedKey == keys.leftArrow) { |
|
|
|
// activate previous label
|
|
|
|
if(caretAtStart && !hasActiveLabel) { |
|
|
|
if((isFocused || caretAtStart) && !hasActiveLabel) { |
|
|
|
$label.last().addClass(className.active); |
|
|
|
} |
|
|
|
else if(hasActiveLabel && !isFirstLabel) { |
|
|
@ -754,6 +756,10 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
} |
|
|
|
else if(pressedKey == keys.rightArrow) { |
|
|
|
// activate first label
|
|
|
|
if(isFocused && !hasActiveLabel) { |
|
|
|
$label.last().addClass(className.active); |
|
|
|
} |
|
|
|
// activate next label
|
|
|
|
if(hasActiveLabel) { |
|
|
|
if(!event.shiftKey) { |
|
|
@ -822,6 +828,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
else { |
|
|
|
module.verbose('Enter key pressed, choosing selected item'); |
|
|
|
module.event.item.click.call($selectedItem, event); |
|
|
|
event.stopImmediatePropagation(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -903,7 +910,6 @@ $.fn.dropdown = function(parameters) { |
|
|
|
; |
|
|
|
module.set.scrollPosition($nextItem); |
|
|
|
} |
|
|
|
|
|
|
|
event.preventDefault(); |
|
|
|
} |
|
|
|
|
|
|
@ -925,11 +931,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.show(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
}, |
|
|
|
resetStyle: function() { |
|
|
|
$(this).removeAttr('style'); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
@ -938,11 +940,11 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.verbose('Determining action', settings.action); |
|
|
|
if( $.isFunction( module.action[settings.action] ) ) { |
|
|
|
module.verbose('Triggering preset action', settings.action, text, value); |
|
|
|
module.action[ settings.action ](text, value); |
|
|
|
module.action[ settings.action ].call(this, text, value); |
|
|
|
} |
|
|
|
else if( $.isFunction(settings.action) ) { |
|
|
|
module.verbose('Triggering user action', settings.action, text, value); |
|
|
|
settings.action(text, value); |
|
|
|
settings.action.call(this, text, value); |
|
|
|
} |
|
|
|
else { |
|
|
|
module.error(error.action, settings.action); |
|
|
@ -963,12 +965,15 @@ $.fn.dropdown = function(parameters) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
}, |
|
|
|
eventInMenu: function(event, callback) { |
|
|
|
eventOnElement: function(event, callback) { |
|
|
|
var |
|
|
|
$target = $(event.target) |
|
|
|
; |
|
|
|
callback = $.isFunction(callback) |
|
|
|
? callback |
|
|
|
: function(){} |
|
|
|
; |
|
|
|
if( $(event.target).closest($menu).length === 0 ) { |
|
|
|
if($target.is($module) || $target.is($icon) || $target.is($text)) { |
|
|
|
module.verbose('Triggering event', callback); |
|
|
|
callback(); |
|
|
|
return true; |
|
|
@ -989,7 +994,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
? value |
|
|
|
: text |
|
|
|
; |
|
|
|
module.set.selected(value); |
|
|
|
module.set.selected(value, $(this)); |
|
|
|
module.hide(function() { |
|
|
|
module.remove.filteredItem(); |
|
|
|
}); |
|
|
@ -1000,7 +1005,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
? value |
|
|
|
: text |
|
|
|
; |
|
|
|
module.set.selected(value); |
|
|
|
module.set.selected(value, $(this)); |
|
|
|
module.hide(function() { |
|
|
|
module.remove.filteredItem(); |
|
|
|
}); |
|
|
@ -1011,7 +1016,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
? value |
|
|
|
: text |
|
|
|
; |
|
|
|
module.set.selected(value); |
|
|
|
module.set.selected(value, $(this)); |
|
|
|
module.hide(function() { |
|
|
|
module.remove.filteredItem(); |
|
|
|
}); |
|
|
@ -1294,22 +1299,25 @@ $.fn.dropdown = function(parameters) { |
|
|
|
set: { |
|
|
|
filtered: function() { |
|
|
|
var |
|
|
|
isMultiple = module.is.multiple(), |
|
|
|
searchValue = $search.val(), |
|
|
|
hasSearchValue = (typeof searchValue === 'string' && searchValue.length > 0), |
|
|
|
searchWidth = (searchValue.length * settings.glyphWidth) + 'em', |
|
|
|
valueIsSet = $input.val() != '' |
|
|
|
isMultiple = module.is.multiple(), |
|
|
|
isSearch = module.is.searchSelection(), |
|
|
|
isSearchMultiple = (isMultiple && isSearch), |
|
|
|
searchValue = (isSearch) |
|
|
|
? $search.val() |
|
|
|
: '', |
|
|
|
hasSearchValue = (typeof searchValue === 'string' && searchValue.length > 0), |
|
|
|
searchWidth = (searchValue.length * settings.glyphWidth) + 'em', |
|
|
|
valueIsSet = $input.val() != '' |
|
|
|
; |
|
|
|
if(isMultiple && hasSearchValue) { |
|
|
|
module.verbose('Adjusting input width', searchWidth, settings.glyphWidth) |
|
|
|
$search.css('width', searchWidth); |
|
|
|
} |
|
|
|
|
|
|
|
if(hasSearchValue || (isMultiple && valueIsSet)) { |
|
|
|
if(hasSearchValue || (isSearchMultiple && valueIsSet)) { |
|
|
|
module.verbose('Hiding placeholder text'); |
|
|
|
$text.addClass(className.filtered); |
|
|
|
} |
|
|
|
else if(!isMultiple || (isMultiple && !valueIsSet)) { |
|
|
|
else if(!isMultiple || (isSearchMultiple && !valueIsSet)) { |
|
|
|
module.verbose('Showing placeholder text'); |
|
|
|
$text.removeClass(className.filtered); |
|
|
|
} |
|
|
@ -1414,10 +1422,11 @@ $.fn.dropdown = function(parameters) { |
|
|
|
currentValue = module.get.values() |
|
|
|
; |
|
|
|
if($input.length > 0) { |
|
|
|
|
|
|
|
if( module.is.multiple() ) { |
|
|
|
|
|
|
|
// extend currently selected values
|
|
|
|
value = [value]; |
|
|
|
|
|
|
|
if($.isArray(currentValue)) { |
|
|
|
value = currentValue.concat(value); |
|
|
|
value = module.get.uniqueArray(value); |
|
|
@ -1463,15 +1472,15 @@ $.fn.dropdown = function(parameters) { |
|
|
|
visible: function() { |
|
|
|
$module.addClass(className.visible); |
|
|
|
}, |
|
|
|
selected: function(value) { |
|
|
|
selected: function(value, $selectedItem) { |
|
|
|
var |
|
|
|
$selectedItem = module.get.item(value), |
|
|
|
isMultiple = module.is.multiple(), |
|
|
|
shouldAnimate = (isMultiple && $selectedItem.length == 1), |
|
|
|
selectedText, |
|
|
|
selectedValue |
|
|
|
; |
|
|
|
if($selectedItem && !$selectedItem.hasClass(className.active) ) { |
|
|
|
$selectedItem = $selectedItem || module.get.item(value); |
|
|
|
|
|
|
|
if($selectedItem) { |
|
|
|
module.debug('Setting selected menu item to', $selectedItem); |
|
|
|
if(!module.is.multiple()) { |
|
|
|
module.remove.activeItem(); |
|
|
@ -1482,14 +1491,14 @@ $.fn.dropdown = function(parameters) { |
|
|
|
.addClass(className.selected) |
|
|
|
.each(function() { |
|
|
|
var |
|
|
|
$selected = $(this) |
|
|
|
$selected = $(this), |
|
|
|
shouldAnimate = (isMultiple && $selectedItem.length == 1) |
|
|
|
; |
|
|
|
selectedText = module.get.choiceText($selected); |
|
|
|
selectedValue = module.get.choiceValue($selected, selectedText); |
|
|
|
if(isMultiple) { |
|
|
|
module.add.label(selectedValue, selectedText, shouldAnimate); |
|
|
|
module.set.value(selectedValue, selectedText, $selected); |
|
|
|
module.set.filtered(); |
|
|
|
} |
|
|
|
else { |
|
|
|
module.set.value(selectedValue, selectedText, $selected); |
|
|
@ -1507,7 +1516,10 @@ $.fn.dropdown = function(parameters) { |
|
|
|
$label = $('<a />') |
|
|
|
.addClass(className.label) |
|
|
|
.attr('data-value', value) |
|
|
|
.html(templates.label(value, text)) |
|
|
|
.html(templates.label(value, text)), |
|
|
|
$next = module.is.searchSelection() |
|
|
|
? $search |
|
|
|
: $text |
|
|
|
; |
|
|
|
if(settings.label.variation) { |
|
|
|
$label.addClass(settings.label.variation); |
|
|
@ -1516,14 +1528,14 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.debug('Animating in label', $label); |
|
|
|
$label |
|
|
|
.addClass(className.hidden) |
|
|
|
.insertBefore($search) |
|
|
|
.insertBefore($next) |
|
|
|
.transition(settings.label.transition, settings.label.duration) |
|
|
|
; |
|
|
|
} |
|
|
|
else { |
|
|
|
module.debug('Adding selection label', $label); |
|
|
|
$label |
|
|
|
.insertBefore($search) |
|
|
|
.insertBefore($next) |
|
|
|
; |
|
|
|
} |
|
|
|
} |
|
|
@ -1553,7 +1565,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
var |
|
|
|
$selectedItem = module.get.item(value), |
|
|
|
$option, |
|
|
|
values = $input.val(), |
|
|
|
values = $input.val(), |
|
|
|
selectedValue = module.get.choiceValue($selectedItem) |
|
|
|
; |
|
|
|
if($selectedItem) { |
|
|
@ -1565,13 +1577,17 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
else { |
|
|
|
values = module.remove.delimitedValue(selectedValue, values); |
|
|
|
$input.val(values); |
|
|
|
$input |
|
|
|
.val(values) |
|
|
|
.trigger('change') |
|
|
|
; |
|
|
|
} |
|
|
|
if(module.is.multiple()) { |
|
|
|
module.remove.label(selectedValue); |
|
|
|
module.set.filtered(); |
|
|
|
} |
|
|
|
$selectedItem |
|
|
|
.removeClass(className.filtered) |
|
|
|
.removeClass(className.selected) |
|
|
|
.removeClass(className.active) |
|
|
|
; |
|
|
|
} |
|
|
@ -1669,6 +1685,9 @@ $.fn.dropdown = function(parameters) { |
|
|
|
: $menu.transition && $menu.transition('is animating') |
|
|
|
; |
|
|
|
}, |
|
|
|
focused: function() { |
|
|
|
return (document.activeElement === $module[0]); |
|
|
|
}, |
|
|
|
focusedOnSearch: function() { |
|
|
|
return (document.activeElement === $search[0]); |
|
|
|
}, |
|
|
@ -1767,6 +1786,9 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.verbose('Automatically determining animation based on animation direction', settings.transition); |
|
|
|
} |
|
|
|
if(settings.transition == 'none') { |
|
|
|
console.log(settings.transition); |
|
|
|
start(); |
|
|
|
$currentMenu.transition('show'); |
|
|
|
callback.call(element); |
|
|
|
} |
|
|
|
else if($.fn.transition !== undefined && $module.transition('is supported')) { |
|
|
@ -1820,6 +1842,8 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
|
|
|
|
if(settings.transition == 'none') { |
|
|
|
start(); |
|
|
|
$currentMenu.transition('hide'); |
|
|
|
callback.call(element); |
|
|
|
} |
|
|
|
else if($.fn.transition !== undefined && $module.transition('is supported')) { |
|
|
@ -2042,17 +2066,17 @@ $.fn.dropdown = function(parameters) { |
|
|
|
|
|
|
|
$.fn.dropdown.settings = { |
|
|
|
|
|
|
|
debug : false, |
|
|
|
verbose : true, |
|
|
|
performance : true, |
|
|
|
debug : false, |
|
|
|
verbose : true, |
|
|
|
performance : true, |
|
|
|
|
|
|
|
on : 'click', |
|
|
|
action : 'activate', |
|
|
|
on : 'click', |
|
|
|
action : 'activate', |
|
|
|
|
|
|
|
allowTab : true, |
|
|
|
fullTextSearch : false, |
|
|
|
preserveHTML : true, |
|
|
|
sortSelect : false, |
|
|
|
allowTab : true, |
|
|
|
fullTextSearch : false, |
|
|
|
preserveHTML : true, |
|
|
|
sortSelect : false, |
|
|
|
|
|
|
|
label: { |
|
|
|
transition : 'horizontal flip', |
|
|
@ -2079,11 +2103,11 @@ $.fn.dropdown.settings = { |
|
|
|
duration : 250, |
|
|
|
|
|
|
|
/* Callbacks */ |
|
|
|
onLabelClick : function($selectedLabels){}, |
|
|
|
onNoResults : function(searchTerm){}, |
|
|
|
onChange : function(value, text, $selected){}, |
|
|
|
onShow : function(){}, |
|
|
|
onHide : function(){}, |
|
|
|
onLabelSelect : function($selectedLabels){}, |
|
|
|
onNoResults : function(searchTerm){}, |
|
|
|
onChange : function(value, text, $selected){}, |
|
|
|
onShow : function(){}, |
|
|
|
onHide : function(){}, |
|
|
|
|
|
|
|
/* Component */ |
|
|
|
|
|
|
|