Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove inline Javascript, part I #9513

Open
wants to merge 56 commits into
base: master
Choose a base branch
from

Commits on Sep 5, 2024

  1. Create and initialize rcmail in external JS file

    We're relying on parsing order here, which means that app.js must(!) be
    loaded after its dependencies, but before all other scripts, and
    rcmail-init.js must be loaded and the end of the page.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    a0bdebc View commit details
    Browse the repository at this point in the history
  2. Replace inline scripts by JSON-data with instructions

    We're now sending JSON-encoded data that instructs the interpreting side
    (app.js), which callbacks to call (or events to trigger) with the given
    arguments. Basically that means server code now calls $output->command() instead
    of add_script().
    This way the change is not too radical but we still can get rid of
    inline Javascript code.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    c233a41 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    28edc31 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    4d66faf View commit details
    Browse the repository at this point in the history
  5. De-inline markasjunk

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    aa144eb View commit details
    Browse the repository at this point in the history
  6. De-inline jquery-ui

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    218e18f View commit details
    Browse the repository at this point in the history
  7. De-inline managesieve

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    c04dad5 View commit details
    Browse the repository at this point in the history
  8. De-inline googiespell

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    66361e6 View commit details
    Browse the repository at this point in the history
  9. De-inline compose.php

    Signed-off-by: Pablo Zmdl <pablo@nextcloud.com>
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    6a0a98e View commit details
    Browse the repository at this point in the history
  10. De-inline new_user_dialog

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    bc2ce23 View commit details
    Browse the repository at this point in the history
  11. Initialize rcmail from app.js

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    600e864 View commit details
    Browse the repository at this point in the history
  12. Initialize googiespell in editor.js, not external file

    This looks like more than it is, because now most of the
    intialization code of rcube_text_editor is wrapped in an init-function,
    which enables us to call other functions.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    a6a052c View commit details
    Browse the repository at this point in the history
  13. Remove redundant json-encoding

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    b70065f View commit details
    Browse the repository at this point in the history
  14. Use data-attribute for js-data to avoid getting data encoded

    None of the methods to get the content of a DOM element (`.innerHTML`,
    `.innerText`, ...) return the content unchanged as it went over the
    wire.
    Using a data-attribute we can achieve that and need not to worry anymore
    about which solution will encode which value and thus break a feature.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    11ccc83 View commit details
    Browse the repository at this point in the history
  15. Clean up spellchecker initialization

    We don't need the global variable, so we got rid of it.
    Also since we're passing the config details encoded anyway, we can also
    use an array instead of a list of key-value pairs, and we can skip the
    quoting, too.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    125f992 View commit details
    Browse the repository at this point in the history
  16. Strip check for 'plugin.'-prefix of JS-calls

    This is done in rcmail_output_html already.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    56e3eaa View commit details
    Browse the repository at this point in the history
  17. Trigger JS only via methods on rcmail, not events

    Having only one way results in clearer code, and using the
    "plugin."-prefix for triggering events isn't obvious, either.
    
    Tacking all function calls onto rcmail/rcube_webmail.prototype maybe
    isn't the best pattern either, because that object/prototype gets huge,
    but it's established in the code base, so it isn't suprising.
    
    Another advantage is that trying to call a missing functions fails
    loudly, whereas triggering an event that nothing listens for doesn't
    produce any error.
    
    The functionality is still present to not break plugins, but our own
    code doesn't use it anymore.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    f879564 View commit details
    Browse the repository at this point in the history
  18. Rename rcmail_output_html's commands to js_calls

    It's a more telling name, and avoids confusion with the `commands` in
    app.js.
    
    The previous method name is still available to avoid breaking plugin
    code, but it is marked as deprecated.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    00ed0d8 View commit details
    Browse the repository at this point in the history
  19. Add eventListeners from data-attributes

    This allows server code to specify events on attributes without using
    inline event listeners (which require a very lax CSP and should be
    avoided).
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    0b7d4d1 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    1d773b6 View commit details
    Browse the repository at this point in the history
  21. html class: Allow to pass array as content

    This allows for a little cleaner code
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    b64dbd0 View commit details
    Browse the repository at this point in the history
  22. Git-ignore *.min.js

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    be692ff View commit details
    Browse the repository at this point in the history
  23. De-inline installer

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    1f0bcb4 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    f322b76 View commit details
    Browse the repository at this point in the history
  25. Fix codestyle errors

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    137d7ff View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    6885cff View commit details
    Browse the repository at this point in the history
  27. Configuration menu
    Copy the full SHA
    6cb1052 View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    f919f89 View commit details
    Browse the repository at this point in the history
  29. Configuration menu
    Copy the full SHA
    ea75d9e View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    ac2bb21 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    9098a60 View commit details
    Browse the repository at this point in the history
  32. Configuration menu
    Copy the full SHA
    846bf9b View commit details
    Browse the repository at this point in the history
  33. Configuration menu
    Copy the full SHA
    4062096 View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    7e8010b View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    04937df View commit details
    Browse the repository at this point in the history
  36. Allow to run event-listener-attacher for given root element

    This allows to call it on specific elements only, e.g. after they've
    been inserted late to the DOM.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    e64be8f View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    d93b381 View commit details
    Browse the repository at this point in the history
  38. De-inline program/include

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    a76698d View commit details
    Browse the repository at this point in the history
  39. Move rcube_webmail static methods to instance

    There's no apparent reason for them to be static, and no explanation,
    but as instance methods they are directly callable from the de-inlined
    event-handlers and we save some helper methods, which is good.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    8b71716 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    f7c63e0 View commit details
    Browse the repository at this point in the history
  41. fixup de-inline actions

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    31233ec View commit details
    Browse the repository at this point in the history
  42. De-inline skins/elastic

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    e15b8e1 View commit details
    Browse the repository at this point in the history
  43. Configuration menu
    Copy the full SHA
    c180952 View commit details
    Browse the repository at this point in the history
  44. Configuration menu
    Copy the full SHA
    00babee View commit details
    Browse the repository at this point in the history
  45. De-eval HTTP response handling

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    73958c5 View commit details
    Browse the repository at this point in the history
  46. WIP: TODO comment

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    d08d6cb View commit details
    Browse the repository at this point in the history
  47. Fix log statement

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    4909f13 View commit details
    Browse the repository at this point in the history
  48. json_encode in html class

    This make it easier for the calling code.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    e7bc61a View commit details
    Browse the repository at this point in the history
  49. Remove useless call

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    f9abd32 View commit details
    Browse the repository at this point in the history
  50. De-inline app.js, part 1

    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    bf1faee View commit details
    Browse the repository at this point in the history
  51. Fix image upload

    Have to repeat attaching event handlers after a clone().
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    e08c14a View commit details
    Browse the repository at this point in the history
  52. Hand around Nodes instead of using innerHTML

    This allows to strip 'unsafe-eval' from the CSP.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    d6daeed View commit details
    Browse the repository at this point in the history
  53. Configuration menu
    Copy the full SHA
    de84737 View commit details
    Browse the repository at this point in the history
  54. innerText is enough here, don't need innerHTML

    innerHTML requires 'unsafe-eval' in the CSP, while innerText doesn't.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    6e2e1a1 View commit details
    Browse the repository at this point in the history
  55. Re-add lost preventDefault

    If the last argument to a data-on* attribute is an object (associative
    array in PHP), it is used as options, which allow to specify if
    preventDefault() should be called on the event.
    This is relevant for some parts of the code and got lost in previous
    changes.
    pabzm committed Sep 5, 2024
    Configuration menu
    Copy the full SHA
    a927b13 View commit details
    Browse the repository at this point in the history
  56. Configuration menu
    Copy the full SHA
    fedc7d2 View commit details
    Browse the repository at this point in the history