Make sure that Joomla namespace is defined otherwise define it!

This prevents error if core.js is not loaded by defining the Joomla namespace

Solves #5258 


I know it not by you :wink: 
but here can be more simple:
```javascript
if(window.toggleSidebar)
```