Archive for January, 2006

HTML_AJAX 0.3.4 is released

Tuesday, January 31st, 2006

HTML_AJAX 0.3.4 was released today, it contains lots of bug fixes so if you use HTML_AJAX you’ll want to upgrade.

Release notes and testing results are available on the wiki, and the examples are available online if you want to see some of the basic features.

I’m hoping to do a beta release soon, so if you have time to help with an API review please get a hold of me.

HTML_AJAX Feature of the Week: Javascript Behaviors

Tuesday, January 24th, 2006

I’m trying out something new here, every week i’m going to write a short post describing an HTML_AJAX feature. Hopefully this will get some people started using the new features and maybe even get some more developers helping out with the project. It will also give me a place to try out some material for my upcoming AJAX book.

JavaScript Behaviors

JavaScript Behaviors are pieces of JavaScript code applied to DOM elements through the use of CSS selectors.

HTML_AJAX ships with a slightly modified version of the Behaviour javascript library. The slight modification is the replacement of the css parsing/selecting code with Dean Edwards cssQuery() library. This was done for a couple reasons, first the css code in behavior is under an unknown license and Dean’s code supports more of the css selector including most of css3.

I also used the American spelling of Behavior instead of the British (darn extra u’s)

Turning Behaviors on

Assuming you already have HTML_AJAX installed all you need to use behaviors is add “behavior” to your list of libraries.

If you just wanted the behavior library you could do:


<script type="text/javascript" src="server.php?client=behavior"></script>

Or including it with some of the other HTML_AJAX pieces


<script type="text/javascript" src="server.php?client=util,main,request,httpclient,behavior"></script>

Adding Behavior Rules

In most cases you’ll want to put your behaviors in their own JavaScript file, that way they can be reused and they don’t clutter up the html, thats the point of them after all. But you can just toss them in a script block in any file.

An example rule is shown below:


Behavior.register(
        "h1",
        function(element) {
                element.style.color = ‘blue’;
        }
);

Now this rule is rather worthless since its just setting a style rule, something that css is much better suited for but it does show a couple important things. You have immediate access to the matching elements, this allows you to create new child elements, update properties including innerHTML, and set event handlers.

You can set event handlers using onEvent methods but i prefer to use a couple util methods in HTML_AJAX that map to setEvent etc.

A more useful example which submits all the forms on a page using AJAX is shown below:


Behavior.register(
        "form",
        function(element) {
                var handler = function(e) {
                        var target = HTML_AJAX_Util.eventTarget(e);
                        HTML_AJAX.formSubmit(target,target);

                        // cancel submission in IE
                        e.returnValue = false;
                        // cancel submission in FF
                        if (e.cancelable) {
                                e.preventDefault();
                        }
                }
                HTML_AJAX_Util.registerEvent(element,’submit’,handler);
        }
);

There isn’t a lot too see here, we build a function to handle the submit event. It submits the form using HTML_AJAX.formSubmit, the first param is the form to submit, the second is the element to update (The second element is optional but do a bug in 0.3.3 it not being set isn’t detected correctly so you’ll have to upgrade to 0.3.4 to skip it). Then we cancel the normal form submission.

Wrapping it up

These examples show some of the power of behaviors, but there really is a lot more that you can do with it. If you have any tips feel free to leave them on the wiki or as comments to this post.

Run the example.

View the full example Source.

Download the example code.

azPHP January Meeting Tonight

Tuesday, January 24th, 2006

After a long holiday break azPHP is back, our January meeting is tonight and we have a couple great presentations lined up.

The meeting is tonight 7:00pm at Walt’s TV in Tempe be sure to invite anyone you know that might be interested.

The meeting will have two two presentations each around 45 minutes long and then will finish things up with a open QA Session answering questions about the presentations or about anything else that is PHP releated.

The Presentations are:

Beginning Presentation: An introduction to the JavaScript DOM and scriptaculous by Jon Roig
Advanced Presentation: Generic Data Objects by Brian Ross

Meeting Timeline –
Tuesday Jan 24
7:00 - PHP News
7:15 - An introduction to the JavaScript DOM and scriptaculous by Jon Roig
8:00 - Generic Data Objects by Brian Ross
8:45 - QA Session
9:30ish - Social Hour(s) at Old Chicago

Uversa is Hiring

Friday, January 13th, 2006

My employer is looking to hire a couple PHP developers.

At Uversa were lucky enough to release many of our products under the GPL, you can see some of our Open Source work at our OP/EN site.

Were are also doing quite a bit of AJAX these days so this could be your opportunity to do some fun JavaScript programming as well.

Also don’t worry to much if your not in the Phoenix area, as long as you can work on the same timezone there shouldn’t be too many issues.

Feel free to contact me if you have any questions about Uversa or the job openings.

ZActiveRecord can’t work?

Monday, January 9th, 2006

In the webcast the following active record example was shown. This looks nice and slick but I don’t see how its possible, at least in php 5.1. There is no way to get the class name of the child in in the find all method.

<?php

< ?php 

class Person extends ZActiveRecord {}     

$people = Person::findAll(array(‘nameFirst’ => ‘Daniel’)); 

foreach ($people as $person)
{
    echo $person->nameFirst . “n”;
} 

?>

?>

This example shows how get_class doesn’t help it always returns parentstatic

<?php

< ?php
class parentstatic {
    static function findAll()
    {
        echo get_class();
    }
}
class childstatic extends parentstatic {
}
echo parentstatic::findAll();
echo childstatic::findAll();
?>

?>

Anyone have a clue on how Zend is planning to get around this problem. From what I can tell its impossible and I haven’t seen anything on 5.1.2dev that would solve the problem but I could just be missing something and there is an easy way around the problem. To me it looks like PHP forces you to do a none static activerecord implmentation.

Update:
This also came up in the comments of Chris’s post about the webcast.

Update after comments from Mike Naberezny:
Webcast showed what Zend hopes will be the final syntax, they are working on a PHP engine level solution, but since they want to work with current php5 installs we will see some other solution as well. Of course the code with work with non-static usage, though thats not as nice Semantically.

PHP Conference in London

Monday, January 9th, 2006

The PHP London user group is staging the UK’s first dedicated PHP conference on Friday February, 10th 2006. It looks too be a well planned conference with lots of great speakers. The talk by Harry Fuecks about AJAX and what he has learned creating his JPSpan project looks really interesting. So does the security talk by Christopher Kunz.

Last year while I was living in London I got to take part in a number of PHP London meetings and it was great fun. Im sure this conference will be a lot of fun as well given all the great people involved. Its really nice to community driven conferences take place, hopefully a successful conference in London will prod other user groups into action as well.

I won’t be able to make it too the conference since I don’t have time for that much traveling but if you’re in the UK (most of Europe too for that matter) it should be a great event.

This circle expands additional navigation
You should really buy my AJAX book.
You'll learn not only the technology you need for implementation but also an understanding that will help you get the most from AJAX.
You'll also have my eternal thanks :-)