Exemplo n.º 1
0
<?php

use yii\helpers\Html;
use yii\helpers\Url;
use yii\bootstrap\ActiveForm;
use app\models\ThumbnailForm;
use newerton\jcrop\jCropAsset;
use yii\web\jQueryAsset;
$thumbnail = new ThumbnailForm();
jCropAsset::register($this);
$this->registerJs('
function imageList(){
    jQuery("#image-list").empty();  
    $.getJSON("' . Url::toRoute(['upload-ajax', 'id' => $model->id]) . '", function(json){  
        $(json).each(function(i, item) {
            $("<li></li>").html("<a href=\\"#\\"><img src=\\""+item["path"]+"\\" width=\\"190\\" class=\\"img-thumbnail\\"></a>").appendTo("#image-list");
        });
    });  
};
jQuery("#choose-thumbnail").on("show.bs.modal", function (e) {
    imageList(); 
});
var jcrop_api;


function showCoords(c)
{
  $("#thumbnailform-x1").val(c.x);
  $("#thumbnailform-y1").val(c.y);
  $("#thumbnailform-x2").val(c.x2);
  $("#thumbnailform-y2").val(c.y2);
Exemplo n.º 2
0
 /**
  * Registers required script for the plugin to work as DatePicker
  */
 public function registerClientScript($registerJs = true)
 {
     $view = $this->getView();
     jCropAsset::register($view);
     $this->jsOptions['onChange'] = new JsExpression("function(c) {ejcrop_getCoords(c,'{$this->id}'); ejcrop_showThumb(c,'{$this->id}');}");
     $this->jsOptions['ajaxUrl'] = $this->ajaxUrl;
     $this->jsOptions['ajaxParams'] = $this->ajaxParams;
     $options = !empty($this->jsOptions) ? Json::encode($this->jsOptions) : '';
     if (!empty($this->buttons)) {
         $js = "ejcrop_initWithButtons('{$this->id}', {$options});";
     } else {
         $js = "jQuery('#{$this->id}').Jcrop({$options});";
     }
     if ($registerJs) {
         $view->registerJs($js);
     }
 }