diff --git a/js/oekaki.js b/js/oekaki.js index 7bea3832..028b8f58 100644 --- a/js/oekaki.js +++ b/js/oekaki.js @@ -1,10 +1,57 @@ $(function() { -var canvas = $("#cvs"); -var context = canvas[0].getContext("2d"); -var is_drawing = false; -var text = ""; -var eraser = getcolor = fill = false; -context.strokeStyle = context.fillStyle = "black"; +// Init +var oekaki_form = '\ + \ + \ + Oekaki\ + \ + \ + lol what you looking at the source for nerd\ +


\ + \ +

\ + \ + \ + ' + +function enable_oekaki() { + // Add oekaki after the file input + $('input[type="file"]').parent().parent().after(oekaki_form); + // Init oekaki vars + canvas = $("#cvs"); + context = canvas[0].getContext("2d"); + is_drawing = false; + text = ""; + eraser = getcolor = fill = false; + context.strokeStyle = context.fillStyle = "black"; + // Attach canvas events + attach_events(); + localStorage['oekaki'] = true; +} + +function disable_oekaki(){ + $("#oekaki").detach() + localStorage['oekaki'] = false; +} + +if (localStorage['oekaki'] === undefined) { localStorage['oekaki'] = true } + +$('hr:first').before('
-
'); +$('div#oekaki-status a').text(_('Oekaki')+' (' + (localStorage['oekaki'] === 'true' ? _('enabled') : _('disabled')) + ')'); + +$('div#oekaki-status a').on('click', function(){ + var enabled = !JSON.parse(localStorage['oekaki']); + + if(enabled){ + enable_oekaki(); + } else { + disable_oekaki(); + } + + $('div#oekaki-status a').text(_('Oekaki')+' (' + (enabled ? _('enabled') : _('disabled')) + ')'); +}); + +if (localStorage['oekaki'] === "true") { enable_oekaki(); } //http://stackoverflow.com/a/5624139/1901658 function hexToRgb(hex) { @@ -69,6 +116,8 @@ function color_under_pixel(x, y){ return context.getImageData(x, y, 1, 1).data; } +function attach_events(){ + canvas.on("mousedown", function(e){ getmousepos(e); $(this).css("cursor","none"); @@ -164,6 +213,7 @@ $("#getcolor").on("click", function(){ $("#fill").on("click", function(){ fill = true; }); +} function dataURItoBlob(dataURI) { var binary = atob(dataURI.split(',')[1]); diff --git a/templates/post_form.html b/templates/post_form.html index 93ca821e..b2e186cc 100644 --- a/templates/post_form.html +++ b/templates/post_form.html @@ -95,20 +95,6 @@ {{ antibot.html() }} - {% if config.oekaki %} - - - {% trans %}Oekaki{% endtrans %} - - - lol what you looking at the source for nerd -


- -

- - - - {% endif %} {% if config.enable_embedding %}