Skip to content
This repository has been archived by the owner on Jun 18, 2021. It is now read-only.

Commit

Permalink
Merge pull request #38 from bupy7/dev
Browse files Browse the repository at this point in the history
v5.0.0
  • Loading branch information
bupy7 authored May 12, 2017
2 parents d81259f + 1fa6faa commit fde049d
Show file tree
Hide file tree
Showing 13 changed files with 426 additions and 317 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
yii2-widget-cropbox
===================

v? [?]
------
v5.0.0 [2017-05-07]
-------------------

- Fixed headers style of markdown. (bryant1410)
- Removed `bupy7\cropbox\Cropbox` and `bupy7\cropbox\MouseWheelAsset` class.
- Added `bupy7\cropbox\CropboxWidget` class.
- Removed `assets` directory.
- Replaced `bower-asset/jq-cropbox` to `bower-asset/js-cropbox` dependency.
- Added jQuery wrapper for `js-cropbox` extension.
- Rewrite `README.md`.

v4.1.2 [2016-09-28]
-------------------
Expand Down
159 changes: 0 additions & 159 deletions Cropbox.php

This file was deleted.

31 changes: 0 additions & 31 deletions CropboxAsset.php

This file was deleted.

137 changes: 137 additions & 0 deletions CropboxWidget.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?php

namespace bupy7\cropbox;

use Yii;
use yii\widgets\InputWidget;
use yii\helpers\Html;
use yii\helpers\Json;
use yii\web\View;
use bupy7\cropbox\assets\WidgetAsset;

/**
* @author Vasilij "BuPy7" Belosludcev http://mihaly4.ru
* @since 5.0.0
*/
class CropboxWidget extends InputWidget
{
/**
* @var string Attribute name that content information about cropped images.
*/
public $croppedDataAttribute;
/**
* @var string Input name that content information about cropped images.
*/
public $croppedDataName;
/**
* @var string Input value with information about cropped images.
*/
public $croppedDataValue;
/**
* @var array Options of plugin:
* - (array) variants: Variants of cropping image. More info: https://github.com/bupy7/js-cropbox#object-variants
* - (array) [selectors]: CSS selectors for attach events of cropbox.
* # (string) fileInput
* # (string) btnCrop
* # (string) btnReset
* # (string) btnScaleIn
* # (string) btnScaleOut
* # (string) croppedContainer
* # (string) croppedDataInput
* # (string) messageContainer
* - (array) [messages]: Alert messages for each a variant.
*/
public $pluginOptions = [];
/**
* @var string URL to image for display before upload to original URL.
*/
public $originalImageUrl;
/**
* @var array URL to images for display before upload to preview URL.
*
* Example:
* [
* '/uploads/1.png',
* '/uploads/2.png',
* ];
*
* or simply string to image.
*/
public $croppedImagesUrl;
/**
* @var string Path to view of cropbox field. Example: '@app/path/to/view'
*/
public $pathToView = 'field';

public function init()
{
parent::init();
WidgetAsset::register($this->view);
$this->registerTranslations();
$this->configuration();
}

public function run()
{
$pluginOptions = Json::encode($this->pluginOptions);
$this->view->registerJs("$('#{$this->id} .plugin').cropbox({$pluginOptions});", View::POS_READY);
return $this->render($this->pathToView, [
'hasModel' => $this->hasModel(),
]);
}

/**
* Translates a message to the specified language.
*
* @param string $message the message to be translated.
* @param array $params the parameters that will be used to replace the corresponding placeholders in the message.
* @param string $language the language code (e.g. `en-US`, `en`). If this is null, the current of application
* language.
* @return string
*/
public static function t($message, $params = [], $language = null)
{
return Yii::t('bupy7/cropbox', $message, $params, $language);
}

/**
* Registration of translation class.
*/
protected function registerTranslations()
{
Yii::$app->i18n->translations['bupy7/cropbox'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en',
'basePath' => '@bupy7/cropbox/messages',
'fileMap' => [
'bupy7/cropbox' => 'core.php',
],
];
}

/**
* Configuration the widget.
*/
protected function configuration()
{
$this->options = array_merge(['accept' => 'image/*'], $this->options);
$croppedDataInput = $this->croppedDataAttribute;
if ($this->hasModel()) {
$croppedDataInput = Html::getInputName($this->model, $croppedDataInput);
} else {
$croppedDataInput = $this->croppedDataName;
}
$this->pluginOptions = array_merge([
'selectors' => [
'fileInput' => sprintf('#%s input[type="file"]', $this->id),
'btnCrop' => sprintf('#%s .btn-crop', $this->id),
'btnReset' => sprintf('#%s .btn-reset', $this->id),
'btnScaleIn' => sprintf('#%s .btn-scale-in', $this->id),
'btnScaleOut' => sprintf('#%s .btn-scale-out', $this->id),
'croppedContainer' => sprintf('#%s .cropped-images-cropbox', $this->id),
'croppedDataInput' => sprintf('#%s input[name="%s"]', $this->id, $croppedDataInput),
'messageContainer' => sprintf('#%s .message-container-cropbox', $this->id),
],
], $this->pluginOptions);
}
}
25 changes: 0 additions & 25 deletions MouseWheelAsset.php

This file was deleted.

Loading

0 comments on commit fde049d

Please sign in to comment.