And I asked this because the way NC has implemented jQuery through .cs back end code is annoying, irritating and blocking me considerably in my customization and creativity as front end designer.
The problems using jQuery in the way it is now:
One:
A big problem with NC's way of binding jQuery in the source is that sometimes the jQuery gets loaded/placed after the jQuery plugin script when the page is build. Thats not a good thing and gives JS errors. The scripts belongs in the head section.
Two:
If you want to add (another) custom jQuery script you need to rebuild again.
Three:
Currently the jQuery is binded on the search and product page in the shop. If you want to use jQuery on all/other pages you have to add the jQuery bind in the XX.CS of every page that is used in the shop and rebuild.
Four: If you want to add a jQuery plugin you need to add it to the source and need to rebuild.
Better implementation of jQuery:
Place code in master pages head section.
<head>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
<![CDATA[
google.load("jquery", "1.4.2"); // jquery codebase
// google.load("jqueryui", "1.7.2"); // basic ui functions
// google.load("swfobject", "2.2"); // flashplayer object
]]>
</script>
<!--
ADD YOUR CUSTOM jQuery plugins/scripts here if needed
-->
</head>
Advances:
1) This is easy to manage without even the need to rebuild project.
2) No need to add a Bind to jQuery in source.
3) Saves bandwidth because our friends at Google delivering the jQuery main code.
4) Because of google script block browser caches the load of the script.
5) Add plugins or custom script without the need to rebuild.
6) ease of use, saves time.
7) Can use jQuery on any page without the need of CS code and re-building.
8) Added the scripts to the head section where it belongs.
To make up for the time being add the following to BaseNopUserControl.cs:
In BaseNopUserControl.cs
protected virtual void BindJQuery()
{
//string jquery = CommonHelper.GetStoreLocation() + "Scripts/jquery-1.4.min.js";
string jqueryBase = "http://www.google.com/jsapi";
StringBuilder jblock = new StringBuilder("<script>");
jblock.AppendLine("google.load(\"jquery\", \"1.4.2\");");
// ## IF Needed:
// jblock.AppendLine(" google.load(\"jqueryui\", \"1.7.2\");");
// jblock.AppendLine(" google.load(\"swfobject\", \"2.2\");");
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);
}
In BaseNopPage.cs:
protected override void OnPreRender(EventArgs e)
{
string publicJS = CommonHelper.GetStoreLocation() + "Scripts/public.js";
Page.ClientScript.RegisterClientScriptInclude(publicJS, publicJS);
string jqueryBase = "http://www.google.com/jsapi";
StringBuilder jblock = new StringBuilder("<script>");
jblock.AppendLine("google.load(\"jquery\", \"1.4.2\");");
// ## IF Needed:
// jblock.AppendLine(" google.load(\"jqueryui\", \"1.7.2\");");
// jblock.AppendLine(" google.load(\"swfobject\", \"2.2\");");
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);
}