Easy integration of Intercooler.js (the easy to use Ajax handler) into Yii2 framework. Provides bunch of ready to use widgets with preddefined Intercooler requirements.
See Intercooler.js official docs on http://intercoolerjs.org
The preferred way to install this extension is through composer.
Either run
$ composer require dlds/yii2-intercooler
or add
"dlds/yii2-intercooler": "~2.0"
to the require
section of your composer.json
file.
Base module class Intercooler holds all options for Intercooler required html element attributes. Also handles registering of required js files using IntercoolerAssets. It is usually init through some of included widgets.
Using base class static methods you are allowed to set specific intercooler headers.
To be able to redirect user to new url after intercooler request is done you have to set redirect header in server side.
Intercooler::doRedirect('/new-destination-url');
To refresh intercooler elements you can set refresh header on your server side and tell intercooler which elements should be refreshed.
Intercooler::doRefresh([
'/foo/bar'
]);
See what '/foo/bar' stand for in official docs
To remove targetted element you have to set remove header on server side.
Intercooler::doRemove();
Integration comes with buch of ready made modules based on intercooler behavior.
Helper which renders appropriate html element with required intercooler attributes.
AjaxBlock::begin([
'id' => 'my-ic-widget',
'wrapper' => 'button',
'options' => ['class' => 'text-gray']
'intercooler' => [
'url' => '/my-custom-url',
'target' => '#my-target-element',
],
]);
// ... custom content
AjaxBlock::end();
For more widget options see AjaxBlock class documentation.
Renderes Infinite ListView widget.
InfiniteList::widget([
'id' => 'my-ic-infinite-list,
// ...
// standart ListView widget options
// ...
'layout' => "{indicatorRefresh}<div class=\"items\">{items}{pager}</div>\n",
'partialLayout' => "{items}{pager}\n",
'intercooler' => [
'url' => '/my-ic-feed-url,
'type' => \dlds\intercooler\Intercooler::RQ_TYPE_SRC,
],
'pager' => [
'class' => InfiniteListPager::className(),
],
]);
For more widget options see InfiniteList class documentation.
Comments