From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Philip Kaludercic Newsgroups: gmane.emacs.bugs Subject: bug#69132: [ELPA] Remove jQuery from elpa.gnu.org Date: Sun, 25 Feb 2024 10:44:45 +0000 Message-ID: <87il2comaq.fsf@posteo.net> References: <87jzn6g7ep.fsf@posteo.net> <87r0h26ux5.fsf@posteo.net> <87v86cvox0.fsf@daniel-mendler.de> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="12778"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 69132@debbugs.gnu.org To: Daniel Mendler Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sun Feb 25 11:46:01 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1reC1A-00034O-Rv for geb-bug-gnu-emacs@m.gmane-mx.org; Sun, 25 Feb 2024 11:46:01 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1reC0q-0007Ai-0p; Sun, 25 Feb 2024 05:45:40 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1reC0o-0007A9-5K for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 05:45:38 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1reC0n-0007r1-QM for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 05:45:37 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1reC1B-0003rV-Pl for bug-gnu-emacs@gnu.org; Sun, 25 Feb 2024 05:46:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Philip Kaludercic Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sun, 25 Feb 2024 10:46:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 69132 X-GNU-PR-Package: emacs Original-Received: via spool by 69132-submit@debbugs.gnu.org id=B69132.170885792014716 (code B ref 69132); Sun, 25 Feb 2024 10:46:01 +0000 Original-Received: (at 69132) by debbugs.gnu.org; 25 Feb 2024 10:45:20 +0000 Original-Received: from localhost ([127.0.0.1]:34545 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1reC0V-0003pF-MF for submit@debbugs.gnu.org; Sun, 25 Feb 2024 05:45:20 -0500 Original-Received: from mout02.posteo.de ([185.67.36.66]:59699) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1reC0S-0003op-P7 for 69132@debbugs.gnu.org; Sun, 25 Feb 2024 05:45:18 -0500 Original-Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id F3C80240101 for <69132@debbugs.gnu.org>; Sun, 25 Feb 2024 11:44:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=posteo.net; s=2017; t=1708857886; bh=lBc3yuz1S2dOxcP6VbOQQq2NwEXuFsHcAGpdqpQHQBA=; h=From:To:Cc:Subject:Autocrypt:Date:Message-ID:MIME-Version: Content-Type:From; b=kmiXL5RI1SyM66/Kusgn/XaPUcdjkoKBLJFe0YtApMZQUomYgRN0HALA1g0ShXwEF l3HZapftU2lXfyEgzT+QbbS0Nx2nCnAJeO602EAUQlkH4K1rMtAsEZ+Xg3PO+U7Nd/ 4h5HoAJcmOaPwGKxg6fXxI+DkjDtfM91WYzVQ72LiT7MRid4/xV0BFOK5ThSLwf+pD JD960/FGTm3nWWpZrYI4J0HFC/jlz07UFW+hVB5NJwbmyyIpVaFww2TuHCM2FtPAg7 VSL50d5Sq5Z2q8luDYS0b1YXcGzK9Wv4votHif4srHanZNwMl0vplDs6/eZtVs1/9O fUo5JAZsZ76fg== Original-Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4TjL3d4CF4z6tx1; Sun, 25 Feb 2024 11:44:45 +0100 (CET) In-Reply-To: <87v86cvox0.fsf@daniel-mendler.de> (Daniel Mendler's message of "Sun, 25 Feb 2024 11:06:19 +0100") X-Hashcash: 1:20:240225:69132@debbugs.gnu.org::CurVQrGje5/9Fukb:1XFi X-Hashcash: 1:20:240225:mail@daniel-mendler.de::wYpHmhIGeeFJCdf6:3A7C Autocrypt: addr=philipk@posteo.net; keydata= mDMEZBBQQhYJKwYBBAHaRw8BAQdAHJuofBrfqFh12uQu0Yi7mrl525F28eTmwUDflFNmdui0QlBo aWxpcCBLYWx1ZGVyY2ljIChnZW5lcmF0ZWQgYnkgYXV0b2NyeXB0LmVsKSA8cGhpbGlwa0Bwb3N0 ZW8ubmV0PoiWBBMWCAA+FiEEDg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwMFCQHhM4AFCwkI BwIGFQoJCAsCBBYCAwECHgECF4AACgkQ8xYDWXahwulikAEA77hloUiSrXgFkUVJhlKBpLCHUjA0 mWZ9j9w5d08+jVwBAK6c4iGP7j+/PhbkxaEKa4V3MzIl7zJkcNNjHCXmvFcEuDgEZBBQQhIKKwYB BAGXVQEFAQEHQI5NLiLRjZy3OfSt1dhCmFyn+fN/QKELUYQetiaoe+MMAwEIB4h+BBgWCAAmFiEE Dg7HY17ghYlni8XN8xYDWXahwukFAmQQUEICGwwFCQHhM4AACgkQ8xYDWXahwukm+wEA8cml4JpK NeAu65rg+auKrPOP6TP/4YWRCTIvuYDm0joBALw98AMz7/qMHvSCeU/hw9PL6u6R2EScxtpKnWof z4oM X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:280609 Archived-At: --=-=-= Content-Type: text/plain Daniel Mendler writes: > Philip Kaludercic writes: > > Hello Philip! > >>> I was recently surprised to see that elpa.gnu.org uses a jQuery library, >>> where it really isn't necessary. Re-implementing the same functionality >>> can be done in a few more lines of plain Javascript, without the need >>> for any minified code. Tested with relatively recent versions of >>> Firefox and Chromium, so perhaps it would be nice if someone with an >>> older browser could check if I didn't make any bold assumptions. >> >> I have pushed updated versions of these patches to elpa.git, does the >> same have to be done for nongnu.git? > > I just tried the updated website on elpa.gnu.org and I observed the > following issues: > > - The filtering feels less responsive. I don't know where the problem > lies, maybe Jquery uses some kind of debouncing, a more efficient > matching or a more efficient way to manipulate the DOM? According to the profiler, most of the CPU time went to reflowing CSS. It appears that if I move around the classList manipulation calls, then the performance improves. > - When deleting the input string after filtering, such that the input > field becomes empty again, all packages are highlighted. Apparently the issue here is that while an empty string is false-y in Javascript "" ? true : false => false an empty regular expression is true-thy new RegExp("") ? true : false => false I updated my patch before pushing it to use RegExp for performance reasons. Due to the above, my "empty-input" check breaks, and the table fields are all highlighted, since the empty regular expression matches every string. That can be easily fixed. A different issue I noticed is that if I input a malformed regular expression, say "+", the site freezes due to an exception. I cannot find any simple analogue for `regexp-quote', but there is a .includes() method on strings that could be used instead (appears to be well supported). > - The jslicense.html website has not been updated yet. Maybe this > website is also not necessary given that no third-party packages are > used? The file has been changed[0], perhaps it also has to be manually updated. [0] https://git.savannah.gnu.org/cgit/emacs/elpa.git/diff/html/jslicense.html?id=4c73cd608e8da3e614aabc083e2a6078c1e631bb > Daniel In effect, I propose these changes: --=-=-= Content-Type: text/plain Content-Disposition: inline diff --git a/html/javascript/package-search.js b/html/javascript/package-search.js index e603853eda..c690632938 100644 --- a/html/javascript/package-search.js +++ b/html/javascript/package-search.js @@ -21,27 +21,38 @@ window.addEventListener("load", function (event) { search.setAttribute("placeholder", "Search packages..."); search.setAttribute("type", "search"); search.addEventListener("input", function(event) { - const query = new RegExp(event.target.value, "i"); + let query = event.target.value; + + if (!query) { // empty input + for (let i = 1; i < table.rows.length; i++) { + const row = table.rows.item(i); + const name = row.childNodes.item(0); + const desc = row.childNodes.item(2); + name.classList.remove("alt"); + desc.classList.remove("alt"); + row.classList.remove("invisible"); + } + return; + } + query = query.toLowerCase(); for (let i = 1; i < table.rows.length; i++) { const row = table.rows.item(i); - row.classList.remove("invisible"); const name = row.childNodes.item(0); - const name_matches = name.innerText.match(query); + const name_matches = name.innerText.toLowerCase().includes(query); name.classList.remove("alt"); const desc = row.childNodes.item(2); - const desc_matches = desc.innerText.match(query); + const desc_matches = desc.innerText.toLowerCase().includes(query); desc.classList.remove("alt"); - if (query) { // avoid matching the empty string - if (name_matches || desc_matches) { - if (name_matches) { name.classList.add("alt"); } - if (desc_matches) { desc.classList.add("alt"); } - } else { - row.classList.add("invisible"); - } + if (name_matches || desc_matches) { + row.classList.remove("invisible"); + if (name_matches) { name.classList.add("alt"); } + if (desc_matches) { desc.classList.add("alt"); } + } else { + row.classList.add("invisible"); } } }); --=-=-= Content-Type: text/plain -- Philip Kaludercic --=-=-=--