djyde / cusdis

lightweight, privacy-friendly alternative to Disqus.
https://cusdis.com
GNU General Public License v3.0
2.63k stars 230 forks source link

Resize doesn't work with index.js #191

Open sajeshcherian opened 2 years ago

sajeshcherian commented 2 years ago

I am self-hosting cusdis on https://comments.simbly.me. The current widget/index.js is not resizing the iframe and as a result the iframe ends up with vertical scrollbars. I compared my index.js script with that of Neils' (@din14970) on his blog (https://nielscautaerts.xyz/) and found it to be slightly different. For reference, his looks like this: https://cusdis.nielscautaerts.xyz/js/cusdis.es.js. So do the rest of the cusdis implementations I was looking at on the web, including the hosted version.

I couldn't figure out the difference very well, but I replaced my JS file with Neils' and the vertical scrollbar issue is gone. (Everything else was working fine anyway). Replacing that JS file is all I did to make the scrollbar go away.

din14970 commented 2 years ago

I just try to use the latest docker container, I do no configuration/modification on the code.

sajeshcherian commented 2 years ago

I went with the manual installation instead of a docker image. Not sure how that made a difference.

zgq354 commented 1 year ago

It is because the window.postMessage is overwritten by the widget/index.js, see this line, and when the iframe send the resize message, the real window.postMessage didn't called.

To fix it there are some ways:

  1. include the cusdis.es.js as a module use a module attribute <script src="cusdis.es.js" module></script>
  2. change the function name at this line
  3. wrap the code into an IIFE, see my commit: https://github.com/zgq354/cusdis/commit/961fa9818d0b7395790c171810fe27535bd4a81f
image