From 87bf352d75b8020170a4b0b713eeebe0fb5d183d Mon Sep 17 00:00:00 2001 From: Sam Hemelryk Date: Thu, 4 Feb 2010 06:51:57 +0000 Subject: [PATCH] navigation MDL-21503 Dock cleanup in preperation of removing global Y --- blocks/dock.js | 28 +++++++++++++++++++++++----- blocks/moodleblock.class.php | 3 +-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/blocks/dock.js b/blocks/dock.js index f742b31376a..433361807b9 100644 --- a/blocks/dock.js +++ b/blocks/dock.js @@ -50,7 +50,8 @@ M.blocks.dock = { */ display:{ spacebeforefirstitem: 10, // Space between the top of the dock and the first item - mindisplaywidth: null // Minimum width for the display of dock items + mindisplaywidth: null, // Minimum width for the display of dock items + removeallicon: M.util.image_url('t/dock_to_block', 'moodle') }, /** * CSS classes to use with the dock @@ -94,6 +95,10 @@ M.blocks.dock = { Y.augment(M.blocks.dock, Y.EventTarget, true); // Re-apply early bindings properly now that we can M.blocks.dock.apply_binds(); + // Check if there is a customisation function + if (typeof(customise_dock_for_theme) === 'function') { + customise_dock_for_theme(); + } }, /** * Adds a dock item into the dock @@ -129,9 +134,8 @@ M.blocks.dock = { if (Y.UA.ie > 0 && Y.UA.ie < 7) { this.node.setStyle('height', this.node.get('winHeight')+'px'); } - var dockcontrol = Y.Node.create('
'); - var removeall = Y.Node.create(''+mstr.block.undockall+''); + var removeall = Y.Node.create(''+mstr.block.undockall+''); removeall.on('removeall|click', this.remove_all, this); dockcontrol.appendChild(removeall); this.node.appendChild(dockcontrol); @@ -160,6 +164,7 @@ M.blocks.dock = { this.items = []; this.node.remove(); this.node = null; + Y.one(document.body).removeClass(M.blocks.dock.cfg.css.body); this.fire('dock:removed'); } return true; @@ -179,6 +184,7 @@ M.blocks.dock = { this.items = []; this.node.remove(); this.node = null; + Y.one(document.body).removeClass(M.blocks.dock.cfg.css.body); Y.fire('dock:removed'); return true; }, @@ -367,7 +373,7 @@ M.blocks.dock = { var spacewidth = this.resize_block_space(placeholder); var blocktitle = Y.Node.getDOMNode(this.cachedcontentnode.one('.title h2')).cloneNode(true); - blocktitle.innerHTML = blocktitle.innerHTML.replace(/(.)/g, "$1
"); + blocktitle = this.fix_title_orientation(blocktitle); var commands = this.cachedcontentnode.all('.title .commands'); var blockcommands = Y.Node.create('
'); @@ -405,6 +411,10 @@ M.blocks.dock = { this.skipsetposition = false; } }, + fix_title_orientation : function(node) { + node.innerHTML = node.innerHTML.replace(/(.)/g, "$1
"); + return node; + }, /** * Resizes the space that contained blocks if there were no blocks left in @@ -437,7 +447,13 @@ M.blocks.dock = { */ return_to_block : function(dockitem) { var placeholder = Y.one('#content_placeholder_'+this.id); - this.cachedcontentnode.appendChild(dockitem.contents); + + if (this.cachedcontentnode.one('.header')) { + this.cachedcontentnode.one('.header').insert(dockitem.contents, 'after'); + } else { + this.cachedcontentnode.insert(dockitem.contents); + } + placeholder.replace(Y.Node.getDOMNode(this.cachedcontentnode)); this.cachedcontentnode = Y.one('#'+this.cachedcontentnode.get('id')); @@ -540,6 +556,7 @@ M.blocks.dock = { xy:position, autofillheight:this.cfg.panel.autofillheight}); this.panel.showEvent.subscribe(this.resize_panel, this, true); + this.panel.renderEvent.subscribe(this.resize_panel, this, true); this.panel.setBody(Y.Node.getDOMNode(this.contents)); this.panel.render(M.blocks.dock.node); if (this.cfg.display.mindisplaywidth !== null && Y.one(this.panel.body).getStyle('minWidth') == '0px') { @@ -662,6 +679,7 @@ M.blocks.genericblock.prototype.init = M.blocks.dock.abstract M.blocks.genericblock.prototype.move_to_dock = M.blocks.dock.abstract_block_class.move_to_dock; M.blocks.genericblock.prototype.resize_block_space = M.blocks.dock.abstract_block_class.resize_block_space; M.blocks.genericblock.prototype.return_to_block = M.blocks.dock.abstract_block_class.return_to_block; +M.blocks.genericblock.prototype.fix_title_orientation = M.blocks.dock.abstract_block_class.fix_title_orientation; /** * This class represents an item in the dock diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index fe1c2f3f143..97415c93b75 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -578,7 +578,6 @@ class block_base { function get_required_javascript() { $this->_initialise_dock(); if ($this->instance_can_be_docked()) { - $this->page->requires->js('/blocks/dock.js'); $this->page->requires->js_object_init(null, 'M.blocks.genericblock', array($this->instance->id), array('blocks_dock')); user_preference_allow_ajax_update('docked_block_instance_'.$this->instance->id, PARAM_INT); } @@ -753,7 +752,7 @@ class block_base { public function _initialise_dock() { global $CFG; if (!self::$dockinitialised) { - $this->page->requires->js_module(array('name'=>'blocks_dock', 'fullpath'=>'/blocks/dock.js', 'requires'=>array('base','dom','io','node', 'event-custom'))); + $this->page->requires->js_module(array('name'=>'blocks_dock', 'fullpath'=>'/blocks/dock.js', 'requires'=>array('dom','io','node', 'event-custom', 'cookie'))); $this->page->requires->strings_for_js(array('addtodock','undockitem','undockall'), 'block'); self::$dockinitialised = true; }