setControl($control); $this->setText($text); $this->setLabelName($labelName); $this->setIsolated($isolated); } /** * Set the Control * * @param Control $control Custom Control * @return \FML\Script\Features\ControlScript */ public function setControl(Control $control) { $control->checkId(); if ($control instanceof Scriptable) { $control->setScriptEvents(true); } $this->control = $control; return $this; } /** * Set the Script Text * * @param string $text Script Text * @return \FML\Script\Features\ControlScript */ public function setText($text) { $this->text = (string)$text; return $this; } /** * Set the Label Name * * @param string $labelName Script Label Name * @return \FML\Script\Features\ControlScript */ public function setLabelName($labelName) { $this->labelName = $labelName; return $this; } /** * Set whether the Script should be isolated * * @param bool $isolated Whether to isolate the Script Text * @return \FML\Script\Features\ControlScript */ public function setIsolated($isolated = true) { $this->isolated = (bool)$isolated; return $this; } /** * @see \FML\Script\Features\ScriptFeature::prepare() */ public function prepare(Script $script) { $script->appendGenericScriptLabel($this->labelName, $this->getEncapsulatedText(), $this->isolated); return $this; } /** * Get the Script Text encapsulated for the Control Event * * @return string */ protected function getEncapsulatedText() { $controlId = $this->control->getId(true); $scriptText = " if (Event.ControlId == \"{$controlId}\") { {$this->text} }"; return $scriptText; } }