[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2012 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\HTML\Helpers; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Layout\FileLayout; 15 use Joomla\CMS\Layout\LayoutHelper; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Utility class for Bootstrap elements. 23 * 24 * @since 3.0 25 */ 26 abstract class Bootstrap 27 { 28 /** 29 * @var array Array containing information for loaded files 30 * @since 3.0 31 */ 32 protected static $loaded = []; 33 34 /** 35 * Add javascript support for Bootstrap alerts 36 * 37 * @param string $selector Common class for the alerts 38 * 39 * @return void 40 * 41 * @throws \Exception 42 * 43 * @since 3.0 44 */ 45 public static function alert($selector = ''): void 46 { 47 // Only load once 48 if (!empty(static::$loaded[__METHOD__][$selector])) { 49 return; 50 } 51 52 $doc = Factory::getDocument(); 53 54 if ($selector !== '') { 55 $scriptOptions = $doc->getScriptOptions('bootstrap.alert'); 56 $options = [$selector]; 57 58 if (is_array($scriptOptions)) { 59 $options = array_merge($scriptOptions, $options); 60 } 61 62 $doc->addScriptOptions('bootstrap.alert', $options, false); 63 } 64 65 // Include the Bootstrap component 66 Factory::getApplication() 67 ->getDocument() 68 ->getWebAssetManager() 69 ->useScript('bootstrap.alert'); 70 71 static::$loaded[__METHOD__][$selector] = true; 72 } 73 74 /** 75 * Add javascript support for Bootstrap buttons 76 * 77 * @param string $selector Common class for the buttons 78 * 79 * @return void 80 * 81 * @throws \Exception 82 * 83 * @since 3.1 84 */ 85 public static function button($selector = ''): void 86 { 87 // Only load once 88 if (!empty(static::$loaded[__METHOD__][$selector])) { 89 return; 90 } 91 92 $doc = Factory::getDocument(); 93 94 if ($selector !== '') { 95 $scriptOptions = $doc->getScriptOptions('bootstrap.button'); 96 $options = [$selector]; 97 98 if (is_array($scriptOptions)) { 99 $options = array_merge($scriptOptions, $options); 100 } 101 102 $doc->addScriptOptions('bootstrap.button', $options, false); 103 } 104 105 // Include the Bootstrap component 106 Factory::getApplication() 107 ->getDocument() 108 ->getWebAssetManager() 109 ->useScript('bootstrap.button'); 110 111 static::$loaded[__METHOD__][$selector] = true; 112 } 113 114 /** 115 * Add javascript support for Bootstrap carousels 116 * 117 * @param string $selector Common class for the carousels. 118 * @param array $params An array of options for the carousel. 119 * 120 * @return void 121 * 122 * @throws \Exception 123 * 124 * @since 3.0 125 * 126 * Options for the carousel can be: 127 * - interval number 5000 The amount of time to delay between automatically cycling an item. 128 * If false, carousel will not automatically cycle. 129 * - keyboard boolean true Whether the carousel should react to keyboard events. 130 * - pause string| hover Pauses the cycling of the carousel on mouseenter and resumes the cycling 131 * boolean of the carousel on mouseleave. 132 * - slide string| false Autoplays the carousel after the user manually cycles the first item. 133 * boolean If "carousel", autoplays the carousel on load. 134 */ 135 public static function carousel($selector = '', $params = []): void 136 { 137 // Only load once 138 if (!empty(static::$loaded[__METHOD__][$selector])) { 139 return; 140 } 141 142 if ($selector !== '') { 143 // Setup options object 144 $opt['interval'] = isset($params['interval']) ? (int) $params['interval'] : 5000; 145 $opt['keyboard'] = isset($params['keyboard']) ? (bool) $params['keyboard'] : true; 146 $opt['pause'] = isset($params['pause']) ? $params['pause'] : 'hover'; 147 $opt['slide'] = isset($params['slide']) ? (bool) $params['slide'] : false; 148 $opt['wrap'] = isset($params['wrap']) ? (bool) $params['wrap'] : true; 149 $opt['touch'] = isset($params['touch']) ? (bool) $params['touch'] : true; 150 151 Factory::getDocument()->addScriptOptions('bootstrap.carousel', [$selector => (object) array_filter((array) $opt)]); 152 } 153 154 // Include the Bootstrap component 155 Factory::getApplication() 156 ->getDocument() 157 ->getWebAssetManager() 158 ->useScript('bootstrap.carousel'); 159 160 static::$loaded[__METHOD__][$selector] = true; 161 } 162 163 /** 164 * Add javascript support for Bootstrap collapse 165 * 166 * @param string $selector Common class for the collapse 167 * @param string[] $params Additional parameters - see below 168 * 169 * @return void 170 * 171 * @throws \Exception 172 * 173 * @since 4.0.0 174 * 175 * Options for the collapse can be: 176 * - parent string false If parent is provided, then all collapsible elements under the specified parent will 177 * be closed when this collapsible item is shown. 178 * - toggle boolean true Toggles the collapsible element on invocation 179 */ 180 public static function collapse($selector = '', $params = []): void 181 { 182 // Only load once 183 if (!empty(static::$loaded[__METHOD__][$selector])) { 184 return; 185 } 186 187 if ($selector !== '') { 188 // Setup options object 189 $opt = []; 190 $opt['parent'] = isset($params['parent']) ? $params['parent'] : false; 191 $opt['toggle'] = isset($params['toggle']) ? (bool) $params['toggle'] : true; 192 193 Factory::getDocument()->addScriptOptions('bootstrap.collapse', [$selector => (object) array_filter((array) $opt)]); 194 } 195 196 // Include the Bootstrap component 197 Factory::getApplication() 198 ->getDocument() 199 ->getWebAssetManager() 200 ->useScript('bootstrap.collapse'); 201 202 static::$loaded[__METHOD__][$selector] = true; 203 } 204 205 /** 206 * Add javascript support for Bootstrap dropdowns 207 * 208 * @param string $selector Common class for the dropdowns 209 * @param array $params The options for the dropdowns 210 * 211 * @return void 212 * 213 * @since 4.0.0 214 * 215 * Options for the collapse can be: 216 * - flip boolean true Allow Dropdown to flip in case of an overlapping on the reference element 217 * - boundary string scrollParent Overflow constraint boundary of the dropdown menu 218 * - reference string toggle Reference element of the dropdown menu. Accepts 'toggle' or 'parent' 219 * - display string dynamic By default, we use Popper for dynamic positioning. Disable this with static 220 */ 221 public static function dropdown($selector = '', $params = []): void 222 { 223 // Only load once 224 if (!empty(static::$loaded[__METHOD__][$selector])) { 225 return; 226 } 227 228 if ($selector !== '') { 229 // Setup options object 230 $opt = []; 231 $opt['flip'] = isset($params['flip']) ? $params['flip'] : true; 232 $opt['boundary'] = isset($params['boundary']) ? $params['boundary'] : 'scrollParent'; 233 $opt['reference'] = isset($params['reference']) ? $params['reference'] : 'toggle'; 234 $opt['display'] = isset($params['display']) ? $params['display'] : 'dynamic'; 235 $opt['popperConfig'] = isset($params['popperConfig']) ? (bool) $params['popperConfig'] : true; 236 237 Factory::getDocument()->addScriptOptions('bootstrap.dropdown', [$selector => (object) array_filter((array) $opt)]); 238 } 239 240 // Include the Bootstrap component 241 Factory::getApplication() 242 ->getDocument() 243 ->getWebAssetManager() 244 ->useScript('bootstrap.dropdown'); 245 246 static::$loaded[__METHOD__][$selector] = true; 247 } 248 249 /** 250 * Add javascript support for Bootstrap modal 251 * 252 * @param string $selector The ID selector for the modal. 253 * @param array $options An array of options for the modal. 254 * 255 * @return void 256 * 257 * @since 4.0.0 258 * 259 * Options for the modal can be: 260 * - backdrop string| true Includes a modal-backdrop element. Alternatively, specify static 261 * boolean for a backdrop which doesn't close the modal on click. 262 * - keyboard boolean true Closes the modal when escape key is pressed 263 * - focus boolean true Closes the modal when escape key is pressed 264 */ 265 public static function modal($selector = '', $options = []): void 266 { 267 // Only load once 268 if (!empty(static::$loaded[__METHOD__][$selector])) { 269 return; 270 } 271 272 if ($selector !== '') { 273 // Setup options object 274 $opt['backdrop'] = isset($options['backdrop']) ? $options['backdrop'] : false; 275 $opt['keyboard'] = isset($options['keyboard']) ? (bool) $options['keyboard'] : true; 276 $opt['focus'] = isset($options['focus']) ? (bool) $options['focus'] : true; 277 278 Factory::getDocument()->addScriptOptions('bootstrap.modal', [$selector => (object) array_filter((array) $opt)]); 279 } 280 281 // Include the Bootstrap component 282 Factory::getApplication() 283 ->getDocument() 284 ->getWebAssetManager() 285 ->useScript('bootstrap.modal'); 286 287 static::$loaded[__METHOD__][$selector] = true; 288 } 289 290 /** 291 * Add javascript support for Bootstrap offcanvas 292 * 293 * @param string $selector The ID selector for the offcanvas. 294 * @param array $options An array of options for the offcanvas. 295 * 296 * @return void 297 * 298 * @since 4.0.0 299 * 300 * Options for the offcanvas can be: 301 * - backdrop boolean true Apply a backdrop on body while offcanvas is open 302 * - keyboard boolean true Closes the offcanvas when escape key is pressed 303 * - scroll boolean false Allow body scrolling while offcanvas is open 304 */ 305 public static function offcanvas($selector = '', $options = []): void 306 { 307 // Only load once 308 if (!empty(static::$loaded[__METHOD__][$selector])) { 309 return; 310 } 311 312 if ($selector !== '') { 313 // Setup options object 314 $opt['backdrop'] = isset($options['backdrop']) ? (bool) $options['backdrop'] : true; 315 $opt['keyboard'] = isset($options['keyboard']) ? (bool) $options['keyboard'] : true; 316 $opt['scroll'] = isset($options['scroll']) ? (bool) $options['scroll'] : false; 317 318 Factory::getDocument()->addScriptOptions('bootstrap.offcanvas', [$selector => (object) array_filter((array) $opt)]); 319 } 320 321 // Include the Bootstrap component 322 Factory::getApplication() 323 ->getDocument() 324 ->getWebAssetManager() 325 ->useScript('bootstrap.offcanvas'); 326 327 static::$loaded[__METHOD__][$selector] = true; 328 } 329 330 /** 331 * Add javascript support for Bootstrap popovers 332 * 333 * Use element's Title as popover content 334 * 335 * @param string $selector Selector for the popover 336 * @param array $options The options for the popover 337 * 338 * @return void 339 * 340 * @since 3.0 341 * 342 * - Options for the popover can be: 343 * - animation boolean true Apply a CSS fade transition to the popover 344 * - container string| false Appends the popover to a specific element. Eg.: 'body' 345 * boolean 346 * - content string null Default content value if data-bs-content attribute isn't present 347 * - delay number 0 Delay showing and hiding the popover (ms) 348 * does not apply to manual trigger type 349 * - html boolean true Insert HTML into the popover. If false, innerText property will be used 350 * to insert content into the DOM. 351 * - placement string right How to position the popover - auto | top | bottom | left | right. 352 * When auto is specified, it will dynamically reorient the popover 353 * - selector string false If a selector is provided, popover objects will be delegated to the 354 * specified targets. 355 * - template string null Base HTML to use when creating the popover. 356 * - title string null Default title value if `title` tag isn't present 357 * - trigger string click How popover is triggered - click | hover | focus | manual 358 * - offset integer 0 Offset of the popover relative to its target. 359 */ 360 public static function popover($selector = '', $options = []): void 361 { 362 // Only load once 363 if (isset(static::$loaded[__METHOD__][$selector])) { 364 return; 365 } 366 367 if ($selector !== '') { 368 // Setup options object 369 $opt['animation'] = isset($options['animation']) ? (bool) $options['animation'] : true; 370 $opt['container'] = isset($options['container']) ? $options['container'] : 'body'; 371 $opt['content'] = isset($options['content']) ? $options['content'] : null; 372 $opt['delay'] = isset($options['delay']) ? (int) $options['delay'] : [ 'show' => 50, 'hide' => 200 ]; 373 $opt['html'] = isset($options['html']) ? (bool) $options['html'] : true; 374 $opt['placement'] = isset($options['placement']) ? $options['placement'] : null; 375 $opt['selector'] = isset($options['selector']) ? $options['selector'] : false; 376 $opt['template'] = isset($options['template']) ? $options['template'] : null; 377 $opt['title'] = isset($options['title']) ? $options['title'] : null; 378 $opt['trigger'] = isset($options['trigger']) ? $options['trigger'] : 'click'; 379 $opt['offset'] = isset($options['offset']) ? $options['offset'] : [0, 10]; 380 $opt['fallbackPlacement'] = isset($options['fallbackPlacement']) ? $options['fallbackPlacement'] : null; 381 $opt['boundary'] = isset($options['boundary']) ? $options['boundary'] : 'scrollParent'; 382 $opt['customClass'] = isset($options['customClass']) ? $options['customClass'] : null; 383 $opt['sanitize'] = isset($options['sanitize']) ? (bool) $options['sanitize'] : null; 384 $opt['allowList'] = isset($options['allowList']) ? $options['allowList'] : null; 385 386 Factory::getDocument()->addScriptOptions('bootstrap.popover', [$selector => (object) array_filter((array) $opt)]); 387 } 388 389 // Include the Bootstrap component 390 Factory::getApplication() 391 ->getDocument() 392 ->getWebAssetManager() 393 ->useScript('bootstrap.popover'); 394 395 static::$loaded[__METHOD__][$selector] = true; 396 } 397 398 /** 399 * Add javascript support for Bootstrap Scrollspy 400 * 401 * @param string $selector The ID selector for the ScrollSpy element. 402 * @param array $options An array of options for the ScrollSpy. 403 * 404 * @return void 405 * 406 * @since 3.0 407 * 408 * Options for the Scrollspy can be: 409 * - offset number Pixels to offset from top when calculating position of scroll. 410 * - method string Finds which section the spied element is in. 411 * - target string Specifies element to apply Scrollspy plugin. 412 */ 413 public static function scrollspy($selector = '', $options = []): void 414 { 415 // Only load once 416 if (isset(static::$loaded[__METHOD__][$selector])) { 417 return; 418 } 419 420 if ($selector !== '') { 421 // Setup options object 422 $opt['offset'] = isset($options['offset']) ? (int) $options['offset'] : 10; 423 $opt['method'] = isset($options['method']) ? $options['method'] : 'auto'; 424 $opt['target'] = isset($options['target']) ? $options['target'] : null; 425 426 Factory::getDocument()->addScriptOptions('bootstrap.scrollspy', [$selector => (object) array_filter((array) $opt)]); 427 } 428 429 // Include the Bootstrap component 430 Factory::getApplication() 431 ->getDocument() 432 ->getWebAssetManager() 433 ->useScript('bootstrap.scrollspy'); 434 435 static::$loaded[__METHOD__][$selector] = true; 436 } 437 438 /** 439 * Add javascript support for Bootstrap tab 440 * 441 * @param string $selector Common class for the tabs 442 * @param array $options Options for the tabs 443 * 444 * @return void 445 * 446 * @throws \Exception 447 * 448 * @since 4.0.0 449 */ 450 public static function tab($selector = '', $options = []): void 451 { 452 // Only load once 453 if (!empty(static::$loaded[__METHOD__][$selector])) { 454 return; 455 } 456 457 if ($selector !== '') { 458 Factory::getDocument()->addScriptOptions('bootstrap.tabs', [$selector => (object) $options]); 459 } 460 461 // Include the Bootstrap component 462 Factory::getApplication() 463 ->getDocument() 464 ->getWebAssetManager() 465 ->useScript('bootstrap.tab'); 466 467 static::$loaded[__METHOD__][$selector] = true; 468 } 469 470 /** 471 * Add javascript support for Bootstrap tooltips 472 * 473 * Add a title attribute to any element in the form 474 * title="title::text" 475 * 476 * @param string $selector The ID selector for the tooltip. 477 * @param array $options An array of options for the tooltip. 478 * 479 * @return void 480 * 481 * @since 3.0 482 * 483 * Options for the tooltip can be: 484 * - animation boolean apply a css fade transition to the popover 485 * - container string|boolean Appends the popover to a specific element: { container: 'body' } 486 * - delay number|object delay showing and hiding the popover (ms) - does not apply to manual trigger type 487 * If a number is supplied, delay is applied to both hide/show 488 * Object structure is: delay: { show: 500, hide: 100 } 489 * - html boolean Insert HTML into the popover. If false, jQuery's text method will be used to 490 * insert content into the dom. 491 * - placement string|function how to position the popover - top | bottom | left | right 492 * - selector string If a selector is provided, popover objects will be 493 * delegated to the specified targets. 494 * - template string Base HTML to use when creating the popover. 495 * - title string|function default title value if `title` tag isn't present 496 * - trigger string how popover is triggered - hover | focus | manual 497 * - constraints array An array of constraints - passed through to Popper. 498 * - offset string Offset of the popover relative to its target. 499 */ 500 public static function tooltip($selector = '', $options = []): void 501 { 502 // Only load once 503 if (isset(static::$loaded[__METHOD__][$selector])) { 504 return; 505 } 506 507 if ($selector !== '') { 508 // Setup options object 509 $opt['animation'] = isset($options['animation']) ? (bool) $options['animation'] : true; 510 $opt['container'] = isset($options['container']) ? $options['container'] : 'body'; 511 $opt['delay'] = isset($options['delay']) ? (int) $options['delay'] : 0; 512 $opt['html'] = isset($options['html']) ? (bool) $options['html'] : true; 513 $opt['placement'] = isset($options['placement']) ? $options['placement'] : null; 514 $opt['selector'] = isset($options['selector']) ? $options['selector'] : false; 515 $opt['template'] = isset($options['template']) ? $options['template'] : null; 516 $opt['title'] = isset($options['title']) ? $options['title'] : null; 517 $opt['trigger'] = isset($options['trigger']) ? $options['trigger'] : 'hover focus'; 518 $opt['fallbackPlacement'] = isset($options['fallbackPlacement']) ? $options['fallbackPlacement'] : null; 519 $opt['boundary'] = isset($options['boundary']) ? $options['boundary'] : 'clippingParents'; 520 $opt['customClass'] = isset($options['customClass']) ? $options['customClass'] : null; 521 $opt['sanitize'] = isset($options['sanitize']) ? (bool) $options['sanitize'] : true; 522 $opt['allowList'] = isset($options['allowList']) ? $options['allowList'] : null; 523 524 Factory::getDocument()->addScriptOptions('bootstrap.tooltip', [$selector => (object) array_filter((array) $opt)]); 525 } 526 527 // Include the Bootstrap component 528 Factory::getApplication() 529 ->getDocument() 530 ->getWebAssetManager() 531 ->useScript('bootstrap.popover'); 532 533 // Set static array 534 static::$loaded[__METHOD__][$selector] = true; 535 } 536 537 /** 538 * Add javascript support for Bootstrap toasts 539 * 540 * @param string $selector Common class for the toasts 541 * @param array $options Options for the toasts 542 * 543 * @return void 544 * 545 * @throws \Exception 546 * 547 * @since 4.0.0 548 */ 549 public static function toast($selector = '', $options = []): void 550 { 551 // Only load once 552 if (!empty(static::$loaded[__METHOD__][$selector])) { 553 return; 554 } 555 556 if ($selector !== '') { 557 // Setup options object 558 $opt['animation'] = isset($options['animation']) ? (string) $options['animation'] : null; 559 $opt['autohide'] = isset($options['autohide']) ? (bool) $options['autohide'] : true; 560 $opt['delay'] = isset($options['delay']) ? (int) $options['delay'] : 5000; 561 562 Factory::getDocument()->addScriptOptions('bootstrap.toast', [$selector => (object) array_filter((array) $opt)]); 563 } 564 565 // Include the Bootstrap component 566 Factory::getApplication() 567 ->getDocument() 568 ->getWebAssetManager() 569 ->useScript('bootstrap.toast'); 570 571 static::$loaded[__METHOD__][$selector] = true; 572 } 573 574 /** 575 * Method to load the ALL the Bootstrap Components 576 * 577 * If debugging mode is on an uncompressed version of Bootstrap is included for easier debugging. 578 * 579 * @param mixed $debug Is debugging mode on? [optional] 580 * 581 * @return void 582 * 583 * @since 3.0 584 * @deprecated 5.0 585 */ 586 public static function framework($debug = null): void 587 { 588 $wa = Factory::getApplication() 589 ->getDocument() 590 ->getWebAssetManager(); 591 592 array_map( 593 function ($script) use ($wa) { 594 $wa->useScript('bootstrap.' . $script); 595 }, 596 ['alert', 'button', 'carousel', 'collapse', 'dropdown', 'modal', 'offcanvas', 'popover', 'scrollspy', 'tab', 'toast'] 597 ); 598 } 599 600 /** 601 * Loads CSS files needed by Bootstrap 602 * 603 * @param boolean $includeMainCss If true, main bootstrap.css files are loaded 604 * @param string $direction rtl or ltr direction. If empty, ltr is assumed 605 * @param array $attribs Optional array of attributes to be passed to HTMLHelper::_('stylesheet') 606 * 607 * @return void 608 * 609 * @since 3.0 610 */ 611 public static function loadCss($includeMainCss = true, $direction = 'ltr', $attribs = []): void 612 { 613 // Load Bootstrap main CSS 614 if ($includeMainCss) { 615 Factory::getDocument()->getWebAssetManager()->useStyle('bootstrap.css'); 616 } 617 } 618 619 /** 620 * Add javascript support for Bootstrap accordions and insert the accordion 621 * 622 * @param string $selector The ID selector for the tooltip. Expects a valid ID without the #! 623 * @param array $options An array of options for the tooltip. 624 * 625 * @return string HTML for the accordion 626 * 627 * @since 3.0 628 * 629 * Options for the tooltip can be: 630 * - parent selector If selector then all collapsible elements under the specified parent will be closed when this 631 * collapsible item is shown. (similar to traditional accordion behavior) 632 * - toggle boolean Toggles the collapsible element on invocation 633 * - active string Sets the active slide during load 634 */ 635 public static function startAccordion($selector = 'myAccordian', $options = []): string 636 { 637 // Only load once 638 if (isset(static::$loaded[__METHOD__][$selector])) { 639 return ''; 640 } 641 642 // Include Bootstrap component 643 Factory::getApplication() 644 ->getDocument() 645 ->getWebAssetManager() 646 ->useScript('bootstrap.collapse'); 647 648 // Setup options object 649 $opt['parent'] = isset($options['parent']) ? 650 ($options['parent'] == true ? '#' . preg_replace('/^[\.#]/', '', $selector) : $options['parent']) : ''; 651 $opt['toggle'] = isset($options['toggle']) ? (bool) $options['toggle'] : !($opt['parent'] === false || isset($options['active'])); 652 $opt['active'] = isset($options['active']) ? (string) $options['active'] : ''; 653 654 // Initialise with the Joomla specifics 655 $opt['isJoomla'] = true; 656 657 Factory::getDocument()->addScriptOptions('bootstrap.accordion', ['#' . preg_replace('/^[\.#]/', '', $selector) => (object) array_filter((array) $opt)]); 658 659 static::$loaded[__METHOD__][$selector] = $opt; 660 661 return '<div id="' . $selector . '" class="accordion" role="tablist">'; 662 } 663 664 /** 665 * Close the current accordion 666 * 667 * @return string HTML to close the accordion 668 * 669 * @since 3.0 670 */ 671 public static function endAccordion(): string 672 { 673 return '</div>'; 674 } 675 676 /** 677 * Begins the display of a new accordion slide. 678 * 679 * @param string $selector Identifier of the accordion group. 680 * @param string $text Text to display. 681 * @param string $id Identifier of the slide. 682 * @param string $class Class of the accordion group. 683 * 684 * @return string HTML to add the slide 685 * 686 * @since 3.0 687 */ 688 public static function addSlide($selector, $text, $id, $class = ''): string 689 { 690 $in = static::$loaded[__CLASS__ . '::startAccordion'][$selector]['active'] === $id ? ' show' : ''; 691 $collapsed = static::$loaded[__CLASS__ . '::startAccordion'][$selector]['active'] === $id ? '' : ' collapsed'; 692 $parent = static::$loaded[__CLASS__ . '::startAccordion'][$selector]['parent'] ? 693 'data-bs-parent="' . static::$loaded[__CLASS__ . '::startAccordion'][$selector]['parent'] . '"' : ''; 694 $class = (!empty($class)) ? ' ' . $class : ''; 695 $ariaExpanded = $in === 'show' ? true : false; 696 697 return <<<HTMLSTR 698 <div class="accordion-item $class"> 699 <h2 class="accordion-header" id="$id-heading"> 700 <button class="accordion-button $collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#$id" aria-expanded="$ariaExpanded" aria-controls="$id" role="tab"> 701 $text 702 </button> 703 </h2> 704 <div id="$id" class="accordion-collapse collapse $in" aria-labelledby="$id-heading" $parent role="tabpanel"> 705 <div class="accordion-body"> 706 HTMLSTR; 707 } 708 709 /** 710 * Close the current slide 711 * 712 * @return string HTML to close the slide 713 * 714 * @since 3.0 715 */ 716 public static function endSlide(): string 717 { 718 return <<<HTMLSTR 719 </div> 720 </div> 721 </div> 722 HTMLSTR; 723 } 724 725 /** 726 * Method to render a Bootstrap modal 727 * 728 * @param string $selector The ID selector for the modal. Expects a valid ID without the #! 729 * @param array $options An array of options for the modal. 730 * @param string $body Markup for the modal body. Appended after the `<iframe>` if the URL option is set 731 * 732 * @return string HTML markup for a modal 733 * 734 * @since 3.0 735 * 736 * Options for the modal can be: 737 * - backdrop string| true Includes a modal-backdrop element. Alternatively, specify static 738 * boolean for a backdrop which doesn't close the modal on click. 739 * - keyboard boolean true Closes the modal when escape key is pressed 740 * - focus boolean true Closes the modal when escape key is pressed 741 * - title string null The modal title 742 * - closeButton boolean true Display modal close button (default = true) 743 * - footer string null Optional markup for the modal footer 744 * - url string null URL of a resource to be inserted as an `<iframe>` inside the modal body 745 * - height string null Height of the `<iframe>` containing the remote resource 746 * - width string null Width of the `<iframe>` containing the remote resource 747 */ 748 public static function renderModal($selector = 'modal', $options = [], $body = ''): string 749 { 750 // Only load once 751 if (!empty(static::$loaded[__METHOD__][$selector])) { 752 return ''; 753 } 754 755 // Initialise with the Joomla specifics 756 $options['isJoomla'] = true; 757 758 // Include Basic Bootstrap component 759 HTMLHelper::_('bootstrap.modal', '#' . preg_replace('/^[\.#]/', '', $selector), $options); 760 761 $layoutData = [ 762 'selector' => $selector, 763 'params' => $options, 764 'body' => $body, 765 ]; 766 767 static::$loaded[__METHOD__][$selector] = true; 768 769 return LayoutHelper::render('libraries.html.bootstrap.modal.main', $layoutData); 770 } 771 772 /** 773 * Creates a tab pane 774 * 775 * @param string $selector The pane identifier. Expects a valid ID without the #! 776 * @param array $params The parameters for the pane 777 * 778 * @return string 779 * 780 * @since 3.1 781 */ 782 public static function startTabSet($selector = 'myTab', $params = []): string 783 { 784 $sig = md5(serialize([$selector, $params])); 785 786 if (!isset(static::$loaded[__METHOD__][$sig])) { 787 // Setup options object 788 $opt['active'] = (isset($params['active']) && ($params['active'])) ? (string) $params['active'] : ''; 789 790 // Initialise with the Joomla specifics 791 $opt['isJoomla'] = true; 792 793 // Include the Bootstrap Tab Component 794 HTMLHelper::_('bootstrap.tab', '#' . preg_replace('/^[\.#]/', '', $selector), $opt); 795 796 // Set static array 797 static::$loaded[__METHOD__][$sig] = true; 798 static::$loaded[__METHOD__][$selector]['active'] = $opt['active']; 799 800 return LayoutHelper::render('libraries.html.bootstrap.tab.starttabset', ['selector' => $selector]); 801 } 802 } 803 804 /** 805 * Close the current tab pane 806 * 807 * @return string HTML to close the pane 808 * 809 * @since 3.1 810 */ 811 public static function endTabSet(): string 812 { 813 return LayoutHelper::render('libraries.html.bootstrap.tab.endtabset'); 814 } 815 816 /** 817 * Begins the display of a new tab content panel. 818 * 819 * @param string $selector Identifier of the panel. Expects a valid ID without the #! 820 * @param string $id The ID of the div element. Expects a valid ID without the #! 821 * @param string $title The title text for the new UL tab 822 * 823 * @return string HTML to start a new panel 824 * 825 * @since 3.1 826 */ 827 public static function addTab($selector, $id, $title): string 828 { 829 static $tabLayout = null; 830 831 $tabLayout = $tabLayout === null ? new FileLayout('libraries.html.bootstrap.tab.addtab') : $tabLayout; 832 $active = (static::$loaded[__CLASS__ . '::startTabSet'][$selector]['active'] == $id) ? ' active' : ''; 833 834 return $tabLayout->render(['id' => preg_replace('/^[\.#]/', '', $id), 'active' => $active, 'title' => $title]); 835 } 836 837 /** 838 * Close the current tab content panel 839 * 840 * @return string HTML to close the pane 841 * 842 * @since 3.1 843 */ 844 public static function endTab(): string 845 { 846 return LayoutHelper::render('libraries.html.bootstrap.tab.endtab'); 847 } 848 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |