-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
base: master
Are you sure you want to change the base?
Commits on Sep 5, 2024
-
Create and initialize
rcmail
in external JS fileWe'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.
Configuration menu - View commit details
-
Copy full SHA for a0bdebc - Browse repository at this point
Copy the full SHA a0bdebcView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for c233a41 - Browse repository at this point
Copy the full SHA c233a41View commit details -
Configuration menu - View commit details
-
Copy full SHA for 28edc31 - Browse repository at this point
Copy the full SHA 28edc31View commit details -
Configuration menu - View commit details
-
Copy full SHA for 4d66faf - Browse repository at this point
Copy the full SHA 4d66fafView commit details -
Configuration menu - View commit details
-
Copy full SHA for aa144eb - Browse repository at this point
Copy the full SHA aa144ebView commit details -
Configuration menu - View commit details
-
Copy full SHA for 218e18f - Browse repository at this point
Copy the full SHA 218e18fView commit details -
Configuration menu - View commit details
-
Copy full SHA for c04dad5 - Browse repository at this point
Copy the full SHA c04dad5View commit details -
Configuration menu - View commit details
-
Copy full SHA for 66361e6 - Browse repository at this point
Copy the full SHA 66361e6View commit details -
Configuration menu - View commit details
-
Copy full SHA for 6a0a98e - Browse repository at this point
Copy the full SHA 6a0a98eView commit details -
Configuration menu - View commit details
-
Copy full SHA for bc2ce23 - Browse repository at this point
Copy the full SHA bc2ce23View commit details -
Configuration menu - View commit details
-
Copy full SHA for 600e864 - Browse repository at this point
Copy the full SHA 600e864View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for a6a052c - Browse repository at this point
Copy the full SHA a6a052cView commit details -
Configuration menu - View commit details
-
Copy full SHA for b70065f - Browse repository at this point
Copy the full SHA b70065fView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 11ccc83 - Browse repository at this point
Copy the full SHA 11ccc83View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 125f992 - Browse repository at this point
Copy the full SHA 125f992View commit details -
Strip check for 'plugin.'-prefix of JS-calls
This is done in rcmail_output_html already.
Configuration menu - View commit details
-
Copy full SHA for 56e3eaa - Browse repository at this point
Copy the full SHA 56e3eaaView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for f879564 - Browse repository at this point
Copy the full SHA f879564View commit details -
Rename rcmail_output_html's
commands
tojs_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.
Configuration menu - View commit details
-
Copy full SHA for 00ed0d8 - Browse repository at this point
Copy the full SHA 00ed0d8View commit details -
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).
Configuration menu - View commit details
-
Copy full SHA for 0b7d4d1 - Browse repository at this point
Copy the full SHA 0b7d4d1View commit details -
Configuration menu - View commit details
-
Copy full SHA for 1d773b6 - Browse repository at this point
Copy the full SHA 1d773b6View commit details -
html class: Allow to pass array as content
This allows for a little cleaner code
Configuration menu - View commit details
-
Copy full SHA for b64dbd0 - Browse repository at this point
Copy the full SHA b64dbd0View commit details -
Configuration menu - View commit details
-
Copy full SHA for be692ff - Browse repository at this point
Copy the full SHA be692ffView commit details -
Configuration menu - View commit details
-
Copy full SHA for 1f0bcb4 - Browse repository at this point
Copy the full SHA 1f0bcb4View commit details -
Configuration menu - View commit details
-
Copy full SHA for f322b76 - Browse repository at this point
Copy the full SHA f322b76View commit details -
Configuration menu - View commit details
-
Copy full SHA for 137d7ff - Browse repository at this point
Copy the full SHA 137d7ffView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6885cff - Browse repository at this point
Copy the full SHA 6885cffView commit details -
Configuration menu - View commit details
-
Copy full SHA for 6cb1052 - Browse repository at this point
Copy the full SHA 6cb1052View commit details -
Configuration menu - View commit details
-
Copy full SHA for f919f89 - Browse repository at this point
Copy the full SHA f919f89View commit details -
Configuration menu - View commit details
-
Copy full SHA for ea75d9e - Browse repository at this point
Copy the full SHA ea75d9eView commit details -
Configuration menu - View commit details
-
Copy full SHA for ac2bb21 - Browse repository at this point
Copy the full SHA ac2bb21View commit details -
Configuration menu - View commit details
-
Copy full SHA for 9098a60 - Browse repository at this point
Copy the full SHA 9098a60View commit details -
Configuration menu - View commit details
-
Copy full SHA for 846bf9b - Browse repository at this point
Copy the full SHA 846bf9bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4062096 - Browse repository at this point
Copy the full SHA 4062096View commit details -
Configuration menu - View commit details
-
Copy full SHA for 7e8010b - Browse repository at this point
Copy the full SHA 7e8010bView commit details -
Configuration menu - View commit details
-
Copy full SHA for 04937df - Browse repository at this point
Copy the full SHA 04937dfView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for e64be8f - Browse repository at this point
Copy the full SHA e64be8fView commit details -
Configuration menu - View commit details
-
Copy full SHA for d93b381 - Browse repository at this point
Copy the full SHA d93b381View commit details -
Configuration menu - View commit details
-
Copy full SHA for a76698d - Browse repository at this point
Copy the full SHA a76698dView commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for 8b71716 - Browse repository at this point
Copy the full SHA 8b71716View commit details -
Configuration menu - View commit details
-
Copy full SHA for f7c63e0 - Browse repository at this point
Copy the full SHA f7c63e0View commit details -
Configuration menu - View commit details
-
Copy full SHA for 31233ec - Browse repository at this point
Copy the full SHA 31233ecView commit details -
Configuration menu - View commit details
-
Copy full SHA for e15b8e1 - Browse repository at this point
Copy the full SHA e15b8e1View commit details -
Configuration menu - View commit details
-
Copy full SHA for c180952 - Browse repository at this point
Copy the full SHA c180952View commit details -
Configuration menu - View commit details
-
Copy full SHA for 00babee - Browse repository at this point
Copy the full SHA 00babeeView commit details -
Configuration menu - View commit details
-
Copy full SHA for 73958c5 - Browse repository at this point
Copy the full SHA 73958c5View commit details -
Configuration menu - View commit details
-
Copy full SHA for d08d6cb - Browse repository at this point
Copy the full SHA d08d6cbView commit details -
Configuration menu - View commit details
-
Copy full SHA for 4909f13 - Browse repository at this point
Copy the full SHA 4909f13View commit details -
Configuration menu - View commit details
-
Copy full SHA for e7bc61a - Browse repository at this point
Copy the full SHA e7bc61aView commit details -
Configuration menu - View commit details
-
Copy full SHA for f9abd32 - Browse repository at this point
Copy the full SHA f9abd32View commit details -
Configuration menu - View commit details
-
Copy full SHA for bf1faee - Browse repository at this point
Copy the full SHA bf1faeeView commit details -
Have to repeat attaching event handlers after a clone().
Configuration menu - View commit details
-
Copy full SHA for e08c14a - Browse repository at this point
Copy the full SHA e08c14aView commit details -
Hand around Nodes instead of using innerHTML
This allows to strip 'unsafe-eval' from the CSP.
Configuration menu - View commit details
-
Copy full SHA for d6daeed - Browse repository at this point
Copy the full SHA d6daeedView commit details -
Configuration menu - View commit details
-
Copy full SHA for de84737 - Browse repository at this point
Copy the full SHA de84737View commit details -
innerText is enough here, don't need innerHTML
innerHTML requires 'unsafe-eval' in the CSP, while innerText doesn't.
Configuration menu - View commit details
-
Copy full SHA for 6e2e1a1 - Browse repository at this point
Copy the full SHA 6e2e1a1View commit details -
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.
Configuration menu - View commit details
-
Copy full SHA for a927b13 - Browse repository at this point
Copy the full SHA a927b13View commit details -
Configuration menu - View commit details
-
Copy full SHA for fedc7d2 - Browse repository at this point
Copy the full SHA fedc7d2View commit details