Skip to content

Commit

Permalink
Consolidate element deletion cleanup methods into single event handler
Browse files Browse the repository at this point in the history
  • Loading branch information
slusarz committed Jun 12, 2014
1 parent a3d3615 commit 433883a
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions imp/js/dimpbase.js
Expand Up @@ -636,7 +636,7 @@ var DimpBase = {
}.bindAsEventListener(this));

container.observe('ViewPort:clear', function(e) {
this._removeMouseEvents([ e.memo ]);
$(e.memo).fire('DimpBase:removeElt');
}.bindAsEventListener(this));

container.observe('ViewPort:contentComplete', function() {
Expand Down Expand Up @@ -869,21 +869,6 @@ var DimpBase = {
: DimpCore.text.vp_empty;
},

_removeMouseEvents: function(elt)
{
elt.each(function(a) {
var d, id = $(a).readAttribute('id');

if (id) {
if ((d = DragDrop.Drags.getDrag(id))) {
d.destroy();
}

DimpCore.DMenu.removeElement(id);
}
});
},

contextOnClick: function(e)
{
var tmp,
Expand Down Expand Up @@ -1826,7 +1811,7 @@ var DimpBase = {
pm = $('previewMsg'),
r = this.ppcache[this._getPPId(uid, mbox)];

this._removeMouseEvents(pm.down('.msgHeaders').select('.address'));
pm.down('.msgHeaders').select('.address').invoke('fire', 'DimpBase:removeElt');

// Add subject. Subject was already html encoded on server (subject
// may include links).
Expand Down Expand Up @@ -2029,9 +2014,7 @@ var DimpBase = {
var pm = $('previewMsg');

if (pm.visible()) {
this._removeMouseEvents(
pm.hide().down('.msgHeaders').select('.address')
);
pm.hide().down('.msgHeaders').select('.address').invoke('fire', 'DimpBase:removeElt');
}

this.loadingImg('msg', false);
Expand Down Expand Up @@ -3102,6 +3085,16 @@ var DimpBase = {
delete this.colorpicker;
},

removeEltHandler: function(e)
{
var id = e.element().readAttribute('id');

if (id) {
[ DragDrop.Drags.getDrag(id), DragDrop.Drops.getDrop(id) ].compact().invoke('destroy');
DimpCore.DMenu.removeElement(id);
}
},

updateSliderCount: function()
{
var range = this.viewport.currentViewableRange();
Expand Down Expand Up @@ -3595,12 +3588,6 @@ var DimpBase = {
});
},

deleteMboxHandler: function(e)
{
[ DragDrop.Drags.getDrag(e.memo.value()), DragDrop.Drops.getDrop(e.memo.value()) ].compact().invoke('destroy');
this._removeMouseEvents([ e.memo.element() ]);
},

_sizeFolderlist: function()
{
var nf = $('imp-normalmboxes');
Expand Down Expand Up @@ -4466,12 +4453,17 @@ document.observe('ContextSensitive:trigger', DimpBase.contextOnTrigger.bindAsEve
document.observe('FormGhost:reset', DimpBase.searchReset.bindAsEventListener(DimpBase));
document.observe('FormGhost:submit', DimpBase.searchSubmit.bindAsEventListener(DimpBase));

/* DimpBase handlers. */
document.observe('DimpBase:removeElt', DimpBase.removeEltHandler.bindAsEventListener(DimpBase));

/* DimpCore handlers. */
document.observe('DimpCore:updateAddressHeader', DimpBase.updateAddressHeader.bindAsEventListener(DimpBase));

/* Folder list element handlers. */
document.observe('IMP_Flist_Mbox:create', DimpBase.createMboxHandler.bind(DimpBase));
document.observe('IMP_Flist_Mbox:delete', DimpBase.deleteMboxHandler.bind(DimpBase));
document.observe('IMP_Flist_Mbox:delete', function(e) {
e.memo.element().fire('DimpBase:removeElt');
});

/* HTML IFRAME handlers. */
document.observe('IMP_JS:htmliframe_keydown', function(e) {
Expand Down

0 comments on commit 433883a

Please sign in to comment.