Crafting the SAPO Campus platform, a thousand pixels at a time.
Search
Latest posts

High Performance Javascript - dealing with JSON

No Widget is an Island

Designing Email - Part II

Designing Email - Part I

The amazing "widget" object

The Facebook Witch Project

SAPO Campus keynote from OSL Unesco demonstration session

SAPO Campus session at the UNESCO OSL Seminar

SAPO Campus - Eden Seventh Open Classroom Conference

SAPO Campus leaflet for the UA freshmen

Archive

Janeiro 2011

Novembro 2010

Fevereiro 2010

Dezembro 2009

Novembro 2009

Outubro 2009

Setembro 2009

Julho 2009

Maio 2009

Abril 2009

Março 2009

Fevereiro 2009

Dezembro 2008

Novembro 2008

Outubro 2008

Setembro 2008

Quarta-feira, 16 de Dezembro de 2009
The amazing "widget" object

The UWA widget object


When developing widgets in conformity with the UWA spec, there is a seminal Javascript object which makes the UWA environment available, exposing essential methods that handle widget events, grab preference values and modify the widget's HTML. I'm talking about the widget object. This handy page lists every method readily available to use in the widget object.

What about my platform?


All these methods and callback functions, as useful as they are, are also very platform agnostic (hey, it's a good thing), thus failing to cover the particular interesting moments of a platform such as our very own PLE. I'm talking about basic stuff here, such as a widget knowing whether it was hidden, shown or closed.

Ok, that's all fine and dandy, but how about a solution? After fighting a somewhat uphill battle trying to access an iFrame's DOM (not the HTML per se, but rather its Global javascript objects) in a way that did not crash in certain browsers (ahem), I finally settled on this little line of (slightly ugly) code:
document.getElementById(frameID).contentWindow;

Armed with this code, I could now access random iFrames and have them execute arbitrary code (maniacal laughter ensues). So I decided it would be cool to let widgets implement some PLE specific functions, allowing developers finer control over how their widget reacts to specific platform events. The functions should be declared in your widget, inside the widget object. They're not required though, so if you have no need for a specific function (or all of them), it's cool, I guess. Not that I care. Hm. Anyway, here's the complete list:

widget.onResize()


This method is triggered when a user resizes columns in the platform. Since this causes the widget to resize as well, you might need to perform complicated Math equations or stuff. I don't know, just saying.

widget.onHide()


Unsurprisingly, this method is fired when the user hides the widget body using the little collapse button on the left of the widget chrome. This is useful if, for example, you need to stop a Flash movie in case the user hides the widget.

widget.onShow()


In 99% of cases, and if you're not CUI - Coding Under the Influence, you should use this method to undo anything the onHide() method did. It fires when the widget is uncollapsed and is thus once again visible to the user.

widget.onClose()


This method is triggered when a user deletes your widget (if your widget is awesome, this will never happen). Once again, use this to stop Flash movies or timed function executions.

widget.onOpen()


The reverse of onClose(), this is triggered when the user undoes the delete action (yay, the user loves your widget again!).
tags:

Published by bruno-abrantes às 16:09

About us
Janeiro 2011
Dom
Seg
Ter
Qua
Qui
Sex
Sab

1

2
3
4
5
6
7
8

9
10
11
12
13
14
15

16
17
18
19
20
21
22

23
24
25
26
27
28
29

30
31


tags

todas as tags

subscrever feeds

RSSPosts

RSSComentários

RSSComentários do post