Reuse DimpCore click handler
authorMichael M Slusarz <slusarz@curecanti.org>
Thu, 26 Feb 2009 21:21:28 +0000 (14:21 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Fri, 27 Feb 2009 18:50:06 +0000 (11:50 -0700)
imp/js/src/DimpBase.js
imp/js/src/DimpCore.js
imp/js/src/compose-dimp.js
imp/js/src/fullmessage-dimp.js

index d3da2eb..e3ae8ad 100644 (file)
@@ -1459,34 +1459,48 @@ var DimpBase = {
         }
     },
 
-    clickHandler: function(e, dblclick)
+    dblclickHandler: function(e)
     {
         if (e.isRightClick()) {
             return;
         }
 
-        var elt = e.element(),
-            orig = e.element(),
-            id, mbox, tmp;
+        var elt = orig = e.element(),
+            tmp;
 
         while (Object.isElement(elt)) {
             id = elt.readAttribute('id');
 
             switch (id) {
             case 'msgList':
-                if (dblclick) {
-                    if (!orig.hasClassName('msgRow')) {
-                        orig = orig.up('.msgRow');
-                    }
-                    if (orig) {
-                        tmp = this.viewport.createSelection('domid', orig.identify()).get('dataob').first();
-                        tmp.draft ? DimpCore.compose('resume', { folder: tmp.view, uid: tmp.imapuid }) : this.msgWindow(tmp);
-                    }
-                    e.stop();
-                    return;
+                if (!orig.hasClassName('msgRow')) {
+                    orig = orig.up('.msgRow');
                 }
-                break;
+                if (orig) {
+                    tmp = this.viewport.createSelection('domid', orig.identify()).get('dataob').first();
+                    tmp.draft ? DimpCore.compose('resume', { folder: tmp.view, uid: tmp.imapuid }) : this.msgWindow(tmp);
+                }
+                e.stop();
+                return;
+            }
+
+            elt = elt.up();
+        }
+    },
 
+    clickHandler: function(parentfunc, e)
+    {
+        if (e.isRightClick()) {
+            return;
+        }
+
+        var elt = e.element(),
+            id, mbox, tmp;
+
+        while (Object.isElement(elt)) {
+            id = elt.readAttribute('id');
+
+            switch (id) {
             case 'RB_Folder_ok':
                 this.cfolderaction(e);
                 e.stop();
@@ -1624,6 +1638,8 @@ var DimpBase = {
 
             elt = elt.up();
         }
+
+        parentfunc(e);
     },
 
     mouseHandler: function(e, type)
@@ -2269,6 +2285,13 @@ var DimpBase = {
 
         var DM = DimpCore.DMenu;
 
+        /* Register global handlers now. */
+        document.observe('keydown', this.keydownHandler.bindAsEventListener(this));
+        document.observe('keyup', this.keyupHandler.bindAsEventListener(this));
+        document.observe('mouseover', this.mouseHandler.bindAsEventListener(this, 'over'));
+        document.observe('dblclick', this.dblclickHandler.bindAsEventListener(this));
+        Event.observe(window, 'resize', this.onResize.bind(this));
+
         $('dimpLoading').hide();
         $('dimpPage').show();
 
@@ -2446,15 +2469,12 @@ DimpCore.onDoActionComplete = function(r) {
     }
 };
 
+/* Click handler. */
+DimpCore.clickHandler = DimpCore.clickHandler.wrap(DimpBase.clickHandler.bind(DimpBase));
+
 /* ContextSensitive functions. */
 DimpCore.contextOnClick = DimpCore.contextOnClick.wrap(DimpBase.contextOnClick.bind(DimpBase));
 DimpCore.contextOnShow = DimpCore.contextOnShow.wrap(DimpBase.contextOnShow.bind(DimpBase));
 
 /* Initialize global event handlers. */
 document.observe('dom:loaded', DimpBase.onDomLoad.bind(DimpBase));
-document.observe('keydown', DimpBase.keydownHandler.bindAsEventListener(DimpBase));
-document.observe('keyup', DimpBase.keyupHandler.bindAsEventListener(DimpBase));
-document.observe('click', DimpBase.clickHandler.bindAsEventListener(DimpBase));
-document.observe('dblclick', DimpBase.clickHandler.bindAsEventListener(DimpBase, true));
-document.observe('mouseover', DimpBase.mouseHandler.bindAsEventListener(DimpBase, 'over'));
-Event.observe(window, 'resize', DimpBase.onResize.bind(DimpBase));
index 423029e..744933d 100644 (file)
@@ -440,7 +440,7 @@ DimpCore = {
     },
 
     /* Mouse click handler. */
-    _clickHandler: function(e)
+    clickHandler: function(e)
     {
         if (e.isRightClick()) {
             return;
@@ -558,13 +558,13 @@ DimpCore = {
         if (!DIMP.conf.ham_reporting) {
             this.buttons = this.buttons.without('button_ham');
         }
+
+        /* Add click handler. */
+        document.observe('click', DimpCore.clickHandler.bindAsEventListener(DimpCore));
     }
 
 };
 
-/* Add click handler. */
-document.observe('click', DimpCore._clickHandler.bindAsEventListener(DimpCore));
-
 /* Helper methods for setting/getting element text without mucking
  * around with multiple TextNodes. */
 Element.addMethods({
index 0f280de..2cdbbe6 100644 (file)
@@ -21,11 +21,11 @@ var DimpCompose = {
             if (DIMP.conf_compose.auto_save_interval_val) {
                 DimpCore.doAction('DeleteDraft', { index: $F('index') });
             }
-            return this._closeCompose();
+            return this.closeCompose();
         }
     },
 
-    _closeCompose: function()
+    closeCompose: function()
     {
         if (DIMP.conf_compose.qreply) {
             this.closeQReply();
@@ -213,7 +213,7 @@ var DimpCompose = {
                     DIMP.baseWindow.DimpCore.showNotifications(r.msgs);
                 }
                 if (DIMP.conf_compose.close_draft) {
-                    return this._closeCompose();
+                    return this.closeCompose();
                 }
                 break;
 
@@ -241,7 +241,7 @@ var DimpCompose = {
 
                     DIMP.baseWindow.DimpCore.showNotifications(r.msgs);
                 }
-                return this._closeCompose();
+                return this.closeCompose();
 
             case 'add_attachment':
                 this.uploading = false;
@@ -314,8 +314,8 @@ var DimpCompose = {
                 $('messageParent').childElements().invoke('show');
                 $('message').hide();
             } catch (e) {
-                this._RTELoading('show');
-                FCKeditor_OnComplete = this._RTELoading.curry('hide');
+                this.RTELoading('show');
+                FCKeditor_OnComplete = this.RTELoading.curry('hide');
                 oFCKeditor.ReplaceTextarea();
             }
         }
@@ -323,7 +323,7 @@ var DimpCompose = {
         $('html').setValue(this.editor_on ? 1 : 0);
     },
 
-    _RTELoading: function(cmd)
+    RTELoading: function(cmd)
     {
         var o, r;
         if (!$('rteloading')) {
@@ -628,13 +628,14 @@ var DimpCompose = {
     },
 
     /* Click observe handler. */
-    clickHandler: function(e)
+    clickHandler: function(parentfunc, e)
     {
         if (e.isRightClick()) {
             return;
         }
 
-        var elt = orig = e.element(), atc_num, id;
+        var elt = orig = e.element(),
+            atc_num, id;
 
         while (Object.isElement(elt)) {
             id = elt.readAttribute('id');
@@ -679,6 +680,8 @@ var DimpCompose = {
 
             elt = elt.up();
         }
+
+        parentfunc(e);
     },
 
     changeHandler: function(e)
@@ -703,6 +706,12 @@ var DimpCompose = {
 
         DimpCore.init();
 
+        /* Attach event handlers. */
+        document.observe('change', this.changeHandler.bindAsEventListener(this));
+        Event.observe(window, 'resize', this.resizeMsgArea.bind(this));
+        $('compose').observe('submit', Event.stop);
+        $('submit_frame').observe('load', this.attachmentComplete.bind(this));
+
         this.resizeMsgArea();
         this.initializeSpellChecker();
 
@@ -772,8 +781,6 @@ ResizeTextArea = Class.create({
 
 /* Attach event handlers. */
 document.observe('dom:loaded', DimpCompose.onDomLoad.bind(DimpCompose));
-document.observe('change', DimpCompose.changeHandler.bindAsEventListener(DimpCompose));
-document.observe('click', DimpCompose.clickHandler.bindAsEventListener(DimpCompose));
-Event.observe(window, 'resize', DimpCompose.resizeMsgArea.bind(DimpCompose));
-$('compose').observe('submit', Event.stop);
-$('submit_frame').observe('load', DimpCompose.attachmentComplete.bind(DimpCompose));
+
+/* Click handler. */
+DimpCore.clickHandler = DimpCore.clickHandler.wrap(DimpCompose.clickHandler.bind(DimpCompose));
index 192e166..d85e7cd 100644 (file)
@@ -67,7 +67,7 @@ var DimpFullmessage = {
     },
 
     /* Click handlers. */
-    clickHandler: function(e)
+    clickHandler: function(parentfunc, e)
     {
         if (e.isRightClick()) {
             return;
@@ -107,6 +107,8 @@ var DimpFullmessage = {
 
             elt = elt.up();
         }
+
+        parentfunc(e);
     },
 
     contextOnClick: function(parentfunc, id, elt)
@@ -131,7 +133,7 @@ var DimpFullmessage = {
     },
 
     /* Add a popdown menu to a dimpactions button. */
-    _addPopdown: function(bid, ctx)
+    addPopdown: function(bid, ctx)
     {
         var bidelt = $(bid);
         bidelt.insert({ after: new Element('SPAN', { className: 'iconImg popdownImg popdown', id: bid + '_img' }) });
@@ -142,8 +144,8 @@ var DimpFullmessage = {
     {
         DimpCore.init();
 
-        this._addPopdown('reply_link', 'replypopdown');
-        this._addPopdown('forward_link', 'fwdpopdown');
+        this.addPopdown('reply_link', 'replypopdown');
+        this.addPopdown('forward_link', 'fwdpopdown');
 
         /* Set up address linking. */
         [ 'from', 'to', 'cc', 'bcc', 'replyTo' ].each(function(a) {
@@ -159,6 +161,8 @@ var DimpFullmessage = {
 /* ContextSensitive functions. */
 DimpCore.contextOnClick = DimpCore.contextOnClick.wrap(DimpFullmessage.contextOnClick.bind(DimpFullmessage));
 
+/* Click handler. */
+DimpCore.clickHandler = DimpCore.clickHandler.wrap(DimpFullmessage.clickHandler.bind(DimpFullmessage));
+
 /* Attach event handlers. */
 document.observe('dom:loaded', DimpFullmessage.onDomLoad.bind(DimpFullmessage));
-document.observe('click', DimpFullmessage.clickHandler.bindAsEventListener(DimpFullmessage));