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

Forums / Developing with Sitefinity / Help - Need process to use custom javascript libraries (work with jquery)

Help - Need process to use custom javascript libraries (work with jquery)

7 posts, 0 answered
  1. Damien
    Damien avatar
    3 posts
    Registered:
    23 Oct 2013
    25 Nov 2013
    Link to this post
    Hi, 
    First sorry for my bad english.
    After many hours to try use a js plugin (it work with our jquery version) and navigation on forum threads, i dont understand the way to use it.
    I probably missed something to do.

    Should somebody explain me how to use a custom js lib (work with j query, so it need be loaded) IN A USER CONTROL (not master page).
    I probably dont understand how resourcelinks works.

    on each threads i have read, never all the process is describe.
    please say me this steps:

    -which folder may i use to js files (app_themes ... global?)

    -how do i resolve path on a custom user control (or template from basics ones)
                             should i use resourcelinks, or something else?

    I m using sitefinity 6, and i m now testing it for my company to buy it, but i have a lot of trouble with that, so i really need help.

    Thanks a lot
  2. Jonathan
    Jonathan avatar
    119 posts
    Registered:
    19 Dec 2012
    25 Nov 2013 in reply to Damien
    Link to this post
    This is the best article i have found for use <sf:ResourceLinks>.

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

      I typically have my jQuery loaded on a master page and then in my controls use a standard <script src="/path/to/js"></scirpt> to put other libraries.  In regards to where to store the JavaScript I typically place it in ~/App_DataSitefinity/WebsiteTemplates/{NameOfTheme}/App_Themes/{NameOfTheme}/JS
    Make sure in your .ascx when you try and use your library that you use $(window).load();
  3. Damien
    Damien avatar
    3 posts
    Registered:
    23 Oct 2013
    28 Nov 2013
    Link to this post
    Thanks for your fast answer, 
    i tried tu use resource link, but i ll try this way.
  4. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Nov 2013 in reply to Damien
    Link to this post
    You SHOULD load jquery though resourcelinks

    Like this
    <sitefinity:ResourceLinks runat="server" UseEmbeddedThemes="false">
        <sitefinity:ResourceFile JavaScriptLibrary="JQuery" />
        <sitefinity:ResourceFile JavaScriptLibrary="KendoWeb" />
    </sitefinity:ResourceLinks>

    I have this right above </head> and never have an issue...just make sure the jsembed control loads at the bottom, OR you include your scripts in resourcelinks...never had an issue.

    The reason you need jQuery loading in resourcelinks is every telerik widget that uses jquery has it defined, so if you have it in your header as <script src='...'/> then resource links has no idea it's already loaded and in the page, so you'll get 2 jquery instances loading.

    The resourcelinks controls main function is to make sure a script loads ONLY once.  So if you have 42 widgets on the page all needing jquery, then it doesn't load the thing 42 times, only once.
  5. Damien
    Damien avatar
    3 posts
    Registered:
    23 Oct 2013
    28 Nov 2013
    Link to this post
    The problem for me is not to load  jquery, it works fine. i use this code (resourcelinks and resourceFiles) in user controls.
    its the way to use my own scripts. i tried to load it with resource links, but if i understand, i should use resourcefile for embeded libraries (like jquery, kendo or jquery ui) in master pages, and use a <script> tag for my own script.

    but, if i use script tag in user controls, if i use 2 same widgets, i ll have 2 times same script right?
  6. Steve
    Steve avatar
    3037 posts
    Registered:
    03 Dec 2008
    28 Nov 2013 in reply to Damien
    Link to this post
    Yeah if you (in your widgets) just use script tags or the javascript widget itself...2 widgets = 2 same scripts.

    ResourceLinks was designed to solve that for you
  7. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    Registered:
    21 Nov 2016
    02 Dec 2013
    Link to this post
    Hello,

    Thank you Steve for your help. Damien you could also take a look at Gabe Sumners blogs post on the matter:

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

    Example:

    <%@ Register Assembly="Telerik.Sitefinity" Namespace="Telerik.Sitefinity.Web.UI" TagPrefix="sf" %>
    <sf:ResourceLinks ID="resourcesLinks" runat="server">
     <sf:ResourceFile JavaScriptLibrary="JQuery"/>
    </sf:ResourceLinks>

    Where the javascript library property accepts the following values:

    public enum JavaScriptLibrary
       {
           /// <summary>
           /// No library
           /// </summary>
           None,
           /// <summary>
           /// jQuery JavaScript library
           /// </summary>
           JQuery,
           /// <summary>
           /// Mootools JavaScript library
           /// </summary>
           Mootools,
           /// <summary>
           /// prototype JavaScript library
           /// </summary>
           Prototype,
           /// <summary>
           /// JQuery FancyBox
           /// </summary>
           JQueryFancyBox,
           /// <summary>
           /// Kendo.all scripts
           /// </summary>
           KendoAll,
           /// <summary>
           /// Kendo.web scripts. These scripts are included in Kendo.all.
           /// </summary>
           KendoWeb,
           /// <summary>
           /// jQuery Cookie library
           /// </summary>
           JQueryCookie,
           /// <summary>
           /// jQuery Validate library
           /// </summary>
           JQueryValidate,
           /// <summary>
           /// jQuery UI library
           /// </summary>
           JQueryUI
       }

    Regards,
    Stefani Tacheva
    Telerik
    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
7 posts, 0 answered