mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-26 12:21:36 +03:00
ebe70534c2
Fixes #788 - Toggles now close all any other open toggles. - Added .active class for post settings menu to ensure highlight stays on settings icon/button until it is closed, not just on hover.
58 lines
1.6 KiB
JavaScript
58 lines
1.6 KiB
JavaScript
// # Toggle Support
|
||
|
||
/*global document, $, Ghost */
|
||
(function () {
|
||
"use strict";
|
||
|
||
Ghost.temporary.hideToggles = function () {
|
||
$('[data-toggle]').each(function () {
|
||
var toggle = $(this).data('toggle');
|
||
$(this).parent().children(toggle + ':visible').fadeOut();
|
||
});
|
||
|
||
// Toggle active classes on menu headers
|
||
$("[data-toggle].active").removeClass("active");
|
||
};
|
||
|
||
Ghost.temporary.initToggles = function ($el) {
|
||
|
||
$el.find('[data-toggle]').each(function () {
|
||
var toggle = $(this).data('toggle');
|
||
$(this).parent().children(toggle).hide();
|
||
});
|
||
|
||
$el.find('[data-toggle]').on('click', function (e) {
|
||
e.preventDefault();
|
||
e.stopPropagation();
|
||
var $this = $(this),
|
||
toggle = $this.data('toggle'),
|
||
isAlreadyActive = $this.is('.active');
|
||
|
||
// Close all the other open toggle menus
|
||
Ghost.temporary.hideToggles();
|
||
|
||
if (!isAlreadyActive) {
|
||
$this.toggleClass('active');
|
||
$(this).parent().children(toggle).toggleClass('open').fadeToggle(200);
|
||
}
|
||
});
|
||
|
||
};
|
||
|
||
|
||
$(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));
|
||
});
|
||
|
||
}());
|