codefog / contao-haste

Haste is a collection of tools and classes to ease working with Contao
http://codefog.pl/extension/haste.html
MIT License
43 stars 24 forks source link

`haste_ajax_operation` does not work in Contao 5 due to new dark theme #227

Open fritzmg opened 5 days ago

fritzmg commented 5 days ago

In Contao 5 the dark theme was introduced. With this change the HTML structure of the toggle operation looks like this:

<a data-haste-ajax-operation-value="0" data-haste-ajax-operation-name="toggle" href="/contao?do=…" class="toggle" onclick="return Haste.toggleAjaxOperation(this, 1);Backend.getScrollOffset();" title="Unpublish element ID 1">
  <img src="/system/themes/flexible/icons/visible--dark.svg" width="16" height="16" alt="Publish/unpublish element" class="color-scheme--dark" loading="lazy">
  <img src="/system/themes/flexible/icons/visible.svg" width="16" height="16" alt="Publish/unpublish element" class="color-scheme--light" loading="lazy">
</a>

i.e. there are now two <img>. dca-ajax-operations.js however only applies the change to the first one:

https://github.com/codefog/contao-haste/blob/e0dfd9904937a76f28fe883acc7b36e2317004b5/assets/dca-ajax-operations.js#L19

and only also only for the default (light) theme (so the action itself does work - just the icon is not replaced correctly).

Not sure what the best way to fix this is. Should the server return an additional nextIconDark which the JavaScript would then apply to the correct <img>?

qzminski commented 4 days ago

Yeah… it would be best if you can use the Contao core features as described in the manual. Or is there a reason you can't do so?

fritzmg commented 4 days ago

These are only available in Contao 5 (I think?). The extension in question still has Contao 4.13 compatibility.