JS in Body is not getting loaded inside the discussions
Hi all,
I placed some JS in the mobile version of my theme to integrate a sliding burger NAV and a "Slide to Top"-Buttons. I placed it between the {literal} tags inside the body and it gets loaded on almost all pages and both functions work. Only inside the discussion page it doesn't work.
Could it be an ID issue?
I'm not really capable to find the error. What would you recommend to look into as it's only targeting the discussion/comment pages itself. Thanx for help.
Here is the code i set in.
{literal} <script type="text/javascript" language="javascript" src="http://www.webpage.com/_mobile/js/trunk.js"></script> <script type='text/javascript'> function toggleDiv(divId) { $("#"+divId).slideToggle(); } </script> <script type='text/javascript'> $(document).ready(function(){ $(window).scroll(function(){ if ($(this).scrollTop() > 100) { $('.scrollToTop').fadeIn(); } else { $('.scrollToTop').fadeOut(); } }); $('.scrollToTop').click(function(){ $('html, body').animate({scrollTop : 0},500); return false; }); }); </script> {/literal}
- VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
- VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
Comments
Why are you putting a script like this in the body? It doesn't need to be.
grep is your friend.
What woudl you recommend @x00?
Whatever i can i move below the fold. Vanilla itself loads a lot of Javascripts above the fold, which is not super smart. So i move some stuff down there. Also it doesn't solve the problem if i move the script somewhere else in the template.
Alright i found out that @R_J 's "Inform New Comments" is breaking my script or vice versa.
@R_J: I do not really know where the error comes from, but might it be an idea to add a more unique ID or Class to the plugin so that there are no JS conflicts like this? Also which is more critical is that it also breaks the Advanced Editors functionality.
http://vanillaforums.org/addon/informnewcomments-plugin
I would recommend using themehooks to add the script to the head. I can't see a reason to have it in the body nor as inline code.
$(document).ready
waits for the DOM to be available anyway.grep is your friend.