MDL-16263 A way for students to flag/bookmark, particular questions during a quiz...
[moodle.git] / question / qengine.js
1 // This script, and the YUI libraries that it needs, are inluded by
2 // the require_js calls in get_html_head_contributions in lib/questionlib.php.
4 question_flag_changer = {
5     init_flag: function(checkboxid, postdata) {
6         var checkbox = document.getElementById(checkboxid);
7         checkbox.ajaxpostdata = postdata;
8         checkbox.className += ' jsworking';
9         question_flag_changer.update_image(checkbox);
10         YAHOO.util.Event.addListener(checkbox, 'change', this.checkbox_state_change);
11         YAHOO.util.Event.addListener(checkbox, 'focus', 'blur()');
12     },
14     checkbox_state_change: function(e) {
15         var checkbox = e.target ? e.target : e.srcElement;
16         question_flag_changer.update_image(checkbox);
17         var postdata = checkbox.ajaxpostdata
18         if (checkbox.checked) {
19             postdata += '&newstate=1'
20         } else {
21             postdata += '&newstate=0'
22         }
23         YAHOO.util.Connect.asyncRequest('POST', qengine_config.wwwroot + '/question/toggleflag.php', null, postdata);
24     },
26     update_image: function(checkbox) {
27         var img = document.getElementById(checkbox.id + 'img');
28         if (checkbox.checked) {
29             img.src = qengine_config.pixpath + '/i/flagged.png';
30             img.alt = qengine_config.flaggedalt;
31             img.title = qengine_config.unflagtooltip;
32         } else {
33             img.src = qengine_config.pixpath + '/i/unflagged.png';
34             img.alt = qengine_config.unflaggedalt;
35             img.title = qengine_config.flagtooltip;
36         }
37     }
38 };