Beispiel #1
0
        /// <summary>
        /// Registers resource reference.
        /// </summary>
        /// <param name="register">The register.</param>
        /// <param name="resourceKey">The resource key.</param>
        /// <param name="throwException">if set to <c>true</c> [throw exception].</param>
        /// <param name="tagName">Name of the tag.</param>
        /// <param name="attribbutes">The attribbutes.</param>
        /// <returns></returns>
        private static System.Web.Mvc.MvcHtmlString RegisterResource(ResourceRegister register, string resourceKey, bool throwException, string tagName, KeyValuePair <string, string>[] attribbutes)
        {
            string output;

            System.Web.Mvc.MvcHtmlString result;

            if (throwException)
            {
                register.RegisterResource(resourceKey);
                output = ResourceHelper.GenerateTag(tagName, attribbutes);
                result = new System.Web.Mvc.MvcHtmlString(output);
            }
            else if (register.TryRegisterResource(resourceKey))
            {
                output = ResourceHelper.GenerateTag(tagName, attribbutes);
                result = new System.Web.Mvc.MvcHtmlString(output);
            }
            else
            {
                result = System.Web.Mvc.MvcHtmlString.Empty;
            }

            return(result);
        }
Beispiel #2
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptPath">The path to the JavaScript file.</param>
 /// <param name="tryUseScriptManager">Indicates whether to use script manager(if exists) when register JavaScript reference.
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 /// <remarks>
 /// This method uses directly the resource from the <see cref="scriptPath" />.
 /// In case you want to use embedded scripts from Sitefinity check <see cref="ResourceHelper.Script(this HtmlHelper helper, ScriptRef scriptReference, bool throwException = false)" />.
 /// </remarks>
 public static MvcHtmlString Script(this HtmlHelper helper, string scriptPath, bool tryUseScriptManager)
 {
     return(ResourceHelper.Script(helper, scriptPath, null, false, tryUseScriptManager));
 }
Beispiel #3
0
 /// <summary>
 /// Registers style sheet reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="resourcePath">The path to the CSS file.</param>
 /// <param name="sectionName">The name of the section that will render this script. If null it will render on the same place of the page</param>
 /// <param name="throwException">Indicates whether to throw an exception if the specified section does not exist.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString StyleSheet(this HtmlHelper helper, string resourcePath, string sectionName, bool throwException)
 {
     return(ResourceHelper.RegisterResource(helper.ViewContext.HttpContext, resourcePath, ResourceType.Css, sectionName, throwException));
 }
Beispiel #4
0
 /// <summary>
 /// Registers style sheet reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="resourcePath">The path to the CSS file.</param>
 /// <param name="sectionName">The name of the section that will render this script. If null it will render on the same place of the page</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString StyleSheet(this HtmlHelper helper, string resourcePath, string sectionName)
 {
     return(ResourceHelper.StyleSheet(helper, resourcePath, sectionName, true));
 }
Beispiel #5
0
 /// <summary>
 /// Registers style sheet reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="resourcePath">The path to the CSS file.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString StyleSheet(this HtmlHelper helper, string resourcePath)
 {
     return(ResourceHelper.StyleSheet(helper, resourcePath, null, false));
 }
Beispiel #6
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <remarks>
 /// This helper references the same resource existing in Sitefinity.
 /// </remarks>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptReference">The script reference.</param>
 /// <param name="sectionName">The name of the section that will render this script. If null it will render on the same place of the page</param>
 /// <param name="throwException">Indicates whether to throw an exception if the specified section does not exist.</param>
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString Script(this HtmlHelper helper, ScriptRef scriptReference, string sectionName, bool throwException)
 {
     return(ResourceHelper.Script(helper, scriptReference, sectionName, throwException, true));
 }
Beispiel #7
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <remarks>
 /// This helper references the same resource existing in Sitefinity.
 /// </remarks>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptReference">The script reference.</param>
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString Script(this HtmlHelper helper, ScriptRef scriptReference)
 {
     return(ResourceHelper.Script(helper, scriptReference, null, false, true));
 }
Beispiel #8
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <remarks>
 /// This helper references the same resource existing in Sitefinity.
 /// </remarks>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptReference">The script reference.</param>
 /// <param name="tryUseScriptManager">Indicates whether to use script manager(if exists) when register JavaScript reference.
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 public static MvcHtmlString Script(this HtmlHelper helper, ScriptRef scriptReference, bool tryUseScriptManager)
 {
     return(ResourceHelper.Script(helper, scriptReference, null, false, tryUseScriptManager));
 }
Beispiel #9
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptPath">The path to the JavaScript file.</param>
 /// <param name="sectionName">The name of the section that will render this script. If null it will render on the same place of the page</param>
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 /// <remarks>
 /// This method uses directly the resource from the <see cref="scriptPath" />.
 /// In case you want to use embedded scripts from Sitefinity check <see cref="ResourceHelper.Script(this HtmlHelper helper, ScriptRef scriptReference, bool throwException = false)" />.
 /// </remarks>
 public static MvcHtmlString Script(this HtmlHelper helper, string scriptPath, string sectionName)
 {
     return(ResourceHelper.Script(helper, scriptPath, sectionName, true));
 }
Beispiel #10
0
 /// <summary>
 /// Registers JavaScript reference and ensures that it loads maximum once for a page.
 /// </summary>
 /// <param name="helper">The helper.</param>
 /// <param name="scriptPath">The path to the JavaScript file.</param>
 /// If it is used the script will always be loaded on the top section of the page.</param>
 /// <returns>
 /// MvcHtmlString
 /// </returns>
 /// <remarks>
 /// This method uses directly the resource from the <see cref="scriptPath" />.
 /// In case you want to use embedded scripts from Sitefinity check <see cref="ResourceHelper.Script(this HtmlHelper helper, ScriptRef scriptReference, bool throwException = false)" />.
 /// </remarks>
 public static MvcHtmlString Script(this HtmlHelper helper, string scriptPath)
 {
     return(ResourceHelper.Script(helper, scriptPath, null, false, true));
 }
Beispiel #11
0
        /// <summary>
        /// Registers JavaScript reference and ensures that it loads maximum once for a page.
        /// </summary>
        /// <remarks>
        /// This method uses directly the resource from the <see cref="scriptPath"/>.
        /// In case you want to use embedded scripts from Sitefinity check <see cref="ResourceHelper.Script(this HtmlHelper helper, ScriptRef scriptReference, bool throwException = false)"/>.
        /// </remarks>
        /// <param name="scriptPath">The path to the JavaScript file.</param>
        /// <param name="throwException">OPTIONAL: Indicates whether to throw an exception if the JavaScript is already registered. By default the value is set to <value>false</value>.</param>
        /// <returns>MvcHtmlString</returns>
        public static System.Web.Mvc.MvcHtmlString Script(this HtmlHelper helper, string scriptPath, bool throwException = false)
        {
            var context = helper.ViewContext.HttpContext;

            return(ResourceHelper.RegisterResource(context, scriptPath, scriptPath, throwException));
        }