Friday, June 15, 2007

Ajax Loader Generator

Well, I have been bit lazy these days by not posting regularly...well actually earlier i was quite busy and now i m very free on a leave from office so dont feel like Starting my PC.

Some weeks ago i found this interesting stuff for all you guys for whom AJAX has become a norm in your web applications...

Got bored of simple "loading..." text or also bored of simple circular loader...then its time to check this site out.
http://ajaxload.info/

Here you can use/customize any loading image based on your web apps design.

I wont please speak much bout it coz this site is really very useful ;P
http://ajaxload.info/

Saturday, June 2, 2007

IE DOM Issue

Recently I had an issue wherein I had to create new HTML element via DOM.And these HTML elements needed to have some properties as well HTML events like onClick(), onMouseOver(), etc.

While doing so my code worked perfectly fine in FireFox, but in IE the new elements created did not behaved in desired manner.
After a bit research I found that setAttribute() function doesnt work always in IE (actually it is suppose to not work at all ;)..).

Substitue for using setAttribute() is to use innerHTML
eg.TR1.innerHTML = "";

In my case innerHTML didnt worked as i had too many parameters to pass wherein I was out of combinations for using single and double quotes.

Below were the different ways I tried.
Not one of the following examples worked in IE:

TD1.setAttribute('onclick', 'doThis(' + param + ');');
TD1.onclick = 'doThis(' + param + ');';
TD1.onclick = new Function('doThis(' + param + ');');
TD1.onclick = function() { doThis(param); };
TD1['onclick'] = 'doThis(' + param + ');';
TD1['onclick'] = new Function('doThis(' + param + ');');
TD1['onclick'] = function() { doThis(param); };

The hack for making onClick work for you in IE via DOM

TD1.onclick = function() {
var temp = new Function("dostuff('"+myvar+"')");
temp();
}

The above code works well with both IE and Mozilla.
The same technique is to be used for calling any function for any HTML Events(onMouseOver).


NOTE: The above code can be simplified only when the function you are calling (dostuff) does not have any parameters to pass.

E.g.
TD1.onclick = function() { dostuff(); }

Some more interesting hacks for making your DOM work in IE are

blah.setAttribute('class','myCSS');


blah.className = 'myCSS'; <-- This line needs to be added

blah.setAttribute('valign', 'top'); This wont work as IE is case-sensitive
blah.setAttribute('vAlign', 'top');

Reference: Why IE Sucks

Wednesday, May 30, 2007

JavaScript Conditional Compilation.


Below are few inbuilt JS variable using which we can know some details of Client machine.

Predefined conditional compilation variables
for JavaScript
Variable Description
@_win32 Returns true if running on a Win32 system, otherwise NaN.
@_win16 Returns true if running on a Win16 system, otherwise NaN.
@_mac Returns true if running on an Apple Macintosh system, otherwise NaN.
@_alpha Returns true if running on a DEC Alpha processor, otherwise NaN.
@_x86 Returns true if running on an Intel Processor, otherwise NaN.
@_mc680x0 Returns true if running on a Motorola 680x0 processor, otherwise NaN.
@_PowerPC Returns true if running on a Motorola PowerPC processor, otherwise NaN.
@_jscript Always returns true.
@_jscript_build The build number of the JScript scripting engine.
@_jscript_version A number representing the JScript version number in major.minor format.

IE4 supports JScript 3.x
IE5.x supports JScript 5.5 or less
IE6 supports JScript 5.6

The version number reported for JScript .NET is 7.x.

@_debug Returns true if compiled in debug mode, otherwise false.
@_fast Returns true if compiled in fast mode, otherwise false.

In most cases, you probably will be limited to just using @_win and @jscript_build:

/*@cc_on
@if (@_win32)
document.write("OS is 32-bit. Browser is IE.");
@else
document.write("OS is NOT 32-bit. Browser is IE.");
@end
@*/

User defined Variables

You can also define your own variables to use within the conditional compilation block, with the syntax being:

@set @varname = term

Numeric and Boolean variables are supported for conditional compilation, though strings are not. For example:

@set @myvar1 = 35
@set @myvar3 = @_jscript_version

The standard set of operators are supported in conditional compilation logic:

  • ! ~
  • * / %
  • + -
  • << >> >>>
  • < <= > >=
  • == != === !==
  • & ^ |
  • &amp;amp;& |

You can test if a user defined variable has been defined by testing for NaN:

@if (@newVar != @newVar)
//this variable isn't defined.

This works since NaN is the only value not equal to itself.

References:

Friday, May 25, 2007

JavaScript No click links

No-click-links are link which you don't have to click.
While Googling for Eazy no click links, I found a Javascript code which enables us to navigate without clicking.
The example is given here

http://labs.mininova.org/noclick/

Other than no Clicks, there quite good number of other examples also like
  • mulitselect without control button use,
  • Visual Passwords,
  • Instant Form Validation,
  • etc. ;)
btw myself hoping to see a revolution in Web Navigation by use of more No click links and Visual passwords.

Thursday, May 24, 2007

Browser-Specific selectors (CSS)

These selectors are very useful when you want to change a style in one browser but not the others.

IE 6 and below

* html {}

IE 7 and below

*:first-child+html {} * html {}

IE 7 only

*:first-child+html {}

IE 7 and modern browsers only

html>body {}

Modern browsers only (not IE 7)

html>/**/body {}

Recent Opera versions 9 and below

html:first-child {}

Safari

html[xmlns*=""] body:last-child {}

To use these selectors, place the code in front of the style. E.g.:

#content-box {
width: 300px;
height: 150px;
}

* html #content-box {
width: 250px;
} /* overrides the above style and changes the width to 250px in IE 6 and below */

Get First Buisness day of Month- PHP

I have written a small function which calculates if given date is first buisness day of that month.
This can be set in cron job and run every day to check if this is first buisness day.
This can be useful for sending newsletters / promotional offers , etc on first buisness day of every month.


function definition is given below

/**
* Function which checks if current date passed is a first buisness day of any month or NOT.

* Description - First it checks if given date is 01 if yes then check if its not sat/ sun / public holidays.
if 01st is nonbuisness day then ignore return false.
In this case when the function will be called again on 02, here it will check if 02 is buisness day, if yes then if 01 was non buisness day then 02 is definitely first buisness day of the month.
This check will be done until 06 of every month.

* @param integer $year year in YYYY format
* @param integer $month Month in MM format
* @param integer $day day in DD format
* @param mixed $non_buisness_days array containing all non buisness days values will be in format Sat, Sun, Tue
* @param mixed $public_holidays An array containing list of all holidays for given year, the dates should be in YYYY-MM-DD format
* @return bool true if given date is first buisness day else otherwise false.
* @author VN (02/05/2007)
**/


function is_first_buisness_day($year,$month,$day,$non_buisness_days='',$public_holidays='')
{
$tmpstamp = mktime(1,1,1,$month,$day,$year);
//echo $year,$month.$day."
";
$ymd = date('Y-m-d',$tmpstamp);

if($public_holidays == ''){
$public_holidays = array();
}
if($non_buisness_days == ''){
$non_buisness_days = array();
}

$d = date('d',$tmpstamp);
$day = date('D',$tmpstamp);
$month = date('m',$tmpstamp);
$year = date('Y',$tmpstamp);



$previous_d = $d-1;
$previous_day = date('D',mktime(1,1,1,$month,$previous_d,$year));

$tp_first_day = mktime(1,1,1,$month,01,$year);
$day_first_day = date('D',$tp_first_day);
$day_first_ymd = date('Y-m-d',$tp_first_day);

if(($d == 01 && (!in_array($day,$non_buisness_days) && !in_array($ymd,$public_holidays)))
($d != 01 && (in_array($day_first_day,$non_buisness_days) in_array($day_first_ymd,$public_holidays)) &&
(!in_array($day,$non_buisness_days)) && (!in_array($ymd,$public_holidays)) &&amp;amp;
($d <=5 && (in_array($previous_day,$non_buisness_days) (in_array($day_first_ymd,$public_holidays)))))){ $return_value = true; } else { $return_value = false; } unset($d); unset($day); unset($month); unset($year); unset($non_buisness_days); unset($previous_d); unset($previous_day); unset($tp_first_day); unset($day_first_day); unset($public_holidays); return $return_value; }

Usage


$pb = array('2007-05-01','2007-12-25');
$dt = $_GET['getdate'];;
$dt = explode('-',$dt);

$non_buisness_days = array('Sat','Sun');

echo "Non Buisness days array:
";
foreach($non_buisness_days as $i => $v){
echo "'".$v."'";
echo " ";
}
echo "

";
echo "Public holiday array:
";
foreach($pb as $i => $v){
echo $v;
echo "
";
}
echo "

";

$bool = is_first_buisness_day($dt[0],$dt[1],$dt[2],$non_buisness_days,$pb);

if($bool){
echo 'YES
'.$_GET['getdate'].' is a first buisness day of Month '.date('F - Y',mktime(1,1,1,$dt[1],$dt[2],$dt[0]));
}
else{
echo 'NO
'.$_GET['getdate'].' is not a first buisness day of Month '.date('F - Y',mktime(1,1,1,$dt[1],$dt[2],$dt[0]));
}


Wednesday, May 23, 2007

Navigation Without Mouse Clicks

Have you ever wondered how Surfing would be without mouse-clicks.
Still thinking what I mean.
Let me make it straight then.
lets Say there exist a "Link". Now inorder to view this page, people would normally click it.
Navigating without mouse clicks is that -all we need to do is just do mouseover on it and the link will be clicked and we will be taken to the desired page.

This is very much possible and many research projects are made online based on No-Click Idea.
If this idea is accepted by Internet Users then there would be no sound of mouse clicking while surfing internet,it would be a Quite expedition and number of people complaining of finger pains due to mouse clicks will also gradually decrease ;).

One such research project is here .
Its www.dontclick.it

I would strongly recommed you all to visit it so as to get that weird-nice experience while navigating this site.

I thoroughly enjoyed my experience and even played few games there.