diff --git a/css/linkit.autocomplete.css b/css/linkit.autocomplete.css index f354505..4159a49 100644 --- a/css/linkit.autocomplete.css +++ b/css/linkit.autocomplete.css @@ -31,24 +31,27 @@ font-size: .9em; } -.linkit-ui-autocomplete.ui-menu .ui-menu-item { - list-style: none; +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper { + margin: 0; padding: 5px 7px; } -.linkit-ui-autocomplete .ui-menu-item.ui-state-focus { - margin: 0; +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper.ui-state-focus, +.linkit-ui-autocomplete.ui-menu .linkit-result-line-wrapper.ui-state-active { border: 0; border-bottom: 1px solid #bfbfbf; background: #0075ba; color: #fff; } -.linkit-result:not(:last-of-type) { +.linkit-result-line:not(:last-of-type) { border-bottom: 1px solid #bfbfbf; } -.linkit-result--group { +.ui-menu .linkit-result-line--group.ui-menu-divider { + margin: 0; + height: auto; + line-height: inherit; padding: 3px; background-color: #e7e7e7; border-bottom: 1px solid #bfbfbf; @@ -58,16 +61,17 @@ color: #555; } -.linkit-result--title { +.linkit-result-line--title { + display: block; font-weight: 600; } -.linkit-result--description { +.linkit-result-line--description { display: block; font-size: 0.9em; line-height: 1.3; } -.linkit-result--description img { +.linkit-result-line--description img { display: block; } diff --git a/js/autocomplete.js b/js/autocomplete.js index 28b158c..c68bee0 100644 --- a/js/autocomplete.js +++ b/js/autocomplete.js @@ -64,7 +64,6 @@ */ function selectHandler(event, ui) { var $form = $(event.target).closest('form'); - if (!ui.item.path) { throw 'Missing path param.' + JSON.stringify(ui.item); } @@ -98,14 +97,14 @@ * jQuery collection of the ul element. */ function renderItem(ul, item) { - var $line = $('
  • ').addClass('linkit-result'); - $line.append($('').html(item.label).addClass('linkit-result--title')); + var $line = $('
  • ').addClass('linkit-result-line'); + var $wrapper = $('
    ').addClass('linkit-result-line-wrapper'); + $wrapper.append($('').html(item.label).addClass('linkit-result-line--title')); if (item.hasOwnProperty('description')) { - $line.append($('').html(item.description).addClass('linkit-result--description')); + $wrapper.append($('').html(item.description).addClass('linkit-result-line--description')); } - - return $line.appendTo(ul); + return $line.append($wrapper).appendTo(ul); } /** @@ -125,7 +124,7 @@ $.each(grouped_items, function (group, items) { if (group.length) { - ul.append('
  • ' + group + '
  • '); + ul.append('
  • ' + group + '
  • '); } $.each(items, function (index, item) { @@ -134,6 +133,16 @@ }); } + function focusHandler() { + return false; + } + + function searchHandler(event) { + var options = autocomplete.options; + + return !options.isComposing; + } + /** * Attaches the autocomplete behavior to all required fields. * @@ -165,6 +174,13 @@ $autocomplete.click(function () { $autocomplete.autocomplete('search', $autocomplete.val()); }); + + $autocomplete.on('compositionstart.autocomplete', function () { + autocomplete.options.isComposing = true; + }); + $autocomplete.on('compositionend.autocomplete', function () { + autocomplete.options.isComposing = false; + }); } }, detach: function (context, settings, trigger) { @@ -183,10 +199,13 @@ cache: {}, options: { source: sourceData, + focus: focusHandler, + search: searchHandler, + select: selectHandler, renderItem: renderItem, renderMenu: renderMenu, - select: selectHandler, - minLength: 1 + minLength: 1, + isComposing: false }, ajax: { dataType: 'json' diff --git a/tests/src/FunctionalJavascript/LinkitDialogTest.php b/tests/src/FunctionalJavascript/LinkitDialogTest.php index 39bf712..dfad7ab 100644 --- a/tests/src/FunctionalJavascript/LinkitDialogTest.php +++ b/tests/src/FunctionalJavascript/LinkitDialogTest.php @@ -178,17 +178,17 @@ class LinkitDialogTest extends JavascriptTestBase { $href_field->keyDown('f'); // Wait for the results to load. - $this->getSession()->wait(5000, "jQuery('.linkit-result.ui-menu-item').length > 0"); + $this->getSession()->wait(5000, "jQuery('.linkit-result-line.ui-menu-item').length > 0"); // Make sure the autocomplete result container is visible. $this->assertTrue($autocomplete_container->isVisible()); // Find all the autocomplete results. - $results = $page->findAll('css', '.linkit-result.ui-menu-item'); + $results = $page->findAll('css', '.linkit-result-line.ui-menu-item'); $this->assertEquals(1, count($results), 'Found autocomplete result'); // Find the first result and click it. - $page->find('xpath', '(//li[contains(@class, "linkit-result") and contains(@class, "ui-menu-item")])[1]')->click(); + $page->find('xpath', '//li[contains(@class, "linkit-result-line") and contains(@class, "ui-menu-item")][1]')->click(); // Make sure the linkit field field is populated with the node url. $this->assertEquals($entity->toUrl()->toString(), $href_field->getValue(), 'The href field is populated with the node url.');