Skip to content

Commit

Permalink
Updates to release v1.8.2 - fixes #52 & fixes #53
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Jan 10, 2016
1 parent 9e50c30 commit 9a9421e
Show file tree
Hide file tree
Showing 18 changed files with 74 additions and 33 deletions.
2 changes: 1 addition & 1 deletion AnimateAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion AssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
7 changes: 7 additions & 0 deletions CHANGE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log: `yii2-krajee-base`
==============================

## Version 1.8.2

**Date:** 10-Jan-2016

- (enh #52): Enhance widget trait for better PJAX initialization.
- (enh #53): New widget property `pluginDestroyJs` for destroying plugin before initialization

## Version 1.8.1

**Date:** 27-Dec-2015
Expand Down
2 changes: 1 addition & 1 deletion Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
7 changes: 4 additions & 3 deletions Html5Input.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down Expand Up @@ -140,7 +140,7 @@ protected function renderInput()
Html::addCssClass($this->options, 'form-control');
$size = isset($this->size) ? ' input-group-' . $this->size : '';
Html::addCssClass($this->containerOptions, 'input-group input-group-html5' . $size);
if (isset($this->width) && ((int) $this->width > 0)) {
if (isset($this->width) && ((int)$this->width > 0)) {
Html::addCssStyle($this->html5Container, 'width:' . $this->width);
}
Html::addCssClass($this->html5Container, 'input-group-addon addon-' . $this->type);
Expand Down Expand Up @@ -192,7 +192,8 @@ protected static function getAddonContent($addon)

/**
* Gets the HTML5 input
* return string
*
* @return string
*/
protected function getHtml5Input()
{
Expand Down
2 changes: 1 addition & 1 deletion Html5InputAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @package yii2-krajee-base
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
10 changes: 8 additions & 2 deletions InputWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down Expand Up @@ -46,6 +46,11 @@ class InputWidget extends \yii\widgets\InputWidget
*/
public $readonly = false;

/**
* @var string the javascript that will be used to destroy the jQuery plugin
*/
public $pluginDestroyJs;

/**
* @var mixed show loading indicator while plugin loads
*/
Expand Down Expand Up @@ -78,7 +83,7 @@ class InputWidget extends \yii\widgets\InputWidget
* ~~~
*/
public $pluginEvents = [];

/**
* @var string a pjax container identifier if applicable inside which the widget will be rendered.
* If this is set, the widget will automatically reinitialize on pjax completion.
Expand Down Expand Up @@ -139,6 +144,7 @@ class InputWidget extends \yii\widgets\InputWidget
public function init()
{
parent::init();
$this->initDestroyJs();
$this->initInputWidget();
}

Expand Down
4 changes: 2 additions & 2 deletions Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand All @@ -13,7 +13,7 @@
* Base module class for Krajee extensions
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.8.1
* @since 1.8.2
*/
class Module extends \yii\base\Module
{
Expand Down
2 changes: 1 addition & 1 deletion PluginAssetBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ This is a base library with set of foundation classes and components used by all
To ensure a leaner code base / foundation component for use in all Krajee extensions (e.g. yii2-widgets, yii2-datecontrol, yii2-grid, yii2-dynagrid etc.). This should allow most developers to plug and play components only they need, without needing the complete suite of widgets. For example, this mitigates [this issue](https://github.com/kartik-v/yii2-grid/issues/123).

## Latest Release
The latest version of the extension is v1.8.1. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-krajee-base/blob/master/CHANGE.md) for details.
The latest version of the extension is v1.8.2. Refer the [CHANGE LOG](https://github.com/kartik-v/yii2-krajee-base/blob/master/CHANGE.md) for details.

## Extension Classes

Expand Down
4 changes: 2 additions & 2 deletions TranslationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand All @@ -17,7 +17,7 @@
* @property array $i18n
*
* @author Kartik Visweswaran <[email protected]>
* @since 1.8.1
* @since 1.8.2
*/
trait TranslationTrait
{
Expand Down
18 changes: 12 additions & 6 deletions Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand All @@ -27,6 +27,11 @@ class Widget extends \yii\base\Widget
*/
public $options = [];

/**
* @var string the javascript that will be used to destroy the jQuery plugin
*/
public $pluginDestroyJs;

/**
* @var array widget plugin options
*/
Expand All @@ -43,6 +48,11 @@ class Widget extends \yii\base\Widget
*/
public $pluginEvents = [];

/**
* @var string the name of the jQuery plugin
*/
public $pluginName = '';

/**
* @var string a pjax container identifier if applicable inside which the widget will be rendered. If this is set,
* the widget will automatically reinitialize on pjax completion.
Expand All @@ -59,11 +69,6 @@ class Widget extends \yii\base\Widget
*/
protected $_msgCat = '';

/**
* @var string the name of the jQuery plugin
*/
protected $_pluginName;

/**
* @var string the hashed global variable name storing the pluginOptions
*/
Expand All @@ -88,5 +93,6 @@ public function init()
if (empty($this->options['id'])) {
$this->options['id'] = $this->getId();
}
$this->initDestroyJs();
}
}
2 changes: 1 addition & 1 deletion WidgetAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand Down
35 changes: 28 additions & 7 deletions WidgetTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @package yii2-krajee-base
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*/

namespace kartik\base;
Expand All @@ -16,6 +16,8 @@
/**
* Trait used for Krajee widgets.
*
* @property string $pluginName
* @property string $pluginDestroyJs
* @property array $options
* @property array $pluginOptions
* @property array $_encOptions
Expand All @@ -42,6 +44,24 @@ protected function setDataVar($name)
$this->_dataVar = "data-krajee-{$name}";
}


/**
* Generates the `pluginDestroyJs` if not set
*/
protected function initDestroyJs()
{
if (isset($this->pluginDestroyJs)) {
return;
}
if (empty($this->pluginName)) {
$this->pluginDestroyJs = '';
return;
}
$id = "jQuery('#" . $this->options['id'] . "')";
$plugin = $this->pluginName;
$this->pluginDestroyJs = "if ({$id}.data('{$this->pluginName}')) { {$id}.{$plugin}('destroy'); }";
}

/**
* Adds an asset to the view
*
Expand Down Expand Up @@ -127,7 +147,7 @@ protected function getPluginScript($name, $element = null, $callback = null, $ca
$script .= "{$id}.on('{$event}', {$function});\n";
}
}
return $script;
return $this->pluginDestroyJs . "\n" . $script;
}

/**
Expand All @@ -148,7 +168,7 @@ protected function registerPlugin($name, $element = null, $callback = null, $cal
* Registers a JS code block for the widget.
*
* @param string $js the JS code block to be registered
* @param integer $position the position at which the JS script tag should be inserted in a page. The possible
* @param integer $pos the position at which the JS script tag should be inserted in a page. The possible
* values are:
* - [[POS_HEAD]]: in the head section
* - [[POS_BEGIN]]: at the beginning of the body section
Expand All @@ -160,16 +180,17 @@ protected function registerPlugin($name, $element = null, $callback = null, $cal
* @param string $key the key that identifies the JS code block. If null, it will use $js as the key. If two JS
* code blocks are registered with the same key, the latter will overwrite the former.
*/
public function registerWidgetJs($js, $position = View::POS_READY, $key = null)
public function registerWidgetJs($js, $pos = View::POS_READY, $key = null)
{
if (empty($js)) {
return;
}
$view = $this->getView();
$view->registerJs($js, $position, $key);
if (!empty($this->pjaxContainerId) && ($position === View::POS_LOAD || $position === View::POS_READY)) {
$view->registerJs($js, $pos, $key);
if (!empty($this->pjaxContainerId) && ($pos === View::POS_LOAD || $pos === View::POS_READY)) {
$pjax = 'jQuery("#' . $this->pjaxContainerId . '")';
$view->registerJs("{$pjax}.on('pjax:complete',function(){ {$js} });");
$evComplete = 'pjax:complete.' . hash('crc32', $js);
$view->registerJs("{$pjax}.off('{$evComplete}').on('{$evComplete}',function(){ {$js} });");
}
}
}
2 changes: 1 addition & 1 deletion assets/css/html5input.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @subpackage yii2-widget-activeform
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*
* HTML 5 input styling for Twitter Bootstrap 3.0
* Covers color and range inputs
Expand Down
2 changes: 1 addition & 1 deletion assets/css/html5input.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion assets/css/kv-widgets.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @subpackage yii2-widget-activeform
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*
* Common CSS file for all kartik\widgets.
*
Expand Down
2 changes: 1 addition & 1 deletion assets/css/kv-widgets.min.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* @subpackage yii2-widget-activeform
* @author Kartik Visweswaran <[email protected]>
* @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
* @version 1.8.1
* @version 1.8.2
*
* Common CSS file for all kartik\widgets.
*
Expand Down

0 comments on commit 9a9421e

Please sign in to comment.