Пример #1
0
        public static void AddScriptReference(this AjaxHelper ajaxHelper, string scriptName, ScriptMode scriptMode)
        {
            ScriptModel scriptModel = GetScriptModel(ajaxHelper);

            if (String.IsNullOrEmpty(scriptName))
            {
                throw new ArgumentNullException("scriptName");
            }

            ScriptSharpSection configSection = ScriptSharpSection.GetSettings();
            ScriptElement      scriptElement = configSection.Scripts.GetElement(scriptName, scriptModel.ScriptFlavor);
            string             actualFlavor  = String.Empty;

            int flavorIndex = scriptElement.Name.IndexOf('.');

            if (flavorIndex > 0)
            {
                actualFlavor = scriptElement.Name.Substring(flavorIndex + 1);
            }

            ScriptReference scriptReference =
                new ScriptReference(scriptName, scriptElement.Url, scriptMode,
                                    scriptElement.GetDependencyList(), scriptElement.Version + actualFlavor);

            scriptModel.AddScriptReference(scriptReference);
        }
Пример #2
0
        public static void InitializeScripts(this AjaxHelper ajaxHelper, string scriptFlavor, bool enableInlining)
        {
            if (ajaxHelper == null)
            {
                throw new ArgumentNullException("ajaxHelper");
            }

            HttpContextBase httpContext = ajaxHelper.ViewContext.HttpContext;

            if (httpContext.Items[typeof(ScriptModel)] != null)
            {
                throw new InvalidOperationException("You must call InitializeScripts only once.");
            }

            ScriptSharpSection configSection     = ScriptSharpSection.GetSettings();
            ScriptElement      coreScriptElement = configSection.Scripts.GetElement(LoaderScriptName, scriptFlavor);

            ScriptInliner scriptInliner = null;

            if (enableInlining)
            {
                string storageCookieName = configSection.ClientScriptStorageCookie;
                if (String.IsNullOrEmpty(storageCookieName) == false)
                {
                    scriptInliner = new ScriptInliner(httpContext, storageCookieName);
                }
            }

            ScriptModel scriptModel = new ScriptModel(coreScriptElement.Url, scriptFlavor, scriptInliner);

            httpContext.Items[typeof(ScriptModel)] = scriptModel;
        }
Пример #3
0
        public static void RenderScripts(this AjaxHelper ajaxHelper)
        {
            ScriptModel scriptModel = GetScriptModel(ajaxHelper);

            scriptModel.IncludeDependencies(ScriptSharpSection.GetSettings().Scripts);
            scriptModel.Render(ajaxHelper.ViewContext.Writer);
        }
Пример #4
0
        public static bool CanInlineScripts(this AjaxHelper ajaxHelper)
        {
            if (ajaxHelper == null)
            {
                throw new ArgumentNullException("ajaxHelper");
            }

            ScriptSharpSection configSection = ScriptSharpSection.GetSettings();

            if (String.IsNullOrEmpty(configSection.ClientScriptStorageCookie) == false)
            {
                return(ScriptInliner.SupportsLocalStorage(ajaxHelper.ViewContext.HttpContext));
            }

            return(false);
        }
Пример #5
0
 public static string GetInlinedScriptsCookie(this AjaxHelper ajaxHelper)
 {
     return(ScriptSharpSection.GetSettings().ClientScriptStorageCookie);
 }