views:

85

answers:

3

i have been asked by a client to develop a javascript(mootools)/html/css/php based game as a widget which can be deployed anywhere.

I have not written a widget before, so would love to get some tips and experiences so that i know some of the pitfalls before i start!

Thanks :)

Dan

A: 

Encapsulate your variables. Don't put anything in the global namespace, because you don't want to conflict with anything else operating there.

Ideally, let your widget write itself into the page; that reduces the number of separate things that have to be dropped into the page by the user, thus making it easier to install.

Make it clear what requirements your widget has - if it needs external libraries like MooTools to function, the person installing the widget will need to know that.

Amber
A: 

First of it depends of what you mean with anywhere? How much code are you allowed to publish to "anywhere".

Any how, the simplest way to publish anywhere is to just send "anywhere" a that implements the game. If you need different variables from each "anywhere" (for example for tracking) you can specify a .php file in the src attr that generates a javascript base on the parameters.

In the script you can use AJAX to talk to your sever and document.write to write at "anywhere" page.

One thing to keep in mind is that using a JS library could be hard since the "anywhere" page might no implement the specific JS library.

..fredrik

fredrik
A: 

good related thread.. http://stackoverflow.com/questions/2366539/widget-what-to-do-and-what-not

thanks for answers so far - the more the better!

significance