diff --git a/dist/js/dropify.js b/dist/js/dropify.js index d7c3d4d..1fb8e2e 100644 --- a/dist/js/dropify.js +++ b/dist/js/dropify.js @@ -207,7 +207,7 @@ Dropify.prototype.readFile = function(input) image.onload = function() { _this.setFileDimensions(this.width, this.height); _this.validateImage(); - _this.input.trigger(eventFileReady, [true, srcBase64]); + _this.input.trigger(eventFileReady, [_this.errorsEvent.errors.length === 0, srcBase64]); }; }.bind(this); diff --git a/useage.md b/useage.md new file mode 100644 index 0000000..08094ed --- /dev/null +++ b/useage.md @@ -0,0 +1,58 @@ +html: + +```html +
+``` + + + +js: + +```javascript + $('#avatarBtn').click(function() { + $("#avatarFile").trigger("click"); + }); + var drEvent = $('#avatarFile').dropify(); + drEvent.on('dropify.fileReady', function(event, previewable, src){ + if(previewable) { + // 提交表单 + $(this).closest('form').submit(); + } else { + dialog('图片格式有问题,请重新选择'); + } + }); + + // 监听表单提交动作 + $('#avatarForm').ajaxForm({ + success: function(responseText, statusText) { + if (responseText === 'ok') { + tip('头像修改成功'); + console.log($('#avatar-img')); + $('#avatar-img').attr('src','${ctxPath }/home/profile/avatar.png?'+Math.random()); + } else { + dialog(responseText); + } + } + }); +``` + + + +**注意:** + +> 这里添加了`dropify.fileReady`作为回调事件,`previewable`代表是否可以预览,`false`代表出现了错误,所以不能预览,建议`previewable==false`时不要提交表单操作。 \ No newline at end of file