Please upgrade here. These earlier versions are no longer being updated and have security issues.
HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

JS in Body is not getting loaded inside the discussions

phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
edited August 2015 in Vanilla 2.0 - 2.8

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.

  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited August 2015

    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.

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • phreakphreak Vanilla*APP (White Label) & Vanilla*Skins Shop MVP
    edited August 2015

    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

    • VanillaAPP | iOS & Android App for Vanilla - White label app for Vanilla Forums OS
    • VanillaSkins | Plugins, Themes, Graphics and Custom Development for Vanilla
  • 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.

Sign In or Register to comment.