Issue #2898261 by droplet, effulgentsia, nod_, andrewmacpherson, cilefen, dmsmidt, drpal, larowlan: In jQuery 3, $('#') throws syntax errors
parent
f9e40fa790
commit
2174766ce5
|
@ -265,28 +265,30 @@
|
|||
* @fires event:formFragmentLinkClickOrHashChange
|
||||
*/
|
||||
const handleFragmentLinkClickOrHashChange = (e) => {
|
||||
let $target;
|
||||
|
||||
let url;
|
||||
if (e.type === 'click') {
|
||||
$target = e.currentTarget.location ? $(e.currentTarget.location.hash) : $(e.currentTarget.hash);
|
||||
url = e.currentTarget.location ? e.currentTarget.location : e.currentTarget;
|
||||
}
|
||||
else {
|
||||
$target = $(`#${location.hash.substr(1)}`);
|
||||
url = location;
|
||||
}
|
||||
const hash = url.hash.substr(1);
|
||||
if (hash) {
|
||||
const $target = $(`#${hash}`);
|
||||
$('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
||||
|
||||
$('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
||||
|
||||
/**
|
||||
* Clicking a fragment link or a hash change should focus the target
|
||||
* element, but event timing issues in multiple browsers require a timeout.
|
||||
*/
|
||||
setTimeout(() => {
|
||||
$target.focus();
|
||||
}, 300, $target);
|
||||
/**
|
||||
* Clicking a fragment link or a hash change should focus the target
|
||||
* element, but event timing issues in multiple browsers require a timeout.
|
||||
*/
|
||||
setTimeout(() => $target.trigger('focus'), 300);
|
||||
}
|
||||
};
|
||||
|
||||
const debouncedHandleFragmentLinkClickOrHashChange = debounce(handleFragmentLinkClickOrHashChange, 300, true);
|
||||
|
||||
// Binds a listener to handle URL fragment changes.
|
||||
$(window).on('hashchange.form-fragment', debounce(handleFragmentLinkClickOrHashChange, 300, true));
|
||||
$(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange);
|
||||
|
||||
/**
|
||||
* Binds a listener to handle clicks on fragment links and absolute URL links
|
||||
|
@ -294,6 +296,6 @@
|
|||
* because clicking such links doesn't trigger a hash change when the fragment
|
||||
* is already in the URL.
|
||||
*/
|
||||
$(document).on('click.form-fragment', 'a[href*="#"]', debounce(handleFragmentLinkClickOrHashChange, 300, true));
|
||||
$(document).on('click.form-fragment', 'a[href*="#"]', debouncedHandleFragmentLinkClickOrHashChange);
|
||||
|
||||
}(jQuery, Drupal, Drupal.debounce));
|
||||
|
|
|
@ -126,22 +126,26 @@
|
|||
};
|
||||
|
||||
var handleFragmentLinkClickOrHashChange = function handleFragmentLinkClickOrHashChange(e) {
|
||||
var $target = void 0;
|
||||
|
||||
var url = void 0;
|
||||
if (e.type === 'click') {
|
||||
$target = e.currentTarget.location ? $(e.currentTarget.location.hash) : $(e.currentTarget.hash);
|
||||
url = e.currentTarget.location ? e.currentTarget.location : e.currentTarget;
|
||||
} else {
|
||||
$target = $('#' + location.hash.substr(1));
|
||||
url = location;
|
||||
}
|
||||
var hash = url.hash.substr(1);
|
||||
if (hash) {
|
||||
var $target = $('#' + hash);
|
||||
$('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
||||
|
||||
$('body').trigger('formFragmentLinkClickOrHashChange', [$target]);
|
||||
|
||||
setTimeout(function () {
|
||||
$target.focus();
|
||||
}, 300, $target);
|
||||
setTimeout(function () {
|
||||
return $target.trigger('focus');
|
||||
}, 300);
|
||||
}
|
||||
};
|
||||
|
||||
$(window).on('hashchange.form-fragment', debounce(handleFragmentLinkClickOrHashChange, 300, true));
|
||||
var debouncedHandleFragmentLinkClickOrHashChange = debounce(handleFragmentLinkClickOrHashChange, 300, true);
|
||||
|
||||
$(document).on('click.form-fragment', 'a[href*="#"]', debounce(handleFragmentLinkClickOrHashChange, 300, true));
|
||||
$(window).on('hashchange.form-fragment', debouncedHandleFragmentLinkClickOrHashChange);
|
||||
|
||||
$(document).on('click.form-fragment', 'a[href*="#"]', debouncedHandleFragmentLinkClickOrHashChange);
|
||||
})(jQuery, Drupal, Drupal.debounce);
|
Loading…
Reference in New Issue