Skip to content
Snippets Groups Projects
Commit 0541afe8 authored by mustanggb's avatar mustanggb Committed by Drew Webber
Browse files

Issue #3325927 by mcdruid, MustangGB: jQuery 3.3+ breaks autocomplete

parent 57b1861c
No related branches found
No related tags found
No related merge requests found
......@@ -59,6 +59,16 @@ function jquery_update_library() {
),
'version' => '0.0.1',
);
$libraries['jquery_update.position.fix'] = array(
'title' => 'jQuery Update Position Fix',
'js' => array(
drupal_get_path('module', 'jquery_update') . '/js/jquery_position.js' => array(
'group' => JS_THEME,
'weight' => 2,
),
),
'version' => '0.0.1',
);
$libraries['jquery.metadata'] = array(
'title' => 'QUnit',
'js' => array(
......@@ -289,6 +299,7 @@ function jquery_update_jquery_replace(array &$javascript, $cdn, $path, $min, $ve
if (!empty($custom_version)) {
$javascript['jquery']['version'] = $custom_version;
jquery_update_add_jquery_browser_fix($javascript, $custom_version);
jquery_update_add_jquery_position_fix($javascript, $custom_version);
}
return;
}
......@@ -343,6 +354,7 @@ function jquery_update_jquery_replace(array &$javascript, $cdn, $path, $min, $ve
break;
}
jquery_update_add_jquery_browser_fix($javascript, $version);
jquery_update_add_jquery_position_fix($javascript, $version);
}
/**
......@@ -357,6 +369,18 @@ function jquery_update_add_jquery_browser_fix(&$libraries, $jquery_version) {
}
}
/**
* Add a workaround for .position() behaviour change.
*/
function jquery_update_add_jquery_position_fix(&$libraries, $jquery_version) {
if (version_compare($jquery_version, '3.3', '>=')) {
$libraries['jquery']['dependencies'][] = array(
'jquery_update',
'jquery_update.position.fix',
);
}
}
/**
* Add the local fallback in case jQuery from the CDN is unavailable.
*
......
/**
* Workaround for .position() behaviour which was changed in jQuery 3.3
* @see https://github.com/jquery/api.jquery.com/issues/1081
*/
var Drupal = Drupal || {};
(function ($, Drupal) {
// Overload Drupal.jsAC.prototype.populatePopup
if (Drupal.jsAC !== undefined && Drupal.jsAC.prototype.populatePopup !== undefined) {
Drupal.jsAC.prototype.populatePopup = function () {
var $input = $(this.input);
var offset = $input.offset();
var offsetParent = $input.offsetParent().offset();
// Show popup.
if (this.popup) {
$(this.popup).remove();
}
this.selected = false;
this.popup = $('<div id="autocomplete"></div>')[0];
this.popup.owner = this;
$(this.popup).css({
top: parseInt(offset.top - offsetParent.top + this.input.offsetHeight, 10) + 'px',
left: parseInt(offset.left - offsetParent.left, 10) + 'px',
width: $input.innerWidth() + 'px',
display: 'none'
});
$input.before(this.popup);
// Do search.
this.db.owner = this;
this.db.search(this.input.value);
};
}
})(jQuery, Drupal);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment