Guest User

Untitled

a guest
Feb 21st, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. changeGridLines: function(color,opacity) {
  2.  
  3. if (!color.match(/.*d.*/g)){
  4. console.log("invalid color value given for calculating grid opacity");
  5. }
  6. // hex & rgb
  7. else if (color.indexOf('rgba') === -1) {
  8.  
  9. if (color.indexOf('#') !== -1) {
  10. color = utility.hexToRgb(color);
  11. }
  12.  
  13. color = color.slice(0, -1) + ', ' + opacity + ')';
  14. color = color.replace('rgb', 'rgba');
  15. }
  16. //rgba
  17. else if ((color.indexOf('rgba') !== -1)){
  18. color = color.substring(0,color.lastIndexOf(',')) + ', ' + opacity + ')';
  19. }
  20. else {
  21. console.log("invalid color value given for calculating grid opacity");
  22. }
  23.  
  24. this.tdArray.forEach(function(td) {
  25. td.style.border = '1px solid';
  26. td.style.borderColor = color;
  27. });
  28. },
  29. clearGridLines: function() {
  30. this.tdArray.forEach(function(td) {
  31. td.style.border = 'none';
  32. });
  33. },
  34. draw: function(elem,color) {
  35.  
  36. // stop the function when element is not table cell (of canvas)
  37. if (elem.tagName !== 'TD')
  38. return;
  39.  
  40. // transform brushsize to number (could be string)
  41. let size = +grid.brushSize.value;
  42.  
  43. // basic draw the cell when brushsize = 1 cell
  44. if (size === 1)
  45. elem.style.backgroundColor = color;
  46. // if brushsize is bigger than 1, calculate the according other cells that have to be painted as well. starting from first cell going right and down
  47. else if (size > 1) {
  48. let tds = elem.parentNode.childNodes;
  49. let trs = elem.parentNode.parentNode.childNodes;
  50. let currentChildNodeIndex = utility.getChildNodeIndex(elem, tds);
  51. let currentRowIndex = utility.getChildNodeIndex(elem.parentNode, trs);
  52.  
  53. for (let j = 0; j < size; j++) {
  54. if (trs[currentRowIndex + j]) {
  55. tds = trs[currentRowIndex + j].childNodes;
  56. }
  57.  
  58. for (let k = 0; k < size; k++) {
  59. if (tds[currentChildNodeIndex + k]) {
  60. tds[currentChildNodeIndex + k].style.backgroundColor = color;
  61. }
  62. }
  63. }
  64. }
  65. },
Add Comment
Please, Sign In to add comment