diff --git a/CHANGELOG.md b/CHANGELOG.md index 38c9aba..099ee1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ 0.7.1 - dev - [ ] add cache system - [ ] add option for gravatar built in unknow avatar @see https://fr.gravatar.com/site/implement/images/ +- use url handler for dynamic js and css 0.7 - 2021.09.09 - fix image directories diff --git a/_prepend.php b/_prepend.php index 537bd36..4560ec0 100644 --- a/_prepend.php +++ b/_prepend.php @@ -31,4 +31,16 @@ $core->url->register( 'noodle', '^noodle/$', ['urlNoodles', 'service'] +); +$core->url->register( + 'noodlescss', + 'noodls.css', + '^noodls.css', + ['urlNoodles', 'css'] +); +$core->url->register( + 'noodlesjs', + 'noodls.js', + '^noodls.js', + ['urlNoodles', 'js'] ); \ No newline at end of file diff --git a/_public.php b/_public.php index af4e3d0..4a21065 100644 --- a/_public.php +++ b/_public.php @@ -45,39 +45,10 @@ class publicNoodles { public static function publicHeadContent($core) { - $__noodles =& $GLOBALS['__noodles']; - - $css = "\n"; - $targets = array(); - foreach($__noodles->noodles() AS $noodle) { - if (!$noodle->active || !$noodle->hasJsCallback()) { - continue; - } - $css .= '.noodles-' . $noodle->id() . '{' . $noodle->css . '}' . "\n"; - $targets[] = - ' $(\'' . html::escapeJS($noodle->target) . '\').noodles({' . - 'imgId:\'' . html::escapeJS($noodle->id()) . '\',' . - 'imgPlace:\'' . html::escapeJS($noodle->place) . '\'' . - '});'; - } - if (empty($targets)) { - return null; - } - - echo - "\n \n" . - '' . - "\n \n" . - dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") . - "\n"; + echo + dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) . + dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") . + dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs')); } } @@ -85,6 +56,53 @@ class urlNoodles extends dcUrlHandlers { public static $api_url = 'http://www.gravatar.com/avatar/%s?s=%s&r=%s&d=%s'; + public static function css($args) + { + global $core, $__noodles; + + $css = ''; + foreach($__noodles->noodles() AS $noodle) { + if (!$noodle->active || !$noodle->hasJsCallback()) { + continue; + } + $css .= '.noodles-' . $noodle->id() . '{' . $noodle->css . '}' . "\n"; + } + + header('Content-Type: text/css; charset=UTF-8'); + + echo $css; + + exit; + } + + public static function js($args) + { + global $core, $__noodles; + + $targets = []; + foreach($__noodles->noodles() AS $noodle) { + if (!$noodle->active || !$noodle->hasJsCallback()) { + continue; + } + $targets[] = + '$(\'' . html::escapeJS($noodle->target) . '\').noodles({' . + ' imgId:\'' . html::escapeJS($noodle->id()) . '\',' . + ' imgPlace:\'' . html::escapeJS($noodle->place) . '\'' . + '});'; + } + + header('Content-Type: text/javascript; charset=UTF-8'); + + echo + "\$(function(){if(!document.getElementById){return;} \n" . + "\$.fn.noodles.defaults.service_url = '" . html::escapeJS($core->blog->url . $core->url->getBase('noodlesservice') . '/') . "'; \n" . + "\$.fn.noodles.defaults.service_func = '" . html::escapeJS('getNoodle') . "'; \n" . + implode("\n", $targets) . + "})\n"; + + exit; + } + public static function service($args) { global $core;