Dark / Light Mode Automatic Toggle Switch / jsdmat

Dark / Light Mode Automatic Toggle Switch / jsdmat 0.4.0

Sem autorização para baixar
Compatibilidade com XF
  1. 2.2.x
Descrição curta
enables a XenForo installation to automatically toggle light and dark styles

About jsdmat​

This modification enables a XenForo installation to automatically toggle light and dark styles based on the user browser's UI setting "prefers-color-scheme".
Adding this CSS media feature directly to XenForo CSS definitions is hardly possible for the current architecture. Switching between light and dark UI without major modifications is easier done by switching between different styles.

Situation​

Various solutions to optimize a manual or time-based switching between styles are/were already available, their advantage is the absolutely user-oriented selection of the style. On the other hand, automatic switching can be very convenient. There are several requirements where automatic switching of styles can be a useful or additional solution: The other available solutions haven't all been tested in combination with jsdmat, but it is likely that they can coexist very well offering a combined scenario of manual and automatic style switching as far as the settings match.

Function​

Collecting XenForo data initially, the JS code then checks the current state on load or triggered and initiates a style change via redirection if appropriate. The switch logic is determined by two corresponding lists of light and dark styles to be toggled automatically. All style_id not in list won't be toggled and stay manually chosen.

Example​


descriptioncodevisualization
  • 7 styles, style_ids 1 .. 7
  • all styles selectable
  • default_style = 1 (light)
  • default dark = 2 (black)
  • secondary dark = 3 (blue)
  • special interest styles:
    • light = 7 and dark = 6
    • always green = 4
    • always grey = 5
Auto toggle definition:
JavaScript:
lightStyles: [ 1, 1, 7 ],
darkStyles: [ 2, 3, 6 ],
261853-b530a06c0707ccdbcf9afdbb8b942a4c.webp
  • Browser prefers dark, entering the platform at style 1, the auto toggle redirects to style 2,
    • flip browser to light -> auto toggle back to 2 (vice versa).
  • Browser prefers light, entering the platform at style 3, the auto toggle redirects to style 1,
    • flip browser to dark -> auto toggle back to 3 (vice versa).
  • Entering the platform or changing the style manually to 4 or 5 will stop the auto toggle,
    • changing the style to a style not 4 or 5 -> auto toggle starts again and flips directly, if chosen style doesn't fit to browser's preference.

Features​

  • Auto toggle between unlimited number of styles
  • Not listed styles won't be affected of auto toggle but can be manually chosen
  • No need for the exact same number of light and dark styles -> utilizes multipath relations:
    • if no "last style_id" available, first match in start list wins (see example above: entering at default style -> 1, toggle -> 2)
    • if "last style_id" available (and fits to browser preference), "last style_id" wins (see example above: entering at preset style -> 3, toggle -> 1, toggle -> 3)
  • Advanced manual override of auto toggle preset utilizing "last_style_id" (see example above: entering at default style -> style 1 is active, toggle -> 2, manually chose style 6, -> toggle back to 1, -> toggle to 6, -> stable loop)
  • Event listener for prefers-color-scheme, proactive light/dark toggle without reload

Known Limitations​

  • XenForo stores the last active style_id for logged in users server-side.
    • Effect: Parallel use of more than one logged in device/browser at the same user account pushes the last active style_id permanently vice versa all devices/browsers (accidentally) having different light/dark preferences.
    • Solution: sorry, none yet (KIS).
  • Styles being listed for auto toggle can't be chosen manually if they do not fit to browser preferences.
    • Effect: The auto toggle mechanism flips the style immediately back/away.
    • Solution: Add child styles not being part of the auto toggle definition, proper naming of styles recommended.
  • Page reloads to switch style cost traffic and time (sorry)
  • Opening a bookmarked tab group of several XenForo pages at once can cause race conditions leading to differently styled tab contents.

Installation​

  • There must be at least 2 enabled styles.
  • Download and unzip package.
  • Upload contents of /upload to XenForo folder:
    • /js/jsdmat
    • /js/jsdmat/jsdmat.js
    • /js/jsdmat/jsdmat.min.js
  • Prepare given template invocation code (txt file)
    • Insert your platform's style_ids into lightStyles and darkStyles lists.
    • Double check if the same number of elements is present in both lists.
  • Modification of template PAGE_CONTAINER for all affected (parent) styles:
    • Add prepared invocation code to the very end of PAGE_CONTAINER.
  • ProcessIoDiagram.webp
    ProcessIoDiagram.webp
    44,3 KB · Visualizações: 0
Autor
axtona
Visualizações
363
Tipo de extensão
zip
Tamanho do arquivo
149,4 KB
Primeiro lançamento
Última atualização
Avaliações 0,00 estrelas 0 avaliações
Link was Broken? Please Enviar mensagem para a equipe NP que vamos ajudá-lo rapidamente!
Apoie o desenvolvedor Se você está satisfeito com o teste ou seu projeto gerou lucro, clique no botão “Mais informações” para apoiar o desenvolvedor comprando.

Últimas atualizações

  1. 0.4.0 - 0.4.0
    Added capability to react and incorporate user-driven style changes including lock and release...

Mais recursos de axtona

Brazilian Language [PT-BR] A
Like the other available Brazilian Portuguese translation
Visualizações
15
Atualizado
SEO Audit A
SEO Audit 1.1.0
A comprehensive SEO auditing dashboard for XenForo administrators.
Visualizações
33
Atualizado
Galeria de mídia XenForo / XFMG A
Galeria XenForo é um addon oficial do XenForo que permite adicionar uma galeria ao seu XF2

Recursos similares

[cXF] Light and dark mode switch H
Add an icon to easily switch between light and dark mode style with some extra features.
Visualizações
642
Atualizado
[TB] Light Dark - One-click Day and Night Mode Switching A
allowing you to switch between day and night mode with a single click.
Visualizações
164
Atualizado
[TB] Dark Light Button A
The plugin allows you to add a light or dark colored button to the navigation area.
Visualizações
178
Atualizado
Top