Hide Teacher Mode content by default in exports by erseco · Pull Request #1972 · exelearning/exelearning · GitHub
Skip to content

Hide Teacher Mode content by default in exports#1972

Merged
eXeLearningProject merged 8 commits into
mainfrom
1772-invert-teacher-mode-default-in-exports-hidden-by-default-opt-in-to-reveal
Jun 26, 2026
Merged

Hide Teacher Mode content by default in exports#1972
eXeLearningProject merged 8 commits into
mainfrom
1772-invert-teacher-mode-default-in-exports-hidden-by-default-opt-in-to-reveal

Conversation

@erseco

@erseco erseco commented Jun 18, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Hides Teacher Mode content (the teacher-only class on blocks and iDevices) by default in exported packages and in the preview.
  • The in-page self-serve toggle is now opt-in: it appears only when the content is opened with ?exe-teacher=1 (also true/yes, the generic alias ?teacher-mode=1, and the legacy ?exe-teacher-toggler=1), and it is OFF by default — the viewer activates it to reveal teacher content (state remembered in localStorage). The parameter never reveals content on its own.
  • Without the parameter there is no toggle and teacher content stays hidden (student view).
  • Removes the need for host plugins (WordPress, Moodle, Omeka-S) to inject CSS/JS to control Teacher Mode — they make the toggle available by changing the content URL only.
  • Adds an authoring hint on the "Teacher only" property.

Context

Fixes #1772.

Previously the only way to reveal teacher content was a self-serve toggle shown to everyone (any student could flip it), which is why every host plugin injected CSS to hide it. Now the toggle is hidden by default and appears only when the host opts in via the URL parameter.

Host integrations switch by changing the URL only:

  • Student view: index.html
  • Teacher-layer selector available: index.html?exe-teacher=1

Implementation

  • All runtime lives in public/app/common/exe_export.js (teacherMode), loaded in <head> for every export format and the preview:
    • bootstrap() runs at parse time: it sets _showToggler from a truthy parameter and, when the toggle is available, restores the viewer's stored on/off choice flicker-free (adds mode-teacher to <html> only if localStorage says on). It never reveals on its own.
    • init() renders the toggle only when the parameter made it available and .teacher-only content exists; the toggle's change handler adds/removes mode-teacher and persists the choice.
    • The active parameter is propagated onto in-package navigation links so the toggle stays available across pages (same-origin and opaque-origin iframes).
  • base.css (html:not(.mode-teacher) .js .teacher-only { display:none !important }) is unchanged.
  • The authoring preview (previewPanel.js) loads the viewer with ?exe-teacher=1, so the toggle is available while editing (still off by default).
  • Authoring hint added via a help field on both teacherOnly definitions in src/routes/config-params.ts.

Notes

  • Presentation mode, not access control. ?exe-teacher=1 only exposes a toggle; it is not authentication and not a security boundary. Truly sensitive answer keys need a separate authenticated/password-gated feature.
  • Does not generate separate student/teacher exports.
  • Existing packages must be re-exported to pick up the new default (changelog/migration note added).
  • Page-level Teacher Mode does not exist today (block/iDevice only); deferred.

Testing

  • public/app/common/exe_export.test.js (Vitest): the parameter sets _showToggler (incl. aliases), does not reveal on its own, restores the revealed state from localStorage only when the toggle is available, and the toggle's render/checked/change behavior.
  • test/integration/teacher-mode-toggle.spec.ts (Bun): teacher-only class + the base.css hide rule in the exported HTML.
  • test/e2e/playwright/specs/teacher-mode-url-param.spec.ts (Playwright): the SW-served preview's runtime makes the toggle available (_showToggler) with ?exe-teacher=1, and not without it.
  • src/routes/config-params.spec.ts: the authoring hint is present and translation-prefixed.

Full suite green: make test-unit (7375), full frontend Vitest (13352), make test-integration (721), the E2E spec, and make fix.

Why host plugins get simpler (and where this is heading)

Because teacher-mode visibility is now driven purely by the package's own ?exe-teacher=1 URL parameter, the host plugins (WordPress, Moodle ×3, Omeka-S) drop the CSS/JS they used to inject into the embedded package to hide the toggle — they only change the iframe URL. Beyond that cleanup, this advances the longer-term goal of isolating embedded resource content from the host: with the host no longer reaching into the package DOM, the resource can later be sandboxed / served cross-origin without losing teacher-mode control. The consuming plugin PRs (kept blocked until this one merges): wp-exelearning#58, omeka-s-exelearning#23, mod_exeweb#65, mod_exescorm#81, mod_exelearning#86.

…RL param

Teacher-only content (blocks and iDevices) is now hidden by default in exported
packages and in the preview, and the in-page self-serve toggle is hidden too.
Hosts (WordPress, Moodle, Omeka-S) reveal teacher content by appending
?exe-teacher=1 to the content URL (aliases true/yes, plus ?teacher-mode=1) — no
injected CSS/JS. ?exe-teacher=0 forces the student view; ?exe-teacher-toggler=1
shows the self-serve toggle.

The reveal is applied by an early <head> script (flicker-free) and propagated
onto in-package navigation links so it survives multi-page navigation. Adds an
authoring hint on the "Teacher only" property warning it is hidden by default.
This is a presentation mode, not access control.

Closes #1772
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 18, 2026

Copy link
Copy Markdown

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Bundle Report

Changes will increase total bundle size by 28 bytes (0.0%) ⬆️. This is within the configured threshold ✅

Detailed changes
Bundle name Size Change
app-bundle 853.41kB 28 bytes (0.0%) ⬆️

Affected Assets, Files, and Routes:

view changes for bundle: app-bundle

Assets Changed:

Asset Name Size Change Total Size Change (%)
app.bundle.js 28 bytes 853.41kB 0.0%

@codecov

codecov Bot commented Jun 18, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.44444% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.10%. Comparing base (39d8956) to head (bde2f81).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
public/app/common/exe_export.js 93.54% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1972      +/-   ##
==========================================
+ Coverage   92.08%   92.10%   +0.01%     
==========================================
  Files         372      372              
  Lines       79675    79703      +28     
==========================================
+ Hits        73369    73407      +38     
+ Misses       6306     6296      -10     
Flag Coverage Δ
frontend 92.10% <94.44%> (+0.01%) ⬆️
unittests 92.10% <94.44%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

The in-app authoring preview now loads the viewer with ?exe-teacher=1 so the
author sees their teacher-only content while editing (the author is the teacher).
Exported packages stay hidden by default; only this in-app preview opts in.

Updates the previewPanel viewer URLs (SW preview + open-in-new-tab), the
previewPanel tests, the E2E spec (preview defaults to teacher mode; the
parameter still forces the student view), and the docs/changelog.
@erseco

erseco commented Jun 19, 2026

Copy link
Copy Markdown
Collaborator Author

Follow-up commit (316c46f): eXeLearning's own authoring preview now reveals Teacher Mode by default — the preview panel loads the viewer with ?exe-teacher=1 so authors see their teacher-only content while editing (the author is the teacher). Exported packages still stay hidden by default; only the in-app preview opts in. previewPanel.js (SW preview + open-in-new-tab), its tests, the E2E spec, and docs/changelog updated.

?exe-teacher=1 (alias ?teacher-mode=1, legacy ?exe-teacher-toggler=1) now makes
the in-page Teacher Mode toggle AVAILABLE; it no longer reveals content on its
own. The toggle is OFF by default and remembers the viewer's choice in
localStorage — the viewer activates it to reveal teacher content. Without the
parameter there is no toggle and teacher content stays hidden (student view).

The authoring preview keeps appending ?exe-teacher=1, so the toggle is available
while editing (off by default), consistent with a normal export opened with the
parameter. Updates exe_export.js bootstrap, its tests, the E2E spec, the
previewPanel comments, and the docs/changelog.
@erseco erseco self-assigned this Jun 19, 2026
@erseco erseco added the ui label Jun 19, 2026
@erseco erseco added this to the v4.0.2 milestone Jun 19, 2026
erseco added a commit to exelearning/wp-exelearning that referenced this pull request Jun 19, 2026
…S injection

eXeLearning packages hide teacher-only content by default and expose an in-page
"teacher layer" selector through the ?exe-teacher=1 URL parameter (upstream
exelearning/exelearning#1972, fixes exelearning/exelearning#1772). The plugin now
appends that parameter to the embed instead of injecting CSS/JS into the package.

- Shortcode (public/class-shortcodes.php): append ?exe-teacher=1 when teacher_mode
  or teacher_mode_visible is on; drop the toggler-hiding and activate-on-load
  inline scripts from render_preview_script.
- Block (includes/class-elp-upload-block.php): append ?exe-teacher=1 in
  build_preview_url when teacherModeVisible is on; remove teacher_mode_hide_script.
- Relabel the block control to "Show teacher layer selector" with homogeneous
  help; refresh the admin shortcode reference, SHORTCODES.md and readme.txt.
- i18n: translate the three changed strings across all 10 catalogs; rebuild .mo
  and the elp-upload.js .json.
- Tests: rewrite the teacher-mode shortcode/block tests for the URL-param model.
@greynoa

greynoa commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

@pabloamayab pabloamayab left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!!! Now I'm going to review Moodle extensions

@eXeLearningProject eXeLearningProject merged commit 90710ed into main Jun 26, 2026
8 checks passed
@eXeLearningProject eXeLearningProject deleted the 1772-invert-teacher-mode-default-in-exports-hidden-by-default-opt-in-to-reveal branch June 26, 2026 11:55
erseco added a commit to exelearning/wp-exelearning that referenced this pull request Jun 26, 2026
…injection (#58)

* fix(teacher-mode): reveal via core ?exe-teacher URL param, drop CSS/JS injection

eXeLearning packages hide teacher-only content by default and expose an in-page
"teacher layer" selector through the ?exe-teacher=1 URL parameter (upstream
exelearning/exelearning#1972, fixes exelearning/exelearning#1772). The plugin now
appends that parameter to the embed instead of injecting CSS/JS into the package.

- Shortcode (public/class-shortcodes.php): append ?exe-teacher=1 when teacher_mode
  or teacher_mode_visible is on; drop the toggler-hiding and activate-on-load
  inline scripts from render_preview_script.
- Block (includes/class-elp-upload-block.php): append ?exe-teacher=1 in
  build_preview_url when teacherModeVisible is on; remove teacher_mode_hide_script.
- Relabel the block control to "Show teacher layer selector" with homogeneous
  help; refresh the admin shortcode reference, SHORTCODES.md and readme.txt.
- i18n: translate the three changed strings across all 10 catalogs; rebuild .mo
  and the elp-upload.js .json.
- Tests: rewrite the teacher-mode shortcode/block tests for the URL-param model.

* Default the teacher-layer selector to OFF (align with #1772 opt-in)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Invert Teacher Mode default in exports: hidden by default, opt-in to reveal

5 participants