Zikula_Template_Plugins
[ class tree: Zikula_Template_Plugins ] [ index: Zikula_Template_Plugins ] [ all elements ]

Source for file function.pnajaxheader.php

Documentation is available at function.pnajaxheader.php

  1. <?php
  2. /**
  3.  * Zikula Application Framework
  4.  *
  5.  * @copyright (c) 2004, Zikula Development Team
  6.  * @link http://www.zikula.org
  7.  * @version $Id: function.pnajaxheader.php 24342 2008-06-06 12:03:14Z markwest $
  8.  * @license GNU/GPL - http://www.gnu.org/copyleft/gpl.html
  9.  * @package Zikula_Template_Plugins
  10.  * @subpackage Functions
  11.  */
  12.  
  13. /**
  14.  * Smarty function to insert the common ajax javascript files (prototype, scriptaculous, behaviour) in the page header using page vars
  15.  * All other jsvascript files have to added manually on demand using the PageUtil::addVar plugin
  16.  *
  17.  * Available parameters:
  18.  *   - modname:          define the module name in which to look for the base javascript file for the module (ajax.js), default to top level module
  19.  *                       when used in a block template, make sure this parameter is set correctly!
  20.  *   - filename:         (optional) filename to load (default ajax.js)
  21.  *   - nobehaviour:      (optional) does not include bahaviour.js if set
  22.  *   - noscriptaculous:  (optional) does not include scriptaculous.js if set
  23.  *   - validation:       (optional) includes validation.js if set
  24.  *   - fabtabulous:      (optional) includes fabtabulous.js if set
  25.  *   - builder:          (optional) includes builder.js if set. Only effective if noscriptaculous is set
  26.  *   - effects:          (optional) includes effects.js if set. Only effective if noscriptaculous is set
  27.  *   - dragdrop:         (optional) includes dragdrop.js if set. Only effective if noscriptaculous is set
  28.  *   - controls:         (optional) includes controls.js if set. Only effective if noscriptaculous is set
  29.  *   - slider:           (optional) includes slider.js if set. Only effective if noscriptaculous is set
  30.  *   - lightbox:         (optional) includes lightbox.js if set (loads scriptaculous effects if noscriptaculous is set)
  31.  *   - assign:           (optional) creates script tags and assign them if set
  32.  *
  33.  * If nobehaviour is not set (= should be included) then noscriptaculous will
  34.  * be ignored because of dependencies
  35.  *
  36.  * Examples:
  37.  *   <!--[pnajaxheader modname=Example filename=example.js]-->
  38.  *   <!--[pnajaxheader modname=Example nobehaviour=1]-->
  39.  *
  40.  * @author       Mark West
  41.  * @author       Frank Schummertz
  42.  * @since        3/4/2006
  43.  * @param        array       $params      All attributes passed to this function from the template
  44.  * @param        object      &$smarty     Reference to the Smarty object
  45.  * @return       null 
  46.  */
  47. function smarty_function_pnajaxheader($params&$smarty)
  48. {
  49.     extract($params);
  50.     unset($params);
  51.  
  52.     // use supplied modname or top level module
  53.     $modname       (isset($modname))         $modname  pnModGetName();
  54.     // define the default filename
  55.     $filename      (isset($filename))        $filename 'ajax.js';
  56.     $behaviour     (isset($nobehaviour))     false     true;
  57.     $scriptaculous (isset($noscriptaculous)) false     true;
  58.     $validation    (isset($validation))      true      false;
  59.     $fabtabulous   (isset($fabtabulous))     true      false;
  60.     $lightbox      (isset($lightbox))        true      false;
  61.     // script.aculo.us components
  62.     $builder       (isset($builder))         true      false;
  63.     $effects       (isset($effects))         true      false;
  64.     $dragdrop      (isset($dragdrop))        true      false;
  65.     $controls      (isset($controls))        true      false;
  66.     $slider        (isset($slider))          true      false;
  67.  
  68.     // create an empty return
  69.     $return '';
  70.  
  71.     $modinfo pnModGetInfo(pnModGetIDFromName($modname));
  72.     if ($modinfo==false{
  73.         $smarty->trigger_error('pnajaxheader: module ' DataUtil::formatForDisplay($modname' not available');
  74.         return false;
  75.     }
  76.  
  77.     // we always need those
  78.     $scripts array('javascript/ajax/prototype.js''javascript/ajax/pnajax.js');
  79.  
  80.     if ($behaviour{
  81.         $scripts['javascript/ajax/scriptaculous.js';
  82.         $scripts['javascript/ajax/behaviour.js';
  83.     else if ($scriptaculous == true{
  84.         $scripts['javascript/ajax/scriptaculous.js';
  85.     }
  86.     if ($validation{
  87.         $scripts['javascript/ajax/validation.js';
  88.     }
  89.     if ($fabtabulous{
  90.         $scripts['javascript/ajax/fabtabulous.js';
  91.     }
  92.     // script.aculo.us components
  93.     if (!$scriptaculous && $builder{
  94.         $scripts['javascript/ajax/scriptaculous.js?load=builder';
  95.     }
  96.     if (!$scriptaculous && ($effects || $lightbox)) {
  97.         $scripts['javascript/ajax/scriptaculous.js?load=effects';
  98.     }
  99.     if (!$scriptaculous && $dragdrop{
  100.         $scripts['javascript/ajax/scriptaculous.js?load=dragdrop';
  101.     }
  102.     if (!$scriptaculous && $controls{
  103.         $scripts['javascript/ajax/scriptaculous.js?load=controls';
  104.     }
  105.     if (!$scriptaculous && $slider{
  106.         $scripts['javascript/ajax/scriptaculous.js?load=slider';
  107.     }
  108.     if ($lightbox{
  109.         // lightbox needs at least the scriptaculous effects components....
  110.         $scripts['javascript/ajax/lightbox.js';
  111.         if (isset($assign)) {
  112.             $return '<link rel="stylesheet" href="javascript/ajax/lightbox/lightbox.css" type="text/css" media="screen" />';
  113.         else {
  114.             PageUtil::addVar('stylesheet''javascript/ajax/lightbox/lightbox.css');
  115.         }
  116.     }
  117.  
  118.     $osdirectory DataUtil::formatForOS($modinfo['directory']);
  119.     $osfilename  DataUtil::formatForOS($filename);
  120.  
  121.     if (($modinfo['type'== && file_exists($file "system/$osdirectory/pnjavascript/$osfilename")) ||
  122.        ($modinfo['type'== && file_exists($file "modules/$osdirectory/pnjavascript/$osfilename"))) {
  123.         $scripts[DataUtil::formatForDisplay($file);
  124.     }
  125.  
  126.     if (isset($assign)) {
  127.         // create script tags now
  128.         foreach($scripts as $script{
  129.             $return .= '<script type="text/javascript" src="' $script '"></script' "\n";
  130.         }
  131.         $smarty->assign($assign$return);
  132.     else {
  133.         PageUtil::addVar('javascript'$scripts);
  134.     }
  135.  
  136.     return;
  137. }

Documentation generated on Fri, 18 Jul 2008 21:45:35 +0200 by phpDocumentor 1.4.1