Blame view

vendor/kartik-v/yii2-krajee-base/AssetBundle.php 3.27 KB
583ea05f   andryeyev   + widget-select2
1
2
3
4
5
6
  <?php
  
  /**
   * @package   yii2-krajee-base
   * @author    Kartik Visweswaran <kartikv2@gmail.com>
   * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014 - 2015
280e92c2   Dmitryi   авторизация через...
7
   * @version   1.7.8
583ea05f   andryeyev   + widget-select2
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
   */
  
  namespace kartik\base;
  
  /**
   * Base asset bundle for all widgets
   *
   * @author Kartik Visweswaran <kartikv2@gmail.com>
   * @since 1.0
   */
  class AssetBundle extends \yii\web\AssetBundle
  {
      const EMPTY_ASSET = 'N0/@$$3T$';
      const EMPTY_PATH = 'N0/P@T#';
      const KRAJEE_ASSET = 'K3/@$$3T$';
      const KRAJEE_PATH = 'K3/P@T#';
280e92c2   Dmitryi   авторизация через...
24
  
583ea05f   andryeyev   + widget-select2
25
26
      public $js = self::KRAJEE_ASSET;
      public $css = self::KRAJEE_ASSET;
280e92c2   Dmitryi   авторизация через...
27
      public $sourcePath = self::KRAJEE_PATH;
583ea05f   andryeyev   + widget-select2
28
29
30
31
32
33
34
35
36
      public $depends = [
          'yii\web\JqueryAsset',
          'yii\web\YiiAsset',
          'yii\bootstrap\BootstrapAsset',
      ];
  
      /**
       * @inheritdoc
       */
280e92c2   Dmitryi   авторизация через...
37
38
      public function init()
      {
583ea05f   andryeyev   + widget-select2
39
40
41
42
43
44
45
46
47
48
49
          parent::init();
          if ($this->js === self::KRAJEE_ASSET) {
              $this->js = [];
          }
          if ($this->css === self::KRAJEE_ASSET) {
              $this->css = [];
          }
          if ($this->sourcePath === self::KRAJEE_PATH) {
              $this->sourcePath = null;
          }
      }
280e92c2   Dmitryi   авторизация через...
50
  
583ea05f   andryeyev   + widget-select2
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
      /**
       * Adds a language JS locale file
       *
       * @param string $lang the ISO language code
       * @param string $prefix the language locale file name prefix
       * @param string $dir the language file directory relative to source path
       * @param bool $min whether to auto use minified version
       *
       * @return AssetBundle instance
       */
      public function addLanguage($lang = '', $prefix = '', $dir = null, $min = false)
      {
          if (empty($lang) || substr($lang, 0, 2) == 'en') {
              return $this;
          }
280e92c2   Dmitryi   авторизация через...
66
          $ext = $min ? (YII_DEBUG ? ".min.js" : ".js") : ".js";
583ea05f   andryeyev   + widget-select2
67
68
69
70
71
72
73
74
75
76
77
78
          $file = "{$prefix}{$lang}{$ext}";
          if ($dir === null) {
              $dir = 'js';
          } elseif ($dir === "/") {
              $dir = '';
          }
          $path = $this->sourcePath . '/' . $dir;
          if (!Config::fileExists("{$path}/{$file}")) {
              $lang = Config::getLang($lang);
              $file = "{$prefix}{$lang}{$ext}";
          }
          if (Config::fileExists("{$path}/{$file}")) {
280e92c2   Dmitryi   авторизация через...
79
              $this->js[] = empty($dir) ? $file : "{$dir}/{$file}";
583ea05f   andryeyev   + widget-select2
80
81
82
          }
          return $this;
      }
280e92c2   Dmitryi   авторизация через...
83
  
583ea05f   andryeyev   + widget-select2
84
85
86
87
      /**
       * Set up CSS and JS asset arrays based on the base-file names
       *
       * @param string $type whether 'css' or 'js'
280e92c2   Dmitryi   авторизация через...
88
       * @param array $files the list of 'css' or 'js' basefile names
583ea05f   andryeyev   + widget-select2
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
       */
      protected function setupAssets($type, $files = [])
      {
          if ($this->$type === self::KRAJEE_ASSET) {
              $srcFiles = [];
              $minFiles = [];
              foreach ($files as $file) {
                  $srcFiles[] = "{$file}.{$type}";
                  $minFiles[] = "{$file}.min.{$type}";
              }
              $this->$type = YII_DEBUG ? $srcFiles : $minFiles;
          } elseif ($this->$type === self::EMPTY_ASSET) {
              $this->$type = [];
          }
      }
  
      /**
       * Sets the source path if empty
       *
       * @param string $path the path to be set
       */
      protected function setSourcePath($path)
      {
          if ($this->sourcePath === self::KRAJEE_PATH) {
              $this->sourcePath = $path;
          } elseif ($this->sourcePath === self::EMPTY_PATH) {
              $this->sourcePath = null;
          }
      }
  }