getJavascripts() 공개 메소드

By default, the position is sfWebResponse::ALL, and the method returns all javascripts ordered by position.
public getJavascripts ( string $position = self::ALL ) : array
$position string The position
리턴 array An associative array of javascript files as keys and options as values
예제 #1
0
 /**
  * Merges all properties from a given sfWebResponse object to the current one.
  *
  * @param sfWebResponse $response  An sfWebResponse instance
  */
 public function merge(sfWebResponse $response)
 {
     foreach ($this->getPositions() as $position) {
         $this->javascripts[$position] = array_merge($this->getJavascripts($position), $response->getJavascripts($position));
         $this->stylesheets[$position] = array_merge($this->getStylesheets($position), $response->getStylesheets($position));
     }
     $this->slots = array_merge($this->getSlots(), $response->getSlots());
 }
 protected function prepareAssetsForNativeApp(sfWebRequest $request, sfWebResponse $response, $buildSettings)
 {
     $this->isInitialRequest = !$request->isXmlHttpRequest();
     foreach ($buildSettings['javascripts'] as $file) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($file);
         if ($this->isInitialRequest) {
             $response->addJavascript($filename, $position);
         } else {
             $response->removeJavascript($filename, $position);
         }
     }
     foreach ($buildSettings['stylesheets'] as $file) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($file);
         if ($this->isInitialRequest) {
             $response->addStylesheet($filename, $position);
         } else {
             $response->removeStylesheet($filename, $position);
         }
     }
     $excludeStylesheets = $buildSettings['excludeStylesheets'];
     foreach ($excludeStylesheets as $assetResource) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($assetResource);
         $response->removeStylesheet($filename, $position);
     }
     $excludeJavascripts = $buildSettings['excludeJavascripts'];
     foreach ($excludeJavascripts as $assetResource) {
         list($filename, $position) = $this->extractFilenameAndPositionForAssetResource($assetResource);
         $response->removeJavascript($filename, $position);
     }
     $context = $this->getContext();
     if (method_exists($context, 'getConfiguration') && method_exists($context->getConfiguration(), 'loadHelpers')) {
         $context->getConfiguration()->loadHelpers('Asset');
     } else {
         if (method_exists('sfLoader', 'loadHelpers')) {
             sfLoader::loadHelpers('Asset');
             //compatibility with symfony 1.0:
         }
     }
     sfConfig::set('symfony.asset.stylesheets_included', true);
     sfConfig::set('symfony.asset.javascripts_included', true);
     $css = '';
     $js = '';
     foreach (array('first', '', 'last') as $position) {
         $stylesheets = $response->getStylesheets($position);
         if (!empty($stylesheets)) {
             $css .= "\n/* position: {$position} */\n";
             $css .= $this->getCombinedAssetsAsString($stylesheets, 'stylesheet_path');
         }
         $javascripts = $response->getJavascripts($position);
         if (!empty($javascripts)) {
             $jsCurrent = $this->getCombinedAssetsAsString($javascripts, 'javascript_path');
             $jsCurrent = str_replace(array("'<script>", "</script>'"), array("'<scr'+'ipt>", "</scr'+'ipt>'"), $jsCurrent);
             //hack to avoid breaking code in jQuery mobile: domain && iframe_doc.write( '<script>document.domain="' + domain + '"</script>' );
             $js .= "\n/* position: {$position} */\n";
             $js .= $jsCurrent;
         }
     }
     if ($this->isInitialRequest) {
         //embed everything directly into main file
         $css = $this->base64EncodeImages($css);
         $this->cssContent = $css;
         $this->jsContent = $js;
         $this->jsContent2 = 'test';
     } else {
         $this->cssSrc = $this->getContentAsFileSrc($css, 'css');
         if (!$this->cssSrc) {
             $this->cssContent = $css;
         }
         //		    $this->jsSrc = $this->getContentAsFileSrc($js, 'js');
         //		    if (!$this->jsSrc) {
         //		    	$this->jsContent = $js;
         //		    }
         $this->jsContent = $js;
         //we have to load javascripts inline because iOs Safari loads external javascripts asynchronesly and thus we could nomore rely on events like pagecreate, pageshow, pagehide dom.ready etc
     }
 }