mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 03:58:13 +08:00
Adding position specification to file resource registration
- so base scripts and styles can be made to appear in the source before the other scripts and styles --HG-- branch : dev
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"%><%
|
<%
|
||||||
// a CSS file for styling things (e.g. content item edit buttons) for users with elevated privileges (in this case, anyone who is authenticated)
|
// a CSS file for styling things (e.g. content item edit buttons) for users with elevated privileges (in this case, anyone who is authenticated)
|
||||||
if (Request.IsAuthenticated) { Html.RegisterStyle("special.css"); }
|
if (Request.IsAuthenticated) { Html.RegisterStyle("special.css"); }
|
||||||
|
|
||||||
Html.RegisterScript("jquery-1.4.2.js"); // <- change to .min.js for use on a real site :)
|
Html.RegisterScript("jquery-1.4.2.js", "1"); // <- change to .min.js for use on a real site :)
|
||||||
Html.RegisterFootScript("base.js");
|
Html.RegisterFootScript("base.js", "1");
|
||||||
%>
|
%>
|
||||||
@@ -99,6 +99,7 @@
|
|||||||
<Content Include="Default.aspx" />
|
<Content Include="Default.aspx" />
|
||||||
<Content Include="Global.asax" />
|
<Content Include="Global.asax" />
|
||||||
<Content Include="Refresh.html" />
|
<Content Include="Refresh.html" />
|
||||||
|
<Content Include="Themes\TheAdmin\Scripts\admin.js" />
|
||||||
<Content Include="Themes\TheAdmin\Styles\ie.css" />
|
<Content Include="Themes\TheAdmin\Styles\ie.css" />
|
||||||
<Content Include="Web.config">
|
<Content Include="Web.config">
|
||||||
<SubType>Designer</SubType>
|
<SubType>Designer</SubType>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BaseViewModel>" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BaseViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
Html.RegisterStyle("blog.css");
|
Html.RegisterStyle("blog.css", "1");
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%-- todo:(nheskew) this will need to be a generated menu --%>
|
<%-- todo:(nheskew) this will need to be a generated menu --%>
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BaseViewModel>" %>
|
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<BaseViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels" %>
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
Html.RegisterStyle("blog.css");
|
Html.RegisterStyle("blog.css", "1");
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<%-- todo:(nheskew) this will need to be a generated menu --%>
|
<%-- todo:(nheskew) this will need to be a generated menu --%>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
|
|
||||||
Model.Zones.AddRenderPartial("header", "Header", Model);
|
Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||||
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
|
|
||||||
Model.Zones.AddRenderPartial("header", "Header", Model);
|
Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||||
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
|
|
||||||
Model.Zones.AddRenderPartial("header", "Header", Model);
|
Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||||
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
|
|
||||||
Model.Zones.AddRenderPartial("header", "Header", Model);
|
Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||||
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("yui.css");
|
Html.RegisterStyle("yui.css", "1");
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
Html.RegisterStyle("blog.css");
|
Html.RegisterStyle("blog.css", "1");
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|||||||
@@ -2,9 +2,9 @@
|
|||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
||||||
|
|
||||||
<%
|
<%
|
||||||
Html.RegisterStyle("yui.css");
|
Html.RegisterStyle("yui.css", "1");
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("site.css", "1");
|
||||||
Html.RegisterStyle("blog.css");
|
Html.RegisterStyle("blog.css", "1");
|
||||||
%>
|
%>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BaseViewModel>" %>
|
<%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl<BaseViewModel>" %>
|
||||||
<%@ Import Namespace="Orchard.Mvc.ViewModels"%>
|
<%@ Import Namespace="Orchard.Mvc.ViewModels"%><%
|
||||||
<%@ Import Namespace="Orchard.Mvc.Html"%><%
|
Html.RegisterStyle("site.css", "1");
|
||||||
Html.RegisterStyle("site.css");
|
Html.RegisterStyle("ie.css", "1").WithCondition("if (lte IE 8)").ForMedia("screen, projection");
|
||||||
Html.RegisterStyle("ie.css").WithCondition("if (lte IE 8)").ForMedia("screen, projection");
|
Html.RegisterStyle("ie6.css", "1").WithCondition("if lte IE 6").ForMedia("screen, projection");
|
||||||
Html.RegisterStyle("ie6.css").WithCondition("if lte IE 6").ForMedia("screen, projection");
|
Html.RegisterFootScript("admin.js", "1");
|
||||||
Model.Zones.AddRenderPartial("header", "Header", Model);
|
Model.Zones.AddRenderPartial("header", "Header", Model);
|
||||||
Model.Zones.AddRenderPartial("header:after", "User", Model); // todo: (heskew) should be a user display or widget
|
Model.Zones.AddRenderPartial("header:after", "User", Model); // todo: (heskew) should be a user display or widget
|
||||||
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
Model.Zones.AddRenderPartial("menu", "Menu", Model);
|
||||||
%>
|
%>
|
||||||
<script src="<%: Url.Content("~/Themes/TheAdmin/Scripts/admin.js") %>" type="text/javascript"></script>
|
|
||||||
<div id="header" role="banner"><% Html.Zone("header"); %></div>
|
<div id="header" role="banner"><% Html.Zone("header"); %></div>
|
||||||
<div id="content">
|
<div id="content">
|
||||||
<div id="navshortcut"><a href="#menu"><%: T("Skip to navigation") %></a></div>
|
<div id="navshortcut"><a href="#menu"><%: T("Skip to navigation") %></a></div>
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ namespace Orchard.Mvc.Html {
|
|||||||
private static readonly Dictionary<string, string> _filePathAttributes = new Dictionary<string, string> {{"script", "src"}, {"link", "href"}};
|
private static readonly Dictionary<string, string> _filePathAttributes = new Dictionary<string, string> {{"script", "src"}, {"link", "href"}};
|
||||||
private static readonly Dictionary<string, TagRenderMode> _fileTagRenderModes = new Dictionary<string, TagRenderMode> {{"script", TagRenderMode.Normal}, {"link", TagRenderMode.SelfClosing}};
|
private static readonly Dictionary<string, TagRenderMode> _fileTagRenderModes = new Dictionary<string, TagRenderMode> {{"script", TagRenderMode.Normal}, {"link", TagRenderMode.SelfClosing}};
|
||||||
|
|
||||||
public FileRegistrationContext(ControllerContext viewContext, IViewDataContainer viewDataContainer, string tagName, string fileName)
|
public FileRegistrationContext(ControllerContext viewContext, IViewDataContainer viewDataContainer, string tagName, string fileName, string position)
|
||||||
: this(viewContext, viewDataContainer, tagName, fileName, _filePathAttributes[tagName], _fileTagRenderModes[tagName]) {
|
: this(viewContext, viewDataContainer, tagName, fileName, position, _filePathAttributes[tagName], _fileTagRenderModes[tagName]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileRegistrationContext(ControllerContext viewContext, IViewDataContainer viewDataContainer, string tagName, string fileName, string filePathAttributeName, TagRenderMode fileTagRenderMode)
|
public FileRegistrationContext(ControllerContext viewContext, IViewDataContainer viewDataContainer, string tagName, string fileName, string position, string filePathAttributeName, TagRenderMode fileTagRenderMode)
|
||||||
: base(viewContext.HttpContext, viewContext.RouteData) {
|
: base(viewContext.HttpContext, viewContext.RouteData) {
|
||||||
_fileTagRenderMode = fileTagRenderMode;
|
_fileTagRenderMode = fileTagRenderMode;
|
||||||
Container = viewDataContainer as TemplateControl;
|
Container = viewDataContainer as TemplateControl;
|
||||||
@@ -31,6 +31,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
}
|
}
|
||||||
|
|
||||||
FileName = fileName;
|
FileName = fileName;
|
||||||
|
Position = position;
|
||||||
FilePathAttributeName = filePathAttributeName;
|
FilePathAttributeName = filePathAttributeName;
|
||||||
_tagBuilder = new TagBuilder(tagName);
|
_tagBuilder = new TagBuilder(tagName);
|
||||||
}
|
}
|
||||||
@@ -40,6 +41,7 @@ namespace Orchard.Mvc.Html {
|
|||||||
public string FileName { get; set; }
|
public string FileName { get; set; }
|
||||||
public string FilePathAttributeName { get; private set; }
|
public string FilePathAttributeName { get; private set; }
|
||||||
public string Condition { get; set; }
|
public string Condition { get; set; }
|
||||||
|
public string Position { get; set; }
|
||||||
|
|
||||||
public void AddAttribute(string name, string value) {
|
public void AddAttribute(string name, string value) {
|
||||||
_tagBuilder.MergeAttribute(name, value);
|
_tagBuilder.MergeAttribute(name, value);
|
||||||
|
|||||||
@@ -102,14 +102,25 @@ namespace Orchard.Mvc.Html {
|
|||||||
return html.Resolve<IResourceManager>().RegisterStyle(fileName, html);
|
return html.Resolve<IResourceManager>().RegisterStyle(fileName, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FileRegistrationContext RegisterStyle(this HtmlHelper html, string fileName, string position) {
|
||||||
|
return html.Resolve<IResourceManager>().RegisterStyle(fileName, html, position);
|
||||||
|
}
|
||||||
|
|
||||||
public static FileRegistrationContext RegisterScript(this HtmlHelper html, string fileName) {
|
public static FileRegistrationContext RegisterScript(this HtmlHelper html, string fileName) {
|
||||||
return html.Resolve<IResourceManager>().RegisterHeadScript(fileName, html);
|
return html.Resolve<IResourceManager>().RegisterHeadScript(fileName, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FileRegistrationContext RegisterScript(this HtmlHelper html, string fileName, string position) {
|
||||||
|
return html.Resolve<IResourceManager>().RegisterHeadScript(fileName, html, position);
|
||||||
|
}
|
||||||
|
|
||||||
public static FileRegistrationContext RegisterFootScript(this HtmlHelper html, string fileName) {
|
public static FileRegistrationContext RegisterFootScript(this HtmlHelper html, string fileName) {
|
||||||
return html.Resolve<IResourceManager>().RegisterFootScript(fileName, html);
|
return html.Resolve<IResourceManager>().RegisterFootScript(fileName, html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static FileRegistrationContext RegisterFootScript(this HtmlHelper html, string fileName, string position) {
|
||||||
|
return html.Resolve<IResourceManager>().RegisterFootScript(fileName, html, position);
|
||||||
|
}
|
||||||
|
|
||||||
public static IDisposable Capture(this ViewUserControl control, string name) {
|
public static IDisposable Capture(this ViewUserControl control, string name) {
|
||||||
var writer = LayoutViewContext.From(control.ViewContext).GetNamedContent(name);
|
var writer = LayoutViewContext.From(control.ViewContext).GetNamedContent(name);
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ namespace Orchard.UI.Resources {
|
|||||||
public interface IResourceManager : IDependency {
|
public interface IResourceManager : IDependency {
|
||||||
void RegisterMeta(string name, string content);
|
void RegisterMeta(string name, string content);
|
||||||
FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html);
|
FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html);
|
||||||
|
FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html, string position);
|
||||||
void RegisterLink(LinkEntry entry, HtmlHelper html);
|
void RegisterLink(LinkEntry entry, HtmlHelper html);
|
||||||
FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html);
|
FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html);
|
||||||
|
FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html, string position);
|
||||||
FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html);
|
FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html);
|
||||||
|
FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html, string position);
|
||||||
MvcHtmlString GetMetas();
|
MvcHtmlString GetMetas();
|
||||||
MvcHtmlString GetStyles();
|
MvcHtmlString GetStyles();
|
||||||
MvcHtmlString GetLinks(HtmlHelper html);
|
MvcHtmlString GetLinks(HtmlHelper html);
|
||||||
|
|||||||
@@ -35,15 +35,27 @@ namespace Orchard.UI.Resources {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html) {
|
public FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html) {
|
||||||
|
return RegisterStyle(fileName, html, "5");
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html) {
|
||||||
|
return RegisterHeadScript(fileName, html, "5");
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html) {
|
||||||
|
return RegisterFootScript(fileName, html, "5");
|
||||||
|
}
|
||||||
|
|
||||||
|
public FileRegistrationContext RegisterStyle(string fileName, HtmlHelper html, string position) {
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
throw new ArgumentException(T("Style fileName was not given.").ToString());
|
throw new ArgumentException(T("Style fileName was not given.").ToString());
|
||||||
|
|
||||||
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "link", fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "link", fileName, position);
|
||||||
context.SetAttribute("type", "text/css");
|
context.SetAttribute("type", "text/css");
|
||||||
context.SetAttribute("rel", "stylesheet");
|
context.SetAttribute("rel", "stylesheet");
|
||||||
|
|
||||||
if (!_styles.Contains(context))
|
if (!_styles.Contains(context))
|
||||||
_styles.Insert(0, context);
|
_styles.Add(context);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@@ -52,28 +64,28 @@ namespace Orchard.UI.Resources {
|
|||||||
_links.Add(entry);
|
_links.Add(entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html) {
|
public FileRegistrationContext RegisterHeadScript(string fileName, HtmlHelper html, string position) {
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
throw new ArgumentException(T("Head script fileName was not given.").ToString());
|
throw new ArgumentException(T("Head script fileName was not given.").ToString());
|
||||||
|
|
||||||
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "script", fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "script", fileName, position);
|
||||||
context.SetAttribute("type", "text/javascript");
|
context.SetAttribute("type", "text/javascript");
|
||||||
|
|
||||||
if (!_headScripts.Contains(context))
|
if (!_headScripts.Contains(context))
|
||||||
_headScripts.Insert(0, context);
|
_headScripts.Add(context);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html) { // type=\"text/javascript\" src=\"{0}\"
|
public FileRegistrationContext RegisterFootScript(string fileName, HtmlHelper html, string position) {
|
||||||
if (string.IsNullOrEmpty(fileName))
|
if (string.IsNullOrEmpty(fileName))
|
||||||
throw new ArgumentException(T("Foot script fileName was not given.").ToString());
|
throw new ArgumentException(T("Foot script fileName was not given.").ToString());
|
||||||
|
|
||||||
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "script", fileName);
|
var context = new FileRegistrationContext(html.ViewContext, html.ViewDataContainer, "script", fileName, position);
|
||||||
context.SetAttribute("type", "text/javascript");
|
context.SetAttribute("type", "text/javascript");
|
||||||
|
|
||||||
if (!_footScripts.Contains(context))
|
if (!_footScripts.Contains(context))
|
||||||
_footScripts.Insert(0, context);
|
_footScripts.Add(context);
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
@@ -139,7 +151,9 @@ namespace Orchard.UI.Resources {
|
|||||||
private static MvcHtmlString GetFiles(IEnumerable<FileRegistrationContext> fileRegistrationContexts, string containerRelativePath) {
|
private static MvcHtmlString GetFiles(IEnumerable<FileRegistrationContext> fileRegistrationContexts, string containerRelativePath) {
|
||||||
return
|
return
|
||||||
MvcHtmlString.Create(string.Join("",
|
MvcHtmlString.Create(string.Join("",
|
||||||
fileRegistrationContexts.Select(
|
fileRegistrationContexts
|
||||||
|
.OrderBy(c => c.Position)
|
||||||
|
.Select(
|
||||||
c =>
|
c =>
|
||||||
string.Format(
|
string.Format(
|
||||||
!string.IsNullOrEmpty(c.Condition)
|
!string.IsNullOrEmpty(c.Condition)
|
||||||
|
|||||||
Reference in New Issue
Block a user