Mailing List Archive

rt branch 6.0/htmx created. rt-5.0.5-231-gc51bd7d189
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "rt".

The branch, 6.0/htmx has been created
at c51bd7d18991ccabfd37c1f1cc4d98a28f4f86ca (commit)

- Log -----------------------------------------------------------------
commit c51bd7d18991ccabfd37c1f1cc4d98a28f4f86ca
Author: sunnavy <sunnavy@bestpractical.com>
Date: Fri Mar 1 15:54:17 2024 -0500

Disable htmx boost requests for Prefs page as it may modify theme

diff --git a/share/html/Prefs/Other.html b/share/html/Prefs/Other.html
index 19818376bf..b9b8a8da72 100644
--- a/share/html/Prefs/Other.html
+++ b/share/html/Prefs/Other.html
@@ -49,7 +49,7 @@
<& /Elements/Tabs &>
<& /Elements/ListActions, actions => \@results &>

-<form method="post" action="Other.html" name="ModifyPreferences" id="ModifyPreferences">
+<form hx-boost="false" method="post" action="Other.html" name="ModifyPreferences" id="ModifyPreferences">
% foreach my $section( RT->Config->Sections ) {
<&|/Widgets/TitleBox, title => loc( $section ) &>
% foreach my $option( RT->Config->Options( Section => $section ) ) {

commit 68baba607c517341512f5139e9923f6af9ecb2cc
Author: sunnavy <sunnavy@bestpractical.com>
Date: Thu Feb 29 15:47:35 2024 -0500

Dynamically refresh recently viewed tickets on hover

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 5cdd7f3d2c..1f6031ee44 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -76,7 +76,16 @@ sub BuildMainNav {
$tickets->child( simple => title => loc('Simple Search'), path => "/Search/Simple.html" );
$tickets->child( new => title => loc('New Search'), path => "/Search/Build.html?NewQuery=1" );

- my $recents = $tickets->child( recent => title => loc('Recently Viewed'));
+ my $recents = $tickets->child(
+ recent => title => loc('Recently Viewed'),
+ attributes => {
+ 'hx-trigger' => 'mouseover queue:none',
+ 'hx-target' => 'next ul',
+ 'hx-swap' => 'outerHTML',
+ 'hx-get' => RT->Config->Get('WebPath') . '/Views/RecentlyViewedTickets',
+ }
+ );
+
for my $ticket ( $current_user->RecentlyViewedTickets ) {
my $title = $ticket->{subject} || loc( "(No subject)" );
if ( length $title > 50 ) {
diff --git a/share/html/Views/RecentlyViewedTickets b/share/html/Views/RecentlyViewedTickets
new file mode 100644
index 0000000000..b8379f9051
--- /dev/null
+++ b/share/html/Views/RecentlyViewedTickets
@@ -0,0 +1,66 @@
+%# BEGIN BPS TAGGED BLOCK {{{
+%#
+%# COPYRIGHT:
+%#
+%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
+%# <sales@bestpractical.com>
+%#
+%# (Except where explicitly superseded by other copyright notices)
+%#
+%#
+%# LICENSE:
+%#
+%# This work is made available to you under the terms of Version 2 of
+%# the GNU General Public License. A copy of that license should have
+%# been provided with this software, but in any event can be snarfed
+%# from www.gnu.org.
+%#
+%# This work is distributed in the hope that it will be useful, but
+%# WITHOUT ANY WARRANTY; without even the implied warranty of
+%# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+%# General Public License for more details.
+%#
+%# You should have received a copy of the GNU General Public License
+%# along with this program; if not, write to the Free Software
+%# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+%# 02110-1301 or visit their web page on the internet at
+%# http://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
+%#
+%#
+%# CONTRIBUTION SUBMISSION POLICY:
+%#
+%# (The following paragraph is not intended to limit the rights granted
+%# to you to modify and distribute this software under the terms of
+%# the GNU General Public License and is only of importance to you if
+%# you choose to contribute your changes and enhancements to the
+%# community by submitting them to Best Practical Solutions, LLC.)
+%#
+%# By intentionally submitting any modifications, corrections or
+%# derivatives to this work, or any other work intended for use with
+%# Request Tracker, to Best Practical Solutions, LLC, you confirm that
+%# you are the copyright holder for those contributions and you grant
+%# Best Practical Solutions, LLC a nonexclusive, worldwide, irrevocable,
+%# royalty-free, perpetual, license to use, copy, create derivative
+%# works based on those contributions, and sublicense and distribute
+%# those contributions and any derivatives thereof.
+%#
+%# END BPS TAGGED BLOCK }}}
+<ul>
+% for my $ticket ( $session{CurrentUser}->RecentlyViewedTickets ) {
+% my $title = $ticket->{subject} || loc( "(No subject)" );
+% if ( length $title > 50 ) {
+% $title = substr($title, 0, 47);
+% $title =~ s/\s+$//;
+% $title .= "...";
+% }
+% $title = "#$ticket->{id}: " . $title;
+ <li id="li-search-tickets-recent-<% $ticket->{id} %>">
+ <a id="search-tickets-recent-<% $ticket->{id} %>" href="<% RT->Config->Get('WebPath') %>/Ticket/Display.html?id=<% $ticket->{id} %>"><% $title %></a>
+ </li>
+% }
+</ul>
+<%INIT>
+return unless $session{CurrentUser}->Id;
+
+
+</%INIT>

commit 453b2476a5a514b7998a2c2fc4d38505741b5e7f
Author: sunnavy <sunnavy@bestpractical.com>
Date: Wed Feb 28 15:08:38 2024 -0500

Show spinner for htmx boost requests

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 78eb0c28ac..ac3a223432 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -123,6 +123,11 @@
% if ($ShowTitle) {
<div id="header"><h1><% $Title %></h1></div>
% }
+
+<div id="hx-boost-spinner" class="d-none">
+ <& /Widgets/Spinner &>
+</div>
+
<%INIT>
my $lang = 'en';
$lang = $session{'CurrentUser'}->LanguageHandle->language_tag
diff --git a/share/static/css/elevator-light/misc.css b/share/static/css/elevator-light/misc.css
index 6ed4dd5eb1..4bb6645a20 100644
--- a/share/static/css/elevator-light/misc.css
+++ b/share/static/css/elevator-light/misc.css
@@ -183,3 +183,15 @@ ul.ui-autocomplete {
.modal.search-results-filter .modal-dialog {
margin: 0;
}
+
+#hx-boost-spinner {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ height: 100vh;
+ width: 100%;
+ position: fixed;
+ top: 0;
+ left: 0;
+ z-index: 9999;
+}
diff --git a/share/static/js/util.js b/share/static/js/util.js
index 5040261cea..b09bad1110 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1039,6 +1039,18 @@ htmx.onLoad(function(elt) {
}
}
});
+
+ document.body.addEventListener('htmx:beforeRequest', function(evt) {
+ if ( evt.detail.boosted ) {
+ document.getElementById('hx-boost-spinner').classList.remove('d-none');
+ }
+ });
+
+ document.body.addEventListener('htmx:afterRequest', function(evt) {
+ if ( evt.detail.boosted ) {
+ document.getElementById('hx-boost-spinner').classList.add('d-none');
+ }
+ });
});

function filterSearchResults (type) {

commit f12c9ea0788dafa0d4e790eb1b6ec84991697c41
Author: sunnavy <sunnavy@bestpractical.com>
Date: Wed Feb 28 08:38:31 2024 -0500

Disable htmx boost requests for DashboardsInMenu as it modifies top menu

diff --git a/share/html/Prefs/DashboardsInMenu.html b/share/html/Prefs/DashboardsInMenu.html
index bf75385a6a..08c1b16f2e 100644
--- a/share/html/Prefs/DashboardsInMenu.html
+++ b/share/html/Prefs/DashboardsInMenu.html
@@ -50,7 +50,7 @@
&>
<& /Elements/ListActions, actions => \@results &>

-<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
+<form hx-boost="false" method="post" name="UpdateSearches" class="mx-auto max-width-lg">
<& /Widgets/SearchSelection,
pane_name => { dashboard => loc('Dashboards in menu') },
sections => [.{
@@ -68,13 +68,13 @@

<&|/Widgets/TitleBox, title => loc("Reset dashboards in menu"), class => "mx-auto max-width-lg" &>
<div class="mt-3 mb-1 ms-3">
- <form method="post" action="DashboardsInMenu.html">
+ <form hx-boost="false" method="post" action="DashboardsInMenu.html">
<input type="submit" name="ResetDashboards" class="button form-control btn btn-primary" value="<% loc('Reset dashboards to default') %>">
</form>
</div>
</&>

-<form method="post" name="UpdateSearches" class="mx-auto max-width-lg">
+<form hx-boost="false" method="post" name="UpdateSearches" class="mx-auto max-width-lg">
<& /Widgets/SearchSelection,
pane_name => { report => loc('Reports in menu') },
sections => [.{
@@ -92,7 +92,7 @@

<&|/Widgets/TitleBox, title => loc("Reset reports in menu"), class => "mx-auto max-width-lg" &>
<div class="mt-3 mb-1 ms-3">
- <form method="post" action="DashboardsInMenu.html">
+ <form hx-boost="false" method="post" action="DashboardsInMenu.html">
<input type="submit" name="ResetReports" class="button form-control btn btn-primary" value="<% loc('Reset reports to default') %>">
</form>
</div>

commit 5f047799a8b973ca65d4a9d7a85860c9b25b0762
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 15:32:20 2024 -0500

Disable htmx boost requests for special links/forms with customized behavior

I.e. bookmark, timer, already-ajaxified forms

diff --git a/share/html/Admin/Elements/AddCustomFieldValue b/share/html/Admin/Elements/AddCustomFieldValue
index 8a1e4060ad..02e5a15cbd 100644
--- a/share/html/Admin/Elements/AddCustomFieldValue
+++ b/share/html/Admin/Elements/AddCustomFieldValue
@@ -48,7 +48,7 @@
<div class="row mt-2">
<div class="col-1"></div>
<div class="col-10">
-<form name="AddCustomFieldValue" action="Modify.html" method="post">
+<form hx-boost="false" name="AddCustomFieldValue" action="Modify.html" method="post">
<input type="hidden" class="hidden" name="id" value="<% $CustomField->id %>" />

% # we need to allow for an extra col-2 if not combobox and categories are enabled
diff --git a/share/html/Ticket/Elements/Bookmark b/share/html/Ticket/Elements/Bookmark
index 040366e6d0..0fe3768f86 100644
--- a/share/html/Ticket/Elements/Bookmark
+++ b/share/html/Ticket/Elements/Bookmark
@@ -63,7 +63,7 @@ $Toggle => 0
</%ARGS>
<span class="toggle-bookmark toggle-bookmark-<% $id %>">
% my $url = RT->Config->Get('WebPath') ."/Helpers/Toggle/TicketBookmark?id=". $id;
-<a href="<% $url %>" onclick="toggle_bookmark(<% $url |n,j %>, <% $id |n,j%>); return false;" >
+<a hx-boost="false" href="<% $url %>" onclick="toggle_bookmark(<% $url |n,j %>, <% $id |n,j%>); return false;" >
% if ( $is_bookmarked ) {
% my $alt = loc('Remove Bookmark');
<span class="fas fa-bookmark bookmark-selected" data-fa-transform="shrink-2 up-0.25" alt="<% $alt %>" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="<% $alt %>"></span>
diff --git a/share/html/Ticket/Elements/PopupTimerLink b/share/html/Ticket/Elements/PopupTimerLink
index 2f77c71f8d..2b1af3d930 100644
--- a/share/html/Ticket/Elements/PopupTimerLink
+++ b/share/html/Ticket/Elements/PopupTimerLink
@@ -52,6 +52,6 @@ $id
my $url = RT->Config->Get('WebPath') . "/Helpers/TicketTimer?id=" . $id;
my $alt = loc('Open Timer');
</%INIT>
-<a href="<% $url %>" onclick="window.open(<% $url |n,j %>, '_blank', 'height=200,width=200'); return false;" >
+<a hx-boost="false" href="<% $url %>" onclick="window.open(<% $url |n,j %>, '_blank', 'height=200,width=200'); return false;" >
<span class="far fa-clock" alt="<% $alt %>" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="<% $alt %>"></span>
</a>

commit ef9a2adc905b3b6b25b2a0712b2e9e29ac98dfcb
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 14:59:43 2024 -0500

Disable htmx boost requests for download links

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index 5b2d445447..5cdd7f3d2c 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -764,7 +764,13 @@ sub BuildPageNav {

my $more = $current_search_menu->child( more => title => loc('Feeds') );

- $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.tsv$args" );
+ $more->child(
+ spreadsheet => title => loc('Spreadsheet'),
+ path => "/Search/Results.tsv$args",
+ attributes => {
+ 'hx-boost' => 'false',
+ },
+ );

if ( $class eq 'RT::Tickets' ) {
my %rss_data
@@ -783,12 +789,25 @@ sub BuildPageNav {
$current_user->UserObj->GenerateAuthString( $short_query{sc}
|| ( $rss_data{Query} . $rss_data{Order} . $rss_data{OrderBy} ) );

- $more->child( rss => title => loc('RSS'), path => "/NoAuth/rss/$RSSPath/$RSSQueryString" );
+ $more->child(
+ rss => title => loc('RSS'),
+ path => "/NoAuth/rss/$RSSPath/$RSSQueryString",
+ attributes => {
+ 'hx-boost' => 'false',
+ },
+ );
+
my $ical_path = join '/', map $HTML::Mason::Commands::m->interp->apply_escapes( $_, 'u' ),
$current_user->UserObj->Name,
$current_user->UserObj->GenerateAuthString( $rss_data{Query} ),
$short_query{sc} ? "sc-$short_query{sc}" : $rss_data{Query};
- $more->child( ical => title => loc('iCal'), path => '/NoAuth/iCal/' . $ical_path );
+ $more->child(
+ ical => title => loc('iCal'),
+ path => '/NoAuth/iCal/' . $ical_path,
+ attributes => {
+ 'hx-boost' => 'false',
+ },
+ );

#XXX TODO better abstraction of SuperUser right check
if ( $current_user->HasRight( Right => 'SuperUser', Object => RT->System ) ) {
@@ -865,6 +884,9 @@ sub BuildPageNav {
$page->child('csv',
title => loc('Download Spreadsheet'),
path => '/Search/Results.tsv?' . QueryString(%search, Class => 'RT::Assets'),
+ attributes => {
+ 'hx-boost' => 'false',
+ },
);
} elsif ($request_path =~ m{^/Asset/Search/}) {
my %search = map @{$_},
@@ -933,7 +955,13 @@ sub BuildPageNav {
path => '/Asset/Search/Bulk.html' . $args,
);
my $more = $page->child( more => title => loc('Feeds') );
- $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.tsv$args" );
+ $more->child(
+ spreadsheet => title => loc('Spreadsheet'),
+ path => "/Search/Results.tsv$args",
+ attributes => {
+ 'hx-boost' => 'false',
+ },
+ );
}
} elsif ($request_path =~ m{^/Admin/Global/CustomFields/Catalog-Assets\.html$}) {
$page->child("create", title => loc("Create New"), path => "/Admin/CustomFields/Modify.html?Create=1;LookupType=" . RT::Asset->CustomFieldLookupType);
diff --git a/share/html/Admin/Tools/Shredder/Elements/DumpFileLink b/share/html/Admin/Tools/Shredder/Elements/DumpFileLink
index 7bfa55a161..683e6cf53e 100644
--- a/share/html/Admin/Tools/Shredder/Elements/DumpFileLink
+++ b/share/html/Admin/Tools/Shredder/Elements/DumpFileLink
@@ -46,7 +46,7 @@
%#
%# END BPS TAGGED BLOCK }}}
<div id="shredder-dump-file-link" class="shredder-help">
-<a href="<% RT->Config->Get('WebPath') %>/Admin/Tools/Shredder/Dumps/<% $File %>"><% loc('Download dumpfile') %></a>
+<a hx-boost="false" href="<% RT->Config->Get('WebPath') %>/Admin/Tools/Shredder/Dumps/<% $File %>"><% loc('Download dumpfile') %></a>
</div>
<%ARGS>
$File => ''
diff --git a/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment b/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment
index 1d6bce28fd..4e9deb47ac 100644
--- a/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment
+++ b/share/html/Admin/Tools/Shredder/Elements/Object/RT--Attachment
@@ -49,6 +49,6 @@
$Object => undef
</%ARGS>
% my $name = (defined $Object->Filename and length $Object->Filename) ? $Object->Filename : loc("(no value)");
-<a href="<% RT->Config->Get('WebPath') %>/Ticket/Attachment/<% $Object->TransactionId %>/<% $Object->id %>/<% $Object->Filename |un %>">
+<a hx-boost="false" href="<% RT->Config->Get('WebPath') %>/Ticket/Attachment/<% $Object->TransactionId %>/<% $Object->id %>/<% $Object->Filename |un %>">
<% loc('Attachment') %>(<% loc('id') %>:<% $Object->id %>, <% loc('Filename') %>: <% $name %>)
</a>
diff --git a/share/html/Elements/CryptStatus b/share/html/Elements/CryptStatus
index b81c769590..2903f263ea 100644
--- a/share/html/Elements/CryptStatus
+++ b/share/html/Elements/CryptStatus
@@ -114,11 +114,11 @@ sub KeyDownloadLink {
my $txt = '';
if ($protocol eq 'GnuPG') {
if ($line->{Fingerprint} && $line->{Fingerprint} !~ /[^0-9A-F]/i) {
- $txt = '<a href="' . RT->Config->Get('WebPath') . '/Crypt/GetGPGPubkey.html?Fingerprint=' . $line->{Fingerprint} . '"> ' . loc('(Download Public Key)') . '</a>';
+ $txt = '<a hx-boost="false" href="' . RT->Config->Get('WebPath') . '/Crypt/GetGPGPubkey.html?Fingerprint=' . $line->{Fingerprint} . '"> ' . loc('(Download Public Key)') . '</a>';
}
} elsif ($protocol eq 'SMIME') {
if ($Message && $Message->TransactionObj && $Message->TransactionObj->Creator) {
- $txt = '<a href="' . RT->Config->Get('WebPath') . '/Crypt/GetSMIMECert.html?Transaction=' . $Message->TransactionObj->Id . '"> ' . loc('(Download S/MIME Certificate)') . '</a>';
+ $txt = '<a hx-boost="false" href="' . RT->Config->Get('WebPath') . '/Crypt/GetSMIMECert.html?Transaction=' . $Message->TransactionObj->Id . '"> ' . loc('(Download S/MIME Certificate)') . '</a>';
}
}

diff --git a/share/html/Elements/EditCustomFieldBinary b/share/html/Elements/EditCustomFieldBinary
index f401c2bf46..2be54b9ab5 100644
--- a/share/html/Elements/EditCustomFieldBinary
+++ b/share/html/Elements/EditCustomFieldBinary
@@ -51,9 +51,9 @@
<input type="checkbox" id="<% $delete_name . $value->id %>" name="<%$delete_name%>" class="form-check-input CF-<%$CustomField->id%>-Edit" value="<% $value->Id %>">
<label class="form-check-label" for="<% $delete_name . $value->id %>">
% if (my $url = RT->System->ExternalStorageURLFor($value)) {
-<a href="<%$url%>">
+<a hx-boost="false" href="<%$url%>">
% } else {
-<a href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>">
+<a hx-boost="false" href="<%RT->Config->Get('WebPath')%>/Download/CustomFieldValue/<% $value->Id %>/<% $value->Content |un %>">
% }

<% $value->Content %>
diff --git a/share/html/Ticket/Elements/ShowAttachments b/share/html/Ticket/Elements/ShowAttachments
index 20c64a8f5a..2f6e5f4927 100644
--- a/share/html/Ticket/Elements/ShowAttachments
+++ b/share/html/Ticket/Elements/ShowAttachments
@@ -73,9 +73,9 @@
<label <% $Selectable ? 'class="form-check-label"' : '' |n%> for="AttachExisting-<% $rev->Id %>">
<span class="revision">
% if (my $url = RT->System->ExternalStorageURLFor($rev)) {
-<a href="<%$url%>">
+<a hx-boost="false" href="<%$url%>">
% } else {
-<a href="<%RT->Config->Get('WebPath')%>/<% $DisplayPath %>/Attachment/<%$rev->TransactionId%>/<%$rev->Id%>/<%$rev->Filename | un %>">
+<a hx-boost="false" href="<%RT->Config->Get('WebPath')%>/<% $DisplayPath %>/Attachment/<%$rev->TransactionId%>/<%$rev->Id%>/<%$rev->Filename | un %>">
% }
% my $desc = loc("[_1] ([_2]) by [_3]", $rev->CreatedAsString, $rev->FriendlyContentLength, $m->scomp('/Elements/ShowUser', User => $rev->CreatorObj));
<% $desc |n%>
diff --git a/share/html/User/Elements/RelatedData b/share/html/User/Elements/RelatedData
index 7a15f8e821..63c32530ca 100644
--- a/share/html/User/Elements/RelatedData
+++ b/share/html/User/Elements/RelatedData
@@ -55,7 +55,7 @@
<div class="download-user-data-buttons row mt-2">
<div class="col-4">
<div>
- <a class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/User/RelatedData.tsv?Type=User&id=<% $UserObj->id %>"><% $UserDataButton %></a>
+ <a hx-boost="false" class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/User/RelatedData.tsv?Type=User&id=<% $UserObj->id %>"><% $UserDataButton %></a>
</div>
<div>
<i class="label"><&|/l&>Core user data</&></i>
@@ -63,7 +63,7 @@
</div>
<div class="col-4">
<div>
- <a class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/Search/Results.tsv?UserData=1&Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>"><% $UserTicketsButton %></a>
+ <a hx-boost="false" class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/Search/Results.tsv?UserData=1&Query=Requestor.id=<% $UserObj->id %>&Format=<% $Format | un %>"><% $UserTicketsButton %></a>
</div>
<div>
<i class="label"><&|/l&>Tickets with this user as a requestor</&></i>
@@ -71,7 +71,7 @@
</div>
<div class="col-4">
<div>
- <a class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/User/RelatedData.tsv?Type=Transaction&id=<% $UserObj->id %>"><% $UserTxnButton %></a>
+ <a hx-boost="false" class="button btn btn-primary" href="<%RT->Config->Get('WebPath')%>/User/RelatedData.tsv?Type=Transaction&id=<% $UserObj->id %>"><% $UserTxnButton %></a>
</div>
<div>
<i class="label"><&|/l&>Ticket transactions this user created</&></i>

commit 6192950b6df2eb22145eaabe8454e8bd94e78497
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 20:13:11 2024 -0500

Protect RequestENV from fake requests in dashboard mailer

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index e0c9177c0d..7b8afdba6e 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -2101,8 +2101,15 @@ sub GetCustomFieldInputNamePrefix {

sub RequestENV {
my $name = shift;
- my $env = $HTML::Mason::Commands::m->cgi_object->env;
- return $name ? $env->{$name} : $env;
+
+ my $value;
+ # For fake requests like dashboard mailer, the cgi_object call might die.
+ eval {
+ my $env = $HTML::Mason::Commands::m->cgi_object->env;
+ $value = $name ? $env->{$name} : $env;
+ };
+
+ return $value;
}

sub ClientIsIE {

commit 662316b66f5ddf5dda22250776b0b542b80dbd76
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 14:55:14 2024 -0500

Skip generating unused tags in head for htmx boosted requests

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index a066a84e47..78eb0c28ac 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -55,6 +55,8 @@
<title><%$Title%></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- The X-UA-Compatible <meta> tag above must be very early in <head> -->
+% if ( !RT::Interface::Web::RequestENV('HTTP_HX_BOOSTED') ) {
+
<& JavascriptConfig &>

% for my $cssfile ( @css_files ) {
@@ -92,6 +94,7 @@

% $m->callback( CallbackName => 'EndOfHead', ARGSRef => \%ARGS );

+% }
</head>
<body hx-boost="true" class="<% join( ' ',@{$ARGS{'BodyClass'}}, GetStylesheet() =~ /-dark$/ ? 'darkmode' : ()) %>" <% $id && qq[id="comp-$id"] |n %>>
% if ( $session{CurrentUser} && $session{CurrentUser}->Id && Menu() && !RT::Interface::Web::RequestENV('HTTP_HX_BOOSTED') ) {

commit cdb13d23c44cac64f21a45ac196023a1225b508e
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 14:39:15 2024 -0500

Move refresh meta to body for htmx boosted requests

Only title in head will be updated for boosted htmx requests.

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 7b2b999f80..a066a84e47 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -55,12 +55,6 @@
<title><%$Title%></title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<!-- The X-UA-Compatible <meta> tag above must be very early in <head> -->
-
-% if ($Refresh && $Refresh =~ /^(\d+)/ && $1 > 0) {
-% my $URL = $m->notes->{RefreshURL}; $URL = $URL ? ";URL=$URL" : "";
- <meta http-equiv="refresh" content="<% "$1$URL" %>" />
-% }
-
<& JavascriptConfig &>

% for my $cssfile ( @css_files ) {
@@ -105,6 +99,12 @@
% }

<div class="main-container">
+
+% if ($Refresh && $Refresh =~ /^(\d+)/ && $1 > 0) {
+% my $URL = $m->notes->{RefreshURL}; $URL = $URL ? ";URL=$URL" : "";
+ <meta http-equiv="refresh" content="<% "$1$URL" %>" />
+% }
+
% # The close div for this is in PageLayout right before the rt body div
% if ( $ShowBar || $ShowTitle ) {
<div id='rt-header-container'>

commit 6b3600c1495d87cd155dd0324d79cc1002d5855a
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 13:49:30 2024 -0500

Disable htmx boost requests for Login

The initial reason is that htmx we cache a few things among boost requests
including top menu and a few state initialized in head tag, which login page
lacks.

diff --git a/share/html/Elements/Login b/share/html/Elements/Login
index ac4aeb4521..e785ba903d 100644
--- a/share/html/Elements/Login
+++ b/share/html/Elements/Login
@@ -66,7 +66,7 @@
<& LoginRedirectWarning, %ARGS &>

% unless (RT->Config->Get('WebRemoteUserAuth') and !RT->Config->Get('WebFallbackToRTLogin')) {
-<form id="login" name="login" method="post" action="<% RT->Config->Get('WebPath') %>/NoAuth/Login.html">
+<form hx-boost="false" id="login" name="login" method="post" action="<% RT->Config->Get('WebPath') %>/NoAuth/Login.html">

<&| /Elements/LabeledValue, Label => loc("Username") &>
<input class="form-control" type="text" name="user" value="<%$user%>" id="user" autocapitalize="off" />

commit f49c1c9c1f79cf2ed02b93d52e2a8c7c49c7bcc6
Author: sunnavy <sunnavy@bestpractical.com>
Date: Fri Mar 1 15:35:10 2024 -0500

Skip generating top menu for htmx boost requests

Top menu is not supposed to change generally and this commit helps
performance especially for RT with complicated ACL setup.

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index ad7257efbe..7b2b999f80 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -100,7 +100,9 @@

</head>
<body hx-boost="true" class="<% join( ' ',@{$ARGS{'BodyClass'}}, GetStylesheet() =~ /-dark$/ ? 'darkmode' : ()) %>" <% $id && qq[id="comp-$id"] |n %>>
+% if ( $session{CurrentUser} && $session{CurrentUser}->Id && Menu() && !RT::Interface::Web::RequestENV('HTTP_HX_BOOSTED') ) {
<div id="main-navigation"><& /Elements/Menu, menu => Menu(), id => 'app-nav' &></div>
+% }

<div class="main-container">
@@ -155,16 +157,24 @@ if (RT->Config->Get("UseSideBySideLayout", $session{'CurrentUser'})) {
push @{$ARGS{'BodyClass'}}, 'sidebyside';
}

-if ( my $top = Menu() ) {
- my $request_path = $HTML::Mason::Commands::r->path_info;
- $request_path =~ s!/{2,}!/!g;
-
- require RT::Interface::Web::MenuBuilder;
- if ( $request_path =~ m{^/SelfService/} ) {
- RT::Interface::Web::MenuBuilder::BuildSelfServiceMainNav( $top );
+# If user just logged out, we should refresh the whole body.
+if ( $session{CurrentUser} && $session{CurrentUser}->Id ) {
+ if ( RT::Interface::Web::RequestENV('HTTP_HX_BOOSTED') ) {
+ $r->headers_out->{'HX-Reselect'} = '.main-container';
+ $r->headers_out->{'HX-Retarget'} = '.main-container';
+ $r->headers_out->{'HX-Reswap'} = 'outerHTML';
}
- else {
- RT::Interface::Web::MenuBuilder::BuildMainNav( $top );
+ elsif ( my $top = Menu() ) {
+ my $request_path = $HTML::Mason::Commands::r->path_info;
+ $request_path =~ s!/{2,}!/!g;
+
+ require RT::Interface::Web::MenuBuilder;
+ if ( $request_path =~ m{^/SelfService/} ) {
+ RT::Interface::Web::MenuBuilder::BuildSelfServiceMainNav( Menu() );
+ }
+ else {
+ RT::Interface::Web::MenuBuilder::BuildMainNav( Menu() );
+ }
}
}
</%INIT>

commit 3c713c4b16d55ece03605595d4e22b21470806f9
Author: sunnavy <sunnavy@bestpractical.com>
Date: Mon Feb 26 15:57:14 2024 -0500

Separate top menu code from others

Top menu is not supposed to change among pages, this commit moves its build
code from other nav code so we can skip it for htmx boost requests.

Previously the current_search submenu in top menu varied on different pages,
this commit drops it. Users can still get current search from the page menu
"Return to Search Results".

diff --git a/lib/RT/Interface/Web/MenuBuilder.pm b/lib/RT/Interface/Web/MenuBuilder.pm
index b3b0e8cd33..5b2d445447 100644
--- a/lib/RT/Interface/Web/MenuBuilder.pm
+++ b/lib/RT/Interface/Web/MenuBuilder.pm
@@ -62,32 +62,10 @@ sub QueryString { HTML::Mason::Commands::QueryString( @_ ); }
sub ShortenSearchQuery { HTML::Mason::Commands::ShortenSearchQuery( @_ ); }

sub BuildMainNav {
- my $request_path = shift;
- my $top = shift;
- my $widgets = shift;
- my $page = shift;
-
- my %args = ( @_ );
-
- my $query_string = $args{QueryString};
- my $query_args = $args{QueryArgs};
+ my $top = shift;

my $current_user = $HTML::Mason::Commands::session{CurrentUser};

- if ($request_path =~ m{^/Asset/}) {
- if (!RT->Config->Get('AssetHideSimpleSearch')) {
- $widgets->child( asset_search => raw_html => $HTML::Mason::Commands::m->scomp('/Asset/Elements/Search') );
- }
- $widgets->child( create_asset => raw_html => $HTML::Mason::Commands::m->scomp('/Asset/Elements/CreateAsset') );
- }
- elsif ($request_path =~ m{^/Articles/}) {
- $widgets->child( article_search => raw_html => $HTML::Mason::Commands::m->scomp('/Articles/Elements/GotoArticle') );
- $widgets->child( create_article => raw_html => $HTML::Mason::Commands::m->scomp('/Articles/Elements/CreateArticleButton') );
- } else {
- $widgets->child( simple_search => raw_html => $HTML::Mason::Commands::m->scomp('SimpleSearch', Placeholder => loc('Search Tickets')) );
- $widgets->child( create_ticket => raw_html => $HTML::Mason::Commands::m->scomp('CreateTicket') );
- }
-
my $home = $top->child( home => title => loc('Homepage'), path => '/' );
$home->child( create_ticket => title => loc("Create Ticket"),
path => "/Ticket/Create.html" );
@@ -121,16 +99,14 @@ sub BuildMainNav {
description => 'Group search'
);

- my $search_assets;
if ($HTML::Mason::Commands::session{CurrentUser}->HasRight( Right => 'ShowAssetsMenu', Object => RT->System )) {
- $search_assets = $search->child( assets => title => loc("Assets"), path => "/Search/Build.html?Class=RT::Assets" );
+ my $search_assets = $search->child( assets => title => loc("Assets"), path => "/Search/Build.html?Class=RT::Assets" );
if (!RT->Config->Get('AssetHideSimpleSearch')) {
$search_assets->child("asset_simple", title => loc("Simple Search"), path => "/Asset/Search/");
}
$search_assets->child("assetsql", title => loc("New Search"), path => "/Search/Build.html?Class=RT::Assets;NewQuery=1");
}

-
my $txns = $search->child( transactions => title => loc('Transactions'), path => '/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket' );
my $txns_tickets = $txns->child( tickets => title => loc('Tickets'), path => "/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket" );
$txns_tickets->child( new => title => loc('New Search'), path => "/Search/Build.html?Class=RT::Transactions;ObjectType=RT::Ticket;NewQuery=1" );
@@ -277,9 +253,9 @@ sub BuildMainNav {
path => '/Tools/PreviewSearches.html',
);

- if ( $current_user->HasRight( Right => 'ShowConfigTab', Object => RT->System ) )
+ if ( $top && $current_user->HasRight( Right => 'ShowConfigTab', Object => RT->System ) )
{
- _BuildAdminMenu( $request_path, $top, $widgets, $page, %args );
+ _BuildAdminTopMenu( $top );
}

my $username = '<span class="current-user">'
@@ -324,6 +300,27 @@ sub BuildMainNav {

}

+ }
+ if ( $current_user->Name ) {
+ $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
+ }
+}
+
+sub BuildPageNav {
+ my $request_path = shift;
+ my $widgets = shift;
+ my $page = shift;
+
+ my %args = ( @_ );
+
+ my $query_string = $args{QueryString};
+ my $query_args = $args{QueryArgs};
+
+ my $current_user = $HTML::Mason::Commands::session{CurrentUser};
+
+ _BuildAdminPageMenu( $request_path, $widgets, $page, %args );
+
+ if ( $current_user->UserObj && $current_user->HasRight( Right => 'ModifySelf', Object => RT->System ) ) {
if ( $request_path =~ qr{/Prefs/(?:SearchOptions|CustomDateRanges)\.html} ) {
$page->child(
search_options => title => loc('Search Preferences'),
@@ -341,9 +338,21 @@ sub BuildMainNav {
);
}
}
- if ( $current_user->Name ) {
- $about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
+
+ if ($request_path =~ m{^/Asset/}) {
+ if (!RT->Config->Get('AssetHideSimpleSearch')) {
+ $widgets->child( asset_search => raw_html => $HTML::Mason::Commands::m->scomp('/Asset/Elements/Search') );
+ }
+ $widgets->child( create_asset => raw_html => $HTML::Mason::Commands::m->scomp('/Asset/Elements/CreateAsset') );
+ }
+ elsif ($request_path =~ m{^/Articles/}) {
+ $widgets->child( article_search => raw_html => $HTML::Mason::Commands::m->scomp('/Articles/Elements/GotoArticle') );
+ $widgets->child( create_article => raw_html => $HTML::Mason::Commands::m->scomp('/Articles/Elements/CreateArticleButton') );
+ } else {
+ $widgets->child( simple_search => raw_html => $HTML::Mason::Commands::m->scomp('SimpleSearch', Placeholder => loc('Search Tickets')) );
+ $widgets->child( create_ticket => raw_html => $HTML::Mason::Commands::m->scomp('CreateTicket') );
}
+
if ( $request_path =~ m{^/Dashboards/(\d+)?}) {
if ( my $id = ( $1 || $HTML::Mason::Commands::DECODED_ARGS->{'id'} ) ) {
my $obj = RT::Dashboard->new( $current_user );
@@ -585,23 +594,12 @@ sub BuildMainNav {
# identifying if it's from simple search or SQL search. For now,
# show "Current Search" only if asset simple search is disabled.

- || ( $search_assets && $request_path =~ m{^/Asset/(?!Search/)} && RT->Config->Get('AssetHideSimpleSearch') )
+ || ( $current_user->HasRight( Right => 'ShowAssetsMenu', Object => RT->System ) && $request_path =~ m{^/Asset/(?!Search/)} && RT->Config->Get('AssetHideSimpleSearch') )
)
{
my $class = $HTML::Mason::Commands::DECODED_ARGS->{Class}
|| ( $request_path =~ m{^/(Transaction|Ticket|Asset)/} ? "RT::$1s" : 'RT::Tickets' );

- my $search;
- if ( $class eq 'RT::Tickets' ) {
- $search = $top->child('search')->child('tickets');
- }
- elsif ( $class eq 'RT::Assets' ) {
- $search = $search_assets;
- }
- else {
- $search = $txns_tickets;
- }
-
my $hash_name = join '-', 'CurrentSearchHash', $class,
$HTML::Mason::Commands::DECODED_ARGS->{ObjectType} || ( $class eq 'RT::Transactions' ? 'RT::Ticket' : () );
my $current_search = $HTML::Mason::Commands::session{$hash_name} || {};
@@ -681,9 +679,6 @@ sub BuildMainNav {
|| $class eq 'RT::Transactions' && $request_path =~ m{^/Transaction}
|| $class eq 'RT::Assets' && $request_path =~ m{^/Asset/(?!Search/)} )
{
- $current_search_menu = $search->child( current_search => title => loc('Current Search') );
- $current_search_menu->path("/Search/Results.html$args") if $has_query;
-
if ( $search_results_page_menu && $has_query ) {
$search_results_page_menu->child(
current_search => title => q{<span class="fas fa-list"></span>},
@@ -731,84 +726,87 @@ sub BuildMainNav {
}
}

- $current_search_menu->child( edit_search =>
- title => loc('Edit Search'), sort_order => 1, path => "/Search/Build.html$args" );
- if ( $current_user->HasRight( Right => 'ShowSearchAdvanced', Object => RT->System ) ) {
- $current_search_menu->child( advanced => title => loc('Advanced'), path => "/Search/Edit.html$args" );
- }
- if ($has_query) {
- my $result_page = $HTML::Mason::Commands::DECODED_ARGS->{ResultPage};
- if ( $result_page ) {
- if ( my $web_path = RT->Config->Get('WebPath') ) {
- $result_page =~ s!^$web_path!!;
- }
- }
- else {
- $result_page = '/Search/Results.html';
+ if ( $current_search_menu ) {
+
+ $current_search_menu->child( edit_search =>
+ title => loc('Edit Search'), sort_order => 1, path => "/Search/Build.html$args" );
+ if ( $current_user->HasRight( Right => 'ShowSearchAdvanced', Object => RT->System ) ) {
+ $current_search_menu->child( advanced => title => loc('Advanced'), path => "/Search/Edit.html$args" );
}
+ if ($has_query) {
+ my $result_page = $HTML::Mason::Commands::DECODED_ARGS->{ResultPage};
+ if ( $result_page ) {
+ if ( my $web_path = RT->Config->Get('WebPath') ) {
+ $result_page =~ s!^$web_path!!;
+ }
+ }
+ else {
+ $result_page = '/Search/Results.html';
+ }

- $current_search_menu->child( results => title => loc('Show Results'), path => "$result_page$args" );
- }
+ $current_search_menu->child( results => title => loc('Show Results'), path => "$result_page$args" );
+ }

- if ( $has_query ) {
- if ( $class eq 'RT::Tickets' ) {
- if ( $current_user->HasRight( Right => 'ShowSearchBulkUpdate', Object => RT->System ) ) {
- $current_search_menu->child( bulk => title => loc('Bulk Update'), path => "/Search/Bulk.html$args" );
+ if ( $has_query ) {
+ if ( $class eq 'RT::Tickets' ) {
+ if ( $current_user->HasRight( Right => 'ShowSearchBulkUpdate', Object => RT->System ) ) {
+ $current_search_menu->child( bulk => title => loc('Bulk Update'), path => "/Search/Bulk.html$args" );
+ }
+ $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
+ }
+ elsif ( $class eq 'RT::Assets' ) {
+ $current_search_menu->child( bulk => title => loc('Bulk Update'), path => "/Asset/Search/Bulk.html$args" );
+ $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
+ }
+ elsif ( $class eq 'RT::Transactions' ) {
+ $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
}
- $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
- }
- elsif ( $class eq 'RT::Assets' ) {
- $current_search_menu->child( bulk => title => loc('Bulk Update'), path => "/Asset/Search/Bulk.html$args" );
- $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
- }
- elsif ( $class eq 'RT::Transactions' ) {
- $current_search_menu->child( chart => title => loc('Chart'), path => "/Search/Chart.html$args" );
- }

- my $more = $current_search_menu->child( more => title => loc('Feeds') );
+ my $more = $current_search_menu->child( more => title => loc('Feeds') );

- $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.tsv$args" );
+ $more->child( spreadsheet => title => loc('Spreadsheet'), path => "/Search/Results.tsv$args" );

- if ( $class eq 'RT::Tickets' ) {
- my %rss_data
- = map { $_ => $query_args->{$_} || $fallback_query_args{$_} || '' } qw(Query Order OrderBy);
- my $RSSQueryString = "?"
- . QueryString(
- $short_query{sc}
- ? ( sc => $short_query{sc} )
- : ( Query => $rss_data{Query},
- Order => $rss_data{Order},
- OrderBy => $rss_data{OrderBy}
- )
- );
- my $RSSPath = join '/', map $HTML::Mason::Commands::m->interp->apply_escapes( $_, 'u' ),
- $current_user->UserObj->Name,
- $current_user->UserObj->GenerateAuthString( $short_query{sc}
- || ( $rss_data{Query} . $rss_data{Order} . $rss_data{OrderBy} ) );
-
- $more->child( rss => title => loc('RSS'), path => "/NoAuth/rss/$RSSPath/$RSSQueryString" );
- my $ical_path = join '/', map $HTML::Mason::Commands::m->interp->apply_escapes( $_, 'u' ),
- $current_user->UserObj->Name,
- $current_user->UserObj->GenerateAuthString( $rss_data{Query} ),
- $short_query{sc} ? "sc-$short_query{sc}" : $rss_data{Query};
- $more->child( ical => title => loc('iCal'), path => '/NoAuth/iCal/' . $ical_path );
-
- #XXX TODO better abstraction of SuperUser right check
- if ( $current_user->HasRight( Right => 'SuperUser', Object => RT->System ) ) {
- my $shred_args = QueryString(
- Search => 1,
- Plugin => 'Tickets',
- $short_query{sc}
+ if ( $class eq 'RT::Tickets' ) {
+ my %rss_data
+ = map { $_ => $query_args->{$_} || $fallback_query_args{$_} || '' } qw(Query Order OrderBy);
+ my $RSSQueryString = "?"
+ . QueryString(
+ $short_query{sc}
? ( sc => $short_query{sc} )
- : ( 'Tickets:query' => $rss_data{'Query'},
- 'Tickets:limit' => $query_args->{'RowsPerPage'},
- ),
- );
+ : ( Query => $rss_data{Query},
+ Order => $rss_data{Order},
+ OrderBy => $rss_data{OrderBy}
+ )
+ );
+ my $RSSPath = join '/', map $HTML::Mason::Commands::m->interp->apply_escapes( $_, 'u' ),
+ $current_user->UserObj->Name,
+ $current_user->UserObj->GenerateAuthString( $short_query{sc}
+ || ( $rss_data{Query} . $rss_data{Order} . $rss_data{OrderBy} ) );
+
+ $more->child( rss => title => loc('RSS'), path => "/NoAuth/rss/$RSSPath/$RSSQueryString" );
+ my $ical_path = join '/', map $HTML::Mason::Commands::m->interp->apply_escapes( $_, 'u' ),
+ $current_user->UserObj->Name,
+ $current_user->UserObj->GenerateAuthString( $rss_data{Query} ),
+ $short_query{sc} ? "sc-$short_query{sc}" : $rss_data{Query};
+ $more->child( ical => title => loc('iCal'), path => '/NoAuth/iCal/' . $ical_path );
+
+ #XXX TODO better abstraction of SuperUser right check
+ if ( $current_user->HasRight( Right => 'SuperUser', Object => RT->System ) ) {
+ my $shred_args = QueryString(
+ Search => 1,
+ Plugin => 'Tickets',
+ $short_query{sc}
+ ? ( sc => $short_query{sc} )
+ : ( 'Tickets:query' => $rss_data{'Query'},
+ 'Tickets:limit' => $query_args->{'RowsPerPage'},
+ ),
+ );

- $more->child(
- shredder => title => loc('Shredder'),
- path => '/Admin/Tools/Shredder/?' . $shred_args
- );
+ $more->child(
+ shredder => title => loc('Shredder'),
+ path => '/Admin/Tools/Shredder/?' . $shred_args
+ );
+ }
}
}
}
@@ -843,7 +841,7 @@ sub BuildMainNav {
}

if ($request_path =~ m{^/Asset/} and $HTML::Mason::Commands::DECODED_ARGS->{id} and $HTML::Mason::Commands::DECODED_ARGS->{id} !~ /\D/) {
- _BuildAssetMenu( $request_path, $top, $widgets, $page, %args );
+ _BuildAssetMenu( $request_path, $widgets, $page, %args );
} elsif ( $request_path =~ m{^/Asset/Search/(?:index\.html)?$}
|| ( $request_path =~ m{^/Asset/Search/Bulk\.html$} && $HTML::Mason::Commands::DECODED_ARGS->{Catalog} ) ) {
my %search = map @{$_},
@@ -1009,7 +1007,6 @@ sub BuildMainNav {

sub _BuildAssetMenu {
my $request_path = shift;
- my $top = shift;
my $widgets = shift;
my $page = shift;

@@ -1040,13 +1037,12 @@ sub _BuildAssetMenu {
);
}

- _BuildAssetMenuActionSubmenu( $request_path, $top, $widgets, $page, %args, Asset => $asset );
+ _BuildAssetMenuActionSubmenu( $request_path, $widgets, $page, %args, Asset => $asset );
}
}

sub _BuildAssetMenuActionSubmenu {
my $request_path = shift;
- my $top = shift;
my $widgets = shift;
my $page = shift;

@@ -1094,13 +1090,8 @@ sub _BuildAssetMenuActionSubmenu {
}
}

-sub _BuildAdminMenu {
- my $request_path = shift;
- my $top = shift;
- my $widgets = shift;
- my $page = shift;
-
- my %args = ( @_ );
+sub _BuildAdminTopMenu {
+ my $top = shift;

my $current_user = $HTML::Mason::Commands::session{CurrentUser};

@@ -1318,10 +1309,6 @@ sub _BuildAdminMenu {
title => loc('Self Service Home Page'),
description => loc('Edit self service home page dashboard'),
path => '/Admin/Global/SelfServiceHomePage.html');
- if ( $request_path =~ m{^/Admin/Global/SelfServiceHomePage} ) {
- $page->child(content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html');
- $page->child(show => title => loc('Show'), path => '/SelfService');
- }
}
}
$admin_global->child( 'dashboards-in-menu' =>
@@ -1384,6 +1371,16 @@ sub _BuildAdminMenu {
description => loc('View shortener details'),
path => '/Admin/Tools/Shortener.html',
);
+}
+
+sub _BuildAdminPageMenu {
+ my $request_path = shift;
+ my $widgets = shift;
+ my $page = shift;
+
+ my %args = ( @_ );
+
+ my $current_user = $HTML::Mason::Commands::session{CurrentUser};

if ( $request_path =~ m{^/Admin/(Queues|Users|Groups|CustomFields|CustomRoles)} ) {
my $type = $1;
@@ -1453,7 +1450,9 @@ sub _BuildAdminMenu {
}
}
}
- if ( $request_path =~ m{^(/Admin/Users|/User/(Summary|History)\.html)} and $admin->child("users") ) {
+ if ( $request_path =~ m{^(/Admin/Users|/User/(Summary|History)\.html)}
+ and $current_user->HasRight( Object => RT->System, Right => 'AdminUsers' ) )
+ {
if ( $HTML::Mason::Commands::DECODED_ARGS->{'id'} && $HTML::Mason::Commands::DECODED_ARGS->{'id'} =~ /^\d+$/ ) {
my $id = $HTML::Mason::Commands::DECODED_ARGS->{'id'};
my $obj = RT::User->new( $current_user );
@@ -1682,31 +1681,19 @@ sub _BuildAdminMenu {
$page->child( create => title => loc('Create'), path => "/Admin/Articles/Classes/Modify.html?Create=1" );
}
}
+
+ if ( $request_path =~ m{^/Admin/Global/SelfServiceHomePage} ) {
+ $page->child( content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html' );
+ $page->child( show => title => loc('Show'), path => '/SelfService' );
+ }
+
}

-sub BuildSelfServiceNav {
- my $request_path = shift;
+sub BuildSelfServiceMainNav {
my $top = shift;
- my $widgets = shift;
- my $page = shift;
-
- my %args = ( @_ );

my $current_user = $HTML::Mason::Commands::session{CurrentUser};

- if ( RT->Config->Get('SelfServiceUseDashboard')
- && $request_path =~ m{^/SelfService/(?:index\.html)?$}
- && $current_user->HasRight(
- Right => 'ShowConfigTab',
- Object => RT->System
- )
- && $current_user->HasRight( Right => 'ModifyDashboard', Object => RT->System )
- )
- {
- $page->child( content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html' );
- $page->child( show => title => loc('Show'), path => '/SelfService/' );
- }
-
my $queues = RT::Queues->new( $current_user );
$queues->UnLimit;

@@ -1758,6 +1745,31 @@ sub BuildSelfServiceNav {
$about_me->child( logout => title => loc('Logout'), path => '/NoAuth/Logout.html' );
}

+}
+
+sub BuildSelfServicePageNav {
+ my $request_path = shift;
+ my $widgets = shift;
+ my $page = shift;
+
+ my %args = ( @_ );
+
+ my $current_user = $HTML::Mason::Commands::session{CurrentUser};
+
+ if ( RT->Config->Get('SelfServiceUseDashboard')
+ && $request_path =~ m{^/SelfService/(?:index\.html)?$}
+ && $current_user->HasRight(
+ Right => 'ShowConfigTab',
+ Object => RT->System
+ )
+ && $current_user->HasRight( Right => 'ModifyDashboard', Object => RT->System )
+ )
+ {
+ $page->child( content => title => loc('Content'), path => '/Admin/Global/SelfServiceHomePage.html' );
+ $page->child( show => title => loc('Show'), path => '/SelfService/' );
+ }
+
+
if ( RT->Config->Get('SelfServiceShowArticleSearch') ) {
$widgets->child( 'goto-article' => raw_html => $HTML::Mason::Commands::m->scomp('/SelfService/Elements/SearchArticle') );
}
@@ -1769,7 +1781,11 @@ sub BuildSelfServiceNav {
$page->child("display", title => loc("Display"), path => "/SelfService/Asset/Display.html?id=$id");
$page->child("history", title => loc("History"), path => "/SelfService/Asset/History.html?id=$id");

- if ($home->child("new")) {
+ my $queues = RT::Queues->new( $current_user );
+ $queues->UnLimit;
+
+ while ( my $queue = $queues->Next ) {
+ next unless $queue->CurrentUserHasRight('CreateTicket');
my $actions = $page->child("actions", title => loc("Actions"));
$actions->child(
"create-linked-ticket",
@@ -1777,6 +1793,7 @@ sub BuildSelfServiceNav {
title => loc("Create linked ticket"),
path => "/SelfService/Asset/CreateLinkedTicket.html?Asset=$id"
);
+ last;
}
}

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 9de1c0140a..ad7257efbe 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -100,6 +100,8 @@

</head>
<body hx-boost="true" class="<% join( ' ',@{$ARGS{'BodyClass'}}, GetStylesheet() =~ /-dark$/ ? 'darkmode' : ()) %>" <% $id && qq[id="comp-$id"] |n %>>
+ <div id="main-navigation"><& /Elements/Menu, menu => Menu(), id => 'app-nav' &></div>
+
<div class="main-container">
% # The close div for this is in PageLayout right before the rt body div
% if ( $ShowBar || $ShowTitle ) {
@@ -153,6 +155,18 @@ if (RT->Config->Get("UseSideBySideLayout", $session{'CurrentUser'})) {
push @{$ARGS{'BodyClass'}}, 'sidebyside';
}

+if ( my $top = Menu() ) {
+ my $request_path = $HTML::Mason::Commands::r->path_info;
+ $request_path =~ s!/{2,}!/!g;
+
+ require RT::Interface::Web::MenuBuilder;
+ if ( $request_path =~ m{^/SelfService/} ) {
+ RT::Interface::Web::MenuBuilder::BuildSelfServiceMainNav( $top );
+ }
+ else {
+ RT::Interface::Web::MenuBuilder::BuildMainNav( $top );
+ }
+}
</%INIT>

<%ARGS>
diff --git a/share/html/Elements/PageLayout b/share/html/Elements/PageLayout
index 630710e0bb..9be7b64b71 100644
--- a/share/html/Elements/PageLayout
+++ b/share/html/Elements/PageLayout
@@ -50,7 +50,6 @@
% }

% if ( $show_menu ) {
-<div id="main-navigation"><& /Elements/Menu, menu => Menu(), id => 'app-nav' &></div>
<div id="page-navigation" class="btn-group page-nav-shadow"><& /Elements/Menu, menu => PageMenu(), id => 'page-menu', class => 'page-menu', 'parent_id' => 'page' &></div>
% }
<div id="topactions"><& /Elements/WidgetBar, menu => PageWidgets() &></div>
diff --git a/share/html/Elements/Tabs b/share/html/Elements/Tabs
index 47d82f642c..12971a52db 100644
--- a/share/html/Elements/Tabs
+++ b/share/html/Elements/Tabs
@@ -52,15 +52,14 @@
my $request_path = $HTML::Mason::Commands::r->path_info;
$request_path =~ s!/{2,}!/!g;

-my $top = Menu();
my $widgets = PageWidgets();
my $page = PageMenu();

use RT::Interface::Web::MenuBuilder;
if ( $request_path !~ m{^/SelfService/} ) {
- RT::Interface::Web::MenuBuilder::BuildMainNav( $request_path, $top, $widgets, $page, %ARGS );
+ RT::Interface::Web::MenuBuilder::BuildPageNav( $request_path, $widgets, $page, %ARGS );
} else {
- RT::Interface::Web::MenuBuilder::BuildSelfServiceNav( $request_path, $top, $widgets, $page, %ARGS );
+ RT::Interface::Web::MenuBuilder::BuildSelfServicePageNav( $request_path, $widgets, $page, %ARGS );
}
</%INIT>
<%ARGS>

commit 4228ea663a046778c96ccf6ac6cdbbd007023a2f
Author: sunnavy <sunnavy@bestpractical.com>
Date: Tue Feb 27 19:38:47 2024 -0500

Disable htmx boost requests for inline edits on ticket list

diff --git a/share/html/Elements/CollectionAsTable/Row b/share/html/Elements/CollectionAsTable/Row
index 48db4cecd9..073fd5b600 100644
--- a/share/html/Elements/CollectionAsTable/Row
+++ b/share/html/Elements/CollectionAsTable/Row
@@ -178,7 +178,7 @@ foreach my $column (@Format) {

if ( $attrs{edit} ) {
my $helper_name = $record->isa('RT::Ticket') ? 'TicketUpdate' : 'AssetUpdate';
- $m->out( '<form method="POST" action="' . RT->Config->Get('WebPath') . "/Helpers/$helper_name?id=" . $record->id . '" class="editor" autocomplete="off">' );
+ $m->out( '<form hx-boost="false" method="POST" action="' . RT->Config->Get('WebPath') . "/Helpers/$helper_name?id=" . $record->id . '" class="editor" autocomplete="off">' );
$m->out( $attrs{edit} );
$m->out( '<span class="cancel text-danger far fa-times-circle" data-bs-toggle="tooltip" data-bs-placement="left" data-bs-title="' . loc('Cancel') . '"></span>' );
$m->out( '<span class="submit text-success far fa-check-circle" data-bs-toggle="tooltip" data-bs-placement="right" data-bs-title="' . loc('Save') . '"></span>' );

commit cee0d5cd91c5adb1d357b539defdaf52517ef0b9
Author: sunnavy <sunnavy@bestpractical.com>
Date: Wed Jan 17 08:46:46 2024 -0500

Disable htmx requests for inline edit toggle buttons

These buttons show inline edit forms and don't interact with servers. Htmx
doesn't boost cancel buttons as the href is "#", so no need to explicitly
disable them.

diff --git a/share/html/Elements/ShowCustomFieldCustomGroupings b/share/html/Elements/ShowCustomFieldCustomGroupings
index dd9681a3ee..86899d3b19 100644
--- a/share/html/Elements/ShowCustomFieldCustomGroupings
+++ b/share/html/Elements/ShowCustomFieldCustomGroupings
@@ -62,7 +62,7 @@ for my $group ( @Groupings ) {

my $modify_url = $title_href ? "$title_href?id=".$Object->id.($group?";Grouping=".$m->interp->apply_escapes($group,'u')."#".CSSClass("$css_class-$group") : "#".$css_class) : undef;
my $modify_inline
- = '<a class="inline-edit-toggle edit" href="'
+ = '<a hx-boost="false" class="inline-edit-toggle edit" href="'
. $m->interp->apply_escapes( ( $modify_url || '#' ), 'h' ) . '">'
. qq{<span class="fas fa-pencil-alt icon-bordered fa-2x" alt="$edit_label" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="$edit_label"></span>}
. '</a>'
diff --git a/share/html/Ticket/Elements/ShowSummary b/share/html/Ticket/Elements/ShowSummary
index 45ca5445eb..e98d672cec 100644
--- a/share/html/Ticket/Elements/ShowSummary
+++ b/share/html/Ticket/Elements/ShowSummary
@@ -52,7 +52,7 @@
<%PERL>
my $modify_url = RT->Config->Get('WebPath')."/Ticket/Modify.html?id=".$Ticket->Id;
my $modify_inline
- = '<a class="inline-edit-toggle edit" href="%s">'
+ = '<a hx-boost="false" class="inline-edit-toggle edit" href="%s">'
. qq{<span class="fas fa-pencil-alt icon-bordered fa-2x" alt="$edit_label" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="$edit_label"></span>}
. '</a>'
. '<a class="inline-edit-toggle cancel hidden" href="#">'

commit 038d0b731920a0cf857d52e67cf0bce8071121a8
Author: sunnavy <sunnavy@bestpractical.com>
Date: Wed Jan 10 17:10:21 2024 -0500

Update richtext values before htmx submits data

CKEditor automatically updates corresponding textarea values on form submit,
but htmx collects data before that, which causes submitted textarea values
to be outdated.

This commit explicitly updates textarea values before htmx submits, to get
around the issue.

diff --git a/share/static/js/util.js b/share/static/js/util.js
index f2360e2e60..5040261cea 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1031,6 +1031,14 @@ htmx.onLoad(function(elt) {
form.addClass('rt-form-submitted');
});
});
+
+ document.body.addEventListener('htmx:configRequest', function(evt) {
+ for ( const param in evt.detail.parameters ) {
+ if ( evt.detail.parameters[param + 'Type'] === 'text/html' && CKEDITOR.instances[param] ) {
+ evt.detail.parameters[param] = CKEDITOR.instances[param].getData();
+ }
+ }
+ });
});

function filterSearchResults (type) {

commit 7814c35553e539964698fb4c6ae5a4b0384965be
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Mon May 22 17:03:37 2023 -0400

Refresh dropdowns after htmx loads them

diff --git a/share/static/js/util.js b/share/static/js/util.js
index 4d026c5312..f2360e2e60 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -1002,6 +1002,7 @@ htmx.onLoad(function(elt) {
}
});

+ refreshSelectpicker(jQuery(elt).find('.selectpicker'));

// Handle implicit form submissions like hitting Return/Enter on text inputs
jQuery(elt).find('form[name=search-results-filter]').submit(filterSearchResults);

commit daf924d92eb818123a263fa4b4f886b17c974f38
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Tue May 23 14:15:27 2023 -0400

Replace default jQuery call with htmx onload

htmx.onLoad runs for every htmx interaction, so replace the previous jQuery
calls with onLoad to make sure the JS that used to run on every page load
still runs as expected when the page doesn't reload.

diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index d10b6924b0..e0c9177c0d 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -120,6 +120,7 @@ sub SquishedJS {

sub JSFiles {
return qw{
+ htmx.min.js
jquery-3.6.0.min.js
jquery_noconflict.js
jquery-ui.min.js
@@ -153,7 +154,6 @@ sub JSFiles {
chartjs-plugin-colorschemes.min.js
jquery.jgrowl.min.js
clipboard.min.js
- htmx.min.js
}, RT->Config->Get('JSFiles');
}

diff --git a/share/static/js/assets.js b/share/static/js/assets.js
index 926be23f13..593c8788c6 100644
--- a/share/static/js/assets.js
+++ b/share/static/js/assets.js
@@ -1,4 +1,4 @@
-jQuery(function() {
+htmx.onLoad(function() {
var showModal = function(html) {
var modal = jQuery("<div class='modal'></div>");
modal.append(html).appendTo("body");
diff --git a/share/static/js/autocomplete.js b/share/static/js/autocomplete.js
index fd41ab592d..c31ed7d2ed 100644
--- a/share/static/js/autocomplete.js
+++ b/share/static/js/autocomplete.js
@@ -231,4 +231,4 @@ window.RT.Autocomplete.bind = function(from) {
};
});
};
-jQuery(function(){ RT.Autocomplete.bind(document) });
+htmx.onLoad(function(){ RT.Autocomplete.bind(document) });
diff --git a/share/static/js/event-registration.js b/share/static/js/event-registration.js
index 03ba528926..4c4ac7bc1f 100644
--- a/share/static/js/event-registration.js
+++ b/share/static/js/event-registration.js
@@ -1,5 +1,5 @@
// Disable chosing individual objects when a scrip is applied globally
-jQuery(function() {
+htmx.onLoad(function() {
var global_checkboxes = [
"form[name=AddRemoveScrip] input[type=checkbox][name^=AddScrip-][value=0]",
"form input[type=checkbox][name^=AddCustomField-][value=0]"
@@ -39,10 +39,10 @@ function ReplaceUserReferences() {
}
);
}
-jQuery(ReplaceUserReferences);
+htmx.onLoad(ReplaceUserReferences);

// Cascaded selects
-jQuery(function() {
+htmx.onLoad(function() {
jQuery("select.cascade-by-optgroup").each(function(){
var name = this.name;
if (!name) return;
@@ -118,7 +118,7 @@ jQuery(function() {
});
});

-jQuery( function() {
+htmx.onLoad( function() {
jQuery("input[type=file]").change( function() {
var input = jQuery(this);
var warning = input.next(".invalid");
@@ -138,7 +138,7 @@ jQuery( function() {
});
});

-jQuery(function() {
+htmx.onLoad(function() {
jQuery("#UpdateType").change(function(ev) {
jQuery(".messagebox-container")
.removeClass("action-response action-private")
diff --git a/share/static/js/forms.js b/share/static/js/forms.js
index bf12c95406..223e7eec5e 100644
--- a/share/static/js/forms.js
+++ b/share/static/js/forms.js
@@ -1,4 +1,4 @@
-jQuery(function() {
+htmx.onLoad(function() {
jQuery('.selectionbox-js').each(function () {
var container = jQuery(this);
var source = container.find('.source');
diff --git a/share/static/js/keyboard-shortcuts.js b/share/static/js/keyboard-shortcuts.js
index 8ae117ed92..7d3d5fb3a0 100644
--- a/share/static/js/keyboard-shortcuts.js
+++ b/share/static/js/keyboard-shortcuts.js
@@ -1,4 +1,4 @@
-jQuery(function() {
+htmx.onLoad(function() {
var goBack = function() {
window.history.back();
};
@@ -70,7 +70,7 @@ jQuery(function() {
Mousetrap.bind('?', openHelp);
});

-jQuery(function() {
+htmx.onLoad(function() {
// Only load these shortcuts if there is a ticket list on the page
var hasTicketList = jQuery('table.ticket-list').length;
if (!hasTicketList) return;
@@ -156,7 +156,7 @@ jQuery(function() {
Mousetrap.bind('x', toggleTicketCheckbox);
});

-jQuery(function() {
+htmx.onLoad(function() {
// Only load these shortcuts if reply or comment action is on page
var ticket_reply = jQuery('a#page-actions-reply');
var ticket_comment = jQuery('a#page-actions-comment');
diff --git a/share/static/js/late.js b/share/static/js/late.js
index 6a83ce0592..7d163acd76 100644
--- a/share/static/js/late.js
+++ b/share/static/js/late.js
@@ -1,4 +1,4 @@
-jQuery(function() { sync_grouped_custom_fields() } );
+htmx.onLoad(function() { sync_grouped_custom_fields() } );
function sync_grouped_custom_fields() {
var all_inputs = jQuery("input,textarea,select");
var parse_cf = /^Object-([\w:]+)-(\d*)-CustomField(?::\w+)?-(\d+)-(.*)$/;
diff --git a/share/static/js/lifecycleui-editor.js b/share/static/js/lifecycleui-editor.js
index c61412dfce..9019e1eba2 100644
--- a/share/static/js/lifecycleui-editor.js
+++ b/share/static/js/lifecycleui-editor.js
@@ -1,4 +1,4 @@
-jQuery(function () {
+htmx.onLoad(function () {
RT.NewLifecycleEditor = class LifecycleEditorNew extends LifecycleModel {
constructor(container, config, maps, layout) {
super("LifecycleModel");
diff --git a/share/static/js/quoteselection.js b/share/static/js/quoteselection.js
index 4512985c32..0cf119224b 100644
--- a/share/static/js/quoteselection.js
+++ b/share/static/js/quoteselection.js
@@ -1,4 +1,4 @@
-jQuery(function() {
+htmx.onLoad(function() {
if(!RT.Config.QuoteSelectedText) {
return;
}
diff --git a/share/static/js/rights-inspector.js b/share/static/js/rights-inspector.js
index 60420a0ac1..21c4ce4106 100644
--- a/share/static/js/rights-inspector.js
+++ b/share/static/js/rights-inspector.js
@@ -1,4 +1,4 @@
-jQuery(function() {
+htmx.onLoad(function() {
var form = jQuery('form#rights-inspector');
if ( !form.length ) return;

diff --git a/share/static/js/util.js b/share/static/js/util.js
index 87626d0b98..4d026c5312 100644
--- a/share/static/js/util.js
+++ b/share/static/js/util.js
@@ -332,9 +332,9 @@ function initDatePicker(elem) {
});
}

-jQuery(function() {
- initDatePicker();
- jQuery('td.collection-as-table:not(.editable)').each( function() {
+htmx.onLoad(function(elt) {
+ initDatePicker(jQuery(elt));
+ jQuery(elt).find('td.collection-as-table:not(.editable)').each( function() {
if ( jQuery(this).children() ) {
var max_height = jQuery(this).css('line-height').replace('px', '') * 5;
if ( jQuery(this).children().height() > max_height ) {
@@ -346,13 +346,13 @@ jQuery(function() {
}
}
});
- jQuery('a.unclip').click(function() {
+ jQuery(elt).find('a.unclip').click(function() {
jQuery(this).siblings('div.clip').css('height', 'auto');
jQuery(this).hide();
jQuery(this).siblings('a.reclip').show();
return false;
});
- jQuery('a.reclip').click(function() {
+ jQuery(elt).find('a.reclip').click(function() {
var clip_div = jQuery(this).siblings('div.clip');
clip_div.height(clip_div.attr('clip-height'));
jQuery(this).siblings('a.unclip').show();
@@ -370,12 +370,13 @@ function textToHTML(value) {
};

CKEDITOR_BASEPATH=RT.Config.WebPath + "/static/RichText/";
-function ReplaceAllTextareas() {
+function ReplaceAllTextareas(elt) {
if (!CKEDITOR.env.isCompatible)
return false;

+ elt ||= document;
// replace all content and signature message boxes
- var allTextAreas = document.getElementsByTagName("textarea");
+ var allTextAreas = elt.getElementsByTagName("textarea");

for (var i=0; i < allTextAreas.length; i++) {
var textArea = allTextAreas[i];
@@ -661,7 +662,7 @@ function refreshCollectionListRow(tbody, table, success, error) {
}

// disable submit on enter in autocomplete boxes
-jQuery(function() {
+htmx.onLoad(function() {
jQuery('input[data-autocomplete], input.ui-autocomplete-input').each(function() {
var input = jQuery(this);

@@ -717,10 +718,39 @@ function loadCollapseStates() {
}

jQuery(function() {
- ReplaceAllTextareas();
- jQuery('select.chosen.CF-Edit').chosen({ width: '20em', placeholder_text_multiple: ' ', no_results_text: ' ', search_contains: true });
+ // Override toggle so when user clicks the dropdown button, current value won't be cleared.
+ var orig_toggle = jQuery.fn.combobox.Constructor.prototype.toggle;
+ jQuery.fn.combobox.Constructor.prototype.toggle = function () {
+ if ( !this.disabled && !this.$container.hasClass('combobox-selected') && !this.shown && this.$element.val() ) {
+ // Show all the options
+ var matcher = this.matcher;
+ this.matcher = function () { return 1 };
+ this.lookup();
+ this.matcher = matcher;
+ }
+ else {
+ orig_toggle.apply(this);
+ }
+ };
+
+ // Trigger change event to update ValidationHint accordingly
+ jQuery.fn.combobox.Constructor.prototype.clearElement = function () {
+ this.$element.val('').change().focus();
+ };
+
+ Chart.platform.disableCSSInjection = true;
+
+ // Make actions dropdown scrollable in case screen is too short
+ jQuery(window).resize(function() {
+ jQuery('#li-page-actions > ul').css('max-height', jQuery(window).height() - jQuery('#rt-header-container').height());
+ }).resize();
+});
+
+htmx.onLoad(function(elt) {
+ ReplaceAllTextareas(elt);
+ jQuery(elt).find('select.chosen.CF-Edit').chosen({ width: '20em', placeholder_text_multiple: ' ', no_results_text: ' ', search_contains: true });
AddAttachmentWarning();
- jQuery('a.delete-attach').click( function() {
+ jQuery(elt).find('a.delete-attach').click( function() {
var parent = jQuery(this).closest('div');
var name = jQuery(this).attr('data-name');
var token = jQuery(this).closest('form').find('input[name=Token]').val();
@@ -732,7 +762,7 @@ jQuery(function() {
return false;
});

- jQuery("#articles-create, .article-create-modal").click(function(ev){
+ jQuery(elt).find("#articles-create, .article-create-modal").click(function(ev){
ev.preventDefault();
jQuery.get(
RT.Config.WebHomePath + "/Articles/Helpers/CreateInClass",
@@ -740,7 +770,7 @@ jQuery(function() {
);
});

- jQuery(".card .card-header .toggle").each(function() {
+ jQuery(elt).find(".card .card-header .toggle").each(function() {
var e = jQuery(jQuery(this).attr('data-bs-target'));
e.on('hide.bs.collapse', function () {
createCookie(e.attr('id'),0,365);
@@ -752,7 +782,7 @@ jQuery(function() {
});
});

- jQuery(".card .accordion-item .toggle").each(function() {
+ jQuery(elt).find(".card .accordion-item .toggle").each(function() {
var e = jQuery(jQuery(this).attr('data-bs-target'));
e.on('hide.bs.collapse', function () {
createCookie(e.attr('id'),0,365);
@@ -762,7 +792,7 @@ jQuery(function() {
});
});

- jQuery(".card .card-body .toggle").each(function() {
+ jQuery(elt).find(".card .card-body .toggle").each(function() {
var e = jQuery(jQuery(this).attr('data-bs-target'));
e.on('hide.bs.collapse', function (event) {
event.stopPropagation();
@@ -772,46 +802,24 @@ jQuery(function() {
});
});

- if ( jQuery('.combobox').combobox ) {
-
- // Override toggle so when user clicks the dropdown button, current value won't be cleared.
- var orig_toggle = jQuery.fn.combobox.Constructor.prototype.toggle;
- jQuery.fn.combobox.Constructor.prototype.toggle = function () {
- if ( !this.disabled && !this.$container.hasClass('combobox-selected') && !this.shown && this.$element.val() ) {
- // Show all the options
- var matcher = this.matcher;
- this.matcher = function () { return 1 };
- this.lookup();
- this.matcher = matcher;
- }
- else {
- orig_toggle.apply(this);
- }
- };
-
- // Trigger change event to update ValidationHint accordingly
- jQuery.fn.combobox.Constructor.prototype.clearElement = function () {
- this.$element.val('').change().focus();
- };
-
- jQuery('.combobox').combobox({ clearIfNoMatch: false });
- jQuery('.combobox-wrapper').each( function() {
+ if ( jQuery(elt).find('.combobox').combobox ) {
+ jQuery(elt).find('.combobox').combobox({ clearIfNoMatch: false });
+ jQuery(elt).find('.combobox-wrapper').each( function() {
jQuery(this).find('input[type=text]').prop('name', jQuery(this).data('name')).prop('value', jQuery(this).data('value'));
});
}

/* Show selected file name in UI */
- jQuery('.custom-file input').change(function (e) {
+ jQuery(elt).find('.custom-file input').change(function (e) {
jQuery(this).next('.custom-file-label').html(e.target.files[0].name);
});

- jQuery('#assets-accordion span.collapsed').find('ul.toplevel:not(.sf-menu)').addClass('sf-menu sf-js-enabled sf-shadow').superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition().find('a').click(function(ev){
+ jQuery(elt).find('#assets-accordion span.collapsed ul.toplevel:not(.sf-menu)').addClass('sf-menu sf-js-enabled sf-shadow').superfish({ dropShadows: false, speed: 'fast', delay: 0 }).supposition().find('a').click(function(ev){
ev.stopPropagation();
return true;
});

loadCollapseStates();
- Chart.platform.disableCSSInjection = true;

if ( window.location.href.indexOf('/Admin/Lifecycles/Advanced.html') != -1 ) {
var validate_json = function (str) {
@@ -823,7 +831,7 @@ jQuery(function() {
return true;
};

- jQuery('[name=Config]').bind('input propertychange', function() {
+ jQuery(elt).find('[name=Config]').bind('input propertychange', function() {
var form = jQuery(this).closest('form');
if ( validate_json(jQuery(this).val()) ) {
form.find('input[type=submit]').prop('disabled', false);
@@ -849,7 +857,7 @@ jQuery(function() {
});

// Toolbar dropdowns insert iframes, we can apply css files there.
- jQuery('body').on('DOMNodeInserted', '.cke_panel', function(e) {
+ jQuery(elt).find('body').on('DOMNodeInserted', '.cke_panel', function(e) {
setTimeout( function(){
var content = jQuery(e.target).find('iframe').contents();
content.find('head').append('<link rel="stylesheet" type="text/css" href="' + RT.Config.WebPath + '/static/RichText/contents-dark.css" media="screen">');
@@ -858,7 +866,7 @@ jQuery(function() {

// "More colors" in color toolbars insert content directly into main DOM.
// This is to rescue colored elements from global dark bg color.
- jQuery('body').on('DOMNodeInserted', '.cke_dialog_container', function(e) {
+ jQuery(elt).find('body').on('DOMNodeInserted', '.cke_dialog_container', function(e) {
if ( !jQuery(e.target).find('.ColorCell:visible').length ) return;

// Override global dark bg color
@@ -890,7 +898,7 @@ jQuery(function() {
}

// Automatically sync to set input values to ones in config files.
- jQuery('form[name=EditConfig] input[name$="-file"]').change(function (e) {
+ jQuery(elt).find('form[name=EditConfig] input[name$="-file"]').change(function (e) {
var file_input = jQuery(this);
var form = file_input.closest('form');
var file_name = file_input.attr('name');
@@ -913,7 +921,7 @@ jQuery(function() {
});

// Automatically sync to uncheck use file config checkbox
- jQuery('form[name=EditConfig] input[name$="-file"]').each(function () {
+ jQuery(elt).find('form[name=EditConfig] input[name$="-file"]').each(function () {
var file_input = jQuery(this);
var form = file_input.closest('form');
var file_name = file_input.attr('name');
@@ -924,7 +932,7 @@ jQuery(function() {
});
});

- jQuery('form[name=BuildQuery] select[name^=SelectCustomField]').change(function() {
+ jQuery(elt).find('form[name=BuildQuery] select[name^=SelectCustomField]').change(function() {
var form = jQuery(this).closest('form');
var row = jQuery(this).closest('div.row');
var val = jQuery(this).val();
@@ -953,7 +961,8 @@ jQuery(function() {
initDatePicker(row);
}
});
- jQuery(".search-filter").click(function(ev){
+
+ jQuery(elt).find(".search-filter").click(function(ev){
ev.preventDefault();
var modal = jQuery(this).closest('th').find('.modal.search-results-filter');
modal.css('top', jQuery(this).offset().top);
@@ -967,7 +976,7 @@ jQuery(function() {
modal.modal('show');
});

- jQuery('input[name=QueueChanged]').each(function() {
+ jQuery(elt).find('input[name=QueueChanged]').each(function() {
var form = jQuery(this).closest('form');
var mark_changed = function(name) {
if ( !form.find('input[name=ChangedField][value="' + name +'"]').length ) {
@@ -993,14 +1002,10 @@ jQuery(function() {
}
});

- // Make actions dropdown scrollable in case screen is too short
- jQuery(window).resize(function() {
- jQuery('#li-page-actions > ul').css('max-height', jQuery(window).height() - jQuery('#rt-header-container').height());
- }).resize();

// Handle implicit form submissions like hitting Return/Enter on text inputs
- jQuery('form[name=search-results-filter]').submit(filterSearchResults);
- jQuery('a.permalink').click(function() {
+ jQuery(elt).find('form[name=search-results-filter]').submit(filterSearchResults);
+ jQuery(elt).find('a.permalink').click(function() {
var link = jQuery(this);
jQuery.get(
RT.Config.WebPath + "/Helpers/Permalink",
@@ -1013,7 +1018,7 @@ jQuery(function() {
// Submit all forms only once.
// This stops all forms of double-clicking or double
// enter/return key.
- jQuery('form').each(function() {
+ jQuery(elt).find('form').each(function() {
var form = jQuery(this);
form.on('submit', function (e) {
// Prevent if already submitting
@@ -1431,6 +1436,9 @@ jQuery(function () {
jQuery(document).on('datepicker:close', 'td.editable.editing form .datepicker', function () {
submitInlineEdit(jQuery(this).closest('form'));
});
+});
+
+htmx.onLoad(function(elt) {

/* inline edit on ticket display */
var toggle_inline_edit = function (link) {
@@ -1439,12 +1447,12 @@ jQuery(function () {
link.closest('.titlebox').toggleClass('editing');
}

- jQuery('.inline-edit-toggle').click(function (e) {
+ jQuery(elt).find('.inline-edit-toggle').click(function (e) {
e.preventDefault();
toggle_inline_edit(jQuery(this));
});

- jQuery('.titlebox[data-inline-edit-behavior="click"] > .titlebox-content').click(function (e) {
+ jQuery(elt).find('.titlebox[data-inline-edit-behavior="click"] > .titlebox-content').click(function (e) {
if (jQuery(e.target).is('input, select, textarea')) {
return;
}
@@ -1465,7 +1473,7 @@ jQuery(function () {
/* on submit, pull in all the other inline edit forms' fields into
* the currently-being-submitted form. that way we don't lose user
* input */
- jQuery('form.inline-edit').submit(function (e) {
+ jQuery(elt).find('form.inline-edit').submit(function (e) {
var currentForm = jQuery(this);

/* limit to currently-editing forms, since cancelling inline
@@ -1539,14 +1547,14 @@ function toggle_hide_unset(e) {
}

// enable bootstrap tooltips
-jQuery(function() {
- jQuery("body").tooltip({
+htmx.onLoad(function(elt) {
+ jQuery(elt).tooltip({
selector: '[data-bs-toggle=tooltip]',
trigger: 'hover focus'
});

// Hide the tooltip everywhere when the element is clicked
- jQuery('[data-bs-toggle="tooltip"]').click(function () {
+ jQuery(elt).find('[data-bs-toggle="tooltip"]').click(function () {
jQuery('[data-bs-toggle="tooltip"]').tooltip("hide");
});
});
@@ -1602,7 +1610,7 @@ function toggleTransactionDetails () {
}

// Use Growl to show any UserMessages written to the page
-jQuery( function() {
+htmx.onLoad( function() {
var userMessages = RT.UserMessages;
for (var key in userMessages) {
jQuery.jGrowl(userMessages[key], { sticky: true, themeState: 'none' });

commit 1c2553904e9b0e3ce58638dc3cf44d356e4c479e
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Fri Apr 28 14:43:19 2023 -0400

Implement htmx lazy loading for searches and components

diff --git a/lib/RT/Dashboard.pm b/lib/RT/Dashboard.pm
index c8bd131962..5fcd324bde 100644
--- a/lib/RT/Dashboard.pm
+++ b/lib/RT/Dashboard.pm
@@ -239,7 +239,17 @@ sub ShowSearchName {
return Name => $portlet->{description};
}

- return SavedSearch => join('-', $portlet->{privacy}, 'SavedSearch', $portlet->{id});
+ return SavedSearch => GetSavedSearchName(Privacy => $portlet->{privacy}, ObjectId => $portlet->{id});
+}
+
+sub GetSavedSearchName {
+ my %args = (
+ Privacy => '',
+ ObjectId => '',
+ @_,
+ );
+
+ return join('-', $args{Privacy}, 'SavedSearch', $args{ObjectId});
}

=head2 PossibleHiddenSearches
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index f009448850..d10b6924b0 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -456,7 +456,10 @@ sub HandleRequest {
# Process per-page final cleanup callbacks
$HTML::Mason::Commands::m->callback( %$ARGS, CallbackName => 'Final', CallbackPage => '/autohandler' );

- $HTML::Mason::Commands::m->comp( '/Elements/Footer', %$ARGS );
+ # Don't show the footer for htmx components
+ if ( $HTML::Mason::Commands::m->request_path !~ /^\/Views/ ) {
+ $HTML::Mason::Commands::m->comp( '/Elements/Footer', %$ARGS );
+ }
}

sub _ForceLogout {
diff --git a/share/html/Elements/Login b/share/html/Elements/Login
index 1ea6308c1c..ac4aeb4521 100644
--- a/share/html/Elements/Login
+++ b/share/html/Elements/Login
@@ -61,7 +61,7 @@
% $m->callback( %ARGS, CallbackName => 'BeforeForm' );

<div id="login-box">
-<&| /Widgets/TitleBox, title => loc('Login'), titleright => $RT::VERSION, hideable => 0 &>
+<&| /Widgets/TitleBox, title => loc('Login'), titleright => $RT::VERSION, hideable => 0, htmx_load => 0 &>

<& LoginRedirectWarning, %ARGS &>

diff --git a/share/html/Elements/MyRT b/share/html/Elements/MyRT
index 553328b03e..38b5bc62b4 100644
--- a/share/html/Elements/MyRT
+++ b/share/html/Elements/MyRT
@@ -133,10 +133,11 @@ my $show_cb = RT::Util::RecursiveSub(sub {
}
}
else {
+ local $m->notes->{HTMXLoadComponent} = $name;
$m->comp( $name, %{ $entry->{arguments} || {} } );
}
} elsif ( $type eq 'search' ) {
- $m->comp( '/Elements/ShowSearch', RT::Dashboard->ShowSearchName($entry), Override => { Rows => $Rows } );
+ $m->comp( '/Elements/ShowSearch', RT::Dashboard->ShowSearchName($entry), HTMXLoad => 1, Override => { Rows => $Rows } );
} elsif ( $type eq 'dashboard' ) {
my $current_dashboard = RT::Dashboard->new($session{CurrentUser});
my ($ok, $msg) = $current_dashboard->LoadById($entry->{id});
diff --git a/share/html/Elements/RefreshHomepage b/share/html/Elements/RefreshHomepage
index d3702f585b..7aeabd47c3 100644
--- a/share/html/Elements/RefreshHomepage
+++ b/share/html/Elements/RefreshHomepage
@@ -46,7 +46,7 @@
%#
%# END BPS TAGGED BLOCK }}}
<&|/Widgets/TitleBox, title => loc('Refresh')&>
-<form method="get" action="<% RT->Config->Get('WebPath') . $m->request_path %>">
+<form method="get" action="<% $ARGS{From} || ( RT->Config->Get('WebPath') . $m->request_path ) %>">
<div class="row mt-2">
<div class="col-auto">
<& /Elements/Refresh, Name => 'HomeRefreshInterval',
diff --git a/share/html/Elements/SavedSearchSelectUser b/share/html/Elements/SavedSearchSelectUser
index c2a9ff1c16..f9d6504b23 100644
--- a/share/html/Elements/SavedSearchSelectUser
+++ b/share/html/Elements/SavedSearchSelectUser
@@ -47,7 +47,7 @@
%# END BPS TAGGED BLOCK }}}

<&|/Widgets/TitleBox, title => loc('Select User')&>
-<form method="get" action="<% RT->Config->Get('WebPath') . $m->request_path %>" class="mx-auto max-width-sm">
+<form method="get" action="<% $ARGS{From} || ( RT->Config->Get('WebPath') . $m->request_path ) %>" class="mx-auto max-width-sm">
<div class="row mt-2 text-center">
<div class="col-12">
<p><&|/l&>Find a user and submit to set the __SelectedUser__ placeholder in saved searches.</&></p>
diff --git a/share/html/Elements/ShowSearch b/share/html/Elements/ShowSearch
index a10661bcd0..fc81e69224 100644
--- a/share/html/Elements/ShowSearch
+++ b/share/html/Elements/ShowSearch
@@ -54,7 +54,9 @@
titleright_raw => $customize ? qq[<span class="fas fa-cog icon-bordered fa-2x" alt="$alt" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="$alt"></span>] : '',
titleright_href => $customize,
hideable => $hideable,
- class => 'fullwidth' &>
+ class => 'fullwidth',
+ htmx_get => '/Views/Component/SavedSearch?SavedSearch=' . $search_htmx_name . $htmx_query_args,
+ htmx_load => $HTMXLoad &>
<& $query_display_component, hideable => $hideable, %$ProcessedSearchArg, ShowNavigation => 0, Class => $class, HasResults => $HasResults, PreferOrderBy => 1 &>
</&>
<%init>
@@ -231,6 +233,18 @@ if ($ShowCount) {
$ProcessedSearchArg->{Collection} = $collection;
$ProcessedSearchArg->{TotalFound} = $count;
}
+
+# Generate the turbo name from the privacy setting for this search for the turbo URL
+my $search_htmx_name = RT::Dashboard::GetSavedSearchName(
+ Privacy => RT::SharedSetting->_build_privacy( $search->ObjectType, $search->ObjectId ),
+ ObjectId => $search->Id,
+ );
+
+my $htmx_query_args = '';
+if ( exists $Override{'Rows'} ) {
+ $htmx_query_args = "&Rows=" . $Override{'Rows'};
+}
+
</%init>
<%ARGS>
$Name => undef
@@ -241,4 +255,5 @@ $hideable => 1
$ShowCustomize => 1
$ShowCount => RT->Config->Get('ShowSearchResultCount')
$HasResults => undef
+$HTMXLoad => 0 # Pass 1 to render with htmx load enabled
</%ARGS>
diff --git a/share/html/Widgets/TitleBox b/share/html/Views/Component/dhandler
similarity index 77%
copy from share/html/Widgets/TitleBox
copy to share/html/Views/Component/dhandler
index 0f50a793a0..8a957d471b 100644
--- a/share/html/Widgets/TitleBox
+++ b/share/html/Views/Component/dhandler
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -45,21 +45,25 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<div class="<% $class %>">
-% if ($hide_chrome) {
- <% $content | n %>
+% if ( $component_name eq 'SavedSearch' ) {
+% $m->comp( "/Elements/ShowSearch", %ARGS, );
% } else {
- <& TitleBoxStart, %ARGS &><% $content | n %><& TitleBoxEnd &>
+% $m->comp( "/Elements/$component_name", %ARGS );
% }
-</div>
-<%ARGS>
-$class => ''
-$hide_empty => 0
-$hide_chrome => 0
-</%ARGS>
-<%INIT>
-my $content = $m->content;
-$m->callback( CallbackName => "ModifyContent", ARGSRef => \%ARGS, Content => \$content,
- Class => \$class, HideEmpty => \$hide_empty, HideChrome => \$hide_chrome );
-return if $hide_empty && $content =~ /^\s*$/s;
-</%INIT>
+
+<%init>
+my ($component_name) = $m->dhandler_arg;
+
+if ( $component_name eq 'SavedSearch' ) {
+ # Put Override args in the correct structure
+ $ARGS{Override} = {};
+ foreach my $override ( qw(Rows) ) {
+ if ( $ARGS{$override} ) {
+ $ARGS{Override}->{$override} = $ARGS{$override};
+ delete $ARGS{$override};
+ }
+ }
+}
+</%init>
+<%args>
+</%args>
diff --git a/share/html/Widgets/TitleBox b/share/html/Widgets/HTMXLoadEnd
similarity index 79%
copy from share/html/Widgets/TitleBox
copy to share/html/Widgets/HTMXLoadEnd
index 0f50a793a0..88b5983771 100644
--- a/share/html/Widgets/TitleBox
+++ b/share/html/Widgets/HTMXLoadEnd
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -45,21 +45,6 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<div class="<% $class %>">
-% if ($hide_chrome) {
- <% $content | n %>
-% } else {
- <& TitleBoxStart, %ARGS &><% $content | n %><& TitleBoxEnd &>
-% }
</div>
<%ARGS>
-$class => ''
-$hide_empty => 0
-$hide_chrome => 0
</%ARGS>
-<%INIT>
-my $content = $m->content;
-$m->callback( CallbackName => "ModifyContent", ARGSRef => \%ARGS, Content => \$content,
- Class => \$class, HideEmpty => \$hide_empty, HideChrome => \$hide_chrome );
-return if $hide_empty && $content =~ /^\s*$/s;
-</%INIT>
diff --git a/share/html/Widgets/TitleBox b/share/html/Widgets/HTMXLoadStart
similarity index 79%
copy from share/html/Widgets/TitleBox
copy to share/html/Widgets/HTMXLoadStart
index 0f50a793a0..5420edf57a 100644
--- a/share/html/Widgets/TitleBox
+++ b/share/html/Widgets/HTMXLoadStart
@@ -2,7 +2,7 @@
%#
%# COPYRIGHT:
%#
-%# This software is Copyright (c) 1996-2023 Best Practical Solutions, LLC
+%# This software is Copyright (c) 1996-2022 Best Practical Solutions, LLC
%# <sales@bestpractical.com>
%#
%# (Except where explicitly superseded by other copyright notices)
@@ -45,21 +45,16 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
-<div class="<% $class %>">
-% if ($hide_chrome) {
- <% $content | n %>
-% } else {
- <& TitleBoxStart, %ARGS &><% $content | n %><& TitleBoxEnd &>
+<div hx-get="<% $htmx_get %>" hx-trigger="<% $lazy_load ? 'revealed' : '' %>" target="_top">
+% if ( $show_spinner ) {
+<div class="text-center htmx-indicator"><div class="spinner-border text-secondary" role="status"><span class="sr-only">Loading...</span></div></div>
% }
-</div>
<%ARGS>
-$class => ''
-$hide_empty => 0
-$hide_chrome => 0
+$htmx_get => undef
+$show_spinner => 1
+$lazy_load => 1
</%ARGS>
-<%INIT>
-my $content = $m->content;
-$m->callback( CallbackName => "ModifyContent", ARGSRef => \%ARGS, Content => \$content,
- Class => \$class, HideEmpty => \$hide_empty, HideChrome => \$hide_chrome );
-return if $hide_empty && $content =~ /^\s*$/s;
-</%INIT>
+
+<%init>
+RT->Logger->error("No htmx_get provided. HTMX needs a get path to issue the request for content.") unless $htmx_get;
+</%init>
diff --git a/share/html/Widgets/TitleBox b/share/html/Widgets/TitleBox
index 0f50a793a0..d206806aaf 100644
--- a/share/html/Widgets/TitleBox
+++ b/share/html/Widgets/TitleBox
@@ -45,20 +45,71 @@
%# those contributions and any derivatives thereof.
%#
%# END BPS TAGGED BLOCK }}}
+
+% if ( not $htmx_load ) {
<div class="<% $class %>">
-% if ($hide_chrome) {
- <% $content | n %>
-% } else {
- <& TitleBoxStart, %ARGS &><% $content | n %><& TitleBoxEnd &>
% }
+
+% if ( not $hide_chrome ) {
+ <& TitleBoxStart, %ARGS &>
+% }
+
+% if ( $htmx_load ) {
+ <& HTMXLoadStart, htmx_get => $htmx_get &>
+% }
+
+<% $content | n %>
+
+% if ( $htmx_load ) {
+ <& HTMXLoadEnd &>
+% }
+
+% if ( not $hide_chrome ) {
+ <& TitleBoxEnd &>
+% }
+
+% if ( not $htmx_load ) {
</div>
+% }
+
<%ARGS>
$class => ''
$hide_empty => 0
$hide_chrome => 0
+$htmx_load => undef
+$htmx_get => undef
</%ARGS>
<%INIT>
-my $content = $m->content;
+
+# With $htmx_load => 1, TitleBox builds the box and the title on the
+# initial load with an htmx trigger. HTMX will then
+# issue another request to load the body.
+
+# Pass $htmx_load => 0 to build an entire component on the initial
+# render like pre-htmx RT.
+
+my $content;
+
+if ( $m->request_path =~ /^\/Views/ ) {
+ # HTMX load, send content with no titlebox
+ $m->out( $m->content );
+ return;
+}
+elsif ( my $name = $m->notes('HTMXLoadComponent') ) {
+ # Request for a mason component
+ $htmx_load //= 1;
+ $htmx_get = '/Views/Component/' . $name . '?From=' . RT->Config->Get('WebPath') . $m->request_path;
+}
+elsif ( $m->request_path =~ /^\/index\.html$/ ) {
+ # Homepage load that isn't a search or a component
+ $content = '';
+}
+
+# Regular request, show the content
+unless ( length $content ) {
+ $content = $m->content;
+}
+
$m->callback( CallbackName => "ModifyContent", ARGSRef => \%ARGS, Content => \$content,
Class => \$class, HideEmpty => \$hide_empty, HideChrome => \$hide_chrome );
return if $hide_empty && $content =~ /^\s*$/s;

commit 400d8245107c002697267c6b1153206568d6b364
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Mon May 22 15:44:08 2023 -0400

Enable htmx for most of RT

diff --git a/share/html/Elements/Header b/share/html/Elements/Header
index 6dc9396461..9de1c0140a 100644
--- a/share/html/Elements/Header
+++ b/share/html/Elements/Header
@@ -99,7 +99,7 @@
% $m->callback( CallbackName => 'EndOfHead', ARGSRef => \%ARGS );

</head>
- <body class="<% join( ' ',@{$ARGS{'BodyClass'}}, GetStylesheet() =~ /-dark$/ ? 'darkmode' : ()) %>" <% $id && qq[id="comp-$id"] |n %>>
+ <body hx-boost="true" class="<% join( ' ',@{$ARGS{'BodyClass'}}, GetStylesheet() =~ /-dark$/ ? 'darkmode' : ()) %>" <% $id && qq[id="comp-$id"] |n %>>
<div class="main-container">
% # The close div for this is in PageLayout right before the rt body div
% if ( $ShowBar || $ShowTitle ) {

commit 2b0ec4d2df48c73862bb8546315f74443049fc26
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Mon Apr 24 09:30:05 2023 -0400

Remove backward compatibility code for RTIR 5.0.1

RT 6 will support only RTIR 6, so no need for RTIR 5 compatibility.

diff --git a/share/html/Elements/MyRT b/share/html/Elements/MyRT
index d066b0fe06..553328b03e 100644
--- a/share/html/Elements/MyRT
+++ b/share/html/Elements/MyRT
@@ -118,66 +118,38 @@ my $show_cb = RT::Util::RecursiveSub(sub {
my $type;
my $name;

- # Back compat for RTIR older than 5.0.2
- if ( defined $RT::IR::VERSION
- && RT::Handle::cmp_version($RT::IR::VERSION, '5.0.1') <= 0
- && $m->callers(1)->path eq '/RTIR/index.html' ) {
+ # Normal handling for RT 5.0.2 and newer
+ my $depth = shift || 0;
+ Abort("Possible recursive dashboard detected.", SuppressHeader => 1) if $depth > 8;

- $type = $entry->{type};
- $name = $entry->{'name'};
- if ( $type eq 'component' ) {
- if (!$allowed_components{$name}) {
- $m->out( $m->interp->apply_escapes( loc("Invalid portlet [_1]", $name), "h" ) );
- RT->Logger->info("Invalid portlet $name found on user " . $user->Name . "'s homepage");
- if ($name eq 'QueueList' && $allowed_components{Quicksearch}) {
- RT->Logger->warning("You may need to replace the component 'Quicksearch' in the HomepageComponents config with 'QueueList'. See the UPGRADING-4.4 document.");
- }
+ $type = $entry->{portlet_type};
+ $name = $entry->{component};
+ if ( $type eq 'component' ) {
+ if (!$allowed_components{$name}) {
+ $m->out( $m->interp->apply_escapes( loc("Invalid portlet [_1]", $name), "h" ) );
+ RT->Logger->info("Invalid portlet $name found on user " . $user->Name . "'s homepage");
+ if ($name eq 'QueueList' && $allowed_components{Quicksearch}) {
+ RT->Logger->warning("You may need to replace the component 'Quicksearch' in the HomepageComponents config with 'QueueList'. See the UPGRADING-4.4 document.");
}
- else {
- $m->comp( $name, %{ $entry->{arguments} || {} } );
- }
- } elsif ( $type eq 'system' ) {
- $m->comp( '/Elements/ShowSearch', Name => $name, Override => { Rows => $Rows } );
- } elsif ( $type eq 'saved' ) {
- $m->comp( '/Elements/ShowSearch', SavedSearch => $name, Override => { Rows => $Rows } );
- } else {
- $RT::Logger->error("unknown portlet type '$type'");
}
- }
- else {
- # Normal handling for RT 5.0.2 and newer
- my $depth = shift || 0;
- Abort("Possible recursive dashboard detected.", SuppressHeader => 1) if $depth > 8;
-
- $type = $entry->{portlet_type};
- $name = $entry->{component};
- if ( $type eq 'component' ) {
- if (!$allowed_components{$name}) {
- $m->out( $m->interp->apply_escapes( loc("Invalid portlet [_1]", $name), "h" ) );
- RT->Logger->info("Invalid portlet $name found on user " . $user->Name . "'s homepage");
- if ($name eq 'QueueList' && $allowed_components{Quicksearch}) {
- RT->Logger->warning("You may need to replace the component 'Quicksearch' in the HomepageComponents config with 'QueueList'. See the UPGRADING-4.4 document.");
- }
- }
- else {
- $m->comp( $name, %{ $entry->{arguments} || {} } );
- }
- } elsif ( $type eq 'search' ) {
- $m->comp( '/Elements/ShowSearch', RT::Dashboard->ShowSearchName($entry), Override => { Rows => $Rows } );
- } elsif ( $type eq 'dashboard' ) {
- my $current_dashboard = RT::Dashboard->new($session{CurrentUser});
- my ($ok, $msg) = $current_dashboard->LoadById($entry->{id});
- if (!$ok) {
- $m->out($msg);
- return;
- }
- my @panes = @{ $current_dashboard->Panes->{$entry->{pane}} || [] };
- for my $portlet (@panes) {
- $self_cb->($portlet, $depth + 1);
- }
- } else {
- $RT::Logger->error("unknown portlet type '$type'");
+ else {
+ $m->comp( $name, %{ $entry->{arguments} || {} } );
+ }
+ } elsif ( $type eq 'search' ) {
+ $m->comp( '/Elements/ShowSearch', RT::Dashboard->ShowSearchName($entry), Override => { Rows => $Rows } );
+ } elsif ( $type eq 'dashboard' ) {
+ my $current_dashboard = RT::Dashboard->new($session{CurrentUser});
+ my ($ok, $msg) = $current_dashboard->LoadById($entry->{id});
+ if (!$ok) {
+ $m->out($msg);
+ return;
+ }
+ my @panes = @{ $current_dashboard->Panes->{$entry->{pane}} || [] };
+ for my $portlet (@panes) {
+ $self_cb->($portlet, $depth + 1);
}
+ } else {
+ $RT::Logger->error("unknown portlet type '$type'");
}
});


commit 1446c1b5b1afa4251cf4cbca7b4f75bd5c449e84
Author: Jim Brandt <jbrandt@bestpractical.com>
Date: Mon May 22 15:15:24 2023 -0400

Add htmx JS files

diff --git a/devel/third-party/README b/devel/third-party/README
index fe52a1713f..f358639669 100644
--- a/devel/third-party/README
+++ b/devel/third-party/README
@@ -66,6 +66,11 @@ Origin: http://thenounproject.com/noun/eye-dropper/ (The Noun Project)
Author: The Noun Project
License: CC BY 3.0

+* htmx-1.9.2
+Description: htmx gives you access to AJAX, CSS Transitions, WebSockets and Server Sent Events directly in HTML, using attributes, so you can build modern user interfaces with the simplicity and power of hypertext
+Origin: https://github.com/bigskysoftware/htmx
+License: BSD 2-Clause License
+
* jquery-3.6.0.js
Description: DOM manipulation
Origin: http://code.jquery.com/jquery-3.6.0.js
diff --git a/devel/third-party/htmx-1.9.2/LICENSE b/devel/third-party/htmx-1.9.2/LICENSE
new file mode 100644
index 0000000000..3ef2fd4668
--- /dev/null
+++ b/devel/third-party/htmx-1.9.2/LICENSE
@@ -0,0 +1,25 @@
+BSD 2-Clause License
+
+Copyright (c) 2020, Big Sky Software
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+1. Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+2. Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/devel/third-party/htmx-1.9.2/htmx.js b/devel/third-party/htmx-1.9.2/htmx.js
new file mode 100644
index 0000000000..c7ea3f4518
--- /dev/null
+++ b/devel/third-party/htmx-1.9.2/htmx.js
@@ -0,0 +1,3566 @@
+// UMD insanity
+// This code sets up support for (in order) AMD, ES6 modules, and globals.
+(function (root, factory) {
+ //@ts-ignore
+ if (typeof define === 'function' && define.amd) {
+ // AMD. Register as an anonymous module.
+ //@ts-ignore
+ define([], factory);
+ } else if (typeof module === 'object' && module.exports) {
+ // Node. Does not work with strict CommonJS, but
+ // only CommonJS-like environments that support module.exports,
+ // like Node.
+ module.exports = factory();
+ } else {
+ // Browser globals
+ root.htmx = root.htmx || factory();
+ }
+}(typeof self !== 'undefined' ? self : this, function () {
+return (function () {
+ 'use strict';
+
+ // Public API
+ //** @type {import("./htmx").HtmxApi} */
+ // TODO: list all methods in public API
+ var htmx = {
+ onLoad: onLoadHelper,
+ process: processNode,
+ on: addEventListenerImpl,
+ off: removeEventListenerImpl,
+ trigger : triggerEvent,
+ ajax : ajaxHelper,
+ find : find,
+ findAll : findAll,
+ closest : closest,
+ values : function(elt, type){
+ var inputValues = getInputValues(elt, type || "post");
+ return inputValues.values;
+ },
+ remove : removeElement,
+ addClass : addClassToElement,
+ removeClass : removeClassFromElement,
+ toggleClass : toggleClassOnElement,
+ takeClass : takeClassForElement,
+ defineExtension : defineExtension,
+ removeExtension : removeExtension,
+ logAll : logAll,
+ logger : null,
+ config : {
+ historyEnabled:true,
+ historyCacheSize:10,
+ refreshOnHistoryMiss:false,
+ defaultSwapStyle:'innerHTML',
+ defaultSwapDelay:0,
+ defaultSettleDelay:20,
+ includeIndicatorStyles:true,
+ indicatorClass:'htmx-indicator',
+ requestClass:'htmx-request',
+ addedClass:'htmx-added',
+ settlingClass:'htmx-settling',
+ swappingClass:'htmx-swapping',
+ allowEval:true,
+ inlineScriptNonce:'',
+ attributesToSettle:["class", "style", "width", "height"],
+ withCredentials:false,
+ timeout:0,
+ wsReconnectDelay: 'full-jitter',
+ wsBinaryType: 'blob',
+ disableSelector: "[hx-disable], [data-hx-disable]",
+ useTemplateFragments: false,
+ scrollBehavior: 'smooth',
+ defaultFocusScroll: false,
+ getCacheBusterParam: false,
+ globalViewTransitions: false,
+ },
+ parseInterval:parseInterval,
+ _:internalEval,
+ createEventSource: function(url){
+ return new EventSource(url, {withCredentials:true})
+ },
+ createWebSocket: function(url){
+ var sock = new WebSocket(url, []);
+ sock.binaryType = htmx.config.wsBinaryType;
+ return sock;
+ },
+ version: "1.9.2"
+ };
+
+ /** @type {import("./htmx").HtmxInternalApi} */
+ var internalAPI = {
+ addTriggerHandler: addTriggerHandler,
+ bodyContains: bodyContains,
+ canAccessLocalStorage: canAccessLocalStorage,
+ filterValues: filterValues,
+ hasAttribute: hasAttribute,
+ getAttributeValue: getAttributeValue,
+ getClosestMatch: getClosestMatch,
+ getExpressionVars: getExpressionVars,
+ getHeaders: getHeaders,
+ getInputValues: getInputValues,
+ getInternalData: getInternalData,
+ getSwapSpecification: getSwapSpecification,
+ getTriggerSpecs: getTriggerSpecs,
+ getTarget: getTarget,
+ makeFragment: makeFragment,
+ mergeObjects: mergeObjects,
+ makeSettleInfo: makeSettleInfo,
+ oobSwap: oobSwap,
+ selectAndSwap: selectAndSwap,
+ settleImmediately: settleImmediately,
+ shouldCancel: shouldCancel,
+ triggerEvent: triggerEvent,
+ triggerErrorEvent: triggerErrorEvent,
+ withExtensions: withExtensions,
+ }
+
+ var VERBS = ['get', 'post', 'put', 'delete', 'patch'];
+ var VERB_SELECTOR = VERBS.map(function(verb){
+ return "[hx-" + verb + "], [data-hx-" + verb + "]"
+ }).join(", ");
+
+ //====================================================================
+ // Utilities
+ //====================================================================
+
+ function parseInterval(str) {
+ if (str == undefined) {
+ return undefined
+ }
+ if (str.slice(-2) == "ms") {
+ return parseFloat(str.slice(0,-2)) || undefined
+ }
+ if (str.slice(-1) == "s") {
+ return (parseFloat(str.slice(0,-1)) * 1000) || undefined
+ }
+ if (str.slice(-1) == "m") {
+ return (parseFloat(str.slice(0,-1)) * 1000 * 60) || undefined
+ }
+ return parseFloat(str) || undefined
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {string} name
+ * @returns {(string | null)}
+ */
+ function getRawAttribute(elt, name) {
+ return elt.getAttribute && elt.getAttribute(name);
+ }
+
+ // resolve with both hx and data-hx prefixes
+ function hasAttribute(elt, qualifiedName) {
+ return elt.hasAttribute && (elt.hasAttribute(qualifiedName) ||
+ elt.hasAttribute("data-" + qualifiedName));
+ }
+
+ /**
+ *
+ * @param {HTMLElement} elt
+ * @param {string} qualifiedName
+ * @returns {(string | null)}
+ */
+ function getAttributeValue(elt, qualifiedName) {
+ return getRawAttribute(elt, qualifiedName) || getRawAttribute(elt, "data-" + qualifiedName);
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @returns {HTMLElement | null}
+ */
+ function parentElt(elt) {
+ return elt.parentElement;
+ }
+
+ /**
+ * @returns {Document}
+ */
+ function getDocument() {
+ return document;
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {(e:HTMLElement) => boolean} condition
+ * @returns {HTMLElement | null}
+ */
+ function getClosestMatch(elt, condition) {
+ while (elt && !condition(elt)) {
+ elt = parentElt(elt);
+ }
+
+ return elt ? elt : null;
+ }
+
+ function getAttributeValueWithDisinheritance(initialElement, ancestor, attributeName){
+ var attributeValue = getAttributeValue(ancestor, attributeName);
+ var disinherit = getAttributeValue(ancestor, "hx-disinherit");
+ if (initialElement !== ancestor && disinherit && (disinherit === "*" || disinherit.split(" ").indexOf(attributeName) >= 0)) {
+ return "unset";
+ } else {
+ return attributeValue
+ }
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {string} attributeName
+ * @returns {string | null}
+ */
+ function getClosestAttributeValue(elt, attributeName) {
+ var closestAttr = null;
+ getClosestMatch(elt, function (e) {
+ return closestAttr = getAttributeValueWithDisinheritance(elt, e, attributeName);
+ });
+ if (closestAttr !== "unset") {
+ return closestAttr;
+ }
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {string} selector
+ * @returns {boolean}
+ */
+ function matches(elt, selector) {
+ // @ts-ignore: non-standard properties for browser compatability
+ // noinspection JSUnresolvedVariable
+ var matchesFunction = elt.matches || elt.matchesSelector || elt.msMatchesSelector || elt.mozMatchesSelector || elt.webkitMatchesSelector || elt.oMatchesSelector;
+ return matchesFunction && matchesFunction.call(elt, selector);
+ }
+
+ /**
+ * @param {string} str
+ * @returns {string}
+ */
+ function getStartTag(str) {
+ var tagMatcher = /<([a-z][^\/\0>\x20\t\r\n\f]*)/i
+ var match = tagMatcher.exec( str );
+ if (match) {
+ return match[1].toLowerCase();
+ } else {
+ return "";
+ }
+ }
+
+ /**
+ *
+ * @param {string} resp
+ * @param {number} depth
+ * @returns {Element}
+ */
+ function parseHTML(resp, depth) {
+ var parser = new DOMParser();
+ var responseDoc = parser.parseFromString(resp, "text/html");
+
+ /** @type {Element} */
+ var responseNode = responseDoc.body;
+ while (depth > 0) {
+ depth--;
+ // @ts-ignore
+ responseNode = responseNode.firstChild;
+ }
+ if (responseNode == null) {
+ // @ts-ignore
+ responseNode = getDocument().createDocumentFragment();
+ }
+ return responseNode;
+ }
+
+ function aFullPageResponse(resp) {
+ return resp.match(/<body/);
+ }
+
+ /**
+ *
+ * @param {string} resp
+ * @returns {Element}
+ */
+ function makeFragment(resp) {
+ var partialResponse = !aFullPageResponse(resp);
+ if (htmx.config.useTemplateFragments && partialResponse) {
+ var documentFragment = parseHTML("<body><template>" + resp + "</template></body>", 0);
+ // @ts-ignore type mismatch between DocumentFragment and Element.
+ // TODO: Are these close enough for htmx to use interchangably?
+ return documentFragment.querySelector('template').content;
+ } else {
+ var startTag = getStartTag(resp);
+ switch (startTag) {
+ case "thead":
+ case "tbody":
+ case "tfoot":
+ case "colgroup":
+ case "caption":
+ return parseHTML("<table>" + resp + "</table>", 1);
+ case "col":
+ return parseHTML("<table><colgroup>" + resp + "</colgroup></table>", 2);
+ case "tr":
+ return parseHTML("<table><tbody>" + resp + "</tbody></table>", 2);
+ case "td":
+ case "th":
+ return parseHTML("<table><tbody><tr>" + resp + "</tr></tbody></table>", 3);
+ case "script":
+ return parseHTML("<div>" + resp + "</div>", 1);
+ default:
+ return parseHTML(resp, 0);
+ }
+ }
+ }
+
+ /**
+ * @param {Function} func
+ */
+ function maybeCall(func){
+ if(func) {
+ func();
+ }
+ }
+
+ /**
+ * @param {any} o
+ * @param {string} type
+ * @returns
+ */
+ function isType(o, type) {
+ return Object.prototype.toString.call(o) === "[object " + type + "]";
+ }
+
+ /**
+ * @param {*} o
+ * @returns {o is Function}
+ */
+ function isFunction(o) {
+ return isType(o, "Function");
+ }
+
+ /**
+ * @param {*} o
+ * @returns {o is Object}
+ */
+ function isRawObject(o) {
+ return isType(o, "Object");
+ }
+
+ /**
+ * getInternalData retrieves "private" data stored by htmx within an element
+ * @param {HTMLElement} elt
+ * @returns {*}
+ */
+ function getInternalData(elt) {
+ var dataProp = 'htmx-internal-data';
+ var data = elt[dataProp];
+ if (!data) {
+ data = elt[dataProp] = {};
+ }
+ return data;
+ }
+
+ /**
+ * toArray converts an ArrayLike object into a real array.
+ * @param {ArrayLike} arr
+ * @returns {any[]}
+ */
+ function toArray(arr) {
+ var returnArr = [];
+ if (arr) {
+ for (var i = 0; i < arr.length; i++) {
+ returnArr.push(arr[i]);
+ }
+ }
+ return returnArr
+ }
+
+ function forEach(arr, func) {
+ if (arr) {
+ for (var i = 0; i < arr.length; i++) {
+ func(arr[i]);
+ }
+ }
+ }
+
+ function isScrolledIntoView(el) {
+ var rect = el.getBoundingClientRect();
+ var elemTop = rect.top;
+ var elemBottom = rect.bottom;
+ return elemTop < window.innerHeight && elemBottom >= 0;
+ }
+
+ function bodyContains(elt) {
+ // IE Fix
+ if (elt.getRootNode && elt.getRootNode() instanceof ShadowRoot) {
+ return getDocument().body.contains(elt.getRootNode().host);
+ } else {
+ return getDocument().body.contains(elt);
+ }
+ }
+
+ function splitOnWhitespace(trigger) {
+ return trigger.trim().split(/\s+/);
+ }
+
+ /**
+ * mergeObjects takes all of the keys from
+ * obj2 and duplicates them into obj1
+ * @param {Object} obj1
+ * @param {Object} obj2
+ * @returns {Object}
+ */
+ function mergeObjects(obj1, obj2) {
+ for (var key in obj2) {
+ if (obj2.hasOwnProperty(key)) {
+ obj1[key] = obj2[key];
+ }
+ }
+ return obj1;
+ }
+
+ function parseJSON(jString) {
+ try {
+ return JSON.parse(jString);
+ } catch(error) {
+ logError(error);
+ return null;
+ }
+ }
+
+ function canAccessLocalStorage() {
+ var test = 'htmx:localStorageTest';
+ try {
+ localStorage.setItem(test, test);
+ localStorage.removeItem(test);
+ return true;
+ } catch(e) {
+ return false;
+ }
+ }
+
+ function normalizePath(path) {
+ try {
+ var url = new URL(path);
+ if (url) {
+ path = url.pathname + url.search;
+ }
+ // remove trailing slash, unless index page
+ if (!path.match('^/$')) {
+ path = path.replace(/\/+$/, '');
+ }
+ return path;
+ } catch (e) {
+ // be kind to IE11, which doesn't support URL()
+ return path;
+ }
+ }
+
+ //==========================================================================================
+ // public API
+ //==========================================================================================
+
+ function internalEval(str){
+ return maybeEval(getDocument().body, function () {
+ return eval(str);
+ });
+ }
+
+ function onLoadHelper(callback) {
+ var value = htmx.on("htmx:load", function(evt) {
+ callback(evt.detail.elt);
+ });
+ return value;
+ }
+
+ function logAll(){
+ htmx.logger = function(elt, event, data) {
+ if(console) {
+ console.log(event, elt, data);
+ }
+ }
+ }
+
+ function find(eltOrSelector, selector) {
+ if (selector) {
+ return eltOrSelector.querySelector(selector);
+ } else {
+ return find(getDocument(), eltOrSelector);
+ }
+ }
+
+ function findAll(eltOrSelector, selector) {
+ if (selector) {
+ return eltOrSelector.querySelectorAll(selector);
+ } else {
+ return findAll(getDocument(), eltOrSelector);
+ }
+ }
+
+ function removeElement(elt, delay) {
+ elt = resolveTarget(elt);
+ if (delay) {
+ setTimeout(function(){
+ removeElement(elt);
+ elt = null;
+ }, delay);
+ } else {
+ elt.parentElement.removeChild(elt);
+ }
+ }
+
+ function addClassToElement(elt, clazz, delay) {
+ elt = resolveTarget(elt);
+ if (delay) {
+ setTimeout(function(){
+ addClassToElement(elt, clazz);
+ elt = null;
+ }, delay);
+ } else {
+ elt.classList && elt.classList.add(clazz);
+ }
+ }
+
+ function removeClassFromElement(elt, clazz, delay) {
+ elt = resolveTarget(elt);
+ if (delay) {
+ setTimeout(function(){
+ removeClassFromElement(elt, clazz);
+ elt = null;
+ }, delay);
+ } else {
+ if (elt.classList) {
+ elt.classList.remove(clazz);
+ // if there are no classes left, remove the class attribute
+ if (elt.classList.length === 0) {
+ elt.removeAttribute("class");
+ }
+ }
+ }
+ }
+
+ function toggleClassOnElement(elt, clazz) {
+ elt = resolveTarget(elt);
+ elt.classList.toggle(clazz);
+ }
+
+ function takeClassForElement(elt, clazz) {
+ elt = resolveTarget(elt);
+ forEach(elt.parentElement.children, function(child){
+ removeClassFromElement(child, clazz);
+ })
+ addClassToElement(elt, clazz);
+ }
+
+ function closest(elt, selector) {
+ elt = resolveTarget(elt);
+ if (elt.closest) {
+ return elt.closest(selector);
+ } else {
+ // TODO remove when IE goes away
+ do{
+ if (elt == null || matches(elt, selector)){
+ return elt;
+ }
+ }
+ while (elt = elt && parentElt(elt));
+ return null;
+ }
+ }
+
+ function normalizeSelector(selector) {
+ var trimmedSelector = selector.trim();
+ if (trimmedSelector.startsWith("<") && trimmedSelector.endsWith("/>")) {
+ return trimmedSelector.substring(1, trimmedSelector.length - 2);
+ } else {
+ return trimmedSelector;
+ }
+ }
+
+ function querySelectorAllExt(elt, selector) {
+ if (selector.indexOf("closest ") === 0) {
+ return [closest(elt, normalizeSelector(selector.substr(8)))];
+ } else if (selector.indexOf("find ") === 0) {
+ return [find(elt, normalizeSelector(selector.substr(5)))];
+ } else if (selector.indexOf("next ") === 0) {
+ return [scanForwardQuery(elt, normalizeSelector(selector.substr(5)))];
+ } else if (selector.indexOf("previous ") === 0) {
+ return [scanBackwardsQuery(elt, normalizeSelector(selector.substr(9)))];
+ } else if (selector === 'document') {
+ return [document];
+ } else if (selector === 'window') {
+ return [window];
+ } else {
+ return getDocument().querySelectorAll(normalizeSelector(selector));
+ }
+ }
+
+ var scanForwardQuery = function(start, match) {
+ var results = getDocument().querySelectorAll(match);
+ for (var i = 0; i < results.length; i++) {
+ var elt = results[i];
+ if (elt.compareDocumentPosition(start) === Node.DOCUMENT_POSITION_PRECEDING) {
+ return elt;
+ }
+ }
+ }
+
+ var scanBackwardsQuery = function(start, match) {
+ var results = getDocument().querySelectorAll(match);
+ for (var i = results.length - 1; i >= 0; i--) {
+ var elt = results[i];
+ if (elt.compareDocumentPosition(start) === Node.DOCUMENT_POSITION_FOLLOWING) {
+ return elt;
+ }
+ }
+ }
+
+ function querySelectorExt(eltOrSelector, selector) {
+ if (selector) {
+ return querySelectorAllExt(eltOrSelector, selector)[0];
+ } else {
+ return querySelectorAllExt(getDocument().body, eltOrSelector)[0];
+ }
+ }
+
+ function resolveTarget(arg2) {
+ if (isType(arg2, 'String')) {
+ return find(arg2);
+ } else {
+ return arg2;
+ }
+ }
+
+ function processEventArgs(arg1, arg2, arg3) {
+ if (isFunction(arg2)) {
+ return {
+ target: getDocument().body,
+ event: arg1,
+ listener: arg2
+ }
+ } else {
+ return {
+ target: resolveTarget(arg1),
+ event: arg2,
+ listener: arg3
+ }
+ }
+
+ }
+
+ function addEventListenerImpl(arg1, arg2, arg3) {
+ ready(function(){
+ var eventArgs = processEventArgs(arg1, arg2, arg3);
+ eventArgs.target.addEventListener(eventArgs.event, eventArgs.listener);
+ })
+ var b = isFunction(arg2);
+ return b ? arg2 : arg3;
+ }
+
+ function removeEventListenerImpl(arg1, arg2, arg3) {
+ ready(function(){
+ var eventArgs = processEventArgs(arg1, arg2, arg3);
+ eventArgs.target.removeEventListener(eventArgs.event, eventArgs.listener);
+ })
+ return isFunction(arg2) ? arg2 : arg3;
+ }
+
+ //====================================================================
+ // Node processing
+ //====================================================================
+
+ var DUMMY_ELT = getDocument().createElement("output"); // dummy element for bad selectors
+ function findAttributeTargets(elt, attrName) {
+ var attrTarget = getClosestAttributeValue(elt, attrName);
+ if (attrTarget) {
+ if (attrTarget === "this") {
+ return [findThisElement(elt, attrName)];
+ } else {
+ var result = querySelectorAllExt(elt, attrTarget);
+ if (result.length === 0) {
+ logError('The selector "' + attrTarget + '" on ' + attrName + " returned no matches!");
+ return [DUMMY_ELT]
+ } else {
+ return result;
+ }
+ }
+ }
+ }
+
+ function findThisElement(elt, attribute){
+ return getClosestMatch(elt, function (elt) {
+ return getAttributeValue(elt, attribute) != null;
+ })
+ }
+
+ function getTarget(elt) {
+ var targetStr = getClosestAttributeValue(elt, "hx-target");
+ if (targetStr) {
+ if (targetStr === "this") {
+ return findThisElement(elt,'hx-target');
+ } else {
+ return querySelectorExt(elt, targetStr)
+ }
+ } else {
+ var data = getInternalData(elt);
+ if (data.boosted) {
+ return getDocument().body;
+ } else {
+ return elt;
+ }
+ }
+ }
+
+ function shouldSettleAttribute(name) {
+ var attributesToSettle = htmx.config.attributesToSettle;
+ for (var i = 0; i < attributesToSettle.length; i++) {
+ if (name === attributesToSettle[i]) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function cloneAttributes(mergeTo, mergeFrom) {
+ forEach(mergeTo.attributes, function (attr) {
+ if (!mergeFrom.hasAttribute(attr.name) && shouldSettleAttribute(attr.name)) {
+ mergeTo.removeAttribute(attr.name)
+ }
+ });
+ forEach(mergeFrom.attributes, function (attr) {
+ if (shouldSettleAttribute(attr.name)) {
+ mergeTo.setAttribute(attr.name, attr.value);
+ }
+ });
+ }
+
+ function isInlineSwap(swapStyle, target) {
+ var extensions = getExtensions(target);
+ for (var i = 0; i < extensions.length; i++) {
+ var extension = extensions[i];
+ try {
+ if (extension.isInlineSwap(swapStyle)) {
+ return true;
+ }
+ } catch(e) {
+ logError(e);
+ }
+ }
+ return swapStyle === "outerHTML";
+ }
+
+ /**
+ *
+ * @param {string} oobValue
+ * @param {HTMLElement} oobElement
+ * @param {*} settleInfo
+ * @returns
+ */
+ function oobSwap(oobValue, oobElement, settleInfo) {
+ var selector = "#" + oobElement.id;
+ var swapStyle = "outerHTML";
+ if (oobValue === "true") {
+ // do nothing
+ } else if (oobValue.indexOf(":") > 0) {
+ swapStyle = oobValue.substr(0, oobValue.indexOf(":"));
+ selector = oobValue.substr(oobValue.indexOf(":") + 1, oobValue.length);
+ } else {
+ swapStyle = oobValue;
+ }
+
+ var targets = getDocument().querySelectorAll(selector);
+ if (targets) {
+ forEach(
+ targets,
+ function (target) {
+ var fragment;
+ var oobElementClone = oobElement.cloneNode(true);
+ fragment = getDocument().createDocumentFragment();
+ fragment.appendChild(oobElementClone);
+ if (!isInlineSwap(swapStyle, target)) {
+ fragment = oobElementClone; // if this is not an inline swap, we use the content of the node, not the node itself
+ }
+
+ var beforeSwapDetails = {shouldSwap: true, target: target, fragment:fragment };
+ if (!triggerEvent(target, 'htmx:oobBeforeSwap', beforeSwapDetails)) return;
+
+ target = beforeSwapDetails.target; // allow re-targeting
+ if (beforeSwapDetails['shouldSwap']){
+ swap(swapStyle, target, target, fragment, settleInfo);
+ }
+ forEach(settleInfo.elts, function (elt) {
+ triggerEvent(elt, 'htmx:oobAfterSwap', beforeSwapDetails);
+ });
+ }
+ );
+ oobElement.parentNode.removeChild(oobElement);
+ } else {
+ oobElement.parentNode.removeChild(oobElement);
+ triggerErrorEvent(getDocument().body, "htmx:oobErrorNoTarget", {content: oobElement});
+ }
+ return oobValue;
+ }
+
+ function handleOutOfBandSwaps(elt, fragment, settleInfo) {
+ var oobSelects = getClosestAttributeValue(elt, "hx-select-oob");
+ if (oobSelects) {
+ var oobSelectValues = oobSelects.split(",");
+ for (let i = 0; i < oobSelectValues.length; i++) {
+ var oobSelectValue = oobSelectValues[i].split(":", 2);
+ var id = oobSelectValue[0].trim();
+ if (id.indexOf("#") === 0) {
+ id = id.substring(1);
+ }
+ var oobValue = oobSelectValue[1] || "true";
+ var oobElement = fragment.querySelector("#" + id);
+ if (oobElement) {
+ oobSwap(oobValue, oobElement, settleInfo);
+ }
+ }
+ }
+ forEach(findAll(fragment, '[hx-swap-oob], [data-hx-swap-oob]'), function (oobElement) {
+ var oobValue = getAttributeValue(oobElement, "hx-swap-oob");
+ if (oobValue != null) {
+ oobSwap(oobValue, oobElement, settleInfo);
+ }
+ });
+ }
+
+ function handlePreservedElements(fragment) {
+ forEach(findAll(fragment, '[hx-preserve], [data-hx-preserve]'), function (preservedElt) {
+ var id = getAttributeValue(preservedElt, "id");
+ var oldElt = getDocument().getElementById(id);
+ if (oldElt != null) {
+ preservedElt.parentNode.replaceChild(oldElt, preservedElt);
+ }
+ });
+ }
+
+ function handleAttributes(parentNode, fragment, settleInfo) {
+ forEach(fragment.querySelectorAll("[id]"), function (newNode) {
+ if (newNode.id && newNode.id.length > 0) {
+ var normalizedId = newNode.id.replace("'", "\\'");
+ var normalizedTag = newNode.tagName.replace(':', '\\:');
+ var oldNode = parentNode.querySelector(normalizedTag + "[id='" + normalizedId + "']");
+ if (oldNode && oldNode !== parentNode) {
+ var newAttributes = newNode.cloneNode();
+ cloneAttributes(newNode, oldNode);
+ settleInfo.tasks.push(function () {
+ cloneAttributes(newNode, newAttributes);
+ });
+ }
+ }
+ });
+ }
+
+ function makeAjaxLoadTask(child) {
+ return function () {
+ removeClassFromElement(child, htmx.config.addedClass);
+ processNode(child);
+ processScripts(child);
+ processFocus(child)
+ triggerEvent(child, 'htmx:load');
+ };
+ }
+
+ function processFocus(child) {
+ var autofocus = "[autofocus]";
+ var autoFocusedElt = matches(child, autofocus) ? child : child.querySelector(autofocus)
+ if (autoFocusedElt != null) {
+ autoFocusedElt.focus();
+ }
+ }
+
+ function insertNodesBefore(parentNode, insertBefore, fragment, settleInfo) {
+ handleAttributes(parentNode, fragment, settleInfo);
+ while(fragment.childNodes.length > 0){
+ var child = fragment.firstChild;
+ addClassToElement(child, htmx.config.addedClass);
+ parentNode.insertBefore(child, insertBefore);
+ if (child.nodeType !== Node.TEXT_NODE && child.nodeType !== Node.COMMENT_NODE) {
+ settleInfo.tasks.push(makeAjaxLoadTask(child));
+ }
+ }
+ }
+
+ // based on https://gist.github.com/hyamamoto/fd435505d29ebfa3d9716fd2be8d42f0,
+ // derived from Java's string hashcode implementation
+ function stringHash(string, hash) {
+ var char = 0;
+ while (char < string.length){
+ hash = (hash << 5) - hash + string.charCodeAt(char++) | 0; // bitwise or ensures we have a 32-bit int
+ }
+ return hash;
+ }
+
+ function attributeHash(elt) {
+ var hash = 0;
+ // IE fix
+ if (elt.attributes) {
+ for (var i = 0; i < elt.attributes.length; i++) {
+ var attribute = elt.attributes[i];
+ if(attribute.value){ // only include attributes w/ actual values (empty is same as non-existent)
+ hash = stringHash(attribute.name, hash);
+ hash = stringHash(attribute.value, hash);
+ }
+ }
+ }
+ return hash;
+ }
+
+ function deInitNode(element) {
+ var internalData = getInternalData(element);
+ if (internalData.timeout) {
+ clearTimeout(internalData.timeout);
+ }
+ if (internalData.webSocket) {
+ internalData.webSocket.close();
+ }
+ if (internalData.sseEventSource) {
+ internalData.sseEventSource.close();
+ }
+ if (internalData.listenerInfos) {
+ forEach(internalData.listenerInfos, function (info) {
+ if (info.on) {
+ info.on.removeEventListener(info.trigger, info.listener);
+ }
+ });
+ }
+ if (internalData.onHandlers) {
+ for (let i = 0; i < internalData.onHandlers.length; i++) {
+ const handlerInfo = internalData.onHandlers[i];
+ element.removeEventListener(handlerInfo.name, handlerInfo.handler);
+ }
+ }
+ }
+
+ function cleanUpElement(element) {
+ triggerEvent(element, "htmx:beforeCleanupElement")
+ deInitNode(element);
+ if (element.children) { // IE
+ forEach(element.children, function(child) { cleanUpElement(child) });
+ }
+ }
+
+ function swapOuterHTML(target, fragment, settleInfo) {
+ if (target.tagName === "BODY") {
+ return swapInnerHTML(target, fragment, settleInfo);
+ } else {
+ // @type {HTMLElement}
+ var newElt
+ var eltBeforeNewContent = target.previousSibling;
+ insertNodesBefore(parentElt(target), target, fragment, settleInfo);
+ if (eltBeforeNewContent == null) {
+ newElt = parentElt(target).firstChild;
+ } else {
+ newElt = eltBeforeNewContent.nextSibling;
+ }
+ getInternalData(target).replacedWith = newElt; // tuck away so we can fire events on it later
+ settleInfo.elts = [] // clear existing elements
+ while(newElt && newElt !== target) {
+ if (newElt.nodeType === Node.ELEMENT_NODE) {
+ settleInfo.elts.push(newElt);
+ }
+ newElt = newElt.nextElementSibling;
+ }
+ cleanUpElement(target);
+ parentElt(target).removeChild(target);
+ }
+ }
+
+ function swapAfterBegin(target, fragment, settleInfo) {
+ return insertNodesBefore(target, target.firstChild, fragment, settleInfo);
+ }
+
+ function swapBeforeBegin(target, fragment, settleInfo) {
+ return insertNodesBefore(parentElt(target), target, fragment, settleInfo);
+ }
+
+ function swapBeforeEnd(target, fragment, settleInfo) {
+ return insertNodesBefore(target, null, fragment, settleInfo);
+ }
+
+ function swapAfterEnd(target, fragment, settleInfo) {
+ return insertNodesBefore(parentElt(target), target.nextSibling, fragment, settleInfo);
+ }
+ function swapDelete(target, fragment, settleInfo) {
+ cleanUpElement(target);
+ return parentElt(target).removeChild(target);
+ }
+
+ function swapInnerHTML(target, fragment, settleInfo) {
+ var firstChild = target.firstChild;
+ insertNodesBefore(target, firstChild, fragment, settleInfo);
+ if (firstChild) {
+ while (firstChild.nextSibling) {
+ cleanUpElement(firstChild.nextSibling)
+ target.removeChild(firstChild.nextSibling);
+ }
+ cleanUpElement(firstChild)
+ target.removeChild(firstChild);
+ }
+ }
+
+ function maybeSelectFromResponse(elt, fragment) {
+ var selector = getClosestAttributeValue(elt, "hx-select");
+ if (selector) {
+ var newFragment = getDocument().createDocumentFragment();
+ forEach(fragment.querySelectorAll(selector), function (node) {
+ newFragment.appendChild(node);
+ });
+ fragment = newFragment;
+ }
+ return fragment;
+ }
+
+ function swap(swapStyle, elt, target, fragment, settleInfo) {
+ switch (swapStyle) {
+ case "none":
+ return;
+ case "outerHTML":
+ swapOuterHTML(target, fragment, settleInfo);
+ return;
+ case "afterbegin":
+ swapAfterBegin(target, fragment, settleInfo);
+ return;
+ case "beforebegin":
+ swapBeforeBegin(target, fragment, settleInfo);
+ return;
+ case "beforeend":
+ swapBeforeEnd(target, fragment, settleInfo);
+ return;
+ case "afterend":
+ swapAfterEnd(target, fragment, settleInfo);
+ return;
+ case "delete":
+ swapDelete(target, fragment, settleInfo);
+ return;
+ default:
+ var extensions = getExtensions(elt);
+ for (var i = 0; i < extensions.length; i++) {
+ var ext = extensions[i];
+ try {
+ var newElements = ext.handleSwap(swapStyle, target, fragment, settleInfo);
+ if (newElements) {
+ if (typeof newElements.length !== 'undefined') {
+ // if handleSwap returns an array (like) of elements, we handle them
+ for (var j = 0; j < newElements.length; j++) {
+ var child = newElements[j];
+ if (child.nodeType !== Node.TEXT_NODE && child.nodeType !== Node.COMMENT_NODE) {
+ settleInfo.tasks.push(makeAjaxLoadTask(child));
+ }
+ }
+ }
+ return;
+ }
+ } catch (e) {
+ logError(e);
+ }
+ }
+ if (swapStyle === "innerHTML") {
+ swapInnerHTML(target, fragment, settleInfo);
+ } else {
+ swap(htmx.config.defaultSwapStyle, elt, target, fragment, settleInfo);
+ }
+ }
+ }
+
+ function findTitle(content) {
+ if (content.indexOf('<title') > -1) {
+ var contentWithSvgsRemoved = content.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim, '');
+ var result = contentWithSvgsRemoved.match(/<title(\s[^>]*>|>)([\s\S]*?)<\/title>/im);
+
+ if (result) {
+ return result[2];
+ }
+ }
+ }
+
+ function selectAndSwap(swapStyle, target, elt, responseText, settleInfo) {
+ settleInfo.title = findTitle(responseText);
+ var fragment = makeFragment(responseText);
+ if (fragment) {
+ handleOutOfBandSwaps(elt, fragment, settleInfo);
+ fragment = maybeSelectFromResponse(elt, fragment);
+ handlePreservedElements(fragment);
+ return swap(swapStyle, elt, target, fragment, settleInfo);
+ }
+ }
+
+ function handleTrigger(xhr, header, elt) {
+ var triggerBody = xhr.getResponseHeader(header);
+ if (triggerBody.indexOf("{") === 0) {
+ var triggers = parseJSON(triggerBody);
+ for (var eventName in triggers) {
+ if (triggers.hasOwnProperty(eventName)) {
+ var detail = triggers[eventName];
+ if (!isRawObject(detail)) {
+ detail = {"value": detail}
+ }
+ triggerEvent(elt, eventName, detail);
+ }
+ }
+ } else {
+ triggerEvent(elt, triggerBody, []);
+ }
+ }
+
+ var WHITESPACE = /\s/;
+ var WHITESPACE_OR_COMMA = /[\s,]/;
+ var SYMBOL_START = /[_$a-zA-Z]/;
+ var SYMBOL_CONT = /[_$a-zA-Z0-9]/;
+ var STRINGISH_START = ['"', "'", "/"];
+ var NOT_WHITESPACE = /[^\s]/;
+ function tokenizeString(str) {
+ var tokens = [];
+ var position = 0;
+ while (position < str.length) {
+ if(SYMBOL_START.exec(str.charAt(position))) {
+ var startPosition = position;
+ while (SYMBOL_CONT.exec(str.charAt(position + 1))) {
+ position++;
+ }
+ tokens.push(str.substr(startPosition, position - startPosition + 1));
+ } else if (STRINGISH_START.indexOf(str.charAt(position)) !== -1) {
+ var startChar = str.charAt(position);
+ var startPosition = position;
+ position++;
+ while (position < str.length && str.charAt(position) !== startChar ) {
+ if (str.charAt(position) === "\\") {
+ position++;
+ }
+ position++;
+ }
+ tokens.push(str.substr(startPosition, position - startPosition + 1));
+ } else {
+ var symbol = str.charAt(position);
+ tokens.push(symbol);
+ }
+ position++;
+ }
+ return tokens;
+ }
+
+ function isPossibleRelativeReference(token, last, paramName) {
+ return SYMBOL_START.exec(token.charAt(0)) &&
+ token !== "true" &&
+ token !== "false" &&
+ token !== "this" &&
+ token !== paramName &&
+ last !== ".";
+ }
+
+ function maybeGenerateConditional(elt, tokens, paramName) {
+ if (tokens[0] === '[.') {
+ tokens.shift();
+ var bracketCount = 1;
+ var conditionalSource = " return (function(" + paramName + "){ return (";
+ var last = null;
+ while (tokens.length > 0) {
+ var token = tokens[0];
+ if (token === "]") {
+ bracketCount--;
+ if (bracketCount === 0) {
+ if (last === null) {
+ conditionalSource = conditionalSource + "true";
+ }
+ tokens.shift();
+ conditionalSource += ")})";
+ try {
+ var conditionFunction = maybeEval(elt,function () {
+ return Function(conditionalSource)();
+ },
+ function(){return true})
+ conditionFunction.source = conditionalSource;
+ return conditionFunction;
+ } catch (e) {
+ triggerErrorEvent(getDocument().body, "htmx:syntax:error", {error:e, source:conditionalSource})
+ return null;
+ }
+ }
+ } else if (token === "[.") {
+ bracketCount++;
+ }
+ if (isPossibleRelativeReference(token, last, paramName)) {
+ conditionalSource += "((" + paramName + "." + token + ") ? (" + paramName + "." + token + ") : (window." + token + "))";
+ } else {
+ conditionalSource = conditionalSource + token;
+ }
+ last = tokens.shift();
+ }
+ }
+ }
+
+ function consumeUntil(tokens, match) {
+ var result = "";
+ while (tokens.length > 0 && !tokens[0].match(match)) {
+ result += tokens.shift();
+ }
+ return result;
+ }
+
+ var INPUT_SELECTOR = 'input, textarea, select';
+
+ /**
+ * @param {HTMLElement} elt
+ * @returns {import("./htmx").HtmxTriggerSpecification[]}
+ */
+ function getTriggerSpecs(elt) {
+ var explicitTrigger = getAttributeValue(elt, 'hx-trigger');
+ var triggerSpecs = [];
+ if (explicitTrigger) {
+ var tokens = tokenizeString(explicitTrigger);
+ do {
+ consumeUntil(tokens, NOT_WHITESPACE);
+ var initialLength = tokens.length;
+ var trigger = consumeUntil(tokens, /[,\[\s]/);
+ if (trigger !== "") {
+ if (trigger === "every") {
+ var every = {trigger: 'every'};
+ consumeUntil(tokens, NOT_WHITESPACE);
+ every.pollInterval = parseInterval(consumeUntil(tokens, /[,\[\s]/));
+ consumeUntil(tokens, NOT_WHITESPACE);
+ var eventFilter = maybeGenerateConditional(elt, tokens, "event");
+ if (eventFilter) {
+ every.eventFilter = eventFilter;
+ }
+ triggerSpecs.push(every);
+ } else if (trigger.indexOf("sse:") === 0) {
+ triggerSpecs.push({trigger: 'sse', sseEvent: trigger.substr(4)});
+ } else {
+ var triggerSpec = {trigger: trigger};
+ var eventFilter = maybeGenerateConditional(elt, tokens, "event");
+ if (eventFilter) {
+ triggerSpec.eventFilter = eventFilter;
+ }
+ while (tokens.length > 0 && tokens[0] !== ",") {
+ consumeUntil(tokens, NOT_WHITESPACE)
+ var token = tokens.shift();
+ if (token === "changed") {
+ triggerSpec.changed = true;
+ } else if (token === "once") {
+ triggerSpec.once = true;
+ } else if (token === "consume") {
+ triggerSpec.consume = true;
+ } else if (token === "delay" && tokens[0] === ":") {
+ tokens.shift();
+ triggerSpec.delay = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
+ } else if (token === "from" && tokens[0] === ":") {
+ tokens.shift();
+ var from_arg = consumeUntil(tokens, WHITESPACE_OR_COMMA);
+ if (from_arg === "closest" || from_arg === "find" || from_arg === "next" || from_arg === "previous") {
+ tokens.shift();
+ from_arg +=
+ " " +
+ consumeUntil(
+ tokens,
+ WHITESPACE_OR_COMMA
+ );
+ }
+ triggerSpec.from = from_arg;
+ } else if (token === "target" && tokens[0] === ":") {
+ tokens.shift();
+ triggerSpec.target = consumeUntil(tokens, WHITESPACE_OR_COMMA);
+ } else if (token === "throttle" && tokens[0] === ":") {
+ tokens.shift();
+ triggerSpec.throttle = parseInterval(consumeUntil(tokens, WHITESPACE_OR_COMMA));
+ } else if (token === "queue" && tokens[0] === ":") {
+ tokens.shift();
+ triggerSpec.queue = consumeUntil(tokens, WHITESPACE_OR_COMMA);
+ } else if ((token === "root" || token === "threshold") && tokens[0] === ":") {
+ tokens.shift();
+ triggerSpec[token] = consumeUntil(tokens, WHITESPACE_OR_COMMA);
+ } else {
+ triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
+ }
+ }
+ triggerSpecs.push(triggerSpec);
+ }
+ }
+ if (tokens.length === initialLength) {
+ triggerErrorEvent(elt, "htmx:syntax:error", {token:tokens.shift()});
+ }
+ consumeUntil(tokens, NOT_WHITESPACE);
+ } while (tokens[0] === "," && tokens.shift())
+ }
+
+ if (triggerSpecs.length > 0) {
+ return triggerSpecs;
+ } else if (matches(elt, 'form')) {
+ return [{trigger: 'submit'}];
+ } else if (matches(elt, 'input[type="button"]')){
+ return [{trigger: 'click'}];
+ } else if (matches(elt, INPUT_SELECTOR)) {
+ return [{trigger: 'change'}];
+ } else {
+ return [{trigger: 'click'}];
+ }
+ }
+
+ function cancelPolling(elt) {
+ getInternalData(elt).cancelled = true;
+ }
+
+ function processPolling(elt, handler, spec) {
+ var nodeData = getInternalData(elt);
+ nodeData.timeout = setTimeout(function () {
+ if (bodyContains(elt) && nodeData.cancelled !== true) {
+ if (!maybeFilterEvent(spec, makeEvent('hx:poll:trigger', {triggerSpec:spec, target:elt}))) {
+ handler(elt);
+ }
+ processPolling(elt, handler, spec);
+ }
+ }, spec.pollInterval);
+ }
+
+ function isLocalLink(elt) {
+ return location.hostname === elt.hostname &&
+ getRawAttribute(elt,'href') &&
+ getRawAttribute(elt,'href').indexOf("#") !== 0;
+ }
+
+ function boostElement(elt, nodeData, triggerSpecs) {
+ if ((elt.tagName === "A" && isLocalLink(elt) && (elt.target === "" || elt.target === "_self")) || elt.tagName === "FORM") {
+ nodeData.boosted = true;
+ var verb, path;
+ if (elt.tagName === "A") {
+ verb = "get";
+ path = elt.href; // DOM property gives the fully resolved href of a relative link
+ } else {
+ var rawAttribute = getRawAttribute(elt, "method");
+ verb = rawAttribute ? rawAttribute.toLowerCase() : "get";
+ if (verb === "get") {
+ }
+ path = getRawAttribute(elt, 'action');
+ }
+ triggerSpecs.forEach(function(triggerSpec) {
+ addEventListener(elt, function(elt, evt) {
+ issueAjaxRequest(verb, path, elt, evt)
+ }, nodeData, triggerSpec, true);
+ });
+ }
+ }
+
+ /**
+ *
+ * @param {Event} evt
+ * @param {HTMLElement} elt
+ * @returns
+ */
+ function shouldCancel(evt, elt) {
+ if (evt.type === "submit" || evt.type === "click") {
+ if (elt.tagName === "FORM") {
+ return true;
+ }
+ if (matches(elt, 'input[type="submit"], button') && closest(elt, 'form') !== null) {
+ return true;
+ }
+ if (elt.tagName === "A" && elt.href &&
+ (elt.getAttribute('href') === '#' || elt.getAttribute('href').indexOf("#") !== 0)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function ignoreBoostedAnchorCtrlClick(elt, evt) {
+ return getInternalData(elt).boosted && elt.tagName === "A" && evt.type === "click" && (evt.ctrlKey || evt.metaKey);
+ }
+
+ function maybeFilterEvent(triggerSpec, evt) {
+ var eventFilter = triggerSpec.eventFilter;
+ if(eventFilter){
+ try {
+ return eventFilter(evt) !== true;
+ } catch(e) {
+ triggerErrorEvent(getDocument().body, "htmx:eventFilter:error", {error: e, source:eventFilter.source});
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function addEventListener(elt, handler, nodeData, triggerSpec, explicitCancel) {
+ var elementData = getInternalData(elt);
+ var eltsToListenOn;
+ if (triggerSpec.from) {
+ eltsToListenOn = querySelectorAllExt(elt, triggerSpec.from);
+ } else {
+ eltsToListenOn = [elt];
+ }
+ // store the initial value of the element so we can tell if it changes
+ if (triggerSpec.changed) {
+ elementData.lastValue = elt.value;
+ }
+ forEach(eltsToListenOn, function (eltToListenOn) {
+ var eventListener = function (evt) {
+ if (!bodyContains(elt)) {
+ eltToListenOn.removeEventListener(triggerSpec.trigger, eventListener);
+ return;
+ }
+ if (ignoreBoostedAnchorCtrlClick(elt, evt)) {
+ return;
+ }
+ if (explicitCancel || shouldCancel(evt, elt)) {
+ evt.preventDefault();
+ }
+ if (maybeFilterEvent(triggerSpec, evt)) {
+ return;
+ }
+ var eventData = getInternalData(evt);
+ eventData.triggerSpec = triggerSpec;
+ if (eventData.handledFor == null) {
+ eventData.handledFor = [];
+ }
+ if (eventData.handledFor.indexOf(elt) < 0) {
+ eventData.handledFor.push(elt);
+ if (triggerSpec.consume) {
+ evt.stopPropagation();
+ }
+ if (triggerSpec.target && evt.target) {
+ if (!matches(evt.target, triggerSpec.target)) {
+ return;
+ }
+ }
+ if (triggerSpec.once) {
+ if (elementData.triggeredOnce) {
+ return;
+ } else {
+ elementData.triggeredOnce = true;
+ }
+ }
+ if (triggerSpec.changed) {
+ if (elementData.lastValue === elt.value) {
+ return;
+ } else {
+ elementData.lastValue = elt.value;
+ }
+ }
+ if (elementData.delayed) {
+ clearTimeout(elementData.delayed);
+ }
+ if (elementData.throttle) {
+ return;
+ }
+
+ if (triggerSpec.throttle) {
+ if (!elementData.throttle) {
+ handler(elt, evt);
+ elementData.throttle = setTimeout(function () {
+ elementData.throttle = null;
+ }, triggerSpec.throttle);
+ }
+ } else if (triggerSpec.delay) {
+ elementData.delayed = setTimeout(function() { handler(elt, evt) }, triggerSpec.delay);
+ } else {
+ triggerEvent(elt, 'htmx:trigger')
+ handler(elt, evt);
+ }
+ }
+ };
+ if (nodeData.listenerInfos == null) {
+ nodeData.listenerInfos = [];
+ }
+ nodeData.listenerInfos.push({
+ trigger: triggerSpec.trigger,
+ listener: eventListener,
+ on: eltToListenOn
+ })
+ eltToListenOn.addEventListener(triggerSpec.trigger, eventListener);
+ });
+ }
+
+ var windowIsScrolling = false // used by initScrollHandler
+ var scrollHandler = null;
+ function initScrollHandler() {
+ if (!scrollHandler) {
+ scrollHandler = function() {
+ windowIsScrolling = true
+ };
+ window.addEventListener("scroll", scrollHandler)
+ setInterval(function() {
+ if (windowIsScrolling) {
+ windowIsScrolling = false;
+ forEach(getDocument().querySelectorAll("[hx-trigger='revealed'],[data-hx-trigger='revealed']"), function (elt) {
+ maybeReveal(elt);
+ })
+ }
+ }, 200);
+ }
+ }
+
+ function maybeReveal(elt) {
+ if (!hasAttribute(elt,'data-hx-revealed') && isScrolledIntoView(elt)) {
+ elt.setAttribute('data-hx-revealed', 'true');
+ var nodeData = getInternalData(elt);
+ if (nodeData.initHash) {
+ triggerEvent(elt, 'revealed');
+ } else {
+ // if the node isn't initialized, wait for it before triggering the request
+ elt.addEventListener("htmx:afterProcessNode", function(evt) { triggerEvent(elt, 'revealed') }, {once: true});
+ }
+ }
+ }
+
+ //====================================================================
+ // Web Sockets
+ //====================================================================
+
+ function processWebSocketInfo(elt, nodeData, info) {
+ var values = splitOnWhitespace(info);
+ for (var i = 0; i < values.length; i++) {
+ var value = values[i].split(/:(.+)/);
+ if (value[0] === "connect") {
+ ensureWebSocket(elt, value[1], 0);
+ }
+ if (value[0] === "send") {
+ processWebSocketSend(elt);
+ }
+ }
+ }
+
+ function ensureWebSocket(elt, wssSource, retryCount) {
+ if (!bodyContains(elt)) {
+ return; // stop ensuring websocket connection when socket bearing element ceases to exist
+ }
+
+ if (wssSource.indexOf("/") == 0) { // complete absolute paths only
+ var base_part = location.hostname + (location.port ? ':'+location.port: '');
+ if (location.protocol == 'https:') {
+ wssSource = "wss://" + base_part + wssSource;
+ } else if (location.protocol == 'http:') {
+ wssSource = "ws://" + base_part + wssSource;
+ }
+ }
+ var socket = htmx.createWebSocket(wssSource);
+ socket.onerror = function (e) {
+ triggerErrorEvent(elt, "htmx:wsError", {error:e, socket:socket});
+ maybeCloseWebSocketSource(elt);
+ };
+
+ socket.onclose = function (e) {
+ if ([1006, 1012, 1013].indexOf(e.code) >= 0) { // Abnormal Closure/Service Restart/Try Again Later
+ var delay = getWebSocketReconnectDelay(retryCount);
+ setTimeout(function() {
+ ensureWebSocket(elt, wssSource, retryCount+1); // creates a websocket with a new timeout
+ }, delay);
+ }
+ };
+ socket.onopen = function (e) {
+ retryCount = 0;
+ }
+
+ getInternalData(elt).webSocket = socket;
+ socket.addEventListener('message', function (event) {
+ if (maybeCloseWebSocketSource(elt)) {
+ return;
+ }
+
+ var response = event.data;
+ withExtensions(elt, function(extension){
+ response = extension.transformResponse(response, null, elt);
+ });
+
+ var settleInfo = makeSettleInfo(elt);
+ var fragment = makeFragment(response);
+ var children = toArray(fragment.children);
+ for (var i = 0; i < children.length; i++) {
+ var child = children[i];
+ oobSwap(getAttributeValue(child, "hx-swap-oob") || "true", child, settleInfo);
+ }
+
+ settleImmediately(settleInfo.tasks);
+ });
+ }
+
+ function maybeCloseWebSocketSource(elt) {
+ if (!bodyContains(elt)) {
+ getInternalData(elt).webSocket.close();
+ return true;
+ }
+ }
+
+ function processWebSocketSend(elt) {
+ var webSocketSourceElt = getClosestMatch(elt, function (parent) {
+ return getInternalData(parent).webSocket != null;
+ });
+ if (webSocketSourceElt) {
+ elt.addEventListener(getTriggerSpecs(elt)[0].trigger, function (evt) {
+ var webSocket = getInternalData(webSocketSourceElt).webSocket;
+ var headers = getHeaders(elt, webSocketSourceElt);
+ var results = getInputValues(elt, 'post');
+ var errors = results.errors;
+ var rawParameters = results.values;
+ var expressionVars = getExpressionVars(elt);
+ var allParameters = mergeObjects(rawParameters, expressionVars);
+ var filteredParameters = filterValues(allParameters, elt);
+ filteredParameters['HEADERS'] = headers;
+ if (errors && errors.length > 0) {
+ triggerEvent(elt, 'htmx:validation:halted', errors);
+ return;
+ }
+ webSocket.send(JSON.stringify(filteredParameters));
+ if(shouldCancel(evt, elt)){
+ evt.preventDefault();
+ }
+ });
+ } else {
+ triggerErrorEvent(elt, "htmx:noWebSocketSourceError");
+ }
+ }
+
+ function getWebSocketReconnectDelay(retryCount) {
+ var delay = htmx.config.wsReconnectDelay;
+ if (typeof delay === 'function') {
+ // @ts-ignore
+ return delay(retryCount);
+ }
+ if (delay === 'full-jitter') {
+ var exp = Math.min(retryCount, 6);
+ var maxDelay = 1000 * Math.pow(2, exp);
+ return maxDelay * Math.random();
+ }
+ logError('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"');
+ }
+
+ //====================================================================
+ // Server Sent Events
+ //====================================================================
+
+ function processSSEInfo(elt, nodeData, info) {
+ var values = splitOnWhitespace(info);
+ for (var i = 0; i < values.length; i++) {
+ var value = values[i].split(/:(.+)/);
+ if (value[0] === "connect") {
+ processSSESource(elt, value[1]);
+ }
+
+ if ((value[0] === "swap")) {
+ processSSESwap(elt, value[1])
+ }
+ }
+ }
+
+ function processSSESource(elt, sseSrc) {
+ var source = htmx.createEventSource(sseSrc);
+ source.onerror = function (e) {
+ triggerErrorEvent(elt, "htmx:sseError", {error:e, source:source});
+ maybeCloseSSESource(elt);
+ };
+ getInternalData(elt).sseEventSource = source;
+ }
+
+ function processSSESwap(elt, sseEventName) {
+ var sseSourceElt = getClosestMatch(elt, hasEventSource);
+ if (sseSourceElt) {
+ var sseEventSource = getInternalData(sseSourceElt).sseEventSource;
+ var sseListener = function (event) {
+ if (maybeCloseSSESource(sseSourceElt)) {
+ sseEventSource.removeEventListener(sseEventName, sseListener);
+ return;
+ }
+
+ ///////////////////////////
+ // TODO: merge this code with AJAX and WebSockets code in the future.
+
+ var response = event.data;
+ withExtensions(elt, function(extension){
+ response = extension.transformResponse(response, null, elt);
+ });
+
+ var swapSpec = getSwapSpecification(elt)
+ var target = getTarget(elt)
+ var settleInfo = makeSettleInfo(elt);
+
+ selectAndSwap(swapSpec.swapStyle, elt, target, response, settleInfo)
+ settleImmediately(settleInfo.tasks)
+ triggerEvent(elt, "htmx:sseMessage", event)
+ };
+
+ getInternalData(elt).sseListener = sseListener;
+ sseEventSource.addEventListener(sseEventName, sseListener);
+ } else {
+ triggerErrorEvent(elt, "htmx:noSSESourceError");
+ }
+ }
+
+ function processSSETrigger(elt, handler, sseEventName) {
+ var sseSourceElt = getClosestMatch(elt, hasEventSource);
+ if (sseSourceElt) {
+ var sseEventSource = getInternalData(sseSourceElt).sseEventSource;
+ var sseListener = function () {
+ if (!maybeCloseSSESource(sseSourceElt)) {
+ if (bodyContains(elt)) {
+ handler(elt);
+ } else {
+ sseEventSource.removeEventListener(sseEventName, sseListener);
+ }
+ }
+ };
+ getInternalData(elt).sseListener = sseListener;
+ sseEventSource.addEventListener(sseEventName, sseListener);
+ } else {
+ triggerErrorEvent(elt, "htmx:noSSESourceError");
+ }
+ }
+
+ function maybeCloseSSESource(elt) {
+ if (!bodyContains(elt)) {
+ getInternalData(elt).sseEventSource.close();
+ return true;
+ }
+ }
+
+ function hasEventSource(node) {
+ return getInternalData(node).sseEventSource != null;
+ }
+
+ //====================================================================
+
+ function loadImmediately(elt, handler, nodeData, delay) {
+ var load = function(){
+ if (!nodeData.loaded) {
+ nodeData.loaded = true;
+ handler(elt);
+ }
+ }
+ if (delay) {
+ setTimeout(load, delay);
+ } else {
+ load();
+ }
+ }
+
+ function processVerbs(elt, nodeData, triggerSpecs) {
+ var explicitAction = false;
+ forEach(VERBS, function (verb) {
+ if (hasAttribute(elt,'hx-' + verb)) {
+ var path = getAttributeValue(elt, 'hx-' + verb);
+ explicitAction = true;
+ nodeData.path = path;
+ nodeData.verb = verb;
+ triggerSpecs.forEach(function(triggerSpec) {
+ addTriggerHandler(elt, triggerSpec, nodeData, function (elt, evt) {
+ issueAjaxRequest(verb, path, elt, evt)
+ })
+ });
+ }
+ });
+ return explicitAction;
+ }
+
+ function addTriggerHandler(elt, triggerSpec, nodeData, handler) {
+ if (triggerSpec.sseEvent) {
+ processSSETrigger(elt, handler, triggerSpec.sseEvent);
+ } else if (triggerSpec.trigger === "revealed") {
+ initScrollHandler();
+ addEventListener(elt, handler, nodeData, triggerSpec);
+ maybeReveal(elt);
+ } else if (triggerSpec.trigger === "intersect") {
+ var observerOptions = {};
+ if (triggerSpec.root) {
+ observerOptions.root = querySelectorExt(elt, triggerSpec.root)
+ }
+ if (triggerSpec.threshold) {
+ observerOptions.threshold = parseFloat(triggerSpec.threshold);
+ }
+ var observer = new IntersectionObserver(function (entries) {
+ for (var i = 0; i < entries.length; i++) {
+ var entry = entries[i];
+ if (entry.isIntersecting) {
+ triggerEvent(elt, "intersect");
+ break;
+ }
+ }
+ }, observerOptions);
+ observer.observe(elt);
+ addEventListener(elt, handler, nodeData, triggerSpec);
+ } else if (triggerSpec.trigger === "load") {
+ if (!maybeFilterEvent(triggerSpec, makeEvent("load", {elt:elt}))) {
+ loadImmediately(elt, handler, nodeData, triggerSpec.delay);
+ }
+ } else if (triggerSpec.pollInterval) {
+ nodeData.polling = true;
+ processPolling(elt, handler, triggerSpec);
+ } else {
+ addEventListener(elt, handler, nodeData, triggerSpec);
+ }
+ }
+
+ function evalScript(script) {
+ if (script.type === "text/javascript" || script.type === "module" || script.type === "") {
+ var newScript = getDocument().createElement("script");
+ forEach(script.attributes, function (attr) {
+ newScript.setAttribute(attr.name, attr.value);
+ });
+ newScript.textContent = script.textContent;
+ newScript.async = false;
+ if (htmx.config.inlineScriptNonce) {
+ newScript.nonce = htmx.config.inlineScriptNonce;
+ }
+ var parent = script.parentElement;
+
+ try {
+ parent.insertBefore(newScript, script);
+ } catch (e) {
+ logError(e);
+ } finally {
+ // remove old script element, but only if it is still in DOM
+ if (script.parentElement) {
+ script.parentElement.removeChild(script);
+ }
+ }
+ }
+ }
+
+ function processScripts(elt) {
+ if (matches(elt, "script")) {
+ evalScript(elt);
+ }
+ forEach(findAll(elt, "script"), function (script) {
+ evalScript(script);
+ });
+ }
+
+ function hasChanceOfBeingBoosted() {
+ return document.querySelector("[hx-boost], [data-hx-boost]");
+ }
+
+ function findElementsToProcess(elt) {
+ if (elt.querySelectorAll) {
+ var boostedElts = hasChanceOfBeingBoosted() ? ", a, form" : "";
+ var results = elt.querySelectorAll(VERB_SELECTOR + boostedElts + ", [hx-sse], [data-hx-sse], [hx-ws]," +
+ " [data-hx-ws], [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger], [hx-on], [data-hx-on]");
+ return results;
+ } else {
+ return [];
+ }
+ }
+
+ function initButtonTracking(form){
+ var maybeSetLastButtonClicked = function(evt){
+ var elt = closest(evt.target, "button, input[type='submit']");
+ if (elt !== null) {
+ var internalData = getInternalData(form);
+ internalData.lastButtonClicked = elt;
+ }
+ };
+
+ // need to handle both click and focus in:
+ // focusin - in case someone tabs in to a button and hits the space bar
+ // click - on OSX buttons do not focus on click see https://bugs.webkit.org/show_bug.cgi?id=13724
+
+ form.addEventListener('click', maybeSetLastButtonClicked)
+ form.addEventListener('focusin', maybeSetLastButtonClicked)
+ form.addEventListener('focusout', function(evt){
+ var internalData = getInternalData(form);
+ internalData.lastButtonClicked = null;
+ })
+ }
+
+ function countCurlies(line) {
+ var tokens = tokenizeString(line);
+ var netCurlies = 0;
+ for (let i = 0; i < tokens.length; i++) {
+ const token = tokens[i];
+ if (token === "{") {
+ netCurlies++;
+ } else if (token === "}") {
+ netCurlies--;
+ }
+ }
+ return netCurlies;
+ }
+
+ function addHxOnEventHandler(elt, eventName, code) {
+ var nodeData = getInternalData(elt);
+ nodeData.onHandlers = [];
+ var func = new Function("event", code + "; return;");
+ var listener = elt.addEventListener(eventName, function (e) {
+ return func.call(elt, e);
+ });
+ nodeData.onHandlers.push({event:eventName, listener:listener});
+ return {nodeData, code, func, listener};
+ }
+
+ function processHxOn(elt) {
+ var hxOnValue = getAttributeValue(elt, 'hx-on');
+ if (hxOnValue) {
+ var handlers = {}
+ var lines = hxOnValue.split("\n");
+ var currentEvent = null;
+ var curlyCount = 0;
+ while (lines.length > 0) {
+ var line = lines.shift();
+ var match = line.match(/^\s*([a-zA-Z:\-]+:)(.*)/);
+ if (curlyCount === 0 && match) {
+ line.split(":")
+ currentEvent = match[1].slice(0, -1); // strip last colon
+ handlers[currentEvent] = match[2];
+ } else {
+ handlers[currentEvent] += line;
+ }
+ curlyCount += countCurlies(line);
+ }
+
+ for (var eventName in handlers) {
+ addHxOnEventHandler(elt, eventName, handlers[eventName]);
+ }
+ }
+ }
+
+ function initNode(elt) {
+ if (elt.closest && elt.closest(htmx.config.disableSelector)) {
+ return;
+ }
+ var nodeData = getInternalData(elt);
+ if (nodeData.initHash !== attributeHash(elt)) {
+
+ nodeData.initHash = attributeHash(elt);
+
+ // clean up any previously processed info
+ deInitNode(elt);
+
+ processHxOn(elt);
+
+ triggerEvent(elt, "htmx:beforeProcessNode")
+
+ if (elt.value) {
+ nodeData.lastValue = elt.value;
+ }
+
+ var triggerSpecs = getTriggerSpecs(elt);
+ var hasExplicitHttpAction = processVerbs(elt, nodeData, triggerSpecs);
+
+ if (!hasExplicitHttpAction) {
+ if (getClosestAttributeValue(elt, "hx-boost") === "true") {
+ boostElement(elt, nodeData, triggerSpecs);
+ } else if (hasAttribute(elt, 'hx-trigger')) {
+ triggerSpecs.forEach(function (triggerSpec) {
+ // For "naked" triggers, don't do anything at all
+ addTriggerHandler(elt, triggerSpec, nodeData, function () {
+ })
+ })
+ }
+ }
+
+ if (elt.tagName === "FORM") {
+ initButtonTracking(elt);
+ }
+
+ var sseInfo = getAttributeValue(elt, 'hx-sse');
+ if (sseInfo) {
+ processSSEInfo(elt, nodeData, sseInfo);
+ }
+
+ var wsInfo = getAttributeValue(elt, 'hx-ws');
+ if (wsInfo) {
+ processWebSocketInfo(elt, nodeData, wsInfo);
+ }
+ triggerEvent(elt, "htmx:afterProcessNode");
+ }
+ }
+
+ function processNode(elt) {
+ elt = resolveTarget(elt);
+ initNode(elt);
+ forEach(findElementsToProcess(elt), function(child) { initNode(child) });
+ }
+
+ //====================================================================
+ // Event/Log Support
+ //====================================================================
+
+ function kebabEventName(str) {
+ return str.replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase();
+ }
+
+ function makeEvent(eventName, detail) {
+ var evt;
+ if (window.CustomEvent && typeof window.CustomEvent === 'function') {
+ evt = new CustomEvent(eventName, {bubbles: true, cancelable: true, detail: detail});
+ } else {
+ evt = getDocument().createEvent('CustomEvent');
+ evt.initCustomEvent(eventName, true, true, detail);
+ }
+ return evt;
+ }
+
+ function triggerErrorEvent(elt, eventName, detail) {
+ triggerEvent(elt, eventName, mergeObjects({error:eventName}, detail));
+ }
+
+ function ignoreEventForLogging(eventName) {
+ return eventName === "htmx:afterProcessNode"
+ }
+
+ /**
+ * `withExtensions` locates all active extensions for a provided element, then
+ * executes the provided function using each of the active extensions. It should
+ * be called internally at every extendable execution point in htmx.
+ *
+ * @param {HTMLElement} elt
+ * @param {(extension:import("./htmx").HtmxExtension) => void} toDo
+ * @returns void
+ */
+ function withExtensions(elt, toDo) {
+ forEach(getExtensions(elt), function(extension){
+ try {
+ toDo(extension);
+ } catch (e) {
+ logError(e);
+ }
+ });
+ }
+
+ function logError(msg) {
+ if(console.error) {
+ console.error(msg);
+ } else if (console.log) {
+ console.log("ERROR: ", msg);
+ }
+ }
+
+ function triggerEvent(elt, eventName, detail) {
+ elt = resolveTarget(elt);
+ if (detail == null) {
+ detail = {};
+ }
+ detail["elt"] = elt;
+ var event = makeEvent(eventName, detail);
+ if (htmx.logger && !ignoreEventForLogging(eventName)) {
+ htmx.logger(elt, eventName, detail);
+ }
+ if (detail.error) {
+ logError(detail.error);
+ triggerEvent(elt, "htmx:error", {errorInfo:detail})
+ }
+ var eventResult = elt.dispatchEvent(event);
+ var kebabName = kebabEventName(eventName);
+ if (eventResult && kebabName !== eventName) {
+ var kebabedEvent = makeEvent(kebabName, event.detail);
+ eventResult = eventResult && elt.dispatchEvent(kebabedEvent)
+ }
+ withExtensions(elt, function (extension) {
+ eventResult = eventResult && (extension.onEvent(eventName, event) !== false)
+ });
+ return eventResult;
+ }
+
+ //====================================================================
+ // History Support
+ //====================================================================
+ var currentPathForHistory = location.pathname+location.search;
+
+ function getHistoryElement() {
+ var historyElt = getDocument().querySelector('[hx-history-elt],[data-hx-history-elt]');
+ return historyElt || getDocument().body;
+ }
+
+ function saveToHistoryCache(url, content, title, scroll) {
+ if (!canAccessLocalStorage()) {
+ return;
+ }
+
+ url = normalizePath(url);
+
+ var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
+ for (var i = 0; i < historyCache.length; i++) {
+ if (historyCache[i].url === url) {
+ historyCache.splice(i, 1);
+ break;
+ }
+ }
+ var newHistoryItem = {url:url, content: content, title:title, scroll:scroll};
+ triggerEvent(getDocument().body, "htmx:historyItemCreated", {item:newHistoryItem, cache: historyCache})
+ historyCache.push(newHistoryItem)
+ while (historyCache.length > htmx.config.historyCacheSize) {
+ historyCache.shift();
+ }
+ while(historyCache.length > 0){
+ try {
+ localStorage.setItem("htmx-history-cache", JSON.stringify(historyCache));
+ break;
+ } catch (e) {
+ triggerErrorEvent(getDocument().body, "htmx:historyCacheError", {cause:e, cache: historyCache})
+ historyCache.shift(); // shrink the cache and retry
+ }
+ }
+ }
+
+ function getCachedHistory(url) {
+ if (!canAccessLocalStorage()) {
+ return null;
+ }
+
+ url = normalizePath(url);
+
+ var historyCache = parseJSON(localStorage.getItem("htmx-history-cache")) || [];
+ for (var i = 0; i < historyCache.length; i++) {
+ if (historyCache[i].url === url) {
+ return historyCache[i];
+ }
+ }
+ return null;
+ }
+
+ function cleanInnerHtmlForHistory(elt) {
+ var className = htmx.config.requestClass;
+ var clone = elt.cloneNode(true);
+ forEach(findAll(clone, "." + className), function(child){
+ removeClassFromElement(child, className);
+ });
+ return clone.innerHTML;
+ }
+
+ function saveCurrentPageToHistory() {
+ var elt = getHistoryElement();
+ var path = currentPathForHistory || location.pathname+location.search;
+
+ // Allow history snapshot feature to be disabled where hx-history="false"
+ // is present *anywhere* in the current document we're about to save,
+ // so we can prevent privileged data entering the cache.
+ // The page will still be reachable as a history entry, but htmx will fetch it
+ // live from the server onpopstate rather than look in the localStorage cache
+ var disableHistoryCache = getDocument().querySelector('[hx-history="false" i],[data-hx-history="false" i]');
+ if (!disableHistoryCache) {
+ triggerEvent(getDocument().body, "htmx:beforeHistorySave", {path: path, historyElt: elt});
+ saveToHistoryCache(path, cleanInnerHtmlForHistory(elt), getDocument().title, window.scrollY);
+ }
+
+ if (htmx.config.historyEnabled) history.replaceState({htmx: true}, getDocument().title, window.location.href);
+ }
+
+ function pushUrlIntoHistory(path) {
+ // remove the cache buster parameter, if any
+ if (htmx.config.getCacheBusterParam) {
+ path = path.replace(/org\.htmx\.cache-buster=[^&]*&?/, '')
+ if (path.endsWith('&') || path.endsWith("?")) {
+ path = path.slice(0, -1);
+ }
+ }
+ if(htmx.config.historyEnabled) {
+ history.pushState({htmx:true}, "", path);
+ }
+ currentPathForHistory = path;
+ }
+
+ function replaceUrlInHistory(path) {
+ if(htmx.config.historyEnabled) history.replaceState({htmx:true}, "", path);
+ currentPathForHistory = path;
+ }
+
+ function settleImmediately(tasks) {
+ forEach(tasks, function (task) {
+ task.call();
+ });
+ }
+
+ function loadHistoryFromServer(path) {
+ var request = new XMLHttpRequest();
+ var details = {path: path, xhr:request};
+ triggerEvent(getDocument().body, "htmx:historyCacheMiss", details);
+ request.open('GET', path, true);
+ request.setRequestHeader("HX-History-Restore-Request", "true");
+ request.onload = function () {
+ if (this.status >= 200 && this.status < 400) {
+ triggerEvent(getDocument().body, "htmx:historyCacheMissLoad", details);
+ var fragment = makeFragment(this.response);
+ // @ts-ignore
+ fragment = fragment.querySelector('[hx-history-elt],[data-hx-history-elt]') || fragment;
+ var historyElement = getHistoryElement();
+ var settleInfo = makeSettleInfo(historyElement);
+ var title = findTitle(this.response);
+ if (title) {
+ var titleElt = find("title");
+ if (titleElt) {
+ titleElt.innerHTML = title;
+ } else {
+ window.document.title = title;
+ }
+ }
+ // @ts-ignore
+ swapInnerHTML(historyElement, fragment, settleInfo)
+ settleImmediately(settleInfo.tasks);
+ currentPathForHistory = path;
+ triggerEvent(getDocument().body, "htmx:historyRestore", {path: path, cacheMiss:true, serverResponse:this.response});
+ } else {
+ triggerErrorEvent(getDocument().body, "htmx:historyCacheMissLoadError", details);
+ }
+ };
+ request.send();
+ }
+
+ function restoreHistory(path) {
+ saveCurrentPageToHistory();
+ path = path || location.pathname+location.search;
+ var cached = getCachedHistory(path);
+ if (cached) {
+ var fragment = makeFragment(cached.content);
+ var historyElement = getHistoryElement();
+ var settleInfo = makeSettleInfo(historyElement);
+ swapInnerHTML(historyElement, fragment, settleInfo)
+ settleImmediately(settleInfo.tasks);
+ document.title = cached.title;
+ window.scrollTo(0, cached.scroll);
+ currentPathForHistory = path;
+ triggerEvent(getDocument().body, "htmx:historyRestore", {path:path, item:cached});
+ } else {
+ if (htmx.config.refreshOnHistoryMiss) {
+
+ // @ts-ignore: optional parameter in reload() function throws error
+ window.location.reload(true);
+ } else {
+ loadHistoryFromServer(path);
+ }
+ }
+ }
+
+ function addRequestIndicatorClasses(elt) {
+ var indicators = findAttributeTargets(elt, 'hx-indicator');
+ if (indicators == null) {
+ indicators = [elt];
+ }
+ forEach(indicators, function (ic) {
+ var internalData = getInternalData(ic);
+ internalData.requestCount = (internalData.requestCount || 0) + 1;
+ ic.classList["add"].call(ic.classList, htmx.config.requestClass);
+ });
+ return indicators;
+ }
+
+ function removeRequestIndicatorClasses(indicators) {
+ forEach(indicators, function (ic) {
+ var internalData = getInternalData(ic);
+ internalData.requestCount = (internalData.requestCount || 0) - 1;
+ if (internalData.requestCount === 0) {
+ ic.classList["remove"].call(ic.classList, htmx.config.requestClass);
+ }
+ });
+ }
+
+ //====================================================================
+ // Input Value Processing
+ //====================================================================
+
+ function haveSeenNode(processed, elt) {
+ for (var i = 0; i < processed.length; i++) {
+ var node = processed[i];
+ if (node.isSameNode(elt)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ function shouldInclude(elt) {
+ if(elt.name === "" || elt.name == null || elt.disabled) {
+ return false;
+ }
+ // ignore "submitter" types (see jQuery src/serialize.js)
+ if (elt.type === "button" || elt.type === "submit" || elt.tagName === "image" || elt.tagName === "reset" || elt.tagName === "file" ) {
+ return false;
+ }
+ if (elt.type === "checkbox" || elt.type === "radio" ) {
+ return elt.checked;
+ }
+ return true;
+ }
+
+ function processInputValue(processed, values, errors, elt, validate) {
+ if (elt == null || haveSeenNode(processed, elt)) {
+ return;
+ } else {
+ processed.push(elt);
+ }
+ if (shouldInclude(elt)) {
+ var name = getRawAttribute(elt,"name");
+ var value = elt.value;
+ if (elt.multiple) {
+ value = toArray(elt.querySelectorAll("option:checked")).map(function (e) { return e.value });
+ }
+ // include file inputs
+ if (elt.files) {
+ value = toArray(elt.files);
+ }
+ // This is a little ugly because both the current value of the named value in the form
+ // and the new value could be arrays, so we have to handle all four cases :/
+ if (name != null && value != null) {
+ var current = values[name];
+ if (current !== undefined) {
+ if (Array.isArray(current)) {
+ if (Array.isArray(value)) {
+ values[name] = current.concat(value);
+ } else {
+ current.push(value);
+ }
+ } else {
+ if (Array.isArray(value)) {
+ values[name] = [current].concat(value);
+ } else {
+ values[name] = [current, value];
+ }
+ }
+ } else {
+ values[name] = value;
+ }
+ }
+ if (validate) {
+ validateElement(elt, errors);
+ }
+ }
+ if (matches(elt, 'form')) {
+ var inputs = elt.elements;
+ forEach(inputs, function(input) {
+ processInputValue(processed, values, errors, input, validate);
+ });
+ }
+ }
+
+ function validateElement(element, errors) {
+ if (element.willValidate) {
+ triggerEvent(element, "htmx:validation:validate")
+ if (!element.checkValidity()) {
+ errors.push({elt: element, message:element.validationMessage, validity:element.validity});
+ triggerEvent(element, "htmx:validation:failed", {message:element.validationMessage, validity:element.validity})
+ }
+ }
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {string} verb
+ */
+ function getInputValues(elt, verb) {
+ var processed = [];
+ var values = {};
+ var formValues = {};
+ var errors = [];
+ var internalData = getInternalData(elt);
+
+ // only validate when form is directly submitted and novalidate or formnovalidate are not set
+ // or if the element has an explicit hx-validate="true" on it
+ var validate = (matches(elt, 'form') && elt.noValidate !== true) || getAttributeValue(elt, "hx-validate") === "true";
+ if (internalData.lastButtonClicked) {
+ validate = validate && internalData.lastButtonClicked.formNoValidate !== true;
+ }
+
+ // for a non-GET include the closest form
+ if (verb !== 'get') {
+ processInputValue(processed, formValues, errors, closest(elt, 'form'), validate);
+ }
+
+ // include the element itself
+ processInputValue(processed, values, errors, elt, validate);
+
+ // if a button or submit was clicked last, include its value
+ if (internalData.lastButtonClicked) {
+ var name = getRawAttribute(internalData.lastButtonClicked,"name");
+ if (name) {
+ values[name] = internalData.lastButtonClicked.value;
+ }
+ }
+
+ // include any explicit includes
+ var includes = findAttributeTargets(elt, "hx-include");
+ forEach(includes, function(node) {
+ processInputValue(processed, values, errors, node, validate);
+ // if a non-form is included, include any input values within it
+ if (!matches(node, 'form')) {
+ forEach(node.querySelectorAll(INPUT_SELECTOR), function (descendant) {
+ processInputValue(processed, values, errors, descendant, validate);
+ })
+ }
+ });
+
+ // form values take precedence, overriding the regular values
+ values = mergeObjects(values, formValues);
+
+ return {errors:errors, values:values};
+ }
+
+ function appendParam(returnStr, name, realValue) {
+ if (returnStr !== "") {
+ returnStr += "&";
+ }
+ if (String(realValue) === "[object Object]") {
+ realValue = JSON.stringify(realValue);
+ }
+ var s = encodeURIComponent(realValue);
+ returnStr += encodeURIComponent(name) + "=" + s;
+ return returnStr;
+ }
+
+ function urlEncode(values) {
+ var returnStr = "";
+ for (var name in values) {
+ if (values.hasOwnProperty(name)) {
+ var value = values[name];
+ if (Array.isArray(value)) {
+ forEach(value, function(v) {
+ returnStr = appendParam(returnStr, name, v);
+ });
+ } else {
+ returnStr = appendParam(returnStr, name, value);
+ }
+ }
+ }
+ return returnStr;
+ }
+
+ function makeFormData(values) {
+ var formData = new FormData();
+ for (var name in values) {
+ if (values.hasOwnProperty(name)) {
+ var value = values[name];
+ if (Array.isArray(value)) {
+ forEach(value, function(v) {
+ formData.append(name, v);
+ });
+ } else {
+ formData.append(name, value);
+ }
+ }
+ }
+ return formData;
+ }
+
+ //====================================================================
+ // Ajax
+ //====================================================================
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {HTMLElement} target
+ * @param {string} prompt
+ * @returns {Object} // TODO: Define/Improve HtmxHeaderSpecification
+ */
+ function getHeaders(elt, target, prompt) {
+ var headers = {
+ "HX-Request" : "true",
+ "HX-Trigger" : getRawAttribute(elt, "id"),
+ "HX-Trigger-Name" : getRawAttribute(elt, "name"),
+ "HX-Target" : getAttributeValue(target, "id"),
+ "HX-Current-URL" : getDocument().location.href,
+ }
+ getValuesForElement(elt, "hx-headers", false, headers)
+ if (prompt !== undefined) {
+ headers["HX-Prompt"] = prompt;
+ }
+ if (getInternalData(elt).boosted) {
+ headers["HX-Boosted"] = "true";
+ }
+ return headers;
+ }
+
+ /**
+ * filterValues takes an object containing form input values
+ * and returns a new object that only contains keys that are
+ * specified by the closest "hx-params" attribute
+ * @param {Object} inputValues
+ * @param {HTMLElement} elt
+ * @returns {Object}
+ */
+ function filterValues(inputValues, elt) {
+ var paramsValue = getClosestAttributeValue(elt, "hx-params");
+ if (paramsValue) {
+ if (paramsValue === "none") {
+ return {};
+ } else if (paramsValue === "*") {
+ return inputValues;
+ } else if(paramsValue.indexOf("not ") === 0) {
+ forEach(paramsValue.substr(4).split(","), function (name) {
+ name = name.trim();
+ delete inputValues[name];
+ });
+ return inputValues;
+ } else {
+ var newValues = {}
+ forEach(paramsValue.split(","), function (name) {
+ name = name.trim();
+ newValues[name] = inputValues[name];
+ });
+ return newValues;
+ }
+ } else {
+ return inputValues;
+ }
+ }
+
+ function isAnchorLink(elt) {
+ return getRawAttribute(elt, 'href') && getRawAttribute(elt, 'href').indexOf("#") >=0
+ }
+
+ /**
+ *
+ * @param {HTMLElement} elt
+ * @param {string} swapInfoOverride
+ * @returns {import("./htmx").HtmxSwapSpecification}
+ */
+ function getSwapSpecification(elt, swapInfoOverride) {
+ var swapInfo = swapInfoOverride ? swapInfoOverride : getClosestAttributeValue(elt, "hx-swap");
+ var swapSpec = {
+ "swapStyle" : getInternalData(elt).boosted ? 'innerHTML' : htmx.config.defaultSwapStyle,
+ "swapDelay" : htmx.config.defaultSwapDelay,
+ "settleDelay" : htmx.config.defaultSettleDelay
+ }
+ if (getInternalData(elt).boosted && !isAnchorLink(elt)) {
+ swapSpec["show"] = "top"
+ }
+ if (swapInfo) {
+ var split = splitOnWhitespace(swapInfo);
+ if (split.length > 0) {
+ swapSpec["swapStyle"] = split[0];
+ for (var i = 1; i < split.length; i++) {
+ var modifier = split[i];
+ if (modifier.indexOf("swap:") === 0) {
+ swapSpec["swapDelay"] = parseInterval(modifier.substr(5));
+ }
+ if (modifier.indexOf("settle:") === 0) {
+ swapSpec["settleDelay"] = parseInterval(modifier.substr(7));
+ }
+ if (modifier.indexOf("transition:") === 0) {
+ swapSpec["transition"] = modifier.substr(11) === "true";
+ }
+ if (modifier.indexOf("scroll:") === 0) {
+ var scrollSpec = modifier.substr(7);
+ var splitSpec = scrollSpec.split(":");
+ var scrollVal = splitSpec.pop();
+ var selectorVal = splitSpec.length > 0 ? splitSpec.join(":") : null;
+ swapSpec["scroll"] = scrollVal;
+ swapSpec["scrollTarget"] = selectorVal;
+ }
+ if (modifier.indexOf("show:") === 0) {
+ var showSpec = modifier.substr(5);
+ var splitSpec = showSpec.split(":");
+ var showVal = splitSpec.pop();
+ var selectorVal = splitSpec.length > 0 ? splitSpec.join(":") : null;
+ swapSpec["show"] = showVal;
+ swapSpec["showTarget"] = selectorVal;
+ }
+ if (modifier.indexOf("focus-scroll:") === 0) {
+ var focusScrollVal = modifier.substr("focus-scroll:".length);
+ swapSpec["focusScroll"] = focusScrollVal == "true";
+ }
+ }
+ }
+ }
+ return swapSpec;
+ }
+
+ function usesFormData(elt) {
+ return getClosestAttributeValue(elt, "hx-encoding") === "multipart/form-data" ||
+ (matches(elt, "form") && getRawAttribute(elt, 'enctype') === "multipart/form-data");
+ }
+
+ function encodeParamsForBody(xhr, elt, filteredParameters) {
+ var encodedParameters = null;
+ withExtensions(elt, function (extension) {
+ if (encodedParameters == null) {
+ encodedParameters = extension.encodeParameters(xhr, filteredParameters, elt);
+ }
+ });
+ if (encodedParameters != null) {
+ return encodedParameters;
+ } else {
+ if (usesFormData(elt)) {
+ return makeFormData(filteredParameters);
+ } else {
+ return urlEncode(filteredParameters);
+ }
+ }
+ }
+
+ /**
+ *
+ * @param {Element} target
+ * @returns {import("./htmx").HtmxSettleInfo}
+ */
+ function makeSettleInfo(target) {
+ return {tasks: [], elts: [target]};
+ }
+
+ function updateScrollState(content, swapSpec) {
+ var first = content[0];
+ var last = content[content.length - 1];
+ if (swapSpec.scroll) {
+ var target = null;
+ if (swapSpec.scrollTarget) {
+ target = querySelectorExt(first, swapSpec.scrollTarget);
+ }
+ if (swapSpec.scroll === "top" && (first || target)) {
+ target = target || first;
+ target.scrollTop = 0;
+ }
+ if (swapSpec.scroll === "bottom" && (last || target)) {
+ target = target || last;
+ target.scrollTop = target.scrollHeight;
+ }
+ }
+ if (swapSpec.show) {
+ var target = null;
+ if (swapSpec.showTarget) {
+ var targetStr = swapSpec.showTarget;
+ if (swapSpec.showTarget === "window") {
+ targetStr = "body";
+ }
+ target = querySelectorExt(first, targetStr);
+ }
+ if (swapSpec.show === "top" && (first || target)) {
+ target = target || first;
+ target.scrollIntoView({block:'start', behavior: htmx.config.scrollBehavior});
+ }
+ if (swapSpec.show === "bottom" && (last || target)) {
+ target = target || last;
+ target.scrollIntoView({block:'end', behavior: htmx.config.scrollBehavior});
+ }
+ }
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {string} attr
+ * @param {boolean=} evalAsDefault
+ * @param {Object=} values
+ * @returns {Object}
+ */
+ function getValuesForElement(elt, attr, evalAsDefault, values) {
+ if (values == null) {
+ values = {};
+ }
+ if (elt == null) {
+ return values;
+ }
+ var attributeValue = getAttributeValue(elt, attr);
+ if (attributeValue) {
+ var str = attributeValue.trim();
+ var evaluateValue = evalAsDefault;
+ if (str === "unset") {
+ return null;
+ }
+ if (str.indexOf("javascript:") === 0) {
+ str = str.substr(11);
+ evaluateValue = true;
+ } else if (str.indexOf("js:") === 0) {
+ str = str.substr(3);
+ evaluateValue = true;
+ }
+ if (str.indexOf('{') !== 0) {
+ str = "{" + str + "}";
+ }
+ var varsValues;
+ if (evaluateValue) {
+ varsValues = maybeEval(elt,function () {return Function("return (" + str + ")")();}, {});
+ } else {
+ varsValues = parseJSON(str);
+ }
+ for (var key in varsValues) {
+ if (varsValues.hasOwnProperty(key)) {
+ if (values[key] == null) {
+ values[key] = varsValues[key];
+ }
+ }
+ }
+ }
+ return getValuesForElement(parentElt(elt), attr, evalAsDefault, values);
+ }
+
+ function maybeEval(elt, toEval, defaultVal) {
+ if (htmx.config.allowEval) {
+ return toEval();
+ } else {
+ triggerErrorEvent(elt, 'htmx:evalDisallowedError');
+ return defaultVal;
+ }
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {*} expressionVars
+ * @returns
+ */
+ function getHXVarsForElement(elt, expressionVars) {
+ return getValuesForElement(elt, "hx-vars", true, expressionVars);
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @param {*} expressionVars
+ * @returns
+ */
+ function getHXValsForElement(elt, expressionVars) {
+ return getValuesForElement(elt, "hx-vals", false, expressionVars);
+ }
+
+ /**
+ * @param {HTMLElement} elt
+ * @returns {Object}
+ */
+ function getExpressionVars(elt) {
+ return mergeObjects(getHXVarsForElement(elt), getHXValsForElement(elt));
+ }
+
+ function safelySetHeaderValue(xhr, header, headerValue) {
+ if (headerValue !== null) {
+ try {
+ xhr.setRequestHeader(header, headerValue);
+ } catch (e) {
+ // On an exception, try to set the header URI encoded instead
+ xhr.setRequestHeader(header, encodeURIComponent(headerValue));
+ xhr.setRequestHeader(header + "-URI-AutoEncoded", "true");
+ }
+ }
+ }
+
+ function getPathFromResponse(xhr) {
+ // NB: IE11 does not support this stuff
+ if (xhr.responseURL && typeof(URL) !== "undefined") {
+ try {
+ var url = new URL(xhr.responseURL);
+ return url.pathname + url.search;
+ } catch (e) {
+ triggerErrorEvent(getDocument().body, "htmx:badResponseUrl", {url: xhr.responseURL});
+ }
+ }
+ }
+
+ function hasHeader(xhr, regexp) {
+ return xhr.getAllResponseHeaders().match(regexp);
+ }
+
+ function ajaxHelper(verb, path, context) {
+ verb = verb.toLowerCase();
+ if (context) {
+ if (context instanceof Element || isType(context, 'String')) {
+ return issueAjaxRequest(verb, path, null, null, {
+ targetOverride: resolveTarget(context),
+ returnPromise: true
+ });
+ } else {
+ return issueAjaxRequest(verb, path, resolveTarget(context.source), context.event,
+ {
+ handler : context.handler,
+ headers : context.headers,
+ values : context.values,
+ targetOverride: resolveTarget(context.target),
+ swapOverride: context.swap,
+ returnPromise: true
+ });
+ }
+ } else {
+ return issueAjaxRequest(verb, path, null, null, {
+ returnPromise: true
+ });
+ }
+ }
+
+ function hierarchyForElt(elt) {
+ var arr = [];
+ while (elt) {
+ arr.push(elt);
+ elt = elt.parentElement;
+ }
+ return arr;
+ }
+
+ function issueAjaxRequest(verb, path, elt, event, etc, confirmed) {
+ var resolve = null;
+ var reject = null;
+ etc = etc != null ? etc : {};
+ if(etc.returnPromise && typeof Promise !== "undefined"){
+ var promise = new Promise(function (_resolve, _reject) {
+ resolve = _resolve;
+ reject = _reject;
+ });
+ }
+ if(elt == null) {
+ elt = getDocument().body;
+ }
+ var responseHandler = etc.handler || handleAjaxResponse;
+
+ if (!bodyContains(elt)) {
+ return; // do not issue requests for elements removed from the DOM
+ }
+ var target = etc.targetOverride || getTarget(elt);
+ if (target == null || target == DUMMY_ELT) {
+ triggerErrorEvent(elt, 'htmx:targetError', {target: getAttributeValue(elt, "hx-target")});
+ return;
+ }
+
+ // allow event-based confirmation w/ a callback
+ if (!confirmed) {
+ var issueRequest = function() {
+ return issueAjaxRequest(verb, path, elt, event, etc, true);
+ }
+ var confirmDetails = {target: target, elt: elt, path: path, verb: verb, triggeringEvent: event, etc: etc, issueRequest: issueRequest};
+ if (triggerEvent(elt, 'htmx:confirm', confirmDetails) === false) {
+ return;
+ }
+ }
+
+ var syncElt = elt;
+ var eltData = getInternalData(elt);
+ var syncStrategy = getClosestAttributeValue(elt, "hx-sync");
+ var queueStrategy = null;
+ var abortable = false;
+ if (syncStrategy) {
+ var syncStrings = syncStrategy.split(":");
+ var selector = syncStrings[0].trim();
+ if (selector === "this") {
+ syncElt = findThisElement(elt, 'hx-sync');
+ } else {
+ syncElt = querySelectorExt(elt, selector);
+ }
+ // default to the drop strategy
+ syncStrategy = (syncStrings[1] || 'drop').trim();
+ eltData = getInternalData(syncElt);
+ if (syncStrategy === "drop" && eltData.xhr && eltData.abortable !== true) {
+ return;
+ } else if (syncStrategy === "abort") {
+ if (eltData.xhr) {
+ return;
+ } else {
+ abortable = true;
+ }
+ } else if (syncStrategy === "replace") {
+ triggerEvent(syncElt, 'htmx:abort'); // abort the current request and continue
+ } else if (syncStrategy.indexOf("queue") === 0) {
+ var queueStrArray = syncStrategy.split(" ");
+ queueStrategy = (queueStrArray[1] || "last").trim();
+ }
+ }
+
+ if (eltData.xhr) {
+ if (eltData.abortable) {
+ triggerEvent(syncElt, 'htmx:abort'); // abort the current request and continue
+ } else {
+ if(queueStrategy == null){
+ if (event) {
+ var eventData = getInternalData(event);
+ if (eventData && eventData.triggerSpec && eventData.triggerSpec.queue) {
+ queueStrategy = eventData.triggerSpec.queue;
+ }
+ }
+ if (queueStrategy == null) {
+ queueStrategy = "last";
+ }
+ }
+ if (eltData.queuedRequests == null) {
+ eltData.queuedRequests = [];
+ }
+ if (queueStrategy === "first" && eltData.queuedRequests.length === 0) {
+ eltData.queuedRequests.push(function () {
+ issueAjaxRequest(verb, path, elt, event, etc)
+ });
+ } else if (queueStrategy === "all") {
+ eltData.queuedRequests.push(function () {
+ issueAjaxRequest(verb, path, elt, event, etc)
+ });
+ } else if (queueStrategy === "last") {
+ eltData.queuedRequests = []; // dump existing queue
+ eltData.queuedRequests.push(function () {
+ issueAjaxRequest(verb, path, elt, event, etc)
+ });
+ }
+ return;
+ }
+ }
+
+ var xhr = new XMLHttpRequest();
+ eltData.xhr = xhr;
+ eltData.abortable = abortable;
+ var endRequestLock = function(){
+ eltData.xhr = null;
+ eltData.abortable = false;
+ if (eltData.queuedRequests != null &&
+ eltData.queuedRequests.length > 0) {
+ var queuedRequest = eltData.queuedRequests.shift();
+ queuedRequest();
+ }
+ }
+ var promptQuestion = getClosestAttributeValue(elt, "hx-prompt");
+ if (promptQuestion) {
+ var promptResponse = prompt(promptQuestion);
+ // prompt returns null if cancelled and empty string if accepted with no entry
+ if (promptResponse === null ||
+ !triggerEvent(elt, 'htmx:prompt', {prompt: promptResponse, target:target})) {
+ maybeCall(resolve);
+ endRequestLock();
+ return promise;
+ }
+ }
+
+ var confirmQuestion = getClosestAttributeValue(elt, "hx-confirm");
+ if (confirmQuestion) {
+ if(!confirm(confirmQuestion)) {
+ maybeCall(resolve);
+ endRequestLock()
+ return promise;
+ }
+ }
+
+
+ var headers = getHeaders(elt, target, promptResponse);
+ if (etc.headers) {
+ headers = mergeObjects(headers, etc.headers);
+ }
+ var results = getInputValues(elt, verb);
+ var errors = results.errors;
+ var rawParameters = results.values;
+ if (etc.values) {
+ rawParameters = mergeObjects(rawParameters, etc.values);
+ }
+ var expressionVars = getExpressionVars(elt);
+ var allParameters = mergeObjects(rawParameters, expressionVars);
+ var filteredParameters = filterValues(allParameters, elt);
+
+ if (verb !== 'get' && !usesFormData(elt)) {
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
+ }
+
+ if (htmx.config.getCacheBusterParam && verb === 'get') {
+ filteredParameters['org.htmx.cache-buster'] = getRawAttribute(target, "id") || "true";
+ }
+
+ // behavior of anchors w/ empty href is to use the current URL
+ if (path == null || path === "") {
+ path = getDocument().location.href;
+ }
+
+
+ var requestAttrValues = getValuesForElement(elt, 'hx-request');
+
+ var eltIsBoosted = getInternalData(elt).boosted;
+ var requestConfig = {
+ boosted: eltIsBoosted,
+ parameters: filteredParameters,
+ unfilteredParameters: allParameters,
+ headers:headers,
+ target:target,
+ verb:verb,
+ errors:errors,
+ withCredentials: etc.credentials || requestAttrValues.credentials || htmx.config.withCredentials,
+ timeout: etc.timeout || requestAttrValues.timeout || htmx.config.timeout,
+ path:path,
+ triggeringEvent:event
+ };
+
+ if(!triggerEvent(elt, 'htmx:configRequest', requestConfig)){
+ maybeCall(resolve);
+ endRequestLock();
+ return promise;
+ }
+
+ // copy out in case the object was overwritten
+ path = requestConfig.path;
+ verb = requestConfig.verb;
+ headers = requestConfig.headers;
+ filteredParameters = requestConfig.parameters;
+ errors = requestConfig.errors;
+
+ if(errors && errors.length > 0){
+ triggerEvent(elt, 'htmx:validation:halted', requestConfig)
+ maybeCall(resolve);
+ endRequestLock();
+ return promise;
+ }
+
+ var splitPath = path.split("#");
+ var pathNoAnchor = splitPath[0];
+ var anchor = splitPath[1];
+ var finalPathForGet = null;
+ if (verb === 'get') {
+ finalPathForGet = pathNoAnchor;
+ var values = Object.keys(filteredParameters).length !== 0;
+ if (values) {
+ if (finalPathForGet.indexOf("?") < 0) {
+ finalPathForGet += "?";
+ } else {
+ finalPathForGet += "&";
+ }
+ finalPathForGet += urlEncode(filteredParameters);
+ if (anchor) {
+ finalPathForGet += "#" + anchor;
+ }
+ }
+ xhr.open('GET', finalPathForGet, true);
+ } else {
+ xhr.open(verb.toUpperCase(), path, true);
+ }
+
+ xhr.overrideMimeType("text/html");
+ xhr.withCredentials = requestConfig.withCredentials;
+ xhr.timeout = requestConfig.timeout;
+
+ // request headers
+ if (requestAttrValues.noHeaders) {
+ // ignore all headers
+ } else {
+ for (var header in headers) {
+ if (headers.hasOwnProperty(header)) {
+ var headerValue = headers[header];
+ safelySetHeaderValue(xhr, header, headerValue);
+ }
+ }
+ }
+
+ var responseInfo = {
+ xhr: xhr, target: target, requestConfig: requestConfig, etc: etc, boosted: eltIsBoosted,
+ pathInfo: {
+ requestPath: path,
+ finalRequestPath: finalPathForGet || path,
+ anchor: anchor
+ }
+ };
+
+ xhr.onload = function () {
+ try {
+ var hierarchy = hierarchyForElt(elt);
+ responseInfo.pathInfo.responsePath = getPathFromResponse(xhr);
+ responseHandler(elt, responseInfo);
+ removeRequestIndicatorClasses(indicators);
+ triggerEvent(elt, 'htmx:afterRequest', responseInfo);
+ triggerEvent(elt, 'htmx:afterOnLoad', responseInfo);
+ // if the body no longer contains the element, trigger the event on the closest parent
+ // remaining in the DOM
+ if (!bodyContains(elt)) {
+ var secondaryTriggerElt = null;
+ while (hierarchy.length > 0 && secondaryTriggerElt == null) {
+ var parentEltInHierarchy = hierarchy.shift();
+ if (bodyContains(parentEltInHierarchy)) {
+ secondaryTriggerElt = parentEltInHierarchy;
+ }
+ }
+ if (secondaryTriggerElt) {
+ triggerEvent(secondaryTriggerElt, 'htmx:afterRequest', responseInfo);
+ triggerEvent(secondaryTriggerElt, 'htmx:afterOnLoad', responseInfo);
+ }
+ }
+ maybeCall(resolve);
+ endRequestLock();
+ } catch (e) {
+ triggerErrorEvent(elt, 'htmx:onLoadError', mergeObjects({error:e}, responseInfo));
+ throw e;
+ }
+ }
+ xhr.onerror = function () {
+ removeRequestIndicatorClasses(indicators);
+ triggerErrorEvent(elt, 'htmx:afterRequest', responseInfo);
+ triggerErrorEvent(elt, 'htmx:sendError', responseInfo);
+ maybeCall(reject);
+ endRequestLock();
+ }
+ xhr.onabort = function() {
+ removeRequestIndicatorClasses(indicators);
+ triggerErrorEvent(elt, 'htmx:afterRequest', responseInfo);
+ triggerErrorEvent(elt, 'htmx:sendAbort', responseInfo);
+ maybeCall(reject);
+ endRequestLock();
+ }
+ xhr.ontimeout = function() {
+ removeRequestIndicatorClasses(indicators);
+ triggerErrorEvent(elt, 'htmx:afterRequest', responseInfo);
+ triggerErrorEvent(elt, 'htmx:timeout', responseInfo);
+ maybeCall(reject);
+ endRequestLock();
+ }
+ if(!triggerEvent(elt, 'htmx:beforeRequest', responseInfo)){
+ maybeCall(resolve);
+ endRequestLock()
+ return promise
+ }
+ var indicators = addRequestIndicatorClasses(elt);
+
+ forEach(['loadstart', 'loadend', 'progress', 'abort'], function(eventName) {
+ forEach([xhr, xhr.upload], function (target) {
+ target.addEventListener(eventName, function(event){
+ triggerEvent(elt, "htmx:xhr:" + eventName, {
+ lengthComputable:event.lengthComputable,
+ loaded:event.loaded,
+ total:event.total
+ });
+ })
+ });
+ });
+ triggerEvent(elt, 'htmx:beforeSend', responseInfo);
+ xhr.send(verb === 'get' ? null : encodeParamsForBody(xhr, elt, filteredParameters));
+ return promise;
+ }
+
+ function determineHistoryUpdates(elt, responseInfo) {
+
+ var xhr = responseInfo.xhr;
+
+ //===========================================
+ // First consult response headers
+ //===========================================
+ var pathFromHeaders = null;
+ var typeFromHeaders = null;
+ if (hasHeader(xhr,/HX-Push:/i)) {
+ pathFromHeaders = xhr.getResponseHeader("HX-Push");
+ typeFromHeaders = "push";
+ } else if (hasHeader(xhr,/HX-Push-Url:/i)) {
+ pathFromHeaders = xhr.getResponseHeader("HX-Push-Url");
+ typeFromHeaders = "push";
+ } else if (hasHeader(xhr,/HX-Replace-Url:/i)) {
+ pathFromHeaders = xhr.getResponseHeader("HX-Replace-Url");
+ typeFromHeaders = "replace";
+ }
+
+ // if there was a response header, that has priority
+ if (pathFromHeaders) {
+ if (pathFromHeaders === "false") {
+ return {}
+ } else {
+ return {
+ type: typeFromHeaders,
+ path : pathFromHeaders
+ }
+ }
+ }
+
+ //===========================================
+ // Next resolve via DOM values
+ //===========================================
+ var requestPath = responseInfo.pathInfo.finalRequestPath;
+ var responsePath = responseInfo.pathInfo.responsePath;
+
+ var pushUrl = getClosestAttributeValue(elt, "hx-push-url");
+ var replaceUrl = getClosestAttributeValue(elt, "hx-replace-url");
+ var elementIsBoosted = getInternalData(elt).boosted;
+
+ var saveType = null;
+ var path = null;
+
+ if (pushUrl) {
+ saveType = "push";
+ path = pushUrl;
+ } else if (replaceUrl) {
+ saveType = "replace";
+ path = replaceUrl;
+ } else if (elementIsBoosted) {
+ saveType = "push";
+ path = responsePath || requestPath; // if there is no response path, go with the original request path
+ }
+
+ if (path) {
+ // false indicates no push, return empty object
+ if (path === "false") {
+ return {};
+ }
+
+ // true indicates we want to follow wherever the server ended up sending us
+ if (path === "true") {
+ path = responsePath || requestPath; // if there is no response path, go with the original request path
+ }
+
+ // restore any anchor associated with the request
+ if (responseInfo.pathInfo.anchor &&
+ path.indexOf("#") === -1) {
+ path = path + "#" + responseInfo.pathInfo.anchor;
+ }
+
+ return {
+ type:saveType,
+ path: path
+ }
+ } else {
+ return {};
+ }
+ }
+
+ function handleAjaxResponse(elt, responseInfo) {
+ var xhr = responseInfo.xhr;
+ var target = responseInfo.target;
+ var etc = responseInfo.etc;
+
+ if (!triggerEvent(elt, 'htmx:beforeOnLoad', responseInfo)) return;
+
+ if (hasHeader(xhr, /HX-Trigger:/i)) {
+ handleTrigger(xhr, "HX-Trigger", elt);
+ }
+
+ if (hasHeader(xhr, /HX-Location:/i)) {
+ saveCurrentPageToHistory();
+ var redirectPath = xhr.getResponseHeader("HX-Location");
+ var swapSpec;
+ if (redirectPath.indexOf("{") === 0) {
+ swapSpec = parseJSON(redirectPath);
+ // what's the best way to throw an error if the user didn't include this
+ redirectPath = swapSpec['path'];
+ delete swapSpec['path'];
+ }
+ ajaxHelper('GET', redirectPath, swapSpec).then(function(){
+ pushUrlIntoHistory(redirectPath);
+ });
+ return;
+ }
+
+ if (hasHeader(xhr, /HX-Redirect:/i)) {
+ location.href = xhr.getResponseHeader("HX-Redirect");
+ return;
+ }
+
+ if (hasHeader(xhr,/HX-Refresh:/i)) {
+ if ("true" === xhr.getResponseHeader("HX-Refresh")) {
+ location.reload();
+ return;
+ }
+ }
+
+ if (hasHeader(xhr,/HX-Retarget:/i)) {
+ responseInfo.target = getDocument().querySelector(xhr.getResponseHeader("HX-Retarget"));
+ }
+
+ var historyUpdate = determineHistoryUpdates(elt, responseInfo);
+
+ // by default htmx only swaps on 200 return codes and does not swap
+ // on 204 'No Content'
+ // this can be ovverriden by responding to the htmx:beforeSwap event and
+ // overriding the detail.shouldSwap property
+ var shouldSwap = xhr.status >= 200 && xhr.status < 400 && xhr.status !== 204;
+ var serverResponse = xhr.response;
+ var isError = xhr.status >= 400;
+ var beforeSwapDetails = mergeObjects({shouldSwap: shouldSwap, serverResponse:serverResponse, isError:isError}, responseInfo);
+ if (!triggerEvent(target, 'htmx:beforeSwap', beforeSwapDetails)) return;
+
+ target = beforeSwapDetails.target; // allow re-targeting
+ serverResponse = beforeSwapDetails.serverResponse; // allow updating content
+ isError = beforeSwapDetails.isError; // allow updating error
+
+ responseInfo.target = target; // Make updated target available to response events
+ responseInfo.failed = isError; // Make failed property available to response events
+ responseInfo.successful = !isError; // Make successful property available to response events
+
+ if (beforeSwapDetails.shouldSwap) {
+ if (xhr.status === 286) {
+ cancelPolling(elt);
+ }
+
+ withExtensions(elt, function (extension) {
+ serverResponse = extension.transformResponse(serverResponse, xhr, elt);
+ });
+
+ // Save current page if there will be a history update
+ if (historyUpdate.type) {
+ saveCurrentPageToHistory();
+ }
+
+ var swapOverride = etc.swapOverride;
+ if (hasHeader(xhr,/HX-Reswap:/i)) {
+ swapOverride = xhr.getResponseHeader("HX-Reswap");
+ }
+ var swapSpec = getSwapSpecification(elt, swapOverride);
+
+ target.classList.add(htmx.config.swappingClass);
+
+ // optional transition API promise callbacks
+ var settleResolve = null;
+ var settleReject = null;
+
+ var doSwap = function () {
+ try {
+ var activeElt = document.activeElement;
+ var selectionInfo = {};
+ try {
+ selectionInfo = {
+ elt: activeElt,
+ // @ts-ignore
+ start: activeElt ? activeElt.selectionStart : null,
+ // @ts-ignore
+ end: activeElt ? activeElt.selectionEnd : null
+ };
+ } catch (e) {
+ // safari issue - see https://github.com/microsoft/playwright/issues/5894
+ }
+
+ var settleInfo = makeSettleInfo(target);
+ selectAndSwap(swapSpec.swapStyle, target, elt, serverResponse, settleInfo);
+
+ if (selectionInfo.elt &&
+ !bodyContains(selectionInfo.elt) &&
+ selectionInfo.elt.id) {
+ var newActiveElt = document.getElementById(selectionInfo.elt.id);
+ var focusOptions = { preventScroll: swapSpec.focusScroll !== undefined ? !swapSpec.focusScroll : !htmx.config.defaultFocusScroll };
+ if (newActiveElt) {
+ // @ts-ignore
+ if (selectionInfo.start && newActiveElt.setSelectionRange) {
+ // @ts-ignore
+ try {
+ newActiveElt.setSelectionRange(selectionInfo.start, selectionInfo.end);
+ } catch (e) {
+ // the setSelectionRange method is present on fields that don't support it, so just let this fail
+ }
+ }
+ newActiveElt.focus(focusOptions);
+ }
+ }
+
+ target.classList.remove(htmx.config.swappingClass);
+ forEach(settleInfo.elts, function (elt) {
+ if (elt.classList) {
+ elt.classList.add(htmx.config.settlingClass);
+ }
+ triggerEvent(elt, 'htmx:afterSwap', responseInfo);
+ });
+
+ if (hasHeader(xhr, /HX-Trigger-After-Swap:/i)) {
+ var finalElt = elt;
+ if (!bodyContains(elt)) {
+ finalElt = getDocument().body;
+ }
+ handleTrigger(xhr, "HX-Trigger-After-Swap", finalElt);
+ }
+
+ var doSettle = function () {
+ forEach(settleInfo.tasks, function (task) {
+ task.call();
+ });
+ forEach(settleInfo.elts, function (elt) {
+ if (elt.classList) {
+ elt.classList.remove(htmx.config.settlingClass);
+ }
+ triggerEvent(elt, 'htmx:afterSettle', responseInfo);
+ });
+
+ // if we need to save history, do so
+ if (historyUpdate.type) {
+ if (historyUpdate.type === "push") {
+ pushUrlIntoHistory(historyUpdate.path);
+ triggerEvent(getDocument().body, 'htmx:pushedIntoHistory', {path: historyUpdate.path});
+ } else {
+ replaceUrlInHistory(historyUpdate.path);
+ triggerEvent(getDocument().body, 'htmx:replacedInHistory', {path: historyUpdate.path});
+ }
+ }
+ if (responseInfo.pathInfo.anchor) {
+ var anchorTarget = find("#" + responseInfo.pathInfo.anchor);
+ if(anchorTarget) {
+ anchorTarget.scrollIntoView({block:'start', behavior: "auto"});
+ }
+ }
+
+ if(settleInfo.title) {
+ var titleElt = find("title");
+ if(titleElt) {
+ titleElt.innerHTML = settleInfo.title;
+ } else {
+ window.document.title = settleInfo.title;
+ }
+ }
+
+ updateScrollState(settleInfo.elts, swapSpec);
+
+ if (hasHeader(xhr, /HX-Trigger-After-Settle:/i)) {
+ var finalElt = elt;
+ if (!bodyContains(elt)) {
+ finalElt = getDocument().body;
+ }
+ handleTrigger(xhr, "HX-Trigger-After-Settle", finalElt);
+ }
+ maybeCall(settleResolve);
+ }
+
+ if (swapSpec.settleDelay > 0) {
+ setTimeout(doSettle, swapSpec.settleDelay)
+ } else {
+ doSettle();
+ }
+ } catch (e) {
+ triggerErrorEvent(elt, 'htmx:swapError', responseInfo);
+ maybeCall(settleReject);
+ throw e;
+ }
+ };
+
+ var shouldTransition = htmx.config.globalViewTransitions
+ if(swapSpec.hasOwnProperty('transition')){
+ shouldTransition = swapSpec.transition;
+ }
+
+ if(shouldTransition &&
+ triggerEvent(elt, 'htmx:beforeTransition', responseInfo) &&
+ typeof Promise !== "undefined" && document.startViewTransition){
+ var settlePromise = new Promise(function (_resolve, _reject) {
+ settleResolve = _resolve;
+ settleReject = _reject;
+ });
+ // wrap the original doSwap() in a call to startViewTransition()
+ var innerDoSwap = doSwap;
+ doSwap = function() {
+ document.startViewTransition(function () {
+ innerDoSwap();
+ return settlePromise;
+ });
+ }
+ }
+
+
+ if (swapSpec.swapDelay > 0) {
+ setTimeout(doSwap, swapSpec.swapDelay)
+ } else {
+ doSwap();
+ }
+ }
+ if (isError) {
+ triggerErrorEvent(elt, 'htmx:responseError', mergeObjects({error: "Response Status Error Code " + xhr.status + " from " + responseInfo.pathInfo.requestPath}, responseInfo));
+ }
+ }
+
+ //====================================================================
+ // Extensions API
+ //====================================================================
+
+ /** @type {Object<string, import("./htmx").HtmxExtension>} */
+ var extensions = {};
+
+ /**
+ * extensionBase defines the default functions for all extensions.
+ * @returns {import("./htmx").HtmxExtension}
+ */
+ function extensionBase() {
+ return {
+ init: function(api) {return null;},
+ onEvent : function(name, evt) {return true;},
+ transformResponse : function(text, xhr, elt) {return text;},
+ isInlineSwap : function(swapStyle) {return false;},
+ handleSwap : function(swapStyle, target, fragment, settleInfo) {return false;},
+ encodeParameters : function(xhr, parameters, elt) {return null;}
+ }
+ }
+
+ /**
+ * defineExtension initializes the extension and adds it to the htmx registry
+ *
+ * @param {string} name
+ * @param {import("./htmx").HtmxExtension} extension
+ */
+ function defineExtension(name, extension) {
+ if(extension.init) {
+ extension.init(internalAPI)
+ }
+ extensions[name] = mergeObjects(extensionBase(), extension);
+ }
+
+ /**
+ * removeExtension removes an extension from the htmx registry
+ *
+ * @param {string} name
+ */
+ function removeExtension(name) {
+ delete extensions[name];
+ }
+
+ /**
+ * getExtensions searches up the DOM tree to return all extensions that can be applied to a given element
+ *
+ * @param {HTMLElement} elt
+ * @param {import("./htmx").HtmxExtension[]=} extensionsToReturn
+ * @param {import("./htmx").HtmxExtension[]=} extensionsToIgnore
+ */
+ function getExtensions(elt, extensionsToReturn, extensionsToIgnore) {
+
+ if (elt == undefined) {
+ return extensionsToReturn;
+ }
+ if (extensionsToReturn == undefined) {
+ extensionsToReturn = [];
+ }
+ if (extensionsToIgnore == undefined) {
+ extensionsToIgnore = [];
+ }
+ var extensionsForElement = getAttributeValue(elt, "hx-ext");
+ if (extensionsForElement) {
+ forEach(extensionsForElement.split(","), function(extensionName){
+ extensionName = extensionName.replace(/ /g, '');
+ if (extensionName.slice(0, 7) == "ignore:") {
+ extensionsToIgnore.push(extensionName.slice(7));
+ return;
+ }
+ if (extensionsToIgnore.indexOf(extensionName) < 0) {
+ var extension = extensions[extensionName];
+ if (extension && extensionsToReturn.indexOf(extension) < 0) {
+ extensionsToReturn.push(extension);
+ }
+ }
+ });
+ }
+ return getExtensions(parentElt(elt), extensionsToReturn, extensionsToIgnore);
+ }
+
+ //====================================================================
+ // Initialization
+ //====================================================================
+
+ function ready(fn) {
+ if (getDocument().readyState !== 'loading') {
+ fn();
+ } else {
+ getDocument().addEventListener('DOMContentLoaded', fn);
+ }
+ }
+
+ function insertIndicatorStyles() {
+ if (htmx.config.includeIndicatorStyles !== false) {
+ getDocument().head.insertAdjacentHTML("beforeend",
+ "<style>\
+ ." + htmx.config.indicatorClass + "{opacity:0;transition: opacity 200ms ease-in;}\
+ ." + htmx.config.requestClass + " ." + htmx.config.indicatorClass + "{opacity:1}\
+ ." + htmx.config.requestClass + "." + htmx.config.indicatorClass + "{opacity:1}\
+ </style>");
+ }
+ }
+
+ function getMetaConfig() {
+ var element = getDocument().querySelector('meta[name="htmx-config"]');
+ if (element) {
+ // @ts-ignore
+ return parseJSON(element.content);
+ } else {
+ return null;
+ }
+ }
+
+ function mergeMetaConfig() {
+ var metaConfig = getMetaConfig();
+ if (metaConfig) {
+ htmx.config = mergeObjects(htmx.config , metaConfig)
+ }
+ }
+
+ // initialize the document
+ ready(function () {
+ mergeMetaConfig();
+ insertIndicatorStyles();
+ var body = getDocument().body;
+ processNode(body);
+ var restoredElts = getDocument().querySelectorAll(
+ "[hx-trigger='restored'],[data-hx-trigger='restored']"
+ );
+ body.addEventListener("htmx:abort", function (evt) {
+ var target = evt.target;
+ var internalData = getInternalData(target);
+ if (internalData && internalData.xhr) {
+ internalData.xhr.abort();
+ }
+ });
+ var originalPopstate = window.onpopstate;
+ window.onpopstate = function (event) {
+ if (event.state && event.state.htmx) {
+ restoreHistory();
+ forEach(restoredElts, function(elt){
+ triggerEvent(elt, 'htmx:restored', {
+ 'document': getDocument(),
+ 'triggerEvent': triggerEvent
+ });
+ });
+ } else {
+ if (originalPopstate) {
+ originalPopstate(event);
+ }
+ }
+ };
+ setTimeout(function () {
+ triggerEvent(body, 'htmx:load', {}); // give ready handlers a chance to load up before firing this event
+ body = null; // kill reference for gc
+ }, 0);
+ })
+
+ return htmx;
+ }
+)()
+}));
diff --git a/lib/RT/Interface/Web.pm b/lib/RT/Interface/Web.pm
index 551ad4af73..f009448850 100644
--- a/lib/RT/Interface/Web.pm
+++ b/lib/RT/Interface/Web.pm
@@ -153,6 +153,7 @@ sub JSFiles {
chartjs-plugin-colorschemes.min.js
jquery.jgrowl.min.js
clipboard.min.js
+ htmx.min.js
}, RT->Config->Get('JSFiles');
}

diff --git a/share/static/js/htmx.min.js b/share/static/js/htmx.min.js
new file mode 100644
index 0000000000..f889d0ea52
--- /dev/null
+++ b/share/static/js/htmx.min.js
@@ -0,0 +1 @@
+(function(e,t){if(typeof define==="function"&&define.amd){define([],t)}else if(typeof module==="object"&&module.exports){module.exports=t()}else{e.htmx=e.htmx||t()}})(typeof self!=="undefined"?self:this,function(){return function(){"use strict";var z={onLoad:t,process:Tt,on:le,off:ue,trigger:ie,ajax:dr,find:b,findAll:f,closest:d,values:function(e,t){var r=Jt(e,t||"post");return r.values},remove:B,addClass:j,removeClass:n,toggleClass:U,takeClass:V,defineExtension:yr,removeExtension:br,logAll:F,logger:null,config:{historyEnabled:true,historyCacheSize:10,refreshOnHistoryMiss:false,defaultSwapStyle:"innerHTML",defaultSwapDelay:0,defaultSettleDelay:20,includeIndicatorStyles:true,indicatorClass:"htmx-indicator",requestClass:"htmx-request",addedClass:"htmx-added",settlingClass:"htmx-settling",swappingClass:"htmx-swapping",allowEval:true,inlineScriptNonce:"",attributesToSettle:["class","style","width","height"],withCredentials:false,timeout:0,wsReconnectDelay:"full-jitter",wsBinaryType:"blo
b",disableSelector:"[hx-disable], [data-hx-disable]",useTemplateFragments:false,scrollBehavior:"smooth",defaultFocusScroll:false,getCacheBusterParam:false,globalViewTransitions:false},parseInterval:v,_:e,createEventSource:function(e){return new EventSource(e,{withCredentials:true})},createWebSocket:function(e){var t=new WebSocket(e,[]);t.binaryType=z.config.wsBinaryType;return t},version:"1.9.2"};var C={addTriggerHandler:xt,bodyContains:ee,canAccessLocalStorage:D,filterValues:er,hasAttribute:q,getAttributeValue:G,getClosestMatch:c,getExpressionVars:fr,getHeaders:Qt,getInputValues:Jt,getInternalData:Y,getSwapSpecification:rr,getTriggerSpecs:ze,getTarget:de,makeFragment:l,mergeObjects:te,makeSettleInfo:S,oobSwap:me,selectAndSwap:Me,settleImmediately:Bt,shouldCancel:Ke,triggerEvent:ie,triggerErrorEvent:ne,withExtensions:w};var R=["get","post","put","delete","patch"];var O=R.map(function(e){return"[hx-"+e+"], [data-hx-"+e+"]"}).join(", ");function v(e){if(e==undefined){return undefined}
if(e.slice(-2)=="ms"){return parseFloat(e.slice(0,-2))||undefined}if(e.slice(-1)=="s"){return parseFloat(e.slice(0,-1))*1e3||undefined}if(e.slice(-1)=="m"){return parseFloat(e.slice(0,-1))*1e3*60||undefined}return parseFloat(e)||undefined}function $(e,t){return e.getAttribute&&e.getAttribute(t)}function q(e,t){return e.hasAttribute&&(e.hasAttribute(t)||e.hasAttribute("data-"+t))}function G(e,t){return $(e,t)||$(e,"data-"+t)}function u(e){return e.parentElement}function J(){return document}function c(e,t){while(e&&!t(e)){e=u(e)}return e?e:null}function T(e,t,r){var n=G(t,r);var i=G(t,"hx-disinherit");if(e!==t&&i&&(i==="*"||i.split(" ").indexOf(r)>=0)){return"unset"}else{return n}}function Z(t,r){var n=null;c(t,function(e){return n=T(t,e,r)});if(n!=="unset"){return n}}function h(e,t){var r=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.webkitMatchesSelector||e.oMatchesSelector;return r&&r.call(e,t)}function H(e){var t=/<([a-z][^\/\0>\x20\t\r\n\f]*)/i;var r=
t.exec(e);if(r){return r[1].toLowerCase()}else{return""}}function i(e,t){var r=new DOMParser;var n=r.parseFromString(e,"text/html");var i=n.body;while(t>0){t--;i=i.firstChild}if(i==null){i=J().createDocumentFragment()}return i}function L(e){return e.match(/<body/)}function l(e){var t=!L(e);if(z.config.useTemplateFragments&&t){var r=i("<body><template>"+e+"</template></body>",0);return r.querySelector("template").content}else{var n=H(e);switch(n){case"thead":case"tbody":case"tfoot":case"colgroup":case"caption":return i("<table>"+e+"</table>",1);case"col":return i("<table><colgroup>"+e+"</colgroup></table>",2);case"tr":return i("<table><tbody>"+e+"</tbody></table>",2);case"td":case"th":return i("<table><tbody><tr>"+e+"</tr></tbody></table>",3);case"script":return i("<div>"+e+"</div>",1);default:return i(e,0)}}}function K(e){if(e){e()}}function A(e,t){return Object.prototype.toString.call(e)==="[object "+t+"]"}function N(e){return A(e,"Function")}function I(e){return A(e,"Object")}func
tion Y(e){var t="htmx-internal-data";var r=e[t];if(!r){r=e[t]={}}return r}function k(e){var t=[];if(e){for(var r=0;r<e.length;r++){t.push(e[r])}}return t}function Q(e,t){if(e){for(var r=0;r<e.length;r++){t(e[r])}}}function P(e){var t=e.getBoundingClientRect();var r=t.top;var n=t.bottom;return r<window.innerHeight&&n>=0}function ee(e){if(e.getRootNode&&e.getRootNode()instanceof ShadowRoot){return J().body.contains(e.getRootNode().host)}else{return J().body.contains(e)}}function M(e){return e.trim().split(/\s+/)}function te(e,t){for(var r in t){if(t.hasOwnProperty(r)){e[r]=t[r]}}return e}function y(e){try{return JSON.parse(e)}catch(e){x(e);return null}}function D(){var e="htmx:localStorageTest";try{localStorage.setItem(e,e);localStorage.removeItem(e);return true}catch(e){return false}}function X(t){try{var e=new URL(t);if(e){t=e.pathname+e.search}if(!t.match("^/$")){t=t.replace(/\/+$/,"")}return t}catch(e){return t}}function e(e){return sr(J().body,function(){return eval(e)})}function
t(t){var e=z.on("htmx:load",function(e){t(e.detail.elt)});return e}function F(){z.logger=function(e,t,r){if(console){console.log(t,e,r)}}}function b(e,t){if(t){return e.querySelector(t)}else{return b(J(),e)}}function f(e,t){if(t){return e.querySelectorAll(t)}else{return f(J(),e)}}function B(e,t){e=s(e);if(t){setTimeout(function(){B(e);e=null},t)}else{e.parentElement.removeChild(e)}}function j(e,t,r){e=s(e);if(r){setTimeout(function(){j(e,t);e=null},r)}else{e.classList&&e.classList.add(t)}}function n(e,t,r){e=s(e);if(r){setTimeout(function(){n(e,t);e=null},r)}else{if(e.classList){e.classList.remove(t);if(e.classList.length===0){e.removeAttribute("class")}}}}function U(e,t){e=s(e);e.classList.toggle(t)}function V(e,t){e=s(e);Q(e.parentElement.children,function(e){n(e,t)});j(e,t)}function d(e,t){e=s(e);if(e.closest){return e.closest(t)}else{do{if(e==null||h(e,t)){return e}}while(e=e&&u(e));return null}}function r(e){var t=e.trim();if(t.startsWith("<")&&t.endsWith("/>")){return t.subst
ring(1,t.length-2)}else{return t}}function _(e,t){if(t.indexOf("closest ")===0){return[d(e,r(t.substr(8)))]}else if(t.indexOf("find ")===0){return[b(e,r(t.substr(5)))]}else if(t.indexOf("next ")===0){return[W(e,r(t.substr(5)))]}else if(t.indexOf("previous ")===0){return[oe(e,r(t.substr(9)))]}else if(t==="document"){return[document]}else if(t==="window"){return[window]}else{return J().querySelectorAll(r(t))}}var W=function(e,t){var r=J().querySelectorAll(t);for(var n=0;n<r.length;n++){var i=r[n];if(i.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_PRECEDING){return i}}};var oe=function(e,t){var r=J().querySelectorAll(t);for(var n=r.length-1;n>=0;n--){var i=r[n];if(i.compareDocumentPosition(e)===Node.DOCUMENT_POSITION_FOLLOWING){return i}}};function re(e,t){if(t){return _(e,t)[0]}else{return _(J().body,e)[0]}}function s(e){if(A(e,"String")){return b(e)}else{return e}}function se(e,t,r){if(N(t)){return{target:J().body,event:e,listener:t}}else{return{target:s(e),event:t,listener:r}}
}function le(t,r,n){Sr(function(){var e=se(t,r,n);e.target.addEventListener(e.event,e.listener)});var e=N(r);return e?r:n}function ue(t,r,n){Sr(function(){var e=se(t,r,n);e.target.removeEventListener(e.event,e.listener)});return N(r)?r:n}var fe=J().createElement("output");function ce(e,t){var r=Z(e,t);if(r){if(r==="this"){return[he(e,t)]}else{var n=_(e,r);if(n.length===0){x('The selector "'+r+'" on '+t+" returned no matches!");return[fe]}else{return n}}}}function he(e,t){return c(e,function(e){return G(e,t)!=null})}function de(e){var t=Z(e,"hx-target");if(t){if(t==="this"){return he(e,"hx-target")}else{return re(e,t)}}else{var r=Y(e);if(r.boosted){return J().body}else{return e}}}function ve(e){var t=z.config.attributesToSettle;for(var r=0;r<t.length;r++){if(e===t[r]){return true}}return false}function ge(t,r){Q(t.attributes,function(e){if(!r.hasAttribute(e.name)&&ve(e.name)){t.removeAttribute(e.name)}});Q(r.attributes,function(e){if(ve(e.name)){t.setAttribute(e.name,e.value)}})}func
tion pe(e,t){var r=wr(t);for(var n=0;n<r.length;n++){var i=r[n];try{if(i.isInlineSwap(e)){return true}}catch(e){x(e)}}return e==="outerHTML"}function me(e,i,a){var t="#"+i.id;var o="outerHTML";if(e==="true"){}else if(e.indexOf(":")>0){o=e.substr(0,e.indexOf(":"));t=e.substr(e.indexOf(":")+1,e.length)}else{o=e}var r=J().querySelectorAll(t);if(r){Q(r,function(e){var t;var r=i.cloneNode(true);t=J().createDocumentFragment();t.appendChild(r);if(!pe(o,e)){t=r}var n={shouldSwap:true,target:e,fragment:t};if(!ie(e,"htmx:oobBeforeSwap",n))return;e=n.target;if(n["shouldSwap"]){ke(o,e,e,t,a)}Q(a.elts,function(e){ie(e,"htmx:oobAfterSwap",n)})});i.parentNode.removeChild(i)}else{i.parentNode.removeChild(i);ne(J().body,"htmx:oobErrorNoTarget",{content:i})}return e}function xe(e,t,r){var n=Z(e,"hx-select-oob");if(n){var i=n.split(",");for(let e=0;e<i.length;e++){var a=i[e].split(":",2);var o=a[0].trim();if(o.indexOf("#")===0){o=o.substring(1)}var s=a[1]||"true";var l=t.querySelector("#"+o);if(l){me(
s,l,r)}}}Q(f(t,"[hx-swap-oob], [data-hx-swap-oob]"),function(e){var t=G(e,"hx-swap-oob");if(t!=null){me(t,e,r)}})}function ye(e){Q(f(e,"[hx-preserve], [data-hx-preserve]"),function(e){var t=G(e,"id");var r=J().getElementById(t);if(r!=null){e.parentNode.replaceChild(r,e)}})}function be(a,e,o){Q(e.querySelectorAll("[id]"),function(e){if(e.id&&e.id.length>0){var t=e.id.replace("'","\\'");var r=e.tagName.replace(":","\\:");var n=a.querySelector(r+"[id='"+t+"']");if(n&&n!==a){var i=e.cloneNode();ge(e,n);o.tasks.push(function(){ge(e,i)})}}})}function we(e){return function(){n(e,z.config.addedClass);Tt(e);bt(e);Se(e);ie(e,"htmx:load")}}function Se(e){var t="[autofocus]";var r=h(e,t)?e:e.querySelector(t);if(r!=null){r.focus()}}function a(e,t,r,n){be(e,r,n);while(r.childNodes.length>0){var i=r.firstChild;j(i,z.config.addedClass);e.insertBefore(i,t);if(i.nodeType!==Node.TEXT_NODE&&i.nodeType!==Node.COMMENT_NODE){n.tasks.push(we(i))}}}function Ee(e,t){var r=0;while(r<e.length){t=(t<<5)-t+e.cha
rCodeAt(r++)|0}return t}function Ce(e){var t=0;if(e.attributes){for(var r=0;r<e.attributes.length;r++){var n=e.attributes[r];if(n.value){t=Ee(n.name,t);t=Ee(n.value,t)}}}return t}function Re(t){var r=Y(t);if(r.timeout){clearTimeout(r.timeout)}if(r.webSocket){r.webSocket.close()}if(r.sseEventSource){r.sseEventSource.close()}if(r.listenerInfos){Q(r.listenerInfos,function(e){if(e.on){e.on.removeEventListener(e.trigger,e.listener)}})}if(r.onHandlers){for(let e=0;e<r.onHandlers.length;e++){const n=r.onHandlers[e];t.removeEventListener(n.name,n.handler)}}}function o(e){ie(e,"htmx:beforeCleanupElement");Re(e);if(e.children){Q(e.children,function(e){o(e)})}}function Oe(e,t,r){if(e.tagName==="BODY"){return Ne(e,t,r)}else{var n;var i=e.previousSibling;a(u(e),e,t,r);if(i==null){n=u(e).firstChild}else{n=i.nextSibling}Y(e).replacedWith=n;r.elts=[];while(n&&n!==e){if(n.nodeType===Node.ELEMENT_NODE){r.elts.push(n)}n=n.nextElementSibling}o(e);u(e).removeChild(e)}}function qe(e,t,r){return a(e,e.fir
stChild,t,r)}function Te(e,t,r){return a(u(e),e,t,r)}function He(e,t,r){return a(e,null,t,r)}function Le(e,t,r){return a(u(e),e.nextSibling,t,r)}function Ae(e,t,r){o(e);return u(e).removeChild(e)}function Ne(e,t,r){var n=e.firstChild;a(e,n,t,r);if(n){while(n.nextSibling){o(n.nextSibling);e.removeChild(n.nextSibling)}o(n);e.removeChild(n)}}function Ie(e,t){var r=Z(e,"hx-select");if(r){var n=J().createDocumentFragment();Q(t.querySelectorAll(r),function(e){n.appendChild(e)});t=n}return t}function ke(e,t,r,n,i){switch(e){case"none":return;case"outerHTML":Oe(r,n,i);return;case"afterbegin":qe(r,n,i);return;case"beforebegin":Te(r,n,i);return;case"beforeend":He(r,n,i);return;case"afterend":Le(r,n,i);return;case"delete":Ae(r,n,i);return;default:var a=wr(t);for(var o=0;o<a.length;o++){var s=a[o];try{var l=s.handleSwap(e,r,n,i);if(l){if(typeof l.length!=="undefined"){for(var u=0;u<l.length;u++){var f=l[u];if(f.nodeType!==Node.TEXT_NODE&&f.nodeType!==Node.COMMENT_NODE){i.tasks.push(we(f))}}}ret
urn}}catch(e){x(e)}}if(e==="innerHTML"){Ne(r,n,i)}else{ke(z.config.defaultSwapStyle,t,r,n,i)}}}function Pe(e){if(e.indexOf("<title")>-1){var t=e.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim,"");var r=t.match(/<title(\s[^>]*>|>)([\s\S]*?)<\/title>/im);if(r){return r[2]}}}function Me(e,t,r,n,i){i.title=Pe(n);var a=l(n);if(a){xe(r,a,i);a=Ie(r,a);ye(a);return ke(e,r,t,a,i)}}function De(e,t,r){var n=e.getResponseHeader(t);if(n.indexOf("{")===0){var i=y(n);for(var a in i){if(i.hasOwnProperty(a)){var o=i[a];if(!I(o)){o={value:o}}ie(r,a,o)}}}else{ie(r,n,[])}}var Xe=/\s/;var g=/[\s,]/;var Fe=/[_$a-zA-Z]/;var Be=/[_$a-zA-Z0-9]/;var je=['"',"'","/"];var p=/[^\s]/;function Ue(e){var t=[];var r=0;while(r<e.length){if(Fe.exec(e.charAt(r))){var n=r;while(Be.exec(e.charAt(r+1))){r++}t.push(e.substr(n,r-n+1))}else if(je.indexOf(e.charAt(r))!==-1){var i=e.charAt(r);var n=r;r++;while(r<e.length&&e.charAt(r)!==i){if(e.charAt(r)==="\\"){r++}r++}t.push(e.substr(n,r-n+1))}else{var a=e.charAt(r);t.push(a
)}r++}return t}function Ve(e,t,r){return Fe.exec(e.charAt(0))&&e!=="true"&&e!=="false"&&e!=="this"&&e!==r&&t!=="."}function _e(e,t,r){if(t[0]==="["){t.shift();var n=1;var i=" return (function("+r+"){ return (";var a=null;while(t.length>0){var o=t[0];if(o==="]"){n--;if(n===0){if(a===null){i=i+"true"}t.shift();i+=")})";try{var s=sr(e,function(){return Function(i)()},function(){return true});s.source=i;return s}catch(e){ne(J().body,"htmx:syntax:error",{error:e,source:i});return null}}}else if(o==="["){n++}if(Ve(o,a,r)){i+="(("+r+"."+o+") ? ("+r+"."+o+") : (window."+o+"))"}else{i=i+o}a=t.shift()}}}function m(e,t){var r="";while(e.length>0&&!e[0].match(t)){r+=e.shift()}return r}var We="input, textarea, select";function ze(e){var t=G(e,"hx-trigger");var r=[];if(t){var n=Ue(t);do{m(n,p);var i=n.length;var a=m(n,/[,\[\s]/);if(a!==""){if(a==="every"){var o={trigger:"every"};m(n,p);o.pollInterval=v(m(n,/[,\[\s]/));m(n,p);var s=_e(e,n,"event");if(s){o.eventFilter=s}r.push(o)}else if(a.indexOf(
"sse:")===0){r.push({trigger:"sse",sseEvent:a.substr(4)})}else{var l={trigger:a};var s=_e(e,n,"event");if(s){l.eventFilter=s}while(n.length>0&&n[0]!==","){m(n,p);var u=n.shift();if(u==="changed"){l.changed=true}else if(u==="once"){l.once=true}else if(u==="consume"){l.consume=true}else if(u==="delay"&&n[0]===":"){n.shift();l.delay=v(m(n,g))}else if(u==="from"&&n[0]===":"){n.shift();var f=m(n,g);if(f==="closest"||f==="find"||f==="next"||f==="previous"){n.shift();f+=" "+m(n,g)}l.from=f}else if(u==="target"&&n[0]===":"){n.shift();l.target=m(n,g)}else if(u==="throttle"&&n[0]===":"){n.shift();l.throttle=v(m(n,g))}else if(u==="queue"&&n[0]===":"){n.shift();l.queue=m(n,g)}else if((u==="root"||u==="threshold")&&n[0]===":"){n.shift();l[u]=m(n,g)}else{ne(e,"htmx:syntax:error",{token:n.shift()})}}r.push(l)}}if(n.length===i){ne(e,"htmx:syntax:error",{token:n.shift()})}m(n,p)}while(n[0]===","&&n.shift())}if(r.length>0){return r}else if(h(e,"form")){return[{trigger:"submit"}]}else if(h(e,'input[ty
pe="button"]')){return[{trigger:"click"}]}else if(h(e,We)){return[{trigger:"change"}]}else{return[{trigger:"click"}]}}function $e(e){Y(e).cancelled=true}function Ge(e,t,r){var n=Y(e);n.timeout=setTimeout(function(){if(ee(e)&&n.cancelled!==true){if(!Qe(r,Lt("hx:poll:trigger",{triggerSpec:r,target:e}))){t(e)}Ge(e,t,r)}},r.pollInterval)}function Je(e){return location.hostname===e.hostname&&$(e,"href")&&$(e,"href").indexOf("#")!==0}function Ze(t,r,e){if(t.tagName==="A"&&Je(t)&&(t.target===""||t.target==="_self")||t.tagName==="FORM"){r.boosted=true;var n,i;if(t.tagName==="A"){n="get";i=t.href}else{var a=$(t,"method");n=a?a.toLowerCase():"get";if(n==="get"){}i=$(t,"action")}e.forEach(function(e){et(t,function(e,t){ae(n,i,e,t)},r,e,true)})}}function Ke(e,t){if(e.type==="submit"||e.type==="click"){if(t.tagName==="FORM"){return true}if(h(t,'input[type="submit"], button')&&d(t,"form")!==null){return true}if(t.tagName==="A"&&t.href&&(t.getAttribute("href")==="#"||t.getAttribute("href").indexOf
("#")!==0)){return true}}return false}function Ye(e,t){return Y(e).boosted&&e.tagName==="A"&&t.type==="click"&&(t.ctrlKey||t.metaKey)}function Qe(e,t){var r=e.eventFilter;if(r){try{return r(t)!==true}catch(e){ne(J().body,"htmx:eventFilter:error",{error:e,source:r.source});return true}}return false}function et(i,a,e,o,s){var l=Y(i);var t;if(o.from){t=_(i,o.from)}else{t=[i]}if(o.changed){l.lastValue=i.value}Q(t,function(r){var n=function(e){if(!ee(i)){r.removeEventListener(o.trigger,n);return}if(Ye(i,e)){return}if(s||Ke(e,i)){e.preventDefault()}if(Qe(o,e)){return}var t=Y(e);t.triggerSpec=o;if(t.handledFor==null){t.handledFor=[]}if(t.handledFor.indexOf(i)<0){t.handledFor.push(i);if(o.consume){e.stopPropagation()}if(o.target&&e.target){if(!h(e.target,o.target)){return}}if(o.once){if(l.triggeredOnce){return}else{l.triggeredOnce=true}}if(o.changed){if(l.lastValue===i.value){return}else{l.lastValue=i.value}}if(l.delayed){clearTimeout(l.delayed)}if(l.throttle){return}if(o.throttle){if(!l.th
rottle){a(i,e);l.throttle=setTimeout(function(){l.throttle=null},o.throttle)}}else if(o.delay){l.delayed=setTimeout(function(){a(i,e)},o.delay)}else{ie(i,"htmx:trigger");a(i,e)}}};if(e.listenerInfos==null){e.listenerInfos=[]}e.listenerInfos.push({trigger:o.trigger,listener:n,on:r});r.addEventListener(o.trigger,n)})}var tt=false;var rt=null;function nt(){if(!rt){rt=function(){tt=true};window.addEventListener("scroll",rt);setInterval(function(){if(tt){tt=false;Q(J().querySelectorAll("[hx-trigger='revealed'],[data-hx-trigger='revealed']"),function(e){it(e)})}},200)}}function it(t){if(!q(t,"data-hx-revealed")&&P(t)){t.setAttribute("data-hx-revealed","true");var e=Y(t);if(e.initHash){ie(t,"revealed")}else{t.addEventListener("htmx:afterProcessNode",function(e){ie(t,"revealed")},{once:true})}}}function at(e,t,r){var n=M(r);for(var i=0;i<n.length;i++){var a=n[i].split(/:(.+)/);if(a[0]==="connect"){ot(e,a[1],0)}if(a[0]==="send"){lt(e)}}}function ot(s,r,n){if(!ee(s)){return}if(r.indexOf("/")=
=0){var e=location.hostname+(location.port?":"+location.port:"");if(location.protocol=="https:"){r="wss://"+e+r}else if(location.protocol=="http:"){r="ws://"+e+r}}var t=z.createWebSocket(r);t.onerror=function(e){ne(s,"htmx:wsError",{error:e,socket:t});st(s)};t.onclose=function(e){if([1006,1012,1013].indexOf(e.code)>=0){var t=ut(n);setTimeout(function(){ot(s,r,n+1)},t)}};t.onopen=function(e){n=0};Y(s).webSocket=t;t.addEventListener("message",function(e){if(st(s)){return}var t=e.data;w(s,function(e){t=e.transformResponse(t,null,s)});var r=S(s);var n=l(t);var i=k(n.children);for(var a=0;a<i.length;a++){var o=i[a];me(G(o,"hx-swap-oob")||"true",o,r)}Bt(r.tasks)})}function st(e){if(!ee(e)){Y(e).webSocket.close();return true}}function lt(u){var f=c(u,function(e){return Y(e).webSocket!=null});if(f){u.addEventListener(ze(u)[0].trigger,function(e){var t=Y(f).webSocket;var r=Qt(u,f);var n=Jt(u,"post");var i=n.errors;var a=n.values;var o=fr(u);var s=te(a,o);var l=er(s,u);l["HEADERS"]=r;if(i&&i.
length>0){ie(u,"htmx:validation:halted",i);return}t.send(JSON.stringify(l));if(Ke(e,u)){e.preventDefault()}})}else{ne(u,"htmx:noWebSocketSourceError")}}function ut(e){var t=z.config.wsReconnectDelay;if(typeof t==="function"){return t(e)}if(t==="full-jitter"){var r=Math.min(e,6);var n=1e3*Math.pow(2,r);return n*Math.random()}x('htmx.config.wsReconnectDelay must either be a function or the string "full-jitter"')}function ft(e,t,r){var n=M(r);for(var i=0;i<n.length;i++){var a=n[i].split(/:(.+)/);if(a[0]==="connect"){ct(e,a[1])}if(a[0]==="swap"){ht(e,a[1])}}}function ct(t,e){var r=z.createEventSource(e);r.onerror=function(e){ne(t,"htmx:sseError",{error:e,source:r});vt(t)};Y(t).sseEventSource=r}function ht(a,o){var s=c(a,gt);if(s){var l=Y(s).sseEventSource;var u=function(e){if(vt(s)){l.removeEventListener(o,u);return}var t=e.data;w(a,function(e){t=e.transformResponse(t,null,a)});var r=rr(a);var n=de(a);var i=S(a);Me(r.swapStyle,a,n,t,i);Bt(i.tasks);ie(a,"htmx:sseMessage",e)};Y(a).sseList
ener=u;l.addEventListener(o,u)}else{ne(a,"htmx:noSSESourceError")}}function dt(e,t,r){var n=c(e,gt);if(n){var i=Y(n).sseEventSource;var a=function(){if(!vt(n)){if(ee(e)){t(e)}else{i.removeEventListener(r,a)}}};Y(e).sseListener=a;i.addEventListener(r,a)}else{ne(e,"htmx:noSSESourceError")}}function vt(e){if(!ee(e)){Y(e).sseEventSource.close();return true}}function gt(e){return Y(e).sseEventSource!=null}function pt(e,t,r,n){var i=function(){if(!r.loaded){r.loaded=true;t(e)}};if(n){setTimeout(i,n)}else{i()}}function mt(t,i,e){var a=false;Q(R,function(r){if(q(t,"hx-"+r)){var n=G(t,"hx-"+r);a=true;i.path=n;i.verb=r;e.forEach(function(e){xt(t,e,i,function(e,t){ae(r,n,e,t)})})}});return a}function xt(n,e,t,r){if(e.sseEvent){dt(n,r,e.sseEvent)}else if(e.trigger==="revealed"){nt();et(n,r,t,e);it(n)}else if(e.trigger==="intersect"){var i={};if(e.root){i.root=re(n,e.root)}if(e.threshold){i.threshold=parseFloat(e.threshold)}var a=new IntersectionObserver(function(e){for(var t=0;t<e.length;t++){v
ar r=e[t];if(r.isIntersecting){ie(n,"intersect");break}}},i);a.observe(n);et(n,r,t,e)}else if(e.trigger==="load"){if(!Qe(e,Lt("load",{elt:n}))){pt(n,r,t,e.delay)}}else if(e.pollInterval){t.polling=true;Ge(n,r,e)}else{et(n,r,t,e)}}function yt(e){if(e.type==="text/javascript"||e.type==="module"||e.type===""){var t=J().createElement("script");Q(e.attributes,function(e){t.setAttribute(e.name,e.value)});t.textContent=e.textContent;t.async=false;if(z.config.inlineScriptNonce){t.nonce=z.config.inlineScriptNonce}var r=e.parentElement;try{r.insertBefore(t,e)}catch(e){x(e)}finally{if(e.parentElement){e.parentElement.removeChild(e)}}}}function bt(e){if(h(e,"script")){yt(e)}Q(f(e,"script"),function(e){yt(e)})}function wt(){return document.querySelector("[hx-boost], [data-hx-boost]")}function St(e){if(e.querySelectorAll){var t=wt()?", a, form":"";var r=e.querySelectorAll(O+t+", [hx-sse], [data-hx-sse], [hx-ws],"+" [data-hx-ws], [hx-ext], [data-hx-ext], [hx-trigger], [data-hx-trigger], [hx-on], [
data-hx-on]");return r}else{return[]}}function Et(n){var e=function(e){var t=d(e.target,"button, input[type='submit']");if(t!==null){var r=Y(n);r.lastButtonClicked=t}};n.addEventListener("click",e);n.addEventListener("focusin",e);n.addEventListener("focusout",function(e){var t=Y(n);t.lastButtonClicked=null})}function Ct(e){var t=Ue(e);var r=0;for(let e=0;e<t.length;e++){const n=t[e];if(n==="{"){r++}else if(n==="}"){r--}}return r}function Rt(t,e,r){var n=Y(t);n.onHandlers=[];var i=new Function("event",r+"; return;");var a=t.addEventListener(e,function(e){return i.call(t,e)});n.onHandlers.push({event:e,listener:a});return{nodeData:n,code:r,func:i,listener:a}}function Ot(e){var t=G(e,"hx-on");if(t){var r={};var n=t.split("\n");var i=null;var a=0;while(n.length>0){var o=n.shift();var s=o.match(/^\s*([a-zA-Z:\-]+:)(.*)/);if(a===0&&s){o.split(":");i=s[1].slice(0,-1);r[i]=s[2]}else{r[i]+=o}a+=Ct(o)}for(var l in r){Rt(e,l,r[l])}}}function qt(t){if(t.closest&&t.closest(z.config.disableSelect
or)){return}var r=Y(t);if(r.initHash!==Ce(t)){r.initHash=Ce(t);Re(t);Ot(t);ie(t,"htmx:beforeProcessNode");if(t.value){r.lastValue=t.value}var e=ze(t);var n=mt(t,r,e);if(!n){if(Z(t,"hx-boost")==="true"){Ze(t,r,e)}else if(q(t,"hx-trigger")){e.forEach(function(e){xt(t,e,r,function(){})})}}if(t.tagName==="FORM"){Et(t)}var i=G(t,"hx-sse");if(i){ft(t,r,i)}var a=G(t,"hx-ws");if(a){at(t,r,a)}ie(t,"htmx:afterProcessNode")}}function Tt(e){e=s(e);qt(e);Q(St(e),function(e){qt(e)})}function Ht(e){return e.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase()}function Lt(e,t){var r;if(window.CustomEvent&&typeof window.CustomEvent==="function"){r=new CustomEvent(e,{bubbles:true,cancelable:true,detail:t})}else{r=J().createEvent("CustomEvent");r.initCustomEvent(e,true,true,t)}return r}function ne(e,t,r){ie(e,t,te({error:t},r))}function At(e){return e==="htmx:afterProcessNode"}function w(e,t){Q(wr(e),function(e){try{t(e)}catch(e){x(e)}})}function x(e){if(console.error){console.error(e)}else if(console.
log){console.log("ERROR: ",e)}}function ie(e,t,r){e=s(e);if(r==null){r={}}r["elt"]=e;var n=Lt(t,r);if(z.logger&&!At(t)){z.logger(e,t,r)}if(r.error){x(r.error);ie(e,"htmx:error",{errorInfo:r})}var i=e.dispatchEvent(n);var a=Ht(t);if(i&&a!==t){var o=Lt(a,n.detail);i=i&&e.dispatchEvent(o)}w(e,function(e){i=i&&e.onEvent(t,n)!==false});return i}var Nt=location.pathname+location.search;function It(){var e=J().querySelector("[hx-history-elt],[data-hx-history-elt]");return e||J().body}function kt(e,t,r,n){if(!D()){return}e=X(e);var i=y(localStorage.getItem("htmx-history-cache"))||[];for(var a=0;a<i.length;a++){if(i[a].url===e){i.splice(a,1);break}}var o={url:e,content:t,title:r,scroll:n};ie(J().body,"htmx:historyItemCreated",{item:o,cache:i});i.push(o);while(i.length>z.config.historyCacheSize){i.shift()}while(i.length>0){try{localStorage.setItem("htmx-history-cache",JSON.stringify(i));break}catch(e){ne(J().body,"htmx:historyCacheError",{cause:e,cache:i});i.shift()}}}function Pt(e){if(!D()){
return null}e=X(e);var t=y(localStorage.getItem("htmx-history-cache"))||[];for(var r=0;r<t.length;r++){if(t[r].url===e){return t[r]}}return null}function Mt(e){var t=z.config.requestClass;var r=e.cloneNode(true);Q(f(r,"."+t),function(e){n(e,t)});return r.innerHTML}function Dt(){var e=It();var t=Nt||location.pathname+location.search;var r=J().querySelector('[hx-history="false" i],[data-hx-history="false" i]');if(!r){ie(J().body,"htmx:beforeHistorySave",{path:t,historyElt:e});kt(t,Mt(e),J().title,window.scrollY)}if(z.config.historyEnabled)history.replaceState({htmx:true},J().title,window.location.href)}function Xt(e){if(z.config.getCacheBusterParam){e=e.replace(/org\.htmx\.cache-buster=[^&]*&?/,"");if(e.endsWith("&")||e.endsWith("?")){e=e.slice(0,-1)}}if(z.config.historyEnabled){history.pushState({htmx:true},"",e)}Nt=e}function Ft(e){if(z.config.historyEnabled)history.replaceState({htmx:true},"",e);Nt=e}function Bt(e){Q(e,function(e){e.call()})}function jt(a){var e=new XMLHttpRequest;
var o={path:a,xhr:e};ie(J().body,"htmx:historyCacheMiss",o);e.open("GET",a,true);e.setRequestHeader("HX-History-Restore-Request","true");e.onload=function(){if(this.status>=200&&this.status<400){ie(J().body,"htmx:historyCacheMissLoad",o);var e=l(this.response);e=e.querySelector("[hx-history-elt],[data-hx-history-elt]")||e;var t=It();var r=S(t);var n=Pe(this.response);if(n){var i=b("title");if(i){i.innerHTML=n}else{window.document.title=n}}Ne(t,e,r);Bt(r.tasks);Nt=a;ie(J().body,"htmx:historyRestore",{path:a,cacheMiss:true,serverResponse:this.response})}else{ne(J().body,"htmx:historyCacheMissLoadError",o)}};e.send()}function Ut(e){Dt();e=e||location.pathname+location.search;var t=Pt(e);if(t){var r=l(t.content);var n=It();var i=S(n);Ne(n,r,i);Bt(i.tasks);document.title=t.title;window.scrollTo(0,t.scroll);Nt=e;ie(J().body,"htmx:historyRestore",{path:e,item:t})}else{if(z.config.refreshOnHistoryMiss){window.location.reload(true)}else{jt(e)}}}function Vt(e){var t=ce(e,"hx-indicator");if(t=
=null){t=[e]}Q(t,function(e){var t=Y(e);t.requestCount=(t.requestCount||0)+1;e.classList["add"].call(e.classList,z.config.requestClass)});return t}function _t(e){Q(e,function(e){var t=Y(e);t.requestCount=(t.requestCount||0)-1;if(t.requestCount===0){e.classList["remove"].call(e.classList,z.config.requestClass)}})}function Wt(e,t){for(var r=0;r<e.length;r++){var n=e[r];if(n.isSameNode(t)){return true}}return false}function zt(e){if(e.name===""||e.name==null||e.disabled){return false}if(e.type==="button"||e.type==="submit"||e.tagName==="image"||e.tagName==="reset"||e.tagName==="file"){return false}if(e.type==="checkbox"||e.type==="radio"){return e.checked}return true}function $t(t,r,n,e,i){if(e==null||Wt(t,e)){return}else{t.push(e)}if(zt(e)){var a=$(e,"name");var o=e.value;if(e.multiple){o=k(e.querySelectorAll("option:checked")).map(function(e){return e.value})}if(e.files){o=k(e.files)}if(a!=null&&o!=null){var s=r[a];if(s!==undefined){if(Array.isArray(s)){if(Array.isArray(o)){r[a]=s.co
ncat(o)}else{s.push(o)}}else{if(Array.isArray(o)){r[a]=[s].concat(o)}else{r[a]=[s,o]}}}else{r[a]=o}}if(i){Gt(e,n)}}if(h(e,"form")){var l=e.elements;Q(l,function(e){$t(t,r,n,e,i)})}}function Gt(e,t){if(e.willValidate){ie(e,"htmx:validation:validate");if(!e.checkValidity()){t.push({elt:e,message:e.validationMessage,validity:e.validity});ie(e,"htmx:validation:failed",{message:e.validationMessage,validity:e.validity})}}}function Jt(e,t){var r=[];var n={};var i={};var a=[];var o=Y(e);var s=h(e,"form")&&e.noValidate!==true||G(e,"hx-validate")==="true";if(o.lastButtonClicked){s=s&&o.lastButtonClicked.formNoValidate!==true}if(t!=="get"){$t(r,i,a,d(e,"form"),s)}$t(r,n,a,e,s);if(o.lastButtonClicked){var l=$(o.lastButtonClicked,"name");if(l){n[l]=o.lastButtonClicked.value}}var u=ce(e,"hx-include");Q(u,function(e){$t(r,n,a,e,s);if(!h(e,"form")){Q(e.querySelectorAll(We),function(e){$t(r,n,a,e,s)})}});n=te(n,i);return{errors:a,values:n}}function Zt(e,t,r){if(e!==""){e+="&"}if(String(r)==="[object
Object]"){r=JSON.stringify(r)}var n=encodeURIComponent(r);e+=encodeURIComponent(t)+"="+n;return e}function Kt(e){var t="";for(var r in e){if(e.hasOwnProperty(r)){var n=e[r];if(Array.isArray(n)){Q(n,function(e){t=Zt(t,r,e)})}else{t=Zt(t,r,n)}}}return t}function Yt(e){var t=new FormData;for(var r in e){if(e.hasOwnProperty(r)){var n=e[r];if(Array.isArray(n)){Q(n,function(e){t.append(r,e)})}else{t.append(r,n)}}}return t}function Qt(e,t,r){var n={"HX-Request":"true","HX-Trigger":$(e,"id"),"HX-Trigger-Name":$(e,"name"),"HX-Target":G(t,"id"),"HX-Current-URL":J().location.href};or(e,"hx-headers",false,n);if(r!==undefined){n["HX-Prompt"]=r}if(Y(e).boosted){n["HX-Boosted"]="true"}return n}function er(t,e){var r=Z(e,"hx-params");if(r){if(r==="none"){return{}}else if(r==="*"){return t}else if(r.indexOf("not ")===0){Q(r.substr(4).split(","),function(e){e=e.trim();delete t[e]});return t}else{var n={};Q(r.split(","),function(e){e=e.trim();n[e]=t[e]});return n}}else{return t}}function tr(e){return
$(e,"href")&&$(e,"href").indexOf("#")>=0}function rr(e,t){var r=t?t:Z(e,"hx-swap");var n={swapStyle:Y(e).boosted?"innerHTML":z.config.defaultSwapStyle,swapDelay:z.config.defaultSwapDelay,settleDelay:z.config.defaultSettleDelay};if(Y(e).boosted&&!tr(e)){n["show"]="top"}if(r){var i=M(r);if(i.length>0){n["swapStyle"]=i[0];for(var a=1;a<i.length;a++){var o=i[a];if(o.indexOf("swap:")===0){n["swapDelay"]=v(o.substr(5))}if(o.indexOf("settle:")===0){n["settleDelay"]=v(o.substr(7))}if(o.indexOf("transition:")===0){n["transition"]=o.substr(11)==="true"}if(o.indexOf("scroll:")===0){var s=o.substr(7);var l=s.split(":");var u=l.pop();var f=l.length>0?l.join(":"):null;n["scroll"]=u;n["scrollTarget"]=f}if(o.indexOf("show:")===0){var c=o.substr(5);var l=c.split(":");var h=l.pop();var f=l.length>0?l.join(":"):null;n["show"]=h;n["showTarget"]=f}if(o.indexOf("focus-scroll:")===0){var d=o.substr("focus-scroll:".length);n["focusScroll"]=d=="true"}}}}return n}function nr(e){return Z(e,"hx-encoding")==="
multipart/form-data"||h(e,"form")&&$(e,"enctype")==="multipart/form-data"}function ir(t,r,n){var i=null;w(r,function(e){if(i==null){i=e.encodeParameters(t,n,r)}});if(i!=null){return i}else{if(nr(r)){return Yt(n)}else{return Kt(n)}}}function S(e){return{tasks:[],elts:[e]}}function ar(e,t){var r=e[0];var n=e[e.length-1];if(t.scroll){var i=null;if(t.scrollTarget){i=re(r,t.scrollTarget)}if(t.scroll==="top"&&(r||i)){i=i||r;i.scrollTop=0}if(t.scroll==="bottom"&&(n||i)){i=i||n;i.scrollTop=i.scrollHeight}}if(t.show){var i=null;if(t.showTarget){var a=t.showTarget;if(t.showTarget==="window"){a="body"}i=re(r,a)}if(t.show==="top"&&(r||i)){i=i||r;i.scrollIntoView({block:"start",behavior:z.config.scrollBehavior})}if(t.show==="bottom"&&(n||i)){i=i||n;i.scrollIntoView({block:"end",behavior:z.config.scrollBehavior})}}}function or(e,t,r,n){if(n==null){n={}}if(e==null){return n}var i=G(e,t);if(i){var a=i.trim();var o=r;if(a==="unset"){return null}if(a.indexOf("javascript:")===0){a=a.substr(11);o=true}
else if(a.indexOf("js:")===0){a=a.substr(3);o=true}if(a.indexOf("{")!==0){a="{"+a+"}"}var s;if(o){s=sr(e,function(){return Function("return ("+a+")")()},{})}else{s=y(a)}for(var l in s){if(s.hasOwnProperty(l)){if(n[l]==null){n[l]=s[l]}}}}return or(u(e),t,r,n)}function sr(e,t,r){if(z.config.allowEval){return t()}else{ne(e,"htmx:evalDisallowedError");return r}}function lr(e,t){return or(e,"hx-vars",true,t)}function ur(e,t){return or(e,"hx-vals",false,t)}function fr(e){return te(lr(e),ur(e))}function cr(t,r,n){if(n!==null){try{t.setRequestHeader(r,n)}catch(e){t.setRequestHeader(r,encodeURIComponent(n));t.setRequestHeader(r+"-URI-AutoEncoded","true")}}}function hr(t){if(t.responseURL&&typeof URL!=="undefined"){try{var e=new URL(t.responseURL);return e.pathname+e.search}catch(e){ne(J().body,"htmx:badResponseUrl",{url:t.responseURL})}}}function E(e,t){return e.getAllResponseHeaders().match(t)}function dr(e,t,r){e=e.toLowerCase();if(r){if(r instanceof Element||A(r,"String")){return ae(e,t,n
ull,null,{targetOverride:s(r),returnPromise:true})}else{return ae(e,t,s(r.source),r.event,{handler:r.handler,headers:r.headers,values:r.values,targetOverride:s(r.target),swapOverride:r.swap,returnPromise:true})}}else{return ae(e,t,null,null,{returnPromise:true})}}function vr(e){var t=[];while(e){t.push(e);e=e.parentElement}return t}function ae(e,t,n,r,i,M){var a=null;var o=null;i=i!=null?i:{};if(i.returnPromise&&typeof Promise!=="undefined"){var s=new Promise(function(e,t){a=e;o=t})}if(n==null){n=J().body}var D=i.handler||pr;if(!ee(n)){return}var l=i.targetOverride||de(n);if(l==null||l==fe){ne(n,"htmx:targetError",{target:G(n,"hx-target")});return}if(!M){var X=function(){return ae(e,t,n,r,i,true)};var F={target:l,elt:n,path:t,verb:e,triggeringEvent:r,etc:i,issueRequest:X};if(ie(n,"htmx:confirm",F)===false){return}}var u=n;var f=Y(n);var c=Z(n,"hx-sync");var h=null;var d=false;if(c){var v=c.split(":");var g=v[0].trim();if(g==="this"){u=he(n,"hx-sync")}else{u=re(n,g)}c=(v[1]||"drop").
trim();f=Y(u);if(c==="drop"&&f.xhr&&f.abortable!==true){return}else if(c==="abort"){if(f.xhr){return}else{d=true}}else if(c==="replace"){ie(u,"htmx:abort")}else if(c.indexOf("queue")===0){var B=c.split(" ");h=(B[1]||"last").trim()}}if(f.xhr){if(f.abortable){ie(u,"htmx:abort")}else{if(h==null){if(r){var p=Y(r);if(p&&p.triggerSpec&&p.triggerSpec.queue){h=p.triggerSpec.queue}}if(h==null){h="last"}}if(f.queuedRequests==null){f.queuedRequests=[]}if(h==="first"&&f.queuedRequests.length===0){f.queuedRequests.push(function(){ae(e,t,n,r,i)})}else if(h==="all"){f.queuedRequests.push(function(){ae(e,t,n,r,i)})}else if(h==="last"){f.queuedRequests=[];f.queuedRequests.push(function(){ae(e,t,n,r,i)})}return}}var m=new XMLHttpRequest;f.xhr=m;f.abortable=d;var x=function(){f.xhr=null;f.abortable=false;if(f.queuedRequests!=null&&f.queuedRequests.length>0){var e=f.queuedRequests.shift();e()}};var y=Z(n,"hx-prompt");if(y){var b=prompt(y);if(b===null||!ie(n,"htmx:prompt",{prompt:b,target:l})){K(a);x();
return s}}var w=Z(n,"hx-confirm");if(w){if(!confirm(w)){K(a);x();return s}}var S=Qt(n,l,b);if(i.headers){S=te(S,i.headers)}var E=Jt(n,e);var C=E.errors;var R=E.values;if(i.values){R=te(R,i.values)}var j=fr(n);var O=te(R,j);var q=er(O,n);if(e!=="get"&&!nr(n)){S["Content-Type"]="application/x-www-form-urlencoded"}if(z.config.getCacheBusterParam&&e==="get"){q["org.htmx.cache-buster"]=$(l,"id")||"true"}if(t==null||t===""){t=J().location.href}var T=or(n,"hx-request");var H=Y(n).boosted;var L={boosted:H,parameters:q,unfilteredParameters:O,headers:S,target:l,verb:e,errors:C,withCredentials:i.credentials||T.credentials||z.config.withCredentials,timeout:i.timeout||T.timeout||z.config.timeout,path:t,triggeringEvent:r};if(!ie(n,"htmx:configRequest",L)){K(a);x();return s}t=L.path;e=L.verb;S=L.headers;q=L.parameters;C=L.errors;if(C&&C.length>0){ie(n,"htmx:validation:halted",L);K(a);x();return s}var U=t.split("#");var V=U[0];var A=U[1];var N=null;if(e==="get"){N=V;var _=Object.keys(q).length!==0;
if(_){if(N.indexOf("?")<0){N+="?"}else{N+="&"}N+=Kt(q);if(A){N+="#"+A}}m.open("GET",N,true)}else{m.open(e.toUpperCase(),t,true)}m.overrideMimeType("text/html");m.withCredentials=L.withCredentials;m.timeout=L.timeout;if(T.noHeaders){}else{for(var I in S){if(S.hasOwnProperty(I)){var W=S[I];cr(m,I,W)}}}var k={xhr:m,target:l,requestConfig:L,etc:i,boosted:H,pathInfo:{requestPath:t,finalRequestPath:N||t,anchor:A}};m.onload=function(){try{var e=vr(n);k.pathInfo.responsePath=hr(m);D(n,k);_t(P);ie(n,"htmx:afterRequest",k);ie(n,"htmx:afterOnLoad",k);if(!ee(n)){var t=null;while(e.length>0&&t==null){var r=e.shift();if(ee(r)){t=r}}if(t){ie(t,"htmx:afterRequest",k);ie(t,"htmx:afterOnLoad",k)}}K(a);x()}catch(e){ne(n,"htmx:onLoadError",te({error:e},k));throw e}};m.onerror=function(){_t(P);ne(n,"htmx:afterRequest",k);ne(n,"htmx:sendError",k);K(o);x()};m.onabort=function(){_t(P);ne(n,"htmx:afterRequest",k);ne(n,"htmx:sendAbort",k);K(o);x()};m.ontimeout=function(){_t(P);ne(n,"htmx:afterRequest",k);ne(
n,"htmx:timeout",k);K(o);x()};if(!ie(n,"htmx:beforeRequest",k)){K(a);x();return s}var P=Vt(n);Q(["loadstart","loadend","progress","abort"],function(t){Q([m,m.upload],function(e){e.addEventListener(t,function(e){ie(n,"htmx:xhr:"+t,{lengthComputable:e.lengthComputable,loaded:e.loaded,total:e.total})})})});ie(n,"htmx:beforeSend",k);m.send(e==="get"?null:ir(m,n,q));return s}function gr(e,t){var r=t.xhr;var n=null;var i=null;if(E(r,/HX-Push:/i)){n=r.getResponseHeader("HX-Push");i="push"}else if(E(r,/HX-Push-Url:/i)){n=r.getResponseHeader("HX-Push-Url");i="push"}else if(E(r,/HX-Replace-Url:/i)){n=r.getResponseHeader("HX-Replace-Url");i="replace"}if(n){if(n==="false"){return{}}else{return{type:i,path:n}}}var a=t.pathInfo.finalRequestPath;var o=t.pathInfo.responsePath;var s=Z(e,"hx-push-url");var l=Z(e,"hx-replace-url");var u=Y(e).boosted;var f=null;var c=null;if(s){f="push";c=s}else if(l){f="replace";c=l}else if(u){f="push";c=o||a}if(c){if(c==="false"){return{}}if(c==="true"){c=o||a}if(t.p
athInfo.anchor&&c.indexOf("#")===-1){c=c+"#"+t.pathInfo.anchor}return{type:f,path:c}}else{return{}}}function pr(s,l){var u=l.xhr;var f=l.target;var e=l.etc;if(!ie(s,"htmx:beforeOnLoad",l))return;if(E(u,/HX-Trigger:/i)){De(u,"HX-Trigger",s)}if(E(u,/HX-Location:/i)){Dt();var t=u.getResponseHeader("HX-Location");var c;if(t.indexOf("{")===0){c=y(t);t=c["path"];delete c["path"]}dr("GET",t,c).then(function(){Xt(t)});return}if(E(u,/HX-Redirect:/i)){location.href=u.getResponseHeader("HX-Redirect");return}if(E(u,/HX-Refresh:/i)){if("true"===u.getResponseHeader("HX-Refresh")){location.reload();return}}if(E(u,/HX-Retarget:/i)){l.target=J().querySelector(u.getResponseHeader("HX-Retarget"))}var h=gr(s,l);var r=u.status>=200&&u.status<400&&u.status!==204;var d=u.response;var n=u.status>=400;var i=te({shouldSwap:r,serverResponse:d,isError:n},l);if(!ie(f,"htmx:beforeSwap",i))return;f=i.target;d=i.serverResponse;n=i.isError;l.target=f;l.failed=n;l.successful=!n;if(i.shouldSwap){if(u.status===286){$e
(s)}w(s,function(e){d=e.transformResponse(d,u,s)});if(h.type){Dt()}var a=e.swapOverride;if(E(u,/HX-Reswap:/i)){a=u.getResponseHeader("HX-Reswap")}var c=rr(s,a);f.classList.add(z.config.swappingClass);var v=null;var g=null;var o=function(){try{var e=document.activeElement;var t={};try{t={elt:e,start:e?e.selectionStart:null,end:e?e.selectionEnd:null}}catch(e){}var n=S(f);Me(c.swapStyle,f,s,d,n);if(t.elt&&!ee(t.elt)&&t.elt.id){var r=document.getElementById(t.elt.id);var i={preventScroll:c.focusScroll!==undefined?!c.focusScroll:!z.config.defaultFocusScroll};if(r){if(t.start&&r.setSelectionRange){try{r.setSelectionRange(t.start,t.end)}catch(e){}}r.focus(i)}}f.classList.remove(z.config.swappingClass);Q(n.elts,function(e){if(e.classList){e.classList.add(z.config.settlingClass)}ie(e,"htmx:afterSwap",l)});if(E(u,/HX-Trigger-After-Swap:/i)){var a=s;if(!ee(s)){a=J().body}De(u,"HX-Trigger-After-Swap",a)}var o=function(){Q(n.tasks,function(e){e.call()});Q(n.elts,function(e){if(e.classList){e.cla
ssList.remove(z.config.settlingClass)}ie(e,"htmx:afterSettle",l)});if(h.type){if(h.type==="push"){Xt(h.path);ie(J().body,"htmx:pushedIntoHistory",{path:h.path})}else{Ft(h.path);ie(J().body,"htmx:replacedInHistory",{path:h.path})}}if(l.pathInfo.anchor){var e=b("#"+l.pathInfo.anchor);if(e){e.scrollIntoView({block:"start",behavior:"auto"})}}if(n.title){var t=b("title");if(t){t.innerHTML=n.title}else{window.document.title=n.title}}ar(n.elts,c);if(E(u,/HX-Trigger-After-Settle:/i)){var r=s;if(!ee(s)){r=J().body}De(u,"HX-Trigger-After-Settle",r)}K(v)};if(c.settleDelay>0){setTimeout(o,c.settleDelay)}else{o()}}catch(e){ne(s,"htmx:swapError",l);K(g);throw e}};var p=z.config.globalViewTransitions;if(c.hasOwnProperty("transition")){p=c.transition}if(p&&ie(s,"htmx:beforeTransition",l)&&typeof Promise!=="undefined"&&document.startViewTransition){var m=new Promise(function(e,t){v=e;g=t});var x=o;o=function(){document.startViewTransition(function(){x();return m})}}if(c.swapDelay>0){setTimeout(o,c.s
wapDelay)}else{o()}}if(n){ne(s,"htmx:responseError",te({error:"Response Status Error Code "+u.status+" from "+l.pathInfo.requestPath},l))}}var mr={};function xr(){return{init:function(e){return null},onEvent:function(e,t){return true},transformResponse:function(e,t,r){return e},isInlineSwap:function(e){return false},handleSwap:function(e,t,r,n){return false},encodeParameters:function(e,t,r){return null}}}function yr(e,t){if(t.init){t.init(C)}mr[e]=te(xr(),t)}function br(e){delete mr[e]}function wr(e,r,n){if(e==undefined){return r}if(r==undefined){r=[]}if(n==undefined){n=[]}var t=G(e,"hx-ext");if(t){Q(t.split(","),function(e){e=e.replace(/ /g,"");if(e.slice(0,7)=="ignore:"){n.push(e.slice(7));return}if(n.indexOf(e)<0){var t=mr[e];if(t&&r.indexOf(t)<0){r.push(t)}}})}return wr(u(e),r,n)}function Sr(e){if(J().readyState!=="loading"){e()}else{J().addEventListener("DOMContentLoaded",e)}}function Er(){if(z.config.includeIndicatorStyles!==false){J().head.insertAdjacentHTML("beforeend","<sty
le> ."+z.config.indicatorClass+"{opacity:0;transition: opacity 200ms ease-in;} ."+z.config.requestClass+" ."+z.config.indicatorClass+"{opacity:1} ."+z.config.requestClass+"."+z.config.indicatorClass+"{opacity:1} </style>")}}function Cr(){var e=J().querySelector('meta[name="htmx-config"]');if(e){return y(e.content)}else{return null}}function Rr(){var e=Cr();if(e){z.config=te(z.config,e)}}Sr(function(){Rr();Er();var e=J().body;Tt(e);var t=J().querySelectorAll("[hx-trigger='restored'],[data-hx-trigger='restored']");e.addEventListener("htmx:abort",function(e){var t=e.target;var r=Y(t);if(r&&r.xhr){r.xhr.abort()}});var r=window.onpopstate;window.onpopstate=function(e){if(e.state&&e.state.htmx){Ut();Q(t,function(e){ie(e,"htmx:restored",{document:J(),triggerEvent:ie})})}else{if(r){r(e)}}};setTimeout(function(){ie(e,"htmx:load",{});e=null},0)});return z}()});
\ No newline at end of file

-----------------------------------------------------------------------


hooks/post-receive
--
rt
_______________________________________________
rt-commit mailing list
rt-commit@lists.bestpractical.com
https://lists.bestpractical.com/mailman/listinfo/rt-commit