Rewrite dropdown menu

This commit is contained in:
Frederic Guillot
2015-08-07 22:42:29 -04:00
parent 2d5621af2f
commit 679cb94de4
14 changed files with 172 additions and 377 deletions

File diff suppressed because one or more lines are too long

View File

@@ -1,10 +1,11 @@
function App() {
this.popover = new Popover(this);
this.markdown = new Markdown();
this.sidebar = new Sidebar();
this.search = new Search();
this.tooltip = new Tooltip(this);
this.swimlane = new Swimlane();
this.dropdown = new Dropdown();
this.tooltip = new Tooltip(this);
this.popover = new Popover(this);
this.keyboardShortcuts();
this.boardSelector();
this.listen();
@@ -33,15 +34,12 @@ App.prototype.listen = function() {
this.markdown.listen();
this.sidebar.listen();
this.tooltip.listen();
this.dropdown.listen();
this.search.listen();
this.search.focus();
this.taskAutoComplete();
this.datePicker();
this.focus();
// Dropdown
$(".dropit-submenu").hide();
$('.dropdown').not(".dropit").dropit({ triggerParentEl : "span" });
};
App.prototype.focus = function() {
@@ -67,6 +65,8 @@ App.prototype.poll = function() {
};
App.prototype.keyboardShortcuts = function() {
var self = this;
// Submit form
Mousetrap.bindGlobal("mod+enter", function() {
$("form").submit();
@@ -77,6 +77,12 @@ App.prototype.keyboardShortcuts = function() {
e.preventDefault();
$('#board-selector').trigger('chosen:open');
});
// Close popover and dropdown
Mousetrap.bindGlobal("esc", function() {
self.popover.close();
self.dropdown.close();
});
};
App.prototype.checkSession = function() {

36
assets/js/src/Dropdown.js Normal file
View File

@@ -0,0 +1,36 @@
function Dropdown() {
}
Dropdown.prototype.listen = function() {
var self = this;
$(document).on('click', function() {
self.close();
});
$(document).on('click', '.dropdown-menu', function(e) {
e.preventDefault();
e.stopImmediatePropagation();
var submenu = $(this).next('ul');
var submenuHeight = 240;
if (! submenu.is(':visible')) {
self.close();
if ($(this).offset().top + submenuHeight > $(window).height()) {
submenu.addClass('dropdown-submenu-open dropdown-submenu-top');
}
else {
submenu.addClass('dropdown-submenu-open');
}
}
else {
self.close();
}
});
};
Dropdown.prototype.close = function() {
$('.dropdown-submenu-open').removeClass('dropdown-submenu-open');
};

View File

@@ -2,7 +2,6 @@ function Popover(app) {
this.app = app;
this.router = new Router();
this.router.addRoute('screenshot-zone', Screenshot);
Mousetrap.bindGlobal("esc", this.close);
}
Popover.prototype.isOpen = function() {
@@ -11,6 +10,7 @@ Popover.prototype.isOpen = function() {
Popover.prototype.open = function(link) {
var self = this;
self.app.dropdown.close();
$.get(link, function(content) {
$("body").append('<div id="popover-container"><div id="popover-content">' + content + '</div></div>');

View File

@@ -1,99 +0,0 @@
/*
* Dropit v1.1.0
* http://dev7studios.com/dropit
*
* Copyright 2012, Dev7studios
* Free to use and abuse under the MIT license.
* http://www.opensource.org/licenses/mit-license.php
*/
;(function($) {
$.fn.dropit = function(method) {
var methods = {
init : function(options) {
this.dropit.settings = $.extend({}, this.dropit.defaults, options);
return this.each(function() {
var $el = $(this),
el = this,
settings = $.fn.dropit.settings;
// Hide initial submenus
$el.addClass('dropit')
.find('>'+ settings.triggerParentEl +':has('+ settings.submenuEl +')').addClass('dropit-trigger')
.find(settings.submenuEl).addClass('dropit-submenu').hide();
// Open on click
$el.on(settings.action, settings.triggerParentEl +':has('+ settings.submenuEl +') > '+ settings.triggerEl +'', function(){
// Close click menu's if clicked again
if(settings.action == 'click' && $(this).parents(settings.triggerParentEl).hasClass('dropit-open')){
settings.beforeHide.call(this);
$(this).parent().removeClass('dropit-open').find(settings.submenuEl).hide();
// $(this).parents(settings.triggerParentEl).removeClass('dropit-open').find(settings.submenuEl).hide();
settings.afterHide.call(this);
return false;
}
// Hide open menus
settings.beforeHide.call(this);
$('.dropit-open').removeClass('dropit-open').find('.dropit-submenu').hide();
settings.afterHide.call(this);
// Open this menu
settings.beforeShow.call(this);
$(this).parent().addClass('dropit-open').find(settings.submenuEl).show();
// $(this).parents(settings.triggerParentEl).addClass('dropit-open').find(settings.submenuEl).show();
settings.afterShow.call(this);
return false;
});
// Close if outside click
$(document).on('click', function(){
settings.beforeHide.call(this);
$('.dropit-open').removeClass('dropit-open').find('.dropit-submenu').hide();
settings.afterHide.call(this);
});
// If hover
if(settings.action == 'mouseenter'){
$el.on('mouseleave', function(){
settings.beforeHide.call(this);
$(this).removeClass('dropit-open').find(settings.submenuEl).hide();
settings.afterHide.call(this);
});
}
settings.afterLoad.call(this);
});
}
};
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
} else if (typeof method === 'object' || !method) {
return methods.init.apply(this, arguments);
} else {
$.error( 'Method "' + method + '" does not exist in dropit plugin!');
}
};
$.fn.dropit.defaults = {
action: 'click', // The open action for the trigger
submenuEl: 'ul', // The submenu element
triggerEl: 'a', // The trigger element
triggerParentEl: 'li', // The trigger parent element
afterLoad: function(){}, // Triggers when plugin has loaded
beforeShow: function(){}, // Triggers before submenu is shown
afterShow: function(){}, // Triggers after submenu is shown
beforeHide: function(){}, // Triggers before submenu is hidden
afterHide: function(){} // Triggers before submenu is hidden
};
$.fn.dropit.settings = {};
})(jQuery);