From 474ee9389abd3cd2d75b67382ebb5f7a20c09077 Mon Sep 17 00:00:00 2001 From: Wale Olujide Date: Tue, 26 Jul 2011 12:07:24 +0100 Subject: [PATCH] MDL-28471 make the question flag smaller, and give it a label. --- lang/en/question.php | 2 ++ question/engine/lib.php | 6 +++++- question/flags.js | 24 ++++++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lang/en/question.php b/lang/en/question.php index 13e17ec6b8e..c1c7947e5b9 100644 --- a/lang/en/question.php +++ b/lang/en/question.php @@ -399,3 +399,5 @@ $string['whethercorrect'] = 'Whether correct'; $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'; diff --git a/question/engine/lib.php b/question/engine/lib.php index 04612977b25..17d3c1f7ea7 100644 --- a/question/engine/lib.php +++ b/question/engine/lib.php @@ -632,20 +632,24 @@ abstract class question_flags { '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; } } diff --git a/question/flags.js b/question/flags.js index 25edaa57a9d..d587a7d1c17 100644 --- a/question/flags.js +++ b/question/flags.js @@ -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]'); @@ -49,10 +51,18 @@ M.core_question_flags = { var image = Y.Node.create(''); 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(''); + 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) { @@ -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) { -- 2.43.0