diff --git a/blocks/moodleblock.class.php b/blocks/moodleblock.class.php index f3b9e062c87..9d9b289ffd0 100644 --- a/blocks/moodleblock.class.php +++ b/blocks/moodleblock.class.php @@ -230,7 +230,7 @@ class block_base { global $CFG; $bc = new block_contents($this->html_attributes()); - + $bc->attributes['data-block'] = $this->name(); $bc->blockinstanceid = $this->instance->id; $bc->blockpositionid = $this->instance->blockpositionid; diff --git a/lib/blocklib.php b/lib/blocklib.php index ae413cfb6e7..9b6051b74be 100644 --- a/lib/blocklib.php +++ b/lib/blocklib.php @@ -446,6 +446,9 @@ class block_manager { throw new coding_exception('block_manager has already prepared the blocks in region ' . $region . 'for output. It is too late to add a fake block.'); } + if (!isset($bc->attributes['data-block'])) { + $bc->attributes['data-block'] = '_fake'; + } $this->extracontent[$region][] = $bc; } @@ -1860,6 +1863,7 @@ function block_add_block_ui($page, $output) { $bc = new block_contents(); $bc->title = get_string('addblock'); $bc->add_class('block_adminblock'); + $bc->attributes['data-block'] = 'adminblock'; $missingblocks = $page->blocks->get_addable_blocks(); if (empty($missingblocks)) { diff --git a/lib/yui/build/moodle-core-dock/moodle-core-dock-debug.js b/lib/yui/build/moodle-core-dock/moodle-core-dock-debug.js index c0fb9817562..9fdb0f90021 100644 --- a/lib/yui/build/moodle-core-dock/moodle-core-dock-debug.js +++ b/lib/yui/build/moodle-core-dock/moodle-core-dock-debug.js @@ -9,28 +9,33 @@ YUI.add('moodle-core-dock', function (Y, NAME) { */ -var LOGNS = 'moodle-core-dock'; -var BODY = Y.one(document.body); -var CSS = { - dock: 'dock', // CSS Class applied to the dock box - dockspacer: 'dockspacer', // CSS class applied to the dockspacer - controls: 'controls', // CSS class applied to the controls box - body: 'has_dock', // CSS class added to the body when there is a dock - buttonscontainer: 'buttons_container', - dockeditem: 'dockeditem', // CSS class added to each item in the dock - dockeditemcontainer: 'dockeditem_container', - dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock - activeitem: 'activeitem', // CSS class added to the active item - contentonly: 'content-only', - dockonload: 'dock_on_load' -}; -var SELECTOR = { - dockableblock: '.block[data-instanceid][data-dockable]', - blockmoveto: '.block[data-instanceid][data-dockable] .moveto', - panelmoveto: '#dockeditempanel .commands a.moveto', - dockonload: '.block.'+CSS.dockonload, - blockregion: '[data-blockregion]' -}; +var LOGNS = 'moodle-core-dock', + BODY = Y.one(Y.config.doc.body), + CSS = { + dock: 'dock', // CSS Class applied to the dock box + dockspacer: 'dockspacer', // CSS class applied to the dockspacer + controls: 'controls', // CSS class applied to the controls box + body: 'has_dock', // CSS class added to the body when there is a dock + buttonscontainer: 'buttons_container', + dockeditem: 'dockeditem', // CSS class added to each item in the dock + dockeditemcontainer: 'dockeditem_container', + dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock + activeitem: 'activeitem', // CSS class added to the active item + contentonly: 'content-only', + dockonload: 'dock_on_load' + }, + SELECTOR = { + dockableblock: '.block[data-instanceid][data-dockable]', + blockmoveto: '.block[data-instanceid][data-dockable] .moveto', + panelmoveto: '#dockeditempanel .commands a.moveto', + dockonload: '.block.'+CSS.dockonload, + blockregion: '[data-blockregion]' + }, + DOCK, + DOCKPANEL, + TABHEIGHTMANAGER, + BLOCK, + DOCKEDITEM; /** * Core namespace. @@ -147,12 +152,18 @@ M.core.dock.dockBlock = function(id) { * @return {Node} The title node to use. */ M.core.dock.fixTitleOrientation = function(title, text) { - var dock = M.core.dock.get(); + var dock = M.core.dock.get(), + fontsize = '11px', + transform = 'rotate(270deg)', + test, + width, + height, + container; title = Y.one(title); if (dock.get('orientation') !== 'vertical') { // If the dock isn't vertical don't adjust it! - title.setContent(text); + title.set('innerHTML', text); return title; } @@ -161,37 +172,34 @@ M.core.dock.fixTitleOrientation = function(title, text) { M.str.langconfig.thisdirectionvertical = 'ver'; } - var clockwise = false; switch (M.str.langconfig.thisdirectionvertical) { case 'ver': // Stacked is easy - return title.setContent(text.split('').join('
')); + return title.set('innerHTML', text.split('').join('
')); case 'ttb': - clockwise = true; + transform = 'rotate(90deg)'; break; case 'btt': - clockwise = false; + // Nothing to do here. transform default is good. break; } if (Y.UA.ie === 8) { // IE8 can flip the text via CSS but not handle transform. IE9+ can handle the CSS3 transform attribute. - title.setContent(text); + title.set('innerHTML', text); title.setAttribute('style', 'writing-mode: tb-rl; filter: flipV flipH;display:inline;'); title.addClass('filterrotate'); return title; } // We need to fix a font-size - sorry theme designers. - var fontsize = '11px'; - var transform = (clockwise) ? 'rotate(90deg)' : 'rotate(270deg)'; - var test = Y.Node.create('

'+text+'

'); + test = Y.Node.create('

'+text+'

'); BODY.insert(test, 0); - var width = test.one('span').get('offsetWidth') * 1.2; - var height = test.one('span').get('offsetHeight'); + width = test.one('span').get('offsetWidth') * 1.2; + height = test.one('span').get('offsetHeight'); test.remove(); - title.setContent(text); + title.set('innerHTML', text); title.addClass('css3transform'); // Move the title into position @@ -220,10 +228,12 @@ M.core.dock.fixTitleOrientation = function(title, text) { '-o-transform' : transform }); - var container = Y.Node.create('
'); + container = Y.Node.create('
'); container.append(title); - container.setStyle('height', width + (width / 4)); - container.setStyle('position', 'relative'); + container.setStyles({ + height : width + (width / 4), + position : 'relative' + }); return container; }; @@ -256,7 +266,7 @@ M.core.dock.notifyBlockChange = function(instanceid) { * @extends Y.Base * @uses Y.EventTarget */ -var DOCK = function() { +DOCK = function() { DOCK.superclass.constructor.apply(this, arguments); }; DOCK.prototype = { @@ -322,7 +332,7 @@ DOCK.prototype = { */ initializer : function() { Y.log('Dock initialising', 'note', LOGNS); - + // Publish the events the dock has /** * Fired when the dock first starts initialising. @@ -404,7 +414,18 @@ DOCK.prototype = { if (this.dockdrawn === true) { return true; } - var dock = this._initialiseDockNode(); + var dock = this._initialiseDockNode(), + clickargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0 + }, + mouseenterargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0.5, + iscontained:true, + preventevent:'click', + preventdelay:3 + }; if (Y.UA.ie > 0 && Y.UA.ie < 7) { // Adjust for IE 6 (can't handle fixed pos) dock.setStyle('height', dock.get('winHeight')+'px'); @@ -416,9 +437,6 @@ DOCK.prototype = { this.tabheightmanager = new TABHEIGHTMANAGER({dock:this}); - var clickargs = {cssselector:'.'+CSS.dockedtitle, delay:0}; - var mouseenterargs = {cssselector:'.'+CSS.dockedtitle, delay:0.5, iscontained:true, preventevent:'click', preventdelay:3}; - // Attach the required event listeners // We use delegate here as that way a handful of events are created for the dock // and all items rather than the same number for the dock AND every item individually @@ -456,8 +474,7 @@ DOCK.prototype = { return false; } e.halt(); - var id = target.getAttribute('rel'); - this.dockeditems[id].toggle(e.action); + this.dockeditems[target.getAttribute('rel')].toggle(e.action); }, /** * Call the theme customisation method "customise_dock_for_theme" if it exists. @@ -506,31 +523,35 @@ DOCK.prototype = { }; // Check for and apply any legacy configuration. for (key in M.core_dock.cfg) { - value = M.core_dock.cfg[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key) && cfgmap[key]) { + value = M.core_dock.cfg[key]; + if (value === null) { + continue; + } + if (!warned) { + Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); + warned = true; + } + // Damn, the've set something. + Y.log('Note for customise_dock_for_theme code: M.core_dock.cfg.'+key+' is now dock.set(\''+key+'\', value)', 'info', LOGNS); + this.set(cfgmap[key], value); } - if (!warned) { - Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); - warned = true; - } - // Damn, the've set something. - Y.log('Note for customise_dock_for_theme code: M.core_dock.cfg.'+key+' is now dock.set(\''+key+'\', value)', 'info', LOGNS); - this.set(cfgmap[key], value); } // Check for and apply any legacy CSS changes.. for (key in M.core_dock.css) { - value = M.core_dock.css[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key)) { + value = M.core_dock.css[key]; + if (value === null) { + continue; + } + if (!warned) { + Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); + warned = true; + } + // Damn, they've set something. + Y.log('Note for customise_dock_for_theme code: M.core_dock.css.'+key+' is now CSS.'+key+' = value', 'info', LOGNS); + CSS[key] = value; } - if (!warned) { - Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); - warned = true; - } - // Damn, they've set something. - Y.log('Note for customise_dock_for_theme code: M.core_dock.css.'+key+' is now CSS.'+key+' = value', 'info', LOGNS); - CSS[key] = value; } } }, @@ -547,7 +568,7 @@ DOCK.prototype = { holdingarea = Y.Node.create('
').setStyles({display:'none'}), buttons = this.get('buttonsNode'), container = this.get('itemContainerNode'); - + if (!dock) { dock = Y.one('#'+CSS.dock); } @@ -642,7 +663,11 @@ DOCK.prototype = { * @return {Boolean} */ handleEvent : function(e, options) { - var item = this.getActiveItem(); + var item = this.getActiveItem(), + target, + targetid, + regex = /^dock_item_(\d+)_title$/, + self = this; if (options.cssselector === 'body') { if (!this.get('dockNode').contains(e.target)) { if (item) { @@ -650,7 +675,6 @@ DOCK.prototype = { } } } else { - var target; if (e.target.test(options.cssselector)) { target = e.target; } else { @@ -665,7 +689,6 @@ DOCK.prototype = { if (options.preventevent) { this.preventevent = options.preventevent; if (options.preventdelay) { - var self = this; setTimeout(function(){ self.preventevent = null; }, options.preventdelay * 1000); @@ -679,8 +702,7 @@ DOCK.prototype = { if (options.delay > 0) { return this.delayEvent(e, options, target); } - var targetid = target.get('id'); - var regex = /^dock_item_(\d+)_title$/; + targetid = target.get('id'); if (targetid.match(regex)) { item = this.dockeditems[targetid.replace(regex, '$1')]; if (item.active) { @@ -735,7 +757,8 @@ DOCK.prototype = { var blockregions = [], populatedblockregions = 0, allnewregions = true, - showregions = false; + showregions = false, + i; // First look for understood regions. Y.all(SELECTOR.blockregion).each(function(){ var regionname = region.getData('blockregion'); @@ -775,22 +798,27 @@ DOCK.prototype = { } if (!allnewregions) { - var i = null; if (populatedblockregions === 0 && showregions === false) { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } else if (populatedblockregions === 1 && showregions === false) { for (i in blockregions) { - if (!blockregions[i].hasblocks) { - BODY.removeClass(blockregions[i].bodyclass); - } else { - BODY.addClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + if (!blockregions[i].hasblocks) { + BODY.removeClass(blockregions[i].bodyclass); + } else { + BODY.addClass(blockregions[i].bodyclass); + } } } } else { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } } @@ -863,8 +891,11 @@ DOCK.prototype = { */ removeAll : function() { Y.log('Undocking all '+this.dockeditems.length+' blocks', 'note', LOGNS); - for (var i in this.dockeditems) { - this.remove(i); + var i; + for (i in this.dockeditems) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + this.remove(i); + } } return true; }, @@ -902,34 +933,43 @@ DOCK.prototype = { * @return {Boolean} */ resize : function() { - var panel = this.getPanel(); - var item = this.getActiveItem(); + var panel = this.getPanel(), + item = this.getActiveItem(), + buffer, + screenh, + docky, + titletop, + containery, + containerheight, + scrolltop, + panelheight, + dockx, + titleleft; if (!panel.get('visible') || !item) { return true; } this.fire('dock:panelresizestart'); if (this.get('orientation') === 'vertical') { - var buffer = this.get('bufferPanel'); - var screenheight = parseInt(BODY.get('winHeight'), 10)-(buffer*2); - var docky = this.get('dockNode').getY(); - var titletop = item.get('dockTitleNode').getY()-docky-buffer; - var containery = this.get('itemContainerNode').getY(); - var containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); - var scrolltop = panel.get('bodyNode').get('scrollTop'); + buffer = this.get('bufferPanel'); + screenh = parseInt(BODY.get('winHeight'), 10)-(buffer*2); + docky = this.get('dockNode').getY(); + titletop = item.get('dockTitleNode').getY()-docky-buffer; + containery = this.get('itemContainerNode').getY(); + containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); + scrolltop = panel.get('bodyNode').get('scrollTop'); panel.get('bodyNode').setStyle('height', 'auto'); panel.get('node').removeClass('oversized_content'); - var panelheight = panel.get('node').get('offsetHeight'); + panelheight = panel.get('node').get('offsetHeight'); if (Y.UA.ie > 0 && Y.UA.ie < 7) { panel.setTop(item.get('dockTitleNode').getY()); - } else if (panelheight > screenheight) { + } else if (panelheight > screenh) { panel.setTop(buffer-containerheight); - panel.get('bodyNode').setStyle('height', (screenheight-panel.get('headerNode').get('offsetHeight'))+'px'); + panel.get('bodyNode').setStyle('height', (screenh-panel.get('headerNode').get('offsetHeight'))+'px'); panel.get('node').addClass('oversized_content'); - } else if (panelheight > (screenheight-(titletop-buffer))) { - var difference = panelheight - (screenheight-titletop); - panel.setTop(titletop-containerheight-difference+buffer); + } else if (panelheight > (screenh-(titletop-buffer))) { + panel.setTop(titletop-containerheight-(panelheight - (screenh-titletop))+buffer); } else { panel.setTop(titletop-containerheight+buffer); } @@ -943,8 +983,8 @@ DOCK.prototype = { panel.get('node').setStyle('left', -panel.get('offsetWidth')+'px'); } else if (this.get('position') === 'top') { - var dockx = this.get('dockNode').getX(); - var titleleft = item.get('dockTitleNode').getX()-dockx; + dockx = this.get('dockNode').getX(); + titleleft = item.get('dockTitleNode').getX()-dockx; panel.get('node').setStyle('left', titleleft+'px'); } @@ -957,7 +997,8 @@ DOCK.prototype = { * @return {DOCKEDITEM} */ getActiveItem : function() { - for (var i in this.dockeditems) { + var i; + for (i in this.dockeditems) { if (this.dockeditems[i].active) { return this.dockeditems[i]; } @@ -1094,7 +1135,7 @@ Y.augment(DOCK, Y.EventTarget); * @extends Y.Base * @uses Y.EventTarget */ -var DOCKPANEL = function() { +DOCKPANEL = function() { DOCKPANEL.superclass.constructor.apply(this, arguments); }; DOCKPANEL.prototype = { @@ -1188,11 +1229,14 @@ DOCKPANEL.prototype = { */ setHeader : function(content) { this.create(); - var header = this.get('headerNode'); + var header = this.get('headerNode'), + i; header.setContent(content); if (arguments.length > 1) { - for (var i=1;i < arguments.length;i++) { - header.append(arguments[i]); + for (i = 1; i < arguments.length; i++) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + header.append(arguments[i]); + } } } }, @@ -1327,7 +1371,7 @@ Y.augment(DOCKPANEL, Y.EventTarget); * @constructor * @extends Y.Base */ -var TABHEIGHTMANAGER = function() { +TABHEIGHTMANAGER = function() { TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments); }; TABHEIGHTMANAGER.prototype = { @@ -1354,12 +1398,14 @@ TABHEIGHTMANAGER.prototype = { id, dockedtitle; if (items.length > 0) { for (id in items) { - dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (dockedtitle) { - if (this.get('enabled')) { - dockedtitle.setStyle('height', 'auto'); + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (dockedtitle) { + if (this.get('enabled')) { + dockedtitle.setStyle('height', 'auto'); + } + totalheight += dockedtitle.get('offsetHeight') || 0; } - totalheight += dockedtitle.get('offsetHeight') || 0; } } if (totalheight > possibleheight) { @@ -1382,20 +1428,22 @@ TABHEIGHTMANAGER.prototype = { Y.log('Enabling the dock tab sizer.', 'note', LOGNS); this.set('enabled', true); for (id in items) { - itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (!itemtitle) { - continue; + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (!itemtitle) { + continue; + } + itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); + offsetheight = itemtitle.get('offsetHeight'); + itemtitle.setStyle('overflow', 'hidden'); + if (offsetheight > itemheight) { + itemtitle.setStyle('height', itemheight+'px'); + usedheight += itemheight; + } else { + usedheight += offsetheight; + } + runningcount++; } - itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); - offsetheight = itemtitle.get('offsetHeight'); - itemtitle.setStyle('overflow', 'hidden'); - if (offsetheight > itemheight) { - itemtitle.setStyle('height', itemheight+'px'); - usedheight += itemheight; - } else { - usedheight += offsetheight; - } - runningcount++; } } }; @@ -1444,24 +1492,24 @@ Y.extend(TABHEIGHTMANAGER, Y.Base, TABHEIGHTMANAGER.prototype, { * @class ActionKey */ Y.Event.define("dock:actionkey", { - // Webkit and IE repeat keydown when you hold down arrow keys. - // Opera links keypress to page scroll; others keydown. - // Firefox prevents page scroll via preventDefault() on either - // keydown or keypress. - _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', + // Webkit and IE repeat keydown when you hold down arrow keys. + // Opera links keypress to page scroll; others keydown. + // Firefox prevents page scroll via preventDefault() on either + // keydown or keypress. + _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', /** * The keys to trigger on. - * @method _keys + * @property _keys */ - _keys: { - //arrows - '37': 'collapse', - '39': 'expand', - //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) - '32': 'toggle', - '13': 'enter' - }, + _keys: { + //arrows + '37': 'collapse', + '39': 'expand', + //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) + '32': 'toggle', + '13': 'enter' + }, /** * Handles key events @@ -1470,18 +1518,18 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {Object} args */ - _keyHandler: function (e, notifier, args) { - var actObj; - if (!args.actions) { - actObj = {collapse:true, expand:true, toggle:true, enter:true}; - } else { - actObj = args.actions; - } - if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { - e.action = this._keys[e.keyCode]; - notifier.fire(e); - } - }, + _keyHandler: function (e, notifier, args) { + var actObj; + if (!args.actions) { + actObj = {collapse: true, expand: true, toggle: true, enter: true}; + } else { + actObj = args.actions; + } + if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { + e.action = this._keys[e.keyCode]; + notifier.fire(e); + } + }, /** * Subscribes to events. @@ -1490,24 +1538,27 @@ Y.Event.define("dock:actionkey", { * @param {Subscription} sub The object tracking this subscription. * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - on: function (node, sub, notifier) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, {actions:false}); - } else { - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, sub.args[0]); - } - }, + on: function (node, sub, notifier) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false}); + } else { + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]); + } + }, /** * Detaches an event listener * @method detach + * @param {Node} node The node this subscription was applied to. + * @param {Subscription} sub The object tracking this subscription. + * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - detach: function (node, sub, notifier) { - //detach our _detacher handle of the subscription made in on() - sub._detacher.detach(); - }, + detach: function (node, sub) { + //detach our _detacher handle of the subscription made in on() + sub._detacher.detach(); + }, /** * Creates a delegated event listener. @@ -1517,15 +1568,15 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - delegate: function (node, sub, notifier, filter) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, {actions:false}); - } else { - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, sub.args[0]); - } - }, + delegate: function (node, sub, notifier, filter) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions:false}); + } else { + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]); + } + }, /** * Detaches a delegated event listener. @@ -1535,9 +1586,9 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - detachDelegate: function (node, sub, notifier, filter) { - sub._delegateDetacher.detach(); - } + detachDelegate: function (node, sub) { + sub._delegateDetacher.detach(); + } }); /** * Dock JS. @@ -1555,7 +1606,7 @@ Y.Event.define("dock:actionkey", { * @constructor * @extends Y.Base */ -var BLOCK = function() { +BLOCK = function() { BLOCK.superclass.constructor.apply(this, arguments); }; BLOCK.prototype = { @@ -1591,7 +1642,7 @@ BLOCK.prototype = { * The dock item associated with this block * @property dockitem * @protected - * @type DOCKITEM + * @type DOCKEDITEM */ dockitem : null, /** @@ -1599,7 +1650,8 @@ BLOCK.prototype = { * @method initializer */ initializer : function() { - var node = Y.one('#inst'+this.get('id')); + var node = Y.one('#inst'+this.get('id')), + commands; if (!node) { return false; } @@ -1611,7 +1663,7 @@ BLOCK.prototype = { // Move the block straight to the dock if required if (node.hasClass(CSS.dockonload)) { node.removeClass(CSS.dockonload); - var commands = node.one('.header .title .commands'); + commands = node.one('.header .title .commands'); if (!commands) { commands = Y.Node.create('
'); if (node.one('.header .title')) { @@ -1631,9 +1683,14 @@ BLOCK.prototype = { * @return String */ _getBlockClass : function(node) { - var classes = node.getAttribute('className').toString(), - regex = /(^|\s)(block_[a-zA-Z0-9_]+)(\s|$)/, - matches = regex.exec(classes); + 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]; } @@ -1641,7 +1698,7 @@ BLOCK.prototype = { }, /** - * This function is reponsible for moving a block from the page structure onto the dock. + * This function is responsible for moving a block from the page structure onto the dock. * @method moveToDock * @param {EventFacade} e */ @@ -1652,7 +1709,13 @@ BLOCK.prototype = { var dock = M.core.dock.get(), id = this.get('id'), - blockcontent = Y.one('#inst'+id).one('.content'); + blockcontent = Y.one('#inst'+id).one('.content'), + icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', + breakchar = (location.href.match(/\?/)) ? '&' : '?', + blocktitle, + blockcommands, + movetoimg, + moveto; if (!blockcontent) { return; @@ -1660,25 +1723,22 @@ BLOCK.prototype = { Y.log('Moving block to the dock:'+this.get('id'), 'note', LOGNS); - var icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', - char = (location.href.match(/\?/)) ? '&' : '?', - blocktitle, - blockcommands, - movetoimg, - moveto; - this.recordBlockState(); blocktitle = this.cachedcontentnode.one('.title h2').cloneNode(true); blockcommands = this.cachedcontentnode.one('.title .commands').cloneNode(true); - // Must set the image src seperatly of we get an error with XML strict headers - movetoimg = Y.Node.create(''+Y.Escape.html(M.str.block.undockitem)+''); - movetoimg.setAttribute('src', M.util.image_url(icon, 'moodle')); - moveto = Y.Node.create('').append(movetoimg); - moveto.set('href', location.href + char + 'dock='+id); - blockcommands.append(moveto); + movetoimg = Y.Node.create('').setAttrs({ + alt : Y.Escape.html(M.str.block.undockitem), + title : Y.Escape.html(M.util.get_string('undockblock', 'block', blocktitle.innerHTML)), + src : M.util.image_url(icon, 'moodle') + }); + moveto = Y.Node.create('').setAttrs({ + className : 'moveto customcommand requiresjs', + href : Y.config.win.location.href + breakchar + 'dock='+id + }); + moveto.append(movetoimg); + blockcommands.append(moveto.append(movetoimg)); // Create a new dock item for the block this.dockitem = new DOCKEDITEM({ @@ -1698,7 +1758,7 @@ BLOCK.prototype = { M.util.set_user_preference('docked_block_instance_'+id, 1); } - this.set('idDocked', true); + this.set('isDocked', true); }, /** * Records the block state and adds it to the docks holding area. @@ -1726,11 +1786,12 @@ BLOCK.prototype = { /** * This function removes a block from the dock and puts it back into the page structure. - * @method returnToBlock + * @method returnToPage * @return {Boolean} */ - returnToBlock : function() { - var id = this.get('id'); + returnToPage : function() { + var id = this.get('id'), + commands; Y.log('Moving block out of the dock:'+this.get('id'), 'note', LOGNS); @@ -1748,7 +1809,7 @@ BLOCK.prototype = { this.contentplaceholder.replace(this.cachedcontentnode); this.cachedcontentnode = Y.one('#'+this.cachedcontentnode.get('id')); - var commands = this.dockitem.get('commands'); + commands = this.dockitem.get('commands'); if (commands) { commands.all('.hidepanelicon').remove(); commands.all('.moveto').remove(); @@ -1757,7 +1818,7 @@ BLOCK.prototype = { this.cachedcontentnode.one('.title').append(commands); this.cachedcontentnode = null; M.util.set_user_preference('docked_block_instance_'+id, 0); - this.set('idDocked', false); + this.set('isDocked', false); return true; } }; @@ -1804,7 +1865,7 @@ Y.extend(BLOCK, Y.Base, BLOCK.prototype, { * @extends Y.Base * @uses Y.EventTarget */ -var DOCKEDITEM = function() { +DOCKEDITEM = function() { DOCKEDITEM.superclass.constructor.apply(this, arguments); }; DOCKEDITEM.prototype = { @@ -1821,7 +1882,8 @@ DOCKEDITEM.prototype = { */ initializer : function() { var title = this.get('title'), - titlestring; + titlestring, + type; /** * Fired before the docked item has been drawn. * @event dockeditem:drawstart @@ -1858,7 +1920,7 @@ DOCKEDITEM.prototype = { */ this.publish('dockeditem:itemremoved', {prefix:'dockeditem'}); if (title) { - var type = title.get('nodeName'); + type = title.get('nodeName'); titlestring = title.cloneNode(true); title = Y.Node.create('<'+type+'>'); title = M.core.dock.fixTitleOrientation(title, titlestring.get('text')); @@ -1920,7 +1982,7 @@ DOCKEDITEM.prototype = { this.fire('dockeditem:showstart'); Y.log('Showing '+this._getLogDescription(), 'info', LOGNS); panel.setHeader(this.get('titlestring'), this.get('commands')); - panel.setBody(Y.Node.create('
').append(this.get('contents'))); + panel.setBody(Y.Node.create('
').append(this.get('contents'))); panel.show(); panel.correctWidth(); @@ -1972,7 +2034,7 @@ DOCKEDITEM.prototype = { remove : function () { this.hide(); // Return the block to its original position. - this.get('block').returnToBlock(); + this.get('block').returnToPage(); // Remove the dock item node. this.get('dockItemNode').remove(); this.fire('dockeditem:itemremoved'); diff --git a/lib/yui/build/moodle-core-dock/moodle-core-dock-min.js b/lib/yui/build/moodle-core-dock/moodle-core-dock-min.js index 2bfff9fcfb6..ed5757861fc 100644 --- a/lib/yui/build/moodle-core-dock/moodle-core-dock-min.js +++ b/lib/yui/build/moodle-core-dock/moodle-core-dock-min.js @@ -1,4 +1,4 @@ -YUI.add("moodle-core-dock",function(e,t){var n="moodle-core-dock",r=e.one(document.body),i={dock:"dock",dockspacer:"dockspacer",controls:"controls",body:"has_dock",buttonscontainer:"buttons_container",dockeditem:"dockeditem",dockeditemcontainer:"dockeditem_container",dockedtitle:"dockedtitle",activeitem:"activeitem",contentonly:"content-only",dockonload:"dock_on_load"},s={dockableblock:".block[data-instanceid][data-dockable]",blockmoveto:".block[data-instanceid][data-dockable] .moveto",panelmoveto:"#dockeditempanel .commands a.moveto",dockonload:".block."+i.dockonload,blockregion:"[data-blockregion]"};M.core=M.core||{},M.core.dock=M.core.dock||{},M.core.dock._dock=null,M.core.dock._dockableblocks={},M.core.dock.init=function(){e.all(s.dockableblock).each(M.core.dock.registerDockableBlock),r.delegate("click",M.core.dock.dockBlock,s.blockmoveto),r.delegate("key",M.core.dock.dockBlock,s.blockmoveto,"enter")},M.core.dock.get=function(){return this._dock===null&&(this._dock=new o),this._dock},M.core.dock.registerDockableBlock=function(e){typeof e=="object"&&typeof e.getData=="function"&&(e=e.getData("instanceid")),M.core.dock._dockableblocks[e]=new f({id:e})},M.core.dock.dockBlock=function(e){typeof e=="object"&&e.target!=="undefined"&&(e=e.target);if(typeof e=="object"){e.test(s.dockableblock)||(e=e.ancestor(s.dockableblock));if(typeof e!="object"||typeof e.getData!="function"||!!e.ancestor("."+i.dock))return;e=e.getData("instanceid")}var t=M.core.dock._dockableblocks[e];t&&t.moveToDock()},M.core.dock.fixTitleOrientation=function(t,n){var i=M.core.dock.get();t=e.one(t);if(i.get("orientation")!=="vertical")return t.setContent(n),t;e.UA.ie>0&&e.UA.ie<8&&(M.str.langconfig.thisdirectionvertical="ver");var s=!1;switch(M.str.langconfig.thisdirectionvertical){case"ver":return t.setContent(n.split("").join("
"));case"ttb":s=!0;break;case"btt":s=!1}if(e.UA.ie===8)return t.setContent(n),t.setAttribute("style","writing-mode: tb-rl; filter: flipV flipH;display:inline;"),t.addClass("filterrotate"),t;var o="11px",u=s?"rotate(90deg)":"rotate(270deg)",a=e.Node.create('

'+n+"

");r.insert(a,0);var f=a.one("span").get("offsetWidth")*1.2,l=a.one("span").get("offsetHeight");a.remove(),t.setContent(n),t.addClass("css3transform"),t.setStyles({margin:"0",padding:"0",position:"relative",fontSize:o,width:f,top:f/2}),right_to_left()?t.setStyle("left",f/2-l):t.setStyle("right",f/2-l),t.setStyles({transform:u,"-ms-transform":u,"-moz-transform":u,"-webkit-transform":u,"-o-transform":u});var c=e.Node.create("
");return c.append(t),c.setStyle("height",f+f/4),c.setStyle("position","relative"),c},M.core.dock.notifyBlockChange=function(e){if(this._dock!==null){var t=M.core.dock.get(),n=t.getActiveItem();n&&n.get("blockinstanceid")===parseInt(e,10)&&t.resizePanelIfRequired()}};var o=function(){o.superclass.constructor.apply(this,arguments)};o.prototype={tabheightmanager:null,preventevent:null,delayedevent:null,dockeditems:[],dockdrawn:!1,count:0,totalcount:0,holdingareanode:null,initializer:function(){this.publish("dock:starting",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:initialised",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:beforedraw",{prefix:"dock",fireOnce:!0}),this.publish("dock:beforeshow",{prefix:"dock"}),this.publish("dock:shown",{prefix:"dock"}),this.publish("dock:hidden",{prefix:"dock"}),this.publish("dock:itemadded",{prefix:"dock"}),this.publish("dock:itemremoved",{prefix:"dock"}),this.publish("dock:itemschanged",{prefix:"dock"}),this.publish("dock:panelgenerated",{prefix:"dock",fireOnce:!0}),this.publish("dock:panelresizestart",{prefix:"dock"}),this.publish("dock:resizepanelcomplete",{prefix:"dock"}),this._applyThemeCustomisation(),this.fire("dock:starting"),this._ensureDockDrawn(),this.fire("dock:initialised")},_ensureDockDrawn:function(){if(this.dockdrawn===!0)return!0;var t=this._initialiseDockNode();e.UA.ie>0&&e.UA.ie<7&&t.setStyle("height",t.get("winHeight")+"px"),this.fire("dock:beforedraw"),this._initialiseDockControls(),this.tabheightmanager=new a({dock:this});var n={cssselector:"."+i.dockedtitle,delay:0},o={cssselector:"."+i.dockedtitle,delay:.5,iscontained:!0,preventevent:"click",preventdelay:3};return e.delegate("click",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,n),e.delegate("mouseenter",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,o),this.get("dockNode").on("mouseleave",this.handleEvent,this,{cssselector:"#dock",delay:.5,iscontained:!1}),e.delegate("click",this.handleReturnToBlock,this.get("dockNode"),s.panelmoveto,this),e.delegate("click",this.handleReturnToBlock,this.get("dockNode"),s.panelmoveto,this),e.delegate("dock:actionkey",this.handleDockedItemEvent,this.get("dockNode"),"."+i.dockeditem,this),r.on("click",this.handleEvent,this,{cssselector:"body",delay:0}),this.on("dock:itemschanged",this.resizeBlockSpace,this),this.on("dock:itemschanged",this.checkDockVisibility,this),this.on("dock:itemschanged",this.resetFirstItem,this),this.dockdrawn=!0,!0},handleDockedItemEvent:function(e){if(e.type!=="dock:actionkey")return!1;var t=e.target,n="."+i.dockeditem;t.test(n)||(t=t.ancestor(n));if(!t)return!1;e.halt();var r=t.getAttribute("rel");this.dockeditems[r].toggle(e.action)},_applyThemeCustomisation:function(){if(typeof customise_dock_for_theme=="function"){M.core_dock=this,M.core_dock.cfg={buffer:null,orientation:null,position:null,spacebeforefirstitem:null,removeallicon:null},M.core_dock.css={dock:null,dockspacer:null,controls:null,body:null,buttonscontainer:null,dockeditem:null,dockeditemcontainer:null,dockedtitle:null,activeitem:null};try{customise_dock_for_theme(this)}catch(e){}var t,n,r=!1,s={buffer:"bufferPanel",orientation:"orientation",position:"position",spacebeforefirstitem:"bufferBeforeFirstItem",removeallicon:"undockAllIconUrl"};for(t in M.core_dock.cfg){n=M.core_dock.cfg[t];if(n===null)continue;r||(r=!0),this -.set(s[t],n)}for(t in M.core_dock.css){n=M.core_dock.css[t];if(n===null)continue;r||(r=!0),i[t]=n}}},_initialiseDockNode:function(){var t=this.get("dockNode"),n=i.dock+"_"+this.get("position")+"_"+this.get("orientation"),o=e.Node.create("
").setStyles({display:"none"}),u=this.get("buttonsNode"),a=this.get("itemContainerNode");return t||(t=e.one("#"+i.dock)),t||(t=e.Node.create('
'),r.append(t)),t.setAttribute("role","menubar").addClass(n),e.all(s.dockonload).size()===0?t.addClass("nothingdocked"):(n=i.body+"_"+this.get("position")+"_"+this.get("orientation"),r.addClass(i.body).addClass()),u||(u=t.one("."+i.buttonscontainer)),u||(u=e.Node.create('
'),t.append(u)),a||(a=t.one("."+i.dockeditemcontainer)),a||(a=e.Node.create('
'),u.append(a)),r.append(o),this.holdingareanode=o,this.set("dockNode",t),this.set("buttonsNode",u),this.set("itemContainerNode",a),t},_initialiseDockControls:function(){var t=e.Node.create(''+M.util.get_string(');t.setAttribute("src",this.get("undockAllIconUrl")),t.on("removeall|click",this.removeAll,this),t.on("dock:actionkey",this.removeAll,this,{actions:{enter:!0}}),this.get("buttonsNode").append(e.Node.create('
').append(t))},getPanel:function(){var t=this.get("panel");return t||(t=new u({dock:this}),t.on("panel:visiblechange",this.resize,this),e.on("windowresize",this.resize,this),this.set("panel",t),this.fire("dock:panelgenerated")),t},resizePanelIfRequired:function(){this.resize();var e=this.get("panel");e&&e.correctWidth()},handleEvent:function(e,t){var n=this.getActiveItem();if(t.cssselector==="body")this.get("dockNode").contains(e.target)||n&&n.hide();else{var r;e.target.test(t.cssselector)?r=e.target:r=e.target.ancestor(t.cssselector);if(!r)return!0;if(this.preventevent!==null&&e.type===this.preventevent)return!0;if(t.preventevent){this.preventevent=t.preventevent;if(t.preventdelay){var i=this;setTimeout(function(){i.preventevent=null},t.preventdelay*1e3)}}this.delayedevent&&this.delayedevent.timeout&&(clearTimeout(this.delayedevent.timeout),this.delayedevent.event.detach(),this.delayedevent=null);if(t.delay>0)return this.delayEvent(e,t,r);var s=r.get("id"),o=/^dock_item_(\d+)_title$/;s.match(o)?(n=this.dockeditems[s.replace(o,"$1")],n.active?n.hide():n.show()):n&&n.hide()}return!0},delayEvent:function(e,t,n){var i=this;return i.delayedevent=function(){return{target:n,event:r.on("mousemove",function(e){i.delayedevent.target=e.target}),timeout:null}}(i),i.delayedevent.timeout=setTimeout(function(){i.delayedevent.timeout=null,i.delayedevent.event.detach(),t.iscontained===i.get("dockNode").contains(i.delayedevent.target)&&i.handleEvent(e,{cssselector:t.cssselector,delay:0,iscontained:t.iscontained})},t.delay*1e3),!0},resizeBlockSpace:function(){if(e.all(s.dockonload).size()>0)return;var t=[],n=0,o=!0,u=!1;e.all(s.blockregion).each(function(){var e=region.getData("blockregion");region.all(".block").size()>0?(n++,r.addClass("used-region-"+e),r.removeClass("empty-region-"+e)):(r.addClass("empty-region-"+e),r.removeClass("used-region-"+e))}),e.all(".block-region").each(function(e){if(e.test(s.blockregion))return;var r=e.all(".block").size()>0;r&&n++,o=!1,t[e.get("id")]={hasblocks:r,bodyclass:e.get("id").replace(/^region\-/,"side-")+"-only"}}),r.hasClass("blocks-moving")&&(u=!0),n===0&&u===!1?r.addClass(i.contentonly):r.removeClass(i.contentonly);if(!o){var a=null;if(n===0&&u===!1)for(a in t)r.removeClass(t[a].bodyclass);else if(n===1&&u===!1)for(a in t)t[a].hasblocks?r.addClass(t[a].bodyclass):r.removeClass(t[a].bodyclass);else for(a in t)r.removeClass(t[a].bodyclass)}},add:function(e){e.set("id",this.totalcount),this.count++,this.totalcount++,this.dockeditems[e.get("id")]=e,this.dockeditems[e.get("id")].draw(),this.fire("dock:itemadded",e),this.fire("dock:itemschanged",e)},append:function(e){this.get("itemContainerNode").append(e)},handleReturnToBlock:function(e){e.halt(),this.remove(this.getActiveItem().get("id"))},remove:function(e){return this.dockeditems[e]?(this.dockeditems[e].remove(),delete this.dockeditems[e],this.count--,this.fire("dock:itemremoved",e),this.fire("dock:itemschanged",e),!0):!1},resetFirstItem:function(){this.get("dockNode").all("."+i.dockeditem+".firstdockitem").removeClass("firstdockitem"),this.get("dockNode").one("."+i.dockeditem)&&this.get("dockNode").one("."+i.dockeditem).addClass("firstdockitem")},removeAll:function(){for(var e in this.dockeditems)this.remove(e);return!0},hideActive:function(){var e=this.getActiveItem();e&&e.hide()},checkDockVisibility:function(){var e=i.body+"_"+this.get("position")+"_"+this.get("orientation");this.count?(this.fire("dock:beforeshow"),this.get("dockNode").removeClass("nothingdocked"),r.addClass(i.body).addClass(e),this.fire("dock:shown")):(this.get("dockNode").addClass("nothingdocked"),r.removeClass(i.body).removeClass(),this.fire("dock:hidden"))},resize:function(){var t=this.getPanel(),n=this.getActiveItem();if(!t.get("visible")||!n)return!0;this.fire("dock:panelresizestart");if(this.get("orientation")==="vertical"){var i=this.get("bufferPanel"),s=parseInt(r.get("winHeight"),10)-i*2,o=this.get("dockNode").getY(),u=n.get("dockTitleNode").getY()-o-i,a=this.get("itemContainerNode").getY(),f=a-o+this.get("buttonsNode").get("offsetHeight"),l=t.get("bodyNode").get("scrollTop");t.get("bodyNode").setStyle("height","auto"),t.get("node").removeClass("oversized_content");var c=t.get("node").get("offsetHeight");if(e.UA.ie>0&&e.UA.ie<7)t.setTop(n.get("dockTitleNode").getY());else if(c>s)t.setTop(i-f),t.get("bodyNode").setStyle("height",s-t.get("headerNode").get("offsetHeight")+"px"),t.get("node").addClass("oversized_content");else if(c>s-(u-i)){var h=c-(s-u);t.setTop(u-f-h+i)}else t.setTop(u-f+i);l&&t.get("bodyNode").set("scrollTop",l)}if(this.get("position")==="right")t.get("node").setStyle("left",-t.get("offsetWidth" -)+"px");else if(this.get("position")==="top"){var p=this.get("dockNode").getX(),d=n.get("dockTitleNode").getX()-p;t.get("node").setStyle("left",d+"px")}return this.fire("dock:resizepanelcomplete"),!0},getActiveItem:function(){for(var e in this.dockeditems)if(this.dockeditems[e].active)return this.dockeditems[e];return!1},addToHoldingArea:function(e){this.holdingareanode.append(e)}},e.extend(o,e.Base,o.prototype,{NAME:"moodle-core-dock",ATTRS:{dockNode:{writeOnce:!0},panel:{writeOnce:!0},buttonsNode:{writeOnce:!0},itemContainerNode:{writeOnce:!0},bufferPanel:{value:10,validator:e.Lang.isNumber},position:{value:"left",validator:e.Lang.isString},orientation:{value:"vertical",validator:e.Lang.isString,setter:function(e){return e.match(/^vertical$/i)?"vertical":"horizontal"}},bufferBeforeFirstItem:{value:10,validator:e.Lang.isNumber},undockAllIconUrl:{value:M.util.image_url("t/dock_to_block","moodle"),validator:e.Lang.isString}}}),e.augment(o,e.EventTarget);var u=function(){u.superclass.constructor.apply(this,arguments)};u.prototype={created:!1,initializer:function(){this.publish("dockpanel:beforeshow",{prefix:"dockpanel"}),this.publish("dockpanel:shown",{prefix:"dockpanel"}),this.publish("dockpanel:beforehide",{prefix:"dockpanel"}),this.publish("dockpanel:hidden",{prefix:"dockpanel"}),this.publish("dockpanel:visiblechange",{prefix:"dockpanel"})},create:function(){if(this.created)return!0;this.created=!0;var t=this.get("dock"),n=t.get("dockNode");this.set("node",e.Node.create('
')),this.set("contentNode",e.Node.create('
')),this.set("headerNode",e.Node.create('
')),this.set("bodyNode",e.Node.create('
')),n.append(this.get("node").append(this.get("contentNode").append(this.get("headerNode")).append(this.get("bodyNode"))))},show:function(){this.create(),this.fire("dockpanel:beforeshow"),this.set("visible",!0),this.get("node").removeClass("dockitempanel_hidden"),this.fire("dockpanel:shown"),this.fire("dockpanel:visiblechange")},hide:function(){this.fire("dockpanel:beforehide"),this.set("visible",!1),this.get("node").addClass("dockitempanel_hidden"),this.fire("dockpanel:hidden"),this.fire("dockpanel:visiblechange")},setHeader:function(e){this.create();var t=this.get("headerNode");t.setContent(e);if(arguments.length>1)for(var n=1;n0&&e.UA.ie<7?this.get("node").setY(t):this.get("node").setStyle("top",t.toString()+"px")},correctWidth:function(){var e=this.get("bodyNode"),t=e.get("clientWidth"),n=e.get("scrollWidth"),r=e.get("offsetWidth"),i=t,s=Math.round(e.get("winWidth")*.8);n>t&&(i=t+(n-t)+(r-t)*2+10),i>s&&(i=s),i>r&&this.get("node").setStyle("width",i+"px")}},e.extend(u,e.Base,u.prototype,{NAME:"moodle-core-dock-panel",ATTRS:{dock:{writeOnce:"initOnly"},node:{value:null},contentNode:{value:null},headerNode:{value:null},bodyNode:{value:null},visible:{value:!1}}}),e.augment(u,e.EventTarget);var a=function(){a.superclass.constructor.apply(this,arguments)};a.prototype={initializer:function(){var t=this.get("dock");t.on("dock:itemschanged",this.checkSizing,this),e.on("windowresize",this.checkSizing,this)},checkSizing:function(){var t=this.get("dock"),n=t.get("dockNode"),r=t.dockeditems,s=n.get("offsetHeight")-n.one(".controls").get("offsetHeight")-t.get("bufferPanel")*3-r.length*2,o=0,u,a;if(r.length>0){for(u in r)a=e.one(r[u].get("title")).ancestor("."+i.dockedtitle),a&&(this.get("enabled")&&a.setStyle("height","auto"),o+=a.get("offsetHeight")||0);o>s&&this.enable(s)}},enable:function(t){var n=this.get("dock"),r=n.dockeditems,s=n.count,o=0,u=0,a,f,l,c;this.set("enabled",!0);for(a in r){f=e.one(r[a].get("title")).ancestor("."+i.dockedtitle);if(!f)continue;l=Math.floor((t-u)/(s-o)),c=f.get("offsetHeight"),f.setStyle("overflow","hidden"),c>l?(f.setStyle("height",l+"px"),u+=l):u+=c,o++}}},e.extend(a,e.Base,a.prototype,{NAME:"moodle-core-tabheightmanager",ATTRS:{dock:{writeOnce:"initOnly"},enabled:{value:!1}}}),e.Event.define("dock:actionkey",{_event:e.UA.webkit||e.UA.ie?"keydown":"keypress",_keys:{37:"collapse",39:"expand",32:"toggle",13:"enter"},_keyHandler:function(e,t,n){var r;n.actions?r=n.actions:r={collapse:!0,expand:!0,toggle:!0,enter:!0},this._keys[e.keyCode]&&r[this._keys[e.keyCode]]&&(e.action=this._keys[e.keyCode],t.fire(e))},on:function(e,t,n){t.args===null?t._detacher=e.on(this._event,this._keyHandler,this,n,{actions:!1}):t._detacher=e.on(this._event,this._keyHandler,this,n,t.args[0])},detach:function(e,t,n){t._detacher.detach()},delegate:function(e,t,n,r){t.args===null?t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,{actions:!1}):t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,t.args[0])},detachDelegate:function(e,t,n,r){t._delegateDetacher.detach()}});var f=function(){f.superclass.constructor.apply(this,arguments)};f.prototype={contentplaceholder:null,contentskipanchor:null,cachedcontentnode:null,skipsetposition:!0,dockitem:null,initializer:function(){var t=e.one("#inst"+this.get("id"));if(!t)return!1;M.core.dock.ensureMoveToIconExists(t);if(t.hasClass(i.dockonload)){t.removeClass(i.dockonload);var n=t.one(".header .title .commands");n||(n=e.Node.create('
'),t.one(".header .title")&&t.one(".header .title").append(n)),this.moveToDock(null,n)}return this.skipsetposition=!1,!0},_getBlockClass:function(e){var t=e.getAttribute("className").toString(),n=/(^|\s)(block_[a-zA-Z0-9_]+)(\s|$)/,r=n.exec(t);return r?r[2]:r},moveToDock:function(t){t&&t.halt(!0);var n=M.core.dock.get(),r=this.get("id"),i=e.one("#inst"+r).one(".content");if(!i)return;var s=right_to_left()?"t/dock_to_block_rtl":"t/dock_to_block",o=location.href.match(/\?/)?"&":"?",u,a,f,c;this.recordBlockState(),u=this.cachedcontentnode.one(".title h2").cloneNode -(!0),a=this.cachedcontentnode.one(".title .commands").cloneNode(!0),f=e.Node.create(''+e.Escape.html(M.str.block.undockitem)+''),f.setAttribute("src",M.util.image_url(s,"moodle")),c=e.Node.create('').append(f),c.set("href",location.href+o+"dock="+r),a.append(c),this.dockitem=new l({block:this,dock:n,blockinstanceid:r,title:u,contents:i,commands:a,blockclass:this._getBlockClass(e.one("#inst"+r))}),n.add(this.dockitem),this.skipsetposition||M.util.set_user_preference("docked_block_instance_"+r,1),this.set("idDocked",!0)},recordBlockState:function(){var t=this.get("id"),n=M.core.dock.get(),r=e.one("#inst"+t),i=r.previous();i.hasClass("skip-block")&&(this.contentskipanchor=i,this.contentskipanchor.hide()),this.cachedcontentnode=r,this.contentplaceholder=e.Node.create('
'),r.replace(this.contentplaceholder),n.addToHoldingArea(r),r=null,this.cachedcontentnode.one(".title .commands")||this.cachedcontentnode.one(".title").append(e.Node.create('
'))},returnToBlock:function(){var t=this.get("id");this.contentskipanchor&&this.contentskipanchor.show(),this.cachedcontentnode.one(".header")?this.cachedcontentnode.one(".header").insert(this.dockitem.get("contents"),"after"):this.cachedcontentnode.insert(this.dockitem.get("contents")),this.contentplaceholder.replace(this.cachedcontentnode),this.cachedcontentnode=e.one("#"+this.cachedcontentnode.get("id"));var n=this.dockitem.get("commands");return n&&(n.all(".hidepanelicon").remove(),n.all(".moveto").remove(),n.remove()),this.cachedcontentnode.one(".title").append(n),this.cachedcontentnode=null,M.util.set_user_preference("docked_block_instance_"+t,0),this.set("idDocked",!1),!0}},e.extend(f,e.Base,f.prototype,{NAME:"moodle-core-dock-block",ATTRS:{id:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},isDocked:{value:!1}}});var l=function(){l.superclass.constructor.apply(this,arguments)};l.prototype={active:!1,initializer:function(){var t=this.get("title"),n;this.publish("dockeditem:drawstart",{prefix:"dockeditem"}),this.publish("dockeditem:drawcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:showstart",{prefix:"dockeditem"}),this.publish("dockeditem:showcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:hidestart",{prefix:"dockeditem"}),this.publish("dockeditem:hidecomplete",{prefix:"dockeditem"}),this.publish("dockeditem:itemremoved",{prefix:"dockeditem"});if(t){var r=t.get("nodeName");n=t.cloneNode(!0),t=e.Node.create("<"+r+">"),t=M.core.dock.fixTitleOrientation(t,n.get("text")),this.set("title",t),this.set("titlestring",n)}},draw:function(){var t=e.Node.create,n=this.get("dock"),r=n.count,s,o,u,a,f=this.get("id");return this.fire("dockeditem:drawstart"),s=t(''),s.append(this.get("title")),o=t('
'),r===1&&o.addClass("firstdockitem"),o.append(s),n.append(o),a=t(''+M.str.block.hidepanel+''),a.setAttribute("src",M.util.image_url("t/dockclose","moodle")),u=t('').append(a),u.on("forceclose|click",this.hide,this),u.on("dock:actionkey",this.hide,this,{actions:{enter:!0,toggle:!0}}),this.get("commands").append(u),this.set("dockTitleNode",s),this.set("dockItemNode",o),this.fire("dockeditem:drawcomplete"),!0},show:function(){var t=this.get("dock"),n=t.getPanel(),r=this.get("dockTitleNode");return t.hideActive(),this.fire("dockeditem:showstart"),n.setHeader(this.get("titlestring"),this.get("commands")),n.setBody(e.Node.create('
').append(this.get("contents"))),n.show(),n.correctWidth(),this.active=!0,r.addClass(i.activeitem),r.set("aria-expanded","true"),this.fire("dockeditem:showcomplete"),t.resize(),!0},hide:function(){this.fire("dockeditem:hidestart"),this.active&&(this.active=!1,this.get("dock").getPanel().hide()),this.get("dockTitleNode").removeClass(i.activeitem).set("aria-expanded","false"),this.fire("dockeditem:hidecomplete")},toggle:function(e){var t=this.get("dockTitleNode");t.hasClass(i.activeitem)&&e!=="expand"?this.hide():!t.hasClass(i.activeitem)&&e!=="collapse"&&this.show()},remove:function(){this.hide(),this.get("block").returnToBlock(),this.get("dockItemNode").remove(),this.fire("dockeditem:itemremoved")},_getLogDescription:function(){return this.get("titlestring").get("innerHTML")+" ("+this.get("blockinstanceid")+")"}},e.extend(l,e.Base,l.prototype,{NAME:"moodle-core-dock-dockeditem",ATTRS:{block:{writeOnce:"initOnly"},dock:{writeOnce:"initOnly"},id:{},blockinstanceid:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},title:{value:null},titlestring:{value:null},contents:{writeOnce:"initOnly"},commands:{writeOnce:"initOnly"},blockclass:{writeOnce:"initOnly"},dockTitleNode:{value:null},dockItemNode:{value:null},dockcontainerNode:{value:null}}}),e.augment(l,e.EventTarget)},"@VERSION@",{requires:["base","node","event-custom","event-mouseenter","event-resize","escape","moodle-core-dockloader"]}); +YUI.add("moodle-core-dock",function(e,t){var n="moodle-core-dock",r=e.one(e.config.doc.body),i={dock:"dock",dockspacer:"dockspacer",controls:"controls",body:"has_dock",buttonscontainer:"buttons_container",dockeditem:"dockeditem",dockeditemcontainer:"dockeditem_container",dockedtitle:"dockedtitle",activeitem:"activeitem",contentonly:"content-only",dockonload:"dock_on_load"},s={dockableblock:".block[data-instanceid][data-dockable]",blockmoveto:".block[data-instanceid][data-dockable] .moveto",panelmoveto:"#dockeditempanel .commands a.moveto",dockonload:".block."+i.dockonload,blockregion:"[data-blockregion]"},o,u,a,f,l;M.core=M.core||{},M.core.dock=M.core.dock||{},M.core.dock._dock=null,M.core.dock._dockableblocks={},M.core.dock.init=function(){e.all(s.dockableblock).each(M.core.dock.registerDockableBlock),r.delegate("click",M.core.dock.dockBlock,s.blockmoveto),r.delegate("key",M.core.dock.dockBlock,s.blockmoveto,"enter")},M.core.dock.get=function(){return this._dock===null&&(this._dock=new o),this._dock},M.core.dock.registerDockableBlock=function(e){typeof e=="object"&&typeof e.getData=="function"&&(e=e.getData("instanceid")),M.core.dock._dockableblocks[e]=new f({id:e})},M.core.dock.dockBlock=function(e){typeof e=="object"&&e.target!=="undefined"&&(e=e.target);if(typeof e=="object"){e.test(s.dockableblock)||(e=e.ancestor(s.dockableblock));if(typeof e!="object"||typeof e.getData!="function"||!!e.ancestor("."+i.dock))return;e=e.getData("instanceid")}var t=M.core.dock._dockableblocks[e];t&&t.moveToDock()},M.core.dock.fixTitleOrientation=function(t,n){var i=M.core.dock.get(),s="11px",o="rotate(270deg)",u,a,f,l;t=e.one(t);if(i.get("orientation")!=="vertical")return t.set("innerHTML",n),t;e.UA.ie>0&&e.UA.ie<8&&(M.str.langconfig.thisdirectionvertical="ver");switch(M.str.langconfig.thisdirectionvertical){case"ver":return t.set("innerHTML",n.split("").join("
"));case"ttb":o="rotate(90deg)";break;case"btt":}return e.UA.ie===8?(t.set("innerHTML",n),t.setAttribute("style","writing-mode: tb-rl; filter: flipV flipH;display:inline;"),t.addClass("filterrotate"),t):(u=e.Node.create('

'+n+"

"),r.insert(u,0),a=u.one("span").get("offsetWidth")*1.2,f=u.one("span").get("offsetHeight"),u.remove(),t.set("innerHTML",n),t.addClass("css3transform"),t.setStyles({margin:"0",padding:"0",position:"relative",fontSize:s,width:a,top:a/2}),right_to_left()?t.setStyle("left",a/2-f):t.setStyle("right",a/2-f),t.setStyles({transform:o,"-ms-transform":o,"-moz-transform":o,"-webkit-transform":o,"-o-transform":o}),l=e.Node.create("
"),l.append(t),l.setStyles({height:a+a/4,position:"relative"}),l)},M.core.dock.notifyBlockChange=function(e){if(this._dock!==null){var t=M.core.dock.get(),n=t.getActiveItem();n&&n.get("blockinstanceid")===parseInt(e,10)&&t.resizePanelIfRequired()}},o=function(){o.superclass.constructor.apply(this,arguments)},o.prototype={tabheightmanager:null,preventevent:null,delayedevent:null,dockeditems:[],dockdrawn:!1,count:0,totalcount:0,holdingareanode:null,initializer:function(){this.publish("dock:starting",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:initialised",{prefix:"dock",broadcast:2,emitFacade:!0,fireOnce:!0}),this.publish("dock:beforedraw",{prefix:"dock",fireOnce:!0}),this.publish("dock:beforeshow",{prefix:"dock"}),this.publish("dock:shown",{prefix:"dock"}),this.publish("dock:hidden",{prefix:"dock"}),this.publish("dock:itemadded",{prefix:"dock"}),this.publish("dock:itemremoved",{prefix:"dock"}),this.publish("dock:itemschanged",{prefix:"dock"}),this.publish("dock:panelgenerated",{prefix:"dock",fireOnce:!0}),this.publish("dock:panelresizestart",{prefix:"dock"}),this.publish("dock:resizepanelcomplete",{prefix:"dock"}),this._applyThemeCustomisation(),this.fire("dock:starting"),this._ensureDockDrawn(),this.fire("dock:initialised")},_ensureDockDrawn:function(){if(this.dockdrawn===!0)return!0;var t=this._initialiseDockNode(),n={cssselector:"."+i.dockedtitle,delay:0},o={cssselector:"."+i.dockedtitle,delay:.5,iscontained:!0,preventevent:"click",preventdelay:3};return e.UA.ie>0&&e.UA.ie<7&&t.setStyle("height",t.get("winHeight")+"px"),this.fire("dock:beforedraw"),this._initialiseDockControls(),this.tabheightmanager=new a({dock:this}),e.delegate("click",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,n),e.delegate("mouseenter",this.handleEvent,this.get("dockNode"),"."+i.dockedtitle,this,o),this.get("dockNode").on("mouseleave",this.handleEvent,this,{cssselector:"#dock",delay:.5,iscontained:!1}),e.delegate("click",this.handleReturnToBlock,this.get("dockNode"),s.panelmoveto,this),e.delegate("click",this.handleReturnToBlock,this.get("dockNode"),s.panelmoveto,this),e.delegate("dock:actionkey",this.handleDockedItemEvent,this.get("dockNode"),"."+i.dockeditem,this),r.on("click",this.handleEvent,this,{cssselector:"body",delay:0}),this.on("dock:itemschanged",this.resizeBlockSpace,this),this.on("dock:itemschanged",this.checkDockVisibility,this),this.on("dock:itemschanged",this.resetFirstItem,this),this.dockdrawn=!0,!0},handleDockedItemEvent:function(e){if(e.type!=="dock:actionkey")return!1;var t=e.target,n="."+i.dockeditem;t.test(n)||(t=t.ancestor(n));if(!t)return!1;e.halt(),this.dockeditems[t.getAttribute("rel")].toggle(e.action)},_applyThemeCustomisation:function(){if(typeof customise_dock_for_theme=="function"){M.core_dock=this,M.core_dock.cfg={buffer:null,orientation:null,position:null,spacebeforefirstitem:null,removeallicon:null},M.core_dock.css={dock:null,dockspacer:null,controls:null,body:null,buttonscontainer:null,dockeditem:null,dockeditemcontainer:null,dockedtitle:null,activeitem:null};try{customise_dock_for_theme(this)}catch(t){}var n,r,s=!1,o={buffer:"bufferPanel",orientation:"orientation",position:"position",spacebeforefirstitem:"bufferBeforeFirstItem",removeallicon:"undockAllIconUrl"};for(n in M.core_dock.cfg)if(e.Lang.isString(n)&&o[n]){r=M.core_dock.cfg[n];if(r===null)continue;s||(s=!0) +,this.set(o[n],r)}for(n in M.core_dock.css)if(e.Lang.isString(n)){r=M.core_dock.css[n];if(r===null)continue;s||(s=!0),i[n]=r}}},_initialiseDockNode:function(){var t=this.get("dockNode"),n=i.dock+"_"+this.get("position")+"_"+this.get("orientation"),o=e.Node.create("
").setStyles({display:"none"}),u=this.get("buttonsNode"),a=this.get("itemContainerNode");return t||(t=e.one("#"+i.dock)),t||(t=e.Node.create('
'),r.append(t)),t.setAttribute("role","menubar").addClass(n),e.all(s.dockonload).size()===0?t.addClass("nothingdocked"):(n=i.body+"_"+this.get("position")+"_"+this.get("orientation"),r.addClass(i.body).addClass()),u||(u=t.one("."+i.buttonscontainer)),u||(u=e.Node.create('
'),t.append(u)),a||(a=t.one("."+i.dockeditemcontainer)),a||(a=e.Node.create('
'),u.append(a)),r.append(o),this.holdingareanode=o,this.set("dockNode",t),this.set("buttonsNode",u),this.set("itemContainerNode",a),t},_initialiseDockControls:function(){var t=e.Node.create(''+M.util.get_string(');t.setAttribute("src",this.get("undockAllIconUrl")),t.on("removeall|click",this.removeAll,this),t.on("dock:actionkey",this.removeAll,this,{actions:{enter:!0}}),this.get("buttonsNode").append(e.Node.create('
').append(t))},getPanel:function(){var t=this.get("panel");return t||(t=new u({dock:this}),t.on("panel:visiblechange",this.resize,this),e.on("windowresize",this.resize,this),this.set("panel",t),this.fire("dock:panelgenerated")),t},resizePanelIfRequired:function(){this.resize();var e=this.get("panel");e&&e.correctWidth()},handleEvent:function(e,t){var n=this.getActiveItem(),r,i,s=/^dock_item_(\d+)_title$/,o=this;if(t.cssselector==="body")this.get("dockNode").contains(e.target)||n&&n.hide();else{e.target.test(t.cssselector)?r=e.target:r=e.target.ancestor(t.cssselector);if(!r)return!0;if(this.preventevent!==null&&e.type===this.preventevent)return!0;t.preventevent&&(this.preventevent=t.preventevent,t.preventdelay&&setTimeout(function(){o.preventevent=null},t.preventdelay*1e3)),this.delayedevent&&this.delayedevent.timeout&&(clearTimeout(this.delayedevent.timeout),this.delayedevent.event.detach(),this.delayedevent=null);if(t.delay>0)return this.delayEvent(e,t,r);i=r.get("id"),i.match(s)?(n=this.dockeditems[i.replace(s,"$1")],n.active?n.hide():n.show()):n&&n.hide()}return!0},delayEvent:function(e,t,n){var i=this;return i.delayedevent=function(){return{target:n,event:r.on("mousemove",function(e){i.delayedevent.target=e.target}),timeout:null}}(i),i.delayedevent.timeout=setTimeout(function(){i.delayedevent.timeout=null,i.delayedevent.event.detach(),t.iscontained===i.get("dockNode").contains(i.delayedevent.target)&&i.handleEvent(e,{cssselector:t.cssselector,delay:0,iscontained:t.iscontained})},t.delay*1e3),!0},resizeBlockSpace:function(){if(e.all(s.dockonload).size()>0)return;var t=[],n=0,o=!0,u=!1,a;e.all(s.blockregion).each(function(){var e=region.getData("blockregion");region.all(".block").size()>0?(n++,r.addClass("used-region-"+e),r.removeClass("empty-region-"+e)):(r.addClass("empty-region-"+e),r.removeClass("used-region-"+e))}),e.all(".block-region").each(function(e){if(e.test(s.blockregion))return;var r=e.all(".block").size()>0;r&&n++,o=!1,t[e.get("id")]={hasblocks:r,bodyclass:e.get("id").replace(/^region\-/,"side-")+"-only"}}),r.hasClass("blocks-moving")&&(u=!0),n===0&&u===!1?r.addClass(i.contentonly):r.removeClass(i.contentonly);if(!o)if(n===0&&u===!1)for(a in t)t[a].bodyclass&&r.removeClass(t[a].bodyclass);else if(n===1&&u===!1)for(a in t)t[a].bodyclass&&(t[a].hasblocks?r.addClass(t[a].bodyclass):r.removeClass(t[a].bodyclass));else for(a in t)t[a].bodyclass&&r.removeClass(t[a].bodyclass)},add:function(e){e.set("id",this.totalcount),this.count++,this.totalcount++,this.dockeditems[e.get("id")]=e,this.dockeditems[e.get("id")].draw(),this.fire("dock:itemadded",e),this.fire("dock:itemschanged",e)},append:function(e){this.get("itemContainerNode").append(e)},handleReturnToBlock:function(e){e.halt(),this.remove(this.getActiveItem().get("id"))},remove:function(e){return this.dockeditems[e]?(this.dockeditems[e].remove(),delete this.dockeditems[e],this.count--,this.fire("dock:itemremoved",e),this.fire("dock:itemschanged",e),!0):!1},resetFirstItem:function(){this.get("dockNode").all("."+i.dockeditem+".firstdockitem").removeClass("firstdockitem"),this.get("dockNode").one("."+i.dockeditem)&&this.get("dockNode").one("."+i.dockeditem).addClass("firstdockitem")},removeAll:function(){var t;for(t in this.dockeditems)(e.Lang.isNumber(t)||e.Lang.isString(t))&&this.remove(t);return!0},hideActive:function(){var e=this.getActiveItem();e&&e.hide()},checkDockVisibility:function(){var e=i.body+"_"+this.get("position")+"_"+this.get("orientation");this.count?(this.fire("dock:beforeshow"),this.get("dockNode").removeClass("nothingdocked"),r.addClass(i.body).addClass(e),this.fire("dock:shown")):(this.get("dockNode").addClass("nothingdocked"),r.removeClass(i.body).removeClass(),this.fire("dock:hidden"))},resize:function(){var t=this.getPanel(),n=this.getActiveItem(),i,s,o,u,a,f,l,c,h,p;return!t.get("visible")||!n?!0:(this.fire("dock:panelresizestart"),this.get("orientation")==="vertical"&&(i=this.get("bufferPanel"),s=parseInt(r.get("winHeight"),10)-i*2,o=this.get("dockNode").getY(),u=n.get("dockTitleNode").getY()-o-i,a=this.get("itemContainerNode").getY(),f=a-o+this.get("buttonsNode").get("offsetHeight"),l=t.get("bodyNode").get("scrollTop"),t.get("bodyNode").setStyle("height","auto"),t.get("node").removeClass("oversized_content"),c=t.get("node").get("offsetHeight"),e.UA.ie>0&&e.UA.ie<7?t.setTop(n.get("dockTitleNode").getY()):c>s?(t.setTop(i-f),t.get("bodyNode").setStyle("height",s-t.get("headerNode").get("offsetHeight")+"px"),t.get("node").addClass("oversized_content")):c>s-(u-i)?t.setTop(u-f-(c-(s-u))+i):t.setTop(u-f+i),l&&t.get("bodyNode").set("scrollTop",l)),this. +get("position")==="right"?t.get("node").setStyle("left",-t.get("offsetWidth")+"px"):this.get("position")==="top"&&(h=this.get("dockNode").getX(),p=n.get("dockTitleNode").getX()-h,t.get("node").setStyle("left",p+"px")),this.fire("dock:resizepanelcomplete"),!0)},getActiveItem:function(){var e;for(e in this.dockeditems)if(this.dockeditems[e].active)return this.dockeditems[e];return!1},addToHoldingArea:function(e){this.holdingareanode.append(e)}},e.extend(o,e.Base,o.prototype,{NAME:"moodle-core-dock",ATTRS:{dockNode:{writeOnce:!0},panel:{writeOnce:!0},buttonsNode:{writeOnce:!0},itemContainerNode:{writeOnce:!0},bufferPanel:{value:10,validator:e.Lang.isNumber},position:{value:"left",validator:e.Lang.isString},orientation:{value:"vertical",validator:e.Lang.isString,setter:function(e){return e.match(/^vertical$/i)?"vertical":"horizontal"}},bufferBeforeFirstItem:{value:10,validator:e.Lang.isNumber},undockAllIconUrl:{value:M.util.image_url("t/dock_to_block","moodle"),validator:e.Lang.isString}}}),e.augment(o,e.EventTarget),u=function(){u.superclass.constructor.apply(this,arguments)},u.prototype={created:!1,initializer:function(){this.publish("dockpanel:beforeshow",{prefix:"dockpanel"}),this.publish("dockpanel:shown",{prefix:"dockpanel"}),this.publish("dockpanel:beforehide",{prefix:"dockpanel"}),this.publish("dockpanel:hidden",{prefix:"dockpanel"}),this.publish("dockpanel:visiblechange",{prefix:"dockpanel"})},create:function(){if(this.created)return!0;this.created=!0;var t=this.get("dock"),n=t.get("dockNode");this.set("node",e.Node.create('
')),this.set("contentNode",e.Node.create('
')),this.set("headerNode",e.Node.create('
')),this.set("bodyNode",e.Node.create('
')),n.append(this.get("node").append(this.get("contentNode").append(this.get("headerNode")).append(this.get("bodyNode"))))},show:function(){this.create(),this.fire("dockpanel:beforeshow"),this.set("visible",!0),this.get("node").removeClass("dockitempanel_hidden"),this.fire("dockpanel:shown"),this.fire("dockpanel:visiblechange")},hide:function(){this.fire("dockpanel:beforehide"),this.set("visible",!1),this.get("node").addClass("dockitempanel_hidden"),this.fire("dockpanel:hidden"),this.fire("dockpanel:visiblechange")},setHeader:function(t){this.create();var n=this.get("headerNode"),r;n.setContent(t);if(arguments.length>1)for(r=1;r0&&e.UA.ie<7?this.get("node").setY(t):this.get("node").setStyle("top",t.toString()+"px")},correctWidth:function(){var e=this.get("bodyNode"),t=e.get("clientWidth"),n=e.get("scrollWidth"),r=e.get("offsetWidth"),i=t,s=Math.round(e.get("winWidth")*.8);n>t&&(i=t+(n-t)+(r-t)*2+10),i>s&&(i=s),i>r&&this.get("node").setStyle("width",i+"px")}},e.extend(u,e.Base,u.prototype,{NAME:"moodle-core-dock-panel",ATTRS:{dock:{writeOnce:"initOnly"},node:{value:null},contentNode:{value:null},headerNode:{value:null},bodyNode:{value:null},visible:{value:!1}}}),e.augment(u,e.EventTarget),a=function(){a.superclass.constructor.apply(this,arguments)},a.prototype={initializer:function(){var t=this.get("dock");t.on("dock:itemschanged",this.checkSizing,this),e.on("windowresize",this.checkSizing,this)},checkSizing:function(){var t=this.get("dock"),n=t.get("dockNode"),r=t.dockeditems,s=n.get("offsetHeight")-n.one(".controls").get("offsetHeight")-t.get("bufferPanel")*3-r.length*2,o=0,u,a;if(r.length>0){for(u in r)if(e.Lang.isNumber(u)||e.Lang.isString(u))a=e.one(r[u].get("title")).ancestor("."+i.dockedtitle),a&&(this.get("enabled")&&a.setStyle("height","auto"),o+=a.get("offsetHeight")||0);o>s&&this.enable(s)}},enable:function(t){var n=this.get("dock"),r=n.dockeditems,s=n.count,o=0,u=0,a,f,l,c;this.set("enabled",!0);for(a in r)if(e.Lang.isNumber(a)||e.Lang.isString(a)){f=e.one(r[a].get("title")).ancestor("."+i.dockedtitle);if(!f)continue;l=Math.floor((t-u)/(s-o)),c=f.get("offsetHeight"),f.setStyle("overflow","hidden"),c>l?(f.setStyle("height",l+"px"),u+=l):u+=c,o++}}},e.extend(a,e.Base,a.prototype,{NAME:"moodle-core-tabheightmanager",ATTRS:{dock:{writeOnce:"initOnly"},enabled:{value:!1}}}),e.Event.define("dock:actionkey",{_event:e.UA.webkit||e.UA.ie?"keydown":"keypress",_keys:{37:"collapse",39:"expand",32:"toggle",13:"enter"},_keyHandler:function(e,t,n){var r;n.actions?r=n.actions:r={collapse:!0,expand:!0,toggle:!0,enter:!0},this._keys[e.keyCode]&&r[this._keys[e.keyCode]]&&(e.action=this._keys[e.keyCode],t.fire(e))},on:function(e,t,n){t.args===null?t._detacher=e.on(this._event,this._keyHandler,this,n,{actions:!1}):t._detacher=e.on(this._event,this._keyHandler,this,n,t.args[0])},detach:function(e,t){t._detacher.detach()},delegate:function(e,t,n,r){t.args===null?t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,{actions:!1}):t._delegateDetacher=e.delegate(this._event,this._keyHandler,r,this,n,t.args[0])},detachDelegate:function(e,t){t._delegateDetacher.detach()}}),f=function(){f.superclass.constructor.apply(this,arguments)},f.prototype={contentplaceholder:null,contentskipanchor:null,cachedcontentnode:null,skipsetposition:!0,dockitem:null,initializer:function(){var t=e.one("#inst"+this.get("id")),n;return t?(M.core.dock.ensureMoveToIconExists(t),t.hasClass(i.dockonload)&&(t.removeClass(i.dockonload),n=t.one(".header .title .commands"),n||(n=e.Node.create('
'),t.one(".header .title")&&t.one(".header .title").append(n)),this.moveToDock(null,n)),this.skipsetposition=!1,!0):!1},_getBlockClass:function(t){var n=t.getData("block"),r,i;return e.Lang.isString(n)&&n!==""?n:(r=t.getAttribute("className").toString(),i=/(^| )block_([^ ]+)/.exec(r),i?i[2]:i)},moveToDock:function(t){t&&t.halt(!0);var n=M.core.dock.get(),r=this.get("id"),i=e.one("#inst"+r).one(".content" +),s=right_to_left()?"t/dock_to_block_rtl":"t/dock_to_block",o=location.href.match(/\?/)?"&":"?",u,a,f,c;if(!i)return;this.recordBlockState(),u=this.cachedcontentnode.one(".title h2").cloneNode(!0),a=this.cachedcontentnode.one(".title .commands").cloneNode(!0),f=e.Node.create("").setAttrs({alt:e.Escape.html(M.str.block.undockitem),title:e.Escape.html(M.util.get_string("undockblock","block",u.innerHTML)),src:M.util.image_url(s,"moodle")}),c=e.Node.create('').setAttrs({className:"moveto customcommand requiresjs",href:e.config.win.location.href+o+"dock="+r}),c.append(f),a.append(c.append(f)),this.dockitem=new l({block:this,dock:n,blockinstanceid:r,title:u,contents:i,commands:a,blockclass:this._getBlockClass(e.one("#inst"+r))}),n.add(this.dockitem),this.skipsetposition||M.util.set_user_preference("docked_block_instance_"+r,1),this.set("isDocked",!0)},recordBlockState:function(){var t=this.get("id"),n=M.core.dock.get(),r=e.one("#inst"+t),i=r.previous();i.hasClass("skip-block")&&(this.contentskipanchor=i,this.contentskipanchor.hide()),this.cachedcontentnode=r,this.contentplaceholder=e.Node.create('
'),r.replace(this.contentplaceholder),n.addToHoldingArea(r),r=null,this.cachedcontentnode.one(".title .commands")||this.cachedcontentnode.one(".title").append(e.Node.create('
'))},returnToPage:function(){var t=this.get("id"),n;return this.contentskipanchor&&this.contentskipanchor.show(),this.cachedcontentnode.one(".header")?this.cachedcontentnode.one(".header").insert(this.dockitem.get("contents"),"after"):this.cachedcontentnode.insert(this.dockitem.get("contents")),this.contentplaceholder.replace(this.cachedcontentnode),this.cachedcontentnode=e.one("#"+this.cachedcontentnode.get("id")),n=this.dockitem.get("commands"),n&&(n.all(".hidepanelicon").remove(),n.all(".moveto").remove(),n.remove()),this.cachedcontentnode.one(".title").append(n),this.cachedcontentnode=null,M.util.set_user_preference("docked_block_instance_"+t,0),this.set("isDocked",!1),!0}},e.extend(f,e.Base,f.prototype,{NAME:"moodle-core-dock-block",ATTRS:{id:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},isDocked:{value:!1}}}),l=function(){l.superclass.constructor.apply(this,arguments)},l.prototype={active:!1,initializer:function(){var t=this.get("title"),n,r;this.publish("dockeditem:drawstart",{prefix:"dockeditem"}),this.publish("dockeditem:drawcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:showstart",{prefix:"dockeditem"}),this.publish("dockeditem:showcomplete",{prefix:"dockeditem"}),this.publish("dockeditem:hidestart",{prefix:"dockeditem"}),this.publish("dockeditem:hidecomplete",{prefix:"dockeditem"}),this.publish("dockeditem:itemremoved",{prefix:"dockeditem"}),t&&(r=t.get("nodeName"),n=t.cloneNode(!0),t=e.Node.create("<"+r+">"),t=M.core.dock.fixTitleOrientation(t,n.get("text")),this.set("title",t),this.set("titlestring",n))},draw:function(){var t=e.Node.create,n=this.get("dock"),r=n.count,s,o,u,a,f=this.get("id");return this.fire("dockeditem:drawstart"),s=t(''),s.append(this.get("title")),o=t('
'),r===1&&o.addClass("firstdockitem"),o.append(s),n.append(o),a=t(''+M.str.block.hidepanel+''),a.setAttribute("src",M.util.image_url("t/dockclose","moodle")),u=t('').append(a),u.on("forceclose|click",this.hide,this),u.on("dock:actionkey",this.hide,this,{actions:{enter:!0,toggle:!0}}),this.get("commands").append(u),this.set("dockTitleNode",s),this.set("dockItemNode",o),this.fire("dockeditem:drawcomplete"),!0},show:function(){var t=this.get("dock"),n=t.getPanel(),r=this.get("dockTitleNode");return t.hideActive(),this.fire("dockeditem:showstart"),n.setHeader(this.get("titlestring"),this.get("commands")),n.setBody(e.Node.create('
').append(this.get("contents"))),n.show(),n.correctWidth(),this.active=!0,r.addClass(i.activeitem),r.set("aria-expanded","true"),this.fire("dockeditem:showcomplete"),t.resize(),!0},hide:function(){this.fire("dockeditem:hidestart"),this.active&&(this.active=!1,this.get("dock").getPanel().hide()),this.get("dockTitleNode").removeClass(i.activeitem).set("aria-expanded","false"),this.fire("dockeditem:hidecomplete")},toggle:function(e){var t=this.get("dockTitleNode");t.hasClass(i.activeitem)&&e!=="expand"?this.hide():!t.hasClass(i.activeitem)&&e!=="collapse"&&this.show()},remove:function(){this.hide(),this.get("block").returnToPage(),this.get("dockItemNode").remove(),this.fire("dockeditem:itemremoved")},_getLogDescription:function(){return this.get("titlestring").get("innerHTML")+" ("+this.get("blockinstanceid")+")"}},e.extend(l,e.Base,l.prototype,{NAME:"moodle-core-dock-dockeditem",ATTRS:{block:{writeOnce:"initOnly"},dock:{writeOnce:"initOnly"},id:{},blockinstanceid:{writeOnce:"initOnly",setter:function(e){return parseInt(e,10)}},title:{value:null},titlestring:{value:null},contents:{writeOnce:"initOnly"},commands:{writeOnce:"initOnly"},blockclass:{writeOnce:"initOnly"},dockTitleNode:{value:null},dockItemNode:{value:null},dockcontainerNode:{value:null}}}),e.augment(l,e.EventTarget)},"@VERSION@",{requires:["base","node","event-custom","event-mouseenter","event-resize","escape","moodle-core-dockloader"]}); diff --git a/lib/yui/build/moodle-core-dock/moodle-core-dock.js b/lib/yui/build/moodle-core-dock/moodle-core-dock.js index 66efa1ae6dc..6542245257c 100644 --- a/lib/yui/build/moodle-core-dock/moodle-core-dock.js +++ b/lib/yui/build/moodle-core-dock/moodle-core-dock.js @@ -9,28 +9,33 @@ YUI.add('moodle-core-dock', function (Y, NAME) { */ -var LOGNS = 'moodle-core-dock'; -var BODY = Y.one(document.body); -var CSS = { - dock: 'dock', // CSS Class applied to the dock box - dockspacer: 'dockspacer', // CSS class applied to the dockspacer - controls: 'controls', // CSS class applied to the controls box - body: 'has_dock', // CSS class added to the body when there is a dock - buttonscontainer: 'buttons_container', - dockeditem: 'dockeditem', // CSS class added to each item in the dock - dockeditemcontainer: 'dockeditem_container', - dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock - activeitem: 'activeitem', // CSS class added to the active item - contentonly: 'content-only', - dockonload: 'dock_on_load' -}; -var SELECTOR = { - dockableblock: '.block[data-instanceid][data-dockable]', - blockmoveto: '.block[data-instanceid][data-dockable] .moveto', - panelmoveto: '#dockeditempanel .commands a.moveto', - dockonload: '.block.'+CSS.dockonload, - blockregion: '[data-blockregion]' -}; +var LOGNS = 'moodle-core-dock', + BODY = Y.one(Y.config.doc.body), + CSS = { + dock: 'dock', // CSS Class applied to the dock box + dockspacer: 'dockspacer', // CSS class applied to the dockspacer + controls: 'controls', // CSS class applied to the controls box + body: 'has_dock', // CSS class added to the body when there is a dock + buttonscontainer: 'buttons_container', + dockeditem: 'dockeditem', // CSS class added to each item in the dock + dockeditemcontainer: 'dockeditem_container', + dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock + activeitem: 'activeitem', // CSS class added to the active item + contentonly: 'content-only', + dockonload: 'dock_on_load' + }, + SELECTOR = { + dockableblock: '.block[data-instanceid][data-dockable]', + blockmoveto: '.block[data-instanceid][data-dockable] .moveto', + panelmoveto: '#dockeditempanel .commands a.moveto', + dockonload: '.block.'+CSS.dockonload, + blockregion: '[data-blockregion]' + }, + DOCK, + DOCKPANEL, + TABHEIGHTMANAGER, + BLOCK, + DOCKEDITEM; /** * Core namespace. @@ -146,12 +151,18 @@ M.core.dock.dockBlock = function(id) { * @return {Node} The title node to use. */ M.core.dock.fixTitleOrientation = function(title, text) { - var dock = M.core.dock.get(); + var dock = M.core.dock.get(), + fontsize = '11px', + transform = 'rotate(270deg)', + test, + width, + height, + container; title = Y.one(title); if (dock.get('orientation') !== 'vertical') { // If the dock isn't vertical don't adjust it! - title.setContent(text); + title.set('innerHTML', text); return title; } @@ -160,37 +171,34 @@ M.core.dock.fixTitleOrientation = function(title, text) { M.str.langconfig.thisdirectionvertical = 'ver'; } - var clockwise = false; switch (M.str.langconfig.thisdirectionvertical) { case 'ver': // Stacked is easy - return title.setContent(text.split('').join('
')); + return title.set('innerHTML', text.split('').join('
')); case 'ttb': - clockwise = true; + transform = 'rotate(90deg)'; break; case 'btt': - clockwise = false; + // Nothing to do here. transform default is good. break; } if (Y.UA.ie === 8) { // IE8 can flip the text via CSS but not handle transform. IE9+ can handle the CSS3 transform attribute. - title.setContent(text); + title.set('innerHTML', text); title.setAttribute('style', 'writing-mode: tb-rl; filter: flipV flipH;display:inline;'); title.addClass('filterrotate'); return title; } // We need to fix a font-size - sorry theme designers. - var fontsize = '11px'; - var transform = (clockwise) ? 'rotate(90deg)' : 'rotate(270deg)'; - var test = Y.Node.create('

'+text+'

'); + test = Y.Node.create('

'+text+'

'); BODY.insert(test, 0); - var width = test.one('span').get('offsetWidth') * 1.2; - var height = test.one('span').get('offsetHeight'); + width = test.one('span').get('offsetWidth') * 1.2; + height = test.one('span').get('offsetHeight'); test.remove(); - title.setContent(text); + title.set('innerHTML', text); title.addClass('css3transform'); // Move the title into position @@ -219,10 +227,12 @@ M.core.dock.fixTitleOrientation = function(title, text) { '-o-transform' : transform }); - var container = Y.Node.create('
'); + container = Y.Node.create('
'); container.append(title); - container.setStyle('height', width + (width / 4)); - container.setStyle('position', 'relative'); + container.setStyles({ + height : width + (width / 4), + position : 'relative' + }); return container; }; @@ -255,7 +265,7 @@ M.core.dock.notifyBlockChange = function(instanceid) { * @extends Y.Base * @uses Y.EventTarget */ -var DOCK = function() { +DOCK = function() { DOCK.superclass.constructor.apply(this, arguments); }; DOCK.prototype = { @@ -320,7 +330,7 @@ DOCK.prototype = { * @method initializer */ initializer : function() { - + // Publish the events the dock has /** * Fired when the dock first starts initialising. @@ -402,7 +412,18 @@ DOCK.prototype = { if (this.dockdrawn === true) { return true; } - var dock = this._initialiseDockNode(); + var dock = this._initialiseDockNode(), + clickargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0 + }, + mouseenterargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0.5, + iscontained:true, + preventevent:'click', + preventdelay:3 + }; if (Y.UA.ie > 0 && Y.UA.ie < 7) { // Adjust for IE 6 (can't handle fixed pos) dock.setStyle('height', dock.get('winHeight')+'px'); @@ -414,9 +435,6 @@ DOCK.prototype = { this.tabheightmanager = new TABHEIGHTMANAGER({dock:this}); - var clickargs = {cssselector:'.'+CSS.dockedtitle, delay:0}; - var mouseenterargs = {cssselector:'.'+CSS.dockedtitle, delay:0.5, iscontained:true, preventevent:'click', preventdelay:3}; - // Attach the required event listeners // We use delegate here as that way a handful of events are created for the dock // and all items rather than the same number for the dock AND every item individually @@ -454,8 +472,7 @@ DOCK.prototype = { return false; } e.halt(); - var id = target.getAttribute('rel'); - this.dockeditems[id].toggle(e.action); + this.dockeditems[target.getAttribute('rel')].toggle(e.action); }, /** * Call the theme customisation method "customise_dock_for_theme" if it exists. @@ -503,27 +520,31 @@ DOCK.prototype = { }; // Check for and apply any legacy configuration. for (key in M.core_dock.cfg) { - value = M.core_dock.cfg[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key) && cfgmap[key]) { + value = M.core_dock.cfg[key]; + if (value === null) { + continue; + } + if (!warned) { + warned = true; + } + // Damn, the've set something. + this.set(cfgmap[key], value); } - if (!warned) { - warned = true; - } - // Damn, the've set something. - this.set(cfgmap[key], value); } // Check for and apply any legacy CSS changes.. for (key in M.core_dock.css) { - value = M.core_dock.css[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key)) { + value = M.core_dock.css[key]; + if (value === null) { + continue; + } + if (!warned) { + warned = true; + } + // Damn, they've set something. + CSS[key] = value; } - if (!warned) { - warned = true; - } - // Damn, they've set something. - CSS[key] = value; } } }, @@ -540,7 +561,7 @@ DOCK.prototype = { holdingarea = Y.Node.create('
').setStyles({display:'none'}), buttons = this.get('buttonsNode'), container = this.get('itemContainerNode'); - + if (!dock) { dock = Y.one('#'+CSS.dock); } @@ -635,7 +656,11 @@ DOCK.prototype = { * @return {Boolean} */ handleEvent : function(e, options) { - var item = this.getActiveItem(); + var item = this.getActiveItem(), + target, + targetid, + regex = /^dock_item_(\d+)_title$/, + self = this; if (options.cssselector === 'body') { if (!this.get('dockNode').contains(e.target)) { if (item) { @@ -643,7 +668,6 @@ DOCK.prototype = { } } } else { - var target; if (e.target.test(options.cssselector)) { target = e.target; } else { @@ -658,7 +682,6 @@ DOCK.prototype = { if (options.preventevent) { this.preventevent = options.preventevent; if (options.preventdelay) { - var self = this; setTimeout(function(){ self.preventevent = null; }, options.preventdelay * 1000); @@ -672,8 +695,7 @@ DOCK.prototype = { if (options.delay > 0) { return this.delayEvent(e, options, target); } - var targetid = target.get('id'); - var regex = /^dock_item_(\d+)_title$/; + targetid = target.get('id'); if (targetid.match(regex)) { item = this.dockeditems[targetid.replace(regex, '$1')]; if (item.active) { @@ -728,7 +750,8 @@ DOCK.prototype = { var blockregions = [], populatedblockregions = 0, allnewregions = true, - showregions = false; + showregions = false, + i; // First look for understood regions. Y.all(SELECTOR.blockregion).each(function(){ var regionname = region.getData('blockregion'); @@ -768,22 +791,27 @@ DOCK.prototype = { } if (!allnewregions) { - var i = null; if (populatedblockregions === 0 && showregions === false) { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } else if (populatedblockregions === 1 && showregions === false) { for (i in blockregions) { - if (!blockregions[i].hasblocks) { - BODY.removeClass(blockregions[i].bodyclass); - } else { - BODY.addClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + if (!blockregions[i].hasblocks) { + BODY.removeClass(blockregions[i].bodyclass); + } else { + BODY.addClass(blockregions[i].bodyclass); + } } } } else { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } } @@ -853,8 +881,11 @@ DOCK.prototype = { * @return {Boolean} */ removeAll : function() { - for (var i in this.dockeditems) { - this.remove(i); + var i; + for (i in this.dockeditems) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + this.remove(i); + } } return true; }, @@ -892,34 +923,43 @@ DOCK.prototype = { * @return {Boolean} */ resize : function() { - var panel = this.getPanel(); - var item = this.getActiveItem(); + var panel = this.getPanel(), + item = this.getActiveItem(), + buffer, + screenh, + docky, + titletop, + containery, + containerheight, + scrolltop, + panelheight, + dockx, + titleleft; if (!panel.get('visible') || !item) { return true; } this.fire('dock:panelresizestart'); if (this.get('orientation') === 'vertical') { - var buffer = this.get('bufferPanel'); - var screenheight = parseInt(BODY.get('winHeight'), 10)-(buffer*2); - var docky = this.get('dockNode').getY(); - var titletop = item.get('dockTitleNode').getY()-docky-buffer; - var containery = this.get('itemContainerNode').getY(); - var containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); - var scrolltop = panel.get('bodyNode').get('scrollTop'); + buffer = this.get('bufferPanel'); + screenh = parseInt(BODY.get('winHeight'), 10)-(buffer*2); + docky = this.get('dockNode').getY(); + titletop = item.get('dockTitleNode').getY()-docky-buffer; + containery = this.get('itemContainerNode').getY(); + containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); + scrolltop = panel.get('bodyNode').get('scrollTop'); panel.get('bodyNode').setStyle('height', 'auto'); panel.get('node').removeClass('oversized_content'); - var panelheight = panel.get('node').get('offsetHeight'); + panelheight = panel.get('node').get('offsetHeight'); if (Y.UA.ie > 0 && Y.UA.ie < 7) { panel.setTop(item.get('dockTitleNode').getY()); - } else if (panelheight > screenheight) { + } else if (panelheight > screenh) { panel.setTop(buffer-containerheight); - panel.get('bodyNode').setStyle('height', (screenheight-panel.get('headerNode').get('offsetHeight'))+'px'); + panel.get('bodyNode').setStyle('height', (screenh-panel.get('headerNode').get('offsetHeight'))+'px'); panel.get('node').addClass('oversized_content'); - } else if (panelheight > (screenheight-(titletop-buffer))) { - var difference = panelheight - (screenheight-titletop); - panel.setTop(titletop-containerheight-difference+buffer); + } else if (panelheight > (screenh-(titletop-buffer))) { + panel.setTop(titletop-containerheight-(panelheight - (screenh-titletop))+buffer); } else { panel.setTop(titletop-containerheight+buffer); } @@ -933,8 +973,8 @@ DOCK.prototype = { panel.get('node').setStyle('left', -panel.get('offsetWidth')+'px'); } else if (this.get('position') === 'top') { - var dockx = this.get('dockNode').getX(); - var titleleft = item.get('dockTitleNode').getX()-dockx; + dockx = this.get('dockNode').getX(); + titleleft = item.get('dockTitleNode').getX()-dockx; panel.get('node').setStyle('left', titleleft+'px'); } @@ -947,7 +987,8 @@ DOCK.prototype = { * @return {DOCKEDITEM} */ getActiveItem : function() { - for (var i in this.dockeditems) { + var i; + for (i in this.dockeditems) { if (this.dockeditems[i].active) { return this.dockeditems[i]; } @@ -1084,7 +1125,7 @@ Y.augment(DOCK, Y.EventTarget); * @extends Y.Base * @uses Y.EventTarget */ -var DOCKPANEL = function() { +DOCKPANEL = function() { DOCKPANEL.superclass.constructor.apply(this, arguments); }; DOCKPANEL.prototype = { @@ -1177,11 +1218,14 @@ DOCKPANEL.prototype = { */ setHeader : function(content) { this.create(); - var header = this.get('headerNode'); + var header = this.get('headerNode'), + i; header.setContent(content); if (arguments.length > 1) { - for (var i=1;i < arguments.length;i++) { - header.append(arguments[i]); + for (i = 1; i < arguments.length; i++) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + header.append(arguments[i]); + } } } }, @@ -1316,7 +1360,7 @@ Y.augment(DOCKPANEL, Y.EventTarget); * @constructor * @extends Y.Base */ -var TABHEIGHTMANAGER = function() { +TABHEIGHTMANAGER = function() { TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments); }; TABHEIGHTMANAGER.prototype = { @@ -1343,12 +1387,14 @@ TABHEIGHTMANAGER.prototype = { id, dockedtitle; if (items.length > 0) { for (id in items) { - dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (dockedtitle) { - if (this.get('enabled')) { - dockedtitle.setStyle('height', 'auto'); + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (dockedtitle) { + if (this.get('enabled')) { + dockedtitle.setStyle('height', 'auto'); + } + totalheight += dockedtitle.get('offsetHeight') || 0; } - totalheight += dockedtitle.get('offsetHeight') || 0; } } if (totalheight > possibleheight) { @@ -1370,20 +1416,22 @@ TABHEIGHTMANAGER.prototype = { id, itemtitle, itemheight, offsetheight; this.set('enabled', true); for (id in items) { - itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (!itemtitle) { - continue; + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (!itemtitle) { + continue; + } + itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); + offsetheight = itemtitle.get('offsetHeight'); + itemtitle.setStyle('overflow', 'hidden'); + if (offsetheight > itemheight) { + itemtitle.setStyle('height', itemheight+'px'); + usedheight += itemheight; + } else { + usedheight += offsetheight; + } + runningcount++; } - itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); - offsetheight = itemtitle.get('offsetHeight'); - itemtitle.setStyle('overflow', 'hidden'); - if (offsetheight > itemheight) { - itemtitle.setStyle('height', itemheight+'px'); - usedheight += itemheight; - } else { - usedheight += offsetheight; - } - runningcount++; } } }; @@ -1432,24 +1480,24 @@ Y.extend(TABHEIGHTMANAGER, Y.Base, TABHEIGHTMANAGER.prototype, { * @class ActionKey */ Y.Event.define("dock:actionkey", { - // Webkit and IE repeat keydown when you hold down arrow keys. - // Opera links keypress to page scroll; others keydown. - // Firefox prevents page scroll via preventDefault() on either - // keydown or keypress. - _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', + // Webkit and IE repeat keydown when you hold down arrow keys. + // Opera links keypress to page scroll; others keydown. + // Firefox prevents page scroll via preventDefault() on either + // keydown or keypress. + _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', /** * The keys to trigger on. - * @method _keys + * @property _keys */ - _keys: { - //arrows - '37': 'collapse', - '39': 'expand', - //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) - '32': 'toggle', - '13': 'enter' - }, + _keys: { + //arrows + '37': 'collapse', + '39': 'expand', + //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) + '32': 'toggle', + '13': 'enter' + }, /** * Handles key events @@ -1458,18 +1506,18 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {Object} args */ - _keyHandler: function (e, notifier, args) { - var actObj; - if (!args.actions) { - actObj = {collapse:true, expand:true, toggle:true, enter:true}; - } else { - actObj = args.actions; - } - if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { - e.action = this._keys[e.keyCode]; - notifier.fire(e); - } - }, + _keyHandler: function (e, notifier, args) { + var actObj; + if (!args.actions) { + actObj = {collapse: true, expand: true, toggle: true, enter: true}; + } else { + actObj = args.actions; + } + if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { + e.action = this._keys[e.keyCode]; + notifier.fire(e); + } + }, /** * Subscribes to events. @@ -1478,24 +1526,27 @@ Y.Event.define("dock:actionkey", { * @param {Subscription} sub The object tracking this subscription. * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - on: function (node, sub, notifier) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, {actions:false}); - } else { - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, sub.args[0]); - } - }, + on: function (node, sub, notifier) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false}); + } else { + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]); + } + }, /** * Detaches an event listener * @method detach + * @param {Node} node The node this subscription was applied to. + * @param {Subscription} sub The object tracking this subscription. + * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - detach: function (node, sub, notifier) { - //detach our _detacher handle of the subscription made in on() - sub._detacher.detach(); - }, + detach: function (node, sub) { + //detach our _detacher handle of the subscription made in on() + sub._detacher.detach(); + }, /** * Creates a delegated event listener. @@ -1505,15 +1556,15 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - delegate: function (node, sub, notifier, filter) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, {actions:false}); - } else { - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, sub.args[0]); - } - }, + delegate: function (node, sub, notifier, filter) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions:false}); + } else { + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]); + } + }, /** * Detaches a delegated event listener. @@ -1523,9 +1574,9 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - detachDelegate: function (node, sub, notifier, filter) { - sub._delegateDetacher.detach(); - } + detachDelegate: function (node, sub) { + sub._delegateDetacher.detach(); + } }); /** * Dock JS. @@ -1543,7 +1594,7 @@ Y.Event.define("dock:actionkey", { * @constructor * @extends Y.Base */ -var BLOCK = function() { +BLOCK = function() { BLOCK.superclass.constructor.apply(this, arguments); }; BLOCK.prototype = { @@ -1579,7 +1630,7 @@ BLOCK.prototype = { * The dock item associated with this block * @property dockitem * @protected - * @type DOCKITEM + * @type DOCKEDITEM */ dockitem : null, /** @@ -1587,7 +1638,8 @@ BLOCK.prototype = { * @method initializer */ initializer : function() { - var node = Y.one('#inst'+this.get('id')); + var node = Y.one('#inst'+this.get('id')), + commands; if (!node) { return false; } @@ -1598,7 +1650,7 @@ BLOCK.prototype = { // Move the block straight to the dock if required if (node.hasClass(CSS.dockonload)) { node.removeClass(CSS.dockonload); - var commands = node.one('.header .title .commands'); + commands = node.one('.header .title .commands'); if (!commands) { commands = Y.Node.create('
'); if (node.one('.header .title')) { @@ -1618,9 +1670,14 @@ BLOCK.prototype = { * @return String */ _getBlockClass : function(node) { - var classes = node.getAttribute('className').toString(), - regex = /(^|\s)(block_[a-zA-Z0-9_]+)(\s|$)/, - matches = regex.exec(classes); + 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]; } @@ -1628,7 +1685,7 @@ BLOCK.prototype = { }, /** - * This function is reponsible for moving a block from the page structure onto the dock. + * This function is responsible for moving a block from the page structure onto the dock. * @method moveToDock * @param {EventFacade} e */ @@ -1639,32 +1696,35 @@ BLOCK.prototype = { var dock = M.core.dock.get(), id = this.get('id'), - blockcontent = Y.one('#inst'+id).one('.content'); + blockcontent = Y.one('#inst'+id).one('.content'), + icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', + breakchar = (location.href.match(/\?/)) ? '&' : '?', + blocktitle, + blockcommands, + movetoimg, + moveto; if (!blockcontent) { return; } - var icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', - char = (location.href.match(/\?/)) ? '&' : '?', - blocktitle, - blockcommands, - movetoimg, - moveto; - this.recordBlockState(); blocktitle = this.cachedcontentnode.one('.title h2').cloneNode(true); blockcommands = this.cachedcontentnode.one('.title .commands').cloneNode(true); - // Must set the image src seperatly of we get an error with XML strict headers - movetoimg = Y.Node.create(''+Y.Escape.html(M.str.block.undockitem)+''); - movetoimg.setAttribute('src', M.util.image_url(icon, 'moodle')); - moveto = Y.Node.create('').append(movetoimg); - moveto.set('href', location.href + char + 'dock='+id); - blockcommands.append(moveto); + movetoimg = Y.Node.create('').setAttrs({ + alt : Y.Escape.html(M.str.block.undockitem), + title : Y.Escape.html(M.util.get_string('undockblock', 'block', blocktitle.innerHTML)), + src : M.util.image_url(icon, 'moodle') + }); + moveto = Y.Node.create('').setAttrs({ + className : 'moveto customcommand requiresjs', + href : Y.config.win.location.href + breakchar + 'dock='+id + }); + moveto.append(movetoimg); + blockcommands.append(moveto.append(movetoimg)); // Create a new dock item for the block this.dockitem = new DOCKEDITEM({ @@ -1684,7 +1744,7 @@ BLOCK.prototype = { M.util.set_user_preference('docked_block_instance_'+id, 1); } - this.set('idDocked', true); + this.set('isDocked', true); }, /** * Records the block state and adds it to the docks holding area. @@ -1712,11 +1772,12 @@ BLOCK.prototype = { /** * This function removes a block from the dock and puts it back into the page structure. - * @method returnToBlock + * @method returnToPage * @return {Boolean} */ - returnToBlock : function() { - var id = this.get('id'); + returnToPage : function() { + var id = this.get('id'), + commands; // Enable the skip anchor when going back to block mode @@ -1733,7 +1794,7 @@ BLOCK.prototype = { this.contentplaceholder.replace(this.cachedcontentnode); this.cachedcontentnode = Y.one('#'+this.cachedcontentnode.get('id')); - var commands = this.dockitem.get('commands'); + commands = this.dockitem.get('commands'); if (commands) { commands.all('.hidepanelicon').remove(); commands.all('.moveto').remove(); @@ -1742,7 +1803,7 @@ BLOCK.prototype = { this.cachedcontentnode.one('.title').append(commands); this.cachedcontentnode = null; M.util.set_user_preference('docked_block_instance_'+id, 0); - this.set('idDocked', false); + this.set('isDocked', false); return true; } }; @@ -1789,7 +1850,7 @@ Y.extend(BLOCK, Y.Base, BLOCK.prototype, { * @extends Y.Base * @uses Y.EventTarget */ -var DOCKEDITEM = function() { +DOCKEDITEM = function() { DOCKEDITEM.superclass.constructor.apply(this, arguments); }; DOCKEDITEM.prototype = { @@ -1806,7 +1867,8 @@ DOCKEDITEM.prototype = { */ initializer : function() { var title = this.get('title'), - titlestring; + titlestring, + type; /** * Fired before the docked item has been drawn. * @event dockeditem:drawstart @@ -1843,7 +1905,7 @@ DOCKEDITEM.prototype = { */ this.publish('dockeditem:itemremoved', {prefix:'dockeditem'}); if (title) { - var type = title.get('nodeName'); + type = title.get('nodeName'); titlestring = title.cloneNode(true); title = Y.Node.create('<'+type+'>'); title = M.core.dock.fixTitleOrientation(title, titlestring.get('text')); @@ -1903,7 +1965,7 @@ DOCKEDITEM.prototype = { dock.hideActive(); this.fire('dockeditem:showstart'); panel.setHeader(this.get('titlestring'), this.get('commands')); - panel.setBody(Y.Node.create('
').append(this.get('contents'))); + panel.setBody(Y.Node.create('
').append(this.get('contents'))); panel.show(); panel.correctWidth(); @@ -1954,7 +2016,7 @@ DOCKEDITEM.prototype = { remove : function () { this.hide(); // Return the block to its original position. - this.get('block').returnToBlock(); + this.get('block').returnToPage(); // Remove the dock item node. this.get('dockItemNode').remove(); this.fire('dockeditem:itemremoved'); diff --git a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-debug.js b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-debug.js index 959ee46e58c..5d90e18610a 100644 --- a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-debug.js +++ b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-debug.js @@ -91,7 +91,8 @@ M.core.dock.loader.delegationEvents = []; M.core.dock.loader.initLoader = function() { Y.log('Dock loader initialising', 'note', LOADERNAME); var dockedblocks = Y.all('.block[data-instanceid][data-dockable]'), - body = Y.one(document.body); + body = Y.one(document.body), + callback; dockedblocks.each(function() { var id = parseInt(this.getData('instanceid'), 10); Y.log('Dock loader watching block with instance id: '+id, 'note', LOADERNAME); @@ -103,13 +104,15 @@ M.core.dock.loader.initLoader = function() { M.core.dock.init(); }); } else { - var callback = function(e) { + callback = function(e) { var i, block = this.ancestor('.block[data-instanceid]'), instanceid = block.getData('instanceid'); e.halt(); for (i in M.core.dock.loader.delegationEvents) { - M.core.dock.loader.delegationEvents[i].detach(); + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + M.core.dock.loader.delegationEvents[i].detach(); + } } block.addClass('dock_on_load'); Y.log('Loading dock module', 'note', LOADERNAME); diff --git a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-min.js b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-min.js index b0dd7c4bc12..f5aff4f2869 100644 --- a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-min.js +++ b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader-min.js @@ -1 +1 @@ -YUI.add("moodle-core-dockloader",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 right_to_left()&&(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);t.each(function(){var e=parseInt(this.getData("instanceid"),10);M.core.dock.ensureMoveToIconExists(this)});if(t.some(function(e){return e.hasClass("dock_on_load")}))e.use("moodle-core-dock",function(){M.core.dock.init()});else{var 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)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-dockloader",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 right_to_left()&&(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"]}); diff --git a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader.js b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader.js index 184bcf4066e..0f838794bbd 100644 --- a/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader.js +++ b/lib/yui/build/moodle-core-dockloader/moodle-core-dockloader.js @@ -90,7 +90,8 @@ M.core.dock.loader.delegationEvents = []; */ M.core.dock.loader.initLoader = function() { var dockedblocks = Y.all('.block[data-instanceid][data-dockable]'), - body = Y.one(document.body); + body = Y.one(document.body), + callback; dockedblocks.each(function() { var id = parseInt(this.getData('instanceid'), 10); M.core.dock.ensureMoveToIconExists(this); @@ -100,13 +101,15 @@ M.core.dock.loader.initLoader = function() { M.core.dock.init(); }); } else { - var callback = function(e) { + callback = function(e) { var i, block = this.ancestor('.block[data-instanceid]'), instanceid = block.getData('instanceid'); e.halt(); for (i in M.core.dock.loader.delegationEvents) { - M.core.dock.loader.delegationEvents[i].detach(); + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + M.core.dock.loader.delegationEvents[i].detach(); + } } block.addClass('dock_on_load'); Y.use('moodle-core-dock', function(){ diff --git a/lib/yui/src/dock/js/actionkey.js b/lib/yui/src/dock/js/actionkey.js index 76dcd48654c..7feeaed6d0b 100644 --- a/lib/yui/src/dock/js/actionkey.js +++ b/lib/yui/src/dock/js/actionkey.js @@ -21,24 +21,24 @@ * @class ActionKey */ Y.Event.define("dock:actionkey", { - // Webkit and IE repeat keydown when you hold down arrow keys. - // Opera links keypress to page scroll; others keydown. - // Firefox prevents page scroll via preventDefault() on either - // keydown or keypress. - _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', + // Webkit and IE repeat keydown when you hold down arrow keys. + // Opera links keypress to page scroll; others keydown. + // Firefox prevents page scroll via preventDefault() on either + // keydown or keypress. + _event: (Y.UA.webkit || Y.UA.ie) ? 'keydown' : 'keypress', /** * The keys to trigger on. - * @method _keys + * @property _keys */ - _keys: { - //arrows - '37': 'collapse', - '39': 'expand', - //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) - '32': 'toggle', - '13': 'enter' - }, + _keys: { + //arrows + '37': 'collapse', + '39': 'expand', + //(@todo: lrt/rtl/M.core_dock.cfg.orientation decision to assign arrow to meanings) + '32': 'toggle', + '13': 'enter' + }, /** * Handles key events @@ -47,18 +47,18 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {Object} args */ - _keyHandler: function (e, notifier, args) { - var actObj; - if (!args.actions) { - actObj = {collapse:true, expand:true, toggle:true, enter:true}; - } else { - actObj = args.actions; - } - if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { - e.action = this._keys[e.keyCode]; - notifier.fire(e); - } - }, + _keyHandler: function (e, notifier, args) { + var actObj; + if (!args.actions) { + actObj = {collapse: true, expand: true, toggle: true, enter: true}; + } else { + actObj = args.actions; + } + if (this._keys[e.keyCode] && actObj[this._keys[e.keyCode]]) { + e.action = this._keys[e.keyCode]; + notifier.fire(e); + } + }, /** * Subscribes to events. @@ -67,24 +67,27 @@ Y.Event.define("dock:actionkey", { * @param {Subscription} sub The object tracking this subscription. * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - on: function (node, sub, notifier) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, {actions:false}); - } else { - sub._detacher = node.on(this._event, this._keyHandler,this, notifier, sub.args[0]); - } - }, + on: function (node, sub, notifier) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, {actions: false}); + } else { + sub._detacher = node.on(this._event, this._keyHandler, this, notifier, sub.args[0]); + } + }, /** * Detaches an event listener * @method detach + * @param {Node} node The node this subscription was applied to. + * @param {Subscription} sub The object tracking this subscription. + * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers */ - detach: function (node, sub, notifier) { - //detach our _detacher handle of the subscription made in on() - sub._detacher.detach(); - }, + detach: function (node, sub) { + //detach our _detacher handle of the subscription made in on() + sub._detacher.detach(); + }, /** * Creates a delegated event listener. @@ -94,15 +97,15 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - delegate: function (node, sub, notifier, filter) { - // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). - if (sub.args === null) { - //no actions given - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, {actions:false}); - } else { - sub._delegateDetacher = node.delegate(this._event, this._keyHandler,filter, this, notifier, sub.args[0]); - } - }, + delegate: function (node, sub, notifier, filter) { + // subscribe to _event and ask keyHandler to handle with given args[0] (the desired actions). + if (sub.args === null) { + //no actions given + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, {actions:false}); + } else { + sub._delegateDetacher = node.delegate(this._event, this._keyHandler, filter, this, notifier, sub.args[0]); + } + }, /** * Detaches a delegated event listener. @@ -112,7 +115,7 @@ Y.Event.define("dock:actionkey", { * @param {SyntheticEvent.Notifier} notifier The notifier used to trigger the execution of subscribers * @param {String|function} filter Selector string or function that accpets an event object and returns null. */ - detachDelegate: function (node, sub, notifier, filter) { - sub._delegateDetacher.detach(); - } + detachDelegate: function (node, sub) { + sub._delegateDetacher.detach(); + } }); diff --git a/lib/yui/src/dock/js/block.js b/lib/yui/src/dock/js/block.js index 42a51e9f03f..a8b0629663f 100644 --- a/lib/yui/src/dock/js/block.js +++ b/lib/yui/src/dock/js/block.js @@ -14,7 +14,7 @@ * @constructor * @extends Y.Base */ -var BLOCK = function() { +BLOCK = function() { BLOCK.superclass.constructor.apply(this, arguments); }; BLOCK.prototype = { @@ -50,7 +50,7 @@ BLOCK.prototype = { * The dock item associated with this block * @property dockitem * @protected - * @type DOCKITEM + * @type DOCKEDITEM */ dockitem : null, /** @@ -58,7 +58,8 @@ BLOCK.prototype = { * @method initializer */ initializer : function() { - var node = Y.one('#inst'+this.get('id')); + var node = Y.one('#inst'+this.get('id')), + commands; if (!node) { return false; } @@ -70,7 +71,7 @@ BLOCK.prototype = { // Move the block straight to the dock if required if (node.hasClass(CSS.dockonload)) { node.removeClass(CSS.dockonload); - var commands = node.one('.header .title .commands'); + commands = node.one('.header .title .commands'); if (!commands) { commands = Y.Node.create('
'); if (node.one('.header .title')) { @@ -90,9 +91,14 @@ BLOCK.prototype = { * @return String */ _getBlockClass : function(node) { - var classes = node.getAttribute('className').toString(), - regex = /(^|\s)(block_[a-zA-Z0-9_]+)(\s|$)/, - matches = regex.exec(classes); + 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]; } @@ -100,7 +106,7 @@ BLOCK.prototype = { }, /** - * This function is reponsible for moving a block from the page structure onto the dock. + * This function is responsible for moving a block from the page structure onto the dock. * @method moveToDock * @param {EventFacade} e */ @@ -111,7 +117,13 @@ BLOCK.prototype = { var dock = M.core.dock.get(), id = this.get('id'), - blockcontent = Y.one('#inst'+id).one('.content'); + blockcontent = Y.one('#inst'+id).one('.content'), + icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', + breakchar = (location.href.match(/\?/)) ? '&' : '?', + blocktitle, + blockcommands, + movetoimg, + moveto; if (!blockcontent) { return; @@ -119,25 +131,22 @@ BLOCK.prototype = { Y.log('Moving block to the dock:'+this.get('id'), 'note', LOGNS); - var icon = (right_to_left()) ? 't/dock_to_block_rtl' : 't/dock_to_block', - char = (location.href.match(/\?/)) ? '&' : '?', - blocktitle, - blockcommands, - movetoimg, - moveto; - this.recordBlockState(); blocktitle = this.cachedcontentnode.one('.title h2').cloneNode(true); blockcommands = this.cachedcontentnode.one('.title .commands').cloneNode(true); - // Must set the image src seperatly of we get an error with XML strict headers - movetoimg = Y.Node.create(''+Y.Escape.html(M.str.block.undockitem)+''); - movetoimg.setAttribute('src', M.util.image_url(icon, 'moodle')); - moveto = Y.Node.create('').append(movetoimg); - moveto.set('href', location.href + char + 'dock='+id); - blockcommands.append(moveto); + movetoimg = Y.Node.create('').setAttrs({ + alt : Y.Escape.html(M.str.block.undockitem), + title : Y.Escape.html(M.util.get_string('undockblock', 'block', blocktitle.innerHTML)), + src : M.util.image_url(icon, 'moodle') + }); + moveto = Y.Node.create('').setAttrs({ + className : 'moveto customcommand requiresjs', + href : Y.config.win.location.href + breakchar + 'dock='+id + }); + moveto.append(movetoimg); + blockcommands.append(moveto.append(movetoimg)); // Create a new dock item for the block this.dockitem = new DOCKEDITEM({ @@ -157,7 +166,7 @@ BLOCK.prototype = { M.util.set_user_preference('docked_block_instance_'+id, 1); } - this.set('idDocked', true); + this.set('isDocked', true); }, /** * Records the block state and adds it to the docks holding area. @@ -185,11 +194,12 @@ BLOCK.prototype = { /** * This function removes a block from the dock and puts it back into the page structure. - * @method returnToBlock + * @method returnToPage * @return {Boolean} */ - returnToBlock : function() { - var id = this.get('id'); + returnToPage : function() { + var id = this.get('id'), + commands; Y.log('Moving block out of the dock:'+this.get('id'), 'note', LOGNS); @@ -207,7 +217,7 @@ BLOCK.prototype = { this.contentplaceholder.replace(this.cachedcontentnode); this.cachedcontentnode = Y.one('#'+this.cachedcontentnode.get('id')); - var commands = this.dockitem.get('commands'); + commands = this.dockitem.get('commands'); if (commands) { commands.all('.hidepanelicon').remove(); commands.all('.moveto').remove(); @@ -216,7 +226,7 @@ BLOCK.prototype = { this.cachedcontentnode.one('.title').append(commands); this.cachedcontentnode = null; M.util.set_user_preference('docked_block_instance_'+id, 0); - this.set('idDocked', false); + this.set('isDocked', false); return true; } }; diff --git a/lib/yui/src/dock/js/dock.js b/lib/yui/src/dock/js/dock.js index 26419d4baf1..fa193a30870 100644 --- a/lib/yui/src/dock/js/dock.js +++ b/lib/yui/src/dock/js/dock.js @@ -7,28 +7,33 @@ */ -var LOGNS = 'moodle-core-dock'; -var BODY = Y.one(document.body); -var CSS = { - dock: 'dock', // CSS Class applied to the dock box - dockspacer: 'dockspacer', // CSS class applied to the dockspacer - controls: 'controls', // CSS class applied to the controls box - body: 'has_dock', // CSS class added to the body when there is a dock - buttonscontainer: 'buttons_container', - dockeditem: 'dockeditem', // CSS class added to each item in the dock - dockeditemcontainer: 'dockeditem_container', - dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock - activeitem: 'activeitem', // CSS class added to the active item - contentonly: 'content-only', - dockonload: 'dock_on_load' -}; -var SELECTOR = { - dockableblock: '.block[data-instanceid][data-dockable]', - blockmoveto: '.block[data-instanceid][data-dockable] .moveto', - panelmoveto: '#dockeditempanel .commands a.moveto', - dockonload: '.block.'+CSS.dockonload, - blockregion: '[data-blockregion]' -}; +var LOGNS = 'moodle-core-dock', + BODY = Y.one(Y.config.doc.body), + CSS = { + dock: 'dock', // CSS Class applied to the dock box + dockspacer: 'dockspacer', // CSS class applied to the dockspacer + controls: 'controls', // CSS class applied to the controls box + body: 'has_dock', // CSS class added to the body when there is a dock + buttonscontainer: 'buttons_container', + dockeditem: 'dockeditem', // CSS class added to each item in the dock + dockeditemcontainer: 'dockeditem_container', + dockedtitle: 'dockedtitle', // CSS class added to the item's title in each dock + activeitem: 'activeitem', // CSS class added to the active item + contentonly: 'content-only', + dockonload: 'dock_on_load' + }, + SELECTOR = { + dockableblock: '.block[data-instanceid][data-dockable]', + blockmoveto: '.block[data-instanceid][data-dockable] .moveto', + panelmoveto: '#dockeditempanel .commands a.moveto', + dockonload: '.block.'+CSS.dockonload, + blockregion: '[data-blockregion]' + }, + DOCK, + DOCKPANEL, + TABHEIGHTMANAGER, + BLOCK, + DOCKEDITEM; /** * Core namespace. @@ -145,12 +150,18 @@ M.core.dock.dockBlock = function(id) { * @return {Node} The title node to use. */ M.core.dock.fixTitleOrientation = function(title, text) { - var dock = M.core.dock.get(); + var dock = M.core.dock.get(), + fontsize = '11px', + transform = 'rotate(270deg)', + test, + width, + height, + container; title = Y.one(title); if (dock.get('orientation') !== 'vertical') { // If the dock isn't vertical don't adjust it! - title.setContent(text); + title.set('innerHTML', text); return title; } @@ -159,37 +170,34 @@ M.core.dock.fixTitleOrientation = function(title, text) { M.str.langconfig.thisdirectionvertical = 'ver'; } - var clockwise = false; switch (M.str.langconfig.thisdirectionvertical) { case 'ver': // Stacked is easy - return title.setContent(text.split('').join('
')); + return title.set('innerHTML', text.split('').join('
')); case 'ttb': - clockwise = true; + transform = 'rotate(90deg)'; break; case 'btt': - clockwise = false; + // Nothing to do here. transform default is good. break; } if (Y.UA.ie === 8) { // IE8 can flip the text via CSS but not handle transform. IE9+ can handle the CSS3 transform attribute. - title.setContent(text); + title.set('innerHTML', text); title.setAttribute('style', 'writing-mode: tb-rl; filter: flipV flipH;display:inline;'); title.addClass('filterrotate'); return title; } // We need to fix a font-size - sorry theme designers. - var fontsize = '11px'; - var transform = (clockwise) ? 'rotate(90deg)' : 'rotate(270deg)'; - var test = Y.Node.create('

'+text+'

'); + test = Y.Node.create('

'+text+'

'); BODY.insert(test, 0); - var width = test.one('span').get('offsetWidth') * 1.2; - var height = test.one('span').get('offsetHeight'); + width = test.one('span').get('offsetWidth') * 1.2; + height = test.one('span').get('offsetHeight'); test.remove(); - title.setContent(text); + title.set('innerHTML', text); title.addClass('css3transform'); // Move the title into position @@ -218,10 +226,12 @@ M.core.dock.fixTitleOrientation = function(title, text) { '-o-transform' : transform }); - var container = Y.Node.create('
'); + container = Y.Node.create('
'); container.append(title); - container.setStyle('height', width + (width / 4)); - container.setStyle('position', 'relative'); + container.setStyles({ + height : width + (width / 4), + position : 'relative' + }); return container; }; @@ -254,7 +264,7 @@ M.core.dock.notifyBlockChange = function(instanceid) { * @extends Y.Base * @uses Y.EventTarget */ -var DOCK = function() { +DOCK = function() { DOCK.superclass.constructor.apply(this, arguments); }; DOCK.prototype = { @@ -320,7 +330,7 @@ DOCK.prototype = { */ initializer : function() { Y.log('Dock initialising', 'note', LOGNS); - + // Publish the events the dock has /** * Fired when the dock first starts initialising. @@ -402,7 +412,18 @@ DOCK.prototype = { if (this.dockdrawn === true) { return true; } - var dock = this._initialiseDockNode(); + var dock = this._initialiseDockNode(), + clickargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0 + }, + mouseenterargs = { + cssselector:'.'+CSS.dockedtitle, + delay:0.5, + iscontained:true, + preventevent:'click', + preventdelay:3 + }; if (Y.UA.ie > 0 && Y.UA.ie < 7) { // Adjust for IE 6 (can't handle fixed pos) dock.setStyle('height', dock.get('winHeight')+'px'); @@ -414,9 +435,6 @@ DOCK.prototype = { this.tabheightmanager = new TABHEIGHTMANAGER({dock:this}); - var clickargs = {cssselector:'.'+CSS.dockedtitle, delay:0}; - var mouseenterargs = {cssselector:'.'+CSS.dockedtitle, delay:0.5, iscontained:true, preventevent:'click', preventdelay:3}; - // Attach the required event listeners // We use delegate here as that way a handful of events are created for the dock // and all items rather than the same number for the dock AND every item individually @@ -454,8 +472,7 @@ DOCK.prototype = { return false; } e.halt(); - var id = target.getAttribute('rel'); - this.dockeditems[id].toggle(e.action); + this.dockeditems[target.getAttribute('rel')].toggle(e.action); }, /** * Call the theme customisation method "customise_dock_for_theme" if it exists. @@ -504,31 +521,35 @@ DOCK.prototype = { }; // Check for and apply any legacy configuration. for (key in M.core_dock.cfg) { - value = M.core_dock.cfg[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key) && cfgmap[key]) { + value = M.core_dock.cfg[key]; + if (value === null) { + continue; + } + if (!warned) { + Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); + warned = true; + } + // Damn, the've set something. + Y.log('Note for customise_dock_for_theme code: M.core_dock.cfg.'+key+' is now dock.set(\''+key+'\', value)', 'info', LOGNS); + this.set(cfgmap[key], value); } - if (!warned) { - Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); - warned = true; - } - // Damn, the've set something. - Y.log('Note for customise_dock_for_theme code: M.core_dock.cfg.'+key+' is now dock.set(\''+key+'\', value)', 'info', LOGNS); - this.set(cfgmap[key], value); } // Check for and apply any legacy CSS changes.. for (key in M.core_dock.css) { - value = M.core_dock.css[key]; - if (value === null) { - continue; + if (Y.Lang.isString(key)) { + value = M.core_dock.css[key]; + if (value === null) { + continue; + } + if (!warned) { + Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); + warned = true; + } + // Damn, they've set something. + Y.log('Note for customise_dock_for_theme code: M.core_dock.css.'+key+' is now CSS.'+key+' = value', 'info', LOGNS); + CSS[key] = value; } - if (!warned) { - Y.log('Warning: customise_dock_for_theme has changed. Please update your code.', 'warn', LOGNS); - warned = true; - } - // Damn, they've set something. - Y.log('Note for customise_dock_for_theme code: M.core_dock.css.'+key+' is now CSS.'+key+' = value', 'info', LOGNS); - CSS[key] = value; } } }, @@ -545,7 +566,7 @@ DOCK.prototype = { holdingarea = Y.Node.create('
').setStyles({display:'none'}), buttons = this.get('buttonsNode'), container = this.get('itemContainerNode'); - + if (!dock) { dock = Y.one('#'+CSS.dock); } @@ -640,7 +661,11 @@ DOCK.prototype = { * @return {Boolean} */ handleEvent : function(e, options) { - var item = this.getActiveItem(); + var item = this.getActiveItem(), + target, + targetid, + regex = /^dock_item_(\d+)_title$/, + self = this; if (options.cssselector === 'body') { if (!this.get('dockNode').contains(e.target)) { if (item) { @@ -648,7 +673,6 @@ DOCK.prototype = { } } } else { - var target; if (e.target.test(options.cssselector)) { target = e.target; } else { @@ -663,7 +687,6 @@ DOCK.prototype = { if (options.preventevent) { this.preventevent = options.preventevent; if (options.preventdelay) { - var self = this; setTimeout(function(){ self.preventevent = null; }, options.preventdelay * 1000); @@ -677,8 +700,7 @@ DOCK.prototype = { if (options.delay > 0) { return this.delayEvent(e, options, target); } - var targetid = target.get('id'); - var regex = /^dock_item_(\d+)_title$/; + targetid = target.get('id'); if (targetid.match(regex)) { item = this.dockeditems[targetid.replace(regex, '$1')]; if (item.active) { @@ -733,7 +755,8 @@ DOCK.prototype = { var blockregions = [], populatedblockregions = 0, allnewregions = true, - showregions = false; + showregions = false, + i; // First look for understood regions. Y.all(SELECTOR.blockregion).each(function(){ var regionname = region.getData('blockregion'); @@ -773,22 +796,27 @@ DOCK.prototype = { } if (!allnewregions) { - var i = null; if (populatedblockregions === 0 && showregions === false) { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } else if (populatedblockregions === 1 && showregions === false) { for (i in blockregions) { - if (!blockregions[i].hasblocks) { - BODY.removeClass(blockregions[i].bodyclass); - } else { - BODY.addClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + if (!blockregions[i].hasblocks) { + BODY.removeClass(blockregions[i].bodyclass); + } else { + BODY.addClass(blockregions[i].bodyclass); + } } } } else { for (i in blockregions) { - BODY.removeClass(blockregions[i].bodyclass); + if (blockregions[i].bodyclass) { + BODY.removeClass(blockregions[i].bodyclass); + } } } } @@ -861,8 +889,11 @@ DOCK.prototype = { */ removeAll : function() { Y.log('Undocking all '+this.dockeditems.length+' blocks', 'note', LOGNS); - for (var i in this.dockeditems) { - this.remove(i); + var i; + for (i in this.dockeditems) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + this.remove(i); + } } return true; }, @@ -900,34 +931,43 @@ DOCK.prototype = { * @return {Boolean} */ resize : function() { - var panel = this.getPanel(); - var item = this.getActiveItem(); + var panel = this.getPanel(), + item = this.getActiveItem(), + buffer, + screenh, + docky, + titletop, + containery, + containerheight, + scrolltop, + panelheight, + dockx, + titleleft; if (!panel.get('visible') || !item) { return true; } this.fire('dock:panelresizestart'); if (this.get('orientation') === 'vertical') { - var buffer = this.get('bufferPanel'); - var screenheight = parseInt(BODY.get('winHeight'), 10)-(buffer*2); - var docky = this.get('dockNode').getY(); - var titletop = item.get('dockTitleNode').getY()-docky-buffer; - var containery = this.get('itemContainerNode').getY(); - var containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); - var scrolltop = panel.get('bodyNode').get('scrollTop'); + buffer = this.get('bufferPanel'); + screenh = parseInt(BODY.get('winHeight'), 10)-(buffer*2); + docky = this.get('dockNode').getY(); + titletop = item.get('dockTitleNode').getY()-docky-buffer; + containery = this.get('itemContainerNode').getY(); + containerheight = containery-docky+this.get('buttonsNode').get('offsetHeight'); + scrolltop = panel.get('bodyNode').get('scrollTop'); panel.get('bodyNode').setStyle('height', 'auto'); panel.get('node').removeClass('oversized_content'); - var panelheight = panel.get('node').get('offsetHeight'); + panelheight = panel.get('node').get('offsetHeight'); if (Y.UA.ie > 0 && Y.UA.ie < 7) { panel.setTop(item.get('dockTitleNode').getY()); - } else if (panelheight > screenheight) { + } else if (panelheight > screenh) { panel.setTop(buffer-containerheight); - panel.get('bodyNode').setStyle('height', (screenheight-panel.get('headerNode').get('offsetHeight'))+'px'); + panel.get('bodyNode').setStyle('height', (screenh-panel.get('headerNode').get('offsetHeight'))+'px'); panel.get('node').addClass('oversized_content'); - } else if (panelheight > (screenheight-(titletop-buffer))) { - var difference = panelheight - (screenheight-titletop); - panel.setTop(titletop-containerheight-difference+buffer); + } else if (panelheight > (screenh-(titletop-buffer))) { + panel.setTop(titletop-containerheight-(panelheight - (screenh-titletop))+buffer); } else { panel.setTop(titletop-containerheight+buffer); } @@ -941,8 +981,8 @@ DOCK.prototype = { panel.get('node').setStyle('left', -panel.get('offsetWidth')+'px'); } else if (this.get('position') === 'top') { - var dockx = this.get('dockNode').getX(); - var titleleft = item.get('dockTitleNode').getX()-dockx; + dockx = this.get('dockNode').getX(); + titleleft = item.get('dockTitleNode').getX()-dockx; panel.get('node').setStyle('left', titleleft+'px'); } @@ -955,7 +995,8 @@ DOCK.prototype = { * @return {DOCKEDITEM} */ getActiveItem : function() { - for (var i in this.dockeditems) { + var i; + for (i in this.dockeditems) { if (this.dockeditems[i].active) { return this.dockeditems[i]; } diff --git a/lib/yui/src/dock/js/dockeditem.js b/lib/yui/src/dock/js/dockeditem.js index ba929677464..62f49a40619 100644 --- a/lib/yui/src/dock/js/dockeditem.js +++ b/lib/yui/src/dock/js/dockeditem.js @@ -15,7 +15,7 @@ * @extends Y.Base * @uses Y.EventTarget */ -var DOCKEDITEM = function() { +DOCKEDITEM = function() { DOCKEDITEM.superclass.constructor.apply(this, arguments); }; DOCKEDITEM.prototype = { @@ -32,7 +32,8 @@ DOCKEDITEM.prototype = { */ initializer : function() { var title = this.get('title'), - titlestring; + titlestring, + type; /** * Fired before the docked item has been drawn. * @event dockeditem:drawstart @@ -69,7 +70,7 @@ DOCKEDITEM.prototype = { */ this.publish('dockeditem:itemremoved', {prefix:'dockeditem'}); if (title) { - var type = title.get('nodeName'); + type = title.get('nodeName'); titlestring = title.cloneNode(true); title = Y.Node.create('<'+type+'>'); title = M.core.dock.fixTitleOrientation(title, titlestring.get('text')); @@ -131,7 +132,7 @@ DOCKEDITEM.prototype = { this.fire('dockeditem:showstart'); Y.log('Showing '+this._getLogDescription(), 'info', LOGNS); panel.setHeader(this.get('titlestring'), this.get('commands')); - panel.setBody(Y.Node.create('
').append(this.get('contents'))); + panel.setBody(Y.Node.create('
').append(this.get('contents'))); panel.show(); panel.correctWidth(); @@ -183,7 +184,7 @@ DOCKEDITEM.prototype = { remove : function () { this.hide(); // Return the block to its original position. - this.get('block').returnToBlock(); + this.get('block').returnToPage(); // Remove the dock item node. this.get('dockItemNode').remove(); this.fire('dockeditem:itemremoved'); diff --git a/lib/yui/src/dock/js/dockloader.js b/lib/yui/src/dock/js/dockloader.js index 1983108d8ad..308b857f417 100644 --- a/lib/yui/src/dock/js/dockloader.js +++ b/lib/yui/src/dock/js/dockloader.js @@ -89,7 +89,8 @@ M.core.dock.loader.delegationEvents = []; M.core.dock.loader.initLoader = function() { Y.log('Dock loader initialising', 'note', LOADERNAME); var dockedblocks = Y.all('.block[data-instanceid][data-dockable]'), - body = Y.one(document.body); + body = Y.one(document.body), + callback; dockedblocks.each(function() { var id = parseInt(this.getData('instanceid'), 10); Y.log('Dock loader watching block with instance id: '+id, 'note', LOADERNAME); @@ -101,13 +102,15 @@ M.core.dock.loader.initLoader = function() { M.core.dock.init(); }); } else { - var callback = function(e) { + callback = function(e) { var i, block = this.ancestor('.block[data-instanceid]'), instanceid = block.getData('instanceid'); e.halt(); for (i in M.core.dock.loader.delegationEvents) { - M.core.dock.loader.delegationEvents[i].detach(); + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + M.core.dock.loader.delegationEvents[i].detach(); + } } block.addClass('dock_on_load'); Y.log('Loading dock module', 'note', LOADERNAME); diff --git a/lib/yui/src/dock/js/panel.js b/lib/yui/src/dock/js/panel.js index d7edf45715d..6d874275795 100644 --- a/lib/yui/src/dock/js/panel.js +++ b/lib/yui/src/dock/js/panel.js @@ -15,7 +15,7 @@ * @extends Y.Base * @uses Y.EventTarget */ -var DOCKPANEL = function() { +DOCKPANEL = function() { DOCKPANEL.superclass.constructor.apply(this, arguments); }; DOCKPANEL.prototype = { @@ -109,11 +109,14 @@ DOCKPANEL.prototype = { */ setHeader : function(content) { this.create(); - var header = this.get('headerNode'); + var header = this.get('headerNode'), + i; header.setContent(content); if (arguments.length > 1) { - for (var i=1;i < arguments.length;i++) { - header.append(arguments[i]); + for (i = 1; i < arguments.length; i++) { + if (Y.Lang.isNumber(i) || Y.Lang.isString(i)) { + header.append(arguments[i]); + } } } }, diff --git a/lib/yui/src/dock/js/tabheightmanager.js b/lib/yui/src/dock/js/tabheightmanager.js index 3f07c0743fc..3e18b317831 100644 --- a/lib/yui/src/dock/js/tabheightmanager.js +++ b/lib/yui/src/dock/js/tabheightmanager.js @@ -15,7 +15,7 @@ * @constructor * @extends Y.Base */ -var TABHEIGHTMANAGER = function() { +TABHEIGHTMANAGER = function() { TABHEIGHTMANAGER.superclass.constructor.apply(this, arguments); }; TABHEIGHTMANAGER.prototype = { @@ -42,12 +42,14 @@ TABHEIGHTMANAGER.prototype = { id, dockedtitle; if (items.length > 0) { for (id in items) { - dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (dockedtitle) { - if (this.get('enabled')) { - dockedtitle.setStyle('height', 'auto'); + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + dockedtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (dockedtitle) { + if (this.get('enabled')) { + dockedtitle.setStyle('height', 'auto'); + } + totalheight += dockedtitle.get('offsetHeight') || 0; } - totalheight += dockedtitle.get('offsetHeight') || 0; } } if (totalheight > possibleheight) { @@ -70,20 +72,22 @@ TABHEIGHTMANAGER.prototype = { Y.log('Enabling the dock tab sizer.', 'note', LOGNS); this.set('enabled', true); for (id in items) { - itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); - if (!itemtitle) { - continue; + if (Y.Lang.isNumber(id) || Y.Lang.isString(id)) { + itemtitle = Y.one(items[id].get('title')).ancestor('.'+CSS.dockedtitle); + if (!itemtitle) { + continue; + } + itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); + offsetheight = itemtitle.get('offsetHeight'); + itemtitle.setStyle('overflow', 'hidden'); + if (offsetheight > itemheight) { + itemtitle.setStyle('height', itemheight+'px'); + usedheight += itemheight; + } else { + usedheight += offsetheight; + } + runningcount++; } - itemheight = Math.floor((possibleheight-usedheight) / (count - runningcount)); - offsetheight = itemtitle.get('offsetHeight'); - itemtitle.setStyle('overflow', 'hidden'); - if (offsetheight > itemheight) { - itemtitle.setStyle('height', itemheight+'px'); - usedheight += itemheight; - } else { - usedheight += offsetheight; - } - runningcount++; } } };