Last active
August 29, 2015 14:07
-
-
Save antonkomarev/63246451ba9464d0a829 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
return [ | |
'components' => [ | |
'view' => [ | |
'class' => 'common\components\View', | |
], | |
], | |
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace frontend\assets; | |
use yii\web\AssetBundle; | |
use yii\web\View; | |
class ShivAsset extends AssetBundle | |
{ | |
public $sourcePath = '@bower'; | |
public $jsOptions = [ | |
'condition' => 'lt IE 9', | |
'position' => View::POS_HEAD, | |
]; | |
public $js = [ | |
'html5shiv/dist/html5shiv.js', | |
'respond/dest/respond.min.js', | |
]; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace common\components; | |
use Yii; | |
use yii\helpers\Html; | |
use yii\web\AssetBundle; | |
class View extends \yii\web\View | |
{ | |
public function registerJsFile($url, $depends = [], $options = [], $key = null) | |
{ | |
$url = Yii::getAlias($url); | |
$key = $key ?: $url; | |
if (empty($depends)) { | |
$position = isset($options['position']) ? $options['position'] : self::POS_END; | |
unset($options['position']); | |
$condition = isset($options['condition']) ? $options['condition'] : null; | |
unset($options['condition']); | |
$tag = Html::jsFile($url, $options); | |
if ($condition) { | |
$tag = "<!--[if ".$condition."]>".$tag."<![endif]-->"; | |
} | |
$this->jsFiles[$position][$key] = $tag; | |
} else { | |
$am = Yii::$app->getAssetManager(); | |
if (strpos($url, '/') !== 0 && strpos($url, '://') === false) { | |
$url = Yii::$app->getRequest()->getBaseUrl() . '/' . $url; | |
} | |
$am->bundles[$key] = new AssetBundle([ | |
'js' => [$url], | |
'jsOptions' => $options, | |
'depends' => (array) $depends, | |
]); | |
$this->registerAssetBundle($key); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment