Skip to content

Commit

Permalink
Fix issue can not load tinymce when minify JS #797
Browse files Browse the repository at this point in the history
  • Loading branch information
sonvnn committed Sep 20, 2024
1 parent 64fbd67 commit 6b81bb7
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
30 changes: 28 additions & 2 deletions framework/library/astroid/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ class Document
protected static $_fontawesome = false;
protected static $_fancybox = false;
protected static $_masonry = false;
protected static $_imagesloaded = false;
protected static $_gsap = false;
protected static $_slick = false;
protected static $_videojs = false;
protected static $_layout_paths = [];
Expand Down Expand Up @@ -291,7 +293,11 @@ public function minifyJS($html)
$base_path = str_replace($juri->getScheme() . '://' . $juri->getHost() . '/', '', $juri->root());

Framework::getDebugger()->log('Minifying JS');
$excludeScripts = ['*validate.js*', '*tinymce.min.js*', '*tiny_mce.js*', '*tinymce.js*', '*editor.min.js*'];
$excludes = Framework::getTemplate()->getParams()->get('minify_js_excludes', '');
$excludes = \explode(',', $excludes);
$excludes = array_merge($excludeScripts, $excludes);

$javascripts = [];
$javascriptFiles = [];
$html = preg_replace_callback('/(<script\s[^>]*src=")([^"]*)("[^>]*>)(.*)(<\/script>)|(<script>)(.*)(<\/script>)|(<script\s[^>]*type=")([^"]*)("[^>]*>)(.*)(<\/script>)/siU', function ($matches) use (&$javascripts, &$javascriptFiles, $base_path, $excludes) {
Expand All @@ -310,7 +316,7 @@ public function minifyJS($html)
}

$file = basename($file_path);
if (Helper::matchFilename($file, \explode(',', $excludes))) {
if (Helper::matchFilename($file, $excludes)) {
return $matches[0];
}
$script = ['content' => $scriptName, 'type' => 'url'];
Expand Down Expand Up @@ -347,7 +353,7 @@ public function minifyJS($html)

$file = basename($file_path);

if (!Helper::matchFilename($file, \explode(',', $excludes))) {
if (!Helper::matchFilename($file, $excludes)) {
$content = "/* `{$file_path}` minified by Astroid */";
if (file_exists(JPATH_SITE . '/' . $file_path)) {
$minifier->add(JPATH_SITE . '/' . $file_path);
Expand Down Expand Up @@ -482,6 +488,8 @@ public function minifyHTML($html): array|string|null
public function _replace($rx, $replacement, $code, $callback = null): array|string|null
{
if ($callback === null) {
if ($rx === null) return $code;
if ($code === null) return '';
return preg_replace($rx, $replacement, $code);
} else {
return preg_replace_callback($rx, $callback, $code);
Expand Down Expand Up @@ -939,6 +947,24 @@ public function loadSlick($obj = '', $config = ''): void
}
}

public function loadImagesLoaded(): void
{
if (!self::$_imagesloaded) {
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('astroid.imagesloaded', 'astroid/imagesloaded.pkgd.min.js', ['relative' => true, 'version' => 'auto']);
self::$_imagesloaded = true;
}
}

public function loadGSAP(): void
{
if (!self::$_gsap) {
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
$wa->registerAndUseScript('astroid.gsap', 'astroid/gsap.min.js', ['relative' => true, 'version' => 'auto']);
self::$_gsap = true;
}
}

public function loadVideoBG(): void
{
if (!self::$_videojs) {
Expand Down
11 changes: 11 additions & 0 deletions js/gsap.min.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions js/imagesloaded.pkgd.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6b81bb7

Please sign in to comment.