Tuesday, November 27, 2012

HTML DTD: strict vs loose

I’ve been writing some HTML5 code lately, and at some point I faced some miscalculations of dimensions through CSS. After some research, I discovered I had my page being rendered in quirks mode. I’ve heard this expression before, but never really bothered much. What happens is that standards compliant pages should have a doctype declaration, which tells the browser the page should be rendered that way, otherwise the HTML will be rendered in a Neanderthal form, the so-called “quirks mode”. I never bothered using a doctype, because I didn’t know the real meaning of it. Until now.

Then, convinced to use a doctype, I faced another problem. There were two types for me:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
The first is called “strict”, the second is “transitional”. The strict cuts away all the deprecated tags, while the transitional is the same strict plus some stuff like iframe, which I’m using at my project. So, my page is a transitional one, and I finally found my DTD.

Good references here and here.

Friday, November 23, 2012

A JavaScript and HTML5 tree graph

Following the previous post, I needed a graphical representation of a tree graph to put on an HTML page. I thought it would be a great opportunity to learn this HTML5 thingy, which everyone is talking about these days. I ended up writing a full implementation of a tree graph using only HTML5 and pure JavaScript, thus avoiding any third-party JavaScript libraries.

However, I faced some problems. I had to plot more than 2,000 nodes, although not all at the same time, sometimes I had hundreds of them being shown. So I had to run into a series of optimizations of the algorithm, not only to speed up the internal calculations, but also the page rendering itself. On my first implementation, each node was a DIV, and the lines were drawn upon a canvas. Then at some point I decided to purely draw the whole monster on canvas, and I rewrote everything, taking the opportunity to add animation effects.

Since I consider it to be good and clean code, and believing that it could be useful to someone else, I published the whole code on GitHub at rodrigocfd/html5-tree-graph, along with an example file.

A hard work and a great experience, indeed.

Monday, November 12, 2012

A jQuery popup modal dialog

These days I needed to display a form in HTML. The simplest way to do this would be just go to another page, where the form would be displayed, then go back to the previous page after the submit. But the form had only a couple fields to use a whole page, and also it felt too cumbersome to go back and forth with the pages. Or I could use an ordinary window popup, but since it’s a modeless window, problems would easily arise.

So, with the aid of jQuery, I wrote a small jQuery plugin to use an ordinary hidden DIV as a popup modal dialog, so that I’d just have to keep the form into a DIV, and it would be shown without leave the current page. At some point, it saw that the OK and Cancel buttons could be automated themselves, so my form would need just the fields.

I also took the opportunity and used the same engine to generate automatic OK and OK/Cancel dialogs, thus beautifying the alert and confirm JavaScript stock functions. Worth mentioning that the popup can be stacked, that is, a modal popup can open another modal popup, and so on.

It ended up helping me a lot, so I published it on GitHub at rodrigocfd/jquery-modalForm, along with an example file.