Skip to content

Commit

Permalink
OU wiki: Add facility to hide annotations (accessibility) #3383 (#3329)
Browse files Browse the repository at this point in the history
  • Loading branch information
sammarshallou committed May 15, 2012
1 parent aed9568 commit 8acb1bf
Show file tree
Hide file tree
Showing 7 changed files with 149 additions and 23 deletions.
45 changes: 45 additions & 0 deletions hideannotations.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.

/**
* 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));
6 changes: 5 additions & 1 deletion lang/en/ouwiki.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
</p>';
$string['endannotation'] = 'End of annotation';
$string['endannotation'] = 'End of annotation';
$string['expandallannotations'] = 'Expand annotations';
$string['collapseallannotations'] = 'Collapse annotations';
$string['showannotationicons'] = 'Show annotations';
$string['hideannotationicons'] = 'Hide annotations';
2 changes: 2 additions & 0 deletions locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 23 additions & 8 deletions renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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) {
Expand All @@ -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');
}
Expand Down
28 changes: 24 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
56 changes: 47 additions & 9 deletions view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
}

Expand Down Expand Up @@ -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);
}
}
};
4 changes: 3 additions & 1 deletion view.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@
'</div>';
}
// 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);
Expand Down

0 comments on commit 8acb1bf

Please sign in to comment.