registerJsFile() public method

Registers a JS file.
public registerJsFile ( string $url, array $options = [], string $key = null )
$url string the JS file to be registered.
$options array the HTML attributes for the script tag. The following options are specially handled and are not treated as HTML attributes: - `depends`: array, specifies the names of the asset bundles that this JS file depends on. - `position`: specifies where the JS script tag should be inserted in a page. The possible values are: * [[POS_HEAD]]: in the head section * [[POS_BEGIN]]: at the beginning of the body section * [[POS_END]]: at the end of the body section. This is the default value. Please refer to [[Html::jsFile()]] for other supported options.
$key string the key that identifies the JS script file. If null, it will use $url as the key. If two JS files are registered with the same key at the same position, the latter will overwrite the former. Note that position option takes precedence, thus files registered with the same key, but different position option will not override each other.
コード例 #1
2
    /**
     * @param string $language
     * @param View   $view
     */
    public function registerLanguage($language, $view)
    {
        if (file_exists($this->sourcePath . "/locale/{$language}.js")) {
            $this->js = array_merge($this->js, ['min/locales.min.js']);
            $view->registerJsFile($this->baseUrl . "/locale/{$language}.js");
            $js = <<<JS
moment.locale('{$language}');
JS;
            $view->registerJs($js, View::POS_READY, 'moment-locale-' . $language);
        }
    }
コード例 #2
2
 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     $manager = $view->getAssetManager();
     foreach ($this->css as $css) {
         $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
     }
     $view->registerJsFile($this->basketJs);
     $jsFiles = [];
     foreach ($this->js as $js) {
         $jsFiles[] = Json::encode(['url' => $manager->getAssetUrl($this, $js)]);
     }
     $view->registerJs(sprintf('basket.require(%s);', implode(",\r\n", $jsFiles)), View::POS_END);
 }
コード例 #3
1
 /**
  * @param \yii\web\View $view
  * @throws \yii\base\InvalidConfigException If file with the locale is not exists.
  */
 public function registerLocaleInternal($view)
 {
     $localeFilePath = $this->tryFindLocale();
     if (YII_DEBUG && !$localeFilePath) {
         throw new InvalidConfigException('Locale file "' . \Yii::$app->language . '" not exists!');
     }
     $manager = $view->getAssetManager();
     $view->registerJsFile($manager->getAssetUrl($this, $this->locale), $this->jsOptions, 'moment-locale-' . $this->locale);
     if ($this->setLocaleOnReady) {
         $js = "moment().locale('" . $this->locale . "');";
         $view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
     }
 }
コード例 #4
1
 /**
  * @param \yii\web\View $view
  * @throws \yii\base\InvalidConfigException If file with the locale is not exists.
  */
 public function registerLocaleInternal($view)
 {
     $localeFile = strtolower($this->locale) . '.js';
     $localeFilePath = "{$this->sourcePath}/{$localeFile}";
     if (YII_DEBUG && !file_exists($localeFilePath)) {
         throw new InvalidConfigException('Locale file "' . $localeFilePath . '" not exists!');
     }
     $manager = $view->getAssetManager();
     $view->registerJsFile($manager->getAssetUrl($this, $localeFile), $this->jsOptions, 'moment-locale-' . $this->locale);
     if ($this->setLocaleOnReady) {
         $js = "moment.locale('{$this->locale}');'";
         $view->registerJs($js, View::POS_READY, 'moment-set-default-locale');
     }
 }
コード例 #5
1
ファイル: View.php プロジェクト: weison-tech/humhub
 /**
  * @inheritdoc
  */
 public function registerJsFile($url, $options = array(), $key = null)
 {
     parent::registerJsFile($this->addCacheBustQuery($url), $options, $key);
 }
コード例 #6
0
 /**
  * Registers the CSS and JS files with the given view.
  * public $css = [
  *      'css/bootstrap.min.css',
  *      'css/font-awesome.min.css' => array('position' => View::POS_END, 'condition' => 'lte IE 8')
  * ]
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     foreach ($this->js as $value) {
         if (is_array($value)) {
             if (isset($value['file'])) {
                 $js = $value['file'];
                 unset($value['file']);
                 $options = ArrayHelper::merge($this->jsOptions, $value);
             } else {
                 if (isset($value['content'])) {
                     $position = isset($value['position']) ? $value['position'] : $view::POS_READY;
                     $view->registerJs($value['content'], $position);
                 }
                 continue;
             }
         } else {
             $js = $value;
             $options = $this->jsOptions;
         }
         if ($js[0] !== '/' && $js[0] !== '.' && strpos($js, '://') === false) {
             $view->registerJsFile($this->baseUrl . '/' . $js, [], $options);
         } else {
             $view->registerJsFile($js, [], $options);
         }
     }
     foreach ($this->css as $value) {
         if (is_array($value)) {
             if (isset($value['file'])) {
                 $css = $value['file'];
                 unset($value['file']);
                 $options = ArrayHelper::merge($this->cssOptions, $value);
             } else {
                 if (isset($value['content'])) {
                     $position = isset($value['position']) ? $value['position'] : $view::POS_READY;
                     $view->registerCss($value['content'], $position);
                 }
                 continue;
             }
         } else {
             $css = $value;
             $options = $this->cssOptions;
         }
         if ($css[0] !== '/' && $css[0] !== '.' && strpos($css, '://') === false) {
             $view->registerCssFile($this->baseUrl . '/' . $css, [], $options);
         } else {
             $view->registerCssFile($css, [], $options);
         }
     }
 }
コード例 #7
0
 public function registerJsFile($url, $options = [], $key = null)
 {
     Yii::log('Registering ' . $url, 'info', __METHOD__);
     // Register in parent in order to trigger any errors with the parameters
     parent::registerJsFile($url, $options, $key);
     // Register using Yii1 client script
     $clientScript = Yii::app()->getClientScript();
     $url = $this->getAssetsUrl() . $url;
     $clientScript->registerScriptFile($url);
 }
コード例 #8
0
ファイル: AppAsset.php プロジェクト: phpsong/ExtJS5-Yii2
 public function registerAssetFiles(View $view)
 {
     $manager = $view->getAssetManager();
     $arr_js = $this->js;
     $arr_css = $this->css;
     if (isset($view->context->layout) && $view->context->layout === 'parts') {
         $arr_js = $this->js_parts;
         $arr_css = $this->css_parts;
     }
     foreach ($arr_js as $js) {
         $view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
     }
     foreach ($arr_css as $css) {
         $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
     }
 }
コード例 #9
0
ファイル: AssetBundle.php プロジェクト: snivs/semanti
 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     $manager = $view->getAssetManager();
     foreach ($this->js as $js) {
         $view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
     }
     foreach ($this->css as $css) {
         // FIX -------------------------------------------------------------
         // save converted files in to css folder instead of scss
         $pos = strrpos($css, '.');
         $ext = $pos !== false ? substr($css, $pos + 1) : null;
         if ($ext == 'css') {
             $css = preg_replace("/^scss\\//i", "css/", $css);
         }
         // -----------------------------------------------------------------
         $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
     }
 }
コード例 #10
0
 /**
  * @param string $language
  * @param View $view
  */
 public function registerLanguage($language, $view)
 {
     $sourcePath = Yii::getAlias($this->sourcePath);
     $fallbackLanguage = substr($language, 0, 2);
     $desiredFile = $sourcePath . DIRECTORY_SEPARATOR . "{$language}.js";
     if (!is_file($desiredFile)) {
         if ($fallbackLanguage === 'en') {
             // en is default, there is not separate locale file for it
             return;
         }
         $desiredFile = $sourcePath . DIRECTORY_SEPARATOR . "{$fallbackLanguage}.js";
         if (file_exists($desiredFile)) {
             $language = $fallbackLanguage;
         }
     }
     $view->registerJsFile($this->baseUrl . "/{$language}.js");
     $js = "moment.locale('{$language}')";
     $view->registerJs($js, View::POS_READY, 'moment-locale-' . $language);
 }
コード例 #11
0
ファイル: AssetBundle.php プロジェクト: sadiqhirani/yii2
 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     $manager = $view->getAssetManager();
     foreach ($this->js as $js) {
         if (is_array($js)) {
             $file = array_shift($js);
             $options = ArrayHelper::merge($this->jsOptions, $js);
             $view->registerJsFile($manager->getAssetUrl($this, $file), $options);
         } else {
             $view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
         }
     }
     foreach ($this->css as $css) {
         if (is_array($css)) {
             $file = array_shift($css);
             $options = ArrayHelper::merge($this->cssOptions, $css);
             $view->registerCssFile($manager->getAssetUrl($this, $file), $options);
         } else {
             $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
         }
     }
 }
コード例 #12
0
 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     $manager = $view->getAssetManager();
     foreach ($this->js as $js) {
         $view->registerJsFile($manager->getAssetUrl($this, $js), $this->jsOptions);
     }
     foreach ($this->css as $css) {
         $view->registerCssFile($manager->getAssetUrl($this, $css), $this->cssOptions);
     }
 }
コード例 #13
0
ファイル: Assets.php プロジェクト: nguyentuansieu/BioMedia
 /**
  * @param \yii\web\View $view
  */
 public static function noConflict($view)
 {
     list(, $path) = \Yii::$app->assetManager->publish(__DIR__ . "/assets");
     $view->registerJsFile($path . '/js/no.conflict.js', ['depends' => [JqueryAsset::className()]]);
 }
コード例 #14
0
 /**
  * @inheritdoc
  */
 public function registerJsFile($url, $options = [], $key = null)
 {
     $key = $key ?: $url;
     $this->_jsFileURLs[$key] = $url;
     parent::registerJsFile($url, $options, $key);
 }
コード例 #15
0
ファイル: Tour.php プロジェクト: kreativmind/humhub
 /**
  * load needed resources files
  */
 public function loadResources(\yii\web\View $view)
 {
     $view->registerJsFile('@web/resources/tour/bootstrap-tour.min.js');
     $view->registerCssFile('@web/resources/tour/bootstrap-tour.min.css');
 }
コード例 #16
0
ファイル: AssetBundle.php プロジェクト: albertborsos/yii2
 /**
  * Registers the CSS and JS files with the given view.
  * @param \yii\web\View $view the view that the asset files are to be registered with.
  */
 public function registerAssetFiles($view)
 {
     foreach ($this->js as $js) {
         if ($js[0] !== '/' && $js[0] !== '.' && strpos($js, '://') === false) {
             $view->registerJsFile($this->baseUrl . '/' . $js, [], $this->jsOptions);
         } else {
             $view->registerJsFile($js, [], $this->jsOptions);
         }
     }
     foreach ($this->css as $css) {
         if ($css[0] !== '/' && $css[0] !== '.' && strpos($css, '://') === false) {
             $view->registerCssFile($this->baseUrl . '/' . $css, [], $this->cssOptions);
         } else {
             $view->registerCssFile($css, [], $this->cssOptions);
         }
     }
 }
コード例 #17
0
ファイル: WebView.php プロジェクト: tqsq2005/dotplant2
 /**
  * @inheritdoc
  */
 public function registerJsFile($url, $options = [], $key = null)
 {
     $this->viewElementsGathener->gather(__FUNCTION__, func_get_args());
     return parent::registerJsFile($url, $options, $key);
 }