Plugin.php 859 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 16/7/4
  6. * Time: 下午1:46
  7. */
  8. namespace plugins\prettify;
  9. use yii\base\BootstrapInterface;
  10. use yii\web\View;
  11. use yii\base\Event;
  12. class Plugin extends \plugins\Plugin implements BootstrapInterface
  13. {
  14. public $info = [
  15. 'author' => 'nodelog',
  16. 'version' => 'v1.0',
  17. 'id' => 'prettify',
  18. 'name' => '代码高亮',
  19. 'description' => '代码高亮模块'
  20. ];
  21. public function bootstrap($app)
  22. {
  23. Event::on(View::className(), 'afterComment', [$this, 'run']);
  24. Event::on(View::className(), 'afterArticleView', [$this, 'run']);
  25. }
  26. public function run()
  27. {
  28. PrettifyAsset::register($this->view);
  29. $script = "$('pre').addClass('prettyprint linenums');prettyPrint();";
  30. $this->view->registerJs($script);
  31. }
  32. }