use url handler for dynamic js and css

master
Jean-Christian Paul Denis 2021-10-30 21:53:30 +02:00
parent 72a1c41fed
commit ecc6982547
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 64 additions and 33 deletions

View File

@ -1,6 +1,7 @@
0.7.1 - dev 0.7.1 - dev
- [ ] add cache system - [ ] add cache system
- [ ] add option for gravatar built in unknow avatar @see https://fr.gravatar.com/site/implement/images/ - [ ] 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 0.7 - 2021.09.09
- fix image directories - fix image directories

View File

@ -32,3 +32,15 @@ $core->url->register(
'^noodle/$', '^noodle/$',
['urlNoodles', 'service'] ['urlNoodles', 'service']
); );
$core->url->register(
'noodlescss',
'noodls.css',
'^noodls.css',
['urlNoodles', 'css']
);
$core->url->register(
'noodlesjs',
'noodls.js',
'^noodls.js',
['urlNoodles', 'js']
);

View File

@ -45,39 +45,10 @@ class publicNoodles
{ {
public static function publicHeadContent($core) 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 echo
"\n<!-- CSS for noodles --> \n" . dcUtils::cssLoad($core->blog->url . $core->url->getURLFor('noodlescss')) .
'<style type="text/css">' . html::escapeHTML($css) . '</style>' .
"\n<!-- JS for noodles --> \n" .
dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") . dcUtils::jsLoad($core->blog->url . $core->url->getBase('noodlesmodule') . "/js/jquery.noodles.js") .
"<script type=\"text/javascript\"> \n" . dcUtils::jsLoad($core->blog->url . $core->url->getURLFor('noodlesjs'));
"//<![CDATA[\n" .
" \$(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" .
"})\n" .
"\n//]]>\n" .
"</script>\n";
} }
} }
@ -85,6 +56,53 @@ class urlNoodles extends dcUrlHandlers
{ {
public static $api_url = 'http://www.gravatar.com/avatar/%s?s=%s&amp;r=%s&amp;d=%s'; public static $api_url = 'http://www.gravatar.com/avatar/%s?s=%s&amp;r=%s&amp;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) public static function service($args)
{ {
global $core; global $core;