Ghost/core/client/toggle.js

40 lines
1.0 KiB
JavaScript
Raw Normal View History

2013-05-11 20:44:25 +04:00
// # Toggle Support
/*global document, $, Ghost */
(function () {
2013-05-11 20:44:25 +04:00
"use strict";
Ghost.temporary.initToggles = function ($el) {
$el.find('[data-toggle]').each(function () {
2013-05-11 20:44:25 +04:00
var toggle = $(this).data('toggle');
$(this).parent().children(toggle).hide();
});
$el.find('[data-toggle]').on('click', function (e) {
2013-05-11 20:44:25 +04:00
e.preventDefault();
e.stopPropagation();
2013-05-11 20:44:25 +04:00
$(this).toggleClass('active');
var toggle = $(this).data('toggle');
$(this).parent().children(toggle).fadeToggle(200).toggleClass('open');
2013-05-11 20:44:25 +04:00
});
};
$(document).ready(function () {
// ## Toggle Up In Your Grill
// Allows for toggling via data-attributes.
// ### Usage
// <nav>
// <a href="#" data-toggle=".toggle-me">Toggle</a>
// <ul class="toggle-me">
// <li>Toggled yo</li>
// </ul>
// </nav>
Ghost.temporary.initToggles($(document));
2013-05-11 20:44:25 +04:00
});
}());