/** * @return string */ public function JS() { $code = $this->getCode(); if (is_string($code)) { $code = array($code); // blöde interfaces vom js helper } elseif ($code instanceof \Psc\JS\Expression) { $code = array($code->JS()); } // load-wrappers (von innen nach außen) if ($this->onPscReady === 'main') { // non blocking mode (is save to use in html inline scripts directly) $this->unshiftRequirement('app/main'); $this->unshiftRequirementAlias('main'); $this->unshiftRequirement('jquery'); $this->unshiftRequirementAlias('jQuery'); $code = Helper::bootLoad($this->getRequirements(), $this->requirementsAliases, $code); } elseif ($this->onPscReady) { // is only save to use in ajax requests / inline scripts where window.requireLoad is already defined $this->unshiftRequirement('jquery'); $this->unshiftRequirementAlias('jQuery'); $code = Helper::requireLoad($this->getRequirements(), $this->requirementsAliases, $code); } elseif (count($req = $this->getRequirements()) > 0) { $code = Helper::requirejs($req, array(), $code); } else { $code = count($code) > 1 ? \Webforge\Common\ArrayUtil::join($code, "%s\n") : current($code); } return TPL::miniTemplate((string) $code, (array) $this->vars); }
/** * Erstellt das Objekt direkt nachdem das HTML geladen wird per inline-Javascript * * vorher werden mögliche Dependencies geladen und es wird auf Main gewartet. * in den Constructor-Parametern ist "main" definiert und zeigt auf Psc.UI.Main * * man muss selbst sicherstellen dass init() aufgerufen wurde (bzw this->html gesetzt ist) */ protected function autoLoad() { if (!$this->disableAutoLoad) { $constructCode = $this->createConstructCode($this->jooseClass, $this->constructParams, FALSE); if (mb_strpos($this->html->getTemplate(), '%autoLoadJoose%') === FALSE) { $this->html->templateAppend("\n" . '%autoLoadJoose%'); } $this->html->getTemplateContent()->autoLoadJoose = jsHelper::embed(jsHelper::requireLoad(array_merge(array('jquery'), array_map(function ($class) { return str_replace('.', '/', $class); }, $this->dependencies)), array('jQuery'), $constructCode)); } return $this; }