Skip to content

Commit

Permalink
navigation MDL-21543 Moved block docking icons next to the show-hide …
Browse files Browse the repository at this point in the history
…block icon
  • Loading branch information
Sam Hemelryk committed Feb 24, 2010
1 parent b0fef57 commit 46de77b
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 68 deletions.
84 changes: 29 additions & 55 deletions blocks/dock.js
Original file line number Diff line number Diff line change
Expand Up @@ -335,26 +335,21 @@ M.core_dock = {
}
}

var moveto = this.Y.Node.create('<a class="moveto customcommand requiresjs"></a>');
moveto.append(this.Y.Node.create('<img src="'+M.util.image_url('t/dock_to_block', 'moodle')+'" alt="'+M.str.block.undockitem+'" title="'+M.str.block.undockitem+'" />'));
if (location.href.match(/\?/)) {
moveto.set('href', location.href+'&dock='+this.id);
var moveto = this.Y.Node.create('<input type="image" class="moveto customcommand requiresjs" src="'+M.util.image_url('t/block_to_dock', 'moodle')+'" alt="'+M.str.block.undockitem+'" title="'+M.str.block.undockitem+'" />');
moveto.on('movetodock|click', this.move_to_dock, this, commands);

var blockaction = node.one('.block_action');
if (blockaction) {
blockaction.prepend(moveto);
} else {
moveto.set('href', location.href+'?dock='+this.id);
commands.append(moveto);
}
commands.append(moveto);
commands.all('a.moveto').on('movetodock|click', this.move_to_dock, this);

node.all('.customcommand').each(function(){
this.remove();
commands.appendChild(this);
});

// Move the block straight to the dock if required
if (node.hasClass('dock_on_load')) {
node.removeClass('dock_on_load')
this.skipsetposition = true;
this.move_to_dock();
this.move_to_dock(null, commands);
}
},

Expand All @@ -363,7 +358,7 @@ M.core_dock = {
* dock
* @param {event}
*/
move_to_dock : function(e) {
move_to_dock : function(e, commands) {
if (e) {
e.halt(true);
}
Expand All @@ -376,17 +371,6 @@ M.core_dock = {

this.cachedcontentnode = node;

node.all('a.moveto').each(function(moveto){
this.Y.Event.purgeElement(this.Y.Node.getDOMNode(moveto), false, 'click');
if (moveto.hasClass('customcommand')) {
moveto.all('img').each(function(movetoimg){
movetoimg.setAttribute('src', M.util.image_url('t/dock_to_block', 'moodle'));
movetoimg.setAttribute('alt', M.str.block.undockitem);
movetoimg.setAttribute('title', M.str.block.undockitem);
}, this);
}
}, this);

var placeholder = this.Y.Node.create('<div id="content_placeholder_'+this.id+'"></div>');
node.replace(this.Y.Node.getDOMNode(placeholder));
node = null;
Expand All @@ -396,11 +380,15 @@ M.core_dock = {
var blocktitle = this.Y.Node.getDOMNode(this.cachedcontentnode.one('.title h2')).cloneNode(true);
blocktitle = this.fix_title_orientation(blocktitle);

var commands = this.cachedcontentnode.all('.title .commands');
var blockcommands = this.Y.Node.create('<div class="commands"></div>');
if (commands.size() > 0) {
blockcommands = commands.item(0);
var blockcommands = this.cachedcontentnode.one('.title .commands');
var moveto = this.Y.Node.create('<a class="moveto customcommand requiresjs"></a>');
moveto.append(this.Y.Node.create('<img src="'+M.util.image_url('t/dock_to_block', 'moodle')+'" alt="'+M.str.block.undockitem+'" title="'+M.str.block.undockitem+'" />'));
if (location.href.match(/\?/)) {
moveto.set('href', location.href+'&dock='+this.id);
} else {
moveto.set('href', location.href+'?dock='+this.id);
}
blockcommands.append(moveto);

// Create a new dock item for the block
var dockitem = new M.core_dock.item(this.Y, this.id, blocktitle, blockcontent, blockcommands);
Expand All @@ -410,12 +398,12 @@ M.core_dock = {
// Wire the draw events to register remove events
dockitem.on('dockeditem:drawcomplete', function(e){
// check the contents block [editing=off]
this.contents.all('a.moveto').on('returntoblock|click', function(e){
this.contents.all('.moveto').on('returntoblock|click', function(e){
e.halt();
M.core_dock.remove(this.id)
}, this);
// check the commands block [editing=on]
this.commands.all('a.moveto').on('returntoblock|click', function(e){
this.commands.all('.moveto').on('returntoblock|click', function(e){
e.halt();
M.core_dock.remove(this.id)
}, this);
Expand Down Expand Up @@ -488,29 +476,11 @@ M.core_dock = {

this.resize_block_space(this.cachedcontentnode);

this.cachedcontentnode.all('a.moveto').each(function(moveto){
this.Y.Event.purgeElement(this.Y.Node.getDOMNode(moveto), false, 'click');
moveto.on('movetodock|click', this.move_to_dock, this);
if (moveto.hasClass('customcommand')) {
moveto.all('img').each(function(movetoimg){
movetoimg.setAttribute('src', M.util.image_url('t/block_to_dock', 'moodle'));
movetoimg.setAttribute('alt', M.str.block.addtodock);
movetoimg.setAttribute('title', M.str.block.addtodock);
}, this);
}
}, this);

var commands = this.cachedcontentnode.all('.commands');
commands.each(function (command){
command.all('.hidepanelicon').remove();
});
var blocktitle = this.cachedcontentnode.all('.title');

if (commands.size() === 1 && blocktitle.size() === 1) {
commands.item(0).remove();
blocktitle.item(0).append(commands.item(0));
}

var commands = this.cachedcontentnode.one('.commands');
commands.all('.hidepanelicon').remove();
commands.all('.moveto').remove();
commands.remove();
this.cachedcontentnode.one('.title').append(commands);
this.cachedcontentnode = null;
M.util.set_user_preference('docked_block_instance_'+this.id, 0);
return true;
Expand Down Expand Up @@ -564,7 +534,11 @@ M.core_dock = {
}
dockitem.append(dockitemtitle);
if (this.commands.hasChildNodes) {
this.contents.appendChild(this.commands);
if (this.contents.ancestor().one('.footer')) {
this.contents.ancestor().one('.footer').appendChild(this.commands);
} else {
this.contents.appendChild(this.commands);
}
}
M.core_dock.append(dockitem);

Expand Down
1 change: 0 additions & 1 deletion blocks/global_navigation_tree/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ M.block_navigation = M.block_navigation || {
* @base M.core_dock.abstractblock
* @param {YUI} Y A yui instance to use with the navigation
* @param {string} id The name of the tree
* @param {int} key The internal id within the tree store
* @param {object} properties Object containing tree properties
*/
M.block_navigation.classes.tree = function(Y, id, properties) {
Expand Down
2 changes: 1 addition & 1 deletion blocks/moodleblock.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ function _load_instance($instance, $page) {

function get_required_javascript() {
$this->_initialise_dock();
if ($this->instance_can_be_docked()) {
if ($this->instance_can_be_docked() && !$this->hide_header()) {
$this->page->requires->js_init_call('M.core_dock.init_genericblock', array($this->instance->id));
user_preference_allow_ajax_update('docked_block_instance_'.$this->instance->id, PARAM_INT);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/javascript-static.js
Original file line number Diff line number Diff line change
Expand Up @@ -1298,9 +1298,12 @@ function block_hider(id, userpref, visibletooltip, hiddentooltip, visibleicon, h
// Add the icon.
this.icon = document.createElement('input');
this.icon.type = 'image';
this.icon.className = 'hide-show-image';
this.update_state();
title_div.insertBefore(this.icon, title_div.firstChild);

var blockactions = YAHOO.util.Dom.getElementsByClassName('block_action', 'div', title_div);
if (blockactions && blockactions[0]) {
blockactions[0].insertBefore(this.icon, blockactions[0].firstChild);
}

// Hook up the event handler.
YAHOO.util.Event.addListener(this.icon, 'click', this.handle_click, null, this);
Expand Down
5 changes: 4 additions & 1 deletion lib/outputrenderers.php
Original file line number Diff line number Diff line change
Expand Up @@ -746,10 +746,13 @@ function block(block_contents $bc, $region) {
}

if ($title || $controlshtml) {
$output .= html_writer::tag('div', html_writer::tag('div', $title . $controlshtml, array('class' => 'title')), array('class' => 'header'));
$output .= html_writer::tag('div', html_writer::tag('div', html_writer::tag('div', '', array('class'=>'block_action')). $title . $controlshtml, array('class' => 'title')), array('class' => 'header'));
}

$output .= html_writer::start_tag('div', array('class' => 'content'));
if (!$title && !$controlshtml) {
$output .= html_writer::tag('div', '', array('class'=>'block_action notitle'));
}
$output .= $bc->content;

if ($bc->footer) {
Expand Down
2 changes: 1 addition & 1 deletion theme/base/style/blocks.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
display: none;
}

.sideblock .header .hide-show-image {
.sideblock .header .block_action {
float:right;
}

Expand Down
16 changes: 9 additions & 7 deletions theme/standardold/style/styles_layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -1573,17 +1573,23 @@ a.skip:focus, a.skip:active {
padding:0;
}

.sideblock .header .hide-show-image {
.sideblock .header .block_action,
.sideblock .content .block_action.notitle {
float:right;
height:11px;
width:11px;
margin-top:0.25em;
}

.sideblock .header .block_action input,
.sideblock .content .block_action.notitle input {
margin-right:2px;
height:11px;
width:11px;
}

.sideblock .header .commands {
margin-top: 0.3em;
clear: both;
height: 16px;
}

.sideblock .header .commands a {
Expand Down Expand Up @@ -1800,10 +1806,6 @@ a.skip:focus, a.skip:active {
/**
* Navigation and settings block
**/
.customcommand img {
margin-left:2px;
margin-right:2px;
}
.sideblock .block_tree_box {
margin:2px;
}
Expand Down

0 comments on commit 46de77b

Please sign in to comment.