Revision 1105
Added by Matthias over 15 years ago
frontend.functions.php | ||
---|---|---|
325 | 325 |
} |
326 | 326 |
} |
327 | 327 |
|
328 |
// Function to add optional module Javascript into the <body> section of the frontend |
|
329 |
if(!function_exists('register_frontend_modfiles_body')) { |
|
330 |
function register_frontend_modfiles_body($file_id="js") { |
|
331 |
// sanity check of parameter passed to the function |
|
332 |
$file_id = strtolower($file_id); |
|
333 |
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { |
|
334 |
return; |
|
335 |
} |
|
336 |
|
|
337 |
global $wb, $database; |
|
338 |
// define default baselink and filename for optional module javascript files |
|
339 |
$body_links = ""; |
|
340 |
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend_body.js" type="text/javascript"></script>'; |
|
341 |
$base_file = "frontend_body.js"; |
|
342 |
|
|
343 |
// gather information for all models embedded on actual page |
|
344 |
$page_id = $wb->page_id; |
|
345 |
$query_modules = $database->query("SELECT module FROM " .TABLE_PREFIX ."sections |
|
346 |
WHERE page_id=$page_id AND module<>'wysiwyg'"); |
|
347 |
|
|
348 |
while($row = $query_modules->fetchRow()) { |
|
349 |
// check if page module directory contains a frontend_body.js file |
|
350 |
if(file_exists(WB_PATH ."/modules/" .$row['module'] ."/$base_file")) { |
|
351 |
// create link with frontend_body.js source for the current module |
|
352 |
$tmp_link = str_replace("{MODULE_DIRECTORY}", $row['module'], $base_link); |
|
353 |
|
|
354 |
// define constant indicating that the register_frontent_files was invoked |
|
355 |
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) define('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED', true); |
|
356 |
|
|
357 |
// ensure that frontend_body.js is only added once per module type |
|
358 |
if(strpos($body_links, $tmp_link) === false) { |
|
359 |
$body_links .= $tmp_link ."\n"; |
|
360 |
} |
|
361 |
}; |
|
362 |
} |
|
363 |
|
|
364 |
/* include the Javascript email protection function |
|
365 |
if( $file_id != 'css' && file_exists(WB_PATH .'/modules/droplets/js/mdcr.js')) { |
|
366 |
$body_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/droplets/js/mdcr.js"></script>'."\n"; |
|
367 |
} elseif( $file_id != 'css' && file_exists(WB_PATH .'/modules/output_filter/js/mdcr.js')) { |
|
368 |
$body_links .= '<script type="text/javascript" src="'.WB_URL.'/modules/output_filter/js/mdcr.js"></script>'."\n"; |
|
369 |
} */ |
|
370 |
echo $body_links; |
|
371 |
} |
|
372 |
} |
|
373 |
|
|
328 | 374 |
// Function to add optional module Javascript or CSS stylesheets into the <head> section of the frontend |
329 | 375 |
if(!function_exists('register_frontend_modfiles')) { |
330 | 376 |
function register_frontend_modfiles($file_id="css") { |
331 | 377 |
// sanity check of parameter passed to the function |
332 | 378 |
$file_id = strtolower($file_id); |
333 |
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") {
|
|
379 |
if($file_id !== "css" && $file_id !== "javascript" && $file_id !== "js") { |
|
334 | 380 |
return; |
335 | 381 |
} |
336 | 382 |
|
... | ... | |
338 | 384 |
// define default baselink and filename for optional module javascript and stylesheet files |
339 | 385 |
$head_links = ""; |
340 | 386 |
if($file_id == "css") { |
341 |
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"';
|
|
387 |
$base_link = '<link href="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.css"'; |
|
342 | 388 |
$base_link.= ' rel="stylesheet" type="text/css" media="screen" />'; |
343 | 389 |
$base_file = "frontend.css"; |
344 | 390 |
} else { |
345 |
$base_link = '<script type="text/javascript" src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js"></script>';
|
|
391 |
$base_link = '<script src="'.WB_URL.'/modules/{MODULE_DIRECTORY}/frontend.js" type="text/javascript"></script>';
|
|
346 | 392 |
$base_file = "frontend.js"; |
347 | 393 |
} |
348 | 394 |
|
Also available in: Unified diff
Added option to use a frontend_body.js in modules to include javascript from modules in the body of the frontend (Thanks to Luisehahne)