Skip to content

Commit

Permalink
Updates to release v1.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
kartik-v committed Sep 7, 2018
1 parent f34ed0f commit 11ee1be
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
4 changes: 3 additions & 1 deletion CHANGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ Change Log: `yii2-widget-fileinput`

## Version 1.0.7

**Date:** 26-Jul-2018
**Date:** 07-Sep-2018

- Updates to support Bootstrap 4.x.
- (kartik-v/yii2-krajee-base#94): Refactor code and consolidate / optimize properties within traits.
- Reorganize relevant code in "src" directory.
- Optimize asset bundles.
- (enh #134): Add Slovak Translations.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
],
"require": {
"kartik-v/yii2-krajee-base": "~1.7",
"kartik-v/yii2-krajee-base": ">=1.9",
"kartik-v/bootstrap-fileinput": "~4.4"
},
"autoload": {
Expand Down
35 changes: 23 additions & 12 deletions src/FileInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use kartik\base\TranslationTrait;

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

/**
* @var array the internalization configuration for this widget
*/
public $i18n = [];

/**
* @inheritdoc
*/
Expand All @@ -76,14 +71,25 @@ class FileInput extends InputWidget
/**
* @var array the list of inbuilt themes
*/
private static $_themes = ['fa', 'gly', 'explorer', 'explorer-fa'];
protected static $_themes = ['fa', 'fas', 'gly', 'explorer', 'explorer-fa', 'explorer-fas'];

/**
* @inheritdoc
* @throws \ReflectionException
* @throws \yii\base\InvalidConfigException
*/
public function run()
{
return $this->initWidget();
}

/**
* @var array initialize the FileInput widget
* Initializes widget
* @throws \ReflectionException
* @throws \yii\base\InvalidConfigException
*/
public function init()
protected function initWidget()
{
parent::init();
$this->_msgCat = 'fileinput';
$this->initI18N(__DIR__);
$this->initLanguage();
Expand All @@ -109,7 +115,7 @@ public function init()
$content = Html::tag('div', $message, $this->messageOptions) . "<script>{$script};</script>";
$input .= "\n" . $this->validateIE($content);
}
echo $input;
return $input;
}

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

/**
* Registers the asset bundle and locale
* @throws \yii\base\InvalidConfigException
*/
public function registerAssetBundle()
{
Expand All @@ -136,6 +143,9 @@ public function registerAssetBundle()
if ($this->resizeImages || $this->autoOrientImages) {
PiExifAsset::register($view);
}
if (empty($this->pluginOptions['theme']) && $this->isBs4()) {
$this->pluginOptions['theme'] = 'fas';
}
$theme = ArrayHelper::getValue($this->pluginOptions, 'theme');
if (!empty($theme) && in_array($theme, self::$_themes)) {
FileInputThemeAsset::register($view)->addTheme($theme);
Expand All @@ -152,6 +162,7 @@ public function registerAssetBundle()

/**
* Registers the needed assets
* @throws \yii\base\InvalidConfigException
*/
public function registerAssets()
{
Expand Down
10 changes: 6 additions & 4 deletions src/FileInputThemeAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace kartik\file;

use yii\web\AssetBundle;
use Yii;

/**
Expand All @@ -28,28 +29,29 @@ class FileInputThemeAsset extends BaseAsset
* Add file input theme file
*
* @param string $theme the theme file name
* @return AssetBundle
*/
public function addTheme($theme)
{
$file = YII_DEBUG ? "theme.js" : "theme.min.js";
if ($this->checkExists("themes/{$theme}/{$file}")) {
$this->js[] = "themes/{$theme}/{$file}";
}
}
$file = YII_DEBUG ? "theme.css" : "theme.min.css";
if ($this->checkExists("themes/{$theme}/{$file}")) {
$this->css[] = "themes/{$theme}/{$file}";
}
}
return $this;
}

/**
* Check if file exists in path provided
*
* @param string $path the file path
*
* @return boolean
*/
protected function checkExists($path)
protected function checkExists($path)
{
return file_exists(Yii::getAlias($this->sourcePath . '/' . $path));
}
Expand Down

0 comments on commit 11ee1be

Please sign in to comment.