setActionName($actionName); } if ($keyName !== null) { $this->setKeyName($keyName); } } /** * Set the action to trigger * * @param string $actionName Triggered action * @return static */ public function setActionName($actionName) { $this->actionName = (string)$actionName; return $this; } /** * Set the key name for triggering the action * * @param string $keyName Key Name * @return static */ public function setKeyName($keyName) { $this->keyName = (string)$keyName; $this->keyCode = null; $this->charPressed = null; return $this; } /** * Set the key code for triggering the action * * @param int $keyCode Key Code * @return static */ public function setKeyCode($keyCode) { $this->keyCode = (int)$keyCode; $this->keyName = null; $this->charPressed = null; return $this; } /** * Set the char to press for triggering the action * * @param string $charPressed Pressed char * @return static */ public function setCharPressed($charPressed) { $this->charPressed = (string)$charPressed; $this->keyName = null; $this->keyCode = null; return $this; } /** * @see \FML\Script\Features\ScriptFeature::prepare() */ public function prepare(Script $script) { $script->appendGenericScriptLabel(ScriptLabel::KEYPRESS, $this->getScriptText()); return $this; } /** * Get the script text * * @return string */ protected function getScriptText() { $actionName = Builder::escapeText($this->actionName, true); $key = null; $value = null; if ($this->keyName !== null) { $key = 'KeyName'; $value = $this->keyName; } else if ($this->keyCode !== null) { $key = 'KeyCode'; $value = $this->keyCode; } else if ($this->charPressed !== null) { $key = 'CharPressed'; $value = $this->charPressed; } $value = Builder::escapeText($value, true); return " if (Event.{$key} == {$value}) { TriggerPageAction({$actionName}); }"; } }