Advertisement:

Author Topic: Overriding parent theme's topic.js file  (Read 1122 times)

Offline franhaselden

  • Semi-Newbie
  • *
  • Posts: 19
Overriding parent theme's topic.js file
« 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?

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Overriding parent theme's topic.js file
« Reply #1 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.
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline franhaselden

  • Semi-Newbie
  • *
  • Posts: 19
Re: Overriding parent theme's topic.js file
« Reply #2 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

Offline Arantor

  • Resident Overthinker
  • SMF Friend
  • SMF Legend
  • *
  • Posts: 69,458
    • StoryBB/StoryBB on GitHub
Re: Overriding parent theme's topic.js file
« Reply #3 on: October 15, 2018, 10:18:38 AM »
Not inside template_html_above()?
Don’t try to tell me that some power can corrupt a person. You haven’t had enough to know what it’s like.

No good deed goes unpunished / No act of charity goes unresented.

Offline franhaselden

  • Semi-Newbie
  • *
  • Posts: 19
Re: Overriding parent theme's topic.js file
« Reply #4 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.

Offline franhaselden

  • Semi-Newbie
  • *
  • Posts: 19
Re: Overriding parent theme's topic.js file
« Reply #5 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:

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

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