Skip to content

Commit 11ee1be

Browse files
committed
Updates to release v1.0.7
1 parent f34ed0f commit 11ee1be

File tree

4 files changed

+33
-18
lines changed

4 files changed

+33
-18
lines changed

CHANGE.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ Change Log: `yii2-widget-fileinput`
33

44
## Version 1.0.7
55

6-
**Date:** 26-Jul-2018
6+
**Date:** 07-Sep-2018
77

8+
- Updates to support Bootstrap 4.x.
9+
- (kartik-v/yii2-krajee-base#94): Refactor code and consolidate / optimize properties within traits.
810
- Reorganize relevant code in "src" directory.
911
- Optimize asset bundles.
1012
- (enh #134): Add Slovak Translations.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
}
1414
],
1515
"require": {
16-
"kartik-v/yii2-krajee-base": "~1.7",
16+
"kartik-v/yii2-krajee-base": ">=1.9",
1717
"kartik-v/bootstrap-fileinput": "~4.4"
1818
},
1919
"autoload": {

src/FileInput.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
use kartik\base\TranslationTrait;
1717

1818
/**
19-
* Wrapper for the Bootstrap FileInput JQuery Plugin by Krajee. The FileInput widget is styled for Bootstrap 3.x
20-
* & 4.x with ability to multiple file selection and preview, format button styles and inputs. Runs on all modern
19+
* Wrapper for the Bootstrap FileInput JQuery Plugin by Krajee. The FileInput widget is styled for Bootstrap 3.x
20+
* & 4.x with ability to multiple file selection and preview, format button styles and inputs. Runs on all modern
2121
* browsers supporting HTML5 File Inputs and File Processing API. For browser versions IE9 and below, this widget
2222
* will gracefully degrade to a native HTML file input.
2323
*
@@ -63,11 +63,6 @@ class FileInput extends InputWidget
6363
*/
6464
public $messageOptions = ['class' => 'alert alert-warning'];
6565

66-
/**
67-
* @var array the internalization configuration for this widget
68-
*/
69-
public $i18n = [];
70-
7166
/**
7267
* @inheritdoc
7368
*/
@@ -76,14 +71,25 @@ class FileInput extends InputWidget
7671
/**
7772
* @var array the list of inbuilt themes
7873
*/
79-
private static $_themes = ['fa', 'gly', 'explorer', 'explorer-fa'];
74+
protected static $_themes = ['fa', 'fas', 'gly', 'explorer', 'explorer-fa', 'explorer-fas'];
75+
76+
/**
77+
* @inheritdoc
78+
* @throws \ReflectionException
79+
* @throws \yii\base\InvalidConfigException
80+
*/
81+
public function run()
82+
{
83+
return $this->initWidget();
84+
}
8085

8186
/**
82-
* @var array initialize the FileInput widget
87+
* Initializes widget
88+
* @throws \ReflectionException
89+
* @throws \yii\base\InvalidConfigException
8390
*/
84-
public function init()
91+
protected function initWidget()
8592
{
86-
parent::init();
8793
$this->_msgCat = 'fileinput';
8894
$this->initI18N(__DIR__);
8995
$this->initLanguage();
@@ -109,7 +115,7 @@ public function init()
109115
$content = Html::tag('div', $message, $this->messageOptions) . "<script>{$script};</script>";
110116
$input .= "\n" . $this->validateIE($content);
111117
}
112-
echo $input;
118+
return $input;
113119
}
114120

115121
/**
@@ -127,6 +133,7 @@ protected function validateIE($content, $validation = 'lt IE 10')
127133

128134
/**
129135
* Registers the asset bundle and locale
136+
* @throws \yii\base\InvalidConfigException
130137
*/
131138
public function registerAssetBundle()
132139
{
@@ -136,6 +143,9 @@ public function registerAssetBundle()
136143
if ($this->resizeImages || $this->autoOrientImages) {
137144
PiExifAsset::register($view);
138145
}
146+
if (empty($this->pluginOptions['theme']) && $this->isBs4()) {
147+
$this->pluginOptions['theme'] = 'fas';
148+
}
139149
$theme = ArrayHelper::getValue($this->pluginOptions, 'theme');
140150
if (!empty($theme) && in_array($theme, self::$_themes)) {
141151
FileInputThemeAsset::register($view)->addTheme($theme);
@@ -152,6 +162,7 @@ public function registerAssetBundle()
152162

153163
/**
154164
* Registers the needed assets
165+
* @throws \yii\base\InvalidConfigException
155166
*/
156167
public function registerAssets()
157168
{

src/FileInputThemeAsset.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace kartik\file;
1111

12+
use yii\web\AssetBundle;
1213
use Yii;
1314

1415
/**
@@ -28,28 +29,29 @@ class FileInputThemeAsset extends BaseAsset
2829
* Add file input theme file
2930
*
3031
* @param string $theme the theme file name
32+
* @return AssetBundle
3133
*/
3234
public function addTheme($theme)
3335
{
3436
$file = YII_DEBUG ? "theme.js" : "theme.min.js";
3537
if ($this->checkExists("themes/{$theme}/{$file}")) {
3638
$this->js[] = "themes/{$theme}/{$file}";
37-
}
39+
}
3840
$file = YII_DEBUG ? "theme.css" : "theme.min.css";
3941
if ($this->checkExists("themes/{$theme}/{$file}")) {
4042
$this->css[] = "themes/{$theme}/{$file}";
41-
}
43+
}
4244
return $this;
4345
}
44-
46+
4547
/**
4648
* Check if file exists in path provided
4749
*
4850
* @param string $path the file path
4951
*
5052
* @return boolean
5153
*/
52-
protected function checkExists($path)
54+
protected function checkExists($path)
5355
{
5456
return file_exists(Yii::getAlias($this->sourcePath . '/' . $path));
5557
}

0 commit comments

Comments
 (0)