From a5012e5cdc22dc91770616e68f1b089157579b41 Mon Sep 17 00:00:00 2001 From: Lisa Seeto Date: Mon, 9 Dec 2019 11:28:09 +1300 Subject: [PATCH] Bug 1855023: Warning produced when adding/ editing an image gallery block - changed for loop in get_get_javascript_javascript func to continue when encountering empty filename vars. behatnotneeded Change-Id: I5b65c4beee4465d80911aa3fe08590a358570141 Signed-off-by: Lisa Seeto --- htdocs/blocktype/lib.php | 35 ++++++++++++++++++++--------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/htdocs/blocktype/lib.php b/htdocs/blocktype/lib.php index d6de7a71cb..be4cac4a53 100644 --- a/htdocs/blocktype/lib.php +++ b/htdocs/blocktype/lib.php @@ -2085,9 +2085,9 @@ class BlockInstance { * Returns javascript to grab & eval javascript from files on the web * * @param array $jsfiles Each element of $jsfiles is either a url, a local filename, - * or an array of the form + * or an array in the form of * array( - * 'file' => string // url or local js filename + * 'file' => string // url or local js filename (or empty if initjs only is required) * 'initjs' => string // js to be executed once the file's * // contents have been loaded * ) @@ -2097,23 +2097,28 @@ class BlockInstance { public function get_get_javascript_javascript($jsfiles) { $js = ''; foreach ($jsfiles as $jsfile) { + if (is_array($jsfile) && empty($jsfile['file']) && !empty($jsfile['initjs'])) { + // Just dealing with initjs option only so do this on page load + $js .= "jQuery(function() {\n" . $jsfile['initjs'] . "\n})"; + } + else { + $file = (is_array($jsfile) && !empty($jsfile['file'])) ? $jsfile['file'] : $jsfile; - $file = (is_array($jsfile) && !empty($jsfile['file'])) ? $jsfile['file'] : $jsfile; - - if (stripos($file, 'http://') === false && stripos($file, 'https://') === false) { - $file = 'blocktype/' . $this->blocktype . '/' . $file; - if ($this->artefactplugin) { - $file = 'artefact/' . $this->artefactplugin . '/' . $file; + if (stripos($file, 'http://') === false && stripos($file, 'https://') === false) { + $file = 'blocktype/' . $this->blocktype . '/' . $file; + if ($this->artefactplugin) { + $file = 'artefact/' . $this->artefactplugin . '/' . $file; + } + $file = get_config('wwwroot') . $file; } - $file = get_config('wwwroot') . $file; - } - $js .= "jQuery.ajax({url: '{$file}', dataType: 'script', cache:true"; - if (is_array($jsfile) && !empty($jsfile['initjs'])) { - // Pass success callback to getScript - $js .= ", success: function(data){\n" . $jsfile['initjs'] . "\n}"; + $js .= "jQuery.ajax({url: '{$file}', dataType: 'script', cache:true"; + if (is_array($jsfile) && !empty($jsfile['initjs'])) { + // Pass success callback to getScript + $js .= ", success: function(data){\n" . $jsfile['initjs'] . "\n}"; + } + $js .= "});\n"; } - $js .= "});\n"; } return $js; } -- GitLab