2017 © Pedro Peláez
 

yii2-extension yii2live

Yii2 Live package

image

digitv/yii2live

Yii2 Live package

  • Tuesday, February 6, 2018
  • by digitv
  • Repository
  • 2 Watchers
  • 0 Stars
  • 40 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 6 Versions
  • 0 % Grown

The README.md

Yii2live SANDBOX project!

This extension helps you with AJAX links, forms and modals., (*1)

Application AJAX response is divided into:, (*2)

  • JS/CSS files;
  • inline JS/CSS;
  • Page widgets output;
  • JS commands.

And all of these things are processed separately. So you can return only few javascript commands and no more else, or just one widget (as old good Pjax), or whole page, but only widgets, state of those were changed., (*3)

For example your Nav widget can decide what to do by itself - render widget fully or just change active link. There are special widget states for this., (*4)

echo \digitv\yii2live\helpers\Html::a('Ajax link', ['action'])
    ->ajax(true)
    ->context(Yii2Live::CONTEXT_TYPE_PARTIAL)
    ->pushState(false)
    ->requestMethod('post')
    ->confirm('Confirm message');
  • Link is AJAX enabled (ajax(true)),
  • using a partial context context(Yii2Live::CONTEXT_TYPE_PARTIAL),
  • page url is not changed on click (->pushState(false)),
  • request method is POST (requestMethod('post')),
  • and using confirm message (confirm('Confirm message')).

Creating HtmlContainer like a Pjax

...
<?php \digitv\yii2live\widgets\PjaxContainer::begin(['id' => 'test-wrapper']) ?>
    <?= \yii\grid\GridView::widget([
        ...
    ]) ?>
<?php \digitv\yii2live\widgets\PjaxContainer::end() ?>
...

All links inside this container will be AJAX enabled. Search form, that will update this container is looks like this:, (*5)

<?php $form = \digitv\yii2live\components\ActiveForm::begin([
    'id' => 'test-search-form',
    'action' => ['index'],
    'method' => 'get',
])->context('test-wrapper'); ?>
...
<?php \digitv\yii2live\components\ActiveForm::end(); ?>

or this, (*6)

<?php $form = ActiveForm::begin([
    'id' => 'test-search-form',
    'action' => ['index'],
])->ajax(true)
    ->requestMethod('get')
    ->context('test-wrapper'); ?>
...
<?php ActiveForm::end(); ?>

Using JS commands

...
    public function actionTest() {
        $live = Yii2Live::getSelf();
        $content = $this->render('test');
        if($live->isLiveRequest()) {
            $cmd = $live->commands();
            return $cmd->jHtml('#insert-selector', '<div>New HTML!</div>')
                ->jRemove('#remove-selector')
                ->modalBody($content)
                ->modalTitle('Modal title')
                ->messageSuccess('Success message!');
        } else {
            return $content;
        }
    }
...
  • jHtml - jQuery.html()
  • jRemove - jQuery.remove()
  • modalBody - Set modal body content
  • modalTitle - Set modal title content
  • messageSuccess - Show success message to user

There are much more JS commands that you can use (@see in digitv\yii2live\components\JsCommand), (*7)

Config options

Option Description
enable Global enabled flag
enableLiveLoad Enable "live" request for each link and form
enableReplaceAnimation Enable replace animation for each widget
enableLoadingOverlay Enable loading animation as animated overlay
headerName Header name used for "request ID" sending
headerNameContext Header name used for "context ID" sending
linkSelector jQuery selector for links (only when enableLiveLoad active)
linkSelectorAjax jQuery selector for links
formSelector jQuery selector for forms (only when enableLiveLoad active)
formSelectorAjax jQuery selector for forms
fieldSelectorAjax jQuery selector for form fields (change event)
messageAdapter Name of message adapter. Used to show messages for user (alert or notify)
modalDefaultSelector jQuery selector for default modal popup
modalDefaultRender Render default modal or not
modalDefaultId Default modal ID
modalDefaultSize Default modal size (sm/lg or empty)
modalDefaultWithFooterClose Show close button in modal footer

The Versions

06/02 2018

dev-master

9999999-dev

Yii2 Live package

  Sources   Download

MIT

The Requires

  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2
  • yiisoft/yii2 ^2.0.13

 

by Digit

yii2 ajax async live node.js

29/01 2018

1.1.9

1.1.9.0

Yii2 Live package

  Sources   Download

MIT

The Requires

  • yiisoft/yii2 ^2.0.13
  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2

 

by Digit

yii2 ajax live node.js

18/01 2018

1.1.8

1.1.8.0

Yii2 Live package

  Sources   Download

MIT

The Requires

  • yiisoft/yii2 ^2.0.13
  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2

 

by Digit

yii2 ajax live node.js

12/01 2018

1.1.7

1.1.7.0

Yii2 Live package

  Sources   Download

MIT

The Requires

  • yiisoft/yii2 ^2.0.13
  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2

 

by Digit

yii2 ajax live node.js

08/12 2017

1.1.6

1.1.6.0

Yii2 Live package

  Sources   Download

MIT

The Requires

  • yiisoft/yii2 *
  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2

 

by Digit

yii2 ajax live node.js

07/12 2017

1.1.5

1.1.5.0

Yii2 Live package

  Sources   Download

MIT

The Requires

  • yiisoft/yii2 *
  • bower-asset/font-awesome ^4.7
  • bower-asset/remarkable-bootstrap-notify ^3.1.3
  • bower-asset/animate.css ^3.5.2

 

by Digit

yii2 ajax live node.js