From 59478e06c25303a790a0840ab2ac30662c4ef781 Mon Sep 17 00:00:00 2001 From: Hugues Hiegel Date: Tue, 5 Aug 2014 16:46:22 +0200 Subject: c'est la merde.. --- plugins/contextmenu/contextmenu.js | 595 +++++++++++++++++++++++++++++++++++++ 1 file changed, 595 insertions(+) create mode 100644 plugins/contextmenu/contextmenu.js (limited to 'plugins/contextmenu/contextmenu.js') diff --git a/plugins/contextmenu/contextmenu.js b/plugins/contextmenu/contextmenu.js new file mode 100644 index 000000000..6d83f1fbe --- /dev/null +++ b/plugins/contextmenu/contextmenu.js @@ -0,0 +1,595 @@ +/** + * ContextMenu plugin script + */ + +rcube_webmail.prototype.contextmenu_command_handlers = new Object(); +rcube_webmail.prototype.contextmenu_disable_multi = new Array('#reply','#reply-all','#reply-list','#forward-inline','#print','#edit','#viewsource','#download','#open','#edit'); + +function rcm_contextmenu_update() { + //if (!rcmail.env.flag_for_deletion && rcmail.env.trash_mailbox && rcmail.env.mailbox != rcmail.env.trash_mailbox) + // $("#rcm_delete").html('' + rcmail.gettext('movemessagetotrash') + ''); + //else + // $("#rcm_delete").html('' + rcmail.gettext('deletemessage') + ''); +} + +function rcm_contextmenu_init(row) { + $("#" + row).contextMenu({ + menu: 'rcmContextMenu', + submenu_delay: 400 + }, + function(command, el, pos) { + var matches = String($(el).attr('id')).match(/rcmrow([a-z0-9\-_=]+)/i); + if ($(el) && matches) { + var prev_uid = rcmail.env.uid; + if (rcmail.message_list.selection.length <= 1 || !rcmail.message_list.in_selection(matches[1])) + rcmail.env.uid = matches[1]; + + // fix command string in IE + if (command.indexOf("#") > 0) + command = command.substr(command.indexOf("#") + 1); + + // enable the required command + cmd = (command == 'read' || command == 'unread' || command == 'flagged' || command == 'unflagged') ? 'mark' : command; + var prev_command = rcmail.commands[cmd]; + rcmail.enable_command(cmd, true); + + // process external commands + if (typeof rcmail.contextmenu_command_handlers[command] == 'function') { + rcmail.contextmenu_command_handlers[command](command, el, pos); + } + else if (typeof rcmail.contextmenu_command_handlers[command] == 'string') { + window[rcmail.contextmenu_command_handlers[command]](command, el, pos); + } + else { + switch (command) { + case 'read': + case 'unread': + case 'flagged': + case 'unflagged': + rcmail.command('mark', command, $(el)); + break; + case 'reply': + case 'reply-all': + case 'reply-list': + case 'forward-inline': + case 'forward-attachment': + case 'print': + case 'download': + case 'viewsource': + rcmail.command(command, '', $(el)); + break; + case 'edit': + rcmail.command(command, 'new', $(el)); + break; + case 'open': + rcmail.command(command, '', rcube_find_object('rcm_open')); + rcmail.sourcewin = window.open(rcube_find_object('rcm_open').href); + if (rcmail.sourcewin) + window.setTimeout(function() { rcmail.sourcewin.focus(); }, 20); + + rcube_find_object('rcm_open').href = '#open'; + break; + case 'delete': + case 'moveto': + if (command == 'moveto' && rcmail.env.rcm_destfolder == rcmail.env.mailbox) + return; + + var prev_sel = null; + + // also select childs of (collapsed) threads + if (rcmail.env.uid) { + if (!rcmail.message_list.in_selection(rcmail.env.uid)) { + prev_sel = rcmail.message_list.get_selection(); + rcmail.message_list.select_row(rcmail.env.uid); + } + + if (rcmail.message_list.rows[rcmail.env.uid].has_children && !rcmail.message_list.rows[rcmail.env.uid].expanded) + rcmail.message_list.select_childs(rcmail.env.uid); + + rcmail.env.uid = null; + } + + rcmail.command(command, rcmail.env.rcm_destfolder, $(el)); + + if (prev_sel) { + rcmail.message_list.clear_selection(); + + for (var i in prev_sel) + rcmail.message_list.select_row(prev_sel[i], CONTROL_KEY); + } + + delete rcmail.env.rcm_destfolder; + break; + } + } + + rcmail.enable_command(cmd, prev_command); + rcmail.env.uid = prev_uid; + } + }); +} + +function rcm_set_dest_folder(folder) { + rcmail.env.rcm_destfolder = folder; +} + +function rcm_contextmenu_register_command(command, callback, label, pos, sep, multi, newSub, menu, liclass) { + if (!menu) + menu = $('#rcmContextMenu'); + + if (!liclass) + liclass = command; + + if (typeof label != 'string') { + var menuItem = label.children('li'); + } + else { + var menuItem = $('
  • ').addClass(liclass); + $('').attr('href', '#' + command).addClass('active').html('' + rcmail.gettext(label) + '').appendTo(menuItem); + } + + rcmail.contextmenu_command_handlers[command] = callback; + + if (pos && menu.children('li.' + pos) && newSub) { + subMenu = menu.children('li.' + pos); + subMenu.addClass('submenu'); + + var mainLink = null; + if (subMenu.children('a') && !subMenu.hasClass('sublink')) { + subMenu.addClass('sublink'); + + var mainLink = $('
  • ').addClass(pos); + subMenu.children('a').clone().appendTo(mainLink) + subMenu.children('a').addClass('mainlink'); + } + + var newMenu = $('