getgrav / grav-plugin-shortcode-ui

Grav Shortcode UI Plugin
https://getgrav.org
MIT License
47 stars 11 forks source link

Add collapse functionality #5

Closed ArrowBaZ closed 7 years ago

ArrowBaZ commented 8 years ago

Button with title and a hide panel

matbrgz commented 7 years ago

+1

cord commented 7 years ago

The shortcode can be used like this:

[ui-collapse title="MyTitle"]
some content to hide
[/ui-collapse]
cord commented 7 years ago

@rhukster this works great OOTB - please merge

cord commented 7 years ago

When placing collapse into tabs, only the first work.

following an alternativ jquery solution ui-collapse.js which works within tabs as well

$(document).ready(function() {
    $('[data-toggle="collapse"]').click(function(event) {
        event.preventDefault();
        $(this).toggleClass("active");
        cEl = $(this).next();
        if ($(this).hasClass('active')) {
            cEl.fadeIn();
        } else {
            cEl.fadeOut();
        }
    });
});

and ui-collapse.html.twig

<button data-toggle="collapse" data-target="collapse-{{ hash }}">{{ title }}</button>
<div id="collapse-{{ hash }}" class="collapse-wrapper" style="display:none">
    <div class="collapse-inner">
        {{ content }}
    </div>
</div>
rhukster commented 7 years ago

Thanks for reminding me about this! I actually wanted to build a more flexible accordian shortcode rather than a simple collapse shortcode. The accordian shortcode I just added is CSS3 only and doesn't need any JS. Also it can be configured as a traditional accordian, or independent panels. it also has indicator arrows, and can be used to show just one panel i you wish. It kinda makes this PR redundant.