TbHtml::carouselIndicators PHP Method

carouselIndicators() public static method

Generates an indicator for the carousel.
public static carouselIndicators ( string $target, integer $numSlides, array $htmlOptions = [] ) : string
$target string the CSS selector for the target element.
$numSlides integer the number of slides.
$htmlOptions array additional HTML attributes.
return string the generated indicators.
    public static function carouselIndicators($target, $numSlides, $htmlOptions = array())
    {
        self::addCssClass('carousel-indicators', $htmlOptions);
        $output = self::openTag('ol', $htmlOptions);
        for ($i = 0; $i < $numSlides; $i++) {
            $itemOptions = array('data-target' => $target, 'data-slide-to' => $i);
            if ($i === 0) {
                $itemOptions['class'] = 'active';
            }
            $output .= self::tag('li', $itemOptions, '', true);
        }
        $output .= '</ol>';
        return $output;
    }

Usage Example

Exemplo n.º 1
0
 public function testCarouselIndicators()
 {
     $I = $this->codeGuy;
     $html = TbHtml::carouselIndicators('#', 3, array('class' => 'list'));
     $ol = $I->createNode($html, 'ol.carousel-indicators');
     $I->seeNodeCssClass($ol, 'list');
     $I->seeNodeChildren($ol, array('li.active', 'li', 'li'));
     foreach ($ol->filter('li') as $i => $element) {
         $node = $I->createNode($element);
         $I->seeNodeAttributes($node, array('data-target' => '#', 'data-slide-to' => $i));
         $I->seeNodeEmpty($node);
     }
 }
TbHtml