var ContextSensitive = Class.create({
- initialize: function()
+ initialize: function(opts)
{
- this.lasttarget = this.target = null;
+ this.basectx = this.lasttarget = this.target = null;
this.elements = $H();
this.submenus = $H();
this.current = [];
- this.basectx = this.onShow = null;
+ this.opts = opts || {};
document.observe('contextmenu', this._rightClickHandler.bindAsEventListener(this));
document.observe('click', this._leftClickHandler.bindAsEventListener(this));
},
/**
- * Set an onshow function.
- */
- setOnShow: function(func)
- {
- this.onShow = func;
- },
-
- /**
* Elements are of type ContextSensitive.Element.
*/
addElement: function(id, target, opts)
x = v.width - size.width - 10;
}
- if (this.onShow) {
- this.onShow(id, this.basectx);
+ if (this.opts.onShow) {
+ this.opts.onShow(id, this.basectx);
}
Effect.Appear(elt.setStyle({ left: x + 'px', top: y + 'px' }), { duration: 0.2, queue: { position: 'end', scope: 'cm_' + id, limit: 2 } });
_onMenuShow: function(ctx_id, ctx)
{
- var elts, folder, ob, sel;
+ var elts, folder, ob, sel, tmp;
switch (ctx_id) {
case 'ctx_folder':
elts = $('ctx_folder_create', 'ctx_folder_rename', 'ctx_folder_delete');
- folder = DimpCore.DMenu.element();
+ folder = $(ctx.ctx);
if (folder.readAttribute('mbox') == 'INBOX') {
elts.invoke('hide');
} else if (DIMP.conf.fixed_folders.indexOf(folder.readAttribute('mbox')) != -1) {
elts.invoke('show');
}
- if (folder.hasAttribute('u')) {
- $('ctx_folder_poll').hide();
- $('ctx_folder_nopoll').show();
- } else {
- $('ctx_folder_poll').show();
- $('ctx_folder_nopoll').hide();
- }
- break;
-
- case 'ctx_message':
- DimpCore.DMenu.addSubMenu('ctx_message_reply', 'ctx_reply');
- DimpCore.DMenu.addSubMenu('ctx_message_forward', 'ctx_forward');
- DimpCore.DMenu.addSubMenu('ctx_message_setflag', 'ctx_flag');
+ tmp = folder.hasAttribute('u');
+ [ $('ctx_folder_poll') ].invoke(tmp ? 'hide' : 'show');
+ [ $('ctx_folder_nopoll') ].invoke(tmp? 'show' : 'hide');
break;
case 'ctx_reply':
case 'ctx_otheractions':
$('oa_setflag', 'oa_sep1', 'oa_blacklist', 'oa_whitelist', 'oa_sep2', 'oa_undeleted').compact().invoke(this.viewport.getSelected().size() ? 'show' : 'hide');
- DimpCore.DMenu.addSubMenu('oa_setflag', 'ctx_flag');
- break;
-
- case 'ctx_draft':
- DimpCore.DMenu.addSubMenu('ctx_draft_setflag', 'ctx_flag');
break;
}
- return true;
},
- _onResize: function(noupdate, nowait)
+ onResize: function(noupdate, nowait)
{
if (this.viewport) {
this.viewport.onResize(noupdate, nowait);
updateTitle: function()
{
var elt, label, unseen;
+
if (this.viewport.isFiltering()) {
label = DIMP.text.search + ' :: ' + (this.viewport.getMetaData('total_rows') || 0) + ' ' + DIMP.text.resfound;
} else {
var s, sortby,
elt = e.element();
+
if (!elt.hasAttribute('sortby')) {
elt = elt.up('[sortby]');
if (!elt) {
/* Folder list updates. */
pollFolders: function()
{
+ var args = {};
+
// Reset poll folder counter.
this.setPollFolders();
- var args = {};
// Check for label info - it is possible that the mailbox may be
// loading but not complete yet and sending this request will cause
_pollFoldersCallback: function(r)
{
- var that;
r = r.response;
if (r.poll) {
- that = this;
$H(r.poll).each(function(u) {
- that.updateUnseenStatus(u.key, u.value);
- });
+ this.updateUnseenStatus(u.key, u.value);
+ }, this);
}
if (r.quota) {
this._displayQuota(r.quota);
_displayQuota: function(r)
{
- q = $('quota').cleanWhitespace();
+ var q = $('quota').cleanWhitespace();
q.setText(r.m);
q.down('SPAN.used IMG').writeAttribute({ width: 99 - r.p });
},
this._setSearchfilterParams(this.viewport.getMetaData('special') ? 'to' : 'from', 'msg');
this._setSearchfilterParams('current', 'folder');
$(document.documentElement).setStyle({ overflowY: 'hidden' });
- Effect.SlideDown(q, { duration: 0.5, afterFinish: function() { this._onResize(false, true); $(document.documentElement).setStyle({ overflowY: 'auto' }); }.bind(this) });
+ Effect.SlideDown(q, { duration: 0.5, afterFinish: function() { this.onResize(false, true); $(document.documentElement).setStyle({ overflowY: 'auto' }); }.bind(this) });
}
},
this.searchobserve = null;
}
this._setFilterText(true);
- Effect.SlideUp($('qoptions').up(), { duration: 0.5, afterFinish: this._onResize.bind(this, reset) });
+ Effect.SlideUp($('qoptions').up(), { duration: 0.5, afterFinish: this.onResize.bind(this, reset) });
this.filtertoggle = 2;
this.resetSelected();
this.viewport.stopFilter(reset);
},
/* Keydown event handler */
- _keydownHandler: function(e)
+ keydownHandler: function(e)
{
var co, form, ps, r, row, rowoff, sel,
elt = e.element(),
}
},
- _keyupHandler: function(e)
+ keyupHandler: function(e)
{
if (e.element().readAttribute('id') == 'msgList_filter') {
if (this.searchobserve) {
}
},
- _clickHandler: function(e, dblclick)
+ clickHandler: function(e, dblclick)
{
if (e.isRightClick()) {
return;
}
},
- _mouseHandler: function(e, type)
+ mouseHandler: function(e, type)
{
var elt = e.element();
/* Onload function. */
onDomLoad: function()
{
- var DC = DimpCore;
+ var DC = DimpCore, DM = DimpCore.DMenu;
+
+ DC.init({ DMenu_onShow: this._onMenuShow.bind(this) });
$('dimpLoading').hide();
$('dimpPage').show();
this._setFilterText(true);
/* Add popdown menus. */
- DC.DMenu.setOnShow(this._onMenuShow.bind(this));
this._addMouseEvents({ id: 'button_reply', type: 'reply' }, true);
- DC.DMenu.disable('button_reply_img', true, true);
+ DM.disable('button_reply_img', true, true);
this._addMouseEvents({ id: 'button_forward', type: 'forward' }, true);
- DC.DMenu.disable('button_forward_img', true, true);
+ DM.disable('button_forward_img', true, true);
this._addMouseEvents({ id: 'button_other', type: 'otheractions' }, true);
+ DM.addSubMenu('ctx_message_reply', 'ctx_reply');
+ DM.addSubMenu('ctx_message_forward', 'ctx_forward');
+ DM.addSubMenu('ctx_message_setflag', 'ctx_flag');
+ DM.addSubMenu('oa_setflag', 'ctx_flag');
+ DM.addSubMenu('ctx_draft_setflag', 'ctx_flag');
new Drop('dropbase', this._folderDropConfig);
/* Check for new mail. */
this.setPollFolders();
- /* Bind key shortcuts. */
- document.observe('keydown', this._keydownHandler.bindAsEventListener(this));
- document.observe('keyup', this._keyupHandler.bindAsEventListener(this));
-
- /* Bind mouse clicks. */
- document.observe('click', this._clickHandler.bindAsEventListener(this));
- document.observe('dblclick', this._clickHandler.bindAsEventListener(this, true));
- document.observe('mouseover', this._mouseHandler.bindAsEventListener(this, 'over'));
-
- /* Resize elements on window size change. */
- Event.observe(window, 'resize', this._onResize.bind(this));
-
if (DIMP.conf.is_ie6) {
/* Disable text selection in preview pane for IE 6. */
document.observe('selectstart', Event.stop);
iframe.setStyle({ width: $('dimpmain').getStyle('width'), height: (document.viewport.getHeight() - 20) + 'px' });
}
}
+
};
/* Need to add after DimpBase is defined. */
}
};
-/* Stuff to do immediately when page is ready. */
+/* 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));
/* DimpCore object. */
DimpCore = {
// Vars used and defaulting to null/false:
- // DMenu, alertrequest, inAjaxCallback, is_logout, onDoActionComplete,
- // window_load
+ // DMenu, alertrequest, inAjaxCallback, is_logout, onDoActionComplete
server_error: 0,
buttons: [
doActionComplete: function(request, callback)
{
this.inAjaxCallback = true;
- var r;
if (!request.responseJSON) {
if (++this.server_error == 3) {
return;
}
- r = request.responseJSON;
+ var r = request.responseJSON;
if (!r.msgs) {
r.msgs = [];
}
if (r.response && Object.isFunction(callback)) {
- if (DIMP.conf.debug) {
+ try {
callback(r);
- } else {
- try {
- callback(r);
- } catch (e) {}
+ } catch (e) {
+ this.debug('doActionComplete', e);
}
}
elt = elt.up();
}
- }
-};
+ },
-// Initialize DMenu now. Need to init here because IE doesn't load dom:loaded
-// in a predictable order.
-if (typeof ContextSensitive != 'undefined') {
- DimpCore.DMenu = new ContextSensitive();
-}
-
-document.observe('dom:loaded', function() {
- /* Don't do additional onload stuff if we are in a popup. We need a
- * try/catch block here since, if the page was loaded by an opener
- * out of this current domain, this will throw an exception. */
- try {
- if (parent.opener &&
- parent.opener.location.host == window.location.host &&
- parent.opener.DimpCore) {
- DIMP.baseWindow = parent.opener.DIMP.baseWindow || parent.opener;
+ /* Dimp initialization function. */
+ init: function(opts)
+ {
+ opts = opts || {};
+
+ if (typeof ContextSensitive != 'undefined') {
+ this.DMenu = new ContextSensitive({ onShow: opts.DMenu_onShow });
}
- } catch (e) {}
- /* Remove unneeded buttons. */
- if (!DIMP.conf.spam_reporting) {
- DimpCore.buttons = DimpCore.buttons.without('button_spam');
- }
- if (!DIMP.conf.ham_reporting) {
- DimpCore.buttons = DimpCore.buttons.without('button_ham');
+ /* Don't do additional onload stuff if we are in a popup. We need a
+ * try/catch block here since, if the page was loaded by an opener
+ * out of this current domain, this will throw an exception. */
+ try {
+ if (parent.opener &&
+ parent.opener.location.host == window.location.host &&
+ parent.opener.DimpCore) {
+ DIMP.baseWindow = parent.opener.DIMP.baseWindow || parent.opener;
+ }
+ } catch (e) {}
+
+ /* Remove unneeded buttons. */
+ if (!DIMP.conf.spam_reporting) {
+ this.buttons = this.buttons.without('button_spam');
+ }
+ if (!DIMP.conf.ham_reporting) {
+ this.buttons = this.buttons.without('button_ham');
+ }
}
- /* Add click handler. */
- document.observe('click', DimpCore._clickHandler.bindAsEventListener(DimpCore));
-});
+};
-Event.observe(window, 'load', function() {
- DimpCore.window_load = true;
-});
+/* Add click handler. */
+document.observe('click', DimpCore._clickHandler.bindAsEventListener(DimpCore));
/* Helper methods for setting/getting element text without mucking
* around with multiple TextNodes. */
elt = new Element('DIV', [ DIMP.text_compose.attachment_limit ]);
} else {
elt = new Element('INPUT', { type: 'file', name: 'file_1' });
- elt.observe('change', this.uploadAttachment.bind(this));
}
$('upload_wait').replace(elt.writeAttribute('id', 'upload'));
this.resizeMsgArea();
de = document.documentElement,
msg = $('message');
- if (!DimpCore.window_load) {
+ if (!document.loaded) {
this.resizeMsgArea.bind(this).defer();
return;
}
uploadAttachment: function()
{
var u = $('upload');
- $('submit_frame').observe('load', this.attachmentComplete.bind(this));
this.uniqueSubmit('add_attachment');
- u.stopObserving('change').replace(new Element('DIV', { id: 'upload_wait' }).insert(DIMP.text_compose.uploading + ' ' + $F(u)));
+ u.replace(new Element('DIV', { id: 'upload_wait' }).insert(DIMP.text_compose.uploading + ' ' + $F(u)));
},
attachmentComplete: function()
{
var sf = $('submit_frame'),
doc = sf.contentDocument || sf.contentWindow.document;
- sf.stopObserving('load');
DimpCore.doActionComplete({ responseJSON: doc.body.innerHTML.evalJSON(true) }, this.uniqueSubmitCallback.bind(this));
},
},
/* Click observe handler. */
-
- _clickHandler: function(e)
+ clickHandler: function(e)
{
if (e.isRightClick()) {
return;
elt = elt.up();
}
+ },
+
+ changeHandler: function(e)
+ {
+ var elt = e.element(),
+ id = elt.readAttribute('id');
+
+ switch (id) {
+ case 'identity':
+ this.change_identity();
+ break;
+
+ case 'upload':
+ this.uploadAttachment();
+ break;
+ }
+ },
+
+ onDomLoad: function()
+ {
+ var boundResize = this.resizeMsgArea.bind(this);
+
+ DimpCore.init();
+
+ this.resizeMsgArea();
+ this.initializeSpellChecker();
+
+ // Automatically resize address fields.
+ this.resizeto = new ResizeTextArea('to', boundResize);
+ this.resizecc = new ResizeTextArea('cc', boundResize);
+ this.resizebcc = new ResizeTextArea('bcc', boundResize);
+
+ // Safari requires a submit target iframe to be at least 1x1 size or
+ // else it will open content in a new window. See:
+ // http://blog.caboo.se/articles/2007/4/2/ajax-file-upload
+ if (Prototype.Browser.WebKit) {
+ $('submit_frame').writeAttribute({ position: 'absolute', width: '1px', height: '1px' }).setStyle({ left: '-999px' }).show();
+ }
+
+ /* Add addressbook link formatting. */
+ if (DIMP.conf_compose.abook_url) {
+ $('sendto', 'sendcc', 'sendbcc').each(function(a) {
+ a.down('TD.label SPAN').addClassName('composeAddrbook');
+ });
+ }
}
+
},
ResizeTextArea = Class.create({
}
}
}
-});
-
-document.observe('dom:loaded', function() {
- var tmp,
- DC = DimpCompose,
- boundResize = DC.resizeMsgArea.bind(DC);
-
- DC.resizeMsgArea();
- DC.initializeSpellChecker();
- $('upload').observe('change', DC.uploadAttachment.bind(DC));
-
- // Automatically resize address fields.
- DC.resizeto = new ResizeTextArea('to', boundResize);
- DC.resizecc = new ResizeTextArea('cc', boundResize);
- DC.resizebcc = new ResizeTextArea('bcc', boundResize);
-
- // Safari requires a submit target iframe to be at least 1x1 size or else
- // it will open content in a new window. See:
- // http://blog.caboo.se/articles/2007/4/2/ajax-file-upload
- if (Prototype.Browser.WebKit) {
- $('submit_frame').writeAttribute({ position: 'absolute', width: '1px', height: '1px' }).setStyle({ left: '-999px' }).show();
- }
-
- /* Add addressbook link formatting. */
- if (DIMP.conf_compose.abook_url) {
- $('sendto', 'sendcc', 'sendbcc').each(function(a) {
- a.down('TD.label SPAN').addClassName('composeAddrbook');
- });
- }
- /* Mouse click handler. */
- document.observe('click', DC._clickHandler.bindAsEventListener(DC));
-
- /* Only allow submit through send button. */
- $('compose').observe('submit', Event.stop);
-
- /* Attach other handlers. */
- $('identity').observe('change', DC.change_identity.bind(DC));
-
- Event.observe(window, 'resize', boundResize);
});
+
+/* 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));
},
/* Mouse click handler. */
- _clickHandler: function(e)
+ clickHandler: function(e)
{
if (e.isRightClick()) {
return;
},
/* Add a popdown menu to a dimpactions button. */
- addPopdown: function(bid, ctx)
+ _addPopdown: function(bid, ctx)
{
var bidelt = $(bid);
bidelt.insert({ after: $($('popdown_img').cloneNode(false)).writeAttribute('id', bid + '_img').show() });
DimpCore.DMenu.addElement(bid + '_img', 'ctx_' + ctx, { offset: bidelt.up(), left: true });
- }
-
-};
+ },
-document.observe('dom:loaded', function() {
- var FM = DimpFullmessage;
+ onDomLoad: function()
+ {
+ DimpCore.init();
- window.focus();
+ this.addPopdown('reply_link', 'replypopdown');
+ this.addPopdown('forward_link', 'fwdpopdown');
- FM.addPopdown('reply_link', 'replypopdown');
- FM.addPopdown('forward_link', 'fwdpopdown');
+ /* Set up address linking. */
+ [ 'from', 'to', 'cc', 'bcc', 'replyTo' ].each(function(a) {
+ if (this[a]) {
+ var elt = $('msgHeader' + a.charAt(0).toUpperCase() + a.substring(1)).down('TD', 1);
+ elt.replace(DimpCore.buildAddressLinks(this[a], elt.cloneNode(false)));
+ }
+ }, this);
+ }
- /* Set up address linking. */
- [ 'from', 'to', 'cc', 'bcc', 'replyTo' ].each(function(a) {
- if (FM[a]) {
- var elt = $('msgHeader' + a.charAt(0).toUpperCase() + a.substring(1)).down('TD', 1);
- elt.replace(DimpCore.buildAddressLinks(FM[a], elt.cloneNode(false)));
- }
- });
+};
- /* Set up click handlers. */
- document.observe('click', FM._clickHandler.bindAsEventListener(FM));
-});
+document.observe('dom:loaded', DimpFullmessage.onDomLoad.bind(DimpFullmessage));
+document.observe('click', DimpFullmessage.clickHandler.bindAsEventListener(DimpFullmessage));