PageRenderTime 63ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/joomla/html/behavior.php

https://bitbucket.org/eternaware/joomus
PHP | 897 lines | 638 code | 73 blank | 186 comment | 40 complexity | a84b67e433464115af348e7586f857c3 MD5 | raw file
Possible License(s): LGPL-2.1
  1. <?php
  2. /**
  3. * @package Joomla.Platform
  4. * @subpackage HTML
  5. *
  6. * @copyright Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE
  8. */
  9. defined('JPATH_PLATFORM') or die;
  10. /**
  11. * Utility class for javascript behaviors
  12. *
  13. * @package Joomla.Platform
  14. * @subpackage HTML
  15. * @since 11.1
  16. */
  17. abstract class JHtmlBehavior
  18. {
  19. /**
  20. * @var array array containing information for loaded files
  21. */
  22. protected static $loaded = array();
  23. /**
  24. * Method to load the MooTools framework into the document head
  25. *
  26. * If debugging mode is on an uncompressed version of MooTools is included for easier debugging.
  27. *
  28. * @param string $extras MooTools file to load
  29. * @param mixed $debug Is debugging mode on? [optional]
  30. *
  31. * @return void
  32. *
  33. * @since 11.1
  34. */
  35. public static function framework($extras = false, $debug = null)
  36. {
  37. $type = $extras ? 'more' : 'core';
  38. // Only load once
  39. if (!empty(self::$loaded[__METHOD__][$type]))
  40. {
  41. return;
  42. }
  43. // If no debugging value is set, use the configuration setting
  44. if ($debug === null)
  45. {
  46. $config = JFactory::getConfig();
  47. $debug = $config->get('debug');
  48. }
  49. if ($type != 'core' && empty(self::$loaded[__METHOD__]['core']))
  50. {
  51. self::framework(false, $debug);
  52. }
  53. JHtml::_('script', 'system/mootools-' . $type . '.js', false, true, false, false, $debug);
  54. JHtml::_('script', 'system/core.js', false, true);
  55. self::$loaded[__METHOD__][$type] = true;
  56. return;
  57. }
  58. /**
  59. * Add unobtrusive javascript support for image captions.
  60. *
  61. * @param string $selector The selector for which a caption behaviour is to be applied.
  62. *
  63. * @return void
  64. *
  65. * @since 11.1
  66. */
  67. public static function caption($selector = 'img.caption')
  68. {
  69. // Only load once
  70. if (isset(self::$loaded[__METHOD__][$selector]))
  71. {
  72. return;
  73. }
  74. // Include MooTools framework
  75. self::framework();
  76. JHtml::_('script', 'system/caption.js', true, true);
  77. // Attach caption to document
  78. JFactory::getDocument()->addScriptDeclaration(
  79. "window.addEvent('load', function() {
  80. new JCaption('" . $selector . "');
  81. });"
  82. );
  83. // Set static array
  84. self::$loaded[__METHOD__][$selector] = true;
  85. }
  86. /**
  87. * Add unobtrusive javascript support for form validation.
  88. *
  89. * To enable form validation the form tag must have class="form-validate".
  90. * Each field that needs to be validated needs to have class="validate".
  91. * Additional handlers can be added to the handler for username, password,
  92. * numeric and email. To use these add class="validate-email" and so on.
  93. *
  94. * @return void
  95. *
  96. * @since 11.1
  97. */
  98. public static function formvalidation()
  99. {
  100. // Only load once
  101. if (isset(self::$loaded[__METHOD__]))
  102. {
  103. return;
  104. }
  105. // Include MooTools framework
  106. self::framework();
  107. JHtml::_('script', 'system/validate.js', true, true);
  108. self::$loaded[__METHOD__] = true;
  109. }
  110. /**
  111. * Add unobtrusive javascript support for submenu switcher support in
  112. * Global Configuration and System Information.
  113. *
  114. * @return void
  115. *
  116. * @since 11.1
  117. */
  118. public static function switcher()
  119. {
  120. // Only load once
  121. if (isset(self::$loaded[__METHOD__]))
  122. {
  123. return;
  124. }
  125. // Include MooTools framework
  126. self::framework();
  127. JHtml::_('script', 'system/switcher.js', true, true);
  128. $script = "
  129. document.switcher = null;
  130. window.addEvent('domready', function(){
  131. toggler = document.id('submenu');
  132. element = document.id('config-document');
  133. if (element) {
  134. document.switcher = new JSwitcher(toggler, element, {cookieName: toggler.getProperty('class')});
  135. }
  136. });";
  137. JFactory::getDocument()->addScriptDeclaration($script);
  138. self::$loaded[__METHOD__] = true;
  139. }
  140. /**
  141. * Add unobtrusive javascript support for a combobox effect.
  142. *
  143. * Note that this control is only reliable in absolutely positioned elements.
  144. * Avoid using a combobox in a slider or dynamic pane.
  145. *
  146. * @return void
  147. *
  148. * @since 11.1
  149. */
  150. public static function combobox()
  151. {
  152. if (isset(self::$loaded[__METHOD__]))
  153. {
  154. return;
  155. }
  156. // Include MooTools framework
  157. self::framework();
  158. JHtml::_('script', 'system/combobox.js', true, true);
  159. self::$loaded[__METHOD__] = true;
  160. }
  161. /**
  162. * Add unobtrusive javascript support for a hover tooltips.
  163. *
  164. * Add a title attribute to any element in the form
  165. * title="title::text"
  166. *
  167. *
  168. * Uses the core Tips class in MooTools.
  169. *
  170. * @param string $selector The class selector for the tooltip.
  171. * @param array $params An array of options for the tooltip.
  172. * Options for the tooltip can be:
  173. * - maxTitleChars integer The maximum number of characters in the tooltip title (defaults to 50).
  174. * - offsets object The distance of your tooltip from the mouse (defaults to {'x': 16, 'y': 16}).
  175. * - showDelay integer The millisecond delay the show event is fired (defaults to 100).
  176. * - hideDelay integer The millisecond delay the hide hide is fired (defaults to 100).
  177. * - className string The className your tooltip container will get.
  178. * - fixed boolean If set to true, the toolTip will not follow the mouse.
  179. * - onShow function The default function for the show event, passes the tip element
  180. * and the currently hovered element.
  181. * - onHide function The default function for the hide event, passes the currently
  182. * hovered element.
  183. *
  184. * @return void
  185. *
  186. * @since 11.1
  187. */
  188. public static function tooltip($selector = '.hasTip', $params = array())
  189. {
  190. $sig = md5(serialize(array($selector, $params)));
  191. if (isset(self::$loaded[__METHOD__][$sig]))
  192. {
  193. return;
  194. }
  195. // Include MooTools framework
  196. self::framework(true);
  197. // Setup options object
  198. $opt['maxTitleChars'] = (isset($params['maxTitleChars']) && ($params['maxTitleChars'])) ? (int) $params['maxTitleChars'] : 50;
  199. // Offsets needs an array in the format: array('x'=>20, 'y'=>30)
  200. $opt['offset'] = (isset($params['offset']) && (is_array($params['offset']))) ? $params['offset'] : null;
  201. $opt['showDelay'] = (isset($params['showDelay'])) ? (int) $params['showDelay'] : null;
  202. $opt['hideDelay'] = (isset($params['hideDelay'])) ? (int) $params['hideDelay'] : null;
  203. $opt['className'] = (isset($params['className'])) ? $params['className'] : null;
  204. $opt['fixed'] = (isset($params['fixed']) && ($params['fixed'])) ? true : false;
  205. $opt['onShow'] = (isset($params['onShow'])) ? '\\' . $params['onShow'] : null;
  206. $opt['onHide'] = (isset($params['onHide'])) ? '\\' . $params['onHide'] : null;
  207. $options = JHtml::getJSObject($opt);
  208. // Attach tooltips to document
  209. JFactory::getDocument()->addScriptDeclaration(
  210. "window.addEvent('domready', function() {
  211. $$('$selector').each(function(el) {
  212. var title = el.get('title');
  213. if (title) {
  214. var parts = title.split('::', 2);
  215. el.store('tip:title', parts[0]);
  216. el.store('tip:text', parts[1]);
  217. }
  218. });
  219. var JTooltips = new Tips($$('$selector'), $options);
  220. });"
  221. );
  222. // Set static array
  223. self::$loaded[__METHOD__][$sig] = true;
  224. return;
  225. }
  226. /**
  227. * Add unobtrusive javascript support for modal links.
  228. *
  229. * @param string $selector The selector for which a modal behaviour is to be applied.
  230. * @param array $params An array of parameters for the modal behaviour.
  231. * Options for the modal behaviour can be:
  232. * - ajaxOptions
  233. * - size
  234. * - shadow
  235. * - overlay
  236. * - onOpen
  237. * - onClose
  238. * - onUpdate
  239. * - onResize
  240. * - onShow
  241. * - onHide
  242. *
  243. * @return void
  244. *
  245. * @since 11.1
  246. */
  247. public static function modal($selector = 'a.modal', $params = array())
  248. {
  249. $document = JFactory::getDocument();
  250. // Load the necessary files if they haven't yet been loaded
  251. if (!isset(self::$loaded[__METHOD__]))
  252. {
  253. // Include MooTools framework
  254. self::framework(true);
  255. // Load the javascript and css
  256. JHtml::_('script', 'system/modal.js', true, true);
  257. JHtml::_('stylesheet', 'system/modal.css', array(), true);
  258. }
  259. $sig = md5(serialize(array($selector, $params)));
  260. if (isset(self::$loaded[__METHOD__][$sig]))
  261. {
  262. return;
  263. }
  264. // Setup options object
  265. $opt['ajaxOptions'] = (isset($params['ajaxOptions']) && (is_array($params['ajaxOptions']))) ? $params['ajaxOptions'] : null;
  266. $opt['handler'] = (isset($params['handler'])) ? $params['handler'] : null;
  267. $opt['parseSecure'] = (isset($params['parseSecure'])) ? (bool) $params['parseSecure'] : null;
  268. $opt['closable'] = (isset($params['closable'])) ? (bool) $params['closable'] : null;
  269. $opt['closeBtn'] = (isset($params['closeBtn'])) ? (bool) $params['closeBtn'] : null;
  270. $opt['iframePreload'] = (isset($params['iframePreload'])) ? (bool) $params['iframePreload'] : null;
  271. $opt['iframeOptions'] = (isset($params['iframeOptions']) && (is_array($params['iframeOptions']))) ? $params['iframeOptions'] : null;
  272. $opt['size'] = (isset($params['size']) && (is_array($params['size']))) ? $params['size'] : null;
  273. $opt['shadow'] = (isset($params['shadow'])) ? $params['shadow'] : null;
  274. $opt['overlay'] = (isset($params['overlay'])) ? $params['overlay'] : null;
  275. $opt['onOpen'] = (isset($params['onOpen'])) ? $params['onOpen'] : null;
  276. $opt['onClose'] = (isset($params['onClose'])) ? $params['onClose'] : null;
  277. $opt['onUpdate'] = (isset($params['onUpdate'])) ? $params['onUpdate'] : null;
  278. $opt['onResize'] = (isset($params['onResize'])) ? $params['onResize'] : null;
  279. $opt['onMove'] = (isset($params['onMove'])) ? $params['onMove'] : null;
  280. $opt['onShow'] = (isset($params['onShow'])) ? $params['onShow'] : null;
  281. $opt['onHide'] = (isset($params['onHide'])) ? $params['onHide'] : null;
  282. if (isset($params['fullScreen']) && (bool) $params['fullScreen'])
  283. {
  284. $opt['size'] = array('x' => '\\window.getSize().x-80', 'y' => '\\window.getSize().y-80');
  285. }
  286. $options = JHtml::getJSObject($opt);
  287. // Attach modal behavior to document
  288. $document
  289. ->addScriptDeclaration(
  290. "
  291. window.addEvent('domready', function() {
  292. SqueezeBox.initialize(" . $options . ");
  293. SqueezeBox.assign($$('" . $selector . "'), {
  294. parse: 'rel'
  295. });
  296. });"
  297. );
  298. // Set static array
  299. self::$loaded[__METHOD__][$sig] = true;
  300. return;
  301. }
  302. /**
  303. * JavaScript behavior to allow shift select in grids
  304. *
  305. * @param string $id The id of the form for which a multiselect behaviour is to be applied.
  306. *
  307. * @return void
  308. *
  309. * @since 11.1
  310. */
  311. public static function multiselect($id = 'adminForm')
  312. {
  313. // Only load once
  314. if (isset(self::$loaded[__METHOD__][$id]))
  315. {
  316. return;
  317. }
  318. // Include MooTools framework
  319. self::framework();
  320. JHtml::_('script', 'system/multiselect.js', true, true);
  321. // Attach multiselect to document
  322. JFactory::getDocument()->addScriptDeclaration(
  323. "window.addEvent('domready', function() {
  324. new Joomla.JMultiSelect('" . $id . "');
  325. });"
  326. );
  327. // Set static array
  328. self::$loaded[__METHOD__][$id] = true;
  329. return;
  330. }
  331. /**
  332. * Add unobtrusive javascript support for the advanced uploader.
  333. *
  334. * @param string $id An index.
  335. * @param array $params An array of options for the uploader.
  336. * @param string $upload_queue The HTML id of the upload queue element (??).
  337. *
  338. * @return void
  339. *
  340. * @since 11.1
  341. */
  342. public static function uploader($id = 'file-upload', $params = array(), $upload_queue = 'upload-queue')
  343. {
  344. // Include MooTools framework
  345. self::framework();
  346. JHtml::_('script', 'system/swf.js', true, true);
  347. JHtml::_('script', 'system/progressbar.js', true, true);
  348. JHtml::_('script', 'system/uploader.js', true, true);
  349. $document = JFactory::getDocument();
  350. if (!isset(self::$loaded[__METHOD__]))
  351. {
  352. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_FILENAME');
  353. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_UPLOAD_COMPLETED');
  354. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ERROR_OCCURRED');
  355. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ALL_FILES');
  356. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_PROGRESS_OVERALL');
  357. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_CURRENT_TITLE');
  358. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_REMOVE');
  359. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_REMOVE_TITLE');
  360. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_CURRENT_FILE');
  361. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_CURRENT_PROGRESS');
  362. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_FILE_ERROR');
  363. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_FILE_SUCCESSFULLY_UPLOADED');
  364. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_VALIDATION_ERROR_DUPLICATE');
  365. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_VALIDATION_ERROR_SIZELIMITMIN');
  366. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_VALIDATION_ERROR_SIZELIMITMAX');
  367. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_VALIDATION_ERROR_FILELISTMAX');
  368. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_VALIDATION_ERROR_FILELISTSIZEMAX');
  369. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ERROR_HTTPSTATUS');
  370. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ERROR_SECURITYERROR');
  371. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ERROR_IOERROR');
  372. JText::script('JLIB_HTML_BEHAVIOR_UPLOADER_ALL_FILES');
  373. }
  374. if (isset(self::$loaded[__METHOD__][$id]))
  375. {
  376. return;
  377. }
  378. $onFileSuccess = '\\function(file, response) {
  379. var json = new Hash(JSON.decode(response, true) || {});
  380. if (json.get(\'status\') == \'1\') {
  381. file.element.addClass(\'file-success\');
  382. file.info.set(\'html\', \'<strong>\' + Joomla.JText._(\'JLIB_HTML_BEHAVIOR_UPLOADER_FILE_SUCCESSFULLY_UPLOADED\') + \'</strong>\');
  383. } else {
  384. file.element.addClass(\'file-failed\');
  385. file.info.set(\'html\', \'<strong>\' +
  386. Joomla.JText._(\'JLIB_HTML_BEHAVIOR_UPLOADER_ERROR_OCCURRED\',
  387. \'An Error Occurred\').substitute({ error: json.get(\'error\') }) + \'</strong>\');
  388. }
  389. }';
  390. // Setup options object
  391. $opt['verbose'] = true;
  392. $opt['url'] = (isset($params['targetURL'])) ? $params['targetURL'] : null;
  393. $opt['path'] = (isset($params['swf'])) ? $params['swf'] : JURI::root(true) . '/media/system/swf/uploader.swf';
  394. $opt['height'] = (isset($params['height'])) && $params['height'] ? (int) $params['height'] : null;
  395. $opt['width'] = (isset($params['width'])) && $params['width'] ? (int) $params['width'] : null;
  396. $opt['multiple'] = (isset($params['multiple']) && !($params['multiple'])) ? false : true;
  397. $opt['queued'] = (isset($params['queued']) && !($params['queued'])) ? (int) $params['queued'] : null;
  398. $opt['target'] = (isset($params['target'])) ? $params['target'] : '\\document.id(\'upload-browse\')';
  399. $opt['instantStart'] = (isset($params['instantStart']) && ($params['instantStart'])) ? true : false;
  400. $opt['allowDuplicates'] = (isset($params['allowDuplicates']) && !($params['allowDuplicates'])) ? false : true;
  401. // "limitSize" is the old parameter name. Remove in 1.7
  402. $opt['fileSizeMax'] = (isset($params['limitSize']) && ($params['limitSize'])) ? (int) $params['limitSize'] : null;
  403. // "fileSizeMax" is the new name. If supplied, it will override the old value specified for limitSize
  404. $opt['fileSizeMax'] = (isset($params['fileSizeMax']) && ($params['fileSizeMax'])) ? (int) $params['fileSizeMax'] : $opt['fileSizeMax'];
  405. $opt['fileSizeMin'] = (isset($params['fileSizeMin']) && ($params['fileSizeMin'])) ? (int) $params['fileSizeMin'] : null;
  406. // "limitFiles" is the old parameter name. Remove in 1.7
  407. $opt['fileListMax'] = (isset($params['limitFiles']) && ($params['limitFiles'])) ? (int) $params['limitFiles'] : null;
  408. // "fileListMax" is the new name. If supplied, it will override the old value specified for limitFiles
  409. $opt['fileListMax'] = (isset($params['fileListMax']) && ($params['fileListMax'])) ? (int) $params['fileListMax'] : $opt['fileListMax'];
  410. $opt['fileListSizeMax'] = (isset($params['fileListSizeMax']) && ($params['fileListSizeMax'])) ? (int) $params['fileListSizeMax'] : null;
  411. // "types" is the old parameter name. Remove in 1.7
  412. $opt['typeFilter'] = (isset($params['types'])) ? '\\' . $params['types']
  413. : '\\{Joomla.JText._(\'JLIB_HTML_BEHAVIOR_UPLOADER_ALL_FILES\'): \'*.*\'}';
  414. $opt['typeFilter'] = (isset($params['typeFilter'])) ? '\\' . $params['typeFilter'] : $opt['typeFilter'];
  415. // Optional functions
  416. $opt['createReplacement'] = (isset($params['createReplacement'])) ? '\\' . $params['createReplacement'] : null;
  417. $opt['onFileComplete'] = (isset($params['onFileComplete'])) ? '\\' . $params['onFileComplete'] : null;
  418. $opt['onBeforeStart'] = (isset($params['onBeforeStart'])) ? '\\' . $params['onBeforeStart'] : null;
  419. $opt['onStart'] = (isset($params['onStart'])) ? '\\' . $params['onStart'] : null;
  420. $opt['onComplete'] = (isset($params['onComplete'])) ? '\\' . $params['onComplete'] : null;
  421. $opt['onFileSuccess'] = (isset($params['onFileSuccess'])) ? '\\' . $params['onFileSuccess'] : $onFileSuccess;
  422. if (!isset($params['startButton']))
  423. {
  424. $params['startButton'] = 'upload-start';
  425. }
  426. if (!isset($params['clearButton']))
  427. {
  428. $params['clearButton'] = 'upload-clear';
  429. }
  430. $opt['onLoad'] = '\\function() {
  431. document.id(\'' . $id
  432. . '\').removeClass(\'hide\'); // we show the actual UI
  433. document.id(\'upload-noflash\').destroy(); // ... and hide the plain form
  434. // We relay the interactions with the overlayed flash to the link
  435. this.target.addEvents({
  436. click: function() {
  437. return false;
  438. },
  439. mouseenter: function() {
  440. this.addClass(\'hover\');
  441. },
  442. mouseleave: function() {
  443. this.removeClass(\'hover\');
  444. this.blur();
  445. },
  446. mousedown: function() {
  447. this.focus();
  448. }
  449. });
  450. // Interactions for the 2 other buttons
  451. document.id(\'' . $params['clearButton']
  452. . '\').addEvent(\'click\', function() {
  453. Uploader.remove(); // remove all files
  454. return false;
  455. });
  456. document.id(\'' . $params['startButton']
  457. . '\').addEvent(\'click\', function() {
  458. Uploader.start(); // start upload
  459. return false;
  460. });
  461. }';
  462. $options = JHtml::getJSObject($opt);
  463. // Attach tooltips to document
  464. $uploaderInit = 'window.addEvent(\'domready\', function(){
  465. var Uploader = new FancyUpload2(document.id(\'' . $id . '\'), document.id(\'' . $upload_queue . '\'), ' . $options . ' );
  466. });';
  467. $document->addScriptDeclaration($uploaderInit);
  468. // Set static array
  469. self::$loaded[__METHOD__][$id] = true;
  470. return;
  471. }
  472. /**
  473. * Add unobtrusive javascript support for a collapsible tree.
  474. *
  475. * @param string $id An index
  476. * @param array $params An array of options.
  477. * @param array $root The root node
  478. *
  479. * @return void
  480. *
  481. * @since 11.1
  482. */
  483. public static function tree($id, $params = array(), $root = array())
  484. {
  485. // Include MooTools framework
  486. self::framework();
  487. JHtml::_('script', 'system/mootree.js', true, true, false, false);
  488. JHtml::_('stylesheet', 'system/mootree.css', array(), true);
  489. if (isset(self::$loaded[__METHOD__][$id]))
  490. {
  491. return;
  492. }
  493. // Setup options object
  494. $opt['div'] = (array_key_exists('div', $params)) ? $params['div'] : $id . '_tree';
  495. $opt['mode'] = (array_key_exists('mode', $params)) ? $params['mode'] : 'folders';
  496. $opt['grid'] = (array_key_exists('grid', $params)) ? '\\' . $params['grid'] : true;
  497. $opt['theme'] = (array_key_exists('theme', $params)) ? $params['theme'] : JHtml::_('image', 'system/mootree.gif', '', array(), true, true);
  498. // Event handlers
  499. $opt['onExpand'] = (array_key_exists('onExpand', $params)) ? '\\' . $params['onExpand'] : null;
  500. $opt['onSelect'] = (array_key_exists('onSelect', $params)) ? '\\' . $params['onSelect'] : null;
  501. $opt['onClick'] = (array_key_exists('onClick', $params)) ? '\\' . $params['onClick']
  502. : '\\function(node){ window.open(node.data.url, node.data.target != null ? node.data.target : \'_self\'); }';
  503. $options = JHtml::getJSObject($opt);
  504. // Setup root node
  505. $rt['text'] = (array_key_exists('text', $root)) ? $root['text'] : 'Root';
  506. $rt['id'] = (array_key_exists('id', $root)) ? $root['id'] : null;
  507. $rt['color'] = (array_key_exists('color', $root)) ? $root['color'] : null;
  508. $rt['open'] = (array_key_exists('open', $root)) ? '\\' . $root['open'] : true;
  509. $rt['icon'] = (array_key_exists('icon', $root)) ? $root['icon'] : null;
  510. $rt['openicon'] = (array_key_exists('openicon', $root)) ? $root['openicon'] : null;
  511. $rt['data'] = (array_key_exists('data', $root)) ? $root['data'] : null;
  512. $rootNode = JHtml::getJSObject($rt);
  513. $treeName = (array_key_exists('treeName', $params)) ? $params['treeName'] : '';
  514. $js = ' window.addEvent(\'domready\', function(){
  515. tree' . $treeName . ' = new MooTreeControl(' . $options . ',' . $rootNode . ');
  516. tree' . $treeName . '.adopt(\'' . $id . '\');})';
  517. // Attach tooltips to document
  518. $document = JFactory::getDocument();
  519. $document->addScriptDeclaration($js);
  520. // Set static array
  521. self::$loaded[__METHOD__][$id] = true;
  522. return;
  523. }
  524. /**
  525. * Add unobtrusive javascript support for a calendar control.
  526. *
  527. * @return void
  528. *
  529. * @since 11.1
  530. */
  531. public static function calendar()
  532. {
  533. // Only load once
  534. if (isset(self::$loaded[__METHOD__]))
  535. {
  536. return;
  537. }
  538. $document = JFactory::getDocument();
  539. $tag = JFactory::getLanguage()->getTag();
  540. JHtml::_('stylesheet', 'system/calendar-jos.css', array(' title' => JText::_('JLIB_HTML_BEHAVIOR_GREEN'), ' media' => 'all'), true);
  541. JHtml::_('script', $tag . '/calendar.js', false, true);
  542. JHtml::_('script', $tag . '/calendar-setup.js', false, true);
  543. $translation = self::_calendartranslation();
  544. if ($translation)
  545. {
  546. $document->addScriptDeclaration($translation);
  547. }
  548. self::$loaded[__METHOD__] = true;
  549. }
  550. /**
  551. * Add unobtrusive javascript support for a color picker.
  552. *
  553. * @return void
  554. *
  555. * @since 11.2
  556. */
  557. public static function colorpicker()
  558. {
  559. // Only load once
  560. if (isset(self::$loaded[__METHOD__]))
  561. {
  562. return;
  563. }
  564. // Include MooTools framework
  565. self::framework(true);
  566. JHtml::_('stylesheet', 'system/mooRainbow.css', array('media' => 'all'), true);
  567. JHtml::_('script', 'system/mooRainbow.js', false, true);
  568. JFactory::getDocument()
  569. ->addScriptDeclaration(
  570. "window.addEvent('domready', function(){
  571. var nativeColorUi = false;
  572. if (Browser.opera && (Browser.version >= 11.5)) {
  573. nativeColorUi = true;
  574. }
  575. $$('.input-colorpicker').each(function(item){
  576. if (nativeColorUi) {
  577. item.type = 'color';
  578. } else {
  579. new MooRainbow(item, {
  580. id: item.id,
  581. imgPath: '" . JURI::root(true) . "/media/system/images/mooRainbow/',
  582. onComplete: function(color) {
  583. this.element.value = color.hex;
  584. },
  585. startColor: item.value.hexToRgb(true) ? item.value.hexToRgb(true) : [0, 0, 0]
  586. });
  587. }
  588. });
  589. });
  590. ");
  591. self::$loaded[__METHOD__] = true;
  592. }
  593. /**
  594. * Keep session alive, for example, while editing or creating an article.
  595. *
  596. * @return void
  597. *
  598. * @since 11.1
  599. */
  600. public static function keepalive()
  601. {
  602. // Only load once
  603. if (isset(self::$loaded[__METHOD__]))
  604. {
  605. return;
  606. }
  607. // Include MooTools framework
  608. self::framework();
  609. $config = JFactory::getConfig();
  610. $lifetime = ($config->get('lifetime') * 60000);
  611. $refreshTime = ($lifetime <= 60000) ? 30000 : $lifetime - 60000;
  612. // Refresh time is 1 minute less than the liftime assined in the configuration.php file.
  613. // The longest refresh period is one hour to prevent integer overflow.
  614. if ($refreshTime > 3600000 || $refreshTime <= 0)
  615. {
  616. $refreshTime = 3600000;
  617. }
  618. $document = JFactory::getDocument();
  619. $script = '';
  620. $script .= 'function keepAlive() {';
  621. $script .= ' var myAjax = new Request({method: "get", url: "index.php"}).send();';
  622. $script .= '}';
  623. $script .= ' window.addEvent("domready", function()';
  624. $script .= '{ keepAlive.periodical(' . $refreshTime . '); }';
  625. $script .= ');';
  626. $document->addScriptDeclaration($script);
  627. self::$loaded[__METHOD__] = true;
  628. return;
  629. }
  630. /**
  631. * Highlight some words via Javascript.
  632. *
  633. * @param array $terms Array of words that should be highlighted.
  634. * @param string $start ID of the element that marks the begin of the section in which words
  635. * should be highlighted. Note this element will be removed from the DOM.
  636. * @param string $end ID of the element that end this section.
  637. * Note this element will be removed from the DOM.
  638. * @param string $className Class name of the element highlights are wrapped in.
  639. * @param string $tag Tag that will be used to wrap the highlighted words.
  640. *
  641. * @return void
  642. *
  643. * @since 11.4
  644. */
  645. public static function highlighter(array $terms, $start = 'highlighter-start', $end = 'highlighter-end', $className = 'highlight', $tag = 'span')
  646. {
  647. $sig = md5(serialize(array($terms, $start, $end)));
  648. if (isset(self::$loaded[__METHOD__][$sig]))
  649. {
  650. return;
  651. }
  652. JHtml::_('script', 'system/highlighter.js', true, true);
  653. $terms = str_replace('"', '\"', $terms);
  654. $document = JFactory::getDocument();
  655. $document->addScriptDeclaration("
  656. window.addEvent('domready', function () {
  657. var start = document.id('" . $start . "');
  658. var end = document.id('" . $end . "');
  659. if (!start || !end || !Joomla.Highlighter) {
  660. return true;
  661. }
  662. highlighter = new Joomla.Highlighter({
  663. startElement: start,
  664. endElement: end,
  665. className: '" . $className . "',
  666. onlyWords: false,
  667. tag: '" . $tag . "'
  668. }).highlight([\"" . implode('","', $terms) . "\"]);
  669. start.dispose();
  670. end.dispose();
  671. });
  672. ");
  673. self::$loaded[__METHOD__][$sig] = true;
  674. return;
  675. }
  676. /**
  677. * Break us out of any containing iframes
  678. *
  679. * @return void
  680. *
  681. * @since 11.1
  682. */
  683. public static function noframes()
  684. {
  685. // Only load once
  686. if (isset(self::$loaded[__METHOD__]))
  687. {
  688. return;
  689. }
  690. // Include MooTools framework
  691. self::framework();
  692. $js = "window.addEvent('domready', function () {if (top == self) {document.documentElement.style.display = 'block'; }" .
  693. " else {top.location = self.location; }});";
  694. $document = JFactory::getDocument();
  695. $document->addStyleDeclaration('html { display:none }');
  696. $document->addScriptDeclaration($js);
  697. JResponse::setHeader('X-Frames-Options', 'SAME-ORIGIN');
  698. self::$loaded[__METHOD__] = true;
  699. }
  700. /**
  701. * Internal method to get a JavaScript object notation string from an array
  702. *
  703. * @param array $array The array to convert to JavaScript object notation
  704. *
  705. * @return string JavaScript object notation representation of the array
  706. *
  707. * @since 11.1
  708. * @dprecated 13.3 Use JHtml::getJSObject() instead.
  709. */
  710. protected static function _getJSObject($array = array())
  711. {
  712. JLog::add('JHtmlBehavior::_getJSObject() is deprecated. JHtml::getJSObject() instead..', JLog::WARNING, 'deprecated');
  713. JHtml::getJSObject($array);
  714. }
  715. /**
  716. * Internal method to translate the JavaScript Calendar
  717. *
  718. * @return string JavaScript that translates the object
  719. *
  720. * @since 11.1
  721. */
  722. protected static function _calendartranslation()
  723. {
  724. static $jsscript = 0;
  725. if ($jsscript == 0)
  726. {
  727. $return = 'Calendar._DN = new Array ("' . JText::_('SUNDAY', true) . '", "' . JText::_('MONDAY', true) . '", "'
  728. . JText::_('TUESDAY', true) . '", "' . JText::_('WEDNESDAY', true) . '", "' . JText::_('THURSDAY', true) . '", "'
  729. . JText::_('FRIDAY', true) . '", "' . JText::_('SATURDAY', true) . '", "' . JText::_('SUNDAY', true) . '");'
  730. . ' Calendar._SDN = new Array ("' . JText::_('SUN', true) . '", "' . JText::_('MON', true) . '", "' . JText::_('TUE', true) . '", "'
  731. . JText::_('WED', true) . '", "' . JText::_('THU', true) . '", "' . JText::_('FRI', true) . '", "' . JText::_('SAT', true) . '", "'
  732. . JText::_('SUN', true) . '");' . ' Calendar._FD = 0;' . ' Calendar._MN = new Array ("' . JText::_('JANUARY', true) . '", "'
  733. . JText::_('FEBRUARY', true) . '", "' . JText::_('MARCH', true) . '", "' . JText::_('APRIL', true) . '", "' . JText::_('MAY', true)
  734. . '", "' . JText::_('JUNE', true) . '", "' . JText::_('JULY', true) . '", "' . JText::_('AUGUST', true) . '", "'
  735. . JText::_('SEPTEMBER', true) . '", "' . JText::_('OCTOBER', true) . '", "' . JText::_('NOVEMBER', true) . '", "'
  736. . JText::_('DECEMBER', true) . '");' . ' Calendar._SMN = new Array ("' . JText::_('JANUARY_SHORT', true) . '", "'
  737. . JText::_('FEBRUARY_SHORT', true) . '", "' . JText::_('MARCH_SHORT', true) . '", "' . JText::_('APRIL_SHORT', true) . '", "'
  738. . JText::_('MAY_SHORT', true) . '", "' . JText::_('JUNE_SHORT', true) . '", "' . JText::_('JULY_SHORT', true) . '", "'
  739. . JText::_('AUGUST_SHORT', true) . '", "' . JText::_('SEPTEMBER_SHORT', true) . '", "' . JText::_('OCTOBER_SHORT', true) . '", "'
  740. . JText::_('NOVEMBER_SHORT', true) . '", "' . JText::_('DECEMBER_SHORT', true) . '");'
  741. . ' Calendar._TT = {};Calendar._TT["INFO"] = "' . JText::_('JLIB_HTML_BEHAVIOR_ABOUT_THE_CALENDAR', true) . '";'
  742. . ' Calendar._TT["ABOUT"] =
  743. "DHTML Date/Time Selector\n" +
  744. "(c) dynarch.com 2002-2005 / Author: Mihai Bazon\n" +
  745. "For latest version visit: http://www.dynarch.com/projects/calendar/\n" +
  746. "Distributed under GNU LGPL. See http://gnu.org/licenses/lgpl.html for details." +
  747. "\n\n" +
  748. "' . JText::_('JLIB_HTML_BEHAVIOR_DATE_SELECTION', false, false) . '" +
  749. "' . JText::_('JLIB_HTML_BEHAVIOR_YEAR_SELECT', false, false) . '" +
  750. "' . JText::_('JLIB_HTML_BEHAVIOR_MONTH_SELECT', false, false) . '" +
  751. "' . JText::_('JLIB_HTML_BEHAVIOR_HOLD_MOUSE', false, false)
  752. . '";
  753. Calendar._TT["ABOUT_TIME"] = "\n\n" +
  754. "Time selection:\n" +
  755. "- Click on any of the time parts to increase it\n" +
  756. "- or Shift-click to decrease it\n" +
  757. "- or click and drag for faster selection.";
  758. Calendar._TT["PREV_YEAR"] = "' . JText::_('JLIB_HTML_BEHAVIOR_PREV_YEAR_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["PREV_MONTH"] = "'
  759. . JText::_('JLIB_HTML_BEHAVIOR_PREV_MONTH_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["GO_TODAY"] = "'
  760. . JText::_('JLIB_HTML_BEHAVIOR_GO_TODAY', true) . '";' . ' Calendar._TT["NEXT_MONTH"] = "'
  761. . JText::_('JLIB_HTML_BEHAVIOR_NEXT_MONTH_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["NEXT_YEAR"] = "'
  762. . JText::_('JLIB_HTML_BEHAVIOR_NEXT_YEAR_HOLD_FOR_MENU', true) . '";' . ' Calendar._TT["SEL_DATE"] = "'
  763. . JText::_('JLIB_HTML_BEHAVIOR_SELECT_DATE', true) . '";' . ' Calendar._TT["DRAG_TO_MOVE"] = "'
  764. . JText::_('JLIB_HTML_BEHAVIOR_DRAG_TO_MOVE', true) . '";' . ' Calendar._TT["PART_TODAY"] = "'
  765. . JText::_('JLIB_HTML_BEHAVIOR_TODAY', true) . '";' . ' Calendar._TT["DAY_FIRST"] = "'
  766. . JText::_('JLIB_HTML_BEHAVIOR_DISPLAY_S_FIRST', true) . '";' . ' Calendar._TT["WEEKEND"] = "0,6";' . ' Calendar._TT["CLOSE"] = "'
  767. . JText::_('JLIB_HTML_BEHAVIOR_CLOSE', true) . '";' . ' Calendar._TT["TODAY"] = "' . JText::_('JLIB_HTML_BEHAVIOR_TODAY', true)
  768. . '";' . ' Calendar._TT["TIME_PART"] = "' . JText::_('JLIB_HTML_BEHAVIOR_SHIFT_CLICK_OR_DRAG_TO_CHANGE_VALUE', true) . '";'
  769. . ' Calendar._TT["DEF_DATE_FORMAT"] = "%Y-%m-%d";' . ' Calendar._TT["TT_DATE_FORMAT"] = "'
  770. . JText::_('JLIB_HTML_BEHAVIOR_TT_DATE_FORMAT', true) . '";' . ' Calendar._TT["WK"] = "' . JText::_('JLIB_HTML_BEHAVIOR_WK', true) . '";'
  771. . ' Calendar._TT["TIME"] = "' . JText::_('JLIB_HTML_BEHAVIOR_TIME', true) . '";';
  772. $jsscript = 1;
  773. return $return;
  774. }
  775. else
  776. {
  777. return false;
  778. }
  779. }
  780. }