A metabox is simply part of the website, whose contents can be drawn from an AJAX call and get refreshed anytime or using an interval.
Changelog ¶
0.4
Added custom css, header and footer support.
0.3
Added begin/end support to render initial content.
Update guide ¶
From 0.2 to 0.4
PHP: Replace attribute initHtml with content
JS: Replace this.$element with this.$content in ajax callbacks
Requirements ¶
Tested on Yii 1.1.12
Usage ¶
Simple initialisation:
$this->widget('ext.metabox.EMetabox', array(
'id' => 'mymetabox',
'url' => array('/myurl'),
));
This prints: ~~~ [html]
~~~ and ~~~ [javascript] $('#mymetabox').metabox({url : 'myurl'}); ~~~You can refresh it manually, using JavaScript, without parameters ~~~ [javascript] $('#mymetabox').metabox('refresh'); ~~~ or with extra parameters ~~~ [javascript] $('#mymetabox').metabox('refresh', { type: 'POST', data : { } }); ~~~
You can initialize it with an interval so that it auto-refreshes:
$this->widget('ext.metabox.EMetabox', array(
'id' => 'mymetabox',
'url' => array('/myurl'),
'options' => array(
'refreshInterval' => 1000, // refresh every second
)
));
The metabox can have initial content. You can use the content attribute:
$this->widget('ext.metabox.EMetabox', array(
...
'content' => 'Initial content'
));
or the begin/end:
$this->beginWidget('ext.metabox.EMetabox', array(
...
));
echo 'Initial content';
$this->endWidget();
You can optionally add a header and/or a footer to the metabox:
$this->widget('ext.metabox.EMetabox', array(
'header' => 'My title',
'footer' => date('H:i:s'),
'content' => 'Initial content'
));
There are also three callbacks you can override which are called in the order shown below:
- beforeRefresh()
- handleResponse(response data)
- afterRefresh(response data)
Metabox::handleResponse by default updates the div's contents with the response data. Within the scope of these methods, this refers to the metabox object. You can access the outer div element by calling the $element attribute and the inner content div by calling the $content attribute as shown below in the example.
Also, you can access the header and footer divs (if they exist) by calling the $header and $footer attribute respectively.
$this->widget('ext.metabox.EMetabox', array(
...
'options' => array(
'handleResponse' => 'js:function(data){this.$content.html(data);}
)
));
Examples ¶
With HTML response
With JSON response
Installation ¶
Unzip into the extensions folder.
Demo
Any demo?
@nafania
Sorry, currently I have no place to put it, really. :(
query
thanks for nice extension.
I have one query that i want to refresh a link which inside views/layouts/main.php
i cant fix the url so it ive me error.
@hiral darji
I can't understand your question. Can you provide more details or a better explanation of the problem?
enhance request :)
nice extension ; but i need such functionality :
it will be better give the client a opportunity to handle it : if i set a js handler then shouldn't use the default behavior . let's say the response is JSON format thus the client side can handle it manually . the call back function can refer the EMetabox::id better as params of the callback function to pass .
@yiqing95
Hi
Please take a look at the new version (0.2) and the example fiddles for inspiration.
Thanks for the feedback.
@Fragoulas nice work
well done !!
cheers
Feedback
There have been some downloads and I would like some feedback on this class, whether it has been useful to anyone or any comments.
thanks
this extensions is working fine for me
cheers.
how to use it with dropDown list?
Thanks for the extension.
How can i use it with onChange dropDown list in a form?
@Shahcheraghean
How do you mean? can you give an example?
@Fragoulas
Thank you so much.I mean I have a dropDown List which I want on its onChange event, fetch some ajax data and change the metabox content by that result data.
For example, When i chose my custom country in dropDown list, I want to show some information about that country in metabox.
Is it possible? HOW?
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.