+1-888-365-2779
Try Now
More in this section

Forums / General Discussions / Adding JavaScript Files to Widget

Adding JavaScript Files to Widget

5 posts, 0 answered
  1. Andrew
    Andrew avatar
    15 posts
    Registered:
    28 Dec 2012
    01 Feb 2013
    Link to this post

    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

  2. Andrew
    Andrew avatar
    15 posts
    Registered:
    28 Dec 2012
    05 Feb 2013
    Link to this post

    Can anyone from Telerik please assist?

  3. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    06 Feb 2013
    Link to this post
    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:

    http://www.sitefinity.com/blogs/gabesumner/posts/gabe-sumners-blog/2011/09/01/how_to_use_jquery_and_other_javascript_libraries_in_sitefinity


    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/controls/utility-controls/resourcelinks-control


    http://www.sitefinity.com/documentation/documentationarticles/developers-guide/sitefinity-essentials/controls/working-with-control-designers/multi-view-control-designers/creating-a-view

    Regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  4. Andrew
    Andrew avatar
    15 posts
    Registered:
    28 Dec 2012
    07 Feb 2013
    Link to this post

    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

  5. Victor Velev
    Victor Velev avatar
    1345 posts
    Registered:
    06 Jul 2015
    12 Feb 2013
    Link to this post
    Hello Andy,

    Can you check the following article which contains a discussion on the proper loading of JQuery:

    http://www.sitefinity.com/developer-network/forums/general-discussions-/trouble-including-jquery


    Regards,
    Victor Velev
    the Telerik team
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
5 posts, 0 answered