From 9b22eeff5dfa6543e4d0028faed30c0a4c442749 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 11 Nov 2013 16:51:06 +0800 Subject: [PATCH 1/2] MDL-42806 dock: check title exists before using it --- .../moodle-core-dock-loader-debug.js | 7 +++++-- .../moodle-core-dock-loader/moodle-core-dock-loader-min.js | 2 +- .../moodle-core-dock-loader/moodle-core-dock-loader.js | 7 +++++-- lib/yui/src/dock/js/loader.js | 7 +++++-- 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-debug.js b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-debug.js index 2d954cacc32..2b7d519af5a 100644 --- a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-debug.js +++ b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-debug.js @@ -35,14 +35,17 @@ M.core.dock.ensureMoveToIconExists = function(blocknode) { var commands, moveto = Y.Node.create(''), blockaction = blocknode.one('.block_action'), - icon = 't/block_to_dock'; + icon = 't/block_to_dock', + titleh2 = blocknode.one('.header .title h2'); // Must set the image src separately of we get an error with XML strict headers if (Y.one(document.body).hasClass('dir-rtl')) { icon = icon + '_rtl'; } moveto.setAttribute('alt', M.util.get_string('addtodock', 'block')); - moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', blocknode.one('.header .title h2').getHTML()))); + if (titleh2) { + moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', titleh2.getHTML()))); + } moveto.setAttribute('src', M.util.image_url(icon, 'moodle')); if (blockaction) { diff --git a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-min.js b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-min.js index 31147f71680..a46e4f9e6fc 100644 --- a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-min.js +++ b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader-min.js @@ -1 +1 @@ -YUI.add("moodle-core-dock-loader",function(e,t){var n="moodle-core-dock-loader";M.core=M.core||{},M.core.dock=M.core.dock||{},M.core.dock.ensureMoveToIconExists=function(t){if(t.one(".moveto"))return!0;var n,r=e.Node.create(''),i=t.one(".block_action"),s="t/block_to_dock";return e.one(document.body).hasClass("dir-rtl")&&(s+="_rtl"),r.setAttribute("alt",M.util.get_string("addtodock","block")),r.setAttribute("title",e.Escape.html(M.util.get_string("dockblock","block",t.one(".header .title h2").getHTML()))),r.setAttribute("src",M.util.image_url(s,"moodle")),i?i.prepend(r):(n=t.one(".header .title .commands"),!n&&t.one(".header .title")&&(n=e.Node.create('
'),t.one(".header .title").append(n)),n.append(r)),!0},M.core.dock.loader=M.core.dock.loader||{},M.core.dock.loader.delegationEvents=[],M.core.dock.loader.initLoader=function(){var t=e.all(".block[data-instanceid][data-dockable]"),n=e.one(document.body),r;t.each(function(){var e=parseInt(this.getData("instanceid"),10);M.core.dock.ensureMoveToIconExists(this)}),t.some(function(e){return e.hasClass("dock_on_load")})?e.use("moodle-core-dock",function(){M.core.dock.init()}):(r=function(t){var n,r=this.ancestor(".block[data-instanceid]"),i=r.getData("instanceid");t.halt();for(n in M.core.dock.loader.delegationEvents)(e.Lang.isNumber(n)||e.Lang.isString(n))&&M.core.dock.loader.delegationEvents[n].detach();r.addClass("dock_on_load"),e.use("moodle-core-dock",function(){M.util.set_user_preference("docked_block_instance_"+i,1),M.core.dock.init()})},M.core.dock.loader.delegationEvents.push(n.delegate("click",r,".moveto")),M.core.dock.loader.delegationEvents.push(n.delegate("key",r,".moveto","enter")))}},"@VERSION@",{requires:["escape"]}); +YUI.add("moodle-core-dock-loader",function(e,t){var n="moodle-core-dock-loader";M.core=M.core||{},M.core.dock=M.core.dock||{},M.core.dock.ensureMoveToIconExists=function(t){if(t.one(".moveto"))return!0;var n,r=e.Node.create(''),i=t.one(".block_action"),s="t/block_to_dock",o=t.one(".header .title h2");return e.one(document.body).hasClass("dir-rtl")&&(s+="_rtl"),r.setAttribute("alt",M.util.get_string("addtodock","block")),o&&r.setAttribute("title",e.Escape.html(M.util.get_string("dockblock","block",o.getHTML()))),r.setAttribute("src",M.util.image_url(s,"moodle")),i?i.prepend(r):(n=t.one(".header .title .commands"),!n&&t.one(".header .title")&&(n=e.Node.create('
'),t.one(".header .title").append(n)),n.append(r)),!0},M.core.dock.loader=M.core.dock.loader||{},M.core.dock.loader.delegationEvents=[],M.core.dock.loader.initLoader=function(){var t=e.all(".block[data-instanceid][data-dockable]"),n=e.one(document.body),r;t.each(function(){var e=parseInt(this.getData("instanceid"),10);M.core.dock.ensureMoveToIconExists(this)}),t.some(function(e){return e.hasClass("dock_on_load")})?e.use("moodle-core-dock",function(){M.core.dock.init()}):(r=function(t){var n,r=this.ancestor(".block[data-instanceid]"),i=r.getData("instanceid");t.halt();for(n in M.core.dock.loader.delegationEvents)(e.Lang.isNumber(n)||e.Lang.isString(n))&&M.core.dock.loader.delegationEvents[n].detach();r.addClass("dock_on_load"),e.use("moodle-core-dock",function(){M.util.set_user_preference("docked_block_instance_"+i,1),M.core.dock.init()})},M.core.dock.loader.delegationEvents.push(n.delegate("click",r,".moveto")),M.core.dock.loader.delegationEvents.push(n.delegate("key",r,".moveto","enter")))}},"@VERSION@",{requires:["escape"]}); diff --git a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader.js b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader.js index e5606947724..dcd9684eced 100644 --- a/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader.js +++ b/lib/yui/build/moodle-core-dock-loader/moodle-core-dock-loader.js @@ -35,14 +35,17 @@ M.core.dock.ensureMoveToIconExists = function(blocknode) { var commands, moveto = Y.Node.create(''), blockaction = blocknode.one('.block_action'), - icon = 't/block_to_dock'; + icon = 't/block_to_dock', + titleh2 = blocknode.one('.header .title h2'); // Must set the image src separately of we get an error with XML strict headers if (Y.one(document.body).hasClass('dir-rtl')) { icon = icon + '_rtl'; } moveto.setAttribute('alt', M.util.get_string('addtodock', 'block')); - moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', blocknode.one('.header .title h2').getHTML()))); + if (titleh2) { + moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', titleh2.getHTML()))); + } moveto.setAttribute('src', M.util.image_url(icon, 'moodle')); if (blockaction) { diff --git a/lib/yui/src/dock/js/loader.js b/lib/yui/src/dock/js/loader.js index a3dbb82eb85..25b04bc2908 100644 --- a/lib/yui/src/dock/js/loader.js +++ b/lib/yui/src/dock/js/loader.js @@ -33,14 +33,17 @@ M.core.dock.ensureMoveToIconExists = function(blocknode) { var commands, moveto = Y.Node.create(''), blockaction = blocknode.one('.block_action'), - icon = 't/block_to_dock'; + icon = 't/block_to_dock', + titleh2 = blocknode.one('.header .title h2'); // Must set the image src separately of we get an error with XML strict headers if (Y.one(document.body).hasClass('dir-rtl')) { icon = icon + '_rtl'; } moveto.setAttribute('alt', M.util.get_string('addtodock', 'block')); - moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', blocknode.one('.header .title h2').getHTML()))); + if (titleh2) { + moveto.setAttribute('title', Y.Escape.html(M.util.get_string('dockblock', 'block', titleh2.getHTML()))); + } moveto.setAttribute('src', M.util.image_url(icon, 'moodle')); if (blockaction) { From 9bbcadb2288b9e5261147e9d9ddb1a81d4ef7598 Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Mon, 11 Nov 2013 17:18:23 +0800 Subject: [PATCH 2/2] MDL-42806 block_mentees: can only be docked if it has a valid title set. --- blocks/mentees/block_mentees.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/blocks/mentees/block_mentees.php b/blocks/mentees/block_mentees.php index aa340af7e41..95c30598a8f 100644 --- a/blocks/mentees/block_mentees.php +++ b/blocks/mentees/block_mentees.php @@ -46,5 +46,14 @@ class block_mentees extends block_base { return $this->content; } + + /** + * Returns true if the block can be docked. + * The mentees block can only be docked if it has a non-empty title. + * @return bool + */ + public function instance_can_be_docked() { + return parent::instance_can_be_docked() && isset($this->config->title) && !empty($this->config->title); + } }