/// <summary> /// 获取所有在location呈现而引入的script /// </summary> /// <param name="renderLocation"><see cref="ResourceRenderLocation"/></param> public IList <ResourceEntry> GetIncludedScripts(ResourceRenderLocation renderLocation) { List <ResourceEntry> resources = new List <ResourceEntry>(); resources.AddRange(FilterResourceEntries(_includedScripts, renderLocation, ResourceRenderPriority.First)); resources.AddRange(FilterResourceEntries(_includedScripts, renderLocation, ResourceRenderPriority.Unspecified)); resources.AddRange(FilterResourceEntries(_includedScripts, renderLocation, ResourceRenderPriority.Last)); return(resources); }
/// <summary> /// 获取注册的需在location呈现css代码块 /// </summary> /// <param name="renderLocation"><see cref="ResourceRenderLocation"/></param> public IList <string> GetRegisteredCssBlocks(ResourceRenderLocation renderLocation) { List <string> cssBlocksOfLocation; if (!_registeredCssBlocks.TryGetValue(renderLocation, out cssBlocksOfLocation)) { return(new List <string>(0)); } return(cssBlocksOfLocation); }
/// <summary> /// 注册在页面呈现的css代码块 /// </summary> private void RegisterCssBlock(ResourceRenderLocation renderLocation, string cssBlock) { List <string> cssBlocksOfLocation; if (!_registeredCssBlocks.TryGetValue(renderLocation, out cssBlocksOfLocation)) { cssBlocksOfLocation = new List <string>(); _registeredCssBlocks[renderLocation] = cssBlocksOfLocation; } cssBlocksOfLocation.Add(cssBlock); }
/// <summary> /// 注册在页面呈现的Script代码块 /// </summary> private void RegisterScriptBlock(ResourceRenderLocation renderLocation, string scriptBlock) { List <string> scriptBlocksOfLocation; if (!_registeredScriptBlocks.TryGetValue(renderLocation, out scriptBlocksOfLocation)) { scriptBlocksOfLocation = new List <string>(); _registeredScriptBlocks[renderLocation] = scriptBlocksOfLocation; } scriptBlocksOfLocation.Add(scriptBlock); }
/// <summary> /// 构造函数 /// </summary> /// <param name="resourceType">资源类型</param> /// <param name="basePath">基路径</param> /// <param name="url"></param> /// <param name="debugUrl"></param> /// <param name="renderPriority"></param> /// <param name="renderLocation"></param> /// <param name="attributes"></param> public ResourceEntry(PageResourceType resourceType, string basePath, string url, string debugUrl, ResourceRenderPriority renderPriority, ResourceRenderLocation renderLocation, IDictionary <string, string> attributes) { this.ResourceType = resourceType; this.BasePath = basePath; this.Url = url; this.DebugUrl = debugUrl; this.RenderPriority = renderPriority; this.RenderLocation = renderLocation; if (attributes != null) { this.Attributes = attributes; } }
/// <summary> /// 设置Script引用 /// </summary> /// <param name="basePath">基路径</param> /// <param name="fileName">文件名称</param> /// <param name="debugFileName">在调试状态使用的文件</param> /// <param name="renderPriority">呈现优先级</param> /// <param name="renderLocation">在页面中的呈现位置</param> /// <param name="htmlAttributes">设置的html属性</param> public void IncludeScript(string basePath, string fileName, string debugFileName = null, ResourceRenderPriority renderPriority = ResourceRenderPriority.Unspecified, ResourceRenderLocation renderLocation = ResourceRenderLocation.Head, IDictionary <string, string> htmlAttributes = null) { if (string.IsNullOrEmpty(fileName)) { throw new ArgumentNullException("fileName"); } ResourceEntry resource = new ResourceEntry(PageResourceType.JS, basePath, fileName, debugFileName, renderPriority, renderLocation, htmlAttributes); _includedScripts.Add(resource); }
/// <summary> /// 基于Combres的ResourceName引入js/css /// </summary> /// <param name="resourceType"><see cref="PageResourceType"/></param> /// <param name="resouceSetName">Combres中设置的ResourceSet</param> /// <param name="debugResouceSetName">debug时使用的ResouceSetName</param> /// <param name="renderPriority">呈现优先级</param> /// <param name="renderLocation">在页面中的呈现位置</param> /// <param name="htmlAttributes">设置的html属性</param> public void IncludeCombresResouceSet(PageResourceType resourceType, string resouceSetName, string debugResouceSetName = null, ResourceRenderPriority renderPriority = ResourceRenderPriority.Unspecified, ResourceRenderLocation renderLocation = ResourceRenderLocation.Head, IDictionary <string, string> htmlAttributes = null) { if (string.IsNullOrEmpty(resouceSetName)) { throw new ArgumentNullException("resouceSetName"); } string url = WebExtensions.CombresUrl(resouceSetName); string debugUrl = null; if (debugResouceSetName != null) { debugUrl = WebExtensions.CombresUrl(debugResouceSetName); } ResourceEntry resource = new ResourceEntry(resourceType, null, url, debugUrl, renderPriority, renderLocation, htmlAttributes); switch (resourceType) { case PageResourceType.JS: _includedScripts.Add(resource); break; case PageResourceType.CSS: _includedCsss.Add(resource); break; } }
/// <summary> /// 在页面引用Script /// </summary> /// <param name="html"></param> /// <param name="basePath">基路径</param> /// <param name="fileName">文件名称</param> /// <param name="debugFileName">用于调试的文件名称</param> /// <param name="renderPriority"><see cref="ResourceRenderPriority"/></param> /// <param name="renderLocation"><see cref="ResourceRenderLocation"/></param> /// <param name="htmlAttributes">html属性</param> public static void IncludeScript(this HtmlHelper html, string basePath, string fileName, string debugFileName = null, ResourceRenderPriority renderPriority = ResourceRenderPriority.Unspecified, ResourceRenderLocation renderLocation = ResourceRenderLocation.Head, IDictionary <string, string> htmlAttributes = null) { IPageResourceManager pageResourceManager = DIContainer.ResolvePerHttpRequest <IPageResourceManager>(); pageResourceManager.IncludeScript(basePath, fileName, debugFileName, renderPriority, renderLocation, htmlAttributes); }