Commit ea5a01fb authored by Sam Hemelryk's avatar Sam Hemelryk
Browse files

MDL-39814 frontend: pre-integration fixes:

* Fixed IE8 display of icons.
* Fixed blocks using course renderer.
* Fixed behat tests.
* codecheckers fixes
* Removed alt from icons with descriptive text
* Tweaked actionmenu initialisation for performance
parent 10fc1569
......@@ -59,7 +59,8 @@ class block_site_main_menu extends block_list {
return $this->content;
}
/// slow & hacky editing mode
// Slow & hacky editing mode.
/** @var core_course_renderer $courserenderer */
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
course_create_sections_if_missing($course, 0);
......@@ -72,7 +73,7 @@ class block_site_main_menu extends block_list {
$strcancel= get_string('cancel');
$stractivityclipboard = $USER->activitycopyname;
}
/// Casting $course->modinfo to string prevents one notice when the field is null
// Casting $course->modinfo to string prevents one notice when the field is null.
$editbuttons = '';
if ($ismoving) {
......@@ -90,7 +91,7 @@ class block_site_main_menu extends block_list {
if (!$ismoving) {
$actions = course_get_cm_edit_actions($mod, -1);
$editbuttons = html_writer::tag('div',
$courserenderer->course_section_cm_edit_actions($actions),
$courserenderer->course_section_cm_edit_actions($actions, $mod),
array('class' => 'buttons'));
} else {
$editbuttons = '';
......
......@@ -62,7 +62,8 @@ class block_social_activities extends block_list {
}
/// slow & hacky editing mode
// Slow & hacky editing mode.
/** @var core_course_renderer $courserenderer */
$courserenderer = $this->page->get_renderer('core', 'course');
$ismoving = ismoving($course->id);
$modinfo = get_fast_modinfo($course);
......@@ -74,7 +75,7 @@ class block_social_activities extends block_list {
$strcancel= get_string('cancel');
$stractivityclipboard = $USER->activitycopyname;
}
/// Casting $course->modinfo to string prevents one notice when the field is null
// Casting $course->modinfo to string prevents one notice when the field is null.
$editbuttons = '';
if ($ismoving) {
......@@ -92,7 +93,7 @@ class block_social_activities extends block_list {
if (!$ismoving) {
$actions = course_get_cm_edit_actions($mod, -1);
$editbuttons = '<br />'.
$courserenderer->course_section_cm_edit_actions($actions);
$courserenderer->course_section_cm_edit_actions($actions, $mod);
} else {
$editbuttons = '';
}
......
......@@ -744,11 +744,11 @@ class dndupload_ajax_processor {
$resp->content = $mod->get_content();
$resp->elementid = 'module-'.$mod->id;
$actions = course_get_cm_edit_actions($mod, 0, $mod->sectionnum);
$resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions);
$resp->commands = ' '. $courserenderer->course_section_cm_edit_actions($actions, $mod);
$resp->onclick = $mod->get_on_click();
$resp->visible = $mod->visible;
// if using groupings, then display grouping name
// If using groupings, then display grouping name.
if (!empty($mod->groupingid) && has_capability('moodle/course:managegroups', $this->context)) {
$groupings = groups_get_all_groupings($this->course->id);
$resp->groupingname = format_string($groupings[$mod->groupingid]->name);
......
@core @core_course @sam
@core @core_course
Feature: Course activity controls works as expected
In order to manage my course's activities
As a teacher
......
......@@ -919,27 +919,27 @@ class action_link implements renderable {
/**
* @var moodle_url Href url
*/
var $url;
public $url;
/**
* @var string Link text HTML fragment
*/
var $text;
public $text;
/**
* @var array HTML attributes
*/
var $attributes;
public $attributes;
/**
* @var array List of actions attached to link
*/
var $actions;
public $actions;
/**
* @var pix_icon Optional pix icon to render with the link
*/
var $icon;
public $icon;
/**
* Constructor
......@@ -3071,13 +3071,13 @@ class action_menu implements renderable {
protected $instance = 0;
/**
* An array of primary actions. Please use {@see action_menu::add_primary_action()} to add actions.
* An array of primary actions. Please use {@link action_menu::add_primary_action()} to add actions.
* @var array
*/
protected $primaryactions = array();
/**
* An array of secondary actions. Please use {@see action_menu::add_secondary_action()} to add actions.
* An array of secondary actions. Please use {@link action_menu::add_secondary_action()} to add actions.
* @var array
*/
protected $secondaryactions = array();
......@@ -3128,6 +3128,7 @@ class action_menu implements renderable {
'aria-labelledby' => 'action-menu-toggle-'.$this->instance,
'role' => 'menu'
);
$this->set_alignment(self::TR, self::BR);
foreach ($actions as $action) {
$this->add($action);
}
......@@ -3150,7 +3151,7 @@ class action_menu implements renderable {
/**
* Adds an action to this action menu.
*
* @param $action
* @param action_menu_link|pix_icon|string $action
*/
public function add($action) {
if ($action instanceof action_menu_link) {
......@@ -3243,8 +3244,15 @@ class action_menu implements renderable {
* @param int $button One of action_menu::TL, action_menu::TR, action_menu::BL, action_menu::BR.
*/
public function set_alignment($dialogue, $button) {
if (isset($this->attributessecondary['data-align'])) {
// We've already got one set, lets remove the old class so as to avoid troubles.
$class = $this->attributessecondary['class'];
$search = 'align-'.$this->attributessecondary['data-align'];
$this->attributessecondary['class'] = str_replace($search, '', $class);
}
$align = $this->get_align_string($dialogue) . '-' . $this->get_align_string($button);
$this->attributessecondary['data-align'] = $align;
$this->attributessecondary['class'] .= ' align-'.$align;
}
/**
......@@ -3255,11 +3263,16 @@ class action_menu implements renderable {
*/
protected function get_align_string($align) {
switch ($align) {
case self::TL : return 'tl';
case self::TR : return 'tr';
case self::BL : return 'bl';
case self::BR : return 'br';
default : return 'tl';
case self::TL :
return 'tl';
case self::TR :
return 'tr';
case self::BL :
return 'bl';
case self::BR :
return 'br';
default :
return 'tl';
}
}
......
......@@ -1098,39 +1098,42 @@ class core_renderer extends renderer_base {
*/
protected function render_action_menu_link(action_menu_link $action) {
$iconrendered = false;
$comparetoalt = '';
$text = '';
if ($action->icon) {
$icon = $action->icon;
if ($action->primary) {
$action->attributes['title'] = $action->text;
}
$text .= $this->render($icon);
$iconrendered = true;
}
if (!$iconrendered || $action->primary === false) {
if (!$action->icon || $action->primary === false) {
$text .= html_writer::start_tag('span', array('class'=>'menu-action-text'));
if ($action->text instanceof renderable) {
$text .= $this->render($action->text);
} else {
$text .= $action->text;
$comparetoalt = $action->text;
}
$text .= html_writer::end_tag('span');
}
$icon = '';
if ($action->icon) {
$icon = $action->icon;
if ($action->primary) {
$action->attributes['title'] = $action->text;
}
if ($icon->attributes['alt'] === $comparetoalt) {
$icon->attributes['alt'] = ' ';
}
$icon = $this->render($icon);
}
// A disabled link is rendered as formatted text.
if (!empty($action->attributes['disabled'])) {
// Do not use div here due to nesting restriction in xhtml strict.
return html_writer::tag('span', $text, array('class'=>'currentlink', 'role' => 'menuitem'));
return html_writer::tag('span', $icon.$text, array('class'=>'currentlink', 'role' => 'menuitem'));
}
$attributes = $action->attributes;
unset($action->attributes['disabled']);
$attributes['href'] = $action->url;
return html_writer::tag('a', $text, $attributes);
return html_writer::tag('a', $icon.$text, $attributes);
}
/**
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
......@@ -66,13 +66,16 @@ ACTIONMENU.prototype = {
var defaultalign = this.get('align').join('-');
Y.all(SELECTOR.MENU).each(function() {
var menucontent = this.one(SELECTOR.MENUCONTENT),
toggle = this.one(SELECTOR.TOGGLE),
align = menucontent.getData('align') || defaultalign;
align;
if (!menucontent) {
return false;
}
toggle.set('aria-haspopup', true);
menucontent.set('aria-hidden', true).addClass('align-'+align);
align = menucontent.getData('align') || defaultalign;
this.one(SELECTOR.TOGGLE).set('aria-haspopup', true);
menucontent.set('aria-hidden', true);
if (!menucontent.hasClass('align-'+align)) {
menucontent.addClass('align-'+align);
}
if (menucontent.hasChildNodes()) {
this.setAttribute('data-enhanced', '1');
}
......@@ -174,7 +177,6 @@ ACTIONMENU.prototype = {
newleft = null,
newtop = null;
if (selector) {
selector = node.ancestor(selector);
}
......@@ -272,4 +274,4 @@ M.core.actionmenu = M.core.actionmenu || {};
*/
M.core.actionmenu.init = M.core.actionmenu.init || function(params) {
M.core.actionmenu.instance = M.core.actionmenu.instance || new ACTIONMENU(params);
};
};
\ No newline at end of file
......@@ -597,6 +597,7 @@ span.editinstructions {
}
.section .activity .moodle-actionmenu .iconsmall {
max-width: none !important; /** reset sets 100% !important which breaks on IE8 without this !important */
width:16px;
height:16px;
width:1rem;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment