diff --git a/inc/config.php b/inc/config.php index 686894d1..e9e52aaf 100644 --- a/inc/config.php +++ b/inc/config.php @@ -642,15 +642,14 @@ // Allow unfiltered HTML in board subtitle. This is useful for placing icons and links. $config['allow_subtitle_html'] = false; - /* - * Enable oekaki (お絵描き). This puts a drawing field on your board. You can either - * enable it globally or enable it on a per-board basis. Oekaki's color field - * can be greatly enhanced by installing jscolor from http://jscolor.com/ and installing it in js/ - * If you enable oekaki, please remember to also enable its script with: - * $config['additional_javascript'][] = 'js/oekaki.js'; - */ - - $config['oekaki'] = false; + // Oekaki - To enable oekaki, just enable its script with: + // $config['additional_javascript'][] = 'js/oekaki.js'; + // Color selection in oekaki can be greatly improved by including the bundled jscolor script. + // $config['additional_javascript'][] = 'js/jscolor/jscolor.js'; + // $config['oekaki'] holds Oekaki options, which are currently just default canvas size. + + $config['oekaki']['height'] = 250; + $config['oekaki']['width'] = 500; /* * ==================== diff --git a/inc/display.php b/inc/display.php index 0f1bc195..9009be9a 100644 --- a/inc/display.php +++ b/inc/display.php @@ -74,6 +74,9 @@ function error($message, $priority = true, $debug_stuff = false) { if ($config['debug'] && isset($db_error)) { $debug_stuff = array_combine(array('SQLSTATE', 'Error code', 'Error message'), $db_error); } + + // Return the bad request header, necessary for AJAX posts + http_response_code(400); die(Element('page.html', array( 'config' => $config, diff --git a/js/jscolor/arrow.gif b/js/jscolor/arrow.gif new file mode 100644 index 00000000..246478a8 Binary files /dev/null and b/js/jscolor/arrow.gif differ diff --git a/js/jscolor/cross.gif b/js/jscolor/cross.gif new file mode 100644 index 00000000..0ee9c7ac Binary files /dev/null and b/js/jscolor/cross.gif differ diff --git a/js/jscolor/hs.png b/js/jscolor/hs.png new file mode 100644 index 00000000..3d94486c Binary files /dev/null and b/js/jscolor/hs.png differ diff --git a/js/jscolor/hv.png b/js/jscolor/hv.png new file mode 100644 index 00000000..1c5e01f8 Binary files /dev/null and b/js/jscolor/hv.png differ diff --git a/js/jscolor/jscolor.js b/js/jscolor/jscolor.js new file mode 100644 index 00000000..712ab9a3 --- /dev/null +++ b/js/jscolor/jscolor.js @@ -0,0 +1,995 @@ +/** + * jscolor, JavaScript Color Picker + * + * @version 1.4.1 + * @license GNU Lesser General Public License, http://www.gnu.org/copyleft/lesser.html + * @author Jan Odvarko, http://odvarko.cz + * @created 2008-06-15 + * @updated 2013-04-08 + * @link http://jscolor.com + */ + + +var jscolor = { + + + dir : '', // location of jscolor directory (leave empty to autodetect) + bindClass : 'color', // class name + binding : true, // automatic binding via + preloading : true, // use image preloading? + + + install : function() { + jscolor.addEvent(window, 'load', jscolor.init); + }, + + + init : function() { + if(jscolor.binding) { + jscolor.bind(); + } + if(jscolor.preloading) { + jscolor.preload(); + } + }, + + + getDir : function() { + if(!jscolor.dir) { + var detected = jscolor.detectDir(); + jscolor.dir = detected!==false ? detected : 'jscolor/'; + } + return jscolor.dir; + }, + + + detectDir : function() { + var base = location.href; + + var e = document.getElementsByTagName('base'); + for(var i=0; i vs[a] ? + (-vp[a]+tp[a]+ts[a]/2 > vs[a]/2 && tp[a]+ts[a]-ps[a] >= 0 ? tp[a]+ts[a]-ps[a] : tp[a]) : + tp[a], + -vp[b]+tp[b]+ts[b]+ps[b]-l+l*c > vs[b] ? + (-vp[b]+tp[b]+ts[b]/2 > vs[b]/2 && tp[b]+ts[b]-l-l*c >= 0 ? tp[b]+ts[b]-l-l*c : tp[b]+ts[b]-l+l*c) : + (tp[b]+ts[b]-l+l*c >= 0 ? tp[b]+ts[b]-l+l*c : tp[b]+ts[b]-l-l*c) + ]; + } + drawPicker(pp[a], pp[b]); + } + }; + + + this.importColor = function() { + if(!valueElement) { + this.exportColor(); + } else { + if(!this.adjust) { + if(!this.fromString(valueElement.value, leaveValue)) { + styleElement.style.backgroundImage = styleElement.jscStyle.backgroundImage; + styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor; + styleElement.style.color = styleElement.jscStyle.color; + this.exportColor(leaveValue | leaveStyle); + } + } else if(!this.required && /^\s*$/.test(valueElement.value)) { + valueElement.value = ''; + styleElement.style.backgroundImage = styleElement.jscStyle.backgroundImage; + styleElement.style.backgroundColor = styleElement.jscStyle.backgroundColor; + styleElement.style.color = styleElement.jscStyle.color; + this.exportColor(leaveValue | leaveStyle); + + } else if(this.fromString(valueElement.value)) { + // OK + } else { + this.exportColor(); + } + } + }; + + + this.exportColor = function(flags) { + if(!(flags & leaveValue) && valueElement) { + var value = this.toString(); + if(this.caps) { value = value.toUpperCase(); } + if(this.hash) { value = '#'+value; } + valueElement.value = value; + } + if(!(flags & leaveStyle) && styleElement) { + styleElement.style.backgroundImage = "none"; + styleElement.style.backgroundColor = + '#'+this.toString(); + styleElement.style.color = + 0.213 * this.rgb[0] + + 0.715 * this.rgb[1] + + 0.072 * this.rgb[2] + < 0.5 ? '#FFF' : '#000'; + } + if(!(flags & leavePad) && isPickerOwner()) { + redrawPad(); + } + if(!(flags & leaveSld) && isPickerOwner()) { + redrawSld(); + } + }; + + + this.fromHSV = function(h, s, v, flags) { // null = don't change + if(h !== null) { h = Math.max(0.0, this.minH, Math.min(6.0, this.maxH, h)); } + if(s !== null) { s = Math.max(0.0, this.minS, Math.min(1.0, this.maxS, s)); } + if(v !== null) { v = Math.max(0.0, this.minV, Math.min(1.0, this.maxV, v)); } + + this.rgb = HSV_RGB( + h===null ? this.hsv[0] : (this.hsv[0]=h), + s===null ? this.hsv[1] : (this.hsv[1]=s), + v===null ? this.hsv[2] : (this.hsv[2]=v) + ); + + this.exportColor(flags); + }; + + + this.fromRGB = function(r, g, b, flags) { // null = don't change + if(r !== null) { r = Math.max(0.0, Math.min(1.0, r)); } + if(g !== null) { g = Math.max(0.0, Math.min(1.0, g)); } + if(b !== null) { b = Math.max(0.0, Math.min(1.0, b)); } + + var hsv = RGB_HSV( + r===null ? this.rgb[0] : r, + g===null ? this.rgb[1] : g, + b===null ? this.rgb[2] : b + ); + if(hsv[0] !== null) { + this.hsv[0] = Math.max(0.0, this.minH, Math.min(6.0, this.maxH, hsv[0])); + } + if(hsv[2] !== 0) { + this.hsv[1] = hsv[1]===null ? null : Math.max(0.0, this.minS, Math.min(1.0, this.maxS, hsv[1])); + } + this.hsv[2] = hsv[2]===null ? null : Math.max(0.0, this.minV, Math.min(1.0, this.maxV, hsv[2])); + + // update RGB according to final HSV, as some values might be trimmed + var rgb = HSV_RGB(this.hsv[0], this.hsv[1], this.hsv[2]); + this.rgb[0] = rgb[0]; + this.rgb[1] = rgb[1]; + this.rgb[2] = rgb[2]; + + this.exportColor(flags); + }; + + + this.fromString = function(hex, flags) { + var m = hex.match(/^\W*([0-9A-F]{3}([0-9A-F]{3})?)\W*$/i); + if(!m) { + return false; + } else { + if(m[1].length === 6) { // 6-char notation + this.fromRGB( + parseInt(m[1].substr(0,2),16) / 255, + parseInt(m[1].substr(2,2),16) / 255, + parseInt(m[1].substr(4,2),16) / 255, + flags + ); + } else { // 3-char notation + this.fromRGB( + parseInt(m[1].charAt(0)+m[1].charAt(0),16) / 255, + parseInt(m[1].charAt(1)+m[1].charAt(1),16) / 255, + parseInt(m[1].charAt(2)+m[1].charAt(2),16) / 255, + flags + ); + } + return true; + } + }; + + + this.toString = function() { + return ( + (0x100 | Math.round(255*this.rgb[0])).toString(16).substr(1) + + (0x100 | Math.round(255*this.rgb[1])).toString(16).substr(1) + + (0x100 | Math.round(255*this.rgb[2])).toString(16).substr(1) + ); + }; + + + function RGB_HSV(r, g, b) { + var n = Math.min(Math.min(r,g),b); + var v = Math.max(Math.max(r,g),b); + var m = v - n; + if(m === 0) { return [ null, 0, v ]; } + var h = r===n ? 3+(b-g)/m : (g===n ? 5+(r-b)/m : 1+(g-r)/m); + return [ h===6?0:h, m/v, v ]; + } + + + function HSV_RGB(h, s, v) { + if(h === null) { return [ v, v, v ]; } + var i = Math.floor(h); + var f = i%2 ? h-i : 1-(h-i); + var m = v * (1 - s); + var n = v * (1 - s*f); + switch(i) { + case 6: + case 0: return [v,n,m]; + case 1: return [n,v,m]; + case 2: return [m,v,n]; + case 3: return [m,n,v]; + case 4: return [n,m,v]; + case 5: return [v,m,n]; + } + } + + + function removePicker() { + delete jscolor.picker.owner; + document.getElementsByTagName('body')[0].removeChild(jscolor.picker.boxB); + } + + + function drawPicker(x, y) { + if(!jscolor.picker) { + jscolor.picker = { + box : document.createElement('div'), + boxB : document.createElement('div'), + pad : document.createElement('div'), + padB : document.createElement('div'), + padM : document.createElement('div'), + sld : document.createElement('div'), + sldB : document.createElement('div'), + sldM : document.createElement('div'), + btn : document.createElement('div'), + btnS : document.createElement('span'), + btnT : document.createTextNode(THIS.pickerCloseText) + }; + for(var i=0,segSize=4; ilol 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); + // Add "edit in oekaki" links + $(".fileinfo").append(' '+_('Edit in oekaki')+''); + // Init oekaki vars + canvas = $("#oekaki_canvas"); + 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(); + $(".edit_in_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) { @@ -51,7 +101,7 @@ function flood_fill(x, y, target){ var data = context.getImageData(n[0], n[1], 1, 1).data; var d = [data[0], data[1], data[2], data[3]]; var t = [target[0], target[1], target[2], target[3]]; - if (arraysEqual(d, t) && n[0] < 500 && n[1] < 250 && n[0] > -1 && n[1] > -1){ + if (arraysEqual(d, t) && n[0] < canvas.width() && n[1] < canvas.height() && n[0] > -1 && n[1] > -1){ context.putImageData(pixel, n[0], n[1]); queue.push([n[0], n[1]-1]); queue.push([n[0], n[1]+1]); @@ -69,6 +119,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"); @@ -127,6 +179,7 @@ function clear(){ context.beginPath(); context.clearRect(0,0,canvas.width(),canvas.height()); $("#confirm_oekaki").attr("checked",false) + canvas[0].height = oekaki_options.height; canvas[0].width = oekaki_options.width; }; $("#clear").on("click", clear); @@ -165,6 +218,17 @@ $("#fill").on("click", function(){ 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) { var binary = atob(dataURI.split(',')[1]); var array = new Array(binary.length); @@ -185,14 +249,14 @@ $("form[name='post']").on("submit", function(e){ fd.append("post", $("input[name='post']").val()); $.ajax({ type: "POST", - url: "/post.php", + url: oekaki_options.root+"post.php", data: fd, processData: false, contentType: false, success: function(data) { location.reload(); }, - error: function(data) {alert("Something went wrong!"); console.log(data)} + error: function(jq, data) {alert($('h2',jq.responseText).text());} }); } diff --git a/templates/main.js b/templates/main.js index 78054a3b..05a8fd5f 100644 --- a/templates/main.js +++ b/templates/main.js @@ -265,7 +265,15 @@ function ready() { onready(init); -{% endraw %}{% if config.google_analytics %}{% raw %} +{% endraw %} + +var oekaki_options = { + width: {{config.oekaki.width}}, + height: {{config.oekaki.height}}, + root: '{{config.root}}' +}; + +{% if config.google_analytics %}{% raw %} var _gaq = _gaq || [];_gaq.push(['_setAccount', '{% endraw %}{{ config.google_analytics }}{% raw %}']);{% endraw %}{% if config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', '{% endraw %}{{ config.google_analytics_domain }}{% raw %}']){% endraw %}{% endif %}{% if not config.google_analytics_domain %}{% raw %}_gaq.push(['_setDomainName', 'none']){% endraw %}{% endif %}{% raw %};_gaq.push(['_trackPageview']);(function() {var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);})();{% endraw %}{% endif %} 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 %}