From bed6afb98bbc9510e86dd6a322d60c26746c8364 Mon Sep 17 00:00:00 2001 From: Nathan Heskew Date: Wed, 12 May 2010 15:52:36 -0700 Subject: [PATCH] Making use of the autofocus attribute --HG-- branch : dev --- .../Views/Admin/Index.ascx | 5 +++-- .../Orchard.Setup/Orchard.Setup.csproj | 1 - .../Orchard.Setup/Views/Setup/Index.ascx | 3 +-- .../Modules/Orchard.Themes/Scripts/base.js | 20 +++++++++++++++---- .../Orchard.Users/Views/Account/LogOn.ascx | 7 +++---- .../Themes/Contoso/Views/LogOn.ascx | 5 ++--- .../Themes/Corporate/Views/LogOn.ascx | 5 ++--- 7 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/Orchard.Web/Modules/Orchard.MultiTenancy/Views/Admin/Index.ascx b/src/Orchard.Web/Modules/Orchard.MultiTenancy/Views/Admin/Index.ascx index c71648210..a4aca06e0 100644 --- a/src/Orchard.Web/Modules/Orchard.MultiTenancy/Views/Admin/Index.ascx +++ b/src/Orchard.Web/Modules/Orchard.MultiTenancy/Views/Admin/Index.ascx @@ -22,8 +22,9 @@ } %> <%=Html.ActionLink(T("Edit").ToString(), "edit", new {tenantName = tenant.Name, area = "Orchard.MultiTenancy"}) %><% if (!string.Equals(tenant.Name, "default", StringComparison.OrdinalIgnoreCase)) { //todo: (heskew) base this off the view model so logic on what can be removed and have its state changed stays in the controller - %><%=_Encoded(" | ")%> - <%=Html.ActionLink(T("Remove").ToString(), "delete", new {tenantName = tenant.Name, area = "Orchard.MultiTenancy"}) %><% + %><%-- + delete not implemented! <%=_Encoded(" | ")%> + <%=Html.ActionLink(T("Remove").ToString(), "delete", new {tenantName = tenant.Name, area = "Orchard.MultiTenancy"}) %>--%><% } %> diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj index 075d62dd5..c8561a05b 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj +++ b/src/Orchard.Web/Modules/Orchard.Setup/Orchard.Setup.csproj @@ -97,7 +97,6 @@ - diff --git a/src/Orchard.Web/Modules/Orchard.Setup/Views/Setup/Index.ascx b/src/Orchard.Web/Modules/Orchard.Setup/Views/Setup/Index.ascx index 551d48fd8..8ac805bab 100644 --- a/src/Orchard.Web/Modules/Orchard.Setup/Views/Setup/Index.ascx +++ b/src/Orchard.Web/Modules/Orchard.Setup/Views/Setup/Index.ascx @@ -1,5 +1,4 @@ <%@ Control Language="C#" Inherits="Orchard.Mvc.ViewUserControl" %> -<%@ Import Namespace="Orchard.Mvc.Html"%> <%@ Import Namespace="Orchard.Setup.ViewModels"%>

<%=Html.TitleForPage(_Encoded("Get Started").ToHtmlString())%>

<% @@ -9,7 +8,7 @@ using (Html.BeginFormAntiForgeryPost()) { %>
- <%=Html.EditorFor(svm => svm.SiteName) %> + <%=Html.TextBoxFor(svm => svm.SiteName, new { autofocus = "autofocus" })%>
diff --git a/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js index 5ee517959..916f30533 100644 --- a/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js +++ b/src/Orchard.Web/Modules/Orchard.Themes/Scripts/base.js @@ -3,9 +3,17 @@ jQuery.fn.extend({ helpfullyFocus: function() { var _this = $(this); var firstError = _this.find(".input-validation-error").first(); - return firstError.size() === 1 - ? firstError.focus() - : _this.find("input:text").first().focus(); + // try to focus the first error on the page + if (firstError.size() === 1) { + return firstError.focus(); + } + // or, give it up to the browser to autofocus + if ('autofocus' in document.createElement('input')) { + return; + } + // otherwise, make the autofocus attribute work + var autofocus = _this.find(":input[autofocus=autofocus]").first(); + return autofocus.focus(); }, toggleWhatYouControl: function() { var _this = $(this); @@ -52,4 +60,8 @@ jQuery.fn.extend({ _this.css({ "position": "absolute", "left": "-9999em" }); $("body").append(_this); }); -})(); \ No newline at end of file +})(); +// a little better autofocus +$(function() { + $("body").helpfullyFocus(); +}); \ No newline at end of file diff --git a/src/Orchard.Web/Modules/Orchard.Users/Views/Account/LogOn.ascx b/src/Orchard.Web/Modules/Orchard.Users/Views/Account/LogOn.ascx index de5f098cd..71020cb5d 100644 --- a/src/Orchard.Web/Modules/Orchard.Users/Views/Account/LogOn.ascx +++ b/src/Orchard.Web/Modules/Orchard.Users/Views/Account/LogOn.ascx @@ -8,8 +8,8 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques
<%=_Encoded("Account Information")%>
- - <%= Html.TextBox("userNameOrEmail")%> + + <%= Html.TextBox("userNameOrEmail", "", new { autofocus = "autofocus" })%> <%= Html.ValidationMessage("userNameOrEmail")%>
@@ -22,5 +22,4 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques
" />
<% -} %><% -using (this.Capture("end-of-page-scripts")) { %><% } %> \ No newline at end of file +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Themes/Contoso/Views/LogOn.ascx b/src/Orchard.Web/Themes/Contoso/Views/LogOn.ascx index 7b9d29760..3f52bab68 100644 --- a/src/Orchard.Web/Themes/Contoso/Views/LogOn.ascx +++ b/src/Orchard.Web/Themes/Contoso/Views/LogOn.ascx @@ -10,7 +10,7 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques <%=_Encoded("Account Information")%>
- <%= Html.TextBox("username")%> + <%= Html.TextBox("username", "", new { autofocus = "autofocus" })%> <%= Html.ValidationMessage("username")%>
@@ -23,5 +23,4 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques
" />
<% -} %><% -using (this.Capture("end-of-page-scripts")) { %><% } %> \ No newline at end of file +} %> \ No newline at end of file diff --git a/src/Orchard.Web/Themes/Corporate/Views/LogOn.ascx b/src/Orchard.Web/Themes/Corporate/Views/LogOn.ascx index 7b9d29760..3f52bab68 100644 --- a/src/Orchard.Web/Themes/Corporate/Views/LogOn.ascx +++ b/src/Orchard.Web/Themes/Corporate/Views/LogOn.ascx @@ -10,7 +10,7 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques <%=_Encoded("Account Information")%>
- <%= Html.TextBox("username")%> + <%= Html.TextBox("username", "", new { autofocus = "autofocus" })%> <%= Html.ValidationMessage("username")%>
@@ -23,5 +23,4 @@ using (Html.BeginFormAntiForgeryPost(Url.Action("LogOn", new {ReturnUrl = Reques
" /> <% -} %><% -using (this.Capture("end-of-page-scripts")) { %><% } %> \ No newline at end of file +} %> \ No newline at end of file