Skip to content

Commit

Permalink
Merge pull request #2 from elementallos/master
Browse files Browse the repository at this point in the history
Fixed JS bug + implemented uniqueness in widget ID
  • Loading branch information
liviuk2 authored Jul 5, 2023
2 parents c30c2a7 + ae7dc06 commit 6eaea77
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# CHANGELOG YII2 FULLCALENDAR

6.0.1-dev
----------------

- Implemented uniqueness for widget id
- Globalization of the JS fullcalendar variable

6.0.0 2023-07-04
----------------

- Initial release for fullcalendar v6 assets
21 changes: 17 additions & 4 deletions yii2fullcalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
namespace yii2fullcalendar;

use Yii;
use yii\helpers\Console;
use yii\helpers\Inflector;
use yii\web\View;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
Expand Down Expand Up @@ -172,21 +174,31 @@ class yii2fullcalendar extends elWidget
*/
public $select = "";

/**
* The global variable name for the widget (used for update/filter calendar events)
* @var string valid JS variable name
*/
public $jsGlobalVar;

/**
* Initializes the widget.
* If you override this method, make sure you call the parent implementation first.
*/
public function init()
{
//checks for the element id
$this->setId(null);
if (!isset($this->options['id'])) {
$this->options['id'] = $this->getId();
$this->options['id'] = 'CalendarTasks';
}
//checks for the class
if (!isset($this->options['class'])) {
$this->options['class'] = 'fullcalendar';
}

$this->jsGlobalVar = Inflector::id2camel($this->options['id']) . '_' . $this->id;
$this->options['id'] = $this->jsGlobalVar;
$this->view->registerJsVar($this->jsGlobalVar, 'undefined');
parent::init();
}

Expand Down Expand Up @@ -259,9 +271,9 @@ protected function registerPlugin()

$cleanOptions = $this->getClientOptions();
$js[] = <<<EOCALENDAR
var calendarEl = document.getElementById('$id');
var calendar = new FullCalendar.Calendar(calendarEl, $cleanOptions);
calendar.render();
let calendarEl = document.getElementById('$id');
$this->jsGlobalVar = new FullCalendar.Calendar(calendarEl, $cleanOptions);
$this->jsGlobalVar.render();
EOCALENDAR;

$view->registerJs(implode("\n", $js), View::POS_READY);
Expand Down Expand Up @@ -324,3 +336,4 @@ protected function getClientOptions()
return Json::encode($options);
}
}

0 comments on commit 6eaea77

Please sign in to comment.