From 19b55d3fcef54d610a8256e861d0bc894b514c5c Mon Sep 17 00:00:00 2001 From: Thomas Tanghus Date: Sat, 12 May 2012 13:42:41 +0200 Subject: [PATCH] Edited combobox to adhere to coding standards and added a dblclick handler. --- apps/contacts/js/jquery.combobox.js | 43 ++++++++++++++++------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/apps/contacts/js/jquery.combobox.js b/apps/contacts/js/jquery.combobox.js index f12d1d7dd2..d9959eb6cd 100644 --- a/apps/contacts/js/jquery.combobox.js +++ b/apps/contacts/js/jquery.combobox.js @@ -23,16 +23,16 @@ minLength: 0, source: function( request, response ) { var matcher = new RegExp( $.ui.autocomplete.escapeRegex(request.term), "i" ); - response( select.children( "option" ).map(function() { + response( select.children('option').map(function() { var text = $( this ).text(); if ( this.value && ( !request.term || matcher.test(text) ) ) return { label: text.replace( new RegExp( - "(?![^&;]+;)(?!<[^<>]*)(" + + '(?![^&;]+;)(?!<[^<>]*)(' + $.ui.autocomplete.escapeRegex(request.term) + - ")(?![^<>]*>)(?![^&;]+;)", "gi" - ), "$1" ), + ')(?![^<>]*>)(?![^&;]+;)', 'gi' + ), '$1'), value: text, option: this }; @@ -42,17 +42,17 @@ self.input.val($(ui.item.option).text()); self.input.trigger('change'); ui.item.option.selected = true; - self._trigger( "selected", event, { + self._trigger('selected', event, { item: ui.item.option }); }, change: function( event, ui ) { if ( !ui.item ) { - var matcher = new RegExp( "^" + $.ui.autocomplete.escapeRegex( $(this).val() ) + "$", "i" ), + var matcher = new RegExp( '^' + $.ui.autocomplete.escapeRegex( $(this).val() ) + '$', 'i' ), valid = false; self.input.val($(this).val()); //self.input.trigger('change'); - select.children( "option" ).each(function() { + select.children('option').each(function() { if ( $( this ).text().match( matcher ) ) { this.selected = valid = true; return false; @@ -62,36 +62,41 @@ // remove invalid value, as it didn't match anything $( this ).val( "" ); select.val( "" ); - input.data( "autocomplete" ).term = ""; + input.data('autocomplete').term = ''; return false; } } } }) - .addClass( "ui-widget ui-widget-content ui-corner-left" ); + .addClass('ui-widget ui-widget-content ui-corner-left'); - input.data( "autocomplete" )._renderItem = function( ul, item ) { - return $( "
  • " ) - .data( "item.autocomplete", item ) - .append( "" + item.label + "" ) + input.data('autocomplete')._renderItem = function( ul, item ) { + return $('
  • ') + .data('item.autocomplete', item ) + .append('' + item.label + '') .appendTo( ul ); }; $.each(this.options, function(key, value) { self._setOption(key, value); }); + input.dblclick(function() { + // pass empty string as value to search for, displaying all results + input.autocomplete('search', ''); + }); + if(this.options['showButton']) { - this.button = $( "" ) - .attr( "tabIndex", -1 ) - .attr( "title", "Show All Items" ) + this.button = $('') + .attr('tabIndex', -1 ) + .attr('title', 'Show All Items') .insertAfter( input ) .addClass('svg') .addClass('action') .addClass('combo-button') .click(function() { // close if already visible - if ( input.autocomplete( "widget" ).is( ":visible" ) ) { - input.autocomplete( "close" ); + if ( input.autocomplete('widget').is(':visible') ) { + input.autocomplete('close'); return; } @@ -99,7 +104,7 @@ $( this ).blur(); // pass empty string as value to search for, displaying all results - input.autocomplete( "search", "" ); + input.autocomplete('search', ''); input.focus(); }); }