00001 <?php 00056 class ZendX_Application_Resource_Jquery 00057 extends Zend_Application_Resource_ResourceAbstract 00058 { 00062 protected $_jquery; 00063 00067 protected $_view; 00068 00074 public function init() 00075 { 00076 return $this->getJquery(); 00077 } 00078 00084 public function getJquery() 00085 { 00086 if (null === $this->_jquery) { 00087 $this->getBootstrap()->bootstrap('view'); 00088 $this->_view = $this->getBootstrap()->view; 00089 00090 ZendX_JQuery::enableView($this->_view); 00091 $this->_parseOptions($this->getOptions()); 00092 00093 $this->_jquery = $this->_view->jQuery(); 00094 } 00095 00096 return $this->_jquery; 00097 } 00098 00105 protected function _parseOptions(array $options) 00106 { 00107 $options = array_merge($options, array('cdn_ssl' => false)); 00108 00109 foreach ($options as $key => $value) { 00110 switch(strtolower($key)) { 00111 case 'noconflictmode': 00112 if (!(bool)$value) { 00113 ZendX_JQuery_View_Helper_JQuery::disableNoConflictMode(); 00114 } else { 00115 ZendX_JQuery_View_Helper_JQuery::enableNoConflictMode(); 00116 } 00117 break; 00118 case 'version': 00119 $this->_view->JQuery()->setVersion($value); 00120 break; 00121 case 'localpath': 00122 $this->_view->JQuery()->setLocalPath($value); 00123 break; 00124 case 'uiversion': 00125 case 'ui_version': 00126 $this->_view->JQuery()->setUiVersion($value); 00127 break; 00128 case 'uilocalpath': 00129 case 'ui_localpath': 00130 $this->_view->JQuery()->setUiLocalPath($value); 00131 break; 00132 case 'cdn_ssl': 00133 $this->_view->JQuery()->setCdnSsl($value); 00134 break; 00135 case 'render_mode': 00136 case 'rendermode': 00137 $this->_view->JQuery()->setRenderMode($value); 00138 break; 00139 case 'javascriptfile': 00140 $this->_view->JQuery()->addJavascriptFile($value); 00141 break; 00142 case 'javascriptfiles': 00143 foreach($options['javascriptfiles'] as $file) { 00144 $this->_view->JQuery()->addJavascriptFile($file); 00145 } 00146 break; 00147 case 'stylesheet': 00148 $this->_view->JQuery()->addStylesheet($value); 00149 break; 00150 case 'stylesheets': 00151 foreach ($value as $stylesheet) { 00152 $this->_view->JQuery()->addStylesheet($stylesheet); 00153 } 00154 break; 00155 } 00156 } 00157 00158 if ((isset($options['uienable']) && (bool) $options['uienable']) 00159 || (isset($options['ui_enable']) && (bool) $options['ui_enable']) 00160 || (!isset($options['ui_enable']) && !isset($options['uienable']))) 00161 { 00162 $this->_view->JQuery()->uiEnable(); 00163 } else { 00164 $this->_view->JQuery()->uiDisable(); 00165 } 00166 } 00167 }