diff options
author | Hugues Hiegel <root@paranoid> | 2014-08-05 16:44:07 +0200 |
---|---|---|
committer | Hugues Hiegel <root@paranoid> | 2014-08-05 16:44:07 +0200 |
commit | f91f8533678c388b879d9e999a6bcc9e22ad7e19 (patch) | |
tree | c0099e25a932399d6cd1066607a42e7fe220b977 /program/js | |
parent | ec116d33c22b371328c8557158736e3d2ee479a8 (diff) |
lot of stuff
Diffstat (limited to 'program/js')
-rw-r--r-- | program/js/app.js | 7271 | ||||
-rw-r--r-- | program/js/common.js | 732 | ||||
-rw-r--r-- | program/js/editor.js | 17 | ||||
-rw-r--r-- | program/js/googiespell.js | 1136 | ||||
l---------[-rw-r--r--] | program/js/jquery.min.js | 3 | ||||
-rw-r--r-- | program/js/jstz.min.js | 13 | ||||
-rw-r--r-- | program/js/list.js | 1626 |
7 files changed, 21 insertions, 10777 deletions
diff --git a/program/js/app.js b/program/js/app.js index f7fd7cea0..efefd3a64 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -1,7270 +1 @@ -/* - +-----------------------------------------------------------------------+ - | Roundcube Webmail Client Script | - | | - | This file is part of the Roundcube Webmail client | - | Copyright (C) 2005-2013, The Roundcube Dev Team | - | Copyright (C) 2011-2013, Kolab Systems AG | - | | - | Licensed under the GNU General Public License version 3 or | - | any later version with exceptions for skins & plugins. | - | See the README file for a full license statement. | - | | - +-----------------------------------------------------------------------+ - | Authors: Thomas Bruederli <roundcube@gmail.com> | - | Aleksander 'A.L.E.C' Machniak <alec@alec.pl> | - | Charles McNulty <charles@charlesmcnulty.com> | - +-----------------------------------------------------------------------+ - | Requires: jquery.js, common.js, list.js | - +-----------------------------------------------------------------------+ -*/ - -function rcube_webmail() -{ - this.labels = {}; - this.buttons = {}; - this.buttons_sel = {}; - this.gui_objects = {}; - this.gui_containers = {}; - this.commands = {}; - this.command_handlers = {}; - this.onloads = []; - this.messages = {}; - this.group2expand = {}; - - // webmail client settings - this.dblclick_time = 500; - this.message_time = 4000; - this.identifier_expr = new RegExp('[^0-9a-z\-_]', 'gi'); - - // environment defaults - this.env = { - request_timeout: 180, // seconds - draft_autosave: 0, // seconds - comm_path: './', - blankpage: 'program/resources/blank.gif', - recipients_separator: ',', - recipients_delimiter: ', ', - popup_width: 1150, - popup_width_small: 900 - }; - - // create protected reference to myself - this.ref = 'rcmail'; - var ref = this; - - // set jQuery ajax options - $.ajaxSetup({ - cache: false, - timeout: this.env.request_timeout * 1000, - error: function(request, status, err){ ref.http_error(request, status, err); }, - beforeSend: function(xmlhttp){ xmlhttp.setRequestHeader('X-Roundcube-Request', ref.env.request_token); } - }); - - // unload fix - $(window).bind('beforeunload', function() { rcmail.unload = true; }); - - // set environment variable(s) - this.set_env = function(p, value) - { - if (p != null && typeof p === 'object' && !value) - for (var n in p) - this.env[n] = p[n]; - else - this.env[p] = value; - }; - - // add a localized label to the client environment - this.add_label = function(p, value) - { - if (typeof p == 'string') - this.labels[p] = value; - else if (typeof p == 'object') - $.extend(this.labels, p); - }; - - // add a button to the button list - this.register_button = function(command, id, type, act, sel, over) - { - var button_prop = {id:id, type:type}; - - if (act) button_prop.act = act; - if (sel) button_prop.sel = sel; - if (over) button_prop.over = over; - - if (!this.buttons[command]) - this.buttons[command] = []; - - this.buttons[command].push(button_prop); - - if (this.loaded) - init_button(command, button_prop); - }; - - // register a specific gui object - this.gui_object = function(name, id) - { - this.gui_objects[name] = this.loaded ? rcube_find_object(id) : id; - }; - - // register a container object - this.gui_container = function(name, id) - { - this.gui_containers[name] = id; - }; - - // add a GUI element (html node) to a specified container - this.add_element = function(elm, container) - { - if (this.gui_containers[container] && this.gui_containers[container].jquery) - this.gui_containers[container].append(elm); - }; - - // register an external handler for a certain command - this.register_command = function(command, callback, enable) - { - this.command_handlers[command] = callback; - - if (enable) - this.enable_command(command, true); - }; - - // execute the given script on load - this.add_onload = function(f) - { - this.onloads.push(f); - }; - - // initialize webmail client - this.init = function() - { - var n, p = this; - this.task = this.env.task; - - // check browser - if (!bw.dom || !bw.xmlhttp_test() || (bw.mz && bw.vendver < 1.9)) { - this.goto_url('error', '_code=0x199'); - return; - } - - // find all registered gui containers - for (n in this.gui_containers) - this.gui_containers[n] = $('#'+this.gui_containers[n]); - - // find all registered gui objects - for (n in this.gui_objects) - this.gui_objects[n] = rcube_find_object(this.gui_objects[n]); - - // clickjacking protection - if (this.env.x_frame_options) { - try { - // bust frame if not allowed - if (this.env.x_frame_options == 'deny' && top.location.href != self.location.href) - top.location.href = self.location.href; - else if (top.location.hostname != self.location.hostname) - throw 1; - } catch (e) { - // possible clickjacking attack: disable all form elements - $('form').each(function(){ ref.lock_form(this, true); }); - this.display_message("Blocked: possible clickjacking attack!", 'error'); - return; - } - } - - // init registered buttons - this.init_buttons(); - - // tell parent window that this frame is loaded - if (this.is_framed()) { - parent.rcmail.set_busy(false, null, parent.rcmail.env.frame_lock); - parent.rcmail.env.frame_lock = null; - } - - // enable general commands - this.enable_command('close', 'logout', 'mail', 'addressbook', 'settings', 'save-pref', - 'compose', 'undo', 'about', 'switch-task', 'menu-open', 'menu-save', true); - - if (this.env.permaurl) - this.enable_command('permaurl', 'extwin', true); - - switch (this.task) { - - case 'mail': - // enable mail commands - this.enable_command('list', 'checkmail', 'add-contact', 'search', 'reset-search', 'collapse-folder', 'import-messages', true); - - if (this.gui_objects.messagelist) { - this.message_list = new rcube_list_widget(this.gui_objects.messagelist, { - multiselect:true, multiexpand:true, draggable:true, keyboard:true, - column_movable:this.env.col_movable, dblclick_time:this.dblclick_time - }); - this.message_list.row_init = function(o){ p.init_message_row(o); }; - this.message_list.addEventListener('dblclick', function(o){ p.msglist_dbl_click(o); }); - this.message_list.addEventListener('click', function(o){ p.msglist_click(o); }); - this.message_list.addEventListener('keypress', function(o){ p.msglist_keypress(o); }); - this.message_list.addEventListener('select', function(o){ p.msglist_select(o); }); - this.message_list.addEventListener('dragstart', function(o){ p.drag_start(o); }); - this.message_list.addEventListener('dragmove', function(e){ p.drag_move(e); }); - this.message_list.addEventListener('dragend', function(e){ p.drag_end(e); }); - this.message_list.addEventListener('expandcollapse', function(e){ p.msglist_expand(e); }); - this.message_list.addEventListener('column_replace', function(e){ p.msglist_set_coltypes(e); }); - this.message_list.addEventListener('listupdate', function(e){ p.triggerEvent('listupdate', e); }); - - document.onmouseup = function(e){ return p.doc_mouse_up(e); }; - this.gui_objects.messagelist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; - - this.message_list.init(); - this.enable_command('toggle_status', 'toggle_flag', 'sort', true); - - // load messages - this.command('list'); - - $(this.gui_objects.qsearchbox).val(this.env.search_text).focusin(function() { rcmail.message_list.blur(); }); - } - - this.set_button_titles(); - - this.env.message_commands = ['show', 'reply', 'reply-all', 'reply-list', - 'move', 'copy', 'delete', 'open', 'mark', 'edit', 'viewsource', - 'print', 'load-attachment', 'download-attachment', 'show-headers', 'hide-headers', 'download', - 'forward', 'forward-inline', 'forward-attachment', 'change-format']; - - if (this.env.action == 'show' || this.env.action == 'preview') { - this.enable_command(this.env.message_commands, this.env.uid); - this.enable_command('reply-list', this.env.list_post); - - if (this.env.action == 'show') { - this.http_request('pagenav', {_uid: this.env.uid, _mbox: this.env.mailbox, _search: this.env.search_request}, - this.display_message('', 'loading')); - } - - if (this.env.blockedobjects) { - if (this.gui_objects.remoteobjectsmsg) - this.gui_objects.remoteobjectsmsg.style.display = 'block'; - this.enable_command('load-images', 'always-load', true); - } - - // make preview/message frame visible - if (this.env.action == 'preview' && this.is_framed()) { - this.enable_command('compose', 'add-contact', false); - parent.rcmail.show_contentframe(true); - } - } - else if (this.env.action == 'compose') { - this.env.address_group_stack = []; - this.env.compose_commands = ['send-attachment', 'remove-attachment', 'send', 'cancel', - 'toggle-editor', 'list-adresses', 'pushgroup', 'search', 'reset-search', 'extwin', - 'insert-response', 'save-response']; - - if (this.env.drafts_mailbox) - this.env.compose_commands.push('savedraft') - - this.enable_command(this.env.compose_commands, 'identities', 'responses', true); - - // add more commands (not enabled) - $.merge(this.env.compose_commands, ['add-recipient', 'firstpage', 'previouspage', 'nextpage', 'lastpage']); - - if (this.env.spellcheck) { - this.env.spellcheck.spelling_state_observer = function(s) { ref.spellcheck_state(); }; - this.env.compose_commands.push('spellcheck') - this.enable_command('spellcheck', true); - } - - // init canned response functions - if (this.gui_objects.responseslist) { - $('a.insertresponse', this.gui_objects.responseslist) - .attr('unselectable', 'on') - .mousedown(function(e){ return rcube_event.cancel(e); }) - .mouseup(function(e){ - ref.command('insert-response', $(this).attr('rel')); - $(document.body).trigger('mouseup'); // hides the menu - return rcube_event.cancel(e); - }); - - // avoid textarea loosing focus when hitting the save-response button/link - for (var i=0; this.buttons['save-response'] && i < this.buttons['save-response'].length; i++) { - $('#'+this.buttons['save-response'][i].id).mousedown(function(e){ return rcube_event.cancel(e); }) - } - } - - document.onmouseup = function(e){ return p.doc_mouse_up(e); }; - - // init message compose form - this.init_messageform(); - } - else if (this.env.action == 'get') - this.enable_command('download', 'print', true); - // show printing dialog - else if (this.env.action == 'print' && this.env.uid) { - if (bw.safari) - setTimeout('window.print()', 10); - else - window.print(); - } - - // get unread count for each mailbox - if (this.gui_objects.mailboxlist) { - this.env.unread_counts = {}; - this.gui_objects.folderlist = this.gui_objects.mailboxlist; - this.http_request('getunread'); - } - - // init address book widget - if (this.gui_objects.contactslist) { - this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, - { multiselect:true, draggable:false, keyboard:false }); - this.contact_list.addEventListener('select', function(o){ ref.compose_recipient_select(o); }); - this.contact_list.addEventListener('dblclick', function(o){ ref.compose_add_recipient('to'); }); - this.contact_list.init(); - } - - if (this.gui_objects.addressbookslist) { - this.gui_objects.folderlist = this.gui_objects.addressbookslist; - this.enable_command('list-adresses', true); - } - - // ask user to send MDN - if (this.env.mdn_request && this.env.uid) { - var postact = 'sendmdn', - postdata = {_uid: this.env.uid, _mbox: this.env.mailbox}; - if (!confirm(this.get_label('mdnrequest'))) { - postdata._flag = 'mdnsent'; - postact = 'mark'; - } - this.http_post(postact, postdata); - } - - // detect browser capabilities - if (!this.is_framed() && !this.env.extwin) - this.browser_capabilities_check(); - - break; - - case 'addressbook': - this.env.address_group_stack = []; - - if (this.gui_objects.folderlist) - this.env.contactfolders = $.extend($.extend({}, this.env.address_sources), this.env.contactgroups); - - this.enable_command('add', 'import', this.env.writable_source); - this.enable_command('list', 'listgroup', 'pushgroup', 'popgroup', 'listsearch', 'search', 'reset-search', 'advanced-search', true); - - if (this.gui_objects.contactslist) { - this.contact_list = new rcube_list_widget(this.gui_objects.contactslist, - {multiselect:true, draggable:this.gui_objects.folderlist?true:false, keyboard:true}); - this.contact_list.row_init = function(row){ p.triggerEvent('insertrow', { cid:row.uid, row:row }); }; - this.contact_list.addEventListener('keypress', function(o){ p.contactlist_keypress(o); }); - this.contact_list.addEventListener('select', function(o){ p.contactlist_select(o); }); - this.contact_list.addEventListener('dragstart', function(o){ p.drag_start(o); }); - this.contact_list.addEventListener('dragmove', function(e){ p.drag_move(e); }); - this.contact_list.addEventListener('dragend', function(e){ p.drag_end(e); }); - this.contact_list.init(); - - if (this.env.cid) - this.contact_list.highlight_row(this.env.cid); - - this.gui_objects.contactslist.parentNode.onmousedown = function(e){ return p.click_on_list(e); }; - document.onmouseup = function(e){ return p.doc_mouse_up(e); }; - - $(this.gui_objects.qsearchbox).focusin(function() { rcmail.contact_list.blur(); }); - - this.update_group_commands(); - this.command('list'); - } - - this.set_page_buttons(); - - if (this.env.cid) { - this.enable_command('show', 'edit', true); - // register handlers for group assignment via checkboxes - if (this.gui_objects.editform) { - $('input.groupmember').change(function() { - ref.group_member_change(this.checked ? 'add' : 'del', ref.env.cid, ref.env.source, this.value); - }); - } - } - - if (this.gui_objects.editform) { - this.enable_command('save', true); - if (this.env.action == 'add' || this.env.action == 'edit' || this.env.action == 'search') - this.init_contact_form(); - } - - break; - - case 'settings': - this.enable_command('preferences', 'identities', 'responses', 'save', 'folders', true); - - if (this.env.action == 'identities') { - this.enable_command('add', this.env.identities_level < 2); - } - else if (this.env.action == 'edit-identity' || this.env.action == 'add-identity') { - this.enable_command('save', 'edit', 'toggle-editor', true); - this.enable_command('delete', this.env.identities_level < 2); - } - else if (this.env.action == 'folders') { - this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true); - } - else if (this.env.action == 'edit-folder' && this.gui_objects.editform) { - this.enable_command('save', 'folder-size', true); - parent.rcmail.env.exists = this.env.messagecount; - parent.rcmail.enable_command('purge', this.env.messagecount); - } - else if (this.env.action == 'responses') { - this.enable_command('add', true); - } - - if (this.gui_objects.identitieslist) { - this.identity_list = new rcube_list_widget(this.gui_objects.identitieslist, {multiselect:false, draggable:false, keyboard:false}); - this.identity_list.addEventListener('select', function(o){ p.identity_select(o); }); - this.identity_list.init(); - this.identity_list.focus(); - - if (this.env.iid) - this.identity_list.highlight_row(this.env.iid); - } - else if (this.gui_objects.sectionslist) { - this.sections_list = new rcube_list_widget(this.gui_objects.sectionslist, {multiselect:false, draggable:false, keyboard:false}); - this.sections_list.addEventListener('select', function(o){ p.section_select(o); }); - this.sections_list.init(); - this.sections_list.focus(); - } - else if (this.gui_objects.subscriptionlist) { - this.init_subscription_list(); - } - else if (this.gui_objects.responseslist) { - this.responses_list = new rcube_list_widget(this.gui_objects.responseslist, {multiselect:false, draggable:false, keyboard:false}); - this.responses_list.addEventListener('select', function(list) { - var win, id = list.get_single_selection(); - p.enable_command('delete', !!id && $.inArray(id, p.env.readonly_responses) < 0); - if (id && (win = p.get_frame_window(p.env.contentframe))) { - p.set_busy(true); - p.location_href({ _action:'edit-response', _key:id, _framed:1 }, win); - } - }); - this.responses_list.init(); - this.responses_list.focus(); - } - - break; - - case 'login': - var input_user = $('#rcmloginuser'); - input_user.bind('keyup', function(e){ return rcmail.login_user_keyup(e); }); - - if (input_user.val() == '') - input_user.focus(); - else - $('#rcmloginpwd').focus(); - - // detect client timezone - if (window.jstz && !bw.ie6) { - var timezone = jstz.determine(); - if (timezone.name()) - $('#rcmlogintz').val(timezone.name()); - } - else { - $('#rcmlogintz').val(new Date().getStdTimezoneOffset() / -60); - } - - // display 'loading' message on form submit, lock submit button - $('form').submit(function () { - $('input[type=submit]', this).prop('disabled', true); - rcmail.clear_messages(); - rcmail.display_message('', 'loading'); - }); - - this.enable_command('login', true); - break; - } - - // select first input field in an edit form - if (this.gui_objects.editform) - $("input,select,textarea", this.gui_objects.editform) - .not(':hidden').not(':disabled').first().select(); - - // unset contentframe variable if preview_pane is enabled - if (this.env.contentframe && !$('#' + this.env.contentframe).is(':visible')) - this.env.contentframe = null; - - // prevent from form submit with Enter key in file input fields - if (bw.ie) - $('input[type=file]').keydown(function(e) { if (e.keyCode == '13') e.preventDefault(); }); - - // flag object as complete - this.loaded = true; - this.env.lastrefresh = new Date(); - - // show message - if (this.pending_message) - this.display_message(this.pending_message[0], this.pending_message[1], this.pending_message[2]); - - // map implicit containers - if (this.gui_objects.folderlist) { - this.gui_containers.foldertray = $(this.gui_objects.folderlist); - - // init treelist widget - if (window.rcube_treelist_widget) { - this.treelist = new rcube_treelist_widget(this.gui_objects.folderlist, { - id_prefix: 'rcmli', - id_encode: this.html_identifier_encode, - id_decode: this.html_identifier_decode, - check_droptarget: function(node){ return !node.virtual && ref.check_droptarget(node.id) } - }); - this.treelist.addEventListener('collapse', function(node){ ref.folder_collapsed(node) }); - this.treelist.addEventListener('expand', function(node){ ref.folder_collapsed(node) }); - this.treelist.addEventListener('select', function(node){ ref.triggerEvent('selectfolder', { folder:node.id, prefix:'rcmli' }) }); - } - } - - // activate html5 file drop feature (if browser supports it and if configured) - if (this.gui_objects.filedrop && this.env.filedrop && ((window.XMLHttpRequest && XMLHttpRequest.prototype && XMLHttpRequest.prototype.sendAsBinary) || window.FormData)) { - $(document.body).bind('dragover dragleave drop', function(e){ return ref.document_drag_hover(e, e.type == 'dragover'); }); - $(this.gui_objects.filedrop).addClass('droptarget') - .bind('dragover dragleave', function(e){ return ref.file_drag_hover(e, e.type == 'dragover'); }) - .get(0).addEventListener('drop', function(e){ return ref.file_dropped(e); }, false); - } - - // trigger init event hook - this.triggerEvent('init', { task:this.task, action:this.env.action }); - - // execute all foreign onload scripts - // @deprecated - for (var i in this.onloads) { - if (typeof this.onloads[i] === 'string') - eval(this.onloads[i]); - else if (typeof this.onloads[i] === 'function') - this.onloads[i](); - } - - // start keep-alive and refresh intervals - this.start_refresh(); - this.start_keepalive(); - }; - - this.log = function(msg) - { - if (window.console && console.log) - console.log(msg); - }; - - /*********************************************************/ - /********* client command interface *********/ - /*********************************************************/ - - // execute a specific command on the web client - this.command = function(command, props, obj, event) - { - var ret, uid, cid, url, flag; - - if (obj && obj.blur) - obj.blur(); - - if (this.busy) - return false; - - // let the browser handle this click (shift/ctrl usually opens the link in a new window/tab) - if ((obj && obj.href && String(obj.href).indexOf('#') < 0) && rcube_event.get_modifier(event)) { - return true; - } - - // command not supported or allowed - if (!this.commands[command]) { - // pass command to parent window - if (this.is_framed()) - parent.rcmail.command(command, props); - - return false; - } - - // check input before leaving compose step - if (this.task == 'mail' && this.env.action == 'compose' && $.inArray(command, this.env.compose_commands)<0) { - if (this.cmp_hash != this.compose_field_hash() && !confirm(this.get_label('notsentwarning'))) - return false; - } - - // process external commands - if (typeof this.command_handlers[command] === 'function') { - ret = this.command_handlers[command](props, obj); - return ret !== undefined ? ret : (obj ? false : true); - } - else if (typeof this.command_handlers[command] === 'string') { - ret = window[this.command_handlers[command]](props, obj); - return ret !== undefined ? ret : (obj ? false : true); - } - - // trigger plugin hooks - this.triggerEvent('actionbefore', {props:props, action:command}); - ret = this.triggerEvent('before'+command, props); - if (ret !== undefined) { - // abort if one of the handlers returned false - if (ret === false) - return false; - else - props = ret; - } - - ret = undefined; - - // process internal command - switch (command) { - - case 'login': - if (this.gui_objects.loginform) - this.gui_objects.loginform.submit(); - break; - - // commands to switch task - case 'mail': - case 'addressbook': - case 'settings': - case 'logout': - this.switch_task(command); - break; - - case 'about': - this.redirect('?_task=settings&_action=about', false); - break; - - case 'permaurl': - if (obj && obj.href && obj.target) - return true; - else if (this.env.permaurl) - parent.location.href = this.env.permaurl; - break; - - case 'extwin': - if (this.env.action == 'compose') { - var form = this.gui_objects.messageform, - win = this.open_window(''); - - $("input[name='_action']", form).val('compose'); - form.action = this.url('mail/compose', { _id: this.env.compose_id, _extwin: 1 }); - form.target = win.name; - form.submit(); - } - else { - this.open_window(this.env.permaurl, true); - } - break; - - case 'change-format': - url = this.env.permaurl + '&_format=' + props; - - if (this.env.action == 'preview') - url = url.replace(/_action=show/, '_action=preview') + '&_framed=1'; - if (this.env.extwin) - url += '&_extwin=1'; - - location.href = url; - break; - - case 'menu-open': - if (props && props.menu == 'attachmentmenu') { - var mimetype = this.env.attachments[props.id]; - this.enable_command('open-attachment', mimetype && this.env.mimetypes && $.inArray(mimetype, this.env.mimetypes) >= 0); - } - - case 'menu-save': - this.triggerEvent(command, {props:props}); - return false; - - case 'open': - if (uid = this.get_single_uid()) { - obj.href = this.url('show', {_mbox: this.env.mailbox, _uid: uid}); - return true; - } - break; - - case 'close': - if (this.env.extwin) - window.close(); - break; - - case 'list': - if (props && props != '') - this.reset_qsearch(); - if (this.env.action == 'compose' && this.env.extwin) - window.close(); - else if (this.task == 'mail') { - this.list_mailbox(props); - this.set_button_titles(); - } - else if (this.task == 'addressbook') - this.list_contacts(props); - break; - - case 'sort': - var sort_order = this.env.sort_order, - sort_col = !this.env.disabled_sort_col ? props : this.env.sort_col; - - if (!this.env.disabled_sort_order) - sort_order = this.env.sort_col == sort_col && sort_order == 'ASC' ? 'DESC' : 'ASC'; - - // set table header and update env - this.set_list_sorting(sort_col, sort_order); - - // reload message list - this.list_mailbox('', '', sort_col+'_'+sort_order); - break; - - case 'nextpage': - this.list_page('next'); - break; - - case 'lastpage': - this.list_page('last'); - break; - - case 'previouspage': - this.list_page('prev'); - break; - - case 'firstpage': - this.list_page('first'); - break; - - case 'expunge': - if (this.env.exists) - this.expunge_mailbox(this.env.mailbox); - break; - - case 'purge': - case 'empty-mailbox': - if (this.env.exists) - this.purge_mailbox(this.env.mailbox); - break; - - // common commands used in multiple tasks - case 'show': - if (this.task == 'mail') { - uid = this.get_single_uid(); - if (uid && (!this.env.uid || uid != this.env.uid)) { - if (this.env.mailbox == this.env.drafts_mailbox) - this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox }); - else - this.show_message(uid); - } - } - else if (this.task == 'addressbook') { - cid = props ? props : this.get_single_cid(); - if (cid && !(this.env.action == 'show' && cid == this.env.cid)) - this.load_contact(cid, 'show'); - } - break; - - case 'add': - if (this.task == 'addressbook') - this.load_contact(0, 'add'); - else if (this.task == 'settings' && this.env.action == 'responses') { - var frame; - if ((frame = this.get_frame_window(this.env.contentframe))) { - this.set_busy(true); - this.location_href({ _action:'add-response', _framed:1 }, frame); - } - } - else if (this.task == 'settings') { - this.identity_list.clear_selection(); - this.load_identity(0, 'add-identity'); - } - break; - - case 'edit': - if (this.task == 'addressbook' && (cid = this.get_single_cid())) - this.load_contact(cid, 'edit'); - else if (this.task == 'settings' && props) - this.load_identity(props, 'edit-identity'); - else if (this.task == 'mail' && (cid = this.get_single_uid())) { - url = { _mbox: this.env.mailbox }; - url[this.env.mailbox == this.env.drafts_mailbox && props != 'new' ? '_draft_uid' : '_uid'] = cid; - this.open_compose_step(url); - } - break; - - case 'save': - var input, form = this.gui_objects.editform; - if (form) { - // adv. search - if (this.env.action == 'search') { - } - // user prefs - else if ((input = $("input[name='_pagesize']", form)) && input.length && isNaN(parseInt(input.val()))) { - alert(this.get_label('nopagesizewarning')); - input.focus(); - break; - } - // contacts/identities - else { - // reload form - if (props == 'reload') { - form.action += '?_reload=1'; - } - else if (this.task == 'settings' && (this.env.identities_level % 2) == 0 && - (input = $("input[name='_email']", form)) && input.length && !rcube_check_email(input.val()) - ) { - alert(this.get_label('noemailwarning')); - input.focus(); - break; - } - - // clear empty input fields - $('input.placeholder').each(function(){ if (this.value == this._placeholder) this.value = ''; }); - } - - // add selected source (on the list) - if (parent.rcmail && parent.rcmail.env.source) - form.action = this.add_url(form.action, '_orig_source', parent.rcmail.env.source); - - form.submit(); - } - break; - - case 'delete': - // mail task - if (this.task == 'mail') - this.delete_messages(event); - // addressbook task - else if (this.task == 'addressbook') - this.delete_contacts(); - // settings: canned response - else if (this.task == 'settings' && this.env.action == 'responses') - this.delete_response(); - // settings: user identities - else if (this.task == 'settings') - this.delete_identity(); - break; - - // mail task commands - case 'move': - case 'moveto': // deprecated - if (this.task == 'mail') - this.move_messages(props); - else if (this.task == 'addressbook') - this.move_contacts(props); - break; - - case 'copy': - if (this.task == 'mail') - this.copy_messages(props); - else if (this.task == 'addressbook') - this.copy_contacts(props); - break; - - case 'mark': - if (props) - this.mark_message(props); - break; - - case 'toggle_status': - case 'toggle_flag': - flag = command == 'toggle_flag' ? 'flagged' : 'read'; - - if (uid = props) { - // toggle flagged/unflagged - if (flag == 'flagged') { - if (this.message_list.rows[uid].flagged) - flag = 'unflagged'; - } - // toggle read/unread - else if (this.message_list.rows[uid].deleted) - flag = 'undelete'; - else if (!this.message_list.rows[uid].unread) - flag = 'unread'; - - this.mark_message(flag, uid); - } - - break; - - case 'always-load': - if (this.env.uid && this.env.sender) { - this.add_contact(this.env.sender); - setTimeout(function(){ ref.command('load-images'); }, 300); - break; - } - - case 'load-images': - if (this.env.uid) - this.show_message(this.env.uid, true, this.env.action=='preview'); - break; - - case 'load-attachment': - case 'open-attachment': - case 'download-attachment': - var qstring = '_mbox='+urlencode(this.env.mailbox)+'&_uid='+this.env.uid+'&_part='+props, - mimetype = this.env.attachments[props]; - - // open attachment in frame if it's of a supported mimetype - if (command != 'download-attachment' && mimetype && this.env.mimetypes && $.inArray(mimetype, this.env.mimetypes) >= 0) { - if (this.open_window(this.env.comm_path+'&_action=get&'+qstring+'&_frame=1')) - break; - } - - this.goto_url('get', qstring+'&_download=1', false); - break; - - case 'select-all': - this.select_all_mode = props ? false : true; - this.dummy_select = true; // prevent msg opening if there's only one msg on the list - if (props == 'invert') - this.message_list.invert_selection(); - else - this.message_list.select_all(props == 'page' ? '' : props); - this.dummy_select = null; - break; - - case 'select-none': - this.select_all_mode = false; - this.message_list.clear_selection(); - break; - - case 'expand-all': - this.env.autoexpand_threads = 1; - this.message_list.expand_all(); - break; - - case 'expand-unread': - this.env.autoexpand_threads = 2; - this.message_list.collapse_all(); - this.expand_unread(); - break; - - case 'collapse-all': - this.env.autoexpand_threads = 0; - this.message_list.collapse_all(); - break; - - case 'nextmessage': - if (this.env.next_uid) - this.show_message(this.env.next_uid, false, this.env.action == 'preview'); - break; - - case 'lastmessage': - if (this.env.last_uid) - this.show_message(this.env.last_uid); - break; - - case 'previousmessage': - if (this.env.prev_uid) - this.show_message(this.env.prev_uid, false, this.env.action == 'preview'); - break; - - case 'firstmessage': - if (this.env.first_uid) - this.show_message(this.env.first_uid); - break; - - case 'compose': - url = {}; - - if (this.task == 'mail') { - url._mbox = this.env.mailbox; - if (props) - url._to = props; - // also send search request so we can go back to search result after message is sent - if (this.env.search_request) - url._search = this.env.search_request; - } - // modify url if we're in addressbook - else if (this.task == 'addressbook') { - // switch to mail compose step directly - if (props && props.indexOf('@') > 0) { - url._to = props; - } - else { - var a_cids = []; - // use contact id passed as command parameter - if (props) - a_cids.push(props); - // get selected contacts - else if (this.contact_list) - a_cids = this.contact_list.get_selection(); - - if (a_cids.length) - this.http_post('mailto', { _cid: a_cids.join(','), _source: this.env.source }, true); - else if (this.env.group) - this.http_post('mailto', { _gid: this.env.group, _source: this.env.source }, true); - - break; - } - } - else if (props) - url._to = props; - - this.open_compose_step(url); - break; - - case 'spellcheck': - if (this.spellcheck_state()) { - this.stop_spellchecking(); - } - else { - if (window.tinyMCE && tinyMCE.get(this.env.composebody)) { - tinyMCE.execCommand('mceSpellCheck', true); - } - else if (this.env.spellcheck && this.env.spellcheck.spellCheck) { - this.env.spellcheck.spellCheck(); - } - } - this.spellcheck_state(); - break; - - case 'savedraft': - // Reset the auto-save timer - clearTimeout(this.save_timer); - - // compose form did not change (and draft wasn't saved already) - if (this.env.draft_id && this.cmp_hash == this.compose_field_hash()) { - this.auto_save_start(); - break; - } - - this.submit_messageform(true); - break; - - case 'send': - if (!props.nocheck && !this.check_compose_input(command)) - break; - - // Reset the auto-save timer - clearTimeout(this.save_timer); - - this.submit_messageform(); - break; - - case 'send-attachment': - // Reset the auto-save timer - clearTimeout(this.save_timer); - - this.upload_file(props || this.gui_objects.uploadform, 'upload'); - break; - - case 'insert-sig': - this.change_identity($("[name='_from']")[0], true); - break; - - case 'list-adresses': - this.list_contacts(props); - this.enable_command('add-recipient', false); - break; - - case 'add-recipient': - this.compose_add_recipient(props); - break; - - case 'reply-all': - case 'reply-list': - case 'reply': - if (uid = this.get_single_uid()) { - url = {_reply_uid: uid, _mbox: this.env.mailbox}; - if (command == 'reply-all') - // do reply-list, when list is detected and popup menu wasn't used - url._all = (!props && this.env.reply_all_mode == 1 && this.commands['reply-list'] ? 'list' : 'all'); - else if (command == 'reply-list') - url._all = 'list'; - - this.open_compose_step(url); - } - break; - - case 'forward-attachment': - case 'forward-inline': - case 'forward': - var uids = this.env.uid ? [this.env.uid] : (this.message_list ? this.message_list.get_selection() : []); - if (uids.length) { - url = { _forward_uid: this.uids_to_list(uids), _mbox: this.env.mailbox }; - if (command == 'forward-attachment' || (!props && this.env.forward_attachment) || uids.length > 1) - url._attachment = 1; - this.open_compose_step(url); - } - break; - - case 'print': - if (this.env.action == 'get') { - this.gui_objects.messagepartframe.contentWindow.print(); - } - else if (uid = this.get_single_uid()) { - ref.printwin = this.open_window(this.env.comm_path+'&_action=print&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox)+(this.env.safemode ? '&_safe=1' : ''), true, true); - if (this.printwin) { - if (this.env.action != 'show') - this.mark_message('read', uid); - } - } - break; - - case 'viewsource': - if (uid = this.get_single_uid()) - this.open_window(this.env.comm_path+'&_action=viewsource&_uid='+uid+'&_mbox='+urlencode(this.env.mailbox), true, true); - break; - - case 'download': - if (this.env.action == 'get') { - location.href = location.href.replace(/_frame=/, '_download='); - } - else if (uid = this.get_single_uid()) - this.goto_url('viewsource', { _uid: uid, _mbox: this.env.mailbox, _save: 1 }); - break; - - // quicksearch - case 'search': - if (!props && this.gui_objects.qsearchbox) - props = this.gui_objects.qsearchbox.value; - if (props) { - this.qsearch(props); - break; - } - - // reset quicksearch - case 'reset-search': - var n, s = this.env.search_request || this.env.qsearch; - - this.reset_qsearch(); - this.select_all_mode = false; - - if (s && this.env.action == 'compose') { - if (this.contact_list) - this.list_contacts_clear(); - } - else if (s && this.env.mailbox) { - this.list_mailbox(this.env.mailbox, 1); - } - else if (s && this.task == 'addressbook') { - if (this.env.source == '') { - for (n in this.env.address_sources) break; - this.env.source = n; - this.env.group = ''; - } - this.list_contacts(this.env.source, this.env.group, 1); - } - break; - - case 'pushgroup': - // add group ID to stack - this.env.address_group_stack.push(props.id); - if (obj && event) - rcube_event.cancel(event); - - case 'listgroup': - this.reset_qsearch(); - this.list_contacts(props.source, props.id); - break; - - case 'popgroup': - if (this.env.address_group_stack.length > 1) { - this.env.address_group_stack.pop(); - this.reset_qsearch(); - this.list_contacts(props.source, this.env.address_group_stack[this.env.address_group_stack.length-1]); - } - break; - - case 'import-messages': - var form = props || this.gui_objects.importform; - $('input[name="_unlock"]', form).val(this.set_busy(true, 'importwait')); - this.upload_file(form, 'import'); - break; - - case 'import': - if (this.env.action == 'import' && this.gui_objects.importform) { - var file = document.getElementById('rcmimportfile'); - if (file && !file.value) { - alert(this.get_label('selectimportfile')); - break; - } - this.gui_objects.importform.submit(); - this.set_busy(true, 'importwait'); - this.lock_form(this.gui_objects.importform, true); - } - else - this.goto_url('import', (this.env.source ? '_target='+urlencode(this.env.source)+'&' : '')); - break; - - case 'export': - if (this.contact_list.rowcount > 0) { - this.goto_url('export', { _source: this.env.source, _gid: this.env.group, _search: this.env.search_request }); - } - break; - - case 'export-selected': - if (this.contact_list.rowcount > 0) { - this.goto_url('export', { _source: this.env.source, _gid: this.env.group, _cid: this.contact_list.get_selection().join(',') }); - } - break; - - case 'upload-photo': - this.upload_contact_photo(props || this.gui_objects.uploadform); - break; - - case 'delete-photo': - this.replace_contact_photo('-del-'); - break; - - // user settings commands - case 'preferences': - case 'identities': - case 'responses': - case 'folders': - this.goto_url('settings/' + command); - break; - - case 'undo': - this.http_request('undo', '', this.display_message('', 'loading')); - break; - - // unified command call (command name == function name) - default: - var func = command.replace(/-/g, '_'); - if (this[func] && typeof this[func] === 'function') { - ret = this[func](props, obj); - } - break; - } - - if (this.triggerEvent('after'+command, props) === false) - ret = false; - this.triggerEvent('actionafter', {props:props, action:command}); - - return ret === false ? false : obj ? false : true; - }; - - // set command(s) enabled or disabled - this.enable_command = function() - { - var i, n, args = Array.prototype.slice.call(arguments), - enable = args.pop(), cmd; - - for (n=0; n<args.length; n++) { - cmd = args[n]; - // argument of type array - if (typeof cmd === 'string') { - this.commands[cmd] = enable; - this.set_button(cmd, (enable ? 'act' : 'pas')); - this.triggerEvent('enable-command', {command: cmd, status: enable}); - } - // push array elements into commands array - else { - for (i in cmd) - args.push(cmd[i]); - } - } - }; - - // lock/unlock interface - this.set_busy = function(a, message, id) - { - if (a && message) { - var msg = this.get_label(message); - if (msg == message) - msg = 'Loading...'; - - id = this.display_message(msg, 'loading'); - } - else if (!a && id) { - this.hide_message(id); - } - - this.busy = a; - //document.body.style.cursor = a ? 'wait' : 'default'; - - if (this.gui_objects.editform) - this.lock_form(this.gui_objects.editform, a); - - return id; - }; - - // return a localized string - this.get_label = function(name, domain) - { - if (domain && this.labels[domain+'.'+name]) - return this.labels[domain+'.'+name]; - else if (this.labels[name]) - return this.labels[name]; - else - return name; - }; - - // alias for convenience reasons - this.gettext = this.get_label; - - // switch to another application task - this.switch_task = function(task) - { - if (this.task===task && task!='mail') - return; - - var url = this.get_task_url(task); - if (task=='mail') - url += '&_mbox=INBOX'; - - this.redirect(url); - }; - - this.get_task_url = function(task, url) - { - if (!url) - url = this.env.comm_path; - - return url.replace(/_task=[a-z0-9_-]+/i, '_task='+task); - }; - - this.reload = function(delay) - { - if (this.is_framed()) - parent.rcmail.reload(delay); - else if (delay) - setTimeout(function(){ rcmail.reload(); }, delay); - else if (window.location) - location.href = this.env.comm_path + (this.env.action ? '&_action='+this.env.action : ''); - }; - - // Add variable to GET string, replace old value if exists - this.add_url = function(url, name, value) - { - value = urlencode(value); - - if (/(\?.*)$/.test(url)) { - var urldata = RegExp.$1, - datax = RegExp('((\\?|&)'+RegExp.escape(name)+'=[^&]*)'); - - if (datax.test(urldata)) { - urldata = urldata.replace(datax, RegExp.$2 + name + '=' + value); - } - else - urldata += '&' + name + '=' + value - - return url.replace(/(\?.*)$/, urldata); - } - - return url + '?' + name + '=' + value; - }; - - this.is_framed = function() - { - return (this.env.framed && parent.rcmail && parent.rcmail != this && parent.rcmail.command); - }; - - this.save_pref = function(prop) - { - var request = {'_name': prop.name, '_value': prop.value}; - - if (prop.session) - request['_session'] = prop.session; - if (prop.env) - this.env[prop.env] = prop.value; - - this.http_post('save-pref', request); - }; - - this.html_identifier = function(str, encode) - { - return encode ? this.html_identifier_encode(str) : String(str).replace(this.identifier_expr, '_'); - }; - - this.html_identifier_encode = function(str) - { - return Base64.encode(String(str)).replace(/=+$/, '').replace(/\+/g, '-').replace(/\//g, '_'); - }; - - this.html_identifier_decode = function(str) - { - str = String(str).replace(/-/g, '+').replace(/_/g, '/'); - - while (str.length % 4) str += '='; - - return Base64.decode(str); - }; - - - /*********************************************************/ - /********* event handling methods *********/ - /*********************************************************/ - - this.drag_menu = function(e, target) - { - var modkey = rcube_event.get_modifier(e), - menu = this.gui_objects.dragmenu; - - if (menu && modkey == SHIFT_KEY && this.commands['copy']) { - var pos = rcube_event.get_mouse_pos(e); - this.env.drag_target = target; - $(menu).css({top: (pos.y-10)+'px', left: (pos.x-10)+'px'}).show(); - return true; - } - - return false; - }; - - this.drag_menu_action = function(action) - { - var menu = this.gui_objects.dragmenu; - if (menu) { - $(menu).hide(); - } - this.command(action, this.env.drag_target); - this.env.drag_target = null; - }; - - this.drag_start = function(list) - { - var model = this.task == 'mail' ? this.env.mailboxes : this.env.contactfolders; - - this.drag_active = true; - - if (this.preview_timer) - clearTimeout(this.preview_timer); - if (this.preview_read_timer) - clearTimeout(this.preview_read_timer); - - // prepare treelist widget for dragging interactions - if (this.treelist) - this.treelist.drag_start(); - }; - - this.drag_end = function(e) - { - this.drag_active = false; - this.env.last_folder_target = null; - - if (this.treelist) - this.treelist.drag_end(); - }; - - this.drag_move = function(e) - { - if (this.gui_objects.folderlist) { - var drag_target, oldclass, - layerclass = 'draglayernormal', - mouse = rcube_event.get_mouse_pos(e); - - if (this.contact_list && this.contact_list.draglayer) - oldclass = this.contact_list.draglayer.attr('class'); - - // mouse intersects a valid drop target on the treelist - if (this.treelist && (drag_target = this.treelist.intersects(mouse, true))) { - this.env.last_folder_target = drag_target; - layerclass = 'draglayer' + (this.check_droptarget(drag_target) > 1 ? 'copy' : 'normal'); - } - else { - // Clear target, otherwise drag end will trigger move into last valid droptarget - this.env.last_folder_target = null; - } - - if (layerclass != oldclass && this.contact_list && this.contact_list.draglayer) - this.contact_list.draglayer.attr('class', layerclass); - } - }; - - this.collapse_folder = function(name) - { - if (this.treelist) - this.treelist.toggle(name); - }; - - this.folder_collapsed = function(node) - { - var prefname = this.env.task == 'addressbook' ? 'collapsed_abooks' : 'collapsed_folders'; - - if (node.collapsed) { - this.env[prefname] = this.env[prefname] + '&'+urlencode(node.id)+'&'; - - // select the folder if one of its childs is currently selected - // don't select if it's virtual (#1488346) - if (this.env.mailbox && this.env.mailbox.startsWith(name + this.env.delimiter) && !node.virtual) - this.command('list', name); - } - else { - var reg = new RegExp('&'+urlencode(node.id)+'&'); - this.env[prefname] = this.env[prefname].replace(reg, ''); - } - - if (!this.drag_active) { - this.command('save-pref', { name: prefname, value: this.env[prefname] }); - - if (this.env.unread_counts) - this.set_unread_count_display(node.id, false); - } - }; - - this.doc_mouse_up = function(e) - { - var model, list, id; - - // ignore event if jquery UI dialog is open - if ($(rcube_event.get_target(e)).closest('.ui-dialog, .ui-widget-overlay').length) - return; - - if (list = this.message_list) - model = this.env.mailboxes; - else if (list = this.contact_list) - model = this.env.contactfolders; - else if (this.ksearch_value) - this.ksearch_blur(); - - if (list && !rcube_mouse_is_over(e, list.list.parentNode)) - list.blur(); - - // handle mouse release when dragging - if (this.drag_active && model && this.env.last_folder_target) { - var target = model[this.env.last_folder_target]; - - this.env.last_folder_target = null; - list.draglayer.hide(); - this.drag_end(e); - - if (this.contact_list) { - if (!this.contacts_drag_menu(e, target)) - this.command('move', target); - } - else if (!this.drag_menu(e, target)) - this.command('move', target); - } - - // reset 'pressed' buttons - if (this.buttons_sel) { - for (id in this.buttons_sel) - if (typeof id !== 'function') - this.button_out(this.buttons_sel[id], id); - this.buttons_sel = {}; - } - }; - - this.click_on_list = function(e) - { - if (this.gui_objects.qsearchbox) - this.gui_objects.qsearchbox.blur(); - - if (this.message_list) - this.message_list.focus(); - else if (this.contact_list) - this.contact_list.focus(); - - return true; - }; - - this.msglist_select = function(list) - { - if (this.preview_timer) - clearTimeout(this.preview_timer); - if (this.preview_read_timer) - clearTimeout(this.preview_read_timer); - - var selected = list.get_single_selection(); - - this.enable_command(this.env.message_commands, selected != null); - if (selected) { - // Hide certain command buttons when Drafts folder is selected - if (this.env.mailbox == this.env.drafts_mailbox) - this.enable_command('reply', 'reply-all', 'reply-list', 'forward', 'forward-attachment', 'forward-inline', false); - // Disable reply-list when List-Post header is not set - else { - var msg = this.env.messages[selected]; - if (!msg.ml) - this.enable_command('reply-list', false); - } - } - // Multi-message commands - this.enable_command('delete', 'move', 'copy', 'mark', 'forward', 'forward-attachment', list.selection.length > 0); - - // reset all-pages-selection - if (selected || (list.selection.length && list.selection.length != list.rowcount)) - this.select_all_mode = false; - - // start timer for message preview (wait for double click) - if (selected && this.env.contentframe && !list.multi_selecting && !this.dummy_select) - this.preview_timer = setTimeout(function() { ref.msglist_get_preview(); }, this.dblclick_time); - else if (this.env.contentframe) - this.show_contentframe(false); - }; - - // This allow as to re-select selected message and display it in preview frame - this.msglist_click = function(list) - { - if (list.multi_selecting || !this.env.contentframe) - return; - - if (list.get_single_selection()) - return; - - var win = this.get_frame_window(this.env.contentframe); - - if (win && win.location.href.indexOf(this.env.blankpage) >= 0) { - if (this.preview_timer) - clearTimeout(this.preview_timer); - if (this.preview_read_timer) - clearTimeout(this.preview_read_timer); - - this.preview_timer = setTimeout(function() { ref.msglist_get_preview(); }, this.dblclick_time); - } - }; - - this.msglist_dbl_click = function(list) - { - if (this.preview_timer) - clearTimeout(this.preview_timer); - if (this.preview_read_timer) - clearTimeout(this.preview_read_timer); - - var uid = list.get_single_selection(); - - if (uid && this.env.mailbox == this.env.drafts_mailbox) - this.open_compose_step({ _draft_uid: uid, _mbox: this.env.mailbox }); - else if (uid) - this.show_message(uid, false, false); - }; - - this.msglist_keypress = function(list) - { - if (list.modkey == CONTROL_KEY) - return; - - if (list.key_pressed == list.ENTER_KEY) - this.command('show'); - else if (list.key_pressed == list.DELETE_KEY || list.key_pressed == list.BACKSPACE_KEY) - this.command('delete'); - else if (list.key_pressed == 33) - this.command('previouspage'); - else if (list.key_pressed == 34) - this.command('nextpage'); - }; - - this.msglist_get_preview = function() - { - var uid = this.get_single_uid(); - if (uid && this.env.contentframe && !this.drag_active) - this.show_message(uid, false, true); - else if (this.env.contentframe) - this.show_contentframe(false); - }; - - this.msglist_expand = function(row) - { - if (this.env.messages[row.uid]) - this.env.messages[row.uid].expanded = row.expanded; - $(row.obj)[row.expanded?'addClass':'removeClass']('expanded'); - }; - - this.msglist_set_coltypes = function(list) - { - var i, found, name, cols = list.thead.rows[0].cells; - - this.env.coltypes = []; - - for (i=0; i<cols.length; i++) - if (cols[i].id && cols[i].id.startsWith('rcm')) { - name = cols[i].id.slice(3); - this.env.coltypes.push(name); - } - - if ((found = $.inArray('flag', this.env.coltypes)) >= 0) - this.env.flagged_col = found; - - if ((found = $.inArray('subject', this.env.coltypes)) >= 0) - this.env.subject_col = found; - - this.command('save-pref', { name: 'list_cols', value: this.env.coltypes, session: 'list_attrib/columns' }); - }; - - this.check_droptarget = function(id) - { - switch (this.task) { - case 'mail': - return (this.env.mailboxes[id] && this.env.mailboxes[id].id != this.env.mailbox && !this.env.mailboxes[id].virtual) ? 1 : 0; - - case 'settings': - return id != this.env.mailbox ? 1 : 0; - - case 'addressbook': - var target; - if (id != this.env.source && (target = this.env.contactfolders[id])) { - // droptarget is a group - if (target.type == 'group') { - if (target.id != this.env.group && !this.env.contactfolders[target.source].readonly) { - var is_other = this.env.selection_sources.length > 1 || $.inArray(target.source, this.env.selection_sources) == -1; - return !is_other || this.commands.move ? 1 : 2; - } - } - // droptarget is a (writable) addressbook and it's not the source - else if (!target.readonly && (this.env.selection_sources.length > 1 || $.inArray(id, this.env.selection_sources) == -1)) { - return this.commands.move ? 1 : 2; - } - } - } - - return 0; - }; - - // open popup window - this.open_window = function(url, small, toolbar) - { - var wname = 'rcmextwin' + new Date().getTime(); - - url += (url.match(/\?/) ? '&' : '?') + '_extwin=1'; - - if (this.env.standard_windows) - extwin = window.open(url, wname); - else { - var win = this.is_framed() ? parent.window : window, - page = $(win), - page_width = page.width(), - page_height = bw.mz ? $('body', win).height() : page.height(), - w = Math.min(small ? this.env.popup_width_small : this.env.popup_width, page_width), - h = page_height, // always use same height - l = (win.screenLeft || win.screenX) + 20, - t = (win.screenTop || win.screenY) + 20, - extwin = window.open(url, wname, - 'width='+w+',height='+h+',top='+t+',left='+l+',resizable=yes,location=no,scrollbars=yes' - +(toolbar ? ',toolbar=yes,menubar=yes,status=yes' : ',toolbar=no,menubar=no,status=no')); - } - - // write loading... message to empty windows - if (!url && extwin.document) { - extwin.document.write('<html><body>' + this.get_label('loading') + '</body></html>'); - } - - // focus window, delayed to bring to front - window.setTimeout(function() { extwin.focus(); }, 10); - - return extwin; - }; - - - /*********************************************************/ - /********* (message) list functionality *********/ - /*********************************************************/ - - this.init_message_row = function(row) - { - var i, fn = {}, self = this, uid = row.uid, - status_icon = (this.env.status_col != null ? 'status' : 'msg') + 'icn' + row.uid; - - if (uid && this.env.messages[uid]) - $.extend(row, this.env.messages[uid]); - - // set eventhandler to status icon - if (row.icon = document.getElementById(status_icon)) { - fn.icon = function(e) { self.command('toggle_status', uid); }; - } - - // save message icon position too - if (this.env.status_col != null) - row.msgicon = document.getElementById('msgicn'+row.uid); - else - row.msgicon = row.icon; - - // set eventhandler to flag icon - if (this.env.flagged_col != null && (row.flagicon = document.getElementById('flagicn'+row.uid))) { - fn.flagicon = function(e) { self.command('toggle_flag', uid); }; - } - - // set event handler to thread expand/collapse icon - if (!row.depth && row.has_children && (row.expando = document.getElementById('rcmexpando'+row.uid))) { - fn.expando = function(e) { self.expand_message_row(e, uid); }; - } - - // attach events - $.each(fn, function(i, f) { - row[i].onclick = function(e) { f(e); return rcube_event.cancel(e); }; - if (bw.touch) { - row[i].addEventListener('touchend', function(e) { - if (e.changedTouches.length == 1) { - f(e); - return rcube_event.cancel(e); - } - }, false); - } - }); - - this.triggerEvent('insertrow', { uid:uid, row:row }); - }; - - // create a table row in the message list - this.add_message_row = function(uid, cols, flags, attop) - { - if (!this.gui_objects.messagelist || !this.message_list) - return false; - - // Prevent from adding messages from different folder (#1487752) - if (flags.mbox != this.env.mailbox && !flags.skip_mbox_check) - return false; - - if (!this.env.messages[uid]) - this.env.messages[uid] = {}; - - // merge flags over local message object - $.extend(this.env.messages[uid], { - deleted: flags.deleted?1:0, - replied: flags.answered?1:0, - unread: !flags.seen?1:0, - forwarded: flags.forwarded?1:0, - flagged: flags.flagged?1:0, - has_children: flags.has_children?1:0, - depth: flags.depth?flags.depth:0, - unread_children: flags.unread_children?flags.unread_children:0, - parent_uid: flags.parent_uid?flags.parent_uid:0, - selected: this.select_all_mode || this.message_list.in_selection(uid), - ml: flags.ml?1:0, - ctype: flags.ctype, - // flags from plugins - flags: flags.extra_flags - }); - - var c, n, col, html, css_class, - tree = '', expando = '', - list = this.message_list, - rows = list.rows, - message = this.env.messages[uid], - row_class = 'message' - + (!flags.seen ? ' unread' : '') - + (flags.deleted ? ' deleted' : '') - + (flags.flagged ? ' flagged' : '') - + (message.selected ? ' selected' : ''), - row = { cols:[], style:{}, id:'rcmrow'+uid }; - - // message status icons - css_class = 'msgicon'; - if (this.env.status_col === null) { - css_class += ' status'; - if (flags.deleted) - css_class += ' deleted'; - else if (!flags.seen) - css_class += ' unread'; - else if (flags.unread_children > 0) - css_class += ' unreadchildren'; - } - if (flags.answered) - css_class += ' replied'; - if (flags.forwarded) - css_class += ' forwarded'; - - // update selection - if (message.selected && !list.in_selection(uid)) - list.selection.push(uid); - - // threads - if (this.env.threading) { - if (message.depth) { - // This assumes that div width is hardcoded to 15px, - tree += '<span id="rcmtab' + uid + '" class="branch" style="width:' + (message.depth * 15) + 'px;"> </span>'; - - if ((rows[message.parent_uid] && rows[message.parent_uid].expanded === false) - || ((this.env.autoexpand_threads == 0 || this.env.autoexpand_threads == 2) && - (!rows[message.parent_uid] || !rows[message.parent_uid].expanded)) - ) { - row.style.display = 'none'; - message.expanded = false; - } - else - message.expanded = true; - - row_class += ' thread expanded'; - } - else if (message.has_children) { - if (message.expanded === undefined && (this.env.autoexpand_threads == 1 || (this.env.autoexpand_threads == 2 && message.unread_children))) { - message.expanded = true; - } - - expando = '<div id="rcmexpando' + uid + '" class="' + (message.expanded ? 'expanded' : 'collapsed') + '"> </div>'; - row_class += ' thread' + (message.expanded? ' expanded' : ''); - } - - if (flags.unread_children && flags.seen && !message.expanded) - row_class += ' unroot'; - } - - tree += '<span id="msgicn'+uid+'" class="'+css_class+'"> </span>'; - row.className = row_class; - - // build subject link - if (!bw.ie && cols.subject) { - var action = flags.mbox == this.env.drafts_mailbox ? 'compose' : 'show'; - var uid_param = flags.mbox == this.env.drafts_mailbox ? '_draft_uid' : '_uid'; - cols.subject = '<a href="./?_task=mail&_action='+action+'&_mbox='+urlencode(flags.mbox)+'&'+uid_param+'='+uid+'"'+ - ' onclick="return rcube_event.cancel(event)" onmouseover="rcube_webmail.long_subject_title(this,'+(message.depth+1)+')">'+cols.subject+'</a>'; - } - - // add each submitted col - for (n in this.env.coltypes) { - c = this.env.coltypes[n]; - col = { className: String(c).toLowerCase() }; - - if (c == 'flag') { - css_class = (flags.flagged ? 'flagged' : 'unflagged'); - html = '<span id="flagicn'+uid+'" class="'+css_class+'"> </span>'; - } - else if (c == 'attachment') { - if (/application\/|multipart\/(m|signed)/.test(flags.ctype)) - html = '<span class="attachment"> </span>'; - else if (/multipart\/report/.test(flags.ctype)) - html = '<span class="report"> </span>'; - else - html = ' '; - } - else if (c == 'status') { - if (flags.deleted) - css_class = 'deleted'; - else if (!flags.seen) - css_class = 'unread'; - else if (flags.unread_children > 0) - css_class = 'unreadchildren'; - else - css_class = 'msgicon'; - html = '<span id="statusicn'+uid+'" class="'+css_class+'"> </span>'; - } - else if (c == 'threads') - html = expando; - else if (c == 'subject') { - if (bw.ie) { - col.onmouseover = function() { rcube_webmail.long_subject_title_ex(this, message.depth+1); }; - if (bw.ie8) - tree = '<span></span>' + tree; // #1487821 - } - html = tree + cols[c]; - } - else if (c == 'priority') { - if (flags.prio > 0 && flags.prio < 6) - html = '<span class="prio'+flags.prio+'"> </span>'; - else - html = ' '; - } - else - html = cols[c]; - - col.innerHTML = html; - row.cols.push(col); - } - - list.insert_row(row, attop); - - // remove 'old' row - if (attop && this.env.pagesize && list.rowcount > this.env.pagesize) { - var uid = list.get_last_row(); - list.remove_row(uid); - list.clear_selection(uid); - } - }; - - this.set_list_sorting = function(sort_col, sort_order) - { - // set table header class - $('#rcm'+this.env.sort_col).removeClass('sorted'+(this.env.sort_order.toUpperCase())); - if (sort_col) - $('#rcm'+sort_col).addClass('sorted'+sort_order); - - this.env.sort_col = sort_col; - this.env.sort_order = sort_order; - }; - - this.set_list_options = function(cols, sort_col, sort_order, threads) - { - var update, post_data = {}; - - if (sort_col === undefined) - sort_col = this.env.sort_col; - if (!sort_order) - sort_order = this.env.sort_order; - - if (this.env.sort_col != sort_col || this.env.sort_order != sort_order) { - update = 1; - this.set_list_sorting(sort_col, sort_order); - } - - if (this.env.threading != threads) { - update = 1; - post_data._threads = threads; - } - - if (cols && cols.length) { - // make sure new columns are added at the end of the list - var i, idx, name, newcols = [], oldcols = this.env.coltypes; - for (i=0; i<oldcols.length; i++) { - name = oldcols[i]; - idx = $.inArray(name, cols); - if (idx != -1) { - newcols.push(name); - delete cols[idx]; - } - } - for (i=0; i<cols.length; i++) - if (cols[i]) - newcols.push(cols[i]); - - if (newcols.join() != oldcols.join()) { - update = 1; - post_data._cols = newcols.join(','); - } - } - - if (update) - this.list_mailbox('', '', sort_col+'_'+sort_order, post_data); - }; - - // when user double-clicks on a row - this.show_message = function(id, safe, preview) - { - if (!id) - return; - - var win, target = window, - action = preview ? 'preview': 'show', - url = '&_action='+action+'&_uid='+id+'&_mbox='+urlencode(this.env.mailbox); - - if (preview && (win = this.get_frame_window(this.env.contentframe))) { - target = win; - url += '&_framed=1'; - } - - if (safe) - url += '&_safe=1'; - - // also send search request to get the right messages - if (this.env.search_request) - url += '&_search='+this.env.search_request; - - // add browser capabilities, so we can properly handle attachments - url += '&_caps='+urlencode(this.browser_capabilities()); - - if (this.env.extwin) - url += '&_extwin=1'; - - if (preview && String(target.location.href).indexOf(url) >= 0) { - this.show_contentframe(true); - } - else { - if (!preview && this.env.message_extwin && !this.env.extwin) - this.open_window(this.env.comm_path+url, true); - else - this.location_href(this.env.comm_path+url, target, true); - - // mark as read and change mbox unread counter - if (preview && this.message_list && this.message_list.rows[id] && this.message_list.rows[id].unread && this.env.preview_pane_mark_read >= 0) { - this.preview_read_timer = setTimeout(function() { - ref.set_message(id, 'unread', false); - ref.update_thread_root(id, 'read'); - if (ref.env.unread_counts[ref.env.mailbox]) { - ref.env.unread_counts[ref.env.mailbox] -= 1; - ref.set_unread_count(ref.env.mailbox, ref.env.unread_counts[ref.env.mailbox], ref.env.mailbox == 'INBOX'); - } - if (ref.env.preview_pane_mark_read > 0) - ref.http_post('mark', {_uid: id, _flag: 'read', _quiet: 1}); - }, this.env.preview_pane_mark_read * 1000); - } - } - }; - - this.show_contentframe = function(show) - { - var frame, win, name = this.env.contentframe; - - if (name && (frame = this.get_frame_element(name))) { - if (!show && (win = this.get_frame_window(name))) { - if (win.location.href.indexOf(this.env.blankpage) < 0) { - if (win.stop) - win.stop(); - else // IE - win.document.execCommand('Stop'); - - win.location.href = this.env.blankpage; - } - } - else if (!bw.safari && !bw.konq) - $(frame)[show ? 'show' : 'hide'](); - } - - if (!show && this.env.frame_lock) - this.set_busy(false, null, this.env.frame_lock); - }; - - this.get_frame_element = function(id) - { - var frame; - - if (id && (frame = document.getElementById(id))) - return frame; - }; - - this.get_frame_window = function(id) - { - var frame = this.get_frame_element(id); - - if (frame && frame.name && window.frames) - return window.frames[frame.name]; - }; - - this.lock_frame = function() - { - if (!this.env.frame_lock) - (this.is_framed() ? parent.rcmail : this).env.frame_lock = this.set_busy(true, 'loading'); - }; - - // list a specific page - this.list_page = function(page) - { - if (page == 'next') - page = this.env.current_page+1; - else if (page == 'last') - page = this.env.pagecount; - else if (page == 'prev' && this.env.current_page > 1) - page = this.env.current_page-1; - else if (page == 'first' && this.env.current_page > 1) - page = 1; - - if (page > 0 && page <= this.env.pagecount) { - this.env.current_page = page; - - if (this.task == 'addressbook' || this.contact_list) - this.list_contacts(this.env.source, this.env.group, page); - else if (this.task == 'mail') - this.list_mailbox(this.env.mailbox, page); - } - }; - - // sends request to check for recent messages - this.checkmail = function() - { - var lock = this.set_busy(true, 'checkingmail'), - params = this.check_recent_params(); - - this.http_request('check-recent', params, lock); - }; - - // list messages of a specific mailbox using filter - this.filter_mailbox = function(filter) - { - var lock = this.set_busy(true, 'searching'); - - this.clear_message_list(); - - // reset vars - this.env.current_page = 1; - this.http_request('search', this.search_params(false, filter), lock); - }; - - // list messages of a specific mailbox - this.list_mailbox = function(mbox, page, sort, url) - { - var win, target = window; - - if (typeof url != 'object') - url = {}; - - if (!mbox) - mbox = this.env.mailbox ? this.env.mailbox : 'INBOX'; - - // add sort to url if set - if (sort) - url._sort = sort; - - // also send search request to get the right messages - if (this.env.search_request) - url._search = this.env.search_request; - - // set page=1 if changeing to another mailbox - if (this.env.mailbox != mbox) { - page = 1; - this.env.current_page = page; - this.select_all_mode = false; - } - - // unselect selected messages and clear the list and message data - this.clear_message_list(); - - if (mbox != this.env.mailbox || (mbox == this.env.mailbox && !page && !sort)) - url._refresh = 1; - - this.select_folder(mbox, '', true); - this.unmark_folder(mbox, 'recent', '', true); - this.env.mailbox = mbox; - - // load message list remotely - if (this.gui_objects.messagelist) { - this.list_mailbox_remote(mbox, page, url); - return; - } - - if (win = this.get_frame_window(this.env.contentframe)) { - target = win; - url._framed = 1; - } - - // load message list to target frame/window - if (mbox) { - this.set_busy(true, 'loading'); - url._mbox = mbox; - if (page) - url._page = page; - this.location_href(url, target); - } - }; - - this.clear_message_list = function() - { - this.env.messages = {}; - this.last_selected = 0; - - this.show_contentframe(false); - if (this.message_list) - this.message_list.clear(true); - }; - - // send remote request to load message list - this.list_mailbox_remote = function(mbox, page, post_data) - { - // clear message list first - this.message_list.clear(); - - var lock = this.set_busy(true, 'loading'); - - if (typeof post_data != 'object') - post_data = {}; - post_data._mbox = mbox; - if (page) - post_data._page = page; - - this.http_request('list', post_data, lock); - }; - - // removes messages that doesn't exists from list selection array - this.update_selection = function() - { - var selected = this.message_list.selection, - rows = this.message_list.rows, - i, selection = []; - - for (i in selected) - if (rows[selected[i]]) - selection.push(selected[i]); - - this.message_list.selection = selection; - } - - // expand all threads with unread children - this.expand_unread = function() - { - var r, tbody = this.gui_objects.messagelist.tBodies[0], - new_row = tbody.firstChild; - - while (new_row) { - if (new_row.nodeType == 1 && (r = this.message_list.rows[new_row.uid]) && r.unread_children) { - this.message_list.expand_all(r); - this.set_unread_children(r.uid); - } - new_row = new_row.nextSibling; - } - return false; - }; - - // thread expanding/collapsing handler - this.expand_message_row = function(e, uid) - { - var row = this.message_list.rows[uid]; - - // handle unread_children mark - row.expanded = !row.expanded; - this.set_unread_children(uid); - row.expanded = !row.expanded; - - this.message_list.expand_row(e, uid); - }; - - // message list expanding - this.expand_threads = function() - { - if (!this.env.threading || !this.env.autoexpand_threads || !this.message_list) - return; - - switch (this.env.autoexpand_threads) { - case 2: this.expand_unread(); break; - case 1: this.message_list.expand_all(); break; - } - }; - - // Initializes threads indicators/expanders after list update - this.init_threads = function(roots, mbox) - { - // #1487752 - if (mbox && mbox != this.env.mailbox) - return false; - - for (var n=0, len=roots.length; n<len; n++) - this.add_tree_icons(roots[n]); - this.expand_threads(); - }; - - // adds threads tree icons to the list (or specified thread) - this.add_tree_icons = function(root) - { - var i, l, r, n, len, pos, tmp = [], uid = [], - row, rows = this.message_list.rows; - - if (root) - row = rows[root] ? rows[root].obj : null; - else - row = this.message_list.tbody.firstChild; - - while (row) { - if (row.nodeType == 1 && (r = rows[row.uid])) { - if (r.depth) { - for (i=tmp.length-1; i>=0; i--) { - len = tmp[i].length; - if (len > r.depth) { - pos = len - r.depth; - if (!(tmp[i][pos] & 2)) - tmp[i][pos] = tmp[i][pos] ? tmp[i][pos]+2 : 2; - } - else if (len == r.depth) { - if (!(tmp[i][0] & 2)) - tmp[i][0] += 2; - } - if (r.depth > len) - break; - } - - tmp.push(new Array(r.depth)); - tmp[tmp.length-1][0] = 1; - uid.push(r.uid); - } - else { - if (tmp.length) { - for (i in tmp) { - this.set_tree_icons(uid[i], tmp[i]); - } - tmp = []; - uid = []; - } - if (root && row != rows[root].obj) - break; - } - } - row = row.nextSibling; - } - - if (tmp.length) { - for (i in tmp) { - this.set_tree_icons(uid[i], tmp[i]); - } - } - }; - - // adds tree icons to specified message row - this.set_tree_icons = function(uid, tree) - { - var i, divs = [], html = '', len = tree.length; - - for (i=0; i<len; i++) { - if (tree[i] > 2) - divs.push({'class': 'l3', width: 15}); - else if (tree[i] > 1) - divs.push({'class': 'l2', width: 15}); - else if (tree[i] > 0) - divs.push({'class': 'l1', width: 15}); - // separator div - else if (divs.length && !divs[divs.length-1]['class']) - divs[divs.length-1].width += 15; - else - divs.push({'class': null, width: 15}); - } - - for (i=divs.length-1; i>=0; i--) { - if (divs[i]['class']) - html += '<div class="tree '+divs[i]['class']+'" />'; - else - html += '<div style="width:'+divs[i].width+'px" />'; - } - - if (html) - $('#rcmtab'+uid).html(html); - }; - - // update parent in a thread - this.update_thread_root = function(uid, flag) - { - if (!this.env.threading) - return; - - var root = this.message_list.find_root(uid); - - if (uid == root) - return; - - var p = this.message_list.rows[root]; - - if (flag == 'read' && p.unread_children) { - p.unread_children--; - } - else if (flag == 'unread' && p.has_children) { - // unread_children may be undefined - p.unread_children = p.unread_children ? p.unread_children + 1 : 1; - } - else { - return; - } - - this.set_message_icon(root); - this.set_unread_children(root); - }; - - // update thread indicators for all messages in a thread below the specified message - // return number of removed/added root level messages - this.update_thread = function (uid) - { - if (!this.env.threading) - return 0; - - var r, parent, count = 0, - rows = this.message_list.rows, - row = rows[uid], - depth = rows[uid].depth, - roots = []; - - if (!row.depth) // root message: decrease roots count - count--; - else if (row.unread) { - // update unread_children for thread root - parent = this.message_list.find_root(uid); - rows[parent].unread_children--; - this.set_unread_children(parent); - } - - parent = row.parent_uid; - - // childrens - row = row.obj.nextSibling; - while (row) { - if (row.nodeType == 1 && (r = rows[row.uid])) { - if (!r.depth || r.depth <= depth) - break; - - r.depth--; // move left - // reset width and clear the content of a tab, icons will be added later - $('#rcmtab'+r.uid).width(r.depth * 15).html(''); - if (!r.depth) { // a new root - count++; // increase roots count - r.parent_uid = 0; - if (r.has_children) { - // replace 'leaf' with 'collapsed' - $('#rcmrow'+r.uid+' '+'.leaf:first') - .attr('id', 'rcmexpando' + r.uid) - .attr('class', (r.obj.style.display != 'none' ? 'expanded' : 'collapsed')) - .bind('mousedown', {uid:r.uid, p:this}, - function(e) { return e.data.p.expand_message_row(e, e.data.uid); }); - - r.unread_children = 0; - roots.push(r); - } - // show if it was hidden - if (r.obj.style.display == 'none') - $(r.obj).show(); - } - else { - if (r.depth == depth) - r.parent_uid = parent; - if (r.unread && roots.length) - roots[roots.length-1].unread_children++; - } - } - row = row.nextSibling; - } - - // update unread_children for roots - for (var i=0; i<roots.length; i++) - this.set_unread_children(roots[i].uid); - - return count; - }; - - this.delete_excessive_thread_rows = function() - { - var rows = this.message_list.rows, - tbody = this.message_list.tbody, - row = tbody.firstChild, - cnt = this.env.pagesize + 1; - - while (row) { - if (row.nodeType == 1 && (r = rows[row.uid])) { - if (!r.depth && cnt) - cnt--; - - if (!cnt) - this.message_list.remove_row(row.uid); - } - row = row.nextSibling; - } - }; - - // set message icon - this.set_message_icon = function(uid) - { - var css_class, - row = this.message_list.rows[uid]; - - if (!row) - return false; - - if (row.icon) { - css_class = 'msgicon'; - if (row.deleted) - css_class += ' deleted'; - else if (row.unread) - css_class += ' unread'; - else if (row.unread_children) - css_class += ' unreadchildren'; - if (row.msgicon == row.icon) { - if (row.replied) - css_class += ' replied'; - if (row.forwarded) - css_class += ' forwarded'; - css_class += ' status'; - } - - row.icon.className = css_class; - } - - if (row.msgicon && row.msgicon != row.icon) { - css_class = 'msgicon'; - if (!row.unread && row.unread_children) - css_class += ' unreadchildren'; - if (row.replied) - css_class += ' replied'; - if (row.forwarded) - css_class += ' forwarded'; - - row.msgicon.className = css_class; - } - - if (row.flagicon) { - css_class = (row.flagged ? 'flagged' : 'unflagged'); - row.flagicon.className = css_class; - } - }; - - // set message status - this.set_message_status = function(uid, flag, status) - { - var row = this.message_list.rows[uid]; - - if (!row) - return false; - - if (flag == 'unread') - row.unread = status; - else if(flag == 'deleted') - row.deleted = status; - else if (flag == 'replied') - row.replied = status; - else if (flag == 'forwarded') - row.forwarded = status; - else if (flag == 'flagged') - row.flagged = status; - }; - - // set message row status, class and icon - this.set_message = function(uid, flag, status) - { - var row = this.message_list && this.message_list.rows[uid]; - - if (!row) - return false; - - if (flag) - this.set_message_status(uid, flag, status); - - var rowobj = $(row.obj); - - if (row.unread && !rowobj.hasClass('unread')) - rowobj.addClass('unread'); - else if (!row.unread && rowobj.hasClass('unread')) - rowobj.removeClass('unread'); - - if (row.deleted && !rowobj.hasClass('deleted')) - rowobj.addClass('deleted'); - else if (!row.deleted && rowobj.hasClass('deleted')) - rowobj.removeClass('deleted'); - - if (row.flagged && !rowobj.hasClass('flagged')) - rowobj.addClass('flagged'); - else if (!row.flagged && rowobj.hasClass('flagged')) - rowobj.removeClass('flagged'); - - this.set_unread_children(uid); - this.set_message_icon(uid); - }; - - // sets unroot (unread_children) class of parent row - this.set_unread_children = function(uid) - { - var row = this.message_list.rows[uid]; - - if (row.parent_uid) - return; - - if (!row.unread && row.unread_children && !row.expanded) - $(row.obj).addClass('unroot'); - else - $(row.obj).removeClass('unroot'); - }; - - // copy selected messages to the specified mailbox - this.copy_messages = function(mbox) - { - if (mbox && typeof mbox === 'object') - mbox = mbox.id; - - // exit if current or no mailbox specified - if (!mbox || mbox == this.env.mailbox) - return; - - var post_data = this.selection_post_data({_target_mbox: mbox}); - - // exit if selection is empty - if (!post_data._uid) - return; - - // send request to server - this.http_post('copy', post_data, this.display_message(this.get_label('copyingmessage'), 'loading')); - }; - - // move selected messages to the specified mailbox - this.move_messages = function(mbox) - { - if (mbox && typeof mbox === 'object') - mbox = mbox.id; - - // exit if current or no mailbox specified - if (!mbox || mbox == this.env.mailbox) - return; - - var lock = false, post_data = this.selection_post_data({_target_mbox: mbox}); - - // exit if selection is empty - if (!post_data._uid) - return; - - // show wait message - if (this.env.action == 'show') - lock = this.set_busy(true, 'movingmessage'); - else - this.show_contentframe(false); - - // Hide message command buttons until a message is selected - this.enable_command(this.env.message_commands, false); - - this._with_selected_messages('move', post_data, lock); - }; - - // delete selected messages from the current mailbox - this.delete_messages = function(event) - { - var uid, i, len, trash = this.env.trash_mailbox, - list = this.message_list, - selection = list ? list.get_selection() : []; - - // exit if no mailbox specified or if selection is empty - if (!this.env.uid && !selection.length) - return; - - // also select childs of collapsed rows - for (i=0, len=selection.length; i<len; i++) { - uid = selection[i]; - if (list.rows[uid].has_children && !list.rows[uid].expanded) - list.select_children(uid); - } - - // if config is set to flag for deletion - if (this.env.flag_for_deletion) { - this.mark_message('delete'); - return false; - } - // if there isn't a defined trash mailbox or we are in it - else if (!trash || this.env.mailbox == trash) - this.permanently_remove_messages(); - // we're in Junk folder and delete_junk is enabled - else if (this.env.delete_junk && this.env.junk_mailbox && this.env.mailbox == this.env.junk_mailbox) - this.permanently_remove_messages(); - // if there is a trash mailbox defined and we're not currently in it - else { - // if shift was pressed delete it immediately - if ((list && list.modkey == SHIFT_KEY) || (event && rcube_event.get_modifier(event) == SHIFT_KEY)) { - if (confirm(this.get_label('deletemessagesconfirm'))) - this.permanently_remove_messages(); - } - else - this.move_messages(trash); - } - - return true; - }; - - // delete the selected messages permanently - this.permanently_remove_messages = function() - { - var post_data = this.selection_post_data(); - - // exit if selection is empty - if (!post_data._uid) - return; - - this.show_contentframe(false); - this._with_selected_messages('delete', post_data); - }; - - // Send a specifc move/delete request with UIDs of all selected messages - // @private - this._with_selected_messages = function(action, post_data, lock) - { - var count = 0, msg; - - // update the list (remove rows, clear selection) - if (this.message_list) { - var n, id, root, roots = [], - selection = this.message_list.get_selection(); - - for (n=0, len=selection.length; n<len; n++) { - id = selection[n]; - - if (this.env.threading) { - count += this.update_thread(id); - root = this.message_list.find_root(id); - if (root != id && $.inArray(root, roots) < 0) { - roots.push(root); - } - } - this.message_list.remove_row(id, (this.env.display_next && n == selection.length-1)); - } - // make sure there are no selected rows - if (!this.env.display_next) - this.message_list.clear_selection(); - // update thread tree icons - for (n=0, len=roots.length; n<len; n++) { - this.add_tree_icons(roots[n]); - } - } - - if (count < 0) - post_data._count = (count*-1); - // remove threads from the end of the list - else if (count > 0) - this.delete_excessive_thread_rows(); - - if (!lock) { - msg = action == 'move' ? 'movingmessage' : 'deletingmessage'; - lock = this.display_message(this.get_label(msg), 'loading'); - } - - // send request to server - this.http_post(action, post_data, lock); - }; - - // build post data for message delete/move/copy/flag requests - this.selection_post_data = function(data) - { - if (typeof(data) != 'object') - data = {}; - - data._mbox = this.env.mailbox; - - if (!data._uid) { - var uids = this.env.uid ? [this.env.uid] : this.message_list.get_selection(); - data._uid = this.uids_to_list(uids); - } - - if (this.env.action) - data._from = this.env.action; - - // also send search request to get the right messages - if (this.env.search_request) - data._search = this.env.search_request; - - if (this.env.display_next && this.env.next_uid) - data._next_uid = this.env.next_uid; - - return data; - }; - - // set a specific flag to one or more messages - this.mark_message = function(flag, uid) - { - var a_uids = [], r_uids = [], len, n, id, - list = this.message_list; - - if (uid) - a_uids[0] = uid; - else if (this.env.uid) - a_uids[0] = this.env.uid; - else if (list) - a_uids = list.get_selection(); - - if (!list) - r_uids = a_uids; - else { - list.focus(); - for (n=0, len=a_uids.length; n<len; n++) { - id = a_uids[n]; - if ((flag == 'read' && list.rows[id].unread) - || (flag == 'unread' && !list.rows[id].unread) - || (flag == 'delete' && !list.rows[id].deleted) - || (flag == 'undelete' && list.rows[id].deleted) - || (flag == 'flagged' && !list.rows[id].flagged) - || (flag == 'unflagged' && list.rows[id].flagged)) - { - r_uids.push(id); - } - } - } - - // nothing to do - if (!r_uids.length && !this.select_all_mode) - return; - - switch (flag) { - case 'read': - case 'unread': - this.toggle_read_status(flag, r_uids); - break; - case 'delete': - case 'undelete': - this.toggle_delete_status(r_uids); - break; - case 'flagged': - case 'unflagged': - this.toggle_flagged_status(flag, a_uids); - break; - } - }; - - // set class to read/unread - this.toggle_read_status = function(flag, a_uids) - { - var i, len = a_uids.length, - post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: flag}), - lock = this.display_message(this.get_label('markingmessage'), 'loading'); - - // mark all message rows as read/unread - for (i=0; i<len; i++) - this.set_message(a_uids[i], 'unread', (flag == 'unread' ? true : false)); - - this.http_post('mark', post_data, lock); - - for (i=0; i<len; i++) - this.update_thread_root(a_uids[i], flag); - }; - - // set image to flagged or unflagged - this.toggle_flagged_status = function(flag, a_uids) - { - var i, len = a_uids.length, - post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: flag}), - lock = this.display_message(this.get_label('markingmessage'), 'loading'); - - // mark all message rows as flagged/unflagged - for (i=0; i<len; i++) - this.set_message(a_uids[i], 'flagged', (flag == 'flagged' ? true : false)); - - this.http_post('mark', post_data, lock); - }; - - // mark all message rows as deleted/undeleted - this.toggle_delete_status = function(a_uids) - { - var len = a_uids.length, - i, uid, all_deleted = true, - rows = this.message_list ? this.message_list.rows : {}; - - if (len == 1) { - if (!this.message_list || (rows[a_uids[0]] && !rows[a_uids[0]].deleted)) - this.flag_as_deleted(a_uids); - else - this.flag_as_undeleted(a_uids); - - return true; - } - - for (i=0; i<len; i++) { - uid = a_uids[i]; - if (rows[uid] && !rows[uid].deleted) { - all_deleted = false; - break; - } - } - - if (all_deleted) - this.flag_as_undeleted(a_uids); - else - this.flag_as_deleted(a_uids); - - return true; - }; - - this.flag_as_undeleted = function(a_uids) - { - var i, len = a_uids.length, - post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: 'undelete'}), - lock = this.display_message(this.get_label('markingmessage'), 'loading'); - - for (i=0; i<len; i++) - this.set_message(a_uids[i], 'deleted', false); - - this.http_post('mark', post_data, lock); - }; - - this.flag_as_deleted = function(a_uids) - { - var r_uids = [], - post_data = this.selection_post_data({_uid: this.uids_to_list(a_uids), _flag: 'delete'}), - lock = this.display_message(this.get_label('markingmessage'), 'loading'), - rows = this.message_list ? this.message_list.rows : {}, - count = 0; - - for (var i=0, len=a_uids.length; i<len; i++) { - uid = a_uids[i]; - if (rows[uid]) { - if (rows[uid].unread) - r_uids[r_uids.length] = uid; - - if (this.env.skip_deleted) { - count += this.update_thread(uid); - this.message_list.remove_row(uid, (this.env.display_next && i == this.message_list.selection.length-1)); - } - else - this.set_message(uid, 'deleted', true); - } - } - - // make sure there are no selected rows - if (this.env.skip_deleted && this.message_list) { - if (!this.env.display_next) - this.message_list.clear_selection(); - if (count < 0) - post_data._count = (count*-1); - else if (count > 0) - // remove threads from the end of the list - this.delete_excessive_thread_rows(); - } - - // ?? - if (r_uids.length) - post_data._ruid = this.uids_to_list(r_uids); - - if (this.env.skip_deleted && this.env.display_next && this.env.next_uid) - post_data._next_uid = this.env.next_uid; - - this.http_post('mark', post_data, lock); - }; - - // flag as read without mark request (called from backend) - // argument should be a coma-separated list of uids - this.flag_deleted_as_read = function(uids) - { - var icn_src, uid, i, len, - rows = this.message_list ? this.message_list.rows : {}; - - uids = String(uids).split(','); - - for (i=0, len=uids.length; i<len; i++) { - uid = uids[i]; - if (rows[uid]) - this.set_message(uid, 'unread', false); - } - }; - - // Converts array of message UIDs to comma-separated list for use in URL - // with select_all mode checking - this.uids_to_list = function(uids) - { - return this.select_all_mode ? '*' : uids.join(','); - }; - - // Sets title of the delete button - this.set_button_titles = function() - { - var label = 'deletemessage'; - - if (!this.env.flag_for_deletion - && this.env.trash_mailbox && this.env.mailbox != this.env.trash_mailbox - && (!this.env.delete_junk || !this.env.junk_mailbox || this.env.mailbox != this.env.junk_mailbox) - ) - label = 'movemessagetotrash'; - - this.set_alttext('delete', label); - }; - - /*********************************************************/ - /********* mailbox folders methods *********/ - /*********************************************************/ - - this.expunge_mailbox = function(mbox) - { - var lock, post_data = {_mbox: mbox}; - - // lock interface if it's the active mailbox - if (mbox == this.env.mailbox) { - lock = this.set_busy(true, 'loading'); - post_data._reload = 1; - if (this.env.search_request) - post_data._search = this.env.search_request; - } - - // send request to server - this.http_post('expunge', post_data, lock); - }; - - this.purge_mailbox = function(mbox) - { - var lock, post_data = {_mbox: mbox}; - - if (!confirm(this.get_label('purgefolderconfirm'))) - return false; - - // lock interface if it's the active mailbox - if (mbox == this.env.mailbox) { - lock = this.set_busy(true, 'loading'); - post_data._reload = 1; - } - - // send request to server - this.http_post('purge', post_data, lock); - }; - - // test if purge command is allowed - this.purge_mailbox_test = function() - { - return (this.env.exists && ( - this.env.mailbox == this.env.trash_mailbox - || this.env.mailbox == this.env.junk_mailbox - || this.env.mailbox.startsWith(this.env.trash_mailbox + this.env.delimiter) - || this.env.mailbox.startsWith(this.env.junk_mailbox + this.env.delimiter) - )); - }; - - - /*********************************************************/ - /********* login form methods *********/ - /*********************************************************/ - - // handler for keyboard events on the _user field - this.login_user_keyup = function(e) - { - var key = rcube_event.get_keycode(e); - var passwd = $('#rcmloginpwd'); - - // enter - if (key == 13 && passwd.length && !passwd.val()) { - passwd.focus(); - return rcube_event.cancel(e); - } - - return true; - }; - - - /*********************************************************/ - /********* message compose methods *********/ - /*********************************************************/ - - this.open_compose_step = function(p) - { - var url = this.url('mail/compose', p); - - // open new compose window - if (this.env.compose_extwin && !this.env.extwin) { - this.open_window(url); - } - else { - this.redirect(url); - if (this.env.extwin) - window.resizeTo(Math.max(this.env.popup_width, $(window).width()), $(window).height() + 24); - } - }; - - // init message compose form: set focus and eventhandlers - this.init_messageform = function() - { - if (!this.gui_objects.messageform) - return false; - - var input_from = $("[name='_from']"), - input_to = $("[name='_to']"), - input_subject = $("input[name='_subject']"), - input_message = $("[name='_message']").get(0), - html_mode = $("input[name='_is_html']").val() == '1', - ac_fields = ['cc', 'bcc', 'replyto', 'followupto'], - ac_props, opener_rc = this.opener(); - - // close compose step in opener - if (opener_rc && opener_rc.env.action == 'compose') { - setTimeout(function(){ opener.history.back(); }, 100); - this.env.opened_extwin = true; - } - - // configure parallel autocompletion - if (this.env.autocomplete_threads > 0) { - ac_props = { - threads: this.env.autocomplete_threads, - sources: this.env.autocomplete_sources - }; - } - - // init live search events - this.init_address_input_events(input_to, ac_props); - for (var i in ac_fields) { - this.init_address_input_events($("[name='_"+ac_fields[i]+"']"), ac_props); - } - - if (!html_mode) { - this.set_caret_pos(input_message, this.env.top_posting ? 0 : $(input_message).val().length); - // add signature according to selected identity - // if we have HTML editor, signature is added in callback - if (input_from.prop('type') == 'select-one') { - this.change_identity(input_from[0]); - } - } - - if (input_to.val() == '') - input_to.focus(); - else if (input_subject.val() == '') - input_subject.focus(); - else if (input_message) - input_message.focus(); - - this.env.compose_focus_elem = document.activeElement; - - // get summary of all field values - this.compose_field_hash(true); - - // start the auto-save timer - this.auto_save_start(); - }; - - this.init_address_input_events = function(obj, props) - { - this.env.recipients_delimiter = this.env.recipients_separator + ' '; - - obj[bw.ie || bw.safari || bw.chrome ? 'keydown' : 'keypress'](function(e) { return ref.ksearch_keydown(e, this, props); }) - .attr('autocomplete', 'off'); - }; - - this.submit_messageform = function(draft) - { - var form = this.gui_objects.messageform; - - if (!form) - return; - - // all checks passed, send message - var msgid = this.set_busy(true, draft ? 'savingmessage' : 'sendingmessage'), - lang = this.spellcheck_lang(), - files = []; - - // send files list - $('li', this.gui_objects.attachmentlist).each(function() { files.push(this.id.replace(/^rcmfile/, '')); }); - $('input[name="_attachments"]', form).val(files.join()); - - form.target = 'savetarget'; - form._draft.value = draft ? '1' : ''; - form.action = this.add_url(form.action, '_unlock', msgid); - form.action = this.add_url(form.action, '_lang', lang); - - // register timer to notify about connection timeout - this.submit_timer = setTimeout(function(){ - ref.set_busy(false, null, msgid); - ref.display_message(ref.get_label('requesttimedout'), 'error'); - }, this.env.request_timeout * 1000); - - form.submit(); - }; - - this.compose_recipient_select = function(list) - { - var id, n, recipients = 0; - for (n=0; n < list.selection.length; n++) { - id = list.selection[n]; - if (this.env.contactdata[id]) - recipients++; - } - this.enable_command('add-recipient', recipients); - }; - - this.compose_add_recipient = function(field) - { - var recipients = [], input = $('#_'+field), delim = this.env.recipients_delimiter; - - if (this.contact_list && this.contact_list.selection.length) { - for (var id, n=0; n < this.contact_list.selection.length; n++) { - id = this.contact_list.selection[n]; - if (id && this.env.contactdata[id]) { - recipients.push(this.env.contactdata[id]); - - // group is added, expand it - if (id.charAt(0) == 'E' && this.env.contactdata[id].indexOf('@') < 0 && input.length) { - var gid = id.substr(1); - this.group2expand[gid] = { name:this.env.contactdata[id], input:input.get(0) }; - this.http_request('group-expand', {_source: this.env.source, _gid: gid}, false); - } - } - } - } - - if (recipients.length && input.length) { - var oldval = input.val(), rx = new RegExp(RegExp.escape(delim) + '\\s*$'); - if (oldval && !rx.test(oldval)) - oldval += delim + ' '; - input.val(oldval + recipients.join(delim + ' ') + delim + ' '); - this.triggerEvent('add-recipient', { field:field, recipients:recipients }); - } - }; - - // checks the input fields before sending a message - this.check_compose_input = function(cmd) - { - // check input fields - var ed, input_to = $("[name='_to']"), - input_cc = $("[name='_cc']"), - input_bcc = $("[name='_bcc']"), - input_from = $("[name='_from']"), - input_subject = $("[name='_subject']"), - input_message = $("[name='_message']"); - - // check sender (if have no identities) - if (input_from.prop('type') == 'text' && !rcube_check_email(input_from.val(), true)) { - alert(this.get_label('nosenderwarning')); - input_from.focus(); - return false; - } - - // check for empty recipient - var recipients = input_to.val() ? input_to.val() : (input_cc.val() ? input_cc.val() : input_bcc.val()); - if (!rcube_check_email(recipients.replace(/^\s+/, '').replace(/[\s,;]+$/, ''), true)) { - alert(this.get_label('norecipientwarning')); - input_to.focus(); - return false; - } - - // check if all files has been uploaded - for (var key in this.env.attachments) { - if (typeof this.env.attachments[key] === 'object' && !this.env.attachments[key].complete) { - alert(this.get_label('notuploadedwarning')); - return false; - } - } - - // display localized warning for missing subject - if (input_subject.val() == '') { - var myprompt = $('<div class="prompt">').html('<div class="message">' + this.get_label('nosubjectwarning') + '</div>').appendTo(document.body); - var prompt_value = $('<input>').attr('type', 'text').attr('size', 30).appendTo(myprompt).val(this.get_label('nosubject')); - - var buttons = {}; - buttons[this.get_label('cancel')] = function(){ - input_subject.focus(); - $(this).dialog('close'); - }; - buttons[this.get_label('sendmessage')] = function(){ - input_subject.val(prompt_value.val()); - $(this).dialog('close'); - ref.command(cmd, { nocheck:true }); // repeat command which triggered this - }; - - myprompt.dialog({ - modal: true, - resizable: false, - buttons: buttons, - close: function(event, ui) { $(this).remove() } - }); - prompt_value.select(); - return false; - } - - // Apply spellcheck changes if spell checker is active - this.stop_spellchecking(); - - if (window.tinyMCE) - ed = tinyMCE.get(this.env.composebody); - - // check for empty body - if (!ed && input_message.val() == '' && !confirm(this.get_label('nobodywarning'))) { - input_message.focus(); - return false; - } - else if (ed) { - if (!ed.getContent() && !confirm(this.get_label('nobodywarning'))) { - ed.focus(); - return false; - } - // move body from html editor to textarea (just to be sure, #1485860) - tinyMCE.triggerSave(); - } - - return true; - }; - - this.toggle_editor = function(props) - { - this.stop_spellchecking(); - - if (props.mode == 'html') { - this.plain2html($('#'+props.id).val(), props.id); - tinyMCE.execCommand('mceAddControl', false, props.id); - - if (this.env.default_font) - setTimeout(function() { - $(tinyMCE.get(props.id).getBody()).css('font-family', rcmail.env.default_font); - }, 500); - } - else { - var thisMCE = tinyMCE.get(props.id), existingHtml; - - if (existingHtml = thisMCE.getContent()) { - if (!confirm(this.get_label('editorwarning'))) { - return false; - } - this.html2plain(existingHtml, props.id); - } - tinyMCE.execCommand('mceRemoveControl', false, props.id); - } - - return true; - }; - - this.insert_response = function(key) - { - var insert = this.env.textresponses[key] ? this.env.textresponses[key].text : null; - if (!insert) - return false; - - // insert into tinyMCE editor - if ($("input[name='_is_html']").val() == '1') { - var editor = tinyMCE.get(this.env.composebody); - editor.getWin().focus(); // correct focus in IE & Chrome - editor.selection.setContent(insert, { format:'text' }); - } - // replace selection in compose textarea - else { - var textarea = rcube_find_object(this.env.composebody), - selection = $(textarea).is(':focus') ? this.get_input_selection(textarea) : { start:0, end:0 }, - inp_value = textarea.value; - pre = inp_value.substring(0, selection.start), - end = inp_value.substring(selection.end, inp_value.length); - - // insert response text - textarea.value = pre + insert + end; - - // set caret after inserted text - this.set_caret_pos(textarea, selection.start + insert.length); - textarea.focus(); - } - }; - - /** - * Open the dialog to save a new canned response - */ - this.save_response = function() - { - var sigstart, text = '', strip = false; - - // get selected text from tinyMCE editor - if ($("input[name='_is_html']").val() == '1') { - var editor = tinyMCE.get(this.env.composebody); - editor.getWin().focus(); // correct focus in IE & Chrome - text = editor.selection.getContent({ format:'text' }); - - if (!text) { - text = editor.getContent({ format:'text' }); - strip = true; - } - } - // get selected text from compose textarea - else { - var textarea = rcube_find_object(this.env.composebody), sigstart; - if (textarea && $(textarea).is(':focus')) { - text = this.get_input_selection(textarea).text; - } - - if (!text && textarea) { - text = textarea.value; - strip = true; - } - } - - // strip off signature - if (strip) { - sigstart = text.indexOf('-- \n'); - if (sigstart > 0) { - text = text.substring(0, sigstart); - } - } - - // show dialog to enter a name and to modify the text to be saved - var buttons = {}, - html = '<form class="propform">' + - '<div class="prop block"><label>' + this.get_label('responsename') + '</label>' + - '<input type="text" name="name" id="ffresponsename" size="40" /></div>' + - '<div class="prop block"><label>' + this.get_label('responsetext') + '</label>' + - '<textarea name="text" id="ffresponsetext" cols="40" rows="8"></textarea></div>' + - '</form>'; - - buttons[this.gettext('save')] = function(e) { - var name = $('#ffresponsename').val(), - text = $('#ffresponsetext').val(); - - if (!text) { - $('#ffresponsetext').select(); - return false; - } - if (!name) - name = text.substring(0,40); - - var lock = ref.display_message(ref.get_label('savingresponse'), 'loading'); - ref.http_post('settings/responses', { _insert:1, _name:name, _text:text }, lock); - $(this).dialog('close'); - }; - - buttons[this.gettext('cancel')] = function() { - $(this).dialog('close'); - }; - - this.show_popup_dialog(html, this.gettext('savenewresponse'), buttons); - - $('#ffresponsetext').val(text); - $('#ffresponsename').select(); - }; - - this.add_response_item = function(response) - { - var key = response.key; - this.env.textresponses[key] = response; - - // append to responses list - if (this.gui_objects.responseslist) { - var li = $('<li>').appendTo(this.gui_objects.responseslist); - $('<a>').addClass('insertresponse active') - .attr('href', '#') - .attr('rel', key) - .html(this.quote_html(response.name)) - .appendTo(li) - .mousedown(function(e){ - return rcube_event.cancel(e); - }) - .mouseup(function(e){ - ref.command('insert-response', key); - $(document.body).trigger('mouseup'); // hides the menu - return rcube_event.cancel(e); - }); - } - }; - - this.edit_responses = function() - { - // TODO: implement inline editing of responses - }; - - this.delete_response = function(key) - { - if (!key && this.responses_list) { - var selection = this.responses_list.get_selection(); - key = selection[0]; - } - - // submit delete request - if (key && confirm(this.get_label('deleteresponseconfirm'))) { - this.http_post('settings/delete-response', { _key: key }, false); - return true; - } - - return false; - }; - - this.stop_spellchecking = function() - { - var ed; - - if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody))) { - if (ed.plugins && ed.plugins.spellchecker && ed.plugins.spellchecker.active) - ed.execCommand('mceSpellCheck'); - } - else if (ed = this.env.spellcheck) { - if (ed.state && ed.state != 'ready' && ed.state != 'no_error_found') - $(ed.spell_span).trigger('click'); - } - - this.spellcheck_state(); - }; - - this.spellcheck_state = function() - { - var ed, active; - - if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)) && ed.plugins && ed.plugins.spellchecker) - active = ed.plugins.spellchecker.active; - else if ((ed = this.env.spellcheck) && ed.state) - active = ed.state != 'ready' && ed.state != 'no_error_found'; - - if (rcmail.buttons.spellcheck) - $('#'+rcmail.buttons.spellcheck[0].id)[active ? 'addClass' : 'removeClass']('selected'); - - return active; - }; - - // get selected language - this.spellcheck_lang = function() - { - var ed; - - if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)) && ed.plugins && ed.plugins.spellchecker) - return ed.plugins.spellchecker.selectedLang; - else if (this.env.spellcheck) - return GOOGIE_CUR_LANG; - }; - - this.spellcheck_lang_set = function(lang) - { - var ed; - - if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody)) && ed.plugins) - ed.plugins.spellchecker.selectedLang = lang; - else if (this.env.spellcheck) - this.env.spellcheck.setCurrentLanguage(lang); - }; - - // resume spellchecking, highlight provided mispellings without new ajax request - this.spellcheck_resume = function(ishtml, data) - { - if (ishtml) { - var ed = tinyMCE.get(this.env.composebody); - sp = ed.plugins.spellchecker; - - sp.active = 1; - sp._markWords(data); - ed.nodeChanged(); - } - else { - var sp = this.env.spellcheck; - sp.prepare(false, true); - sp.processData(data); - } - - this.spellcheck_state(); - } - - this.set_draft_id = function(id) - { - var rc; - - if (!this.env.draft_id && id && (rc = this.opener())) { - // refresh the drafts folder in opener window - if (rc.env.task == 'mail' && rc.env.action == '' && rc.env.mailbox == this.env.drafts_mailbox) - rc.command('checkmail'); - } - - this.env.draft_id = id; - $("input[name='_draft_saveid']").val(id); - }; - - this.auto_save_start = function() - { - if (this.env.draft_autosave) - this.save_timer = setTimeout(function(){ ref.command("savedraft"); }, this.env.draft_autosave * 1000); - - // Unlock interface now that saving is complete - this.busy = false; - }; - - this.compose_field_hash = function(save) - { - // check input fields - var ed, i, val, str = '', hash_fields = ['to', 'cc', 'bcc', 'subject']; - - for (i=0; i<hash_fields.length; i++) - if (val = $('[name="_' + hash_fields[i] + '"]').val()) - str += val + ':'; - - if (window.tinyMCE && (ed = tinyMCE.get(this.env.composebody))) - str += ed.getContent(); - else - str += $("[name='_message']").val(); - - if (this.env.attachments) - for (var upload_id in this.env.attachments) - str += upload_id; - - if (save) - this.cmp_hash = str; - - return str; - }; - - this.change_identity = function(obj, show_sig) - { - if (!obj || !obj.options) - return false; - - if (!show_sig) - show_sig = this.env.show_sig; - - // first function execution - if (!this.env.identities_initialized) { - this.env.identities_initialized = true; - if (this.env.show_sig_later) - this.env.show_sig = true; - if (this.env.opened_extwin) - return; - } - - var i, rx, cursor_pos, p = -1, - id = obj.options[obj.selectedIndex].value, - input_message = $("[name='_message']"), - message = input_message.val(), - is_html = ($("input[name='_is_html']").val() == '1'), - sig = this.env.identity, - delim = this.env.recipients_separator, - rx_delim = RegExp.escape(delim), - headers = ['replyto', 'bcc']; - - // update reply-to/bcc fields with addresses defined in identities - for (i in headers) { - var key = headers[i], - old_val = sig && this.env.identities[sig] ? this.env.identities[sig][key] : '', - new_val = id && this.env.identities[id] ? this.env.identities[id][key] : '', - input = $('[name="_'+key+'"]'), input_val = input.val(); - - // remove old address(es) - if (old_val && input_val) { - rx = new RegExp('\\s*' + RegExp.escape(old_val) + '\\s*'); - input_val = input_val.replace(rx, ''); - } - - // cleanup - rx = new RegExp(rx_delim + '\\s*' + rx_delim, 'g'); - input_val = input_val.replace(rx, delim); - rx = new RegExp('^[\\s' + rx_delim + ']+'); - input_val = input_val.replace(rx, ''); - - // add new address(es) - if (new_val && input_val.indexOf(new_val) == -1 && input_val.indexOf(new_val.replace(/"/g, '')) == -1) { - if (input_val) { - rx = new RegExp('[' + rx_delim + '\\s]+$') - input_val = input_val.replace(rx, '') + delim + ' '; - } - - input_val += new_val + delim + ' '; - } - - if (old_val || new_val) - input.val(input_val).change(); - } - - // enable manual signature insert - if (this.env.signatures && this.env.signatures[id]) { - this.enable_command('insert-sig', true); - this.env.compose_commands.push('insert-sig'); - } - else - this.enable_command('insert-sig', false); - - if (!is_html) { - // remove the 'old' signature - if (show_sig && sig && this.env.signatures && this.env.signatures[sig]) { - sig = this.env.signatures[sig].text; - sig = sig.replace(/\r\n/g, '\n'); - - p = this.env.top_posting ? message.indexOf(sig) : message.lastIndexOf(sig); - if (p >= 0) - message = message.substring(0, p) + message.substring(p+sig.length, message.length); - } - // add the new signature string - if (show_sig && this.env.signatures && this.env.signatures[id]) { - sig = this.env.signatures[id].text; - sig = sig.replace(/\r\n/g, '\n'); - - if (this.env.top_posting) { - if (p >= 0) { // in place of removed signature - message = message.substring(0, p) + sig + message.substring(p, message.length); - cursor_pos = p - 1; - } - else if (!message) { // empty message - cursor_pos = 0; - message = '\n\n' + sig; - } - else if (pos = this.get_caret_pos(input_message.get(0))) { // at cursor position - message = message.substring(0, pos) + '\n' + sig + '\n\n' + message.substring(pos, message.length); - cursor_pos = pos; - } - else { // on top - cursor_pos = 0; - message = '\n\n' + sig + '\n\n' + message.replace(/^[\r\n]+/, ''); - } - } - else { - message = message.replace(/[\r\n]+$/, ''); - cursor_pos = !this.env.top_posting && message.length ? message.length+1 : 0; - message += '\n\n' + sig; - } - } - else - cursor_pos = this.env.top_posting ? 0 : message.length; - - input_message.val(message); - - // move cursor before the signature - this.set_caret_pos(input_message.get(0), cursor_pos); - } - else if (show_sig && this.env.signatures) { // html - var editor = tinyMCE.get(this.env.composebody), - sigElem = editor.dom.get('_rc_sig'); - - // Append the signature as a div within the body - if (!sigElem) { - var body = editor.getBody(), - doc = editor.getDoc(); - - sigElem = doc.createElement('div'); - sigElem.setAttribute('id', '_rc_sig'); - - if (this.env.top_posting) { - // if no existing sig and top posting then insert at caret pos - editor.getWin().focus(); // correct focus in IE & Chrome - - var node = editor.selection.getNode(); - if (node.nodeName == 'BODY') { - // no real focus, insert at start - body.insertBefore(sigElem, body.firstChild); - body.insertBefore(doc.createElement('br'), body.firstChild); - } - else { - body.insertBefore(sigElem, node.nextSibling); - body.insertBefore(doc.createElement('br'), node.nextSibling); - } - } - else { - if (bw.ie) // add empty line before signature on IE - body.appendChild(doc.createElement('br')); - - body.appendChild(sigElem); - } - } - - if (this.env.signatures[id]) - sigElem.innerHTML = this.env.signatures[id].html; - } - - this.env.identity = id; - this.triggerEvent('change_identity'); - return true; - }; - - // upload (attachment) file - this.upload_file = function(form, action) - { - if (!form) - return false; - - // count files and size on capable browser - var size = 0, numfiles = 0; - - $('input[type=file]', form).each(function(i, field) { - var files = field.files ? field.files.length : (field.value ? 1 : 0); - - // check file size - if (field.files) { - for (var i=0; i < files; i++) - size += field.files[i].size; - } - - numfiles += files; - }); - - // create hidden iframe and post upload form - if (numfiles) { - if (this.env.max_filesize && this.env.filesizeerror && size > this.env.max_filesize) { - this.display_message(this.env.filesizeerror, 'error'); - return; - } - - var frame_name = this.async_upload_form(form, action || 'upload', function(e) { - var d, content = ''; - try { - if (this.contentDocument) { - d = this.contentDocument; - } else if (this.contentWindow) { - d = this.contentWindow.document; - } - content = d.childNodes[0].innerHTML; - } catch (err) {} - - if (!content.match(/add2attachment/) && (!bw.opera || (rcmail.env.uploadframe && rcmail.env.uploadframe == e.data.ts))) { - if (!content.match(/display_message/)) - rcmail.display_message(rcmail.get_label('fileuploaderror'), 'error'); - rcmail.remove_from_attachment_list(e.data.ts); - } - // Opera hack: handle double onload - if (bw.opera) - rcmail.env.uploadframe = e.data.ts; - }); - - // display upload indicator and cancel button - var content = '<span>' + this.get_label('uploading' + (numfiles > 1 ? 'many' : '')) + '</span>', - ts = frame_name.replace(/^rcmupload/, ''); - - this.add2attachment_list(ts, { name:'', html:content, classname:'uploading', frame:frame_name, complete:false }); - - // upload progress support - if (this.env.upload_progress_time) { - this.upload_progress_start('upload', ts); - } - } - - // set reference to the form object - this.gui_objects.attachmentform = form; - return true; - }; - - // add file name to attachment list - // called from upload page - this.add2attachment_list = function(name, att, upload_id) - { - if (!this.gui_objects.attachmentlist) - return false; - - if (!att.complete && ref.env.loadingicon) - att.html = '<img src="'+ref.env.loadingicon+'" alt="" class="uploading" />' + att.html; - - if (!att.complete && att.frame) - att.html = '<a title="'+this.get_label('cancel')+'" onclick="return rcmail.cancel_attachment_upload(\''+name+'\', \''+att.frame+'\');" href="#cancelupload" class="cancelupload">' - + (this.env.cancelicon ? '<img src="'+this.env.cancelicon+'" alt="" />' : this.get_label('cancel')) + '</a>' + att.html; - - var indicator, li = $('<li>'); - - li.attr('id', name) - .addClass(att.classname) - .html(att.html) - .on('mouseover', function() { rcube_webmail.long_subject_title_ex(this, 0); }); - - // replace indicator's li - if (upload_id && (indicator = document.getElementById(upload_id))) { - li.replaceAll(indicator); - } - else { // add new li - li.appendTo(this.gui_objects.attachmentlist); - } - - if (upload_id && this.env.attachments[upload_id]) - delete this.env.attachments[upload_id]; - - this.env.attachments[name] = att; - - return true; - }; - - this.remove_from_attachment_list = function(name) - { - delete this.env.attachments[name]; - $('#'+name).remove(); - }; - - this.remove_attachment = function(name) - { - if (name && this.env.attachments[name]) - this.http_post('remove-attachment', { _id:this.env.compose_id, _file:name }); - - return true; - }; - - this.cancel_attachment_upload = function(name, frame_name) - { - if (!name || !frame_name) - return false; - - this.remove_from_attachment_list(name); - $("iframe[name='"+frame_name+"']").remove(); - return false; - }; - - this.upload_progress_start = function(action, name) - { - setTimeout(function() { rcmail.http_request(action, {_progress: name}); }, - this.env.upload_progress_time * 1000); - }; - - this.upload_progress_update = function(param) - { - var elem = $('#'+param.name + '> span'); - - if (!elem.length || !param.text) - return; - - elem.text(param.text); - - if (!param.done) - this.upload_progress_start(param.action, param.name); - }; - - // send remote request to add a new contact - this.add_contact = function(value) - { - if (value) - this.http_post('addcontact', {_address: value}); - - return true; - }; - - // send remote request to search mail or contacts - this.qsearch = function(value) - { - if (value != '') { - var r, lock = this.set_busy(true, 'searching'), - url = this.search_params(value); - - if (this.message_list) - this.clear_message_list(); - else if (this.contact_list) - this.list_contacts_clear(); - - if (this.env.source) - url._source = this.env.source; - if (this.env.group) - url._gid = this.env.group; - - // reset vars - this.env.current_page = 1; - - var action = this.env.action == 'compose' && this.contact_list ? 'search-contacts' : 'search'; - r = this.http_request(action, url, lock); - - this.env.qsearch = {lock: lock, request: r}; - } - }; - - // build URL params for search - this.search_params = function(search, filter) - { - var n, url = {}, mods_arr = [], - mods = this.env.search_mods, - mbox = this.env.mailbox; - - if (!filter && this.gui_objects.search_filter) - filter = this.gui_objects.search_filter.value; - - if (!search && this.gui_objects.qsearchbox) - search = this.gui_objects.qsearchbox.value; - - if (filter) - url._filter = filter; - - if (search) { - url._q = search; - - if (mods && this.message_list) - mods = mods[mbox] ? mods[mbox] : mods['*']; - - if (mods) { - for (n in mods) - mods_arr.push(n); - url._headers = mods_arr.join(','); - } - } - - if (mbox) - url._mbox = mbox; - - return url; - }; - - // reset quick-search form - this.reset_qsearch = function() - { - if (this.gui_objects.qsearchbox) - this.gui_objects.qsearchbox.value = ''; - - if (this.env.qsearch) - this.abort_request(this.env.qsearch); - - this.env.qsearch = null; - this.env.search_request = null; - this.env.search_id = null; - }; - - this.sent_successfully = function(type, msg, folders) - { - this.display_message(msg, type); - - if (this.env.extwin) { - var rc = this.opener(); - this.lock_form(this.gui_objects.messageform); - if (rc) { - rc.display_message(msg, type); - // refresh the folder where sent message was saved or replied message comes from - if (folders && rc.env.task == 'mail' && rc.env.action == '' && $.inArray(rc.env.mailbox, folders) >= 0) { - // @TODO: try with 'checkmail' here when #1485186 is fixed. See also #1489249. - rc.command('list'); - } - } - setTimeout(function(){ window.close() }, 1000); - } - else { - // before redirect we need to wait some time for Chrome (#1486177) - setTimeout(function(){ ref.list_mailbox(); }, 500); - } - }; - - - /*********************************************************/ - /********* keyboard live-search methods *********/ - /*********************************************************/ - - // handler for keyboard events on address-fields - this.ksearch_keydown = function(e, obj, props) - { - if (this.ksearch_timer) - clearTimeout(this.ksearch_timer); - - var highlight, - key = rcube_event.get_keycode(e), - mod = rcube_event.get_modifier(e); - - switch (key) { - case 38: // arrow up - case 40: // arrow down - if (!this.ksearch_visible()) - break; - - var dir = key==38 ? 1 : 0; - - highlight = document.getElementById('rcmksearchSelected'); - if (!highlight) - highlight = this.ksearch_pane.__ul.firstChild; - - if (highlight) - this.ksearch_select(dir ? highlight.previousSibling : highlight.nextSibling); - - return rcube_event.cancel(e); - - case 9: // tab - if (mod == SHIFT_KEY || !this.ksearch_visible()) { - this.ksearch_hide(); - return; - } - - case 13: // enter - if (!this.ksearch_visible()) - return false; - - // insert selected address and hide ksearch pane - this.insert_recipient(this.ksearch_selected); - this.ksearch_hide(); - - return rcube_event.cancel(e); - - case 27: // escape - this.ksearch_hide(); - return; - - case 37: // left - case 39: // right - if (mod != SHIFT_KEY) - return; - } - - // start timer - this.ksearch_timer = setTimeout(function(){ ref.ksearch_get_results(props); }, 200); - this.ksearch_input = obj; - - return true; - }; - - this.ksearch_visible = function() - { - return (this.ksearch_selected !== null && this.ksearch_selected !== undefined && this.ksearch_value); - }; - - this.ksearch_select = function(node) - { - var current = $('#rcmksearchSelected'); - if (current[0] && node) { - current.removeAttr('id').removeClass('selected'); - } - - if (node) { - $(node).attr('id', 'rcmksearchSelected').addClass('selected'); - this.ksearch_selected = node._rcm_id; - } - }; - - this.insert_recipient = function(id) - { - if (id === null || !this.env.contacts[id] || !this.ksearch_input) - return; - - // get cursor pos - var inp_value = this.ksearch_input.value, - cpos = this.get_caret_pos(this.ksearch_input), - p = inp_value.lastIndexOf(this.ksearch_value, cpos), - trigger = false, - insert = '', - // replace search string with full address - pre = inp_value.substring(0, p), - end = inp_value.substring(p+this.ksearch_value.length, inp_value.length); - - this.ksearch_destroy(); - - // insert all members of a group - if (typeof this.env.contacts[id] === 'object' && this.env.contacts[id].id) { - insert += this.env.contacts[id].name + this.env.recipients_delimiter; - this.group2expand[this.env.contacts[id].id] = $.extend({ input: this.ksearch_input }, this.env.contacts[id]); - this.http_request('mail/group-expand', {_source: this.env.contacts[id].source, _gid: this.env.contacts[id].id}, false); - } - else if (typeof this.env.contacts[id] === 'string') { - insert = this.env.contacts[id] + this.env.recipients_delimiter; - trigger = true; - } - - this.ksearch_input.value = pre + insert + end; - - // set caret to insert pos - cpos = p+insert.length; - if (this.ksearch_input.setSelectionRange) - this.ksearch_input.setSelectionRange(cpos, cpos); - - if (trigger) - this.triggerEvent('autocomplete_insert', { field:this.ksearch_input, insert:insert }); - }; - - this.replace_group_recipients = function(id, recipients) - { - if (this.group2expand[id]) { - this.group2expand[id].input.value = this.group2expand[id].input.value.replace(this.group2expand[id].name, recipients); - this.triggerEvent('autocomplete_insert', { field:this.group2expand[id].input, insert:recipients }); - this.group2expand[id] = null; - } - }; - - // address search processor - this.ksearch_get_results = function(props) - { - var inp_value = this.ksearch_input ? this.ksearch_input.value : null; - - if (inp_value === null) - return; - - if (this.ksearch_pane && this.ksearch_pane.is(":visible")) - this.ksearch_pane.hide(); - - // get string from current cursor pos to last comma - var cpos = this.get_caret_pos(this.ksearch_input), - p = inp_value.lastIndexOf(this.env.recipients_separator, cpos-1), - q = inp_value.substring(p+1, cpos), - min = this.env.autocomplete_min_length, - ac = this.ksearch_data; - - // trim query string - q = $.trim(q); - - // Don't (re-)search if the last results are still active - if (q == this.ksearch_value) - return; - - this.ksearch_destroy(); - - if (q.length && q.length < min) { - if (!this.ksearch_info) { - this.ksearch_info = this.display_message( - this.get_label('autocompletechars').replace('$min', min)); - } - return; - } - - var old_value = this.ksearch_value; - this.ksearch_value = q; - - // ...string is empty - if (!q.length) - return; - - // ...new search value contains old one and previous search was not finished or its result was empty - if (old_value && old_value.length && q.startsWith(old_value) && (!ac || ac.num <= 0) && this.env.contacts && !this.env.contacts.length) - return; - - var i, lock, source, xhr, reqid = new Date().getTime(), - post_data = {_search: q, _id: reqid}, - threads = props && props.threads ? props.threads : 1, - sources = props && props.sources ? props.sources : [], - action = props && props.action ? props.action : 'mail/autocomplete'; - - this.ksearch_data = {id: reqid, sources: sources.slice(), action: action, - locks: [], requests: [], num: sources.length}; - - for (i=0; i<threads; i++) { - source = this.ksearch_data.sources.shift(); - if (threads > 1 && source === undefined) - break; - - post_data._source = source ? source : ''; - lock = this.display_message(this.get_label('searching'), 'loading'); - xhr = this.http_post(action, post_data, lock); - - this.ksearch_data.locks.push(lock); - this.ksearch_data.requests.push(xhr); - } - }; - - this.ksearch_query_results = function(results, search, reqid) - { - // search stopped in meantime? - if (!this.ksearch_value) - return; - - // ignore this outdated search response - if (this.ksearch_input && search != this.ksearch_value) - return; - - // display search results - var i, len, ul, li, text, init, - value = this.ksearch_value, - data = this.ksearch_data, - maxlen = this.env.autocomplete_max ? this.env.autocomplete_max : 15; - - // create results pane if not present - if (!this.ksearch_pane) { - ul = $('<ul>'); - this.ksearch_pane = $('<div>').attr('id', 'rcmKSearchpane') - .css({ position:'absolute', 'z-index':30000 }).append(ul).appendTo(document.body); - this.ksearch_pane.__ul = ul[0]; - } - - ul = this.ksearch_pane.__ul; - - // remove all search results or add to existing list if parallel search - if (reqid && this.ksearch_pane.data('reqid') == reqid) { - maxlen -= ul.childNodes.length; - } - else { - this.ksearch_pane.data('reqid', reqid); - init = 1; - // reset content - ul.innerHTML = ''; - this.env.contacts = []; - // move the results pane right under the input box - var pos = $(this.ksearch_input).offset(); - this.ksearch_pane.css({ left:pos.left+'px', top:(pos.top + this.ksearch_input.offsetHeight)+'px', display: 'none'}); - } - - // add each result line to list - if (results && (len = results.length)) { - for (i=0; i < len && maxlen > 0; i++) { - text = typeof results[i] === 'object' ? results[i].name : results[i]; - li = document.createElement('LI'); - li.innerHTML = text.replace(new RegExp('('+RegExp.escape(value)+')', 'ig'), '##$1%%').replace(/</g, '<').replace(/>/g, '>').replace(/##([^%]+)%%/g, '<b>$1</b>'); - li.onmouseover = function(){ ref.ksearch_select(this); }; - li.onmouseup = function(){ ref.ksearch_click(this) }; - li._rcm_id = this.env.contacts.length + i; - ul.appendChild(li); - maxlen -= 1; - } - } - - if (ul.childNodes.length) { - this.ksearch_pane.show(); - // select the first - if (!this.env.contacts.length) { - $('li:first', ul).attr('id', 'rcmksearchSelected').addClass('selected'); - this.ksearch_selected = 0; - } - } - - if (len) - this.env.contacts = this.env.contacts.concat(results); - - // run next parallel search - if (data.id == reqid) { - data.num--; - if (maxlen > 0 && data.sources.length) { - var lock, xhr, source = data.sources.shift(), post_data; - if (source) { - post_data = {_search: value, _id: reqid, _source: source}; - lock = this.display_message(this.get_label('searching'), 'loading'); - xhr = this.http_post(data.action, post_data, lock); - - this.ksearch_data.locks.push(lock); - this.ksearch_data.requests.push(xhr); - } - } - else if (!maxlen) { - if (!this.ksearch_msg) - this.ksearch_msg = this.display_message(this.get_label('autocompletemore')); - // abort pending searches - this.ksearch_abort(); - } - } - }; - - this.ksearch_click = function(node) - { - if (this.ksearch_input) - this.ksearch_input.focus(); - - this.insert_recipient(node._rcm_id); - this.ksearch_hide(); - }; - - this.ksearch_blur = function() - { - if (this.ksearch_timer) - clearTimeout(this.ksearch_timer); - - this.ksearch_input = null; - this.ksearch_hide(); - }; - - this.ksearch_hide = function() - { - this.ksearch_selected = null; - this.ksearch_value = ''; - - if (this.ksearch_pane) - this.ksearch_pane.hide(); - - this.ksearch_destroy(); - }; - - // Clears autocomplete data/requests - this.ksearch_destroy = function() - { - this.ksearch_abort(); - - if (this.ksearch_info) - this.hide_message(this.ksearch_info); - - if (this.ksearch_msg) - this.hide_message(this.ksearch_msg); - - this.ksearch_data = null; - this.ksearch_info = null; - this.ksearch_msg = null; - } - - // Aborts pending autocomplete requests - this.ksearch_abort = function() - { - var i, len, ac = this.ksearch_data; - - if (!ac) - return; - - for (i=0, len=ac.locks.length; i<len; i++) - this.abort_request({request: ac.requests[i], lock: ac.locks[i]}); - }; - - - /*********************************************************/ - /********* address book methods *********/ - /*********************************************************/ - - this.contactlist_keypress = function(list) - { - if (list.key_pressed == list.DELETE_KEY) - this.command('delete'); - }; - - this.contactlist_select = function(list) - { - if (this.preview_timer) - clearTimeout(this.preview_timer); - - var n, id, sid, contact, ref = this, writable = false, - source = this.env.source ? this.env.address_sources[this.env.source] : null; - - // we don't have dblclick handler here, so use 200 instead of this.dblclick_time - if (id = list.get_single_selection()) - this.preview_timer = setTimeout(function(){ ref.load_contact(id, 'show'); }, 200); - else if (this.env.contentframe) - this.show_contentframe(false); - - if (list.selection.length) { - list.draggable = false; - - // no source = search result, we'll need to detect if any of - // selected contacts are in writable addressbook to enable edit/delete - // we'll also need to know sources used in selection for copy - // and group-addmember operations (drag&drop) - this.env.selection_sources = []; - - if (source) { - this.env.selection_sources.push(this.env.source); - } - - for (n in list.selection) { - contact = list.data[list.selection[n]]; - if (!source) { - sid = String(list.selection[n]).replace(/^[^-]+-/, ''); - if (sid && this.env.address_sources[sid]) { - writable = writable || (!this.env.address_sources[sid].readonly && !contact.readonly); - this.env.selection_sources.push(sid); - } - } - else { - writable = writable || (!source.readonly && !contact.readonly); - } - - if (contact._type != 'group') - list.draggable = true; - } - - this.env.selection_sources = $.unique(this.env.selection_sources); - } - - // if a group is currently selected, and there is at least one contact selected - // thend we can enable the group-remove-selected command - this.enable_command('group-remove-selected', this.env.group && list.selection.length > 0 && writable); - this.enable_command('compose', this.env.group || list.selection.length > 0); - this.enable_command('export-selected', 'copy', list.selection.length > 0); - this.enable_command('edit', id && writable); - this.enable_command('delete', 'move', list.selection.length > 0 && writable); - - return false; - }; - - this.list_contacts = function(src, group, page) - { - var win, folder, url = {}, - target = window; - - if (!src) - src = this.env.source; - - if (page && this.current_page == page && src == this.env.source && group == this.env.group) - return false; - - if (src != this.env.source) { - page = this.env.current_page = 1; - this.reset_qsearch(); - } - else if (group != this.env.group) - page = this.env.current_page = 1; - - if (this.env.search_id) - folder = 'S'+this.env.search_id; - else if (!this.env.search_request) - folder = group ? 'G'+src+group : src; - - this.env.source = src; - this.env.group = group; - - // truncate groups listing stack - var index = $.inArray(this.env.group, this.env.address_group_stack); - if (index < 0) - this.env.address_group_stack = []; - else - this.env.address_group_stack = this.env.address_group_stack.slice(0,index); - - // make sure the current group is on top of the stack - if (this.env.group) { - this.env.address_group_stack.push(this.env.group); - - // mark the first group on the stack as selected in the directory list - folder = 'G'+src+this.env.address_group_stack[0]; - } - else if (this.gui_objects.addresslist_title) { - $(this.gui_objects.addresslist_title).html(this.get_label('contacts')); - } - - this.select_folder(folder, '', true); - - // load contacts remotely - if (this.gui_objects.contactslist) { - this.list_contacts_remote(src, group, page); - return; - } - - if (win = this.get_frame_window(this.env.contentframe)) { - target = win; - url._framed = 1; - } - - if (group) - url._gid = group; - if (page) - url._page = page; - if (src) - url._source = src; - - // also send search request to get the correct listing - if (this.env.search_request) - url._search = this.env.search_request; - - this.set_busy(true, 'loading'); - this.location_href(url, target); - }; - - // send remote request to load contacts list - this.list_contacts_remote = function(src, group, page) - { - // clear message list first - this.list_contacts_clear(); - - // send request to server - var url = {}, lock = this.set_busy(true, 'loading'); - - if (src) - url._source = src; - if (page) - url._page = page; - if (group) - url._gid = group; - - this.env.source = src; - this.env.group = group; - - // also send search request to get the right records - if (this.env.search_request) - url._search = this.env.search_request; - - this.http_request(this.env.task == 'mail' ? 'list-contacts' : 'list', url, lock); - }; - - this.list_contacts_clear = function() - { - this.contact_list.data = {}; - this.contact_list.clear(true); - this.show_contentframe(false); - this.enable_command('delete', 'move', 'copy', false); - this.enable_command('compose', this.env.group ? true : false); - }; - - this.set_group_prop = function(prop) - { - if (this.gui_objects.addresslist_title) { - var boxtitle = $(this.gui_objects.addresslist_title).html(''); // clear contents - - // add link to pop back to parent group - if (this.env.address_group_stack.length > 1) { - $('<a href="#list">...</a>') - .addClass('poplink') - .appendTo(boxtitle) - .click(function(e){ return ref.command('popgroup','',this); }); - boxtitle.append(' » '); - } - - boxtitle.append($('<span>').text(prop.name)); - } - - this.triggerEvent('groupupdate', prop); - }; - - // load contact record - this.load_contact = function(cid, action, framed) - { - var win, url = {}, target = window, - rec = this.contact_list ? this.contact_list.data[cid] : null; - - if (win = this.get_frame_window(this.env.contentframe)) { - url._framed = 1; - target = win; - this.show_contentframe(true); - - // load dummy content, unselect selected row(s) - if (!cid) - this.contact_list.clear_selection(); - - this.enable_command('compose', rec && rec.email); - this.enable_command('export-selected', rec && rec._type != 'group'); - } - else if (framed) - return false; - - if (action && (cid || action=='add') && !this.drag_active) { - if (this.env.group) - url._gid = this.env.group; - - url._action = action; - url._source = this.env.source; - url._cid = cid; - - this.location_href(url, target, true); - } - - return true; - }; - - // add/delete member to/from the group - this.group_member_change = function(what, cid, source, gid) - { - what = what == 'add' ? 'add' : 'del'; - var label = this.get_label(what == 'add' ? 'addingmember' : 'removingmember'), - lock = this.display_message(label, 'loading'), - post_data = {_cid: cid, _source: source, _gid: gid}; - - this.http_post('group-'+what+'members', post_data, lock); - }; - - this.contacts_drag_menu = function(e, to) - { - var dest = to.type == 'group' ? to.source : to.id, - source = this.env.source; - - if (!this.env.address_sources[dest] || this.env.address_sources[dest].readonly) - return true; - - // search result may contain contacts from many sources, but if there is only one... - if (source == '' && this.env.selection_sources.length == 1) - source = this.env.selection_sources[0]; - - if (to.type == 'group' && dest == source) { - var cid = this.contact_list.get_selection().join(','); - this.group_member_change('add', cid, dest, to.id); - return true; - } - // move action is not possible, "redirect" to copy if menu wasn't requested - else if (!this.commands.move && rcube_event.get_modifier(e) != SHIFT_KEY) { - this.copy_contacts(to); - return true; - } - - return this.drag_menu(e, to); - }; - - // copy contact(s) to the specified target (group or directory) - this.copy_contacts = function(to) - { - var n, dest = to.type == 'group' ? to.source : to.id, - source = this.env.source, - group = this.env.group ? this.env.group : '', - cid = this.contact_list.get_selection().join(','); - - if (!cid || !this.env.address_sources[dest] || this.env.address_sources[dest].readonly) - return; - - // search result may contain contacts from many sources, but if there is only one... - if (source == '' && this.env.selection_sources.length == 1) - source = this.env.selection_sources[0]; - - // tagret is a group - if (to.type == 'group') { - if (dest == source) - return; - - var lock = this.display_message(this.get_label('copyingcontact'), 'loading'), - post_data = {_cid: cid, _source: this.env.source, _to: dest, _togid: to.id, _gid: group}; - - this.http_post('copy', post_data, lock); - } - // target is an addressbook - else if (to.id != source) { - var lock = this.display_message(this.get_label('copyingcontact'), 'loading'), - post_data = {_cid: cid, _source: this.env.source, _to: to.id, _gid: group}; - - this.http_post('copy', post_data, lock); - } - }; - - // move contact(s) to the specified target (group or directory) - this.move_contacts = function(to) - { - var dest = to.type == 'group' ? to.source : to.id, - source = this.env.source, - group = this.env.group ? this.env.group : ''; - - if (!this.env.address_sources[dest] || this.env.address_sources[dest].readonly) - return; - - // search result may contain contacts from many sources, but if there is only one... - if (source == '' && this.env.selection_sources.length == 1) - source = this.env.selection_sources[0]; - - if (to.type == 'group') { - if (dest == source) - return; - - this._with_selected_contacts('move', {_to: dest, _togid: to.id}); - } - // target is an addressbook - else if (to.id != source) - this._with_selected_contacts('move', {_to: to.id}); - }; - - // delete contact(s) - this.delete_contacts = function() - { - var undelete = this.env.source && this.env.address_sources[this.env.source].undelete; - - if (!undelete && !confirm(this.get_label('deletecontactconfirm'))) - return; - - return this._with_selected_contacts('delete'); - }; - - this._with_selected_contacts = function(action, post_data) - { - var selection = this.contact_list ? this.contact_list.get_selection() : []; - - // exit if no mailbox specified or if selection is empty - if (!selection.length && !this.env.cid) - return; - - var n, a_cids = [], - label = action == 'delete' ? 'contactdeleting' : 'movingcontact', - lock = this.display_message(this.get_label(label), 'loading'); - if (this.env.cid) - a_cids.push(this.env.cid); - else { - for (n=0; n<selection.length; n++) { - id = selection[n]; - a_cids.push(id); - this.contact_list.remove_row(id, (n == selection.length-1)); - } - - // hide content frame if we delete the currently displayed contact - if (selection.length == 1) - this.show_contentframe(false); - } - - if (!post_data) - post_data = {}; - - post_data._source = this.env.source; - post_data._from = this.env.action; - post_data._cid = a_cids.join(','); - - if (this.env.group) - post_data._gid = this.env.group; - - // also send search request to get the right records from the next page - if (this.env.search_request) - post_data._search = this.env.search_request; - - // send request to server - this.http_post(action, post_data, lock) - - return true; - }; - - // update a contact record in the list - this.update_contact_row = function(cid, cols_arr, newcid, source, data) - { - var c, row, list = this.contact_list; - - cid = this.html_identifier(cid); - - // when in searching mode, concat cid with the source name - if (!list.rows[cid]) { - cid = cid+'-'+source; - if (newcid) - newcid = newcid+'-'+source; - } - - list.update_row(cid, cols_arr, newcid, true); - list.data[cid] = data; - }; - - // add row to contacts list - this.add_contact_row = function(cid, cols, classes, data) - { - if (!this.gui_objects.contactslist) - return false; - - var c, col, list = this.contact_list, - row = { cols:[] }; - - row.id = 'rcmrow'+this.html_identifier(cid); - row.className = 'contact ' + (classes || ''); - - if (list.in_selection(cid)) - row.className += ' selected'; - - // add each submitted col - for (c in cols) { - col = {}; - col.className = String(c).toLowerCase(); - col.innerHTML = cols[c]; - row.cols.push(col); - } - - // store data in list member - list.data[cid] = data; - list.insert_row(row); - - this.enable_command('export', list.rowcount > 0); - }; - - this.init_contact_form = function() - { - var ref = this, col; - - if (this.env.coltypes) { - this.set_photo_actions($('#ff_photo').val()); - for (col in this.env.coltypes) - this.init_edit_field(col, null); - } - - $('.contactfieldgroup .row a.deletebutton').click(function() { - ref.delete_edit_field(this); - return false; - }); - - $('select.addfieldmenu').change(function(e) { - ref.insert_edit_field($(this).val(), $(this).attr('rel'), this); - this.selectedIndex = 0; - }); - - // enable date pickers on date fields - if ($.datepicker && this.env.date_format) { - $.datepicker.setDefaults({ - dateFormat: this.env.date_format, - changeMonth: true, - changeYear: true, - yearRange: '-100:+10', - showOtherMonths: true, - selectOtherMonths: true, - onSelect: function(dateText) { $(this).focus().val(dateText) } - }); - $('input.datepicker').datepicker(); - } - - // Submit search form on Enter - if (this.env.action == 'search') - $(this.gui_objects.editform).append($('<input type="submit">').hide()) - .submit(function() { $('input.mainaction').click(); return false; }); - }; - - this.group_create = function() - { - this.add_input_row('contactgroup'); - }; - - this.group_rename = function() - { - if (!this.env.group || !this.gui_objects.folderlist) - return; - - if (!this.name_input) { - this.enable_command('list', 'listgroup', false); - this.name_input = $('<input>').attr('type', 'text').val(this.env.contactgroups['G'+this.env.source+this.env.group].name); - this.name_input.bind('keydown', function(e){ return rcmail.add_input_keydown(e); }); - this.env.group_renaming = true; - - var link, li = this.get_folder_li('G'+this.env.source+this.env.group,'',true); - if (li && (link = li.firstChild)) { - $(link).hide().before(this.name_input); - } - } - - this.name_input.select().focus(); - }; - - this.group_delete = function() - { - if (this.env.group && confirm(this.get_label('deletegroupconfirm'))) { - var lock = this.set_busy(true, 'groupdeleting'); - this.http_post('group-delete', {_source: this.env.source, _gid: this.env.group}, lock); - } - }; - - // callback from server upon group-delete command - this.remove_group_item = function(prop) - { - var key = 'G'+prop.source+prop.id; - if (this.treelist.remove(key)) { - delete this.env.contactfolders[key]; - delete this.env.contactgroups[key]; - } - - this.list_contacts(prop.source, 0); - }; - - // @TODO: maybe it would be better to use popup instead of inserting input to the list? - this.add_input_row = function(type) - { - if (!this.gui_objects.folderlist) - return; - - if (!this.name_input) { - this.name_input = $('<input>').attr('type', 'text').data('tt', type); - this.name_input.bind('keydown', function(e){ return rcmail.add_input_keydown(e); }); - this.name_input_li = $('<li>').addClass(type).append(this.name_input); - - var ul, li; - - // find list (UL) element - if (type == 'contactsearch') - ul = this.gui_objects.folderlist; - else - ul = $('ul.groups', this.get_folder_li(this.env.source,'',true)); - - // append to the list - li = $('li:last', ul); - if (li.length) - this.name_input_li.insertAfter(li); - else { - this.name_input_li.appendTo(ul); - ul.show(); // make sure the list is visible - } - } - - this.name_input.select().focus(); - }; - - //remove selected contacts from current active group - this.group_remove_selected = function() - { - ref.http_post('group-delmembers', {_cid: this.contact_list.selection, - _source: this.env.source, _gid: this.env.group}); - }; - - //callback after deleting contact(s) from current group - this.remove_group_contacts = function(props) - { - if('undefined' != typeof this.env.group && (this.env.group === props.gid)){ - var n, selection = this.contact_list.get_selection(); - for (n=0; n<selection.length; n++) { - id = selection[n]; - this.contact_list.remove_row(id, (n == selection.length-1)); - } - } - } - - // handler for keyboard events on the input field - this.add_input_keydown = function(e) - { - var key = rcube_event.get_keycode(e), - input = $(e.target), itype = input.data('tt'); - - // enter - if (key == 13) { - var newname = input.val(); - - if (newname) { - var lock = this.set_busy(true, 'loading'); - - if (itype == 'contactsearch') - this.http_post('search-create', {_search: this.env.search_request, _name: newname}, lock); - else if (this.env.group_renaming) - this.http_post('group-rename', {_source: this.env.source, _gid: this.env.group, _name: newname}, lock); - else - this.http_post('group-create', {_source: this.env.source, _name: newname}, lock); - } - return false; - } - // escape - else if (key == 27) - this.reset_add_input(); - - return true; - }; - - this.reset_add_input = function() - { - if (this.name_input) { - var li = this.name_input.parent(); - if (this.env.group_renaming) { - li.children().last().show(); - this.env.group_renaming = false; - } - else if ($('li', li.parent()).length == 1) - li.parent().hide(); - - this.name_input.remove(); - - if (this.name_input_li) - this.name_input_li.remove(); - - this.name_input = this.name_input_li = null; - } - - this.enable_command('list', 'listgroup', true); - }; - - // callback for creating a new contact group - this.insert_contact_group = function(prop) - { - this.reset_add_input(); - - prop.type = 'group'; - var key = 'G'+prop.source+prop.id, - link = $('<a>').attr('href', '#') - .attr('rel', prop.source+':'+prop.id) - .click(function() { return rcmail.command('listgroup', prop, this); }) - .html(prop.name); - - this.env.contactfolders[key] = this.env.contactgroups[key] = prop; - this.treelist.insert({ id:key, html:link, classes:['contactgroup'] }, prop.source, true); - - this.triggerEvent('group_insert', { id:prop.id, source:prop.source, name:prop.name, li:this.treelist.get_item(key) }); - }; - - // callback for renaming a contact group - this.update_contact_group = function(prop) - { - this.reset_add_input(); - - var key = 'G'+prop.source+prop.id, - newnode = {}; - - // group ID has changed, replace link node and identifiers - if (prop.newid) { - var newkey = 'G'+prop.source+prop.newid, - newprop = $.extend({}, prop); - - this.env.contactfolders[newkey] = this.env.contactfolders[key]; - this.env.contactfolders[newkey].id = prop.newid; - this.env.group = prop.newid; - - delete this.env.contactfolders[key]; - delete this.env.contactgroups[key]; - - newprop.id = prop.newid; - newprop.type = 'group'; - - newnode.id = newkey; - newnode.html = $('<a>').attr('href', '#') - .attr('rel', prop.source+':'+prop.newid) - .click(function() { return rcmail.command('listgroup', newprop, this); }) - .html(prop.name); - } - // update displayed group name - else { - $(this.treelist.get_item(key)).children().first().html(prop.name); - this.env.contactfolders[key].name = this.env.contactgroups[key].name = prop.name; - } - - // update list node and re-sort it - this.treelist.update(key, newnode, true); - - this.triggerEvent('group_update', { id:prop.id, source:prop.source, name:prop.name, li:this.treelist.get_item(key), newid:prop.newid }); - }; - - this.update_group_commands = function() - { - var source = this.env.source != '' ? this.env.address_sources[this.env.source] : null; - this.enable_command('group-create', (source && source.groups && !source.readonly)); - this.enable_command('group-rename', 'group-delete', (source && source.groups && this.env.group && !source.readonly)); - }; - - this.init_edit_field = function(col, elem) - { - var label = this.env.coltypes[col].label; - - if (!elem) - elem = $('.ff_' + col); - - if (label) - elem.placeholder(label); - }; - - this.insert_edit_field = function(col, section, menu) - { - // just make pre-defined input field visible - var elem = $('#ff_'+col); - if (elem.length) { - elem.show().focus(); - $(menu).children('option[value="'+col+'"]').prop('disabled', true); - } - else { - var lastelem = $('.ff_'+col), - appendcontainer = $('#contactsection'+section+' .contactcontroller'+col); - - if (!appendcontainer.length) { - var sect = $('#contactsection'+section), - lastgroup = $('.contactfieldgroup', sect).last(); - appendcontainer = $('<fieldset>').addClass('contactfieldgroup contactcontroller'+col); - if (lastgroup.length) - appendcontainer.insertAfter(lastgroup); - else - sect.prepend(appendcontainer); - } - - if (appendcontainer.length && appendcontainer.get(0).nodeName == 'FIELDSET') { - var input, colprop = this.env.coltypes[col], - row = $('<div>').addClass('row'), - cell = $('<div>').addClass('contactfieldcontent data'), - label = $('<div>').addClass('contactfieldlabel label'); - - if (colprop.subtypes_select) - label.html(colprop.subtypes_select); - else - label.html(colprop.label); - - var name_suffix = colprop.limit != 1 ? '[]' : ''; - if (colprop.type == 'text' || colprop.type == 'date') { - input = $('<input>') - .addClass('ff_'+col) - .attr({type: 'text', name: '_'+col+name_suffix, size: colprop.size}) - .appendTo(cell); - - this.init_edit_field(col, input); - - if (colprop.type == 'date' && $.datepicker) - input.datepicker(); - } - else if (colprop.type == 'textarea') { - input = $('<textarea>') - .addClass('ff_'+col) - .attr({ name: '_'+col+name_suffix, cols:colprop.size, rows:colprop.rows }) - .appendTo(cell); - - this.init_edit_field(col, input); - } - else if (colprop.type == 'composite') { - var childcol, cp, first, templ, cols = [], suffices = []; - // read template for composite field order - if ((templ = this.env[col+'_template'])) { - for (var j=0; j < templ.length; j++) { - cols.push(templ[j][1]); - suffices.push(templ[j][2]); - } - } - else { // list fields according to appearance in colprop - for (childcol in colprop.childs) - cols.push(childcol); - } - - for (var i=0; i < cols.length; i++) { - childcol = cols[i]; - cp = colprop.childs[childcol]; - input = $('<input>') - .addClass('ff_'+childcol) - .attr({ type: 'text', name: '_'+childcol+name_suffix, size: cp.size }) - .appendTo(cell); - cell.append(suffices[i] || " "); - this.init_edit_field(childcol, input); - if (!first) first = input; - } - input = first; // set focus to the first of this composite fields - } - else if (colprop.type == 'select') { - input = $('<select>') - .addClass('ff_'+col) - .attr('name', '_'+col+name_suffix) - .appendTo(cell); - - var options = input.attr('options'); - options[options.length] = new Option('---', ''); - if (colprop.options) - $.each(colprop.options, function(i, val){ options[options.length] = new Option(val, i); }); - } - - if (input) { - var delbutton = $('<a href="#del"></a>') - .addClass('contactfieldbutton deletebutton') - .attr({title: this.get_label('delete'), rel: col}) - .html(this.env.delbutton) - .click(function(){ ref.delete_edit_field(this); return false }) - .appendTo(cell); - - row.append(label).append(cell).appendTo(appendcontainer.show()); - input.first().focus(); - - // disable option if limit reached - if (!colprop.count) colprop.count = 0; - if (++colprop.count == colprop.limit && colprop.limit) - $(menu).children('option[value="'+col+'"]').prop('disabled', true); - } - } - } - }; - - this.delete_edit_field = function(elem) - { - var col = $(elem).attr('rel'), - colprop = this.env.coltypes[col], - fieldset = $(elem).parents('fieldset.contactfieldgroup'), - addmenu = fieldset.parent().find('select.addfieldmenu'); - - // just clear input but don't hide the last field - if (--colprop.count <= 0 && colprop.visible) - $(elem).parent().children('input').val('').blur(); - else { - $(elem).parents('div.row').remove(); - // hide entire fieldset if no more rows - if (!fieldset.children('div.row').length) - fieldset.hide(); - } - - // enable option in add-field selector or insert it if necessary - if (addmenu.length) { - var option = addmenu.children('option[value="'+col+'"]'); - if (option.length) - option.prop('disabled', false); - else - option = $('<option>').attr('value', col).html(colprop.label).appendTo(addmenu); - addmenu.show(); - } - }; - - this.upload_contact_photo = function(form) - { - if (form && form.elements._photo.value) { - this.async_upload_form(form, 'upload-photo', function(e) { - rcmail.set_busy(false, null, rcmail.file_upload_id); - }); - - // display upload indicator - this.file_upload_id = this.set_busy(true, 'uploading'); - } - }; - - this.replace_contact_photo = function(id) - { - var img_src = id == '-del-' ? this.env.photo_placeholder : - this.env.comm_path + '&_action=photo&_source=' + this.env.source + '&_cid=' + (this.env.cid || 0) + '&_photo=' + id; - - this.set_photo_actions(id); - $(this.gui_objects.contactphoto).children('img').attr('src', img_src); - }; - - this.photo_upload_end = function() - { - this.set_busy(false, null, this.file_upload_id); - delete this.file_upload_id; - }; - - this.set_photo_actions = function(id) - { - var n, buttons = this.buttons['upload-photo']; - for (n=0; buttons && n < buttons.length; n++) - $('a#'+buttons[n].id).html(this.get_label(id == '-del-' ? 'addphoto' : 'replacephoto')); - - $('#ff_photo').val(id); - this.enable_command('upload-photo', this.env.coltypes.photo ? true : false); - this.enable_command('delete-photo', this.env.coltypes.photo && id != '-del-'); - }; - - // load advanced search page - this.advanced_search = function() - { - var win, url = {_form: 1, _action: 'search'}, target = window; - - if (win = this.get_frame_window(this.env.contentframe)) { - url._framed = 1; - target = win; - this.contact_list.clear_selection(); - } - - this.location_href(url, target, true); - - return true; - }; - - // unselect directory/group - this.unselect_directory = function() - { - this.select_folder(''); - this.enable_command('search-delete', false); - }; - - // callback for creating a new saved search record - this.insert_saved_search = function(name, id) - { - this.reset_add_input(); - - var key = 'S'+id, - link = $('<a>').attr('href', '#') - .attr('rel', id) - .click(function() { return rcmail.command('listsearch', id, this); }) - .html(name), - prop = { name:name, id:id }; - - this.treelist.insert({ id:key, html:link, classes:['contactsearch'] }, null, 'contactsearch'); - this.select_folder(key,'',true); - this.enable_command('search-delete', true); - this.env.search_id = id; - - this.triggerEvent('abook_search_insert', prop); - }; - - // creates an input for saved search name - this.search_create = function() - { - this.add_input_row('contactsearch'); - }; - - this.search_delete = function() - { - if (this.env.search_request) { - var lock = this.set_busy(true, 'savedsearchdeleting'); - this.http_post('search-delete', {_sid: this.env.search_id}, lock); - } - }; - - // callback from server upon search-delete command - this.remove_search_item = function(id) - { - var li, key = 'S'+id; - if (this.treelist.remove(key)) { - this.triggerEvent('search_delete', { id:id, li:li }); - } - - this.env.search_id = null; - this.env.search_request = null; - this.list_contacts_clear(); - this.reset_qsearch(); - this.enable_command('search-delete', 'search-create', false); - }; - - this.listsearch = function(id) - { - var folder, lock = this.set_busy(true, 'searching'); - - if (this.contact_list) { - this.list_contacts_clear(); - } - - this.reset_qsearch(); - this.select_folder('S'+id, '', true); - - // reset vars - this.env.current_page = 1; - this.http_request('search', {_sid: id}, lock); - }; - - - /*********************************************************/ - /********* user settings methods *********/ - /*********************************************************/ - - // preferences section select and load options frame - this.section_select = function(list) - { - var win, id = list.get_single_selection(), target = window, - url = {_action: 'edit-prefs', _section: id}; - - if (id) { - if (win = this.get_frame_window(this.env.contentframe)) { - url._framed = 1; - target = win; - } - this.location_href(url, target, true); - } - - return true; - }; - - this.identity_select = function(list) - { - var id; - if (id = list.get_single_selection()) { - this.enable_command('delete', list.rowcount > 1 && this.env.identities_level < 2); - this.load_identity(id, 'edit-identity'); - } - }; - - // load identity record - this.load_identity = function(id, action) - { - if (action == 'edit-identity' && (!id || id == this.env.iid)) - return false; - - var win, target = window, - url = {_action: action, _iid: id}; - - if (win = this.get_frame_window(this.env.contentframe)) { - url._framed = 1; - target = win; - } - - if (action && (id || action == 'add-identity')) { - this.set_busy(true); - this.location_href(url, target); - } - - return true; - }; - - this.delete_identity = function(id) - { - // exit if no identity is specified or if selection is empty - var selection = this.identity_list.get_selection(); - if (!(selection.length || this.env.iid)) - return; - - if (!id) - id = this.env.iid ? this.env.iid : selection[0]; - - // submit request with appended token - if (confirm(this.get_label('deleteidentityconfirm'))) - this.goto_url('delete-identity', { _iid: id, _token: this.env.request_token }, true); - - return true; - }; - - this.update_identity_row = function(id, name, add) - { - var list = this.identity_list, - rid = this.html_identifier(id); - - if (add) { - list.insert_row({ id:'rcmrow'+rid, cols:[ { className:'mail', innerHTML:name } ] }); - list.select(rid); - } - else { - list.update_row(rid, [ name ]); - } - }; - - this.update_response_row = function(response, oldkey) - { - var list = this.responses_list; - - if (list && oldkey) { - list.update_row(oldkey, [ response.name ], response.key, true); - } - else if (list) { - list.insert_row({ id:'rcmrow'+response.key, cols:[ { className:'name', innerHTML:response.name } ] }); - list.select(response.key); - } - }; - - this.remove_response = function(key) - { - var frame; - - if (this.env.textresponses) { - delete this.env.textresponses[key]; - } - - if (this.responses_list) { - this.responses_list.remove_row(key); - if (this.env.contentframe && (frame = this.get_frame_window(this.env.contentframe))) { - frame.location.href = this.env.blankpage; - } - } - }; - - - /*********************************************************/ - /********* folder manager methods *********/ - /*********************************************************/ - - this.init_subscription_list = function() - { - var p = this, delim = RegExp.escape(this.env.delimiter); - - this.last_sub_rx = RegExp('['+delim+']?[^'+delim+']+$'); - - this.subscription_list = new rcube_list_widget(this.gui_objects.subscriptionlist, - {multiselect:false, draggable:true, keyboard:false, toggleselect:true}); - this.subscription_list.addEventListener('select', function(o){ p.subscription_select(o); }); - this.subscription_list.addEventListener('dragstart', function(o){ p.drag_active = true; }); - this.subscription_list.addEventListener('dragend', function(o){ p.subscription_move_folder(o); }); - this.subscription_list.row_init = function (row) { - row.obj.onmouseover = function() { p.focus_subscription(row.id); }; - row.obj.onmouseout = function() { p.unfocus_subscription(row.id); }; - }; - this.subscription_list.init(); - - $('#mailboxroot') - .mouseover(function(){ p.focus_subscription(this.id); }) - .mouseout(function(){ p.unfocus_subscription(this.id); }) - }; - - this.focus_subscription = function(id) - { - var row, folder; - - if (this.drag_active && this.env.mailbox && (row = document.getElementById(id))) - if (this.env.subscriptionrows[id] && - (folder = this.env.subscriptionrows[id][0]) !== null - ) { - if (this.check_droptarget(folder) && - !this.env.subscriptionrows[this.get_folder_row_id(this.env.mailbox)][2] && - folder != this.env.mailbox.replace(this.last_sub_rx, '') && - !folder.startsWith(this.env.mailbox + this.env.delimiter) - ) { - this.env.dstfolder = folder; - $(row).addClass('droptarget'); - } - } - }; - - this.unfocus_subscription = function(id) - { - var row = $('#'+id); - - this.env.dstfolder = null; - - if (this.env.subscriptionrows[id] && row.length) - row.removeClass('droptarget'); - else - $(this.subscription_list.frame).removeClass('droptarget'); - }; - - this.subscription_select = function(list) - { - var id, folder; - - if (list && (id = list.get_single_selection()) && - (folder = this.env.subscriptionrows['rcmrow'+id]) - ) { - this.env.mailbox = folder[0]; - this.show_folder(folder[0]); - this.enable_command('delete-folder', !folder[2]); - } - else { - this.env.mailbox = null; - this.show_contentframe(false); - this.enable_command('delete-folder', 'purge', false); - } - }; - - this.subscription_move_folder = function(list) - { - if (this.env.mailbox && this.env.dstfolder !== null && - this.env.dstfolder != this.env.mailbox && - this.env.dstfolder != this.env.mailbox.replace(this.last_sub_rx, '') - ) { - var path = this.env.mailbox.split(this.env.delimiter), - basename = path.pop(), - newname = this.env.dstfolder === '' ? basename : this.env.dstfolder + this.env.delimiter + basename; - - if (newname != this.env.mailbox) { - this.http_post('rename-folder', {_folder_oldname: this.env.mailbox, _folder_newname: newname}, this.set_busy(true, 'foldermoving')); - this.subscription_list.draglayer.hide(); - } - } - - this.drag_active = false; - this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder)); - }; - - // tell server to create and subscribe a new mailbox - this.create_folder = function() - { - this.show_folder('', this.env.mailbox); - }; - - // delete a specific mailbox with all its messages - this.delete_folder = function(name) - { - var id = this.get_folder_row_id(name ? name : this.env.mailbox), - folder = this.env.subscriptionrows[id][0]; - - if (folder && confirm(this.get_label('deletefolderconfirm'))) { - var lock = this.set_busy(true, 'folderdeleting'); - this.http_post('delete-folder', {_mbox: folder}, lock); - } - }; - - // Add folder row to the table and initialize it - this.add_folder_row = function (name, display_name, is_protected, subscribed, skip_init, class_name) - { - if (!this.gui_objects.subscriptionlist) - return false; - - var row, n, i, tmp, tmp_name, folders, rowid, list = [], slist = [], - tbody = this.gui_objects.subscriptionlist.tBodies[0], - refrow = $('tr', tbody).get(1), - id = 'rcmrow'+((new Date).getTime()); - - if (!refrow) { - // Refresh page if we don't have a table row to clone - this.goto_url('folders'); - return false; - } - - // clone a table row if there are existing rows - row = $(refrow).clone(true); - - // set ID, reset css class - row.attr('id', id); - row.attr('class', class_name); - - // set folder name - row.find('td:first').html(display_name); - - // update subscription checkbox - $('input[name="_subscribed[]"]', row).val(name) - .prop({checked: subscribed ? true : false, disabled: is_protected ? true : false}); - - // add to folder/row-ID map - this.env.subscriptionrows[id] = [name, display_name, 0]; - - // sort folders, to find a place where to insert the row - folders = []; - $.each(this.env.subscriptionrows, function(k,v){ folders.push(v) }); - folders.sort(function(a,b){ return a[0] < b[0] ? -1 : (a[0] > b[0] ? 1 : 0) }); - - for (n in folders) { - // protected folder - if (folders[n][2]) { - tmp_name = folders[n][0] + this.env.delimiter; - // prefix namespace cannot have subfolders (#1488349) - if (tmp_name == this.env.prefix_ns) - continue; - slist.push(folders[n][0]); - tmp = tmp_name; - } - // protected folder's child - else if (tmp && folders[n][0].startsWith(tmp)) - slist.push(folders[n][0]); - // other - else { - list.push(folders[n][0]); - tmp = null; - } - } - - // check if subfolder of a protected folder - for (n=0; n<slist.length; n++) { - if (name.startsWith(slist[n] + this.env.delimiter)) - rowid = this.get_folder_row_id(slist[n]); - } - - // find folder position after sorting - for (n=0; !rowid && n<list.length; n++) { - if (n && list[n] == name) - rowid = this.get_folder_row_id(list[n-1]); - } - - // add row to the table - if (rowid) - $('#'+rowid).after(row); - else - row.appendTo(tbody); - - // update list widget - this.subscription_list.clear_selection(); - if (!skip_init) - this.init_subscription_list(); - - row = row.get(0); - if (row.scrollIntoView) - row.scrollIntoView(); - - return row; - }; - - // replace an existing table row with a new folder line (with subfolders) - this.replace_folder_row = function(oldfolder, newfolder, display_name, is_protected, class_name) - { - if (!this.gui_objects.subscriptionlist) - return false; - - var i, n, len, name, dispname, oldrow, tmprow, row, level, - tbody = this.gui_objects.subscriptionlist.tBodies[0], - folders = this.env.subscriptionrows, - id = this.get_folder_row_id(oldfolder), - prefix_len = oldfolder.length, - subscribed = $('input[name="_subscribed[]"]', $('#'+id)).prop('checked'), - // find subfolders of renamed folder - list = this.get_subfolders(oldfolder); - - // replace an existing table row - this._remove_folder_row(id); - row = $(this.add_folder_row(newfolder, display_name, is_protected, subscribed, true, class_name)); - - // detect tree depth change - if (len = list.length) { - level = (oldfolder.split(this.env.delimiter)).length - (newfolder.split(this.env.delimiter)).length; - } - - // move subfolders to the new branch - for (n=0; n<len; n++) { - id = list[n]; - name = this.env.subscriptionrows[id][0]; - dispname = this.env.subscriptionrows[id][1]; - oldrow = $('#'+id); - tmprow = oldrow.clone(true); - oldrow.remove(); - row.after(tmprow); - row = tmprow; - // update folder index - name = newfolder + name.slice(prefix_len); - $('input[name="_subscribed[]"]', row).val(name); - this.env.subscriptionrows[id][0] = name; - // update the name if level is changed - if (level != 0) { - if (level > 0) { - for (i=level; i>0; i--) - dispname = dispname.replace(/^ /, ''); - } - else { - for (i=level; i<0; i++) - dispname = ' ' + dispname; - } - row.find('td:first').html(dispname); - this.env.subscriptionrows[id][1] = dispname; - } - } - - // update list widget - this.init_subscription_list(); - }; - - // remove the table row of a specific mailbox from the table - this.remove_folder_row = function(folder, subs) - { - var n, len, list = [], id = this.get_folder_row_id(folder); - - // get subfolders if any - if (subs) - list = this.get_subfolders(folder); - - // remove old row - this._remove_folder_row(id); - - // remove subfolders - for (n=0, len=list.length; n<len; n++) - this._remove_folder_row(list[n]); - }; - - this._remove_folder_row = function(id) - { - this.subscription_list.remove_row(id.replace(/^rcmrow/, '')); - $('#'+id).remove(); - delete this.env.subscriptionrows[id]; - } - - this.get_subfolders = function(folder) - { - var name, list = [], - prefix = folder + this.env.delimiter, - row = $('#'+this.get_folder_row_id(folder)).get(0); - - while (row = row.nextSibling) { - if (row.id) { - name = this.env.subscriptionrows[row.id][0]; - if (name && name.startsWith(prefix)) { - list.push(row.id); - } - else - break; - } - } - - return list; - } - - this.subscribe = function(folder) - { - if (folder) { - var lock = this.display_message(this.get_label('foldersubscribing'), 'loading'); - this.http_post('subscribe', {_mbox: folder}, lock); - } - }; - - this.unsubscribe = function(folder) - { - if (folder) { - var lock = this.display_message(this.get_label('folderunsubscribing'), 'loading'); - this.http_post('unsubscribe', {_mbox: folder}, lock); - } - }; - - // helper method to find a specific mailbox row ID - this.get_folder_row_id = function(folder) - { - var id, folders = this.env.subscriptionrows; - for (id in folders) - if (folders[id] && folders[id][0] == folder) - break; - - return id; - }; - - // when user select a folder in manager - this.show_folder = function(folder, path, force) - { - var win, target = window, - url = '&_action=edit-folder&_mbox='+urlencode(folder); - - if (path) - url += '&_path='+urlencode(path); - - if (win = this.get_frame_window(this.env.contentframe)) { - target = win; - url += '&_framed=1'; - } - - if (String(target.location.href).indexOf(url) >= 0 && !force) - this.show_contentframe(true); - else - this.location_href(this.env.comm_path+url, target, true); - }; - - // disables subscription checkbox (for protected folder) - this.disable_subscription = function(folder) - { - var id = this.get_folder_row_id(folder); - if (id) - $('input[name="_subscribed[]"]', $('#'+id)).prop('disabled', true); - }; - - this.folder_size = function(folder) - { - var lock = this.set_busy(true, 'loading'); - this.http_post('folder-size', {_mbox: folder}, lock); - }; - - this.folder_size_update = function(size) - { - $('#folder-size').replaceWith(size); - }; - - - /*********************************************************/ - /********* GUI functionality *********/ - /*********************************************************/ - - var init_button = function(cmd, prop) - { - var elm = document.getElementById(prop.id); - if (!elm) - return; - - var preload = false; - if (prop.type == 'image') { - elm = elm.parentNode; - preload = true; - } - - elm._command = cmd; - elm._id = prop.id; - if (prop.sel) { - elm.onmousedown = function(e){ return rcmail.button_sel(this._command, this._id); }; - elm.onmouseup = function(e){ return rcmail.button_out(this._command, this._id); }; - if (preload) - new Image().src = prop.sel; - } - if (prop.over) { - elm.onmouseover = function(e){ return rcmail.button_over(this._command, this._id); }; - elm.onmouseout = function(e){ return rcmail.button_out(this._command, this._id); }; - if (preload) - new Image().src = prop.over; - } - }; - - // set event handlers on registered buttons - this.init_buttons = function() - { - for (var cmd in this.buttons) { - if (typeof cmd !== 'string') - continue; - - for (var i=0; i<this.buttons[cmd].length; i++) { - init_button(cmd, this.buttons[cmd][i]); - } - } - - // set active task button - this.set_button(this.task, 'sel'); - }; - - // set button to a specific state - this.set_button = function(command, state) - { - var n, button, obj, a_buttons = this.buttons[command], - len = a_buttons ? a_buttons.length : 0; - - for (n=0; n<len; n++) { - button = a_buttons[n]; - obj = document.getElementById(button.id); - - if (!obj) - continue; - - // get default/passive setting of the button - if (button.type == 'image' && !button.status) { - button.pas = obj._original_src ? obj._original_src : obj.src; - // respect PNG fix on IE browsers - if (obj.runtimeStyle && obj.runtimeStyle.filter && obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/)) - button.pas = RegExp.$1; - } - else if (!button.status) - button.pas = String(obj.className); - - // set image according to button state - if (button.type == 'image' && button[state]) { - button.status = state; - obj.src = button[state]; - } - // set class name according to button state - else if (button[state] !== undefined) { - button.status = state; - obj.className = button[state]; - } - // disable/enable input buttons - if (button.type == 'input') { - button.status = state; - obj.disabled = !state; - } - } - }; - - // display a specific alttext - this.set_alttext = function(command, label) - { - var n, button, obj, link, a_buttons = this.buttons[command], - len = a_buttons ? a_buttons.length : 0; - - for (n=0; n<len; n++) { - button = a_buttons[n]; - obj = document.getElementById(button.id); - - if (button.type == 'image' && obj) { - obj.setAttribute('alt', this.get_label(label)); - if ((link = obj.parentNode) && link.tagName.toLowerCase() == 'a') - link.setAttribute('title', this.get_label(label)); - } - else if (obj) - obj.setAttribute('title', this.get_label(label)); - } - }; - - // mouse over button - this.button_over = function(command, id) - { - this.button_event(command, id, 'over'); - }; - - // mouse down on button - this.button_sel = function(command, id) - { - this.button_event(command, id, 'sel'); - }; - - // mouse out of button - this.button_out = function(command, id) - { - this.button_event(command, id, 'act'); - }; - - // event of button - this.button_event = function(command, id, event) - { - var n, button, obj, a_buttons = this.buttons[command], - len = a_buttons ? a_buttons.length : 0; - - for (n=0; n<len; n++) { - button = a_buttons[n]; - if (button.id == id && button.status == 'act') { - if (button[event] && (obj = document.getElementById(button.id))) { - obj[button.type == 'image' ? 'src' : 'className'] = button[event]; - } - - if (event == 'sel') { - this.buttons_sel[id] = command; - } - } - } - }; - - // write to the document/window title - this.set_pagetitle = function(title) - { - if (title && document.title) - document.title = title; - }; - - // display a system message, list of types in common.css (below #message definition) - this.display_message = function(msg, type, timeout) - { - // pass command to parent window - if (this.is_framed()) - return parent.rcmail.display_message(msg, type, timeout); - - if (!this.gui_objects.message) { - // save message in order to display after page loaded - if (type != 'loading') - this.pending_message = [msg, type, timeout]; - return 1; - } - - type = type ? type : 'notice'; - - var ref = this, - key = this.html_identifier(msg), - date = new Date(), - id = type + date.getTime(); - - if (!timeout) - timeout = this.message_time * (type == 'error' || type == 'warning' ? 2 : 1); - - if (type == 'loading') { - key = 'loading'; - timeout = this.env.request_timeout * 1000; - if (!msg) - msg = this.get_label('loading'); - } - - // The same message is already displayed - if (this.messages[key]) { - // replace label - if (this.messages[key].obj) - this.messages[key].obj.html(msg); - // store label in stack - if (type == 'loading') { - this.messages[key].labels.push({'id': id, 'msg': msg}); - } - // add element and set timeout - this.messages[key].elements.push(id); - setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); - return id; - } - - // create DOM object and display it - var obj = $('<div>').addClass(type).html(msg).data('key', key), - cont = $(this.gui_objects.message).append(obj).show(); - - this.messages[key] = {'obj': obj, 'elements': [id]}; - - if (type == 'loading') { - this.messages[key].labels = [{'id': id, 'msg': msg}]; - } - else { - obj.click(function() { return ref.hide_message(obj); }); - } - - this.triggerEvent('message', { message:msg, type:type, timeout:timeout, object:obj }); - - if (timeout > 0) - setTimeout(function() { ref.hide_message(id, type == 'loading'); }, timeout); - return id; - }; - - // make a message to disapear - this.hide_message = function(obj, fade) - { - // pass command to parent window - if (this.is_framed()) - return parent.rcmail.hide_message(obj, fade); - - if (!this.gui_objects.message) - return; - - var k, n, i, o, m = this.messages; - - // Hide message by object, don't use for 'loading'! - if (typeof obj === 'object') { - o = $(obj); - k = o.data('key'); - this.hide_message_object(o, fade); - if (m[k]) - delete m[k]; - } - // Hide message by id - else { - for (k in m) { - for (n in m[k].elements) { - if (m[k] && m[k].elements[n] == obj) { - m[k].elements.splice(n, 1); - // hide DOM element if last instance is removed - if (!m[k].elements.length) { - this.hide_message_object(m[k].obj, fade); - delete m[k]; - } - // set pending action label for 'loading' message - else if (k == 'loading') { - for (i in m[k].labels) { - if (m[k].labels[i].id == obj) { - delete m[k].labels[i]; - } - else { - o = m[k].labels[i].msg; - m[k].obj.html(o); - } - } - } - } - } - } - } - }; - - // hide message object and remove from the DOM - this.hide_message_object = function(o, fade) - { - if (fade) - o.fadeOut(600, function() {$(this).remove(); }); - else - o.hide().remove(); - }; - - // remove all messages immediately - this.clear_messages = function() - { - // pass command to parent window - if (this.is_framed()) - return parent.rcmail.clear_messages(); - - var k, n, m = this.messages; - - for (k in m) - for (n in m[k].elements) - if (m[k].obj) - this.hide_message_object(m[k].obj); - - this.messages = {}; - }; - - // open a jquery UI dialog with the given content - this.show_popup_dialog = function(html, title, buttons, options) - { - // forward call to parent window - if (this.is_framed()) { - return parent.rcmail.show_popup_dialog(html, title, buttons); - } - - var popup = $('<div class="popup">') - .html(html) - .dialog($.extend({ - title: title, - buttons: buttons, - modal: true, - resizable: true, - width: 500, - close: function(event, ui) { $(this).remove() } - }, options || {})); - - // resize and center popup - var win = $(window), w = win.width(), h = win.height(), - width = popup.width(), height = popup.height(); - - popup.dialog('option', { - height: Math.min(h - 40, height + 75 + (buttons ? 50 : 0)), - width: Math.min(w - 20, width + 20) - }); - - return popup; - }; - - // enable/disable buttons for page shifting - this.set_page_buttons = function() - { - this.enable_command('nextpage', 'lastpage', this.env.pagecount > this.env.current_page); - this.enable_command('previouspage', 'firstpage', this.env.current_page > 1); - }; - - // mark a mailbox as selected and set environment variable - this.select_folder = function(name, prefix, encode) - { - if (this.treelist) { - this.treelist.select(name); - } - else if (this.gui_objects.folderlist) { - $('li.selected', this.gui_objects.folderlist) - .removeClass('selected').addClass('unfocused'); - $(this.get_folder_li(name, prefix, encode)) - .removeClass('unfocused').addClass('selected'); - - // trigger event hook - this.triggerEvent('selectfolder', { folder:name, prefix:prefix }); - } - }; - - // adds a class to selected folder - this.mark_folder = function(name, class_name, prefix, encode) - { - $(this.get_folder_li(name, prefix, encode)).addClass(class_name); - }; - - // adds a class to selected folder - this.unmark_folder = function(name, class_name, prefix, encode) - { - $(this.get_folder_li(name, prefix, encode)).removeClass(class_name); - }; - - // helper method to find a folder list item - this.get_folder_li = function(name, prefix, encode) - { - if (!prefix) - prefix = 'rcmli'; - - if (this.gui_objects.folderlist) { - name = this.html_identifier(name, encode); - return document.getElementById(prefix+name); - } - }; - - // for reordering column array (Konqueror workaround) - // and for setting some message list global variables - this.set_message_coltypes = function(coltypes, repl, smart_col) - { - var list = this.message_list, - thead = list ? list.thead : null, - cell, col, n, len, th, tr; - - this.env.coltypes = coltypes; - - // replace old column headers - if (thead) { - if (repl) { - th = document.createElement('thead'); - tr = document.createElement('tr'); - - for (c=0, len=repl.length; c < len; c++) { - cell = document.createElement('td'); - cell.innerHTML = repl[c].html || ''; - if (repl[c].id) cell.id = repl[c].id; - if (repl[c].className) cell.className = repl[c].className; - tr.appendChild(cell); - } - th.appendChild(tr); - thead.parentNode.replaceChild(th, thead); - list.thead = thead = th; - } - - for (n=0, len=this.env.coltypes.length; n<len; n++) { - col = this.env.coltypes[n]; - if ((cell = thead.rows[0].cells[n]) && (col == 'from' || col == 'to' || col == 'fromto')) { - cell.id = 'rcm'+col; - $('span,a', cell).text(this.get_label(col == 'fromto' ? smart_col : col)); - // if we have links for sorting, it's a bit more complicated... - $('a', cell).click(function(){ - return rcmail.command('sort', this.id.replace(/^rcm/, ''), this); - }); - } - } - } - - this.env.subject_col = null; - this.env.flagged_col = null; - this.env.status_col = null; - - if ((n = $.inArray('subject', this.env.coltypes)) >= 0) { - this.env.subject_col = n; - if (list) - list.subject_col = n; - } - if ((n = $.inArray('flag', this.env.coltypes)) >= 0) - this.env.flagged_col = n; - if ((n = $.inArray('status', this.env.coltypes)) >= 0) - this.env.status_col = n; - - if (list) - list.init_header(); - }; - - // replace content of row count display - this.set_rowcount = function(text, mbox) - { - // #1487752 - if (mbox && mbox != this.env.mailbox) - return false; - - $(this.gui_objects.countdisplay).html(text); - - // update page navigation buttons - this.set_page_buttons(); - }; - - // replace content of mailboxname display - this.set_mailboxname = function(content) - { - if (this.gui_objects.mailboxname && content) - this.gui_objects.mailboxname.innerHTML = content; - }; - - // replace content of quota display - this.set_quota = function(content) - { - if (this.gui_objects.quotadisplay && content && content.type == 'text') - $(this.gui_objects.quotadisplay).html(content.percent+'%').attr('title', content.title); - - this.triggerEvent('setquota', content); - this.env.quota_content = content; - }; - - // update the mailboxlist - this.set_unread_count = function(mbox, count, set_title, mark) - { - if (!this.gui_objects.mailboxlist) - return false; - - this.env.unread_counts[mbox] = count; - this.set_unread_count_display(mbox, set_title); - - if (mark) - this.mark_folder(mbox, mark, '', true); - else if (!count) - this.unmark_folder(mbox, 'recent', '', true); - }; - - // update the mailbox count display - this.set_unread_count_display = function(mbox, set_title) - { - var reg, link, text_obj, item, mycount, childcount, div; - - if (item = this.get_folder_li(mbox, '', true)) { - mycount = this.env.unread_counts[mbox] ? this.env.unread_counts[mbox] : 0; - link = $(item).children('a').eq(0); - text_obj = link.children('span.unreadcount'); - if (!text_obj.length && mycount) - text_obj = $('<span>').addClass('unreadcount').appendTo(link); - reg = /\s+\([0-9]+\)$/i; - - childcount = 0; - if ((div = item.getElementsByTagName('div')[0]) && - div.className.match(/collapsed/)) { - // add children's counters - for (var k in this.env.unread_counts) - if (k.startsWith(mbox + this.env.delimiter)) - childcount += this.env.unread_counts[k]; - } - - if (mycount && text_obj.length) - text_obj.html(this.env.unreadwrap.replace(/%[sd]/, mycount)); - else if (text_obj.length) - text_obj.remove(); - - // set parent's display - reg = new RegExp(RegExp.escape(this.env.delimiter) + '[^' + RegExp.escape(this.env.delimiter) + ']+$'); - if (mbox.match(reg)) - this.set_unread_count_display(mbox.replace(reg, ''), false); - - // set the right classes - if ((mycount+childcount)>0) - $(item).addClass('unread'); - else - $(item).removeClass('unread'); - } - - // set unread count to window title - reg = /^\([0-9]+\)\s+/i; - if (set_title && document.title) { - var new_title = '', - doc_title = String(document.title); - - if (mycount && doc_title.match(reg)) - new_title = doc_title.replace(reg, '('+mycount+') '); - else if (mycount) - new_title = '('+mycount+') '+doc_title; - else - new_title = doc_title.replace(reg, ''); - - this.set_pagetitle(new_title); - } - }; - - // display fetched raw headers - this.set_headers = function(content) - { - if (this.gui_objects.all_headers_row && this.gui_objects.all_headers_box && content) - $(this.gui_objects.all_headers_box).html(content).show(); - }; - - // display all-headers row and fetch raw message headers - this.show_headers = function(props, elem) - { - if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box || !this.env.uid) - return; - - $(elem).removeClass('show-headers').addClass('hide-headers'); - $(this.gui_objects.all_headers_row).show(); - elem.onclick = function() { rcmail.command('hide-headers', '', elem); }; - - // fetch headers only once - if (!this.gui_objects.all_headers_box.innerHTML) { - var lock = this.display_message(this.get_label('loading'), 'loading'); - this.http_post('headers', {_uid: this.env.uid}, lock); - } - }; - - // hide all-headers row - this.hide_headers = function(props, elem) - { - if (!this.gui_objects.all_headers_row || !this.gui_objects.all_headers_box) - return; - - $(elem).removeClass('hide-headers').addClass('show-headers'); - $(this.gui_objects.all_headers_row).hide(); - elem.onclick = function() { rcmail.command('show-headers', '', elem); }; - }; - - - /********************************************************/ - /********* html to text conversion functions *********/ - /********************************************************/ - - this.html2plain = function(htmlText, id) - { - var rcmail = this, - url = '?_task=utils&_action=html2text', - lock = this.set_busy(true, 'converting'); - - this.log('HTTP POST: ' + url); - - $.ajax({ type: 'POST', url: url, data: htmlText, contentType: 'application/octet-stream', - error: function(o, status, err) { rcmail.http_error(o, status, err, lock); }, - success: function(data) { rcmail.set_busy(false, null, lock); $('#'+id).val(data); rcmail.log(data); } - }); - }; - - this.plain2html = function(plain, id) - { - var lock = this.set_busy(true, 'converting'); - - plain = plain.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>'); - $('#'+id).val(plain ? '<pre>'+plain+'</pre>' : ''); - - this.set_busy(false, null, lock); - }; - - - /********************************************************/ - /********* remote request methods *********/ - /********************************************************/ - - // compose a valid url with the given parameters - this.url = function(action, query) - { - var querystring = typeof query === 'string' ? '&' + query : ''; - - if (typeof action !== 'string') - query = action; - else if (!query || typeof query !== 'object') - query = {}; - - if (action) - query._action = action; - else - query._action = this.env.action; - - var base = this.env.comm_path, k, param = {}; - - // overwrite task name - if (query._action.match(/([a-z0-9_-]+)\/([a-z0-9-_.]+)/)) { - query._action = RegExp.$2; - base = base.replace(/\_task=[a-z0-9_-]+/, '_task='+RegExp.$1); - } - - // remove undefined values - for (k in query) { - if (query[k] !== undefined && query[k] !== null) - param[k] = query[k]; - } - - return base + '&' + $.param(param) + querystring; - }; - - this.redirect = function(url, lock) - { - if (lock || lock === null) - this.set_busy(true); - - if (this.is_framed()) { - parent.rcmail.redirect(url, lock); - } - else { - if (this.env.extwin) { - if (typeof url == 'string') - url += (url.indexOf('?') < 0 ? '?' : '&') + '_extwin=1'; - else - url._extwin = 1; - } - this.location_href(url, window); - } - }; - - this.goto_url = function(action, query, lock) - { - this.redirect(this.url(action, query)); - }; - - this.location_href = function(url, target, frame) - { - if (frame) - this.lock_frame(); - - if (typeof url == 'object') - url = this.env.comm_path + '&' + $.param(url); - - // simulate real link click to force IE to send referer header - if (bw.ie && target == window) - $('<a>').attr('href', url).appendTo(document.body).get(0).click(); - else - target.location.href = url; - - // reset keep-alive interval - this.start_keepalive(); - }; - - // send a http request to the server - this.http_request = function(action, query, lock) - { - var url = this.url(action, query); - - // trigger plugin hook - var result = this.triggerEvent('request'+action, query); - - if (result !== undefined) { - // abort if one the handlers returned false - if (result === false) - return false; - else - url = this.url(action, result); - } - - url += '&_remote=1'; - - // send request - this.log('HTTP GET: ' + url); - - // reset keep-alive interval - this.start_keepalive(); - - return $.ajax({ - type: 'GET', url: url, data: { _unlock:(lock?lock:0) }, dataType: 'json', - success: function(data){ ref.http_response(data); }, - error: function(o, status, err) { ref.http_error(o, status, err, lock, action); } - }); - }; - - // send a http POST request to the server - this.http_post = function(action, postdata, lock) - { - var url = this.url(action); - - if (postdata && typeof postdata === 'object') { - postdata._remote = 1; - postdata._unlock = (lock ? lock : 0); - } - else - postdata += (postdata ? '&' : '') + '_remote=1' + (lock ? '&_unlock='+lock : ''); - - // trigger plugin hook - var result = this.triggerEvent('request'+action, postdata); - if (result !== undefined) { - // abort if one of the handlers returned false - if (result === false) - return false; - else - postdata = result; - } - - // send request - this.log('HTTP POST: ' + url); - - // reset keep-alive interval - this.start_keepalive(); - - return $.ajax({ - type: 'POST', url: url, data: postdata, dataType: 'json', - success: function(data){ ref.http_response(data); }, - error: function(o, status, err) { ref.http_error(o, status, err, lock, action); } - }); - }; - - // aborts ajax request - this.abort_request = function(r) - { - if (r.request) - r.request.abort(); - if (r.lock) - this.set_busy(false, null, r.lock); - }; - - // handle HTTP response - this.http_response = function(response) - { - if (!response) - return; - - if (response.unlock) - this.set_busy(false); - - this.triggerEvent('responsebefore', {response: response}); - this.triggerEvent('responsebefore'+response.action, {response: response}); - - // set env vars - if (response.env) - this.set_env(response.env); - - // we have labels to add - if (typeof response.texts === 'object') { - for (var name in response.texts) - if (typeof response.texts[name] === 'string') - this.add_label(name, response.texts[name]); - } - - // if we get javascript code from server -> execute it - if (response.exec) { - this.log(response.exec); - eval(response.exec); - } - - // execute callback functions of plugins - if (response.callbacks && response.callbacks.length) { - for (var i=0; i < response.callbacks.length; i++) - this.triggerEvent(response.callbacks[i][0], response.callbacks[i][1]); - } - - // process the response data according to the sent action - switch (response.action) { - case 'delete': - if (this.task == 'addressbook') { - var sid, uid = this.contact_list.get_selection(), writable = false; - - if (uid && this.contact_list.rows[uid]) { - // search results, get source ID from record ID - if (this.env.source == '') { - sid = String(uid).replace(/^[^-]+-/, ''); - writable = sid && this.env.address_sources[sid] && !this.env.address_sources[sid].readonly; - } - else { - writable = !this.env.address_sources[this.env.source].readonly; - } - } - this.enable_command('compose', (uid && this.contact_list.rows[uid])); - this.enable_command('delete', 'edit', writable); - this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0)); - this.enable_command('export-selected', false); - } - - case 'move': - if (this.env.action == 'show') { - // re-enable commands on move/delete error - this.enable_command(this.env.message_commands, true); - if (!this.env.list_post) - this.enable_command('reply-list', false); - } - else if (this.task == 'addressbook') { - this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount }); - } - - case 'purge': - case 'expunge': - if (this.task == 'mail') { - if (!this.env.exists) { - // clear preview pane content - if (this.env.contentframe) - this.show_contentframe(false); - // disable commands useless when mailbox is empty - this.enable_command(this.env.message_commands, 'purge', 'expunge', - 'select-all', 'select-none', 'expand-all', 'expand-unread', 'collapse-all', false); - } - if (this.message_list) - this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount }); - } - break; - - case 'refresh': - case 'check-recent': - case 'getunread': - case 'search': - this.env.qsearch = null; - case 'list': - if (this.task == 'mail') { - this.enable_command('show', 'select-all', 'select-none', this.env.messagecount > 0); - this.enable_command('expunge', this.env.exists); - this.enable_command('purge', this.purge_mailbox_test()); - this.enable_command('expand-all', 'expand-unread', 'collapse-all', this.env.threading && this.env.messagecount); - - if ((response.action == 'list' || response.action == 'search') && this.message_list) { - this.msglist_select(this.message_list); - this.message_list.resize(); - this.triggerEvent('listupdate', { folder:this.env.mailbox, rowcount:this.message_list.rowcount }); - } - } - else if (this.task == 'addressbook') { - this.enable_command('export', (this.contact_list && this.contact_list.rowcount > 0)); - - if (response.action == 'list' || response.action == 'search') { - this.enable_command('search-create', this.env.source == ''); - this.enable_command('search-delete', this.env.search_id); - this.update_group_commands(); - this.contact_list.resize(); - this.triggerEvent('listupdate', { folder:this.env.source, rowcount:this.contact_list.rowcount }); - } - } - break; - } - - if (response.unlock) - this.hide_message(response.unlock); - - this.triggerEvent('responseafter', {response: response}); - this.triggerEvent('responseafter'+response.action, {response: response}); - - // reset keep-alive interval - this.start_keepalive(); - }; - - // handle HTTP request errors - this.http_error = function(request, status, err, lock, action) - { - var errmsg = request.statusText; - - this.set_busy(false, null, lock); - request.abort(); - - // don't display error message on page unload (#1488547) - if (this.unload) - return; - - if (request.status && errmsg) - this.display_message(this.get_label('servererror') + ' (' + errmsg + ')', 'error'); - else if (status == 'timeout') - this.display_message(this.get_label('requesttimedout'), 'error'); - else if (request.status == 0 && status != 'abort') - this.display_message(this.get_label('servererror') + ' (No connection)', 'error'); - - // redirect to url specified in location header if not empty - var location_url = request.getResponseHeader("Location"); - if (location_url && this.env.action != 'compose') // don't redirect on compose screen, contents might get lost (#1488926) - this.redirect(location_url); - - // 403 Forbidden response (CSRF prevention) - reload the page. - // In case there's a new valid session it will be used, otherwise - // login form will be presented (#1488960). - if (request.status == 403) { - (this.is_framed() ? parent : window).location.reload(); - return; - } - - // re-send keep-alive requests after 30 seconds - if (action == 'keep-alive') - setTimeout(function(){ ref.keep_alive(); ref.start_keepalive(); }, 30000); - }; - - // callback when an iframe finished loading - this.iframe_loaded = function(unlock) - { - this.set_busy(false, null, unlock); - - if (this.submit_timer) - clearTimeout(this.submit_timer); - }; - - // post the given form to a hidden iframe - this.async_upload_form = function(form, action, onload) - { - var frame, ts = new Date().getTime(), - frame_name = 'rcmupload'+ts; - - // upload progress support - if (this.env.upload_progress_name) { - var fname = this.env.upload_progress_name, - field = $('input[name='+fname+']', form); - - if (!field.length) { - field = $('<input>').attr({type: 'hidden', name: fname}); - field.prependTo(form); - } - - field.val(ts); - } - - // have to do it this way for IE - // otherwise the form will be posted to a new window - if (document.all) { - document.body.insertAdjacentHTML('BeforeEnd', '<iframe name="'+frame_name+'"' - + ' src="program/resources/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>'); - frame = $('iframe[name="'+frame_name+'"]'); - } - // for standards-compliant browsers - else { - frame = $('<iframe>').attr('name', frame_name) - .css({border: 'none', width: 0, height: 0, visibility: 'hidden'}) - .appendTo(document.body); - } - - // handle upload errors, parsing iframe content in onload - frame.bind('load', {ts:ts}, onload); - - $(form).attr({ - target: frame_name, - action: this.url(action, { _id:this.env.compose_id||'', _uploadid:ts }), - method: 'POST'}) - .attr(form.encoding ? 'encoding' : 'enctype', 'multipart/form-data') - .submit(); - - return frame_name; - }; - - // html5 file-drop API - this.document_drag_hover = function(e, over) - { - e.preventDefault(); - $(ref.gui_objects.filedrop)[(over?'addClass':'removeClass')]('active'); - }; - - this.file_drag_hover = function(e, over) - { - e.preventDefault(); - e.stopPropagation(); - $(ref.gui_objects.filedrop)[(over?'addClass':'removeClass')]('hover'); - }; - - // handler when files are dropped to a designated area. - // compose a multipart form data and submit it to the server - this.file_dropped = function(e) - { - // abort event and reset UI - this.file_drag_hover(e, false); - - // prepare multipart form data composition - var files = e.target.files || e.dataTransfer.files, - formdata = window.FormData ? new FormData() : null, - fieldname = (this.env.filedrop.fieldname || '_file') + (this.env.filedrop.single ? '' : '[]'), - boundary = '------multipartformboundary' + (new Date).getTime(), - dashdash = '--', crlf = '\r\n', - multipart = dashdash + boundary + crlf; - - if (!files || !files.length) - return; - - // inline function to submit the files to the server - var submit_data = function() { - var multiple = files.length > 1, - ts = new Date().getTime(), - content = '<span>' + (multiple ? ref.get_label('uploadingmany') : files[0].name) + '</span>'; - - // add to attachments list - if (!ref.add2attachment_list(ts, { name:'', html:content, classname:'uploading', complete:false })) - ref.file_upload_id = ref.set_busy(true, 'uploading'); - - // complete multipart content and post request - multipart += dashdash + boundary + dashdash + crlf; - - $.ajax({ - type: 'POST', - dataType: 'json', - url: ref.url(ref.env.filedrop.action||'upload', { _id:ref.env.compose_id||ref.env.cid||'', _uploadid:ts, _remote:1 }), - contentType: formdata ? false : 'multipart/form-data; boundary=' + boundary, - processData: false, - timeout: 0, // disable default timeout set in ajaxSetup() - data: formdata || multipart, - headers: {'X-Roundcube-Request': ref.env.request_token}, - xhr: function() { var xhr = jQuery.ajaxSettings.xhr(); if (!formdata && xhr.sendAsBinary) xhr.send = xhr.sendAsBinary; return xhr; }, - success: function(data){ ref.http_response(data); }, - error: function(o, status, err) { ref.http_error(o, status, err, null, 'attachment'); } - }); - }; - - // get contents of all dropped files - var last = this.env.filedrop.single ? 0 : files.length - 1; - for (var j=0, i=0, f; j <= last && (f = files[i]); i++) { - if (!f.name) f.name = f.fileName; - if (!f.size) f.size = f.fileSize; - if (!f.type) f.type = 'application/octet-stream'; - - // file name contains non-ASCII characters, do UTF8-binary string conversion. - if (!formdata && /[^\x20-\x7E]/.test(f.name)) - f.name_bin = unescape(encodeURIComponent(f.name)); - - // filter by file type if requested - if (this.env.filedrop.filter && !f.type.match(new RegExp(this.env.filedrop.filter))) { - // TODO: show message to user - continue; - } - - // do it the easy way with FormData (FF 4+, Chrome 5+, Safari 5+) - if (formdata) { - formdata.append(fieldname, f); - if (j == last) - return submit_data(); - } - // use FileReader supporetd by Firefox 3.6 - else if (window.FileReader) { - var reader = new FileReader(); - - // closure to pass file properties to async callback function - reader.onload = (function(file, j) { - return function(e) { - multipart += 'Content-Disposition: form-data; name="' + fieldname + '"'; - multipart += '; filename="' + (f.name_bin || file.name) + '"' + crlf; - multipart += 'Content-Length: ' + file.size + crlf; - multipart += 'Content-Type: ' + file.type + crlf + crlf; - multipart += reader.result + crlf; - multipart += dashdash + boundary + crlf; - - if (j == last) // we're done, submit the data - return submit_data(); - } - })(f,j); - reader.readAsBinaryString(f); - } - // Firefox 3 - else if (f.getAsBinary) { - multipart += 'Content-Disposition: form-data; name="' + fieldname + '"'; - multipart += '; filename="' + (f.name_bin || f.name) + '"' + crlf; - multipart += 'Content-Length: ' + f.size + crlf; - multipart += 'Content-Type: ' + f.type + crlf + crlf; - multipart += f.getAsBinary() + crlf; - multipart += dashdash + boundary +crlf; - - if (j == last) - return submit_data(); - } - - j++; - } - }; - - // starts interval for keep-alive signal - this.start_keepalive = function() - { - if (!this.env.session_lifetime || this.env.framed || this.env.extwin || this.task == 'login' || this.env.action == 'print') - return; - - if (this._keepalive) - clearInterval(this._keepalive); - - this._keepalive = setInterval(function(){ ref.keep_alive(); }, this.env.session_lifetime * 0.5 * 1000); - }; - - // starts interval for refresh signal - this.start_refresh = function() - { - if (!this.env.refresh_interval || this.env.framed || this.env.extwin || this.task == 'login' || this.env.action == 'print') - return; - - if (this._refresh) - clearInterval(this._refresh); - - this._refresh = setInterval(function(){ ref.refresh(); }, this.env.refresh_interval * 1000); - }; - - // sends keep-alive signal - this.keep_alive = function() - { - if (!this.busy) - this.http_request('keep-alive'); - }; - - // sends refresh signal - this.refresh = function() - { - if (this.busy) { - // try again after 10 seconds - setTimeout(function(){ ref.refresh(); ref.start_refresh(); }, 10000); - return; - } - - var params = {}, lock = this.set_busy(true, 'refreshing'); - - if (this.task == 'mail' && this.gui_objects.mailboxlist) - params = this.check_recent_params(); - - params._last = Math.floor(this.env.lastrefresh.getTime() / 1000); - this.env.lastrefresh = new Date(); - - // plugins should bind to 'requestrefresh' event to add own params - this.http_request('refresh', params, lock); - }; - - // returns check-recent request parameters - this.check_recent_params = function() - { - var params = {_mbox: this.env.mailbox}; - - if (this.gui_objects.mailboxlist) - params._folderlist = 1; - if (this.gui_objects.messagelist) - params._list = 1; - if (this.gui_objects.quotadisplay) - params._quota = 1; - if (this.env.search_request) - params._search = this.env.search_request; - - return params; - }; - - - /********************************************************/ - /********* helper methods *********/ - /********************************************************/ - - /** - * Quote html entities - */ - this.quote_html = function(str) - { - return String(str).replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); - }; - - // get window.opener.rcmail if available - this.opener = function() - { - // catch Error: Permission denied to access property rcmail - try { - if (window.opener && !opener.closed && opener.rcmail) - return opener.rcmail; - } - catch (e) {} - }; - - // check if we're in show mode or if we have a unique selection - // and return the message uid - this.get_single_uid = function() - { - return this.env.uid ? this.env.uid : (this.message_list ? this.message_list.get_single_selection() : null); - }; - - // same as above but for contacts - this.get_single_cid = function() - { - return this.env.cid ? this.env.cid : (this.contact_list ? this.contact_list.get_single_selection() : null); - }; - - // gets cursor position - this.get_caret_pos = function(obj) - { - if (obj.selectionEnd !== undefined) - return obj.selectionEnd; - - if (document.selection && document.selection.createRange) { - var range = document.selection.createRange(); - if (range.parentElement() != obj) - return 0; - - var gm = range.duplicate(); - if (obj.tagName == 'TEXTAREA') - gm.moveToElementText(obj); - else - gm.expand('textedit'); - - gm.setEndPoint('EndToStart', range); - var p = gm.text.length; - - return p <= obj.value.length ? p : -1; - } - - return obj.value.length; - }; - - // moves cursor to specified position - this.set_caret_pos = function(obj, pos) - { - if (obj.setSelectionRange) - obj.setSelectionRange(pos, pos); - else if (obj.createTextRange) { - var range = obj.createTextRange(); - range.collapse(true); - range.moveEnd('character', pos); - range.moveStart('character', pos); - range.select(); - } - }; - - // get selected text from an input field - // http://stackoverflow.com/questions/7186586/how-to-get-the-selected-text-in-textarea-using-jquery-in-internet-explorer-7 - this.get_input_selection = function(obj) - { - var start = 0, end = 0, - normalizedValue, range, - textInputRange, len, endRange; - - if (typeof obj.selectionStart == "number" && typeof obj.selectionEnd == "number") { - normalizedValue = obj.value; - start = obj.selectionStart; - end = obj.selectionEnd; - } - else { - range = document.selection.createRange(); - - if (range && range.parentElement() == obj) { - len = obj.value.length; - normalizedValue = obj.value; //.replace(/\r\n/g, "\n"); - - // create a working TextRange that lives only in the input - textInputRange = obj.createTextRange(); - textInputRange.moveToBookmark(range.getBookmark()); - - // Check if the start and end of the selection are at the very end - // of the input, since moveStart/moveEnd doesn't return what we want - // in those cases - endRange = obj.createTextRange(); - endRange.collapse(false); - - if (textInputRange.compareEndPoints("StartToEnd", endRange) > -1) { - start = end = len; - } - else { - start = -textInputRange.moveStart("character", -len); - start += normalizedValue.slice(0, start).split("\n").length - 1; - - if (textInputRange.compareEndPoints("EndToEnd", endRange) > -1) { - end = len; - } - else { - end = -textInputRange.moveEnd("character", -len); - end += normalizedValue.slice(0, end).split("\n").length - 1; - } - } - } - } - - return { start:start, end:end, text:normalizedValue.substr(start, end-start) }; - }; - - // disable/enable all fields of a form - this.lock_form = function(form, lock) - { - if (!form || !form.elements) - return; - - var n, len, elm; - - if (lock) - this.disabled_form_elements = []; - - for (n=0, len=form.elements.length; n<len; n++) { - elm = form.elements[n]; - - if (elm.type == 'hidden') - continue; - // remember which elem was disabled before lock - if (lock && elm.disabled) - this.disabled_form_elements.push(elm); - // check this.disabled_form_elements before inArray() as a workaround for FF5 bug - // http://bugs.jquery.com/ticket/9873 - else if (lock || (this.disabled_form_elements && $.inArray(elm, this.disabled_form_elements)<0)) - elm.disabled = lock; - } - }; - - this.mailto_handler_uri = function() - { - return location.href.split('?')[0] + '?_task=mail&_action=compose&_to=%s'; - }; - - this.register_protocol_handler = function(name) - { - try { - window.navigator.registerProtocolHandler('mailto', this.mailto_handler_uri(), name); - } - catch(e) {}; - }; - - this.check_protocol_handler = function(name, elem) - { - var nav = window.navigator; - if (!nav - || (typeof nav.registerProtocolHandler != 'function') - || ((typeof nav.isProtocolHandlerRegistered == 'function') - && nav.isProtocolHandlerRegistered('mailto', this.mailto_handler_uri()) == 'registered') - ) - $(elem).addClass('disabled'); - else - $(elem).click(function() { rcmail.register_protocol_handler(name); return false; }); - }; - - // Checks browser capabilities eg. PDF support, TIF support - this.browser_capabilities_check = function() - { - if (!this.env.browser_capabilities) - this.env.browser_capabilities = {}; - - if (this.env.browser_capabilities.pdf === undefined) - this.env.browser_capabilities.pdf = this.pdf_support_check(); - - if (this.env.browser_capabilities.flash === undefined) - this.env.browser_capabilities.flash = this.flash_support_check(); - - if (this.env.browser_capabilities.tif === undefined) - this.tif_support_check(); - }; - - // Returns browser capabilities string - this.browser_capabilities = function() - { - if (!this.env.browser_capabilities) - return ''; - - var n, ret = []; - - for (n in this.env.browser_capabilities) - ret.push(n + '=' + this.env.browser_capabilities[n]); - - return ret.join(); - }; - - this.tif_support_check = function() - { - var img = new Image(); - - img.onload = function() { rcmail.env.browser_capabilities.tif = 1; }; - img.onerror = function() { rcmail.env.browser_capabilities.tif = 0; }; - img.src = 'program/resources/blank.tif'; - }; - - this.pdf_support_check = function() - { - var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/pdf"] : {}, - plugins = navigator.plugins, - len = plugins.length, - regex = /Adobe Reader|PDF|Acrobat/i; - - if (plugin && plugin.enabledPlugin) - return 1; - - if (window.ActiveXObject) { - try { - if (axObj = new ActiveXObject("AcroPDF.PDF")) - return 1; - } - catch (e) {} - try { - if (axObj = new ActiveXObject("PDF.PdfCtrl")) - return 1; - } - catch (e) {} - } - - for (i=0; i<len; i++) { - plugin = plugins[i]; - if (typeof plugin === 'String') { - if (regex.test(plugin)) - return 1; - } - else if (plugin.name && regex.test(plugin.name)) - return 1; - } - - return 0; - }; - - this.flash_support_check = function() - { - var plugin = navigator.mimeTypes ? navigator.mimeTypes["application/x-shockwave-flash"] : {}; - - if (plugin && plugin.enabledPlugin) - return 1; - - if (window.ActiveXObject) { - try { - if (axObj = new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) - return 1; - } - catch (e) {} - } - - return 0; - }; - - // Cookie setter - this.set_cookie = function(name, value, expires) - { - setCookie(name, value, expires, this.env.cookie_path, this.env.cookie_domain, this.env.cookie_secure); - } - -} // end object rcube_webmail - - -// some static methods -rcube_webmail.long_subject_title = function(elem, indent) -{ - if (!elem.title) { - var $elem = $(elem); - if ($elem.width() + indent * 15 > $elem.parent().width()) - elem.title = $elem.text(); - } -}; - -rcube_webmail.long_subject_title_ex = function(elem, indent) -{ - if (!elem.title) { - var $elem = $(elem), - txt = $.trim($elem.text()), - tmp = $('<span>').text(txt) - .css({'position': 'absolute', 'float': 'left', 'visibility': 'hidden', - 'font-size': $elem.css('font-size'), 'font-weight': $elem.css('font-weight')}) - .appendTo($('body')), - w = tmp.width(); - - tmp.remove(); - if (w + indent * 15 > $elem.width()) - elem.title = txt; - } -}; - -rcube_webmail.prototype.get_cookie = getCookie; - -// copy event engine prototype -rcube_webmail.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; -rcube_webmail.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; -rcube_webmail.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; +function rcube_webmail(){this.labels={};this.buttons={};this.buttons_sel={};this.gui_objects={};this.gui_containers={};this.commands={};this.command_handlers={};this.onloads=[];this.messages={};this.group2expand={};this.dblclick_time=500;this.message_time=4000;this.identifier_expr=new RegExp("[^0-9a-z-_]","gi");this.env={request_timeout:180,draft_autosave:0,comm_path:"./",blankpage:"program/resources/blank.gif",recipients_separator:",",recipients_delimiter:", "};this.ref="rcmail";var ref=this;$.ajaxSetup({cache:false,timeout:this.env.request_timeout*1000,error:function(request,status,err){ref.http_error(request,status,err)},beforeSend:function(xmlhttp){xmlhttp.setRequestHeader("X-Roundcube-Request",ref.env.request_token)}});$(window).bind("beforeunload",function(){rcmail.unload=true});this.set_env=function(p,value){if(p!=null&&typeof p==="object"&&!value){for(var n in p){this.env[n]=p[n]}}else{this.env[p]=value}};this.add_label=function(p,value){if(typeof p=="string"){this.labels[p]=value}else{if(typeof p=="object"){$.extend(this.labels,p)}}};this.register_button=function(command,id,type,act,sel,over){var button_prop={id:id,type:type};if(act){button_prop.act=act}if(sel){button_prop.sel=sel}if(over){button_prop.over=over}if(!this.buttons[command]){this.buttons[command]=[]}this.buttons[command].push(button_prop);if(this.loaded){init_button(command,button_prop)}};this.gui_object=function(name,id){this.gui_objects[name]=this.loaded?rcube_find_object(id):id};this.gui_container=function(name,id){this.gui_containers[name]=id};this.add_element=function(elm,container){if(this.gui_containers[container]&&this.gui_containers[container].jquery){this.gui_containers[container].append(elm)}};this.register_command=function(command,callback,enable){this.command_handlers[command]=callback;if(enable){this.enable_command(command,true)}};this.add_onload=function(f){this.onloads.push(f)};this.init=function(){var n,p=this;this.task=this.env.task;if(!bw.dom||!bw.xmlhttp_test()||(bw.mz&&bw.vendver<1.9)){this.goto_url("error","_code=0x199");return}for(n in this.gui_containers){this.gui_containers[n]=$("#"+this.gui_containers[n])}for(n in this.gui_objects){this.gui_objects[n]=rcube_find_object(this.gui_objects[n])}if(this.env.x_frame_options){try{if(this.env.x_frame_options=="deny"&&top.location.href!=self.location.href){top.location.href=self.location.href}else{if(top.location.hostname!=self.location.hostname){throw 1}}}catch(e){$("form").each(function(){ref.lock_form(this,true)});this.display_message("Blocked: possible clickjacking attack!","error");return}}this.init_buttons();if(this.is_framed()){parent.rcmail.set_busy(false,null,parent.rcmail.env.frame_lock);parent.rcmail.env.frame_lock=null}this.enable_command("close","logout","mail","addressbook","settings","save-pref","compose","undo","about","switch-task",true);if(this.env.permaurl){this.enable_command("permaurl","extwin",true)}switch(this.task){case"mail":this.enable_command("list","checkmail","add-contact","search","reset-search","collapse-folder",true);if(this.gui_objects.messagelist){this.message_list=new rcube_list_widget(this.gui_objects.messagelist,{multiselect:true,multiexpand:true,draggable:true,keyboard:true,column_movable:this.env.col_movable,dblclick_time:this.dblclick_time});this.message_list.row_init=function(o){p.init_message_row(o)};this.message_list.addEventListener("dblclick",function(o){p.msglist_dbl_click(o)});this.message_list.addEventListener("click",function(o){p.msglist_click(o)});this.message_list.addEventListener("keypress",function(o){p.msglist_keypress(o)});this.message_list.addEventListener("select",function(o){p.msglist_select(o)});this.message_list.addEventListener("dragstart",function(o){p.drag_start(o)});this.message_list.addEventListener("dragmove",function(e){p.drag_move(e)});this.message_list.addEventListener("dragend",function(e){p.drag_end(e)});this.message_list.addEventListener("expandcollapse",function(e){p.msglist_expand(e)});this.message_list.addEventListener("column_replace",function(e){p.msglist_set_coltypes(e)});document.onmouseup=function(e){return p.doc_mouse_up(e)};this.gui_objects.messagelist.parentNode.onmousedown=function(e){return p.click_on_list(e)};this.message_list.init();this.enable_command("toggle_status","toggle_flag","menu-open","menu-save","sort",true);this.command("list")}if(this.gui_objects.qsearchbox){if(this.env.search_text!=null){this.gui_objects.qsearchbox.value=this.env.search_text}$(this.gui_objects.qsearchbox).focusin(function(){rcmail.message_list&&rcmail.message_list.blur()})}this.set_button_titles();this.env.message_commands=["show","reply","reply-all","reply-list","moveto","copy","delete","open","mark","edit","viewsource","print","load-attachment","show-headers","hide-headers","download","forward","forward-inline","forward-attachment"];if(this.env.action=="show"||this.env.action=="preview"){this.enable_command(this.env.message_commands,this.env.uid);this.enable_command("reply-list",this.env.list_post);if(this.env.action=="show"){this.http_request("pagenav",{_uid:this.env.uid,_mbox:this.env.mailbox,_search:this.env.search_request},this.display_message("","loading"))}if(this.env.blockedobjects){if(this.gui_objects.remoteobjectsmsg){this.gui_objects.remoteobjectsmsg.style.display="block"}this.enable_command("load-images","always-load",true)}if(this.env.action=="preview"&&this.is_framed()){this.enable_command("compose","add-contact",false);parent.rcmail.show_contentframe(true)}}else{if(this.env.action=="compose"){this.env.compose_commands=["send-attachment","remove-attachment","send","cancel","toggle-editor","list-adresses","search","reset-search","extwin"];if(this.env.drafts_mailbox){this.env.compose_commands.push("savedraft")}this.enable_command(this.env.compose_commands,"identities",true);$.merge(this.env.compose_commands,["add-recipient","firstpage","previouspage","nextpage","lastpage"]);if(this.env.spellcheck){this.env.spellcheck.spelling_state_observer=function(s){ref.spellcheck_state()};this.env.compose_commands.push("spellcheck");this.enable_command("spellcheck",true)}document.onmouseup=function(e){return p.doc_mouse_up(e)};this.init_messageform()}else{if(this.env.action=="print"&&this.env.uid){if(bw.safari){setTimeout("window.print()",10)}else{window.print()}}}}if(this.gui_objects.mailboxlist){this.env.unread_counts={};this.gui_objects.folderlist=this.gui_objects.mailboxlist;this.http_request("getunread")}if(this.gui_objects.contactslist){this.contact_list=new rcube_list_widget(this.gui_objects.contactslist,{multiselect:true,draggable:false,keyboard:false});this.contact_list.addEventListener("select",function(o){ref.compose_recipient_select(o)});this.contact_list.addEventListener("dblclick",function(o){ref.compose_add_recipient("to")});this.contact_list.init()}if(this.gui_objects.addressbookslist){this.gui_objects.folderlist=this.gui_objects.addressbookslist;this.enable_command("list-adresses",true)}if(this.env.mdn_request&&this.env.uid){var postact="sendmdn",postdata={_uid:this.env.uid,_mbox:this.env.mailbox};if(!confirm(this.get_label("mdnrequest"))){postdata._flag="mdnsent";postact="mark"}this.http_post(postact,postdata)}if(!this.is_framed()&&!this.env.extwin){this.browser_capabilities_check()}break;case"addressbook":if(this.gui_objects.folderlist){this.env.contactfolders=$.extend($.extend({},this.env.address_sources),this.env.contactgroups)}this.enable_command("add","import",this.env.writable_source);this.enable_command("list","listgroup","listsearch","advanced-search",true);if(this.gui_objects.contactslist){this.contact_list=new rcube_list_widget(this.gui_objects.contactslist,{multiselect:true,draggable:this.gui_objects.folderlist?true:false,keyboard:true});this.contact_list.row_init=function(row){p.triggerEvent("insertrow",{cid:row.uid,row:row})};this.contact_list.addEventListener("keypress",function(o){p.contactlist_keypress(o)});this.contact_list.addEventListener("select",function(o){p.contactlist_select(o)});this.contact_list.addEventListener("dragstart",function(o){p.drag_start(o)});this.contact_list.addEventListener("dragmove",function(e){p.drag_move(e)});this.contact_list.addEventListener("dragend",function(e){p.drag_end(e)});this.contact_list.init();if(this.env.cid){this.contact_list.highlight_row(this.env.cid)}this.gui_objects.contactslist.parentNode.onmousedown=function(e){return p.click_on_list(e)};document.onmouseup=function(e){return p.doc_mouse_up(e)};if(this.gui_objects.qsearchbox){$(this.gui_objects.qsearchbox).focusin(function(){rcmail.contact_list.blur()})}this.update_group_commands();this.command("list")}this.set_page_buttons();if(this.env.cid){this.enable_command("show","edit",true);if(this.gui_objects.editform){$("input.groupmember").change(function(){ref.group_member_change(this.checked?"add":"del",ref.env.cid,ref.env.source,this.value)})}}if(this.gui_objects.editform){this.enable_command("save",true);if(this.env.action=="add"||this.env.action=="edit"||this.env.action=="search"){this.init_contact_form()}}if(this.gui_objects.qsearchbox){this.enable_command("search","reset-search","moveto",true)}break;case"settings":this.enable_command("preferences","identities","save","folders",true);if(this.env.action=="identities"){this.enable_command("add",this.env.identities_level<2)}else{if(this.env.action=="edit-identity"||this.env.action=="add-identity"){this.enable_command("save","edit","toggle-editor",true);this.enable_command("delete",this.env.identities_level<2);if(this.env.action=="add-identity"){$("input[type='text']").first().select()}}else{if(this.env.action=="folders"){this.enable_command("subscribe","unsubscribe","create-folder","rename-folder",true)}else{if(this.env.action=="edit-folder"&&this.gui_objects.editform){this.enable_command("save","folder-size",true);parent.rcmail.env.exists=this.env.messagecount;parent.rcmail.enable_command("purge",this.env.messagecount);$("input[type='text']").first().select()}}}}if(this.gui_objects.identitieslist){this.identity_list=new rcube_list_widget(this.gui_objects.identitieslist,{multiselect:false,draggable:false,keyboard:false});this.identity_list.addEventListener("select",function(o){p.identity_select(o)});this.identity_list.init();this.identity_list.focus();if(this.env.iid){this.identity_list.highlight_row(this.env.iid)}}else{if(this.gui_objects.sectionslist){this.sections_list=new rcube_list_widget(this.gui_objects.sectionslist,{multiselect:false,draggable:false,keyboard:false});this.sections_list.addEventListener("select",function(o){p.section_select(o)});this.sections_list.init();this.sections_list.focus()}else{if(this.gui_objects.subscriptionlist){this.init_subscription_list()}}}break;case"login":var input_user=$("#rcmloginuser");input_user.bind("keyup",function(e){return rcmail.login_user_keyup(e)});if(input_user.val()==""){input_user.focus()}else{$("#rcmloginpwd").focus()}if(window.jstz&&!bw.ie6){var timezone=jstz.determine();if(timezone.name()){$("#rcmlogintz").val(timezone.name())}}else{$("#rcmlogintz").val(new Date().getStdTimezoneOffset()/-60)}$("form").submit(function(){$("input[type=submit]",this).prop("disabled",true);rcmail.clear_messages();rcmail.display_message("","loading")});this.enable_command("login",true);break}if(this.env.contentframe&&!$("#"+this.env.contentframe).is(":visible")){this.env.contentframe=null}if(bw.ie){$("input[type=file]").keydown(function(e){if(e.keyCode=="13"){e.preventDefault()}})}this.loaded=true;if(this.pending_message){this.display_message(this.pending_message[0],this.pending_message[1],this.pending_message[2])}if(this.gui_objects.folderlist){this.gui_containers.foldertray=$(this.gui_objects.folderlist)}if(this.gui_objects.filedrop&&this.env.filedrop&&((window.XMLHttpRequest&&XMLHttpRequest.prototype&&XMLHttpRequest.prototype.sendAsBinary)||window.FormData)){$(document.body).bind("dragover dragleave drop",function(e){return ref.document_drag_hover(e,e.type=="dragover")});$(this.gui_objects.filedrop).addClass("droptarget").bind("dragover dragleave",function(e){return ref.file_drag_hover(e,e.type=="dragover")}).get(0).addEventListener("drop",function(e){return ref.file_dropped(e)},false)}this.triggerEvent("init",{task:this.task,action:this.env.action});for(var i in this.onloads){if(typeof this.onloads[i]==="string"){eval(this.onloads[i])}else{if(typeof this.onloads[i]==="function"){this.onloads[i]()}}}this.start_refresh();this.start_keepalive()};this.log=function(msg){if(window.console&&console.log){console.log(msg)}};this.command=function(command,props,obj,event){var ret,uid,cid,url,flag;if(obj&&obj.blur){obj.blur()}if(this.busy){return false}if((obj&&obj.href&&String(obj.href).indexOf("#")<0)&&rcube_event.get_modifier(event)){return true}if(!this.commands[command]){if(this.is_framed()){parent.rcmail.command(command,props)}return false}if(this.task=="mail"&&this.env.action=="compose"&&$.inArray(command,this.env.compose_commands)<0){if(this.cmp_hash!=this.compose_field_hash()&&!confirm(this.get_label("notsentwarning"))){return false}}if(typeof this.command_handlers[command]==="function"){ret=this.command_handlers[command](props,obj);return ret!==undefined?ret:(obj?false:true)}else{if(typeof this.command_handlers[command]==="string"){ret=window[this.command_handlers[command]](props,obj);return ret!==undefined?ret:(obj?false:true)}}this.triggerEvent("actionbefore",{props:props,action:command});ret=this.triggerEvent("before"+command,props);if(ret!==undefined){if(ret===false){return false}else{props=ret}}ret=undefined;switch(command){case"login":if(this.gui_objects.loginform){this.gui_objects.loginform.submit()}break;case"mail":case"addressbook":case"settings":case"logout":this.switch_task(command);break;case"about":this.redirect("?_task=settings&_action=about",false);break;case"permaurl":if(obj&&obj.href&&obj.target){return true}else{if(this.env.permaurl){parent.location.href=this.env.permaurl}}break;case"extwin":if(this.env.action=="compose"){var prevstate=this.env.compose_extwin;$("input[name='_action']",this.gui_objects.messageform).val("compose");this.gui_objects.messageform.action=this.url("mail/compose",{_id:this.env.compose_id,_extwin:1});this.gui_objects.messageform.target=this.open_window("",1100);this.gui_objects.messageform.submit()}else{this.open_window(this.env.permaurl,900)}break;case"menu-open":case"menu-save":this.triggerEvent(command,{props:props});return false;case"open":if(uid=this.get_single_uid()){obj.href=this.url("show",{_mbox:this.env.mailbox,_uid:uid});return true}break;case"close":if(this.env.extwin){window.close()}break;case"list":if(props&&props!=""){this.reset_qsearch()}if(this.env.action=="compose"&&this.env.extwin){window.close()}else{if(this.task=="mail"){this.list_mailbox(props);this.set_button_titles()}else{if(this.task=="addressbook"){this.list_contacts(props)}}}break;case"sort":var sort_order=this.env.sort_order,sort_col=!this.env.disabled_sort_col?props:this.env.sort_col;if(!this.env.disabled_sort_order){sort_order=this.env.sort_col==sort_col&&sort_order=="ASC"?"DESC":"ASC"}this.set_list_sorting(sort_col,sort_order);this.list_mailbox("","",sort_col+"_"+sort_order);break;case"nextpage":this.list_page("next");break;case"lastpage":this.list_page("last");break;case"previouspage":this.list_page("prev");break;case"firstpage":this.list_page("first");break;case"expunge":if(this.env.exists){this.expunge_mailbox(this.env.mailbox)}break;case"purge":case"empty-mailbox":if(this.env.exists){this.purge_mailbox(this.env.mailbox)}break;case"show":if(this.task=="mail"){uid=this.get_single_uid();if(uid&&(!this.env.uid||uid!=this.env.uid)){if(this.env.mailbox==this.env.drafts_mailbox){this.open_compose_step({_draft_uid:uid,_mbox:this.env.mailbox})}else{this.show_message(uid)}}}else{if(this.task=="addressbook"){cid=props?props:this.get_single_cid();if(cid&&!(this.env.action=="show"&&cid==this.env.cid)){this.load_contact(cid,"show")}}}break;case"add":if(this.task=="addressbook"){this.load_contact(0,"add")}else{if(this.task=="settings"){this.identity_list.clear_selection();this.load_identity(0,"add-identity")}}break;case"edit":if(this.task=="addressbook"&&(cid=this.get_single_cid())){this.load_contact(cid,"edit")}else{if(this.task=="settings"&&props){this.load_identity(props,"edit-identity")}else{if(this.task=="mail"&&(cid=this.get_single_uid())){url={_mbox:this.env.mailbox};url[this.env.mailbox==this.env.drafts_mailbox&&props!="new"?"_draft_uid":"_uid"]=cid;this.open_compose_step(url)}}}break;case"save":var input,form=this.gui_objects.editform;if(form){if(this.env.action=="search"){}else{if((input=$("input[name='_pagesize']",form))&&input.length&&isNaN(parseInt(input.val()))){alert(this.get_label("nopagesizewarning"));input.focus();break}else{if(props=="reload"){form.action+="?_reload=1"}else{if(this.task=="settings"&&(this.env.identities_level%2)==0&&(input=$("input[name='_email']",form))&&input.length&&!rcube_check_email(input.val())){alert(this.get_label("noemailwarning"));input.focus();break}}$("input.placeholder").each(function(){if(this.value==this._placeholder){this.value=""}})}}if(parent.rcmail&&parent.rcmail.env.source){form.action=this.add_url(form.action,"_orig_source",parent.rcmail.env.source)}form.submit()}break;case"delete":if(this.task=="mail"){this.delete_messages(event)}else{if(this.task=="addressbook"){this.delete_contacts()}else{if(this.task=="settings"){this.delete_identity()}}}break;case"move":case"moveto":if(this.task=="mail"){this.move_messages(props)}else{if(this.task=="addressbook"&&this.drag_active){this.copy_contact(null,props)}}break;case"copy":if(this.task=="mail"){this.copy_messages(props)}break;case"mark":if(props){this.mark_message(props)}break;case"toggle_status":if(props&&!props._row){break}flag="read";if(props._row.uid){uid=props._row.uid;if(this.message_list.rows[uid].deleted){flag="undelete"}else{if(!this.message_list.rows[uid].unread){flag="unread"}}}this.mark_message(flag,uid);break;case"toggle_flag":if(props&&!props._row){break}flag="flagged";if(props._row.uid){uid=props._row.uid;if(this.message_list.rows[uid].flagged){flag="unflagged"}}this.mark_message(flag,uid);break;case"always-load":if(this.env.uid&&this.env.sender){this.add_contact(this.env.sender);setTimeout(function(){ref.command("load-images")},300);break}case"load-images":if(this.env.uid){this.show_message(this.env.uid,true,this.env.action=="preview")}break;case"load-attachment":var qstring="_mbox="+urlencode(this.env.mailbox)+"&_uid="+this.env.uid+"&_part="+props.part;if(this.env.uid&&props.mimetype&&this.env.mimetypes&&$.inArray(props.mimetype,this.env.mimetypes)>=0){var attachment_win=window.open(this.env.comm_path+"&_action=get&"+qstring+"&_frame=1",this.html_identifier("rcubemailattachment"+this.env.uid+props.part));if(attachment_win){setTimeout(function(){attachment_win.focus()},10);break}}this.goto_url("get",qstring+"&_download=1",false);break;case"select-all":this.select_all_mode=props?false:true;this.dummy_select=true;if(props=="invert"){this.message_list.invert_selection()}else{this.message_list.select_all(props=="page"?"":props)}this.dummy_select=null;break;case"select-none":this.select_all_mode=false;this.message_list.clear_selection();break;case"expand-all":this.env.autoexpand_threads=1;this.message_list.expand_all();break;case"expand-unread":this.env.autoexpand_threads=2;this.message_list.collapse_all();this.expand_unread();break;case"collapse-all":this.env.autoexpand_threads=0;this.message_list.collapse_all();break;case"nextmessage":if(this.env.next_uid){this.show_message(this.env.next_uid,false,this.env.action=="preview")}break;case"lastmessage":if(this.env.last_uid){this.show_message(this.env.last_uid)}break;case"previousmessage":if(this.env.prev_uid){this.show_message(this.env.prev_uid,false,this.env.action=="preview")}break;case"firstmessage":if(this.env.first_uid){this.show_message(this.env.first_uid)}break;case"compose":url={};if(this.task=="mail"){url._mbox=this.env.mailbox;if(props){url._to=props}if(this.env.search_request){url._search=this.env.search_request}}else{if(this.task=="addressbook"){if(props&&props.indexOf("@")>0){url._to=props}else{var n,len,a_cids=[];if(props){a_cids.push(props)}else{if(this.contact_list){var selection=this.contact_list.get_selection();for(n=0,len=selection.length;n<len;n++){a_cids.push(selection[n])}}}if(a_cids.length){this.http_post("mailto",{_cid:a_cids.join(","),_source:this.env.source},true)}else{if(this.env.group){this.http_post("mailto",{_gid:this.env.group,_source:this.env.source},true)}}break}}else{if(props){url._to=props}}}this.open_compose_step(url);break;case"spellcheck":if(this.spellcheck_state()){this.stop_spellchecking()}else{if(window.tinyMCE&&tinyMCE.get(this.env.composebody)){tinyMCE.execCommand("mceSpellCheck",true)}else{if(this.env.spellcheck&&this.env.spellcheck.spellCheck){this.env.spellcheck.spellCheck()}}}this.spellcheck_state();break;case"savedraft":clearTimeout(this.save_timer);if(this.env.draft_id&&this.cmp_hash==this.compose_field_hash()){this.auto_save_start();break}this.submit_messageform(true);break;case"send":if(!props.nocheck&&!this.check_compose_input(command)){break}clearTimeout(this.save_timer);this.submit_messageform();break;case"send-attachment":clearTimeout(this.save_timer);this.upload_file(props||this.gui_objects.uploadform);break;case"insert-sig":this.change_identity($("[name='_from']")[0],true);break;case"list-adresses":this.list_contacts(props);this.enable_command("add-recipient",false);break;case"add-recipient":this.compose_add_recipient(props);break;case"reply-all":case"reply-list":case"reply":if(uid=this.get_single_uid()){url={_reply_uid:uid,_mbox:this.env.mailbox};if(command=="reply-all"){url._all=(!props&&this.commands["reply-list"]?"list":"all")}else{if(command=="reply-list"){url._all="list"}}this.open_compose_step(url)}break;case"forward-attachment":case"forward-inline":case"forward":var uids=this.env.uid?[this.env.uid]:(this.message_list?this.message_list.get_selection():[]);if(uids.length){url={_forward_uid:this.uids_to_list(uids),_mbox:this.env.mailbox};if(command=="forward-attachment"||(!props&&this.env.forward_attachment)||uids.length>1){url._attachment=1}this.open_compose_step(url)}break;case"print":if(uid=this.get_single_uid()){ref.printwin=window.open(this.env.comm_path+"&_action=print&_uid="+uid+"&_mbox="+urlencode(this.env.mailbox)+(this.env.safemode?"&_safe=1":""));if(this.printwin){setTimeout(function(){ref.printwin.focus()},20);if(this.env.action!="show"){this.mark_message("read",uid)}}}break;case"viewsource":if(uid=this.get_single_uid()){ref.sourcewin=window.open(this.env.comm_path+"&_action=viewsource&_uid="+uid+"&_mbox="+urlencode(this.env.mailbox));if(this.sourcewin){setTimeout(function(){ref.sourcewin.focus()},20)}}break;case"download":if(uid=this.get_single_uid()){this.goto_url("viewsource",{_uid:uid,_mbox:this.env.mailbox,_save:1})}break;case"search":if(!props&&this.gui_objects.qsearchbox){props=this.gui_objects.qsearchbox.value}if(props){this.qsearch(props);break}case"reset-search":var n,s=this.env.search_request||this.env.qsearch;this.reset_qsearch();this.select_all_mode=false;if(s&&this.env.action=="compose"){if(this.contact_list){this.list_contacts_clear()}}else{if(s&&this.env.mailbox){this.list_mailbox(this.env.mailbox,1)}else{if(s&&this.task=="addressbook"){if(this.env.source==""){for(n in this.env.address_sources){break}this.env.source=n;this.env.group=""}this.list_contacts(this.env.source,this.env.group,1)}}}break;case"listgroup":this.reset_qsearch();this.list_contacts(props.source,props.id);break;case"import":if(this.env.action=="import"&&this.gui_objects.importform){var file=document.getElementById("rcmimportfile");if(file&&!file.value){alert(this.get_label("selectimportfile"));break}this.gui_objects.importform.submit();this.set_busy(true,"importwait");this.lock_form(this.gui_objects.importform,true)}else{this.goto_url("import",(this.env.source?"_target="+urlencode(this.env.source)+"&":""))}break;case"export":if(this.contact_list.rowcount>0){this.goto_url("export",{_source:this.env.source,_gid:this.env.group,_search:this.env.search_request})}break;case"upload-photo":this.upload_contact_photo(props||this.gui_objects.uploadform);break;case"delete-photo":this.replace_contact_photo("-del-");break;case"preferences":case"identities":case"folders":this.goto_url("settings/"+command);break;case"undo":this.http_request("undo","",this.display_message("","loading"));break;default:var func=command.replace(/-/g,"_");if(this[func]&&typeof this[func]==="function"){ret=this[func](props,obj)}break}if(this.triggerEvent("after"+command,props)===false){ret=false}this.triggerEvent("actionafter",{props:props,action:command});return ret===false?false:obj?false:true};this.enable_command=function(){var i,n,args=Array.prototype.slice.call(arguments),enable=args.pop(),cmd;for(n=0;n<args.length;n++){cmd=args[n];if(typeof cmd==="string"){this.commands[cmd]=enable;this.set_button(cmd,(enable?"act":"pas"))}else{for(i in cmd){args.push(cmd[i])}}}};this.set_busy=function(a,message,id){if(a&&message){var msg=this.get_label(message);if(msg==message){msg="Loading..."}id=this.display_message(msg,"loading")}else{if(!a&&id){this.hide_message(id)}}this.busy=a;if(this.gui_objects.editform){this.lock_form(this.gui_objects.editform,a)}return id};this.get_label=function(name,domain){if(domain&&this.labels[domain+"."+name]){return this.labels[domain+"."+name]}else{if(this.labels[name]){return this.labels[name]}else{return name}}};this.gettext=this.get_label;this.switch_task=function(task){if(this.task===task&&task!="mail"){return}var url=this.get_task_url(task);if(task=="mail"){url+="&_mbox=INBOX"}this.redirect(url)};this.get_task_url=function(task,url){if(!url){url=this.env.comm_path}return url.replace(/_task=[a-z]+/,"_task="+task)};this.reload=function(delay){if(this.is_framed()){parent.rcmail.reload(delay)}else{if(delay){setTimeout(function(){rcmail.reload()},delay)}else{if(window.location){location.href=this.env.comm_path+(this.env.action?"&_action="+this.env.action:"")}}}};this.add_url=function(url,name,value){value=urlencode(value);if(/(\?.*)$/.test(url)){var urldata=RegExp.$1,datax=RegExp("((\\?|&)"+RegExp.escape(name)+"=[^&]*)");if(datax.test(urldata)){urldata=urldata.replace(datax,RegExp.$2+name+"="+value)}else{urldata+="&"+name+"="+value}return url.replace(/(\?.*)$/,urldata)}return url+"?"+name+"="+value};this.is_framed=function(){return(this.env.framed&&parent.rcmail&&parent.rcmail!=this&&parent.rcmail.command)};this.save_pref=function(prop){var request={_name:prop.name,_value:prop.value};if(prop.session){request._session=prop.session}if(prop.env){this.env[prop.env]=prop.value}this.http_post("save-pref",request)};this.html_identifier=function(str,encode){str=String(str);if(encode){return Base64.encode(str).replace(/=+$/,"").replace(/\+/g,"-").replace(/\//g,"_")}else{return str.replace(this.identifier_expr,"_")}};this.html_identifier_decode=function(str){str=String(str).replace(/-/g,"+").replace(/_/g,"/");while(str.length%4){str+="="}return Base64.decode(str)};this.drag_menu=function(e,target){var modkey=rcube_event.get_modifier(e),menu=this.gui_objects.message_dragmenu;if(menu&&modkey==SHIFT_KEY&&this.commands.copy){var pos=rcube_event.get_mouse_pos(e);this.env.drag_target=target;$(menu).css({top:(pos.y-10)+"px",left:(pos.x-10)+"px"}).show();return true}return false};this.drag_menu_action=function(action){var menu=this.gui_objects.message_dragmenu;if(menu){$(menu).hide()}this.command(action,this.env.drag_target);this.env.drag_target=null};this.drag_start=function(list){var model=this.task=="mail"?this.env.mailboxes:this.env.contactfolders;this.drag_active=true;if(this.preview_timer){clearTimeout(this.preview_timer)}if(this.preview_read_timer){clearTimeout(this.preview_read_timer)}if(this.gui_objects.folderlist&&model){this.initialBodyScrollTop=bw.ie?0:window.pageYOffset;this.initialListScrollTop=this.gui_objects.folderlist.parentNode.scrollTop;var k,li,height,list=$(this.gui_objects.folderlist);pos=list.offset();this.env.folderlist_coords={x1:pos.left,y1:pos.top,x2:pos.left+list.width(),y2:pos.top+list.height()};this.env.folder_coords=[];for(k in model){if(li=this.get_folder_li(k)){if(height=li.firstChild.offsetHeight){pos=$(li.firstChild).offset();this.env.folder_coords[k]={x1:pos.left,y1:pos.top,x2:pos.left+li.firstChild.offsetWidth,y2:pos.top+height,on:0}}}}}};this.drag_end=function(e){this.drag_active=false;this.env.last_folder_target=null;if(this.folder_auto_timer){clearTimeout(this.folder_auto_timer);this.folder_auto_timer=null;this.folder_auto_expand=null}if(this.gui_objects.folderlist&&this.env.folder_coords){for(var k in this.env.folder_coords){if(this.env.folder_coords[k].on){$(this.get_folder_li(k)).removeClass("droptarget")}}}};this.drag_move=function(e){if(this.gui_objects.folderlist&&this.env.folder_coords){var k,li,div,check,oldclass,layerclass="draglayernormal",mouse=rcube_event.get_mouse_pos(e),pos=this.env.folderlist_coords,boffset=bw.ie?-document.documentElement.scrollTop:this.initialBodyScrollTop,moffset=this.initialListScrollTop-this.gui_objects.folderlist.parentNode.scrollTop;if(this.contact_list&&this.contact_list.draglayer){oldclass=this.contact_list.draglayer.attr("class")}mouse.y+=-moffset-boffset;if(mouse.x<pos.x1||mouse.x>=pos.x2||mouse.y<pos.y1||mouse.y>=pos.y2){if(this.env.last_folder_target){$(this.get_folder_li(this.env.last_folder_target)).removeClass("droptarget");this.env.folder_coords[this.env.last_folder_target].on=0;this.env.last_folder_target=null}if(layerclass!=oldclass&&this.contact_list&&this.contact_list.draglayer){this.contact_list.draglayer.attr("class",layerclass)}return}for(k in this.env.folder_coords){pos=this.env.folder_coords[k];if(mouse.x>=pos.x1&&mouse.x<pos.x2&&mouse.y>=pos.y1&&mouse.y<pos.y2){if(check=this.check_droptarget(k)){li=this.get_folder_li(k);div=$(li.getElementsByTagName("div")[0]);if(div.hasClass("collapsed")){if(this.folder_auto_timer){clearTimeout(this.folder_auto_timer)}this.folder_auto_expand=this.env.mailboxes[k].id;this.folder_auto_timer=setTimeout(function(){rcmail.command("collapse-folder",rcmail.folder_auto_expand);rcmail.drag_start(null)},1000)}else{if(this.folder_auto_timer){clearTimeout(this.folder_auto_timer);this.folder_auto_timer=null;this.folder_auto_expand=null}}$(li).addClass("droptarget");this.env.folder_coords[k].on=1;this.env.last_folder_target=k;layerclass="draglayer"+(check>1?"copy":"normal")}else{this.env.last_folder_target=null}}else{if(pos.on){$(this.get_folder_li(k)).removeClass("droptarget");this.env.folder_coords[k].on=0}}}if(layerclass!=oldclass&&this.contact_list&&this.contact_list.draglayer){this.contact_list.draglayer.attr("class",layerclass)}}};this.collapse_folder=function(name){var li=this.get_folder_li(name,"",true),div=$("div:first",li),ul=$("ul:first",li);if(div.hasClass("collapsed")){ul.show();div.removeClass("collapsed").addClass("expanded");var reg=new RegExp("&"+urlencode(name)+"&");this.env.collapsed_folders=this.env.collapsed_folders.replace(reg,"")}else{if(div.hasClass("expanded")){ul.hide();div.removeClass("expanded").addClass("collapsed");this.env.collapsed_folders=this.env.collapsed_folders+"&"+urlencode(name)+"&";if(this.env.mailbox.indexOf(name+this.env.delimiter)==0&&!$(li).hasClass("virtual")){this.command("list",name)}}else{return}}if(bw.ie6||bw.ie7){var siblings=li.nextSibling?li.nextSibling.getElementsByTagName("ul"):null;if(siblings&&siblings.length&&(li=siblings[0])&&li.style&&li.style.display!="none"){li.style.display="none";li.style.display=""}}this.command("save-pref",{name:"collapsed_folders",value:this.env.collapsed_folders});this.set_unread_count_display(name,false)};this.doc_mouse_up=function(e){var model,list,id;if($(rcube_event.get_target(e)).closest(".ui-dialog, .ui-widget-overlay").length){return}if(list=this.message_list){model=this.env.mailboxes}else{if(list=this.contact_list){model=this.env.contactfolders}else{if(this.ksearch_value){this.ksearch_blur()}}}if(list&&!rcube_mouse_is_over(e,list.list.parentNode)){list.blur()}if(this.drag_active&&model&&this.env.last_folder_target){var target=model[this.env.last_folder_target];$(this.get_folder_li(this.env.last_folder_target)).removeClass("droptarget");this.env.last_folder_target=null;list.draglayer.hide();if(!this.drag_menu(e,target)){this.command("moveto",target)}}if(this.buttons_sel){for(id in this.buttons_sel){if(typeof id!=="function"){this.button_out(this.buttons_sel[id],id)}}this.buttons_sel={}}};this.click_on_list=function(e){if(this.gui_objects.qsearchbox){this.gui_objects.qsearchbox.blur()}if(this.message_list){this.message_list.focus()}else{if(this.contact_list){this.contact_list.focus()}}return true};this.msglist_select=function(list){if(this.preview_timer){clearTimeout(this.preview_timer)}if(this.preview_read_timer){clearTimeout(this.preview_read_timer)}var selected=list.get_single_selection();this.enable_command(this.env.message_commands,selected!=null);if(selected){if(this.env.mailbox==this.env.drafts_mailbox){this.enable_command("reply","reply-all","reply-list","forward","forward-attachment","forward-inline",false)}else{var msg=this.env.messages[selected];if(!msg.ml){this.enable_command("reply-list",false)}}}this.enable_command("delete","moveto","copy","mark","forward","forward-attachment",list.selection.length>0);if(selected||(list.selection.length&&list.selection.length!=list.rowcount)){this.select_all_mode=false}if(selected&&this.env.contentframe&&!list.multi_selecting&&!this.dummy_select){this.preview_timer=setTimeout(function(){ref.msglist_get_preview()},this.dblclick_time)}else{if(this.env.contentframe){this.show_contentframe(false)}}};this.msglist_click=function(list){if(list.multi_selecting||!this.env.contentframe){return}if(list.get_single_selection()){return}var win=this.get_frame_window(this.env.contentframe);if(win&&win.location.href.indexOf(this.env.blankpage)>=0){if(this.preview_timer){clearTimeout(this.preview_timer)}if(this.preview_read_timer){clearTimeout(this.preview_read_timer)}this.preview_timer=setTimeout(function(){ref.msglist_get_preview()},this.dblclick_time)}};this.msglist_dbl_click=function(list){if(this.preview_timer){clearTimeout(this.preview_timer)}if(this.preview_read_timer){clearTimeout(this.preview_read_timer)}var uid=list.get_single_selection();if(uid&&this.env.mailbox==this.env.drafts_mailbox){this.open_compose_step({_draft_uid:uid,_mbox:this.env.mailbox})}else{if(uid){this.show_message(uid,false,false)}}};this.msglist_keypress=function(list){if(list.modkey==CONTROL_KEY){return}if(list.key_pressed==list.ENTER_KEY){this.command("show")}else{if(list.key_pressed==list.DELETE_KEY||list.key_pressed==list.BACKSPACE_KEY){this.command("delete")}else{if(list.key_pressed==33){this.command("previouspage")}else{if(list.key_pressed==34){this.command("nextpage")}}}}};this.msglist_get_preview=function(){var uid=this.get_single_uid();if(uid&&this.env.contentframe&&!this.drag_active){this.show_message(uid,false,true)}else{if(this.env.contentframe){this.show_contentframe(false)}}};this.msglist_expand=function(row){if(this.env.messages[row.uid]){this.env.messages[row.uid].expanded=row.expanded}$(row.obj)[row.expanded?"addClass":"removeClass"]("expanded")};this.msglist_set_coltypes=function(list){var i,found,name,cols=list.list.tHead.rows[0].cells;this.env.coltypes=[];for(i=0;i<cols.length;i++){if(cols[i].id&&cols[i].id.match(/^rcm/)){name=cols[i].id.replace(/^rcm/,"");this.env.coltypes.push(name)}}if((found=$.inArray("flag",this.env.coltypes))>=0){this.env.flagged_col=found}if((found=$.inArray("subject",this.env.coltypes))>=0){this.env.subject_col=found}this.command("save-pref",{name:"list_cols",value:this.env.coltypes,session:"list_attrib/columns"})};this.check_droptarget=function(id){if(this.task=="mail"){return(this.env.mailboxes[id]&&this.env.mailboxes[id].id!=this.env.mailbox&&!this.env.mailboxes[id].virtual)?1:0}if(this.task=="settings"){return id!=this.env.mailbox?1:0}if(this.task=="addressbook"){if(id!=this.env.source&&this.env.contactfolders[id]){if(this.env.contactfolders[id].type=="group"){var target_abook=this.env.contactfolders[id].source;if(this.env.contactfolders[id].id!=this.env.group&&!this.env.contactfolders[target_abook].readonly){return(this.env.selection_sources.length>1||$.inArray(target_abook,this.env.selection_sources)==-1)?2:1}}else{if(!this.env.contactfolders[id].readonly){return(this.env.selection_sources.length>1||$.inArray(id,this.env.selection_sources)==-1)?2:0}}}}return 0};this.open_window=function(url,width){var win=this.is_framed()?parent.window:window,page=$(win),page_width=page.width(),page_height=bw.mz?$("body",win).height():page.height(),w=Math.min(width,page_width),h=page_height,l=(win.screenLeft||win.screenX)+20,t=(win.screenTop||win.screenY)+20,wname="rcmextwin"+new Date().getTime(),extwin=window.open(url+(url.match(/\?/)?"&":"?")+"_extwin=1",wname,"width="+w+",height="+h+",top="+t+",left="+l+",resizable=yes,toolbar=no,status=no,location=no");if(!url&&extwin.document){extwin.document.write("<html><body>"+this.get_label("loading")+"</body></html>")}window.setTimeout(function(){extwin.focus()},10);return wname};this.init_message_row=function(row){var expando,self=this,uid=row.uid,status_icon=(this.env.status_col!=null?"status":"msg")+"icn"+row.uid;if(uid&&this.env.messages[uid]){$.extend(row,this.env.messages[uid])}if(row.icon=document.getElementById(status_icon)){row.icon._row=row.obj;row.icon.onmousedown=function(e){self.command("toggle_status",this);rcube_event.cancel(e)}}if(this.env.status_col!=null){row.msgicon=document.getElementById("msgicn"+row.uid)}else{row.msgicon=row.icon}if(this.env.flagged_col!=null&&(row.flagicon=document.getElementById("flagicn"+row.uid))){row.flagicon._row=row.obj;row.flagicon.onmousedown=function(e){self.command("toggle_flag",this);rcube_event.cancel(e)}}if(!row.depth&&row.has_children&&(expando=document.getElementById("rcmexpando"+row.uid))){row.expando=expando;expando.onmousedown=function(e){return self.expand_message_row(e,uid)};if(bw.touch){expando.addEventListener("touchend",function(e){if(e.changedTouches.length==1){self.expand_message_row(e,uid);return rcube_event.cancel(e)}},false)}}this.triggerEvent("insertrow",{uid:uid,row:row})};this.add_message_row=function(uid,cols,flags,attop){if(!this.gui_objects.messagelist||!this.message_list){return false}if(flags.mbox!=this.env.mailbox&&!flags.skip_mbox_check){return false}if(!this.env.messages[uid]){this.env.messages[uid]={}}$.extend(this.env.messages[uid],{deleted:flags.deleted?1:0,replied:flags.answered?1:0,unread:!flags.seen?1:0,forwarded:flags.forwarded?1:0,flagged:flags.flagged?1:0,has_children:flags.has_children?1:0,depth:flags.depth?flags.depth:0,unread_children:flags.unread_children?flags.unread_children:0,parent_uid:flags.parent_uid?flags.parent_uid:0,selected:this.select_all_mode||this.message_list.in_selection(uid),ml:flags.ml?1:0,ctype:flags.ctype,flags:flags.extra_flags});var c,n,col,html,css_class,tree="",expando="",list=this.message_list,rows=list.rows,message=this.env.messages[uid],row_class="message"+(!flags.seen?" unread":"")+(flags.deleted?" deleted":"")+(flags.flagged?" flagged":"")+(message.selected?" selected":""),row=document.createElement("tr");row.id="rcmrow"+uid;css_class="msgicon";if(this.env.status_col===null){css_class+=" status";if(flags.deleted){css_class+=" deleted"}else{if(!flags.seen){css_class+=" unread"}else{if(flags.unread_children>0){css_class+=" unreadchildren"}}}}if(flags.answered){css_class+=" replied"}if(flags.forwarded){css_class+=" forwarded"}if(message.selected&&!list.in_selection(uid)){list.selection.push(uid)}if(this.env.threading){if(message.depth){tree+='<span id="rcmtab'+uid+'" class="branch" style="width:'+(message.depth*15)+'px;"> </span>';if((rows[message.parent_uid]&&rows[message.parent_uid].expanded===false)||((this.env.autoexpand_threads==0||this.env.autoexpand_threads==2)&&(!rows[message.parent_uid]||!rows[message.parent_uid].expanded))){row.style.display="none";message.expanded=false}else{message.expanded=true}row_class+=" thread expanded"}else{if(message.has_children){if(message.expanded===undefined&&(this.env.autoexpand_threads==1||(this.env.autoexpand_threads==2&&message.unread_children))){message.expanded=true}expando='<div id="rcmexpando'+uid+'" class="'+(message.expanded?"expanded":"collapsed")+'"> </div>';row_class+=" thread"+(message.expanded?" expanded":"")}}if(flags.unread_children&&flags.seen&&!message.expanded){row_class+=" unroot"}}tree+='<span id="msgicn'+uid+'" class="'+css_class+'"> </span>';row.className=row_class;if(!bw.ie&&cols.subject){var action=flags.mbox==this.env.drafts_mailbox?"compose":"show";var uid_param=flags.mbox==this.env.drafts_mailbox?"_draft_uid":"_uid";cols.subject='<a href="./?_task=mail&_action='+action+"&_mbox="+urlencode(flags.mbox)+"&"+uid_param+"="+uid+'" onclick="return rcube_event.cancel(event)" onmouseover="rcube_webmail.long_subject_title(this,'+(message.depth+1)+')">'+cols.subject+"</a>"}for(n in this.env.coltypes){c=this.env.coltypes[n];col=document.createElement("td");col.className=String(c).toLowerCase();if(c=="flag"){css_class=(flags.flagged?"flagged":"unflagged");html='<span id="flagicn'+uid+'" class="'+css_class+'"> </span>'}else{if(c=="attachment"){if(/application\/|multipart\/(m|signed)/.test(flags.ctype)){html='<span class="attachment"> </span>'}else{if(/multipart\/report/.test(flags.ctype)){html='<span class="report"> </span>'}else{html=" "}}}else{if(c=="status"){if(flags.deleted){css_class="deleted"}else{if(!flags.seen){css_class="unread"}else{if(flags.unread_children>0){css_class="unreadchildren"}else{css_class="msgicon"}}}html='<span id="statusicn'+uid+'" class="'+css_class+'"> </span>'}else{if(c=="threads"){html=expando}else{if(c=="subject"){if(bw.ie){col.onmouseover=function(){rcube_webmail.long_subject_title_ex(this,message.depth+1)};if(bw.ie8){tree="<span></span>"+tree}}html=tree+cols[c]}else{if(c=="priority"){if(flags.prio>0&&flags.prio<6){html='<span class="prio'+flags.prio+'"> </span>'}else{html=" "}}else{html=cols[c]}}}}}}if(html){col.innerHTML=html}row.appendChild(col)}list.insert_row(row,attop);if(attop&&this.env.pagesize&&list.rowcount>this.env.pagesize){var uid=list.get_last_row();list.remove_row(uid);list.clear_selection(uid)}};this.set_list_sorting=function(sort_col,sort_order){$("#rcm"+this.env.sort_col).removeClass("sorted"+(this.env.sort_order.toUpperCase()));if(sort_col){$("#rcm"+sort_col).addClass("sorted"+sort_order)}this.env.sort_col=sort_col;this.env.sort_order=sort_order};this.set_list_options=function(cols,sort_col,sort_order,threads){var update,post_data={};if(sort_col===undefined){sort_col=this.env.sort_col}if(!sort_order){sort_order=this.env.sort_order}if(this.env.sort_col!=sort_col||this.env.sort_order!=sort_order){update=1;this.set_list_sorting(sort_col,sort_order)}if(this.env.threading!=threads){update=1;post_data._threads=threads}if(cols&&cols.length){var i,idx,name,newcols=[],oldcols=this.env.coltypes;for(i=0;i<oldcols.length;i++){name=oldcols[i];idx=$.inArray(name,cols);if(idx!=-1){newcols.push(name);delete cols[idx]}}for(i=0;i<cols.length;i++){if(cols[i]){newcols.push(cols[i])}}if(newcols.join()!=oldcols.join()){update=1;post_data._cols=newcols.join(",")}}if(update){this.list_mailbox("","",sort_col+"_"+sort_order,post_data)}};this.show_message=function(id,safe,preview){if(!id){return}var win,target=window,action=preview?"preview":"show",url="&_action="+action+"&_uid="+id+"&_mbox="+urlencode(this.env.mailbox);if(preview&&(win=this.get_frame_window(this.env.contentframe))){target=win;url+="&_framed=1"}if(safe){url+="&_safe=1"}if(this.env.search_request){url+="&_search="+this.env.search_request}url+="&_caps="+urlencode(this.browser_capabilities());if(this.env.extwin){url+="&_extwin=1"}if(preview&&String(target.location.href).indexOf(url)>=0){this.show_contentframe(true)}else{if(!preview&&this.env.message_extwin&&!this.env.extwin){this.open_window(this.env.comm_path+url,1000)}else{this.location_href(this.env.comm_path+url,target,true)}if(preview&&this.message_list&&this.message_list.rows[id]&&this.message_list.rows[id].unread&&this.env.preview_pane_mark_read>=0){this.preview_read_timer=setTimeout(function(){ref.set_message(id,"unread",false);ref.update_thread_root(id,"read");if(ref.env.unread_counts[ref.env.mailbox]){ref.env.unread_counts[ref.env.mailbox]-=1;ref.set_unread_count(ref.env.mailbox,ref.env.unread_counts[ref.env.mailbox],ref.env.mailbox=="INBOX")}if(ref.env.preview_pane_mark_read>0){ref.http_post("mark",{_uid:id,_flag:"read",_quiet:1})}},this.env.preview_pane_mark_read*1000)}}};this.show_contentframe=function(show){var frame,win,name=this.env.contentframe;if(name&&(frame=this.get_frame_element(name))){if(!show&&(win=this.get_frame_window(name))){if(win.location&&win.location.href.indexOf(this.env.blankpage)<0){win.location.href=this.env.blankpage}}else{if(!bw.safari&&!bw.konq){$(frame)[show?"show":"hide"]()}}}if(!show&&this.busy){this.set_busy(false,null,this.env.frame_lock)}};this.get_frame_element=function(id){var frame;if(id&&(frame=document.getElementById(id))){return frame}};this.get_frame_window=function(id){var frame=this.get_frame_element(id);if(frame&&frame.name&&window.frames){return window.frames[frame.name]}};this.lock_frame=function(){if(!this.env.frame_lock){(this.is_framed()?parent.rcmail:this).env.frame_lock=this.set_busy(true,"loading")}};this.list_page=function(page){if(page=="next"){page=this.env.current_page+1}else{if(page=="last"){page=this.env.pagecount}else{if(page=="prev"&&this.env.current_page>1){page=this.env.current_page-1}else{if(page=="first"&&this.env.current_page>1){page=1}}}}if(page>0&&page<=this.env.pagecount){this.env.current_page=page;if(this.task=="addressbook"||this.contact_list){this.list_contacts(this.env.source,this.env.group,page)}else{if(this.task=="mail"){this.list_mailbox(this.env.mailbox,page)}}}};this.checkmail=function(){var lock=this.set_busy(true,"checkingmail"),params=this.check_recent_params();this.http_request("check-recent",params,lock)};this.filter_mailbox=function(filter){var lock=this.set_busy(true,"searching");this.clear_message_list();this.env.current_page=1;this.http_request("search",this.search_params(false,filter),lock)};this.list_mailbox=function(mbox,page,sort,url){var win,target=window;if(typeof url!="object"){url={}}if(!mbox){mbox=this.env.mailbox?this.env.mailbox:"INBOX"}if(sort){url._sort=sort}if(this.env.search_request){url._search=this.env.search_request}if(this.env.mailbox!=mbox){page=1;this.env.current_page=page;this.select_all_mode=false}this.clear_message_list();if(mbox!=this.env.mailbox||(mbox==this.env.mailbox&&!page&&!sort)){url._refresh=1}this.select_folder(mbox,"",true);this.unmark_folder(mbox,"recent","",true);this.env.mailbox=mbox;if(this.gui_objects.messagelist){this.list_mailbox_remote(mbox,page,url);return}if(win=this.get_frame_window(this.env.contentframe)){target=win;url._framed=1}if(mbox){this.set_busy(true,"loading");url._mbox=mbox;if(page){url._page=page}this.location_href(url,target)}};this.clear_message_list=function(){this.env.messages={};this.last_selected=0;this.show_contentframe(false);if(this.message_list){this.message_list.clear(true)}};this.list_mailbox_remote=function(mbox,page,post_data){this.message_list.clear();var lock=this.set_busy(true,"loading");if(typeof post_data!="object"){post_data={}}post_data._mbox=mbox;if(page){post_data._page=page}this.http_request("list",post_data,lock)};this.update_selection=function(){var selected=this.message_list.selection,rows=this.message_list.rows,i,selection=[];for(i in selected){if(rows[selected[i]]){selection.push(selected[i])}}this.message_list.selection=selection};this.expand_unread=function(){var r,tbody=this.gui_objects.messagelist.tBodies[0],new_row=tbody.firstChild;while(new_row){if(new_row.nodeType==1&&(r=this.message_list.rows[new_row.uid])&&r.unread_children){this.message_list.expand_all(r);this.set_unread_children(r.uid)}new_row=new_row.nextSibling}return false};this.expand_message_row=function(e,uid){var row=this.message_list.rows[uid];row.expanded=!row.expanded;this.set_unread_children(uid);row.expanded=!row.expanded;this.message_list.expand_row(e,uid)};this.expand_threads=function(){if(!this.env.threading||!this.env.autoexpand_threads||!this.message_list){return}switch(this.env.autoexpand_threads){case 2:this.expand_unread();break;case 1:this.message_list.expand_all();break}};this.init_threads=function(roots,mbox){if(mbox&&mbox!=this.env.mailbox){return false}for(var n=0,len=roots.length;n<len;n++){this.add_tree_icons(roots[n])}this.expand_threads()};this.add_tree_icons=function(root){var i,l,r,n,len,pos,tmp=[],uid=[],row,rows=this.message_list.rows;if(root){row=rows[root]?rows[root].obj:null}else{row=this.message_list.list.tBodies[0].firstChild}while(row){if(row.nodeType==1&&(r=rows[row.uid])){if(r.depth){for(i=tmp.length-1;i>=0;i--){len=tmp[i].length;if(len>r.depth){pos=len-r.depth;if(!(tmp[i][pos]&2)){tmp[i][pos]=tmp[i][pos]?tmp[i][pos]+2:2}}else{if(len==r.depth){if(!(tmp[i][0]&2)){tmp[i][0]+=2}}}if(r.depth>len){break}}tmp.push(new Array(r.depth));tmp[tmp.length-1][0]=1;uid.push(r.uid)}else{if(tmp.length){for(i in tmp){this.set_tree_icons(uid[i],tmp[i])}tmp=[];uid=[]}if(root&&row!=rows[root].obj){break}}}row=row.nextSibling}if(tmp.length){for(i in tmp){this.set_tree_icons(uid[i],tmp[i])}}};this.set_tree_icons=function(uid,tree){var i,divs=[],html="",len=tree.length;for(i=0;i<len;i++){if(tree[i]>2){divs.push({"class":"l3",width:15})}else{if(tree[i]>1){divs.push({"class":"l2",width:15})}else{if(tree[i]>0){divs.push({"class":"l1",width:15})}else{if(divs.length&&!divs[divs.length-1]["class"]){divs[divs.length-1].width+=15}else{divs.push({"class":null,width:15})}}}}}for(i=divs.length-1;i>=0;i--){if(divs[i]["class"]){html+='<div class="tree '+divs[i]["class"]+'" />'}else{html+='<div style="width:'+divs[i].width+'px" />'}}if(html){$("#rcmtab"+uid).html(html)}};this.update_thread_root=function(uid,flag){if(!this.env.threading){return}var root=this.message_list.find_root(uid);if(uid==root){return}var p=this.message_list.rows[root];if(flag=="read"&&p.unread_children){p.unread_children--}else{if(flag=="unread"&&p.has_children){p.unread_children=p.unread_children?p.unread_children+1:1}else{return}}this.set_message_icon(root);this.set_unread_children(root)};this.update_thread=function(uid){if(!this.env.threading){return 0}var r,parent,count=0,rows=this.message_list.rows,row=rows[uid],depth=rows[uid].depth,roots=[];if(!row.depth){count--}else{if(row.unread){parent=this.message_list.find_root(uid);rows[parent].unread_children--;this.set_unread_children(parent)}}parent=row.parent_uid;row=row.obj.nextSibling;while(row){if(row.nodeType==1&&(r=rows[row.uid])){if(!r.depth||r.depth<=depth){break}r.depth--;$("#rcmtab"+r.uid).width(r.depth*15).html("");if(!r.depth){count++;r.parent_uid=0;if(r.has_children){$("#rcmrow"+r.uid+" .leaf:first").attr("id","rcmexpando"+r.uid).attr("class",(r.obj.style.display!="none"?"expanded":"collapsed")).bind("mousedown",{uid:r.uid,p:this},function(e){return e.data.p.expand_message_row(e,e.data.uid)});r.unread_children=0;roots.push(r)}if(r.obj.style.display=="none"){$(r.obj).show()}}else{if(r.depth==depth){r.parent_uid=parent}if(r.unread&&roots.length){roots[roots.length-1].unread_children++}}}row=row.nextSibling}for(var i=0;i<roots.length;i++){this.set_unread_children(roots[i].uid)}return count};this.delete_excessive_thread_rows=function(){var rows=this.message_list.rows,tbody=this.message_list.list.tBodies[0],row=tbody.firstChild,cnt=this.env.pagesize+1;while(row){if(row.nodeType==1&&(r=rows[row.uid])){if(!r.depth&&cnt){cnt--}if(!cnt){this.message_list.remove_row(row.uid)}}row=row.nextSibling}};this.set_message_icon=function(uid){var css_class,row=this.message_list.rows[uid];if(!row){return false}if(row.icon){css_class="msgicon";if(row.deleted){css_class+=" deleted"}else{if(row.unread){css_class+=" unread"}else{if(row.unread_children){css_class+=" unreadchildren"}}}if(row.msgicon==row.icon){if(row.replied){css_class+=" replied"}if(row.forwarded){css_class+=" forwarded"}css_class+=" status"}row.icon.className=css_class}if(row.msgicon&&row.msgicon!=row.icon){css_class="msgicon";if(!row.unread&&row.unread_children){css_class+=" unreadchildren"}if(row.replied){css_class+=" replied"}if(row.forwarded){css_class+=" forwarded"}row.msgicon.className=css_class}if(row.flagicon){css_class=(row.flagged?"flagged":"unflagged");row.flagicon.className=css_class}};this.set_message_status=function(uid,flag,status){var row=this.message_list.rows[uid];if(!row){return false}if(flag=="unread"){row.unread=status}else{if(flag=="deleted"){row.deleted=status}else{if(flag=="replied"){row.replied=status}else{if(flag=="forwarded"){row.forwarded=status}else{if(flag=="flagged"){row.flagged=status}}}}}};this.set_message=function(uid,flag,status){var row=this.message_list&&this.message_list.rows[uid];if(!row){return false}if(flag){this.set_message_status(uid,flag,status)}var rowobj=$(row.obj);if(row.unread&&!rowobj.hasClass("unread")){rowobj.addClass("unread")}else{if(!row.unread&&rowobj.hasClass("unread")){rowobj.removeClass("unread")}}if(row.deleted&&!rowobj.hasClass("deleted")){rowobj.addClass("deleted")}else{if(!row.deleted&&rowobj.hasClass("deleted")){rowobj.removeClass("deleted")}}if(row.flagged&&!rowobj.hasClass("flagged")){rowobj.addClass("flagged")}else{if(!row.flagged&&rowobj.hasClass("flagged")){rowobj.removeClass("flagged")}}this.set_unread_children(uid);this.set_message_icon(uid)};this.set_unread_children=function(uid){var row=this.message_list.rows[uid];if(row.parent_uid){return}if(!row.unread&&row.unread_children&&!row.expanded){$(row.obj).addClass("unroot")}else{$(row.obj).removeClass("unroot")}};this.copy_messages=function(mbox){if(mbox&&typeof mbox==="object"){mbox=mbox.id}if(!mbox||mbox==this.env.mailbox){return}var post_data=this.selection_post_data({_target_mbox:mbox});if(!post_data._uid){return}this.http_post("copy",post_data,this.display_message(this.get_label("copyingmessage"),"loading"))};this.move_messages=function(mbox){if(mbox&&typeof mbox==="object"){mbox=mbox.id}if(!mbox||mbox==this.env.mailbox){return}var lock=false,post_data=this.selection_post_data({_target_mbox:mbox});if(!post_data._uid){return}if(this.env.action=="show"){lock=this.set_busy(true,"movingmessage")}else{this.show_contentframe(false)}this.enable_command(this.env.message_commands,false);this._with_selected_messages("moveto",post_data,lock)};this.delete_messages=function(event){var uid,i,len,trash=this.env.trash_mailbox,list=this.message_list,selection=list?list.get_selection():[];if(!this.env.uid&&!selection.length){return}for(i=0,len=selection.length;i<len;i++){uid=selection[i];if(list.rows[uid].has_children&&!list.rows[uid].expanded){list.select_children(uid)}}if(this.env.flag_for_deletion){this.mark_message("delete");return false}else{if(!trash||this.env.mailbox==trash){this.permanently_remove_messages()}else{if(this.env.delete_junk&&this.env.junk_mailbox&&this.env.mailbox==this.env.junk_mailbox){this.permanently_remove_messages()}else{if((list&&list.modkey==SHIFT_KEY)||(event&&rcube_event.get_modifier(event)==SHIFT_KEY)){if(confirm(this.get_label("deletemessagesconfirm"))){this.permanently_remove_messages()}}else{this.move_messages(trash)}}}}return true};this.permanently_remove_messages=function(){var post_data=this.selection_post_data();if(!post_data._uid){return}this.show_contentframe(false);this._with_selected_messages("delete",post_data)};this._with_selected_messages=function(action,post_data,lock){var count=0,msg;if(this.message_list){var n,id,root,roots=[],selection=this.message_list.get_selection();for(n=0,len=selection.length;n<len;n++){id=selection[n];if(this.env.threading){count+=this.update_thread(id);root=this.message_list.find_root(id);if(root!=id&&$.inArray(root,roots)<0){roots.push(root)}}this.message_list.remove_row(id,(this.env.display_next&&n==selection.length-1))}if(!this.env.display_next){this.message_list.clear_selection()}for(n=0,len=roots.length;n<len;n++){this.add_tree_icons(roots[n])}}if(this.env.display_next&&this.env.next_uid){post_data._next_uid=this.env.next_uid}if(count<0){post_data._count=(count*-1)}else{if(count>0){this.delete_excessive_thread_rows()}}if(!lock){msg=action=="moveto"?"movingmessage":"deletingmessage";lock=this.display_message(this.get_label(msg),"loading")}this.http_post(action,post_data,lock)};this.selection_post_data=function(data){if(typeof(data)!="object"){data={}}data._mbox=this.env.mailbox;if(!data._uid){var uids=this.env.uid?[this.env.uid]:this.message_list.get_selection();data._uid=this.uids_to_list(uids)}if(this.env.action){data._from=this.env.action}if(this.env.search_request){data._search=this.env.search_request}return data};this.mark_message=function(flag,uid){var a_uids=[],r_uids=[],len,n,id,list=this.message_list;if(uid){a_uids[0]=uid}else{if(this.env.uid){a_uids[0]=this.env.uid}else{if(list){a_uids=list.get_selection()}}}if(!list){r_uids=a_uids}else{list.focus();for(n=0,len=a_uids.length;n<len;n++){id=a_uids[n];if((flag=="read"&&list.rows[id].unread)||(flag=="unread"&&!list.rows[id].unread)||(flag=="delete"&&!list.rows[id].deleted)||(flag=="undelete"&&list.rows[id].deleted)||(flag=="flagged"&&!list.rows[id].flagged)||(flag=="unflagged"&&list.rows[id].flagged)){r_uids.push(id)}}}if(!r_uids.length&&!this.select_all_mode){return}switch(flag){case"read":case"unread":this.toggle_read_status(flag,r_uids);break;case"delete":case"undelete":this.toggle_delete_status(r_uids);break;case"flagged":case"unflagged":this.toggle_flagged_status(flag,a_uids);break}};this.toggle_read_status=function(flag,a_uids){var i,len=a_uids.length,post_data=this.selection_post_data({_uid:this.uids_to_list(a_uids),_flag:flag}),lock=this.display_message(this.get_label("markingmessage"),"loading");for(i=0;i<len;i++){this.set_message(a_uids[i],"unread",(flag=="unread"?true:false))}this.http_post("mark",post_data,lock);for(i=0;i<len;i++){this.update_thread_root(a_uids[i],flag)}};this.toggle_flagged_status=function(flag,a_uids){var i,len=a_uids.length,post_data=this.selection_post_data({_uid:this.uids_to_list(a_uids),_flag:flag}),lock=this.display_message(this.get_label("markingmessage"),"loading");for(i=0;i<len;i++){this.set_message(a_uids[i],"flagged",(flag=="flagged"?true:false))}this.http_post("mark",post_data,lock)};this.toggle_delete_status=function(a_uids){var len=a_uids.length,i,uid,all_deleted=true,rows=this.message_list?this.message_list.rows:[];if(len==1){if(!rows.length||(rows[a_uids[0]]&&!rows[a_uids[0]].deleted)){this.flag_as_deleted(a_uids)}else{this.flag_as_undeleted(a_uids)}return true}for(i=0;i<len;i++){uid=a_uids[i];if(rows[uid]&&!rows[uid].deleted){all_deleted=false;break}}if(all_deleted){this.flag_as_undeleted(a_uids)}else{this.flag_as_deleted(a_uids)}return true};this.flag_as_undeleted=function(a_uids){var i,len=a_uids.length,post_data=this.selection_post_data({_uid:this.uids_to_list(a_uids),_flag:"undelete"}),lock=this.display_message(this.get_label("markingmessage"),"loading");for(i=0;i<len;i++){this.set_message(a_uids[i],"deleted",false)}this.http_post("mark",post_data,lock)};this.flag_as_deleted=function(a_uids){var r_uids=[],post_data=this.selection_post_data({_uid:this.uids_to_list(a_uids),_flag:"delete"}),lock=this.display_message(this.get_label("markingmessage"),"loading"),rows=this.message_list?this.message_list.rows:[],count=0;for(var i=0,len=a_uids.length;i<len;i++){uid=a_uids[i];if(rows[uid]){if(rows[uid].unread){r_uids[r_uids.length]=uid}if(this.env.skip_deleted){count+=this.update_thread(uid);this.message_list.remove_row(uid,(this.env.display_next&&i==this.message_list.selection.length-1))}else{this.set_message(uid,"deleted",true)}}}if(this.env.skip_deleted&&this.message_list){if(!this.env.display_next){this.message_list.clear_selection()}if(count<0){post_data._count=(count*-1)}else{if(count>0){this.delete_excessive_thread_rows()}}}if(r_uids.length){post_data._ruid=this.uids_to_list(r_uids)}if(this.env.skip_deleted&&this.env.display_next&&this.env.next_uid){post_data._next_uid=this.env.next_uid}this.http_post("mark",post_data,lock)};this.flag_deleted_as_read=function(uids){var icn_src,uid,i,len,rows=this.message_list?this.message_list.rows:[];uids=String(uids).split(",");for(i=0,len=uids.length;i<len;i++){uid=uids[i];if(rows[uid]){this.set_message(uid,"unread",false)}}};this.uids_to_list=function(uids){return this.select_all_mode?"*":uids.join(",")};this.set_button_titles=function(){var label="deletemessage";if(!this.env.flag_for_deletion&&this.env.trash_mailbox&&this.env.mailbox!=this.env.trash_mailbox&&(!this.env.delete_junk||!this.env.junk_mailbox||this.env.mailbox!=this.env.junk_mailbox)){label="movemessagetotrash"}this.set_alttext("delete",label)};this.expunge_mailbox=function(mbox){var lock,post_data={_mbox:mbox};if(mbox==this.env.mailbox){lock=this.set_busy(true,"loading");post_data._reload=1;if(this.env.search_request){post_data._search=this.env.search_request}}this.http_post("expunge",post_data,lock)};this.purge_mailbox=function(mbox){var lock,post_data={_mbox:mbox};if(!confirm(this.get_label("purgefolderconfirm"))){return false}if(mbox==this.env.mailbox){lock=this.set_busy(true,"loading");post_data._reload=1}this.http_post("purge",post_data,lock)};this.purge_mailbox_test=function(){return(this.env.exists&&(this.env.mailbox==this.env.trash_mailbox||this.env.mailbox==this.env.junk_mailbox||this.env.mailbox.match("^"+RegExp.escape(this.env.trash_mailbox)+RegExp.escape(this.env.delimiter))||this.env.mailbox.match("^"+RegExp.escape(this.env.junk_mailbox)+RegExp.escape(this.env.delimiter))))};this.login_user_keyup=function(e){var key=rcube_event.get_keycode(e);var passwd=$("#rcmloginpwd");if(key==13&&passwd.length&&!passwd.val()){passwd.focus();return rcube_event.cancel(e)}return true};this.open_compose_step=function(p){var url=this.url("mail/compose",p);if(this.env.compose_extwin&&!this.env.extwin){this.open_window(url,1150)}else{this.redirect(url);if(this.env.extwin){window.resizeTo(Math.max(1150,$(window).width()),$(window).height()+24)}}};this.init_messageform=function(){if(!this.gui_objects.messageform){return false}var input_from=$("[name='_from']"),input_to=$("[name='_to']"),input_subject=$("input[name='_subject']"),input_message=$("[name='_message']").get(0),html_mode=$("input[name='_is_html']").val()=="1",ac_fields=["cc","bcc","replyto","followupto"],ac_props,opener_rc=this.opener();if(opener_rc&&opener_rc.env.action=="compose"){setTimeout(function(){opener.history.back()},100);this.env.opened_extwin=true}if(this.env.autocomplete_threads>0){ac_props={threads:this.env.autocomplete_threads,sources:this.env.autocomplete_sources}}this.init_address_input_events(input_to,ac_props);for(var i in ac_fields){this.init_address_input_events($("[name='_"+ac_fields[i]+"']"),ac_props)}if(!html_mode){this.set_caret_pos(input_message,this.env.top_posting?0:$(input_message).val().length);if(input_from.prop("type")=="select-one"){this.change_identity(input_from[0])}}if(input_to.val()==""){input_to.focus()}else{if(input_subject.val()==""){input_subject.focus()}else{if(input_message){input_message.focus()}}}this.env.compose_focus_elem=document.activeElement;this.compose_field_hash(true);this.auto_save_start()};this.init_address_input_events=function(obj,props){this.env.recipients_delimiter=this.env.recipients_separator+" ";obj[bw.ie||bw.safari||bw.chrome?"keydown":"keypress"](function(e){return ref.ksearch_keydown(e,this,props)}).attr("autocomplete","off")};this.submit_messageform=function(draft){var form=this.gui_objects.messageform;if(!form){return}var msgid=this.set_busy(true,draft?"savingmessage":"sendingmessage"),lang=this.spellcheck_lang(),files=[];$("li",this.gui_objects.attachmentlist).each(function(){files.push(this.id.replace(/^rcmfile/,""))});$('input[name="_attachments"]',form).val(files.join());form.target="savetarget";form._draft.value=draft?"1":"";form.action=this.add_url(form.action,"_unlock",msgid);form.action=this.add_url(form.action,"_lang",lang);this.submit_timer=setTimeout(function(){ref.set_busy(false,null,msgid);ref.display_message(ref.get_label("requesttimedout"),"error")},this.env.request_timeout*1000);form.submit()};this.compose_recipient_select=function(list){this.enable_command("add-recipient",list.selection.length>0)};this.compose_add_recipient=function(field){var recipients=[],input=$("#_"+field),delim=this.env.recipients_delimiter;if(this.contact_list&&this.contact_list.selection.length){for(var id,n=0;n<this.contact_list.selection.length;n++){id=this.contact_list.selection[n];if(id&&this.env.contactdata[id]){recipients.push(this.env.contactdata[id]);if(id.charAt(0)=="E"&&this.env.contactdata[id].indexOf("@")<0&&input.length){var gid=id.substr(1);this.group2expand[gid]={name:this.env.contactdata[id],input:input.get(0)};this.http_request("group-expand",{_source:this.env.source,_gid:gid},false)}}}}if(recipients.length&&input.length){var oldval=input.val(),rx=new RegExp(RegExp.escape(delim)+"\\s*$");if(oldval&&!rx.test(oldval)){oldval+=delim+" "}input.val(oldval+recipients.join(delim+" ")+delim+" ");this.triggerEvent("add-recipient",{field:field,recipients:recipients})}};this.check_compose_input=function(cmd){var ed,input_to=$("[name='_to']"),input_cc=$("[name='_cc']"),input_bcc=$("[name='_bcc']"),input_from=$("[name='_from']"),input_subject=$("[name='_subject']"),input_message=$("[name='_message']");if(input_from.prop("type")=="text"&&!rcube_check_email(input_from.val(),true)){alert(this.get_label("nosenderwarning"));input_from.focus();return false}var recipients=input_to.val()?input_to.val():(input_cc.val()?input_cc.val():input_bcc.val());if(!rcube_check_email(recipients.replace(/^\s+/,"").replace(/[\s,;]+$/,""),true)){alert(this.get_label("norecipientwarning"));input_to.focus();return false}for(var key in this.env.attachments){if(typeof this.env.attachments[key]==="object"&&!this.env.attachments[key].complete){alert(this.get_label("notuploadedwarning"));return false}}if(input_subject.val()==""){var myprompt=$('<div class="prompt">').html('<div class="message">'+this.get_label("nosubjectwarning")+"</div>").appendTo(document.body);var prompt_value=$("<input>").attr("type","text").attr("size",30).appendTo(myprompt).val(this.get_label("nosubject"));var buttons={};buttons[this.get_label("cancel")]=function(){input_subject.focus();$(this).dialog("close")};buttons[this.get_label("sendmessage")]=function(){input_subject.val(prompt_value.val());$(this).dialog("close");ref.command(cmd,{nocheck:true})};myprompt.dialog({modal:true,resizable:false,buttons:buttons,close:function(event,ui){$(this).remove()}});prompt_value.select();return false}this.stop_spellchecking();if(window.tinyMCE){ed=tinyMCE.get(this.env.composebody)}if(!ed&&input_message.val()==""&&!confirm(this.get_label("nobodywarning"))){input_message.focus();return false}else{if(ed){if(!ed.getContent()&&!confirm(this.get_label("nobodywarning"))){ed.focus();return false}tinyMCE.triggerSave()}}return true};this.toggle_editor=function(props){this.stop_spellchecking();if(props.mode=="html"){this.plain2html($("#"+props.id).val(),props.id);tinyMCE.execCommand("mceAddControl",false,props.id);if(this.env.default_font){setTimeout(function(){$(tinyMCE.get(props.id).getBody()).css("font-family",rcmail.env.default_font)},500)}}else{var thisMCE=tinyMCE.get(props.id),existingHtml;if(existingHtml=thisMCE.getContent()){if(!confirm(this.get_label("editorwarning"))){return false}this.html2plain(existingHtml,props.id)}tinyMCE.execCommand("mceRemoveControl",false,props.id)}return true};this.stop_spellchecking=function(){var ed;if(window.tinyMCE&&(ed=tinyMCE.get(this.env.composebody))){if(ed.plugins&&ed.plugins.spellchecker&&ed.plugins.spellchecker.active){ed.execCommand("mceSpellCheck")}}else{if(ed=this.env.spellcheck){if(ed.state&&ed.state!="ready"&&ed.state!="no_error_found"){$(ed.spell_span).trigger("click")}}}this.spellcheck_state()};this.spellcheck_state=function(){var ed,active;if(window.tinyMCE&&(ed=tinyMCE.get(this.env.composebody))&&ed.plugins&&ed.plugins.spellchecker){active=ed.plugins.spellchecker.active}else{if((ed=this.env.spellcheck)&&ed.state){active=ed.state!="ready"&&ed.state!="no_error_found"}}if(rcmail.buttons.spellcheck){$("#"+rcmail.buttons.spellcheck[0].id)[active?"addClass":"removeClass"]("selected")}return active};this.spellcheck_lang=function(){var ed;if(window.tinyMCE&&(ed=tinyMCE.get(this.env.composebody))&&ed.plugins&&ed.plugins.spellchecker){return ed.plugins.spellchecker.selectedLang}else{if(this.env.spellcheck){return GOOGIE_CUR_LANG}}};this.spellcheck_lang_set=function(lang){var ed;if(window.tinyMCE&&(ed=tinyMCE.get(this.env.composebody))&&ed.plugins){ed.plugins.spellchecker.selectedLang=lang}else{if(this.env.spellcheck){this.env.spellcheck.setCurrentLanguage(lang)}}};this.spellcheck_resume=function(ishtml,data){if(ishtml){var ed=tinyMCE.get(this.env.composebody);sp=ed.plugins.spellchecker;sp.active=1;sp._markWords(data);ed.nodeChanged()}else{var sp=this.env.spellcheck;sp.prepare(false,true);sp.processData(data)}this.spellcheck_state()};this.set_draft_id=function(id){var rc;if(!this.env.draft_id&&id&&(rc=this.opener())){if(rc.env.task=="mail"&&rc.env.action==""&&rc.env.mailbox==this.env.drafts_mailbox){rc.command("checkmail")}}this.env.draft_id=id;$("input[name='_draft_saveid']").val(id)};this.auto_save_start=function(){if(this.env.draft_autosave){this.save_timer=setTimeout(function(){ref.command("savedraft")},this.env.draft_autosave*1000)}this.busy=false};this.compose_field_hash=function(save){var ed,i,val,str="",hash_fields=["to","cc","bcc","subject"];for(i=0;i<hash_fields.length;i++){if(val=$('[name="_'+hash_fields[i]+'"]').val()){str+=val+":"}}if(window.tinyMCE&&(ed=tinyMCE.get(this.env.composebody))){str+=ed.getContent()}else{str+=$("[name='_message']").val()}if(this.env.attachments){for(var upload_id in this.env.attachments){str+=upload_id}}if(save){this.cmp_hash=str}return str};this.change_identity=function(obj,show_sig){if(!obj||!obj.options){return false}if(!show_sig){show_sig=this.env.show_sig}if(!this.env.identities_initialized){this.env.identities_initialized=true;if(this.env.show_sig_later){this.env.show_sig=true}if(this.env.opened_extwin){return}}var cursor_pos,p=-1,id=obj.options[obj.selectedIndex].value,input_message=$("[name='_message']"),message=input_message.val(),is_html=($("input[name='_is_html']").val()=="1"),sig=this.env.identity;if(this.env.signatures&&this.env.signatures[id]){this.enable_command("insert-sig",true);this.env.compose_commands.push("insert-sig")}else{this.enable_command("insert-sig",false)}if(!is_html){if(show_sig&&sig&&this.env.signatures&&this.env.signatures[sig]){sig=this.env.signatures[sig].text;sig=sig.replace(/\r\n/g,"\n");p=this.env.top_posting?message.indexOf(sig):message.lastIndexOf(sig);if(p>=0){message=message.substring(0,p)+message.substring(p+sig.length,message.length)}}if(show_sig&&this.env.signatures&&this.env.signatures[id]){sig=this.env.signatures[id].text;sig=sig.replace(/\r\n/g,"\n");if(this.env.top_posting){if(p>=0){message=message.substring(0,p)+sig+message.substring(p,message.length);cursor_pos=p-1}else{if(!message){cursor_pos=0;message="\n\n"+sig}else{if(pos=this.get_caret_pos(input_message.get(0))){message=message.substring(0,pos)+"\n"+sig+"\n\n"+message.substring(pos,message.length);cursor_pos=pos}else{cursor_pos=0;message="\n\n"+sig+"\n\n"+message.replace(/^[\r\n]+/,"")}}}}else{message=message.replace(/[\r\n]+$/,"");cursor_pos=!this.env.top_posting&&message.length?message.length+1:0;message+="\n\n"+sig}}else{cursor_pos=this.env.top_posting?0:message.length}input_message.val(message);this.set_caret_pos(input_message.get(0),cursor_pos)}else{if(show_sig&&this.env.signatures){var editor=tinyMCE.get(this.env.composebody),sigElem=editor.dom.get("_rc_sig");if(!sigElem){var body=editor.getBody(),doc=editor.getDoc();sigElem=doc.createElement("div");sigElem.setAttribute("id","_rc_sig");if(this.env.top_posting){editor.getWin().focus();var node=editor.selection.getNode();if(node.nodeName=="BODY"){body.insertBefore(sigElem,body.firstChild);body.insertBefore(doc.createElement("br"),body.firstChild)}else{body.insertBefore(sigElem,node.nextSibling);body.insertBefore(doc.createElement("br"),node.nextSibling)}}else{if(bw.ie){body.appendChild(doc.createElement("br"))}body.appendChild(sigElem)}}if(this.env.signatures[id]){sigElem.innerHTML=this.env.signatures[id].html}}}this.env.identity=id;return true};this.upload_file=function(form){if(!form){return false}var size=0,numfiles=0;$("input[type=file]",form).each(function(i,field){var files=field.files?field.files.length:(field.value?1:0);if(field.files){for(var i=0;i<files;i++){size+=field.files[i].size}}numfiles+=files});if(numfiles){if(this.env.max_filesize&&this.env.filesizeerror&&size>this.env.max_filesize){this.display_message(this.env.filesizeerror,"error");return}var frame_name=this.async_upload_form(form,"upload",function(e){var d,content="";try{if(this.contentDocument){d=this.contentDocument}else{if(this.contentWindow){d=this.contentWindow.document}}content=d.childNodes[0].innerHTML}catch(err){}if(!content.match(/add2attachment/)&&(!bw.opera||(rcmail.env.uploadframe&&rcmail.env.uploadframe==e.data.ts))){if(!content.match(/display_message/)){rcmail.display_message(rcmail.get_label("fileuploaderror"),"error")}rcmail.remove_from_attachment_list(e.data.ts)}if(bw.opera){rcmail.env.uploadframe=e.data.ts}});var content="<span>"+this.get_label("uploading"+(numfiles>1?"many":""))+"</span>",ts=frame_name.replace(/^rcmupload/,"");this.add2attachment_list(ts,{name:"",html:content,classname:"uploading",frame:frame_name,complete:false});if(this.env.upload_progress_time){this.upload_progress_start("upload",ts)}}this.gui_objects.attachmentform=form;return true};this.add2attachment_list=function(name,att,upload_id){if(!this.gui_objects.attachmentlist){return false}if(!att.complete&&ref.env.loadingicon){att.html='<img src="'+ref.env.loadingicon+'" alt="" class="uploading" />'+att.html}if(!att.complete&&att.frame){att.html='<a title="'+this.get_label("cancel")+'" onclick="return rcmail.cancel_attachment_upload(\''+name+"', '"+att.frame+'\');" href="#cancelupload" class="cancelupload">'+(this.env.cancelicon?'<img src="'+this.env.cancelicon+'" alt="" />':this.get_label("cancel"))+"</a>"+att.html}var indicator,li=$("<li>");li.attr("id",name).addClass(att.classname).html(att.html).on("mouseover",function(){rcube_webmail.long_subject_title_ex(this,0)});if(upload_id&&(indicator=document.getElementById(upload_id))){li.replaceAll(indicator)}else{li.appendTo(this.gui_objects.attachmentlist)}if(upload_id&&this.env.attachments[upload_id]){delete this.env.attachments[upload_id]}this.env.attachments[name]=att;return true};this.remove_from_attachment_list=function(name){delete this.env.attachments[name];$("#"+name).remove()};this.remove_attachment=function(name){if(name&&this.env.attachments[name]){this.http_post("remove-attachment",{_id:this.env.compose_id,_file:name})}return true};this.cancel_attachment_upload=function(name,frame_name){if(!name||!frame_name){return false}this.remove_from_attachment_list(name);$("iframe[name='"+frame_name+"']").remove();return false};this.upload_progress_start=function(action,name){setTimeout(function(){rcmail.http_request(action,{_progress:name})},this.env.upload_progress_time*1000)};this.upload_progress_update=function(param){var elem=$("#"+param.name+"> span");if(!elem.length||!param.text){return}elem.text(param.text);if(!param.done){this.upload_progress_start(param.action,param.name)}};this.add_contact=function(value){if(value){this.http_post("addcontact",{_address:value})}return true};this.qsearch=function(value){if(value!=""){var r,lock=this.set_busy(true,"searching"),url=this.search_params(value);if(this.message_list){this.clear_message_list()}else{if(this.contact_list){this.list_contacts_clear()}}if(this.env.source){url._source=this.env.source}if(this.env.group){url._gid=this.env.group}this.env.current_page=1;var action=this.env.action=="compose"&&this.contact_list?"search-contacts":"search";r=this.http_request(action,url,lock);this.env.qsearch={lock:lock,request:r}}};this.search_params=function(search,filter){var n,url={},mods_arr=[],mods=this.env.search_mods,mbox=this.env.mailbox;if(!filter&&this.gui_objects.search_filter){filter=this.gui_objects.search_filter.value}if(!search&&this.gui_objects.qsearchbox){search=this.gui_objects.qsearchbox.value}if(filter){url._filter=filter}if(search){url._q=search;if(mods&&this.message_list){mods=mods[mbox]?mods[mbox]:mods["*"]}if(mods){for(n in mods){mods_arr.push(n)}url._headers=mods_arr.join(",")}}if(mbox){url._mbox=mbox}return url};this.reset_qsearch=function(){if(this.gui_objects.qsearchbox){this.gui_objects.qsearchbox.value=""}if(this.env.qsearch){this.abort_request(this.env.qsearch)}this.env.qsearch=null;this.env.search_request=null;this.env.search_id=null};this.sent_successfully=function(type,msg,target){this.display_message(msg,type);if(this.env.extwin){var rc=this.opener();this.lock_form(this.gui_objects.messageform);if(rc){rc.display_message(msg,type);if(target&&rc.env.task=="mail"&&rc.env.action==""&&rc.env.mailbox==target){rc.command("checkmail")}}setTimeout(function(){window.close()},1000)}else{setTimeout(function(){ref.list_mailbox()},500)}};this.ksearch_keydown=function(e,obj,props){if(this.ksearch_timer){clearTimeout(this.ksearch_timer)}var highlight,key=rcube_event.get_keycode(e),mod=rcube_event.get_modifier(e);switch(key){case 38:case 40:if(!this.ksearch_visible()){break}var dir=key==38?1:0;highlight=document.getElementById("rcmksearchSelected");if(!highlight){highlight=this.ksearch_pane.__ul.firstChild}if(highlight){this.ksearch_select(dir?highlight.previousSibling:highlight.nextSibling)}return rcube_event.cancel(e);case 9:if(mod==SHIFT_KEY||!this.ksearch_visible()){this.ksearch_hide();return}case 13:if(!this.ksearch_visible()){return false}this.insert_recipient(this.ksearch_selected);this.ksearch_hide();return rcube_event.cancel(e);case 27:this.ksearch_hide();return;case 37:case 39:if(mod!=SHIFT_KEY){return}}this.ksearch_timer=setTimeout(function(){ref.ksearch_get_results(props)},200);this.ksearch_input=obj;return true};this.ksearch_visible=function(){return(this.ksearch_selected!==null&&this.ksearch_selected!==undefined&&this.ksearch_value)};this.ksearch_select=function(node){var current=$("#rcmksearchSelected");if(current[0]&&node){current.removeAttr("id").removeClass("selected")}if(node){$(node).attr("id","rcmksearchSelected").addClass("selected");this.ksearch_selected=node._rcm_id}};this.insert_recipient=function(id){if(id===null||!this.env.contacts[id]||!this.ksearch_input){return}var inp_value=this.ksearch_input.value,cpos=this.get_caret_pos(this.ksearch_input),p=inp_value.lastIndexOf(this.ksearch_value,cpos),trigger=false,insert="",pre=inp_value.substring(0,p),end=inp_value.substring(p+this.ksearch_value.length,inp_value.length);this.ksearch_destroy();if(typeof this.env.contacts[id]==="object"&&this.env.contacts[id].id){insert+=this.env.contacts[id].name+this.env.recipients_delimiter;this.group2expand[this.env.contacts[id].id]=$.extend({input:this.ksearch_input},this.env.contacts[id]);this.http_request("mail/group-expand",{_source:this.env.contacts[id].source,_gid:this.env.contacts[id].id},false)}else{if(typeof this.env.contacts[id]==="string"){insert=this.env.contacts[id]+this.env.recipients_delimiter;trigger=true}}this.ksearch_input.value=pre+insert+end;cpos=p+insert.length;if(this.ksearch_input.setSelectionRange){this.ksearch_input.setSelectionRange(cpos,cpos)}if(trigger){this.triggerEvent("autocomplete_insert",{field:this.ksearch_input,insert:insert})}};this.replace_group_recipients=function(id,recipients){if(this.group2expand[id]){this.group2expand[id].input.value=this.group2expand[id].input.value.replace(this.group2expand[id].name,recipients);this.triggerEvent("autocomplete_insert",{field:this.group2expand[id].input,insert:recipients});this.group2expand[id]=null}};this.ksearch_get_results=function(props){var inp_value=this.ksearch_input?this.ksearch_input.value:null;if(inp_value===null){return}if(this.ksearch_pane&&this.ksearch_pane.is(":visible")){this.ksearch_pane.hide()}var cpos=this.get_caret_pos(this.ksearch_input),p=inp_value.lastIndexOf(this.env.recipients_separator,cpos-1),q=inp_value.substring(p+1,cpos),min=this.env.autocomplete_min_length,ac=this.ksearch_data;q=$.trim(q);if(q==this.ksearch_value){return}this.ksearch_destroy();if(q.length&&q.length<min){if(!this.ksearch_info){this.ksearch_info=this.display_message(this.get_label("autocompletechars").replace("$min",min))}return}var old_value=this.ksearch_value;this.ksearch_value=q;if(!q.length){return}if(old_value&&old_value.length&&q.indexOf(old_value)==0&&(!ac||ac.num<=0)&&this.env.contacts&&!this.env.contacts.length){return}var i,lock,source,xhr,reqid=new Date().getTime(),post_data={_search:q,_id:reqid},threads=props&&props.threads?props.threads:1,sources=props&&props.sources?props.sources:[],action=props&&props.action?props.action:"mail/autocomplete";this.ksearch_data={id:reqid,sources:sources.slice(),action:action,locks:[],requests:[],num:sources.length};for(i=0;i<threads;i++){source=this.ksearch_data.sources.shift();if(threads>1&&source===undefined){break}post_data._source=source?source:"";lock=this.display_message(this.get_label("searching"),"loading");xhr=this.http_post(action,post_data,lock);this.ksearch_data.locks.push(lock);this.ksearch_data.requests.push(xhr)}};this.ksearch_query_results=function(results,search,reqid){if(!this.ksearch_value){return}if(this.ksearch_input&&search!=this.ksearch_value){return}var i,len,ul,li,text,init,value=this.ksearch_value,data=this.ksearch_data,maxlen=this.env.autocomplete_max?this.env.autocomplete_max:15;if(!this.ksearch_pane){ul=$("<ul>");this.ksearch_pane=$("<div>").attr("id","rcmKSearchpane").css({position:"absolute","z-index":30000}).append(ul).appendTo(document.body);this.ksearch_pane.__ul=ul[0]}ul=this.ksearch_pane.__ul;if(reqid&&this.ksearch_pane.data("reqid")==reqid){maxlen-=ul.childNodes.length}else{this.ksearch_pane.data("reqid",reqid);init=1;ul.innerHTML="";this.env.contacts=[];var pos=$(this.ksearch_input).offset();this.ksearch_pane.css({left:pos.left+"px",top:(pos.top+this.ksearch_input.offsetHeight)+"px",display:"none"})}if(results&&(len=results.length)){for(i=0;i<len&&maxlen>0;i++){text=typeof results[i]==="object"?results[i].name:results[i];li=document.createElement("LI");li.innerHTML=text.replace(new RegExp("("+RegExp.escape(value)+")","ig"),"##$1%%").replace(/</g,"<").replace(/>/g,">").replace(/##([^%]+)%%/g,"<b>$1</b>");li.onmouseover=function(){ref.ksearch_select(this)};li.onmouseup=function(){ref.ksearch_click(this)};li._rcm_id=this.env.contacts.length+i;ul.appendChild(li);maxlen-=1}}if(ul.childNodes.length){this.ksearch_pane.show();if(!this.env.contacts.length){$("li:first",ul).attr("id","rcmksearchSelected").addClass("selected");this.ksearch_selected=0}}if(len){this.env.contacts=this.env.contacts.concat(results)}if(data.id==reqid){data.num--;if(maxlen>0&&data.sources.length){var lock,xhr,source=data.sources.shift(),post_data;if(source){post_data={_search:value,_id:reqid,_source:source};lock=this.display_message(this.get_label("searching"),"loading");xhr=this.http_post(data.action,post_data,lock);this.ksearch_data.locks.push(lock);this.ksearch_data.requests.push(xhr)}}else{if(!maxlen){if(!this.ksearch_msg){this.ksearch_msg=this.display_message(this.get_label("autocompletemore"))}this.ksearch_abort()}}}};this.ksearch_click=function(node){if(this.ksearch_input){this.ksearch_input.focus()}this.insert_recipient(node._rcm_id);this.ksearch_hide()};this.ksearch_blur=function(){if(this.ksearch_timer){clearTimeout(this.ksearch_timer)}this.ksearch_input=null;this.ksearch_hide()};this.ksearch_hide=function(){this.ksearch_selected=null;this.ksearch_value="";if(this.ksearch_pane){this.ksearch_pane.hide()}this.ksearch_destroy()};this.ksearch_destroy=function(){this.ksearch_abort();if(this.ksearch_info){this.hide_message(this.ksearch_info)}if(this.ksearch_msg){this.hide_message(this.ksearch_msg)}this.ksearch_data=null;this.ksearch_info=null;this.ksearch_msg=null};this.ksearch_abort=function(){var i,len,ac=this.ksearch_data;if(!ac){return}for(i=0,len=ac.locks.length;i<len;i++){this.abort_request({request:ac.requests[i],lock:ac.locks[i]})}};this.contactlist_keypress=function(list){if(list.key_pressed==list.DELETE_KEY){this.command("delete")}};this.contactlist_select=function(list){if(this.preview_timer){clearTimeout(this.preview_timer)}var n,id,sid,ref=this,writable=false,source=this.env.source?this.env.address_sources[this.env.source]:null;if(id=list.get_single_selection()){this.preview_timer=setTimeout(function(){ref.load_contact(id,"show")},200)}else{if(this.env.contentframe){this.show_contentframe(false)}}if(list.selection.length){this.env.selection_sources=[];if(!source){for(n in list.selection){sid=String(list.selection[n]).replace(/^[^-]+-/,"");if(sid&&this.env.address_sources[sid]){writable=writable||!this.env.address_sources[sid].readonly;this.env.selection_sources.push(sid)}}this.env.selection_sources=$.unique(this.env.selection_sources)}else{this.env.selection_sources.push(this.env.source);writable=!source.readonly}}this.enable_command("group-remove-selected",this.env.group&&list.selection.length>0);this.enable_command("compose",this.env.group||list.selection.length>0);this.enable_command("edit",id&&writable);this.enable_command("delete",list.selection.length&&writable);return false};this.list_contacts=function(src,group,page){var win,folder,url={},target=window;if(!src){src=this.env.source}if(page&&this.current_page==page&&src==this.env.source&&group==this.env.group){return false}if(src!=this.env.source){page=this.env.current_page=1;this.reset_qsearch()}else{if(group!=this.env.group){page=this.env.current_page=1}}if(this.env.search_id){folder="S"+this.env.search_id}else{if(!this.env.search_request){folder=group?"G"+src+group:src}}this.select_folder(folder);this.env.source=src;this.env.group=group;if(this.gui_objects.contactslist){this.list_contacts_remote(src,group,page);return}if(win=this.get_frame_window(this.env.contentframe)){target=win;url._framed=1}if(group){url._gid=group}if(page){url._page=page}if(src){url._source=src}if(this.env.search_request){url._search=this.env.search_request}this.set_busy(true,"loading");this.location_href(url,target)};this.list_contacts_remote=function(src,group,page){this.list_contacts_clear();var url={},lock=this.set_busy(true,"loading");if(src){url._source=src}if(page){url._page=page}if(group){url._gid=group}this.env.source=src;this.env.group=group;if(this.env.search_request){url._search=this.env.search_request}this.http_request(this.env.task=="mail"?"list-contacts":"list",url,lock)};this.list_contacts_clear=function(){this.contact_list.clear(true);this.show_contentframe(false);this.enable_command("delete",false);this.enable_command("compose",this.env.group?true:false)};this.load_contact=function(cid,action,framed){var win,url={},target=window;if(win=this.get_frame_window(this.env.contentframe)){url._framed=1;target=win;this.show_contentframe(true);if(!cid){this.contact_list.clear_selection();this.enable_command("delete","compose",false)}}else{if(framed){return false}}if(action&&(cid||action=="add")&&!this.drag_active){if(this.env.group){url._gid=this.env.group}url._action=action;url._source=this.env.source;url._cid=cid;this.location_href(url,target,true)}return true};this.group_member_change=function(what,cid,source,gid){what=what=="add"?"add":"del";var label=this.get_label(what=="add"?"addingmember":"removingmember"),lock=this.display_message(label,"loading"),post_data={_cid:cid,_source:source,_gid:gid};this.http_post("group-"+what+"members",post_data,lock)};this.copy_contact=function(cid,to){var n,dest=to.type=="group"?to.source:to.id,source=this.env.source,group=this.env.group?this.env.group:"";if(!cid){cid=this.contact_list.get_selection().join(",")}if(!cid||!this.env.address_sources[dest]||this.env.address_sources[dest].readonly){return}if(source==""&&this.env.selection_sources.length==1){source=this.env.selection_sources[0]}if(to.type=="group"){if(dest==source){this.group_member_change("add",cid,dest,to.id)}else{var lock=this.display_message(this.get_label("copyingcontact"),"loading"),post_data={_cid:cid,_source:this.env.source,_to:dest,_togid:to.id,_gid:group};this.http_post("copy",post_data,lock)}}else{if(to.id!=source){var lock=this.display_message(this.get_label("copyingcontact"),"loading"),post_data={_cid:cid,_source:this.env.source,_to:to.id,_gid:group};this.http_post("copy",post_data,lock)}}};this.delete_contacts=function(){var selection=this.contact_list.get_selection(),undelete=this.env.source&&this.env.address_sources[this.env.source].undelete;if(!(selection.length||this.env.cid)||(!undelete&&!confirm(this.get_label("deletecontactconfirm")))){return}var id,n,a_cids=[],post_data={_source:this.env.source,_from:(this.env.action?this.env.action:"")},lock=this.display_message(this.get_label("contactdeleting"),"loading");if(this.env.cid){a_cids.push(this.env.cid)}else{for(n=0;n<selection.length;n++){id=selection[n];a_cids.push(id);this.contact_list.remove_row(id,(n==selection.length-1))}if(selection.length==1){this.show_contentframe(false)}}post_data._cid=a_cids.join(",");if(this.env.group){post_data._gid=this.env.group}if(this.env.search_request){post_data._search=this.env.search_request}this.http_post("delete",post_data,lock);return true};this.update_contact_row=function(cid,cols_arr,newcid,source){var c,row,list=this.contact_list;cid=this.html_identifier(cid);if(!list.rows[cid]){cid=cid+"-"+source;if(newcid){newcid=newcid+"-"+source}}if(list.rows[cid]&&(row=list.rows[cid].obj)){for(c=0;c<cols_arr.length;c++){if(row.cells[c]){$(row.cells[c]).html(cols_arr[c])}}if(newcid){newcid=this.html_identifier(newcid);row.id="rcmrow"+newcid;list.remove_row(cid);list.init_row(row);list.selection[0]=newcid;row.style.display=""}}};this.add_contact_row=function(cid,cols,classes){if(!this.gui_objects.contactslist){return false}var c,col,list=this.contact_list,row=document.createElement("tr");row.id="rcmrow"+this.html_identifier(cid);row.className="contact "+(classes||"");if(list.in_selection(cid)){row.className+=" selected"}for(c in cols){col=document.createElement("td");col.className=String(c).toLowerCase();if(cols[c]){col.innerHTML=cols[c]}row.appendChild(col)}list.insert_row(row);this.enable_command("export",list.rowcount>0)};this.init_contact_form=function(){var ref=this,col;if(this.env.coltypes){this.set_photo_actions($("#ff_photo").val());for(col in this.env.coltypes){this.init_edit_field(col,null)}}$(".contactfieldgroup .row a.deletebutton").click(function(){ref.delete_edit_field(this);return false});$("select.addfieldmenu").change(function(e){ref.insert_edit_field($(this).val(),$(this).attr("rel"),this);this.selectedIndex=0});if($.datepicker&&this.env.date_format){$.datepicker.setDefaults({dateFormat:this.env.date_format,changeMonth:true,changeYear:true,yearRange:"-100:+10",showOtherMonths:true,selectOtherMonths:true,onSelect:function(dateText){$(this).focus().val(dateText)}});$("input.datepicker").datepicker()}$("input[type='text']:visible").first().focus();if(this.env.action=="search"){$(this.gui_objects.editform).append($('<input type="submit">').hide()).submit(function(){$("input.mainaction").click();return false})}};this.group_create=function(){this.add_input_row("contactgroup")};this.group_rename=function(){if(!this.env.group||!this.gui_objects.folderlist){return}if(!this.name_input){this.enable_command("list","listgroup",false);this.name_input=$("<input>").attr("type","text").val(this.env.contactgroups["G"+this.env.source+this.env.group].name);this.name_input.bind("keydown",function(e){return rcmail.add_input_keydown(e)});this.env.group_renaming=true;var link,li=this.get_folder_li(this.env.source+this.env.group,"rcmliG");if(li&&(link=li.firstChild)){$(link).hide().before(this.name_input)}}this.name_input.select().focus()};this.group_delete=function(){if(this.env.group&&confirm(this.get_label("deletegroupconfirm"))){var lock=this.set_busy(true,"groupdeleting");this.http_post("group-delete",{_source:this.env.source,_gid:this.env.group},lock)}};this.remove_group_item=function(prop){var li,key="G"+prop.source+prop.id;if((li=this.get_folder_li(key))){this.triggerEvent("group_delete",{source:prop.source,id:prop.id,li:li});li.parentNode.removeChild(li);delete this.env.contactfolders[key];delete this.env.contactgroups[key]}this.list_contacts(prop.source,0)};this.add_input_row=function(type){if(!this.gui_objects.folderlist){return}if(!this.name_input){this.name_input=$("<input>").attr("type","text").data("tt",type);this.name_input.bind("keydown",function(e){return rcmail.add_input_keydown(e)});this.name_input_li=$("<li>").addClass(type).append(this.name_input);var li=type=="contactsearch"?$("li:last",this.gui_objects.folderlist):this.get_folder_li(this.env.source);this.name_input_li.insertAfter(li)}this.name_input.select().focus()};this.group_remove_selected=function(){ref.http_post("group-delmembers",{_cid:this.contact_list.selection,_source:this.env.source,_gid:this.env.group})};this.remove_group_contacts=function(props){if("undefined"!=typeof this.env.group&&(this.env.group===props.gid)){var n,selection=this.contact_list.get_selection();for(n=0;n<selection.length;n++){id=selection[n];this.contact_list.remove_row(id,(n==selection.length-1))}}};this.add_input_keydown=function(e){var key=rcube_event.get_keycode(e),input=$(e.target),itype=input.data("tt");if(key==13){var newname=input.val();if(newname){var lock=this.set_busy(true,"loading");if(itype=="contactsearch"){this.http_post("search-create",{_search:this.env.search_request,_name:newname},lock)}else{if(this.env.group_renaming){this.http_post("group-rename",{_source:this.env.source,_gid:this.env.group,_name:newname},lock)}else{this.http_post("group-create",{_source:this.env.source,_name:newname},lock)}}}return false}else{if(key==27){this.reset_add_input()}}return true};this.reset_add_input=function(){if(this.name_input){if(this.env.group_renaming){var li=this.name_input.parent();li.children().last().show();this.env.group_renaming=false}this.name_input.remove();if(this.name_input_li){this.name_input_li.remove()}this.name_input=this.name_input_li=null}this.enable_command("list","listgroup",true)};this.insert_contact_group=function(prop){this.reset_add_input();prop.type="group";var key="G"+prop.source+prop.id,link=$("<a>").attr("href","#").attr("rel",prop.source+":"+prop.id).click(function(){return rcmail.command("listgroup",prop,this)}).html(prop.name),li=$("<li>").attr({id:"rcmli"+this.html_identifier(key),"class":"contactgroup"}).append(link);this.env.contactfolders[key]=this.env.contactgroups[key]=prop;this.add_contact_group_row(prop,li);this.triggerEvent("group_insert",{id:prop.id,source:prop.source,name:prop.name,li:li[0]})};this.update_contact_group=function(prop){this.reset_add_input();var key="G"+prop.source+prop.id,li=this.get_folder_li(key),link;if(li&&prop.newid){var newkey="G"+prop.source+prop.newid,newprop=$.extend({},prop);li.id="rcmli"+this.html_identifier(newkey);this.env.contactfolders[newkey]=this.env.contactfolders[key];this.env.contactfolders[newkey].id=prop.newid;this.env.group=prop.newid;delete this.env.contactfolders[key];delete this.env.contactgroups[key];newprop.id=prop.newid;newprop.type="group";link=$("<a>").attr("href","#").attr("rel",prop.source+":"+prop.newid).click(function(){return rcmail.command("listgroup",newprop,this)}).html(prop.name);$(li).children().replaceWith(link)}else{if(li&&(link=li.firstChild)&&link.tagName.toLowerCase()=="a"){link.innerHTML=prop.name}}this.env.contactfolders[key].name=this.env.contactgroups[key].name=prop.name;this.add_contact_group_row(prop,$(li),true);this.triggerEvent("group_update",{id:prop.id,source:prop.source,name:prop.name,li:li[0],newid:prop.newid})};this.add_contact_group_row=function(prop,li,reloc){var row,name=prop.name.toUpperCase(),sibling=this.get_folder_li(prop.source),prefix="rcmliG"+this.html_identifier(prop.source);if(reloc){row=li.clone(true);li.remove()}else{row=li}$('li[id^="'+prefix+'"]',this.gui_objects.folderlist).each(function(i,elem){if(name>=$(this).text().toUpperCase()){sibling=elem}else{return false}});row.insertAfter(sibling)};this.update_group_commands=function(){var source=this.env.source!=""?this.env.address_sources[this.env.source]:null;this.enable_command("group-create",(source&&source.groups&&!source.readonly));this.enable_command("group-rename","group-delete",(source&&source.groups&&this.env.group&&!source.readonly))};this.init_edit_field=function(col,elem){var label=this.env.coltypes[col].label;if(!elem){elem=$(".ff_"+col)}if(label){elem.placeholder(label)}};this.insert_edit_field=function(col,section,menu){var elem=$("#ff_"+col);if(elem.length){elem.show().focus();$(menu).children('option[value="'+col+'"]').prop("disabled",true)}else{var lastelem=$(".ff_"+col),appendcontainer=$("#contactsection"+section+" .contactcontroller"+col);if(!appendcontainer.length){var sect=$("#contactsection"+section),lastgroup=$(".contactfieldgroup",sect).last();appendcontainer=$("<fieldset>").addClass("contactfieldgroup contactcontroller"+col);if(lastgroup.length){appendcontainer.insertAfter(lastgroup)}else{sect.prepend(appendcontainer)}}if(appendcontainer.length&&appendcontainer.get(0).nodeName=="FIELDSET"){var input,colprop=this.env.coltypes[col],row=$("<div>").addClass("row"),cell=$("<div>").addClass("contactfieldcontent data"),label=$("<div>").addClass("contactfieldlabel label");if(colprop.subtypes_select){label.html(colprop.subtypes_select)}else{label.html(colprop.label)}var name_suffix=colprop.limit!=1?"[]":"";if(colprop.type=="text"||colprop.type=="date"){input=$("<input>").addClass("ff_"+col).attr({type:"text",name:"_"+col+name_suffix,size:colprop.size}).appendTo(cell);this.init_edit_field(col,input);if(colprop.type=="date"&&$.datepicker){input.datepicker()}}else{if(colprop.type=="textarea"){input=$("<textarea>").addClass("ff_"+col).attr({name:"_"+col+name_suffix,cols:colprop.size,rows:colprop.rows}).appendTo(cell);this.init_edit_field(col,input)}else{if(colprop.type=="composite"){var childcol,cp,first,templ,cols=[],suffices=[];if((templ=this.env[col+"_template"])){for(var j=0;j<templ.length;j++){cols.push(templ[j][1]);suffices.push(templ[j][2])}}else{for(childcol in colprop.childs){cols.push(childcol)}}for(var i=0;i<cols.length;i++){childcol=cols[i];cp=colprop.childs[childcol];input=$("<input>").addClass("ff_"+childcol).attr({type:"text",name:"_"+childcol+name_suffix,size:cp.size}).appendTo(cell);cell.append(suffices[i]||" ");this.init_edit_field(childcol,input);if(!first){first=input}}input=first}else{if(colprop.type=="select"){input=$("<select>").addClass("ff_"+col).attr("name","_"+col+name_suffix).appendTo(cell);var options=input.attr("options");options[options.length]=new Option("---","");if(colprop.options){$.each(colprop.options,function(i,val){options[options.length]=new Option(val,i)})}}}}}if(input){var delbutton=$('<a href="#del"></a>').addClass("contactfieldbutton deletebutton").attr({title:this.get_label("delete"),rel:col}).html(this.env.delbutton).click(function(){ref.delete_edit_field(this);return false}).appendTo(cell);row.append(label).append(cell).appendTo(appendcontainer.show());input.first().focus();if(!colprop.count){colprop.count=0}if(++colprop.count==colprop.limit&&colprop.limit){$(menu).children('option[value="'+col+'"]').prop("disabled",true)}}}}};this.delete_edit_field=function(elem){var col=$(elem).attr("rel"),colprop=this.env.coltypes[col],fieldset=$(elem).parents("fieldset.contactfieldgroup"),addmenu=fieldset.parent().find("select.addfieldmenu");if(--colprop.count<=0&&colprop.visible){$(elem).parent().children("input").val("").blur()}else{$(elem).parents("div.row").remove();if(!fieldset.children("div.row").length){fieldset.hide()}}if(addmenu.length){var option=addmenu.children('option[value="'+col+'"]');if(option.length){option.prop("disabled",false)}else{option=$("<option>").attr("value",col).html(colprop.label).appendTo(addmenu)}addmenu.show()}};this.upload_contact_photo=function(form){if(form&&form.elements._photo.value){this.async_upload_form(form,"upload-photo",function(e){rcmail.set_busy(false,null,rcmail.file_upload_id)});this.file_upload_id=this.set_busy(true,"uploading")}};this.replace_contact_photo=function(id){var img_src=id=="-del-"?this.env.photo_placeholder:this.env.comm_path+"&_action=photo&_source="+this.env.source+"&_cid="+this.env.cid+"&_photo="+id;this.set_photo_actions(id);$(this.gui_objects.contactphoto).children("img").attr("src",img_src)};this.photo_upload_end=function(){this.set_busy(false,null,this.file_upload_id);delete this.file_upload_id};this.set_photo_actions=function(id){var n,buttons=this.buttons["upload-photo"];for(n=0;buttons&&n<buttons.length;n++){$("a#"+buttons[n].id).html(this.get_label(id=="-del-"?"addphoto":"replacephoto"))}$("#ff_photo").val(id);this.enable_command("upload-photo",this.env.coltypes.photo?true:false);this.enable_command("delete-photo",this.env.coltypes.photo&&id!="-del-")};this.advanced_search=function(){var win,url={_form:1,_action:"search"},target=window;if(win=this.get_frame_window(this.env.contentframe)){url._framed=1;target=win;this.contact_list.clear_selection()}this.location_href(url,target,true);return true};this.unselect_directory=function(){this.select_folder("");this.enable_command("search-delete",false)};this.insert_saved_search=function(name,id){this.reset_add_input();var key="S"+id,link=$("<a>").attr("href","#").attr("rel",id).click(function(){return rcmail.command("listsearch",id,this)}).html(name),li=$("<li>").attr({id:"rcmli"+this.html_identifier(key),"class":"contactsearch"}).append(link),prop={name:name,id:id,li:li[0]};this.add_saved_search_row(prop,li);this.select_folder("S"+id);this.enable_command("search-delete",true);this.env.search_id=id;this.triggerEvent("abook_search_insert",prop)};this.add_saved_search_row=function(prop,li,reloc){var row,sibling,name=prop.name.toUpperCase();if(reloc){row=li.clone(true);li.remove()}else{row=li}$('li[class~="contactsearch"]',this.gui_objects.folderlist).each(function(i,elem){if(!sibling){sibling=this.previousSibling}if(name>=$(this).text().toUpperCase()){sibling=elem}else{return false}});if(sibling){row.insertAfter(sibling)}else{row.appendTo(this.gui_objects.folderlist)}};this.search_create=function(){this.add_input_row("contactsearch")};this.search_delete=function(){if(this.env.search_request){var lock=this.set_busy(true,"savedsearchdeleting");this.http_post("search-delete",{_sid:this.env.search_id},lock)}};this.remove_search_item=function(id){var li,key="S"+id;if((li=this.get_folder_li(key))){this.triggerEvent("search_delete",{id:id,li:li});li.parentNode.removeChild(li)}this.env.search_id=null;this.env.search_request=null;this.list_contacts_clear();this.reset_qsearch();this.enable_command("search-delete","search-create",false)};this.listsearch=function(id){var folder,lock=this.set_busy(true,"searching");if(this.contact_list){this.list_contacts_clear()}this.reset_qsearch();this.select_folder("S"+id);this.env.current_page=1;this.http_request("search",{_sid:id},lock)};this.section_select=function(list){var win,id=list.get_single_selection(),target=window,url={_action:"edit-prefs",_section:id};if(id){if(win=this.get_frame_window(this.env.contentframe)){url._framed=1;target=win}this.location_href(url,target,true)}return true};this.identity_select=function(list){var id;if(id=list.get_single_selection()){this.enable_command("delete",list.rowcount>1&&this.env.identities_level<2);this.load_identity(id,"edit-identity")}};this.load_identity=function(id,action){if(action=="edit-identity"&&(!id||id==this.env.iid)){return false}var win,target=window,url={_action:action,_iid:id};if(win=this.get_frame_window(this.env.contentframe)){url._framed=1;target=win}if(action&&(id||action=="add-identity")){this.set_busy(true);this.location_href(url,target)}return true};this.delete_identity=function(id){var selection=this.identity_list.get_selection();if(!(selection.length||this.env.iid)){return}if(!id){id=this.env.iid?this.env.iid:selection[0]}if(confirm(this.get_label("deleteidentityconfirm"))){this.goto_url("delete-identity",{_iid:id,_token:this.env.request_token},true)}return true};this.update_identity_row=function(id,name,add){var row,col,list=this.identity_list,rid=this.html_identifier(id);if(list.rows[rid]&&(row=list.rows[rid].obj)){$(row.cells[0]).html(name)}else{if(add){row=$("<tr>").attr("id","rcmrow"+rid).get(0);col=$("<td>").addClass("mail").html(name).appendTo(row);list.insert_row(row);list.select(rid)}}};this.init_subscription_list=function(){var p=this;this.subscription_list=new rcube_list_widget(this.gui_objects.subscriptionlist,{multiselect:false,draggable:true,keyboard:false,toggleselect:true});this.subscription_list.addEventListener("select",function(o){p.subscription_select(o)});this.subscription_list.addEventListener("dragstart",function(o){p.drag_active=true});this.subscription_list.addEventListener("dragend",function(o){p.subscription_move_folder(o)});this.subscription_list.row_init=function(row){row.obj.onmouseover=function(){p.focus_subscription(row.id)};row.obj.onmouseout=function(){p.unfocus_subscription(row.id)}};this.subscription_list.init();$("#mailboxroot").mouseover(function(){p.focus_subscription(this.id)}).mouseout(function(){p.unfocus_subscription(this.id)})};this.focus_subscription=function(id){var row,folder,delim=RegExp.escape(this.env.delimiter),reg=RegExp("["+delim+"]?[^"+delim+"]+$");if(this.drag_active&&this.env.mailbox&&(row=document.getElementById(id))){if(this.env.subscriptionrows[id]&&(folder=this.env.subscriptionrows[id][0])!==null){if(this.check_droptarget(folder)&&!this.env.subscriptionrows[this.get_folder_row_id(this.env.mailbox)][2]&&(folder!=this.env.mailbox.replace(reg,""))&&(!folder.match(new RegExp("^"+RegExp.escape(this.env.mailbox+this.env.delimiter))))){this.env.dstfolder=folder;$(row).addClass("droptarget")}}}};this.unfocus_subscription=function(id){var row=$("#"+id);this.env.dstfolder=null;if(this.env.subscriptionrows[id]&&row[0]){row.removeClass("droptarget")}else{$(this.subscription_list.frame).removeClass("droptarget")}};this.subscription_select=function(list){var id,folder;if(list&&(id=list.get_single_selection())&&(folder=this.env.subscriptionrows["rcmrow"+id])){this.env.mailbox=folder[0];this.show_folder(folder[0]);this.enable_command("delete-folder",!folder[2])}else{this.env.mailbox=null;this.show_contentframe(false);this.enable_command("delete-folder","purge",false)}};this.subscription_move_folder=function(list){var delim=RegExp.escape(this.env.delimiter),reg=RegExp("["+delim+"]?[^"+delim+"]+$");if(this.env.mailbox&&this.env.dstfolder!==null&&(this.env.dstfolder!=this.env.mailbox)&&(this.env.dstfolder!=this.env.mailbox.replace(reg,""))){reg=new RegExp("[^"+delim+"]*["+delim+"]","g");var basename=this.env.mailbox.replace(reg,""),newname=this.env.dstfolder===""?basename:this.env.dstfolder+this.env.delimiter+basename;if(newname!=this.env.mailbox){this.http_post("rename-folder",{_folder_oldname:this.env.mailbox,_folder_newname:newname},this.set_busy(true,"foldermoving"));this.subscription_list.draglayer.hide()}}this.drag_active=false;this.unfocus_subscription(this.get_folder_row_id(this.env.dstfolder))};this.create_folder=function(){this.show_folder("",this.env.mailbox)};this.delete_folder=function(name){var id=this.get_folder_row_id(name?name:this.env.mailbox),folder=this.env.subscriptionrows[id][0];if(folder&&confirm(this.get_label("deletefolderconfirm"))){var lock=this.set_busy(true,"folderdeleting");this.http_post("delete-folder",{_mbox:folder},lock)}};this.add_folder_row=function(name,display_name,is_protected,subscribed,skip_init,class_name){if(!this.gui_objects.subscriptionlist){return false}var row,n,i,tmp,tmp_name,folders,rowid,list=[],slist=[],tbody=this.gui_objects.subscriptionlist.tBodies[0],refrow=$("tr",tbody).get(1),id="rcmrow"+((new Date).getTime());if(!refrow){this.goto_url("folders");return false}row=$(refrow).clone(true);row.attr("id",id);row.attr("class",class_name);row.find("td:first").html(display_name);$('input[name="_subscribed[]"]',row).val(name).prop({checked:subscribed?true:false,disabled:is_protected?true:false});this.env.subscriptionrows[id]=[name,display_name,0];folders=[];$.each(this.env.subscriptionrows,function(k,v){folders.push(v)});folders.sort(function(a,b){return a[0]<b[0]?-1:(a[0]>b[0]?1:0)});for(n in folders){if(folders[n][2]){tmp_name=folders[n][0]+this.env.delimiter;if(tmp_name==this.env.prefix_ns){continue}slist.push(folders[n][0]);tmp=tmp_name}else{if(tmp&&folders[n][0].indexOf(tmp)==0){slist.push(folders[n][0])}else{list.push(folders[n][0]);tmp=null}}}for(n=0;n<slist.length;n++){if(name.indexOf(slist[n]+this.env.delimiter)==0){rowid=this.get_folder_row_id(slist[n])}}for(n=0;!rowid&&n<list.length;n++){if(n&&list[n]==name){rowid=this.get_folder_row_id(list[n-1])}}if(rowid){$("#"+rowid).after(row)}else{row.appendTo(tbody)}this.subscription_list.clear_selection();if(!skip_init){this.init_subscription_list()}row=row.get(0);if(row.scrollIntoView){row.scrollIntoView()}return row};this.replace_folder_row=function(oldfolder,newfolder,display_name,is_protected,class_name){if(!this.gui_objects.subscriptionlist){return false}var i,n,len,name,dispname,oldrow,tmprow,row,level,tbody=this.gui_objects.subscriptionlist.tBodies[0],folders=this.env.subscriptionrows,id=this.get_folder_row_id(oldfolder),regex=new RegExp("^"+RegExp.escape(oldfolder)),subscribed=$('input[name="_subscribed[]"]',$("#"+id)).prop("checked"),list=this.get_subfolders(oldfolder);this._remove_folder_row(id);row=$(this.add_folder_row(newfolder,display_name,is_protected,subscribed,true,class_name));if(len=list.length){level=(oldfolder.split(this.env.delimiter)).length-(newfolder.split(this.env.delimiter)).length}for(n=0;n<len;n++){id=list[n];name=this.env.subscriptionrows[id][0];dispname=this.env.subscriptionrows[id][1];oldrow=$("#"+id);tmprow=oldrow.clone(true);oldrow.remove();row.after(tmprow);row=tmprow;name=name.replace(regex,newfolder);$('input[name="_subscribed[]"]',row).val(name);this.env.subscriptionrows[id][0]=name;if(level!=0){if(level>0){for(i=level;i>0;i--){dispname=dispname.replace(/^ /,"")}}else{for(i=level;i<0;i++){dispname=" "+dispname}}row.find("td:first").html(dispname);this.env.subscriptionrows[id][1]=dispname}}this.init_subscription_list()};this.remove_folder_row=function(folder,subs){var n,len,list=[],id=this.get_folder_row_id(folder);if(subs){list=this.get_subfolders(folder)}this._remove_folder_row(id);for(n=0,len=list.length;n<len;n++){this._remove_folder_row(list[n])}};this._remove_folder_row=function(id){this.subscription_list.remove_row(id.replace(/^rcmrow/,""));$("#"+id).remove();delete this.env.subscriptionrows[id]};this.get_subfolders=function(folder){var name,list=[],regex=new RegExp("^"+RegExp.escape(folder)+RegExp.escape(this.env.delimiter)),row=$("#"+this.get_folder_row_id(folder)).get(0);while(row=row.nextSibling){if(row.id){name=this.env.subscriptionrows[row.id][0];if(regex.test(name)){list.push(row.id)}else{break}}}return list};this.subscribe=function(folder){if(folder){var lock=this.display_message(this.get_label("foldersubscribing"),"loading");this.http_post("subscribe",{_mbox:folder},lock)}};this.unsubscribe=function(folder){if(folder){var lock=this.display_message(this.get_label("folderunsubscribing"),"loading");this.http_post("unsubscribe",{_mbox:folder},lock)}};this.get_folder_row_id=function(folder){var id,folders=this.env.subscriptionrows;for(id in folders){if(folders[id]&&folders[id][0]==folder){break}}return id};this.show_folder=function(folder,path,force){var win,target=window,url="&_action=edit-folder&_mbox="+urlencode(folder);if(path){url+="&_path="+urlencode(path)}if(win=this.get_frame_window(this.env.contentframe)){target=win;url+="&_framed=1"}if(String(target.location.href).indexOf(url)>=0&&!force){this.show_contentframe(true)}else{this.location_href(this.env.comm_path+url,target,true)}};this.disable_subscription=function(folder){var id=this.get_folder_row_id(folder);if(id){$('input[name="_subscribed[]"]',$("#"+id)).prop("disabled",true)}};this.folder_size=function(folder){var lock=this.set_busy(true,"loading");this.http_post("folder-size",{_mbox:folder},lock)};this.folder_size_update=function(size){$("#folder-size").replaceWith(size)};var init_button=function(cmd,prop){var elm=document.getElementById(prop.id);if(!elm){return}var preload=false;if(prop.type=="image"){elm=elm.parentNode;preload=true}elm._command=cmd;elm._id=prop.id;if(prop.sel){elm.onmousedown=function(e){return rcmail.button_sel(this._command,this._id)};elm.onmouseup=function(e){return rcmail.button_out(this._command,this._id)};if(preload){new Image().src=prop.sel}}if(prop.over){elm.onmouseover=function(e){return rcmail.button_over(this._command,this._id)};elm.onmouseout=function(e){return rcmail.button_out(this._command,this._id)};if(preload){new Image().src=prop.over}}};this.init_buttons=function(){for(var cmd in this.buttons){if(typeof cmd!=="string"){continue}for(var i=0;i<this.buttons[cmd].length;i++){init_button(cmd,this.buttons[cmd][i])}}this.set_button(this.task,"sel")};this.set_button=function(command,state){var n,button,obj,a_buttons=this.buttons[command],len=a_buttons?a_buttons.length:0;for(n=0;n<len;n++){button=a_buttons[n];obj=document.getElementById(button.id);if(!obj){continue}if(button.type=="image"&&!button.status){button.pas=obj._original_src?obj._original_src:obj.src;if(obj.runtimeStyle&&obj.runtimeStyle.filter&&obj.runtimeStyle.filter.match(/src=['"]([^'"]+)['"]/)){button.pas=RegExp.$1}}else{if(!button.status){button.pas=String(obj.className)}}if(button.type=="image"&&button[state]){button.status=state;obj.src=button[state]}else{if(button[state]!==undefined){button.status=state;obj.className=button[state]}}if(button.type=="input"){button.status=state;obj.disabled=!state}}};this.set_alttext=function(command,label){var n,button,obj,link,a_buttons=this.buttons[command],len=a_buttons?a_buttons.length:0;for(n=0;n<len;n++){button=a_buttons[n];obj=document.getElementById(button.id);if(button.type=="image"&&obj){obj.setAttribute("alt",this.get_label(label));if((link=obj.parentNode)&&link.tagName.toLowerCase()=="a"){link.setAttribute("title",this.get_label(label))}}else{if(obj){obj.setAttribute("title",this.get_label(label))}}}};this.button_over=function(command,id){var n,button,obj,a_buttons=this.buttons[command],len=a_buttons?a_buttons.length:0;for(n=0;n<len;n++){button=a_buttons[n];if(button.id==id&&button.status=="act"){obj=document.getElementById(button.id);if(obj&&button.over){if(button.type=="image"){obj.src=button.over}else{obj.className=button.over}}}}};this.button_sel=function(command,id){var n,button,obj,a_buttons=this.buttons[command],len=a_buttons?a_buttons.length:0;for(n=0;n<len;n++){button=a_buttons[n];if(button.id==id&&button.status=="act"){obj=document.getElementById(button.id);if(obj&&button.sel){if(button.type=="image"){obj.src=button.sel}else{obj.className=button.sel}}this.buttons_sel[id]=command}}};this.button_out=function(command,id){var n,button,obj,a_buttons=this.buttons[command],len=a_buttons?a_buttons.length:0;for(n=0;n<len;n++){button=a_buttons[n];if(button.id==id&&button.status=="act"){obj=document.getElementById(button.id);if(obj&&button.act){if(button.type=="image"){obj.src=button.act}else{obj.className=button.act}}}}};this.set_pagetitle=function(title){if(title&&document.title){document.title=title}};this.display_message=function(msg,type,timeout){if(this.is_framed()){return parent.rcmail.display_message(msg,type,timeout)}if(!this.gui_objects.message){if(type!="loading"){this.pending_message=[msg,type,timeout]}return 1}type=type?type:"notice";var ref=this,key=this.html_identifier(msg),date=new Date(),id=type+date.getTime();if(!timeout){timeout=this.message_time*(type=="error"||type=="warning"?2:1)}if(type=="loading"){key="loading";timeout=this.env.request_timeout*1000;if(!msg){msg=this.get_label("loading")}}if(this.messages[key]){if(this.messages[key].obj){this.messages[key].obj.html(msg)}if(type=="loading"){this.messages[key].labels.push({id:id,msg:msg})}this.messages[key].elements.push(id);setTimeout(function(){ref.hide_message(id,type=="loading")},timeout);return id}var obj=$("<div>").addClass(type).html(msg).data("key",key),cont=$(this.gui_objects.message).append(obj).show();this.messages[key]={obj:obj,elements:[id]};if(type=="loading"){this.messages[key].labels=[{id:id,msg:msg}]}else{obj.click(function(){return ref.hide_message(obj)})}this.triggerEvent("message",{message:msg,type:type,timeout:timeout,object:obj});if(timeout>0){setTimeout(function(){ref.hide_message(id,type=="loading")},timeout)}return id};this.hide_message=function(obj,fade){if(this.is_framed()){return parent.rcmail.hide_message(obj,fade)}if(!this.gui_objects.message){return}var k,n,i,msg,m=this.messages;if(typeof obj==="object"){$(obj)[fade?"fadeOut":"hide"]();msg=$(obj).data("key");if(this.messages[msg]){delete this.messages[msg]}}else{for(k in m){for(n in m[k].elements){if(m[k]&&m[k].elements[n]==obj){m[k].elements.splice(n,1);if(!m[k].elements.length){m[k].obj[fade?"fadeOut":"hide"]();delete m[k]}else{if(k=="loading"){for(i in m[k].labels){if(m[k].labels[i].id==obj){delete m[k].labels[i]}else{msg=m[k].labels[i].msg}m[k].obj.html(msg)}}}}}}}};this.clear_messages=function(){if(this.is_framed()){return parent.rcmail.clear_messages()}var k,n,m=this.messages;for(k in m){for(n in m[k].elements){if(m[k].obj){m[k].obj.hide()}}}this.messages={}};this.show_popup_dialog=function(html,title){if(this.is_framed()){parent.rcmail.show_popup_dialog(html,title);return}var popup=$('<div class="popup">').html(html).dialog({title:title,modal:true,resizable:true,width:580,close:function(event,ui){$(this).remove()}});var win=$(window),w=win.width(),h=win.height(),width=popup.width(),height=popup.height();popup.dialog("option",{height:Math.min(h-40,height+50),width:Math.min(w-20,width+50)}).dialog("option","position",["center","center"])};this.set_page_buttons=function(){this.enable_command("nextpage","lastpage",(this.env.pagecount>this.env.current_page));this.enable_command("previouspage","firstpage",(this.env.current_page>1))};this.select_folder=function(name,prefix,encode){if(this.gui_objects.folderlist){var current_li,target_li;if((current_li=$("li.selected",this.gui_objects.folderlist))){current_li.removeClass("selected").addClass("unfocused")}if((target_li=this.get_folder_li(name,prefix,encode))){$(target_li).removeClass("unfocused").addClass("selected")}this.triggerEvent("selectfolder",{folder:name,prefix:prefix})}};this.mark_folder=function(name,class_name,prefix,encode){$(this.get_folder_li(name,prefix,encode)).addClass(class_name)};this.unmark_folder=function(name,class_name,prefix,encode){$(this.get_folder_li(name,prefix,encode)).removeClass(class_name)};this.get_folder_li=function(name,prefix,encode){if(!prefix){prefix="rcmli"}if(this.gui_objects.folderlist){name=this.html_identifier(name,encode);return document.getElementById(prefix+name)}return null};this.set_message_coltypes=function(coltypes,repl,smart_col){var list=this.message_list,thead=list?list.list.tHead:null,cell,col,n,len,th,tr;this.env.coltypes=coltypes;if(thead){if(repl){th=document.createElement("thead");tr=document.createElement("tr");for(c=0,len=repl.length;c<len;c++){cell=document.createElement("td");cell.innerHTML=repl[c].html||"";if(repl[c].id){cell.id=repl[c].id}if(repl[c].className){cell.className=repl[c].className}tr.appendChild(cell)}th.appendChild(tr);thead.parentNode.replaceChild(th,thead);list.thead=thead=th}for(n=0,len=this.env.coltypes.length;n<len;n++){col=this.env.coltypes[n];if((cell=thead.rows[0].cells[n])&&(col=="from"||col=="to"||col=="fromto")){cell.id="rcm"+col;$("span,a",cell).text(this.get_label(col=="fromto"?smart_col:col));$("a",cell).click(function(){return rcmail.command("sort",this.id.replace(/^rcm/,""),this)})}}}this.env.subject_col=null;this.env.flagged_col=null;this.env.status_col=null;if((n=$.inArray("subject",this.env.coltypes))>=0){this.env.subject_col=n;if(list){list.subject_col=n}}if((n=$.inArray("flag",this.env.coltypes))>=0){this.env.flagged_col=n}if((n=$.inArray("status",this.env.coltypes))>=0){this.env.status_col=n}if(list){list.init_header()}};this.set_rowcount=function(text,mbox){if(mbox&&mbox!=this.env.mailbox){return false}$(this.gui_objects.countdisplay).html(text);this.set_page_buttons()};this.set_mailboxname=function(content){if(this.gui_objects.mailboxname&&content){this.gui_objects.mailboxname.innerHTML=content}};this.set_quota=function(content){if(this.gui_objects.quotadisplay&&content&&content.type=="text"){$(this.gui_objects.quotadisplay).html(content.percent+"%").attr("title",content.title)}this.triggerEvent("setquota",content);this.env.quota_content=content};this.set_unread_count=function(mbox,count,set_title,mark){if(!this.gui_objects.mailboxlist){return false}this.env.unread_counts[mbox]=count;this.set_unread_count_display(mbox,set_title);if(mark){this.mark_folder(mbox,mark,"",true)}else{if(!count){this.unmark_folder(mbox,"recent","",true)}}};this.set_unread_count_display=function(mbox,set_title){var reg,link,text_obj,item,mycount,childcount,div;if(item=this.get_folder_li(mbox,"",true)){mycount=this.env.unread_counts[mbox]?this.env.unread_counts[mbox]:0;link=$(item).children("a").eq(0);text_obj=link.children("span.unreadcount");if(!text_obj.length&&mycount){text_obj=$("<span>").addClass("unreadcount").appendTo(link)}reg=/\s+\([0-9]+\)$/i;childcount=0;if((div=item.getElementsByTagName("div")[0])&&div.className.match(/collapsed/)){for(var k in this.env.unread_counts){if(k.indexOf(mbox+this.env.delimiter)==0){childcount+=this.env.unread_counts[k]}}}if(mycount&&text_obj.length){text_obj.html(this.env.unreadwrap.replace(/%[sd]/,mycount))}else{if(text_obj.length){text_obj.remove()}}reg=new RegExp(RegExp.escape(this.env.delimiter)+"[^"+RegExp.escape(this.env.delimiter)+"]+$");if(mbox.match(reg)){this.set_unread_count_display(mbox.replace(reg,""),false)}if((mycount+childcount)>0){$(item).addClass("unread")}else{$(item).removeClass("unread")}}reg=/^\([0-9]+\)\s+/i;if(set_title&&document.title){var new_title="",doc_title=String(document.title);if(mycount&&doc_title.match(reg)){new_title=doc_title.replace(reg,"("+mycount+") ")}else{if(mycount){new_title="("+mycount+") "+doc_title}else{new_title=doc_title.replace(reg,"")}}this.set_pagetitle(new_title)}};this.set_headers=function(content){if(this.gui_objects.all_headers_row&&this.gui_objects.all_headers_box&&content){$(this.gui_objects.all_headers_box).html(content).show()}};this.show_headers=function(props,elem){if(!this.gui_objects.all_headers_row||!this.gui_objects.all_headers_box||!this.env.uid){return}$(elem).removeClass("show-headers").addClass("hide-headers");$(this.gui_objects.all_headers_row).show();elem.onclick=function(){rcmail.command("hide-headers","",elem)};if(!this.gui_objects.all_headers_box.innerHTML){var lock=this.display_message(this.get_label("loading"),"loading");this.http_post("headers",{_uid:this.env.uid},lock)}};this.hide_headers=function(props,elem){if(!this.gui_objects.all_headers_row||!this.gui_objects.all_headers_box){return}$(elem).removeClass("hide-headers").addClass("show-headers");$(this.gui_objects.all_headers_row).hide();elem.onclick=function(){rcmail.command("show-headers","",elem)}};this.html2plain=function(htmlText,id){var rcmail=this,url="?_task=utils&_action=html2text",lock=this.set_busy(true,"converting");this.log("HTTP POST: "+url);$.ajax({type:"POST",url:url,data:htmlText,contentType:"application/octet-stream",error:function(o,status,err){rcmail.http_error(o,status,err,lock)},success:function(data){rcmail.set_busy(false,null,lock);$("#"+id).val(data);rcmail.log(data)}})};this.plain2html=function(plain,id){var lock=this.set_busy(true,"converting");plain=plain.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");$("#"+id).val(plain?"<pre>"+plain+"</pre>":"");this.set_busy(false,null,lock)};this.url=function(action,query){var querystring=typeof query==="string"?"&"+query:"";if(typeof action!=="string"){query=action}else{if(!query||typeof query!=="object"){query={}}}if(action){query._action=action}else{query._action=this.env.action}var base=this.env.comm_path,k,param={};if(query._action.match(/([a-z]+)\/([a-z0-9-_.]+)/)){query._action=RegExp.$2;base=base.replace(/\_task=[a-z]+/,"_task="+RegExp.$1)}for(k in query){if(query[k]!==undefined&&query[k]!==null){param[k]=query[k]}}return base+"&"+$.param(param)+querystring};this.redirect=function(url,lock){if(lock||lock===null){this.set_busy(true)}if(this.is_framed()){parent.rcmail.redirect(url,lock)}else{if(this.env.extwin){if(typeof url=="string"){url+=(url.indexOf("?")<0?"?":"&")+"_extwin=1"}else{url._extwin=1}}this.location_href(url,window)}};this.goto_url=function(action,query,lock){this.redirect(this.url(action,query))};this.location_href=function(url,target,frame){if(frame){this.lock_frame()}if(typeof url=="object"){url=this.env.comm_path+"&"+$.param(url)}if(bw.ie&&target==window){$("<a>").attr("href",url).appendTo(document.body).get(0).click()}else{target.location.href=url}this.start_keepalive()};this.http_request=function(action,query,lock){var url=this.url(action,query);var result=this.triggerEvent("request"+action,query);if(result!==undefined){if(result===false){return false}else{query=result}}url+="&_remote=1";this.log("HTTP GET: "+url);this.start_keepalive();return $.ajax({type:"GET",url:url,data:{_unlock:(lock?lock:0)},dataType:"json",success:function(data){ref.http_response(data)},error:function(o,status,err){ref.http_error(o,status,err,lock,action)}})};this.http_post=function(action,postdata,lock){var url=this.url(action);if(postdata&&typeof postdata==="object"){postdata._remote=1;postdata._unlock=(lock?lock:0)}else{postdata+=(postdata?"&":"")+"_remote=1"+(lock?"&_unlock="+lock:"")}var result=this.triggerEvent("request"+action,postdata);if(result!==undefined){if(result===false){return false}else{postdata=result}}this.log("HTTP POST: "+url);this.start_keepalive();return $.ajax({type:"POST",url:url,data:postdata,dataType:"json",success:function(data){ref.http_response(data)},error:function(o,status,err){ref.http_error(o,status,err,lock,action)}})};this.abort_request=function(r){if(r.request){r.request.abort()}if(r.lock){this.set_busy(false,null,r.lock)}};this.http_response=function(response){if(!response){return}if(response.unlock){this.set_busy(false)}this.triggerEvent("responsebefore",{response:response});this.triggerEvent("responsebefore"+response.action,{response:response});if(response.env){this.set_env(response.env)}if(typeof response.texts==="object"){for(var name in response.texts){if(typeof response.texts[name]==="string"){this.add_label(name,response.texts[name])}}}if(response.exec){this.log(response.exec);eval(response.exec)}if(response.callbacks&&response.callbacks.length){for(var i=0;i<response.callbacks.length;i++){this.triggerEvent(response.callbacks[i][0],response.callbacks[i][1])}}switch(response.action){case"delete":if(this.task=="addressbook"){var sid,uid=this.contact_list.get_selection(),writable=false;if(uid&&this.contact_list.rows[uid]){if(this.env.source==""){sid=String(uid).replace(/^[^-]+-/,"");writable=sid&&this.env.address_sources[sid]&&!this.env.address_sources[sid].readonly}else{writable=!this.env.address_sources[this.env.source].readonly}}this.enable_command("compose",(uid&&this.contact_list.rows[uid]));this.enable_command("delete","edit",writable);this.enable_command("export",(this.contact_list&&this.contact_list.rowcount>0))}case"moveto":if(this.env.action=="show"){this.enable_command(this.env.message_commands,true);if(!this.env.list_post){this.enable_command("reply-list",false)}}else{if(this.task=="addressbook"){this.triggerEvent("listupdate",{folder:this.env.source,rowcount:this.contact_list.rowcount})}}case"purge":case"expunge":if(this.task=="mail"){if(!this.env.exists){if(this.env.contentframe){this.show_contentframe(false)}this.enable_command(this.env.message_commands,"purge","expunge","select-all","select-none","expand-all","expand-unread","collapse-all",false)}if(this.message_list){this.triggerEvent("listupdate",{folder:this.env.mailbox,rowcount:this.message_list.rowcount})}}break;case"refresh":case"check-recent":case"getunread":case"search":this.env.qsearch=null;case"list":if(this.task=="mail"){this.enable_command("show","select-all","select-none",this.env.messagecount>0);this.enable_command("expunge",this.env.exists);this.enable_command("purge",this.purge_mailbox_test());this.enable_command("expand-all","expand-unread","collapse-all",this.env.threading&&this.env.messagecount);if((response.action=="list"||response.action=="search")&&this.message_list){this.msglist_select(this.message_list);this.triggerEvent("listupdate",{folder:this.env.mailbox,rowcount:this.message_list.rowcount})}}else{if(this.task=="addressbook"){this.enable_command("export",(this.contact_list&&this.contact_list.rowcount>0));if(response.action=="list"||response.action=="search"){this.enable_command("search-create",this.env.source=="");this.enable_command("search-delete",this.env.search_id);this.update_group_commands();this.triggerEvent("listupdate",{folder:this.env.source,rowcount:this.contact_list.rowcount})}}}break}if(response.unlock){this.hide_message(response.unlock)}this.triggerEvent("responseafter",{response:response});this.triggerEvent("responseafter"+response.action,{response:response});this.start_keepalive()};this.http_error=function(request,status,err,lock,action){var errmsg=request.statusText;this.set_busy(false,null,lock);request.abort();if(this.unload){return}if(request.status&&errmsg){this.display_message(this.get_label("servererror")+" ("+errmsg+")","error")}else{if(status=="timeout"){this.display_message(this.get_label("requesttimedout"),"error")}else{if(request.status==0&&status!="abort"){this.display_message(this.get_label("servererror")+" (No connection)","error")}}}var location_url=request.getResponseHeader("Location");if(location_url&&this.env.action!="compose"){this.redirect(location_url)}if(request.status==403){(this.is_framed()?parent:window).location.reload();return}if(action=="keep-alive"){setTimeout(function(){ref.keep_alive();ref.start_keepalive()},30000)}};this.iframe_loaded=function(unlock){this.set_busy(false,null,unlock);if(this.submit_timer){clearTimeout(this.submit_timer)}};this.async_upload_form=function(form,action,onload){var frame,ts=new Date().getTime(),frame_name="rcmupload"+ts;if(this.env.upload_progress_name){var fname=this.env.upload_progress_name,field=$("input[name="+fname+"]",form);if(!field.length){field=$("<input>").attr({type:"hidden",name:fname});field.prependTo(form)}field.val(ts)}if(document.all){document.body.insertAdjacentHTML("BeforeEnd",'<iframe name="'+frame_name+'" src="program/resources/blank.gif" style="width:0;height:0;visibility:hidden;"></iframe>');frame=$('iframe[name="'+frame_name+'"]')}else{frame=$("<iframe>").attr("name",frame_name).css({border:"none",width:0,height:0,visibility:"hidden"}).appendTo(document.body)}frame.bind("load",{ts:ts},onload);$(form).attr({target:frame_name,action:this.url(action,{_id:this.env.compose_id||"",_uploadid:ts}),method:"POST"}).attr(form.encoding?"encoding":"enctype","multipart/form-data").submit();return frame_name};this.document_drag_hover=function(e,over){e.preventDefault();$(ref.gui_objects.filedrop)[(over?"addClass":"removeClass")]("active")};this.file_drag_hover=function(e,over){e.preventDefault();e.stopPropagation();$(ref.gui_objects.filedrop)[(over?"addClass":"removeClass")]("hover")};this.file_dropped=function(e){this.file_drag_hover(e,false);var files=e.target.files||e.dataTransfer.files,formdata=window.FormData?new FormData():null,fieldname=(this.env.filedrop.fieldname||"_file")+(this.env.filedrop.single?"":"[]"),boundary="------multipartformboundary"+(new Date).getTime(),dashdash="--",crlf="\r\n",multipart=dashdash+boundary+crlf;if(!files||!files.length){return}var submit_data=function(){var multiple=files.length>1,ts=new Date().getTime(),content="<span>"+(multiple?ref.get_label("uploadingmany"):files[0].name)+"</span>";if(!ref.add2attachment_list(ts,{name:"",html:content,classname:"uploading",complete:false})){ref.file_upload_id=ref.set_busy(true,"uploading")}multipart+=dashdash+boundary+dashdash+crlf;$.ajax({type:"POST",dataType:"json",url:ref.url(ref.env.filedrop.action||"upload",{_id:ref.env.compose_id||ref.env.cid||"",_uploadid:ts,_remote:1}),contentType:formdata?false:"multipart/form-data; boundary="+boundary,processData:false,timeout:0,data:formdata||multipart,headers:{"X-Roundcube-Request":ref.env.request_token},xhr:function(){var xhr=jQuery.ajaxSettings.xhr();if(!formdata&&xhr.sendAsBinary){xhr.send=xhr.sendAsBinary}return xhr},success:function(data){ref.http_response(data)},error:function(o,status,err){ref.http_error(o,status,err,null,"attachment")}})};var last=this.env.filedrop.single?0:files.length-1;for(var j=0,i=0,f;j<=last&&(f=files[i]);i++){if(!f.name){f.name=f.fileName}if(!f.size){f.size=f.fileSize}if(!f.type){f.type="application/octet-stream"}if(!formdata&&/[^\x20-\x7E]/.test(f.name)){f.name_bin=unescape(encodeURIComponent(f.name))}if(this.env.filedrop.filter&&!f.type.match(new RegExp(this.env.filedrop.filter))){continue}if(formdata){formdata.append(fieldname,f);if(j==last){return submit_data()}}else{if(window.FileReader){var reader=new FileReader();reader.onload=(function(file,j){return function(e){multipart+='Content-Disposition: form-data; name="'+fieldname+'"';multipart+='; filename="'+(f.name_bin||file.name)+'"'+crlf;multipart+="Content-Length: "+file.size+crlf;multipart+="Content-Type: "+file.type+crlf+crlf;multipart+=reader.result+crlf;multipart+=dashdash+boundary+crlf;if(j==last){return submit_data()}}})(f,j);reader.readAsBinaryString(f)}else{if(f.getAsBinary){multipart+='Content-Disposition: form-data; name="'+fieldname+'"';multipart+='; filename="'+(f.name_bin||f.name)+'"'+crlf;multipart+="Content-Length: "+f.size+crlf;multipart+="Content-Type: "+f.type+crlf+crlf;multipart+=f.getAsBinary()+crlf;multipart+=dashdash+boundary+crlf;if(j==last){return submit_data()}}}}j++}};this.start_keepalive=function(){if(!this.env.session_lifetime||this.env.framed||this.env.extwin||this.task=="login"||this.env.action=="print"){return}if(this._keepalive){clearInterval(this._keepalive)}this._keepalive=setInterval(function(){ref.keep_alive()},this.env.session_lifetime*0.5*1000)};this.start_refresh=function(){if(!this.env.refresh_interval||this.env.framed||this.env.extwin||this.task=="login"||this.env.action=="print"){return}if(this._refresh){clearInterval(this._refresh)}this._refresh=setInterval(function(){ref.refresh()},this.env.refresh_interval*1000)};this.keep_alive=function(){if(!this.busy){this.http_request("keep-alive")}};this.refresh=function(){if(this.busy){setTimeout(function(){ref.refresh();ref.start_refresh()},10000);return}var params={},lock=this.set_busy(true,"refreshing");if(this.task=="mail"&&this.gui_objects.mailboxlist){params=this.check_recent_params()}this.http_request("refresh",params,lock)};this.check_recent_params=function(){var params={_mbox:this.env.mailbox};if(this.gui_objects.mailboxlist){params._folderlist=1}if(this.gui_objects.messagelist){params._list=1}if(this.gui_objects.quotadisplay){params._quota=1}if(this.env.search_request){params._search=this.env.search_request}return params};this.opener=function(){try{if(window.opener&&!opener.closed&&opener.rcmail){return opener.rcmail}}catch(e){}};this.get_single_uid=function(){return this.env.uid?this.env.uid:(this.message_list?this.message_list.get_single_selection():null)};this.get_single_cid=function(){return this.env.cid?this.env.cid:(this.contact_list?this.contact_list.get_single_selection():null)};this.get_caret_pos=function(obj){if(obj.selectionEnd!==undefined){return obj.selectionEnd}if(document.selection&&document.selection.createRange){var range=document.selection.createRange();if(range.parentElement()!=obj){return 0}var gm=range.duplicate();if(obj.tagName=="TEXTAREA"){gm.moveToElementText(obj)}else{gm.expand("textedit")}gm.setEndPoint("EndToStart",range);var p=gm.text.length;return p<=obj.value.length?p:-1}return obj.value.length};this.set_caret_pos=function(obj,pos){if(obj.setSelectionRange){obj.setSelectionRange(pos,pos)}else{if(obj.createTextRange){var range=obj.createTextRange();range.collapse(true);range.moveEnd("character",pos);range.moveStart("character",pos);range.select()}}};this.lock_form=function(form,lock){if(!form||!form.elements){return}var n,len,elm;if(lock){this.disabled_form_elements=[]}for(n=0,len=form.elements.length;n<len;n++){elm=form.elements[n];if(elm.type=="hidden"){continue}if(lock&&elm.disabled){this.disabled_form_elements.push(elm)}else{if(lock||(this.disabled_form_elements&&$.inArray(elm,this.disabled_form_elements)<0)){elm.disabled=lock}}}};this.mailto_handler_uri=function(){return location.href.split("?")[0]+"?_task=mail&_action=compose&_to=%s"};this.register_protocol_handler=function(name){try{window.navigator.registerProtocolHandler("mailto",this.mailto_handler_uri(),name)}catch(e){}};this.check_protocol_handler=function(name,elem){var nav=window.navigator;if(!nav||(typeof nav.registerProtocolHandler!="function")||((typeof nav.isProtocolHandlerRegistered=="function")&&nav.isProtocolHandlerRegistered("mailto",this.mailto_handler_uri())=="registered")){$(elem).addClass("disabled")}else{$(elem).click(function(){rcmail.register_protocol_handler(name);return false})}};this.browser_capabilities_check=function(){if(!this.env.browser_capabilities){this.env.browser_capabilities={}}if(this.env.browser_capabilities.pdf===undefined){this.env.browser_capabilities.pdf=this.pdf_support_check()}if(this.env.browser_capabilities.flash===undefined){this.env.browser_capabilities.flash=this.flash_support_check()}if(this.env.browser_capabilities.tif===undefined){this.tif_support_check()}};this.browser_capabilities=function(){if(!this.env.browser_capabilities){return""}var n,ret=[];for(n in this.env.browser_capabilities){ret.push(n+"="+this.env.browser_capabilities[n])}return ret.join()};this.tif_support_check=function(){var img=new Image();img.onload=function(){rcmail.env.browser_capabilities.tif=1};img.onerror=function(){rcmail.env.browser_capabilities.tif=0};img.src="program/resources/blank.tif"};this.pdf_support_check=function(){var plugin=navigator.mimeTypes?navigator.mimeTypes["application/pdf"]:{},plugins=navigator.plugins,len=plugins.length,regex=/Adobe Reader|PDF|Acrobat/i;if(plugin&&plugin.enabledPlugin){return 1}if(window.ActiveXObject){try{if(axObj=new ActiveXObject("AcroPDF.PDF")){return 1}}catch(e){}try{if(axObj=new ActiveXObject("PDF.PdfCtrl")){return 1}}catch(e){}}for(i=0;i<len;i++){plugin=plugins[i];if(typeof plugin==="String"){if(regex.test(plugin)){return 1}}else{if(plugin.name&®ex.test(plugin.name)){return 1}}}return 0};this.flash_support_check=function(){var plugin=navigator.mimeTypes?navigator.mimeTypes["application/x-shockwave-flash"]:{};if(plugin&&plugin.enabledPlugin){return 1}if(window.ActiveXObject){try{if(axObj=new ActiveXObject("ShockwaveFlash.ShockwaveFlash")){return 1}}catch(e){}}return 0};this.set_cookie=function(name,value,expires){setCookie(name,value,expires,this.env.cookie_path,this.env.cookie_domain,this.env.cookie_secure)}}rcube_webmail.long_subject_title=function(d,a){if(!d.title){var b=$(d);if(b.width()+a*15>b.parent().width()){d.title=b.text()}}};rcube_webmail.long_subject_title_ex=function(g,b){if(!g.title){var e=$(g),a=$.trim(e.text()),f=$("<span>").text(a).css({position:"absolute","float":"left",visibility:"hidden","font-size":e.css("font-size"),"font-weight":e.css("font-weight")}).appendTo($("body")),d=f.width();f.remove();if(d+b*15>e.width()){g.title=a}}};rcube_webmail.prototype.get_cookie=getCookie;rcube_webmail.prototype.addEventListener=rcube_event_engine.prototype.addEventListener;rcube_webmail.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener;rcube_webmail.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;
\ No newline at end of file diff --git a/program/js/common.js b/program/js/common.js index 02934f734..f6fa154ef 100644 --- a/program/js/common.js +++ b/program/js/common.js @@ -1,731 +1 @@ -/* - +-----------------------------------------------------------------------+ - | Roundcube common js library | - | | - | This file is part of the Roundcube web development suite | - | Copyright (C) 2005-2012, The Roundcube Dev Team | - | | - | Licensed under the GNU General Public License version 3 or | - | any later version with exceptions for skins & plugins. | - | See the README file for a full license statement. | - | | - +-----------------------------------------------------------------------+ - | Author: Thomas Bruederli <roundcube@gmail.com> | - +-----------------------------------------------------------------------+ -*/ - -// Constants -var CONTROL_KEY = 1; -var SHIFT_KEY = 2; -var CONTROL_SHIFT_KEY = 3; - - -/** - * Default browser check class - * @constructor - */ -function roundcube_browser() -{ - var n = navigator; - - this.ver = parseFloat(n.appVersion); - this.appver = n.appVersion; - this.agent = n.userAgent; - this.agent_lc = n.userAgent.toLowerCase(); - this.name = n.appName; - this.vendor = n.vendor ? n.vendor : ''; - this.vendver = n.vendorSub ? parseFloat(n.vendorSub) : 0; - this.product = n.product ? n.product : ''; - this.platform = String(n.platform).toLowerCase(); - this.lang = (n.language) ? n.language.substring(0,2) : - (n.browserLanguage) ? n.browserLanguage.substring(0,2) : - (n.systemLanguage) ? n.systemLanguage.substring(0,2) : 'en'; - - this.win = (this.platform.indexOf('win') >= 0); - this.mac = (this.platform.indexOf('mac') >= 0); - this.linux = (this.platform.indexOf('linux') >= 0); - this.unix = (this.platform.indexOf('unix') >= 0); - - this.dom = document.getElementById ? true : false; - this.dom2 = (document.addEventListener && document.removeEventListener); - - this.ie = (document.all && !window.opera); - this.ie4 = (this.ie && !this.dom); - this.ie5 = (this.dom && this.appver.indexOf('MSIE 5')>0); - this.ie8 = (this.dom && this.appver.indexOf('MSIE 8')>0); - this.ie9 = (this.dom && this.appver.indexOf('MSIE 9')>0); - this.ie7 = (this.dom && this.appver.indexOf('MSIE 7')>0); - this.ie6 = (this.dom && !this.ie8 && !this.ie7 && this.appver.indexOf('MSIE 6')>0); - - this.ns = ((this.ver < 5 && this.name == 'Netscape') || (this.ver >= 5 && this.vendor.indexOf('Netscape') >= 0)); - this.chrome = (this.agent_lc.indexOf('chrome') > 0); - this.safari = (!this.chrome && (this.agent_lc.indexOf('safari') > 0 || this.agent_lc.indexOf('applewebkit') > 0)); - this.konq = (this.agent_lc.indexOf('konqueror') > 0); - this.mz = (this.dom && !this.ie && !this.ns && !this.chrome && !this.safari && !this.konq && this.agent.indexOf('Mozilla') >= 0); - this.iphone = (this.safari && (this.agent_lc.indexOf('iphone') > 0 || this.agent_lc.indexOf('ipod') > 0)); - this.ipad = (this.safari && this.agent_lc.indexOf('ipad') > 0); - this.opera = window.opera ? true : false; - - if (this.opera && window.RegExp) - this.vendver = (/opera(\s|\/)([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$2) : -1; - else if (this.chrome && window.RegExp) - this.vendver = (/chrome\/([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; - else if (!this.vendver && this.safari) - this.vendver = (/(safari|applewebkit)\/([0-9]+)/.test(this.agent_lc)) ? parseInt(RegExp.$2) : 0; - else if ((!this.vendver && this.mz) || this.agent.indexOf('Camino')>0) - this.vendver = (/rv:([0-9\.]+)/.test(this.agent)) ? parseFloat(RegExp.$1) : 0; - else if (this.ie && window.RegExp) - this.vendver = (/msie\s+([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; - else if (this.konq && window.RegExp) - this.vendver = (/khtml\/([0-9\.]+)/.test(this.agent_lc)) ? parseFloat(RegExp.$1) : 0; - - // get real language out of safari's user agent - if (this.safari && (/;\s+([a-z]{2})-[a-z]{2}\)/.test(this.agent_lc))) - this.lang = RegExp.$1; - - this.tablet = /ipad|android|xoom|sch-i800|playbook|tablet|kindle/i.test(this.agent_lc); - this.mobile = /iphone|ipod|blackberry|iemobile|opera mini|opera mobi|mobile/i.test(this.agent_lc); - this.touch = this.mobile || this.tablet; - this.dhtml = ((this.ie4 && this.win) || this.ie5 || this.ie6 || this.ns4 || this.mz); - this.vml = (this.win && this.ie && this.dom && !this.opera); - this.pngalpha = (this.mz || (this.opera && this.vendver >= 6) || (this.ie && this.mac && this.vendver >= 5) || - (this.ie && this.win && this.vendver >= 5.5) || this.safari); - this.opacity = (this.mz || (this.ie && this.vendver >= 5.5 && !this.opera) || (this.safari && this.vendver >= 100)); - this.cookies = n.cookieEnabled; - - // test for XMLHTTP support - this.xmlhttp_test = function() - { - var activeX_test = new Function("try{var o=new ActiveXObject('Microsoft.XMLHTTP');return true;}catch(err){return false;}"); - this.xmlhttp = (window.XMLHttpRequest || (window.ActiveXObject && activeX_test())); - return this.xmlhttp; - }; - - // set class names to html tag according to the current user agent detection - // this allows browser-specific css selectors like "html.chrome .someclass" - this.set_html_class = function() - { - var classname = ' js'; - - if (this.ie) - classname += ' ie ie'+parseInt(this.vendver); - else if (this.opera) - classname += ' opera'; - else if (this.konq) - classname += ' konqueror'; - else if (this.safari) - classname += ' chrome'; - else if (this.chrome) - classname += ' chrome'; - else if (this.mz) - classname += ' mozilla'; - - if (this.iphone) - classname += ' iphone'; - else if (this.ipad) - classname += ' ipad'; - else if (this.safari || this.chrome) - classname += ' webkit'; - - if (this.mobile) - classname += ' mobile'; - if (this.tablet) - classname += ' tablet'; - - if (document.documentElement) - document.documentElement.className += classname; - }; -}; - - -// static functions for DOM event handling -var rcube_event = { - -/** - * returns the event target element - */ -get_target: function(e) -{ - e = e || window.event; - return e && e.target ? e.target : e.srcElement; -}, - -/** - * returns the event key code - */ -get_keycode: function(e) -{ - e = e || window.event; - return e && e.keyCode ? e.keyCode : (e && e.which ? e.which : 0); -}, - -/** - * returns the event key code - */ -get_button: function(e) -{ - e = e || window.event; - return e && e.button !== undefined ? e.button : (e && e.which ? e.which : 0); -}, - -/** - * returns modifier key (constants defined at top of file) - */ -get_modifier: function(e) -{ - var opcode = 0; - e = e || window.event; - - if (bw.mac && e) - opcode += (e.metaKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY); - else if (e) - opcode += (e.ctrlKey && CONTROL_KEY) + (e.shiftKey && SHIFT_KEY); - - return opcode; -}, - -/** - * Return absolute mouse position of an event - */ -get_mouse_pos: function(e) -{ - if (!e) e = window.event; - var mX = (e.pageX) ? e.pageX : e.clientX, - mY = (e.pageY) ? e.pageY : e.clientY; - - if (document.body && document.all) { - mX += document.body.scrollLeft; - mY += document.body.scrollTop; - } - - if (e._offset) { - mX += e._offset.left; - mY += e._offset.top; - } - - return { x:mX, y:mY }; -}, - -/** - * Add an object method as event listener to a certain element - */ -add_listener: function(p) -{ - if (!p.object || !p.method) // not enough arguments - return; - if (!p.element) - p.element = document; - - if (!p.object._rc_events) - p.object._rc_events = []; - - var key = p.event + '*' + p.method; - if (!p.object._rc_events[key]) - p.object._rc_events[key] = function(e){ return p.object[p.method](e); }; - - if (p.element.addEventListener) - p.element.addEventListener(p.event, p.object._rc_events[key], false); - else if (p.element.attachEvent) { - // IE allows multiple events with the same function to be applied to the same object - // forcibly detach the event, then attach - p.element.detachEvent('on'+p.event, p.object._rc_events[key]); - p.element.attachEvent('on'+p.event, p.object._rc_events[key]); - } - else - p.element['on'+p.event] = p.object._rc_events[key]; -}, - -/** - * Remove event listener - */ -remove_listener: function(p) -{ - if (!p.element) - p.element = document; - - var key = p.event + '*' + p.method; - if (p.object && p.object._rc_events && p.object._rc_events[key]) { - if (p.element.removeEventListener) - p.element.removeEventListener(p.event, p.object._rc_events[key], false); - else if (p.element.detachEvent) - p.element.detachEvent('on'+p.event, p.object._rc_events[key]); - else - p.element['on'+p.event] = null; - } -}, - -/** - * Prevent event propagation and bubbling - */ -cancel: function(evt) -{ - var e = evt ? evt : window.event; - if (e.preventDefault) - e.preventDefault(); - if (e.stopPropagation) - e.stopPropagation(); - - e.cancelBubble = true; - e.returnValue = false; - return false; -}, - -touchevent: function(e) -{ - return { pageX:e.pageX, pageY:e.pageY, offsetX:e.pageX - e.target.offsetLeft, offsetY:e.pageY - e.target.offsetTop, target:e.target, istouch:true }; -} - -}; - - -/** - * rcmail objects event interface - */ -function rcube_event_engine() -{ - this._events = {}; -}; - -rcube_event_engine.prototype = { - -/** - * Setter for object event handlers - * - * @param {String} Event name - * @param {Function} Handler function - * @return Listener ID (used to remove this handler later on) - */ -addEventListener: function(evt, func, obj) -{ - if (!this._events) - this._events = {}; - if (!this._events[evt]) - this._events[evt] = []; - - this._events[evt].push({func:func, obj:obj ? obj : window}); -}, - -/** - * Removes a specific event listener - * - * @param {String} Event name - * @param {Int} Listener ID to remove - */ -removeEventListener: function(evt, func, obj) -{ - if (obj === undefined) - obj = window; - - for (var h,i=0; this._events && this._events[evt] && i < this._events[evt].length; i++) - if ((h = this._events[evt][i]) && h.func == func && h.obj == obj) - this._events[evt][i] = null; -}, - -/** - * This will execute all registered event handlers - * - * @param {String} Event to trigger - * @param {Object} Event object/arguments - */ -triggerEvent: function(evt, e) -{ - var ret, h; - if (e === undefined) - e = this; - else if (typeof e === 'object') - e.event = evt; - - if (this._events && this._events[evt] && !this._event_exec) { - this._event_exec = true; - for (var i=0; i < this._events[evt].length; i++) { - if ((h = this._events[evt][i])) { - if (typeof h.func === 'function') - ret = h.func.call ? h.func.call(h.obj, e) : h.func(e); - else if (typeof h.obj[h.func] === 'function') - ret = h.obj[h.func](e); - - // cancel event execution - if (ret !== undefined && !ret) - break; - } - } - if (ret && ret.event) { - try { - delete ret.event; - } catch (err) { - // IE6-7 doesn't support deleting HTMLFormElement attributes (#1488017) - $(ret).removeAttr('event'); - } - } - } - - this._event_exec = false; - if (e.event) { - try { - delete e.event; - } catch (err) { - // IE6-7 doesn't support deleting HTMLFormElement attributes (#1488017) - $(e).removeAttr('event'); - } - } - - return ret; -} - -}; // end rcube_event_engine.prototype - - -// check if input is a valid email address -// By Cal Henderson <cal@iamcal.com> -// http://code.iamcal.com/php/rfc822/ -function rcube_check_email(input, inline) -{ - if (input && window.RegExp) { - var qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]', - dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', - atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', - quoted_pair = '\\x5c[\\x00-\\x7f]', - quoted_string = '\\x22('+qtext+'|'+quoted_pair+')*\\x22', - ipv4 = '\\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\\]', - ipv6 = '\\[IPv6:[0-9a-f:.]+\\]', - ip_addr = '(' + ipv4 + ')|(' + ipv6 + ')', - // Use simplified domain matching, because we need to allow Unicode characters here - // So, e-mail address should be validated also on server side after idn_to_ascii() use - //domain_literal = '\\x5b('+dtext+'|'+quoted_pair+')*\\x5d', - //sub_domain = '('+atom+'|'+domain_literal+')', - // allow punycode/unicode top-level domain - domain = '(('+ip_addr+')|(([^@\\x2e]+\\x2e)+([^\\x00-\\x40\\x5b-\\x60\\x7b-\\x7f]{2,}|xn--[a-z0-9]{2,})))', - // ICANN e-mail test (http://idn.icann.org/E-mail_test) - icann_domains = [ - '\\u0645\\u062b\\u0627\\u0644\\x2e\\u0625\\u062e\\u062a\\u0628\\u0627\\u0631', - '\\u4f8b\\u5b50\\x2e\\u6d4b\\u8bd5', - '\\u4f8b\\u5b50\\x2e\\u6e2c\\u8a66', - '\\u03c0\\u03b1\\u03c1\\u03ac\\u03b4\\u03b5\\u03b9\\u03b3\\u03bc\\u03b1\\x2e\\u03b4\\u03bf\\u03ba\\u03b9\\u03bc\\u03ae', - '\\u0909\\u0926\\u093e\\u0939\\u0930\\u0923\\x2e\\u092a\\u0930\\u0940\\u0915\\u094d\\u0937\\u093e', - '\\u4f8b\\u3048\\x2e\\u30c6\\u30b9\\u30c8', - '\\uc2e4\\ub840\\x2e\\ud14c\\uc2a4\\ud2b8', - '\\u0645\\u062b\\u0627\\u0644\\x2e\\u0622\\u0632\\u0645\\u0627\\u06cc\\u0634\u06cc', - '\\u043f\\u0440\\u0438\\u043c\\u0435\\u0440\\x2e\\u0438\\u0441\\u043f\\u044b\\u0442\\u0430\\u043d\\u0438\\u0435', - '\\u0b89\\u0ba4\\u0bbe\\u0bb0\\u0ba3\\u0bae\\u0bcd\\x2e\\u0baa\\u0bb0\\u0bbf\\u0b9f\\u0bcd\\u0b9a\\u0bc8', - '\\u05d1\\u05f2\\u05b7\\u05e9\\u05e4\\u05bc\\u05d9\\u05dc\\x2e\\u05d8\\u05e2\\u05e1\\u05d8' - ], - icann_addr = 'mailtest\\x40('+icann_domains.join('|')+')', - word = '('+atom+'|'+quoted_string+')', - delim = '[,;\s\n]', - local_part = word+'(\\x2e'+word+')*', - addr_spec = '(('+local_part+'\\x40'+domain+')|('+icann_addr+'))', - reg1 = inline ? new RegExp('(^|<|'+delim+')'+addr_spec+'($|>|'+delim+')', 'i') : new RegExp('^'+addr_spec+'$', 'i'); - - return reg1.test(input) ? true : false; - } - - return false; -}; - -// recursively copy an object -function rcube_clone_object(obj) -{ - var out = {}; - - for (var key in obj) { - if (obj[key] && typeof obj[key] === 'object') - out[key] = rcube_clone_object(obj[key]); - else - out[key] = obj[key]; - } - - return out; -}; - -// make a string URL safe (and compatible with PHP's rawurlencode()) -function urlencode(str) -{ - if (window.encodeURIComponent) - return encodeURIComponent(str).replace('*', '%2A'); - - return escape(str) - .replace('+', '%2B') - .replace('*', '%2A') - .replace('/', '%2F') - .replace('@', '%40'); -}; - - -// get any type of html objects by id/name -function rcube_find_object(id, d) -{ - var n, f, obj, e; - if(!d) d = document; - - if(d.getElementsByName && (e = d.getElementsByName(id))) - obj = e[0]; - if(!obj && d.getElementById) - obj = d.getElementById(id); - if(!obj && d.all) - obj = d.all[id]; - - if(!obj && d.images.length) - obj = d.images[id]; - - if (!obj && d.forms.length) { - for (f=0; f<d.forms.length; f++) { - if(d.forms[f].name == id) - obj = d.forms[f]; - else if(d.forms[f].elements[id]) - obj = d.forms[f].elements[id]; - } - } - - if (!obj && d.layers) { - if (d.layers[id]) obj = d.layers[id]; - for (n=0; !obj && n<d.layers.length; n++) - obj = rcube_find_object(id, d.layers[n].document); - } - - return obj; -}; - -// determine whether the mouse is over the given object or not -function rcube_mouse_is_over(ev, obj) -{ - var mouse = rcube_event.get_mouse_pos(ev), - pos = $(obj).offset(); - - return ((mouse.x >= pos.left) && (mouse.x < (pos.left + obj.offsetWidth)) && - (mouse.y >= pos.top) && (mouse.y < (pos.top + obj.offsetHeight))); -}; - - -// cookie functions by GoogieSpell -function setCookie(name, value, expires, path, domain, secure) -{ - var curCookie = name + "=" + escape(value) + - (expires ? "; expires=" + expires.toGMTString() : "") + - (path ? "; path=" + path : "") + - (domain ? "; domain=" + domain : "") + - (secure ? "; secure" : ""); - document.cookie = curCookie; -}; - -function getCookie(name) -{ - var dc = document.cookie, - prefix = name + "=", - begin = dc.indexOf("; " + prefix); - - if (begin == -1) { - begin = dc.indexOf(prefix); - if (begin != 0) - return null; - } - else { - begin += 2; - } - - var end = dc.indexOf(";", begin); - if (end == -1) - end = dc.length; - - return unescape(dc.substring(begin + prefix.length, end)); -}; - -// deprecated aliases, to be removed, use rcmail.set_cookie/rcmail.get_cookie -roundcube_browser.prototype.set_cookie = setCookie; -roundcube_browser.prototype.get_cookie = getCookie; - -// tiny replacement for Firebox functionality -function rcube_console() -{ - this.log = function(msg) - { - var box = rcube_find_object('dbgconsole'); - - if (box) { - if (msg.charAt(msg.length-1)=='\n') - msg += '--------------------------------------\n'; - else - msg += '\n--------------------------------------\n'; - - // Konqueror doesn't allow to just change the value of hidden element - if (bw.konq) { - box.innerText += msg; - box.value = box.innerText; - } else - box.value += msg; - } - }; - - this.reset = function() - { - var box = rcube_find_object('dbgconsole'); - if (box) - box.innerText = box.value = ''; - }; -}; - -var bw = new roundcube_browser(); -bw.set_html_class(); - - -// Add escape() method to RegExp object -// http://dev.rubyonrails.org/changeset/7271 -RegExp.escape = function(str) -{ - return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1'); -}; - -// Extend Date prototype to detect Standard timezone without DST -// from http://www.michaelapproved.com/articles/timezone-detect-and-ignore-daylight-saving-time-dst/ -Date.prototype.getStdTimezoneOffset = function() -{ - var m = 12, - d = new Date(null, m, 1), - tzo = d.getTimezoneOffset(); - - while (--m) { - d.setUTCMonth(m); - if (tzo != d.getTimezoneOffset()) { - return Math.max(tzo, d.getTimezoneOffset()); - } - } - - return tzo; -} - -// define String's startsWith() method for old browsers -if (!String.prototype.startsWith) { - String.prototype.startsWith = function(search, position) { - position = position || 0; - return this.slice(position, search.length) === search; - }; -} - -// Make getElementById() case-sensitive on IE -if (bw.ie) { - document._getElementById = document.getElementById; - document.getElementById = function(id) { - var i = 0, obj = document._getElementById(id); - - if (obj && obj.id != id) - while ((obj = document.all[i]) && obj.id != id) - i++; - - return obj; - } -} - -// jQuery plugin to emulate HTML5 placeholder attributes on input elements -jQuery.fn.placeholder = function(text) { - return this.each(function() { - var active = false, elem = $(this); - this.title = text; - - // Try HTML5 placeholder attribute first - if ('placeholder' in this) { - elem.attr('placeholder', text); - } - // Fallback to Javascript emulation of placeholder - else { - this._placeholder = text; - elem.blur(function(e) { - if ($.trim(elem.val()) == "") - elem.val(text); - elem.triggerHandler('change'); - }) - .focus(function(e) { - if ($.trim(elem.val()) == text) - elem.val(""); - elem.triggerHandler('change'); - }) - .change(function(e) { - var active = elem.val() == text; - elem[(active ? 'addClass' : 'removeClass')]('placeholder').attr('spellcheck', active); - }); - - // Do not blur currently focused element (catch exception: #1489008) - try { active = this == document.activeElement; } catch(e) {} - if (!active) - elem.blur(); - } - }); -}; - - -// This code was written by Tyler Akins and has been placed in the -// public domain. It would be nice if you left this header intact. -// Base64 code from Tyler Akins -- http://rumkin.com -var Base64 = (function () { - var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; - - var obj = { - /** - * Encodes a string in base64 - * @param {String} input The string to encode in base64. - */ - encode: function (input) { - if (typeof(window.btoa) === 'function') - return btoa(input); - - var chr1, chr2, chr3, enc1, enc2, enc3, enc4, i = 0, output = '', len = input.length; - - do { - chr1 = input.charCodeAt(i++); - chr2 = input.charCodeAt(i++); - chr3 = input.charCodeAt(i++); - - enc1 = chr1 >> 2; - enc2 = ((chr1 & 3) << 4) | (chr2 >> 4); - enc3 = ((chr2 & 15) << 2) | (chr3 >> 6); - enc4 = chr3 & 63; - - if (isNaN(chr2)) - enc3 = enc4 = 64; - else if (isNaN(chr3)) - enc4 = 64; - - output = output - + keyStr.charAt(enc1) + keyStr.charAt(enc2) - + keyStr.charAt(enc3) + keyStr.charAt(enc4); - } while (i < len); - - return output; - }, - - /** - * Decodes a base64 string. - * @param {String} input The string to decode. - */ - decode: function (input) { - if (typeof(window.atob) === 'function') - return atob(input); - - var chr1, chr2, chr3, enc1, enc2, enc3, enc4, len, i = 0, output = ''; - - // remove all characters that are not A-Z, a-z, 0-9, +, /, or = - input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); - len = input.length; - - do { - enc1 = keyStr.indexOf(input.charAt(i++)); - enc2 = keyStr.indexOf(input.charAt(i++)); - enc3 = keyStr.indexOf(input.charAt(i++)); - enc4 = keyStr.indexOf(input.charAt(i++)); - - chr1 = (enc1 << 2) | (enc2 >> 4); - chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); - chr3 = ((enc3 & 3) << 6) | enc4; - - output = output + String.fromCharCode(chr1); - - if (enc3 != 64) - output = output + String.fromCharCode(chr2); - if (enc4 != 64) - output = output + String.fromCharCode(chr3); - } while (i < len); - - return output; - } - }; - - return obj; -})(); +var CONTROL_KEY=1;var SHIFT_KEY=2;var CONTROL_SHIFT_KEY=3;function roundcube_browser(){var a=navigator;this.ver=parseFloat(a.appVersion);this.appver=a.appVersion;this.agent=a.userAgent;this.agent_lc=a.userAgent.toLowerCase();this.name=a.appName;this.vendor=a.vendor?a.vendor:"";this.vendver=a.vendorSub?parseFloat(a.vendorSub):0;this.product=a.product?a.product:"";this.platform=String(a.platform).toLowerCase();this.lang=(a.language)?a.language.substring(0,2):(a.browserLanguage)?a.browserLanguage.substring(0,2):(a.systemLanguage)?a.systemLanguage.substring(0,2):"en";this.win=(this.platform.indexOf("win")>=0);this.mac=(this.platform.indexOf("mac")>=0);this.linux=(this.platform.indexOf("linux")>=0);this.unix=(this.platform.indexOf("unix")>=0);this.dom=document.getElementById?true:false;this.dom2=(document.addEventListener&&document.removeEventListener);this.ie=(document.all&&!window.opera);this.ie4=(this.ie&&!this.dom);this.ie5=(this.dom&&this.appver.indexOf("MSIE 5")>0);this.ie8=(this.dom&&this.appver.indexOf("MSIE 8")>0);this.ie9=(this.dom&&this.appver.indexOf("MSIE 9")>0);this.ie7=(this.dom&&this.appver.indexOf("MSIE 7")>0);this.ie6=(this.dom&&!this.ie8&&!this.ie7&&this.appver.indexOf("MSIE 6")>0);this.ns=((this.ver<5&&this.name=="Netscape")||(this.ver>=5&&this.vendor.indexOf("Netscape")>=0));this.chrome=(this.agent_lc.indexOf("chrome")>0);this.safari=(!this.chrome&&(this.agent_lc.indexOf("safari")>0||this.agent_lc.indexOf("applewebkit")>0));this.konq=(this.agent_lc.indexOf("konqueror")>0);this.mz=(this.dom&&!this.ie&&!this.ns&&!this.chrome&&!this.safari&&!this.konq&&this.agent.indexOf("Mozilla")>=0);this.iphone=(this.safari&&(this.agent_lc.indexOf("iphone")>0||this.agent_lc.indexOf("ipod")>0));this.ipad=(this.safari&&this.agent_lc.indexOf("ipad")>0);this.opera=window.opera?true:false;if(this.opera&&window.RegExp){this.vendver=(/opera(\s|\/)([0-9\.]+)/.test(this.agent_lc))?parseFloat(RegExp.$2):-1}else{if(this.chrome&&window.RegExp){this.vendver=(/chrome\/([0-9\.]+)/.test(this.agent_lc))?parseFloat(RegExp.$1):0}else{if(!this.vendver&&this.safari){this.vendver=(/(safari|applewebkit)\/([0-9]+)/.test(this.agent_lc))?parseInt(RegExp.$2):0}else{if((!this.vendver&&this.mz)||this.agent.indexOf("Camino")>0){this.vendver=(/rv:([0-9\.]+)/.test(this.agent))?parseFloat(RegExp.$1):0}else{if(this.ie&&window.RegExp){this.vendver=(/msie\s+([0-9\.]+)/.test(this.agent_lc))?parseFloat(RegExp.$1):0}else{if(this.konq&&window.RegExp){this.vendver=(/khtml\/([0-9\.]+)/.test(this.agent_lc))?parseFloat(RegExp.$1):0}}}}}}if(this.safari&&(/;\s+([a-z]{2})-[a-z]{2}\)/.test(this.agent_lc))){this.lang=RegExp.$1}this.tablet=/ipad|android|xoom|sch-i800|playbook|tablet|kindle/i.test(this.agent_lc);this.mobile=/iphone|ipod|blackberry|iemobile|opera mini|opera mobi|mobile/i.test(this.agent_lc);this.touch=this.mobile||this.tablet;this.dhtml=((this.ie4&&this.win)||this.ie5||this.ie6||this.ns4||this.mz);this.vml=(this.win&&this.ie&&this.dom&&!this.opera);this.pngalpha=(this.mz||(this.opera&&this.vendver>=6)||(this.ie&&this.mac&&this.vendver>=5)||(this.ie&&this.win&&this.vendver>=5.5)||this.safari);this.opacity=(this.mz||(this.ie&&this.vendver>=5.5&&!this.opera)||(this.safari&&this.vendver>=100));this.cookies=a.cookieEnabled;this.xmlhttp_test=function(){var b=new Function("try{var o=new ActiveXObject('Microsoft.XMLHTTP');return true;}catch(err){return false;}");this.xmlhttp=(window.XMLHttpRequest||(window.ActiveXObject&&b()));return this.xmlhttp};this.set_html_class=function(){var b=" js";if(this.ie){b+=" ie ie"+parseInt(this.vendver)}else{if(this.opera){b+=" opera"}else{if(this.konq){b+=" konqueror"}else{if(this.safari){b+=" chrome"}else{if(this.chrome){b+=" chrome"}else{if(this.mz){b+=" mozilla"}}}}}}if(this.iphone){b+=" iphone"}else{if(this.ipad){b+=" ipad"}else{if(this.safari||this.chrome){b+=" webkit"}}}if(this.mobile){b+=" mobile"}if(this.tablet){b+=" tablet"}if(document.documentElement){document.documentElement.className+=b}}}var rcube_event={get_target:function(a){a=a||window.event;return a&&a.target?a.target:a.srcElement},get_keycode:function(a){a=a||window.event;return a&&a.keyCode?a.keyCode:(a&&a.which?a.which:0)},get_button:function(a){a=a||window.event;return a&&a.button!==undefined?a.button:(a&&a.which?a.which:0)},get_modifier:function(b){var a=0;b=b||window.event;if(bw.mac&&b){a+=(b.metaKey&&CONTROL_KEY)+(b.shiftKey&&SHIFT_KEY)}else{if(b){a+=(b.ctrlKey&&CONTROL_KEY)+(b.shiftKey&&SHIFT_KEY)}}return a},get_mouse_pos:function(c){if(!c){c=window.event}var b=(c.pageX)?c.pageX:c.clientX,a=(c.pageY)?c.pageY:c.clientY;if(document.body&&document.all){b+=document.body.scrollLeft;a+=document.body.scrollTop}if(c._offset){b+=c._offset.left;a+=c._offset.top}return{x:b,y:a}},add_listener:function(b){if(!b.object||!b.method){return}if(!b.element){b.element=document}if(!b.object._rc_events){b.object._rc_events=[]}var a=b.event+"*"+b.method;if(!b.object._rc_events[a]){b.object._rc_events[a]=function(c){return b.object[b.method](c)}}if(b.element.addEventListener){b.element.addEventListener(b.event,b.object._rc_events[a],false)}else{if(b.element.attachEvent){b.element.detachEvent("on"+b.event,b.object._rc_events[a]);b.element.attachEvent("on"+b.event,b.object._rc_events[a])}else{b.element["on"+b.event]=b.object._rc_events[a]}}},remove_listener:function(b){if(!b.element){b.element=document}var a=b.event+"*"+b.method;if(b.object&&b.object._rc_events&&b.object._rc_events[a]){if(b.element.removeEventListener){b.element.removeEventListener(b.event,b.object._rc_events[a],false)}else{if(b.element.detachEvent){b.element.detachEvent("on"+b.event,b.object._rc_events[a])}else{b.element["on"+b.event]=null}}}},cancel:function(a){var b=a?a:window.event;if(b.preventDefault){b.preventDefault()}if(b.stopPropagation){b.stopPropagation()}b.cancelBubble=true;b.returnValue=false;return false},touchevent:function(a){return{pageX:a.pageX,pageY:a.pageY,offsetX:a.pageX-a.target.offsetLeft,offsetY:a.pageY-a.target.offsetTop,target:a.target,istouch:true}}};function rcube_event_engine(){this._events={}}rcube_event_engine.prototype={addEventListener:function(a,b,d){if(!this._events){this._events={}}if(!this._events[a]){this._events[a]=[]}var c={func:b,obj:d?d:window};this._events[a][this._events[a].length]=c},removeEventListener:function(a,d,e){if(e===undefined){e=window}for(var c,b=0;this._events&&this._events[a]&&b<this._events[a].length;b++){if((c=this._events[a][b])&&c.func==d&&c.obj==e){this._events[a][b]=null}}},triggerEvent:function(a,g){var b,d;if(g===undefined){g=this}else{if(typeof g==="object"){g.event=a}}if(this._events&&this._events[a]&&!this._event_exec){this._event_exec=true;for(var c=0;c<this._events[a].length;c++){if((d=this._events[a][c])){if(typeof d.func==="function"){b=d.func.call?d.func.call(d.obj,g):d.func(g)}else{if(typeof d.obj[d.func]==="function"){b=d.obj[d.func](g)}}if(b!==undefined&&!b){break}}}if(b&&b.event){try{delete b.event}catch(f){$(b).removeAttr("event")}}}this._event_exec=false;if(g.event){try{delete g.event}catch(f){$(g).removeAttr("event")}}return b}};function rcube_layer(b,a){this.name=b;this.create=function(m){var d=(m.x)?m.x:0,k=(m.y)?m.y:0,j=m.width,f=m.height,g=m.zindex,c=m.vis,i=m.parent,e=document.createElement("DIV");e.id=this.name;e.style.position="absolute";e.style.visibility=(c)?(c==2)?"inherit":"visible":"hidden";e.style.left=d+"px";e.style.top=k+"px";if(j){e.style.width=j.toString().match(/\%$/)?j:j+"px"}if(f){e.style.height=f.toString().match(/\%$/)?f:f+"px"}if(g){e.style.zIndex=g}if(i){i.appendChild(e)}else{document.body.appendChild(e)}this.elm=e};if(a!=null){this.create(a);this.name=this.elm.id}else{this.elm=document.getElementById(b)}if(!this.elm){return false}this.css=this.elm.style;this.event=this.elm;this.width=this.elm.offsetWidth;this.height=this.elm.offsetHeight;this.x=parseInt(this.elm.offsetLeft);this.y=parseInt(this.elm.offsetTop);this.visible=(this.css.visibility=="visible"||this.css.visibility=="show"||this.css.visibility=="inherit")?true:false;this.move=function(c,d){this.x=c;this.y=d;this.css.left=Math.round(this.x)+"px";this.css.top=Math.round(this.y)+"px"};this.resize=function(c,d){this.css.width=c+"px";this.css.height=d+"px";this.width=c;this.height=d};this.show=function(c){if(c==1){this.css.visibility="visible";this.visible=true}else{if(c==2){this.css.visibility="inherit";this.visible=true}else{this.css.visibility="hidden";this.visible=false}}};this.write=function(c){this.elm.innerHTML=c}}function rcube_check_email(h,c){if(h&&window.RegExp){var f="[^\\x0d\\x22\\x5c\\x80-\\xff]",e="[^\\x0d\\x5b-\\x5d\\x80-\\xff]",a="[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+",g="\\x5c[\\x00-\\x7f]",l="\\x22("+f+"|"+g+")*\\x22",k="\\[(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}\\]",j="\\[IPv6:[0-9a-f:.]+\\]",i="("+k+")|("+j+")",r="(("+i+")|(([^@\\x2e]+\\x2e)+([^\\x00-\\x40\\x5b-\\x60\\x7b-\\x7f]{2,}|xn--[a-z0-9]{2,})))",d=["\\u0645\\u062b\\u0627\\u0644\\x2e\\u0625\\u062e\\u062a\\u0628\\u0627\\u0631","\\u4f8b\\u5b50\\x2e\\u6d4b\\u8bd5","\\u4f8b\\u5b50\\x2e\\u6e2c\\u8a66","\\u03c0\\u03b1\\u03c1\\u03ac\\u03b4\\u03b5\\u03b9\\u03b3\\u03bc\\u03b1\\x2e\\u03b4\\u03bf\\u03ba\\u03b9\\u03bc\\u03ae","\\u0909\\u0926\\u093e\\u0939\\u0930\\u0923\\x2e\\u092a\\u0930\\u0940\\u0915\\u094d\\u0937\\u093e","\\u4f8b\\u3048\\x2e\\u30c6\\u30b9\\u30c8","\\uc2e4\\ub840\\x2e\\ud14c\\uc2a4\\ud2b8","\\u0645\\u062b\\u0627\\u0644\\x2e\\u0622\\u0632\\u0645\\u0627\\u06cc\\u0634\u06cc","\\u043f\\u0440\\u0438\\u043c\\u0435\\u0440\\x2e\\u0438\\u0441\\u043f\\u044b\\u0442\\u0430\\u043d\\u0438\\u0435","\\u0b89\\u0ba4\\u0bbe\\u0bb0\\u0ba3\\u0bae\\u0bcd\\x2e\\u0baa\\u0bb0\\u0bbf\\u0b9f\\u0bcd\\u0b9a\\u0bc8","\\u05d1\\u05f2\\u05b7\\u05e9\\u05e4\\u05bc\\u05d9\\u05dc\\x2e\\u05d8\\u05e2\\u05e1\\u05d8"],p="mailtest\\x40("+d.join("|")+")",n="("+a+"|"+l+")",q="[,;s\n]",m=n+"(\\x2e"+n+")*",b="(("+m+"\\x40"+r+")|("+p+"))",o=c?new RegExp("(^|<|"+q+")"+b+"($|>|"+q+")","i"):new RegExp("^"+b+"$","i");return o.test(h)?true:false}return false}function rcube_clone_object(c){var a={};for(var b in c){if(c[b]&&typeof c[b]==="object"){a[b]=clone_object(c[b])}else{a[b]=c[b]}}return a}function urlencode(a){if(window.encodeURIComponent){return encodeURIComponent(a).replace("*","%2A")}return escape(a).replace("+","%2B").replace("*","%2A").replace("/","%2F").replace("@","%40")}function rcube_find_object(i,g){var h,a,c,b;if(!g){g=document}if(g.getElementsByName&&(b=g.getElementsByName(i))){c=b[0]}if(!c&&g.getElementById){c=g.getElementById(i)}if(!c&&g.all){c=g.all[i]}if(!c&&g.images.length){c=g.images[i]}if(!c&&g.forms.length){for(a=0;a<g.forms.length;a++){if(g.forms[a].name==i){c=g.forms[a]}else{if(g.forms[a].elements[i]){c=g.forms[a].elements[i]}}}}if(!c&&g.layers){if(g.layers[i]){c=g.layers[i]}for(h=0;!c&&h<g.layers.length;h++){c=rcube_find_object(i,g.layers[h].document)}}return c}function rcube_mouse_is_over(b,c){var a=rcube_event.get_mouse_pos(b),d=$(c).offset();return((a.x>=d.left)&&(a.x<(d.left+c.offsetWidth))&&(a.y>=d.top)&&(a.y<(d.top+c.offsetHeight)))}function setCookie(c,e,a,g,d,f){var b=c+"="+escape(e)+(a?"; expires="+a.toGMTString():"")+(g?"; path="+g:"")+(d?"; domain="+d:"")+(f?"; secure":"");document.cookie=b}function getCookie(c){var b=document.cookie,e=c+"=",d=b.indexOf("; "+e);if(d==-1){d=b.indexOf(e);if(d!=0){return null}}else{d+=2}var a=b.indexOf(";",d);if(a==-1){a=b.length}return unescape(b.substring(d+e.length,a))}roundcube_browser.prototype.set_cookie=setCookie;roundcube_browser.prototype.get_cookie=getCookie;function rcube_console(){this.log=function(b){var a=rcube_find_object("dbgconsole");if(a){if(b.charAt(b.length-1)=="\n"){b+="--------------------------------------\n"}else{b+="\n--------------------------------------\n"}if(bw.konq){a.innerText+=b;a.value=a.innerText}else{a.value+=b}}};this.reset=function(){var a=rcube_find_object("dbgconsole");if(a){a.innerText=a.value=""}}}var bw=new roundcube_browser();bw.set_html_class();RegExp.escape=function(a){return String(a).replace(/([.*+?^=!:${}()|[\]\/\\])/g,"\\$1")};Date.prototype.getStdTimezoneOffset=function(){var a=12,c=new Date(null,a,1),b=c.getTimezoneOffset();while(--a){c.setUTCMonth(a);if(b!=c.getTimezoneOffset()){return Math.max(b,c.getTimezoneOffset())}}return b};if(bw.ie){document._getElementById=document.getElementById;document.getElementById=function(c){var a=0,b=document._getElementById(c);if(b&&b.id!=c){while((b=document.all[a])&&b.id!=c){a++}}return b}}jQuery.fn.placeholder=function(a){return this.each(function(){var d=false,b=$(this);this.title=a;if("placeholder" in this){b.attr("placeholder",a)}else{this._placeholder=a;b.blur(function(f){if($.trim(b.val())==""){b.val(a)}b.triggerHandler("change")}).focus(function(f){if($.trim(b.val())==a){b.val("")}b.triggerHandler("change")}).change(function(g){var f=b.val()==a;b[(f?"addClass":"removeClass")]("placeholder").attr("spellcheck",f)});try{d=this==document.activeElement}catch(c){}if(!d){b.blur()}}})};var Base64=(function(){var a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";var b={encode:function(f){if(typeof(window.btoa)==="function"){return btoa(f)}var n,l,j,m,k,h,g,d=0,c="",e=f.length;do{n=f.charCodeAt(d++);l=f.charCodeAt(d++);j=f.charCodeAt(d++);m=n>>2;k=((n&3)<<4)|(l>>4);h=((l&15)<<2)|(j>>6);g=j&63;if(isNaN(l)){h=g=64}else{if(isNaN(j)){g=64}}c=c+a.charAt(m)+a.charAt(k)+a.charAt(h)+a.charAt(g)}while(d<e);return c},decode:function(f){if(typeof(window.atob)==="function"){return atob(f)}var n,l,j,m,k,h,g,e,d=0,c="";f=f.replace(/[^A-Za-z0-9\+\/\=]/g,"");e=f.length;do{m=a.indexOf(f.charAt(d++));k=a.indexOf(f.charAt(d++));h=a.indexOf(f.charAt(d++));g=a.indexOf(f.charAt(d++));n=(m<<2)|(k>>4);l=((k&15)<<4)|(h>>2);j=((h&3)<<6)|g;c=c+String.fromCharCode(n);if(h!=64){c=c+String.fromCharCode(l)}if(g!=64){c=c+String.fromCharCode(j)}}while(d<e);return c}};return b})();
\ No newline at end of file diff --git a/program/js/editor.js b/program/js/editor.js index 020971d6e..bc36e9a39 100644 --- a/program/js/editor.js +++ b/program/js/editor.js @@ -41,7 +41,7 @@ function rcmail_editor_init(config) $.extend(conf, { plugins: 'paste,tabfocus', theme_advanced_buttons1: 'bold,italic,underline,strikethrough,justifyleft,justifycenter,justifyright,justifyfull,separator,outdent,indent,charmap,hr,link,unlink,code,forecolor', - theme_advanced_buttons2: 'fontselect,fontsizeselect' + theme_advanced_buttons2: ',fontselect,fontsizeselect' }); else { // mail compose $.extend(conf, { @@ -74,18 +74,11 @@ function rcmail_editor_init(config) // react to real individual tinyMCE editor init function rcmail_editor_callback() { - var css = {}, - elem = rcube_find_object('_from'), + var elem = rcube_find_object('_from'), fe = rcmail.env.compose_focus_elem; if (rcmail.env.default_font) - css['font-family'] = rcmail.env.default_font; - - if (rcmail.env.default_font_size) - css['font-size'] = rcmail.env.default_font_size; - - if (css['font-family'] || css['font-size']) - $(tinyMCE.get(rcmail.env.composebody).getBody()).css(css); + $(tinyMCE.get(rcmail.env.composebody).getBody()).css('font-family', rcmail.env.default_font); if (elem && elem.type == 'select-one') { rcmail.change_identity(elem); @@ -161,8 +154,8 @@ function rcmail_editor_images() for (i in files) { att = files[i]; - if (att.complete && att.mimetype.startsWith('image/')) { - list.push([att.name, rcmail.env.comm_path+'&_id='+rcmail.env.compose_id+'&_action=display-attachment&_file='+i]); + if (att.complete && att.mimetype.indexOf('image/') == 0) { + list.push([att.name, rcmail.env.comm_path+'&_action=display-attachment&_file='+i+'&_id='+rcmail.env.compose_id]); } } diff --git a/program/js/googiespell.js b/program/js/googiespell.js index 9832116dd..6d0a19c06 100644 --- a/program/js/googiespell.js +++ b/program/js/googiespell.js @@ -1,1135 +1 @@ -/* - +-----------------------------------------------------------------------+ - | Roundcube SpellCheck script | - | jQuery'fied spell checker based on GoogieSpell 4.0 | - | (which was published under GPL "version 2 or any later version") | - | | - | This file is part of the Roundcube Webmail client | - | Copyright (C) 2006 Amir Salihefendic | - | Copyright (C) 2009 The Roundcube Dev Team | - | Copyright (C) 2011 Kolab Systems AG | - | | - | Licensed under the GNU General Public License version 3 or | - | any later version with exceptions for skins & plugins. | - | See the README file for a full license statement. | - | | - +-----------------------------------------------------------------------+ - | Authors: 4mir Salihefendic <amix@amix.dk> | - | Aleksander Machniak - <alec [at] alec.pl> | - +-----------------------------------------------------------------------+ -*/ - -var GOOGIE_CUR_LANG, - GOOGIE_DEFAULT_LANG = 'en'; - -function GoogieSpell(img_dir, server_url, has_dict) -{ - var ref = this, - cookie_value = rcmail.get_cookie('language'); - - GOOGIE_CUR_LANG = cookie_value != null ? cookie_value : GOOGIE_DEFAULT_LANG; - - this.array_keys = function(arr) { - var res = []; - for (var key in arr) { res.push([key]); } - return res; - } - - this.img_dir = img_dir; - this.server_url = server_url; - - this.org_lang_to_word = { - "da": "Dansk", "de": "Deutsch", "en": "English", - "es": "Español", "fr": "Français", "it": "Italiano", - "nl": "Nederlands", "pl": "Polski", "pt": "Português", - "ru": "Русский", "fi": "Suomi", "sv": "Svenska" - }; - this.lang_to_word = this.org_lang_to_word; - this.langlist_codes = this.array_keys(this.lang_to_word); - this.show_change_lang_pic = true; - this.change_lang_pic_placement = 'right'; - this.report_state_change = true; - - this.ta_scroll_top = 0; - this.el_scroll_top = 0; - - this.lang_chck_spell = "Check spelling"; - this.lang_revert = "Revert to"; - this.lang_close = "Close"; - this.lang_rsm_edt = "Resume editing"; - this.lang_no_error_found = "No spelling errors found"; - this.lang_no_suggestions = "No suggestions"; - this.lang_learn_word = "Add to dictionary"; - - this.show_spell_img = false; // roundcube mod. - this.decoration = true; - this.use_close_btn = false; - this.edit_layer_dbl_click = true; - this.report_ta_not_found = true; - - // Extensions - this.custom_ajax_error = null; - this.custom_no_spelling_error = null; - this.custom_menu_builder = []; // Should take an eval function and a build menu function - this.custom_item_evaulator = null; // Should take an eval function and a build menu function - this.extra_menu_items = []; - this.custom_spellcheck_starter = null; - this.main_controller = true; - this.has_dictionary = has_dict; - - // Observers - this.lang_state_observer = null; - this.spelling_state_observer = null; - this.show_menu_observer = null; - this.all_errors_fixed_observer = null; - - // Focus links - used to give the text box focus - this.use_focus = false; - this.focus_link_t = null; - this.focus_link_b = null; - - // Counters - this.cnt_errors = 0; - this.cnt_errors_fixed = 0; - - // Set document's onclick to hide the language and error menu - $(document).bind('click', function(e) { - var target = $(e.target); - if(target.attr('googie_action_btn') != '1' && ref.isLangWindowShown()) - ref.hideLangWindow(); - if(target.attr('googie_action_btn') != '1' && ref.isErrorWindowShown()) - ref.hideErrorWindow(); - }); - - -this.decorateTextarea = function(id) -{ - this.text_area = typeof id === 'string' ? document.getElementById(id) : id; - - if (this.text_area) { - if (!this.spell_container && this.decoration) { - var table = document.createElement('table'), - tbody = document.createElement('tbody'), - tr = document.createElement('tr'), - spell_container = document.createElement('td'), - r_width = this.isDefined(this.force_width) ? this.force_width : this.text_area.offsetWidth, - r_height = this.isDefined(this.force_height) ? this.force_height : 16; - - tr.appendChild(spell_container); - tbody.appendChild(tr); - $(table).append(tbody).insertBefore(this.text_area).width('100%').height(r_height); - $(spell_container).height(r_height).width(r_width).css('text-align', 'right'); - - this.spell_container = spell_container; - } - - this.checkSpellingState(); - } - else if (this.report_ta_not_found) - alert('Text area not found'); -}; - -////// -// API Functions (the ones that you can call) -///// -this.setSpellContainer = function(id) -{ - this.spell_container = typeof id === 'string' ? document.getElementById(id) : id; -}; - -this.setLanguages = function(lang_dict) -{ - this.lang_to_word = lang_dict; - this.langlist_codes = this.array_keys(lang_dict); -}; - -this.setCurrentLanguage = function(lan_code) -{ - GOOGIE_CUR_LANG = lan_code; - - //Set cookie - var now = new Date(); - now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000); - rcmail.set_cookie('language', lan_code, now); -}; - -this.setForceWidthHeight = function(width, height) -{ - // Set to null if you want to use one of them - this.force_width = width; - this.force_height = height; -}; - -this.setDecoration = function(bool) -{ - this.decoration = bool; -}; - -this.dontUseCloseButtons = function() -{ - this.use_close_btn = false; -}; - -this.appendNewMenuItem = function(name, call_back_fn, checker) -{ - this.extra_menu_items.push([name, call_back_fn, checker]); -}; - -this.appendCustomMenuBuilder = function(eval_fn, builder) -{ - this.custom_menu_builder.push([eval_fn, builder]); -}; - -this.setFocus = function() -{ - try { - this.focus_link_b.focus(); - this.focus_link_t.focus(); - return true; - } - catch(e) { - return false; - } -}; - - -////// -// Set functions (internal) -///// -this.setStateChanged = function(current_state) -{ - this.state = current_state; - if (this.spelling_state_observer != null && this.report_state_change) - this.spelling_state_observer(current_state, this); -}; - -this.setReportStateChange = function(bool) -{ - this.report_state_change = bool; -}; - - -////// -// Request functions -///// -this.getUrl = function() -{ - return this.server_url + GOOGIE_CUR_LANG; -}; - -this.escapeSpecial = function(val) -{ - return val ? val.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">") : ''; -}; - -this.createXMLReq = function (text) -{ - return '<?xml version="1.0" encoding="utf-8" ?>' - + '<spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1">' - + '<text>' + text + '</text></spellrequest>'; -}; - -this.spellCheck = function(ignore) -{ - this.prepare(ignore); - - var req_text = this.escapeSpecial(this.orginal_text), - ref = this; - - $.ajax({ type: 'POST', url: this.getUrl(), data: this.createXMLReq(req_text), dataType: 'text', - error: function(o) { - if (ref.custom_ajax_error) - ref.custom_ajax_error(ref); - else - alert('An error was encountered on the server. Please try again later.'); - if (ref.main_controller) { - $(ref.spell_span).remove(); - ref.removeIndicator(); - } - ref.checkSpellingState(); - }, - success: function(data) { - ref.processData(data); - if (!ref.results.length) { - if (!ref.custom_no_spelling_error) - ref.flashNoSpellingErrorState(); - else - ref.custom_no_spelling_error(ref); - } - ref.removeIndicator(); - } - }); -}; - -this.learnWord = function(word, id) -{ - word = this.escapeSpecial(word.innerHTML); - - var ref = this, - req_text = '<?xml version="1.0" encoding="utf-8" ?><learnword><text>' + word + '</text></learnword>'; - - $.ajax({ type: 'POST', url: this.getUrl(), data: req_text, dataType: 'text', - error: function(o) { - if (ref.custom_ajax_error) - ref.custom_ajax_error(ref); - else - alert('An error was encountered on the server. Please try again later.'); - }, - success: function(data) { - } - }); -}; - - -////// -// Spell checking functions -///// -this.prepare = function(ignore, no_indicator) -{ - this.cnt_errors_fixed = 0; - this.cnt_errors = 0; - this.setStateChanged('checking_spell'); - - if (!no_indicator && this.main_controller) - this.appendIndicator(this.spell_span); - - this.error_links = []; - this.ta_scroll_top = this.text_area.scrollTop; - this.ignore = ignore; - this.hideLangWindow(); - - if ($(this.text_area).val() == '' || ignore) { - if (!this.custom_no_spelling_error) - this.flashNoSpellingErrorState(); - else - this.custom_no_spelling_error(this); - this.removeIndicator(); - return; - } - - this.createEditLayer(this.text_area.offsetWidth, this.text_area.offsetHeight); - this.createErrorWindow(); - $('body').append(this.error_window); - - try { netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead"); } - catch (e) { } - - if (this.main_controller) - $(this.spell_span).unbind('click'); - - this.orginal_text = $(this.text_area).val(); -}; - -this.parseResult = function(r_text) -{ - // Returns an array: result[item] -> ['attrs'], ['suggestions'] - var re_split_attr_c = /\w+="(\d+|true)"/g, - re_split_text = /\t/g, - matched_c = r_text.match(/<c[^>]*>[^<]*<\/c>/g), - results = []; - - if (matched_c == null) - return results; - - for (var i=0, len=matched_c.length; i < len; i++) { - var item = []; - this.errorFound(); - - // Get attributes - item['attrs'] = []; - var c_attr, val, - split_c = matched_c[i].match(re_split_attr_c); - for (var j=0; j < split_c.length; j++) { - c_attr = split_c[j].split(/=/); - val = c_attr[1].replace(/"/g, ''); - item['attrs'][c_attr[0]] = val != 'true' ? parseInt(val) : val; - } - - // Get suggestions - item['suggestions'] = []; - var only_text = matched_c[i].replace(/<[^>]*>/g, ''), - split_t = only_text.split(re_split_text); - for (var k=0; k < split_t.length; k++) { - if(split_t[k] != '') - item['suggestions'].push(split_t[k]); - } - results.push(item); - } - - return results; -}; - -this.processData = function(data) -{ - this.results = this.parseResult(data); - if (this.results.length) { - this.showErrorsInIframe(); - this.resumeEditingState(); - } -}; - -////// -// Error menu functions -///// -this.createErrorWindow = function() -{ - this.error_window = document.createElement('div'); - $(this.error_window).addClass('googie_window popupmenu').attr('googie_action_btn', '1'); -}; - -this.isErrorWindowShown = function() -{ - return $(this.error_window).is(':visible'); -}; - -this.hideErrorWindow = function() -{ - $(this.error_window).hide(); - $(this.error_window_iframe).hide(); -}; - -this.updateOrginalText = function(offset, old_value, new_value, id) -{ - var part_1 = this.orginal_text.substring(0, offset), - part_2 = this.orginal_text.substring(offset+old_value.length), - add_2_offset = new_value.length - old_value.length; - - this.orginal_text = part_1 + new_value + part_2; - $(this.text_area).val(this.orginal_text); - for (var j=0, len=this.results.length; j<len; j++) { - // Don't edit the offset of the current item - if (j != id && j > id) - this.results[j]['attrs']['o'] += add_2_offset; - } -}; - -this.saveOldValue = function(elm, old_value) { - elm.is_changed = true; - elm.old_value = old_value; -}; - -this.createListSeparator = function() -{ - var td = document.createElement('td'), - tr = document.createElement('tr'); - - $(td).html(' ').attr('googie_action_btn', '1') - .css({'cursor': 'default', 'font-size': '3px', 'border-top': '1px solid #ccc', 'padding-top': '3px'}); - tr.appendChild(td); - - return tr; -}; - -this.correctError = function(id, elm, l_elm, rm_pre_space) -{ - var old_value = elm.innerHTML, - new_value = l_elm.nodeType == 3 ? l_elm.nodeValue : l_elm.innerHTML, - offset = this.results[id]['attrs']['o']; - - if (rm_pre_space) { - var pre_length = elm.previousSibling.innerHTML; - elm.previousSibling.innerHTML = pre_length.slice(0, pre_length.length-1); - old_value = " " + old_value; - offset--; - } - - this.hideErrorWindow(); - this.updateOrginalText(offset, old_value, new_value, id); - - $(elm).html(new_value).css('color', 'green').attr('is_corrected', true); - - this.results[id]['attrs']['l'] = new_value.length; - - if (!this.isDefined(elm.old_value)) - this.saveOldValue(elm, old_value); - - this.errorFixed(); -}; - -this.ignoreError = function(elm, id) -{ - // @TODO: ignore all same words - $(elm).removeAttr('class').css('color', '').unbind(); - this.hideErrorWindow(); -}; - -this.showErrorWindow = function(elm, id) -{ - if (this.show_menu_observer) - this.show_menu_observer(this); - - var ref = this, - pos = $(elm).offset(), - table = document.createElement('table'), - list = document.createElement('tbody'); - - $(this.error_window).html(''); - $(table).addClass('googie_list').attr('googie_action_btn', '1'); - - // Check if we should use custom menu builder, if not we use the default - var changed = false; - for (var k=0; k<this.custom_menu_builder.length; k++) { - var eb = this.custom_menu_builder[k]; - if (eb[0](this.results[id])) { - changed = eb[1](this, list, elm); - break; - } - } - - if (!changed) { - // Build up the result list - var suggestions = this.results[id]['suggestions'], - offset = this.results[id]['attrs']['o'], - len = this.results[id]['attrs']['l'], - row, item, dummy; - - // [Add to dictionary] button - if (this.has_dictionary && !$(elm).attr('is_corrected')) { - row = document.createElement('tr'), - item = document.createElement('td'), - dummy = document.createElement('span'); - - $(dummy).text(this.lang_learn_word); - $(item).attr('googie_action_btn', '1').css('cursor', 'default') - .mouseover(ref.item_onmouseover) - .mouseout(ref.item_onmouseout) - .click(function(e) { - ref.learnWord(elm, id); - ref.ignoreError(elm, id); - }); - - item.appendChild(dummy); - row.appendChild(item); - list.appendChild(row); - } -/* - if (suggestions.length == 0) { - row = document.createElement('tr'), - item = document.createElement('td'), - dummy = document.createElement('span'); - - $(dummy).text(this.lang_no_suggestions); - $(item).attr('googie_action_btn', '1').css('cursor', 'default'); - - item.appendChild(dummy); - row.appendChild(item); - list.appendChild(row); - } -*/ - for (var i=0, len=suggestions.length; i < len; i++) { - row = document.createElement('tr'), - item = document.createElement('td'), - dummy = document.createElement('span'); - - $(dummy).html(suggestions[i]); - - $(item).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout) - .click(function(e) { ref.correctError(id, elm, e.target.firstChild) }); - - item.appendChild(dummy); - row.appendChild(item); - list.appendChild(row); - } - - // The element is changed, append the revert - if (elm.is_changed && elm.innerHTML != elm.old_value) { - var old_value = elm.old_value, - revert_row = document.createElement('tr'), - revert = document.createElement('td'), - rev_span = document.createElement('span'); - - $(rev_span).addClass('googie_list_revert').html(this.lang_revert + ' ' + old_value); - - $(revert).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout) - .click(function(e) { - ref.updateOrginalText(offset, elm.innerHTML, old_value, id); - $(elm).removeAttr('is_corrected').css('color', '#b91414').html(old_value); - ref.hideErrorWindow(); - }); - - revert.appendChild(rev_span); - revert_row.appendChild(revert); - list.appendChild(revert_row); - } - - // Append the edit box - var edit_row = document.createElement('tr'), - edit = document.createElement('td'), - edit_input = document.createElement('input'), - ok_pic = document.createElement('img'), - edit_form = document.createElement('form'); - - var onsub = function () { - if (edit_input.value != '') { - if (!ref.isDefined(elm.old_value)) - ref.saveOldValue(elm, elm.innerHTML); - - ref.updateOrginalText(offset, elm.innerHTML, edit_input.value, id); - $(elm).attr('is_corrected', true).css('color', 'green').html(edit_input.value); - ref.hideErrorWindow(); - } - return false; - }; - - $(edit_input).width(120).css({'margin': 0, 'padding': 0}); - $(edit_input).val(elm.innerHTML).attr('googie_action_btn', '1'); - $(edit).css('cursor', 'default').attr('googie_action_btn', '1'); - - $(ok_pic).attr('src', this.img_dir + 'ok.gif') - .width(32).height(16) - .css({'cursor': 'pointer', 'margin-left': '2px', 'margin-right': '2px'}) - .click(onsub); - - $(edit_form).attr('googie_action_btn', '1') - .css({'margin': 0, 'padding': 0, 'cursor': 'default', 'white-space': 'nowrap'}) - .submit(onsub); - - edit_form.appendChild(edit_input); - edit_form.appendChild(ok_pic); - edit.appendChild(edit_form); - edit_row.appendChild(edit); - list.appendChild(edit_row); - - // Append extra menu items - if (this.extra_menu_items.length > 0) - list.appendChild(this.createListSeparator()); - - var loop = function(i) { - if (i < ref.extra_menu_items.length) { - var e_elm = ref.extra_menu_items[i]; - - if (!e_elm[2] || e_elm[2](elm, ref)) { - var e_row = document.createElement('tr'), - e_col = document.createElement('td'); - - $(e_col).html(e_elm[0]) - .mouseover(ref.item_onmouseover) - .mouseout(ref.item_onmouseout) - .click(function() { return e_elm[1](elm, ref) }); - - e_row.appendChild(e_col); - list.appendChild(e_row); - } - loop(i+1); - } - }; - - loop(0); - loop = null; - - //Close button - if (this.use_close_btn) { - list.appendChild(this.createCloseButton(this.hideErrorWindow)); - } - } - - table.appendChild(list); - this.error_window.appendChild(table); - - // calculate and set position - var height = $(this.error_window).height(), - width = $(this.error_window).width(), - pageheight = $(document).height(), - pagewidth = $(document).width(), - top = pos.top + height + 20 < pageheight ? pos.top + 20 : pos.top - height, - left = pos.left + width < pagewidth ? pos.left : pos.left - width; - - $(this.error_window).css({'top': top+'px', 'left': left+'px'}).show(); - - // Dummy for IE - dropdown bug fix - if (document.all && !window.opera) { - if (!this.error_window_iframe) { - var iframe = $('<iframe>').css({'position': 'absolute', 'z-index': -1}); - $('body').append(iframe); - this.error_window_iframe = iframe; - } - - $(this.error_window_iframe) - .css({'top': this.error_window.offsetTop, 'left': this.error_window.offsetLeft, - 'width': this.error_window.offsetWidth, 'height': this.error_window.offsetHeight}) - .show(); - } -}; - - -////// -// Edit layer (the layer where the suggestions are stored) -////// -this.createEditLayer = function(width, height) -{ - this.edit_layer = document.createElement('div'); - $(this.edit_layer).addClass('googie_edit_layer').attr('id', 'googie_edit_layer') - .width('auto').height(height); - - if (this.text_area.nodeName.toLowerCase() != 'input' || $(this.text_area).val() == '') { - $(this.edit_layer).css('overflow', 'auto').height(height-4); - } else { - $(this.edit_layer).css('overflow', 'hidden'); - } - - var ref = this; - - if (this.edit_layer_dbl_click) { - $(this.edit_layer).dblclick(function(e) { - if (e.target.className != 'googie_link' && !ref.isErrorWindowShown()) { - ref.resumeEditing(); - var fn1 = function() { - $(ref.text_area).focus(); - fn1 = null; - }; - window.setTimeout(fn1, 10); - } - return false; - }); - } -}; - -this.resumeEditing = function() -{ - this.setStateChanged('ready'); - - if (this.edit_layer) - this.el_scroll_top = this.edit_layer.scrollTop; - - this.hideErrorWindow(); - - if (this.main_controller) - $(this.spell_span).removeClass().addClass('googie_no_style'); - - if (!this.ignore) { - if (this.use_focus) { - $(this.focus_link_t).remove(); - $(this.focus_link_b).remove(); - } - - $(this.edit_layer).remove(); - $(this.text_area).show(); - - if (this.el_scroll_top != undefined) - this.text_area.scrollTop = this.el_scroll_top; - } - this.checkSpellingState(false); -}; - -this.createErrorLink = function(text, id) -{ - var elm = document.createElement('span'), - ref = this, - d = function (e) { - ref.showErrorWindow(elm, id); - d = null; - return false; - }; - - $(elm).html(text).addClass('googie_link').click(d).removeAttr('is_corrected') - .attr({'googie_action_btn' : '1', 'g_id' : id}); - - return elm; -}; - -this.createPart = function(txt_part) -{ - if (txt_part == " ") - return document.createTextNode(" "); - - txt_part = this.escapeSpecial(txt_part); - txt_part = txt_part.replace(/\n/g, "<br>"); - txt_part = txt_part.replace(/ /g, " "); - txt_part = txt_part.replace(/^ /g, " "); - txt_part = txt_part.replace(/ $/g, " "); - - var span = document.createElement('span'); - $(span).html(txt_part); - return span; -}; - -this.showErrorsInIframe = function() -{ - var output = document.createElement('div'), - pointer = 0, - results = this.results; - - if (results.length > 0) { - for (var i=0, length=results.length; i < length; i++) { - var offset = results[i]['attrs']['o'], - len = results[i]['attrs']['l'], - part_1_text = this.orginal_text.substring(pointer, offset), - part_1 = this.createPart(part_1_text); - - output.appendChild(part_1); - pointer += offset - pointer; - - // If the last child was an error, then insert some space - var err_link = this.createErrorLink(this.orginal_text.substr(offset, len), i); - this.error_links.push(err_link); - output.appendChild(err_link); - pointer += len; - } - - // Insert the rest of the orginal text - var part_2_text = this.orginal_text.substr(pointer, this.orginal_text.length), - part_2 = this.createPart(part_2_text); - - output.appendChild(part_2); - } - else - output.innerHTML = this.orginal_text; - - $(output).css('text-align', 'left'); - - var me = this; - if (this.custom_item_evaulator) - $.map(this.error_links, function(elm){me.custom_item_evaulator(me, elm)}); - - $(this.edit_layer).append(output); - - // Hide text area and show edit layer - $(this.text_area).hide(); - $(this.edit_layer).insertBefore(this.text_area); - - if (this.use_focus) { - this.focus_link_t = this.createFocusLink('focus_t'); - this.focus_link_b = this.createFocusLink('focus_b'); - - $(this.focus_link_t).insertBefore(this.edit_layer); - $(this.focus_link_b).insertAfter(this.edit_layer); - } - -// this.edit_layer.scrollTop = this.ta_scroll_top; -}; - - -////// -// Choose language menu -////// -this.createLangWindow = function() -{ - this.language_window = document.createElement('div'); - $(this.language_window).addClass('googie_window popupmenu') - .width(100).attr('googie_action_btn', '1'); - - // Build up the result list - var table = document.createElement('table'), - list = document.createElement('tbody'), - ref = this, - row, item, span; - - $(table).addClass('googie_list').width('100%'); - this.lang_elms = []; - - for (i=0; i < this.langlist_codes.length; i++) { - row = document.createElement('tr'); - item = document.createElement('td'); - span = document.createElement('span'); - - $(span).text(this.lang_to_word[this.langlist_codes[i]]); - this.lang_elms.push(item); - - $(item).attr('googieId', this.langlist_codes[i]) - .bind('click', function(e) { - ref.deHighlightCurSel(); - ref.setCurrentLanguage($(this).attr('googieId')); - - if (ref.lang_state_observer != null) { - ref.lang_state_observer(); - } - - ref.highlightCurSel(); - ref.hideLangWindow(); - }) - .bind('mouseover', function(e) { - if (this.className != "googie_list_selected") - this.className = "googie_list_onhover"; - }) - .bind('mouseout', function(e) { - if (this.className != "googie_list_selected") - this.className = "googie_list_onout"; - }); - - item.appendChild(span); - row.appendChild(item); - list.appendChild(row); - } - - // Close button - if (this.use_close_btn) { - list.appendChild(this.createCloseButton(function () { ref.hideLangWindow.apply(ref) })); - } - - this.highlightCurSel(); - - table.appendChild(list); - this.language_window.appendChild(table); -}; - -this.isLangWindowShown = function() -{ - return $(this.language_window).is(':visible'); -}; - -this.hideLangWindow = function() -{ - $(this.language_window).hide(); - $(this.switch_lan_pic).removeClass().addClass('googie_lang_3d_on'); -}; - -this.showLangWindow = function(elm) -{ - if (this.show_menu_observer) - this.show_menu_observer(this); - - this.createLangWindow(); - $('body').append(this.language_window); - - var pos = $(elm).offset(), - height = $(elm).height(), - width = $(elm).width(), - h = $(this.language_window).height(), - pageheight = $(document).height(), - left = this.change_lang_pic_placement == 'right' ? - pos.left - 100 + width : pos.left + width, - top = pos.top + h < pageheight ? pos.top + height : pos.top - h - 4; - - $(this.language_window).css({'top' : top+'px','left' : left+'px'}).show(); - - this.highlightCurSel(); -}; - -this.deHighlightCurSel = function() -{ - $(this.lang_cur_elm).removeClass().addClass('googie_list_onout'); -}; - -this.highlightCurSel = function() -{ - if (GOOGIE_CUR_LANG == null) - GOOGIE_CUR_LANG = GOOGIE_DEFAULT_LANG; - for (var i=0; i < this.lang_elms.length; i++) { - if ($(this.lang_elms[i]).attr('googieId') == GOOGIE_CUR_LANG) { - this.lang_elms[i].className = 'googie_list_selected'; - this.lang_cur_elm = this.lang_elms[i]; - } - else { - this.lang_elms[i].className = 'googie_list_onout'; - } - } -}; - -this.createChangeLangPic = function() -{ - var img = $('<img>') - .attr({src: this.img_dir + 'change_lang.gif', 'alt': 'Change language', 'googie_action_btn': '1'}), - switch_lan = document.createElement('span'); - ref = this; - - $(switch_lan).addClass('googie_lang_3d_on') - .append(img) - .bind('click', function(e) { - var elm = this.tagName.toLowerCase() == 'img' ? this.parentNode : this; - if($(elm).hasClass('googie_lang_3d_click')) { - elm.className = 'googie_lang_3d_on'; - ref.hideLangWindow(); - } - else { - elm.className = 'googie_lang_3d_click'; - ref.showLangWindow(elm); - } - }); - - return switch_lan; -}; - -this.createSpellDiv = function() -{ - var span = document.createElement('span'); - - $(span).addClass('googie_check_spelling_link').text(this.lang_chck_spell); - - if (this.show_spell_img) { - $(span).append(' ').append($('<img>').attr('src', this.img_dir + 'spellc.gif')); - } - return span; -}; - - -////// -// State functions -///// -this.flashNoSpellingErrorState = function(on_finish) -{ - this.setStateChanged('no_error_found'); - - var ref = this; - if (this.main_controller) { - var no_spell_errors; - if (on_finish) { - var fn = function() { - on_finish(); - ref.checkSpellingState(); - }; - no_spell_errors = fn; - } - else - no_spell_errors = function () { ref.checkSpellingState() }; - - var rsm = $('<span>').text(this.lang_no_error_found); - - $(this.switch_lan_pic).hide(); - $(this.spell_span).empty().append(rsm) - .removeClass().addClass('googie_check_spelling_ok'); - - window.setTimeout(no_spell_errors, 1000); - } -}; - -this.resumeEditingState = function() -{ - this.setStateChanged('resume_editing'); - - //Change link text to resume - if (this.main_controller) { - var rsm = $('<span>').text(this.lang_rsm_edt); - var ref = this; - - $(this.switch_lan_pic).hide(); - $(this.spell_span).empty().unbind().append(rsm) - .bind('click', function() { ref.resumeEditing() }) - .removeClass().addClass('googie_resume_editing'); - } - - try { this.edit_layer.scrollTop = this.ta_scroll_top; } - catch (e) {}; -}; - -this.checkSpellingState = function(fire) -{ - if (fire) - this.setStateChanged('ready'); - - if (this.show_change_lang_pic) - this.switch_lan_pic = this.createChangeLangPic(); - else - this.switch_lan_pic = document.createElement('span'); - - var span_chck = this.createSpellDiv(), - ref = this; - - if (this.custom_spellcheck_starter) - $(span_chck).bind('click', function(e) { ref.custom_spellcheck_starter() }); - else { - $(span_chck).bind('click', function(e) { ref.spellCheck() }); - } - - if (this.main_controller) { - if (this.change_lang_pic_placement == 'left') { - $(this.spell_container).empty().append(this.switch_lan_pic).append(' ').append(span_chck); - } else { - $(this.spell_container).empty().append(span_chck).append(' ').append(this.switch_lan_pic); - } - } - - this.spell_span = span_chck; -}; - - -////// -// Misc. functions -///// -this.isDefined = function(o) -{ - return (o !== undefined && o !== null) -}; - -this.errorFixed = function() -{ - this.cnt_errors_fixed++; - if (this.all_errors_fixed_observer) - if (this.cnt_errors_fixed == this.cnt_errors) { - this.hideErrorWindow(); - this.all_errors_fixed_observer(); - } -}; - -this.errorFound = function() -{ - this.cnt_errors++; -}; - -this.createCloseButton = function(c_fn) -{ - return this.createButton(this.lang_close, 'googie_list_close', c_fn); -}; - -this.createButton = function(name, css_class, c_fn) -{ - var btn_row = document.createElement('tr'), - btn = document.createElement('td'), - spn_btn; - - if (css_class) { - spn_btn = document.createElement('span'); - $(spn_btn).addClass(css_class).html(name); - } else { - spn_btn = document.createTextNode(name); - } - - $(btn).bind('click', c_fn) - .bind('mouseover', this.item_onmouseover) - .bind('mouseout', this.item_onmouseout); - - btn.appendChild(spn_btn); - btn_row.appendChild(btn); - - return btn_row; -}; - -this.removeIndicator = function(elm) -{ - //$(this.indicator).remove(); - // roundcube mod. - if (window.rcmail) - rcmail.set_busy(false, null, this.rc_msg_id); -}; - -this.appendIndicator = function(elm) -{ - // modified by roundcube - if (window.rcmail) - this.rc_msg_id = rcmail.set_busy(true, 'checking'); -/* - this.indicator = document.createElement('img'); - $(this.indicator).attr('src', this.img_dir + 'indicator.gif') - .css({'margin-right': '5px', 'text-decoration': 'none'}).width(16).height(16); - - if (elm) - $(this.indicator).insertBefore(elm); - else - $('body').append(this.indicator); -*/ -} - -this.createFocusLink = function(name) -{ - var link = document.createElement('a'); - $(link).attr({'href': 'javascript:;', 'name': name}); - return link; -}; - -this.item_onmouseover = function(e) -{ - if (this.className != 'googie_list_revert' && this.className != 'googie_list_close') - this.className = 'googie_list_onhover'; - else - this.parentNode.className = 'googie_list_onhover'; -}; - -this.item_onmouseout = function(e) -{ - if (this.className != 'googie_list_revert' && this.className != 'googie_list_close') - this.className = 'googie_list_onout'; - else - this.parentNode.className = 'googie_list_onout'; -}; - - -}; +var GOOGIE_CUR_LANG,GOOGIE_DEFAULT_LANG="en";function GoogieSpell(c,a,e){var b=this,d=rcmail.get_cookie("language");GOOGIE_CUR_LANG=d!=null?d:GOOGIE_DEFAULT_LANG;this.array_keys=function(f){var h=[];for(var g in f){h.push([g])}return h};this.img_dir=c;this.server_url=a;this.org_lang_to_word={da:"Dansk",de:"Deutsch",en:"English",es:"Español",fr:"Français",it:"Italiano",nl:"Nederlands",pl:"Polski",pt:"Português",ru:"Русский",fi:"Suomi",sv:"Svenska"};this.lang_to_word=this.org_lang_to_word;this.langlist_codes=this.array_keys(this.lang_to_word);this.show_change_lang_pic=true;this.change_lang_pic_placement="right";this.report_state_change=true;this.ta_scroll_top=0;this.el_scroll_top=0;this.lang_chck_spell="Check spelling";this.lang_revert="Revert to";this.lang_close="Close";this.lang_rsm_edt="Resume editing";this.lang_no_error_found="No spelling errors found";this.lang_no_suggestions="No suggestions";this.lang_learn_word="Add to dictionary";this.show_spell_img=false;this.decoration=true;this.use_close_btn=false;this.edit_layer_dbl_click=true;this.report_ta_not_found=true;this.custom_ajax_error=null;this.custom_no_spelling_error=null;this.custom_menu_builder=[];this.custom_item_evaulator=null;this.extra_menu_items=[];this.custom_spellcheck_starter=null;this.main_controller=true;this.has_dictionary=e;this.lang_state_observer=null;this.spelling_state_observer=null;this.show_menu_observer=null;this.all_errors_fixed_observer=null;this.use_focus=false;this.focus_link_t=null;this.focus_link_b=null;this.cnt_errors=0;this.cnt_errors_fixed=0;$(document).bind("click",function(g){var f=$(g.target);if(f.attr("googie_action_btn")!="1"&&b.isLangWindowShown()){b.hideLangWindow()}if(f.attr("googie_action_btn")!="1"&&b.isErrorWindowShown()){b.hideErrorWindow()}});this.decorateTextarea=function(m){this.text_area=typeof m==="string"?document.getElementById(m):m;if(this.text_area){if(!this.spell_container&&this.decoration){var j=document.createElement("table"),g=document.createElement("tbody"),l=document.createElement("tr"),k=document.createElement("td"),f=this.isDefined(this.force_width)?this.force_width:this.text_area.offsetWidth,h=this.isDefined(this.force_height)?this.force_height:16;l.appendChild(k);g.appendChild(l);$(j).append(g).insertBefore(this.text_area).width("100%").height(h);$(k).height(h).width(f).css("text-align","right");this.spell_container=k}this.checkSpellingState()}else{if(this.report_ta_not_found){alert("Text area not found")}}};this.setSpellContainer=function(f){this.spell_container=typeof f==="string"?document.getElementById(f):f};this.setLanguages=function(f){this.lang_to_word=f;this.langlist_codes=this.array_keys(f)};this.setCurrentLanguage=function(g){GOOGIE_CUR_LANG=g;var f=new Date();f.setTime(f.getTime()+365*24*60*60*1000);rcmail.set_cookie("language",g,f)};this.setForceWidthHeight=function(g,f){this.force_width=g;this.force_height=f};this.setDecoration=function(f){this.decoration=f};this.dontUseCloseButtons=function(){this.use_close_btn=false};this.appendNewMenuItem=function(g,h,f){this.extra_menu_items.push([g,h,f])};this.appendCustomMenuBuilder=function(g,f){this.custom_menu_builder.push([g,f])};this.setFocus=function(){try{this.focus_link_b.focus();this.focus_link_t.focus();return true}catch(f){return false}};this.setStateChanged=function(f){this.state=f;if(this.spelling_state_observer!=null&&this.report_state_change){this.spelling_state_observer(f,this)}};this.setReportStateChange=function(f){this.report_state_change=f};this.getUrl=function(){return this.server_url+GOOGIE_CUR_LANG};this.escapeSpecial=function(f){return f?f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">"):""};this.createXMLReq=function(f){return'<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>'+f+"</text></spellrequest>"};this.spellCheck=function(h){this.prepare(h);var g=this.escapeSpecial(this.orginal_text),f=this;$.ajax({type:"POST",url:this.getUrl(),data:this.createXMLReq(g),dataType:"text",error:function(j){if(f.custom_ajax_error){f.custom_ajax_error(f)}else{alert("An error was encountered on the server. Please try again later.")}if(f.main_controller){$(f.spell_span).remove();f.removeIndicator()}f.checkSpellingState()},success:function(j){f.processData(j);if(!f.results.length){if(!f.custom_no_spelling_error){f.flashNoSpellingErrorState()}else{f.custom_no_spelling_error(f)}}f.removeIndicator()}})};this.learnWord=function(h,j){h=this.escapeSpecial(h.innerHTML);var g=this,f='<?xml version="1.0" encoding="utf-8" ?><learnword><text>'+h+"</text></learnword>";$.ajax({type:"POST",url:this.getUrl(),data:f,dataType:"text",error:function(k){if(g.custom_ajax_error){g.custom_ajax_error(g)}else{alert("An error was encountered on the server. Please try again later.")}},success:function(k){}})};this.prepare=function(h,g){this.cnt_errors_fixed=0;this.cnt_errors=0;this.setStateChanged("checking_spell");if(!g&&this.main_controller){this.appendIndicator(this.spell_span)}this.error_links=[];this.ta_scroll_top=this.text_area.scrollTop;this.ignore=h;this.hideLangWindow();if($(this.text_area).val()==""||h){if(!this.custom_no_spelling_error){this.flashNoSpellingErrorState()}else{this.custom_no_spelling_error(this)}this.removeIndicator();return}this.createEditLayer(this.text_area.offsetWidth,this.text_area.offsetHeight);this.createErrorWindow();$("body").append(this.error_window);try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")}catch(f){}if(this.main_controller){$(this.spell_span).unbind("click")}this.orginal_text=$(this.text_area).val()};this.parseResult=function(s){var l=/\w+="(\d+|true)"/g,o=/\t/g,f=s.match(/<c[^>]*>[^<]*<\/c>/g),p=[];if(f==null){return p}for(var q=0,r=f.length;q<r;q++){var w=[];this.errorFound();w.attrs=[];var u,h,v=f[q].match(l);for(var n=0;n<v.length;n++){u=v[n].split(/=/);h=u[1].replace(/"/g,"");w.attrs[u[0]]=h!="true"?parseInt(h):h}w.suggestions=[];var t=f[q].replace(/<[^>]*>/g,""),g=t.split(o);for(var m=0;m<g.length;m++){if(g[m]!=""){w.suggestions.push(g[m])}}p.push(w)}return p};this.processData=function(f){this.results=this.parseResult(f);if(this.results.length){this.showErrorsInIframe();this.resumeEditingState()}};this.createErrorWindow=function(){this.error_window=document.createElement("div");$(this.error_window).addClass("googie_window popupmenu").attr("googie_action_btn","1")};this.isErrorWindowShown=function(){return $(this.error_window).is(":visible")};this.hideErrorWindow=function(){$(this.error_window).hide();$(this.error_window_iframe).hide()};this.updateOrginalText=function(k,n,p,f){var h=this.orginal_text.substring(0,k),g=this.orginal_text.substring(k+n.length),o=p.length-n.length;this.orginal_text=h+p+g;$(this.text_area).val(this.orginal_text);for(var l=0,m=this.results.length;l<m;l++){if(l!=f&&l>f){this.results[l]["attrs"]["o"]+=o}}};this.saveOldValue=function(g,f){g.is_changed=true;g.old_value=f};this.createListSeparator=function(){var g=document.createElement("td"),f=document.createElement("tr");$(g).html(" ").attr("googie_action_btn","1").css({cursor:"default","font-size":"3px","border-top":"1px solid #ccc","padding-top":"3px"});f.appendChild(g);return f};this.correctError=function(n,m,l,f){var g=m.innerHTML,h=l.nodeType==3?l.nodeValue:l.innerHTML,k=this.results[n]["attrs"]["o"];if(f){var j=m.previousSibling.innerHTML;m.previousSibling.innerHTML=j.slice(0,j.length-1);g=" "+g;k--}this.hideErrorWindow();this.updateOrginalText(k,g,h,n);$(m).html(h).css("color","green").attr("is_corrected",true);this.results[n]["attrs"]["l"]=h.length;if(!this.isDefined(m.old_value)){this.saveOldValue(m,g)}this.errorFixed()};this.ignoreError=function(g,f){$(g).removeAttr("class").css("color","").unbind();this.hideErrorWindow()};this.showErrorWindow=function(u,B){if(this.show_menu_observer){this.show_menu_observer(this)}var o=this,p=$(u).offset(),I=document.createElement("table"),J=document.createElement("tbody");$(this.error_window).html("");$(I).addClass("googie_list").attr("googie_action_btn","1");var r=false;for(var F=0;F<this.custom_menu_builder.length;F++){var q=this.custom_menu_builder[F];if(q[0](this.results[B])){r=q[1](this,J,u);break}}if(!r){var z=this.results[B]["suggestions"],n=this.results[B]["attrs"]["o"],H=this.results[B]["attrs"]["l"],t,K,O;if(this.has_dictionary&&!$(u).attr("is_corrected")){t=document.createElement("tr"),K=document.createElement("td"),O=document.createElement("span");$(O).text(this.lang_learn_word);$(K).attr("googie_action_btn","1").css("cursor","default").mouseover(o.item_onmouseover).mouseout(o.item_onmouseout).click(function(k){o.learnWord(u,B);o.ignoreError(u,B)});K.appendChild(O);t.appendChild(K);J.appendChild(t)}for(var G=0,H=z.length;G<H;G++){t=document.createElement("tr"),K=document.createElement("td"),O=document.createElement("span");$(O).html(z[G]);$(K).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(k){o.correctError(B,u,k.target.firstChild)});K.appendChild(O);t.appendChild(K);J.appendChild(t)}if(u.is_changed&&u.innerHTML!=u.old_value){var g=u.old_value,j=document.createElement("tr"),f=document.createElement("td"),s=document.createElement("span");$(s).addClass("googie_list_revert").html(this.lang_revert+" "+g);$(f).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(k){o.updateOrginalText(n,u.innerHTML,g,B);$(u).removeAttr("is_corrected").css("color","#b91414").html(g);o.hideErrorWindow()});f.appendChild(s);j.appendChild(f);J.appendChild(j)}var M=document.createElement("tr"),C=document.createElement("td"),N=document.createElement("input"),w=document.createElement("img"),h=document.createElement("form");var m=function(){if(N.value!=""){if(!o.isDefined(u.old_value)){o.saveOldValue(u,u.innerHTML)}o.updateOrginalText(n,u.innerHTML,N.value,B);$(u).attr("is_corrected",true).css("color","green").html(N.value);o.hideErrorWindow()}return false};$(N).width(120).css({margin:0,padding:0});$(N).val(u.innerHTML).attr("googie_action_btn","1");$(C).css("cursor","default").attr("googie_action_btn","1");$(w).attr("src",this.img_dir+"ok.gif").width(32).height(16).css({cursor:"pointer","margin-left":"2px","margin-right":"2px"}).click(m);$(h).attr("googie_action_btn","1").css({margin:0,padding:0,cursor:"default","white-space":"nowrap"}).submit(m);h.appendChild(N);h.appendChild(w);C.appendChild(h);M.appendChild(C);J.appendChild(M);if(this.extra_menu_items.length>0){J.appendChild(this.createListSeparator())}var L=function(Q){if(Q<o.extra_menu_items.length){var P=o.extra_menu_items[Q];if(!P[2]||P[2](u,o)){var k=document.createElement("tr"),R=document.createElement("td");$(R).html(P[0]).mouseover(o.item_onmouseover).mouseout(o.item_onmouseout).click(function(){return P[1](u,o)});k.appendChild(R);J.appendChild(k)}L(Q+1)}};L(0);L=null;if(this.use_close_btn){J.appendChild(this.createCloseButton(this.hideErrorWindow))}}I.appendChild(J);this.error_window.appendChild(I);var A=$(this.error_window).height(),E=$(this.error_window).width(),x=$(document).height(),D=$(document).width(),y=p.top+A+20<x?p.top+20:p.top-A,l=p.left+E<D?p.left:p.left-E;$(this.error_window).css({top:y+"px",left:l+"px"}).show();if($.browser.msie){if(!this.error_window_iframe){var v=$("<iframe>").css({position:"absolute","z-index":-1});$("body").append(v);this.error_window_iframe=v}$(this.error_window_iframe).css({top:this.error_window.offsetTop,left:this.error_window.offsetLeft,width:this.error_window.offsetWidth,height:this.error_window.offsetHeight}).show()}};this.createEditLayer=function(g,f){this.edit_layer=document.createElement("div");$(this.edit_layer).addClass("googie_edit_layer").attr("id","googie_edit_layer").width("auto").height(f);if(this.text_area.nodeName.toLowerCase()!="input"||$(this.text_area).val()==""){$(this.edit_layer).css("overflow","auto").height(f-4)}else{$(this.edit_layer).css("overflow","hidden")}var h=this;if(this.edit_layer_dbl_click){$(this.edit_layer).dblclick(function(k){if(k.target.className!="googie_link"&&!h.isErrorWindowShown()){h.resumeEditing();var j=function(){$(h.text_area).focus();j=null};window.setTimeout(j,10)}return false})}};this.resumeEditing=function(){this.setStateChanged("ready");if(this.edit_layer){this.el_scroll_top=this.edit_layer.scrollTop}this.hideErrorWindow();if(this.main_controller){$(this.spell_span).removeClass().addClass("googie_no_style")}if(!this.ignore){if(this.use_focus){$(this.focus_link_t).remove();$(this.focus_link_b).remove()}$(this.edit_layer).remove();$(this.text_area).show();if(this.el_scroll_top!=undefined){this.text_area.scrollTop=this.el_scroll_top}}this.checkSpellingState(false)};this.createErrorLink=function(h,k){var j=document.createElement("span"),f=this,g=function(l){f.showErrorWindow(j,k);g=null;return false};$(j).html(h).addClass("googie_link").click(g).removeAttr("is_corrected").attr({googie_action_btn:"1",g_id:k});return j};this.createPart=function(g){if(g==" "){return document.createTextNode(" ")}g=this.escapeSpecial(g);g=g.replace(/\n/g,"<br>");g=g.replace(/ /g," ");g=g.replace(/^ /g," ");g=g.replace(/ $/g," ");var f=document.createElement("span");$(f).html(g);return f};this.showErrorsInIframe=function(){var m=document.createElement("div"),f=0,o=this.results;if(o.length>0){for(var p=0,k=o.length;p<k;p++){var n=o[p]["attrs"]["o"],r=o[p]["attrs"]["l"],j=this.orginal_text.substring(f,n),l=this.createPart(j);m.appendChild(l);f+=n-f;var g=this.createErrorLink(this.orginal_text.substr(n,r),p);this.error_links.push(g);m.appendChild(g);f+=r}var q=this.orginal_text.substr(f,this.orginal_text.length),h=this.createPart(q);m.appendChild(h)}else{m.innerHTML=this.orginal_text}$(m).css("text-align","left");var s=this;if(this.custom_item_evaulator){$.map(this.error_links,function(t){s.custom_item_evaulator(s,t)})}$(this.edit_layer).append(m);$(this.text_area).hide();$(this.edit_layer).insertBefore(this.text_area);if(this.use_focus){this.focus_link_t=this.createFocusLink("focus_t");this.focus_link_b=this.createFocusLink("focus_b");$(this.focus_link_t).insertBefore(this.edit_layer);$(this.focus_link_b).insertAfter(this.edit_layer)}};this.createLangWindow=function(){this.language_window=document.createElement("div");$(this.language_window).addClass("googie_window popupmenu").width(100).attr("googie_action_btn","1");var j=document.createElement("table"),k=document.createElement("tbody"),h=this,l,g,f;$(j).addClass("googie_list").width("100%");this.lang_elms=[];for(i=0;i<this.langlist_codes.length;i++){l=document.createElement("tr");g=document.createElement("td");f=document.createElement("span");$(f).text(this.lang_to_word[this.langlist_codes[i]]);this.lang_elms.push(g);$(g).attr("googieId",this.langlist_codes[i]).bind("click",function(m){h.deHighlightCurSel();h.setCurrentLanguage($(this).attr("googieId"));if(h.lang_state_observer!=null){h.lang_state_observer()}h.highlightCurSel();h.hideLangWindow()}).bind("mouseover",function(m){if(this.className!="googie_list_selected"){this.className="googie_list_onhover"}}).bind("mouseout",function(m){if(this.className!="googie_list_selected"){this.className="googie_list_onout"}});g.appendChild(f);l.appendChild(g);k.appendChild(l)}if(this.use_close_btn){k.appendChild(this.createCloseButton(function(){h.hideLangWindow.apply(h)}))}this.highlightCurSel();j.appendChild(k);this.language_window.appendChild(j)};this.isLangWindowShown=function(){return $(this.language_window).is(":visible")};this.hideLangWindow=function(){$(this.language_window).hide();$(this.switch_lan_pic).removeClass().addClass("googie_lang_3d_on")};this.showLangWindow=function(o){if(this.show_menu_observer){this.show_menu_observer(this)}this.createLangWindow();$("body").append(this.language_window);var n=$(o).offset(),f=$(o).height(),j=$(o).width(),g=$(this.language_window).height(),k=$(document).height(),m=this.change_lang_pic_placement=="right"?n.left-100+j:n.left+j,l=n.top+g<k?n.top+f:n.top-g-4;$(this.language_window).css({top:l+"px",left:m+"px"}).show();this.highlightCurSel()};this.deHighlightCurSel=function(){$(this.lang_cur_elm).removeClass().addClass("googie_list_onout")};this.highlightCurSel=function(){if(GOOGIE_CUR_LANG==null){GOOGIE_CUR_LANG=GOOGIE_DEFAULT_LANG}for(var f=0;f<this.lang_elms.length;f++){if($(this.lang_elms[f]).attr("googieId")==GOOGIE_CUR_LANG){this.lang_elms[f].className="googie_list_selected";this.lang_cur_elm=this.lang_elms[f]}else{this.lang_elms[f].className="googie_list_onout"}}};this.createChangeLangPic=function(){var f=$("<img>").attr({src:this.img_dir+"change_lang.gif",alt:"Change language",googie_action_btn:"1"}),g=document.createElement("span");b=this;$(g).addClass("googie_lang_3d_on").append(f).bind("click",function(h){var j=this.tagName.toLowerCase()=="img"?this.parentNode:this;if($(j).hasClass("googie_lang_3d_click")){j.className="googie_lang_3d_on";b.hideLangWindow()}else{j.className="googie_lang_3d_click";b.showLangWindow(j)}});return g};this.createSpellDiv=function(){var f=document.createElement("span");$(f).addClass("googie_check_spelling_link").text(this.lang_chck_spell);if(this.show_spell_img){$(f).append(" ").append($("<img>").attr("src",this.img_dir+"spellc.gif"))}return f};this.flashNoSpellingErrorState=function(f){this.setStateChanged("no_error_found");var j=this;if(this.main_controller){var k;if(f){var h=function(){f();j.checkSpellingState()};k=h}else{k=function(){j.checkSpellingState()}}var g=$("<span>").text(this.lang_no_error_found);$(this.switch_lan_pic).hide();$(this.spell_span).empty().append(g).removeClass().addClass("googie_check_spelling_ok");window.setTimeout(k,1000)}};this.resumeEditingState=function(){this.setStateChanged("resume_editing");if(this.main_controller){var f=$("<span>").text(this.lang_rsm_edt);var g=this;$(this.switch_lan_pic).hide();$(this.spell_span).empty().unbind().append(f).bind("click",function(){g.resumeEditing()}).removeClass().addClass("googie_resume_editing")}try{this.edit_layer.scrollTop=this.ta_scroll_top}catch(h){}};this.checkSpellingState=function(g){if(g){this.setStateChanged("ready")}if(this.show_change_lang_pic){this.switch_lan_pic=this.createChangeLangPic()}else{this.switch_lan_pic=document.createElement("span")}var f=this.createSpellDiv(),h=this;if(this.custom_spellcheck_starter){$(f).bind("click",function(j){h.custom_spellcheck_starter()})}else{$(f).bind("click",function(j){h.spellCheck()})}if(this.main_controller){if(this.change_lang_pic_placement=="left"){$(this.spell_container).empty().append(this.switch_lan_pic).append(" ").append(f)}else{$(this.spell_container).empty().append(f).append(" ").append(this.switch_lan_pic)}}this.spell_span=f};this.isDefined=function(f){return(f!==undefined&&f!==null)};this.errorFixed=function(){this.cnt_errors_fixed++;if(this.all_errors_fixed_observer){if(this.cnt_errors_fixed==this.cnt_errors){this.hideErrorWindow();this.all_errors_fixed_observer()}}};this.errorFound=function(){this.cnt_errors++};this.createCloseButton=function(f){return this.createButton(this.lang_close,"googie_list_close",f)};this.createButton=function(g,j,l){var k=document.createElement("tr"),h=document.createElement("td"),f;if(j){f=document.createElement("span");$(f).addClass(j).html(g)}else{f=document.createTextNode(g)}$(h).bind("click",l).bind("mouseover",this.item_onmouseover).bind("mouseout",this.item_onmouseout);h.appendChild(f);k.appendChild(h);return k};this.removeIndicator=function(f){if(window.rcmail){rcmail.set_busy(false,null,this.rc_msg_id)}};this.appendIndicator=function(f){if(window.rcmail){this.rc_msg_id=rcmail.set_busy(true,"checking")}};this.createFocusLink=function(f){var g=document.createElement("a");$(g).attr({href:"javascript:;",name:f});return g};this.item_onmouseover=function(f){if(this.className!="googie_list_revert"&&this.className!="googie_list_close"){this.className="googie_list_onhover"}else{this.parentNode.className="googie_list_onhover"}};this.item_onmouseout=function(f){if(this.className!="googie_list_revert"&&this.className!="googie_list_close"){this.className="googie_list_onout"}else{this.parentNode.className="googie_list_onout"}}};
\ No newline at end of file diff --git a/program/js/jquery.min.js b/program/js/jquery.min.js index 83589daa7..5cb76ea03 100644..120000 --- a/program/js/jquery.min.js +++ b/program/js/jquery.min.js @@ -1,2 +1 @@ -/*! jQuery v1.8.3 jquery.com | jquery.org/license */
-(function(e,t){function _(e){var t=M[e]={};return v.each(e.split(y),function(e,n){t[n]=!0}),t}function H(e,n,r){if(r===t&&e.nodeType===1){var i="data-"+n.replace(P,"-$1").toLowerCase();r=e.getAttribute(i);if(typeof r=="string"){try{r=r==="true"?!0:r==="false"?!1:r==="null"?null:+r+""===r?+r:D.test(r)?v.parseJSON(r):r}catch(s){}v.data(e,n,r)}else r=t}return r}function B(e){var t;for(t in e){if(t==="data"&&v.isEmptyObject(e[t]))continue;if(t!=="toJSON")return!1}return!0}function et(){return!1}function tt(){return!0}function ut(e){return!e||!e.parentNode||e.parentNode.nodeType===11}function at(e,t){do e=e[t];while(e&&e.nodeType!==1);return e}function ft(e,t,n){t=t||0;if(v.isFunction(t))return v.grep(e,function(e,r){var i=!!t.call(e,r,e);return i===n});if(t.nodeType)return v.grep(e,function(e,r){return e===t===n});if(typeof t=="string"){var r=v.grep(e,function(e){return e.nodeType===1});if(it.test(t))return v.filter(t,r,!n);t=v.filter(t,r)}return v.grep(e,function(e,r){return v.inArray(e,t)>=0===n})}function lt(e){var t=ct.split("|"),n=e.createDocumentFragment();if(n.createElement)while(t.length)n.createElement(t.pop());return n}function Lt(e,t){return e.getElementsByTagName(t)[0]||e.appendChild(e.ownerDocument.createElement(t))}function At(e,t){if(t.nodeType!==1||!v.hasData(e))return;var n,r,i,s=v._data(e),o=v._data(t,s),u=s.events;if(u){delete o.handle,o.events={};for(n in u)for(r=0,i=u[n].length;r<i;r++)v.event.add(t,n,u[n][r])}o.data&&(o.data=v.extend({},o.data))}function Ot(e,t){var n;if(t.nodeType!==1)return;t.clearAttributes&&t.clearAttributes(),t.mergeAttributes&&t.mergeAttributes(e),n=t.nodeName.toLowerCase(),n==="object"?(t.parentNode&&(t.outerHTML=e.outerHTML),v.support.html5Clone&&e.innerHTML&&!v.trim(t.innerHTML)&&(t.innerHTML=e.innerHTML)):n==="input"&&Et.test(e.type)?(t.defaultChecked=t.checked=e.checked,t.value!==e.value&&(t.value=e.value)):n==="option"?t.selected=e.defaultSelected:n==="input"||n==="textarea"?t.defaultValue=e.defaultValue:n==="script"&&t.text!==e.text&&(t.text=e.text),t.removeAttribute(v.expando)}function Mt(e){return typeof e.getElementsByTagName!="undefined"?e.getElementsByTagName("*"):typeof e.querySelectorAll!="undefined"?e.querySelectorAll("*"):[]}function _t(e){Et.test(e.type)&&(e.defaultChecked=e.checked)}function Qt(e,t){if(t in e)return t;var n=t.charAt(0).toUpperCase()+t.slice(1),r=t,i=Jt.length;while(i--){t=Jt[i]+n;if(t in e)return t}return r}function Gt(e,t){return e=t||e,v.css(e,"display")==="none"||!v.contains(e.ownerDocument,e)}function Yt(e,t){var n,r,i=[],s=0,o=e.length;for(;s<o;s++){n=e[s];if(!n.style)continue;i[s]=v._data(n,"olddisplay"),t?(!i[s]&&n.style.display==="none"&&(n.style.display=""),n.style.display===""&&Gt(n)&&(i[s]=v._data(n,"olddisplay",nn(n.nodeName)))):(r=Dt(n,"display"),!i[s]&&r!=="none"&&v._data(n,"olddisplay",r))}for(s=0;s<o;s++){n=e[s];if(!n.style)continue;if(!t||n.style.display==="none"||n.style.display==="")n.style.display=t?i[s]||"":"none"}return e}function Zt(e,t,n){var r=Rt.exec(t);return r?Math.max(0,r[1]-(n||0))+(r[2]||"px"):t}function en(e,t,n,r){var i=n===(r?"border":"content")?4:t==="width"?1:0,s=0;for(;i<4;i+=2)n==="margin"&&(s+=v.css(e,n+$t[i],!0)),r?(n==="content"&&(s-=parseFloat(Dt(e,"padding"+$t[i]))||0),n!=="margin"&&(s-=parseFloat(Dt(e,"border"+$t[i]+"Width"))||0)):(s+=parseFloat(Dt(e,"padding"+$t[i]))||0,n!=="padding"&&(s+=parseFloat(Dt(e,"border"+$t[i]+"Width"))||0));return s}function tn(e,t,n){var r=t==="width"?e.offsetWidth:e.offsetHeight,i=!0,s=v.support.boxSizing&&v.css(e,"boxSizing")==="border-box";if(r<=0||r==null){r=Dt(e,t);if(r<0||r==null)r=e.style[t];if(Ut.test(r))return r;i=s&&(v.support.boxSizingReliable||r===e.style[t]),r=parseFloat(r)||0}return r+en(e,t,n||(s?"border":"content"),i)+"px"}function nn(e){if(Wt[e])return Wt[e];var t=v("<"+e+">").appendTo(i.body),n=t.css("display");t.remove();if(n==="none"||n===""){Pt=i.body.appendChild(Pt||v.extend(i.createElement("iframe"),{frameBorder:0,width:0,height:0}));if(!Ht||!Pt.createElement)Ht=(Pt.contentWindow||Pt.contentDocument).document,Ht.write("<!doctype html><html><body>"),Ht.close();t=Ht.body.appendChild(Ht.createElement(e)),n=Dt(t,"display"),i.body.removeChild(Pt)}return Wt[e]=n,n}function fn(e,t,n,r){var i;if(v.isArray(t))v.each(t,function(t,i){n||sn.test(e)?r(e,i):fn(e+"["+(typeof i=="object"?t:"")+"]",i,n,r)});else if(!n&&v.type(t)==="object")for(i in t)fn(e+"["+i+"]",t[i],n,r);else r(e,t)}function Cn(e){return function(t,n){typeof t!="string"&&(n=t,t="*");var r,i,s,o=t.toLowerCase().split(y),u=0,a=o.length;if(v.isFunction(n))for(;u<a;u++)r=o[u],s=/^\+/.test(r),s&&(r=r.substr(1)||"*"),i=e[r]=e[r]||[],i[s?"unshift":"push"](n)}}function kn(e,n,r,i,s,o){s=s||n.dataTypes[0],o=o||{},o[s]=!0;var u,a=e[s],f=0,l=a?a.length:0,c=e===Sn;for(;f<l&&(c||!u);f++)u=a[f](n,r,i),typeof u=="string"&&(!c||o[u]?u=t:(n.dataTypes.unshift(u),u=kn(e,n,r,i,u,o)));return(c||!u)&&!o["*"]&&(u=kn(e,n,r,i,"*",o)),u}function Ln(e,n){var r,i,s=v.ajaxSettings.flatOptions||{};for(r in n)n[r]!==t&&((s[r]?e:i||(i={}))[r]=n[r]);i&&v.extend(!0,e,i)}function An(e,n,r){var i,s,o,u,a=e.contents,f=e.dataTypes,l=e.responseFields;for(s in l)s in r&&(n[l[s]]=r[s]);while(f[0]==="*")f.shift(),i===t&&(i=e.mimeType||n.getResponseHeader("content-type"));if(i)for(s in a)if(a[s]&&a[s].test(i)){f.unshift(s);break}if(f[0]in r)o=f[0];else{for(s in r){if(!f[0]||e.converters[s+" "+f[0]]){o=s;break}u||(u=s)}o=o||u}if(o)return o!==f[0]&&f.unshift(o),r[o]}function On(e,t){var n,r,i,s,o=e.dataTypes.slice(),u=o[0],a={},f=0;e.dataFilter&&(t=e.dataFilter(t,e.dataType));if(o[1])for(n in e.converters)a[n.toLowerCase()]=e.converters[n];for(;i=o[++f];)if(i!=="*"){if(u!=="*"&&u!==i){n=a[u+" "+i]||a["* "+i];if(!n)for(r in a){s=r.split(" ");if(s[1]===i){n=a[u+" "+s[0]]||a["* "+s[0]];if(n){n===!0?n=a[r]:a[r]!==!0&&(i=s[0],o.splice(f--,0,i));break}}}if(n!==!0)if(n&&e["throws"])t=n(t);else try{t=n(t)}catch(l){return{state:"parsererror",error:n?l:"No conversion from "+u+" to "+i}}}u=i}return{state:"success",data:t}}function Fn(){try{return new e.XMLHttpRequest}catch(t){}}function In(){try{return new e.ActiveXObject("Microsoft.XMLHTTP")}catch(t){}}function $n(){return setTimeout(function(){qn=t},0),qn=v.now()}function Jn(e,t){v.each(t,function(t,n){var r=(Vn[t]||[]).concat(Vn["*"]),i=0,s=r.length;for(;i<s;i++)if(r[i].call(e,t,n))return})}function Kn(e,t,n){var r,i=0,s=0,o=Xn.length,u=v.Deferred().always(function(){delete a.elem}),a=function(){var t=qn||$n(),n=Math.max(0,f.startTime+f.duration-t),r=n/f.duration||0,i=1-r,s=0,o=f.tweens.length;for(;s<o;s++)f.tweens[s].run(i);return u.notifyWith(e,[f,i,n]),i<1&&o?n:(u.resolveWith(e,[f]),!1)},f=u.promise({elem:e,props:v.extend({},t),opts:v.extend(!0,{specialEasing:{}},n),originalProperties:t,originalOptions:n,startTime:qn||$n(),duration:n.duration,tweens:[],createTween:function(t,n,r){var i=v.Tween(e,f.opts,t,n,f.opts.specialEasing[t]||f.opts.easing);return f.tweens.push(i),i},stop:function(t){var n=0,r=t?f.tweens.length:0;for(;n<r;n++)f.tweens[n].run(1);return t?u.resolveWith(e,[f,t]):u.rejectWith(e,[f,t]),this}}),l=f.props;Qn(l,f.opts.specialEasing);for(;i<o;i++){r=Xn[i].call(f,e,l,f.opts);if(r)return r}return Jn(f,l),v.isFunction(f.opts.start)&&f.opts.start.call(e,f),v.fx.timer(v.extend(a,{anim:f,queue:f.opts.queue,elem:e})),f.progress(f.opts.progress).done(f.opts.done,f.opts.complete).fail(f.opts.fail).always(f.opts.always)}function Qn(e,t){var n,r,i,s,o;for(n in e){r=v.camelCase(n),i=t[r],s=e[n],v.isArray(s)&&(i=s[1],s=e[n]=s[0]),n!==r&&(e[r]=s,delete e[n]),o=v.cssHooks[r];if(o&&"expand"in o){s=o.expand(s),delete e[r];for(n in s)n in e||(e[n]=s[n],t[n]=i)}else t[r]=i}}function Gn(e,t,n){var r,i,s,o,u,a,f,l,c,h=this,p=e.style,d={},m=[],g=e.nodeType&&Gt(e);n.queue||(l=v._queueHooks(e,"fx"),l.unqueued==null&&(l.unqueued=0,c=l.empty.fire,l.empty.fire=function(){l.unqueued||c()}),l.unqueued++,h.always(function(){h.always(function(){l.unqueued--,v.queue(e,"fx").length||l.empty.fire()})})),e.nodeType===1&&("height"in t||"width"in t)&&(n.overflow=[p.overflow,p.overflowX,p.overflowY],v.css(e,"display")==="inline"&&v.css(e,"float")==="none"&&(!v.support.inlineBlockNeedsLayout||nn(e.nodeName)==="inline"?p.display="inline-block":p.zoom=1)),n.overflow&&(p.overflow="hidden",v.support.shrinkWrapBlocks||h.done(function(){p.overflow=n.overflow[0],p.overflowX=n.overflow[1],p.overflowY=n.overflow[2]}));for(r in t){s=t[r];if(Un.exec(s)){delete t[r],a=a||s==="toggle";if(s===(g?"hide":"show"))continue;m.push(r)}}o=m.length;if(o){u=v._data(e,"fxshow")||v._data(e,"fxshow",{}),"hidden"in u&&(g=u.hidden),a&&(u.hidden=!g),g?v(e).show():h.done(function(){v(e).hide()}),h.done(function(){var t;v.removeData(e,"fxshow",!0);for(t in d)v.style(e,t,d[t])});for(r=0;r<o;r++)i=m[r],f=h.createTween(i,g?u[i]:0),d[i]=u[i]||v.style(e,i),i in u||(u[i]=f.start,g&&(f.end=f.start,f.start=i==="width"||i==="height"?1:0))}}function Yn(e,t,n,r,i){return new Yn.prototype.init(e,t,n,r,i)}function Zn(e,t){var n,r={height:e},i=0;t=t?1:0;for(;i<4;i+=2-t)n=$t[i],r["margin"+n]=r["padding"+n]=e;return t&&(r.opacity=r.width=e),r}function tr(e){return v.isWindow(e)?e:e.nodeType===9?e.defaultView||e.parentWindow:!1}var n,r,i=e.document,s=e.location,o=e.navigator,u=e.jQuery,a=e.$,f=Array.prototype.push,l=Array.prototype.slice,c=Array.prototype.indexOf,h=Object.prototype.toString,p=Object.prototype.hasOwnProperty,d=String.prototype.trim,v=function(e,t){return new v.fn.init(e,t,n)},m=/[\-+]?(?:\d*\.|)\d+(?:[eE][\-+]?\d+|)/.source,g=/\S/,y=/\s+/,b=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,w=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,E=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,S=/^[\],:{}\s]*$/,x=/(?:^|:|,)(?:\s*\[)+/g,T=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,N=/"[^"\\\r\n]*"|true|false|null|-?(?:\d\d*\.|)\d+(?:[eE][\-+]?\d+|)/g,C=/^-ms-/,k=/-([\da-z])/gi,L=function(e,t){return(t+"").toUpperCase()},A=function(){i.addEventListener?(i.removeEventListener("DOMContentLoaded",A,!1),v.ready()):i.readyState==="complete"&&(i.detachEvent("onreadystatechange",A),v.ready())},O={};v.fn=v.prototype={constructor:v,init:function(e,n,r){var s,o,u,a;if(!e)return this;if(e.nodeType)return this.context=this[0]=e,this.length=1,this;if(typeof e=="string"){e.charAt(0)==="<"&&e.charAt(e.length-1)===">"&&e.length>=3?s=[null,e,null]:s=w.exec(e);if(s&&(s[1]||!n)){if(s[1])return n=n instanceof v?n[0]:n,a=n&&n.nodeType?n.ownerDocument||n:i,e=v.parseHTML(s[1],a,!0),E.test(s[1])&&v.isPlainObject(n)&&this.attr.call(e,n,!0),v.merge(this,e);o=i.getElementById(s[2]);if(o&&o.parentNode){if(o.id!==s[2])return r.find(e);this.length=1,this[0]=o}return this.context=i,this.selector=e,this}return!n||n.jquery?(n||r).find(e):this.constructor(n).find(e)}return v.isFunction(e)?r.ready(e):(e.selector!==t&&(this.selector=e.selector,this.context=e.context),v.makeArray(e,this))},selector:"",jquery:"1.8.3",length:0,size:function(){return this.length},toArray:function(){return l.call(this)},get:function(e){return e==null?this.toArray():e<0?this[this.length+e]:this[e]},pushStack:function(e,t,n){var r=v.merge(this.constructor(),e);return r.prevObject=this,r.context=this.context,t==="find"?r.selector=this.selector+(this.selector?" ":"")+n:t&&(r.selector=this.selector+"."+t+"("+n+")"),r},each:function(e,t){return v.each(this,e,t)},ready:function(e){return v.ready.promise().done(e),this},eq:function(e){return e=+e,e===-1?this.slice(e):this.slice(e,e+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(l.apply(this,arguments),"slice",l.call(arguments).join(","))},map:function(e){return this.pushStack(v.map(this,function(t,n){return e.call(t,n,t)}))},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:[].sort,splice:[].splice},v.fn.init.prototype=v.fn,v.extend=v.fn.extend=function(){var e,n,r,i,s,o,u=arguments[0]||{},a=1,f=arguments.length,l=!1;typeof u=="boolean"&&(l=u,u=arguments[1]||{},a=2),typeof u!="object"&&!v.isFunction(u)&&(u={}),f===a&&(u=this,--a);for(;a<f;a++)if((e=arguments[a])!=null)for(n in e){r=u[n],i=e[n];if(u===i)continue;l&&i&&(v.isPlainObject(i)||(s=v.isArray(i)))?(s?(s=!1,o=r&&v.isArray(r)?r:[]):o=r&&v.isPlainObject(r)?r:{},u[n]=v.extend(l,o,i)):i!==t&&(u[n]=i)}return u},v.extend({noConflict:function(t){return e.$===v&&(e.$=a),t&&e.jQuery===v&&(e.jQuery=u),v},isReady:!1,readyWait:1,holdReady:function(e){e?v.readyWait++:v.ready(!0)},ready:function(e){if(e===!0?--v.readyWait:v.isReady)return;if(!i.body)return setTimeout(v.ready,1);v.isReady=!0;if(e!==!0&&--v.readyWait>0)return;r.resolveWith(i,[v]),v.fn.trigger&&v(i).trigger("ready").off("ready")},isFunction:function(e){return v.type(e)==="function"},isArray:Array.isArray||function(e){return v.type(e)==="array"},isWindow:function(e){return e!=null&&e==e.window},isNumeric:function(e){return!isNaN(parseFloat(e))&&isFinite(e)},type:function(e){return e==null?String(e):O[h.call(e)]||"object"},isPlainObject:function(e){if(!e||v.type(e)!=="object"||e.nodeType||v.isWindow(e))return!1;try{if(e.constructor&&!p.call(e,"constructor")&&!p.call(e.constructor.prototype,"isPrototypeOf"))return!1}catch(n){return!1}var r;for(r in e);return r===t||p.call(e,r)},isEmptyObject:function(e){var t;for(t in e)return!1;return!0},error:function(e){throw new Error(e)},parseHTML:function(e,t,n){var r;return!e||typeof e!="string"?null:(typeof t=="boolean"&&(n=t,t=0),t=t||i,(r=E.exec(e))?[t.createElement(r[1])]:(r=v.buildFragment([e],t,n?null:[]),v.merge([],(r.cacheable?v.clone(r.fragment):r.fragment).childNodes)))},parseJSON:function(t){if(!t||typeof t!="string")return null;t=v.trim(t);if(e.JSON&&e.JSON.parse)return e.JSON.parse(t);if(S.test(t.replace(T,"@").replace(N,"]").replace(x,"")))return(new Function("return "+t))();v.error("Invalid JSON: "+t)},parseXML:function(n){var r,i;if(!n||typeof n!="string")return null;try{e.DOMParser?(i=new DOMParser,r=i.parseFromString(n,"text/xml")):(r=new ActiveXObject("Microsoft.XMLDOM"),r.async="false",r.loadXML(n))}catch(s){r=t}return(!r||!r.documentElement||r.getElementsByTagName("parsererror").length)&&v.error("Invalid XML: "+n),r},noop:function(){},globalEval:function(t){t&&g.test(t)&&(e.execScript||function(t){e.eval.call(e,t)})(t)},camelCase:function(e){return e.replace(C,"ms-").replace(k,L)},nodeName:function(e,t){return e.nodeName&&e.nodeName.toLowerCase()===t.toLowerCase()},each:function(e,n,r){var i,s=0,o=e.length,u=o===t||v.isFunction(e);if(r){if(u){for(i in e)if(n.apply(e[i],r)===!1)break}else for(;s<o;)if(n.apply(e[s++],r)===!1)break}else if(u){for(i in e)if(n.call(e[i],i,e[i])===!1)break}else for(;s<o;)if(n.call(e[s],s,e[s++])===!1)break;return e},trim:d&&!d.call("\ufeff\u00a0")?function(e){return e==null?"":d.call(e)}:function(e){return e==null?"":(e+"").replace(b,"")},makeArray:function(e,t){var n,r=t||[];return e!=null&&(n=v.type(e),e.length==null||n==="string"||n==="function"||n==="regexp"||v.isWindow(e)?f.call(r,e):v.merge(r,e)),r},inArray:function(e,t,n){var r;if(t){if(c)return c.call(t,e,n);r=t.length,n=n?n<0?Math.max(0,r+n):n:0;for(;n<r;n++)if(n in t&&t[n]===e)return n}return-1},merge:function(e,n){var r=n.length,i=e.length,s=0;if(typeof r=="number")for(;s<r;s++)e[i++]=n[s];else while(n[s]!==t)e[i++]=n[s++];return e.length=i,e},grep:function(e,t,n){var r,i=[],s=0,o=e.length;n=!!n;for(;s<o;s++)r=!!t(e[s],s),n!==r&&i.push(e[s]);return i},map:function(e,n,r){var i,s,o=[],u=0,a=e.length,f=e instanceof v||a!==t&&typeof a=="number"&&(a>0&&e[0]&&e[a-1]||a===0||v.isArray(e));if(f)for(;u<a;u++)i=n(e[u],u,r),i!=null&&(o[o.length]=i);else for(s in e)i=n(e[s],s,r),i!=null&&(o[o.length]=i);return o.concat.apply([],o)},guid:1,proxy:function(e,n){var r,i,s;return typeof n=="string"&&(r=e[n],n=e,e=r),v.isFunction(e)?(i=l.call(arguments,2),s=function(){return e.apply(n,i.concat(l.call(arguments)))},s.guid=e.guid=e.guid||v.guid++,s):t},access:function(e,n,r,i,s,o,u){var a,f=r==null,l=0,c=e.length;if(r&&typeof r=="object"){for(l in r)v.access(e,n,l,r[l],1,o,i);s=1}else if(i!==t){a=u===t&&v.isFunction(i),f&&(a?(a=n,n=function(e,t,n){return a.call(v(e),n)}):(n.call(e,i),n=null));if(n)for(;l<c;l++)n(e[l],r,a?i.call(e[l],l,n(e[l],r)):i,u);s=1}return s?e:f?n.call(e):c?n(e[0],r):o},now:function(){return(new Date).getTime()}}),v.ready.promise=function(t){if(!r){r=v.Deferred();if(i.readyState==="complete")setTimeout(v.ready,1);else if(i.addEventListener)i.addEventListener("DOMContentLoaded",A,!1),e.addEventListener("load",v.ready,!1);else{i.attachEvent("onreadystatechange",A),e.attachEvent("onload",v.ready);var n=!1;try{n=e.frameElement==null&&i.documentElement}catch(s){}n&&n.doScroll&&function o(){if(!v.isReady){try{n.doScroll("left")}catch(e){return setTimeout(o,50)}v.ready()}}()}}return r.promise(t)},v.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(e,t){O["[object "+t+"]"]=t.toLowerCase()}),n=v(i);var M={};v.Callbacks=function(e){e=typeof e=="string"?M[e]||_(e):v.extend({},e);var n,r,i,s,o,u,a=[],f=!e.once&&[],l=function(t){n=e.memory&&t,r=!0,u=s||0,s=0,o=a.length,i=!0;for(;a&&u<o;u++)if(a[u].apply(t[0],t[1])===!1&&e.stopOnFalse){n=!1;break}i=!1,a&&(f?f.length&&l(f.shift()):n?a=[]:c.disable())},c={add:function(){if(a){var t=a.length;(function r(t){v.each(t,function(t,n){var i=v.type(n);i==="function"?(!e.unique||!c.has(n))&&a.push(n):n&&n.length&&i!=="string"&&r(n)})})(arguments),i?o=a.length:n&&(s=t,l(n))}return this},remove:function(){return a&&v.each(arguments,function(e,t){var n;while((n=v.inArray(t,a,n))>-1)a.splice(n,1),i&&(n<=o&&o--,n<=u&&u--)}),this},has:function(e){return v.inArray(e,a)>-1},empty:function(){return a=[],this},disable:function(){return a=f=n=t,this},disabled:function(){return!a},lock:function(){return f=t,n||c.disable(),this},locked:function(){return!f},fireWith:function(e,t){return t=t||[],t=[e,t.slice?t.slice():t],a&&(!r||f)&&(i?f.push(t):l(t)),this},fire:function(){return c.fireWith(this,arguments),this},fired:function(){return!!r}};return c},v.extend({Deferred:function(e){var t=[["resolve","done",v.Callbacks("once memory"),"resolved"],["reject","fail",v.Callbacks("once memory"),"rejected"],["notify","progress",v.Callbacks("memory")]],n="pending",r={state:function(){return n},always:function(){return i.done(arguments).fail(arguments),this},then:function(){var e=arguments;return v.Deferred(function(n){v.each(t,function(t,r){var s=r[0],o=e[t];i[r[1]](v.isFunction(o)?function(){var e=o.apply(this,arguments);e&&v.isFunction(e.promise)?e.promise().done(n.resolve).fail(n.reject).progress(n.notify):n[s+"With"](this===i?n:this,[e])}:n[s])}),e=null}).promise()},promise:function(e){return e!=null?v.extend(e,r):r}},i={};return r.pipe=r.then,v.each(t,function(e,s){var o=s[2],u=s[3];r[s[1]]=o.add,u&&o.add(function(){n=u},t[e^1][2].disable,t[2][2].lock),i[s[0]]=o.fire,i[s[0]+"With"]=o.fireWith}),r.promise(i),e&&e.call(i,i),i},when:function(e){var t=0,n=l.call(arguments),r=n.length,i=r!==1||e&&v.isFunction(e.promise)?r:0,s=i===1?e:v.Deferred(),o=function(e,t,n){return function(r){t[e]=this,n[e]=arguments.length>1?l.call(arguments):r,n===u?s.notifyWith(t,n):--i||s.resolveWith(t,n)}},u,a,f;if(r>1){u=new Array(r),a=new Array(r),f=new Array(r);for(;t<r;t++)n[t]&&v.isFunction(n[t].promise)?n[t].promise().done(o(t,f,n)).fail(s.reject).progress(o(t,a,u)):--i}return i||s.resolveWith(f,n),s.promise()}}),v.support=function(){var t,n,r,s,o,u,a,f,l,c,h,p=i.createElement("div");p.setAttribute("className","t"),p.innerHTML=" <link/><table></table><a href='/a'>a</a><input type='checkbox'/>",n=p.getElementsByTagName("*"),r=p.getElementsByTagName("a")[0];if(!n||!r||!n.length)return{};s=i.createElement("select"),o=s.appendChild(i.createElement("option")),u=p.getElementsByTagName("input")[0],r.style.cssText="top:1px;float:left;opacity:.5",t={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName("tbody").length,htmlSerialize:!!p.getElementsByTagName("link").length,style:/top/.test(r.getAttribute("style")),hrefNormalized:r.getAttribute("href")==="/a",opacity:/^0.5/.test(r.style.opacity),cssFloat:!!r.style.cssFloat,checkOn:u.value==="on",optSelected:o.selected,getSetAttribute:p.className!=="t",enctype:!!i.createElement("form").enctype,html5Clone:i.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",boxModel:i.compatMode==="CSS1Compat",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,boxSizingReliable:!0,pixelPosition:!1},u.checked=!0,t.noCloneChecked=u.cloneNode(!0).checked,s.disabled=!0,t.optDisabled=!o.disabled;try{delete p.test}catch(d){t.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent("onclick",h=function(){t.noCloneEvent=!1}),p.cloneNode(!0).fireEvent("onclick"),p.detachEvent("onclick",h)),u=i.createElement("input"),u.value="t",u.setAttribute("type","radio"),t.radioValue=u.value==="t",u.setAttribute("checked","checked"),u.setAttribute("name","t"),p.appendChild(u),a=i.createDocumentFragment(),a.appendChild(p.lastChild),t.checkClone=a.cloneNode(!0).cloneNode(!0).lastChild.checked,t.appendChecked=u.checked,a.removeChild(u),a.appendChild(p);if(p.attachEvent)for(l in{submit:!0,change:!0,focusin:!0})f="on"+l,c=f in p,c||(p.setAttribute(f,"return;"),c=typeof p[f]=="function"),t[l+"Bubbles"]=c;return v(function(){var n,r,s,o,u="padding:0;margin:0;border:0;display:block;overflow:hidden;",a=i.getElementsByTagName("body")[0];if(!a)return;n=i.createElement("div"),n.style.cssText="visibility:hidden;border:0;width:0;height:0;position:static;top:0;margin-top:1px",a.insertBefore(n,a.firstChild),r=i.createElement("div"),n.appendChild(r),r.innerHTML="<table><tr><td></td><td>t</td></tr></table>",s=r.getElementsByTagName("td"),s[0].style.cssText="padding:0;margin:0;border:0;display:none",c=s[0].offsetHeight===0,s[0].style.display="",s[1].style.display="none",t.reliableHiddenOffsets=c&&s[0].offsetHeight===0,r.innerHTML="",r.style.cssText="box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;padding:1px;border:1px;display:block;width:4px;margin-top:1%;position:absolute;top:1%;",t.boxSizing=r.offsetWidth===4,t.doesNotIncludeMarginInBodyOffset=a.offsetTop!==1,e.getComputedStyle&&(t.pixelPosition=(e.getComputedStyle(r,null)||{}).top!=="1%",t.boxSizingReliable=(e.getComputedStyle(r,null)||{width:"4px"}).width==="4px",o=i.createElement("div"),o.style.cssText=r.style.cssText=u,o.style.marginRight=o.style.width="0",r.style.width="1px",r.appendChild(o),t.reliableMarginRight=!parseFloat((e.getComputedStyle(o,null)||{}).marginRight)),typeof r.style.zoom!="undefined"&&(r.innerHTML="",r.style.cssText=u+"width:1px;padding:1px;display:inline;zoom:1",t.inlineBlockNeedsLayout=r.offsetWidth===3,r.style.display="block",r.style.overflow="visible",r.innerHTML="<div></div>",r.firstChild.style.width="5px",t.shrinkWrapBlocks=r.offsetWidth!==3,n.style.zoom=1),a.removeChild(n),n=r=s=o=null}),a.removeChild(p),n=r=s=o=u=a=p=null,t}();var D=/(?:\{[\s\S]*\}|\[[\s\S]*\])$/,P=/([A-Z])/g;v.extend({cache:{},deletedIds:[],uuid:0,expando:"jQuery"+(v.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(e){return e=e.nodeType?v.cache[e[v.expando]]:e[v.expando],!!e&&!B(e)},data:function(e,n,r,i){if(!v.acceptData(e))return;var s,o,u=v.expando,a=typeof n=="string",f=e.nodeType,l=f?v.cache:e,c=f?e[u]:e[u]&&u;if((!c||!l[c]||!i&&!l[c].data)&&a&&r===t)return;c||(f?e[u]=c=v.deletedIds.pop()||v.guid++:c=u),l[c]||(l[c]={},f||(l[c].toJSON=v.noop));if(typeof n=="object"||typeof n=="function")i?l[c]=v.extend(l[c],n):l[c].data=v.extend(l[c].data,n);return s=l[c],i||(s.data||(s.data={}),s=s.data),r!==t&&(s[v.camelCase(n)]=r),a?(o=s[n],o==null&&(o=s[v.camelCase(n)])):o=s,o},removeData:function(e,t,n){if(!v.acceptData(e))return;var r,i,s,o=e.nodeType,u=o?v.cache:e,a=o?e[v.expando]:v.expando;if(!u[a])return;if(t){r=n?u[a]:u[a].data;if(r){v.isArray(t)||(t in r?t=[t]:(t=v.camelCase(t),t in r?t=[t]:t=t.split(" ")));for(i=0,s=t.length;i<s;i++)delete r[t[i]];if(!(n?B:v.isEmptyObject)(r))return}}if(!n){delete u[a].data;if(!B(u[a]))return}o?v.cleanData([e],!0):v.support.deleteExpando||u!=u.window?delete u[a]:u[a]=null},_data:function(e,t,n){return v.data(e,t,n,!0)},acceptData:function(e){var t=e.nodeName&&v.noData[e.nodeName.toLowerCase()];return!t||t!==!0&&e.getAttribute("classid")===t}}),v.fn.extend({data:function(e,n){var r,i,s,o,u,a=this[0],f=0,l=null;if(e===t){if(this.length){l=v.data(a);if(a.nodeType===1&&!v._data(a,"parsedAttrs")){s=a.attributes;for(u=s.length;f<u;f++)o=s[f].name,o.indexOf("data-")||(o=v.camelCase(o.substring(5)),H(a,o,l[o]));v._data(a,"parsedAttrs",!0)}}return l}return typeof e=="object"?this.each(function(){v.data(this,e)}):(r=e.split(".",2),r[1]=r[1]?"."+r[1]:"",i=r[1]+"!",v.access(this,function(n){if(n===t)return l=this.triggerHandler("getData"+i,[r[0]]),l===t&&a&&(l=v.data(a,e),l=H(a,e,l)),l===t&&r[1]?this.data(r[0]):l;r[1]=n,this.each(function(){var t=v(this);t.triggerHandler("setData"+i,r),v.data(this,e,n),t.triggerHandler("changeData"+i,r)})},null,n,arguments.length>1,null,!1))},removeData:function(e){return this.each(function(){v.removeData(this,e)})}}),v.extend({queue:function(e,t,n){var r;if(e)return t=(t||"fx")+"queue",r=v._data(e,t),n&&(!r||v.isArray(n)?r=v._data(e,t,v.makeArray(n)):r.push(n)),r||[]},dequeue:function(e,t){t=t||"fx";var n=v.queue(e,t),r=n.length,i=n.shift(),s=v._queueHooks(e,t),o=function(){v.dequeue(e,t)};i==="inprogress"&&(i=n.shift(),r--),i&&(t==="fx"&&n.unshift("inprogress"),delete s.stop,i.call(e,o,s)),!r&&s&&s.empty.fire()},_queueHooks:function(e,t){var n=t+"queueHooks";return v._data(e,n)||v._data(e,n,{empty:v.Callbacks("once memory").add(function(){v.removeData(e,t+"queue",!0),v.removeData(e,n,!0)})})}}),v.fn.extend({queue:function(e,n){var r=2;return typeof e!="string"&&(n=e,e="fx",r--),arguments.length<r?v.queue(this[0],e):n===t?this:this.each(function(){var t=v.queue(this,e,n);v._queueHooks(this,e),e==="fx"&&t[0]!=="inprogress"&&v.dequeue(this,e)})},dequeue:function(e){return this.each(function(){v.dequeue(this,e)})},delay:function(e,t){return e=v.fx?v.fx.speeds[e]||e:e,t=t||"fx",this.queue(t,function(t,n){var r=setTimeout(t,e);n.stop=function(){clearTimeout(r)}})},clearQueue:function(e){return this.queue(e||"fx",[])},promise:function(e,n){var r,i=1,s=v.Deferred(),o=this,u=this.length,a=function(){--i||s.resolveWith(o,[o])};typeof e!="string"&&(n=e,e=t),e=e||"fx";while(u--)r=v._data(o[u],e+"queueHooks"),r&&r.empty&&(i++,r.empty.add(a));return a(),s.promise(n)}});var j,F,I,q=/[\t\r\n]/g,R=/\r/g,U=/^(?:button|input)$/i,z=/^(?:button|input|object|select|textarea)$/i,W=/^a(?:rea|)$/i,X=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,V=v.support.getSetAttribute;v.fn.extend({attr:function(e,t){return v.access(this,v.attr,e,t,arguments.length>1)},removeAttr:function(e){return this.each(function(){v.removeAttr(this,e)})},prop:function(e,t){return v.access(this,v.prop,e,t,arguments.length>1)},removeProp:function(e){return e=v.propFix[e]||e,this.each(function(){try{this[e]=t,delete this[e]}catch(n){}})},addClass:function(e){var t,n,r,i,s,o,u;if(v.isFunction(e))return this.each(function(t){v(this).addClass(e.call(this,t,this.className))});if(e&&typeof e=="string"){t=e.split(y);for(n=0,r=this.length;n<r;n++){i=this[n];if(i.nodeType===1)if(!i.className&&t.length===1)i.className=e;else{s=" "+i.className+" ";for(o=0,u=t.length;o<u;o++)s.indexOf(" "+t[o]+" ")<0&&(s+=t[o]+" ");i.className=v.trim(s)}}}return this},removeClass:function(e){var n,r,i,s,o,u,a;if(v.isFunction(e))return this.each(function(t){v(this).removeClass(e.call(this,t,this.className))});if(e&&typeof e=="string"||e===t){n=(e||"").split(y);for(u=0,a=this.length;u<a;u++){i=this[u];if(i.nodeType===1&&i.className){r=(" "+i.className+" ").replace(q," ");for(s=0,o=n.length;s<o;s++)while(r.indexOf(" "+n[s]+" ")>=0)r=r.replace(" "+n[s]+" "," ");i.className=e?v.trim(r):""}}}return this},toggleClass:function(e,t){var n=typeof e,r=typeof t=="boolean";return v.isFunction(e)?this.each(function(n){v(this).toggleClass(e.call(this,n,this.className,t),t)}):this.each(function(){if(n==="string"){var i,s=0,o=v(this),u=t,a=e.split(y);while(i=a[s++])u=r?u:!o.hasClass(i),o[u?"addClass":"removeClass"](i)}else if(n==="undefined"||n==="boolean")this.className&&v._data(this,"__className__",this.className),this.className=this.className||e===!1?"":v._data(this,"__className__")||""})},hasClass:function(e){var t=" "+e+" ",n=0,r=this.length;for(;n<r;n++)if(this[n].nodeType===1&&(" "+this[n].className+" ").replace(q," ").indexOf(t)>=0)return!0;return!1},val:function(e){var n,r,i,s=this[0];if(!arguments.length){if(s)return n=v.valHooks[s.type]||v.valHooks[s.nodeName.toLowerCase()],n&&"get"in n&&(r=n.get(s,"value"))!==t?r:(r=s.value,typeof r=="string"?r.replace(R,""):r==null?"":r);return}return i=v.isFunction(e),this.each(function(r){var s,o=v(this);if(this.nodeType!==1)return;i?s=e.call(this,r,o.val()):s=e,s==null?s="":typeof s=="number"?s+="":v.isArray(s)&&(s=v.map(s,function(e){return e==null?"":e+""})),n=v.valHooks[this.type]||v.valHooks[this.nodeName.toLowerCase()];if(!n||!("set"in n)||n.set(this,s,"value")===t)this.value=s})}}),v.extend({valHooks:{option:{get:function(e){var t=e.attributes.value;return!t||t.specified?e.value:e.text}},select:{get:function(e){var t,n,r=e.options,i=e.selectedIndex,s=e.type==="select-one"||i<0,o=s?null:[],u=s?i+1:r.length,a=i<0?u:s?i:0;for(;a<u;a++){n=r[a];if((n.selected||a===i)&&(v.support.optDisabled?!n.disabled:n.getAttribute("disabled")===null)&&(!n.parentNode.disabled||!v.nodeName(n.parentNode,"optgroup"))){t=v(n).val();if(s)return t;o.push(t)}}return o},set:function(e,t){var n=v.makeArray(t);return v(e).find("option").each(function(){this.selected=v.inArray(v(this).val(),n)>=0}),n.length||(e.selectedIndex=-1),n}}},attrFn:{},attr:function(e,n,r,i){var s,o,u,a=e.nodeType;if(!e||a===3||a===8||a===2)return;if(i&&v.isFunction(v.fn[n]))return v(e)[n](r);if(typeof e.getAttribute=="undefined")return v.prop(e,n,r);u=a!==1||!v.isXMLDoc(e),u&&(n=n.toLowerCase(),o=v.attrHooks[n]||(X.test(n)?F:j));if(r!==t){if(r===null){v.removeAttr(e,n);return}return o&&"set"in o&&u&&(s=o.set(e,r,n))!==t?s:(e.setAttribute(n,r+""),r)}return o&&"get"in o&&u&&(s=o.get(e,n))!==null?s:(s=e.getAttribute(n),s===null?t:s)},removeAttr:function(e,t){var n,r,i,s,o=0;if(t&&e.nodeType===1){r=t.split(y);for(;o<r.length;o++)i=r[o],i&&(n=v.propFix[i]||i,s=X.test(i),s||v.attr(e,i,""),e.removeAttribute(V?i:n),s&&n in e&&(e[n]=!1))}},attrHooks:{type:{set:function(e,t){if(U.test(e.nodeName)&&e.parentNode)v.error("type property can't be changed");else if(!v.support.radioValue&&t==="radio"&&v.nodeName(e,"input")){var n=e.value;return e.setAttribute("type",t),n&&(e.value=n),t}}},value:{get:function(e,t){return j&&v.nodeName(e,"button")?j.get(e,t):t in e?e.value:null},set:function(e,t,n){if(j&&v.nodeName(e,"button"))return j.set(e,t,n);e.value=t}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(e,n,r){var i,s,o,u=e.nodeType;if(!e||u===3||u===8||u===2)return;return o=u!==1||!v.isXMLDoc(e),o&&(n=v.propFix[n]||n,s=v.propHooks[n]),r!==t?s&&"set"in s&&(i=s.set(e,r,n))!==t?i:e[n]=r:s&&"get"in s&&(i=s.get(e,n))!==null?i:e[n]},propHooks:{tabIndex:{get:function(e){var n=e.getAttributeNode("tabindex");return n&&n.specified?parseInt(n.value,10):z.test(e.nodeName)||W.test(e.nodeName)&&e.href?0:t}}}}),F={get:function(e,n){var r,i=v.prop(e,n);return i===!0||typeof i!="boolean"&&(r=e.getAttributeNode(n))&&r.nodeValue!==!1?n.toLowerCase():t},set:function(e,t,n){var r;return t===!1?v.removeAttr(e,n):(r=v.propFix[n]||n,r in e&&(e[r]=!0),e.setAttribute(n,n.toLowerCase())),n}},V||(I={name:!0,id:!0,coords:!0},j=v.valHooks.button={get:function(e,n){var r;return r=e.getAttributeNode(n),r&&(I[n]?r.value!=="":r.specified)?r.value:t},set:function(e,t,n){var r=e.getAttributeNode(n);return r||(r=i.createAttribute(n),e.setAttributeNode(r)),r.value=t+""}},v.each(["width","height"],function(e,t){v.attrHooks[t]=v.extend(v.attrHooks[t],{set:function(e,n){if(n==="")return e.setAttribute(t,"auto"),n}})}),v.attrHooks.contenteditable={get:j.get,set:function(e,t,n){t===""&&(t="false"),j.set(e,t,n)}}),v.support.hrefNormalized||v.each(["href","src","width","height"],function(e,n){v.attrHooks[n]=v.extend(v.attrHooks[n],{get:function(e){var r=e.getAttribute(n,2);return r===null?t:r}})}),v.support.style||(v.attrHooks.style={get:function(e){return e.style.cssText.toLowerCase()||t},set:function(e,t){return e.style.cssText=t+""}}),v.support.optSelected||(v.propHooks.selected=v.extend(v.propHooks.selected,{get:function(e){var t=e.parentNode;return t&&(t.selectedIndex,t.parentNode&&t.parentNode.selectedIndex),null}})),v.support.enctype||(v.propFix.enctype="encoding"),v.support.checkOn||v.each(["radio","checkbox"],function(){v.valHooks[this]={get:function(e){return e.getAttribute("value")===null?"on":e.value}}}),v.each(["radio","checkbox"],function(){v.valHooks[this]=v.extend(v.valHooks[this],{set:function(e,t){if(v.isArray(t))return e.checked=v.inArray(v(e).val(),t)>=0}})});var $=/^(?:textarea|input|select)$/i,J=/^([^\.]*|)(?:\.(.+)|)$/,K=/(?:^|\s)hover(\.\S+|)\b/,Q=/^key/,G=/^(?:mouse|contextmenu)|click/,Y=/^(?:focusinfocus|focusoutblur)$/,Z=function(e){return v.event.special.hover?e:e.replace(K,"mouseenter$1 mouseleave$1")};v.event={add:function(e,n,r,i,s){var o,u,a,f,l,c,h,p,d,m,g;if(e.nodeType===3||e.nodeType===8||!n||!r||!(o=v._data(e)))return;r.handler&&(d=r,r=d.handler,s=d.selector),r.guid||(r.guid=v.guid++),a=o.events,a||(o.events=a={}),u=o.handle,u||(o.handle=u=function(e){return typeof v=="undefined"||!!e&&v.event.triggered===e.type?t:v.event.dispatch.apply(u.elem,arguments)},u.elem=e),n=v.trim(Z(n)).split(" ");for(f=0;f<n.length;f++){l=J.exec(n[f])||[],c=l[1],h=(l[2]||"").split(".").sort(),g=v.event.special[c]||{},c=(s?g.delegateType:g.bindType)||c,g=v.event.special[c]||{},p=v.extend({type:c,origType:l[1],data:i,handler:r,guid:r.guid,selector:s,needsContext:s&&v.expr.match.needsContext.test(s),namespace:h.join(".")},d),m=a[c];if(!m){m=a[c]=[],m.delegateCount=0;if(!g.setup||g.setup.call(e,i,h,u)===!1)e.addEventListener?e.addEventListener(c,u,!1):e.attachEvent&&e.attachEvent("on"+c,u)}g.add&&(g.add.call(e,p),p.handler.guid||(p.handler.guid=r.guid)),s?m.splice(m.delegateCount++,0,p):m.push(p),v.event.global[c]=!0}e=null},global:{},remove:function(e,t,n,r,i){var s,o,u,a,f,l,c,h,p,d,m,g=v.hasData(e)&&v._data(e);if(!g||!(h=g.events))return;t=v.trim(Z(t||"")).split(" ");for(s=0;s<t.length;s++){o=J.exec(t[s])||[],u=a=o[1],f=o[2];if(!u){for(u in h)v.event.remove(e,u+t[s],n,r,!0);continue}p=v.event.special[u]||{},u=(r?p.delegateType:p.bindType)||u,d=h[u]||[],l=d.length,f=f?new RegExp("(^|\\.)"+f.split(".").sort().join("\\.(?:.*\\.|)")+"(\\.|$)"):null;for(c=0;c<d.length;c++)m=d[c],(i||a===m.origType)&&(!n||n.guid===m.guid)&&(!f||f.test(m.namespace))&&(!r||r===m.selector||r==="**"&&m.selector)&&(d.splice(c--,1),m.selector&&d.delegateCount--,p.remove&&p.remove.call(e,m));d.length===0&&l!==d.length&&((!p.teardown||p.teardown.call(e,f,g.handle)===!1)&&v.removeEvent(e,u,g.handle),delete h[u])}v.isEmptyObject(h)&&(delete g.handle,v.removeData(e,"events",!0))},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(n,r,s,o){if(!s||s.nodeType!==3&&s.nodeType!==8){var u,a,f,l,c,h,p,d,m,g,y=n.type||n,b=[];if(Y.test(y+v.event.triggered))return;y.indexOf("!")>=0&&(y=y.slice(0,-1),a=!0),y.indexOf(".")>=0&&(b=y.split("."),y=b.shift(),b.sort());if((!s||v.event.customEvent[y])&&!v.event.global[y])return;n=typeof n=="object"?n[v.expando]?n:new v.Event(y,n):new v.Event(y),n.type=y,n.isTrigger=!0,n.exclusive=a,n.namespace=b.join("."),n.namespace_re=n.namespace?new RegExp("(^|\\.)"+b.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,h=y.indexOf(":")<0?"on"+y:"";if(!s){u=v.cache;for(f in u)u[f].events&&u[f].events[y]&&v.event.trigger(n,r,u[f].handle.elem,!0);return}n.result=t,n.target||(n.target=s),r=r!=null?v.makeArray(r):[],r.unshift(n),p=v.event.special[y]||{};if(p.trigger&&p.trigger.apply(s,r)===!1)return;m=[[s,p.bindType||y]];if(!o&&!p.noBubble&&!v.isWindow(s)){g=p.delegateType||y,l=Y.test(g+y)?s:s.parentNode;for(c=s;l;l=l.parentNode)m.push([l,g]),c=l;c===(s.ownerDocument||i)&&m.push([c.defaultView||c.parentWindow||e,g])}for(f=0;f<m.length&&!n.isPropagationStopped();f++)l=m[f][0],n.type=m[f][1],d=(v._data(l,"events")||{})[n.type]&&v._data(l,"handle"),d&&d.apply(l,r),d=h&&l[h],d&&v.acceptData(l)&&d.apply&&d.apply(l,r)===!1&&n.preventDefault();return n.type=y,!o&&!n.isDefaultPrevented()&&(!p._default||p._default.apply(s.ownerDocument,r)===!1)&&(y!=="click"||!v.nodeName(s,"a"))&&v.acceptData(s)&&h&&s[y]&&(y!=="focus"&&y!=="blur"||n.target.offsetWidth!==0)&&!v.isWindow(s)&&(c=s[h],c&&(s[h]=null),v.event.triggered=y,s[y](),v.event.triggered=t,c&&(s[h]=c)),n.result}return},dispatch:function(n){n=v.event.fix(n||e.event);var r,i,s,o,u,a,f,c,h,p,d=(v._data(this,"events")||{})[n.type]||[],m=d.delegateCount,g=l.call(arguments),y=!n.exclusive&&!n.namespace,b=v.event.special[n.type]||{},w=[];g[0]=n,n.delegateTarget=this;if(b.preDispatch&&b.preDispatch.call(this,n)===!1)return;if(m&&(!n.button||n.type!=="click"))for(s=n.target;s!=this;s=s.parentNode||this)if(s.disabled!==!0||n.type!=="click"){u={},f=[];for(r=0;r<m;r++)c=d[r],h=c.selector,u[h]===t&&(u[h]=c.needsContext?v(h,this).index(s)>=0:v.find(h,this,null,[s]).length),u[h]&&f.push(c);f.length&&w.push({elem:s,matches:f})}d.length>m&&w.push({elem:this,matches:d.slice(m)});for(r=0;r<w.length&&!n.isPropagationStopped();r++){a=w[r],n.currentTarget=a.elem;for(i=0;i<a.matches.length&&!n.isImmediatePropagationStopped();i++){c=a.matches[i];if(y||!n.namespace&&!c.namespace||n.namespace_re&&n.namespace_re.test(c.namespace))n.data=c.data,n.handleObj=c,o=((v.event.special[c.origType]||{}).handle||c.handler).apply(a.elem,g),o!==t&&(n.result=o,o===!1&&(n.preventDefault(),n.stopPropagation()))}}return b.postDispatch&&b.postDispatch.call(this,n),n.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(e,t){return e.which==null&&(e.which=t.charCode!=null?t.charCode:t.keyCode),e}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(e,n){var r,s,o,u=n.button,a=n.fromElement;return e.pageX==null&&n.clientX!=null&&(r=e.target.ownerDocument||i,s=r.documentElement,o=r.body,e.pageX=n.clientX+(s&&s.scrollLeft||o&&o.scrollLeft||0)-(s&&s.clientLeft||o&&o.clientLeft||0),e.pageY=n.clientY+(s&&s.scrollTop||o&&o.scrollTop||0)-(s&&s.clientTop||o&&o.clientTop||0)),!e.relatedTarget&&a&&(e.relatedTarget=a===e.target?n.toElement:a),!e.which&&u!==t&&(e.which=u&1?1:u&2?3:u&4?2:0),e}},fix:function(e){if(e[v.expando])return e;var t,n,r=e,s=v.event.fixHooks[e.type]||{},o=s.props?this.props.concat(s.props):this.props;e=v.Event(r);for(t=o.length;t;)n=o[--t],e[n]=r[n];return e.target||(e.target=r.srcElement||i),e.target.nodeType===3&&(e.target=e.target.parentNode),e.metaKey=!!e.metaKey,s.filter?s.filter(e,r):e},special:{load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(e,t,n){v.isWindow(this)&&(this.onbeforeunload=n)},teardown:function(e,t){this.onbeforeunload===t&&(this.onbeforeunload=null)}}},simulate:function(e,t,n,r){var i=v.extend(new v.Event,n,{type:e,isSimulated:!0,originalEvent:{}});r?v.event.trigger(i,null,t):v.event.dispatch.call(t,i),i.isDefaultPrevented()&&n.preventDefault()}},v.event.handle=v.event.dispatch,v.removeEvent=i.removeEventListener?function(e,t,n){e.removeEventListener&&e.removeEventListener(t,n,!1)}:function(e,t,n){var r="on"+t;e.detachEvent&&(typeof e[r]=="undefined"&&(e[r]=null),e.detachEvent(r,n))},v.Event=function(e,t){if(!(this instanceof v.Event))return new v.Event(e,t);e&&e.type?(this.originalEvent=e,this.type=e.type,this.isDefaultPrevented=e.defaultPrevented||e.returnValue===!1||e.getPreventDefault&&e.getPreventDefault()?tt:et):this.type=e,t&&v.extend(this,t),this.timeStamp=e&&e.timeStamp||v.now(),this[v.expando]=!0},v.Event.prototype={preventDefault:function(){this.isDefaultPrevented=tt;var e=this.originalEvent;if(!e)return;e.preventDefault?e.preventDefault():e.returnValue=!1},stopPropagation:function(){this.isPropagationStopped=tt;var e=this.originalEvent;if(!e)return;e.stopPropagation&&e.stopPropagation(),e.cancelBubble=!0},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=tt,this.stopPropagation()},isDefaultPrevented:et,isPropagationStopped:et,isImmediatePropagationStopped:et},v.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(e,t){v.event.special[e]={delegateType:t,bindType:t,handle:function(e){var n,r=this,i=e.relatedTarget,s=e.handleObj,o=s.selector;if(!i||i!==r&&!v.contains(r,i))e.type=s.origType,n=s.handler.apply(this,arguments),e.type=t;return n}}}),v.support.submitBubbles||(v.event.special.submit={setup:function(){if(v.nodeName(this,"form"))return!1;v.event.add(this,"click._submit keypress._submit",function(e){var n=e.target,r=v.nodeName(n,"input")||v.nodeName(n,"button")?n.form:t;r&&!v._data(r,"_submit_attached")&&(v.event.add(r,"submit._submit",function(e){e._submit_bubble=!0}),v._data(r,"_submit_attached",!0))})},postDispatch:function(e){e._submit_bubble&&(delete e._submit_bubble,this.parentNode&&!e.isTrigger&&v.event.simulate("submit",this.parentNode,e,!0))},teardown:function(){if(v.nodeName(this,"form"))return!1;v.event.remove(this,"._submit")}}),v.support.changeBubbles||(v.event.special.change={setup:function(){if($.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")v.event.add(this,"propertychange._change",function(e){e.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),v.event.add(this,"click._change",function(e){this._just_changed&&!e.isTrigger&&(this._just_changed=!1),v.event.simulate("change",this,e,!0)});return!1}v.event.add(this,"beforeactivate._change",function(e){var t=e.target;$.test(t.nodeName)&&!v._data(t,"_change_attached")&&(v.event.add(t,"change._change",function(e){this.parentNode&&!e.isSimulated&&!e.isTrigger&&v.event.simulate("change",this.parentNode,e,!0)}),v._data(t,"_change_attached",!0))})},handle:function(e){var t=e.target;if(this!==t||e.isSimulated||e.isTrigger||t.type!=="radio"&&t.type!=="checkbox")return e.handleObj.handler.apply(this,arguments)},teardown:function(){return v.event.remove(this,"._change"),!$.test(this.nodeName)}}),v.support.focusinBubbles||v.each({focus:"focusin",blur:"focusout"},function(e,t){var n=0,r=function(e){v.event.simulate(t,e.target,v.event.fix(e),!0)};v.event.special[t]={setup:function(){n++===0&&i.addEventListener(e,r,!0)},teardown:function(){--n===0&&i.removeEventListener(e,r,!0)}}}),v.fn.extend({on:function(e,n,r,i,s){var o,u;if(typeof e=="object"){typeof n!="string"&&(r=r||n,n=t);for(u in e)this.on(u,n,r,e[u],s);return this}r==null&&i==null?(i=n,r=n=t):i==null&&(typeof n=="string"?(i=r,r=t):(i=r,r=n,n=t));if(i===!1)i=et;else if(!i)return this;return s===1&&(o=i,i=function(e){return v().off(e),o.apply(this,arguments)},i.guid=o.guid||(o.guid=v.guid++)),this.each(function(){v.event.add(this,e,i,r,n)})},one:function(e,t,n,r){return this.on(e,t,n,r,1)},off:function(e,n,r){var i,s;if(e&&e.preventDefault&&e.handleObj)return i=e.handleObj,v(e.delegateTarget).off(i.namespace?i.origType+"."+i.namespace:i.origType,i.selector,i.handler),this;if(typeof e=="object"){for(s in e)this.off(s,n,e[s]);return this}if(n===!1||typeof n=="function")r=n,n=t;return r===!1&&(r=et),this.each(function(){v.event.remove(this,e,r,n)})},bind:function(e,t,n){return this.on(e,null,t,n)},unbind:function(e,t){return this.off(e,null,t)},live:function(e,t,n){return v(this.context).on(e,this.selector,t,n),this},die:function(e,t){return v(this.context).off(e,this.selector||"**",t),this},delegate:function(e,t,n,r){return this.on(t,e,n,r)},undelegate:function(e,t,n){return arguments.length===1?this.off(e,"**"):this.off(t,e||"**",n)},trigger:function(e,t){return this.each(function(){v.event.trigger(e,t,this)})},triggerHandler:function(e,t){if(this[0])return v.event.trigger(e,t,this[0],!0)},toggle:function(e){var t=arguments,n=e.guid||v.guid++,r=0,i=function(n){var i=(v._data(this,"lastToggle"+e.guid)||0)%r;return v._data(this,"lastToggle"+e.guid,i+1),n.preventDefault(),t[i].apply(this,arguments)||!1};i.guid=n;while(r<t.length)t[r++].guid=n;return this.click(i)},hover:function(e,t){return this.mouseenter(e).mouseleave(t||e)}}),v.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(e,t){v.fn[t]=function(e,n){return n==null&&(n=e,e=null),arguments.length>0?this.on(t,null,e,n):this.trigger(t)},Q.test(t)&&(v.event.fixHooks[t]=v.event.keyHooks),G.test(t)&&(v.event.fixHooks[t]=v.event.mouseHooks)}),function(e,t){function nt(e,t,n,r){n=n||[],t=t||g;var i,s,a,f,l=t.nodeType;if(!e||typeof e!="string")return n;if(l!==1&&l!==9)return[];a=o(t);if(!a&&!r)if(i=R.exec(e))if(f=i[1]){if(l===9){s=t.getElementById(f);if(!s||!s.parentNode)return n;if(s.id===f)return n.push(s),n}else if(t.ownerDocument&&(s=t.ownerDocument.getElementById(f))&&u(t,s)&&s.id===f)return n.push(s),n}else{if(i[2])return S.apply(n,x.call(t.getElementsByTagName(e),0)),n;if((f=i[3])&&Z&&t.getElementsByClassName)return S.apply(n,x.call(t.getElementsByClassName(f),0)),n}return vt(e.replace(j,"$1"),t,n,r,a)}function rt(e){return function(t){var n=t.nodeName.toLowerCase();return n==="input"&&t.type===e}}function it(e){return function(t){var n=t.nodeName.toLowerCase();return(n==="input"||n==="button")&&t.type===e}}function st(e){return N(function(t){return t=+t,N(function(n,r){var i,s=e([],n.length,t),o=s.length;while(o--)n[i=s[o]]&&(n[i]=!(r[i]=n[i]))})})}function ot(e,t,n){if(e===t)return n;var r=e.nextSibling;while(r){if(r===t)return-1;r=r.nextSibling}return 1}function ut(e,t){var n,r,s,o,u,a,f,l=L[d][e+" "];if(l)return t?0:l.slice(0);u=e,a=[],f=i.preFilter;while(u){if(!n||(r=F.exec(u)))r&&(u=u.slice(r[0].length)||u),a.push(s=[]);n=!1;if(r=I.exec(u))s.push(n=new m(r.shift())),u=u.slice(n.length),n.type=r[0].replace(j," ");for(o in i.filter)(r=J[o].exec(u))&&(!f[o]||(r=f[o](r)))&&(s.push(n=new m(r.shift())),u=u.slice(n.length),n.type=o,n.matches=r);if(!n)break}return t?u.length:u?nt.error(e):L(e,a).slice(0)}function at(e,t,r){var i=t.dir,s=r&&t.dir==="parentNode",o=w++;return t.first?function(t,n,r){while(t=t[i])if(s||t.nodeType===1)return e(t,n,r)}:function(t,r,u){if(!u){var a,f=b+" "+o+" ",l=f+n;while(t=t[i])if(s||t.nodeType===1){if((a=t[d])===l)return t.sizset;if(typeof a=="string"&&a.indexOf(f)===0){if(t.sizset)return t}else{t[d]=l;if(e(t,r,u))return t.sizset=!0,t;t.sizset=!1}}}else while(t=t[i])if(s||t.nodeType===1)if(e(t,r,u))return t}}function ft(e){return e.length>1?function(t,n,r){var i=e.length;while(i--)if(!e[i](t,n,r))return!1;return!0}:e[0]}function lt(e,t,n,r,i){var s,o=[],u=0,a=e.length,f=t!=null;for(;u<a;u++)if(s=e[u])if(!n||n(s,r,i))o.push(s),f&&t.push(u);return o}function ct(e,t,n,r,i,s){return r&&!r[d]&&(r=ct(r)),i&&!i[d]&&(i=ct(i,s)),N(function(s,o,u,a){var f,l,c,h=[],p=[],d=o.length,v=s||dt(t||"*",u.nodeType?[u]:u,[]),m=e&&(s||!t)?lt(v,h,e,u,a):v,g=n?i||(s?e:d||r)?[]:o:m;n&&n(m,g,u,a);if(r){f=lt(g,p),r(f,[],u,a),l=f.length;while(l--)if(c=f[l])g[p[l]]=!(m[p[l]]=c)}if(s){if(i||e){if(i){f=[],l=g.length;while(l--)(c=g[l])&&f.push(m[l]=c);i(null,g=[],f,a)}l=g.length;while(l--)(c=g[l])&&(f=i?T.call(s,c):h[l])>-1&&(s[f]=!(o[f]=c))}}else g=lt(g===o?g.splice(d,g.length):g),i?i(null,o,g,a):S.apply(o,g)})}function ht(e){var t,n,r,s=e.length,o=i.relative[e[0].type],u=o||i.relative[" "],a=o?1:0,f=at(function(e){return e===t},u,!0),l=at(function(e){return T.call(t,e)>-1},u,!0),h=[function(e,n,r){return!o&&(r||n!==c)||((t=n).nodeType?f(e,n,r):l(e,n,r))}];for(;a<s;a++)if(n=i.relative[e[a].type])h=[at(ft(h),n)];else{n=i.filter[e[a].type].apply(null,e[a].matches);if(n[d]){r=++a;for(;r<s;r++)if(i.relative[e[r].type])break;return ct(a>1&&ft(h),a>1&&e.slice(0,a-1).join("").replace(j,"$1"),n,a<r&&ht(e.slice(a,r)),r<s&&ht(e=e.slice(r)),r<s&&e.join(""))}h.push(n)}return ft(h)}function pt(e,t){var r=t.length>0,s=e.length>0,o=function(u,a,f,l,h){var p,d,v,m=[],y=0,w="0",x=u&&[],T=h!=null,N=c,C=u||s&&i.find.TAG("*",h&&a.parentNode||a),k=b+=N==null?1:Math.E;T&&(c=a!==g&&a,n=o.el);for(;(p=C[w])!=null;w++){if(s&&p){for(d=0;v=e[d];d++)if(v(p,a,f)){l.push(p);break}T&&(b=k,n=++o.el)}r&&((p=!v&&p)&&y--,u&&x.push(p))}y+=w;if(r&&w!==y){for(d=0;v=t[d];d++)v(x,m,a,f);if(u){if(y>0)while(w--)!x[w]&&!m[w]&&(m[w]=E.call(l));m=lt(m)}S.apply(l,m),T&&!u&&m.length>0&&y+t.length>1&&nt.uniqueSort(l)}return T&&(b=k,c=N),x};return o.el=0,r?N(o):o}function dt(e,t,n){var r=0,i=t.length;for(;r<i;r++)nt(e,t[r],n);return n}function vt(e,t,n,r,s){var o,u,f,l,c,h=ut(e),p=h.length;if(!r&&h.length===1){u=h[0]=h[0].slice(0);if(u.length>2&&(f=u[0]).type==="ID"&&t.nodeType===9&&!s&&i.relative[u[1].type]){t=i.find.ID(f.matches[0].replace($,""),t,s)[0];if(!t)return n;e=e.slice(u.shift().length)}for(o=J.POS.test(e)?-1:u.length-1;o>=0;o--){f=u[o];if(i.relative[l=f.type])break;if(c=i.find[l])if(r=c(f.matches[0].replace($,""),z.test(u[0].type)&&t.parentNode||t,s)){u.splice(o,1),e=r.length&&u.join("");if(!e)return S.apply(n,x.call(r,0)),n;break}}}return a(e,h)(r,t,s,n,z.test(e)),n}function mt(){}var n,r,i,s,o,u,a,f,l,c,h=!0,p="undefined",d=("sizcache"+Math.random()).replace(".",""),m=String,g=e.document,y=g.documentElement,b=0,w=0,E=[].pop,S=[].push,x=[].slice,T=[].indexOf||function(e){var t=0,n=this.length;for(;t<n;t++)if(this[t]===e)return t;return-1},N=function(e,t){return e[d]=t==null||t,e},C=function(){var e={},t=[];return N(function(n,r){return t.push(n)>i.cacheLength&&delete e[t.shift()],e[n+" "]=r},e)},k=C(),L=C(),A=C(),O="[\\x20\\t\\r\\n\\f]",M="(?:\\\\.|[-\\w]|[^\\x00-\\xa0])+",_=M.replace("w","w#"),D="([*^$|!~]?=)",P="\\["+O+"*("+M+")"+O+"*(?:"+D+O+"*(?:(['\"])((?:\\\\.|[^\\\\])*?)\\3|("+_+")|)|)"+O+"*\\]",H=":("+M+")(?:\\((?:(['\"])((?:\\\\.|[^\\\\])*?)\\2|([^()[\\]]*|(?:(?:"+P+")|[^:]|\\\\.)*|.*))\\)|)",B=":(even|odd|eq|gt|lt|nth|first|last)(?:\\("+O+"*((?:-\\d)?\\d*)"+O+"*\\)|)(?=[^-]|$)",j=new RegExp("^"+O+"+|((?:^|[^\\\\])(?:\\\\.)*)"+O+"+$","g"),F=new RegExp("^"+O+"*,"+O+"*"),I=new RegExp("^"+O+"*([\\x20\\t\\r\\n\\f>+~])"+O+"*"),q=new RegExp(H),R=/^(?:#([\w\-]+)|(\w+)|\.([\w\-]+))$/,U=/^:not/,z=/[\x20\t\r\n\f]*[+~]/,W=/:not\($/,X=/h\d/i,V=/input|select|textarea|button/i,$=/\\(?!\\)/g,J={ID:new RegExp("^#("+M+")"),CLASS:new RegExp("^\\.("+M+")"),NAME:new RegExp("^\\[name=['\"]?("+M+")['\"]?\\]"),TAG:new RegExp("^("+M.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+H),POS:new RegExp(B,"i"),CHILD:new RegExp("^:(only|nth|first|last)-child(?:\\("+O+"*(even|odd|(([+-]|)(\\d*)n|)"+O+"*(?:([+-]|)"+O+"*(\\d+)|))"+O+"*\\)|)","i"),needsContext:new RegExp("^"+O+"*[>+~]|"+B,"i")},K=function(e){var t=g.createElement("div");try{return e(t)}catch(n){return!1}finally{t=null}},Q=K(function(e){return e.appendChild(g.createComment("")),!e.getElementsByTagName("*").length}),G=K(function(e){return e.innerHTML="<a href='#'></a>",e.firstChild&&typeof e.firstChild.getAttribute!==p&&e.firstChild.getAttribute("href")==="#"}),Y=K(function(e){e.innerHTML="<select></select>";var t=typeof e.lastChild.getAttribute("multiple");return t!=="boolean"&&t!=="string"}),Z=K(function(e){return e.innerHTML="<div class='hidden e'></div><div class='hidden'></div>",!e.getElementsByClassName||!e.getElementsByClassName("e").length?!1:(e.lastChild.className="e",e.getElementsByClassName("e").length===2)}),et=K(function(e){e.id=d+0,e.innerHTML="<a name='"+d+"'></a><div name='"+d+"'></div>",y.insertBefore(e,y.firstChild);var t=g.getElementsByName&&g.getElementsByName(d).length===2+g.getElementsByName(d+0).length;return r=!g.getElementById(d),y.removeChild(e),t});try{x.call(y.childNodes,0)[0].nodeType}catch(tt){x=function(e){var t,n=[];for(;t=this[e];e++)n.push(t);return n}}nt.matches=function(e,t){return nt(e,null,null,t)},nt.matchesSelector=function(e,t){return nt(t,null,null,[e]).length>0},s=nt.getText=function(e){var t,n="",r=0,i=e.nodeType;if(i){if(i===1||i===9||i===11){if(typeof e.textContent=="string")return e.textContent;for(e=e.firstChild;e;e=e.nextSibling)n+=s(e)}else if(i===3||i===4)return e.nodeValue}else for(;t=e[r];r++)n+=s(t);return n},o=nt.isXML=function(e){var t=e&&(e.ownerDocument||e).documentElement;return t?t.nodeName!=="HTML":!1},u=nt.contains=y.contains?function(e,t){var n=e.nodeType===9?e.documentElement:e,r=t&&t.parentNode;return e===r||!!(r&&r.nodeType===1&&n.contains&&n.contains(r))}:y.compareDocumentPosition?function(e,t){return t&&!!(e.compareDocumentPosition(t)&16)}:function(e,t){while(t=t.parentNode)if(t===e)return!0;return!1},nt.attr=function(e,t){var n,r=o(e);return r||(t=t.toLowerCase()),(n=i.attrHandle[t])?n(e):r||Y?e.getAttribute(t):(n=e.getAttributeNode(t),n?typeof e[t]=="boolean"?e[t]?t:null:n.specified?n.value:null:null)},i=nt.selectors={cacheLength:50,createPseudo:N,match:J,attrHandle:G?{}:{href:function(e){return e.getAttribute("href",2)},type:function(e){return e.getAttribute("type")}},find:{ID:r?function(e,t,n){if(typeof t.getElementById!==p&&!n){var r=t.getElementById(e);return r&&r.parentNode?[r]:[]}}:function(e,n,r){if(typeof n.getElementById!==p&&!r){var i=n.getElementById(e);return i?i.id===e||typeof i.getAttributeNode!==p&&i.getAttributeNode("id").value===e?[i]:t:[]}},TAG:Q?function(e,t){if(typeof t.getElementsByTagName!==p)return t.getElementsByTagName(e)}:function(e,t){var n=t.getElementsByTagName(e);if(e==="*"){var r,i=[],s=0;for(;r=n[s];s++)r.nodeType===1&&i.push(r);return i}return n},NAME:et&&function(e,t){if(typeof t.getElementsByName!==p)return t.getElementsByName(name)},CLASS:Z&&function(e,t,n){if(typeof t.getElementsByClassName!==p&&!n)return t.getElementsByClassName(e)}},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(e){return e[1]=e[1].replace($,""),e[3]=(e[4]||e[5]||"").replace($,""),e[2]==="~="&&(e[3]=" "+e[3]+" "),e.slice(0,4)},CHILD:function(e){return e[1]=e[1].toLowerCase(),e[1]==="nth"?(e[2]||nt.error(e[0]),e[3]=+(e[3]?e[4]+(e[5]||1):2*(e[2]==="even"||e[2]==="odd")),e[4]=+(e[6]+e[7]||e[2]==="odd")):e[2]&&nt.error(e[0]),e},PSEUDO:function(e){var t,n;if(J.CHILD.test(e[0]))return null;if(e[3])e[2]=e[3];else if(t=e[4])q.test(t)&&(n=ut(t,!0))&&(n=t.indexOf(")",t.length-n)-t.length)&&(t=t.slice(0,n),e[0]=e[0].slice(0,n)),e[2]=t;return e.slice(0,3)}},filter:{ID:r?function(e){return e=e.replace($,""),function(t){return t.getAttribute("id")===e}}:function(e){return e=e.replace($,""),function(t){var n=typeof t.getAttributeNode!==p&&t.getAttributeNode("id");return n&&n.value===e}},TAG:function(e){return e==="*"?function(){return!0}:(e=e.replace($,"").toLowerCase(),function(t){return t.nodeName&&t.nodeName.toLowerCase()===e})},CLASS:function(e){var t=k[d][e+" "];return t||(t=new RegExp("(^|"+O+")"+e+"("+O+"|$)"))&&k(e,function(e){return t.test(e.className||typeof e.getAttribute!==p&&e.getAttribute("class")||"")})},ATTR:function(e,t,n){return function(r,i){var s=nt.attr(r,e);return s==null?t==="!=":t?(s+="",t==="="?s===n:t==="!="?s!==n:t==="^="?n&&s.indexOf(n)===0:t==="*="?n&&s.indexOf(n)>-1:t==="$="?n&&s.substr(s.length-n.length)===n:t==="~="?(" "+s+" ").indexOf(n)>-1:t==="|="?s===n||s.substr(0,n.length+1)===n+"-":!1):!0}},CHILD:function(e,t,n,r){return e==="nth"?function(e){var t,i,s=e.parentNode;if(n===1&&r===0)return!0;if(s){i=0;for(t=s.firstChild;t;t=t.nextSibling)if(t.nodeType===1){i++;if(e===t)break}}return i-=r,i===n||i%n===0&&i/n>=0}:function(t){var n=t;switch(e){case"only":case"first":while(n=n.previousSibling)if(n.nodeType===1)return!1;if(e==="first")return!0;n=t;case"last":while(n=n.nextSibling)if(n.nodeType===1)return!1;return!0}}},PSEUDO:function(e,t){var n,r=i.pseudos[e]||i.setFilters[e.toLowerCase()]||nt.error("unsupported pseudo: "+e);return r[d]?r(t):r.length>1?(n=[e,e,"",t],i.setFilters.hasOwnProperty(e.toLowerCase())?N(function(e,n){var i,s=r(e,t),o=s.length;while(o--)i=T.call(e,s[o]),e[i]=!(n[i]=s[o])}):function(e){return r(e,0,n)}):r}},pseudos:{not:N(function(e){var t=[],n=[],r=a(e.replace(j,"$1"));return r[d]?N(function(e,t,n,i){var s,o=r(e,null,i,[]),u=e.length;while(u--)if(s=o[u])e[u]=!(t[u]=s)}):function(e,i,s){return t[0]=e,r(t,null,s,n),!n.pop()}}),has:N(function(e){return function(t){return nt(e,t).length>0}}),contains:N(function(e){return function(t){return(t.textContent||t.innerText||s(t)).indexOf(e)>-1}}),enabled:function(e){return e.disabled===!1},disabled:function(e){return e.disabled===!0},checked:function(e){var t=e.nodeName.toLowerCase();return t==="input"&&!!e.checked||t==="option"&&!!e.selected},selected:function(e){return e.parentNode&&e.parentNode.selectedIndex,e.selected===!0},parent:function(e){return!i.pseudos.empty(e)},empty:function(e){var t;e=e.firstChild;while(e){if(e.nodeName>"@"||(t=e.nodeType)===3||t===4)return!1;e=e.nextSibling}return!0},header:function(e){return X.test(e.nodeName)},text:function(e){var t,n;return e.nodeName.toLowerCase()==="input"&&(t=e.type)==="text"&&((n=e.getAttribute("type"))==null||n.toLowerCase()===t)},radio:rt("radio"),checkbox:rt("checkbox"),file:rt("file"),password:rt("password"),image:rt("image"),submit:it("submit"),reset:it("reset"),button:function(e){var t=e.nodeName.toLowerCase();return t==="input"&&e.type==="button"||t==="button"},input:function(e){return V.test(e.nodeName)},focus:function(e){var t=e.ownerDocument;return e===t.activeElement&&(!t.hasFocus||t.hasFocus())&&!!(e.type||e.href||~e.tabIndex)},active:function(e){return e===e.ownerDocument.activeElement},first:st(function(){return[0]}),last:st(function(e,t){return[t-1]}),eq:st(function(e,t,n){return[n<0?n+t:n]}),even:st(function(e,t){for(var n=0;n<t;n+=2)e.push(n);return e}),odd:st(function(e,t){for(var n=1;n<t;n+=2)e.push(n);return e}),lt:st(function(e,t,n){for(var r=n<0?n+t:n;--r>=0;)e.push(r);return e}),gt:st(function(e,t,n){for(var r=n<0?n+t:n;++r<t;)e.push(r);return e})}},f=y.compareDocumentPosition?function(e,t){return e===t?(l=!0,0):(!e.compareDocumentPosition||!t.compareDocumentPosition?e.compareDocumentPosition:e.compareDocumentPosition(t)&4)?-1:1}:function(e,t){if(e===t)return l=!0,0;if(e.sourceIndex&&t.sourceIndex)return e.sourceIndex-t.sourceIndex;var n,r,i=[],s=[],o=e.parentNode,u=t.parentNode,a=o;if(o===u)return ot(e,t);if(!o)return-1;if(!u)return 1;while(a)i.unshift(a),a=a.parentNode;a=u;while(a)s.unshift(a),a=a.parentNode;n=i.length,r=s.length;for(var f=0;f<n&&f<r;f++)if(i[f]!==s[f])return ot(i[f],s[f]);return f===n?ot(e,s[f],-1):ot(i[f],t,1)},[0,0].sort(f),h=!l,nt.uniqueSort=function(e){var t,n=[],r=1,i=0;l=h,e.sort(f);if(l){for(;t=e[r];r++)t===e[r-1]&&(i=n.push(r));while(i--)e.splice(n[i],1)}return e},nt.error=function(e){throw new Error("Syntax error, unrecognized expression: "+e)},a=nt.compile=function(e,t){var n,r=[],i=[],s=A[d][e+" "];if(!s){t||(t=ut(e)),n=t.length;while(n--)s=ht(t[n]),s[d]?r.push(s):i.push(s);s=A(e,pt(i,r))}return s},g.querySelectorAll&&function(){var e,t=vt,n=/'|\\/g,r=/\=[\x20\t\r\n\f]*([^'"\]]*)[\x20\t\r\n\f]*\]/g,i=[":focus"],s=[":active"],u=y.matchesSelector||y.mozMatchesSelector||y.webkitMatchesSelector||y.oMatchesSelector||y.msMatchesSelector;K(function(e){e.innerHTML="<select><option selected=''></option></select>",e.querySelectorAll("[selected]").length||i.push("\\["+O+"*(?:checked|disabled|ismap|multiple|readonly|selected|value)"),e.querySelectorAll(":checked").length||i.push(":checked")}),K(function(e){e.innerHTML="<p test=''></p>",e.querySelectorAll("[test^='']").length&&i.push("[*^$]="+O+"*(?:\"\"|'')"),e.innerHTML="<input type='hidden'/>",e.querySelectorAll(":enabled").length||i.push(":enabled",":disabled")}),i=new RegExp(i.join("|")),vt=function(e,r,s,o,u){if(!o&&!u&&!i.test(e)){var a,f,l=!0,c=d,h=r,p=r.nodeType===9&&e;if(r.nodeType===1&&r.nodeName.toLowerCase()!=="object"){a=ut(e),(l=r.getAttribute("id"))?c=l.replace(n,"\\$&"):r.setAttribute("id",c),c="[id='"+c+"'] ",f=a.length;while(f--)a[f]=c+a[f].join("");h=z.test(e)&&r.parentNode||r,p=a.join(",")}if(p)try{return S.apply(s,x.call(h.querySelectorAll(p),0)),s}catch(v){}finally{l||r.removeAttribute("id")}}return t(e,r,s,o,u)},u&&(K(function(t){e=u.call(t,"div");try{u.call(t,"[test!='']:sizzle"),s.push("!=",H)}catch(n){}}),s=new RegExp(s.join("|")),nt.matchesSelector=function(t,n){n=n.replace(r,"='$1']");if(!o(t)&&!s.test(n)&&!i.test(n))try{var a=u.call(t,n);if(a||e||t.document&&t.document.nodeType!==11)return a}catch(f){}return nt(n,null,null,[t]).length>0})}(),i.pseudos.nth=i.pseudos.eq,i.filters=mt.prototype=i.pseudos,i.setFilters=new mt,nt.attr=v.attr,v.find=nt,v.expr=nt.selectors,v.expr[":"]=v.expr.pseudos,v.unique=nt.uniqueSort,v.text=nt.getText,v.isXMLDoc=nt.isXML,v.contains=nt.contains}(e);var nt=/Until$/,rt=/^(?:parents|prev(?:Until|All))/,it=/^.[^:#\[\.,]*$/,st=v.expr.match.needsContext,ot={children:!0,contents:!0,next:!0,prev:!0};v.fn.extend({find:function(e){var t,n,r,i,s,o,u=this;if(typeof e!="string")return v(e).filter(function(){for(t=0,n=u.length;t<n;t++)if(v.contains(u[t],this))return!0});o=this.pushStack("","find",e);for(t=0,n=this.length;t<n;t++){r=o.length,v.find(e,this[t],o);if(t>0)for(i=r;i<o.length;i++)for(s=0;s<r;s++)if(o[s]===o[i]){o.splice(i--,1);break}}return o},has:function(e){var t,n=v(e,this),r=n.length;return this.filter(function(){for(t=0;t<r;t++)if(v.contains(this,n[t]))return!0})},not:function(e){return this.pushStack(ft(this,e,!1),"not",e)},filter:function(e){return this.pushStack(ft(this,e,!0),"filter",e)},is:function(e){return!!e&&(typeof e=="string"?st.test(e)?v(e,this.context).index(this[0])>=0:v.filter(e,this).length>0:this.filter(e).length>0)},closest:function(e,t){var n,r=0,i=this.length,s=[],o=st.test(e)||typeof e!="string"?v(e,t||this.context):0;for(;r<i;r++){n=this[r];while(n&&n.ownerDocument&&n!==t&&n.nodeType!==11){if(o?o.index(n)>-1:v.find.matchesSelector(n,e)){s.push(n);break}n=n.parentNode}}return s=s.length>1?v.unique(s):s,this.pushStack(s,"closest",e)},index:function(e){return e?typeof e=="string"?v.inArray(this[0],v(e)):v.inArray(e.jquery?e[0]:e,this):this[0]&&this[0].parentNode?this.prevAll().length:-1},add:function(e,t){var n=typeof e=="string"?v(e,t):v.makeArray(e&&e.nodeType?[e]:e),r=v.merge(this.get(),n);return this.pushStack(ut(n[0])||ut(r[0])?r:v.unique(r))},addBack:function(e){return this.add(e==null?this.prevObject:this.prevObject.filter(e))}}),v.fn.andSelf=v.fn.addBack,v.each({parent:function(e){var t=e.parentNode;return t&&t.nodeType!==11?t:null},parents:function(e){return v.dir(e,"parentNode")},parentsUntil:function(e,t,n){return v.dir(e,"parentNode",n)},next:function(e){return at(e,"nextSibling")},prev:function(e){return at(e,"previousSibling")},nextAll:function(e){return v.dir(e,"nextSibling")},prevAll:function(e){return v.dir(e,"previousSibling")},nextUntil:function(e,t,n){return v.dir(e,"nextSibling",n)},prevUntil:function(e,t,n){return v.dir(e,"previousSibling",n)},siblings:function(e){return v.sibling((e.parentNode||{}).firstChild,e)},children:function(e){return v.sibling(e.firstChild)},contents:function(e){return v.nodeName(e,"iframe")?e.contentDocument||e.contentWindow.document:v.merge([],e.childNodes)}},function(e,t){v.fn[e]=function(n,r){var i=v.map(this,t,n);return nt.test(e)||(r=n),r&&typeof r=="string"&&(i=v.filter(r,i)),i=this.length>1&&!ot[e]?v.unique(i):i,this.length>1&&rt.test(e)&&(i=i.reverse()),this.pushStack(i,e,l.call(arguments).join(","))}}),v.extend({filter:function(e,t,n){return n&&(e=":not("+e+")"),t.length===1?v.find.matchesSelector(t[0],e)?[t[0]]:[]:v.find.matches(e,t)},dir:function(e,n,r){var i=[],s=e[n];while(s&&s.nodeType!==9&&(r===t||s.nodeType!==1||!v(s).is(r)))s.nodeType===1&&i.push(s),s=s[n];return i},sibling:function(e,t){var n=[];for(;e;e=e.nextSibling)e.nodeType===1&&e!==t&&n.push(e);return n}});var ct="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",ht=/ jQuery\d+="(?:null|\d+)"/g,pt=/^\s+/,dt=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,vt=/<([\w:]+)/,mt=/<tbody/i,gt=/<|&#?\w+;/,yt=/<(?:script|style|link)/i,bt=/<(?:script|object|embed|option|style)/i,wt=new RegExp("<(?:"+ct+")[\\s/>]","i"),Et=/^(?:checkbox|radio)$/,St=/checked\s*(?:[^=]|=\s*.checked.)/i,xt=/\/(java|ecma)script/i,Tt=/^\s*<!(?:\[CDATA\[|\-\-)|[\]\-]{2}>\s*$/g,Nt={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},Ct=lt(i),kt=Ct.appendChild(i.createElement("div"));Nt.optgroup=Nt.option,Nt.tbody=Nt.tfoot=Nt.colgroup=Nt.caption=Nt.thead,Nt.th=Nt.td,v.support.htmlSerialize||(Nt._default=[1,"X<div>","</div>"]),v.fn.extend({text:function(e){return v.access(this,function(e){return e===t?v.text(this):this.empty().append((this[0]&&this[0].ownerDocument||i).createTextNode(e))},null,e,arguments.length)},wrapAll:function(e){if(v.isFunction(e))return this.each(function(t){v(this).wrapAll(e.call(this,t))});if(this[0]){var t=v(e,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&t.insertBefore(this[0]),t.map(function(){var e=this;while(e.firstChild&&e.firstChild.nodeType===1)e=e.firstChild;return e}).append(this)}return this},wrapInner:function(e){return v.isFunction(e)?this.each(function(t){v(this).wrapInner(e.call(this,t))}):this.each(function(){var t=v(this),n=t.contents();n.length?n.wrapAll(e):t.append(e)})},wrap:function(e){var t=v.isFunction(e);return this.each(function(n){v(this).wrapAll(t?e.call(this,n):e)})},unwrap:function(){return this.parent().each(function(){v.nodeName(this,"body")||v(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(e){(this.nodeType===1||this.nodeType===11)&&this.appendChild(e)})},prepend:function(){return this.domManip(arguments,!0,function(e){(this.nodeType===1||this.nodeType===11)&&this.insertBefore(e,this.firstChild)})},before:function(){if(!ut(this[0]))return this.domManip(arguments,!1,function(e){this.parentNode.insertBefore(e,this)});if(arguments.length){var e=v.clean(arguments);return this.pushStack(v.merge(e,this),"before",this.selector)}},after:function(){if(!ut(this[0]))return this.domManip(arguments,!1,function(e){this.parentNode.insertBefore(e,this.nextSibling)});if(arguments.length){var e=v.clean(arguments);return this.pushStack(v.merge(this,e),"after",this.selector)}},remove:function(e,t){var n,r=0;for(;(n=this[r])!=null;r++)if(!e||v.filter(e,[n]).length)!t&&n.nodeType===1&&(v.cleanData(n.getElementsByTagName("*")),v.cleanData([n])),n.parentNode&&n.parentNode.removeChild(n);return this},empty:function(){var e,t=0;for(;(e=this[t])!=null;t++){e.nodeType===1&&v.cleanData(e.getElementsByTagName("*"));while(e.firstChild)e.removeChild(e.firstChild)}return this},clone:function(e,t){return e=e==null?!1:e,t=t==null?e:t,this.map(function(){return v.clone(this,e,t)})},html:function(e){return v.access(this,function(e){var n=this[0]||{},r=0,i=this.length;if(e===t)return n.nodeType===1?n.innerHTML.replace(ht,""):t;if(typeof e=="string"&&!yt.test(e)&&(v.support.htmlSerialize||!wt.test(e))&&(v.support.leadingWhitespace||!pt.test(e))&&!Nt[(vt.exec(e)||["",""])[1].toLowerCase()]){e=e.replace(dt,"<$1></$2>");try{for(;r<i;r++)n=this[r]||{},n.nodeType===1&&(v.cleanData(n.getElementsByTagName("*")),n.innerHTML=e);n=0}catch(s){}}n&&this.empty().append(e)},null,e,arguments.length)},replaceWith:function(e){return ut(this[0])?this.length?this.pushStack(v(v.isFunction(e)?e():e),"replaceWith",e):this:v.isFunction(e)?this.each(function(t){var n=v(this),r=n.html();n.replaceWith(e.call(this,t,r))}):(typeof e!="string"&&(e=v(e).detach()),this.each(function(){var t=this.nextSibling,n=this.parentNode;v(this).remove(),t?v(t).before(e):v(n).append(e)}))},detach:function(e){return this.remove(e,!0)},domManip:function(e,n,r){e=[].concat.apply([],e);var i,s,o,u,a=0,f=e[0],l=[],c=this.length;if(!v.support.checkClone&&c>1&&typeof f=="string"&&St.test(f))return this.each(function(){v(this).domManip(e,n,r)});if(v.isFunction(f))return this.each(function(i){var s=v(this);e[0]=f.call(this,i,n?s.html():t),s.domManip(e,n,r)});if(this[0]){i=v.buildFragment(e,this,l),o=i.fragment,s=o.firstChild,o.childNodes.length===1&&(o=s);if(s){n=n&&v.nodeName(s,"tr");for(u=i.cacheable||c-1;a<c;a++)r.call(n&&v.nodeName(this[a],"table")?Lt(this[a],"tbody"):this[a],a===u?o:v.clone(o,!0,!0))}o=s=null,l.length&&v.each(l,function(e,t){t.src?v.ajax?v.ajax({url:t.src,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0}):v.error("no ajax"):v.globalEval((t.text||t.textContent||t.innerHTML||"").replace(Tt,"")),t.parentNode&&t.parentNode.removeChild(t)})}return this}}),v.buildFragment=function(e,n,r){var s,o,u,a=e[0];return n=n||i,n=!n.nodeType&&n[0]||n,n=n.ownerDocument||n,e.length===1&&typeof a=="string"&&a.length<512&&n===i&&a.charAt(0)==="<"&&!bt.test(a)&&(v.support.checkClone||!St.test(a))&&(v.support.html5Clone||!wt.test(a))&&(o=!0,s=v.fragments[a],u=s!==t),s||(s=n.createDocumentFragment(),v.clean(e,n,s,r),o&&(v.fragments[a]=u&&s)),{fragment:s,cacheable:o}},v.fragments={},v.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(e,t){v.fn[e]=function(n){var r,i=0,s=[],o=v(n),u=o.length,a=this.length===1&&this[0].parentNode;if((a==null||a&&a.nodeType===11&&a.childNodes.length===1)&&u===1)return o[t](this[0]),this;for(;i<u;i++)r=(i>0?this.clone(!0):this).get(),v(o[i])[t](r),s=s.concat(r);return this.pushStack(s,e,o.selector)}}),v.extend({clone:function(e,t,n){var r,i,s,o;v.support.html5Clone||v.isXMLDoc(e)||!wt.test("<"+e.nodeName+">")?o=e.cloneNode(!0):(kt.innerHTML=e.outerHTML,kt.removeChild(o=kt.firstChild));if((!v.support.noCloneEvent||!v.support.noCloneChecked)&&(e.nodeType===1||e.nodeType===11)&&!v.isXMLDoc(e)){Ot(e,o),r=Mt(e),i=Mt(o);for(s=0;r[s];++s)i[s]&&Ot(r[s],i[s])}if(t){At(e,o);if(n){r=Mt(e),i=Mt(o);for(s=0;r[s];++s)At(r[s],i[s])}}return r=i=null,o},clean:function(e,t,n,r){var s,o,u,a,f,l,c,h,p,d,m,g,y=t===i&&Ct,b=[];if(!t||typeof t.createDocumentFragment=="undefined")t=i;for(s=0;(u=e[s])!=null;s++){typeof u=="number"&&(u+="");if(!u)continue;if(typeof u=="string")if(!gt.test(u))u=t.createTextNode(u);else{y=y||lt(t),c=t.createElement("div"),y.appendChild(c),u=u.replace(dt,"<$1></$2>"),a=(vt.exec(u)||["",""])[1].toLowerCase(),f=Nt[a]||Nt._default,l=f[0],c.innerHTML=f[1]+u+f[2];while(l--)c=c.lastChild;if(!v.support.tbody){h=mt.test(u),p=a==="table"&&!h?c.firstChild&&c.firstChild.childNodes:f[1]==="<table>"&&!h?c.childNodes:[];for(o=p.length-1;o>=0;--o)v.nodeName(p[o],"tbody")&&!p[o].childNodes.length&&p[o].parentNode.removeChild(p[o])}!v.support.leadingWhitespace&&pt.test(u)&&c.insertBefore(t.createTextNode(pt.exec(u)[0]),c.firstChild),u=c.childNodes,c.parentNode.removeChild(c)}u.nodeType?b.push(u):v.merge(b,u)}c&&(u=c=y=null);if(!v.support.appendChecked)for(s=0;(u=b[s])!=null;s++)v.nodeName(u,"input")?_t(u):typeof u.getElementsByTagName!="undefined"&&v.grep(u.getElementsByTagName("input"),_t);if(n){m=function(e){if(!e.type||xt.test(e.type))return r?r.push(e.parentNode?e.parentNode.removeChild(e):e):n.appendChild(e)};for(s=0;(u=b[s])!=null;s++)if(!v.nodeName(u,"script")||!m(u))n.appendChild(u),typeof u.getElementsByTagName!="undefined"&&(g=v.grep(v.merge([],u.getElementsByTagName("script")),m),b.splice.apply(b,[s+1,0].concat(g)),s+=g.length)}return b},cleanData:function(e,t){var n,r,i,s,o=0,u=v.expando,a=v.cache,f=v.support.deleteExpando,l=v.event.special;for(;(i=e[o])!=null;o++)if(t||v.acceptData(i)){r=i[u],n=r&&a[r];if(n){if(n.events)for(s in n.events)l[s]?v.event.remove(i,s):v.removeEvent(i,s,n.handle);a[r]&&(delete a[r],f?delete i[u]:i.removeAttribute?i.removeAttribute(u):i[u]=null,v.deletedIds.push(r))}}}}),function(){var e,t;v.uaMatch=function(e){e=e.toLowerCase();var t=/(chrome)[ \/]([\w.]+)/.exec(e)||/(webkit)[ \/]([\w.]+)/.exec(e)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(e)||/(msie) ([\w.]+)/.exec(e)||e.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(e)||[];return{browser:t[1]||"",version:t[2]||"0"}},e=v.uaMatch(o.userAgent),t={},e.browser&&(t[e.browser]=!0,t.version=e.version),t.chrome?t.webkit=!0:t.webkit&&(t.safari=!0),v.browser=t,v.sub=function(){function e(t,n){return new e.fn.init(t,n)}v.extend(!0,e,this),e.superclass=this,e.fn=e.prototype=this(),e.fn.constructor=e,e.sub=this.sub,e.fn.init=function(r,i){return i&&i instanceof v&&!(i instanceof e)&&(i=e(i)),v.fn.init.call(this,r,i,t)},e.fn.init.prototype=e.fn;var t=e(i);return e}}();var Dt,Pt,Ht,Bt=/alpha\([^)]*\)/i,jt=/opacity=([^)]*)/,Ft=/^(top|right|bottom|left)$/,It=/^(none|table(?!-c[ea]).+)/,qt=/^margin/,Rt=new RegExp("^("+m+")(.*)$","i"),Ut=new RegExp("^("+m+")(?!px)[a-z%]+$","i"),zt=new RegExp("^([-+])=("+m+")","i"),Wt={BODY:"block"},Xt={position:"absolute",visibility:"hidden",display:"block"},Vt={letterSpacing:0,fontWeight:400},$t=["Top","Right","Bottom","Left"],Jt=["Webkit","O","Moz","ms"],Kt=v.fn.toggle;v.fn.extend({css:function(e,n){return v.access(this,function(e,n,r){return r!==t?v.style(e,n,r):v.css(e,n)},e,n,arguments.length>1)},show:function(){return Yt(this,!0)},hide:function(){return Yt(this)},toggle:function(e,t){var n=typeof e=="boolean";return v.isFunction(e)&&v.isFunction(t)?Kt.apply(this,arguments):this.each(function(){(n?e:Gt(this))?v(this).show():v(this).hide()})}}),v.extend({cssHooks:{opacity:{get:function(e,t){if(t){var n=Dt(e,"opacity");return n===""?"1":n}}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":v.support.cssFloat?"cssFloat":"styleFloat"},style:function(e,n,r,i){if(!e||e.nodeType===3||e.nodeType===8||!e.style)return;var s,o,u,a=v.camelCase(n),f=e.style;n=v.cssProps[a]||(v.cssProps[a]=Qt(f,a)),u=v.cssHooks[n]||v.cssHooks[a];if(r===t)return u&&"get"in u&&(s=u.get(e,!1,i))!==t?s:f[n];o=typeof r,o==="string"&&(s=zt.exec(r))&&(r=(s[1]+1)*s[2]+parseFloat(v.css(e,n)),o="number");if(r==null||o==="number"&&isNaN(r))return;o==="number"&&!v.cssNumber[a]&&(r+="px");if(!u||!("set"in u)||(r=u.set(e,r,i))!==t)try{f[n]=r}catch(l){}},css:function(e,n,r,i){var s,o,u,a=v.camelCase(n);return n=v.cssProps[a]||(v.cssProps[a]=Qt(e.style,a)),u=v.cssHooks[n]||v.cssHooks[a],u&&"get"in u&&(s=u.get(e,!0,i)),s===t&&(s=Dt(e,n)),s==="normal"&&n in Vt&&(s=Vt[n]),r||i!==t?(o=parseFloat(s),r||v.isNumeric(o)?o||0:s):s},swap:function(e,t,n){var r,i,s={};for(i in t)s[i]=e.style[i],e.style[i]=t[i];r=n.call(e);for(i in t)e.style[i]=s[i];return r}}),e.getComputedStyle?Dt=function(t,n){var r,i,s,o,u=e.getComputedStyle(t,null),a=t.style;return u&&(r=u.getPropertyValue(n)||u[n],r===""&&!v.contains(t.ownerDocument,t)&&(r=v.style(t,n)),Ut.test(r)&&qt.test(n)&&(i=a.width,s=a.minWidth,o=a.maxWidth,a.minWidth=a.maxWidth=a.width=r,r=u.width,a.width=i,a.minWidth=s,a.maxWidth=o)),r}:i.documentElement.currentStyle&&(Dt=function(e,t){var n,r,i=e.currentStyle&&e.currentStyle[t],s=e.style;return i==null&&s&&s[t]&&(i=s[t]),Ut.test(i)&&!Ft.test(t)&&(n=s.left,r=e.runtimeStyle&&e.runtimeStyle.left,r&&(e.runtimeStyle.left=e.currentStyle.left),s.left=t==="fontSize"?"1em":i,i=s.pixelLeft+"px",s.left=n,r&&(e.runtimeStyle.left=r)),i===""?"auto":i}),v.each(["height","width"],function(e,t){v.cssHooks[t]={get:function(e,n,r){if(n)return e.offsetWidth===0&&It.test(Dt(e,"display"))?v.swap(e,Xt,function(){return tn(e,t,r)}):tn(e,t,r)},set:function(e,n,r){return Zt(e,n,r?en(e,t,r,v.support.boxSizing&&v.css(e,"boxSizing")==="border-box"):0)}}}),v.support.opacity||(v.cssHooks.opacity={get:function(e,t){return jt.test((t&&e.currentStyle?e.currentStyle.filter:e.style.filter)||"")?.01*parseFloat(RegExp.$1)+"":t?"1":""},set:function(e,t){var n=e.style,r=e.currentStyle,i=v.isNumeric(t)?"alpha(opacity="+t*100+")":"",s=r&&r.filter||n.filter||"";n.zoom=1;if(t>=1&&v.trim(s.replace(Bt,""))===""&&n.removeAttribute){n.removeAttribute("filter");if(r&&!r.filter)return}n.filter=Bt.test(s)?s.replace(Bt,i):s+" "+i}}),v(function(){v.support.reliableMarginRight||(v.cssHooks.marginRight={get:function(e,t){return v.swap(e,{display:"inline-block"},function(){if(t)return Dt(e,"marginRight")})}}),!v.support.pixelPosition&&v.fn.position&&v.each(["top","left"],function(e,t){v.cssHooks[t]={get:function(e,n){if(n){var r=Dt(e,t);return Ut.test(r)?v(e).position()[t]+"px":r}}}})}),v.expr&&v.expr.filters&&(v.expr.filters.hidden=function(e){return e.offsetWidth===0&&e.offsetHeight===0||!v.support.reliableHiddenOffsets&&(e.style&&e.style.display||Dt(e,"display"))==="none"},v.expr.filters.visible=function(e){return!v.expr.filters.hidden(e)}),v.each({margin:"",padding:"",border:"Width"},function(e,t){v.cssHooks[e+t]={expand:function(n){var r,i=typeof n=="string"?n.split(" "):[n],s={};for(r=0;r<4;r++)s[e+$t[r]+t]=i[r]||i[r-2]||i[0];return s}},qt.test(e)||(v.cssHooks[e+t].set=Zt)});var rn=/%20/g,sn=/\[\]$/,on=/\r?\n/g,un=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,an=/^(?:select|textarea)/i;v.fn.extend({serialize:function(){return v.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?v.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||an.test(this.nodeName)||un.test(this.type))}).map(function(e,t){var n=v(this).val();return n==null?null:v.isArray(n)?v.map(n,function(e,n){return{name:t.name,value:e.replace(on,"\r\n")}}):{name:t.name,value:n.replace(on,"\r\n")}}).get()}}),v.param=function(e,n){var r,i=[],s=function(e,t){t=v.isFunction(t)?t():t==null?"":t,i[i.length]=encodeURIComponent(e)+"="+encodeURIComponent(t)};n===t&&(n=v.ajaxSettings&&v.ajaxSettings.traditional);if(v.isArray(e)||e.jquery&&!v.isPlainObject(e))v.each(e,function(){s(this.name,this.value)});else for(r in e)fn(r,e[r],n,s);return i.join("&").replace(rn,"+")};var ln,cn,hn=/#.*$/,pn=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,dn=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,vn=/^(?:GET|HEAD)$/,mn=/^\/\//,gn=/\?/,yn=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bn=/([?&])_=[^&]*/,wn=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+)|)|)/,En=v.fn.load,Sn={},xn={},Tn=["*/"]+["*"];try{cn=s.href}catch(Nn){cn=i.createElement("a"),cn.href="",cn=cn.href}ln=wn.exec(cn.toLowerCase())||[],v.fn.load=function(e,n,r){if(typeof e!="string"&&En)return En.apply(this,arguments);if(!this.length)return this;var i,s,o,u=this,a=e.indexOf(" ");return a>=0&&(i=e.slice(a,e.length),e=e.slice(0,a)),v.isFunction(n)?(r=n,n=t):n&&typeof n=="object"&&(s="POST"),v.ajax({url:e,type:s,dataType:"html",data:n,complete:function(e,t){r&&u.each(r,o||[e.responseText,t,e])}}).done(function(e){o=arguments,u.html(i?v("<div>").append(e.replace(yn,"")).find(i):e)}),this},v.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(e,t){v.fn[t]=function(e){return this.on(t,e)}}),v.each(["get","post"],function(e,n){v[n]=function(e,r,i,s){return v.isFunction(r)&&(s=s||i,i=r,r=t),v.ajax({type:n,url:e,data:r,success:i,dataType:s})}}),v.extend({getScript:function(e,n){return v.get(e,t,n,"script")},getJSON:function(e,t,n){return v.get(e,t,n,"json")},ajaxSetup:function(e,t){return t?Ln(e,v.ajaxSettings):(t=e,e=v.ajaxSettings),Ln(e,t),e},ajaxSettings:{url:cn,isLocal:dn.test(ln[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":Tn},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":e.String,"text html":!0,"text json":v.parseJSON,"text xml":v.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:Cn(Sn),ajaxTransport:Cn(xn),ajax:function(e,n){function T(e,n,s,a){var l,y,b,w,S,T=n;if(E===2)return;E=2,u&&clearTimeout(u),o=t,i=a||"",x.readyState=e>0?4:0,s&&(w=An(c,x,s));if(e>=200&&e<300||e===304)c.ifModified&&(S=x.getResponseHeader("Last-Modified"),S&&(v.lastModified[r]=S),S=x.getResponseHeader("Etag"),S&&(v.etag[r]=S)),e===304?(T="notmodified",l=!0):(l=On(c,w),T=l.state,y=l.data,b=l.error,l=!b);else{b=T;if(!T||e)T="error",e<0&&(e=0)}x.status=e,x.statusText=(n||T)+"",l?d.resolveWith(h,[y,T,x]):d.rejectWith(h,[x,T,b]),x.statusCode(g),g=t,f&&p.trigger("ajax"+(l?"Success":"Error"),[x,c,l?y:b]),m.fireWith(h,[x,T]),f&&(p.trigger("ajaxComplete",[x,c]),--v.active||v.event.trigger("ajaxStop"))}typeof e=="object"&&(n=e,e=t),n=n||{};var r,i,s,o,u,a,f,l,c=v.ajaxSetup({},n),h=c.context||c,p=h!==c&&(h.nodeType||h instanceof v)?v(h):v.event,d=v.Deferred(),m=v.Callbacks("once memory"),g=c.statusCode||{},b={},w={},E=0,S="canceled",x={readyState:0,setRequestHeader:function(e,t){if(!E){var n=e.toLowerCase();e=w[n]=w[n]||e,b[e]=t}return this},getAllResponseHeaders:function(){return E===2?i:null},getResponseHeader:function(e){var n;if(E===2){if(!s){s={};while(n=pn.exec(i))s[n[1].toLowerCase()]=n[2]}n=s[e.toLowerCase()]}return n===t?null:n},overrideMimeType:function(e){return E||(c.mimeType=e),this},abort:function(e){return e=e||S,o&&o.abort(e),T(0,e),this}};d.promise(x),x.success=x.done,x.error=x.fail,x.complete=m.add,x.statusCode=function(e){if(e){var t;if(E<2)for(t in e)g[t]=[g[t],e[t]];else t=e[x.status],x.always(t)}return this},c.url=((e||c.url)+"").replace(hn,"").replace(mn,ln[1]+"//"),c.dataTypes=v.trim(c.dataType||"*").toLowerCase().split(y),c.crossDomain==null&&(a=wn.exec(c.url.toLowerCase()),c.crossDomain=!(!a||a[1]===ln[1]&&a[2]===ln[2]&&(a[3]||(a[1]==="http:"?80:443))==(ln[3]||(ln[1]==="http:"?80:443)))),c.data&&c.processData&&typeof c.data!="string"&&(c.data=v.param(c.data,c.traditional)),kn(Sn,c,n,x);if(E===2)return x;f=c.global,c.type=c.type.toUpperCase(),c.hasContent=!vn.test(c.type),f&&v.active++===0&&v.event.trigger("ajaxStart");if(!c.hasContent){c.data&&(c.url+=(gn.test(c.url)?"&":"?")+c.data,delete c.data),r=c.url;if(c.cache===!1){var N=v.now(),C=c.url.replace(bn,"$1_="+N);c.url=C+(C===c.url?(gn.test(c.url)?"&":"?")+"_="+N:"")}}(c.data&&c.hasContent&&c.contentType!==!1||n.contentType)&&x.setRequestHeader("Content-Type",c.contentType),c.ifModified&&(r=r||c.url,v.lastModified[r]&&x.setRequestHeader("If-Modified-Since",v.lastModified[r]),v.etag[r]&&x.setRequestHeader("If-None-Match",v.etag[r])),x.setRequestHeader("Accept",c.dataTypes[0]&&c.accepts[c.dataTypes[0]]?c.accepts[c.dataTypes[0]]+(c.dataTypes[0]!=="*"?", "+Tn+"; q=0.01":""):c.accepts["*"]);for(l in c.headers)x.setRequestHeader(l,c.headers[l]);if(!c.beforeSend||c.beforeSend.call(h,x,c)!==!1&&E!==2){S="abort";for(l in{success:1,error:1,complete:1})x[l](c[l]);o=kn(xn,c,n,x);if(!o)T(-1,"No Transport");else{x.readyState=1,f&&p.trigger("ajaxSend",[x,c]),c.async&&c.timeout>0&&(u=setTimeout(function(){x.abort("timeout")},c.timeout));try{E=1,o.send(b,T)}catch(k){if(!(E<2))throw k;T(-1,k)}}return x}return x.abort()},active:0,lastModified:{},etag:{}});var Mn=[],_n=/\?/,Dn=/(=)\?(?=&|$)|\?\?/,Pn=v.now();v.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var e=Mn.pop()||v.expando+"_"+Pn++;return this[e]=!0,e}}),v.ajaxPrefilter("json jsonp",function(n,r,i){var s,o,u,a=n.data,f=n.url,l=n.jsonp!==!1,c=l&&Dn.test(f),h=l&&!c&&typeof a=="string"&&!(n.contentType||"").indexOf("application/x-www-form-urlencoded")&&Dn.test(a);if(n.dataTypes[0]==="jsonp"||c||h)return s=n.jsonpCallback=v.isFunction(n.jsonpCallback)?n.jsonpCallback():n.jsonpCallback,o=e[s],c?n.url=f.replace(Dn,"$1"+s):h?n.data=a.replace(Dn,"$1"+s):l&&(n.url+=(_n.test(f)?"&":"?")+n.jsonp+"="+s),n.converters["script json"]=function(){return u||v.error(s+" was not called"),u[0]},n.dataTypes[0]="json",e[s]=function(){u=arguments},i.always(function(){e[s]=o,n[s]&&(n.jsonpCallback=r.jsonpCallback,Mn.push(s)),u&&v.isFunction(o)&&o(u[0]),u=o=t}),"script"}),v.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(e){return v.globalEval(e),e}}}),v.ajaxPrefilter("script",function(e){e.cache===t&&(e.cache=!1),e.crossDomain&&(e.type="GET",e.global=!1)}),v.ajaxTransport("script",function(e){if(e.crossDomain){var n,r=i.head||i.getElementsByTagName("head")[0]||i.documentElement;return{send:function(s,o){n=i.createElement("script"),n.async="async",e.scriptCharset&&(n.charset=e.scriptCharset),n.src=e.url,n.onload=n.onreadystatechange=function(e,i){if(i||!n.readyState||/loaded|complete/.test(n.readyState))n.onload=n.onreadystatechange=null,r&&n.parentNode&&r.removeChild(n),n=t,i||o(200,"success")},r.insertBefore(n,r.firstChild)},abort:function(){n&&n.onload(0,1)}}}});var Hn,Bn=e.ActiveXObject?function(){for(var e in Hn)Hn[e](0,1)}:!1,jn=0;v.ajaxSettings.xhr=e.ActiveXObject?function(){return!this.isLocal&&Fn()||In()}:Fn,function(e){v.extend(v.support,{ajax:!!e,cors:!!e&&"withCredentials"in e})}(v.ajaxSettings.xhr()),v.support.ajax&&v.ajaxTransport(function(n){if(!n.crossDomain||v.support.cors){var r;return{send:function(i,s){var o,u,a=n.xhr();n.username?a.open(n.type,n.url,n.async,n.username,n.password):a.open(n.type,n.url,n.async);if(n.xhrFields)for(u in n.xhrFields)a[u]=n.xhrFields[u];n.mimeType&&a.overrideMimeType&&a.overrideMimeType(n.mimeType),!n.crossDomain&&!i["X-Requested-With"]&&(i["X-Requested-With"]="XMLHttpRequest");try{for(u in i)a.setRequestHeader(u,i[u])}catch(f){}a.send(n.hasContent&&n.data||null),r=function(e,i){var u,f,l,c,h;try{if(r&&(i||a.readyState===4)){r=t,o&&(a.onreadystatechange=v.noop,Bn&&delete Hn[o]);if(i)a.readyState!==4&&a.abort();else{u=a.status,l=a.getAllResponseHeaders(),c={},h=a.responseXML,h&&h.documentElement&&(c.xml=h);try{c.text=a.responseText}catch(p){}try{f=a.statusText}catch(p){f=""}!u&&n.isLocal&&!n.crossDomain?u=c.text?200:404:u===1223&&(u=204)}}}catch(d){i||s(-1,d)}c&&s(u,f,c,l)},n.async?a.readyState===4?setTimeout(r,0):(o=++jn,Bn&&(Hn||(Hn={},v(e).unload(Bn)),Hn[o]=r),a.onreadystatechange=r):r()},abort:function(){r&&r(0,1)}}}});var qn,Rn,Un=/^(?:toggle|show|hide)$/,zn=new RegExp("^(?:([-+])=|)("+m+")([a-z%]*)$","i"),Wn=/queueHooks$/,Xn=[Gn],Vn={"*":[function(e,t){var n,r,i=this.createTween(e,t),s=zn.exec(t),o=i.cur(),u=+o||0,a=1,f=20;if(s){n=+s[2],r=s[3]||(v.cssNumber[e]?"":"px");if(r!=="px"&&u){u=v.css(i.elem,e,!0)||n||1;do a=a||".5",u/=a,v.style(i.elem,e,u+r);while(a!==(a=i.cur()/o)&&a!==1&&--f)}i.unit=r,i.start=u,i.end=s[1]?u+(s[1]+1)*n:n}return i}]};v.Animation=v.extend(Kn,{tweener:function(e,t){v.isFunction(e)?(t=e,e=["*"]):e=e.split(" ");var n,r=0,i=e.length;for(;r<i;r++)n=e[r],Vn[n]=Vn[n]||[],Vn[n].unshift(t)},prefilter:function(e,t){t?Xn.unshift(e):Xn.push(e)}}),v.Tween=Yn,Yn.prototype={constructor:Yn,init:function(e,t,n,r,i,s){this.elem=e,this.prop=n,this.easing=i||"swing",this.options=t,this.start=this.now=this.cur(),this.end=r,this.unit=s||(v.cssNumber[n]?"":"px")},cur:function(){var e=Yn.propHooks[this.prop];return e&&e.get?e.get(this):Yn.propHooks._default.get(this)},run:function(e){var t,n=Yn.propHooks[this.prop];return this.options.duration?this.pos=t=v.easing[this.easing](e,this.options.duration*e,0,1,this.options.duration):this.pos=t=e,this.now=(this.end-this.start)*t+this.start,this.options.step&&this.options.step.call(this.elem,this.now,this),n&&n.set?n.set(this):Yn.propHooks._default.set(this),this}},Yn.prototype.init.prototype=Yn.prototype,Yn.propHooks={_default:{get:function(e){var t;return e.elem[e.prop]==null||!!e.elem.style&&e.elem.style[e.prop]!=null?(t=v.css(e.elem,e.prop,!1,""),!t||t==="auto"?0:t):e.elem[e.prop]},set:function(e){v.fx.step[e.prop]?v.fx.step[e.prop](e):e.elem.style&&(e.elem.style[v.cssProps[e.prop]]!=null||v.cssHooks[e.prop])?v.style(e.elem,e.prop,e.now+e.unit):e.elem[e.prop]=e.now}}},Yn.propHooks.scrollTop=Yn.propHooks.scrollLeft={set:function(e){e.elem.nodeType&&e.elem.parentNode&&(e.elem[e.prop]=e.now)}},v.each(["toggle","show","hide"],function(e,t){var n=v.fn[t];v.fn[t]=function(r,i,s){return r==null||typeof r=="boolean"||!e&&v.isFunction(r)&&v.isFunction(i)?n.apply(this,arguments):this.animate(Zn(t,!0),r,i,s)}}),v.fn.extend({fadeTo:function(e,t,n,r){return this.filter(Gt).css("opacity",0).show().end().animate({opacity:t},e,n,r)},animate:function(e,t,n,r){var i=v.isEmptyObject(e),s=v.speed(t,n,r),o=function(){var t=Kn(this,v.extend({},e),s);i&&t.stop(!0)};return i||s.queue===!1?this.each(o):this.queue(s.queue,o)},stop:function(e,n,r){var i=function(e){var t=e.stop;delete e.stop,t(r)};return typeof e!="string"&&(r=n,n=e,e=t),n&&e!==!1&&this.queue(e||"fx",[]),this.each(function(){var t=!0,n=e!=null&&e+"queueHooks",s=v.timers,o=v._data(this);if(n)o[n]&&o[n].stop&&i(o[n]);else for(n in o)o[n]&&o[n].stop&&Wn.test(n)&&i(o[n]);for(n=s.length;n--;)s[n].elem===this&&(e==null||s[n].queue===e)&&(s[n].anim.stop(r),t=!1,s.splice(n,1));(t||!r)&&v.dequeue(this,e)})}}),v.each({slideDown:Zn("show"),slideUp:Zn("hide"),slideToggle:Zn("toggle"),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(e,t){v.fn[e]=function(e,n,r){return this.animate(t,e,n,r)}}),v.speed=function(e,t,n){var r=e&&typeof e=="object"?v.extend({},e):{complete:n||!n&&t||v.isFunction(e)&&e,duration:e,easing:n&&t||t&&!v.isFunction(t)&&t};r.duration=v.fx.off?0:typeof r.duration=="number"?r.duration:r.duration in v.fx.speeds?v.fx.speeds[r.duration]:v.fx.speeds._default;if(r.queue==null||r.queue===!0)r.queue="fx";return r.old=r.complete,r.complete=function(){v.isFunction(r.old)&&r.old.call(this),r.queue&&v.dequeue(this,r.queue)},r},v.easing={linear:function(e){return e},swing:function(e){return.5-Math.cos(e*Math.PI)/2}},v.timers=[],v.fx=Yn.prototype.init,v.fx.tick=function(){var e,n=v.timers,r=0;qn=v.now();for(;r<n.length;r++)e=n[r],!e()&&n[r]===e&&n.splice(r--,1);n.length||v.fx.stop(),qn=t},v.fx.timer=function(e){e()&&v.timers.push(e)&&!Rn&&(Rn=setInterval(v.fx.tick,v.fx.interval))},v.fx.interval=13,v.fx.stop=function(){clearInterval(Rn),Rn=null},v.fx.speeds={slow:600,fast:200,_default:400},v.fx.step={},v.expr&&v.expr.filters&&(v.expr.filters.animated=function(e){return v.grep(v.timers,function(t){return e===t.elem}).length});var er=/^(?:body|html)$/i;v.fn.offset=function(e){if(arguments.length)return e===t?this:this.each(function(t){v.offset.setOffset(this,e,t)});var n,r,i,s,o,u,a,f={top:0,left:0},l=this[0],c=l&&l.ownerDocument;if(!c)return;return(r=c.body)===l?v.offset.bodyOffset(l):(n=c.documentElement,v.contains(n,l)?(typeof l.getBoundingClientRect!="undefined"&&(f=l.getBoundingClientRect()),i=tr(c),s=n.clientTop||r.clientTop||0,o=n.clientLeft||r.clientLeft||0,u=i.pageYOffset||n.scrollTop,a=i.pageXOffset||n.scrollLeft,{top:f.top+u-s,left:f.left+a-o}):f)},v.offset={bodyOffset:function(e){var t=e.offsetTop,n=e.offsetLeft;return v.support.doesNotIncludeMarginInBodyOffset&&(t+=parseFloat(v.css(e,"marginTop"))||0,n+=parseFloat(v.css(e,"marginLeft"))||0),{top:t,left:n}},setOffset:function(e,t,n){var r=v.css(e,"position");r==="static"&&(e.style.position="relative");var i=v(e),s=i.offset(),o=v.css(e,"top"),u=v.css(e,"left"),a=(r==="absolute"||r==="fixed")&&v.inArray("auto",[o,u])>-1,f={},l={},c,h;a?(l=i.position(),c=l.top,h=l.left):(c=parseFloat(o)||0,h=parseFloat(u)||0),v.isFunction(t)&&(t=t.call(e,n,s)),t.top!=null&&(f.top=t.top-s.top+c),t.left!=null&&(f.left=t.left-s.left+h),"using"in t?t.using.call(e,f):i.css(f)}},v.fn.extend({position:function(){if(!this[0])return;var e=this[0],t=this.offsetParent(),n=this.offset(),r=er.test(t[0].nodeName)?{top:0,left:0}:t.offset();return n.top-=parseFloat(v.css(e,"marginTop"))||0,n.left-=parseFloat(v.css(e,"marginLeft"))||0,r.top+=parseFloat(v.css(t[0],"borderTopWidth"))||0,r.left+=parseFloat(v.css(t[0],"borderLeftWidth"))||0,{top:n.top-r.top,left:n.left-r.left}},offsetParent:function(){return this.map(function(){var e=this.offsetParent||i.body;while(e&&!er.test(e.nodeName)&&v.css(e,"position")==="static")e=e.offsetParent;return e||i.body})}}),v.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(e,n){var r=/Y/.test(n);v.fn[e]=function(i){return v.access(this,function(e,i,s){var o=tr(e);if(s===t)return o?n in o?o[n]:o.document.documentElement[i]:e[i];o?o.scrollTo(r?v(o).scrollLeft():s,r?s:v(o).scrollTop()):e[i]=s},e,i,arguments.length,null)}}),v.each({Height:"height",Width:"width"},function(e,n){v.each({padding:"inner"+e,content:n,"":"outer"+e},function(r,i){v.fn[i]=function(i,s){var o=arguments.length&&(r||typeof i!="boolean"),u=r||(i===!0||s===!0?"margin":"border");return v.access(this,function(n,r,i){var s;return v.isWindow(n)?n.document.documentElement["client"+e]:n.nodeType===9?(s=n.documentElement,Math.max(n.body["scroll"+e],s["scroll"+e],n.body["offset"+e],s["offset"+e],s["client"+e])):i===t?v.css(n,r,i,u):v.style(n,r,i,u)},n,o?i:t,o,null)}})}),e.jQuery=e.$=v,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return v})})(window);
\ No newline at end of file +../../../javascript/jquery/jquery.min.js
\ No newline at end of file diff --git a/program/js/jstz.min.js b/program/js/jstz.min.js index d5f888cac..81c5057fd 100644 --- a/program/js/jstz.min.js +++ b/program/js/jstz.min.js @@ -1,2 +1,11 @@ -/*! jsTimezoneDetect - v1.0.5 - 2013-04-01 */ -(function(e){var t=function(){"use strict";var e="s",n=2011,r=function(e){var t=-e.getTimezoneOffset();return t!==null?t:0},i=function(e,t,n){var r=new Date;return e!==undefined&&r.setFullYear(e),r.setDate(n),r.setMonth(t),r},s=function(e){return r(i(e,0,2))},o=function(e){return r(i(e,5,2))},u=function(e){var t=e.getMonth()>7?o(e.getFullYear()):s(e.getFullYear()),n=r(e);return t-n!==0},a=function(){var t=s(n),r=o(n),i=t-r;return i<0?t+",1":i>0?r+",1,"+e:t+",0"},f=function(){var e=a();return new t.TimeZone(t.olson.timezones[e])},l=function(e){var t=new Date(2010,6,15,1,0,0,0),n={"America/Denver":new Date(2011,2,13,3,0,0,0),"America/Mazatlan":new Date(2011,3,3,3,0,0,0),"America/Chicago":new Date(2011,2,13,3,0,0,0),"America/Mexico_City":new Date(2011,3,3,3,0,0,0),"America/Asuncion":new Date(2012,9,7,3,0,0,0),"America/Santiago":new Date(2012,9,3,3,0,0,0),"America/Campo_Grande":new Date(2012,9,21,5,0,0,0),"America/Montevideo":new Date(2011,9,2,3,0,0,0),"America/Sao_Paulo":new Date(2011,9,16,5,0,0,0),"America/Los_Angeles":new Date(2011,2,13,8,0,0,0),"America/Santa_Isabel":new Date(2011,3,5,8,0,0,0),"America/Havana":new Date(2012,2,10,2,0,0,0),"America/New_York":new Date(2012,2,10,7,0,0,0),"Asia/Beirut":new Date(2011,2,27,1,0,0,0),"Europe/Helsinki":new Date(2011,2,27,4,0,0,0),"Europe/Istanbul":new Date(2011,2,28,5,0,0,0),"Asia/Damascus":new Date(2011,3,1,2,0,0,0),"Asia/Jerusalem":new Date(2011,3,1,6,0,0,0),"Asia/Gaza":new Date(2009,2,28,0,30,0,0),"Africa/Cairo":new Date(2009,3,25,0,30,0,0),"Pacific/Auckland":new Date(2011,8,26,7,0,0,0),"Pacific/Fiji":new Date(2010,10,29,23,0,0,0),"America/Halifax":new Date(2011,2,13,6,0,0,0),"America/Goose_Bay":new Date(2011,2,13,2,1,0,0),"America/Miquelon":new Date(2011,2,13,5,0,0,0),"America/Godthab":new Date(2011,2,27,1,0,0,0),"Europe/Moscow":t,"Asia/Yekaterinburg":t,"Asia/Omsk":t,"Asia/Krasnoyarsk":t,"Asia/Irkutsk":t,"Asia/Yakutsk":t,"Asia/Vladivostok":t,"Asia/Kamchatka":t,"Europe/Minsk":t,"Pacific/Apia":new Date(2010,10,1,1,0,0,0),"Australia/Perth":new Date(2008,10,1,1,0,0,0)};return n[e]};return{determine:f,date_is_dst:u,dst_start_for:l}}();t.TimeZone=function(e){"use strict";var n={"America/Denver":["America/Denver","America/Mazatlan"],"America/Chicago":["America/Chicago","America/Mexico_City"],"America/Santiago":["America/Santiago","America/Asuncion","America/Campo_Grande"],"America/Montevideo":["America/Montevideo","America/Sao_Paulo"],"Asia/Beirut":["Asia/Beirut","Europe/Helsinki","Europe/Istanbul","Asia/Damascus","Asia/Jerusalem","Asia/Gaza"],"Pacific/Auckland":["Pacific/Auckland","Pacific/Fiji"],"America/Los_Angeles":["America/Los_Angeles","America/Santa_Isabel"],"America/New_York":["America/Havana","America/New_York"],"America/Halifax":["America/Goose_Bay","America/Halifax"],"America/Godthab":["America/Miquelon","America/Godthab"],"Asia/Dubai":["Europe/Moscow"],"Asia/Dhaka":["Asia/Yekaterinburg"],"Asia/Jakarta":["Asia/Omsk"],"Asia/Shanghai":["Asia/Krasnoyarsk","Australia/Perth"],"Asia/Tokyo":["Asia/Irkutsk"],"Australia/Brisbane":["Asia/Yakutsk"],"Pacific/Noumea":["Asia/Vladivostok"],"Pacific/Tarawa":["Asia/Kamchatka"],"Pacific/Tongatapu":["Pacific/Apia"],"Africa/Johannesburg":["Asia/Gaza","Africa/Cairo"],"Asia/Baghdad":["Europe/Minsk"]},r=e,i=function(){var e=n[r],i=e.length,s=0,o=e[0];for(;s<i;s+=1){o=e[s];if(t.date_is_dst(t.dst_start_for(o))){r=o;return}}},s=function(){return typeof n[r]!="undefined"};return s()&&i(),{name:function(){return r}}},t.olson={},t.olson.timezones={"-720,0":"Pacific/Majuro","-660,0":"Pacific/Pago_Pago","-600,1":"America/Adak","-600,0":"Pacific/Honolulu","-570,0":"Pacific/Marquesas","-540,0":"Pacific/Gambier","-540,1":"America/Anchorage","-480,1":"America/Los_Angeles","-480,0":"Pacific/Pitcairn","-420,0":"America/Phoenix","-420,1":"America/Denver","-360,0":"America/Guatemala","-360,1":"America/Chicago","-360,1,s":"Pacific/Easter","-300,0":"America/Bogota","-300,1":"America/New_York","-270,0":"America/Caracas","-240,1":"America/Halifax","-240,0":"America/Santo_Domingo","-240,1,s":"America/Santiago","-210,1":"America/St_Johns","-180,1":"America/Godthab","-180,0":"America/Argentina/Buenos_Aires","-180,1,s":"America/Montevideo","-120,0":"America/Noronha","-120,1":"America/Noronha","-60,1":"Atlantic/Azores","-60,0":"Atlantic/Cape_Verde","0,0":"UTC","0,1":"Europe/London","60,1":"Europe/Berlin","60,0":"Africa/Lagos","60,1,s":"Africa/Windhoek","120,1":"Asia/Beirut","120,0":"Africa/Johannesburg","180,0":"Asia/Baghdad","180,1":"Europe/Moscow","210,1":"Asia/Tehran","240,0":"Asia/Dubai","240,1":"Asia/Baku","270,0":"Asia/Kabul","300,1":"Asia/Yekaterinburg","300,0":"Asia/Karachi","330,0":"Asia/Kolkata","345,0":"Asia/Kathmandu","360,0":"Asia/Dhaka","360,1":"Asia/Omsk","390,0":"Asia/Rangoon","420,1":"Asia/Krasnoyarsk","420,0":"Asia/Jakarta","480,0":"Asia/Shanghai","480,1":"Asia/Irkutsk","525,0":"Australia/Eucla","525,1,s":"Australia/Eucla","540,1":"Asia/Yakutsk","540,0":"Asia/Tokyo","570,0":"Australia/Darwin","570,1,s":"Australia/Adelaide","600,0":"Australia/Brisbane","600,1":"Asia/Vladivostok","600,1,s":"Australia/Sydney","630,1,s":"Australia/Lord_Howe","660,1":"Asia/Kamchatka","660,0":"Pacific/Noumea","690,0":"Pacific/Norfolk","720,1,s":"Pacific/Auckland","720,0":"Pacific/Tarawa","765,1,s":"Pacific/Chatham","780,0":"Pacific/Tongatapu","780,1,s":"Pacific/Apia","840,0":"Pacific/Kiritimati"},typeof exports!="undefined"?exports.jstz=t:e.jstz=t})(this);
\ No newline at end of file +var jstz=function(){var b=function(a){a=-a.getTimezoneOffset();return null!==a?a:0},c=function(){return b(new Date(2010,0,1,0,0,0,0))},f=function(){return b(new Date(2010,5,1,0,0,0,0))},e=function(){var a=c(),d=f(),b=c()-f();return new jstz.TimeZone(jstz.olson.timezones[0>b?a+",1":0<b?d+",1,s":a+",0"])};return{determine_timezone:function(){"undefined"!==typeof console&&console.log("jstz.determine_timezone() is deprecated and will be removed in an upcoming version. Please use jstz.determine() instead."); +return e()},determine:e,date_is_dst:function(a){var d=5<a.getMonth()?f():c(),a=b(a);return 0!==d-a}}}();jstz.TimeZone=function(b){var c=null,c=b;"undefined"!==typeof jstz.olson.ambiguity_list[c]&&function(){for(var b=jstz.olson.ambiguity_list[c],e=b.length,a=0,d=b[0];a<e;a+=1)if(d=b[a],jstz.date_is_dst(jstz.olson.dst_start_dates[d])){c=d;break}}();return{name:function(){return c}}};jstz.olson={}; +jstz.olson.timezones={"-720,0":"Etc/GMT+12","-660,0":"Pacific/Pago_Pago","-600,1":"America/Adak","-600,0":"Pacific/Honolulu","-570,0":"Pacific/Marquesas","-540,0":"Pacific/Gambier","-540,1":"America/Anchorage","-480,1":"America/Los_Angeles","-480,0":"Pacific/Pitcairn","-420,0":"America/Phoenix","-420,1":"America/Denver","-360,0":"America/Guatemala","-360,1":"America/Chicago","-360,1,s":"Pacific/Easter","-300,0":"America/Bogota","-300,1":"America/New_York","-270,0":"America/Caracas","-240,1":"America/Halifax", +"-240,0":"America/Santo_Domingo","-240,1,s":"America/Asuncion","-210,1":"America/St_Johns","-180,1":"America/Godthab","-180,0":"America/Argentina/Buenos_Aires","-180,1,s":"America/Montevideo","-120,0":"America/Noronha","-120,1":"Etc/GMT+2","-60,1":"Atlantic/Azores","-60,0":"Atlantic/Cape_Verde","0,0":"Etc/UTC","0,1":"Europe/London","60,1":"Europe/Berlin","60,0":"Africa/Lagos","60,1,s":"Africa/Windhoek","120,1":"Asia/Beirut","120,0":"Africa/Johannesburg","180,1":"Europe/Moscow","180,0":"Asia/Baghdad", +"210,1":"Asia/Tehran","240,0":"Asia/Dubai","240,1":"Asia/Yerevan","270,0":"Asia/Kabul","300,1":"Asia/Yekaterinburg","300,0":"Asia/Karachi","330,0":"Asia/Kolkata","345,0":"Asia/Kathmandu","360,0":"Asia/Dhaka","360,1":"Asia/Omsk","390,0":"Asia/Rangoon","420,1":"Asia/Krasnoyarsk","420,0":"Asia/Jakarta","480,0":"Asia/Shanghai","480,1":"Asia/Irkutsk","525,0":"Australia/Eucla","525,1,s":"Australia/Eucla","540,1":"Asia/Yakutsk","540,0":"Asia/Tokyo","570,0":"Australia/Darwin","570,1,s":"Australia/Adelaide", +"600,0":"Australia/Brisbane","600,1":"Asia/Vladivostok","600,1,s":"Australia/Sydney","630,1,s":"Australia/Lord_Howe","660,1":"Asia/Kamchatka","660,0":"Pacific/Noumea","690,0":"Pacific/Norfolk","720,1,s":"Pacific/Auckland","720,0":"Pacific/Tarawa","765,1,s":"Pacific/Chatham","780,0":"Pacific/Tongatapu","780,1,s":"Pacific/Apia","840,0":"Pacific/Kiritimati"}; +jstz.olson.dst_start_dates={"America/Denver":new Date(2011,2,13,3,0,0,0),"America/Mazatlan":new Date(2011,3,3,3,0,0,0),"America/Chicago":new Date(2011,2,13,3,0,0,0),"America/Mexico_City":new Date(2011,3,3,3,0,0,0),"Atlantic/Stanley":new Date(2011,8,4,7,0,0,0),"America/Asuncion":new Date(2011,9,2,3,0,0,0),"America/Santiago":new Date(2011,9,9,3,0,0,0),"America/Campo_Grande":new Date(2011,9,16,5,0,0,0),"America/Montevideo":new Date(2011,9,2,3,0,0,0),"America/Sao_Paulo":new Date(2011,9,16,5,0,0,0),"America/Los_Angeles":new Date(2011, +2,13,8,0,0,0),"America/Santa_Isabel":new Date(2011,3,5,8,0,0,0),"America/Havana":new Date(2011,2,13,2,0,0,0),"America/New_York":new Date(2011,2,13,7,0,0,0),"Asia/Gaza":new Date(2011,2,26,23,0,0,0),"Asia/Beirut":new Date(2011,2,27,1,0,0,0),"Europe/Minsk":new Date(2011,2,27,2,0,0,0),"Europe/Helsinki":new Date(2011,2,27,4,0,0,0),"Europe/Istanbul":new Date(2011,2,28,5,0,0,0),"Asia/Damascus":new Date(2011,3,1,2,0,0,0),"Asia/Jerusalem":new Date(2011,3,1,6,0,0,0),"Africa/Cairo":new Date(2010,3,30,4,0,0, +0),"Asia/Yerevan":new Date(2011,2,27,4,0,0,0),"Asia/Baku":new Date(2011,2,27,8,0,0,0),"Pacific/Auckland":new Date(2011,8,26,7,0,0,0),"Pacific/Fiji":new Date(2010,11,29,23,0,0,0),"America/Halifax":new Date(2011,2,13,6,0,0,0),"America/Goose_Bay":new Date(2011,2,13,2,1,0,0),"America/Miquelon":new Date(2011,2,13,5,0,0,0),"America/Godthab":new Date(2011,2,27,1,0,0,0)}; +jstz.olson.ambiguity_list={"America/Denver":["America/Denver","America/Mazatlan"],"America/Chicago":["America/Chicago","America/Mexico_City"],"America/Asuncion":["Atlantic/Stanley","America/Asuncion","America/Santiago","America/Campo_Grande"],"America/Montevideo":["America/Montevideo","America/Sao_Paulo"],"Asia/Beirut":"Asia/Gaza Asia/Beirut Europe/Minsk Europe/Helsinki Europe/Istanbul Asia/Damascus Asia/Jerusalem Africa/Cairo".split(" "),"Asia/Yerevan":["Asia/Yerevan","Asia/Baku"],"Pacific/Auckland":["Pacific/Auckland", +"Pacific/Fiji"],"America/Los_Angeles":["America/Los_Angeles","America/Santa_Isabel"],"America/New_York":["America/Havana","America/New_York"],"America/Halifax":["America/Goose_Bay","America/Halifax"],"America/Godthab":["America/Miquelon","America/Godthab"]};
\ No newline at end of file diff --git a/program/js/list.js b/program/js/list.js index 4ae6c0c66..fbb478db7 100644 --- a/program/js/list.js +++ b/program/js/list.js @@ -1,1625 +1 @@ -/* - +-----------------------------------------------------------------------+ - | Roundcube List Widget | - | | - | This file is part of the Roundcube Webmail client | - | Copyright (C) 2006-2013, The Roundcube Dev Team | - | | - | Licensed under the GNU General Public License version 3 or | - | any later version with exceptions for skins & plugins. | - | See the README file for a full license statement. | - | | - +-----------------------------------------------------------------------+ - | Authors: Thomas Bruederli <roundcube@gmail.com> | - | Charles McNulty <charles@charlesmcnulty.com> | - +-----------------------------------------------------------------------+ - | Requires: common.js | - +-----------------------------------------------------------------------+ -*/ - - -/** - * Roundcube List Widget class - * @contructor - */ -function rcube_list_widget(list, p) -{ - // static contants - this.ENTER_KEY = 13; - this.DELETE_KEY = 46; - this.BACKSPACE_KEY = 8; - - this.list = list ? list : null; - this.tagname = this.list ? this.list.nodeName.toLowerCase() : 'table'; - this.id_regexp = /^rcmrow([a-z0-9\-_=\+\/]+)/i; - this.thead; - this.tbody; - this.fixed_header; - this.frame = null; - this.rows = {}; - this.selection = []; - this.rowcount = 0; - this.colcount = 0; - - this.subject_col = -1; - this.modkey = 0; - this.multiselect = false; - this.multiexpand = false; - this.multi_selecting = false; - this.draggable = false; - this.column_movable = false; - this.keyboard = false; - this.toggleselect = false; - - this.drag_active = false; - this.col_drag_active = false; - this.column_fixed = null; - this.last_selected = 0; - this.shift_start = 0; - this.focused = false; - this.drag_mouse_start = null; - this.dblclick_time = 500; // default value on MS Windows is 500 - this.row_init = function(){}; // @deprecated; use list.addEventListener('initrow') instead - - // overwrite default paramaters - if (p && typeof p === 'object') - for (var n in p) - this[n] = p[n]; -}; - - -rcube_list_widget.prototype = { - - -/** - * get all message rows from HTML table and init each row - */ -init: function() -{ - if (this.tagname == 'table' && this.list && this.list.tBodies[0]) { - this.thead = this.list.tHead; - this.tbody = this.list.tBodies[0]; - } - else if (this.tagname != 'table' && this.list) { - this.tbody = this.list; - } - - if (this.tbody) { - this.rows = {}; - this.rowcount = 0; - - var r, len, rows = this.tbody.childNodes; - - for (r=0, len=rows.length; r<len; r++) { - this.init_row(rows[r]); - this.rowcount++; - } - - this.init_header(); - this.frame = this.list.parentNode; - - // set body events - if (this.keyboard) - rcube_event.add_listener({event:'keydown', object:this, method:'key_press'}); - } -}, - - -/** - * Init list row and set mouse events on it - */ -init_row: function(row) -{ - // make references in internal array and set event handlers - if (row && String(row.id).match(this.id_regexp)) { - var self = this, - uid = RegExp.$1; - row.uid = uid; - this.rows[uid] = {uid:uid, id:row.id, obj:row}; - - // set eventhandlers to table row - row.onmousedown = function(e){ return self.drag_row(e, this.uid); }; - row.onmouseup = function(e){ return self.click_row(e, this.uid); }; - - if (bw.touch) { - row.addEventListener('touchstart', function(e) { - if (e.touches.length == 1) { - self.touchmoved = false; - self.drag_row(rcube_event.touchevent(e.touches[0]), this.uid) - } - }, false); - row.addEventListener('touchend', function(e) { - if (e.changedTouches.length == 1) { - if (!self.touchmoved && !self.click_row(rcube_event.touchevent(e.changedTouches[0]), this.uid)) - e.preventDefault(); - } - }, false); - row.addEventListener('touchmove', function(e) { - if (e.changedTouches.length == 1) { - self.touchmoved = true; - if (self.drag_active) - e.preventDefault(); - } - }, false); - } - - if (document.all) - row.onselectstart = function() { return false; }; - - this.row_init(this.rows[uid]); // legacy support - this.triggerEvent('initrow', this.rows[uid]); - } -}, - - -/** - * Init list column headers and set mouse events on them - */ -init_header: function() -{ - if (this.thead) { - this.colcount = 0; - - if (this.fixed_header) { // copy (modified) fixed header back to the actual table - $(this.list.tHead).replaceWith($(this.fixed_header).find('thead').clone()); - $(this.list.tHead).find('tr td').attr('style', ''); // remove fixed widths - } - else if (!bw.touch && this.list.className.indexOf('fixedheader') >= 0) { - this.init_fixed_header(); - } - - var col, r, p = this; - // add events for list columns moving - if (this.column_movable && this.thead && this.thead.rows) { - for (r=0; r<this.thead.rows[0].cells.length; r++) { - if (this.column_fixed == r) - continue; - col = this.thead.rows[0].cells[r]; - col.onmousedown = function(e){ return p.drag_column(e, this); }; - this.colcount++; - } - } - } -}, - -init_fixed_header: function() -{ - var clone = $(this.list.tHead).clone(); - - if (!this.fixed_header) { - this.fixed_header = $('<table>') - .attr('class', this.list.className + ' fixedcopy') - .css({ position:'fixed' }) - .append(clone) - .append('<tbody></tbody>'); - $(this.list).before(this.fixed_header); - - var me = this; - $(window).resize(function(){ me.resize() }); - } - else { - $(this.fixed_header).find('thead').replaceWith(clone); - } - - this.thead = clone.get(0); - this.resize(); -}, - -resize: function() -{ - if (!this.fixed_header) - return; - - var column_widths = []; - - // get column widths from original thead - $(this.tbody).parent().find('thead tr td').each(function(index) { - column_widths[index] = $(this).width(); - }); - - // apply fixed widths to fixed table header - $(this.thead).parent().width($(this.tbody).parent().width()); - $(this.thead).find('tr td').each(function(index) { - $(this).css('width', column_widths[index]); - }); -}, - -/** - * Remove all list rows - */ -clear: function(sel) -{ - if (this.tagname == 'table') { - var tbody = document.createElement('tbody'); - this.list.insertBefore(tbody, this.tbody); - this.list.removeChild(this.list.tBodies[1]); - this.tbody = tbody; - } - else { - $(this.row_tagname() + ':not(.thead)', this.tbody).remove(); - } - - this.rows = {}; - this.rowcount = 0; - - if (sel) - this.clear_selection(); - - // reset scroll position (in Opera) - if (this.frame) - this.frame.scrollTop = 0; -}, - - -/** - * 'remove' message row from list (just hide it) - */ -remove_row: function(uid, sel_next) -{ - var node = this.rows[uid] ? this.rows[uid].obj : null; - - if (!node) - return; - - node.style.display = 'none'; - - if (sel_next) - this.select_next(); - - delete this.rows[uid]; - this.rowcount--; -}, - - -/** - * Add row to the list and initialize it - */ -insert_row: function(row, before) -{ - var tbody = this.tbody; - - // create a real dom node first - if (row.nodeName === undefined) { - // for performance reasons use DOM instead of jQuery here - var domrow = document.createElement(this.row_tagname()); - if (row.id) domrow.id = row.id; - if (row.className) domrow.className = row.className; - if (row.style) $.extend(domrow.style, row.style); - - for (var domcell, col, i=0; row.cols && i < row.cols.length; i++) { - col = row.cols[i]; - domcell = document.createElement(this.col_tagname()); - if (col.className) domcell.className = col.className; - if (col.innerHTML) domcell.innerHTML = col.innerHTML; - domrow.appendChild(domcell); - } - - row = domrow; - } - - if (before && tbody.childNodes.length) - tbody.insertBefore(row, (typeof before == 'object' && before.parentNode == tbody) ? before : tbody.firstChild); - else - tbody.appendChild(row); - - this.init_row(row); - this.rowcount++; -}, - -/** - * - */ -update_row: function(id, cols, newid, select) -{ - var row = this.rows[id]; - if (!row) return false; - - var domrow = row.obj; - for (var domcell, col, i=0; cols && i < cols.length; i++) { - this.get_cell(domrow, i).html(cols[i]); - } - - if (newid) { - delete this.rows[id]; - domrow.id = 'rcmrow' + newid; - this.init_row(domrow); - - if (select) - this.selection[0] = newid; - } -}, - - -/** - * Set focus to the list - */ -focus: function(e) -{ - var n, id; - this.focused = true; - - for (n in this.selection) { - id = this.selection[n]; - if (this.rows[id] && this.rows[id].obj) { - $(this.rows[id].obj).addClass('selected').removeClass('unfocused'); - } - } - - // Un-focus already focused elements (#1487123, #1487316, #1488600, #1488620) - // It looks that window.focus() does the job for all browsers, but not Firefox (#1489058) - $(':focus:not(body)').blur(); - window.focus(); - - if (e || (e = window.event)) - rcube_event.cancel(e); -}, - - -/** - * remove focus from the list - */ -blur: function() -{ - var n, id; - this.focused = false; - for (n in this.selection) { - id = this.selection[n]; - if (this.rows[id] && this.rows[id].obj) { - $(this.rows[id].obj).removeClass('selected focused').addClass('unfocused'); - } - } -}, - - -/** - * onmousedown-handler of message list column - */ -drag_column: function(e, col) -{ - if (this.colcount > 1) { - this.drag_start = true; - this.drag_mouse_start = rcube_event.get_mouse_pos(e); - - rcube_event.add_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); - rcube_event.add_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); - - // enable dragging over iframes - this.add_dragfix(); - - // find selected column number - for (var i=0; i<this.thead.rows[0].cells.length; i++) { - if (col == this.thead.rows[0].cells[i]) { - this.selected_column = i; - break; - } - } - } - - return false; -}, - - -/** - * onmousedown-handler of message list row - */ -drag_row: function(e, id) -{ - // don't do anything (another action processed before) - if (!this.is_event_target(e)) - return true; - - // accept right-clicks - if (rcube_event.get_button(e) == 2) - return true; - - this.in_selection_before = e && e.istouch || this.in_selection(id) ? id : false; - - // selects currently unselected row - if (!this.in_selection_before) { - var mod_key = rcube_event.get_modifier(e); - this.select_row(id, mod_key, true); - } - - if (this.draggable && this.selection.length && this.in_selection(id)) { - this.drag_start = true; - this.drag_mouse_start = rcube_event.get_mouse_pos(e); - - rcube_event.add_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); - rcube_event.add_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); - if (bw.touch) { - rcube_event.add_listener({event:'touchmove', object:this, method:'drag_mouse_move'}); - rcube_event.add_listener({event:'touchend', object:this, method:'drag_mouse_up'}); - } - - // enable dragging over iframes - this.add_dragfix(); - } - - return false; -}, - - -/** - * onmouseup-handler of message list row - */ -click_row: function(e, id) -{ - // don't do anything (another action processed before) - if (!this.is_event_target(e)) - return true; - - var now = new Date().getTime(), - dblclicked = now - this.rows[id].clicked < this.dblclick_time; - - // unselects currently selected row - if (!this.drag_active && !dblclicked && this.in_selection_before == id) - this.select_row(id, rcube_event.get_modifier(e), true); - - this.drag_start = false; - this.in_selection_before = false; - - // row was double clicked - if (this.rowcount && dblclicked && this.in_selection(id)) { - this.triggerEvent('dblclick'); - now = 0; - } - else - this.triggerEvent('click'); - - if (!this.drag_active) { - // remove temp divs - this.del_dragfix(); - rcube_event.cancel(e); - } - - this.rows[id].clicked = now; - return false; -}, - - -/** - * Check target of the current event - */ -is_event_target: function(e) -{ - var target = rcube_event.get_target(e), - tagname = target.tagName.toLowerCase(); - - return !(target && (tagname == 'input' || tagname == 'img' || (tagname != 'a' && target.onclick))); -}, - - -/* - * Returns thread root ID for specified row ID - */ -find_root: function(uid) -{ - var r = this.rows[uid]; - - if (r && r.parent_uid) - return this.find_root(r.parent_uid); - else - return uid; -}, - - -expand_row: function(e, id) -{ - var row = this.rows[id], - evtarget = rcube_event.get_target(e), - mod_key = rcube_event.get_modifier(e); - - // Don't treat double click on the expando as double click on the message. - row.clicked = 0; - - if (row.expanded) { - evtarget.className = 'collapsed'; - if (mod_key == CONTROL_KEY || this.multiexpand) - this.collapse_all(row); - else - this.collapse(row); - } - else { - evtarget.className = 'expanded'; - if (mod_key == CONTROL_KEY || this.multiexpand) - this.expand_all(row); - else - this.expand(row); - } -}, - -collapse: function(row) -{ - row.expanded = false; - this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); - var depth = row.depth; - var new_row = row ? row.obj.nextSibling : null; - var r; - - while (new_row) { - if (new_row.nodeType == 1) { - var r = this.rows[new_row.uid]; - if (r && r.depth <= depth) - break; - $(new_row).css('display', 'none'); - if (r.expanded) { - r.expanded = false; - this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); - } - } - new_row = new_row.nextSibling; - } - - this.resize(); - this.triggerEvent('listupdate'); - return false; -}, - -expand: function(row) -{ - var r, p, depth, new_row, last_expanded_parent_depth; - - if (row) { - row.expanded = true; - depth = row.depth; - new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); - this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); - } - else { - var tbody = this.tbody; - new_row = tbody.firstChild; - depth = 0; - last_expanded_parent_depth = 0; - } - - while (new_row) { - if (new_row.nodeType == 1) { - r = this.rows[new_row.uid]; - if (r) { - if (row && (!r.depth || r.depth <= depth)) - break; - - if (r.parent_uid) { - p = this.rows[r.parent_uid]; - if (p && p.expanded) { - if ((row && p == row) || last_expanded_parent_depth >= p.depth - 1) { - last_expanded_parent_depth = p.depth; - $(new_row).css('display', ''); - r.expanded = true; - this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); - } - } - else - if (row && (! p || p.depth <= depth)) - break; - } - } - } - new_row = new_row.nextSibling; - } - - this.resize(); - this.triggerEvent('listupdate'); - return false; -}, - - -collapse_all: function(row) -{ - var depth, new_row, r; - - if (row) { - row.expanded = false; - depth = row.depth; - new_row = row.obj.nextSibling; - this.update_expando(row.uid); - this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); - - // don't collapse sub-root tree in multiexpand mode - if (depth && this.multiexpand) - return false; - } - else { - new_row = this.tbody.firstChild; - depth = 0; - } - - while (new_row) { - if (new_row.nodeType == 1) { - if (r = this.rows[new_row.uid]) { - if (row && (!r.depth || r.depth <= depth)) - break; - - if (row || r.depth) - $(new_row).css('display', 'none'); - if (r.has_children && r.expanded) { - r.expanded = false; - this.update_expando(r.uid, false); - this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); - } - } - } - new_row = new_row.nextSibling; - } - - this.resize(); - this.triggerEvent('listupdate'); - return false; -}, - - -expand_all: function(row) -{ - var depth, new_row, r; - - if (row) { - row.expanded = true; - depth = row.depth; - new_row = row.obj.nextSibling; - this.update_expando(row.uid, true); - this.triggerEvent('expandcollapse', { uid:row.uid, expanded:row.expanded, obj:row.obj }); - } - else { - new_row = this.tbody.firstChild; - depth = 0; - } - - while (new_row) { - if (new_row.nodeType == 1) { - if (r = this.rows[new_row.uid]) { - if (row && r.depth <= depth) - break; - - $(new_row).css('display', ''); - if (r.has_children && !r.expanded) { - r.expanded = true; - this.update_expando(r.uid, true); - this.triggerEvent('expandcollapse', { uid:r.uid, expanded:r.expanded, obj:new_row }); - } - } - } - new_row = new_row.nextSibling; - } - - this.resize(); - this.triggerEvent('listupdate'); - return false; -}, - - -update_expando: function(uid, expanded) -{ - var expando = document.getElementById('rcmexpando' + uid); - if (expando) - expando.className = expanded ? 'expanded' : 'collapsed'; -}, - - -/** - * get first/next/previous/last rows that are not hidden - */ -get_next_row: function() -{ - if (!this.rowcount) - return false; - - var last_selected_row = this.rows[this.last_selected], - new_row = last_selected_row ? last_selected_row.obj.nextSibling : null; - - while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) - new_row = new_row.nextSibling; - - return new_row; -}, - -get_prev_row: function() -{ - if (!this.rowcount) - return false; - - var last_selected_row = this.rows[this.last_selected], - new_row = last_selected_row ? last_selected_row.obj.previousSibling : null; - - while (new_row && (new_row.nodeType != 1 || new_row.style.display == 'none')) - new_row = new_row.previousSibling; - - return new_row; -}, - -get_first_row: function() -{ - if (this.rowcount) { - var i, len, rows = this.tbody.childNodes; - - for (i=0, len=rows.length-1; i<len; i++) - if (rows[i].id && String(rows[i].id).match(this.id_regexp) && this.rows[RegExp.$1] != null) - return RegExp.$1; - } - - return null; -}, - -get_last_row: function() -{ - if (this.rowcount) { - var i, rows = this.tbody.childNodes; - - for (i=rows.length-1; i>=0; i--) - if (rows[i].id && String(rows[i].id).match(this.id_regexp) && this.rows[RegExp.$1] != null) - return RegExp.$1; - } - - return null; -}, - -row_tagname: function() -{ - var row_tagnames = { table:'tr', ul:'li', '*':'div' }; - return row_tagnames[this.tagname] || row_tagnames['*']; -}, - -col_tagname: function() -{ - var col_tagnames = { table:'td', '*':'span' }; - return col_tagnames[this.tagname] || col_tagnames['*']; -}, - -get_cell: function(row, index) -{ - return $(this.col_tagname(), row).eq(index); -}, - -/** - * selects or unselects the proper row depending on the modifier key pressed - */ -select_row: function(id, mod_key, with_mouse) -{ - var select_before = this.selection.join(','); - - if (!this.multiselect) - mod_key = 0; - - if (!this.shift_start) - this.shift_start = id - - if (!mod_key) { - this.shift_start = id; - this.highlight_row(id, false); - this.multi_selecting = false; - } - else { - switch (mod_key) { - case SHIFT_KEY: - this.shift_select(id, false); - break; - - case CONTROL_KEY: - if (with_mouse) { - this.shift_start = id; - this.highlight_row(id, true); - } - break; - - case CONTROL_SHIFT_KEY: - this.shift_select(id, true); - break; - - default: - this.highlight_row(id, false); - break; - } - - this.multi_selecting = true; - } - - // trigger event if selection changed - if (this.selection.join(',') != select_before) - this.triggerEvent('select'); - - if (this.last_selected != 0 && this.rows[this.last_selected]) - $(this.rows[this.last_selected].obj).removeClass('focused'); - - // unselect if toggleselect is active and the same row was clicked again - if (this.toggleselect && this.last_selected == id) { - this.clear_selection(); - id = null; - } - else - $(this.rows[id].obj).addClass('focused'); - - if (!this.selection.length) - this.shift_start = null; - - this.last_selected = id; -}, - - -/** - * Alias method for select_row - */ -select: function(id) -{ - this.select_row(id, false); - this.scrollto(id); -}, - - -/** - * Select row next to the last selected one. - * Either below or above. - */ -select_next: function() -{ - var next_row = this.get_next_row(), - prev_row = this.get_prev_row(), - new_row = (next_row) ? next_row : prev_row; - - if (new_row) - this.select_row(new_row.uid, false, false); -}, - - -/** - * Select first row - */ -select_first: function(mod_key) -{ - var row = this.get_first_row(); - if (row) { - this.select_row(row, mod_key, false); - this.scrollto(row); - } -}, - - -/** - * Select last row - */ -select_last: function(mod_key) -{ - var row = this.get_last_row(); - if (row) { - this.select_row(row, mod_key, false); - this.scrollto(row); - } -}, - - -/** - * Add all childs of the given row to selection - */ -select_children: function(uid) -{ - var i, children = this.row_children(uid), len = children.length; - - for (i=0; i<len; i++) - if (!this.in_selection(children[i])) - this.select_row(children[i], CONTROL_KEY, true); -}, - - -/** - * Perform selection when shift key is pressed - */ -shift_select: function(id, control) -{ - if (!this.rows[this.shift_start] || !this.selection.length) - this.shift_start = id; - - var n, i, j, to_row = this.rows[id], - from_rowIndex = this._rowIndex(this.rows[this.shift_start].obj), - to_rowIndex = this._rowIndex(to_row.obj); - - // if we're going down the list, and we hit a thread, and it's closed, select the whole thread - if (from_rowIndex < to_rowIndex && !to_row.expanded && to_row.has_children) - if (to_row = this.rows[(this.row_children(id)).pop()]) - to_rowIndex = this._rowIndex(to_row.obj); - - i = ((from_rowIndex < to_rowIndex) ? from_rowIndex : to_rowIndex), - j = ((from_rowIndex > to_rowIndex) ? from_rowIndex : to_rowIndex); - - // iterate through the entire message list - for (n in this.rows) { - if (this._rowIndex(this.rows[n].obj) >= i && this._rowIndex(this.rows[n].obj) <= j) { - if (!this.in_selection(n)) { - this.highlight_row(n, true); - } - } - else { - if (this.in_selection(n) && !control) { - this.highlight_row(n, true); - } - } - } -}, - - -/** - * Helper method to emulate the rowIndex property of non-tr elements - */ -_rowIndex: function(obj) -{ - return (obj.rowIndex !== undefined) ? obj.rowIndex : $(obj).prevAll().length; -}, - -/** - * Check if given id is part of the current selection - */ -in_selection: function(id) -{ - for (var n in this.selection) - if (this.selection[n]==id) - return true; - - return false; -}, - - -/** - * Select each row in list - */ -select_all: function(filter) -{ - if (!this.rowcount) - return false; - - // reset but remember selection first - var n, select_before = this.selection.join(','); - this.selection = []; - - for (n in this.rows) { - if (!filter || this.rows[n][filter] == true) { - this.last_selected = n; - this.highlight_row(n, true, true); - } - else { - $(this.rows[n].obj).removeClass('selected').removeClass('unfocused'); - } - } - - // trigger event if selection changed - if (this.selection.join(',') != select_before) - this.triggerEvent('select'); - - this.focus(); - - return true; -}, - - -/** - * Invert selection - */ -invert_selection: function() -{ - if (!this.rowcount) - return false; - - // remember old selection - var n, select_before = this.selection.join(','); - - for (n in this.rows) - this.highlight_row(n, true); - - // trigger event if selection changed - if (this.selection.join(',') != select_before) - this.triggerEvent('select'); - - this.focus(); - - return true; -}, - - -/** - * Unselect selected row(s) - */ -clear_selection: function(id) -{ - var n, num_select = this.selection.length; - - // one row - if (id) { - for (n in this.selection) - if (this.selection[n] == id) { - this.selection.splice(n,1); - break; - } - } - // all rows - else { - for (n in this.selection) - if (this.rows[this.selection[n]]) { - $(this.rows[this.selection[n]].obj).removeClass('selected').removeClass('unfocused'); - } - - this.selection = []; - } - - if (num_select && !this.selection.length) - this.triggerEvent('select'); -}, - - -/** - * Getter for the selection array - */ -get_selection: function() -{ - return this.selection; -}, - - -/** - * Return the ID if only one row is selected - */ -get_single_selection: function() -{ - if (this.selection.length == 1) - return this.selection[0]; - else - return null; -}, - - -/** - * Highlight/unhighlight a row - */ -highlight_row: function(id, multiple, norecur) -{ - if (!this.rows[id]) - return; - - if (!multiple) { - if (this.selection.length > 1 || !this.in_selection(id)) { - this.clear_selection(); - this.selection[0] = id; - $(this.rows[id].obj).addClass('selected'); - } - } - else { - if (!this.in_selection(id)) { // select row - this.selection.push(id); - $(this.rows[id].obj).addClass('selected'); - if (!norecur && !this.rows[id].expanded) - this.highlight_children(id, true); - } - else { // unselect row - var p = $.inArray(id, this.selection), - a_pre = this.selection.slice(0, p), - a_post = this.selection.slice(p+1, this.selection.length); - - this.selection = a_pre.concat(a_post); - $(this.rows[id].obj).removeClass('selected').removeClass('unfocused'); - if (!norecur && !this.rows[id].expanded) - this.highlight_children(id, false); - } - } -}, - - -/** - * Highlight/unhighlight all childs of the given row - */ -highlight_children: function(id, status) -{ - var i, selected, - children = this.row_children(id), len = children.length; - - for (i=0; i<len; i++) { - selected = this.in_selection(children[i]); - if ((status && !selected) || (!status && selected)) - this.highlight_row(children[i], true, true); - } -}, - - -/** - * Handler for keyboard events - */ -key_press: function(e) -{ - var target = e.target || {}; - if (this.focused != true || target.nodeName == 'INPUT' || target.nodeName == 'TEXTAREA' || target.nodeName == 'SELECT') - return true; - - var keyCode = rcube_event.get_keycode(e), - mod_key = rcube_event.get_modifier(e); - - switch (keyCode) { - case 40: - case 38: - case 63233: // "down", in safari keypress - case 63232: // "up", in safari keypress - // Stop propagation so that the browser doesn't scroll - rcube_event.cancel(e); - return this.use_arrow_key(keyCode, mod_key); - - case 32: - rcube_event.cancel(e); - return this.select_row(this.last_selected, mod_key, true); - - case 37: // Left arrow key - case 39: // Right arrow key - case 107: // Plus sign on a numeric keypad - case 109: // Minus sign on a numeric keypad - // Stop propagation - rcube_event.cancel(e); - var ret = this.use_plusminus_key(keyCode, mod_key); - this.key_pressed = keyCode; - this.modkey = mod_key; - this.triggerEvent('keypress'); - this.modkey = 0; - return ret; - - case 36: // Home - this.select_first(mod_key); - return rcube_event.cancel(e); - - case 35: // End - this.select_last(mod_key); - return rcube_event.cancel(e); - - case 27: - if (this.drag_active) - return this.drag_mouse_up(e); - - if (this.col_drag_active) { - this.selected_column = null; - return this.column_drag_mouse_up(e); - } - - return rcube_event.cancel(e); - - default: - this.key_pressed = keyCode; - this.modkey = mod_key; - this.triggerEvent('keypress'); - this.modkey = 0; - - if (this.key_pressed == this.BACKSPACE_KEY) - return rcube_event.cancel(e); - } - - return true; -}, - - -/** - * Special handling method for arrow keys - */ -use_arrow_key: function(keyCode, mod_key) -{ - var new_row; - // Safari uses the nonstandard keycodes 63232/63233 for up/down, if we're - // using the keypress event (but not the keydown or keyup event). - if (keyCode == 40 || keyCode == 63233) // down arrow key pressed - new_row = this.get_next_row(); - else if (keyCode == 38 || keyCode == 63232) // up arrow key pressed - new_row = this.get_prev_row(); - - if (new_row) { - this.select_row(new_row.uid, mod_key, false); - this.scrollto(new_row.uid); - } - - return false; -}, - - -/** - * Special handling method for +/- keys - */ -use_plusminus_key: function(keyCode, mod_key) -{ - var selected_row = this.rows[this.last_selected]; - - if (!selected_row || !selected_row.has_children) - return; - - // expand - if (keyCode == 39 || keyCode == 107) { - if (selected_row.expanded) - return; - - if (mod_key == CONTROL_KEY || this.multiexpand) - this.expand_all(selected_row); - else - this.expand(selected_row); - } - // collapse - else { - if (!selected_row.expanded) - return; - - if (mod_key == CONTROL_KEY || this.multiexpand) - this.collapse_all(selected_row); - else - this.collapse(selected_row); - } - - this.update_expando(selected_row.uid, selected_row.expanded); - - return false; -}, - - -/** - * Try to scroll the list to make the specified row visible - */ -scrollto: function(id) -{ - var row = this.rows[id].obj; - if (row && this.frame) { - var scroll_to = Number(row.offsetTop), - head_offset = 0; - - // expand thread if target row is hidden (collapsed) - if (!scroll_to && this.rows[id].parent_uid) { - var parent = this.find_root(this.rows[id].uid); - this.expand_all(this.rows[parent]); - scroll_to = Number(row.offsetTop); - } - - if (this.fixed_header) - head_offset = Number(this.thead.offsetHeight); - - // if row is above the frame (or behind header) - if (scroll_to < Number(this.frame.scrollTop) + head_offset) { - // scroll window so that row isn't behind header - this.frame.scrollTop = scroll_to - head_offset; - } - else if (scroll_to + Number(row.offsetHeight) > Number(this.frame.scrollTop) + Number(this.frame.offsetHeight)) - this.frame.scrollTop = (scroll_to + Number(row.offsetHeight)) - Number(this.frame.offsetHeight); - } -}, - - -/** - * Handler for mouse move events - */ -drag_mouse_move: function(e) -{ - // convert touch event - if (e.type == 'touchmove') { - if (e.touches.length == 1 && e.changedTouches.length == 1) - e = rcube_event.touchevent(e.changedTouches[0]); - else - return rcube_event.cancel(e); - } - - if (this.drag_start) { - // check mouse movement, of less than 3 pixels, don't start dragging - var m = rcube_event.get_mouse_pos(e); - - if (!this.drag_mouse_start || (Math.abs(m.x - this.drag_mouse_start.x) < 3 && Math.abs(m.y - this.drag_mouse_start.y) < 3)) - return false; - - if (!this.draglayer) - this.draglayer = $('<div>').attr('id', 'rcmdraglayer') - .css({ position:'absolute', display:'none', 'z-index':2000 }) - .appendTo(document.body); - - // also select childs of (collapsed) threads for dragging - var n, uid, selection = $.merge([], this.selection); - for (n in selection) { - uid = selection[n]; - if (!this.rows[uid].expanded) - this.select_children(uid); - } - - // reset content - this.draglayer.html(''); - - // get subjects of selected messages - var i, n, obj, me; - for (n=0; n<this.selection.length; n++) { - // only show 12 lines - if (n>12) { - this.draglayer.append('...'); - break; - } - - me = this; - if (obj = this.rows[this.selection[n]].obj) { - $('> '+this.col_tagname(), obj).each(function(i,elem){ - if (n == 0) - me.drag_start_pos = $(elem).offset(); - - if (me.subject_col < 0 || (me.subject_col >= 0 && me.subject_col == i)) { - var subject = $(elem).text(); - - if (subject) { - // remove leading spaces - subject = $.trim(subject); - // truncate line to 50 characters - subject = (subject.length > 50 ? subject.substring(0, 50) + '...' : subject); - - var entry = $('<div>').text(subject); - me.draglayer.append(entry); - } - - return false; // break - } - }); - } - } - - this.draglayer.show(); - this.drag_active = true; - this.triggerEvent('dragstart'); - } - - if (this.drag_active && this.draglayer) { - var pos = rcube_event.get_mouse_pos(e); - this.draglayer.css({ left:(pos.x+20)+'px', top:(pos.y-5 + (bw.ie ? document.documentElement.scrollTop : 0))+'px' }); - this.triggerEvent('dragmove', e?e:window.event); - } - - this.drag_start = false; - - return false; -}, - - -/** - * Handler for mouse up events - */ -drag_mouse_up: function(e) -{ - document.onmousemove = null; - - if (e.type == 'touchend') { - if (e.changedTouches.length != 1) - return rcube_event.cancel(e); - } - - if (this.draglayer && this.draglayer.is(':visible')) { - if (this.drag_start_pos) - this.draglayer.animate(this.drag_start_pos, 300, 'swing').hide(20); - else - this.draglayer.hide(); - } - - if (this.drag_active) - this.focus(); - this.drag_active = false; - - rcube_event.remove_listener({event:'mousemove', object:this, method:'drag_mouse_move'}); - rcube_event.remove_listener({event:'mouseup', object:this, method:'drag_mouse_up'}); - - if (bw.touch) { - rcube_event.remove_listener({event:'touchmove', object:this, method:'drag_mouse_move'}); - rcube_event.remove_listener({event:'touchend', object:this, method:'drag_mouse_up'}); - } - - // remove temp divs - this.del_dragfix(); - - this.triggerEvent('dragend', e); - - return rcube_event.cancel(e); -}, - - -/** - * Handler for mouse move events for dragging list column - */ -column_drag_mouse_move: function(e) -{ - if (this.drag_start) { - // check mouse movement, of less than 3 pixels, don't start dragging - var i, m = rcube_event.get_mouse_pos(e); - - if (!this.drag_mouse_start || (Math.abs(m.x - this.drag_mouse_start.x) < 3 && Math.abs(m.y - this.drag_mouse_start.y) < 3)) - return false; - - if (!this.col_draglayer) { - var lpos = $(this.list).offset(), - cells = this.thead.rows[0].cells; - - // create dragging layer - this.col_draglayer = $('<div>').attr('id', 'rcmcoldraglayer') - .css(lpos).css({ position:'absolute', 'z-index':2001, - 'background-color':'white', opacity:0.75, - height: (this.frame.offsetHeight-2)+'px', width: (this.frame.offsetWidth-2)+'px' }) - .appendTo(document.body) - // ... and column position indicator - .append($('<div>').attr('id', 'rcmcolumnindicator') - .css({ position:'absolute', 'border-right':'2px dotted #555', - 'z-index':2002, height: (this.frame.offsetHeight-2)+'px' })); - - this.cols = []; - this.list_pos = this.list_min_pos = lpos.left; - // save columns positions - for (i=0; i<cells.length; i++) { - this.cols[i] = cells[i].offsetWidth; - if (this.column_fixed !== null && i <= this.column_fixed) { - this.list_min_pos += this.cols[i]; - } - } - } - - this.col_draglayer.show(); - this.col_drag_active = true; - this.triggerEvent('column_dragstart'); - } - - // set column indicator position - if (this.col_drag_active && this.col_draglayer) { - var i, cpos = 0, pos = rcube_event.get_mouse_pos(e); - - for (i=0; i<this.cols.length; i++) { - if (pos.x >= this.cols[i]/2 + this.list_pos + cpos) - cpos += this.cols[i]; - else - break; - } - - // handle fixed columns on left - if (i == 0 && this.list_min_pos > pos.x) - cpos = this.list_min_pos - this.list_pos; - // empty list needs some assignment - else if (!this.list.rowcount && i == this.cols.length) - cpos -= 2; - $('#rcmcolumnindicator').css({ width: cpos+'px'}); - this.triggerEvent('column_dragmove', e?e:window.event); - } - - this.drag_start = false; - - return false; -}, - - -/** - * Handler for mouse up events for dragging list columns - */ -column_drag_mouse_up: function(e) -{ - document.onmousemove = null; - - if (this.col_draglayer) { - (this.col_draglayer).remove(); - this.col_draglayer = null; - } - - if (this.col_drag_active) - this.focus(); - this.col_drag_active = false; - - rcube_event.remove_listener({event:'mousemove', object:this, method:'column_drag_mouse_move'}); - rcube_event.remove_listener({event:'mouseup', object:this, method:'column_drag_mouse_up'}); - // remove temp divs - this.del_dragfix(); - - if (this.selected_column !== null && this.cols && this.cols.length) { - var i, cpos = 0, pos = rcube_event.get_mouse_pos(e); - - // find destination position - for (i=0; i<this.cols.length; i++) { - if (pos.x >= this.cols[i]/2 + this.list_pos + cpos) - cpos += this.cols[i]; - else - break; - } - - if (i != this.selected_column && i != this.selected_column+1) { - this.column_replace(this.selected_column, i); - } - } - - this.triggerEvent('column_dragend', e); - - return rcube_event.cancel(e); -}, - - -/** - * Returns IDs of all rows in a thread (except root) for specified root - */ -row_children: function(uid) -{ - if (!this.rows[uid] || !this.rows[uid].has_children) - return []; - - var res = [], depth = this.rows[uid].depth, - row = this.rows[uid].obj.nextSibling; - - while (row) { - if (row.nodeType == 1) { - if ((r = this.rows[row.uid])) { - if (!r.depth || r.depth <= depth) - break; - res.push(r.uid); - } - } - row = row.nextSibling; - } - - return res; -}, - - -/** - * Creates a layer for drag&drop over iframes - */ -add_dragfix: function() -{ - $('iframe').each(function() { - $('<div class="iframe-dragdrop-fix"></div>') - .css({background: '#fff', - width: this.offsetWidth+'px', height: this.offsetHeight+'px', - position: 'absolute', opacity: '0.001', zIndex: 1000 - }) - .css($(this).offset()) - .appendTo(document.body); - }); -}, - - -/** - * Removes the layer for drag&drop over iframes - */ -del_dragfix: function() -{ - $('div.iframe-dragdrop-fix').each(function() { this.parentNode.removeChild(this); }); -}, - - -/** - * Replaces two columns - */ -column_replace: function(from, to) -{ - // only supported for <table> lists - if (!this.thead || !this.thead.rows) - return; - - var len, cells = this.thead.rows[0].cells, - elem = cells[from], - before = cells[to], - td = document.createElement('td'); - - // replace header cells - if (before) - cells[0].parentNode.insertBefore(td, before); - else - cells[0].parentNode.appendChild(td); - cells[0].parentNode.replaceChild(elem, td); - - // replace list cells - for (r=0, len=this.tbody.rows.length; r<len; r++) { - row = this.tbody.rows[r]; - - elem = row.cells[from]; - before = row.cells[to]; - td = document.createElement('td'); - - if (before) - row.insertBefore(td, before); - else - row.appendChild(td); - row.replaceChild(elem, td); - } - - // update subject column position - if (this.subject_col == from) - this.subject_col = to > from ? to - 1 : to; - else if (this.subject_col < from && to <= this.subject_col) - this.subject_col++; - else if (this.subject_col > from && to >= this.subject_col) - this.subject_col--; - - if (this.fixed_header) - this.init_header(); - - this.triggerEvent('column_replace'); -} - -}; - -rcube_list_widget.prototype.addEventListener = rcube_event_engine.prototype.addEventListener; -rcube_list_widget.prototype.removeEventListener = rcube_event_engine.prototype.removeEventListener; -rcube_list_widget.prototype.triggerEvent = rcube_event_engine.prototype.triggerEvent; +function rcube_list_widget(a,b){this.ENTER_KEY=13;this.DELETE_KEY=46;this.BACKSPACE_KEY=8;this.list=a?a:null;this.frame=null;this.rows=[];this.selection=[];this.rowcount=0;this.colcount=0;this.subject_col=-1;this.modkey=0;this.multiselect=false;this.multiexpand=false;this.multi_selecting=false;this.draggable=false;this.column_movable=false;this.keyboard=false;this.toggleselect=false;this.dont_select=false;this.drag_active=false;this.col_drag_active=false;this.column_fixed=null;this.last_selected=0;this.shift_start=0;this.in_selection_before=false;this.focused=false;this.drag_mouse_start=null;this.dblclick_time=600;this.row_init=function(){};if(b&&typeof b==="object"){for(var c in b){this[c]=b[c]}}}rcube_list_widget.prototype={init:function(){if(this.list&&this.list.tBodies[0]){this.rows=[];this.rowcount=0;var b,a,c=this.list.tBodies[0].rows;for(b=0,a=c.length;b<a;b++){this.init_row(c[b]);this.rowcount++}this.init_header();this.frame=this.list.parentNode;if(this.keyboard){rcube_event.add_listener({event:"keydown",object:this,method:"key_press"})}}},init_row:function(c){if(c&&String(c.id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i)){var a=this,b=RegExp.$1;c.uid=b;this.rows[b]={uid:b,id:c.id,obj:c};c.onmousedown=function(d){return a.drag_row(d,this.uid)};c.onmouseup=function(d){return a.click_row(d,this.uid)};if(bw.touch){c.addEventListener("touchstart",function(d){if(d.touches.length==1){a.touchmoved=false;a.drag_row(rcube_event.touchevent(d.touches[0]),this.uid)}},false);c.addEventListener("touchend",function(d){if(d.changedTouches.length==1){if(!a.touchmoved&&!a.click_row(rcube_event.touchevent(d.changedTouches[0]),this.uid)){d.preventDefault()}}},false);c.addEventListener("touchmove",function(d){if(d.changedTouches.length==1){a.touchmoved=true;if(a.drag_active){d.preventDefault()}}},false)}if(document.all){c.onselectstart=function(){return false}}this.row_init(this.rows[b])}},init_header:function(){if(this.list&&this.list.tHead){this.colcount=0;var a,b,c=this;if(this.column_movable&&this.list.tHead&&this.list.tHead.rows){for(b=0;b<this.list.tHead.rows[0].cells.length;b++){if(this.column_fixed==b){continue}a=this.list.tHead.rows[0].cells[b];a.onmousedown=function(d){return c.drag_column(d,this)};this.colcount++}}}},clear:function(b){var a=document.createElement("tbody");this.list.insertBefore(a,this.list.tBodies[0]);this.list.removeChild(this.list.tBodies[1]);this.rows=[];this.rowcount=0;if(b){this.clear_selection()}if(this.frame){this.frame.scrollTop=0}},remove_row:function(a,b){var c=this.rows[a]?this.rows[a].obj:null;if(!c){return}c.style.display="none";if(b){this.select_next()}delete this.rows[a];this.rowcount--},insert_row:function(c,a){var b=this.list.tBodies[0];if(a&&b.rows.length){b.insertBefore(c,b.firstChild)}else{b.appendChild(c)}this.init_row(c);this.rowcount++},focus:function(a){var c,b;this.focused=true;for(c in this.selection){b=this.selection[c];if(this.rows[b]&&this.rows[b].obj){$(this.rows[b].obj).addClass("selected").removeClass("unfocused")}}$(":focus:not(body)").blur();window.focus();if(a||(a=window.event)){rcube_event.cancel(a)}},blur:function(){var b,a;this.focused=false;for(b in this.selection){a=this.selection[b];if(this.rows[a]&&this.rows[a].obj){$(this.rows[a].obj).removeClass("selected focused").addClass("unfocused")}}},drag_column:function(c,a){if(this.colcount>1){this.drag_start=true;this.drag_mouse_start=rcube_event.get_mouse_pos(c);rcube_event.add_listener({event:"mousemove",object:this,method:"column_drag_mouse_move"});rcube_event.add_listener({event:"mouseup",object:this,method:"column_drag_mouse_up"});this.add_dragfix();for(var b=0;b<this.list.tHead.rows[0].cells.length;b++){if(a==this.list.tHead.rows[0].cells[b]){this.selected_column=b;break}}}return false},drag_row:function(d,f){var c=rcube_event.get_target(d),b=c.tagName.toLowerCase();if(this.dont_select||(c&&(b=="input"||b=="img"))){return true}if(rcube_event.get_button(d)==2){return true}this.in_selection_before=d&&d.istouch||this.in_selection(f)?f:false;if(!this.in_selection_before){var a=rcube_event.get_modifier(d);this.select_row(f,a,false)}if(this.draggable&&this.selection.length&&this.in_selection(f)){this.drag_start=true;this.drag_mouse_start=rcube_event.get_mouse_pos(d);rcube_event.add_listener({event:"mousemove",object:this,method:"drag_mouse_move"});rcube_event.add_listener({event:"mouseup",object:this,method:"drag_mouse_up"});if(bw.touch){rcube_event.add_listener({event:"touchmove",object:this,method:"drag_mouse_move"});rcube_event.add_listener({event:"touchend",object:this,method:"drag_mouse_up"})}this.add_dragfix()}return false},click_row:function(g,h){var c=new Date().getTime(),b=rcube_event.get_modifier(g),f=rcube_event.get_target(g),d=f.tagName.toLowerCase();if((f&&(d=="input"||d=="img"))){return true}if(this.dont_select){this.dont_select=false;return false}var a=c-this.rows[h].clicked<this.dblclick_time;if(!this.drag_active&&this.in_selection_before==h&&!a){this.select_row(h,b,false)}this.drag_start=false;this.in_selection_before=false;if(this.rows&&a&&this.in_selection(h)){this.triggerEvent("dblclick");c=0}else{this.triggerEvent("click")}if(!this.drag_active){this.del_dragfix();rcube_event.cancel(g)}this.rows[h].clicked=c;return false},find_root:function(a){var b=this.rows[a];if(b&&b.parent_uid){return this.find_root(b.parent_uid)}else{return a}},expand_row:function(c,f){var d=this.rows[f],b=rcube_event.get_target(c),a=rcube_event.get_modifier(c);this.dont_select=true;d.clicked=0;if(d.expanded){b.className="collapsed";if(a==CONTROL_KEY||this.multiexpand){this.collapse_all(d)}else{this.collapse(d)}}else{b.className="expanded";if(a==CONTROL_KEY||this.multiexpand){this.expand_all(d)}else{this.expand(d)}}},collapse:function(d){d.expanded=false;this.triggerEvent("expandcollapse",{uid:d.uid,expanded:d.expanded,obj:d.obj});var c=d.depth;var a=d?d.obj.nextSibling:null;var b;while(a){if(a.nodeType==1){var b=this.rows[a.uid];if(b&&b.depth<=c){break}$(a).css("display","none");if(b.expanded){b.expanded=false;this.triggerEvent("expandcollapse",{uid:b.uid,expanded:b.expanded,obj:a})}}a=a.nextSibling}return false},expand:function(g){var d,e,f,b,a;if(g){g.expanded=true;f=g.depth;b=g.obj.nextSibling;this.update_expando(g.uid,true);this.triggerEvent("expandcollapse",{uid:g.uid,expanded:g.expanded,obj:g.obj})}else{var c=this.list.tBodies[0];b=c.firstChild;f=0;a=0}while(b){if(b.nodeType==1){d=this.rows[b.uid];if(d){if(g&&(!d.depth||d.depth<=f)){break}if(d.parent_uid){e=this.rows[d.parent_uid];if(e&&e.expanded){if((g&&e==g)||a>=e.depth-1){a=e.depth;$(b).css("display","");d.expanded=true;this.triggerEvent("expandcollapse",{uid:d.uid,expanded:d.expanded,obj:b})}}else{if(g&&(!e||e.depth<=f)){break}}}}}b=b.nextSibling}return false},collapse_all:function(d){var c,a,b;if(d){d.expanded=false;c=d.depth;a=d.obj.nextSibling;this.update_expando(d.uid);this.triggerEvent("expandcollapse",{uid:d.uid,expanded:d.expanded,obj:d.obj});if(c&&this.multiexpand){return false}}else{a=this.list.tBodies[0].firstChild;c=0}while(a){if(a.nodeType==1){if(b=this.rows[a.uid]){if(d&&(!b.depth||b.depth<=c)){break}if(d||b.depth){$(a).css("display","none")}if(b.has_children&&b.expanded){b.expanded=false;this.update_expando(b.uid,false);this.triggerEvent("expandcollapse",{uid:b.uid,expanded:b.expanded,obj:a})}}}a=a.nextSibling}return false},expand_all:function(d){var c,a,b;if(d){d.expanded=true;c=d.depth;a=d.obj.nextSibling;this.update_expando(d.uid,true);this.triggerEvent("expandcollapse",{uid:d.uid,expanded:d.expanded,obj:d.obj})}else{a=this.list.tBodies[0].firstChild;c=0}while(a){if(a.nodeType==1){if(b=this.rows[a.uid]){if(d&&b.depth<=c){break}$(a).css("display","");if(b.has_children&&!b.expanded){b.expanded=true;this.update_expando(b.uid,true);this.triggerEvent("expandcollapse",{uid:b.uid,expanded:b.expanded,obj:a})}}}a=a.nextSibling}return false},update_expando:function(b,a){var c=document.getElementById("rcmexpando"+b);if(c){c.className=a?"expanded":"collapsed"}},get_next_row:function(){if(!this.rows){return false}var b=this.rows[this.last_selected],a=b?b.obj.nextSibling:null;while(a&&(a.nodeType!=1||a.style.display=="none")){a=a.nextSibling}return a},get_prev_row:function(){if(!this.rows){return false}var b=this.rows[this.last_selected],a=b?b.obj.previousSibling:null;while(a&&(a.nodeType!=1||a.style.display=="none")){a=a.previousSibling}return a},get_first_row:function(){if(this.rowcount){var b,a,c=this.list.tBodies[0].rows;for(b=0,a=c.length-1;b<a;b++){if(c[b].id&&String(c[b].id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i)&&this.rows[RegExp.$1]!=null){return RegExp.$1}}}return null},get_last_row:function(){if(this.rowcount){var a,b=this.list.tBodies[0].rows;for(a=b.length-1;a>=0;a--){if(b[a].id&&String(b[a].id).match(/^rcmrow([a-z0-9\-_=\+\/]+)/i)&&this.rows[RegExp.$1]!=null){return RegExp.$1}}}return null},select_row:function(d,a,c){var b=this.selection.join(",");if(!this.multiselect){a=0}if(!this.shift_start){this.shift_start=d}if(!a){this.shift_start=d;this.highlight_row(d,false);this.multi_selecting=false}else{switch(a){case SHIFT_KEY:this.shift_select(d,false);break;case CONTROL_KEY:if(!c){this.highlight_row(d,true)}break;case CONTROL_SHIFT_KEY:this.shift_select(d,true);break;default:this.highlight_row(d,false);break}this.multi_selecting=true}if(this.selection.join(",")!=b){this.triggerEvent("select")}if(this.last_selected!=0&&this.rows[this.last_selected]){$(this.rows[this.last_selected].obj).removeClass("focused")}if(this.toggleselect&&this.last_selected==d){this.clear_selection();d=null}else{$(this.rows[d].obj).addClass("focused")}if(!this.selection.length){this.shift_start=null}this.last_selected=d},select:function(a){this.select_row(a,false);this.scrollto(a)},select_next:function(){var b=this.get_next_row(),c=this.get_prev_row(),a=(b)?b:c;if(a){this.select_row(a.uid,false,false)}},select_first:function(a){var b=this.get_first_row();if(b){if(a){this.shift_select(b,a);this.triggerEvent("select");this.scrollto(b)}else{this.select(b)}}},select_last:function(a){var b=this.get_last_row();if(b){if(a){this.shift_select(b,a);this.triggerEvent("select");this.scrollto(b)}else{this.select(b)}}},select_children:function(d){var c,b=this.row_children(d),a=b.length;for(c=0;c<a;c++){if(!this.in_selection(b[c])){this.select_row(b[c],CONTROL_KEY)}}},shift_select:function(h,f){if(!this.rows[this.shift_start]||!this.selection.length){this.shift_start=h}var g,d,c,a=this.rows[h],e=this.rows[this.shift_start].obj.rowIndex,b=a.obj.rowIndex;if(!a.expanded&&a.has_children){if(a=this.rows[(this.row_children(h)).pop()]){b=a.obj.rowIndex}}d=((e<b)?e:b),c=((e>b)?e:b);for(g in this.rows){if(this.rows[g].obj.rowIndex>=d&&this.rows[g].obj.rowIndex<=c){if(!this.in_selection(g)){this.highlight_row(g,true)}}else{if(this.in_selection(g)&&!f){this.highlight_row(g,true)}}}},in_selection:function(b){for(var a in this.selection){if(this.selection[a]==b){return true}}return false},select_all:function(b){if(!this.rows||!this.rows.length){return false}var c,a=this.selection.join(",");this.selection=[];for(c in this.rows){if(!b||this.rows[c][b]==true){this.last_selected=c;this.highlight_row(c,true,true)}else{$(this.rows[c].obj).removeClass("selected").removeClass("unfocused")}}if(this.selection.join(",")!=a){this.triggerEvent("select")}this.focus();return true},invert_selection:function(){if(!this.rows||!this.rows.length){return false}var b,a=this.selection.join(",");for(b in this.rows){this.highlight_row(b,true)}if(this.selection.join(",")!=a){this.triggerEvent("select")}this.focus();return true},clear_selection:function(c){var b,a=this.selection.length;if(c){for(b in this.selection){if(this.selection[b]==c){this.selection.splice(b,1);break}}}else{for(b in this.selection){if(this.rows[this.selection[b]]){$(this.rows[this.selection[b]].obj).removeClass("selected").removeClass("unfocused")}}this.selection=[]}if(a&&!this.selection.length){this.triggerEvent("select")}},get_selection:function(){return this.selection},get_single_selection:function(){if(this.selection.length==1){return this.selection[0]}else{return null}},highlight_row:function(f,a,e){if(!this.rows[f]){return}if(!a){if(this.selection.length>1||!this.in_selection(f)){this.clear_selection();this.selection[0]=f;$(this.rows[f].obj).addClass("selected")}}else{if(!this.in_selection(f)){this.selection.push(f);$(this.rows[f].obj).addClass("selected");if(!e&&!this.rows[f].expanded){this.highlight_children(f,true)}}else{var d=$.inArray(f,this.selection),c=this.selection.slice(0,d),b=this.selection.slice(d+1,this.selection.length);this.selection=c.concat(b);$(this.rows[f].obj).removeClass("selected").removeClass("unfocused");if(!e&&!this.rows[f].expanded){this.highlight_children(f,false)}}}},highlight_children:function(f,b){var d,e,c=this.row_children(f),a=c.length;for(d=0;d<a;d++){e=this.in_selection(c[d]);if((b&&!e)||(!b&&e)){this.highlight_row(c[d],true,true)}}},key_press:function(f){var d=f.target||{};if(this.focused!=true||d.nodeName=="INPUT"||d.nodeName=="TEXTAREA"||d.nodeName=="SELECT"){return true}var c=rcube_event.get_keycode(f),a=rcube_event.get_modifier(f);switch(c){case 40:case 38:case 63233:case 63232:rcube_event.cancel(f);return this.use_arrow_key(c,a);case 61:case 107:case 109:case 32:rcube_event.cancel(f);var b=this.use_plusminus_key(c,a);this.key_pressed=c;this.modkey=a;this.triggerEvent("keypress");this.modkey=0;return b;case 36:this.select_first(a);return rcube_event.cancel(f);case 35:this.select_last(a);return rcube_event.cancel(f);case 27:if(this.drag_active){return this.drag_mouse_up(f)}if(this.col_drag_active){this.selected_column=null;return this.column_drag_mouse_up(f)}return rcube_event.cancel(f);default:this.key_pressed=c;this.modkey=a;this.triggerEvent("keypress");this.modkey=0;if(this.key_pressed==this.BACKSPACE_KEY){return rcube_event.cancel(f)}}return true},use_arrow_key:function(c,b){var a;if(c==40||c==63233){a=this.get_next_row()}else{if(c==38||c==63232){a=this.get_prev_row()}}if(a){this.select_row(a.uid,b,false);this.scrollto(a.uid)}return false},use_plusminus_key:function(c,a){var b=this.rows[this.last_selected];if(!b){return}if(c==32){c=b.expanded?109:61}if(c==61||c==107){if(a==CONTROL_KEY||this.multiexpand){this.expand_all(b)}else{this.expand(b)}}else{if(a==CONTROL_KEY||this.multiexpand){this.collapse_all(b)}else{this.collapse(b)}}this.update_expando(b.uid,b.expanded);return false},scrollto:function(d){var c=this.rows[d].obj;if(c&&this.frame){var b=Number(c.offsetTop);if(!b&&this.rows[d].parent_uid){var a=this.find_root(this.rows[d].uid);this.expand_all(this.rows[a]);b=Number(c.offsetTop)}if(b<Number(this.frame.scrollTop)){this.frame.scrollTop=b}else{if(b+Number(c.offsetHeight)>Number(this.frame.scrollTop)+Number(this.frame.offsetHeight)){this.frame.scrollTop=(b+Number(c.offsetHeight))-Number(this.frame.offsetHeight)}}}},drag_mouse_move:function(l){if(l.type=="touchmove"){if(l.touches.length==1&&l.changedTouches.length==1){l=rcube_event.touchevent(l.changedTouches[0])}else{return rcube_event.cancel(l)}}if(this.drag_start){var f=rcube_event.get_mouse_pos(l);if(!this.drag_mouse_start||(Math.abs(f.x-this.drag_mouse_start.x)<3&&Math.abs(f.y-this.drag_mouse_start.y)<3)){return false}if(!this.draglayer){this.draglayer=$("<div>").attr("id","rcmdraglayer").css({position:"absolute",display:"none","z-index":2000}).appendTo(document.body)}var b,j,t=$.merge([],this.selection);for(b in t){j=t[b];if(!this.rows[j].expanded){this.select_children(j)}}this.draglayer.html("");var o,h,b,p,g;for(b=0;b<this.selection.length;b++){if(b>12){this.draglayer.append("...");break}if(g=this.rows[this.selection[b]].obj){p="";for(o=0,h=0;h<g.childNodes.length;h++){if(g.childNodes[h].nodeName=="TD"){if(b==0){this.drag_start_pos=$(g.childNodes[h]).offset()}if(this.subject_col<0||(this.subject_col>=0&&this.subject_col==o)){var s,d,k,a=g.childNodes[h].childNodes;for(f=0;f<a.length;f++){if((k=g.childNodes[h].childNodes[f])&&(k.nodeType==3||k.nodeName=="A")){d=k}}if(!d){break}p=$(d).text();p=$.trim(p);p=(p.length>50?p.substring(0,50)+"...":p);s=$("<div>").text(p);this.draglayer.append(s);break}o++}}}}this.draglayer.show();this.drag_active=true;this.triggerEvent("dragstart")}if(this.drag_active&&this.draglayer){var q=rcube_event.get_mouse_pos(l);this.draglayer.css({left:(q.x+20)+"px",top:(q.y-5+(bw.ie?document.documentElement.scrollTop:0))+"px"});this.triggerEvent("dragmove",l?l:window.event)}this.drag_start=false;return false},drag_mouse_up:function(a){document.onmousemove=null;if(a.type=="touchend"){if(a.changedTouches.length!=1){return rcube_event.cancel(a)}}if(this.draglayer&&this.draglayer.is(":visible")){if(this.drag_start_pos){this.draglayer.animate(this.drag_start_pos,300,"swing").hide(20)}else{this.draglayer.hide()}}if(this.drag_active){this.focus()}this.drag_active=false;rcube_event.remove_listener({event:"mousemove",object:this,method:"drag_mouse_move"});rcube_event.remove_listener({event:"mouseup",object:this,method:"drag_mouse_up"});if(bw.touch){rcube_event.remove_listener({event:"touchmove",object:this,method:"drag_mouse_move"});rcube_event.remove_listener({event:"touchend",object:this,method:"drag_mouse_up"})}this.del_dragfix();this.triggerEvent("dragend");return rcube_event.cancel(a)},column_drag_mouse_move:function(f){if(this.drag_start){var c,a=rcube_event.get_mouse_pos(f);if(!this.drag_mouse_start||(Math.abs(a.x-this.drag_mouse_start.x)<3&&Math.abs(a.y-this.drag_mouse_start.y)<3)){return false}if(!this.col_draglayer){var d=$(this.list).offset(),b=this.list.tHead.rows[0].cells;this.col_draglayer=$("<div>").attr("id","rcmcoldraglayer").css(d).css({position:"absolute","z-index":2001,"background-color":"white",opacity:0.75,height:(this.frame.offsetHeight-2)+"px",width:(this.frame.offsetWidth-2)+"px"}).appendTo(document.body).append($("<div>").attr("id","rcmcolumnindicator").css({position:"absolute","border-right":"2px dotted #555","z-index":2002,height:(this.frame.offsetHeight-2)+"px"}));this.cols=[];this.list_pos=this.list_min_pos=d.left;for(c=0;c<b.length;c++){this.cols[c]=b[c].offsetWidth;if(this.column_fixed!==null&&c<=this.column_fixed){this.list_min_pos+=this.cols[c]}}}this.col_draglayer.show();this.col_drag_active=true;this.triggerEvent("column_dragstart")}if(this.col_drag_active&&this.col_draglayer){var c,h=0,g=rcube_event.get_mouse_pos(f);for(c=0;c<this.cols.length;c++){if(g.x>=this.cols[c]/2+this.list_pos+h){h+=this.cols[c]}else{break}}if(c==0&&this.list_min_pos>g.x){h=this.list_min_pos-this.list_pos}else{if(!this.list.rowcount&&c==this.cols.length){h-=2}}$("#rcmcolumnindicator").css({width:h+"px"});this.triggerEvent("column_dragmove",f?f:window.event)}this.drag_start=false;return false},column_drag_mouse_up:function(b){document.onmousemove=null;if(this.col_draglayer){(this.col_draglayer).remove();this.col_draglayer=null}if(this.col_drag_active){this.focus()}this.col_drag_active=false;rcube_event.remove_listener({event:"mousemove",object:this,method:"column_drag_mouse_move"});rcube_event.remove_listener({event:"mouseup",object:this,method:"column_drag_mouse_up"});this.del_dragfix();if(this.selected_column!==null&&this.cols&&this.cols.length){var a,d=0,c=rcube_event.get_mouse_pos(b);for(a=0;a<this.cols.length;a++){if(c.x>=this.cols[a]/2+this.list_pos+d){d+=this.cols[a]}else{break}}if(a!=this.selected_column&&a!=this.selected_column+1){this.column_replace(this.selected_column,a)}}this.triggerEvent("column_dragend");return rcube_event.cancel(b)},row_children:function(b){if(!this.rows[b]||!this.rows[b].has_children){return[]}var a=[],d=this.rows[b].depth,c=this.rows[b].obj.nextSibling;while(c){if(c.nodeType==1){if((r=this.rows[c.uid])){if(!r.depth||r.depth<=d){break}a.push(r.uid)}}c=c.nextSibling}return a},add_dragfix:function(){$("iframe").each(function(){$('<div class="iframe-dragdrop-fix"></div>').css({background:"#fff",width:this.offsetWidth+"px",height:this.offsetHeight+"px",position:"absolute",opacity:"0.001",zIndex:1000}).css($(this).offset()).appendTo(document.body)})},del_dragfix:function(){$("div.iframe-dragdrop-fix").each(function(){this.parentNode.removeChild(this)})},column_replace:function(g,f){var a,b=this.list.tHead.rows[0].cells,c=b[g],d=b[f],e=document.createElement("td");if(d){b[0].parentNode.insertBefore(e,d)}else{b[0].parentNode.appendChild(e)}b[0].parentNode.replaceChild(c,e);for(r=0,a=this.list.tBodies[0].rows.length;r<a;r++){row=this.list.tBodies[0].rows[r];c=row.cells[g];d=row.cells[f];e=document.createElement("td");if(d){row.insertBefore(e,d)}else{row.appendChild(e)}row.replaceChild(c,e)}if(this.subject_col==g){this.subject_col=f>g?f-1:f}else{if(this.subject_col<g&&f<=this.subject_col){this.subject_col++}else{if(this.subject_col>g&&f>=this.subject_col){this.subject_col--}}}this.triggerEvent("column_replace")}};rcube_list_widget.prototype.addEventListener=rcube_event_engine.prototype.addEventListener;rcube_list_widget.prototype.removeEventListener=rcube_event_engine.prototype.removeEventListener;rcube_list_widget.prototype.triggerEvent=rcube_event_engine.prototype.triggerEvent;
\ No newline at end of file |