Edit images in thread/board using Oekaki

This commit is contained in:
ctrlcctrlv 2013-08-17 18:56:16 +00:00
parent e3600131fc
commit 6cb863005d
2 changed files with 19 additions and 3 deletions

View File

@ -17,6 +17,8 @@ var oekaki_form = '\
function enable_oekaki() { function enable_oekaki() {
// Add oekaki after the file input // Add oekaki after the file input
$('input[type="file"]').parent().parent().after(oekaki_form); $('input[type="file"]').parent().parent().after(oekaki_form);
// Add "edit in oekaki" links
$(".fileinfo").append(' <a href="javascript:void(0)" class="edit_in_oekaki">'+_('Edit in oekaki')+'</a>');
// Init oekaki vars // Init oekaki vars
canvas = $("#oekaki_canvas"); canvas = $("#oekaki_canvas");
context = canvas[0].getContext("2d"); context = canvas[0].getContext("2d");
@ -30,7 +32,8 @@ function enable_oekaki() {
} }
function disable_oekaki(){ function disable_oekaki(){
$("#oekaki").detach() $("#oekaki").detach();
$(".edit_in_oekaki").detach();
localStorage['oekaki'] = false; localStorage['oekaki'] = false;
} }
@ -176,6 +179,7 @@ function clear(){
context.beginPath(); context.beginPath();
context.clearRect(0,0,canvas.width(),canvas.height()); context.clearRect(0,0,canvas.width(),canvas.height());
$("#confirm_oekaki").attr("checked",false) $("#confirm_oekaki").attr("checked",false)
canvas[0].height = oekaki_options.height; canvas[0].width = oekaki_options.width;
}; };
$("#clear").on("click", clear); $("#clear").on("click", clear);
@ -213,6 +217,16 @@ $("#getcolor").on("click", function(){
$("#fill").on("click", function(){ $("#fill").on("click", function(){
fill = true; fill = true;
}); });
$(".edit_in_oekaki").on("click", function(){
var img_link = $(this).parent().parent().find("a>img.post-image").parent()[0]
var img = new Image();
img.onload = function() {
canvas[0].width = img.width; canvas[0].height = img.height;
context.drawImage(img, 0, 0);
}
img.src = $(img_link).attr("href");
});
} }
function dataURItoBlob(dataURI) { function dataURItoBlob(dataURI) {
@ -235,12 +249,13 @@ $("form[name='post']").on("submit", function(e){
fd.append("post", $("input[name='post']").val()); fd.append("post", $("input[name='post']").val());
$.ajax({ $.ajax({
type: "POST", type: "POST",
url: "/post.php", url: oekaki_options.root+"post.php",
data: fd, data: fd,
processData: false, processData: false,
contentType: false, contentType: false,
success: function(data) { success: function(data) {
location.reload(); //location.reload();
console.log(data);
}, },
error: function(data) {alert("Something went wrong!"); console.log(data)} error: function(data) {alert("Something went wrong!"); console.log(data)}
}); });

View File

@ -270,6 +270,7 @@ onready(init);
var oekaki_options = { var oekaki_options = {
width: {{config.oekaki.width}}, width: {{config.oekaki.width}},
height: {{config.oekaki.height}}, height: {{config.oekaki.height}},
root: '{{config.root}}'
}; };
{% if config.google_analytics %}{% raw %} {% if config.google_analytics %}{% raw %}