mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-09-12 06:51:38 +08:00
添加Metronic(作为LFS)
This commit is contained in:
39
frontend/static/js/common/imgPreview.js
Normal file
39
frontend/static/js/common/imgPreview.js
Normal file
@@ -0,0 +1,39 @@
|
||||
jQuery.fn.extend({
|
||||
imgPreview: function (opts) {
|
||||
var _self = this,
|
||||
_this = $(this);
|
||||
opts = jQuery.extend({
|
||||
id: "imgPreview",
|
||||
width: '100px',
|
||||
height: '100px',
|
||||
imgType: ["gif", "jpeg", "jpg", "bmp", "png"],
|
||||
callback: function () {}
|
||||
}, opts || {});
|
||||
$("#" + opts.id).css({
|
||||
'width': opts.width,
|
||||
'height': opts.height
|
||||
});
|
||||
_self.getObjectURL = function (file) {
|
||||
var url = null;
|
||||
if (window.createObjectURL != undefined) {
|
||||
url = window.createObjectURL(file);
|
||||
} else if (window.URL != undefined) {
|
||||
url = window.URL.createObjectURL(file);
|
||||
} else if (window.webkitURL != undefined) {
|
||||
url = window.webkitURL.createObjectURL(file);
|
||||
}
|
||||
return url;
|
||||
};
|
||||
_this.change(function () {
|
||||
if (this.value) {
|
||||
if (!RegExp("\.(" + opts.imgType.join("|") + ")$", "i").test(this.value.toLowerCase())) {
|
||||
alert("选择文件错误,图片类型必须是" + opts.imgType.join(",") + "中的一种");
|
||||
this.value = "";
|
||||
return false;
|
||||
}
|
||||
$("#" + opts.id).attr('src', _self.getObjectURL(this.files[0]));
|
||||
opts.callback();
|
||||
}
|
||||
})
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user