Seva's notes

Wisdom, Awareness, Responsibility :)

Archive for the ‘prototype’ Category

Prototype styled Google Analytics javascript snippet

leave a comment »

Recently I’ve created a prototype styled javascript snippet to enable google analytics on one of my sites. Save this code in file and include it from the head tag of the page just after including of the prototype.js:

gaTrackerId = 'ss-ddddddd-d'; // insert your tracker id here
document.observe('dom:loaded', function() {
    var gaJsHost = (
        'https:' == document.location.protocol
            ? 'https://ssl.'
            : 'http://www.'
    ) + '';
    var script = new Element('script', { 'src': gaJsHost});
    var gaTrack = function() {
        if (
            || /loaded|complete/.test(script.readyState)
        ) {
            var pageTracker = _gat._getTracker(gaTrackerId);
    script.observe('load', gaTrack);
    script.observe('readystatechange', gaTrack);

Written by Seva

2008-08-11 (August 11) at 08:00:07

Integration of Zend Framework and Prototype Ajax

with 3 comments

Last two days I’ve worked on implementing an example of integration of Zend Framework‘s MVC and Prototype‘s Ajax for HTML Forms submission and validation.

The solution consist of 2 parts:

1. There is a new View Helper to create an Ajax-enabled form.

This part mostly consists of JavaScript code, which alters default HTML Form behavior to submit the input element values to the action’s URL with Ajax, if form’s method is set to ‘ajax’.

In addition the form itself listens to submission result events and (by default) marks input elements if they are invalid.

2. There is a new customized abstract base Controller which replaces default ViewRenderer with a new one, which:

a) detects whether the request was received from Ajax.
b) if true, will not render the view, but instead will output with the input validation information, if either.

Well, the development is not really over yet, but what I originally wanted to say is I’ve just realized how I miss writing good old JS. 🙂

By the way, I need to repeat [ad:start] how happy I am to have PHP, HTML and JavaScript editors in one powerful standardized environment (Eclipse) – what I never had in the past, before PDT, WST & ATF came to the picture [ad:end] :)).

Written by Seva

2007-10-29 (October 29) at 10:49:00