1. Список говнокодов пользователя partybreaker

    Всего: 1

  2. JavaScript / Говнокод #19413

    −4

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    37. 37
    38. 38
    39. 39
    40. 40
    41. 41
    42. 42
    43. 43
    44. 44
    45. 45
    46. 46
    47. 47
    48. 48
    49. 49
    50. 50
    51. 51
    52. 52
    53. 53
    54. 54
    55. 55
    56. 56
    57. 57
    58. 58
    59. 59
    60. 60
    61. 61
    62. 62
    63. 63
    64. 64
    65. 65
    66. 66
    67. 67
    68. 68
    69. 69
    70. 70
    71. 71
    72. 72
    73. 73
    74. 74
    75. 75
    76. 76
    77. 77
    78. 78
    79. 79
    80. 80
    81. 81
    82. 82
    83. 83
    84. 84
    85. 85
    86. 86
    87. 87
    88. 88
    89. 89
    90. 90
    91. 91
    92. 92
    93. 93
    94. 94
    95. 95
    96. 96
    97. 97
    98. 98
    99. 99
    var up = document.getElementById('upload'),
        text1 = document.getElementById('text1'),
        text2 = document.getElementById('text2'),
        sliderSize = document.getElementById('sliderSize'),
        sliderImage = document.getElementById('sliderImage'),
        file  = document.getElementById('image'),
        canvas = document.getElementById('canvas'),
        uploaded = document.getElementById('uploaded'),
        placeholder_image = document.getElementById('placeholder_image');
    
    up.addEventListener('click', uploadToImgur);
    
    text1.addEventListener('keyup', updateImage);
    text2.addEventListener('keyup', updateImage);
    sliderSize.addEventListener('change', updateImage);
    sliderImage.addEventListener('change', updateImage);
    file.addEventListener('change', changeAndUpdateImage);
    
    function readFile(fileInput, callback) {
        var f = fileInput.files[0];
        var reader = new FileReader();
        reader.onload = (function(theFile) {
            return function(e) {
                callback(e.target.result);
            };
        })(f);
        reader.readAsDataURL(f);
    }
    
    var curImg = null;
    
    placeholder_image.onload = function() {
        curImg = placeholder_image;
        updateImage();
    }
    
    function changeAndUpdateImage() {
        var img = new Image();
        readFile(file, function(dataURL) {
            img.onload = function() {
                curImg = img;
                sliderImage.value = Math.max(img.width, img.height);
                canvas.width = img.width;
                canvas.height = img.height;
                //canvas.style.height = img.height + 'px';
                //canvas.style.width = img.width + 'px';
                updateImage();
            }
            img.src = dataURL;
    
        });
           
    }
    
    function drawLines(ctx, lines, x, y, yStep) {
        lines = lines.split('\n');
        if (yStep < 0) lines = lines.reverse();
        lines.forEach(function(l, k) {
            ctx.strokeText(l, x, y + yStep * k);
            ctx.fillText(l,   x, y + yStep * k);
     
        });
    }
    
    
    
    function updateImage() {
        var LINE_HEIGHT = 1.1;
        var PARAGRAPH_HEIGHT = 1.5;
        
        var imgSizeLimit = parseFloat(sliderImage.value);
    
        var canvasSize = autoScale({
            w: curImg.width, 
            h: curImg.height
        }, imgSizeLimit);
    
        canvas.width = canvasSize.w;
        canvas.height = canvasSize.h;
    
        var ctx = canvas.getContext("2d");
        var txtSize = parseFloat(sliderSize.value) || 24;
    
        if (!curImg) return;
        
        ctx.strokeStyle = '#000000';
        ctx.fillStyle = '#ffffff';
        ctx.fillRect(0, 0, canvas.width, canvas.height);
        ctx.drawImage(curImg, 0, 0, canvas.width, canvas.height);
    
        ctx.font = txtSize + "px Impact";
        ctx.textAlign = 'center';
        ctx.textBaseline = 'middle';
        ctx.lineWidth = Math.round(Math.max(1, txtSize / 12));
    
        drawLines(ctx, text1.value, canvas.width / 2, 
                  txtSize * PARAGRAPH_HEIGHT / 2, LINE_HEIGHT * txtSize);
        drawLines(ctx, text2.value, canvas.width / 2, 
                  canvas.height - txtSize * PARAGRAPH_HEIGHT / 2, -1 * LINE_HEIGHT * txtSize );

    partybreaker, 07 Февраля 2016

    Комментарии (14)