Posts by Tag "Javascript"

Subscribe to posts of this tag

jQuery Helper - What is to include?

I took some time in the last days to develop the concept for a possible jQuery View Helper that could pass the integration into the ZF Core. Since jQuery is organized somewhat different than Dojo is, its possible implementation for ZF will differ.

The jQuery Helper itself will manage inclusion of jQuery javascript files and the base library, much like the Dojo component works (Using the Google CDN). On top of this simple Helpers should mimic $.get, $.post, $.load and $.getJSON in a simple way, so that with a simple function call you can generate an XmlHttpRequest that updates a specified part of the DOM (via injection). (See: CakePHP Ajax)

Problematic are the next ideas: Additional Helpers will allow to specifiy the jQuery UI Library components (DatePicker, Sortables, Draggable, Dropable..), jQuery Autocomplete or jQuery Form (AjaxForm and AjaxSubmit). These libraries need additional javascript content to be downloaded and implemented in the Zend Framework project. There currently exists no way to implement them using a CDN. Therefore any documentation must clearly specify which additional content has to be installed and how. The helpers will have to be general enough to support this.

My proposal is currently in the workings and will be on the ZF Wiki in the next couple of hours.

Discussing a jQuery Helper for Zend Framework

Yesterday I had some time to test Matthews Dojo View Helper and the Zend_Dojo_Form component. At a first glance the implementation looks great and can almost instantly generate you a very nice form with all the possible Dijit form extensions that Dojo has to offer.

If one were to refactor the Dojo Component to allow for jQuery elements one bigger problem appears. Dojo has a CDN (Content Distribution Network) for all its components, that is, the Zend Dojo components can load all javascript and css files from a distant server. JQuery can only offer its main library to be loaded from a CDN. All additional components, for example the jQuery DatePicker, have to be installed locally. This significantly reduces the possibility for rapid development of Javascript/Ajax/Form components with jQuery and Zend Framework.

One could offer a complete dependency downloadable archive with all the CSS, Javascript and Images inside, but this would be very complex to maintain. Looking at the future Zend Tool capabilites one possibilty would be to offer a download client for all the relevant jQuery plugins, but there would have to be a man-middle-server that maintaines the most up to date locations of all the plugins, which also has to be maintained. Does anybody have a better solution to solve this problem? Perhaps the jQuery Team needs to be made aware that they need a CDN for their most stable plugins.

Abstracting from the CDN problem, I implemented a simple jQuery View Helper (mostly copy paste and simple rewrites from Matthews Dojo component) and a HtmlElement Form Helper which constructs a Date-Picker from within the template. This is very easy to use and looks great. In the next days I will add further helpers for the jQuery plugins I use in my day to day work live and hope to present a demo. I might even optin for a jQuery proposal aiming at inclusion in the Zend Extras Library.

Update: I got a reply on the jQuery mailing list stating that a CDN is planned for the jQuery UI library. Sadly this does not include plugins for which one might desperatly need a View Helper except for maybe the Date Picker. I will post further comments on this issue in the near future.

On Frameworks and Javascript Coupling

Zend announced they work together with the Dojo Team to integrate Javascript support into the Zend Framework. What this actually means is that you can write your Javascript Code in PHP if you're javascript library of choice is Dojo.

Since Dojo is not my library of choice I would have to write a JQuery View Helper on my own or wait until somebody else releases one.

But why not write javascript? Its very easy with all those libraries and addresses most cross browser incompabilities: One Django, one Zend Framework developer argue framework and javascript coupling is not the way to go based on the arguments that its breaks the MVC pattern, leads to function calls equal to those in javascript in its framework respective language, and that javascript is actually something any good webdeveloper should be able to programm, even when its just using library components.

Using JQuery without any help from tools for about a year now I can say there are still those days where javascript drives me mad, but most of the time I its working perfect. Since Ajax related calls like GET, POST, and FORM stuff are oneliners I don't see why one would need tighter integration of JS and frameworks.

Larger Javascript components like Popup Calendars, Autocomplete and the like are harder to integrate than in Rails or cakePHP, but thinking about the problem a little longer leads to powerful reusable solutions, that save time on integration after the first initial setup.