Blog <-

Archive for the ‘javascript’ Category

RSS   RSS feed for this category

Object Oriented Javascript

I never really gave it much thought, but it turns out that, naturally, Javascript supports Object Oriented programming. It's a bit awkward, but still:

 * Class description
function MyClass(param1, param2) {
    this.property1 = false;
    thisObj.eventHappened = false;
     * METHODS
     * method1
    this.method1 = function(param2) {
        this.property1 = param2;
    this.property2 = param1
    var out = "";
    out += "&lt;div id='"+param1+"'&gt;"+param2+"&lt;/div&gt;";
    this.div1 = document.getElementById(param1);
     * EVENTS
    /* Because 'this' in events is actually the event, we assign a
     * special variable here so we can reference this object from
     * the events.
    var thisObj = this;
    this.div1.onkeyup = function(e) {
        thisObj.eventHappened = true;
var myClassInstance = MyClass('myDiv', 'Hello!');

Information harvested by NSA larger than acknowledged

From Slashdot:
The New York Times is reporting that the "volume of information harvested from telecommunication data and voice networks, without court-approved warrants, is much larger than the White House has acknowledged." The NSA gained the cooperation of many American telecommunication companies after 9/11 to access streams of communication, both domestic and international, as a part of a presidentially approved program to hunt for evidence of terrorist activity.
What was it again? Oh yeah!

First they came for the communists, and I did not speak out—
because I was not a communist;
Then they came for the socialists, and I did not speak out—
because I was not a socialist;
Then they came for the trade unionists, and I did not speak out—
because I was not a trade unionist;
Then they came for the Jews, and I did not speak out—
because I was not a Jew;
Then they came for me—
and there was no one left to speak out.

Rev. Martin Niemöller

Land of the Free indeed.

Playground: Table column drag'n'drop resize

I write web applications at my work and in them I frequently make use of tables displaying information. Unfortunatelly, everybody always keeps asking 'Can you increase the size of this or that limited table column?'. Normally, we use tooltips to display contents that has been cut off, but that often requires some users to mouse-over all rows just to be able to see the full contents.

So I was thinking, wouldn't it be possible to use javascript to dynamically resize table columns? Here's a little Proof-of-concept. It only works in Firefox and is still rather clunky. That's because it started out as a general page element dragger, and was then rebuilt (or rather, adapted) to also resize table columns. Still, this is proof that it can be done.

Now I just need:

  • Removable columns
  • Editable cell contens
  • database fields that can be dragged into the table on-the-fly without having to do a reload
  • etc, etc.

Playground: Online Webbased TicTacToe

Here's a little TicTacToe game which can be played online in your browser against an reallife opponent. Everything is interactive, no need to refresh anything. It uses XMLHttpRequest to do Client 2 Server 2 Client communications.

WebGUI toolkit: A (small) proof-of-concept

Felt a little better today (I've got the flu), so I decided to do some hacking. I had this idea for a while about building a WebGUI toolkit with Widgets and all that stuff. So I made a little Proof-of-Concept. More (just barely) information can be found in the Playground.

Imagine what you could do if you linked this up with XMLHttpRequest! Awesome. Gonna test that out soon.


I've heard about XMLHttpRequest before, but never really gave it much attention. Which means I didn't even know what it was supposed to do, and therefor never looked into it further.

Turns out it's pretty neat though. If you're a webdeveloper, you must know how we deal with stuff like changing the values in a dropdown box depending on a chosen value in another dropdown box? You either send all possible information with the page when you construct it and then use Javascript to fill in the information on demand. Or you submit a form when something is chosen by the user and fill in the information server-side.

XMLHttpRequests let's you retrieve information from the server using a client-side Javascript XML object without requiring a page reload. In essance, it's a mixture between the two hacky methods mentioned above.

For more information, check out this article. An example is also present. While that example is nice, I like this one better.

I only had time to quickly skim through the article, so I'm still left with some more researching to do:

  • What about security? Can we XML request over a secure connection?
  • Do we have to transfer server-side session ID's manually?
  • Any complete frameworks available where have a XMLHttpRequest enabled front-end (client side) which queries a bunch of server-side pages which in their turn query the database (or stored XML information) and return information in XML?
  • Can this be a nice platform for three-tire webapplications?

(Thanks to Joel On Software for posting about this)

I hate….

It should speak for itself because, you know, who doesn't.. but still:

I HATE Javascript. Really. I bloody hate it. I'm not even going to explain why I hate it. If you don't know, you should try working with it some time. It's hilarious, truely! I mean.. even location.href=…. has undocumented behaviour. Such a simple piece of code. Same goes for location.replace() and location.reload().

I hate it.