23 Dec

rich text editors for christmas

I’ve been working on getting FCKEditor working in Konqueror. This is a very difficult task. I got around the problem of script elements not supporting onload through the use of a brute-force hack, but that is nothing compared to the obstacles that face me.
In order to get the thing working, I need to emulate contenteditable and execCommand.
contenteditable is not a w3c-sanctioned CSS attribute, but is incredibly useful, so both Mozilla and IE have written code for it. Konqueror does not yet support this.
execCommand is a javascript function which allows you to run a pre-defined command on a selection. execCommand exists for both IE and Firefox.
I will need to emulate contenteditable, which allows you to make a page editable (duh). As there is no existing ability for this, I will need to write this from the ground up – trapping key-presses and interpretting them – a bloody nuisance, but there you go…
As for execCommand – that should be a bit easier to emulate – there is a list of preset commands which I will need to emulate. I believe this will not be too difficult – it will be drudge-work, but not difficult.
If anyone knows of any existing KHTML code for any of this, please do tell me.

21 Dec

dropbox tracer

I’m just finishing off a shopping cart for an Irish examination papers website, and was thinking about what I have learned from this site and how I could improve it in future sites.
One of the things I learned in this one is that the basket of a shopping cart must not be visible at all times, as it can get quite large. In the present example, I have solved this by hiding the basket, unless explicitly displayed (see the "[show]" link in the Basket area (one you have added something to the cart)).
I was considering going a step further in the next project, though – maybe just displaying a basket icon in the top-right of the page, which symbolises the shopping cart – clicking on it would open up a view of the basket.
Then, it occured to me that it could get very user-unfriendly – how would the shoppers know where to look for their stuff?
The answer is that I would have to show them.
In Microsoft’s Windows Update site, when you click to add an item to the product list to download, the item appears to float up and into a drop-box, giving a very good analogy of putting an item into the box for later. This solves two problems – first, it shows that something is actually happening (which can be a problem in AJAX!!), and secondly, it shows where to look for the item.
So, I’ve written a simple function which can do something similar.
Here is the demo
What it does is that when you click on an action link, it "shows" a box being placed in another box. I will use this in future shopping carts to "show" items being placed in the cart.
The usage of it is incredibly simple. All you need to do is link to this file, and start off the thing with this:


In the above, "from" is the id of the element being placed in the other element "to".

21 Dec

intelligent design ruled to be religion

"Well, d’uh!", I think is the sentiment every non-american would like to express. I really can’t understand how this farce made it so far through the courts. Thank $deity (haha!) that this has been thrown out.
It seems that the only difference between Creationism and Intelligent Design is that in Creationism, the weirdos are willing to give the creative force a name, but in ID, they pretend that the creative force is unknown to them.
I really don’t understand what the problem is that Creationists have with evolution. After all, evolutionary theory does not say that there is no god, but rather that if humans were "created" by God, then evolution is evidently the tool that God used!
Kae Verens, registered atheist/agnostic #1664

05 Dec

utf8 in javascript, php, and mysql

I am working on a large site which uses a lot of Irish-language addresses. This involves quite a lot of fádas (accents) in words. Unfortunately, these characters cause problems when you try interact between JavaScript, PHP and MySQL.
The problem is character sets. JavaScript (actually, ECMAScript) specifies that external JavaScript files must be written in ASCII. ASCII is a 96-character set which does not include such letters as "áíéóú". This poses a problem when you are using, for example, AJAX, to import your data.
A similar problem exists with MySQL, although it’s a bit more complex there.
Anyway – the soution is the utf8_encode() function in PHP. For AJAX and other JavaScript purposes, and also for your MySQL queries, run all strings through utf8_encode() before displaying/committing them, and all should be fine.
Now, that can be a mountain of work to apply to your existing work, unless you’ve been using nicely abstracted packages, such as the Pear DB class and the Sajax package.
For DB, it’s a simple matter to add "$query=utf8_encode($query);" at the beginning of the simpleQuery() function in /usr/local/pear/DB/mysql.php.
For Sajax, change the sajax_esc() function to this:

function sajax_esc($val){
  return utf8_encode($val);

And that’s it! You should have no trouble with character encodings again…