assets/javascripts/semantic_ui/definitions/modules/dropdown.js in less-rails-semantic_ui-2.2.6.0 vs assets/javascripts/semantic_ui/definitions/modules/dropdown.js in less-rails-semantic_ui-2.2.9.0

- old
+ new

@@ -459,10 +459,14 @@ show: function(callback) { callback = $.isFunction(callback) ? callback : function(){} ; + if(!module.can.show() && module.is.remote()) { + module.debug('No API results retrieved, searching before show'); + module.queryRemote(module.get.query(), module.show); + } if( module.can.show() && !module.is.active() ) { module.debug('Showing dropdown'); if(module.has.message() && !(module.has.maxSelections() || module.has.allResultsFiltered()) ) { module.remove.message(); } @@ -615,12 +619,21 @@ } $module .on('mousedown' + eventNamespace, module.event.mousedown) .on('mouseup' + eventNamespace, module.event.mouseup) .on('focus' + eventNamespace, module.event.focus) - .on('blur' + eventNamespace, module.event.blur) ; + if(module.has.menuSearch() ) { + $module + .on('blur' + eventNamespace, selector.search, module.event.search.blur) + ; + } + else { + $module + .on('blur' + eventNamespace, module.event.blur) + ; + } } $menu .on('mouseenter' + eventNamespace, selector.item, module.event.item.mouseenter) .on('mouseleave' + eventNamespace, selector.item, module.event.item.mouseleave) .on('click' + eventNamespace, selector.item, module.event.item.click) @@ -700,10 +713,13 @@ return; } if(settings.apiSettings) { if( module.can.useAPI() ) { module.queryRemote(searchTerm, function() { + if(settings.filterRemoteData) { + module.filterItems(searchTerm); + } afterFiltered(); }); } else { module.error(error.noAPI); @@ -755,11 +771,11 @@ var searchTerm = (query !== undefined) ? query : module.get.query(), results = null, - escapedTerm = module.escape.regExp(searchTerm), + escapedTerm = module.escape.string(searchTerm), beginsWithRegExp = new RegExp('^' + escapedTerm, 'igm') ; // avoid loop if we're matching nothing if( module.has.query() ) { results = []; @@ -787,19 +803,22 @@ return true; } } if(settings.match == 'both' || settings.match == 'value') { value = String(module.get.choiceValue($choice, text)); - if(value.search(beginsWithRegExp) !== -1) { results.push(this); return true; } - else if(settings.fullTextSearch && module.fuzzySearch(searchTerm, value)) { + else if (settings.fullTextSearch === 'exact' && module.exactSearch(searchTerm, value)) { results.push(this); return true; } + else if (settings.fullTextSearch === true && module.fuzzySearch(searchTerm, value)) { + results.push(this); + return true; + } } }) ; } module.debug('Showing only matched items', searchTerm); @@ -874,11 +893,11 @@ $selectedItem = ($currentlySelected.length > 0) ? $currentlySelected : $activeItem, hasSelected = ($selectedItem.length > 0) ; - if(hasSelected) { + if(hasSelected && !module.is.multiple()) { module.debug('Forcing partial selection to selected item', $selectedItem); module.event.item.click.call($selectedItem, {}, true); return; } else { @@ -2181,11 +2200,11 @@ module.debug('Setting placeholder text', text); module.set.text(text); $text.addClass(className.placeholder); }, tabbable: function() { - if( module.has.search() ) { + if( module.is.searchSelection() ) { module.debug('Added tabindex to searchable dropdown'); $search .val('') .attr('tabindex', 0) ; @@ -2293,16 +2312,17 @@ } } }, selectedItem: function($item) { var - value = module.get.choiceValue($item), - text = module.get.choiceText($item, false) + value = module.get.choiceValue($item), + searchText = module.get.choiceText($item, false), + text = module.get.choiceText($item, true) ; module.debug('Setting user selection to item', $item); module.remove.activeItem(); - module.set.partialSearch(text); + module.set.partialSearch(searchText); module.set.activeItem($item); module.set.selected(value, $item); module.set.text(text); }, selectedLetter: function(letter) { @@ -2507,11 +2527,11 @@ escapedValue = module.escape.value(value), $label ; $label = $('<a />') .addClass(className.label) - .attr('data-value', escapedValue) + .attr('data-' + metadata.value, escapedValue) .html(templates.label(escapedValue, text)) ; $label = settings.onLabelCreate.call($label, escapedValue, text); if(module.has.label(value)) { @@ -2555,11 +2575,11 @@ } }, optionValue: function(value) { var escapedValue = module.escape.value(value), - $option = $input.find('option[value="' + escapedValue + '"]'), + $option = $input.find('option[value="' + module.escape.string(escapedValue) + '"]'), hasOption = ($option.length > 0) ; if(hasOption) { return; } @@ -2728,11 +2748,11 @@ module.remove.empty(); }, optionValue: function(value) { var escapedValue = module.escape.value(value), - $option = $input.find('option[value="' + escapedValue + '"]'), + $option = $input.find('option[value="' + module.escape.string(escapedValue) + '"]'), hasOption = ($option.length > 0) ; if(!hasOption || !$option.hasClass(className.addition)) { return; } @@ -2847,11 +2867,11 @@ return values; }, label: function(value, shouldAnimate) { var $labels = $module.find(selector.label), - $removedLabel = $labels.filter('[data-value="' + value +'"]') + $removedLabel = $labels.filter('[data-' + metadata.value + '="' + module.escape.string(value) +'"]') ; module.verbose('Removing label', $removedLabel); $removedLabel.remove(); }, activeLabels: function($activeLabels) { @@ -2887,11 +2907,11 @@ } }) ; }, tabbable: function() { - if( module.has.search() ) { + if( module.is.searchSelection() ) { module.debug('Searchable dropdown initialized'); $search .removeAttr('tabindex') ; $menu @@ -2961,11 +2981,11 @@ label: function(value) { var escapedValue = module.escape.value(value), $labels = $module.find(selector.label) ; - return ($labels.filter('[data-value="' + escapedValue +'"]').length > 0); + return ($labels.filter('[data-' + metadata.value + '="' + module.escape.string(escapedValue) +'"]').length > 0); }, maxSelections: function() { return (settings.maxSelections && module.get.selectionCount() >= settings.maxSelections); }, allResultsFiltered: function() { @@ -3081,10 +3101,13 @@ return found; }, multiple: function() { return $module.hasClass(className.multiple); }, + remote: function() { + return settings.apiSettings && module.can.useAPI(); + }, single: function() { return !module.is.multiple(); }, selectMutation: function(mutations) { var @@ -3286,11 +3309,11 @@ stringValue = (typeof value === 'string'), isUnparsable = (!stringValue && !multipleValues), hasQuotes = (stringValue && value.search(regExp.quote) !== -1), values = [] ; - if(!module.has.selectInput() || isUnparsable || !hasQuotes) { + if(isUnparsable || !hasQuotes) { return value; } module.debug('Encoding quote values for use in select', value); if(multipleValues) { $.each(value, function(index, value){ @@ -3298,11 +3321,11 @@ }); return values; } return value.replace(regExp.quote, '&quot;'); }, - regExp: function(text) { + string: function(text) { text = String(text); return text.replace(regExp.escape, '\\$&'); } }, @@ -3501,10 +3524,13 @@ apiSettings : false, selectOnKeydown : true, // Whether selection should occur automatically when keyboard shortcuts used minCharacters : 0, // Minimum characters required to trigger API call + + filterRemoteData : false, // Whether API results should be filtered after being returned for query term saveRemoteData : true, // Whether remote name/value pairs should be stored in sessionStorage to allow remote data to be restored on page refresh + throttle : 200, // How long to wait after last user input to search remotely context : window, // Context to use when determining if on screen direction : 'auto', // Whether dropdown should always open in one direction keepOnScreen : true, // Whether dropdown should check whether it is on screen before showing