Skip to content

Commit

Permalink
improve active function detection
Browse files Browse the repository at this point in the history
  • Loading branch information
johndoh committed Aug 2, 2014
1 parent 08ae9b9 commit ba6025f
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 18 deletions.
49 changes: 33 additions & 16 deletions contextmenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ function rcm_foldermenu_init(el, props, events) {
if (!events)
events = {};

var menu = rcm_callbackmenu_init(this, $.extend({'menu_name': 'folderlist', 'list_object': null, 'check_active': true}, props), $.extend({
var menu = rcm_callbackmenu_init(this, $.extend({'menu_name': 'folderlist', 'list_object': null, 'show_parent': true}, props), $.extend({
'afteractivate': function(p) {
if (rcmail.env.context_menu_source_id != rcmail.env.mailbox) {
p.obj.find('a').removeClass('active').addClass('disabled');
}

if ($(p.source).children('a:first').has('span.unreadcount').length)
if ($(p.source).children('a:first').has('span.unreadcount').length > 0) {
p.obj.find('a.readfolder').addClass('active');
}
else {
p.obj.find('a').removeClass('active').addClass('disabled');
}

p.obj.find('a.rcmglobal').addClass('active');
}
Expand Down Expand Up @@ -94,7 +98,7 @@ function rcm_groupmenu_init(el, props, events) {
if (!events)
events = {};

var menu = rcm_callbackmenu_init(this, $.extend({'menu_name': 'grouplist', 'list_object': null, 'check_active': true}, props), $.extend({
var menu = rcm_callbackmenu_init(this, $.extend({'menu_name': 'grouplist', 'list_object': null, 'show_parent': true}, props), $.extend({
'afteractivate': function(p) {
var ids = rcmail.env.context_menu_source_id.split(':', 2);
cur_source = ids[0];
Expand Down Expand Up @@ -224,9 +228,8 @@ function rcube_context_menu(p) {
this.menu_name = null;
this.menu_source = null;
this.is_submenu = false;
this.check_active = false;
this.show_parent = false;
this.list_object = rcmail.message_list;
this.list_object_select = true;
this.source_class = 'contextRow';
this.mouseover_submenu = true;
this.mouseover_timeout = 400;
Expand Down Expand Up @@ -264,8 +267,10 @@ function rcube_context_menu(p) {
link.setAttribute('aria-disabled', 'true');
span.className = this.is_submenu ? 'icon' : 'icon cmicon';

if (this.is_submenu)
if (this.is_submenu) {
this.container.addClass('rcmsubmenu');
this.show_parent = true;
}

// loop over possible menu elements
sources = typeof this.menu_source == 'string' ? [this.menu_source] : this.menu_source;
Expand Down Expand Up @@ -406,23 +411,23 @@ function rcube_context_menu(p) {
}

this.parent_menu.triggerEvent('beforeactivate', {ref: this, obj: this.container, source: obj});
if (ref.check_active)
if (ref.show_parent)
typeof ref.menu_source == 'string' ? $(ref.menu_source).parent().show() : $.each(ref.menu_source, function(i) { $(ref.menu_source[i]).parent().show(); } );

$.each(this.container.find('a'), function() {
if (btn = $(this).attr('class').match(/rcm_elem_([a-z0-9]+)/)) {
$(this).parent('li')[$('#' + btn[1]).is(':visible') ? 'show' : 'hide']();
$(this).removeClass('active').removeClass('disabled');

if ($('#' + btn[1]).hasClass('disabled') && ref.list_object && ref.list_object.selection.length > 1) {
if (rcm_check_button_state(btn[1], false) && ref.list_object && ref.list_object.selection.length > 1) {
$(this).addClass('disabled');
}
else if (!ref.check_active || $('#' + btn[1]).hasClass('active')) {
else if (!rcm_check_button_state(btn[1], false) && (!ref.is_submenu || rcm_check_button_state(btn[1], true))) {
$(this).addClass('active');
}
}
});
if (ref.check_active)
if (ref.show_parent)
typeof ref.menu_source == 'string' ? $(ref.menu_source).parent().hide() : $.each(ref.menu_source, function(i) { $(ref.menu_source[i]).parent().hide(); } );

this.parent_menu.triggerEvent('afteractivate', {ref: this, obj: this.container, source: obj});
Expand Down Expand Up @@ -472,7 +477,7 @@ function rcube_context_menu(p) {

var id = rcmail.gui_containers[$(link).data('popup_id')] ? rcmail.gui_containers[$(link).data('popup_id')].attr('id') : $(link).data('popup_id');
if (!this.submenus[id]) {
this.submenus[id] = new rcube_context_menu({'menu_name': id, 'menu_source': '#' + id + ' ul', 'parent_menu': this, 'parent_object': link, 'is_submenu': true, 'check_active': true, 'list_object': this.list_object});
this.submenus[id] = new rcube_context_menu({'menu_name': id, 'menu_source': '#' + id + ' ul', 'parent_menu': this, 'parent_object': link, 'is_submenu': true, 'list_object': this.list_object});
this.submenus[id].init();
}

Expand Down Expand Up @@ -511,8 +516,6 @@ function rcube_context_menu(p) {

for (var i in prev_sel)
this.list_object.highlight_row(prev_sel[i], true);

if (this.list_object_select)
this.list_object.triggerEvent('select');
}
}
Expand All @@ -521,9 +524,7 @@ function rcube_context_menu(p) {
this.list_object.highlight_row(prev_sel[i], true);

this.list_object.highlight_row(rcmail.env.context_menu_source_id, true);

if (this.list_object_select)
this.list_object.triggerEvent('select');
this.list_object.triggerEvent('select');
}

return prev_sel;
Expand Down Expand Up @@ -558,6 +559,22 @@ function rcm_override_mailbox_command(props, before) {
}
}

function rcm_check_button_state(btn, active) {
var classes = active ? rcmail.context_menu_button_active_class : rcmail.context_menu_button_disabled_class;
var found = false;

$.each(classes, function(i) {
if ($('#' + btn).hasClass(classes[i])) {
found = true;

// stop processing
return false;
}
});

return found;
}

$(document).ready(function() {
if (window.rcmail) {
rcmail.register_command('plugin.contextmenu.readfolder', function(props, obj) {
Expand Down
4 changes: 3 additions & 1 deletion skins/classic/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

rcube_webmail.prototype.context_menu_skip_commands = $.merge(rcube_webmail.prototype.context_menu_skip_commands, new Array('addressbook-group-remove-selected'));
rcube_webmail.prototype.context_menu_popup_pattern = /rcmail_ui\.show_popup\(\'([^\']+)\'/;
rcube_webmail.prototype.context_menu_button_active_class = new Array('active', 'button');
rcube_webmail.prototype.context_menu_button_disabled_class = new Array('disabled', 'buttonPas');

$(document).ready(function() {
if (window.rcmail) {
Expand All @@ -21,7 +23,7 @@ $(document).ready(function() {
}

if (rcmail.env.task == 'addressbook' && rcmail.env.action == '') {
rcmail.addEventListener('insertrow', function(props) { rcm_listmenu_init(props.row.id, {'menu_name': 'contactlist', 'menu_source': '#abooktoolbar', 'list_object': rcmail.contact_list, 'list_object_select': false}); } );
rcmail.addEventListener('insertrow', function(props) { rcm_listmenu_init(props.row.id, {'menu_name': 'contactlist', 'menu_source': '#abooktoolbar', 'list_object': rcmail.contact_list}); } );
rcmail.add_onload("rcm_abookmenu_init('#directorylist li.addressbook', {'menu_source': '#directorylist-footer'})");
rcmail.add_onload("rcm_groupmenu_init('#directorylist ul.groups li', {'menu_source': '#groupoptionsmenu ul'})");
rcmail.addEventListener('group_insert', function(props) { rcm_groupmenu_init(props.li, {'menu_source': '#groupoptionsmenu'}) } );
Expand Down
4 changes: 3 additions & 1 deletion skins/larry/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/

rcube_webmail.prototype.context_menu_popup_pattern = /UI\.toggle_popup\(\'([^\']+)\'/;
rcube_webmail.prototype.context_menu_button_active_class = new Array('active');
rcube_webmail.prototype.context_menu_button_disabled_class = new Array('disabled');

function add_menu_text(menu, p) {
if (menu == 'composeto') {
Expand Down Expand Up @@ -50,7 +52,7 @@ $(document).ready(function() {
}

if (rcmail.env.task == 'addressbook' && rcmail.env.action == '') {
rcmail.addEventListener('insertrow', function(props) { rcm_listmenu_init(props.row.id, {'menu_name': 'contactlist', 'menu_source': ['#addressbooktoolbar','#addresslist div.boxfooter a.delete', ,'#addresslist div.boxfooter a.removegroup'], 'list_object': rcmail.contact_list, 'list_object_select': false}, {
rcmail.addEventListener('insertrow', function(props) { rcm_listmenu_init(props.row.id, {'menu_name': 'contactlist', 'menu_source': ['#addressbooktoolbar','#addresslist div.boxfooter a.delete','#addresslist div.boxfooter a.removegroup'], 'list_object': rcmail.contact_list}, {
'insertitem': function(p) { add_menu_text('contactlist', p); },
'init': function(p) { reorder_contact_menu(p); },
'afteractivate': function(p) {
Expand Down

0 comments on commit ba6025f

Please sign in to comment.