mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
MDL-21235 converted help cions to final render outputlib api
This commit is contained in:
parent
5d0c95a5ac
commit
bf11293a94
@ -1248,6 +1248,11 @@ function init_help_icons() {
|
||||
zIndex: '1000'
|
||||
});
|
||||
|
||||
// remove all titles, they would obscure the YUI tooltip
|
||||
for (var i = 0; i < iconspans.length; i++) {
|
||||
iconspans[i].getElementsByTagName('a')[0].title = '';
|
||||
}
|
||||
|
||||
tooltip.contextTriggerEvent.subscribe(
|
||||
function(type, args) {
|
||||
// Fetch help page contents asynchronously
|
||||
@ -1261,8 +1266,6 @@ function init_help_icons() {
|
||||
context.title = '';
|
||||
|
||||
var link = context.getElementsByTagName('a')[0];
|
||||
link.title = '';
|
||||
YAHOO.util.Dom.getElementsByClassName('iconhelp', 'img', link)[0].title = '';
|
||||
var thistooltip = this;
|
||||
var ajaxurl = link.href + '&fortooltip=1';
|
||||
|
||||
|
@ -45,7 +45,7 @@ interface renderable {
|
||||
|
||||
|
||||
/**
|
||||
* Component representing a user picture.
|
||||
* Data structure representing a user picture.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault, 2010 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
@ -139,6 +139,55 @@ class user_picture implements renderable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Data structure representing a help icon.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault, 2010 Petr Skoda
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class help_icon implements renderable {
|
||||
/**
|
||||
* @var string $page name of help page
|
||||
*/
|
||||
public $helppage;
|
||||
/**
|
||||
* @var string $title A descriptive text for title tooltip
|
||||
*/
|
||||
public $title = '';
|
||||
/**
|
||||
* @var string $component Component name, the same as in get_string()
|
||||
*/
|
||||
public $component = 'moodle';
|
||||
/**
|
||||
* @var string $linktext Extra descriptive text next to the icon
|
||||
*/
|
||||
public $linktext = '';
|
||||
|
||||
/**
|
||||
* Constructor: sets up the other components in case they are needed
|
||||
* @param string $page The keyword that defines a help page
|
||||
* @param string $title A descriptive text for accesibility only
|
||||
* @param string $component
|
||||
* @param bool $linktext add extra text to icon
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($helppage, $title, $component = 'moodle') {
|
||||
if (empty($title)) {
|
||||
throw new coding_exception('A help_icon object requires a $text parameter');
|
||||
}
|
||||
if (empty($helppage)) {
|
||||
throw new coding_exception('A help_icon object requires a $helppage parameter');
|
||||
}
|
||||
|
||||
$this->helppage = $helppage;
|
||||
$this->title = $title;
|
||||
$this->component = $component;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// ==== HTML writer and helper classes, will be probably moved elsewhere ======
|
||||
|
||||
|
||||
@ -197,7 +246,9 @@ class html_writer {
|
||||
if (is_array($value)) {
|
||||
debugging("Passed an array for the HTML attribute $name", DEBUG_DEVELOPER);
|
||||
}
|
||||
|
||||
if ($value instanceof moodle_url) {
|
||||
return ' ' . $name . '="' . $value->out() . '"';
|
||||
}
|
||||
$value = trim($value);
|
||||
if ($value == HTML_ATTR_EMPTY) {
|
||||
return ' ' . $name . '=""';
|
||||
@ -2100,96 +2151,6 @@ class moodle_paging_bar extends html_component {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Component representing a help icon.
|
||||
*
|
||||
* @copyright 2009 Nicolas Connault
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
* @since Moodle 2.0
|
||||
*/
|
||||
class help_icon extends html_image {
|
||||
public $page;
|
||||
/**
|
||||
* @var string $module Which module is the page defined in
|
||||
*/
|
||||
/**
|
||||
* @var string $text A descriptive text
|
||||
*/
|
||||
public $text;
|
||||
/**
|
||||
* @var string $page The keyword that defines a help page
|
||||
*/
|
||||
public $component = 'moodle';
|
||||
/**
|
||||
* @var boolean $linktext Whether or not to show text next to the icon
|
||||
*/
|
||||
public $linktext = false;
|
||||
|
||||
/**
|
||||
* @var html_link $link A html_link object that will hold the URL info
|
||||
*/
|
||||
public $link;
|
||||
|
||||
/**
|
||||
* Constructor: sets up the other components in case they are needed
|
||||
* @param string $page The keyword that defines a help page
|
||||
* @param string $text A descriptive text
|
||||
* @param string $component
|
||||
* @param bool $linktext add extra text to icon
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($helppage, $text, $component='moodle', $linktext=false) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($helppage)) {
|
||||
throw new coding_exception('A help_icon object requires a $helppage parameter');
|
||||
}
|
||||
|
||||
if (empty($text)) {
|
||||
throw new coding_exception('A help_icon object requires a $text parameter');
|
||||
}
|
||||
|
||||
parent::__construct(null, array('class'=>'iconhelp'));
|
||||
|
||||
$this->helppage = $helppage;
|
||||
$this->text = $text;
|
||||
$this->component = $component;
|
||||
$this->linktext = $linktext;
|
||||
|
||||
$this->link = new html_link();
|
||||
$this->link->url = new moodle_url($CFG->wwwroot.'/help.php', array('module' => $this->component, 'file' => $this->helppage .'.html'));
|
||||
// Warn users about new window for Accessibility
|
||||
}
|
||||
|
||||
/**
|
||||
* @see lib/html_component#prepare()
|
||||
* @return void
|
||||
*/
|
||||
public function prepare(renderer_base $output, moodle_page $page, $target) {
|
||||
global $CFG;
|
||||
|
||||
if (empty($this->link->title)) {
|
||||
$this->link->title = get_string('helpprefix2', '', trim($this->text, ". \t")) .' ('.get_string('newwindow').')';
|
||||
}
|
||||
|
||||
if (empty($this->src)) {
|
||||
$this->src = $output->pix_url('help');
|
||||
}
|
||||
|
||||
if ($this->linktext) {
|
||||
$this->image->alt = get_string('helpwiththis');
|
||||
} else {
|
||||
$this->image->alt = $this->text;
|
||||
}
|
||||
|
||||
$popup = new popup_action('click', $this->link->url);
|
||||
$this->link->add_action($popup);
|
||||
|
||||
parent::prepare($output, $page, $target);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This class represents how a block appears on a page.
|
||||
*
|
||||
|
@ -1157,23 +1157,61 @@ class core_renderer extends renderer_base {
|
||||
* Print a help icon.
|
||||
*
|
||||
* @param string $page The keyword that defines a help page
|
||||
* @param string $text A descriptive text
|
||||
* @param string $title A descriptive text for accessibility only
|
||||
* @param string $component component name
|
||||
* @param bool $linktext show extra descriptive text
|
||||
|
||||
* @return string HTML fragment
|
||||
* @param string|bool $linktext true means use $title as link text, string means link text value
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
public function help_icon($helppage, $text=null, $component='moodle', $linktext=false) {
|
||||
$icon = new help_icon($helppage, $text, $component, $linktext);
|
||||
public function help_icon($helppage, $title, $component = 'moodle', $linktext='') {
|
||||
$icon = new help_icon($helppage, $title, $component);
|
||||
if ($linktext === true) {
|
||||
$icon->linktext = $title;
|
||||
} else if (!empty($linktext)) {
|
||||
$icon->linktext = $linktext;
|
||||
}
|
||||
return $this->render($icon);
|
||||
}
|
||||
|
||||
$icon->prepare($this, $this->page, $this->target);
|
||||
/**
|
||||
* Implementation of user image rendering.
|
||||
* @param help_icon $helpicon
|
||||
* @return string HTML fragment
|
||||
*/
|
||||
protected function render_help_icon(help_icon $helpicon) {
|
||||
global $CFG;
|
||||
|
||||
$icon->link->text = $this->image($icon);
|
||||
if ($icon->linktext) {
|
||||
$icon->link->text .= $icon->text;
|
||||
// first get the help image icon
|
||||
$src = $this->pix_url('help');
|
||||
|
||||
if (empty($helpicon->linktext)) {
|
||||
$alt = $helpicon->title;
|
||||
} else {
|
||||
$alt = get_string('helpwiththis');
|
||||
}
|
||||
|
||||
return html_writer::tag('span', array('class' => 'helplink'), $this->link($icon->link));
|
||||
$attributes = array('src'=>$src, 'alt'=>$alt, 'class'=>'iconhelp');
|
||||
$output = html_writer::empty_tag('img', $attributes);
|
||||
|
||||
// add the link text if given
|
||||
if (!empty($helpicon->linktext)) {
|
||||
// the spacing has to be done through CSS
|
||||
$output .= $helpicon->linktext;
|
||||
}
|
||||
|
||||
// now create the link around it - TODO: this will be changed during the big lang cleanup in 2.0
|
||||
$url = new moodle_url($CFG->wwwroot.'/help.php', array('module' => $helpicon->component, 'file' => $helpicon->helppage .'.html'));
|
||||
|
||||
// note: this title is displayed only if JS is disabled, otherwise the link will have the new ajax tooltip
|
||||
$title = get_string('helpprefix2', '', trim($helpicon->title, ". \t"));
|
||||
|
||||
$attributes = array('href'=>$url, 'title'=>$title);
|
||||
$id = html_writer::random_id('helpicon');
|
||||
$attributes['id'] = $id;
|
||||
$this->add_action_handler($id, new popup_action('click', $url));
|
||||
$output = html_writer::tag('a', $attributes, $output);
|
||||
|
||||
// and finally span
|
||||
return html_writer::tag('span', array('class' => 'helplink'), $output);
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
x
Reference in New Issue
Block a user