thanks_for_posts
thanks_for_posts copied to clipboard
Add optional AJAX mode for thanking without page reloads
Adds an optional AJAX mode (disabled by default) to allow thanking and un-thanking to update the UI directly, without leaving the page.
Behind the scenes, the JS simply fetches the HTML from the existing routes, submits the relevant forms inside hidden iframe
s, and rewrites the existing elements with the updated DOM, so the added complexity is minimal (+184 lines, mostly JS). Any changes to themes, icons, translations, etc. are carried over from the non-AJAX UI, with no additional configuration required; this avoids, for example, the problems with icons from the 3rd-party extension, as reported in this thread.
Demo:
This is great addition, although I didn't plan ajaxifying the extension because It's complexify the ext maintenance. Thanks for the PR.
Now tested and working in desktop Chrome, Firefox, Edge, mobile Chrome, mobile Firefox. In Internet Explorer it fails, as expected, but the "failure" mode just falls back to the original (non-AJAX) behavior, which IMO is acceptable given that Internet Explorer Is Officially Dead.
I think the benefit of the 3rd-party extension is that it operates small json data portions rather than the whole DOM on the page, doesn't it.
I think the benefit of the 3rd-party extension is that it operates small json data portions rather than the whole DOM on the page, doesn't it.
That's correct — this version sacrifices some performance in favor of maximum simplicity. I figured this is a worthwhile tradeoff, as it's still no worse performance-wise than the non-AJAX version (EDIT: it's now slightly better, due to swapping out 1 GET request for a HEAD one); it simply reproduces the exact same data flow, just without any full-page navigations.
Is there any possibility of this feature making it into the extension? It seems super useful not to have to leave a thread page when liking a post, but using ajax to send the "like" instead.
Implemented with #119.
May I ask, how to add this AJAX behaviour. Just copy and overwrite the files from this repo into the "/forum/ext/gfksx/thanksforposts/" folder? Sorry for the dumb question, I searched, but couldn't find any instructions.
In general it should work with usual extension update instruction, like described here https://www.phpbb.com/extensions/installing/#updating but specifically for this very extension versions 2.0.6+. For updating from prior versions, see https://www.phpbb.com/customise/db/extension/thanks_for_posts_2/faq/2626