Merge branch 'MDL-36752-MOODLE_23_STABLE' of git://git.luns.net.uk/moodle into MOODLE_23_STABLE

This commit is contained in:
Dan Poltawski 2012-11-27 13:32:47 +08:00
commit 148c786f7c
2 changed files with 27 additions and 27 deletions

View file

@ -1418,14 +1418,20 @@ M.util.help_popups = {
M.util.help_icon = { M.util.help_icon = {
Y : null, Y : null,
instance : null, instance : null,
add : function(Y, properties) { initialised : false,
this.Y = Y; setup : function(Y) {
properties.node = Y.one('#'+properties.id); if (this.initialised) {
if (properties.node) { // Exit early if we have already completed setup
properties.node.on('click', this.display, this, properties); return;
} }
this.Y = Y;
Y.one('body').delegate('click', this.display, 'span.helplink a', this);
this.initialised = true;
}, },
display : function(event, args) { add : function(Y, properties) {
this.setup(Y);
},
display : function(event) {
event.preventDefault(); event.preventDefault();
if (M.util.help_icon.instance === null) { if (M.util.help_icon.instance === null) {
var Y = M.util.help_icon.Y; var Y = M.util.help_icon.Y;
@ -1455,7 +1461,7 @@ M.util.help_icon = {
// Hide the menu if the user clicks outside of its content // Hide the menu if the user clicks outside of its content
boundingBox.get("ownerDocument").on("mousedown", function (event) { boundingBox.get("ownerDocument").on("mousedown", function (event) {
var oTarget = event.target; var oTarget = event.target;
var menuButton = Y.one("#"+args.id); var menuButton = this.helplink;
if (!oTarget.compareTo(menuButton) && if (!oTarget.compareTo(menuButton) &&
!menuButton.contains(oTarget) && !menuButton.contains(oTarget) &&
@ -1472,28 +1478,24 @@ M.util.help_icon = {
this.overlay.hide(); this.overlay.hide();
}, },
display : function(event, args) { display : function(event) {
if (Y.one('html').get('dir') == 'rtl') { var overlayPosition;
var overlayPosition = [Y.WidgetPositionAlign.TR, Y.WidgetPositionAlign.LC]; this.helplink = event.target.ancestor('span.helplink a', true);
if (Y.one('html').get('dir') === 'rtl') {
overlayPosition = [Y.WidgetPositionAlign.TR, Y.WidgetPositionAlign.LC];
} else { } else {
var overlayPosition = [Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.RC]; overlayPosition = [Y.WidgetPositionAlign.TL, Y.WidgetPositionAlign.RC];
} }
this.helplink = args.node;
this.overlay.set('bodyContent', Y.Node.create('<img src="'+M.cfg.loadingicon+'" class="spinner" />')); this.overlay.set('bodyContent', Y.Node.create('<img src="'+M.cfg.loadingicon+'" class="spinner" />'));
this.overlay.set("align", {node:args.node, points: overlayPosition}); this.overlay.set("align", {node:this.helplink, points: overlayPosition});
var fullurl = args.url;
if (!args.url.match(/https?:\/\//)) {
fullurl = M.cfg.wwwroot + args.url;
}
var ajaxurl = fullurl + '&ajax=1';
var cfg = { var cfg = {
method: 'get', method: 'get',
context : this, context : this,
data : {
ajax : 1
},
on: { on: {
success: function(id, o, node) { success: function(id, o, node) {
this.display_callback(o.responseText); this.display_callback(o.responseText);
@ -1508,7 +1510,7 @@ M.util.help_icon = {
} }
}; };
Y.io(ajaxurl, cfg); Y.io(this.helplink.get('href'), cfg);
this.overlay.show(); this.overlay.show();
}, },
@ -1524,10 +1526,10 @@ M.util.help_icon = {
}; };
help_content_overlay.init(); help_content_overlay.init();
M.util.help_icon.instance = help_content_overlay; M.util.help_icon.instance = help_content_overlay;
M.util.help_icon.instance.display(event, args); M.util.help_icon.instance.display(event);
}); });
} else { } else {
M.util.help_icon.instance.display(event, args); M.util.help_icon.instance.display(event);
} }
}, },
init : function(Y) { init : function(Y) {

View file

@ -1804,11 +1804,9 @@ class core_renderer extends renderer_base {
$title = get_string('helpprefix2', '', trim($title, ". \t")); $title = get_string('helpprefix2', '', trim($title, ". \t"));
$attributes = array('href'=>$url, 'title'=>$title, 'aria-haspopup' => 'true'); $attributes = array('href'=>$url, 'title'=>$title, 'aria-haspopup' => 'true');
$id = html_writer::random_id('helpicon');
$attributes['id'] = $id;
$output = html_writer::tag('a', $output, $attributes); $output = html_writer::tag('a', $output, $attributes);
$this->page->requires->js_init_call('M.util.help_icon.add', array(array('id'=>$id, 'url'=>$url->out(false)))); $this->page->requires->js_init_call('M.util.help_icon.setup');
$this->page->requires->string_for_js('close', 'form'); $this->page->requires->string_for_js('close', 'form');
// and finally span // and finally span