javascript - 如何在每个时间段检测到最大条目时更改日历覆盖

标签 javascript css sharepoint calendar

Please follow these steps:

  1. you need to create a view to represent your calendar (You'll need to declare your filters).
  2. create a calendar overlay, in this example, I filtered "ms-acal-item" because it is where the calendar items per hour is located, you'll need to open the IE Developer Tool by pressing F12, and trace the ... to get the exact value getElementsByClassName.
var times = [
            "7:00 am - 7:30 am ", 
            "7:30 am - 8:00 am ", 
            "8:00 am - 8:30 am ", 
            "8:30 am - 9:00 am ",
            "9:00 am - 9:30 am ",
            "9:30 am - 10:00 am ",
            "10:00 am - 10:30 am ",
            "10:30 am - 11:00 am ",
            "11:00 am - 11:30 am ",
            "11:30 am - 12:00 pm ",
            "12:00 pm - 12:30 pm ",
            "12:30 pm - 1:00 pm ",
            "1:00 pm - 1:30 pm ",
            "1:30 pm - 2:00 pm ",
            "2:00 pm - 2:30 pm ",
            "2:30 pm - 3:00 pm ",
            "3:00 pm - 3:30 pm ",
            "3:30 pm - 4:00 pm ",
            "4:00 am - 4:30 am ",
            "4:30 am - 5:00 am ",
            "5:00 pm - 5:30 pm ",
            "5:30 pm - 6:00 pm ",
            "6:00 pm - 6:30 pm ",
            "6:30 pm - 7:00 pm "
            ];

function ApplyColor() {

    var nodes, iCount, TimeIdentifier;

    for (x = 0; x < times.length; x++){
        TimeIdentifier = times[x];
        console.log(times[x]);
        nodes = document.getElementsByClassName("ms-acal-item");

        iCount = 0;

        for (var i = 0; i < nodes.length; i++) {

            if (nodes[i].outerHTML.indexOf(TimeIdentifier) != -1) {

                console.log(nodes[i].outerHTML);
                var parts = nodes[i].outerHTML.split(TimeIdentifier);

                iCount += 1;

                // Set the maximim number of entries to make it red
                if (iCount >= 4)
                {
                    if (parts[1])
                    {
                        var color = GetCalendarColour("red");
                        nodes[i].style.background = color;
                    }
                }
            }
        }                       
    }
}

function GetCalendarColour(desc) {
    var colour;
    switch (desc.toLowerCase()) {

        case "red":
            colour = "rgb(255,000,000)";
            break;

        default:
            colour = "";
    }
    return colour;
}

window.setInterval(function () {
    ApplyColor();
}, 500);

最佳答案

Correction for var times "3:30 pm - 4:00 pm ", "4:00 am - 4:30 am ", "4:30 am - 5:00 am ", "5:00 pm - 5:30 pm ", should be pm. Thanks

var times = [
            "7:00 am - 7:30 am ", 
            "7:30 am - 8:00 am ", 
            "8:00 am - 8:30 am ", 
            "8:30 am - 9:00 am ",
            "9:00 am - 9:30 am ",
            "9:30 am - 10:00 am ",
            "10:00 am - 10:30 am ",
            "10:30 am - 11:00 am ",
            "11:00 am - 11:30 am ",
            "11:30 am - 12:00 pm ",
            "12:00 pm - 12:30 pm ",
            "12:30 pm - 1:00 pm ",
            "1:00 pm - 1:30 pm ",
            "1:30 pm - 2:00 pm ",
            "2:00 pm - 2:30 pm ",
            "2:30 pm - 3:00 pm ",
            "3:00 pm - 3:30 pm ",
            "3:30 pm - 4:00 pm ",
            "4:00 pm - 4:30 pm ",
            "4:30 pm - 5:00 pm ",
            "5:00 pm - 5:30 pm ",
            "5:30 pm - 6:00 pm ",
            "6:00 pm - 6:30 pm ",
            "6:30 pm - 7:00 pm "
            ];

关于javascript - 如何在每个时间段检测到最大条目时更改日历覆盖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48069854/

相关文章:

jQuery 改变事件类图标的状态

sharepoint - checkin 和 checkout SPFile 对象

javascript - JavaScript 中的查找函数

javascript - npm 模块 - 是否可以拆分 bin 和 lib 依赖项?

javascript - 如何用户异步守护?

javascript - 默认情况下导航栏下拉项无法隐藏

jquery - 照片网格仅显示一些图像

sharepoint - 如何让 SharePoint 链接列表默认在新窗口中打开?

Sharepoint 计时器作业创建列表项但不触发项目事件处理程序

javascript - 当用户单击键盘上的 Enter 时触发按钮单击