Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,15 @@ See the demo here: http://andyvr.github.io/picEdit/
_type: string, default: false_ - an image to be loaded in the editor by default ('path/to/image')
<h6><i>use only images located on the same server to prevent CORS issues</i></h6>

**submitForm**

_type: bool, default: true_ - boolean to automatically submit the form, set to true. To wait to submit the form (if multiple image inputs are present), set all but the last instance to false.

```
$('#image_1').picEdit({ submitForm: false });
$('#image_2').picEdit({ submitForm: true });
```

**maxWidth**

_type: int/auto, default: 400_ - max width for the picedit element (the original image will not be re-scaled if it's wider than maxWidth, this parameter controls image preview only)
Expand Down
60 changes: 36 additions & 24 deletions dist/js/picedit.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
maxWidth: 400, // Max width parameter
maxHeight: 'auto', // Max height parameter
aspectRatio: true, // Preserve aspect ratio
submitForm: true,
defaultImage: false // Default image to be used with the plugin
};

Expand Down Expand Up @@ -686,36 +687,47 @@
else {
var _this = this;
this.set_loading().delay(200).promise().done(function() {
_this._theformdata = new FormData(_this._theform[0]);
try {
if(window.form_data) {
console.log("Form Data Already Created");
} else {
window.form_data = new FormData(_this._theform[0]);
console.log("Creating Form Data");
}
}
catch(e) {
}
if(_this._image) {
var inputname = $(_this.inputelement).prop("name") || "file";
var inputblob = _this._dataURItoBlob(_this._image.src);
if(!_this._filename) _this._filename = inputblob.type.replace("/", ".");
else _this._filename = _this._filename.match(/^[^\.]*/) + "." + inputblob.type.match(/[^\/]*$/);
_this._theformdata.append(inputname, inputblob, _this._filename);
window.form_data.append(inputname, inputblob, _this._filename);
}
//send request
var request = new XMLHttpRequest();
request.onprogress = function(e) {
if(e.lengthComputable) var total = e.total;
else var total = Math.ceil(inputblob.size * 1.3);
var progress = Math.ceil(((e.loaded)/total)*100);
if (progress > 100) progress = 100;
_this.set_messagebox("Please Wait... Uploading... " + progress + "% Uploaded.", false, false);
};
request.open(_this._theform.prop("method"), _this._theform.prop("action"), true);
request.onload = function(e) {
if(this.status != 200) {
_this.set_messagebox("Server did not accept data!");
}
else {
if(_this.options.redirectUrl === true) window.location.reload();
else if(_this.options.redirectUrl) window.location = _this.options.redirectUrl;
else _this.set_messagebox("Data successfully submitted!");
}
_this.options.formSubmitted(this);
};
request.send(_this._theformdata);
if(_this.options.submitForm === true) {
var request = new XMLHttpRequest();
request.onprogress = function(e) {
if(e.lengthComputable) var total = e.total;
else var total = Math.ceil(inputblob.size * 1.3);
var progress = Math.ceil(((e.loaded)/total)*100);
if (progress > 100) progress = 100;
_this.set_messagebox("Please Wait... Uploading... " + progress + "% Uploaded.", false, false);
};
request.open(_this._theform.prop("method"), _this._theform.prop("action"), true);
request.onload = function(e) {
if(this.status != 200) {
_this.set_messagebox("Server did not accept data!");
}
else {
if(_this.options.redirectUrl === true) window.location.reload();
else if(_this.options.redirectUrl) window.location = _this.options.redirectUrl;
else _this.set_messagebox("Data successfully submitted!");
}
_this.options.formSubmitted(this);
};
request.send(window.form_data);
}
});
}
return false;
Expand Down Expand Up @@ -803,4 +815,4 @@
}
};

}(jQuery, window, document));
}(jQuery, window, document));
Loading