(
function
($) {
$.fn.imgEdit =
function
(options) {
var
settings = $.extend({
inputName :
"profile-picture"
,
form :
"#profile"
,
}, options);
$(
this
).click(
function
(e){
var
target =
this
;
input = document.createElement(
'input'
);
input.setAttribute(
'type'
,
'file'
);
input.setAttribute(
'name'
, settings.inputName);
input.setAttribute(
'accept'
,
'.jpg, .jpeg, .png'
);
input.setAttribute(
'style'
,
'display:none;'
);
input.click();
input.onchange =
function
() {
$(
"#imgEditInput"
).remove();
input.setAttribute(
'id'
,
'imgEditInput'
);
if
(input.files && input.files[0]){
var
reader =
new
FileReader();
reader.onload =
function
(e) {
$(target).attr(
'src'
, e.target.result);
}
reader.readAsDataURL(input.files[0]);
$(settings.form).append(input);
}
};
});
};
}(jQuery));