Repository navigation
Expand file tree
/
Copy pathSearchBox.cs
More file actions
83 lines (73 loc) · 3.14 KB
/
Copy pathSearchBox.cs
File metadata and controls
83 lines (73 loc) · 3.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// --------------------------------------------------------------------------------------------------------------------
// <summary>
// Includes a reference to a JavaScript.
// <remarks>
// This control is needed in order to let the src
// attribute of the script tage be relative to the root.
// </remarks>
// </summary>
// --------------------------------------------------------------------------------------------------------------------
using System.Text;
using System.Web;
using System.Web.UI;
using BlogEngine.Core;
namespace BlogEngineWA.CustomCode.Controls
{
/// <summary>
/// Includes a reference to a JavaScript.
/// <remarks>
/// This control is needed in order to let the src
/// attribute of the script tage be relative to the root.
/// </remarks>
/// </summary>
public class SearchBox : Control
{
#region Public Methods
/// <summary>
/// Renders the control as a script tag.
/// </summary>
/// <param name="writer">
/// The writer.
/// </param>
public override void RenderControl(HtmlTextWriter writer)
{
writer.Write(this.BuildHtml());
}
#endregion
#region Methods
/// <summary>
/// The build html.
/// </summary>
private string BuildHtml()
{
var text = this.Context.Request.QueryString["q"] != null
? HttpUtility.HtmlEncode(this.Context.Request.QueryString["q"])
: BlogSettings.Instance.SearchDefaultText;
var sb = new StringBuilder();
sb.AppendLine("<div id=\"searchbox\">");
sb.Append("<label for=\"searchfield\" style=\"display:none\">Search</label>");
sb.AppendFormat(
"<input type=\"text\" value=\"{0}\" id=\"searchfield\" onkeypress=\"if(event.keyCode==13) return BlogEngine.search('{1}')\" onfocus=\"BlogEngine.searchClear('{2}')\" onblur=\"BlogEngine.searchClear('{2}')\" />",
text,
Utils.RelativeWebRoot,
text.Replace("'", "\\'"));
sb.AppendFormat(
"<input type=\"button\" value=\"{0}\" id=\"searchbutton\" onclick=\"BlogEngine.search('{1}');\" onkeypress=\"BlogEngine.search('{1}');\" />",
BlogSettings.Instance.SearchButtonText,
Utils.RelativeWebRoot);
if (BlogSettings.Instance.EnableCommentSearch)
{
var check = this.Context.Request.QueryString["comment"] != null ? "checked=\"checked\"" : string.Empty;
sb.AppendFormat("<br /><input type=\"checkbox\" id=\"searchcomments\" {0} />", check);
if (!string.IsNullOrEmpty(BlogSettings.Instance.SearchCommentLabelText))
{
sb.AppendFormat(
"<label for=\"searchcomments\">{0}</label>", BlogSettings.Instance.SearchCommentLabelText);
}
}
sb.AppendLine("</div>");
return sb.ToString();
}
#endregion
}
}