1 <?php
2 /**
3 * @package Joomla.Libraries
4 * @subpackage Toolbar
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE.txt
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * Renders a button to render an HTML element in a slider container
14 *
15 * @since 3.0
16 */
17 class JToolbarButtonSlider extends JToolbarButton
18 {
19 /**
20 * Button type
21 *
22 * @var string
23 */
24 protected $_name = 'Slider';
25
26 /**
27 * Fetch the HTML for the button
28 *
29 * @param string $type Unused string, formerly button type.
30 * @param string $name Button name
31 * @param string $text The link text
32 * @param string $url URL for popup
33 * @param integer $width Width of popup
34 * @param integer $height Height of popup
35 * @param string $onClose JavaScript for the onClose event.
36 *
37 * @return string HTML string for the button
38 *
39 * @since 3.0
40 */
41 public function fetchButton($type = 'Slider', $name = '', $text = '', $url = '', $width = 640, $height = 480, $onClose = '')
42 {
43 JHtml::_('script', 'jui/cms.js', array('version' => 'auto', 'relative' => true));
44
45 // Store all data to the options array for use with JLayout
46 $options = array();
47 $options['text'] = JText::_($text);
48 $options['name'] = $name;
49 $options['class'] = $this->fetchIconClass($name);
50 $options['onClose'] = '';
51
52 $doTask = $this->_getCommand($url);
53 $options['doTask'] = 'Joomla.setcollapse(\'' . $doTask . '\', \'' . $name . '\', \'' . $height . '\');';
54
55 if ($onClose)
56 {
57 $options['onClose'] = ' rel="{onClose: function() {' . $onClose . '}}"';
58 }
59
60 // Instantiate a new JLayoutFile instance and render the layout
61 $layout = new JLayoutFile('joomla.toolbar.slider');
62
63 return $layout->render($options);
64 }
65
66 /**
67 * Get the button id
68 *
69 * @param string $type Button type
70 * @param string $name Button name
71 *
72 * @return string Button CSS Id
73 *
74 * @since 3.0
75 */
76 public function fetchId($type, $name)
77 {
78 return $this->_parent->getName() . '-slider-' . $name;
79 }
80
81 /**
82 * Get the JavaScript command for the button
83 *
84 * @param string $url URL for popup
85 *
86 * @return string JavaScript command string
87 *
88 * @since 3.0
89 */
90 private function _getCommand($url)
91 {
92 if (strpos($url, 'http') !== 0)
93 {
94 $url = JUri::base() . $url;
95 }
96
97 return $url;
98 }
99 }
100