|
|
@ -4034,6 +4034,12 @@ $.fn.dropdown = function(parameters) { |
|
|
|
}); |
|
|
|
} |
|
|
|
}, |
|
|
|
menu: function() { |
|
|
|
$menu = $('<div />') |
|
|
|
.addClass(className.menu) |
|
|
|
.appendTo($module) |
|
|
|
; |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
search: function(query) { |
|
|
@ -4091,6 +4097,9 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.setup.select(); |
|
|
|
module.setup.returnedObject(); |
|
|
|
} |
|
|
|
if( !module.has.menu() ) { |
|
|
|
module.create.menu(); |
|
|
|
} |
|
|
|
if( module.is.search() && !module.has.search() ) { |
|
|
|
module.verbose('Adding search input'); |
|
|
|
$search = $('<input />') |
|
|
@ -4101,12 +4110,6 @@ $.fn.dropdown = function(parameters) { |
|
|
|
if(settings.allowTab) { |
|
|
|
module.set.tabbable(); |
|
|
|
} |
|
|
|
if($menu.length === 0) { |
|
|
|
$menu = $('<div />') |
|
|
|
.addClass(className.menu) |
|
|
|
.appendTo($module) |
|
|
|
; |
|
|
|
} |
|
|
|
}, |
|
|
|
select: function() { |
|
|
|
var |
|
|
@ -4120,7 +4123,10 @@ $.fn.dropdown = function(parameters) { |
|
|
|
if($input.parent(selector.dropdown).length > 0) { |
|
|
|
module.debug('UI dropdown already exists. Creating dropdown menu only'); |
|
|
|
$module = $input.closest(selector.dropdown); |
|
|
|
$menu = $module.children(selector.menu); |
|
|
|
if( !module.has.menu() ) { |
|
|
|
module.create.menu(); |
|
|
|
} |
|
|
|
$menu = $module.children(selector.menu); |
|
|
|
module.setup.menu(selectValues); |
|
|
|
} |
|
|
|
else { |
|
|
@ -4223,10 +4229,11 @@ $.fn.dropdown = function(parameters) { |
|
|
|
; |
|
|
|
if( module.can.show() && !module.is.active() ) { |
|
|
|
module.debug('Showing dropdown'); |
|
|
|
if(module.is.multiple()) { |
|
|
|
if(!module.has.search() && module.is.allFiltered()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if(module.is.multiple() && !module.has.search() && module.is.allFiltered()) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
if(module.has.message() && !module.has.maxSelections()) { |
|
|
|
module.remove.message(); |
|
|
|
} |
|
|
|
module.animate.show(function() { |
|
|
|
if( module.can.click() ) { |
|
|
@ -4491,7 +4498,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
beginsWithRegExp = new RegExp('^' + escapedTerm, 'igm') |
|
|
|
; |
|
|
|
// avoid loop if we're matching nothing
|
|
|
|
if(searchTerm === '') { |
|
|
|
if( !module.has.query() ) { |
|
|
|
$results = $item; |
|
|
|
} |
|
|
|
else { |
|
|
@ -4588,7 +4595,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
: $activeItem, |
|
|
|
hasSelected = ($selectedItem.size() > 0) |
|
|
|
; |
|
|
|
if(hasSelected) { |
|
|
|
if( hasSelected && module.has.query() ) { |
|
|
|
module.debug('Forcing partial selection to selected item', $selectedItem); |
|
|
|
module.event.item.click.call($selectedItem); |
|
|
|
} |
|
|
@ -4726,7 +4733,9 @@ $.fn.dropdown = function(parameters) { |
|
|
|
touch: function(event) { |
|
|
|
module.determine.eventOnElement(event, function() { |
|
|
|
if(event.type == 'touchstart') { |
|
|
|
module.timer = setTimeout(module.hide, settings.delay.touch); |
|
|
|
module.timer = setTimeout(function() { |
|
|
|
module.hide(); |
|
|
|
}, settings.delay.touch); |
|
|
|
} |
|
|
|
else if(event.type == 'touchmove') { |
|
|
|
clearTimeout(module.timer); |
|
|
@ -4776,15 +4785,17 @@ $.fn.dropdown = function(parameters) { |
|
|
|
}, settings.delay.hide); |
|
|
|
} |
|
|
|
}, |
|
|
|
touchend: function() { |
|
|
|
}, |
|
|
|
click: function (event) { |
|
|
|
var |
|
|
|
$choice = $(this), |
|
|
|
$target = (event) |
|
|
|
$choice = $(this), |
|
|
|
$target = (event) |
|
|
|
? $(event.target) |
|
|
|
: $(''), |
|
|
|
$subMenu = $choice.find(selector.menu), |
|
|
|
text = module.get.choiceText($choice), |
|
|
|
value = module.get.choiceValue($choice, text), |
|
|
|
$subMenu = $choice.find(selector.menu), |
|
|
|
text = module.get.choiceText($choice), |
|
|
|
value = module.get.choiceValue($choice, text), |
|
|
|
hasSubMenu = ($subMenu.length > 0), |
|
|
|
isBubbledEvent = ($subMenu.find($target).length > 0) |
|
|
|
; |
|
|
@ -5184,6 +5195,15 @@ $.fn.dropdown = function(parameters) { |
|
|
|
id: function() { |
|
|
|
return id; |
|
|
|
}, |
|
|
|
defaultText: function() { |
|
|
|
return $module.data(metadata.defaultText); |
|
|
|
}, |
|
|
|
defaultValue: function() { |
|
|
|
return $module.data(metadata.defaultValue); |
|
|
|
}, |
|
|
|
placeholderText: function() { |
|
|
|
return $module.data(metadata.placeholderText) || ''; |
|
|
|
}, |
|
|
|
text: function() { |
|
|
|
return $text.text(); |
|
|
|
}, |
|
|
@ -5449,7 +5469,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
; |
|
|
|
shouldSearch = (isMultiple) |
|
|
|
? (value.length > 0) |
|
|
|
: (value !== undefined && value !== '' && value !== null) |
|
|
|
: (value !== undefined && value !== null) |
|
|
|
; |
|
|
|
isMultiple = (module.is.multiple() && $.isArray(value)); |
|
|
|
strict = (value === '' || value === 0) |
|
|
@ -5534,15 +5554,21 @@ $.fn.dropdown = function(parameters) { |
|
|
|
}, |
|
|
|
defaultText: function() { |
|
|
|
var |
|
|
|
defaultText = $module.data(metadata.defaultText) |
|
|
|
defaultText = module.get.defaultText(), |
|
|
|
placeholderText = module.get.placeholderText |
|
|
|
; |
|
|
|
module.debug('Restoring default text', defaultText); |
|
|
|
module.set.text(defaultText); |
|
|
|
$text.addClass(className.placeholder); |
|
|
|
if(defaultText === placeholderText) { |
|
|
|
module.debug('Restoring default placeholder text', defaultText); |
|
|
|
module.set.placeholderText(defaultText); |
|
|
|
} |
|
|
|
else { |
|
|
|
module.debug('Restoring default text', defaultText); |
|
|
|
module.set.text(defaultText); |
|
|
|
} |
|
|
|
}, |
|
|
|
defaultValue: function() { |
|
|
|
var |
|
|
|
defaultValue = $module.data(metadata.defaultValue) |
|
|
|
defaultValue = module.get.defaultValue() |
|
|
|
; |
|
|
|
if(defaultValue !== undefined) { |
|
|
|
module.debug('Restoring default value', defaultValue); |
|
|
@ -5654,7 +5680,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
var |
|
|
|
text |
|
|
|
; |
|
|
|
if($text.hasClass(className.placeholder)) { |
|
|
|
if(settings.placeholder !== false && $text.hasClass(className.placeholder)) { |
|
|
|
text = module.get.text(); |
|
|
|
module.verbose('Saving placeholder text as', text); |
|
|
|
$module.data(metadata.placeholderText, text); |
|
|
@ -5688,8 +5714,8 @@ $.fn.dropdown = function(parameters) { |
|
|
|
|
|
|
|
scrollPage: function(direction, $selectedItem) { |
|
|
|
var |
|
|
|
$selectedItem = $selectedItem || module.get.selectedItem(), |
|
|
|
$menu = $selectedItem.closest(selector.menu), |
|
|
|
$currentItem = $selectedItem || module.get.selectedItem(), |
|
|
|
$menu = $currentItem.closest(selector.menu), |
|
|
|
menuHeight = $menu.outerHeight(), |
|
|
|
currentScroll = $menu.scrollTop(), |
|
|
|
itemHeight = $item.eq(0).outerHeight(), |
|
|
@ -5704,8 +5730,8 @@ $.fn.dropdown = function(parameters) { |
|
|
|
elementIndex |
|
|
|
; |
|
|
|
elementIndex = (direction == 'up') |
|
|
|
? $selectableItem.index($selectedItem) - itemsPerPage |
|
|
|
: $selectableItem.index($selectedItem) + itemsPerPage |
|
|
|
? $selectableItem.index($currentItem) - itemsPerPage |
|
|
|
: $selectableItem.index($currentItem) + itemsPerPage |
|
|
|
; |
|
|
|
isWithinRange = (direction == 'up') |
|
|
|
? (elementIndex >= 0) |
|
|
@ -5719,7 +5745,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
; |
|
|
|
if($nextSelectedItem.length > 0) { |
|
|
|
module.debug('Scrolling page', direction, $nextSelectedItem); |
|
|
|
$selectedItem |
|
|
|
$currentItem |
|
|
|
.removeClass(className.selected) |
|
|
|
; |
|
|
|
$nextSelectedItem |
|
|
@ -5761,12 +5787,10 @@ $.fn.dropdown = function(parameters) { |
|
|
|
$module.addClass(className.loading); |
|
|
|
}, |
|
|
|
placeholderText: function(text) { |
|
|
|
text = text || $module.data(metadata.placeholderText); |
|
|
|
if(text) { |
|
|
|
module.debug('Restoring placeholder text'); |
|
|
|
module.set.text(text); |
|
|
|
$text.addClass(className.placeholder); |
|
|
|
} |
|
|
|
text = text || module.get.placeholderText(); |
|
|
|
module.debug('Setting placeholder text', text); |
|
|
|
module.set.text(text); |
|
|
|
$text.addClass(className.placeholder); |
|
|
|
}, |
|
|
|
tabbable: function() { |
|
|
|
if( module.has.search() ) { |
|
|
@ -5849,10 +5873,12 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
if(text !== module.get.placeholderText()) { |
|
|
|
$text.removeClass(className.placeholder); |
|
|
|
} |
|
|
|
module.debug('Changing text', text, $text); |
|
|
|
$text |
|
|
|
.removeClass(className.filtered) |
|
|
|
.removeClass(className.placeholder) |
|
|
|
; |
|
|
|
if(settings.preserveHTML) { |
|
|
|
$text.html(text); |
|
|
@ -5938,8 +5964,13 @@ $.fn.dropdown = function(parameters) { |
|
|
|
module.debug('Updating input value', value, currentValue); |
|
|
|
$input |
|
|
|
.val(value) |
|
|
|
.trigger('change') |
|
|
|
; |
|
|
|
if(settings.fireOnInit === false && module.is.initialLoad()) { |
|
|
|
module.debug('Input native change event ignored on initial load'); |
|
|
|
} |
|
|
|
else { |
|
|
|
$input.trigger('change'); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
module.verbose('Storing value in metadata', value, $input); |
|
|
@ -6218,7 +6249,7 @@ $.fn.dropdown = function(parameters) { |
|
|
|
} |
|
|
|
|
|
|
|
if(settings.fireOnInit === false && module.is.initialLoad()) { |
|
|
|
module.verbose('No callback on initial load', settings.onAdd); |
|
|
|
module.verbose('Skipping onadd callback on initial load', settings.onAdd); |
|
|
|
} |
|
|
|
else { |
|
|
|
settings.onAdd.call(element, addedValue, addedText, $selectedItem); |
|
|
@ -6468,6 +6499,9 @@ $.fn.dropdown = function(parameters) { |
|
|
|
allResultsFiltered: function() { |
|
|
|
return ($item.filter(selector.unselectable).length === $item.length); |
|
|
|
}, |
|
|
|
query: function() { |
|
|
|
return (module.get.query() !== ''); |
|
|
|
}, |
|
|
|
value: function(value) { |
|
|
|
var |
|
|
|
values = module.get.values(), |
|
|
|