Skip to content

Commit

Permalink
Update ModalAjax.php
Browse files Browse the repository at this point in the history
  • Loading branch information
a1inani committed Jan 16, 2022
1 parent 254379e commit 9a86ed5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/ModalAjax.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace ivankff\yii2ModalAjax;
namespace a1inani\yii2ModalAjax;

use yii\base\Widget;
use yii\helpers\ArrayHelper;
Expand All @@ -20,6 +20,7 @@ class ModalAjax extends Widget

const BOOTSTRAP_VERSION_3 = 3;
const BOOTSTRAP_VERSION_4 = 4;
const BOOTSTRAP_VERSION_5 = 5;

/**
* events
Expand Down Expand Up @@ -145,7 +146,7 @@ public function init()
}

$this->modalWidgetConfig = ArrayHelper::merge([
'class' => $this->_isBs4() ? 'yii\bootstrap4\Modal' : 'yii\bootstrap\Modal',
'class' => $this->_isBs5() ? 'yii\bootstrap5\Modal' : 'yii\bootstrap\Modal',
'id' => $this->getId(false),
'headerOptions' => $this->headerOptions,
'bodyOptions' => $this->bodyOptions,
Expand All @@ -159,7 +160,7 @@ public function init()
'clientEvents' => $this->clientEvents,
], $this->modalWidgetConfig);

if ($this->_isBs4()) {
if ($this->_isBs5()) {
$this->modalWidgetConfig = ArrayHelper::merge([
'title' => $this->header,
], $this->modalWidgetConfig);
Expand Down Expand Up @@ -233,14 +234,14 @@ protected function registerMultiModal($id, $view)
e.preventDefault();
$(this).attr('data-toggle', 'modal');
$(this).attr('data-target', '#$id');
var bs_url = $(this).attr('href');
var title = $(this).attr('title');
if (!title) title = ' ';
jQuery('#$id').find('.modal-title').html(title);
jQuery('#$id').kbModalAjax({
selector: $(this),
url: bs_url,
Expand Down Expand Up @@ -309,4 +310,12 @@ private function _isBs4()
return $this->bootstrapVersion === self::BOOTSTRAP_VERSION_4;
}

/**
* @return bool
*/
private function _isBs5()
{
return $this->bootstrapVersion === self::BOOTSTRAP_VERSION_5;
}

}

0 comments on commit 9a86ed5

Please sign in to comment.