From 8acb1bf351a080e2655fcab1085089acf91931b8 Mon Sep 17 00:00:00 2001 From: sam marshall Date: Mon, 14 May 2012 14:10:12 +0100 Subject: [PATCH] OU wiki: Add facility to hide annotations (accessibility) #3383 (#3329) --- hideannotations.php | 45 ++++++++++++++++++++++++++++++++++++ lang/en/ouwiki.php | 6 ++++- locallib.php | 2 ++ renderer.php | 31 ++++++++++++++++++------- styles.css | 28 +++++++++++++++++++---- view.js | 56 +++++++++++++++++++++++++++++++++++++-------- view.php | 4 +++- 7 files changed, 149 insertions(+), 23 deletions(-) create mode 100644 hideannotations.php diff --git a/hideannotations.php b/hideannotations.php new file mode 100644 index 0000000..1b94c79 --- /dev/null +++ b/hideannotations.php @@ -0,0 +1,45 @@ +. + +/** + * Toggles the controls whether to load HQ videos or SQ videos for this user + * @package mod_ouwiki + * @copyright 2012 The Open University + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require('../../config.php'); +require($CFG->dirroot . '/mod/ouwiki/basicpage.php'); + +require_login(); +require_sesskey(); + +$hide = required_param('hide', PARAM_INT); + +if ($hide) { + set_user_preference(OUWIKI_PREF_HIDEANNOTATIONS, 1); +} else { + unset_user_preference(OUWIKI_PREF_HIDEANNOTATIONS); +} + +// If this is the AJAX version, stop processing now. +if (optional_param('ajax', 0, PARAM_INT)) { + exit; +} + +// Otherwise redirect back. +redirect('view.php?' .ouwiki_display_wiki_parameters( + $pagename, $subwiki, $cm, OUWIKI_PARAMS_URL)); diff --git a/lang/en/ouwiki.php b/lang/en/ouwiki.php index ca5b40c..801d512 100644 --- a/lang/en/ouwiki.php +++ b/lang/en/ouwiki.php @@ -490,4 +490,8 @@ they are very determined. They could edit a page and wait until the timeout is about to expire before saving changes then very quickly editing it again.

'; -$string['endannotation'] = 'End of annotation'; \ No newline at end of file +$string['endannotation'] = 'End of annotation'; +$string['expandallannotations'] = 'Expand annotations'; +$string['collapseallannotations'] = 'Collapse annotations'; +$string['showannotationicons'] = 'Show annotations'; +$string['hideannotationicons'] = 'Hide annotations'; diff --git a/locallib.php b/locallib.php index ca26ed7..0dc9e4c 100644 --- a/locallib.php +++ b/locallib.php @@ -74,6 +74,8 @@ define('OUWIKI_USER_PARTICIPATION', 2); define('OUWIKI_PARTICIPATION_PERPAGE', 100); +// User preference +define('OUWIKI_PREF_HIDEANNOTATIONS', 'ouwiki_hide_annotations'); function ouwiki_dberror($error, $source = null) { if (!$source) { diff --git a/renderer.php b/renderer.php index 4858afb..02c1a20 100644 --- a/renderer.php +++ b/renderer.php @@ -35,10 +35,11 @@ class mod_ouwiki_renderer extends plugin_renderer_base { * we can make links * @param object $cm Course-module object (again for making links) * @param object $pageversion Data from page and version tables. + * @param bool $hideannotations If true, adds extra class to hide annotations * @return string HTML content for page */ public function ouwiki_print_page($subwiki, $cm, $pageversion, $gewgaws = null, - $page = 'history', $showwordcount = 0) { + $page = 'history', $showwordcount = 0, $hideannotations = false) { $output = ''; $modcontext = get_context_instance(CONTEXT_MODULE, $cm->id); @@ -79,7 +80,8 @@ public function ouwiki_print_page($subwiki, $cm, $pageversion, $gewgaws = null, $files = $fs->get_area_files($modcontext->id, 'mod_ouwiki', 'attachment', $pageversion->versionid, "timemodified", false); - $output .= html_writer::start_tag('div', array('class' => 'ouwiki-content')); + $output .= html_writer::start_tag('div', array('class' => 'ouwiki-content' . + ($hideannotations ? ' ouwiki-hide-annotations' : ''))); $output .= html_writer::start_tag('div', array('class' => 'ouw_topheading')); $output .= html_writer::start_tag('div', array('class' => 'ouw_heading')); $output .= html_writer::tag('h1', format_string($title), @@ -265,7 +267,7 @@ public function render_heading_bit($headingnumber, $pagename, $subwiki, $cm, 'class' => 'ouw_annotate')); } - // 'Show all' annotation controls + // 'Expand/collapse all' and 'Show/hide all' annotation controls if ($annotations != false) { $orphancount = 0; foreach ($annotations as $annotation) { @@ -274,16 +276,29 @@ public function render_heading_bit($headingnumber, $pagename, $subwiki, $cm, } } if (count($annotations) > $orphancount) { - $output .= html_writer::start_tag('span', array('id' => 'showhideannotations')); - $output .= ' '.html_writer::tag('a', 'Show all annotations', + // Show and hide annotation icon links. Visibility controlled by CSS. + $output .= html_writer::start_tag('span', array('id' => 'showhideannotationicons')); + $output .= ' '.html_writer::tag('a', get_string('showannotationicons', 'ouwiki'), + array('href' => 'hideannotations.php?hide=0&' . ouwiki_display_wiki_parameters( + $pagename, $subwiki, $cm, OUWIKI_PARAMS_URL) . '&sesskey=' . sesskey(), + 'id' => 'showannotationicons')); + $output .= html_writer::tag('a', get_string('hideannotationicons', 'ouwiki'), + array('href' => 'hideannotations.php?hide=1&' . ouwiki_display_wiki_parameters( + $pagename, $subwiki, $cm, OUWIKI_PARAMS_URL) . '&sesskey=' . sesskey(), + 'id' => 'hideannotationicons')); + $output .= html_writer::end_tag('span'); + + // Expand and collapse annotations links. + $output .= html_writer::start_tag('span', array('id' => 'expandcollapseannotations')); + $output .= ' '.html_writer::tag('a', get_string('expandallannotations', 'ouwiki'), array( 'href' => 'javascript:ouwikiShowAllAnnotations("block")', - 'id' => 'showallannotations' + 'id' => 'expandallannotations' )); - $output .= html_writer::tag('a', 'Hide all annotations', + $output .= html_writer::tag('a', get_string('collapseallannotations', 'ouwiki'), array( 'href' => 'javascript:ouwikiShowAllAnnotations("none")', - 'id' => 'hideallannotations' + 'id' => 'collapseallannotations' )); $output .= html_writer::end_tag('span'); } diff --git a/styles.css b/styles.css index 556a8c0..d4bc5b2 100644 --- a/styles.css +++ b/styles.css @@ -352,10 +352,28 @@ body.jsenabled #ouwiki_belowtabs_annotate_nojs { #page-mod-ouwiki-view .ouw_editsection, #page-mod-ouwiki-view .ouw_annotate, #page-mod-ouwiki-view .ouw_editpage, -#page-mod-ouwiki-view #showhideannotations { +#page-mod-ouwiki-view #expandcollapseannotations, +#page-mod-ouwiki-view #showhideannotationicons { margin-right:1em; } +/* Annotation icon show/hide link logic */ +#page-mod-ouwiki-view .ouwiki-hide-annotations #hideannotationicons { + display: none; +} +#page-mod-ouwiki-view #showannotationicons { + display: none; +} +#page-mod-ouwiki-view .ouwiki-hide-annotations #showannotationicons { + display: inline; +} +#page-mod-ouwiki-view .ouwiki-hide-annotations .ouwiki-annotation-tag { + display: none; +} +#page-mod-ouwiki-view.jsenabled .ouwiki-hide-annotations #expandcollapseannotations { + display: none; +} + .ouwiki_content h1, .ouwiki_content h2 { font-size:1.5em; @@ -683,9 +701,11 @@ a.ouwiki_noshow:link,a.ouwiki_noshow:visited { .ouwiki-annotation-marker:hover{background-color:#99ccff;} -#showhideannotations {display:none;} -#showallannotations {display:inline;} -#hideallannotations {display:none;} +#page-mod-ouwiki-view #expandcollapseannotations {display:none;} +#page-mod-ouwiki-view.jsenabled #expandcollapseannotations {display:inline;} +#page-mod-ouwiki-view #expandallannotations {display:inline;} +#page-mod-ouwiki-view #collapseallannotations {display:none;} + #ouwiki_addannotation label { display:block; diff --git a/view.js b/view.js index 213cd35..17fdff3 100644 --- a/view.js +++ b/view.js @@ -147,17 +147,14 @@ function ouwikiShowAllAnnotations(action) { } function ouwikiSwapAnnotationUrl(action){ - var showurl = document.getElementById("showhideannotations"); - var show = document.getElementById("showallannotations"); - var hide = document.getElementById("hideallannotations"); + var show = document.getElementById("expandallannotations"); + var hide = document.getElementById("collapseallannotations"); if (action == "hide") { show.style.display = "none"; hide.style.display = "inline"; } else if (action == "show") { show.style.display = "inline"; hide.style.display = "none"; - } else if (action == "showall") { - showurl.style.display = "inline"; } } @@ -209,19 +206,60 @@ function ouwikiOnLoad() { function init() { ouwikiShowAllAnnotations("none"); - ouwikiSwapAnnotationUrl("showall"); annospans = YAHOO.util.Dom.getElementsByClassName('ouwiki-annotation-tag', 'span'); for (var span = 0; span < annospans.length; span++) { setupspans(annospans[span]); } + setupAnnotationIcons(); } M.mod_ouwiki = { + Y : null, + /** * Main init function called from HTML. */ - init : function() { + init : function(Y) { + this.Y = Y; + // TODO: Change wiki JavaScript to actually use Moodle 2 style. At - // present this is only here in order to pass language strings. + // present this is mostly here in order to pass language strings. + + // Turn the annotation icon show/hide links to use JS + Y.one('#showannotationicons').on('click', function(e) { + e.preventDefault(); + M.mod_ouwiki.show_annotation_icons(true); + }); + Y.one('#hideannotationicons').on('click', function(e) { + e.preventDefault(); + M.mod_ouwiki.show_annotation_icons(false); + }); + }, + + /** + * Called when user selects to show or hide the annotations. Does two + * things: makes AJAX call to set the option, and adds the class to hide + * the icons. + * @param show If true, shows icons + */ + show_annotation_icons : function(show) { + // Set or remove the class + var container = this.Y.one('.ouwiki-content'); + var hideclass = 'ouwiki-hide-annotations'; + if (show) { + container.removeClass(hideclass); + } else { + console.log(container); + container.addClass(hideclass); + } + + // Get URL from original link + var url = this.Y.one(show ? '#showannotationicons' : '#hideannotationicons').get('href'); + + // Add on the 'ajax' marker + url += '&ajax=1'; + + // Request it with AJAX, ignoring result + this.Y.io(url); } -} +}; diff --git a/view.php b/view.php index 9e8948e..ff26148 100644 --- a/view.php +++ b/view.php @@ -73,7 +73,9 @@ ''; } // Print page content - $data = $ouwikioutput->ouwiki_print_page($subwiki, $cm, $pageversion, true, 'view', $ouwiki->enablewordcount); + $hideannotations = get_user_preferences(OUWIKI_PREF_HIDEANNOTATIONS, 0); + $data = $ouwikioutput->ouwiki_print_page($subwiki, $cm, $pageversion, true, 'view', + $ouwiki->enablewordcount, (bool)$hideannotations); echo $data[0]; if ($subwiki->canedit && $pageversion->locked != '1') { print ouwiki_display_create_page_form($subwiki, $cm, $pageversion);