mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-18 02:21:47 -05:00
Refactored menu fading to be a plugin for extendability.
Need to find suitable place for the `.overlay` hideAway function call.
This commit is contained in:
parent
8b0763ee9c
commit
3057945b70
2 changed files with 28 additions and 12 deletions
|
@ -83,18 +83,6 @@
|
|||
|
||||
$(document).ready(function () {
|
||||
|
||||
// ## Set interactions for all menus
|
||||
// This finds all visible '.overlay' elements and hides them upon clicking away from the element itself.
|
||||
$("body").on('click', function (event) {
|
||||
var $target = $(event.target);
|
||||
if (!$target.parents().is(".overlay:visible") && !$target.is(".overlay:visible")) {
|
||||
$("body").find(".overlay:visible").fadeOut();
|
||||
|
||||
// Toggle active classes on menu headers
|
||||
$("[data-toggle].active").removeClass("active");
|
||||
}
|
||||
});
|
||||
|
||||
// LOGIN SCREEN
|
||||
$(window).trigger('resize');
|
||||
|
||||
|
|
28
core/client/assets/lib/jquery-utils.js
vendored
28
core/client/assets/lib/jquery-utils.js
vendored
|
@ -54,4 +54,32 @@
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Set interactions for all menus and overlays
|
||||
* This finds all visible 'hideClass' elements and hides them upon clicking away from the element itself.
|
||||
* A callback can be defined to customise the results. By default it will hide the element.
|
||||
* @param callback
|
||||
*/
|
||||
$.fn.hideAway = function (callback) {
|
||||
var $self = $(this);
|
||||
$("body").on('click', function (event) {
|
||||
var $target = $(event.target),
|
||||
hideClass = $self.selector;
|
||||
if (!$target.parents().is(hideClass + ":visible") && !$target.is(hideClass + ":visible")) {
|
||||
if (callback) {
|
||||
callback($("body").find(hideClass + ":visible"));
|
||||
} else {
|
||||
$("body").find(hideClass + ":visible").fadeOut();
|
||||
|
||||
// Toggle active classes on menu headers
|
||||
$("[data-toggle].active").removeClass("active");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
$('.overlay').hideAway(); // TODO: Move to a more sensible global file.
|
||||
|
||||
}());
|
Loading…
Add table
Reference in a new issue