1
0
Fork 0
mirror of https://github.com/TryGhost/Ghost-Admin.git synced 2023-12-14 02:33:04 +01: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:
Matthew Harrison-Jones 2013-07-26 12:32:26 +01:00
parent a5290b06ba
commit 74f4c3f5fc
2 changed files with 28 additions and 12 deletions

View file

@ -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');

View file

@ -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.
}());