Widget outputting JS as plain text

Did you try to put propper <script>tags around your code?

So instead of inserting the raw JS code, I suppose you encapsule the code it like this:

<script>
// JS goes here
</script>

This at least works with the common text widget.