Adding JavaScript Files to Widget
Hello,
I'm having issues getting external JS files into my widget. I created the widget with Sitefinity Thunder, and it registered everything fine on the server, and I'm able to pull in my widget from the toolbox. I've tried multiple ways, including random embedding and path changes, on this Sitefinity 5.3 instance with no luck, so hopefully someone can tell me the correct way to add it.
Currently, I have the build action set on all these files to NOT embed, but rather stay the default of "Content". Here's my resource links definition at the top of my user control:
<sf:ResourceLinks ID="resourceLinks" runat="server">
<sf:ResourceFile Name="~/Custom/User Controls/Event Calendar/eventCalendar_v402/css/eventCalendar.css" Static="true" />
<sf:ResourceFile Name="~/Custom/User Controls/Event Calendar/eventCalendar_v402/css/eventCalendar_theme_responsive.css" Static="true" />
<sf:ResourceFile Name="~/Custom/User Controls/Event Calendar/eventCalendar_v402/css/paragridma.css" Static="true" />
<sf:ResourceFile JavaScriptLibrary="JQuery"></sf:ResourceFile>
<sf:ResourceFile Name="~/Custom/Widgets/EventCalendar/eventCalendar_v402/js/jquery.eventCalendar.js" />
<sf:ResourceFile Name="~/Custom/Widgets/EventCalendar/eventCalendar_v402/js/jquery.timeago.js" />
</sf:ResourceLinks>
They are not loading at all. What do I need to do to get these added in my user control (and note that the plugins need to be loaded AFTER JQuery).
PS. I tried adding a rad script manager to my user control, but it always says I can't have more than one instance on a page, even though I did not choose to add the manager when creating my test page.
Thanks,
Andy
Can anyone from Telerik please assist?
Hello Andrew,
You have correctly referenced the .js files, however please note that you need the following:
1. Register the script inside AssemblyInfo.cs class of the class library
sample:
[assembly: WebResource("TestControlProject.Resources.RotatorDesigner.js", "application/x-javascript")]
2. The script file build action should be "EmbeddedResource".
There are also several articles which can help you with the registration of custom JS files:
www.sitefinity.com/.../how_to_use_jquery_and_other_javascript_libraries_in_sitefinity
www.sitefinity.com/.../resourcelinks-control
www.sitefinity.com/.../creating-a-view
Regards,
Victor Velev
the Telerik team
Thanks for the info. I have things working (my ending problem was actually that I forgot to put UseEmbeddedThemes="false" in the definition of my ResourceLinks tag, and I didn't need to register the files in the assembly).
However, I still have another issue. The JS files I'm attempting to load are a JQuery plugin. The problem I'm seeing is that I can't get my files to load after JQuery does, so the scripts always fail because they don't have access to $ from JQuery. How can I make my scripts load after JQuery when defining my custom JS files in my user control/widget?
Thanks, Andy
Hello Andy,
Can you check the following article which contains a discussion on the proper loading of JQuery:
www.sitefinity.com/.../trouble-including-jquery
Regards,
Victor Velev
the Telerik team