PageRenderTime 52ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/common/lib/Yii/zii/widgets/jui/CJuiWidget.php

https://bitbucket.org/haichau59/manga
PHP | 145 lines | 51 code | 6 blank | 88 comment | 10 complexity | 6a7774bb50ba5db4081c362ecbf3feea MD5 | raw file
  1. <?php
  2. /**
  3. * CJuiWidget class file.
  4. *
  5. * @author Sebastian Thierer <sebathi@gmail.com>
  6. * @author Qiang Xue <qiang.xue@gmail.com>
  7. * @link http://www.yiiframework.com/
  8. * @copyright Copyright &copy; 2008-2011 Yii Software LLC
  9. * @license http://www.yiiframework.com/license/
  10. */
  11. /**
  12. * This is the base class for all JUI widget classes.
  13. *
  14. * @author Sebastian Thierer <sebathi@gmail.com>
  15. * @author Qiang Xue <qiang.xue@gmail.com>
  16. * @version $Id$
  17. * @package zii.widgets.jui
  18. * @since 1.1
  19. */
  20. abstract class CJuiWidget extends CWidget
  21. {
  22. /**
  23. * @var string the root URL that contains all JUI JavaScript files.
  24. * If this property is not set (default), Yii will publish the JUI package included in the zii release and use
  25. * that to infer the root script URL. You should set this property if you intend to use
  26. * a JUI package whose version is different from the one included in zii.
  27. * Note that under this URL, there must be a file whose name is specified by {@link scriptFile}.
  28. * Do not append any slash character to the URL.
  29. */
  30. public $scriptUrl;
  31. /**
  32. * @var string the root URL that contains all JUI theme folders.
  33. * If this property is not set (default), Yii will publish the JUI package included in the zii release and use
  34. * that to infer the root theme URL. You should set this property if you intend to use
  35. * a theme that is not found in the JUI package included in zii.
  36. * Note that under this URL, there must be a directory whose name is specified by {@link theme}.
  37. * Do not append any slash character to the URL.
  38. */
  39. public $themeUrl;
  40. /**
  41. * @var string the JUI theme name. Defaults to 'base'. Make sure that under {@link themeUrl} there
  42. * is a directory whose name is the same as this property value (case-sensitive).
  43. */
  44. public $theme='base';
  45. /**
  46. * @var mixed the main JUI JavaScript file. Defaults to 'jquery-ui.min.js'.
  47. * Note the file must exist under the URL specified by {@link scriptUrl}.
  48. * If you need to include multiple script files (e.g. during development, you want to include individual
  49. * plugin script files rather than the minized JUI script file), you may set this property
  50. * as an array of the script file names.
  51. * This property can also be set as false, which means the widget will not include any script file,
  52. * and it is your responsibility to explicitly include it somewhere else.
  53. */
  54. public $scriptFile='jquery-ui.min.js';
  55. /**
  56. * @var mixed the theme CSS file name. Defaults to 'jquery-ui.css'.
  57. * Note the file must exist under the URL specified by {@link themeUrl}/{@link theme}.
  58. * If you need to include multiple theme CSS files (e.g. during development, you want to include individual
  59. * plugin CSS files), you may set this property as an array of the CSS file names.
  60. * This property can also be set as false, which means the widget will not include any theme CSS file,
  61. * and it is your responsibility to explicitly include it somewhere else.
  62. */
  63. public $cssFile='jquery-ui.css';
  64. /**
  65. * @var array the initial JavaScript options that should be passed to the JUI plugin.
  66. */
  67. public $options=array();
  68. /**
  69. * @var array the HTML attributes that should be rendered in the HTML tag representing the JUI widget.
  70. */
  71. public $htmlOptions=array();
  72. /**
  73. * Initializes the widget.
  74. * This method will publish JUI assets if necessary.
  75. * It will also register jquery and JUI JavaScript files and the theme CSS file.
  76. * If you override this method, make sure you call the parent implementation first.
  77. */
  78. public function init()
  79. {
  80. $this->resolvePackagePath();
  81. $this->registerCoreScripts();
  82. parent::init();
  83. }
  84. /**
  85. * Determine the JUI package installation path.
  86. * This method will identify the JavaScript root URL and theme root URL.
  87. * If they are not explicitly specified, it will publish the included JUI package
  88. * and use that to resolve the needed paths.
  89. */
  90. protected function resolvePackagePath()
  91. {
  92. if($this->scriptUrl===null || $this->themeUrl===null)
  93. {
  94. $cs=Yii::app()->getClientScript();
  95. if($this->scriptUrl===null)
  96. $this->scriptUrl=$cs->getCoreScriptUrl().'/jui/js';
  97. if($this->themeUrl===null)
  98. $this->themeUrl=$cs->getCoreScriptUrl().'/jui/css';
  99. }
  100. }
  101. /**
  102. * Registers the core script files.
  103. * This method registers jquery and JUI JavaScript files and the theme CSS file.
  104. */
  105. protected function registerCoreScripts()
  106. {
  107. $cs=Yii::app()->getClientScript();
  108. if(is_string($this->cssFile))
  109. $cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$this->cssFile);
  110. else if(is_array($this->cssFile))
  111. {
  112. foreach($this->cssFile as $cssFile)
  113. $cs->registerCssFile($this->themeUrl.'/'.$this->theme.'/'.$cssFile);
  114. }
  115. $cs->registerCoreScript('jquery');
  116. if(is_string($this->scriptFile))
  117. $this->registerScriptFile($this->scriptFile);
  118. else if(is_array($this->scriptFile))
  119. {
  120. foreach($this->scriptFile as $scriptFile)
  121. $this->registerScriptFile($scriptFile);
  122. }
  123. }
  124. /**
  125. * Registers a JavaScript file under {@link scriptUrl}.
  126. * Note that by default, the script file will be rendered at the end of a page to improve page loading speed.
  127. * @param string $fileName JavaScript file name
  128. * @param integer $position the position of the JavaScript file. Valid values include the following:
  129. * <ul>
  130. * <li>CClientScript::POS_HEAD : the script is inserted in the head section right before the title element.</li>
  131. * <li>CClientScript::POS_BEGIN : the script is inserted at the beginning of the body section.</li>
  132. * <li>CClientScript::POS_END : the script is inserted at the end of the body section.</li>
  133. * </ul>
  134. */
  135. protected function registerScriptFile($fileName,$position=CClientScript::POS_END)
  136. {
  137. Yii::app()->getClientScript()->registerScriptFile($this->scriptUrl.'/'.$fileName,$position);
  138. }
  139. }