Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

functions.js 29KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070
  1. /**
  2. * Roundcube functions for default skin interface
  3. *
  4. * @licstart The following is the entire license notice for the
  5. * JavaScript code in this file.
  6. *
  7. * Copyright (c) 2006-2014, The Roundcube Dev Team
  8. *
  9. * The JavaScript code in this page is free software: you can redistribute it
  10. * and/or modify it under the terms of the GNU General Public License
  11. * as published by the Free Software Foundation, either version 3 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * @licend The above is the entire license notice
  15. * for the JavaScript code in this file.
  16. */
  17. /**
  18. * Settings
  19. */
  20. function rcube_init_settings_tabs()
  21. {
  22. var el, cl, container = $('#tabsbar'),
  23. last_tab = $('span:last', container),
  24. tab = '#settingstabpreferences',
  25. action = window.rcmail && rcmail.env.action ? rcmail.env.action : null;
  26. // move About tab to the end
  27. if (last_tab && last_tab.attr('id') != 'settingstababout' && (el = $('#settingstababout'))) {
  28. cl = el.clone(true);
  29. el.remove();
  30. last_tab.after(cl);
  31. }
  32. // get selected tab
  33. if (action)
  34. tab = '#settingstab' + (action.indexOf('identity')>0 ? 'identities' : action.replace(/\./g, ''));
  35. $(tab).addClass('tablink-selected');
  36. $('a', tab).removeAttr('onclick').click(function() { return false; });
  37. }
  38. // Fieldsets-to-tabs converter
  39. // Warning: don't place "caller" <script> inside page element (id)
  40. function rcube_init_tabs(id, current)
  41. {
  42. var content = $('#'+id),
  43. fs = content.children('fieldset');
  44. if (!fs.length)
  45. return;
  46. current = current ? current : 0;
  47. // first hide not selected tabs
  48. fs.each(function(idx) { if (idx != current) $(this).hide(); });
  49. // create tabs container
  50. var tabs = $('<div>').addClass('tabsbar').appendTo(content);
  51. // convert fildsets into tabs
  52. fs.each(function(idx) {
  53. var tab, a, elm = $(this), legend = elm.children('legend');
  54. // create a tab
  55. a = $('<a>').text(legend.text()).attr('href', '#');
  56. tab = $('<span>').attr({'id': 'tab'+idx, 'class': 'tablink'})
  57. .click(function() { rcube_show_tab(id, idx); return false })
  58. // remove legend
  59. legend.remove();
  60. // style fieldset
  61. elm.addClass('tabbed');
  62. // style selected tab
  63. if (idx == current)
  64. tab.addClass('tablink-selected');
  65. // add the tab to container
  66. tab.append(a).appendTo(tabs);
  67. });
  68. }
  69. function rcube_show_tab(id, index)
  70. {
  71. var fs = $('#'+id).children('fieldset');
  72. fs.each(function(idx) {
  73. // Show/hide fieldset (tab content)
  74. $(this)[index==idx ? 'show' : 'hide']();
  75. // Select/unselect tab
  76. $('#tab'+idx).toggleClass('tablink-selected', idx==index);
  77. });
  78. }
  79. /**
  80. * Mail UI
  81. */
  82. function rcube_mail_ui()
  83. {
  84. this.popups = {
  85. markmenu: {id:'markmessagemenu'},
  86. replyallmenu: {id:'replyallmenu'},
  87. forwardmenu: {id:'forwardmenu', editable:1},
  88. searchmenu: {id:'searchmenu', editable:1},
  89. messagemenu: {id:'messagemenu'},
  90. attachmentmenu: {id:'attachmentmenu'},
  91. dragmenu: {id:'dragmenu', sticky:1},
  92. groupmenu: {id:'groupoptionsmenu', above:1},
  93. mailboxmenu: {id:'mailboxoptionsmenu', above:1},
  94. composemenu: {id:'composeoptionsmenu', editable:1, overlap:1},
  95. spellmenu: {id:'spellmenu'},
  96. responsesmenu: {id:'responsesmenu'},
  97. // toggle: #1486823, #1486930
  98. uploadmenu: {id:'attachment-form', editable:1, above:1, toggle:!bw.ie&&!bw.linux },
  99. uploadform: {id:'upload-form', editable:1, toggle:!bw.ie&&!bw.linux }
  100. };
  101. var obj;
  102. for (var k in this.popups) {
  103. obj = $('#'+this.popups[k].id)
  104. if (obj.length)
  105. this.popups[k].obj = obj;
  106. else {
  107. delete this.popups[k];
  108. }
  109. }
  110. }
  111. rcube_mail_ui.prototype = {
  112. show_popup: function(popup, show, config)
  113. {
  114. var obj;
  115. // auto-register menu object
  116. if (!this.popups[popup] && (obj = $('#'+popup)) && obj.length)
  117. this.popups[popup] = $.extend(config, {id: popup, obj: obj});
  118. if (typeof this[popup] == 'function')
  119. return this[popup](show);
  120. else
  121. return this.show_popupmenu(popup, show);
  122. },
  123. show_popupmenu: function(popup, show)
  124. {
  125. var obj = this.popups[popup].obj,
  126. above = this.popups[popup].above,
  127. ref = $(this.popups[popup].link ? this.popups[popup].link : rcube_find_object(popup+'link'));
  128. if (typeof show == 'undefined')
  129. show = obj.is(':visible') ? false : true;
  130. else if (this.popups[popup].toggle && show && this.popups[popup].obj.is(':visible') )
  131. show = false;
  132. if (show && ref.length) {
  133. var parent = ref.parent(),
  134. win = $(window),
  135. pos = parent.hasClass('dropbutton') ? parent.offset() : ref.offset();
  136. if (!above && pos.top + ref.height() + obj.height() > win.height())
  137. above = true;
  138. if (pos.left + obj.width() > win.width())
  139. pos.left = win.width() - obj.width() - 30;
  140. obj.css({ left:pos.left, top:(pos.top + (above ? -obj.height() : ref.height())) });
  141. }
  142. obj[show?'show':'hide']();
  143. },
  144. dragmenu: function(show)
  145. {
  146. this.popups.dragmenu.obj[show?'show':'hide']();
  147. },
  148. forwardmenu: function(show)
  149. {
  150. $("input[name='forwardtype'][value="+(rcmail.env.forward_attachment ? 1 : 0)+"]", this.popups.forwardmenu.obj)
  151. .prop('checked', true);
  152. this.show_popupmenu('forwardmenu', show);
  153. },
  154. uploadmenu: function(show)
  155. {
  156. if (typeof show == 'object') // called as event handler
  157. show = false;
  158. // clear upload form
  159. if (!show) {
  160. try { $('#attachment-form form')[0].reset(); }
  161. catch(e){} // ignore errors
  162. }
  163. if (rcmail.mailvelope_editor)
  164. return;
  165. this.show_popupmenu('uploadmenu', show);
  166. if (!document.all && this.popups.uploadmenu.obj.is(':visible'))
  167. $('#attachment-form input[type=file]').click();
  168. },
  169. searchmenu: function(show)
  170. {
  171. var obj = this.popups.searchmenu.obj,
  172. ref = rcube_find_object('searchmenulink');
  173. if (typeof show == 'undefined')
  174. show = obj.is(':visible') ? false : true;
  175. if (show && ref) {
  176. var pos = $(ref).offset();
  177. obj.css({left:pos.left, top:(pos.top + ref.offsetHeight + 2)});
  178. if (rcmail.env.search_mods) {
  179. var n, all,
  180. list = $('input:checkbox[name="s_mods[]"]', obj),
  181. mbox = rcmail.env.mailbox,
  182. mods = rcmail.env.search_mods,
  183. scope = rcmail.env.search_scope || 'base';
  184. if (rcmail.env.task == 'mail') {
  185. mods = mods[mbox] ? mods[mbox] : mods['*'];
  186. all = 'text';
  187. $('input:radio[name="s_scope"]').prop('checked', false).filter('#s_scope_'+scope).prop('checked', true);
  188. }
  189. else {
  190. all = '*';
  191. }
  192. if (mods[all])
  193. list.map(function() {
  194. this.checked = true;
  195. this.disabled = this.value != all;
  196. });
  197. else {
  198. list.prop('disabled', false).prop('checked', false);
  199. for (n in mods)
  200. $('#s_mod_' + n).prop('checked', true);
  201. }
  202. }
  203. }
  204. obj[show?'show':'hide']();
  205. },
  206. set_searchmod: function(elem)
  207. {
  208. var all, m, task = rcmail.env.task,
  209. mods = rcmail.env.search_mods,
  210. mbox = rcmail.env.mailbox,
  211. scope = $('input[name="s_scope"]:checked').val();
  212. if (scope == 'all')
  213. mbox = '*';
  214. if (!mods)
  215. mods = {};
  216. if (task == 'mail') {
  217. if (!mods[mbox])
  218. mods[mbox] = rcube_clone_object(mods['*']);
  219. m = mods[mbox];
  220. all = 'text';
  221. }
  222. else { //addressbook
  223. m = mods;
  224. all = '*';
  225. }
  226. if (!elem.checked)
  227. delete(m[elem.value]);
  228. else
  229. m[elem.value] = 1;
  230. // mark all fields
  231. if (elem.value == all) {
  232. $('input:checkbox[name="s_mods[]"]').map(function() {
  233. if (this == elem)
  234. return;
  235. this.checked = true;
  236. if (elem.checked) {
  237. this.disabled = true;
  238. delete m[this.value];
  239. }
  240. else {
  241. this.disabled = false;
  242. m[this.value] = 1;
  243. }
  244. });
  245. }
  246. rcmail.set_searchmods(m);
  247. },
  248. show_listmenu: function(p)
  249. {
  250. var self = this, buttons = {}, $dialog = $('#listmenu');
  251. // close the dialog
  252. if ($dialog.is(':visible')) {
  253. $dialog.dialog('close', p.originalEvent);
  254. return;
  255. }
  256. // set form values
  257. $('input[name="sort_col"][value="'+rcmail.env.sort_col+'"]').prop('checked', true);
  258. $('input[name="sort_ord"][value="DESC"]').prop('checked', rcmail.env.sort_order == 'DESC');
  259. $('input[name="sort_ord"][value="ASC"]').prop('checked', rcmail.env.sort_order != 'DESC');
  260. $('input[name="view"][value="thread"]').prop('checked', rcmail.env.threading ? true : false);
  261. $('input[name="view"][value="list"]').prop('checked', rcmail.env.threading ? false : true);
  262. // set checkboxes
  263. $('input[name="list_col[]"]').each(function() {
  264. $(this).prop('checked', $.inArray(this.value, rcmail.env.listcols) != -1);
  265. });
  266. buttons[rcmail.gettext('save')] = function(e) {
  267. $dialog.dialog('close', e);
  268. self.save_listmenu();
  269. };
  270. $dialog.dialog({
  271. modal: true,
  272. resizable: false,
  273. closeOnEscape: true,
  274. title: null,
  275. open: function(e) {
  276. var maxheight = 0;
  277. $('#listmenu fieldset').each(function() {
  278. var height = $(this).height();
  279. if (height > maxheight) {
  280. maxheight = height;
  281. }
  282. }).css("min-height", maxheight+"px").height(maxheight);
  283. setTimeout(function() { $dialog.find('a, input:not(:disabled)').not('[aria-disabled=true]').first().focus(); }, 100);
  284. },
  285. close: function(e) {
  286. $dialog.dialog('destroy').hide();
  287. if (e.originalEvent && rcube_event.is_keyboard(e.originalEvent))
  288. $('#listmenulink').focus();
  289. },
  290. buttons: buttons,
  291. minWidth: 500,
  292. width: $dialog.width()+20
  293. }).show();
  294. },
  295. save_listmenu: function()
  296. {
  297. var sort = $('input[name="sort_col"]:checked').val(),
  298. ord = $('input[name="sort_ord"]:checked').val(),
  299. thread = $('input[name="view"]:checked').val(),
  300. cols = $('input[name="list_col[]"]:checked')
  301. .map(function(){ return this.value; }).get();
  302. rcmail.set_list_options(cols, sort, ord, thread == 'thread' ? 1 : 0);
  303. },
  304. spellmenu: function(show)
  305. {
  306. var link, li,
  307. lang = rcmail.spellcheck_lang(),
  308. menu = this.popups.spellmenu.obj,
  309. ul = $('ul', menu);
  310. if (!ul.length) {
  311. ul = $('<ul>');
  312. for (i in rcmail.env.spell_langs) {
  313. li = $('<li>');
  314. link = $('<a href="#"></a>').text(rcmail.env.spell_langs[i])
  315. .addClass('active').data('lang', i)
  316. .click(function() {
  317. rcmail.spellcheck_lang_set($(this).data('lang'));
  318. });
  319. link.appendTo(li);
  320. li.appendTo(ul);
  321. }
  322. ul.appendTo(menu);
  323. }
  324. // select current language
  325. $('li', ul).each(function() {
  326. var el = $('a', this);
  327. if (el.data('lang') == lang)
  328. el.addClass('selected');
  329. else if (el.hasClass('selected'))
  330. el.removeClass('selected');
  331. });
  332. this.show_popupmenu('spellmenu', show);
  333. },
  334. show_attachmentmenu: function(elem, event)
  335. {
  336. var id = elem.parentNode.id.replace(/^attach/, '');
  337. $('#attachmenuopen').off('click').attr('onclick', '').click(function(e) {
  338. return rcmail.command('open-attachment', id, this);
  339. });
  340. $('#attachmenudownload').off('click').attr('onclick', '').click(function() {
  341. rcmail.command('download-attachment', id, this);
  342. });
  343. this.popups.attachmentmenu.link = elem;
  344. rcmail.command('menu-open', {menu: 'attachmentmenu', id: id}, elem, event);
  345. },
  346. menu_open: function(p)
  347. {
  348. if (p && p.name == 'messagelistmenu')
  349. this.show_listmenu();
  350. },
  351. body_mouseup: function(e)
  352. {
  353. var target = e.target; ref = this;
  354. $.each(this.popups, function(i, popup) {
  355. if (popup.obj.is(':visible') && target != rcube_find_object(i + 'link')
  356. && !popup.toggle
  357. && target != popup.obj.get(0) // check if scroll bar was clicked (#1489832)
  358. && (!popup.editable || !ref.target_overlaps(target, popup.id))
  359. && (!popup.sticky || !rcube_mouse_is_over(e, rcube_find_object(popup.id)))
  360. && !$(target).is('.folder-selector-link') && !$(target).children('.folder-selector-link').length
  361. ) {
  362. window.setTimeout('rcmail_ui.show_popup("'+i+'",false);', 50);
  363. }
  364. });
  365. },
  366. target_overlaps: function (target, elementid)
  367. {
  368. var element = rcube_find_object(elementid);
  369. while (target.parentNode) {
  370. if (target.parentNode == element)
  371. return true;
  372. target = target.parentNode;
  373. }
  374. return false;
  375. },
  376. body_keydown: function(e)
  377. {
  378. if (e.keyCode == 27) {
  379. for (var k in this.popups) {
  380. if (this.popups[k].obj.is(':visible'))
  381. this.show_popup(k, false);
  382. }
  383. }
  384. },
  385. switch_preview_pane: function(elem)
  386. {
  387. var uid, prev_frm = $('#mailpreviewframe');
  388. if (elem.checked) {
  389. rcmail.env.contentframe = 'messagecontframe';
  390. if (mailviewsplit.layer) {
  391. mailviewsplit.resize();
  392. mailviewsplit.layer.elm.style.display = '';
  393. }
  394. else
  395. mailviewsplit.init();
  396. if (bw.opera) {
  397. $('#messagelistcontainer').css({height: ''});
  398. }
  399. prev_frm.show();
  400. if (uid = rcmail.message_list.get_single_selection())
  401. rcmail.show_message(uid, false, true);
  402. }
  403. else {
  404. prev_frm.hide();
  405. if (bw.ie7) {
  406. var fr = document.getElementById('mailcontframe');
  407. fr.style.bottom = 0;
  408. fr.style.height = parseInt(fr.parentNode.offsetHeight)+'px';
  409. }
  410. else {
  411. $('#mailcontframe').css({height: 'auto', bottom: 0});
  412. if (bw.opera)
  413. $('#messagelistcontainer').css({height: 'auto'});
  414. }
  415. if (mailviewsplit.layer)
  416. mailviewsplit.layer.elm.style.display = 'none';
  417. rcmail.env.contentframe = null;
  418. rcmail.show_contentframe(false);
  419. }
  420. rcmail.command('save-pref', {name: 'preview_pane', value: (elem.checked?1:0)});
  421. },
  422. /* Message composing */
  423. init_compose_form: function()
  424. {
  425. var f, v, field, fields = ['cc', 'bcc', 'replyto', 'followupto'],
  426. div = document.getElementById('compose-div'),
  427. headers_div = document.getElementById('compose-headers-div');
  428. // Show input elements with non-empty value
  429. for (f=0; f<fields.length; f++) {
  430. v = fields[f]; field = $('#_'+v);
  431. if (field.length) {
  432. field.on('change', {v:v}, function(e) { if (this.value) rcmail_ui.show_header_form(e.data.v); });
  433. if (field.val() != '')
  434. rcmail_ui.show_header_form(v);
  435. }
  436. }
  437. // prevent from form data loss when pressing ESC key in IE
  438. if (bw.ie) {
  439. var form = rcube_find_object('form');
  440. form.onkeydown = function (e) {
  441. if (rcube_event.get_keycode(e) == 27)
  442. rcube_event.cancel(e);
  443. };
  444. }
  445. $(window).resize(function() {
  446. rcmail_ui.resize_compose_body();
  447. });
  448. $('#compose-container').resize(function() {
  449. rcmail_ui.resize_compose_body();
  450. });
  451. div.style.top = (parseInt(headers_div.offsetHeight, 10) + 3) + 'px';
  452. $(window).resize();
  453. // fixes contacts-table position when there's more than one addressbook
  454. $('#contacts-table').css('top', $('#directorylist').height() + 24 + 'px');
  455. // contacts search submit
  456. $('#quicksearchbox').keydown(function(e) {
  457. if (rcube_event.get_keycode(e) == 13)
  458. rcmail.command('search');
  459. });
  460. },
  461. resize_compose_body: function()
  462. {
  463. var div = $('#compose-div .boxlistcontent'),
  464. w = div.width() - 6,
  465. h = div.height() - 2,
  466. x = bw.ie || bw.opera ? 4 : 0;
  467. $('#compose-body_ifr').width(w + 6).height(h - 1 - $('div.mce-toolbar').height());
  468. $('#compose-body').width(w-x).height(h);
  469. $('#googie_edit_layer').width(w).height(h);
  470. },
  471. resize_compose_body_ev: function()
  472. {
  473. window.setTimeout(function(){rcmail_ui.resize_compose_body();}, 100);
  474. },
  475. show_header_form: function(id)
  476. {
  477. var row, s,
  478. link = document.getElementById(id + '-link');
  479. if ((s = this.next_sibling(link)))
  480. s.style.display = 'none';
  481. else if ((s = this.prev_sibling(link)))
  482. s.style.display = 'none';
  483. link.style.display = 'none';
  484. if ((row = document.getElementById('compose-' + id))) {
  485. var div = document.getElementById('compose-div'),
  486. headers_div = document.getElementById('compose-headers-div');
  487. $(row).show();
  488. div.style.top = (parseInt(headers_div.offsetHeight, 10) + 3) + 'px';
  489. this.resize_compose_body();
  490. }
  491. return false;
  492. },
  493. hide_header_form: function(id)
  494. {
  495. var row, ns,
  496. link = document.getElementById(id + '-link'),
  497. parent = link.parentNode,
  498. links = parent.getElementsByTagName('a');
  499. link.style.display = '';
  500. for (var i=0; i<links.length; i++)
  501. if (links[i].style.display != 'none')
  502. for (var j=i+1; j<links.length; j++)
  503. if (links[j].style.display != 'none')
  504. if ((ns = this.next_sibling(links[i]))) {
  505. ns.style.display = '';
  506. break;
  507. }
  508. document.getElementById('_' + id).value = '';
  509. if ((row = document.getElementById('compose-' + id))) {
  510. var div = document.getElementById('compose-div'),
  511. headers_div = document.getElementById('compose-headers-div');
  512. row.style.display = 'none';
  513. div.style.top = (parseInt(headers_div.offsetHeight, 10) + 1) + 'px';
  514. this.resize_compose_body();
  515. }
  516. return false;
  517. },
  518. next_sibling: function(elm)
  519. {
  520. var ns = elm.nextSibling;
  521. while (ns && ns.nodeType == 3)
  522. ns = ns.nextSibling;
  523. return ns;
  524. },
  525. prev_sibling: function(elm)
  526. {
  527. var ps = elm.previousSibling;
  528. while (ps && ps.nodeType == 3)
  529. ps = ps.previousSibling;
  530. return ps;
  531. },
  532. enable_command: function(p)
  533. {
  534. if (p.command == 'reply-list' && rcmail.env.reply_all_mode == 1) {
  535. var label = rcmail.gettext(p.status ? 'replylist' : 'replyall');
  536. $('a.button.replyAll').attr('title', label);
  537. }
  538. else if (p.command == 'compose-encrypted') {
  539. // show the toolbar button for Mailvelope
  540. $('#messagetoolbar > a.encrypt').show();
  541. }
  542. },
  543. folder_search_init: function(container)
  544. {
  545. // animation to unfold list search box
  546. $('.boxtitle a.search', container).click(function(e) {
  547. var title = $('.boxtitle', container),
  548. box = $('.listsearchbox', container),
  549. dir = box.is(':visible') ? -1 : 1,
  550. height = 24 + ($('select', box).length ? 24 : 0);
  551. box.slideToggle({
  552. duration: 160,
  553. progress: function(animation, progress) {
  554. if (dir < 0) progress = 1 - progress;
  555. $('.boxlistcontent', container).css('top', (title.outerHeight() + height * progress) + 'px');
  556. },
  557. complete: function() {
  558. box.toggleClass('expanded');
  559. if (box.is(':visible')) {
  560. box.find('input[type=text]').focus();
  561. }
  562. else {
  563. $('a.reset', box).click();
  564. }
  565. // TODO: save state in cookie
  566. }
  567. });
  568. return false;
  569. });
  570. }
  571. };
  572. /**
  573. * Roundcube generic layer (floating box) class
  574. *
  575. * @constructor
  576. */
  577. function rcube_layer(id, attributes)
  578. {
  579. this.name = id;
  580. // create a new layer in the current document
  581. this.create = function(arg)
  582. {
  583. var l = (arg.x) ? arg.x : 0,
  584. t = (arg.y) ? arg.y : 0,
  585. w = arg.width,
  586. h = arg.height,
  587. z = arg.zindex,
  588. vis = arg.vis,
  589. parent = arg.parent,
  590. obj = document.createElement('DIV');
  591. obj.id = this.name;
  592. obj.style.position = 'absolute';
  593. obj.style.visibility = (vis) ? (vis==2) ? 'inherit' : 'visible' : 'hidden';
  594. obj.style.left = l+'px';
  595. obj.style.top = t+'px';
  596. if (w)
  597. obj.style.width = w.toString().match(/\%$/) ? w : w+'px';
  598. if (h)
  599. obj.style.height = h.toString().match(/\%$/) ? h : h+'px';
  600. if (z)
  601. obj.style.zIndex = z;
  602. if (parent)
  603. parent.appendChild(obj);
  604. else
  605. document.body.appendChild(obj);
  606. this.elm = obj;
  607. };
  608. // create new layer
  609. if (attributes != null) {
  610. this.create(attributes);
  611. this.name = this.elm.id;
  612. }
  613. else // just refer to the object
  614. this.elm = document.getElementById(id);
  615. if (!this.elm)
  616. return false;
  617. // ********* layer object properties *********
  618. this.css = this.elm.style;
  619. this.event = this.elm;
  620. this.width = this.elm.offsetWidth;
  621. this.height = this.elm.offsetHeight;
  622. this.x = parseInt(this.elm.offsetLeft);
  623. this.y = parseInt(this.elm.offsetTop);
  624. this.visible = (this.css.visibility=='visible' || this.css.visibility=='show' || this.css.visibility=='inherit') ? true : false;
  625. // ********* layer object methods *********
  626. // move the layer to a specific position
  627. this.move = function(x, y)
  628. {
  629. this.x = x;
  630. this.y = y;
  631. this.css.left = Math.round(this.x)+'px';
  632. this.css.top = Math.round(this.y)+'px';
  633. };
  634. // change the layers width and height
  635. this.resize = function(w,h)
  636. {
  637. this.css.width = w+'px';
  638. this.css.height = h+'px';
  639. this.width = w;
  640. this.height = h;
  641. };
  642. // show or hide the layer
  643. this.show = function(a)
  644. {
  645. if(a == 1) {
  646. this.css.visibility = 'visible';
  647. this.visible = true;
  648. }
  649. else if(a == 2) {
  650. this.css.visibility = 'inherit';
  651. this.visible = true;
  652. }
  653. else {
  654. this.css.visibility = 'hidden';
  655. this.visible = false;
  656. }
  657. };
  658. // write new content into a Layer
  659. this.write = function(cont)
  660. {
  661. this.elm.innerHTML = cont;
  662. };
  663. };
  664. /**
  665. * Scroller
  666. *
  667. * @deprecated Use treelist widget
  668. */
  669. function rcmail_scroller(list, top, bottom)
  670. {
  671. var ref = this;
  672. this.list = $(list);
  673. this.top = $(top);
  674. this.bottom = $(bottom);
  675. this.step_size = 6;
  676. this.step_time = 20;
  677. this.delay = 500;
  678. this.top
  679. .mouseenter(function() { ref.ts = window.setTimeout(function() { ref.scroll('down'); }, ref.delay); })
  680. .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
  681. this.bottom
  682. .mouseenter(function() { ref.ts = window.setTimeout(function() { ref.scroll('up'); }, ref.delay); })
  683. .mouseout(function() { if (ref.ts) window.clearTimeout(ref.ts); });
  684. this.scroll = function(dir)
  685. {
  686. var ref = this, size = this.step_size;
  687. if (!rcmail.drag_active)
  688. return;
  689. if (dir == 'down')
  690. size *= -1;
  691. this.list.get(0).scrollTop += size;
  692. this.ts = window.setTimeout(function() { ref.scroll(dir); }, this.step_time);
  693. };
  694. };
  695. // Abbreviate mailbox names to fit width of the container
  696. function rcube_render_mailboxlist()
  697. {
  698. var list = $('#mailboxlist > li > a, #mailboxlist ul:visible > li > a');
  699. // it's too slow with really big number of folders, especially on IE
  700. if (list.length > (bw.ie && bw.vendver < 9 ? 40 : 100))
  701. return;
  702. list.each(function() {
  703. var elem = $(this),
  704. text = elem.data('text');
  705. if (!text) {
  706. text = elem.text().replace(/\s+\([0-9]+\)$/, '');
  707. elem.data('text', text);
  708. }
  709. if (text.length < 6)
  710. return;
  711. var abbrev = fit_string_to_size(text, elem, elem.width() - elem.children('span.unreadcount').width() - 16);
  712. if (abbrev != text)
  713. elem.attr('title', text);
  714. elem.contents().filter(function(){ return (this.nodeType == 3); }).get(0).data = abbrev;
  715. });
  716. };
  717. // inspired by https://gist.github.com/24261/7fdb113f1e26111bd78c0c6fe515f6c0bf418af5
  718. function fit_string_to_size(str, elem, len)
  719. {
  720. var w, span, $span, result = str, ellip = '...';
  721. if (!rcmail.env.tmp_span) {
  722. // it should be appended to elem to use the same css style
  723. // but for performance reasons we'll append it to body (once)
  724. span = $('<b>').css({visibility: 'hidden', padding: '0px',
  725. 'font-family': elem.css('font-family'),
  726. 'font-size': elem.css('font-size')})
  727. .appendTo($('body', document)).get(0);
  728. rcmail.env.tmp_span = span;
  729. }
  730. else {
  731. span = rcmail.env.tmp_span;
  732. }
  733. $span = $(span);
  734. $span.text(result);
  735. // on first run, check if string fits into the length already.
  736. w = span.offsetWidth;
  737. if (w > len) {
  738. var cut = Math.max(1, Math.floor(str.length * ((w - len) / w) / 2)),
  739. mid = Math.floor(str.length / 2),
  740. offLeft = mid,
  741. offRight = mid;
  742. while (true) {
  743. offLeft = mid - cut;
  744. offRight = mid + cut;
  745. $span.text(str.substring(0,offLeft) + ellip + str.substring(offRight));
  746. // break loop if string fits size
  747. if (offLeft < 3 || span.offsetWidth)
  748. break;
  749. cut++;
  750. }
  751. // build resulting string
  752. result = str.substring(0,offLeft) + ellip + str.substring(offRight);
  753. }
  754. return result;
  755. };
  756. function update_quota(data)
  757. {
  758. percent_indicator(rcmail.gui_objects.quotadisplay, data);
  759. if (data.table) {
  760. var menu = $('#quotamenu');
  761. if (!menu.length)
  762. menu = $('<div id="quotamenu" class="popupmenu">').appendTo($('body'));
  763. menu.html(data.table);
  764. $('#quotaimg').css('cursor', 'pointer').off('click').on('click', function(e) {
  765. return rcmail.command('menu-open', 'quotamenu', e.target, e);
  766. });
  767. }
  768. };
  769. // percent (quota) indicator
  770. function percent_indicator(obj, data)
  771. {
  772. if (!data || !obj)
  773. return false;
  774. var limit_high = 80,
  775. limit_mid = 55,
  776. width = data.width ? data.width : rcmail.env.indicator_width ? rcmail.env.indicator_width : 100,
  777. height = data.height ? data.height : rcmail.env.indicator_height ? rcmail.env.indicator_height : 14,
  778. quota = data.percent ? Math.abs(parseInt(data.percent)) : 0,
  779. quota_width = parseInt(quota / 100 * width),
  780. pos = $(obj).position();
  781. // workarounds for Opera and Webkit bugs
  782. pos.top = Math.max(0, pos.top);
  783. pos.left = Math.max(0, pos.left);
  784. rcmail.env.indicator_width = width;
  785. rcmail.env.indicator_height = height;
  786. // overlimit
  787. if (quota_width > width) {
  788. quota_width = width;
  789. quota = 100;
  790. }
  791. if (data.title)
  792. data.title = rcmail.get_label('quota') + ': ' + data.title;
  793. // main div
  794. var main = $('<div>');
  795. main.css({position: 'absolute', top: pos.top, left: pos.left,
  796. width: width + 'px', height: height + 'px', zIndex: 100, lineHeight: height + 'px'})
  797. .attr('title', data.title).addClass('quota_text').html(quota + '%');
  798. // used bar
  799. var bar1 = $('<div>');
  800. bar1.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
  801. width: quota_width + 'px', height: height + 'px', zIndex: 99});
  802. // background
  803. var bar2 = $('<div>');
  804. bar2.css({position: 'absolute', top: pos.top + 1, left: pos.left + 1,
  805. width: width + 'px', height: height + 'px', zIndex: 98})
  806. .addClass('quota_bg');
  807. if (quota >= limit_high) {
  808. main.addClass(' quota_text_high');
  809. bar1.addClass('quota_high');
  810. }
  811. else if(quota >= limit_mid) {
  812. main.addClass(' quota_text_mid');
  813. bar1.addClass('quota_mid');
  814. }
  815. else {
  816. main.addClass(' quota_text_low');
  817. bar1.addClass('quota_low');
  818. }
  819. // replace quota image
  820. $(obj).html('').append(bar1).append(bar2).append(main);
  821. // update #quotaimg title
  822. $('#quotaimg').attr('title', data.title);
  823. };
  824. // Optional parameters used by TinyMCE
  825. var rcmail_editor_settings = {};
  826. var rcmail_ui;
  827. function rcube_init_mail_ui()
  828. {
  829. rcmail_ui = new rcube_mail_ui();
  830. $(document.body).mouseup(function(e) { rcmail_ui.body_mouseup(e); })
  831. .mousedown(function(e) { rcmail_ui.body_keydown(e); });
  832. rcmail.addEventListener('init', function() {
  833. if (rcmail.env.quota_content)
  834. update_quota(rcmail.env.quota_content);
  835. rcmail.addEventListener('setquota', update_quota);
  836. rcube_webmail.set_iframe_events({mouseup: function(e) { return rcmail_ui.body_mouseup(e); }});
  837. if (rcmail.env.task == 'mail') {
  838. rcmail.addEventListener('enable-command', 'enable_command', rcmail_ui)
  839. .addEventListener('menu-open', 'menu_open', rcmail_ui)
  840. .addEventListener('aftersend-attachment', 'uploadmenu', rcmail_ui)
  841. .addEventListener('aftertoggle-editor', 'resize_compose_body_ev', rcmail_ui)
  842. .gui_object('dragmenu', 'dragmenu');
  843. if (rcmail.gui_objects.mailboxlist) {
  844. rcmail.treelist.addEventListener('expand', rcube_render_mailboxlist);
  845. rcmail.addEventListener('responseaftermark', rcube_render_mailboxlist)
  846. .addEventListener('responseaftergetunread', rcube_render_mailboxlist)
  847. .addEventListener('responseaftercheck-recent', rcube_render_mailboxlist)
  848. .addEventListener('responseafterrefresh', rcube_render_mailboxlist)
  849. .addEventListener('afterimport-messages', function(){ rcmail_ui.show_popup('uploadform', false); });
  850. }
  851. rcmail.init_pagejumper('#pagejumper');
  852. // fix message list header on window resize (#1490213)
  853. if (bw.ie && rcmail.message_list)
  854. $(window).resize(function() {
  855. setTimeout(function() { rcmail.message_list.resize(); }, 10);
  856. });
  857. if (rcmail.env.action == 'compose') {
  858. rcmail_ui.init_compose_form();
  859. rcmail.addEventListener('compose-encrypted', function(e) {
  860. $("a.button.encrypt")[(e.active ? 'addClass' : 'removeClass')]('selected');
  861. $("select[name='editorSelector']").prop('disabled', e.active);
  862. $('a.button.attach, a.button.responses, a.button.attach, #uploadmenulink')[(e.active ? 'addClass' : 'removeClass')]('buttonPas disabled');
  863. $('#responseslist a.insertresponse')[(e.active ? 'removeClass' : 'addClass')]('active');
  864. });
  865. }
  866. else if (rcmail.env.action == 'show' || rcmail.env.action == 'preview') {
  867. // add menu link for each attachment
  868. $('#attachment-list > li[id^="attach"]').each(function() {
  869. $(this).append($('<a class="drop"></a>').on('click keypress', function(e) {
  870. if (e.type != 'keypress' || e.which == 13) {
  871. rcmail_ui.show_attachmentmenu(this, e);
  872. return false;
  873. }
  874. }));
  875. });
  876. $(window).resize(function() {
  877. var mvlpe = $('#messagebody.mailvelope');
  878. if (mvlpe.length) {
  879. var content = $('#messageframe'),
  880. h = (content.length ? content.height() + content.offset().top - 25 : $(this).height()) - mvlpe.offset().top - 20;
  881. mvlpe.height(h);
  882. }
  883. });
  884. }
  885. }
  886. else if (rcmail.env.task == 'addressbook') {
  887. rcmail.addEventListener('afterupload-photo', function(){ rcmail_ui.show_popup('uploadform', false); })
  888. .gui_object('dragmenu', 'dragmenu');
  889. }
  890. else if (rcmail.env.task == 'settings') {
  891. if (rcmail.env.action == 'folders') {
  892. rcmail_ui.folder_search_init($('#folder-manager'));
  893. }
  894. }
  895. });
  896. }