Archive for the ‘imgAreaSelect’ Category

ImgAreaSelect 0.9

Monday, July 20th, 2009

I finally found enough time to finish developing the new version of imgAreaSelect, and I’m happy to announce it’s available for download.

This release brings a few major changes and new features — here’s a summary:

  • Styling the plugin is now done with CSS (the old styling options are still supported)
  • A new option has been added to show/hide the plugin with a fade effect
  • A new option has been added to get an instance of the plugin’s object
  • Some of the plugin’s methods have been made public and can be called through the instance
  • A new callback function has been introduced (onInit)

Implementing and testing the new features took me about one third of the total time I worked on this version, I spent the rest cleaning up and refactoring the code. As a result, although the new version has many new features, it’s actually a bit smaller that the previous release (0.8). The packed JavaScript file (included in the distribution package) is less than 8KB in size.

The plugin’s project page has also undergone some face lift and reorganization. The documentation is now on a separate page, and there’s a new examples page (at this moment, only three examples are included, but I will be adding more soon, I promise).

There is also a special bonus for all the people who want to modify the plugin’s source code and implement their own solutions based on it — I have made available an extensively commented version of the source code.

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.

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.

ImgAreaSelect 0.6.2

Wednesday, December 24th, 2008

What better present can you get for Christmas than a new release of the imgAreaSelect jQuery plugin?

Uh, ok, I guess you could point out a few examples. Especially that it’s a minor release with no new features, just one fix (canceling the selection now triggers the onSelectChange and onSelectEnd callback functions). But, that’s what you’re going to get from me this year, so enjoy it.

Oh, and…

Merry Christmas Everyone!

ImgAreaSelect 0.6

Monday, November 17th, 2008

Hello, my fellow web developers, it’s time for a new release of your favorite image-area-selecting jQuery plugin — here’s imgAreaSelect 0.6.

This version introduces two new features: keyboard support, which makes it possible to manipulate the selection using arrow keys, and the persistent option, which prevents the user from starting a new selection (so the user can only resize and move the pre-selected area).

The plugin now responds differently to clicking outside the selection area — the current selection is discarded, but a new one is not started until the user begins moving the mouse pointer. This way it’s possible to cancel the selection by clicking in the outer area and not end up with a 0×0 border, as it happened with the previous versions.

Update:
Drat, I just noticed a leftover debugging statement (which displayed keyboard codes in window.status) in the newly released version. I removed it and released the updated code as version 0.6.1.

ImgAreaSelect 0.5.1

Friday, September 19th, 2008

Version 0.5.1 of imgAreaSelect is out. There was a bug in version 0.5 that caused the selection area to be positioned incorrectly in WebKit-based browsers, and the new version fixes it — so go and grab it if you want your image cropping (or tagging, or whatever) application to work fine in Safari, Konqueror, and the world famous Google Chrome (and a couple others).

By the way, remember the PHP image cropping tutorial I mentioned in my last post? WebMotionUK just published an updated version of it.

ImgAreaSelect Image Cropping Tutorial

Sunday, August 24th, 2008

Since most people are using the imgAreaSelect plugin to implement image cropping interfaces, and I’ve received a few requests for a fully functional example of such a thing, I planned to write a tutorial on it. But, it seems someone already did this — WebMotionUK has a good article on building a simple tool that allows you to upload an image and crop it, with PHP and imgAreaSelect. So go ahead and read it.

If you have any other interesting examples of using imgAreaSelect, let me know — I’ll be happy to put a link here.

ImgAreaSelect 0.5

Wednesday, August 20th, 2008

As promised, I’m releasing a new version of the imgAreaSelect plugin.

The plugin code has undergone significant reorganization to make it behave properly in some extreme cases — for example, when the image is placed in a scrollable div. I’ve also added a few features that were frequently requested (like an option to set the parent element).

ImgAreaSelect 0.4

Tuesday, May 20th, 2008

Here’s a new release of my imgAreaSelect jQuery plugin. I’ve fixed a few bugs and introduced two new features that have been asked for: the ability to enable/disable the plugin on demand, and to set the color and opacity of the unselected area.

Edit:
There were a few bugs in the 0.4 code (thanks to vivo for catching them quickly), so I’ve made a quick update and released version 0.4.1.

Edit #2:
This is definitely not my lucky day. It seems my quick update was in fact too quick, as the updated version turned out to be broken in IE. I fixed it (and TESTED this time) and made yet another release, so it’s version 0.4.2 now.