Moodle Assignment功能可在分配中插入额外的文本

时间:2017-03-01 15:42:05

标签: javascript moodle

许多大学都有蓝卡计划,让有特殊学习困难的学生(SpLD)用蓝卡标记他们的工作,因此导师会在适当考虑的情况下对其进行标记。

我们需要一种方法让学生更容易用蓝卡标记他们的工作,我已经提出了以下脚本,该脚本进入Moodle的站点管理中的附加HTML部分,并与Moodle一起使用作业功能(参见a blue card script that works with the Turnitin plugin的上一篇文章)。

首先,学生点击按钮添加蓝卡,在提交评论字段中插入带有“蓝卡”字样的评论。提交表单后,JavaScript会在评分表中查找注释,并在状态列中添加一个标记,以提醒教师查看注释。然后,导师可以显示评论,并看到“蓝卡”(这是阅读障碍标记指南的链接)。

1 个答案:

答案 0 :(得分:0)

/* MOODLE ASSIGNMENT BLUE CARD */

var MoodleAssignBlueCardButton =  '<input type="button" id="mabluecard" value="Flag with Blue Card" class="bluecard"/> <a href="http://www.brookes.ac.uk/students/wellbeing/dyslexia-spld/blue-marking-cards/"  target="_blank" title="What is the Blue Card scheme?">What\'s this?</a><br/>';

if (!document.getElementsByClassName('submissionstatustable')[0]) {
   /* do nothing */
} else {
    var assignTable = document.getElementsByClassName('submissionstatustable')[0];
    assignTable.insertAdjacentHTML('beforebegin', MoodleAssignBlueCardButton);
}

/* EVENT LISTENER FOR MOODLE ASSIGNMENT BLUE CARD BUTTON */
if (!document.getElementById('mabluecard')) {
   /* do nothing */
} else {
    document.getElementById("mabluecard").addEventListener('click', function () {  
        var commentbox = document.getElementsByClassName('comment-area')[0];
        var textarea = commentbox.getElementsByTagName('textarea')[0];
        if (!textarea.value) {
            textarea.value = ('<a href="http://www.brookes.ac.uk/students/wellbeing/dyslexia-spld/blue-marking-cards/" target="_blank" style="background-color: #99ccff">Blue Card</a>'); 
         } else if  (textarea.value == 'Add a comment...') {
               textarea.value = ('<a href="http://www.brookes.ac.uk/students/wellbeing/dyslexia-spld/blue-marking-cards/" target="_blank" style="background-color: #99ccff">Blue Card</a>'); 
       } else {
            textarea.value = ('<a href="http://www.brookes.ac.uk/students/wellbeing/dyslexia-spld/blue-marking-cards/" target="_blank" style="background-color: #99ccff">Blue Card</a>: ' + textarea.value);
         }
    /* save the comment */
    document.getElementsByClassName("comment-link")[0].click();
    var saveLink = document.getElementsByClassName("fd")[0].getElementsByTagName("a")[0];
     saveLink.click();
    });
}

/* flag the Blue Card submission in the Grading Table */
if (!document.getElementsByClassName('gradingtable')[0]) {
   /* do nothing */ 
} else {
    var table = document.getElementsByClassName('gradingtable')[0];
     var tbody = table.getElementsByTagName('tbody')[0];

     var comments = tbody.getElementsByClassName('c10');
         for (var i=0, len=comments.length; i<len; i++){
             if (comments[i].innerHTML.includes('Comments')){
              thisRow = comments[i].parentNode;
            thisRow.style.backgroundColor = '#ffffcc';
            statusCell = thisRow.getElementsByClassName("c5")[0];
             statusCell.innerHTML += ' <div style="background-color: #99bbff">Student has added comments, please review</div>';
            }
        }
    }

注意:代码按原样提供&#39;没有任何承诺使其符合目的,也没有任何承诺维护或支持。

also posted on our team blog

更新:要使其在Internet Explorer 11中正常运行,我必须进行以下调整:

/* flag the Blue Card submission in the Grading Table */
if (!document.getElementsByClassName('gradingtable')[0]) {
   /* do nothing */ 
} else {
     var table = document.getElementsByClassName('gradingtable')[0];
     var tbody = table.getElementsByTagName('tbody')[0];
     var comments = tbody.getElementsByClassName('c10');
         for (var i=0, len=comments.length; i<len; i++){
             if (comments[i].innerText.search('Comments') > -1){
            thisRow = comments[i].parentNode; 
           alert('thisRow ' + thisRow);
            thisRow.style.backgroundColor = '#ffffcc';
            nameLink = thisRow.getElementsByTagName("a")[1]; 
            nameLink.insertAdjacentHTML('afterend', ' <div style="background-color: #99bbff">Student has added comments, please review</div>');
             }
        }
    }

它还需要以下CSS来制作&#34;添加蓝卡&#34;按钮蓝色:

.bluecard {
  background-color: rgba(0, 0, 255, 1) !important;
  color: #fff;
  padding: 6px;
  border-radius: 6px;
}

这是因为includes() methodinnerHTML() method在IE中不起作用。