diff --git a/ui/rules.autocomplete.js b/ui/rules.autocomplete.js index a888fd5..b79cdbe 100644 --- a/ui/rules.autocomplete.js +++ b/ui/rules.autocomplete.js @@ -103,14 +103,17 @@ Drupal.rules = Drupal.rules || {}; }); }); + // Newer versions of jQuery UI use element.data('ui-autocomplete'), older versions use element.data('autocomplete'). + var autocompleteDataKey = typeof(this.jqObject.data('autocomplete')) === 'object' ? 'autocomplete' : 'ui-autocomplete'; + // Since jquery autocomplete by default strips html text by using .text() // we need our own _renderItem function to display html content. - this.jqObject.data("autocomplete")._renderItem = function(ul, item) { + this.jqObject.data(autocompleteDataKey)._renderItem = function(ul, item) { return $("
  • ").data("item.autocomplete", item).append("" + item.label + "").appendTo(ul); }; // Override close function - this.jqObject.data("autocomplete").close = function (event) { + this.jqObject.data(autocompleteDataKey).close = function (event) { var value = this.element.val(); // If the selector is not a group, then trigger the close event an and // hide the menu. @@ -119,7 +122,10 @@ Drupal.rules = Drupal.rules || {}; if (this.menu.element.is(":visible")) { this._trigger("close", event); this.menu.element.hide(); - this.menu.deactivate(); + // Use deactivate for older versions of jQuery UI. + if (typeof(this.menu.deactivate) === 'function') { + this.menu.deactivate(); + } } } else { diff --git a/ui/ui.theme.inc b/ui/ui.theme.inc index 42bf6e8..a3af54d 100644 --- a/ui/ui.theme.inc +++ b/ui/ui.theme.inc @@ -256,6 +256,14 @@ function theme_rules_autocomplete($variables) { drupal_add_library('system', 'ui.autocomplete'); drupal_add_library('system', 'ui.button'); + // If the jQuery Update module is in use, then the UI Menu component may be + // needed (for later versions of jQuery UI). + if (module_exists('jquery_update') && variable_get('jquery_update_jquery_version', '1.5') >= '1.7') { + $minify = variable_get('jquery_update_compression_type', 'min') == 'min'; + drupal_add_js(drupal_get_path('module', 'jquery_update') . '/replace/ui/ui/' + . ($minify ? 'minified/jquery.ui.menu.min.js' : 'jquery.ui.menu.js')); + } + $element['#attributes']['type'] = 'text'; element_set_attributes($element, array('id', 'name', 'value', 'size', 'maxlength')); _form_set_class($element, array('form-text', 'rules-autocomplete'));