MDL-39964 report_progress: don't browser sniff for SVG support

Use feature detection, its more robust and better practice.
This commit is contained in:
Dan Poltawski 2013-05-31 14:33:59 +08:00
parent b6f8a93642
commit 26c4242c68
2 changed files with 11 additions and 7 deletions

View file

@ -146,8 +146,6 @@ if ($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are
$line="\n"; $line="\n";
} }
} else { } else {
// Use SVG to draw sideways text if supported
$svgcleverness = can_use_rotated_text();
// Navigation and header // Navigation and header
$strreports = get_string("reports"); $strreports = get_string("reports");
@ -156,11 +154,8 @@ if ($csv && $grandtotal && count($activities)>0) { // Only show CSV if there are
$PAGE->set_title($strcompletion); $PAGE->set_title($strcompletion);
$PAGE->set_heading($course->fullname); $PAGE->set_heading($course->fullname);
echo $OUTPUT->header(); echo $OUTPUT->header();
$PAGE->requires->js('/report/progress/textrotate.js');
if ($svgcleverness) { $PAGE->requires->js_function_call('textrotate_init', null, true);
$PAGE->requires->js('/report/progress/textrotate.js');
$PAGE->requires->js_function_call('textrotate_init', null, true);
}
// Handle groups (if enabled) // Handle groups (if enabled)
groups_print_course_menu($course,$CFG->wwwroot.'/report/progress/?course='.$course->id); groups_print_course_menu($course,$CFG->wwwroot.'/report/progress/?course='.$course->id);

View file

@ -48,7 +48,16 @@ function textrotate_make_svg(el)
el.parentNode.removeChild(el); el.parentNode.removeChild(el);
} }
function browser_supports_svg() {
return document.implementation.hasFeature("http://www.w3.org/TR/SVG11/feature#BasicStructure", "1.1");
}
function textrotate_init() { function textrotate_init() {
if (!browser_supports_svg()) {
// Feature detect, else bail.
return;
}
YUI().use('yui2-dom', function(Y) { YUI().use('yui2-dom', function(Y) {
var elements= Y.YUI2.util.Dom.getElementsByClassName('completion-activityname', 'span'); var elements= Y.YUI2.util.Dom.getElementsByClassName('completion-activityname', 'span');
for(var i=0;i<elements.length;i++) for(var i=0;i<elements.length;i++)