[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/tags/core/ -> script.tag.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2003 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TAG
   8  * @version $Id: script.tag.php,v 1.5 2004/11/18 04:22:47 jeffmoore Exp $
   9  */
  10  
  11  /**
  12  * Register the tag
  13  */
  14  $taginfo =& new TagInfo('core:SCRIPT', 'CoreScriptTag');
  15  $taginfo->setEndTag(ENDTAG_FORBIDDEN);
  16  TagDictionary::registerTag($taginfo, __FILE__);
  17  
  18  /**
  19  * Acts as a placeholder for writing JavaScript. Allows JavaScript to be
  20  * written both at compile time and runtime. Normally this tag would be
  21  * placed inside the head tag of an HTML page but for other markups, e.g.
  22  * XUL, it may appear otherwise. It is the responsibility of the template
  23  * designer to place this tag correctly.
  24  * When writing complile time Javascript to it, add the JavaScript using
  25  * the components preParse() method. Within preParse use findParentByClass
  26  * to get the root of the component tree then findChildByClass to find
  27  * the CoreScriptTag.
  28  * @see http://www.juicystudio.com/tutorial/javascript/embedding.asp
  29  * @see http://wact.sourceforge.net/index.php/CoreScriptTag
  30  * @see InputAutoCompleteTag
  31  * @access protected
  32  * @package WACT_TAG
  33  */
  34  class CoreScriptTag extends ServerComponentTag {
  35      /**
  36      * File to include at runtime
  37      * @var string path to runtime component relative to WACT_ROOT
  38      * @access private
  39      */
  40      var $runtimeIncludeFile = 'template/components/core/script.inc.php';
  41      /**
  42      * Name of runtime component class
  43      * @var string
  44      * @access private
  45      */
  46      var $runtimeComponentName = 'CoreScriptComponent';
  47  
  48      /**
  49      * Compile time JavaScript to write to template
  50      * @var string
  51      * @access private
  52      */
  53      var $javascript = '';
  54  
  55      /**
  56      * Write some JavaScript into the container
  57      * @param string JavaScript to write to compiled template
  58      * @return void
  59      * @access public
  60      */
  61  	function writeJavaScript($javascript) {
  62          $this->javascript.=$javascript;
  63      }
  64      /**
  65      * @param CodeWriter
  66      * @return void
  67      * @access protected
  68      */
  69  	function generateContents(&$code) {
  70          parent::generateContents($code);
  71          if ( !$type = $this->getAttribute('type') ) {
  72              $type = 'text/javascript';
  73          }
  74          $code->writeHTML('<script type="'.$type.'">');
  75          if ( $escapestyle = $this->getAttribute('escapestyle') ) {
  76              $escapestyles = array('comment','cdata','both');
  77              $escapestyle = strtolower($escapestyle);
  78              if ( !in_array($escapestyle,$escapestyles) ) {
  79                  $escapestyle = 'comment';
  80              }
  81          } else {
  82              $escapestyle = 'comment';
  83          }
  84          switch ( $escapestyle ) {
  85              case 'both':
  86                  $code->writeHTML("\n<!--//<![CDATA[\n");
  87              break;
  88              case 'cdata':
  89                  $code->writeHTML("\n<![CDATA[\n");
  90              break;
  91              default:
  92                  $code->writeHTML("\n<!--\n");
  93              break;
  94          }
  95  
  96          $code->writeHTML($this->javascript);
  97          $code->writePHP('echo '.$this->getComponentRefCode() . '->readJavaScript();');
  98  
  99          switch ( $escapestyle ) {
 100              case 'both':
 101                  $code->writeHTML("\n//]]>-->\n");
 102              break;
 103              case 'cdata':
 104                  $code->writeHTML("\n]]>\n");
 105              break;
 106              default:
 107                  $code->writeHTML("\n//-->\n");
 108              break;
 109          }
 110  
 111          $code->writeHTML('</script>');
 112      }
 113  }
 114  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5