Saturday, 28 March 2009

HTML element related data storage

Hi Folks,

I'm working on a voting widget generator Drupal module. Arbitrary voting widgets can be defined through a hook, and my module renders them to the node page. At the final phase the forms are converted to an ajaxian style and this needs a lot of information related to elements. The good old (quick and dirty) way to do this is the custom attributes. For example:

<img src="" class="..." weight="..." type="..." key="..." nid="..." />

As far as I know, it works in most browser, however, I bet it fails on any xhtml validation. (And so ugly.) My idea is a common data storage. You create a new element with a unique ID that can be a key as well in a javascript object, which would contain data. Let's see an example:
<script type="text/javascript>
var data = {};
$('div.class').append('<img id="i1" src="pic1.png" />');
// save data
data['i1'] = {weight:__, type:__, key:__, nid:__, names:[__, __, __]};
// retrieve data
var necessary_name = data['i1'].names[2];

That's all. This example is just a schema. It can help if you generate lots of elements or you want to attach data elements in runtime.


Friday, 13 March 2009

Drupal module finder Flex - AIR application


Recently I began learning Flex. The idea was from my boss and a girl who linked an adobe site with a LOT flex video on it. (Thanks @SquirrelMaster) - check it

In the Drupal world there are two important buzzwords related to Flash: Druplash and Druplex. In a nutshell, these words cover the intelligent way that a Drupal application and a Flash application can communicate between each other. The basic idea behind this is the usage of Drupal as a back-end (information source) and the Flash as a better way to visualize the datas. To embed a flash game, video or a file/image uploader is not communication at all. As far as I know, it is very new field, however, there are quite a lot interesting idea there isn't any world changing way to implement it. If you interested in it, here you are some links to dig:

SWFObject provide a better way to add flash content to your HTML. It checks the client's flash player and browser capabilities. And if the environment unable to render your SWF appropriately, it displays an alternative content -> in the SEO side, makes your page readable for robots.

With SWFAddress your flash object can communicate with the JavaScript on the same page. Thus JavaScript can send a state (like the url) about the site (and from the url the flash can restore some action or timeline state - for example if the url is, it loads the shoes page). And of course vica-versa. Flash can send it's state to javascript and with that the javascript can modify the url for example. If its seems useless just think about sending a url for your friend. If the flash site can't handle the url, it always shows the home page.

Drupal has a module called Services. It defines a bunch of services (user services, node services, ...etc) and supports several layers to communicate (HTTP, RPC, XML-RPC, SOAP). The work-flow abstraction is quite simple. You send a request to the Drupal site, it does something (get data) and send back to the caller. The real power that you can create any custom services easily and with it you can retrieve any the information you want from Drupal.

AMF is a message format Flash use in transactions. It's binary, so mush more smaller than an XML message format. AMFPHP is a converter from AMF to PHP native format.

AMFPHP porting to Drupal.

There are some slides about Druplash and Druplex:

Anyway. I fell in love with Flex. The reason I'm writing this post I developed a small application that helps searching Drupal modules on your desktop. How? With AIR. Unfortunately you have to install the desktop flash interpreter tool: called AIR player. It's more or less the same as Flash Player with a minor difference, it have the flash ran on desktop. Another interesting development: Adobe put the SWF and FLV/F4L technology to free license and strives to ease running flash applications on different devices. You know, now it's not the best on a unix based distro. But, ... at least you have the option for it.

So, back to my Flex app. If you want to try, you can download from here:

Adobe AIR player is available at here:

I can imagine a lot Flex application which can help the Drupal development. Making this was't more than 2 hours. Well, I know, it doesn't do too much as well.

If you have a creative idea that would be great to implement with Flex, please tell me. I'd be pleased to hear any feedback.