From 2a97b876cae3310fb74df2891b2a108984dacc6c Mon Sep 17 00:00:00 2001 From: Paul Massendari Date: Thu, 12 Oct 2017 11:31:05 +0200 Subject: [PATCH 1/3] Update Assets.php This is a small addition to the previous change. This allows to have multiple type on inlined js. Without this change, if you have something like ``` {% do assets.addInlineJs('Hello', 100,'', "somespecialtype") %} {% do assets.addInlineJs('Good Morning', 100,'', "anothertype") %} {% do assets.addInlineJs('Goodbye', 100,'') %} // regular inlined js {% do assets.addInlineJs('Bonjour', 100,'') %} // regular inlined js ``` It will be rendered like this: ``` ``` With this fix, it should display ``` // These two inlined js has no type specified, so we can group them on the same tag ``` --- system/src/Grav/Common/Assets.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 47c76849c..f51d5b4a2 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -663,14 +663,18 @@ public function js($group = 'head', $attributes = []) // Render Inline JS foreach ($this->inline_js as $inline) { - if ($group && $inline['group'] == $group) { + if (($group && $inline['group'] == $group) && ($inline['type'] == '')) { + // concatenate inlined js if type is empty $inline_js .= $inline['asset'] . "\n"; + } else { + // build a script tag if inline type is set + $attributeString = " type=\"" . $inline['type'] . "\""; + $output .= "\n\n" . $inline['asset'] . "\n\n"; } } if ($inline_js) { - $attribute_string = isset($inline) && $inline['type'] ? " type=\"" . $inline['type'] . "\"" : ''; - $output .= "\n\n" . $inline_js . "\n\n"; + $output .= "\n\n"; } return $output; From e5e858d78946d35f8fc2752cfdcae14078cd5d62 Mon Sep 17 00:00:00 2001 From: Paul Massendari Date: Mon, 16 Oct 2017 11:02:57 +0200 Subject: [PATCH 2/3] Update assets.php as per recommendation --- system/src/Grav/Common/Assets.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index f51d5b4a2..474547287 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -663,7 +663,7 @@ public function js($group = 'head', $attributes = []) // Render Inline JS foreach ($this->inline_js as $inline) { - if (($group && $inline['group'] == $group) && ($inline['type'] == '')) { + if ($group && $inline['group'] === $group && $inline['type'] === '') { // concatenate inlined js if type is empty $inline_js .= $inline['asset'] . "\n"; } else { From 5cd745f74f9b03b640e15a28a0147e39b029601b Mon Sep 17 00:00:00 2001 From: Paul Massendari Date: Mon, 16 Oct 2017 12:04:02 +0200 Subject: [PATCH 3/3] Update Assets.php --- system/src/Grav/Common/Assets.php | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/system/src/Grav/Common/Assets.php b/system/src/Grav/Common/Assets.php index 474547287..c5bcbf0f8 100644 --- a/system/src/Grav/Common/Assets.php +++ b/system/src/Grav/Common/Assets.php @@ -487,7 +487,7 @@ public function addInlineJs($asset, $priority = null, $group = null, $attributes 'priority' => intval($priority ?: 10), 'order' => count($this->js), 'group' => $group ?: 'head', - 'type' => $attributes ?: '', + 'type' => $attributes ?: 'text/javascript', ]; // check for dynamic array and merge with defaults @@ -663,20 +663,11 @@ public function js($group = 'head', $attributes = []) // Render Inline JS foreach ($this->inline_js as $inline) { - if ($group && $inline['group'] === $group && $inline['type'] === '') { - // concatenate inlined js if type is empty - $inline_js .= $inline['asset'] . "\n"; - } else { - // build a script tag if inline type is set + if ($group && $inline['group'] === $group) { $attributeString = " type=\"" . $inline['type'] . "\""; $output .= "\n\n" . $inline['asset'] . "\n\n"; - } + } } - - if ($inline_js) { - $output .= "\n\n"; - } - return $output; }