Personal tools

June

Jun 29, 2010

TextAreaBound: trying my first jQuery plugin

Filed Under:

HTML has some nice attributes to control the size and bound of input fields. However those features aren't working for textarea. Our customer asked us for those features: max number of lines in a textarea, max numbers of character in the textarea AND in a line... Let's try to develop a jQuery plugin for obtaining this!

The APIs we want

We must reach this:

$(...).maxLinesLengthBound(n)
$(...).maxLinesCountBound(n)
$(...).maxTextLength(n)

Obviously, we like jQuery chaining so also this must work:

$("#textareaid").maxLinesLengthBound(20).maxLinesCountBound(15)

All of the 3 new jQuery feature take all the textarea element from the expression given and apply new bounds.

  • The maxLinesLengthBound method will put a limit on the number of lines in a textarea
  • The maxLinesCountBound method will put a limit in the number of characters of each line
  • The maxTextLength method is the most simple: put a limit to the number of total character in textareas

Bad news one: Javascript events

When adding character in Javascript we can rely on 3 events:

  • keydown event is called when a key is pressed (before it's released)
  • keyup event is called when a key came up after keydown.
  • keypress event is called when a key is... pressed! So it goes down and then up. More important, if you keep pressed a button, starting the characters-repeat, this even is called multiple times.

As you can see, the keypress is the best choice... but using this event has a great limitation.

When you rely on keydown event, the "actual" value of the field is the old one. When you bind an handler to the keyup or keypress events the value you can read is the new one. You have no way to know what was the old value of the field.

Don't think to use other events like change event. This type of event has the same problems and also is called only when the control loose focus.

Solution to bad news one

Yes, we can only read the new value of the field, but we can also use the event object and take from it the value of the pressed key, so we can know what new character will be added to the textarea

Bad news two: knowing where the cursor is (on Internet Explorer)

Unluckily in a textarea you not always append characters... you can also add new characters inside the text. The pressed key is still a very important resource, but we must also know in which position we are inside the textarea.

The task seems simple on all browsers, with only a single exception: you can read the selectionStart attribute of the textarea DOM element.

We really need this only for one of the 3 APIs we need above: the maxLinesLengthBound method. Other 2 APIs don't need to know where the cursor is...

The vary bad news is this: Internet Explorer do not support selectionStart!

Solution to bad news two (AKA: bad news three)

You can surf the Web looking for an alternative, and you will find a lot of blog post, articles and script for giving an alternative.

What is clear is that you must use some funny IE specific APIs like getBookmark and createRange... and you will fail.

I found no way to really have the same simple features. On Internet Explorer 7 I have a lot of problems when I go to the second line. Those APIs seems buggy and the browser don't see that you go on a new line.

Tired of this, I leave the problem to someone more expert than me with IE Javascript.

Wanna help me?

The jQuery plugin

You can find the plugin on the jQuery plugin official page, and also other info and the SVN repository in my Google Code space.

 

Jun 26, 2010

System.getProperty() returns null

Filed Under:

How to avoid a null pointer using System.getProperty() within a java agent.

Sometimes, for some reason, you have to do it. I'm talking about the use of System.setProperty() method within a java agent. If you don't pay attention it's easy to get a null pointer as result. Infact I got it. 

After a quick search I found out a way to solve the issue:

I will use "jna.library.path" as example.

First of all add the following line in "java.policy" file (in the "jvm\lib\security" folder below the Domino program folder).

permission java.util.PropertyPermission "jna.library.path", "read,write";

 

After that, add the java code to your agent :

String jnaProperty = "jna.library.path";
if(System.getProperty(jnaProperty) == null) {
   System.setProperty(jnaProperty,"your path");
}
 
And that it's all.
 
Bye

Jun 24, 2010

rt.vuvuzela?!

Filed Under:

Creato durante l'agonia di Italia - Slovacchia

rt.vuvuzela e' su pypi

Per vedere ciò di cui rt.vuvuzela è capace aggiungetela agli come al solito alla sezione [instance] del vostro buildout (eggs e zcml).

Una volta rilanciato il buildout la vista vuvuzela sarà a vostra disposizione.

Ecco uno screenshot della vista:

rt.vuvuzela at work

Per accedere al player aggiungete "vuvuzela" all'url, ad esempio:
http://nohost.com/vuvuzela
http://nohost.com/mycontent/vuvuzela

Un logo per rt.vuvuzela???

rt.vuvuzela logo

rt.vuvuzela is out!

Filed Under:

Developed while watching Italy on tv. Suffering...

rt.vuvuzela is available from pypi

As usual add rt.vuvuzela to eggs and zcml into the [instance] section of your buildout.

Then you can just go to your site and you will have a nice vuvuzela view displaying a player stealed borrowed from wikipedia. Here you can see a snapshot of the view:

rt.vuvuzela at work

To see it live just append "vuvuzela" to your browser url, e.g.:

http://nohost.com/vuvuzela
http://nohost.com/mycontent/vuvuzela


rt.vuvuzela logo???

rt.vuvuzela logo

Jun 17, 2010

New 'Email Triage' Technology by IBM

by fabio
Filed Under: