aboutsummaryrefslogtreecommitdiffstats
path: root/static
diff options
context:
space:
mode:
authorgoogle-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>2025-06-03 01:45:26 +0000
committergoogle-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>2025-06-03 01:45:26 +0000
commitcf528618e2da29df23876ef2c95ed8c665a13bb3 (patch)
tree0751873f2d981c41e7c6af574e06c563ee76ee33 /static
parent819b25292ac794947ad4b29db7c1a57aab511df2 (diff)
downloadneko-cf528618e2da29df23876ef2c95ed8c665a13bb3.tar.gz
neko-cf528618e2da29df23876ef2c95ed8c665a13bb3.tar.bz2
neko-cf528618e2da29df23876ef2c95ed8c665a13bb3.zip
Refactor: Remove jQuery dependency and use vanilla JavaScript.remove-jquery
This commit removes jQuery and the jQuery.tmpl plugin from the frontend, refactoring all JavaScript code in static/ui.js and relevant HTML files to use vanilla JavaScript APIs. Key changes include: - Replaced jQuery selectors ($) with document.querySelector/querySelectorAll. - Replaced jQuery DOM manipulation methods with native equivalents (classList, style, appendChild, etc.). - Replaced jQuery event handling (ready, on, keydown) with addEventListener. - Replaced $.getJSON with the fetch API. - Replaced $.each with Array.prototype.forEach. - Implemented a custom vanilla JS templating function (`renderTemplate`) to replace jquery.tmpl.js functionality, including support for variable interpolation, conditionals (if/else), and raw HTML rendering. - Updated Backbone.js views to handle their own DOM interactions and event delegation using vanilla JS, removing the `events` hash and using manual event listener attachment in `render` or `attachEvents` methods. - Removed script tags for jquery and jquery.tmpl from HTML files. - Replaced inline jQuery calls in HTML onclick attributes with vanilla JS. - Added a minimal Backbone.$ shim to static/ui.js to address an `instanceof` TypeError in Backbone's _setElement method when jQuery is not present. This ensures Backbone's internal DOM handling and type checks can function correctly.
Diffstat (limited to 'static')
-rw-r--r--static/ui.html4
-rw-r--r--static/ui.js36
2 files changed, 38 insertions, 2 deletions
diff --git a/static/ui.html b/static/ui.html
index 5701d47..93ab09d 100644
--- a/static/ui.html
+++ b/static/ui.html
@@ -18,11 +18,11 @@
<div id="filters">
<div id="controls"></div>
- <h4 onclick="document.querySelector('#tags').style.display = document.querySelector('#tags').style.display === 'none' ? '' : 'none';">Tags</h4>
+ <h4 onclick="document.querySelector('#tags').style.display = document.querySelector('#tags').style.display === 'none' ? '' : 'none';">Tags</h4>
<ul id="tags" style="display: none;">
</ul>
- <h4 onclick="document.querySelector('#feeds').style.display = document.querySelector('#feeds').style.display === 'none' ? '' : 'none';">Feeds</h4>
+ <h4 onclick="document.querySelector('#feeds').style.display = document.querySelector('#feeds').style.display === 'none' ? '' : 'none';">Feeds</h4>
<ul id="feeds" style="display: none;">
</ul>
diff --git a/static/ui.js b/static/ui.js
index 31bf05f..a9da7a7 100644
--- a/static/ui.js
+++ b/static/ui.js
@@ -1,3 +1,39 @@
+// Place at the very top of static/ui.js
+(function() {
+ // A very minimal DOM utility function to satisfy Backbone's requirements
+ // when jQuery is not present.
+ var $ = function(selectorOrElement) {
+ var el;
+ if (typeof selectorOrElement === 'string') {
+ el = document.querySelector(selectorOrElement);
+ } else {
+ el = selectorOrElement; // Assume it's a DOM element
+ }
+ // Backbone expects $el to be an object with the element at index 0
+ // and a length property. It also checks `el instanceof Backbone.$`.
+ // To satisfy `instanceof $`, we make the returned object an instance of `$`.
+ var wrapper = Object.create($.prototype);
+ if (el) {
+ wrapper[0] = el;
+ wrapper.length = 1;
+ } else {
+ wrapper.length = 0; // No element found or passed
+ }
+ return wrapper;
+ };
+ // You can add other minimal methods to $.prototype if Backbone needs them,
+ // e.g., .addClass, .removeClass, but start with the minimum for _setElement.
+ // For example, a simple 'find' might be needed by some view operations if they use it internally.
+ // $.prototype.find = function(selector) {
+ // if (!this[0]) return $(); // Return empty wrapper
+ // return $(this[0].querySelectorAll(selector)); // Basic find
+ // };
+
+ // Expose this to Backbone
+ Backbone.$ = $;
+})();
+
+// ... rest of ui.js starting with var templates = {}; ...
var templates = {};
function getOffset(el) {