00001 <?php
00002
00013 class TKToggleAction extends TKAction {
00014 protected $actions;
00015 protected static $toggleID = 0;
00016 protected $myToggleID;
00017
00022 public function __construct($actions) {
00023 parent::__construct();
00024
00025 $this->actions = $actions;
00026 $this->addExtraJS('tkv_toggle_' . self::$toggleID,
00027 "Toolkit.\$toggleIndex[" . self::$toggleID . "] = 0;\n" .
00028 "Toolkit.\$toggleCount[" . self::$toggleID . "] = " . count($actions) . ";\n");
00029
00030 $js = "Toolkit.\$toggleStates[" . self::$toggleID . "] = function(idx){switch(idx){";
00031
00032 foreach($actions as $i => $a) {
00033 if(is_array($a)) {
00034 $js .= "case $i:";
00035 foreach($a as $iaction) {
00036 if(is_string($iaction))
00037 $iaction = new TKCustomAction('', $iaction);
00038 $js .= $iaction->getInvocation() . ";";
00039 }
00040 $js .= "break;";
00041 }
00042 else {
00043 if(is_string($a))
00044 $a = new TKCustomAction('', $a);
00045 $js .= "case $i:" . $a->getInvocation() . ";break;";
00046 }
00047 }
00048 $js .= "}}\n";
00049 $this->addExtraJS("tk_toggle_" . self::$toggleID, $js);
00050 $this->myToggleId = self::$toggleID;
00051 self::$toggleID++;
00052 }
00053
00055 public function getInvocation() {
00056 return "Toolkit.doToggleNext('" . $this->myToggleId . "')";
00057 }
00058
00060 public static function createFromXML($attrs, $children) {
00061 $actions = array();
00062 foreach($children as $child) {
00063 if($child['tag'] == "event") {
00064 array_push($actions, self::convertAction($child));
00065 }
00066 }
00067 $obj = new TKToggleAction($actions);
00068 return $obj;
00069 }
00070 }
00071
00072 ?>