Skip to content

Rewrite the editor and menu without jQuery, Backbone and underscore - #180

Open
PetrDlouhy wants to merge 3 commits into
caktus:masterfrom
PetrDlouhy:upstream-no-jquery
Open

PetrDlouhy wants to merge 3 commits into
caktus:masterfrom
PetrDlouhy:upstream-no-jquery

Conversation

@PetrDlouhy

@PetrDlouhy PetrDlouhy commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

The bundle shipped jQuery, Backbone and underscore to power the inline editor. Everything they did here has a small plain-DOM equivalent, and a host page that does not load jQuery itself should not have to get it back through the scribbler bundle:

  • Backbone.View becomes two plain constructors; the only Backbone.Events pieces in use (on/trigger for the editor's open event) live in the new scribbler-dom.js together with the DOM helpers.
  • $.post becomes fetch with a form-encoded body — the preview and save views read request.POST, so the wire format stays the same, and the csrfmiddlewaretoken input keeps riding along in the form data.
  • $.animate/fadeIn/fadeOut become CSS transitions on inline styles; the stylesheet already pins the editor at height 0 and the menu off-screen.
  • The draft store keeps only the localStorage path: the cookie fallback compared against a never-assigned variable, so it could never restore anything.
  • plugins/themes.js is deleted: an AMD module from the require.js era, nothing has been able to load it since the browserify migration, and it required jQuery.
  • Everything stays ES5, so the existing browserify + uglify-js pipeline builds it unchanged; make lint-js (jshint) passes. The minified bundle drops from 553 kB to 367 kB.

Behavior was verified by running the built bundle against a real scribble fixture in two environments:

  • jsdom (34 checks): boot, menu toggle/highlight, opening a scribble, preview and save round-trips (body encoding, CSRF, prefix stripping), the template-error path, and the draft save/restore/discard cycle.
  • headless Chrome on the minified bundle (10 checks): CodeMirror mounts and lays out, the editor slides open, the preview POST carries the edit and the CSRF token, and the console stays clean.

Two intentional behavior notes:

  • Preview HTML is injected with innerHTML, which does not execute embedded <script> tags the way jQuery's .html() did. This only affects the editing session's live preview.
  • The qunit/PhantomJS rig is replaced, not just removed: PhantomJS predates fetch, so it could never run this code. scribbler/tests/js/editor_smoke.cjs runs the built bundle in jsdom against a real scribble fixture — 34 checks over boot, menu, open, preview/save round-trips, the error path, and the draft cycle. Run with make test-js (jsdom is a devDependency; phantomjs-prebuilt and its binary download are gone).

The first commit here is the CI modernization from #181, cherry-picked so this PR's checks can run — git resolves the identical changes cleanly whichever merges first.

The bundle shipped jQuery, Backbone and underscore to power one staff
tool. Everything they did here has a small plain-DOM equivalent, and a
host page that removes its own jQuery must not get it back through the
scribbler bundle:

- Backbone.View becomes two plain constructors; the only Backbone.Events
  pieces in use (on/trigger for the editor's open event) live in the new
  scribbler-dom.js together with the DOM helpers.
- $.post becomes fetch with a form-encoded body -- the preview and save
  views read request.POST, so the wire format stays the same, and the
  csrfmiddlewaretoken input keeps riding along in the form data.
- $.animate/fadeIn/fadeOut become CSS transitions on inline styles; the
  stylesheet already pins the editor at height 0 and the menu off-screen.
- The draft store keeps only the localStorage path: the cookie fallback
  compared against a never-assigned variable, so it could never restore
  anything.
- plugins/themes.js is deleted: an AMD module from the require.js era,
  nothing has been able to load it since the browserify migration, and it
  required jQuery.

Behavior verified by running the built bundle in jsdom against a real
scribble fixture: boot, menu toggle/highlight, open, preview and save
round-trips (body, CSRF, prefix stripping), template-error path, and the
draft save/restore/discard cycle.

The qunit/PhantomJS rig was not ported: PhantomJS predates fetch and
sinon's fake XHR cannot intercept it, so those tests need a real headless
browser to be meaningful again.

Bundle size drops from 553 kB to 367 kB minified.
Every check on this repo has been unable to start for a while: the
workflow asks for ubuntu-20.04, which GitHub retired in April 2025, via
actions/checkout@v2 and setup-python@v2, which stopped working when the
node16 action runtime was removed. Any PR (and the weekly cron) shows
"no checks reported".

- Workflows move to ubuntu-latest with checkout@v4 / setup-python@v5.
- The python matrix becomes 3.9-3.13 and tox tests the two supported
  Django LTS lines, 4.2 and 5.2 (whose floor is py3.9). The suite passes
  on them unchanged.
- One py>=3.12 fix in the tests themselves: assertEquals was removed;
  testUnicodeURL now uses assertEqual.
- tox no longer builds the frontend assets before the python suite: the
  only tests that ever looked at them are the selenium class that has
  been @skipIf(True, 'PhantomJS was deprecated') for years, so the make
  steps only added an npm dependency (and PhantomJS download) to every
  python run. selenium stays in deps because the module still imports it.
- The qunit tox env is dropped from envlist for the same reason: it
  needs PhantomJS, which cannot run anywhere anymore.

Coverage keeps its 80% gate, now on py3.13/Django 5.2; the docs env is
untouched apart from the runner.
The qunit tests could only run under PhantomJS, which predates fetch --
after the jQuery removal they could never execute the editor again, and
phantomjs-prebuilt's binary download is itself a liability on modern
systems. In their place, scribbler/tests/js/editor_smoke.cjs runs the
BUILT bundle in jsdom against a real scribble fixture and walks the
whole editor surface: boot, menu toggle/highlight, opening a scribble,
the preview and save POST round-trips (form encoding, CSRF, prefix
stripping), the template-error path, and the localStorage draft
save/restore/discard cycle -- 34 checks.

Run it with `make test-js` (builds the bundle first; needs the jsdom
devDependency). phantomjs-prebuilt and browserify-compile-templates
leave package.json with the rig.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant