From 0b88d99844b4d54eab322a7d0abaa4a9dc714655 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 23 Apr 2010 10:28:27 -0600 Subject: [PATCH] Further improvements to contextmenu generation/initialization --- imp/js/DimpBase.js | 69 +++++++++++++++++++++------------------------- imp/js/DimpCore.js | 32 +++++++++++++++++++-- imp/js/fullmessage-dimp.js | 12 ++------ 3 files changed, 64 insertions(+), 49 deletions(-) diff --git a/imp/js/DimpBase.js b/imp/js/DimpBase.js index db2056fe0..591de156f 100644 --- a/imp/js/DimpBase.js +++ b/imp/js/DimpBase.js @@ -522,9 +522,10 @@ var DimpBase = { /* Custom ViewPort events. */ container.observe('ViewPort:add', function(e) { var row = e.memo.identify(); - - // Add context menu - this._addMouseEvents({ id: row, type: 'message' }); + DimpCore.addContextMenu({ + id: row, + type: 'message' + }); new Drag(row, this._msgDragConfig); }.bindAsEventListener(this)); @@ -672,29 +673,6 @@ var DimpBase = { }); }, - _addPopdown: function(p, t) - { - var elt = new Element('SPAN', { className: 'iconImg popdownImg popdown' }); - $(p).insert({ after: elt }); - this._addPopdownContextMenu(elt, t); - return elt; - }, - - _addPopdownContextMenu: function(elt, t) - { - this._addMouseEvents({ - id: elt.identify(), - left: true, - offset: elt.up(), - type: t - }); - }, - - _addMouseEvents: function(p) - { - DimpCore.DMenu.addElement(p.id, 'ctx_' + p.type, p); - }, - _removeMouseEvents: function(elt) { var d, id = $(elt).readAttribute('id'); @@ -2571,12 +2549,18 @@ var DimpBase = { case 'container': case 'folder': new Drag(li, this._folderDragConfig); - this._addMouseEvents({ id: fid, type: ftype }); + DimpCore.addContextMenu({ + id: fid, + type: ftype + }); break; case 'scontainer': case 'virtual': - this._addMouseEvents({ id: fid, type: (ob.v == 2) ? 'vfolder' : 'noactions' }); + DimpCore.addContextMenu({ + id: fid, + type: (ob.v == 2) ? 'vfolder' : 'noactions' + }); break; } }, @@ -2937,8 +2921,18 @@ var DimpBase = { * list since it may be disabled if we are in a search mailbox. */ if ($('qsearch')) { $('qsearch_input').observe('blur', this._quicksearchOnBlur.bind(this)); - this._addMouseEvents({ id: 'qsearch_icon', left: true, offset: 'qsearch', type: 'qsearchopts' }); - this._addMouseEvents({ id: 'qsearch_icon', left: false, offset: 'qsearch', type: 'qsearchopts' }); + DimpCore.addContextMenu({ + id: 'qsearch_icon', + left: true, + offset: 'qsearch', + type: 'qsearchopts' + }); + DimpCore.addContextMenu({ + id: 'qsearch_icon', + left: false, + offset: 'qsearch', + type: 'qsearchopts' + }); DM.addSubMenu('ctx_qsearchopts_by', 'ctx_qsearchby'); DM.addSubMenu('ctx_qsearchopts_filter', 'ctx_flag'); DM.addSubMenu('ctx_qsearchopts_filternot', 'ctx_flag'); @@ -2971,10 +2965,8 @@ var DimpBase = { this._setQsearchText(true); /* Add popdown menus. Check for disabled compose at the same time. */ - this._addPopdown('button_other', 'otheractions'); - this._addPopdownContextMenu($('button_other'), 'otheractions'); - this._addPopdown('folderopts_link', 'folderopts'); - this._addPopdownContextMenu($('folderopts_link'), 'folderopts'); + DimpCore.addPopdown('button_other', 'otheractions'); + DimpCore.addPopdown('folderopts_link', 'folderopts'); DM.addSubMenu('ctx_message_reply', 'ctx_reply'); DM.addSubMenu('ctx_message_forward', 'ctx_forward'); @@ -2989,11 +2981,14 @@ var DimpBase = { if (DIMP.conf.disable_compose) { $('button_reply', 'button_forward').compact().invoke('up', 'SPAN').concat($('button_compose', 'composelink', 'ctx_contacts_new')).compact().invoke('remove'); } else { - DM.disable(this._addPopdown('button_reply', 'reply').identify(), true, true); - DM.disable(this._addPopdown('button_forward', 'forward').identify(), true, true); + DimpCore.addPopdown('button_reply', 'reply', true); + DimpCore.addPopdown('button_forward', 'forward', true); } - this._addMouseEvents({ id: 'msglistHeader', type: 'mboxsort' }); + DimpCore.addContextMenu({ + id: 'msglistHeader', + type: 'mboxsort' + }); new Drop('dropbase', this._folderDropConfig); diff --git a/imp/js/DimpCore.js b/imp/js/DimpCore.js index 270845157..e1952b740 100644 --- a/imp/js/DimpCore.js +++ b/imp/js/DimpCore.js @@ -320,13 +320,41 @@ var DimpCore = { toggleButtons: function(elts, disable) { elts.each(function(b) { + var tmp; [ b.up() ].invoke(disable ? 'addClassName' : 'removeClassName', 'disabled'); - if (this.DMenu) { - this.DMenu.disable(b.identify() + '_img', true, disable); + if (this.DMenu && + (tmp = b.next('.popdown'))) { + this.DMenu.disable(tmp.identify(), true, disable); } }, this); }, + // p = (Element) Parent element + // t = (string) Context menu type + // d = (boolean) Disabled? + addPopdown: function(p, t, d) + { + var elt = new Element('SPAN', { className: 'iconImg popdownImg popdown' }); + $(p).insert({ after: elt }); + + this.addContextMenu({ + disable: d, + id: elt.identify(), + left: true, + offset: elt.up(), + type: t + }); + + return elt; + }, + + addContextMenu: function(p) + { + if (this.DMenu) { + this.DMenu.addElement(p.id, 'ctx_' + p.type, p); + } + }, + /* Add dropdown menus to addresses. */ buildAddressLinks: function(alist, elt) { diff --git a/imp/js/fullmessage-dimp.js b/imp/js/fullmessage-dimp.js index f5bf5ce26..d49cf116d 100644 --- a/imp/js/fullmessage-dimp.js +++ b/imp/js/fullmessage-dimp.js @@ -181,14 +181,6 @@ var DimpFullmessage = { } }, - /* Add a popdown menu to a dimpactions button. */ - addPopdown: function(bid, ctx) - { - var bidelt = $(bid); - bidelt.insert({ after: new Element('SPAN', { className: 'iconImg popdownImg popdown', id: bid + '_img' }) }); - DimpCore.DMenu.addElement(bid + '_img', 'ctx_' + ctx, { offset: bidelt.up(), left: true }); - }, - resizeWindow: function() { var mb = $('msgData').down('DIV.messageBody'); @@ -204,8 +196,8 @@ var DimpFullmessage = { if (DIMP.conf.disable_compose) { tmp = $('reply_link', 'forward_link').compact().invoke('up', 'SPAN').concat([ $('ctx_contacts_new') ]).compact().invoke('remove'); } else { - this.addPopdown('reply_link', 'replypopdown'); - this.addPopdown('forward_link', 'forwardpopdown'); + DimpCore.addPopdown('reply_link', 'replypopdown'); + DimpCore.addPopdown('forward_link', 'forwardpopdown'); } /* Set up address linking. */ -- 2.11.0