original_string: protected function __toJS($strCustomJs = "", $arrInitArguments = array(), $blnRawJs = false)
      {
          $strReturn = "";
          $strJs = "";
  
          // *** Loop through all form elements and get their javascript code.
          foreach ($this->__elements as $element) {
              $strJs .= $element->toJS();
          }
  
          // *** Form Events.
          foreach ($this->__jsevents as $event => $method) {
              $strJs .= "\tobjForm.addEvent(\"{$event}\", {$method});\n";
          }
  
          // Indent javascript
          $strJs = str_replace("\n", "\n\t", $strJs);
  
          if (! $blnRawJs) {
              $strReturn .= "<script type=\"text/javascript\">\n";
              $strReturn .= "// <![CDATA[\n";
          }
  
          $strName = str_replace("-", "_", $this->__name);
          $strReturn .= "function {$strName}_init() {\n";
  
          $strCalledClass = static::getStrippedClassName(get_called_class());
          $strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\"";
          if (count($arrInitArguments) > 0) {
              $strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\", " . json_encode($arrInitArguments);
          }
  
          /**
           * If the ValidForm class is extended, try to initialize a custom javascript class with the same name as well
           * If that javascript class is not available / does not exist, continue initializing ValidForm as usual.
           */
          if ($strCalledClass !== "ValidForm") {
              $strReturn .= "\tvar objForm = (typeof {$strCalledClass} !== \"undefined\") ? ";
              $strReturn .= "new {$strCalledClass}({$strArguments}) : ";
              $strReturn .= "new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n";
          } else {
              $strReturn .= "\tvar objForm = new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n";
          }
  
          $strReturn .= $strJs;
          if (! empty($strCustomJs)) {
              $strReturn .= $strCustomJs;
          }
  
          $strReturn .= "\tobjForm.initialize();\n";
          $strReturn .= "\t$(\"#{$this->__name}\").data(\"vf__formElement\", objForm);";
          $strReturn .= "};\n";
          $strReturn .= "\n";
          $strReturn .= "try {\n";
          $strReturn .= "\tjQuery(function(){\n";
          $strReturn .= "\t\t{$this->__name}_init();\n";
          $strReturn .= "\t});\n";
          $strReturn .= "} catch (e) {\n";
          $strReturn .= "\talert('Exception caught while initiating ValidForm:\\n\\n' + e.message);\n";
          $strReturn .= "}\n";
  
          if (! $blnRawJs) {
              $strReturn .= "// ]]>\n";
              $strReturn .= "</script>\n";
          }
  
          return $strReturn;
      }
code: protected function __toJS($strCustomJs = "", $arrInitArguments = array(), $blnRawJs = false)
      {
          $strReturn = "";
          $strJs = "";
  
          // *** Loop through all form elements and get their javascript code.
          foreach ($this->__elements as $element) {
              $strJs .= $element->toJS();
          }
  
          // *** Form Events.
          foreach ($this->__jsevents as $event => $method) {
              $strJs .= "\tobjForm.addEvent(\"{$event}\", {$method});\n";
          }
  
          // Indent javascript
          $strJs = str_replace("\n", "\n\t", $strJs);
  
          if (! $blnRawJs) {
              $strReturn .= "<script type=\"text/javascript\">\n";
              $strReturn .= "// <![CDATA[\n";
          }
  
          $strName = str_replace("-", "_", $this->__name);
          $strReturn .= "function {$strName}_init() {\n";
  
          $strCalledClass = static::getStrippedClassName(get_called_class());
          $strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\"";
          if (count($arrInitArguments) > 0) {
              $strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\", " . json_encode($arrInitArguments);
          }
  
          /**
           * If the ValidForm class is extended, try to initialize a custom javascript class with the same name as well
           * If that javascript class is not available / does not exist, continue initializing ValidForm as usual.
           */
          if ($strCalledClass !== "ValidForm") {
              $strReturn .= "\tvar objForm = (typeof {$strCalledClass} !== \"undefined\") ? ";
              $strReturn .= "new {$strCalledClass}({$strArguments}) : ";
              $strReturn .= "new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n";
          } else {
              $strReturn .= "\tvar objForm = new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n";
          }
  
          $strReturn .= $strJs;
          if (! empty($strCustomJs)) {
              $strReturn .= $strCustomJs;
          }
  
          $strReturn .= "\tobjForm.initialize();\n";
          $strReturn .= "\t$(\"#{$this->__name}\").data(\"vf__formElement\", objForm);";
          $strReturn .= "};\n";
          $strReturn .= "\n";
          $strReturn .= "try {\n";
          $strReturn .= "\tjQuery(function(){\n";
          $strReturn .= "\t\t{$this->__name}_init();\n";
          $strReturn .= "\t});\n";
          $strReturn .= "} catch (e) {\n";
          $strReturn .= "\talert('Exception caught while initiating ValidForm:\\n\\n' + e.message);\n";
          $strReturn .= "}\n";
  
          if (! $blnRawJs) {
              $strReturn .= "// ]]>\n";
              $strReturn .= "</script>\n";
          }
  
          return $strReturn;
      }
code_tokens: protected function __toJS ( $ strCustomJs = "" , $ arrInitArguments = array ( ) , $ blnRawJs = false ) { $ strReturn = "" ; $ strJs = "" ; // *** Loop through all form elements and get their javascript code. foreach ( $ this -> __elements as $ element ) { $ strJs .= $ element -> toJS ( ) ; } // *** Form Events. foreach ( $ this -> __jsevents as $ event => $ method ) { $ strJs .= "\tobjForm.addEvent(\"{$event}\", {$method});\n" ; } // Indent javascript $ strJs = str_replace ( "\n" , "\n\t" , $ strJs ) ; if ( ! $ blnRawJs ) { $ strReturn .= "<script type=\"text/javascript\">\n" ; $ strReturn .= "// <![CDATA[\n" ; } $ strName = str_replace ( "-" , "_" , $ this -> __name ) ; $ strReturn .= "function {$strName}_init() {\n" ; $ strCalledClass = static :: getStrippedClassName ( get_called_class ( ) ) ; $ strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\"" ; if ( count ( $ arrInitArguments ) > 0 ) { $ strArguments = "\"{$this->__name}\", \"{$this->__mainalert}\", " . json_encode ( $ arrInitArguments ) ; } /**
           * If the ValidForm class is extended, try to initialize a custom javascript class with the same name as well
           * If that javascript class is not available / does not exist, continue initializing ValidForm as usual.
           */ if ( $ strCalledClass !== "ValidForm" ) { $ strReturn .= "\tvar objForm = (typeof {$strCalledClass} !== \"undefined\") ? " ; $ strReturn .= "new {$strCalledClass}({$strArguments}) : " ; $ strReturn .= "new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n" ; } else { $ strReturn .= "\tvar objForm = new ValidForm(\"{$this->__name}\", \"{$this->__mainalert}\");\n" ; } $ strReturn .= $ strJs ; if ( ! empty ( $ strCustomJs ) ) { $ strReturn .= $ strCustomJs ; } $ strReturn .= "\tobjForm.initialize();\n" ; $ strReturn .= "\t$(\"#{$this->__name}\").data(\"vf__formElement\", objForm);" ; $ strReturn .= "};\n" ; $ strReturn .= "\n" ; $ strReturn .= "try {\n" ; $ strReturn .= "\tjQuery(function(){\n" ; $ strReturn .= "\t\t{$this->__name}_init();\n" ; $ strReturn .= "\t});\n" ; $ strReturn .= "} catch (e) {\n" ; $ strReturn .= "\talert('Exception caught while initiating ValidForm:\\n\\n' + e.message);\n" ; $ strReturn .= "}\n" ; if ( ! $ blnRawJs ) { $ strReturn .= "// ]]>\n" ; $ strReturn .= "</script>\n" ; } return $ strReturn ; }
docstring: Generate javascript initialization code.
  
  This generates the javascript used to create a client-side ValidForm Builder instance.
  
  @param string $strCustomJs Optional custom javascript code to be executed at the same
  time the form is initialized
  @param array $arrInitArguments Only use this when initializing a custom client-side object. This is a flat array
  of arguments being passed to the custom client-side object.
  @param bool $blnRawJs If set to true, the generated javascript will not be wrapped in a <script> element. This
  is particulary useful when generating javascript to be returned to an AJAX response.
  
  @return string Generated javascript code
docstring_tokens: Generate javascript initialization code .