The version of vichan running on lainchan.org
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

130 lignes
4.1KB

  1. /*
  2. * wpaint.js - wPaint integration javascript
  3. * https://github.com/vichan-devel/Tinyboard/blob/master/js/wpaint.js
  4. *
  5. * Released under the MIT license
  6. * Copyright (c) 2014 Marcin Łabanowski <marcin@6irc.net>
  7. *
  8. * Contains parts of old oekaki code:
  9. * Copyright (c) 2013 copypaste <wizardchan@hush.com>
  10. * Copyright (c) 2013-2014 Marcin Łabanowski <marcin@6irc.net>
  11. *
  12. * Usage:
  13. * $config['additional_javascript'][] = 'js/jquery.min.js';
  14. * $config['additional_javascript'][] = 'js/jquery-ui.custom.min.js';
  15. * $config['additional_javascript'][] = 'js/ajax.js';
  16. * $config['additional_javascript'][] = 'js/wPaint/8ch.js';
  17. * $config['additional_javascript'][] = 'js/wpaint.js';
  18. * $config['additional_javascript'][] = 'js/upload-selection.js';
  19. *
  20. */
  21. window.oekaki = (function(){
  22. "use strict";
  23. var oekaki = {};
  24. oekaki.settings = new script_settings('wpaint');
  25. oekaki.height = oekaki.settings.get("height", 250);
  26. oekaki.width = oekaki.settings.get("width", 500);
  27. function dataURItoBlob(dataURI) {
  28. var binary = atob(dataURI.split(',')[1]);
  29. var array = new Array(binary.length);
  30. for(var i = 0; i < binary.length; i++) {
  31. array[i] = binary.charCodeAt(i);
  32. }
  33. return new Blob([new Uint8Array(array)], {type: 'image/jpeg'});
  34. }
  35. oekaki.do_css = function() {
  36. }
  37. oekaki.init = function() {
  38. var oekaki_form = '<tr id="oekaki"><th>Oekaki</th><td><div id="wpaintctr"><div id="wpaintdiv"></div></div></td></tr>';
  39. // Add oekaki after the file input
  40. $('form[name="post"]:not(#quick-reply) [id="upload"]').after(oekaki_form);
  41. $('<link class="wpaintcss" rel="stylesheet" href="'+configRoot+'js/wPaint/wPaint.min.css" />').appendTo($("head"));
  42. $('<link class="wpaintcss" rel="stylesheet" href="'+configRoot+'js/wPaint/lib/wColorPicker.min.css" />').appendTo($("head"));
  43. $('<link class="wpaintcss" rel="stylesheet" href="'+configRoot+'stylesheets/jquery-ui/core.css" />').appendTo($("head"));
  44. $('<link class="wpaintcss" rel="stylesheet" href="'+configRoot+'stylesheets/jquery-ui/resizable.css" />').appendTo($("head"));
  45. $('<link class="wpaintcss" rel="stylesheet" href="'+configRoot+'stylesheets/jquery-ui/theme.css" />').appendTo($("head"));
  46. var initcount = 0;
  47. $('.wpaintcss').one('load', function() {
  48. initcount++;
  49. if (initcount == 5) {
  50. $.extend($.fn.wPaint.defaults, {
  51. mode: 'pencil', // set mode
  52. lineWidth: '1', // starting line width
  53. fillStyle: '#FFFFFF', // starting fill style
  54. strokeStyle: '#000000', // start stroke style
  55. });
  56. delete $.fn.wPaint.menus.main.items.save;
  57. $('#wpaintdiv').wPaint({
  58. path: configRoot+'js/wPaint/',
  59. menuOffsetTop: -46,
  60. bg: "#ffffff",
  61. loadImgFg: oekaki.load_img,
  62. loadImgBg: oekaki.load_img
  63. });
  64. $("#wpaintctr").resizable({
  65. stop: function(event,ui) {
  66. $("#wpaintdiv").wPaint("resize");
  67. },
  68. alsoResize: "#wpaintdiv",
  69. });
  70. $('#wpaintctr .ui-resizable-se').css({'height':'12px', 'width':'12px'});
  71. }
  72. });
  73. $("#wpaintdiv").width(oekaki.width).height(oekaki.height).css("position", "relative");
  74. $("#wpaintctr").width(oekaki.width+5).height(oekaki.height+5).css("padding-top", 48).css("position", "relative");
  75. $(document).on("ajax_before_post.wpaint", function(e, postData) {
  76. var blob = $('#wpaintdiv').wPaint("image");
  77. blob = dataURItoBlob(blob);
  78. postData.append("file", blob, "Oekaki.png");
  79. });
  80. $(window).on('stylesheet', function() {
  81. oekaki.do_css();
  82. if ($('link#stylesheet').attr('href')) {
  83. $('link#stylesheet')[0].onload = oekaki.do_css;
  84. }
  85. });
  86. oekaki.initialized = true;
  87. };
  88. oekaki.load_img = function() {
  89. alert(_("Click on any image on this site to load it into oekaki applet"));
  90. $('img').one('click.loadimg', function(e) {
  91. $('img').off('click.loadimg');
  92. e.stopImmediatePropagation();
  93. e.preventDefault();
  94. var url = $(this).prop('src');
  95. $('#wpaintdiv').wPaint('setBg', url);
  96. return false;
  97. });
  98. };
  99. oekaki.deinit = function() {
  100. $('#oekaki, .wpaintcss').remove();
  101. $(document).off("ajax_before_post.wpaint");
  102. oekaki.initialized = false;
  103. };
  104. oekaki.initialized = false;
  105. return oekaki;
  106. })();