Anybody have examples of widgets

A place to share your Plugins and Extensions

Anybody have examples of widgets

Postby cajazzer » Fri Dec 31, 2010 1:26 am

Hello,

I started implementing a ui plugin and realized that perhaps it should actually be a widget? Does anyone have examples of a widget? Do I subclass RaxanUIWidget and respond to events similar to RaxanPlugin?

Thanks
cajazzer
 
Posts: 9
Joined: Fri Dec 31, 2010 12:06 am

Re: Anybody have examples of widgets

Postby raymond » Fri Dec 31, 2010 3:31 am

Hello,

I started implementing a ui plugin and realized that perhaps it should actually be a widget? Does anyone have examples of a widget? Do I subclass RaxanUIWidget and respond to events similar to RaxanPlugin?


Yes you need to subclass RaxanUIWidget and use event handlers to control the behaviour of the widget.

I'm working on a few sample widgets to be uploaded within the forums but here's a quick example of how to create a widget:

Code: Select all
class HelloWidget extends RaxanUIWidget {
    protected function _config(){
        // optional - do something here
    }
    protected function _init(){
        // optional - do something here
    }
    protected function _load(){
        // optional - do something here
    }
    protected function _prerender(){
        // code to render widget UI
        $this->html('Hello World!');
    }
}


Save the widget to raxan/ui/widgets folder and use the Raxan::loadWidget() method load it when needed.

To use the widget you can do one of the following:

1. Create an instance programmatically:
Code: Select all
$widget = new HelloWidget();
$this->append($widget);    // append to document


2. Use the xt-ui attribute to convert an element within a page into a widget:

Code: Select all
<div xt-ui="HelloWidget"></div>

When the page is view the above <div> tag will contain the word "Hello world"

Please let me know if this little intro was helpful.

Best regards,
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am

Re: Anybody have examples of widgets

Postby cajazzer » Fri Dec 31, 2010 7:23 pm

Very helpful. Thanks
cajazzer
 
Posts: 9
Joined: Fri Dec 31, 2010 12:06 am

Re: Anybody have examples of widgets

Postby cajazzer » Tue Jan 04, 2011 10:55 pm

Found a slight problem with widgets when calling programmatically:

The example
$widget = new HelloWidget();
$this->append($widget); // append to document

did not work for me as the RaxanUIWidget class constructor requires the first argument. If binding to an existing element, I was able to:

$domElement = $this->page->findById('helloDiv')->get(0);
$widget = new HelloWidget($domElement);

Thanks
cajazzer
 
Posts: 9
Joined: Fri Dec 31, 2010 12:06 am

Re: Anybody have examples of widgets

Postby raymond » Tue Jan 04, 2011 11:34 pm

Hi,

Yes, you're correct. My bad with the HelloWidget example. I mainly use the xt-ui when creating a widget.

The first parameter is require. It can either be an Id or DOMElement.

Example:

Code: Select all
$w = new Widget('id1'); // Use an existing element with id1
$w = new Widget('id2'); // Create a new element with id2
$w = new Widget($element); // DOMElement


As soon as I can I will have to add the Widget documentation to the user guide

Best regards,
__
Raymond
raymond
Site Admin
 
Posts: 215
Joined: Tue Mar 17, 2009 5:04 am


Return to Plugins & Widgets

Who is online

Users browsing this forum: No registered users and 1 guest

cron