/* global BLOCK, LOGNS, DOCKEDITEM */ /** * Dock JS. * * This file contains the block class used to manage blocks (both docked and not) for the dock. * * @module moodle-core-dock */ /** * Block. * * @namespace M.core.dock * @class Block * @constructor * @extends Base */ BLOCK = function() { BLOCK.superclass.constructor.apply(this, arguments); }; BLOCK.prototype = { /** * A content place holder used when the block has been docked. * @property contentplaceholder * @protected * @type Node */ contentplaceholder: null, /** * The skip link associated with this block. * @property contentskipanchor * @protected * @type Node */ contentskipanchor: null, /** * The cached content node for the actual block * @property cachedcontentnode * @protected * @type Node */ cachedcontentnode: null, /** * If true the user preference isn't updated * @property skipsetposition * @protected * @type Boolean */ skipsetposition: true, /** * The dock item associated with this block * @property dockitem * @protected * @type DOCKEDITEM */ dockitem: null, /** * Called during the initialisation process of the object. * @method initializer */ initializer: function() { var node = Y.one('#inst' + this.get('id')); if (!node) { return false; } Y.log('Initialised block with instance id:' + this.get('id'), 'debug', LOGNS); M.core.dock.ensureMoveToIconExists(node); // Move the block straight to the dock if required if (node.hasClass(CSS.dockonload)) { node.removeClass(CSS.dockonload); this.moveToDock(); } this.skipsetposition = false; return true; }, /** * Returns the class associated with this block. * @method _getBlockClass * @private * @param {Node} node * @return String */ _getBlockClass: function(node) { var block = node.getData('block'), classes, matches; if (Y.Lang.isString(block) && block !== '') { return block; } classes = node.getAttribute('className').toString(); matches = /(^| )block_([^ ]+)/.exec(classes); if (matches) { return matches[2]; } return matches; }, /** * This function is responsible for moving a block from the page structure onto the dock. * @method moveToDock * @param {EventFacade} e */ moveToDock: function(e) { if (e) { e.halt(true); } var dock = M.core.dock.get(), id = this.get('id'), blockcontent = Y.one('#inst' + id).one('.content'), icon = (window.right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', breakchar = (location.href.match(/\?/)) ? '&' : '?', blocktitle, blockcommands, movetoimg, moveto; if (!blockcontent) { return; } Y.log('Moving block to the dock:' + this.get('id'), 'debug', LOGNS); this.recordBlockState(); blocktitle = this.cachedcontentnode.one('.title h2').cloneNode(true); // Build up the block commands. // These should not actually added to the DOM. blockcommands = this.cachedcontentnode.one('.title .commands'); if (blockcommands) { blockcommands = blockcommands.cloneNode(true); } else { blockcommands = Y.Node.create('
'); } movetoimg = Y.Node.create('