Code zealot in a connected world
AJAX, Tooltip, World of Warcraft (WoW)
/Spend a whole day trying to work around a simple issue.
I give myself one html page. No server side code.
Write a javascript/css based approach to pull data from either Thottbot or Allakhazam and return the data, then render it as a popup.
The AJAX isn't hard, nor is the pop-up page, the problem lies in the "no server side code".
Both IE and FireFox don't like to make XMLHttpRequest cross-domain. That is, it doesn't like being hosted on a http://localhost/test.html or even file host file:///test.html, making a request to thottbot.com.
On IE, you get a security question pop'up everytime you try to make such a call. If the user clicks "OK", he'd be let through.
On FireFox, it's automatically denied unless you try to obtain UniversalBrowserRead privilege. Extremely difficult and potentially a security loophole.
The solution seems bleak.
Use AJAX to query the origin server - without making a cross-domain call. But use the server to make the 'translation' - possibly caching as well.
I give myself one html page. No server side code.
Write a javascript/css based approach to pull data from either Thottbot or Allakhazam and return the data, then render it as a popup.
The AJAX isn't hard, nor is the pop-up page, the problem lies in the "no server side code".
Both IE and FireFox don't like to make XMLHttpRequest cross-domain. That is, it doesn't like being hosted on a http://localhost/test.html or even file host file:///test.html, making a request to thottbot.com.
On IE, you get a security question pop'up everytime you try to make such a call. If the user clicks "OK", he'd be let through.
On FireFox, it's automatically denied unless you try to obtain UniversalBrowserRead privilege. Extremely difficult and potentially a security loophole.
The solution seems bleak.
Use AJAX to query the origin server - without making a cross-domain call. But use the server to make the 'translation' - possibly caching as well.
Be serious with the Lord
/I got quite a bit out of brother Ron's memorial service. Although there was a strong sense of loss, I am extremely glad he has finished his course and ran his race. Now he can finally rest in the Lord and pray for the Lord's coming and our overcoming.
- be a proper person
- have a living that can match our desire to be useful
- turn to my spirit quickly
- don't missing the gatherings
Generics, Casting and Anonymous Delegates and the Where clause
/I have a situation where the code looks like:
( ( TextBox ) ( _someParentControl.FindControl( "_childControlId" ) ) ).Text = "SomeText";
( ( TextBox ) ( _someParentControl.FindControl( "_childControlId" ) ) ).Enabled = someBool;
repeat about 10 times with different child control type, parent controls, child Ids, and properties.
obviously, there's a similarity and refactoring was in order.
private static void ExecuteOnControl<T>( WebControl parent, string id, Action<T> action) where T : WebControl
{
T control = parent.FindControl( id ) as T;
if (control != null && action != null)
{
action( control );
}
}
The where clause is important because you can't cast "As" within the function without having some limits on the generc T.
Which allowed me to shrink the example down to:
ExecuteOnControl<TextBox>(_parentControl, "_childControlId", delegate(TextBox tb) { tb.Text = "someText"; });
This can be further simplified since the delegate can be declared once and used later.
Action<TextBox> tbDel = delegate(TextBox tb) { tb.Text = "someText"; };
ExecuteOnControl<TextBox>(_parentControl, "_childControlId1", tbDel);
ExecuteOnControl<TextBox>(_parentControl, "_childControlId2", tbDel);
One can argue here that the new code isn't really that much more readable though, but it was good hacking
( ( TextBox ) ( _someParentControl.FindControl( "_childControlId" ) ) ).Text = "SomeText";
( ( TextBox ) ( _someParentControl.FindControl( "_childControlId" ) ) ).Enabled = someBool;
repeat about 10 times with different child control type, parent controls, child Ids, and properties.
obviously, there's a similarity and refactoring was in order.
private static void ExecuteOnControl<T>( WebControl parent, string id, Action<T> action) where T : WebControl
{
T control = parent.FindControl( id ) as T;
if (control != null && action != null)
{
action( control );
}
}
The where clause is important because you can't cast "As" within the function without having some limits on the generc T.
Which allowed me to shrink the example down to:
ExecuteOnControl<TextBox>(_parentControl, "_childControlId", delegate(TextBox tb) { tb.Text = "someText"; });
This can be further simplified since the delegate can be declared once and used later.
Action<TextBox> tbDel = delegate(TextBox tb) { tb.Text = "someText"; };
ExecuteOnControl<TextBox>(_parentControl, "_childControlId1", tbDel);
ExecuteOnControl<TextBox>(_parentControl, "_childControlId2", tbDel);
One can argue here that the new code isn't really that much more readable though, but it was good hacking
10 April 2007
/Write a GreeseMonkey filter for the new wow forums.
- kill list
- space
- hide signature
- work-safe