1 <?php
2 3 4 5 6 7 8
9
10 defined('JPATH_PLATFORM') or die;
11
12 13 14 15 16
17 abstract class JHtmlDropdown
18 {
19 20 21 22
23 protected static $loaded = array();
24
25 26 27 28
29 protected static $dropDownList = null;
30
31 32 33 34 35 36 37
38 public static function init()
39 {
40
41 if (isset(static::$loaded[__METHOD__]))
42 {
43 return;
44 }
45
46
47 JHtml::_('bootstrap.framework');
48
49 JFactory::getDocument()->addScriptDeclaration("
50 (function($){
51 $(document).ready(function (){
52 $('.has-context')
53 .mouseenter(function (){
54 $('.btn-group',$(this)).show();
55 })
56 .mouseleave(function (){
57 $('.btn-group',$(this)).hide();
58 $('.btn-group',$(this)).removeClass('open');
59 });
60
61 contextAction =function (cbId, task)
62 {
63 $('input[name=\"cid[]\"]').removeAttr('checked');
64 $('#' + cbId).attr('checked','checked');
65 Joomla.submitbutton(task);
66 }
67 });
68 })(jQuery);
69 "
70 );
71
72
73 static::$loaded[__METHOD__] = true;
74
75 return;
76 }
77
78 79 80 81 82 83 84
85 public static function start()
86 {
87
88 if (isset(static::$loaded[__METHOD__]) && static::$loaded[__METHOD__] == true)
89 {
90 return;
91 }
92
93 $dropDownList = '<div class="btn-group" style="margin-left:6px;display:none">
94 <a href="#" data-toggle="dropdown" class="dropdown-toggle btn btn-mini">
95 <span class="caret"></span>
96 </a>
97 <ul class="dropdown-menu">';
98 static::$dropDownList = $dropDownList;
99 static::$loaded[__METHOD__] = true;
100
101 return;
102 }
103
104 105 106 107 108 109 110
111 public static function render()
112 {
113 $dropDownList = static::$dropDownList;
114 $dropDownList .= '</ul></div>';
115
116 static::$dropDownList = null;
117 static::$loaded['JHtmlDropdown::start'] = false;
118
119 return $dropDownList;
120 }
121
122 123 124 125 126 127 128 129 130 131 132
133 public static function edit($id, $prefix = '', $customLink = '')
134 {
135 static::start();
136
137 if (!$customLink)
138 {
139 $option = JFactory::getApplication()->input->getCmd('option');
140 $link = 'index.php?option=' . $option;
141 }
142 else
143 {
144 $link = $customLink;
145 }
146
147 $link .= '&task=' . $prefix . 'edit&id=' . $id;
148 $link = JRoute::_($link);
149
150 static::addCustomItem(JText::_('JACTION_EDIT'), $link);
151
152 return;
153 }
154
155 156 157 158 159 160 161 162 163 164
165 public static function publish($checkboxId, $prefix = '')
166 {
167 $task = $prefix . 'publish';
168 static::addCustomItem(JText::_('JTOOLBAR_PUBLISH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
169
170 return;
171 }
172
173 174 175 176 177 178 179 180 181 182
183 public static function unpublish($checkboxId, $prefix = '')
184 {
185 $task = $prefix . 'unpublish';
186 static::addCustomItem(JText::_('JTOOLBAR_UNPUBLISH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
187
188 return;
189 }
190
191 192 193 194 195 196 197 198 199 200
201 public static function featured($checkboxId, $prefix = '')
202 {
203 $task = $prefix . 'featured';
204 static::addCustomItem(JText::_('JFEATURED'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
205
206 return;
207 }
208
209 210 211 212 213 214 215 216 217 218
219 public static function unfeatured($checkboxId, $prefix = '')
220 {
221 $task = $prefix . 'unfeatured';
222 static::addCustomItem(JText::_('JUNFEATURED'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
223
224 return;
225 }
226
227 228 229 230 231 232 233 234 235 236
237 public static function archive($checkboxId, $prefix = '')
238 {
239 $task = $prefix . 'archive';
240 static::addCustomItem(JText::_('JTOOLBAR_ARCHIVE'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
241
242 return;
243 }
244
245 246 247 248 249 250 251 252 253 254
255 public static function unarchive($checkboxId, $prefix = '')
256 {
257 $task = $prefix . 'unpublish';
258 static::addCustomItem(JText::_('JTOOLBAR_UNARCHIVE'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
259
260 return;
261 }
262
263 264 265 266 267 268 269 270 271 272
273 public static function trash($checkboxId, $prefix = '')
274 {
275 $task = $prefix . 'trash';
276 static::addCustomItem(JText::_('JTOOLBAR_TRASH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
277
278 return;
279 }
280
281 282 283 284 285 286 287 288 289 290
291 public static function untrash($checkboxId, $prefix = '')
292 {
293 $task = $prefix . 'publish';
294 static::addCustomItem(JText::_('JTOOLBAR_UNTRASH'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
295
296 return;
297 }
298
299 300 301 302 303 304 305 306 307 308
309 public static function checkin($checkboxId, $prefix = '')
310 {
311 $task = $prefix . 'checkin';
312 static::addCustomItem(JText::_('JTOOLBAR_CHECKIN'), 'javascript:void(0)', 'onclick="contextAction(\'' . $checkboxId . '\', \'' . $task . '\')"');
313
314 return;
315 }
316
317 318 319 320 321 322 323
324 public static function divider()
325 {
326 static::$dropDownList .= '<li class="divider"></li>';
327
328 return;
329 }
330
331 332 333 334 335 336 337 338 339 340 341 342 343 344
345 public static function addCustomItem($label, $link = 'javascript:void(0)', $linkAttributes = '', $className = '', $ajaxLoad = false,
346 $jsCallBackFunc = null)
347 {
348 static::start();
349
350 if ($ajaxLoad)
351 {
352 $href = ' href = "javascript:void(0)" onclick="loadAjax(\'' . $link . '\', \'' . $jsCallBackFunc . '\')"';
353 }
354 else
355 {
356 $href = ' href = "' . $link . '" ';
357 }
358
359 $dropDownList = static::$dropDownList;
360 $dropDownList .= '<li class="' . $className . '"><a ' . $linkAttributes . $href . ' >';
361 $dropDownList .= $label;
362 $dropDownList .= '</a></li>';
363 static::$dropDownList = $dropDownList;
364
365 return;
366 }
367 }
368