Wednesday, July 14, 2010

XUI JS return false

When creating a HTML link and using XUI, you will HAVE to set the OnClick function of the HTML link tag to contain "return false;".

This is done as XUI events do not implement "return false" properly

Sunday, July 4, 2010

jQuery date picker

To have this working,

1. Include the jQuery UI javascript file into your page.

2. Create an input field and assign it a class. For the purposes of this example, I shall name the input field class, "testDatePicker"

2. Have a jQuery.Document.Ready function and within it, apply the following code.

$('.testDatePicker').datepicker({
dateFormat: 'dd/mm/yy',
showOn: 'both',
buttonImage: '/images/buttons/cal.png',
buttonImageOnly: true,
onSelect: function(){
//Insert any form of logic you will have.
//NOTE: it will have to be in the JavaScript syntax
}
});

Friday, July 2, 2010

jQuery alternating show and hide ...continued

After performing what I thought solve the issue, I came up with another blockage.

The technique from my previous posting worked brilliantly but it wasn't how I wanted it.

This post will further illustrate what I mean.

You see, what I set out to do was to allow the 'jQuery alternating show and hide' individually for each data row.

Let me explain.

I have a list of some data. For the purpose of this example. Lets use HTML unordered-list items.

<ul>
<li>blah1</li>
<li>blah2</li>
<li>blah3</li>
.
.
.
<li>blah-n</li>
</ul>

I had a HTML link (a-href tag) and a HTML paragraph (p tag) in each HTML li tag (see above). The a-href tag was suppose to perform the 'jQuery alternating show and hide' on the p tag.

Within the p tag, there lies the data.

Thus, to solved this, do the following.

1. Create a ASP.Net literal tag to replace the a-href tag.
If you are binding data to a repeater like what I am doing, you can simply access the ASP.Net literal tag in the OnItemDataBound event of the repeater.


2.Use the IF-ELSE statement from Step 5 of the previous post and convert that into a string.

NOTE: open & close swiggly brackets will have to be done twice for each instance.
This caught me out and I was having string issues when building my code.



3. After converting the IF-ELSE statement of Step 5 of the previous post to a string, append the converted string such that it make a distinction on each a-href tag.
The way I did this was to append "_" followed by the ID obtained from the data.

NOTE: Remember to include "return false;" after you've completed the IF-ELSE statement, if not the page will reload to the top of the page!

4. You will also have to append the p tag to used the same method as mentioned in Step 3.

Build your code and

TA-DAH, you're done!

jQuery alternating show and hide

Recently I was working on an iPhone WAP and required to alternate the jQuery show and hide.

This is a How-To to do such an event.

1. Create a HTML A-Href tag and specify the class value of it. For the purposes of this example, I shall call it 'hrefTest'.

Eg:
<a href="#" class="hrefTest">Some test link</a>


2. Create the hidden field. For the purpose of this example, I am going to create a HTML P tag and assign the class value of this P tag to 'test' and also specify in the style value of the P tag of display: none.

Eg:
<p class="test" style="display: none">Some test value</p>


3. Ensure that you have the jQuery library file (jQuery-1.4.2.min.js) or similar has been referenced at the top of the page.
This is something that I often forget to do

4. Declare another script tag and include the jQuery document.ready function.

5. Within the jQuery document.ready function, insert the following

$(".hrefTest").click(function(){
if($(".test").css("display") == "none")
{
$(".test").show();
}
else
{
$(".test").hide();
}
});


And walah, you have yourself a HTML link that will alternate between showing and hiding some text or whatever data.

Wednesday, June 30, 2010

Jokes #1

With many more light-hearted notes to come, I'd start this with #1

Tuesday, June 8, 2010

SQL Haversine formula

This will give you the straight-line a.k.a "as the crow flies" distance between 2 geospatial coordinates.

(6371.392896*2*ATN2(SQRT((sin((radians(GeoLatitude - @lat2Compare)) / 2) * sin((radians(GeoLatitude - @lat2Compare)) / 2)) + (cos(radians(GeoLatitude)) * cos(radians(@lat2Compare)) * sin(radians(GeoLongitude - @long2Compare)/2) * sin(radians(GeoLongitude - @long2Compare)/2)))
, SQRT(1-((sin((radians(GeoLatitude - @lat2Compare)) / 2) * sin((radians(GeoLatitude - @lat2Compare)) / 2)) + (cos(radians(GeoLatitude)) * cos(radians(@lat2Compare)) * sin(radians(GeoLongitude - @long2Compare)/2) * sin(radians(GeoLongitude - @long2Compare)/2)))
)))

Thursday, April 8, 2010

Facebook with DotNet

Recently, I was given the opportunity to work on connecting to Facebook.

The way I've done it is by using Facebook Developer Toolkit available on Codeplex.

Codeplex - Facebook Developer Toolkit

All that is required on Facebook is to create an application and specify the Connect Url on the Connect tab to a specific URL, obtain the API & Secret key and you are set to go.

Facebook developer

More to follow

ps: This has now change as Facebook released their new Graph API.
Further post to come