Skip to content

Commit

Permalink
MDL-28471 make the question flag smaller, and give it a label.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wale Olujide authored and timhunt committed Jul 26, 2011
1 parent 6f05796 commit 474ee93
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lang/en/question.php
Original file line number Diff line number Diff line change
Expand Up @@ -399,3 +399,5 @@
$string['withselected'] = 'With selected';
$string['xoutofmax'] = '{$a->mark} out of {$a->max}';
$string['yougotnright'] = 'You have correctly selected {$a->num}.';
$string['clickflag'] = 'Flag question';
$string['clickunflag'] = 'Unflag question';
6 changes: 5 additions & 1 deletion question/engine/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -632,20 +632,24 @@ public static function initialise_js() {
'requires' => array('base', 'dom', 'event-delegate', 'io-base'),
);
$actionurl = $CFG->wwwroot . '/question/toggleflag.php';
$fltext = array(0 => get_string('clickflag', 'question'),
1 => get_string('clickunflag', 'question'));
$flagattributes = array(
0 => array(
'src' => $OUTPUT->pix_url('i/unflagged') . '',
'title' => get_string('clicktoflag', 'question'),
'alt' => get_string('notflagged', 'question'),
// 'text' => get_string('clickflag', 'question'),
),
1 => array(
'src' => $OUTPUT->pix_url('i/flagged') . '',
'title' => get_string('clicktounflag', 'question'),
'alt' => get_string('flagged', 'question'),
// 'text' => get_string('clickunflag', 'question'),
),
);
$PAGE->requires->js_init_call('M.core_question_flags.init',
array($actionurl, $flagattributes), false, $module);
array($actionurl, $flagattributes, $fltext), false, $module);
$done = true;
}
}
Expand Down
24 changes: 22 additions & 2 deletions question/flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@
M.core_question_flags = {
flagattributes: null,
actionurl: null,
fltext: null,
listeners: [],

init: function(Y, actionurl, flagattributes) {
init: function(Y, actionurl, flagattributes, fltext) {
M.core_question_flags.flagattributes = flagattributes;
M.core_question_flags.actionurl = actionurl;
M.core_question_flags.fltext = fltext;

Y.all('div.questionflag').each(function(flagdiv, i) {
var checkbox = flagdiv.one('input[type=checkbox]');
Expand All @@ -49,10 +51,18 @@ M.core_question_flags = {
var image = Y.Node.create('<input type="image" class="questionflagimage" />');
M.core_question_flags.update_flag(input, image);

// Create flag text
var flstatus = input.get('value');
var txt = M.core_question_flags.fltext[flstatus];
var flagtext = Y.Node.create('<span class="flag-text">');
flagtext.addClass(txt);
flagtext.append(txt);

checkbox.remove();
flagdiv.one('label').remove();
flagdiv.append(input);
flagdiv.append(image);
flagdiv.append(flagtext);
});

Y.delegate('click', function(e) {
Expand All @@ -69,7 +79,17 @@ M.core_question_flags = {
},

update_flag: function(input, image) {
image.setAttrs(M.core_question_flags.flagattributes[input.get('value')]);

YUI().use('node', function (Y) {
image.setAttrs(M.core_question_flags.flagattributes[input.get('value')]);
// get flag text which is next to image element
var element = image.next();
// if element update its text
if(element){
element.set('innerText', M.core_question_flags.fltext[input.get('value')]);
}
});

},

add_listener: function(listener) {
Expand Down

0 comments on commit 474ee93

Please sign in to comment.