1. JavaScript / Говнокод #25383

    0

    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
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>Calendar</title>
    </head>
    <body>
    
    <style>
    .month, .month.vert .week, .day { display:inline-block; }
    .month.vert .day { display:block; }
    .day { border:1px solid #ccc; width:30px; line-height:30px; text-align:center; }
    </style>
    
    <div class="month"></div>
    
    <script>
    var calendar = {
        update: function (year, month) {
            this.days.length = 7;
            var stepDay = new Date(year, month, 1);
            stepDay.setDate(1 - stepDay.getDay());
            var lastDay = new Date(year, month + 1, 0);
            lastDay.setDate(lastDay.getDate() + 6 - lastDay.getDay());
            while (stepDay <= lastDay) {
                this.days.push(stepDay.getDate());
                stepDay.setHours(24);
            }
        },
        render: function () {
            var html = '';
            for (var i = 0, j = 0; i < this.days.length; j = ++i % 7) {
                if (j == 0) html += '<div class="week">';
                html += '<div class="day">' +  this.days[i] + '</div>';
                if (j == 6) html += '</div>';
            }
            this.element.innerHTML = html;
        },
        toggle: function () {
            this.element.classList.toggle('vert');
        }
    };
    var today =  new Date, thisYear = today.getFullYear(), thisMonth = today.getMonth();
    calendar.days = ['S', 'M', 'T', 'W', 'T', 'F', 'S'];
    calendar.element = document.querySelector('.month');
    calendar.element.addEventListener('click', function () { calendar.toggle() });
    calendar.update(thisYear, thisMonth);
    calendar.render();
    </script>
    
    </body>
    </html>

    Запостил: unicorn, 16 Февраля 2019

    Комментарии (4) RSS

    Добавить комментарий