custom_portal.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. ===============================================================================
  3. This JS file may be used to customize the YunoHost user portal *and* also
  4. will be loaded in all app pages if the app nginx's conf does include the
  5. appropriate snippet.
  6. You can monkeypatch init_portal (loading of the user portal) and
  7. init_portal_button_and_overlay (loading of the button and overlay...) to do
  8. custom stuff
  9. ===============================================================================
  10. */
  11. var app_tile_colors = ['redbg','purpledarkbg','darkbluebg','orangebg','greenbg', 'yellowbg','lightpinkbg','pinkbg','turquoisebg','lightbluebg', 'bluebg'];
  12. function set_app_tile_style(el)
  13. {
  14. // Select a color value from the App label
  15. randomColorNumber = parseInt(el.textContent, 36) % app_tile_colors.length;
  16. // Add color class.
  17. el.classList.add(app_tile_colors[randomColorNumber]);
  18. }
  19. // Monkeypatch init_portal to customize the app tile style
  20. init_portal_original = init_portal;
  21. init_portal = function()
  22. {
  23. init_portal_original();
  24. Array.each(document.getElementsByClassName("app-tile"), set_app_tile_style);
  25. }
  26. /*
  27. * Monkey patching example to do custom stuff when loading inside an app
  28. *
  29. init_portal_button_and_overlay_original = init_portal_button_and_overlay;
  30. init_portal_button_and_overlay = function()
  31. {
  32. init_portal_button_and_overlay_original();
  33. // Custom stuff to do when loading inside an app
  34. }
  35. */