1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-08 07:47:00 +02:00

Small improvements to the pw-dropdowns code in /wire/templates-admin/main.js. Fixes one jQuery 3.x error, adds code to prevent double initialization, and adds code to trigger a pw-show-dropdown JS event when a dropdown is shown.

This commit is contained in:
Ryan Cramer
2024-07-19 12:14:30 -04:00
parent e508cfa2a7
commit 962d26a749
2 changed files with 14 additions and 3 deletions

View File

@@ -1,7 +1,7 @@
/**
* ProcessWire Admin common javascript
*
* Copyright 2016 by Ryan Cramer
* Copyright 2016-2024 by Ryan Cramer
*
*/
@@ -117,6 +117,8 @@ var ProcessWireAdmin = {
var $a = $(this);
var $ul;
if($a.hasClass('pw-dropdown-init')) return;
if($a.attr('data-pw-dropdown')) {
// see if it is specifying a certain <ul>
@@ -181,6 +183,7 @@ var ProcessWireAdmin = {
$a.removeClass('hover');
});
}
$a.addClass('pw-dropdown-init');
}
function mouseenterDropdownToggle(e) {
@@ -239,6 +242,7 @@ var ProcessWireAdmin = {
$a.addClass('hover');
$ul.show();
$ul.trigger('pw-show-dropdown', [ $ul ]);
$ul.data('pw-dropdown-last-offset', offset);
}, delay);
@@ -254,7 +258,10 @@ var ProcessWireAdmin = {
if(timeout) clearTimeout(timeout);
setTimeout(function() {
if($ul.filter(":hover").length) return;
// filter(':hover') does not work in jQuery 3.x
// if($ul.filter(":hover").length) return;
var hovered = $ul.filter(function() { return $(this).is(':hover'); });
if(hovered.length) return;
$ul.find('ul').hide();
$ul.hide();
$a.removeClass('hover');
@@ -433,6 +440,10 @@ var ProcessWireAdmin = {
});
$(".pw-dropdown-toggle").each(setupDropdown);
$('.InputfieldForm').on('reloaded', function() {
$('.pw-dropdown-toggle:not(.pw-dropdown-init)').each(setupDropdown);
});
$(document)
.on('mousedown', '.pw-dropdown-toggle-click', mouseenterDropdownToggle)

File diff suppressed because one or more lines are too long