1

My "share this" button is written in the index.php and thus appear also in frontend straight into my editor. How could I disable it (only) when I use frontend editing?

in my template/index.php :

<head>
<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="http://w.sharethis.com/button/buttons.js"></script>
<script type="text/javascript" src="http://s.sharethis.com/loader.js"></script>
</head>

<body>
<script type="text/javascript">stLight.options({doNotCopy:true});</script>
<script>
var options={ "publisher": "aef4218e-316d-45b9-9571-fb565e462989", "position": "left", "ad": { "visible": false, "openDelay": 5, "closeDelay":0}, "chicklets": { "items": ["facebook", "twitter", "email"]}};
var st_hover_widget = new sharethis.widgets.hoverbuttons(options);
</script>
</body>
  • index.php is separate for front-end and back-end. For which index.php are you talking about? – Gaurav Jul 11 '14 at 10:39
2

You could wrap the JS loading into an if clause which checks if the current layout is an edit layout. Something like this (untested):

if (JFactory::getApplication()->input->get('layout') != 'edit')
{
    // Load your JS here
}
2

It's better if you avoid any modification to core files. If not, you can easily lost all changes when Joomla is updated to a new release.

To implement common scripts, you can download extensions from JED http://extensions.joomla.org/ There are several already developed modules for sharethis. This option is the best to have configuration support on proven use cases.

If you prefer to install your own custom script, there also several extensions for this. My personal choice is NoNumber's Sourcerer http://www.nonumber.nl/extensions/sourcerer

In both cases, front-end assigment is solved. Furthermore, plenty of assigment conditions are available to assign the script.

  • 2
    I think he is referring to the index.php from a template. – Valentin Despa Jul 11 '14 at 12:04
  • Thanks but I was indeed referring the index.php of my template (sorry for the misleading info). And when its such a simple thing I prefer to don't use modules to avoid upgrade and other hassles. But thanks again! – JinSnow Jul 11 '14 at 15:36
  • Even though, I wouldn't change the template index. From a content management point of view, it's much better to have modules to assign, instead of locking the template in a fixed version. Moreover, it's very easy to forget all modified files in minor edits. – Anibal Jul 11 '14 at 23:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.