From bca0975478ef8372afabfd3c863544524bd0c1b5 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Fri, 22 Jan 2010 10:34:09 +0000 Subject: [PATCH] MDL-21170 migrated code to new M.util.image_url() function that returns correct theme images --- blocks/dock.js | 8 ++++---- comment/comment.js | 8 ++++---- lib/ajax/ajaxlib.php | 2 -- lib/javascript-static.js | 38 +++++++++++++++++++++++--------------- 4 files changed, 31 insertions(+), 25 deletions(-) diff --git a/blocks/dock.js b/blocks/dock.js index 25e1243dd06..f742b31376a 100644 --- a/blocks/dock.js +++ b/blocks/dock.js @@ -131,7 +131,7 @@ M.blocks.dock = { } var dockcontrol = Y.Node.create('
'); - var removeall = Y.Node.create(''+mstr.block.undockall+''); + var removeall = Y.Node.create(''+mstr.block.undockall+''); removeall.on('removeall|click', this.remove_all, this); dockcontrol.appendChild(removeall); this.node.appendChild(dockcontrol); @@ -309,7 +309,7 @@ M.blocks.dock = { } var moveto = Y.Node.create(''); - moveto.append(Y.Node.create(''+mstr.block.undockitem+'')); + moveto.append(Y.Node.create(''+mstr.block.undockitem+'')); if (location.href.match(/\?/)) { moveto.set('href', location.href+'&dock='+this.id); } else { @@ -353,7 +353,7 @@ M.blocks.dock = { Y.Event.purgeElement(Y.Node.getDOMNode(moveto), false, 'click'); if (moveto.hasClass('customcommand')) { moveto.all('img').each(function(movetoimg){ - movetoimg.setAttribute('src', get_image_url('t/dock_to_block', 'moodle')); + movetoimg.setAttribute('src', M.util.image_url('t/dock_to_block', 'moodle')); movetoimg.setAttribute('alt', mstr.block.undockitem); movetoimg.setAttribute('title', mstr.block.undockitem); }, this); @@ -448,7 +448,7 @@ M.blocks.dock = { moveto.on('movetodock|click', this.move_to_dock, this); if (moveto.hasClass('customcommand')) { moveto.all('img').each(function(movetoimg){ - movetoimg.setAttribute('src', get_image_url('t/block_to_dock', 'moodle')); + movetoimg.setAttribute('src', M.util.image_url('t/block_to_dock', 'moodle')); movetoimg.setAttribute('alt', mstr.block.addtodock); movetoimg.setAttribute('title', mstr.block.addtodock); }, this); diff --git a/comment/comment.js b/comment/comment.js index 30f93ade908..ed018f26ce3 100644 --- a/comment/comment.js +++ b/comment/comment.js @@ -158,7 +158,7 @@ M.core_comment = { var val = template.get('innerHTML'); val = val.replace('___name___', list[i].username); if (list[i]['delete']||newcmt) { - list[i].content = '
' + list[i].content; + list[i].content = '
' + list[i].content; } val = val.replace('___time___', list[i].time); val = val.replace('___picture___', list[i].avatar); @@ -279,11 +279,11 @@ M.core_comment = { // show this.load(page); container.setStyle('display', 'block'); - img.src=M.cfg.wwwroot+'/pix/t/expanded.png'; + img.src=M.util.image_url('t/expanded', 'core'); } else { // hide container.setStyle('display', 'none'); - img.src=M.cfg.wwwroot+'/pix/t/collapsed.png'; + img.src=M.util.image_url('t/collapsed', 'core'); ta.set('value',''); } //toggle_textarea.apply(ta, [false]); @@ -318,7 +318,7 @@ M.core_comment = { }, wait: function() { var container = Y.one('#comment-list-'+this.client_id); - container.set('innerHTML', '
'); + container.set('innerHTML', '
'); } }); diff --git a/lib/ajax/ajaxlib.php b/lib/ajax/ajaxlib.php index 21f9311b300..9b5f04f38d8 100644 --- a/lib/ajax/ajaxlib.php +++ b/lib/ajax/ajaxlib.php @@ -215,8 +215,6 @@ class page_requirements_manager { // Otherwise, in some situations, users will get warnings about insecure content // on sercure pages from their web browser. - //TODO: problem here is we may need this in some included JS - move this somehow to the very beginning - // right after the YUI loading $this->M_cfg = array( 'wwwroot' => $CFG->httpswwwroot, // Yes, really. See above. 'sesskey' => sesskey(), diff --git a/lib/javascript-static.js b/lib/javascript-static.js index 0019d880c81..523a79b2bea 100644 --- a/lib/javascript-static.js +++ b/lib/javascript-static.js @@ -14,6 +14,29 @@ M.yui.add_module = function(modules) { } }; +/** + * Various utility functions + */ +M.util = { + /** + * Returns url for images. + */ + image_url: function(imagename, component) { + var url = M.cfg.wwwroot + '/theme/image.php?theme=' + M.cfg.theme + '&image=' + imagename; + + if (M.cfg.themerev > 0) { + url = url + '&rev=' + M.cfg.themerev; + } + + if (component != '' && component != 'moodle' && component != 'core') { + url = url + '&component=' + component; + } + + return url; + } +} + + function launch_filemanager(options) { Y.use('core_filemanager', function() { var client_id = options.client_id; @@ -1398,21 +1421,6 @@ function frame_breakout(e, properties) { this.setAttribute('target', properties.framename); } -function get_image_url(imagename, component) { - var url = M.cfg.wwwroot + '/theme/image.php?theme=' + M.cfg.theme + '&image=' + imagename; - - if (M.cfg.themerev > 0) { - url = url + '&rev=' + M.cfg.themerev; - } - - if (component != '' && component != 'moodle' && component != 'core') { - url = url + '&component=' + component; - } - - return url; -} - - // ===== Deprecated core Javascript functions for Moodle ==== // DO NOT USE!!!!!!!