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
57 changes: 54 additions & 3 deletions croppic.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
cropUrl:'',
cropData:{},
outputUrlId:'',
deleteUrl:'',
//styles
imgEyecandy:true,
imgEyecandyOpacity:0.2,
Expand Down Expand Up @@ -155,6 +156,7 @@

that.croppedImg.remove();
$(this).hide();
that.delete(that.cropUrl);

if (typeof (that.options.onAfterRemoveCroppedImg) === typeof(Function)) {
that.options.onAfterRemoveCroppedImg.call(that);
Expand Down Expand Up @@ -412,7 +414,10 @@
that.cropControlCrop.on('click',function(){ that.crop(); });

that.cropControlReset = that.cropControlsCrop.find('.cropControlReset');
that.cropControlReset.on('click',function(){ that.reset(); });
that.cropControlReset.on('click',function(){
that.delete(that.imgUrl);
that.reset();
});

},
initDrag:function(){
Expand Down Expand Up @@ -621,6 +626,7 @@
that.imgEyecandy.hide();

that.destroy();
that.cropUrl=response.url;

that.obj.append('<img class="croppedImg" src="'+response.url+'">');
if(that.options.outputUrlId !== ''){ $('#'+that.options.outputUrlId).val(response.url); }
Expand Down Expand Up @@ -675,6 +681,51 @@
if( !$.isEmptyObject( that.loader ) ){ that.loader.remove(); }
if( !$.isEmptyObject( that.form ) ){ that.form.remove(); }
that.obj.html('');
}
},

delete: function (myURL) {
var that = this;

var deleteData = {
deleteUrl:myURL
};

var formData = new FormData();

for (var key in deleteData) {
if( deleteData.hasOwnProperty(key) ) {
formData.append( key , deleteData[key] );
}
}

$.ajax({
url: that.options.deleteUrl,
data: formData,
context: document.body,
cache: false,
contentType: false,
processData: false,
type: 'POST'
}).always(function(data) {
response = typeof data == 'object' ? data : jQuery.parseJSON(data);

if (response.status == 'success') {

//add code if desired

}

if (response.status == 'error') {
if (that.options.onError)
that.options.onError.call(that, response.message);
that.hideLoader();
setTimeout(function() {
that.reset();
}, 2000)
}

});

}
};
})(window, document);
})(window, document);
19 changes: 19 additions & 0 deletions img_delete_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/*
* !!! THIS IS JUST AN EXAMPLE !!!
*/
$deleteUrl = $_POST['deleteUrl'];

// delete the cropped file
unlink ($deleteUrl);

if (!file_exists ($deleteUrl)) {
$response = Array(
"status" => 'success',
);
} else {
$response = Array(
"status" => 'error',
);
}
print json_encode($response);