Revision 1105
Added by Matthias over 16 years ago
| trunk/CHANGELOG | ||
|---|---|---|
| 12 | 12 |
|
| 13 | 13 |
------------------------------------- 2.8.0 ------------------------------------- |
| 14 | 14 |
6-Aug-2009 Matthias Gallas |
| 15 |
+ Added option to use a frontend_body.js in modules to include javascript from modules |
|
| 16 |
in the body of the frontend (Thanks to Luisehahne) |
|
| 15 | 17 |
! Updated Danish language Files (Thanks to Achrist) |
| 16 | 18 |
# Fixed some display issues in argos_theme (Thanks to Argos) |
| 17 | 19 |
30-July-2009 Ruud Eisinga (Ruud) |
| trunk/wb/framework/module.functions.php | ||
|---|---|---|
| 155 | 155 |
|
| 156 | 156 |
if($css_file == 'frontend.css') {
|
| 157 | 157 |
// check if frontend.css needs to be included into the <body> section |
| 158 |
if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
|
| 158 |
if(!((!function_exists('register_frontend_modfiles') || !defined('MOD_FRONTEND_CSS_REGISTERED')) &&
|
|
| 159 | 159 |
file_exists(WB_PATH .'/modules/' .$mymod_dir .'/frontend.css'))) {
|
| 160 | 160 |
return false; |
| 161 | 161 |
} |
| ... | ... | |
| 178 | 178 |
if (!function_exists('requires_module_js')) {
|
| 179 | 179 |
function requires_module_js($mymod_dir, $js_file) {
|
| 180 | 180 |
if(!in_array(strtolower($js_file), array('frontend.js', 'backend.js'))) {
|
| 181 |
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'"
|
|
| 182 |
specified in module "' .htmlentities($mymod_dir) .'" not valid.';
|
|
| 181 |
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'" |
|
| 182 |
specified in module "' .htmlentities($mymod_dir) .'" not valid.'; |
|
| 183 | 183 |
return false; |
| 184 | 184 |
} |
| 185 |
|
|
| 185 |
|
|
| 186 | 186 |
if($js_file == 'frontend.js') {
|
| 187 | 187 |
// check if frontend.js is included to the <head> section |
| 188 | 188 |
if(!defined('MOD_FRONTEND_JAVASCRIPT_REGISTERED')) {
|
| ... | ... | |
| 192 | 192 |
to ensure that module frontend.js files are automatically loaded if required.</p> |
| 193 | 193 |
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles\')) { <br />
|
| 194 | 194 |
register_frontend_modfiles(\'js\');<br />?></code><br /> |
| 195 |
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template.
|
|
| 196 |
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable
|
|
| 197 |
<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs
|
|
| 195 |
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template. |
|
| 196 |
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable |
|
| 197 |
<code>$requires_frontend_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs |
|
| 198 | 198 |
to be upgraded to work with this module.</p> |
| 199 | 199 |
'; |
| 200 | 200 |
return false; |
| ... | ... | |
| 214 | 214 |
return true; |
| 215 | 215 |
} |
| 216 | 216 |
} |
| 217 |
// function to check if the optional module Javascript files are loaded into the <body> section |
|
| 218 |
if (!function_exists('requires_module_body_js')) {
|
|
| 219 |
function requires_module_body_js($mymod_dir, $js_file) {
|
|
| 220 |
if(!in_array(strtolower($js_file), array('frontend_body.js', 'backend_body.js'))) {
|
|
| 221 |
echo '<strong>Note: </strong>Javascript file "' .htmlentities($js_file) .'" |
|
| 222 |
specified in module "' .htmlentities($mymod_dir) .'" not valid.'; |
|
| 223 |
return false; |
|
| 224 |
} |
|
| 217 | 225 |
|
| 226 |
if($js_file == 'frontend_body.js') {
|
|
| 227 |
// check if frontend_body.js is included to the <body> section |
|
| 228 |
if(!defined('MOD_FRONTEND_BODY_JAVASCRIPT_REGISTERED')) {
|
|
| 229 |
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p> |
|
| 230 |
<p>This module uses Javascript functions contained in frontend_body.js of the module.<br /> |
|
| 231 |
Add the code below before to the </body> section in the index.php of your template |
|
| 232 |
to ensure that module frontend_body.js files are automatically loaded if required.</p> |
|
| 233 |
<code style="color: #800000;"><?php<br />if(function_exists(\'register_frontend_modfiles_body\')) { <br />
|
|
| 234 |
register_frontend_modfiles_body(\'js\');<br />?></code><br /> |
|
| 235 |
<p><strong>Tip:</strong> For WB 2.6.7 copy the code above to the index.php of your template. |
|
| 236 |
Then open the view.php of the "' .htmlentities($mymod_dir) .'" module and set the variable |
|
| 237 |
<code>$requires_frontend_body_js</code> to false. This may do the trick.</p><p>All WB versions below 2.6.7 needs |
|
| 238 |
to be upgraded to work with this module.</p> |
|
| 239 |
'; |
|
| 240 |
return false; |
|
| 241 |
} |
|
| 242 |
} else {
|
|
| 243 |
// check if backend_body.js is included to the <body> section |
|
| 244 |
global $admin; |
|
| 245 |
if(!method_exists($admin, 'register_backend_modfiles_body') && file_exists(WB_PATH .'/modules/' .$mymod_dir .'/backend_body.js')) {
|
|
| 246 |
echo '<p><strong>Note:</strong> The module: "' .htmlentities($mymod_dir) .'" requires WB 2.6.7 or higher</p> |
|
| 247 |
<p>This module uses Javascript functions contained in backend_body.js of the module.<br /> |
|
| 248 |
You need WB 2.6.7 or higher to ensure that module backend_body.js files are automatically loaded if required.</p> |
|
| 249 |
<p>Sorry, you can not use this tool with your WB installation, please upgrade to the latest WB version available.</p><br /> |
|
| 250 |
'; |
|
| 251 |
return false; |
|
| 252 |
} |
|
| 253 |
} |
|
| 254 |
return true; |
|
| 255 |
} |
|
| 256 |
} |
|
| 257 |
|
|
| 218 | 258 |
?> |
| trunk/wb/framework/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)