Skip to content

Commit

Permalink
attribute部分重写
Browse files Browse the repository at this point in the history
  • Loading branch information
EVA09 committed Apr 27, 2020
1 parent 0beaae1 commit fddfccb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
8 changes: 3 additions & 5 deletions resources/views/cropper.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
@include('admin::form.error')
<div class="btn btn-info pull-left cropper-btn">{{ trans('admin_cropper.choose') }}</div>
@include('admin::form.help-block')
<input class="cropper-file" type="file" accept="image/*"/>
<input class="cropper-file" type="file" accept="image/*" {!! $attributes !!}/>
<!-- <img class="cropper-img" {!! empty($value) ? '' : 'src="'.old($column, $value).'"' !!}> -->
<img class="cropper-img" {!! empty($value) ? '' : 'src="'.$preview.'"' !!}>
<input class="cropper-input" name="{{$name}}" value="{{ old($column, $value) }}" {!! $attributes !!} />

<input class="cropper-input" name="{{$name}}" value="{{ old($column, $value) }}"/>
</div>
</div>

</div>
13 changes: 5 additions & 8 deletions src/Crop.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ function getMIME(url)
}
}
function cropper(imgSrc,cropperFileE,w,h)
function cropper(imgSrc,cropperFileE)
{
var w = $(cropperFileE).attr('data-w');
var h = $(cropperFileE).attr('data-h');
var cropperImg = '<div id="cropping-div"><img id="cropping-img" src="'+imgSrc+'"><\/div>';
//生成弹层模块
layer.open({
Expand Down Expand Up @@ -193,9 +195,6 @@ function cropper(imgSrc,cropperFileE,w,h)
//在input file内容改变的时候触发事件
$('form').on('change','.cropper-file',function(fileE){
var w = $(this).attr('data-w');
var h = $(this).attr('data-h');
//获取input file的files文件数组;
//这边默认只能选一个,但是存放形式仍然是数组,所以取第一个元素使用[0];
var file = $(this)[0].files[0];
Expand All @@ -208,7 +207,7 @@ function cropper(imgSrc,cropperFileE,w,h)
//选择所要显示图片的img,要赋值给img的src就是e中target下result里面的base64编码格式的地址
$(this).nextAll('.cropper-img').attr('src',e.target.result);
//调取剪切函数(内部包含了一个弹出框)
cropper(e.target.result,$(fileE.target),w,h);
cropper(e.target.result,$(fileE.target));
//向后两轮定位到隐藏起来的输入框体
$(this).nextAll('.cropper-input').val(e.target.result);
};
Expand All @@ -217,9 +216,7 @@ function cropper(imgSrc,cropperFileE,w,h)
//点击图片触发弹层
$('form').on('click','.cropper-img',function(){
var w = $(this).attr('data-w');
var h = $(this).attr('data-h');
cropper($(this).attr('src'),$(this).prevAll('.cropper-file'),w,h);
cropper($(this).attr('src'),$(this).prevAll('.cropper-file'));
return false;
});
Expand Down

0 comments on commit fddfccb

Please sign in to comment.