Categories

My first post from nexus one

I stumbled upon this app for WordPress while looking for something else. This is very nicely designed and very user friendly.

Pixel Converter

This is an update to my earlier post Pixel to EM converter which focused on the online utility to convert ‘pixels’ to ‘ems’. I have updated the utility to support more units and it now can convert between any of the following units:

Pixel
EM
Point
Percent

You can also convert a CSS file contain any of all of the above units/formats to any of the desired format. I have also moved the utility to a more descriptive domain pixelconverter.kleptomac.com

Pixel Converter

HTTP REFERER header not set when location.href is used for page navigation | Microsoft Connect

Its pretty frustrating to see that IE doesn’t set the ‘referer’ header when navigating pages using ‘location.href’. The header is set properly if you are using anchor tags (<A>) to navigate through pages.

Normally this is much of an issue for navigation unless you validate using the referer header. One such case is when you are using ‘Re-write’ rules for your site. In such cases, although your site will work on other browsers, it fails in IE because of the missing referer header.

Microsoft doesn’t seem to be in any mood to fix this soon and have postponed the fix to IE9 :) check out the link below.

Re-opening to be fixed in IE9
HTTP REFERER header not set when location.href is used for page navigation | Microsoft Connect.


One interesting workaround which I found here is to simulate an anchor click like this:

function goTo(url) {
 var a = document.createElement("a");
 if(!a.click) { //only IE has this (at the moment);
  window.location = url;
  return;
 }
 a.setAttribute("href", url);
 a.style.display = "none";
 $("body").append(a); //prototype shortcut
 a.click();
}

Pixel to EM converter

Its been 6 months since I am working on this project and just when I thought I am done with it, I realize that I have been using Pixels in my stylesheets all the while and this doesn’t support the browser based “text size” settings (Internet Explorer). So, when the user changes the ‘text size’ settings, the font size of the applications doesn’t change. For this to work, all pixels now have to be modified to ‘em’ unit.

Em is considered to be a more effective way of representing layouts as it is relative to the body text/font size. This ensures that the aspect ratio of the layout is maintained even when the dimensions of the text changes (browser settings).

For me however, looking at the size and the number of the CSS files I had, this was a daunting task. A quick Google search showed a good number of articles on how to convert pixels to em, but all of them were mere number converters. I still would have to convert each pixel into em manually. I never had the patience to do that and therefore I wrote a small utility script that takes a CSS dump and converts all pixel values to em. The online version of this is available at pixel2em.kleptomac.com pixelconverter.kleptomac.com (An updated version of the tool is available now. Please refer to pixel converter post). I hope you will find it useful.

Pixel to Em

pixel2em

Auto update for Adobe Air executable (exe)

If you are used to using the ApplicationUpdaterUI class for providing the auto update feature for your AIR application, and have recently started to work on the new Native Process API in Adobe Air 2 beta for compiling into a Native app, you would realize that the auto update functionality just doesn’t work. This is because the ApplicationUpdaterUI is designed to work only for the default AIR applications (.air). If you want to provide auto update functionality for your executables (.exe), you need to rather use the ApplicationUpdater Class. You don’t have to modify the update.xml file. The only difference is since this is an executable, you can’t do an auto upgrade of the file. Rather, you will need to let the user download the file (if you are trying the update the .exe file). The most simplest way to do it is to capture the “UpdateStatus” event of the ApplicationUpdater and check if an update is available and then trigger a ‘navigateToURL”. Checking if there is a new version available can be done using the “StatusUpdateEvent.available” property. Here is the code that you can use.

private function checkForUpdate():void
{
appUpdater.updateURL=”<path>/update.xml”; // Server-side XML file describing update
appUpdater.addEventListener(UpdateEvent.INITIALIZED, onUpdate); // Once initialized, run onUpdate
appUpdater.addEventListener(StatusUpdateEvent.UPDATE_STATUS, onUpdateStatus);
appUpdater.addEventListener(ErrorEvent.ERROR, onError); // If something goes wrong, run onError
appUpdater.initialize(); // Initialize the update framework
}

private function onError(e:UpdateEvent):void
{
Alert.show(e.toString());
}

private function onUpdate(e:UpdateEvent):void
{
appUpdater.checkNow();
}

private function onUpdateStatus(event:StatusUpdateEvent):void
{
if( event.available ) {
// set an information text for the user
application.updateInfo.label = “An updated version ” +
event.version + ” is available. Click here to download.”;
// or directly display a download prompt
var urlReq:URLRequest = new URLRequest(“<url to the executable>”);
navigateToURL(urlReq);
}
}