summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs56
-rw-r--r--src/DotNetOpenAuth/InfoCard/SupportingScript.js19
2 files changed, 55 insertions, 20 deletions
diff --git a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
index 3ca8e88..a23db1d 100644
--- a/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
+++ b/src/DotNetOpenAuth/InfoCard/InfoCardSelector.cs
@@ -355,6 +355,13 @@ namespace DotNetOpenAuth.InfoCard {
}
/// <summary>
+ /// Gets the id of the OBJECT tag that creates the InfoCard Selector.
+ /// </summary>
+ private string SelectorObjectId {
+ get { return this.ClientID + "_cs"; }
+ }
+
+ /// <summary>
/// Gets the XML token, which will be encrypted if it was received over SSL.
/// </summary>
private string TokenXml {
@@ -515,34 +522,43 @@ namespace DotNetOpenAuth.InfoCard {
image.ToolTip = InfoCardStrings.SelectorClickPrompt;
image.Style[HtmlTextWriterStyle.Cursor] = "hand";
+ image.Attributes["onclick"] = this.GetInfoCardSelectorActivationScript(false);
+ supportedPanel.Controls.Add(image);
+
+ // trigger the selector at page load?
+ if (this.AutoPopup && !this.Page.IsPostBack) {
+ this.Page.ClientScript.RegisterStartupScript(
+ typeof(InfoCardSelector),
+ "selector_load_trigger",
+ this.GetInfoCardSelectorActivationScript(true),
+ true);
+ }
+
+ return supportedPanel;
+ }
+
+ /// <summary>
+ /// Gets the InfoCard selector activation script.
+ /// </summary>
+ /// <param name="alwaysPostback">Whether a postback should always immediately follow the selector, even if <see cref="AutoPostBack"/> is <c>false</c>.</param>
+ /// <returns>The javascript to inject into the surrounding context.</returns>
+ private string GetInfoCardSelectorActivationScript(bool alwaysPostback) {
// generate call do __doPostback
PostBackOptions options = new PostBackOptions(this);
- string postback = this.Page.ClientScript.GetPostBackEventReference(options);
+ string postback = string.Empty;
+ if (alwaysPostback || this.AutoPostBack) {
+ postback = this.Page.ClientScript.GetPostBackEventReference(options) + ";";
+ }
// generate the onclick script for the image
string invokeScript = string.Format(
CultureInfo.InvariantCulture,
- @"try {{ document.getElementById('{0}').value = document.getElementById('{1}_cs').value; {2} }} catch (e) {{ /* canceled */ }}",
+ @"if (ActivateSelector('{0}', '{1}')) {{ {2} }}",
+ this.SelectorObjectId,
this.HiddenFieldName,
- this.ClientID,
- this.AutoPostBack ? postback : "");
+ postback);
- image.Attributes["onclick"] = invokeScript;
- supportedPanel.Controls.Add(image);
-
- // trigger the selector at page load?
- if (this.AutoPopup && !this.Page.IsPostBack) {
- string loadScript = string.Format(
- CultureInfo.InvariantCulture,
- @"try {{ document.getElementById('{0}').value = document.getElementById('{1}_cs').value; {2} }} catch (e) {{ /* canceled */ }}",
- this.HiddenFieldName,
- this.ClientID,
- postback);
-
- this.Page.ClientScript.RegisterStartupScript(typeof(InfoCardSelector), "selector_load_trigger", loadScript, true);
- }
-
- return supportedPanel;
+ return invokeScript;
}
/// <summary>
diff --git a/src/DotNetOpenAuth/InfoCard/SupportingScript.js b/src/DotNetOpenAuth/InfoCard/SupportingScript.js
index 9fb2822..60103f5 100644
--- a/src/DotNetOpenAuth/InfoCard/SupportingScript.js
+++ b/src/DotNetOpenAuth/InfoCard/SupportingScript.js
@@ -44,6 +44,25 @@ function AreCardsSupported() {
return false;
}
+function ActivateSelector(selectorId, hiddenFieldName) {
+ var selector = document.getElementById(selectorId);
+ var hiddenField = document.getElementsByName(hiddenFieldName)[0];
+ try {
+ hiddenField.value = selector.value;
+ } catch (e) {
+ // Selector was canceled
+ return false;
+ }
+ if (hiddenField.value == 'undefined') {
+ // We're dealing with a bad FireFox selector plugin.
+ // Just add the control to the form by setting its name property and submit to activate.
+ selector.name = hiddenFieldName;
+ hiddenField.parentNode.removeChild(hiddenField);
+ return true;
+ }
+ return true;
+};
+
function HideStatic(divName) {
var div = document.getElementById(divName);
if (div) {