From 323c2f82866a6df0c461fec9dae18eaa017f789e Mon Sep 17 00:00:00 2001 From: Ad Schellevis Date: Sun, 24 May 2020 15:19:29 +0200 Subject: [PATCH] firewall: categories typeahead issue, closes https://github.com/opnsense/core/issues/4126 Although this isn't a great fix, we can prevent forking https://github.com/bassjobsen/Bootstrap-3-Typeahead for now and hope someone fixes the relative issue some day. When Typeahead inputs aren't in relative containers, postition() returns the correct values, which is why our quick menu search likely still works. --- src/www/firewall_rules_edit.php | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/www/firewall_rules_edit.php b/src/www/firewall_rules_edit.php index 1271e2424..0d1eb834c 100644 --- a/src/www/firewall_rules_edit.php +++ b/src/www/firewall_rules_edit.php @@ -678,6 +678,59 @@ include("head.inc"); $("#category").typeahead({ source: categories }); + + /*************************************************************************************************************** + * typeahead seems to be broken since jQuery 3.3.0 + * temporary fix to make sure "position()" returns the expected values as suggested in: + * https://github.com/bassjobsen/Bootstrap-3-Typeahead/issues/384 + * + * When being used outside position: relative items, the plugin still seems to be working + * (which is likely why the menu quick search isn't affected). + ***************************************************************************************************************/ + $.fn.position = function() { + if ( !this[ 0 ] ) { + return; + } + + var offsetParent, offset, doc, + elem = this[ 0 ], + parentOffset = { top: 0, left: 0 }; + + // position:fixed elements are offset from the viewport, which itself always has zero offset + if ( jQuery.css( elem, "position" ) === "fixed" ) { + + // Assume position:fixed implies availability of getBoundingClientRect + offset = elem.getBoundingClientRect(); + + } else { + offset = this.offset(); + + // Account for the *real* offset parent, which can be the document or its root element + // when a statically positioned element is identified + doc = elem.ownerDocument; + offsetParent = elem.offsetParent || doc.documentElement; + while ( offsetParent && + offsetParent !== doc && + ( offsetParent !== doc.body && offsetParent !== doc.documentElement ) && + jQuery.css( offsetParent, "position" ) === "static" ) { + + offsetParent = offsetParent.parentNode; + } + if ( offsetParent && offsetParent !== elem && offsetParent.nodeType === 1 ) { + + // Incorporate borders into its offset, since they are outside its content origin + parentOffset = jQuery( offsetParent ).offset(); + parentOffset.top += jQuery.css( offsetParent, "borderTopWidth", true ); + parentOffset.left += jQuery.css( offsetParent, "borderLeftWidth", true ); + } + } + + // Subtract parent offsets and element margins + return { + top: offset.top - parentOffset.top - jQuery.css( elem, "marginTop", true ), + left: offset.left - parentOffset.left - jQuery.css( elem, "marginLeft", true ) + }; + }; });