NC's way of JQuery implementation is anoying...

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
13 years ago
In the end I altered the controls code to make jQuery work on all pages without conflicts:


In /controls/BaseNopUserControl.cs remark the Line 44 and add code:
// Page.ClientScript.RegisterClientScriptInclude(jquery, jquery);


Add code below above remark:
//Custom JQuery insert
            string jqueryBase = "http://www.google.com/jsapi";
            StringBuilder jblock = new StringBuilder("<script>");
            jblock.AppendLine("google.load(\"jquery\", \"1.4.4\");");
            jblock.AppendLine(" google.load(\"jqueryui\", \"1.8.7\");");
            jblock.AppendLine("</script>");

            Page.ClientScript.RegisterClientScriptInclude(jqueryBase, jqueryBase);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), jblock.ToString(), jblock.ToString());


Below that you can insert your custom JQuery plugins like so:

// Include custom plugin scripts
            string jcorners =  CommonHelper.GetStoreLocation() + "Scripts/jcorners.js";
            Page.ClientScript.RegisterClientScriptInclude(jcorners, jcorners);
            string slideshow =  CommonHelper.GetStoreLocation() + "Scripts/slideshow.js";
            Page.ClientScript.RegisterClientScriptInclude(slideshow, slideshow);
            string jdefault =  CommonHelper.GetStoreLocation() + "Scripts/jdefault.js";
            Page.ClientScript.RegisterClientScriptInclude(jdefault, jdefault);



In BaseNopPages.cs add replace whole code to OnPreRender(Eventargs e) section (line 170):

            string publicJS = CommonHelper.GetStoreLocation() + "Scripts/public.js";
            Page.ClientScript.RegisterClientScriptInclude(publicJS, publicJS);

            // include custom plugin scripts
            string jqueryBase = "http://www.google.com/jsapi";

            StringBuilder jblock = new StringBuilder("<script>");
            jblock.AppendLine("google.load(\"jquery\", \"1.4.4\");");
            jblock.AppendLine(" google.load(\"jqueryui\", \"1.8.7\");");
            jblock.AppendLine("</script>");
          
            Page.ClientScript.RegisterClientScriptInclude(jqueryBase, jqueryBase);
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), jblock.ToString(), jblock.ToString());
          
            //include custom plugin scripts
            string jcorners = CommonHelper.GetStoreLocation() + "Scripts/jcorners.js";
            Page.ClientScript.RegisterClientScriptInclude(jcorners, jcorners);
            string slideshow = CommonHelper.GetStoreLocation() + "Scripts/slideshow.js";
            Page.ClientScript.RegisterClientScriptInclude(slideshow, slideshow);
            string jdefault = CommonHelper.GetStoreLocation() + "Scripts/jdefault.js";
            Page.ClientScript.RegisterClientScriptInclude(jdefault, jdefault);
            base.OnPreRender(e);




The problem with this, if you want to add plugins or update de jquery version. You have to completely rebuild your site. So I rather remove all jquery related stuff from code behind and place it in de root.master page. Its much much much easier to update without comprising the site or need to rebuild the site code. You can change your jQuery code on the fly.
13 years ago
I checked out the implementation of the hosted code binding in the source while I was poking around on this other stuff. I finally implemented a solution for my path problem - the obvious easy one since I couldn't make anything else work (my coding skills are still a bit limited).
Of course I figured out I didn't need to load JQuery as it is already bound. I put the links for my other scripts in the head of the Root.Master with a Placeholder control and used ResolveUrl like this

    <asp:PlaceHolder id="CufonScripts" runat="server">
        <script src="<%=ResolveUrl("~/Scripts/cufon-yui.js") %>" type="text/javascript"></script>
        <script src="<%=ResolveUrl("~/Scripts/cufon-replace.js") %>" type="text/javascript"></script>
        <script src="<%=ResolveUrl("~/Scripts/Jikharev_400.font.js") %>" type="text/javascript"></script>
    </asp:PlaceHolder>


Now the scripts work on every single page.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.