Archive for 2009

ImgAreaSelect vs. Dashed Borders in IE

Friday, April 24th, 2009

In the recently released version 0.8 of imgAreaSelect, I introduced the borderOpacity option, which (as the name implies) allows you to set the opacity of the selection area border. It’s set to 0.5 by default, making the border semi-transparent, and giving the plugin a slightly more attractive look (at least in my opinion).

I didn’t expect that such a simple change might lead to any kind of a problem, but, well, having been dealing with browser bugs for the past few years I should have known better. The semi-transparent border looks and behaves fine in all browsers except one. Can you guess which one? Yeah, that was too easy — of course it’s Internet Explorer.

IE6 and IE7 display the border incorrectly when the selection area is being resized. The dashed border suddenly appears as if it was a solid line. Here’s the correct rendering in Firefox:

Selection area border in Firefox

And this is how IE6 and IE7 render it while resizing:

Selection area border in IE

It gets back to normal when the mouse cursor moves over the selection area. OK, so this is what happens in IE6 and IE7 — I thought that the super-standards-compliant IE8 would get this right, but I was waaay wrong. In fact, it seems IE8 takes this bug to the next level, as it displays the border incorrectly all the time, even if no resizing is taking place.

I’ve investigated this issue a bit and discovered that the border is not really turning into a solid line, it’s just that the empty space between dashes gets filled with white. And since the top-level dashes are also white (that’s the default value of borderColor2), it looks like a solid line. Interestingly, this only happens if the border is exactly one pixel wide.

I found out that the bug has already been reported to the IE8 team at Microsoft, so there’s a slight chance that it will be fixed in the final version that’s supposed to come out in the next few months. Nevertheless, I still had to find a workaround to at least make it work correctly in IE6 and IE7.

The fact that moving the mouse pointer over the bordered div seemed to fix the problem gave me hope that I might be able to force the div to be repainted, for example by playing with its margin/padding properties. And it turned out to be partially true — toggling the margin property between "0" and "auto" (which is visually the same) makes the border fine again. So basically, every time the selection area was being updated, I had to do this:

$border1.add($border2).css('margin', '0'); $border1.add($border2).css('margin', 'auto');

Or, not exactly this. Unfortunately, it only works if the incorrect “solid” border is actually rendered first. There must be some delay after the first .css() call to let IE draw it incorrectly, then the second call fixes it. Putting the second call in setTimeout() does the trick:

$border1.add($border2).css('margin', '0'); setTimeout(function () { $border1.add($border2).css('margin', 'auto'); }, 0);

This method has a side effect of causing the border to flicker a bit — it’s barely noticeable, but still. Additionally, it doesn’t do any good in IE8, as that bastard just fills the empty spaces with white no matter what. All in all, it’s an ugly and insufficient workaround, but it’s the best I’ve come up with so far. If anyone knows of or has an idea for a better solution, please let me know.

Regardless of whether I find a better workaround or not, imgAreaSelect 0.9 is going to support image-based borders, allowing you to effectively circumvent all this border-related stupidity of Internet Explorer.

ImgAreaSelect 0.8

Thursday, April 16th, 2009

I’ve just released version 0.8 of the imgAreaSelect jQuery plugin. The most significant changes in this version are:

  • two new options to set the true dimensions of scaled images: imageWidth and imageHeight,
  • a new option, zIndex, to allow explicit setting of the base z-index for plugin elements,
  • the plugin can now be initialized with either $(window).load() or $(document).ready().

Additionally, I’ve cleaned up some parts of the code and fixed a few problems. Thanks to all the people who reported bugs, provided feedback, and helped me with the testing.

Stay tuned for version 0.9, which is already under development and should be around fairly soon, with a few more new features. As usual, feedback and feature requests are more than welcome — just post a comment here or send me an e-mail.

Editdns.pl – EditDNS Record Management Script

Tuesday, March 31st, 2009

Over the last couple of years, I’ve used a few more or less popular free DNS hosting services, and my best experience so far has been with EditDNS.net — mostly because their service really puts you in control of your domains and records. I started using them when I needed to set up SPF records (which are technically TXT records in a specific format) for a domain, and I discovered TXT records were not supported by most DNS hosting services — EditDNS being one of the few exceptions.

However, a couple days ago I encountered a problem. I wanted to set up a round robin DNS configuration for a domain with two IP addresses, one of them being a dynamic IP (that changed once every month or two). One of the key objectives was that the DNS records should be updated automatically when the IP changed. An obvious solution would be to use DynDNS records (supported by EditDNS), but I quickly learned that it’s not possible to set up two records with the same name (which is the basis for a round robin configuration) and make only one of them DynDNS ready. The system considered both records dynamic and wouldn’t just update one, keeping the other one intact. So, bummer. My next idea was to use the EditDNS API to simply delete the old record and create a new one with the new IP address, but this turned out to be impossible too, as the delete function is not yet implemented in the API. Bummer again.

But there are no unsolvable problems, just unwritten Perl scripts. I ended up putting together a simple script that uses LWP::UserAgent to log in to the EditDNS website and add new records or delete existing ones. The script is flexible enough for general use, so I’m making it available — if any fellow EditDNS users are reading this, maybe you’ll find it useful too.

Postfix and Google’s SMTP Server

Tuesday, March 24th, 2009

I was recently configuring my local Postfix e-mail server to relay messages destined for Gmail accounts through Google’s SMTP server. The setup is actually pretty simple, and there are numerous good articles on this subject available on the Intertubes, to name a few:

The above sources will give you a detailed description of what you need to do (including creating a certificate, in case you don’t have one already), I’m just going to list the essential parts here. As a prerequisite, you need a Gmail account, as Google’s SMTP server requires you to authorize before allowing you to relay anything.

Note: My e-mail server is running FreeBSD, so if you’re on a different operating system, the location of Postfix configuration files will probably be different — you might have /etc/postfix instead of /usr/local/etc/postfix.

To tell Postfix to relay all messages destined for *@gmail.com through Google’s SMTP server, put this into /usr/local/etc/postfix/transport:

gmail.com smtp:[smtp.gmail.com]:587

Then, create the /usr/local/etc/postfix/sasl_passwd file, telling Postfix to authorize with your Gmail login credentials when connecting to Google’s SMTP server:

[smtp.gmail.com]:587 username@gmail.com:password

Finally, put the following into /usr/local/etc/postfix/main.cf:

transport_maps = hash:/usr/local/etc/postfix/transport smtp_sasl_auth_enable = yes smtp_sasl_password_maps = hash:/usr/local/etc/postfix/sasl_passwd smtp_sasl_mechanism_filter = plain, login smtp_sasl_security_options = noanonymous smtp_use_tls = yes

The transport and sasl_passwd files need to be hashed with postmap:

# postmap transport && postmap sasl_passwd

That’s it for the configuration. Restart Postfix to make the changes effective (again, the command below is for FreeBSD):

# /usr/local/etc/rc.d/postfix restart

That’s it — you can now test it by sending something to your Gmail account.

It’s working? Grrreat. However, you might notice that there’s one fundamental problem with this solution — any message transmitted this way has it’s original “from” address replaced with your Gmail account’s address, making it look as if it was actually sent from Gmail.

Luckily, as I found out, the “from” address will be left intact if it is listed as one of the “other addresses” assigned to your Gmail account. So, you just need to log in to your account, go to Settings → Accounts, and use the “Add another email address” option to add any addresses that you want to relay mail for.

ImgAreaSelect 0.7

Thursday, March 19th, 2009

Yesterday I released the new version of the imgAreaSelect jQuery plugin. The most significant addition in this release is support for resize handles on the selection area (enabled with an option), as requested by a few people. I’ve also managed to find a workaround for the annoying bug in Opera that prevented the move/resize cursors from being displayed properly.

While working on this version, I began planning the next one, and I’m probably going to rewrite and reorganize some parts of the code. The plugin has grown bigger than I imagined (both in features and code size), so a little restructuring certainly won’t hurt.

Weekend Project(s): Cardboard Cat Chaise / Greasemonkey Unit Conversion Script

Saturday, January 3rd, 2009

Every once in a while I like doing some DIY stuff just for the fun of it — I suppose it’s my deeply buried need to create something that is physical and not source code, for a change. Some time ago, I came across building instructions for a cardboard cat chaise, and I thought it might be fun to make. Besides, I had no doubts my cats would like it, as they’ve always demonstrated an evident fetish for cardboard boxes.

So, the day came yesterday — I got a big cardboard box, prepared the tools, arranged a workspace on the floor, and began reading the instructions. To my disappointment, all the dimensions in the text turned out to have been given in inches, which seemed perverted for a normal, healthy, metric-oriented person that I am.

Of course, it wouldn’t be a big deal if I just took a calculator, did a few multiplications, and got the respective values in centimetres. Or I could use the mighty unit conversion capabilities of Google search. But then I thought to myself — hey, isn’t this the 21st century, Web 2.0, and stuff? I shouldn’t be forced to do such a tedious task of entering numbers and doing the calculations, this bloody machine/Web/whatever should do it for me. With this in mind, I turned to Userscripts.org to see if there was a Greasemonkey script that could parse those awful inches and convert them to lovely centimetres right there on the webpage. But, bummer — it seemed there was no such script.

This is where my need to create something physical had to retreat for a while, as the more powerful need to immediately transform the idea for a conversion script into an implementation was taking over. I quickly coded a basic script that converted inches, feet, yards, and miles into centimetres, metres, and kilometres, and displayed the result in a tooltip when the mouse cursor was placed over the value in question, like this:

US to Metric

To make the script a bit more useful, I also added conversion rules for units of mass (ounces and pounds to grams and kilograms) and temperature (Fahrenheit degrees to Celsius). If you want to give it a try, you can grab it from Userscripts.org.

And the chaise? It turned out quite well, and the cats started using it instantly. Here’s one satisfied customer:

Happy cat on a chaise

If you compare my result with the original one from the article, you’ll notice I went with a more primitive IKEA-ish design, but my cats are just simple unpretencious DSHs and they don’t like fancy furniture.