Simple Machines Community Forum

Customizing SMF => SMF Coding Discussion => Topic started by: franhaselden on October 15, 2018, 08:53:28 AM

Title: Overriding parent theme's topic.js file
Post by: franhaselden on October 15, 2018, 08:53:28 AM
I was under the impression that, as with templates, simply placing a new version of a .js file in my theme's script dir would override the default SMF version of the file and use mine instead.

I want to change the way that the expandThumb function works, so I copied the topic.js file where this function resides and placed it in my theme's script dir, but it seems to still be using the default version.

Is there a place where I need to reset the path that it's pointing to?
Title: Re: Overriding parent theme's topic.js file
Post by: Arantor on October 15, 2018, 09:20:50 AM
If memory serves you basically need to hack the code that loads the file, there is no way other than that to override the JS files.

Look at your theme's index.template.php, the call should be in there.
Title: Re: Overriding parent theme's topic.js file
Post by: franhaselden on October 15, 2018, 10:17:10 AM
Can't find any reference call to topic.js in index.template.php - hmm. I'll have to pull down the full theme and search
Title: Re: Overriding parent theme's topic.js file
Post by: Arantor on October 15, 2018, 10:18:38 AM
Not inside template_html_above()?
Title: Re: Overriding parent theme's topic.js file
Post by: franhaselden on October 15, 2018, 10:23:07 AM
No, but when I look at the source code, topic.js script seems to be inserted in an odd location (I'd have expected either in the head or at the end of the page, but it's inserted just after the quickReply box).

I'll look through the other template files and see if I can find it.
Title: Re: Overriding parent theme's topic.js file
Post by: franhaselden on October 15, 2018, 10:24:20 AM
Found it in the bottom of the Display template. I'm guessing this is so it is only loaded on topic pages.

For anyone stumbling across this, I'm using Reseller theme and located it in my Display template file. The code includes /scripts/topic.js, but it's pointing to the default theme.

Original:

<script type="text/javascript" src="' . $settings['default_theme_url'] . '/scripts/topic.js"></script>

My change:

<script type="text/javascript" src="' . $settings['actual_theme_url'] . '/scripts/topic.js"></script>