This is a migrated thread and some comments may be shown as answers.

JQuery noConflict and JQuery plugins

2 Answers 607 Views
ScriptManager and StyleSheetManager
This is a migrated thread and some comments may be shown as answers.
Gene
Top achievements
Rank 1
Gene asked on 23 Jun 2010, 05:10 PM
I would like to make a suggestion/observation about the use of the JQuery library in the Telerik controls.  First of all, let me say that I am extremely appreciative of your use of it - I love JQuery and think it makes my development life easier.

That being said, I noticed that, in Telerik's implementation of JQuery, you have the following lines at the end of your jQuery library:

// Move jQuery to $telerik 
$telerik.$ = jQuery.noConflict(true); 
 

What I wonder is, why are you passing true to noConflict?  In the JQuery docs, it says this:

If necessary, we can free up the jQuery name as well by passing true as an argument to the method. This is rarely necessary, and if we must do this (for example, if we need to use multiple versions of the jQuery library on the same page), we need to consider that most plug-ins rely on the presence of the jQuery variable and may not operate correctly in this situation.

This is indeed the problem I am seeing when trying to use jQuery plugins with my installation.  I am having to modify every single plugin, so instead of it passing the jQuery object to the plugin, it passes $telerik.$.  I don't see the need to "hide" the jQuery object in this way.  Why can't we have access to the jQuery object just as it should be, through jQuery and through $?  Currently, to make my coding shorter, I am calling this line after the telerik scripts are loaded:

window.$ = $telerik.$; 

This is just so I can use typical jQuery shorthand, like $(document).ready().  What was the need for obscuring the JQuery object in $telerik.$?  Wouldn't it be better to keep it the way it was intended, and allow the developers using your framework to decide whether to call noConflict if they are using other frameworks in addition to yours?

Thanks,
Gene






2 Answers, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 24 Jun 2010, 01:50 PM
Hello Gene,

Thank you for the excellent question. The reason we use noConflict is exactly the one stated in the documentation - we need to support multiple versions of jQuery on the page.

We, as component vendor, cannot make assumptions whether the user has jQuery on the page or what version it is. So we do the next best thing and hide the jQuery instance from the global namespace.

That doesn't mean that we can't undo this. If you want to bring back the jQuery and $ globals use the following script references:

<telerik:RadScriptManager runat="server" ID="RadScriptManager1"
     <Scripts
         <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" /> 
         <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" /> 
         <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQueryInclude.js" />
     </Scripts
  </telerik:RadScriptManager

I hope this helps.

Sincerely yours,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Gene
Top achievements
Rank 1
answered on 24 Jun 2010, 02:37 PM
Tsvetomir,

Thanks a lot for your quick reply.  That makes perfect sense.  I was not aware of the jQueryInclude, but that's exactly what I needed.  Looking back at the documentation, I see where this is documented now:

http://www.telerik.com/help/aspnet-ajax/using-jquery-plugins.html

Guess I should have RTFM :-)







Thanks,
Gene
Tags
ScriptManager and StyleSheetManager
Asked by
Gene
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Gene
Top achievements
Rank 1
Share this question
or