Jquery.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category ZendX
  16. * @package ZendX_Application
  17. * @subpackage Resource
  18. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Jquery.php 20240 2010-01-13 04:51:56Z matthew $
  21. */
  22. /**
  23. * JQuery application resource
  24. *
  25. * Example configuration:
  26. * <pre>
  27. * resources.Jquery.noconflictmode = false ; default
  28. * resources.Jquery.version = 1.7.1 ; <null>
  29. * resources.Jquery.localpath = "/foo/bar"
  30. * resources.Jquery.enable = true
  31. * resources.Jquery.uienable = true;
  32. * resources.Jquery.ui_enable = true;
  33. * resources.Jquery.uiversion = 0.7.7;
  34. * resources.Jquery.ui_version = 0.7.7;
  35. * resources.Jquery.uilocalpath = "/bar/foo";
  36. * resources.Jquery.ui_localpath = "/bar/foo";
  37. * resources.Jquery.cdn_ssl = false
  38. * resources.Jquery.render_mode = 255 ; default
  39. * resources.Jquery.rendermode = 255 ; default
  40. *
  41. * resources.Jquery.javascriptfile = "/some/file.js"
  42. * resources.Jquery.javascriptfiles.0 = "/some/file.js"
  43. * resources.Jquery.stylesheet = "/some/file.css"
  44. * resources.Jquery.stylesheets.0 = "/some/file.css"
  45. * </pre>
  46. *
  47. * Resource for settings JQuery options
  48. *
  49. * @uses Zend_Application_Resource_ResourceAbstract
  50. * @category ZendX
  51. * @package ZendX_Application
  52. * @subpackage Resource
  53. * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
  54. * @license http://framework.zend.com/license/new-bsd New BSD License
  55. */
  56. class ZendX_Application_Resource_Jquery
  57. extends Zend_Application_Resource_ResourceAbstract
  58. {
  59. /**
  60. * @var ZendX_JQuery_View_Helper_JQuery_Container
  61. */
  62. protected $_jquery;
  63. /**
  64. * @var Zend_View
  65. */
  66. protected $_view;
  67. /**
  68. * Defined by Zend_Application_Resource_Resource
  69. *
  70. * @return ZendX_JQuery_View_Helper_JQuery_Container
  71. */
  72. public function init()
  73. {
  74. return $this->getJquery();
  75. }
  76. /**
  77. * Retrieve JQuery View Helper
  78. *
  79. * @return ZendX_JQuery_View_Helper_JQuery_Container
  80. */
  81. public function getJquery()
  82. {
  83. if (null === $this->_jquery) {
  84. $this->getBootstrap()->bootstrap('view');
  85. $this->_view = $this->getBootstrap()->view;
  86. ZendX_JQuery::enableView($this->_view);
  87. $this->_parseOptions($this->getOptions());
  88. $this->_jquery = $this->_view->jQuery();
  89. }
  90. return $this->_jquery;
  91. }
  92. /**
  93. * Parse options to find those pertinent to jquery helper and invoke them
  94. *
  95. * @param array $options
  96. * @return void
  97. */
  98. protected function _parseOptions(array $options)
  99. {
  100. foreach ($options as $key => $value) {
  101. switch(strtolower($key)) {
  102. case 'noconflictmode':
  103. if (!(bool)$value) {
  104. ZendX_JQuery_View_Helper_JQuery::disableNoConflictMode();
  105. } else {
  106. ZendX_JQuery_View_Helper_JQuery::enableNoConflictMode();
  107. }
  108. break;
  109. case 'version':
  110. $this->_view->JQuery()->setVersion($value);
  111. break;
  112. case 'localpath':
  113. $this->_view->JQuery()->setLocalPath($value);
  114. break;
  115. case 'uiversion':
  116. case 'ui_version':
  117. $this->_view->JQuery()->setUiVersion($value);
  118. break;
  119. case 'uilocalpath':
  120. case 'ui_localpath':
  121. $this->_view->JQuery()->setUiLocalPath($value);
  122. break;
  123. case 'cdn_ssl':
  124. $this->_view->JQuery()->setCdnSsl($value);
  125. break;
  126. case 'render_mode':
  127. case 'rendermode':
  128. $this->_view->JQuery()->setRenderMode($value);
  129. break;
  130. case 'javascriptfile':
  131. $this->_view->JQuery()->addJavascriptFile($value);
  132. break;
  133. case 'javascriptfiles':
  134. foreach($options['javascriptfiles'] as $file) {
  135. $this->_view->JQuery()->addJavascriptFile($file);
  136. }
  137. break;
  138. case 'stylesheet':
  139. $this->_view->JQuery()->addStylesheet($value);
  140. break;
  141. case 'stylesheets':
  142. foreach ($value as $stylesheet) {
  143. $this->_view->JQuery()->addStylesheet($stylesheet);
  144. }
  145. break;
  146. }
  147. }
  148. if ((isset($options['uienable']) && (bool) $options['uienable'])
  149. || (isset($options['ui_enable']) && (bool) $options['ui_enable'])
  150. || (!isset($options['ui_enable']) && !isset($options['uienable'])))
  151. {
  152. $this->_view->JQuery()->uiEnable();
  153. } else {
  154. $this->_view->JQuery()->uiDisable();
  155. }
  156. if ((isset($options['enable']) && (bool) $options['enable'])
  157. || !isset($options['enable']))
  158. {
  159. $this->_view->JQuery()->enable();
  160. } else {
  161. $this->_view->JQuery()->disable();
  162. }
  163. }
  164. }