-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #94: Refactor code and consolidate / optimize properties within t…
…raits
- Loading branch information
Showing
8 changed files
with
160 additions
and
344 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,15 +16,42 @@ | |
/** | ||
* BootstrapTrait includes bootstrap library init and parsing methods | ||
* | ||
* @property string $bsVersion | ||
* @property string $_defaultIconPrefix | ||
* @property string $_defaultBtnCss | ||
* @property bool $_isBs4 | ||
* | ||
* @author Kartik Visweswaran <[email protected]> | ||
*/ | ||
trait BootstrapTrait | ||
{ | ||
/** | ||
* @var int|string the bootstrap library version. | ||
* | ||
* To use with bootstrap 3 - you can set this to any string starting with 3 (e.g. `3` or `3.3.7` or `3.x`) | ||
* To use with bootstrap 4 - you can set this to any string starting with 4 (e.g. `4` or `4.1.1` or `4.x`) | ||
* | ||
* This property can be set up globally in Yii application params in your Yii2 application config file. | ||
* | ||
* For example: | ||
* `Yii::$app->params['bsVersion'] = '4.x'` to use with Bootstrap 4.x globally | ||
* | ||
* If this property is set, this setting will override the `Yii::$app->params['bsVersion']`. If this is not set, and | ||
* `Yii::$app->params['bsVersion']` is also not set, this will default to `3.x` (Bootstrap 3.x version). | ||
*/ | ||
public $bsVersion; | ||
|
||
/** | ||
* @var string default icon CSS prefix | ||
*/ | ||
protected $_defaultIconPrefix; | ||
|
||
/** | ||
* @var string default bootstrap button CSS | ||
*/ | ||
protected $_defaultBtnCss; | ||
|
||
/** | ||
* @var bool flag to detect whether bootstrap 4.x version is set | ||
*/ | ||
protected $_isBs4; | ||
|
||
/** | ||
* Initializes bootstrap versions for the widgets and asset bundles. | ||
* Sets the [[_isBs4]] flag by parsing [[bsVersion]] | ||
|
@@ -107,4 +134,4 @@ protected static function isSameVersion($ver1, $ver2) | |
} | ||
return static::parseVer($ver1) === static::parseVer($ver2); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ | |
use yii\helpers\FormatConverter; | ||
use yii\helpers\Html; | ||
use yii\helpers\ArrayHelper; | ||
use yii\web\View; | ||
use yii\widgets\InputWidget as YiiInputWidget; | ||
|
||
/** | ||
|
@@ -33,6 +32,22 @@ | |
* ]) ?> | ||
* ``` | ||
* | ||
* @property string|int $bsVersion | ||
* @property bool $enablePopStateFix | ||
* @property string $pluginDestroyJs | ||
* @property array $pluginEvents | ||
* @property array $pluginOptions | ||
* @property array $defaultPluginOptions | ||
* @property array $defaultOptions | ||
* @property array $i18n | ||
* @property string $_defaultIconPrefix | ||
* @property string $_defaultBtnCss | ||
* @property integer $hashVarLoadPosition | ||
* @property string $_hashVar | ||
* @property string $_dataVar | ||
* @property array $_encOptions | ||
* @property bool $_isBs4 | ||
* | ||
* @author Kartik Visweswaran <[email protected]> | ||
* @since 1.0 | ||
*/ | ||
|
@@ -44,28 +59,9 @@ class InputWidget extends YiiInputWidget | |
const LOAD_PROGRESS = '<div class="kv-plugin-loading"> </div>'; | ||
|
||
/** | ||
* @var int|string the bootstrap library version. | ||
* | ||
* To use with bootstrap 3 - you can set this to any string starting with 3 (e.g. `3` or `3.3.7` or `3.x`) | ||
* To use with bootstrap 4 - you can set this to any string starting with 4 (e.g. `4` or `4.1.1` or `4.x`) | ||
* | ||
* This property can be set up globally in Yii application params in your Yii2 application config file. | ||
* | ||
* For example: | ||
* `Yii::$app->params['bsVersion'] = '4.x'` to use with Bootstrap 4.x globally | ||
* | ||
* If this property is set, this setting will override the `Yii::$app->params['bsVersion']`. If this is not set, and | ||
* `Yii::$app->params['bsVersion']` is also not set, this will default to `3.x` (Bootstrap 3.x version). | ||
*/ | ||
public $bsVersion; | ||
|
||
/** | ||
* @var string the module identifier if this widget is part of a module. If not set, the module identifier will | ||
* be auto derived based on the \yii\base\Module::getInstance method. This can be useful, if you are setting | ||
* multiple module identifiers for the same module in your Yii configuration file. To specify children or grand | ||
* children modules you can specify the module identifiers relative to the parent module (e.g. `admin/content`). | ||
* @var string the name of the jQuery plugin. | ||
*/ | ||
public $moduleId; | ||
public $pluginName = ''; | ||
|
||
/** | ||
* @var string the language configuration (e.g. 'fr-FR', 'zh-CN'). The format for the language/locale is | ||
|
@@ -85,11 +81,6 @@ class InputWidget extends YiiInputWidget | |
*/ | ||
public $readonly = false; | ||
|
||
/** | ||
* @var string the javascript that will be used to destroy the jQuery plugin | ||
*/ | ||
public $pluginDestroyJs; | ||
|
||
/** | ||
* @var boolean show loading indicator while plugin loads | ||
*/ | ||
|
@@ -100,52 +91,6 @@ class InputWidget extends YiiInputWidget | |
*/ | ||
public $data = []; | ||
|
||
/** | ||
* @var string the name of the jQuery plugin. | ||
*/ | ||
public $pluginName = ''; | ||
|
||
/** | ||
* @var array the default HTML attributes for the input tag. | ||
* @see \yii\helpers\Html::renderTagAttributes() for details on how attributes are being rendered. | ||
*/ | ||
public $defaultOptions = []; | ||
|
||
/** | ||
* @var array widget plugin options. | ||
*/ | ||
public $defaultPluginOptions = []; | ||
|
||
/** | ||
* @var array widget plugin options. | ||
*/ | ||
public $pluginOptions = []; | ||
|
||
/** | ||
* @var array widget JQuery events. You must define events in `event-name => event-function` format. For example: | ||
* | ||
* ~~~ | ||
* pluginEvents = [ | ||
* 'change' => 'function() { log("change"); }', | ||
* 'open' => 'function() { log("open"); }', | ||
* ]; | ||
* ~~~ | ||
*/ | ||
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 render completion. | ||
* | ||
* Note: You can set this to the HTML id attribute of any PJAX parent container element that encloses the widget. | ||
*/ | ||
public $pjaxContainerId; | ||
|
||
/** | ||
* @var boolean enable pop state fix for pjax container on press of browser back & forward buttons. | ||
*/ | ||
public $enablePopStateFix = false; | ||
|
||
/** | ||
* @var boolean whether the widget should automatically format the date from the PHP DateTime format to the | ||
* javascript/jquery plugin format. This is more applicable for widgets that manage date / time inputs. | ||
|
@@ -154,37 +99,6 @@ class InputWidget extends YiiInputWidget | |
*/ | ||
public $convertFormat = false; | ||
|
||
/** | ||
* @var integer the position where the client JS hash variables for the input widget will be loaded. | ||
* Defaults to `View::POS_HEAD`. This can be set to `View::POS_READY` for specific scenarios like when | ||
* rendering the widget via `renderAjax`. | ||
*/ | ||
public $hashVarLoadPosition = View::POS_HEAD; | ||
|
||
/** | ||
* @var array the the internalization configuration for this widget. | ||
* | ||
* @see [[\yii\i18n\I18N]] component for understanding the configuration details. | ||
*/ | ||
public $i18n = []; | ||
|
||
/** | ||
* @var string the HTML5 data variable name that will be used to store the Json encoded pluginOptions within the | ||
* element on which the jQuery plugin will be initialized. | ||
*/ | ||
protected $_dataVar; | ||
|
||
/** | ||
* @var string the generated hashed variable name that will store the JSON encoded pluginOptions in | ||
* [[View::POS_HEAD]]. | ||
*/ | ||
protected $_hashVar; | ||
|
||
/** | ||
* @var string the JSON encoded plugin options. | ||
*/ | ||
protected $_encOptions = ''; | ||
|
||
/** | ||
* @var string the indicator to be displayed while plugin is loading. | ||
*/ | ||
|
@@ -200,43 +114,23 @@ class InputWidget extends YiiInputWidget | |
*/ | ||
protected $_langFile = ''; | ||
|
||
/** | ||
* @var string translation message file category name for i18n. | ||
* | ||
* @see [[\yii\i18n\I18N]] | ||
*/ | ||
protected $_msgCat = ''; | ||
|
||
/** | ||
* @var string default icon CSS prefix | ||
*/ | ||
protected $_defaultIconPrefix; | ||
|
||
/** | ||
* @var string default bootstrap button CSS | ||
*/ | ||
protected $_defaultBtnCss; | ||
|
||
/** | ||
* @var bool flag to detect whether bootstrap 4.x version is set | ||
*/ | ||
protected $_isBs4; | ||
/** | ||
* @inheritdoc | ||
* @throws InvalidConfigException | ||
* @throws \ReflectionException | ||
*/ | ||
public function init() | ||
{ | ||
$this->initBsVersion(); | ||
parent::init(); | ||
$this->pluginOptions = ArrayHelper::merge($this->defaultPluginOptions, $this->pluginOptions); | ||
$this->options = ArrayHelper::merge($this->defaultOptions, $this->options); | ||
$this->mergeDefaultOptions(); | ||
$this->initDestroyJs(); | ||
$this->initInputWidget(); | ||
} | ||
|
||
/** | ||
* Initializes the input widget. | ||
* @throws \ReflectionException | ||
*/ | ||
protected function initInputWidget() | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,13 +16,25 @@ | |
/** | ||
* TranslationTrait manages methods for all translations used in Krajee extensions | ||
* | ||
* @property array $i18n | ||
* | ||
* @author Kartik Visweswaran <[email protected]> | ||
* @since 1.9.3 | ||
*/ | ||
trait TranslationTrait | ||
{ | ||
/** | ||
* @var array the the internalization configuration for this widget. | ||
* | ||
* @see [[\yii\i18n\I18N]] component for understanding the configuration details. | ||
*/ | ||
public $i18n = []; | ||
|
||
/** | ||
* @var string translation message file category name for i18n. | ||
* | ||
* @see [[\yii\i18n\I18N]] | ||
*/ | ||
protected $_msgCat = ''; | ||
|
||
/** | ||
* Yii i18n messages configuration for generating translations | ||
* | ||
|
Oops, something went wrong.