|
@ -161,7 +161,34 @@ $.fn.dropdown = function(parameters) { |
|
|
elementNamespace = '.' + id; |
|
|
elementNamespace = '.' + id; |
|
|
module.verbose('Creating unique id for element', id); |
|
|
module.verbose('Creating unique id for element', id); |
|
|
}, |
|
|
}, |
|
|
userLabels: function() { |
|
|
|
|
|
|
|
|
userChoice: function(values) { |
|
|
|
|
|
var |
|
|
|
|
|
$userChoices, |
|
|
|
|
|
$userChoice, |
|
|
|
|
|
html |
|
|
|
|
|
; |
|
|
|
|
|
values = values || module.get.userValues(); |
|
|
|
|
|
values = $.isArray(values) |
|
|
|
|
|
? values |
|
|
|
|
|
: [values] |
|
|
|
|
|
; |
|
|
|
|
|
module.debug('Creating user choices for each value', values); |
|
|
|
|
|
$.each(values, function(index, value) { |
|
|
|
|
|
html = settings.templates.addition(value); |
|
|
|
|
|
$userChoice = $('<div />') |
|
|
|
|
|
.html(html) |
|
|
|
|
|
.data(metadata.value, value) |
|
|
|
|
|
.addClass(className.addition) |
|
|
|
|
|
.addClass(className.item) |
|
|
|
|
|
; |
|
|
|
|
|
$userChoices = ($userChoices === undefined) |
|
|
|
|
|
? $userChoice |
|
|
|
|
|
: $userChoices.add($userChoice) |
|
|
|
|
|
; |
|
|
|
|
|
}); |
|
|
|
|
|
return $userChoices; |
|
|
|
|
|
}, |
|
|
|
|
|
userLabels: function(value) { |
|
|
var |
|
|
var |
|
|
userValues = module.get.userValues() |
|
|
userValues = module.get.userValues() |
|
|
; |
|
|
; |
|
@ -532,7 +559,7 @@ $.fn.dropdown = function(parameters) { |
|
|
module.remove.message(); |
|
|
module.remove.message(); |
|
|
} |
|
|
} |
|
|
if(settings.allowAdditions) { |
|
|
if(settings.allowAdditions) { |
|
|
module.add.userChoice(query); |
|
|
|
|
|
|
|
|
module.add.userSuggestion(query); |
|
|
} |
|
|
} |
|
|
if(module.is.searchSelection() && module.can.show() && module.is.focusedOnSearch() ) { |
|
|
if(module.is.searchSelection() && module.can.show() && module.is.focusedOnSearch() ) { |
|
|
module.show(); |
|
|
module.show(); |
|
@ -2001,7 +2028,8 @@ $.fn.dropdown = function(parameters) { |
|
|
}, |
|
|
}, |
|
|
selected: function(value, $selectedItem) { |
|
|
selected: function(value, $selectedItem) { |
|
|
var |
|
|
var |
|
|
isMultiple = module.is.multiple() |
|
|
|
|
|
|
|
|
isMultiple = module.is.multiple(), |
|
|
|
|
|
$userSelectedItem |
|
|
; |
|
|
; |
|
|
$selectedItem = $selectedItem || module.get.item(value); |
|
|
$selectedItem = $selectedItem || module.get.item(value); |
|
|
if(!$selectedItem) { |
|
|
if(!$selectedItem) { |
|
@ -2015,6 +2043,11 @@ $.fn.dropdown = function(parameters) { |
|
|
else if(settings.useLabels) { |
|
|
else if(settings.useLabels) { |
|
|
module.remove.selectedItem(); |
|
|
module.remove.selectedItem(); |
|
|
} |
|
|
} |
|
|
|
|
|
if(settings.allowAdditions) { |
|
|
|
|
|
$userSelectedItem = module.create.userChoice(value); |
|
|
|
|
|
$selectedItem = $selectedItem.add($userSelectedItem); |
|
|
|
|
|
} |
|
|
|
|
|
// select each item
|
|
|
$selectedItem |
|
|
$selectedItem |
|
|
.each(function() { |
|
|
.each(function() { |
|
|
var |
|
|
var |
|
@ -2144,10 +2177,11 @@ $.fn.dropdown = function(parameters) { |
|
|
}); |
|
|
}); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
userChoice: function(value) { |
|
|
|
|
|
|
|
|
userSuggestion: function(value) { |
|
|
var |
|
|
var |
|
|
alreadyHasValue = module.get.item(value), |
|
|
|
|
|
$addition = $menu.children(selector.addition), |
|
|
|
|
|
|
|
|
$addition = $menu.children(selector.addition), |
|
|
|
|
|
alreadyHasValue = module.get.item(value), |
|
|
|
|
|
hasUserSuggestion = $addition.length > 0, |
|
|
html |
|
|
html |
|
|
; |
|
|
; |
|
|
if(module.has.maxSelections()) { |
|
|
if(module.has.maxSelections()) { |
|
@ -2157,27 +2191,26 @@ $.fn.dropdown = function(parameters) { |
|
|
$addition.remove(); |
|
|
$addition.remove(); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
html = settings.templates.addition(value); |
|
|
|
|
|
$item |
|
|
$item |
|
|
.removeClass(className.selected) |
|
|
.removeClass(className.selected) |
|
|
; |
|
|
; |
|
|
if($addition.length > 0) { |
|
|
|
|
|
|
|
|
if(hasUserSuggestion) { |
|
|
|
|
|
html = settings.templates.addition(value); |
|
|
$addition |
|
|
$addition |
|
|
.html(html) |
|
|
.html(html) |
|
|
.data(metadata.value, value) |
|
|
.data(metadata.value, value) |
|
|
.removeClass(className.filtered) |
|
|
.removeClass(className.filtered) |
|
|
.addClass(className.selected) |
|
|
.addClass(className.selected) |
|
|
; |
|
|
; |
|
|
|
|
|
module.verbose('Replacing user suggestion with new value', $addition); |
|
|
} |
|
|
} |
|
|
else { |
|
|
else { |
|
|
$addition = $('<div/>') |
|
|
|
|
|
.html(html) |
|
|
|
|
|
.data(metadata.value, value) |
|
|
|
|
|
.addClass(className.addition) |
|
|
|
|
|
.addClass(className.item) |
|
|
|
|
|
|
|
|
$addition = module.create.userChoice(value); |
|
|
|
|
|
$addition |
|
|
.prependTo($menu) |
|
|
.prependTo($menu) |
|
|
.addClass(className.selected) |
|
|
.addClass(className.selected) |
|
|
; |
|
|
; |
|
|
|
|
|
module.verbose('Adding item choice to menu corresponding with user choice addition', $addition); |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
variables: function(message) { |
|
|
variables: function(message) { |
|
@ -2189,6 +2222,7 @@ $.fn.dropdown = function(parameters) { |
|
|
count, |
|
|
count, |
|
|
query |
|
|
query |
|
|
; |
|
|
; |
|
|
|
|
|
module.verbose('Adding templated variables to message', message); |
|
|
if(hasCount) { |
|
|
if(hasCount) { |
|
|
count = module.get.selectionCount(); |
|
|
count = module.get.selectionCount(); |
|
|
message = message.replace('{count}', count); |
|
|
message = message.replace('{count}', count); |
|
|