PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Web/Controls/GreyBoxHyperlink.cs

#
C# | 188 lines | 95 code | 43 blank | 50 comment | 16 complexity | ffdefe0e6f66b59466c487aa8afc9728 MD5 | raw file
Possible License(s): LGPL-2.1, Apache-2.0, BSD-3-Clause, CPL-1.0, CC-BY-SA-3.0, GPL-2.0
  1. // Author: Joe Audette
  2. // Created: 2009-04-08
  3. // Last Modified: 2010-04-27
  4. //
  5. // The use and distribution terms for this software are covered by the
  6. // Common Public License 1.0 (http://opensource.org/licenses/cpl.php)
  7. // which can be found in the file CPL.TXT at the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by
  9. // the terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. using System;
  13. using System.Web;
  14. using System.Web.UI;
  15. using System.Web.UI.WebControls;
  16. using Resources;
  17. namespace mojoPortal.Web.UI
  18. {
  19. public class GreyBoxHyperlink : HyperLink
  20. {
  21. private bool assumeScriptsAreLoaded = false;
  22. private string scriptBaseUrl = "~/ClientScript/greybox/";
  23. private string rel = string.Empty;
  24. private string dialogCloseText = string.Empty;
  25. private string clientClick = string.Empty;
  26. public string ScriptBaseUrl
  27. {
  28. get { return scriptBaseUrl; }
  29. set { scriptBaseUrl = value; }
  30. }
  31. /// <summary>
  32. /// examples:
  33. /// return GB_show('Google', this.href)
  34. /// return GB_showCenter('Google', this.href)
  35. /// return GB_showFullScreen('Google', this.href)
  36. /// return GB_showPage('Google', this.href)
  37. /// </summary>
  38. public string ClientClick
  39. {
  40. get { return clientClick; }
  41. set { clientClick = value; }
  42. }
  43. /// <summary>
  44. /// examples:
  45. /// gb_page[WIDTH, HEIGHT]
  46. /// gb_page_fs[]
  47. /// </summary>
  48. public string Rel
  49. {
  50. get { return rel; }
  51. set { rel = value; }
  52. }
  53. public string DialogCloseText
  54. {
  55. get { return dialogCloseText; }
  56. set { dialogCloseText = value; }
  57. }
  58. /// <summary>
  59. /// If using this on the same page as neatupload with NeatUpload greyboxProgressBar, set this to true because NeatUpload already loads the scripts.
  60. /// </summary>
  61. public bool AssumeScriptsAreLoaded
  62. {
  63. get { return assumeScriptsAreLoaded; }
  64. set { assumeScriptsAreLoaded = value; }
  65. }
  66. protected override void OnLoad(EventArgs e)
  67. {
  68. base.OnLoad(e);
  69. if (HttpContext.Current == null) { return; }
  70. dialogCloseText = Resource.DialogCloseLink;
  71. SetupScript();
  72. SetupCss();
  73. }
  74. protected override void OnPreRender(EventArgs e)
  75. {
  76. base.OnPreRender(e);
  77. if (HttpContext.Current == null) { return; }
  78. if (clientClick.Length > 0)
  79. {
  80. this.Attributes.Add("onclick", clientClick);
  81. }
  82. else if (rel.Length > 0)
  83. {
  84. this.Attributes.Add("rel", rel);
  85. }
  86. }
  87. protected override void Render(HtmlTextWriter writer)
  88. {
  89. if (HttpContext.Current == null)
  90. {
  91. writer.Write("[" + this.ID + "]");
  92. return;
  93. }
  94. base.Render(writer);
  95. }
  96. private void SetupScript()
  97. {
  98. if (assumeScriptsAreLoaded) { return; }
  99. Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
  100. "gbVar", "\n<script type=\"text/javascript\">"
  101. + "var GB_ROOT_DIR = '" + Page.ResolveUrl(scriptBaseUrl) + "'; var GBCloseText = '" + dialogCloseText + "';" + " </script>");
  102. if (Page is mojoBasePage)
  103. {
  104. mojoBasePage mojoPage = Page as mojoBasePage;
  105. mojoPage.ScriptConfig.IncludeGreyBox = true;
  106. }
  107. else
  108. {
  109. //Page.ClientScript.RegisterClientScriptBlock(typeof(Page),
  110. // "GreyBoxJs", "\n<script src=\""
  111. // + Page.ResolveUrl(scriptBaseUrl + "gbcombined.js") + "\" type=\"text/javascript\" ></script>");
  112. //The commented version above is the preferred syntax, the uncommented one below is the deprecated version.
  113. //There is a reason we are using the deprecated version, greybox is registered also by NeatUpload using the deprecated
  114. //syntax, the reason they use the older syntax is because they also support .NET v1.1
  115. //We use the old syntax here for compatibility with NeatUpload so that it does not get registered more than once
  116. // on pages that use NeatUpload. Otherwise we would have to always modify our copy of NeatUpload.
  117. Page.RegisterClientScriptBlock("GreyBoxJs", "\n<script src=\""
  118. + Page.ResolveUrl(scriptBaseUrl + "gbcombined.js") + "\" type=\"text/javascript\" ></script>");
  119. }
  120. }
  121. private void SetupCss()
  122. {
  123. if (assumeScriptsAreLoaded) { return; }
  124. //<link href="/ClientScript/greybox/gb_styles.css" rel="stylesheet" type="text/css" media="all" />
  125. if (Page.Master == null) { return; }
  126. StyleSheetCombiner style = Page.Master.FindControl("StyleSheetCombiner") as StyleSheetCombiner;
  127. if (style != null) { style.IncludeGreyBoxCss = true; }
  128. //Control head = Page.Master.FindControl("Head1");
  129. //if (head == null) { return; }
  130. //try
  131. //{
  132. // if (head.FindControl("gb_styles") == null)
  133. // {
  134. // Literal cssLink = new Literal();
  135. // cssLink.ID = "gb_styles";
  136. // cssLink.Text = "\n<link rel='stylesheet' type='text/css' href='"
  137. // + Page.ResolveUrl(scriptBaseUrl + "gb_styles.css")
  138. // + "' media='all' />";
  139. // head.Controls.Add(cssLink);
  140. // }
  141. //}
  142. //catch (HttpException) { }
  143. }
  144. }
  145. }