Browse Source

Asset feature refactoring (WIP)

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
368a4cfe66
  1. 28
      apps/advanced/backend/config/AppAsset.php
  2. 18
      apps/advanced/backend/config/assets.php
  3. 3
      apps/advanced/backend/config/main.php
  4. 3
      apps/advanced/backend/views/layouts/main.php
  5. 28
      apps/advanced/frontend/config/AppAsset.php
  6. 18
      apps/advanced/frontend/config/assets.php
  7. 3
      apps/advanced/frontend/config/main.php
  8. 3
      apps/advanced/frontend/views/layouts/main.php
  9. 1
      apps/basic/assets/.gitkeep
  10. 29
      apps/basic/config/AppAsset.php
  11. 18
      apps/basic/config/assets.php
  12. 3
      apps/basic/config/web.php
  13. 2
      apps/basic/views/layouts/main.php
  14. 7
      docs/guide/upgrade-from-v1.md
  15. 24
      extensions/jui/yii/jui/CoreAsset.php
  16. 24
      extensions/jui/yii/jui/WidgetAsset.php
  17. 16
      extensions/jui/yii/jui/assets.php
  18. 9
      framework/yii/YiiBase.php
  19. 64
      framework/yii/assets.php
  20. 24
      framework/yii/base/View.php
  21. 26
      framework/yii/bootstrap/AffixAsset.php
  22. 26
      framework/yii/bootstrap/AlertAsset.php
  23. 21
      framework/yii/bootstrap/BootstrapAsset.php
  24. 26
      framework/yii/bootstrap/ButtonAsset.php
  25. 26
      framework/yii/bootstrap/CarouselAsset.php
  26. 26
      framework/yii/bootstrap/CollapseAsset.php
  27. 26
      framework/yii/bootstrap/DropdownAsset.php
  28. 26
      framework/yii/bootstrap/ModalAsset.php
  29. 2
      framework/yii/bootstrap/Nav.php
  30. 8
      framework/yii/bootstrap/NavBar.php
  31. 24
      framework/yii/bootstrap/PopoverAsset.php
  32. 6
      framework/yii/bootstrap/Progress.php
  33. 24
      framework/yii/bootstrap/ResponsiveAsset.php
  34. 26
      framework/yii/bootstrap/ScrollspyAsset.php
  35. 26
      framework/yii/bootstrap/TabAsset.php
  36. 26
      framework/yii/bootstrap/TooltipAsset.php
  37. 25
      framework/yii/bootstrap/TransitionAsset.php
  38. 4
      framework/yii/bootstrap/Typeahead.php
  39. 26
      framework/yii/bootstrap/TypeaheadAsset.php
  40. 10
      framework/yii/bootstrap/Widget.php
  41. 119
      framework/yii/bootstrap/assets.php
  42. 25
      framework/yii/debug/DebugAsset.php
  43. 1
      framework/yii/debug/views/default/index.php
  44. 2
      framework/yii/debug/views/default/view.php
  45. 2
      framework/yii/debug/views/layouts/main.php
  46. 2
      framework/yii/validators/BooleanValidator.php
  47. 2
      framework/yii/validators/CaptchaValidator.php
  48. 2
      framework/yii/validators/CompareValidator.php
  49. 4
      framework/yii/validators/EmailValidator.php
  50. 2
      framework/yii/validators/NumberValidator.php
  51. 21
      framework/yii/validators/PunycodeAsset.php
  52. 2
      framework/yii/validators/RangeValidator.php
  53. 2
      framework/yii/validators/RegularExpressionValidator.php
  54. 2
      framework/yii/validators/RequiredValidator.php
  55. 2
      framework/yii/validators/StringValidator.php
  56. 4
      framework/yii/validators/UrlValidator.php
  57. 24
      framework/yii/validators/ValidationAsset.php
  58. 12
      framework/yii/web/AssetBundle.php
  59. 63
      framework/yii/web/AssetManager.php
  60. 20
      framework/yii/web/JqueryAsset.php
  61. 23
      framework/yii/web/YiiAsset.php
  62. 5
      framework/yii/widgets/ActiveForm.php
  63. 24
      framework/yii/widgets/ActiveFormAsset.php
  64. 5
      framework/yii/widgets/Captcha.php
  65. 24
      framework/yii/widgets/CaptchaAsset.php
  66. 5
      framework/yii/widgets/MaskedInput.php
  67. 24
      framework/yii/widgets/MaskedInputAsset.php

28
apps/advanced/backend/config/AppAsset.php

@ -0,0 +1,28 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace backend\config;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@wwwroot';
public $baseUrl = '@www';
public $css = array(
'css/site.css',
);
public $js = array(
);
public $depends = array(
'yii\web\YiiAsset',
'yii\bootstrap\ResponsiveAsset',
);
}

18
apps/advanced/backend/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

3
apps/advanced/backend/config/main.php

@ -23,9 +23,6 @@ return array(
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
),
'assetManager' => array(
'bundles' => require(__DIR__ . '/assets.php'),
),
'log' => array(
'targets' => array(
array(

3
apps/advanced/backend/views/layouts/main.php

@ -1,4 +1,5 @@
<?php
use backend\config\AppAsset;
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\widgets\Breadcrumbs;
@ -7,7 +8,7 @@ use yii\widgets\Breadcrumbs;
* @var $this \yii\base\View
* @var $content string
*/
$this->registerAssetBundle('app');
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>

28
apps/advanced/frontend/config/AppAsset.php

@ -0,0 +1,28 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace frontend\config;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@wwwroot';
public $baseUrl = '@www';
public $css = array(
'css/site.css',
);
public $js = array(
);
public $depends = array(
'yii\web\YiiAsset',
'yii\bootstrap\ResponsiveAsset',
);
}

18
apps/advanced/frontend/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

3
apps/advanced/frontend/config/main.php

@ -22,9 +22,6 @@ return array(
'class' => 'yii\web\User',
'identityClass' => 'common\models\User',
),
'assetManager' => array(
'bundles' => require(__DIR__ . '/assets.php'),
),
'log' => array(
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(

3
apps/advanced/frontend/views/layouts/main.php

@ -1,4 +1,5 @@
<?php
use frontend\config\AppAsset;
use yii\helpers\Html;
use yii\widgets\Menu;
use yii\widgets\Breadcrumbs;
@ -7,7 +8,7 @@ use yii\widgets\Breadcrumbs;
* @var $this \yii\base\View
* @var $content string
*/
$this->registerAssetBundle('app');
AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>

1
apps/basic/assets/.gitkeep

@ -1 +0,0 @@
*

29
apps/basic/config/AppAsset.php

@ -0,0 +1,29 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace app\config;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@wwwroot';
public $baseUrl = '@www';
public $css = array(
'css/site.css',
);
public $js = array(
);
public $depends = array(
'yii\web\YiiAsset',
'yii\bootstrap\ResponsiveAsset',
);
}

18
apps/basic/config/assets.php

@ -1,18 +0,0 @@
<?php
return array(
'app' => array(
'basePath' => '@wwwroot',
'baseUrl' => '@www',
'css' => array(
'css/site.css',
),
'js' => array(
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
);

3
apps/basic/config/web.php

@ -18,9 +18,6 @@ return array(
'class' => 'yii\web\User',
'identityClass' => 'app\models\User',
),
'assetManager' => array(
'bundles' => require(__DIR__ . '/assets.php'),
),
'log' => array(
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => array(

2
apps/basic/views/layouts/main.php

@ -7,7 +7,7 @@ use yii\widgets\Breadcrumbs;
* @var $this \yii\base\View
* @var $content string
*/
$this->registerAssetBundle('app');
app\config\AppAsset::register($this);
?>
<?php $this->beginPage(); ?>
<!DOCTYPE html>

7
docs/guide/upgrade-from-v1.md

@ -311,9 +311,10 @@ Yii 2.0 introduces a new concept called *asset bundle*. It is similar to script
packages (managed by `CClientScript`) in 1.1, but with better support.
An asset bundle is a collection of asset files (e.g. JavaScript files, CSS files, image files, etc.)
under a directory. By registering an asset bundle via `View::registerAssetBundle()`, you
will be able to make the assets in that bundle accessible via Web, and the current page
will automatically contain references to the JavaScript and CSS files in that bundle.
under a directory. Each asset bundle is represented as a class extending `AssetBundle`.
By registering an asset bundle via `AssetBundle::register()`, you will be able to make
the assets in that bundle accessible via Web, and the current page will automatically
contain the references to the JavaScript and CSS files specified in that bundle.

24
extensions/jui/yii/jui/CoreAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\jui;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CoreAsset extends AssetBundle
{
public $sourcePath = '@yii/jui/assets';
public $js = array(
'jquery.ui.core.js',
);
public $depends = array(
'yii\web\JqueryAsset',
);
}

24
extensions/jui/yii/jui/WidgetAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\jui;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class WidgetAsset extends AssetBundle
{
public $sourcePath = '@yii/jui/assets';
public $js = array(
'jquery.ui.widget.js',
);
public $depends = array(
'yii\web\JqueryAsset',
);
}

16
extensions/jui/yii/jui/assets.php

@ -1,20 +1,8 @@
<?php
return array(
'yii/jui/core' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'jquery.ui.core.js',
),
'depends' => array('yii/jquery'),
),
'yii/jui/widget' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'jquery.ui.widget.js',
),
'depends' => array('yii/jquery'),
),
yii\jui\CoreAsset::className(),
yii\jui\WidgetAsset::className(),
'yii/jui/accordion' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(

9
framework/yii/YiiBase.php

@ -69,7 +69,7 @@ class YiiBase
* @see getAlias
* @see setAlias
*/
public static $aliases;
public static $aliases = array('@yii' => __DIR__);
/**
* @var array initial property values that will be applied to objects newly created via [[createObject]].
* The array keys are class names without leading backslashes "\", and the array values are the corresponding
@ -616,10 +616,3 @@ class YiiBase
return get_object_vars($object);
}
}
YiiBase::$aliases = array(
'@yii' => array(
'@yii/bootstrap' => __DIR__ . '/bootstrap',
'@yii' => __DIR__,
),
);

64
framework/yii/assets.php

@ -1,61 +1,11 @@
<?php
return array(
'yii' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'yii.js',
),
'depends' => array('yii/jquery'),
),
'yii/jquery' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
YII_DEBUG ? 'jquery.js' : 'jquery.min.js',
),
),
'yii/validation' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'yii.validation.js',
),
'depends' => array('yii'),
),
'yii/form' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'yii.activeForm.js',
),
'depends' => array('yii'),
),
'yii/captcha' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'yii.captcha.js',
),
'depends' => array('yii'),
),
'yii/punycode' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
YII_DEBUG ? 'punycode/punycode.js' : 'punycode/punycode.min.js',
),
),
'yii/maskedinput' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'jquery.maskedinput.js',
),
'depends' => array('yii/jquery'),
),
'yii/debug' => array(
'sourcePath' => __DIR__ . '/debug/assets',
'css' => array(
'main.css',
),
'depends' => array(
'yii',
'yii/bootstrap/responsive',
),
),
yii\web\YiiAsset::className(),
yii\web\JqueryAsset::className(),
yii\validators\PunycodeAsset::className(),
yii\validators\ValidationAsset::className(),
yii\widgets\ActiveFormAsset::className(),
yii\widgets\CaptchaAsset::className(),
yii\widgets\MaskedInputAsset::className(),
);

24
framework/yii/base/View.php

@ -10,6 +10,8 @@ namespace yii\base;
use Yii;
use yii\helpers\FileHelper;
use yii\helpers\Html;
use yii\web\JqueryAsset;
use yii\web\AssetBundle;
use yii\widgets\Block;
use yii\widgets\ContentDecorator;
use yii\widgets\FragmentCache;
@ -72,15 +74,15 @@ class View extends Component
/**
* This is internally used as the placeholder for receiving the content registered for the head section.
*/
const PL_HEAD = '<![CDATA[YII-BLOCK-HEAD]]>';
const PH_HEAD = '<![CDATA[YII-BLOCK-HEAD]]>';
/**
* This is internally used as the placeholder for receiving the content registered for the beginning of the body section.
*/
const PL_BODY_BEGIN = '<![CDATA[YII-BLOCK-BODY-BEGIN]]>';
const PH_BODY_BEGIN = '<![CDATA[YII-BLOCK-BODY-BEGIN]]>';
/**
* This is internally used as the placeholder for receiving the content registered for the end of the body section.
*/
const PL_BODY_END = '<![CDATA[YII-BLOCK-BODY-END]]>';
const PH_BODY_END = '<![CDATA[YII-BLOCK-BODY-END]]>';
/**
@ -519,9 +521,9 @@ class View extends Component
$content = ob_get_clean();
echo strtr($content, array(
self::PL_HEAD => $this->renderHeadHtml(),
self::PL_BODY_BEGIN => $this->renderBodyBeginHtml(),
self::PL_BODY_END => $this->renderBodyEndHtml(),
self::PH_HEAD => $this->renderHeadHtml(),
self::PH_BODY_BEGIN => $this->renderBodyBeginHtml(),
self::PH_BODY_END => $this->renderBodyEndHtml(),
));
unset(
@ -540,7 +542,7 @@ class View extends Component
*/
public function beginBody()
{
echo self::PL_BODY_BEGIN;
echo self::PH_BODY_BEGIN;
$this->trigger(self::EVENT_BEGIN_BODY);
}
@ -550,7 +552,7 @@ class View extends Component
public function endBody()
{
$this->trigger(self::EVENT_END_BODY);
echo self::PL_BODY_END;
echo self::PH_BODY_END;
}
/**
@ -558,13 +560,14 @@ class View extends Component
*/
public function head()
{
echo self::PL_HEAD;
echo self::PH_HEAD;
}
/**
* Registers the named asset bundle.
* All dependent asset bundles will be registered.
* @param string $name the name of the asset bundle.
* @return AssetBundle the registered asset bundle instance
* @throws InvalidConfigException if the asset bundle does not exist or a circular dependency is detected
*/
public function registerAssetBundle($name)
@ -582,6 +585,7 @@ class View extends Component
} elseif ($this->assetBundles[$name] === false) {
throw new InvalidConfigException("A circular dependency is detected for bundle '$name'.");
}
return $this->assetBundles[$name];
}
/**
@ -665,7 +669,7 @@ class View extends Component
$key = $key ?: md5($js);
$this->js[$position][$key] = $js;
if ($position === self::POS_READY) {
$this->registerAssetBundle('yii/jquery');
JqueryAsset::register($this);
}
}

26
framework/yii/bootstrap/AffixAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AffixAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-affix.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/AlertAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class AlertAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-alert.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

21
framework/yii/bootstrap/BootstrapAsset.php

@ -0,0 +1,21 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class BootstrapAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $css = array(
'css/bootstrap.css',
);
}

26
framework/yii/bootstrap/ButtonAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ButtonAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-button.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/CarouselAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CarouselAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-carousel.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/CollapseAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CollapseAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-collapse.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/DropdownAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class DropdownAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-dropdown.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/ModalAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ModalAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-modal.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

2
framework/yii/bootstrap/Nav.php

@ -88,7 +88,7 @@ class Nav extends Widget
public function run()
{
echo $this->renderItems();
$this->getView()->registerAssetBundle('yii/bootstrap');
BootstrapAsset::register($this->getView());
}
/**

8
framework/yii/bootstrap/NavBar.php

@ -119,7 +119,11 @@ class NavBar extends Widget
echo Html::beginTag('div', $this->options);
echo $this->renderItems();
echo Html::endTag('div');
$this->getView()->registerAssetBundle(self::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap');
if (self::$responsive) {
ResponsiveAsset::register($this->getView());
} else {
BootstrapAsset::register($this->getView());
}
}
/**
@ -136,7 +140,7 @@ class NavBar extends Widget
$brand = Html::a($this->brandLabel, $this->brandUrl, $this->brandOptions);
if (self::$responsive) {
$this->getView()->registerAssetBundle('yii/bootstrap/collapse');
CollapseAsset::register($this->getView());
$contents = Html::tag('div',
$this->renderToggleButton() .
$brand . "\n" .

24
framework/yii/bootstrap/PopoverAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class PopoverAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-popover.js',
);
public $depends = array(
'yii\bootstrap\TooltipAsset',
);
}

6
framework/yii/bootstrap/Progress.php

@ -105,7 +105,11 @@ class Progress extends Widget
echo Html::beginTag('div', $this->options) . "\n";
echo $this->renderProgress() . "\n";
echo Html::endTag('div') . "\n";
$this->getView()->registerAssetBundle(static::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap');
if (self::$responsive) {
ResponsiveAsset::register($this->getView());
} else {
BootstrapAsset::register($this->getView());
}
}
/**

24
framework/yii/bootstrap/ResponsiveAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ResponsiveAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $css = array(
'css/bootstrap-responsive.css',
);
public $depends = array(
'yii\bootstrap\BootstrapAsset',
);
}

26
framework/yii/bootstrap/ScrollspyAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ScrollspyAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-scrollspy.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/TabAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class TabAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-tab.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

26
framework/yii/bootstrap/TooltipAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class TooltipAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-tooltip.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

25
framework/yii/bootstrap/TransitionAsset.php

@ -0,0 +1,25 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class TransitionAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-transition.js',
);
public $depends = array(
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

4
framework/yii/bootstrap/TypeAhead.php → framework/yii/bootstrap/Typeahead.php

@ -13,7 +13,7 @@ use yii\base\Model;
use yii\helpers\Html;
/**
* TypeAhead renders a typehead bootstrap javascript component.
* Typeahead renders a typehead bootstrap javascript component.
*
* For example,
*
@ -42,7 +42,7 @@ use yii\helpers\Html;
* @author Antonio Ramirez <amigo.cobos@gmail.com>
* @since 2.0
*/
class TypeAhead extends Widget
class Typeahead extends Widget
{
/**
* @var \yii\base\Model the data model that this widget is associated with

26
framework/yii/bootstrap/TypeaheadAsset.php

@ -0,0 +1,26 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\bootstrap;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class TypeaheadAsset extends AssetBundle
{
public $sourcePath = '@yii/bootstrap/assets';
public $js = array(
'js/bootstrap-typeahead.js',
);
public $depends = array(
'yii\bootstrap\TransitionAsset',
'yii\bootstrap\BootstrapAsset',
'yii\web\JqueryAsset',
);
}

10
framework/yii/bootstrap/Widget.php

@ -65,8 +65,14 @@ class Widget extends \yii\base\Widget
{
$id = $this->options['id'];
$view = $this->getView();
$view->registerAssetBundle(static::$responsive ? 'yii/bootstrap/responsive' : 'yii/bootstrap');
$view->registerAssetBundle("yii/bootstrap/$name");
if (self::$responsive) {
ResponsiveAsset::register($view);
} else {
BootstrapAsset::register($view);
}
/** @var \yii\web\AssetBundle $assetClass */
$assetClass = 'yii\bootstrap\\' . ucfirst($name);
$assetClass::register($view);
if ($this->clientOptions !== false) {
$options = empty($this->clientOptions) ? '' : Json::encode($this->clientOptions);

119
framework/yii/bootstrap/assets.php

@ -6,108 +6,19 @@
*/
return array(
'yii/bootstrap' => array(
'sourcePath' => __DIR__ . '/assets',
'css' => array(
YII_DEBUG ? 'css/bootstrap.css' : 'css/bootstrap.min.css',
),
),
'yii/bootstrap/responsive' => array(
'sourcePath' => __DIR__ . '/assets',
'css' => array(
YII_DEBUG ? 'css/bootstrap-responsive.css' : 'css/bootstrap-responsive.min.css',
),
'depends' => array('yii/bootstrap'),
),
'yii/bootstrap/affix' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-affix.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/alert' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-alert.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/button' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-button.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/carousel' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-carousel.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/collapse' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-collapse.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/dropdown' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-dropdown.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/modal' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-modal.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/popover' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-popover.js',
),
'depends' => array('yii/bootstrap/tooltip'),
),
'yii/bootstrap/scrollspy' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-scrollspy.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/tab' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-tab.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/tooltip' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-tooltip.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
'yii/bootstrap/transition' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-transition.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap'),
),
'yii/bootstrap/typeahead' => array(
'sourcePath' => __DIR__ . '/assets',
'js' => array(
'js/bootstrap-typeahead.js',
),
'depends' => array('yii/jquery', 'yii/bootstrap', 'yii/bootstrap/transition'),
),
yii\bootstrap\BootstrapAsset::className(),
yii\bootstrap\ResponsiveAsset::className(),
yii\bootstrap\DropdownAsset::className(),
yii\bootstrap\TransitionAsset::className(),
yii\bootstrap\AffixAsset::className(),
yii\bootstrap\AlertAsset::className(),
yii\bootstrap\ButtonAsset::className(),
yii\bootstrap\CarouselAsset::className(),
yii\bootstrap\CollapseAsset::className(),
yii\bootstrap\ModalAsset::className(),
yii\bootstrap\PopoverAsset::className(),
yii\bootstrap\TooltipAsset::className(),
yii\bootstrap\ScrollspyAsset::className(),
yii\bootstrap\TabAsset::className(),
yii\bootstrap\TypeaheadAsset::className(),
);

25
framework/yii/debug/DebugAsset.php

@ -0,0 +1,25 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\debug;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class DebugAsset extends AssetBundle
{
public $sourcePath = '@yii/debug/assets';
public $css = array(
'main.css',
);
public $depends = array(
'yii\web\YiiAsset',
'yii\bootstrap\ResponsiveAsset',
);
}

1
framework/yii/debug/views/default/index.php

@ -7,7 +7,6 @@ use yii\helpers\Html;
* @var array $manifest
*/
$this->registerAssetBundle('yii/bootstrap/dropdown');
$this->title = 'Yii Debugger';
?>
<div class="default-index">

2
framework/yii/debug/views/default/view.php

@ -11,8 +11,8 @@ use yii\helpers\Html;
* @var \yii\debug\Panel $activePanel
*/
$this->registerAssetBundle('yii/bootstrap/dropdown');
$this->title = 'Yii Debugger';
yii\bootstrap\DropdownAsset::register($this);
?>
<div class="default-view">
<div class="navbar">

2
framework/yii/debug/views/layouts/main.php

@ -5,7 +5,7 @@
*/
use yii\helpers\Html;
Yii::$app->getView()->registerAssetBundle('yii/debug');
yii\debug\DebugAsset::register($this);
?>
<!DOCTYPE html>
<html>

2
framework/yii/validators/BooleanValidator.php

@ -102,7 +102,7 @@ class BooleanValidator extends Validator
$options['strict'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.boolean(value, messages, ' . json_encode($options) . ');';
}
}

2
framework/yii/validators/CaptchaValidator.php

@ -116,7 +116,7 @@ class CaptchaValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.captcha(value, messages, ' . json_encode($options) . ');';
}
}

2
framework/yii/validators/CompareValidator.php

@ -205,7 +205,7 @@ class CompareValidator extends Validator
'{compareValue}' => $compareValue,
)));
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.compare(value, messages, ' . json_encode($options) . ');';
}
}

4
framework/yii/validators/EmailValidator.php

@ -139,9 +139,9 @@ class EmailValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
if ($this->enableIDN) {
$view->registerAssetBundle('yii/punycode');
PunycodeAsset::register($view);
}
return 'yii.validation.email(value, messages, ' . Json::encode($options) . ');';
}

2
framework/yii/validators/NumberValidator.php

@ -151,7 +151,7 @@ class NumberValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.number(value, messages, ' . Json::encode($options) . ');';
}
}

21
framework/yii/validators/PunycodeAsset.php

@ -0,0 +1,21 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\validators;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class PunycodeAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'punycode/punycode.js',
);
}

2
framework/yii/validators/RangeValidator.php

@ -103,7 +103,7 @@ class RangeValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.range(value, messages, ' . json_encode($options) . ');';
}
}

2
framework/yii/validators/RegularExpressionValidator.php

@ -112,7 +112,7 @@ class RegularExpressionValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.regularExpression(value, messages, ' . Json::encode($options) . ');';
}
}

2
framework/yii/validators/RequiredValidator.php

@ -126,7 +126,7 @@ class RequiredValidator extends Validator
'{value}' => $object->$attribute,
)));
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.required(value, messages, ' . json_encode($options) . ');';
}
}

2
framework/yii/validators/StringValidator.php

@ -170,7 +170,7 @@ class StringValidator extends Validator
$options['skipOnEmpty'] = 1;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
return 'yii.validation.string(value, messages, ' . json_encode($options) . ');';
}
}

4
framework/yii/validators/UrlValidator.php

@ -143,9 +143,9 @@ class UrlValidator extends Validator
$options['defaultScheme'] = $this->defaultScheme;
}
$view->registerAssetBundle('yii/validation');
ValidationAsset::register($view);
if ($this->enableIDN) {
$view->registerAssetBundle('yii/punycode');
PunycodeAsset::register($view);
}
return 'yii.validation.url(value, messages, ' . Json::encode($options) . ');';
}

24
framework/yii/validators/ValidationAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\validators;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ValidationAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'yii.validation.js',
);
public $depends = array(
'yii\web\YiiAsset',
);
}

12
framework/yii/web/AssetBundle.php

@ -10,6 +10,7 @@ namespace yii\web;
use Yii;
use yii\base\InvalidConfigException;
use yii\base\Object;
use yii\base\View;
/**
* AssetBundle represents a collection of asset files, such as CSS, JS, images.
@ -102,6 +103,15 @@ class AssetBundle extends Object
public $publishOptions = array();
/**
* @param View $view
* @return AssetBundle the registered asset bundle instance
*/
public static function register($view)
{
return $view->registerAssetBundle(get_called_class());
}
/**
* Initializes the bundle.
*/
public function init()
@ -150,7 +160,7 @@ class AssetBundle extends Object
*/
public function publish($am)
{
if ($this->sourcePath !== null) {
if ($this->sourcePath !== null && !isset($this->basePath, $this->baseUrl)) {
list ($this->basePath, $this->baseUrl) = $am->publish($this->sourcePath, $this->publishOptions);
}
$converter = $am->getConverter();

63
framework/yii/web/AssetManager.php

@ -22,10 +22,11 @@ use yii\helpers\FileHelper;
class AssetManager extends Component
{
/**
* @var array list of available asset bundles. The keys are the bundle names, and the values are the configuration
* arrays for creating the [[AssetBundle]] objects.
* @var array list of available asset bundles. The keys are the class names of the asset bundles,
* and the values are either the configuration arrays for creating the [[AssetBundle]] objects
* or the corresponding asset bundle instances.
*/
public $bundles;
public $bundles = array();
/**
* @return string the root directory storing the published asset files.
*/
@ -81,55 +82,29 @@ class AssetManager extends Component
$this->basePath = realpath($this->basePath);
}
$this->baseUrl = rtrim(Yii::getAlias($this->baseUrl), '/');
foreach (require(YII_PATH . '/assets.php') as $name => $bundle) {
if (!isset($this->bundles[$name])) {
$this->bundles[$name] = $bundle;
}
}
}
/**
* Returns the named bundle.
* This method will first look for the bundle in [[bundles]]. If not found,
* it will attempt to find the bundle from an installed extension using the following procedure:
*
* 1. Convert the bundle into a path alias;
* 2. Determine the root alias and use it to locate the bundle manifest file "assets.php";
* 3. Look for the bundle in the manifest file.
* Returns the named asset bundle.
*
* For example, given the bundle name "foo/button", the method will first convert it
* into the path alias "@foo/button"; since "@foo" is the root alias, it will look
* for the bundle manifest file "@foo/assets.php". The manifest file should return an array
* that lists the bundles used by the "foo/button" extension. The array format is the same as [[bundles]].
* This method will first look for the bundle in [[bundles]]. If not found,
* it will treat `$name` as the class of the asset bundle and create a new instance of it.
*
* @param string $name the bundle name
* @return AssetBundle the loaded bundle object. Null is returned if the bundle does not exist.
* @param string $name the class name of the asset bundle
* @return AssetBundle the asset bundle instance
* @throws InvalidConfigException if $name does not refer to a valid asset bundle
*/
public function getBundle($name)
{
if (!isset($this->bundles[$name])) {
$rootAlias = Yii::getRootAlias("@$name");
if ($rootAlias !== false) {
$manifest = Yii::getAlias("$rootAlias/assets.php", false);
if ($manifest !== false && is_file($manifest)) {
foreach (require($manifest) as $bn => $config) {
$this->bundles[$bn] = $config;
}
}
}
if (!isset($this->bundles[$name])) {
return null;
}
}
if (is_array($this->bundles[$name])) {
$config = $this->bundles[$name];
if (!isset($config['class'])) {
$config['class'] = 'yii\\web\\AssetBundle';
if (isset($this->bundles[$name])) {
if (is_array($this->bundles[$name])) {
$this->bundles[$name] = Yii::createObject(array_merge(array('class' => $name), $this->bundles[$name]));
} elseif (!$this->bundles[$name] instanceof AssetBundle) {
throw new InvalidConfigException("Invalid asset bundle: $name");
}
$this->bundles[$name] = Yii::createObject($config);
} else {
$this->bundles[$name] = Yii::createObject($name);
}
return $this->bundles[$name];
}
@ -142,9 +117,7 @@ class AssetManager extends Component
public function getConverter()
{
if ($this->_converter === null) {
$this->_converter = Yii::createObject(array(
'class' => 'yii\\web\\AssetConverter',
));
$this->_converter = Yii::createObject(AssetConverter::className());
} elseif (is_array($this->_converter) || is_string($this->_converter)) {
$this->_converter = Yii::createObject($this->_converter);
}

20
framework/yii/web/JqueryAsset.php

@ -0,0 +1,20 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class JqueryAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'jquery.js',
);
}

23
framework/yii/web/YiiAsset.php

@ -0,0 +1,23 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\web;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class YiiAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'yii.js',
);
public $depends = array(
'yii\web\JqueryAsset',
);
}

5
framework/yii/widgets/ActiveForm.php

@ -167,8 +167,9 @@ class ActiveForm extends Widget
$id = $this->options['id'];
$options = Json::encode($this->getClientOptions());
$attributes = Json::encode($this->attributes);
$this->getView()->registerAssetBundle('yii/form');
$this->getView()->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
$view = $this->getView();
ActiveFormAsset::register($view);
$view->registerJs("jQuery('#$id').yiiActiveForm($attributes, $options);");
}
echo Html::endForm();
}

24
framework/yii/widgets/ActiveFormAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class ActiveFormAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'yii.activeForm.js',
);
public $depends = array(
'yii\web\YiiAsset',
);
}

5
framework/yii/widgets/Captcha.php

@ -97,8 +97,9 @@ class Captcha extends InputWidget
$options = $this->getClientOptions();
$options = empty($options) ? '' : Json::encode($options);
$id = $this->imageOptions['id'];
$this->getView()->registerAssetBundle('yii/captcha');
$this->getView()->registerJs("jQuery('#$id').yiiCaptcha($options);");
$view = $this->getView();
CaptchaAsset::register($view);
$view->registerJs("jQuery('#$id').yiiCaptcha($options);");
}
/**

24
framework/yii/widgets/CaptchaAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class CaptchaAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'yii.captcha.js',
);
public $depends = array(
'yii\web\YiiAsset',
);
}

5
framework/yii/widgets/MaskedInput.php

@ -109,8 +109,9 @@ class MaskedInput extends InputWidget
}
$id = $this->options['id'];
$js .= "jQuery(\"#{$id}\").mask(\"{$this->mask}\"{$options});";
$this->getView()->registerAssetBundle('yii/maskedinput');
$this->getView()->registerJs($js);
$view = $this->getView();
MaskedInputAsset::register($view);
$view->registerJs($js);
}
/**

24
framework/yii/widgets/MaskedInputAsset.php

@ -0,0 +1,24 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace yii\widgets;
use yii\web\AssetBundle;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class MaskedInputAsset extends AssetBundle
{
public $sourcePath = '@yii/assets';
public $js = array(
'jquery.maskedinput.js',
);
public $depends = array(
'yii\web\YiiAsset',
);
}
Loading…
Cancel
Save