PageRenderTime 47ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/joomla/libraries/joomla/html/html/behavior.php

https://github.com/bhar1red/anahita
PHP | 402 lines | 290 code | 50 blank | 62 comment | 36 complexity | adbcac50fa84ba455bf94c283ae27071 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1
  1. <?php
  2. /**
  3. * @version $Id: behavior.php 14401 2010-01-26 14:10:00Z louis $
  4. * @package Joomla.Framework
  5. * @subpackage HTML
  6. * @copyright Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
  7. * @license GNU/GPL, see LICENSE.php
  8. * Joomla! is free software. This version may have been modified pursuant
  9. * to the GNU General Public License, and as distributed it includes or
  10. * is derivative of works licensed under the GNU General Public License or
  11. * other free or open source software licenses.
  12. * See COPYRIGHT.php for copyright notices and details.
  13. */
  14. defined('JPATH_BASE') or die();
  15. /**
  16. * Utility class for javascript behaviors
  17. *
  18. * @static
  19. * @package Joomla.Framework
  20. * @subpackage HTML
  21. * @version 1.5
  22. */
  23. class JHTMLBehavior
  24. {
  25. /**
  26. * Method to load the mootools framework into the document head
  27. *
  28. * - If debugging mode is on an uncompressed version of mootools is included for easier debugging.
  29. *
  30. * @static
  31. * @param boolean $debug Is debugging mode on? [optional]
  32. * @return void
  33. * @since 1.5
  34. */
  35. function mootools($debug = null)
  36. {
  37. static $loaded;
  38. // Only load once
  39. if ($loaded) {
  40. return;
  41. }
  42. // If no debugging value is set, use the configuration setting
  43. if ($debug === null) {
  44. $config = &JFactory::getConfig();
  45. $debug = $config->getValue('config.debug');
  46. }
  47. // TODO NOTE: Here we are checking for Konqueror - If they fix thier issue with compressed, we will need to update this
  48. $konkcheck = isset($_SERVER['HTTP_USER_AGENT']) ? strpos(strtolower($_SERVER['HTTP_USER_AGENT']), "konqueror") : null;
  49. if ( JFactory::getApplication()->isAdmin() ) {
  50. JHTML::script('lib_anahita/js/production/mootools.js', 'media/', false);
  51. }
  52. if ($debug || $konkcheck) {
  53. //JHTML::script('lib_anahita/js/vendors/mootools-core.js', 'media/', false);
  54. //JHTML::script('lib_anahita/js/vendors/mootools-more.js', 'media/', false);
  55. //JHTML::script('lib_anahita/js/vendors/clientcide.js', 'media/', false);
  56. //JHTML::script('lib_anahita/js/min/mootools.js', 'media/', false);
  57. } else {
  58. //JHTML::script('lib_anahita/js/min/mootools.js', 'media/', false);
  59. }
  60. $loaded = true;
  61. return;
  62. }
  63. function caption() {
  64. JHTML::script('caption.js');
  65. }
  66. function formvalidation() {
  67. JHTML::script('validate.js' );
  68. }
  69. function switcher() {
  70. JHTML::script('switcher.js' );
  71. }
  72. function combobox() {
  73. JHTML::script('combobox.js' );
  74. }
  75. function tooltip($selector='.hasTip', $params = array())
  76. {
  77. static $tips;
  78. if (!isset($tips)) {
  79. $tips = array();
  80. }
  81. // Include mootools framework
  82. JHTMLBehavior::mootools();
  83. $sig = md5(serialize(array($selector,$params)));
  84. if (isset($tips[$sig]) && ($tips[$sig])) {
  85. return;
  86. }
  87. // Setup options object
  88. $opt['maxTitleChars'] = (isset($params['maxTitleChars']) && ($params['maxTitleChars'])) ? (int)$params['maxTitleChars'] : 50 ;
  89. // offsets needs an array in the format: array('x'=>20, 'y'=>30)
  90. $opt['offsets'] = (isset($params['offsets']) && (is_array($params['offsets']))) ? $params['offsets'] : null;
  91. $opt['showDelay'] = (isset($params['showDelay'])) ? (int)$params['showDelay'] : null;
  92. $opt['hideDelay'] = (isset($params['hideDelay'])) ? (int)$params['hideDelay'] : null;
  93. $opt['className'] = (isset($params['className'])) ? $params['className'] : null;
  94. $opt['fixed'] = (isset($params['fixed']) && ($params['fixed'])) ? '\\true' : '\\false';
  95. $opt['onShow'] = (isset($params['onShow'])) ? '\\'.$params['onShow'] : null;
  96. $opt['onHide'] = (isset($params['onHide'])) ? '\\'.$params['onHide'] : null;
  97. $options = JHTMLBehavior::_getJSObject($opt);
  98. // Attach tooltips to document
  99. $document =& JFactory::getDocument();
  100. $tooltipInit = ' window.addEvent(\'domready\', function(){ var JTooltips = new Tips($$(\''.$selector.'\'), '.$options.'); });';
  101. $document->addScriptDeclaration($tooltipInit);
  102. // Set static array
  103. $tips[$sig] = true;
  104. return;
  105. }
  106. function modal($selector='a.modal', $params = array())
  107. {
  108. static $modals;
  109. static $included;
  110. $document =& JFactory::getDocument();
  111. // Load the necessary files if they haven't yet been loaded
  112. if (!isset($included)) {
  113. // Load the javascript and css
  114. JHTML::script('modal.js');
  115. JHTML::stylesheet('modal.css');
  116. $included = true;
  117. }
  118. if (!isset($modals)) {
  119. $modals = array();
  120. }
  121. $sig = md5(serialize(array($selector,$params)));
  122. if (isset($modals[$sig]) && ($modals[$sig])) {
  123. return;
  124. }
  125. // Setup options object
  126. $opt['ajaxOptions'] = (isset($params['ajaxOptions']) && (is_array($params['ajaxOptions']))) ? $params['ajaxOptions'] : null;
  127. $opt['size'] = (isset($params['size']) && (is_array($params['size']))) ? $params['size'] : null;
  128. $opt['onOpen'] = (isset($params['onOpen'])) ? $params['onOpen'] : null;
  129. $opt['onClose'] = (isset($params['onClose'])) ? $params['onClose'] : null;
  130. $opt['onUpdate'] = (isset($params['onUpdate'])) ? $params['onUpdate'] : null;
  131. $opt['onResize'] = (isset($params['onResize'])) ? $params['onResize'] : null;
  132. $opt['onMove'] = (isset($params['onMove'])) ? $params['onMove'] : null;
  133. $opt['onShow'] = (isset($params['onShow'])) ? $params['onShow'] : null;
  134. $opt['onHide'] = (isset($params['onHide'])) ? $params['onHide'] : null;
  135. $options = JHTMLBehavior::_getJSObject($opt);
  136. // Attach modal behavior to document
  137. $document->addScriptDeclaration("
  138. window.addEvent('domready', function() {
  139. SqueezeBox.initialize(".$options.");
  140. $$('".$selector."').each(function(el) {
  141. el.addEvent('click', function(e) {
  142. new Event(e).stop();
  143. SqueezeBox.fromElement(el);
  144. });
  145. });
  146. });");
  147. // Set static array
  148. $modals[$sig] = true;
  149. return;
  150. }
  151. function uploader($id='file-upload', $params = array())
  152. {
  153. JHTML::script('swf.js' );
  154. JHTML::script('uploader.js' );
  155. static $uploaders;
  156. if (!isset($uploaders)) {
  157. $uploaders = array();
  158. }
  159. if (isset($uploaders[$id]) && ($uploaders[$id])) {
  160. return;
  161. }
  162. // Setup options object
  163. $opt['url'] = (isset($params['targetURL'])) ? $params['targetURL'] : null ;
  164. $opt['swf'] = (isset($params['swf'])) ? $params['swf'] : JURI::root(true).'/media/system/swf/uploader.swf';
  165. $opt['multiple'] = (isset($params['multiple']) && !($params['multiple'])) ? '\\false' : '\\true';
  166. $opt['queued'] = (isset($params['queued']) && !($params['queued'])) ? '\\false' : '\\true';
  167. $opt['queueList'] = (isset($params['queueList'])) ? $params['queueList'] : 'upload-queue';
  168. $opt['instantStart'] = (isset($params['instantStart']) && ($params['instantStart'])) ? '\\true' : '\\false';
  169. $opt['allowDuplicates'] = (isset($params['allowDuplicates']) && !($params['allowDuplicates'])) ? '\\false' : '\\true';
  170. $opt['limitSize'] = (isset($params['limitSize']) && ($params['limitSize'])) ? (int)$params['limitSize'] : null;
  171. $opt['limitFiles'] = (isset($params['limitFiles']) && ($params['limitFiles'])) ? (int)$params['limitFiles'] : null;
  172. $opt['optionFxDuration'] = (isset($params['optionFxDuration'])) ? (int)$params['optionFxDuration'] : null;
  173. $opt['container'] = (isset($params['container'])) ? '\\$('.$params['container'].')' : '\\$(\''.$id.'\').getParent()';
  174. $opt['types'] = (isset($params['types'])) ?'\\'.$params['types'] : '\\{\'All Files (*.*)\': \'*.*\'}';
  175. // Optional functions
  176. $opt['createReplacement'] = (isset($params['createReplacement'])) ? '\\'.$params['createReplacement'] : null;
  177. $opt['onComplete'] = (isset($params['onComplete'])) ? '\\'.$params['onComplete'] : null;
  178. $opt['onAllComplete'] = (isset($params['onAllComplete'])) ? '\\'.$params['onAllComplete'] : null;
  179. /* types: Object with (description: extension) pairs, default: Images (*.jpg; *.jpeg; *.gif; *.png)
  180. */
  181. $options = JHTMLBehavior::_getJSObject($opt);
  182. // Attach tooltips to document
  183. $document =& JFactory::getDocument();
  184. $uploaderInit = 'sBrowseCaption=\''.JText::_('Browse Files', true).'\';
  185. sRemoveToolTip=\''.JText::_('Remove from queue', true).'\';
  186. window.addEvent(\'load\', function(){
  187. var Uploader = new FancyUpload($(\''.$id.'\'), '.$options.');
  188. $(\'upload-clear\').adopt(new Element(\'input\', { type: \'button\', events: { click: Uploader.clearList.bind(Uploader, [false])}, value: \''.JText::_('Clear Completed').'\' })); });';
  189. $document->addScriptDeclaration($uploaderInit);
  190. // Set static array
  191. $uploaders[$id] = true;
  192. return;
  193. }
  194. function tree($id, $params = array(), $root = array())
  195. {
  196. static $trees;
  197. if (!isset($trees)) {
  198. $trees = array();
  199. }
  200. // Include mootools framework
  201. JHTMLBehavior::mootools();
  202. JHTML::script('mootree.js');
  203. JHTML::stylesheet('mootree.css');
  204. if (isset($trees[$id]) && ($trees[$id])) {
  205. return;
  206. }
  207. // Setup options object
  208. $opt['div'] = (array_key_exists('div', $params)) ? $params['div'] : $id.'_tree';
  209. $opt['mode'] = (array_key_exists('mode', $params)) ? $params['mode'] : 'folders';
  210. $opt['grid'] = (array_key_exists('grid', $params)) ? '\\'.$params['grid'] : '\\true';
  211. $opt['theme'] = (array_key_exists('theme', $params)) ? $params['theme'] : JURI::root(true).'/media/system/images/mootree.gif';
  212. // Event handlers
  213. $opt['onExpand'] = (array_key_exists('onExpand', $params)) ? '\\'.$params['onExpand'] : null;
  214. $opt['onSelect'] = (array_key_exists('onSelect', $params)) ? '\\'.$params['onSelect'] : null;
  215. $opt['onClick'] = (array_key_exists('onClick', $params)) ? '\\'.$params['onClick'] : '\\function(node){ window.open(node.data.url, $chk(node.data.target) ? node.data.target : \'_self\'); }';
  216. $options = JHTMLBehavior::_getJSObject($opt);
  217. // Setup root node
  218. $rt['text'] = (array_key_exists('text', $root)) ? $root['text'] : 'Root';
  219. $rt['id'] = (array_key_exists('id', $root)) ? $root['id'] : null;
  220. $rt['color'] = (array_key_exists('color', $root)) ? $root['color'] : null;
  221. $rt['open'] = (array_key_exists('open', $root)) ? '\\'.$root['open'] : '\\true';
  222. $rt['icon'] = (array_key_exists('icon', $root)) ? $root['icon'] : null;
  223. $rt['openicon'] = (array_key_exists('openicon', $root)) ? $root['openicon'] : null;
  224. $rt['data'] = (array_key_exists('data', $root)) ? $root['data'] : null;
  225. $rootNode = JHTMLBehavior::_getJSObject($rt);
  226. $treeName = (array_key_exists('treeName', $params)) ? $params['treeName'] : '';
  227. $js = ' window.addEvent(\'domready\', function(){
  228. tree'.$treeName.' = new MooTreeControl('.$options.','.$rootNode.');
  229. tree'.$treeName.'.adopt(\''.$id.'\');})';
  230. // Attach tooltips to document
  231. $document =& JFactory::getDocument();
  232. $document->addScriptDeclaration($js);
  233. // Set static array
  234. $trees[$id] = true;
  235. return;
  236. }
  237. function calendar()
  238. {
  239. $document =& JFactory::getDocument();
  240. JHTML::stylesheet('calendar-jos.css', 'media/system/css/', array(' title' => JText::_( 'green' ) ,' media' => 'all' ));
  241. JHTML::script( 'calendar.js', 'media/system/js/' );
  242. JHTML::script( 'calendar-setup.js', 'media/system/js/' );
  243. $translation = JHTMLBehavior::_calendartranslation();
  244. if($translation) {
  245. $document->addScriptDeclaration($translation);
  246. }
  247. }
  248. /**
  249. * Keep session alive, for example, while editing or creating an article.
  250. */
  251. function keepalive()
  252. {
  253. // Include mootools framework
  254. JHTMLBehavior::mootools();
  255. $config =& JFactory::getConfig();
  256. $lifetime = ( $config->getValue('lifetime') * 60000 );
  257. $refreshTime = ( $lifetime <= 60000 ) ? 30000 : $lifetime - 60000;
  258. //refresh time is 1 minute less than the liftime assined in the configuration.php file
  259. $document =& JFactory::getDocument();
  260. $script = '';
  261. $script .= 'function keepAlive( ) {';
  262. $script .= ' var myAjax = new Request.HTML( "index.php", { method: "get" } ).send();';
  263. $script .= '}';
  264. $script .= ' window.addEvent("domready", function()';
  265. $script .= '{ keepAlive.periodical('.$refreshTime.' ); }';
  266. $script .= ');';
  267. $document->addScriptDeclaration($script);
  268. return;
  269. }
  270. /**
  271. * Internal method to get a JavaScript object notation string from an array
  272. *
  273. * @param array $array The array to convert to JavaScript object notation
  274. * @return string JavaScript object notation representation of the array
  275. * @since 1.5
  276. */
  277. function _getJSObject($array=array())
  278. {
  279. // Initialize variables
  280. $object = '{';
  281. // Iterate over array to build objects
  282. foreach ((array)$array as $k => $v)
  283. {
  284. if (is_null($v)) {
  285. continue;
  286. }
  287. if (!is_array($v) && !is_object($v)) {
  288. $object .= ' '.$k.': ';
  289. $object .= (is_numeric($v) || strpos($v, '\\') === 0) ? (is_numeric($v)) ? $v : substr($v, 1) : "'".$v."'";
  290. $object .= ',';
  291. } else {
  292. $object .= ' '.$k.': '.JHTMLBehavior::_getJSObject($v).',';
  293. }
  294. }
  295. if (substr($object, -1) == ',') {
  296. $object = substr($object, 0, -1);
  297. }
  298. $object .= '}';
  299. return $object;
  300. }
  301. /**
  302. * Internal method to translate the JavaScript Calendar
  303. *
  304. * @return string JavaScript that translates the object
  305. * @since 1.5
  306. */
  307. function _calendartranslation()
  308. {
  309. static $jsscript = 0;
  310. if($jsscript == 0)
  311. {
  312. $return = 'Calendar._DN = new Array ("'.JText::_('Sunday').'", "'.JText::_('Monday').'", "'.JText::_('Tuesday').'", "'.JText::_('Wednesday').'", "'.JText::_('Thursday').'", "'.JText::_('Friday').'", "'.JText::_('Saturday').'", "'.JText::_('Sunday').'");Calendar._SDN = new Array ("'.JText::_('Sun').'", "'.JText::_('Mon').'", "'.JText::_('Tue').'", "'.JText::_('Wed').'", "'.JText::_('Thu').'", "'.JText::_('Fri').'", "'.JText::_('Sat').'", "'.JText::_('Sun').'"); Calendar._FD = 0; Calendar._MN = new Array ("'.JText::_('January').'", "'.JText::_('February').'", "'.JText::_('March').'", "'.JText::_('April').'", "'.JText::_('May').'", "'.JText::_('June').'", "'.JText::_('July').'", "'.JText::_('August').'", "'.JText::_('September').'", "'.JText::_('October').'", "'.JText::_('November').'", "'.JText::_('December').'"); Calendar._SMN = new Array ("'.JText::_('January_short').'", "'.JText::_('February_short').'", "'.JText::_('March_short').'", "'.JText::_('April_short').'", "'.JText::_('May_short').'", "'.JText::_('June_short').'", "'.JText::_('July_short').'", "'.JText::_('August_short').'", "'.JText::_('September_short').'", "'.JText::_('October_short').'", "'.JText::_('November_short').'", "'.JText::_('December_short').'");Calendar._TT = {};Calendar._TT["INFO"] = "'.JText::_('About the calendar').'";
  313. Calendar._TT["ABOUT"] =
  314. "DHTML Date/Time Selector\n" +
  315. "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +
  316. "For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
  317. "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
  318. "\n\n" +
  319. "Date selection:\n" +
  320. "- Use the \xab, \xbb buttons to select year\n" +
  321. "- Use the " + String.fromCharCode(0x2039) + ", " + String.fromCharCode(0x203a) + " buttons to select month\n" +
  322. "- Hold mouse button on any of the above buttons for faster selection.";
  323. Calendar._TT["ABOUT_TIME"] = "\n\n" +
  324. "Time selection:\n" +
  325. "- Click on any of the time parts to increase it\n" +
  326. "- or Shift-click to decrease it\n" +
  327. "- or click and drag for faster selection.";
  328. Calendar._TT["PREV_YEAR"] = "'.JText::_('Prev. year (hold for menu)').'";Calendar._TT["PREV_MONTH"] = "'.JText::_('Prev. month (hold for menu)').'"; Calendar._TT["GO_TODAY"] = "'.JText::_('Go Today').'";Calendar._TT["NEXT_MONTH"] = "'.JText::_('Next month (hold for menu)').'";Calendar._TT["NEXT_YEAR"] = "'.JText::_('Next year (hold for menu)').'";Calendar._TT["SEL_DATE"] = "'.JText::_('Select date').'";Calendar._TT["DRAG_TO_MOVE"] = "'.JText::_('Drag to move').'";Calendar._TT["PART_TODAY"] = "'.JText::_('(Today)').'";Calendar._TT["DAY_FIRST"] = "'.JText::_('Display %s first').'";Calendar._TT["WEEKEND"] = "0,6";Calendar._TT["CLOSE"] = "'.JText::_('Close').'";Calendar._TT["TODAY"] = "'.JText::_('Today').'";Calendar._TT["TIME_PART"] = "'.JText::_('(Shift-)Click or drag to change value').'";Calendar._TT["DEF_DATE_FORMAT"] = "'.JText::_('%Y-%m-%d').'"; Calendar._TT["TT_DATE_FORMAT"] = "'.JText::_('%a, %b %e').'";Calendar._TT["WK"] = "'.JText::_('wk').'";Calendar._TT["TIME"] = "'.JText::_('Time:').'";';
  329. $jsscript = 1;
  330. return $return;
  331. } else {
  332. return false;
  333. }
  334. }
  335. }