Archive for the ‘javascript’ Category

Pingerator

Sunday, October 1st, 2006

Some of you might know that I’m a fan of microformats. I’ve had a few lectures here in Slovenia in our local multimedia center, I’ve done some persuading and some watching from a distance. I’ve been on the uf-discuss mailing list for some time now and on Saturday I read about this problem Andy Mabbett had with the Pingerati ping service for microformated pages – it only takes one URL per ping. This makes for a very painful resubmitting process.

Well since I was just back from a short vacation I decided to stretch my fingers and write up a small page that allows users to add multiple URLs that will get submitted to the Pingerati service one by one. It didn’t really take me much time – about an hour – and it was done. I present you the pingerator.

It’s an easy to use one page app. All you do is enter the URLs, one per line as the instruction says, and click ping! If you want to resubmit the URLs in the form you can click save and the URLs will be stored in a cookie. You can easily restore the URLs by clicking restore! The pinging is done via an iframe and you can even see the pingerati response if you toggle the visibility of the window.

I haven’t really had time to test it though so any bug reports are welcome. The application will probably be under some refurbishing in the next few days but that should not break the saved URLs or the ease of use it sports today.

Javascript compare

Thursday, May 18th, 2006

Today I found something in Javascript that just doesn’t make any sense. Ok, maybe some other things don’t make sense either, but I think this one just beats all of them.

Let’s say we have a string and a number:

a = "1";
b = 1;

Now we want to compare these:

alert((a>b) ' : ' (aa) ' : ' (b==a));

Both will give you ‘false : false : true’.

If we change a to “2”

a = "2";
b = 1;

we get a ‘true : false : false’. We’re still OK.

Now let’s change a to “a”

a = "a";
b = 1;

The weird thing is we get ‘false : false : false’ on both alerts.

In typestrict languages you’d get an error. Or at least you should. In php you get a ‘false : true : false’ and ‘true : false : false’ which would mean they decided that all strings are smaller than numbers. This is weird – if you make b a string “1” the return values change – but at least they made a choice.

For what I can comprehend Javascript casts both values to int and I can understand that. The core of the problem is obviously with the NaN value. What I can’t understand is how something’s not smaller, not bigger and not equal at the same time? I’m sure someone can explain this…

Frameworks in the future..

Sunday, May 14th, 2006

We recently had two workshops on AJAX and in the second one my co-host presented some JavaScript frameworks and we got into a discussion about when we’ll start using one of them. It seems that it was not a question of if but of when. I should point out that both of us are proficient in JavaScript and are not the primary targets of frameworks.

A few days later Eric posted Flummoxed by frameworks that started a huge debate about it (he also posted a later explanation). Yesterday I was also listening to Dustin’s episode 12: YUI Library Discussion about the Yahoo! User Interface Library.

What I got from all this was a weird feeling about frameworks. I can’t decide whether I like them or not and why. I don’t especially like any single one of them. Like any other advanced developer I have my own bunch of methods/functions/objects that I regularly use and copy around. This code evolves automatically as I find bugs or need more features. Frameworks on the other hand do this with a plan. Or so it seems. Hopefully the developers behind them are strong enough to fight the feature requests coming from noobs to keep the core frameworks small, simple and above all understandable. Even though some say bandwidth is almost free nowadays.

After a whole day of pondering I think I like the idea but probably not the hype and the implementations that more than anything frustrate me. I’m off to write my own framework.

Changing the way we change websites…

Friday, May 5th, 2006

A while ago Marko wrote about reusability of css based designs. I didn’t agree with him fully but had no idea how to explain/prove it.

In the times of table layouts the process od redesigning a site was actually (at least) three things. First the content was restructured and some of it written again (the sitemap). Then the layout was changed to reflect the new structure and to better fit the content (the wireframes). At the end a façade was made for reflecting the latest trends in ‘webdesign’ (the design – or is there a better word for it?). Even if it was a three way process it was rarely done by three different people – ‘webdesigners’ did almost everything themselves. Since this was quite a lengthy process it was also expensive and some corporate websites changed once every three (or more) years.

Now it seems things are changing for the better. With a DIV layout, CSS based designs and a strict separation of layout and content we can actually split these three into separate stages. The strict division of these stages gives us the posibility to focus our work on what it really has to achieve. It’s true that you cannot use the whole 100% of the other parts but being able to keep 80% is good enough.

About a week ago I found out about two ‘design’ contents and the one Slashdot is holding was interesting because it was about proving a point – you can change the façade without changing the layout or the content. I did the whole thing without changing a bit of HTML (with a bit ugly CSS, would be nicer if a few lines of the code were changed).

I think this way of thinking will settle in and more and more changes will include only one of the three stages. Hopefully they will be based on user testing and/or usage data…

AJAX workshop

Wednesday, April 12th, 2006

We’re preparing a workshop at Spletne urice (“Web hours” in Slovenian, a weekly meeting of web enthusiasts) that will focus on AJAX, hosted by me and another Marko. Actually we’re preparing two of them. The first one will cover the basics of asynchronous transport and data, the second one will add some DOM scripting and review some AJAX frameworks.

I’m asking you, my ’till-now-non-existent/anonymous’ readers, to come forward and suggest any AJAX frameworks and/or sites that need/want an AJAX makeover. We might use this information for the workshop and transform your site. If you want to come you can register here. The workshop will probably be held in Slovenian, but the code will be written in universally understood JavaScript so come back for the slides and a showcase of the makeover.

Why I don’t like widgets

Sunday, April 9th, 2006

The reason is really simple – they’re bloated. Widgets is another word for a huge javascript that does what you want/need and a whole other stuff somebody needed or maybe just the developer thought somebody would someday need. Usually the javascript is so ‘complex’ that you can’t just remove the stuff you don’t need – it’d be faster if you wrote your own.

There is another reason that goes beyond javascript. Most widgets don’t exploit the technology and go about reinventing the wheel which results in crappy/invalid HTML, problems with data persistance and a low level of pluggability. Some actually do use an API but I think that’s overkill.

It’s funny what wikipedia says about widgetsclearly, they represent any purely mercantile commodity that has no artistic or spiritual value. When I first started writing the SortedTable I wanted to accomplish the contrary. I tried to write something that would exploit the advantages of valid XHTML and the fact that you can nowadays rely on DOM functionality of the browser. I did it for me and not for money (and released it under CC license).

The problem is I got many feature requests, that could simply be accomplished via some DOM scripting and using the built-in event handlers. I decided to keep the script simple and display the possibilities through samples. What needs to be done next is the reimplementation of the sort function which is a bit slow – I already have an old implementation of Quicksort in javascript that is going to come in handy for this one.

Anyway, a new version is out. This is the changelist:

  • corrected a weird error that broke some sorts in ie6
  • added the possibility for a nonsortable column via class=”nosort” on the th cell
  • added the possibility to ‘regroup’ tbody elements if there’s more than one (for whatever reason)
  • added additional hook to put your custom javascript on (onsort)