Beispiel #1
0
        public static void RenderScripts(this AjaxHelper ajaxHelper)
        {
            ScriptModel scriptModel = GetScriptModel(ajaxHelper);

            scriptModel.IncludeDependencies(SharpenSection.GetSettings().Scripts);
            scriptModel.Render(ajaxHelper.ViewContext.Writer);
        }
Beispiel #2
0
        public static void AddScriptReference(this AjaxHelper ajaxHelper, string scriptName, ScriptMode scriptMode)
        {
            ScriptModel scriptModel = GetScriptModel(ajaxHelper);

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

            SharpenSection configSection = SharpenSection.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);
        }
Beispiel #3
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.");
            }

            SharpenSection configSection     = SharpenSection.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;
        }
Beispiel #4
0
        public static bool CanInlineScripts(this AjaxHelper ajaxHelper)
        {
            if (ajaxHelper == null)
            {
                throw new ArgumentNullException("ajaxHelper");
            }

            SharpenSection configSection = SharpenSection.GetSettings();

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

            return(false);
        }
Beispiel #5
0
 public static string GetInlinedScriptsCookie(this AjaxHelper ajaxHelper)
 {
     return(SharpenSection.GetSettings().ClientScriptStorageCookie);
 }