/* * LibreOffice Online toolbar */ /* global $ map closebutton w2ui w2utils vex _ _UNO */ /* exported onUseritemClicked editorUpdate */ var mobileWidth = 768; function onDelete(e) { if (e !== false) { map.deletePage(); } } var nUsers, oneUser, noUser; function _mobilify() { var toolbarUp = w2ui['toolbar-up']; var statusbar = w2ui['toolbar-down']; toolbarUp.items.forEach(function(item) { if (item.mobile === false && !item.hidden) { toolbarUp.hide(item.id); } }); statusbar.items.forEach(function(item) { if (item.mobile === false && !item.hidden) { statusbar.hide(item.id); } }); nUsers = '%n'; oneUser = '1'; noUser = '0'; updateUserListCount(); $('#document-name-input').hide(); } function _unmobilify() { var toolbarUp = w2ui['toolbar-up']; var statusbar = w2ui['toolbar-down']; toolbarUp.items.forEach(function(item) { if (item.mobile === false && item.hidden) { toolbarUp.show(item.id); } }); statusbar.items.forEach(function(item) { if (item.mobile === false && item.hidden) { statusbar.show(item.id); } }); nUsers = _('%n users'); oneUser = _('1 user'); noUser = _('0 users'); updateUserListCount(); $('#document-name-input').show(); } function resizeToolbar() { var toolbarUp = w2ui['toolbar-up']; var statusbar = w2ui['toolbar-down']; if ($(window).width() < mobileWidth) { _mobilify(); } else { _unmobilify(); } toolbarUp.resize(); statusbar.resize(); } function _cancelSearch() { var toolbar = w2ui['toolbar-down']; map.resetSelection(); toolbar.hide('cancelsearch'); toolbar.disable('searchprev'); toolbar.disable('searchnext'); L.DomUtil.get('search-input').value = ''; map.focus(); } function onClick(e, id, item, subItem) { if (w2ui['toolbar-up'].get(id) !== null) { var toolbar = w2ui['toolbar-up']; item = toolbar.get(id); } else if (w2ui.formulabar.get(id) !== null) { toolbar = w2ui.formulabar; item = toolbar.get(id); } else if (w2ui['toolbar-down'].get(id) !== null) { toolbar = w2ui['toolbar-down']; item = toolbar.get(id); } else if (w2ui['spreadsheet-toolbar'].get(id) !== null) { toolbar = w2ui['spreadsheet-toolbar']; item = toolbar.get(id); } else if (w2ui['presentation-toolbar'].get(id) !== null) { toolbar = w2ui['presentation-toolbar']; item = toolbar.get(id); } else if (item && subItem) { var command = { 'StatusBarFunc': { type: 'unsigned short', value: subItem.func } }; map.sendUnoCommand('.uno:StatusBarFunc', command); } else { throw new Error('unknown id: ' + id); } var docLayer = map._docLayer; map.focus(); if (item.disabled) { return; } if (item.postmessage && item.type === 'button') { map.fire('postMessage', {msgId: 'Clicked_Button', args: {Id: item.id} }); } else if (item.uno) { if (item.unosheet && map.getDocType() === 'spreadsheet') { map.toggleCommandState(item.unosheet); } else { map.toggleCommandState(item.uno); } } else if (id === 'save') { map.save(false /* An explicit save should terminate cell edit */, false /* An explicit save should save it again */); } else if (id === 'repair') { map._socket.sendMessage('commandvalues command=.uno:DocumentRepair'); } else if (id === 'zoomin' && map.getZoom() < map.getMaxZoom()) { map.zoomIn(1); } else if (id === 'zoomout' && map.getZoom() > map.getMinZoom()) { map.zoomOut(1); } else if (id === 'zoomreset') { map.setZoom(map.options.zoom); } else if (id === 'prev' || id === 'next') { if (docLayer._docType === 'text') { map.goToPage(id); } else { map.setPart(id); } } else if (id === 'searchprev') { map.search(L.DomUtil.get('search-input').value, true); } else if (id === 'searchnext') { map.search(L.DomUtil.get('search-input').value); } else if (id === 'cancelsearch') { _cancelSearch(); } else if (id === 'presentation' && map.getDocType() === 'presentation') { map.fire('fullscreen'); } else if (id === 'insertannotation') { map.insertComment(); } else if (id === 'insertpage') { map.insertPage(); } else if (id === 'duplicatepage') { map.duplicatePage(); } else if (id === 'deletepage') { vex.dialog.confirm({ message: _('Are you sure you want to delete this page?'), callback: onDelete }); } else if (id === 'insertsheet') { var nPos = $('#spreadsheet-tab-scroll')[0].childElementCount; map.insertPage(nPos + 1); $('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').prop('scrollWidth')); } else if (id === 'firstrecord') { $('#spreadsheet-tab-scroll').scrollLeft(0); } // TODO: We should get visible tab's width instead of 60px else if (id === 'nextrecord') { $('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() + 60); } else if (id === 'prevrecord') { $('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() - 30); } else if (id === 'lastrecord') { $('#spreadsheet-tab-scroll').scrollLeft($('#spreadsheet-tab-scroll').scrollLeft() + 120); } else if (id.startsWith('menu:wrap:wrap-')) { var wrapType = id.substring('menu:wrap:wrap-'.length); map.toggleCommandState(wrapType); } else if (id === 'insertgraphic') { L.DomUtil.get('insertgraphic').click(); } else if (id === 'fontcolor' && e.color) { onColorPick(id, e.color); } else if (id === 'backcolor' && e.color) { onColorPick(id, e.color) } else if (id === 'sum') { map.sendUnoCommand('.uno:AutoSum'); } else if (id === 'function') { L.DomUtil.get('formulaInput').value = '='; L.DomUtil.get('formulaInput').focus(); map.cellEnterString(L.DomUtil.get('formulaInput').value); } else if (id === 'cancelformula') { map.sendUnoCommand('.uno:Cancel'); w2ui['formulabar'].hide('acceptformula', 'cancelformula'); w2ui['formulabar'].show('sum', 'function'); } else if (id === 'acceptformula') { // focus on map, and press enter map.focus(); map._docLayer._postKeyboardEvent('input', map.keyboard.keyCodes.enter, map.keyboard._toUNOKeyCode(map.keyboard.keyCodes.enter)); w2ui['formulabar'].hide('acceptformula', 'cancelformula'); w2ui['formulabar'].show('sum', 'function'); } } function insertTable() { var rows = 10; var cols = 10; var $grid = $('.inserttable-grid'); var $status = $('#inserttable-status'); // init for (var r = 0; r < rows; r++) { var $row = $('
').addClass('row'); $grid.append($row); for (var c = 0; c < cols; c++) { var $col = $('
').addClass('col'); $row.append($col); } } // events $grid.on({ mouseover: function () { var col = $(this).index() + 1; var row = $(this).parent().index() + 1; $('.col').removeClass('bright'); $('.row:nth-child(-n+' + row + ') .col:nth-child(-n+' + col + ')') .addClass('bright'); $status.html(col + 'x' + row); }, click: function() { var col = $(this).index() + 1; var row = $(this).parent().index() + 1; $('.col').removeClass('bright'); $status.html('
'); var msg = 'uno .uno:InsertTable {' + ' "Columns": { "type": "long","value": ' + col + ' }, "Rows": { "type": "long","value": ' + row + ' }}'; if ($('#w2ui-overlay-toolbar-up').length > 0) { $('#w2ui-overlay-toolbar-up').removeData('keepOpen')[0].hide(); } map._socket.sendMessage(msg); // refocus map due popup map.focus(); } }, '.col'); } function onColorPick(id, color) { if (map.getPermission() !== 'edit' || color === undefined) { return; } // transform from #FFFFFF to an Int color = parseInt(color.replace('#', ''), 16); var command = {}; var fontcolor, backcolor; if (id === 'fontcolor') { fontcolor = {'text': 'FontColor', 'spreadsheet': 'Color', 'presentation': 'Color'}[map.getDocType()]; command[fontcolor] = {}; command[fontcolor].type = 'long'; command[fontcolor].value = color; var uno = '.uno:' + fontcolor; } else if (id === 'backcolor') { backcolor = {'text': 'BackColor', 'spreadsheet': 'BackgroundColor', 'presentation': 'CharBackColor'}[map.getDocType()]; command[backcolor] = {}; command[backcolor].type = 'long'; command[backcolor].value = color; uno = '.uno:' + backcolor; } map.sendUnoCommand(uno, command); map.focus(); } var stylesSelectValue; var fontsSelectValue; var fontsizesSelectValue; $(function () { $('#toolbar-up').w2toolbar({ name: 'toolbar-up', items: [ {type: 'menu', id: 'writer:menu:wrap', caption: _('Textwrap'), items: [ { text: _('No wrap'), id: 'wrap-WrapOff' }, { text: _('Page wrap'), id: 'wrap-WrapOn' }, { text: _('Wrap anchor only'), id: 'wrap-WrapAnchorOnly' }, { text: _('Ideal wrap'), id: 'wrap-WrapIdeal' }, { text: _('Left wrap'), id: 'wrap-WrapLeft' }, { text: _('Right wrap'), id: 'wrap-WrapRight' }, { text: _('Wrap through'), id: 'wrap-WrapThrough' } ]}, {type: 'button', id: 'save', img: 'save', hint: _UNO('.uno:Save')}, {type: 'break', id: 'savebreak'}, {type: 'button', id: 'undo', img: 'undo', hint: _UNO('.uno:Undo'), uno: 'Undo', disabled: true}, {type: 'button', id: 'redo', img: 'redo', hint: _UNO('.uno:Redo'), uno: 'Redo', disabled: true}, {type: 'button', id: 'repair', img: 'repair', hint: _('Document repair'), disabled: true}, {type: 'break'}, {type: 'html', id: 'styles', html: '', mobile: false}, {type: 'html', id: 'fonts', html: '', mobile: false}, {type: 'html', id: 'fontsizes', html: '', mobile: false}, {type: 'break', mobile: false}, {type: 'button', id: 'bold', img: 'bold', hint: _UNO('.uno:Bold'), uno: 'Bold', disabled: true}, {type: 'button', id: 'italic', img: 'italic', hint: _UNO('.uno:Italic'), uno: 'Italic', disabled: true}, {type: 'button', id: 'underline', img: 'underline', hint: _UNO('.uno:Underline'), uno: 'Underline', disabled: true}, {type: 'button', id: 'strikeout', img: 'strikeout', hint: _UNO('.uno:Strikeout'), uno: 'Strikeout', disabled: true}, {type: 'break', id: 'formatbreak'}, {type: 'button', id: 'insertfootnote', img: 'insertfootnote', hint: _UNO('.uno:InsertFootnote'), uno: 'InsertFootnote', mobile: false}, {type: 'break' , mobile:false}, {type: 'text-color', id: 'fontcolor', hint: _UNO('.uno:FontColor')}, {type: 'color', id: 'backcolor', hint: _UNO('.uno:BackgroundColor')}, {type: 'break'}, {type: 'button', id: 'leftpara', img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true), uno: 'LeftPara', unosheet: 'AlignLeft', disabled: true}, {type: 'button', id: 'centerpara', img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true), uno: 'CenterPara', unosheet: 'AlignHorizontalCenter', disabled: true}, {type: 'button', id: 'rightpara', img: 'alignright', hint: _UNO('.uno:RightPara', '', true), uno: 'RightPara', unosheet: 'AlignRight', disabled: true}, {type: 'button', id: 'justifypara', img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara', unosheet: '', disabled: true}, {type: 'break', id: 'wraptextseparator'}, {type: 'button', id: 'wraptext', img: 'wraptext', hint: _UNO('.uno:WrapText', 'spreadsheet', true), uno: 'WrapText', disabled: true}, {type: 'button', id: 'togglemergecells', img: 'togglemergecells', hint: _UNO('.uno:ToggleMergeCells', 'spreadsheet', true), uno: 'ToggleMergeCells', disabled: true}, {type: 'break', id: 'break-toggle'}, {type: 'button', id: 'numberformatcurrency', img: 'numberformatcurrency', hint: _UNO('.uno:NumberFormatCurrency', 'spreadsheet', true), uno: 'NumberFormatCurrency', disabled: true}, {type: 'button', id: 'numberformatpercent', img: 'numberformatpercent', hint: _UNO('.uno:NumberFormatPercent', 'spreadsheet', true), uno: 'NumberFormatPercent', disabled: true}, {type: 'button', id: 'numberformatdecimal', img: 'numberformatdecimal', hint: _UNO('.uno:NumberFormatDecimal', 'spreadsheet', true), uno: 'NumberFormatDecimal', disabled: true}, {type: 'button', id: 'numberformatdate', img: 'numberformatdate', hint: _UNO('.uno:NumberFormatDate', 'spreadsheet', true), uno: 'NumberFormatDate', disabled: true}, {type: 'button', id: 'numberformatincdecimals', img: 'numberformatincdecimals', hint: _UNO('.uno:NumberFormatIncDecimals', 'spreadsheet', true), uno: 'NumberFormatIncDecimals', disabled: true}, {type: 'button', id: 'numberformatdecdecimals', img: 'numberformatdecdecimals', hint: _UNO('.uno:NumberFormatDecDecimals', 'spreadsheet', true), uno: 'NumberFormatDecDecimals', disabled: true}, {type: 'break', id: 'break-number'}, {type: 'button', id: 'sortascending', img: 'sortascending', hint: _UNO('.uno:SortAscending', 'spreadsheet', true), uno: 'SortAscending', disabled: true}, {type: 'button', id: 'sortdescending', img: 'sortdescending', hint: _UNO('.uno:SortDescending', 'spreadsheet', true), uno: 'SortDescending', disabled: true}, {type: 'break', id: 'break-align'}, {type: 'button', id: 'defaultbullet', img: 'bullet', hint: _UNO('.uno:DefaultBullet', '', true), uno: 'DefaultBullet', disabled: true}, {type: 'button', id: 'defaultnumbering', img: 'numbering', hint: _UNO('.uno:DefaultNumbering', '', true), uno: 'DefaultNumbering', disabled: true}, {type: 'break', id: 'break-numbering'}, {type: 'button', id: 'incrementindent', img: 'incrementindent', hint: _UNO('.uno:IncrementIndent', '', true), uno: 'IncrementIndent', disabled: true}, {type: 'button', id: 'decrementindent', img: 'decrementindent', hint: _UNO('.uno:DecrementIndent', '', true), uno: 'DecrementIndent', disabled: true}, {type: 'break', id: 'incdecindent'}, {type: 'drop', id: 'inserttable', img: 'inserttable', hint: _('Insert table'), overlay: {onShow: insertTable}, html: '

'}, {type: 'button', id: 'insertobjectchart', img: 'insertobjectchart', hint: _UNO('.uno:InsertObjectChart', '', true), uno: 'InsertObjectChart'}, {type: 'button', id: 'insertannotation', img: 'annotation', hint: _UNO('.uno:InsertAnnotation', '', true)}, {type: 'button', id: 'insertgraphic', img: 'insertgraphic', hint: _UNO('.uno:InsertGraphic', '', true)}, {type: 'button', id: 'specialcharacter', img: 'specialcharacter', hint: _UNO('.uno:InsertSymbol', '', true), uno: '.uno:InsertSymbol'} ], onClick: function (e) { onClick(e, e.target); }, onRefresh: function() { if (map.getDocType() === 'presentation') { // Fill the style select box if not yet filled if ($('.styles-select')[0] && $('.styles-select')[0].length === 0) { var data = ['']; // Inserts a separator element data = data.concat({text: '\u2500\u2500\u2500\u2500\u2500\u2500', disabled: true}); L.Styles.impressLayout.forEach(function(layout) { data = data.concat({id: layout.id, text: _(layout.text)}); }, this); $('.styles-select').select2({ data: data, placeholder: _UNO('.uno:LayoutStatus', 'presentation') }); $('.styles-select').on('select2:select', onStyleSelect); } } updateCommandValues(); insertTable(); } }); $('#formulabar').w2toolbar({ name: 'formulabar', items: [ {type: 'html', id: 'left'}, {type: 'html', id: 'address', html: ''}, {type: 'break'}, {type: 'button', id: 'sum', img: 'autosum', hint: _('Sum')}, {type: 'button', id: 'function', img: 'equal', hint: _('Function')}, {type: 'button', hidden: true, id: 'cancelformula', img: 'cancel', hint: _('Cancel')}, {type: 'button', hidden: true, id: 'acceptformula', img: 'accepttrackedchanges', hint: _('Accept')}, {type: 'html', id: 'formula', html: ''} ], onClick: function (e) { onClick(e, e.target); }, onRefresh: function() { $('#addressInput').off('keyup', onAddressInput).on('keyup', onAddressInput); $('#formulaInput').off('keyup', onFormulaInput).on('keyup', onFormulaInput); $('#formulaInput').off('blur', onFormulaBarBlur).on('blur', onFormulaBarBlur); $('#formulaInput').off('focus', onFormulaBarFocus).on('focus', onFormulaBarFocus); } }); $('#spreadsheet-toolbar').w2toolbar({ name: 'spreadsheet-toolbar', items: [ {type: 'button', id: 'firstrecord', img: 'firstrecord', hidden: true, hint: _('First sheet')}, {type: 'button', id: 'prevrecord', img: 'prevrecord', hidden: true, hint: _('Previous sheet')}, {type: 'button', id: 'nextrecord', img: 'nextrecord', hidden: true, hint: _('Next sheet')}, {type: 'button', id: 'lastrecord', img: 'lastrecord', hidden: true, hint: _('Last sheet')}, {type: 'button', id: 'insertsheet', img: 'insertsheet', hidden:true, hint: _('Insert sheet')} ], onClick: function (e) { onClick(e, e.target); } }); $('#presentation-toolbar').w2toolbar({ name: 'presentation-toolbar', items: [ {type: 'html', id: 'left'}, {type: 'button', id: 'presentation', img: 'presentation', hidden:true, hint: _('Fullscreen presentation')}, {type: 'break', id: 'presentationbreak', hidden:true}, {type: 'button', id: 'insertpage', img: 'insertpage', hidden:true, hint: _UNO('.uno:TaskPaneInsertPage', 'presentation')}, {type: 'button', id: 'duplicatepage', img: 'duplicatepage', hidden:true, hint: _UNO('.uno:DuplicateSlide', 'presentation')}, {type: 'button', id: 'deletepage', img: 'deletepage', hidden:true, hint: _UNO('.uno:DeleteSlide', 'presentation')}, {type: 'html', id: 'right'} ], onClick: function (e) { onClick(e, e.target); } }); $('#toolbar-down').w2toolbar({ name: 'toolbar-down', items: [ {type: 'html', id: 'search', html: '
' + ' ' + _('Search:') + ' ' + '
' }, {type: 'button', id: 'searchprev', img: 'prev', hint: _UNO('.uno:UpSearch'), disabled: true}, {type: 'button', id: 'searchnext', img: 'next', hint: _UNO('.uno:DownSearch'), disabled: true}, {type: 'button', id: 'cancelsearch', img: 'cancel', hint: _('Cancel the search'), hidden: true}, {type: 'html', id: 'left'}, {type: 'html', id: 'right'}, {type: 'html', id: 'modifiedstatuslabel', html: '
', mobile:false}, {type: 'break', id: 'modifiedstatuslabelbreak', mobile:false}, {type: 'drop', id: 'userlist', text: _('No users'), html: '
' + '
' + '' + '' + '' + '' + '
' + _('Always follow the editor') + '
' + '

' + _('Current') + ' -

' + '
' }, {type: 'break', id: 'userlistbreak'}, {type: 'button', id: 'prev', img: 'prev', hint: _UNO('.uno:PageUp', 'text')}, {type: 'button', id: 'next', img: 'next', hint: _UNO('.uno:PageDown', 'text')}, {type: 'break', id: 'prevnextbreak'}, {type: 'button', id: 'zoomreset', img: 'zoomreset', hint: _('Reset zoom')}, {type: 'button', id: 'zoomout', img: 'zoomout', hint: _UNO('.uno:ZoomMinus')}, {type: 'html', id: 'zoomlevel', html: '
100%
', mobile: false}, {type: 'button', id: 'zoomin', img: 'zoomin', hint: _UNO('.uno:ZoomPlus')} ], onClick: function (e) { if (e.item.id === 'userlist') { setTimeout(function() { var cBox = $('#follow-checkbox')[0]; var docLayer = map._docLayer; var editorId = docLayer._editorId; if (cBox) cBox.checked = docLayer._followEditor; if (docLayer.editorId !== -1 && map._viewInfo[editorId]) $('#current-editor').text(map._viewInfo[editorId].username); else $('#currently-msg').hide(); }, 100); return; } onClick(e, e.target, e.item, e.subItem); }, onRefresh: function() { $('#tb_toolbar-down_item_userlist .w2ui-tb-caption').addClass('loleaflet-font'); $('#search-input').off('input', onSearch).on('input', onSearch); $('#search-input').off('keydown', onSearchKeyDown).on('keydown', onSearchKeyDown); } }); }); var userJoinedPopupMessage = '
' + _('%user has joined') + '
'; var userLeftPopupMessage = '
' + _('%user has left') + '
'; var userPopupTimeout = null; function localizeStateTableCell (text) { var stateArray = text.split(';'); var stateArrayLength = stateArray.length; var localizedText = ''; for (var i = 0; i < stateArrayLength; i++) { var labelValuePair = stateArray[i].split(':'); localizedText += _(labelValuePair[0].trim()) + ':' + labelValuePair[1]; if (stateArrayLength > 1 && i < stateArrayLength - 1) { localizedText += '; '; } } return localizedText; } function toLocalePattern (pattern, regex, text, sub1, sub2) { var matches = new RegExp(regex, 'g').exec(text); if (matches) { text = pattern.toLocaleString().replace(sub1, parseInt(matches[1].replace(',','')).toLocaleString(String.locale)).replace(sub2, parseInt(matches[2].replace(',','')).toLocaleString(String.locale)); } return text; } function updateToolbarItem(toolbar, id, html) { var item = toolbar.get(id); if (item) { item.html = html; } } function unoCmdToToolbarId(commandname) { var id = commandname.toLowerCase().substr(5); if (map.getDocType() === 'spreadsheet') { switch (id) { case 'alignleft': id = 'leftpara'; break; case 'alignhorizontalcenter': id = 'centerpara'; break; case 'alignright': id = 'rightpara'; break; } } return id; } function selectItem(item, func) { var index = -1; for (var it = 0; it < item.items.length; it++) { if (item.items[it].func === func) { index = it; break; } } if (index !== -1) { item.items[item.current].icon = ''; item.items[index].icon = 'selected'; item.current = index; } } function onSearch() { var toolbar = w2ui['toolbar-down']; // conditionally disabling until, we find a solution for tdf#108577 if (L.DomUtil.get('search-input').value === '') { toolbar.disable('searchprev'); toolbar.disable('searchnext'); toolbar.hide('cancelsearch'); } else { if (map.getDocType() === 'text') map.search(L.DomUtil.get('search-input').value, false, '', 0, true /* expand search */); toolbar.enable('searchprev'); toolbar.enable('searchnext'); toolbar.show('cancelsearch'); } } function onSearchKeyDown(e) { if ((e.keyCode === 71 && e.ctrlKey) || e.keyCode === 114 || e.keyCode === 13) { if (e.shiftKey) { map.search(L.DomUtil.get('search-input').value, true); } else { map.search(L.DomUtil.get('search-input').value); } e.preventDefault(); } else if (e.keyCode === 27) { _cancelSearch(); } } function documentNameConfirm() { var value = $('#document-name-input').val(); if (value !== null && value != '' && value != map['wopi'].BaseFileName) { map.saveAs(value); } map._onGotFocus(); } function documentNameCancel() { $('#document-name-input').val(map['wopi'].BaseFileName); map._onGotFocus(); } function onDocumentNameKeyPress(e) { if (e.keyCode === 13) { // Enter key documentNameConfirm(); } else if (e.keyCode === 27) { // Escape key documentNameCancel(); } } function onDocumentNameFocus() { // hide the caret in the main document map._onLostFocus(); } function sortFontSizes() { var oldVal = $('.fontsizes-select').val(); var selectList = $('.fontsizes-select option'); selectList.sort(function (a, b) { a = parseFloat($(a).text() * 1); b = parseFloat($(b).text() * 1); if (a > b) { return 1; } else if (a < b) { return -1; } return 0; }); $('.fontsizes-select').html(selectList); $('.fontsizes-select').val(oldVal).trigger('change'); } function onStyleSelect(e) { var style = e.target.value; if (style.startsWith('.uno:')) { map.sendUnoCommand(style); } else if (map.getDocType() === 'text') { map.applyStyle(style, 'ParagraphStyles'); } else if (map.getDocType() === 'spreadsheet') { map.applyStyle(style, 'CellStyles'); } else if (map.getDocType() === 'presentation' || map.getDocType() === 'drawing') { map.applyLayout(style); } map.focus(); } function updateFontSizeList(font) { var oldSize = $('.fontsizes-select').val(); var found = false; $('.fontsizes-select').find('option').remove(); var data = ['']; data = data.concat(map.getToolbarCommandValues('.uno:CharFontName')[font]); $('.fontsizes-select').select2({ data: data, placeholder: _('Size'), //Allow manually entered font size. createTag: function(query) { return { id: query.term, text: query.term, tag: true }; }, tags: true }); $('.fontsizes-select option').each(function (i, e) { if ($(e).text() === oldSize) { $('.fontsizes-select').val(oldSize).trigger('change'); found = true; return; } }); if (!found) { // we need to add the size $('.fontsizes-select') .append($('') .text(oldSize)); } $('.fontsizes-select').val(oldSize).trigger('change'); sortFontSizes(); } function onFontSelect(e) { var font = e.target.value; updateFontSizeList(font); map.applyFont(font); map.focus(); } function onFontSizeSelect(e) { var size = e.target.value; var command = {}; $(e.target).find('option[data-select2-tag]').removeAttr('data-select2-tag'); map.applyFontSize(size); var fontcolor = map.getDocType() === 'text' ? 'FontColor' : 'Color'; command[fontcolor] = {}; map.focus(); } function onInsertFile() { var insertGraphic = L.DomUtil.get('insertgraphic'); if ('files' in insertGraphic) { for (var i = 0; i < insertGraphic.files.length; i++) { var file = insertGraphic.files[i]; map.insertFile(file); } } // Set the value to null everytime so that onchange event is triggered, // even if the same file is selected insertGraphic.value = null; return false; } function onAddressInput(e) { if (e.keyCode === 13) { // address control should not have focus anymore map.focus(); var value = L.DomUtil.get('addressInput').value; var command = { ToPoint : { type: 'string', value: value } }; map.sendUnoCommand('.uno:GoToCell', command); } else if (e.keyCode === 27) { // 27 = esc key map.sendUnoCommand('.uno:Cancel'); map.focus(); } } function onFormulaInput(e) { // keycode = 13 is 'enter' if (e.keyCode === 13) { // formula bar should not have focus anymore map.focus(); // forward the 'enter' keystroke to map to deal with the formula entered var data = { originalEvent: e }; map.fire('keypress', data); } else if (e.keyCode === 27) { // 27 = esc key map.sendUnoCommand('.uno:Cancel'); map.focus(); } else { map.cellEnterString(L.DomUtil.get('formulaInput').value); } } function onFormulaBarFocus() { var formulabar = w2ui.formulabar; formulabar.hide('sum'); formulabar.hide('function'); formulabar.show('cancelformula'); formulabar.show('acceptformula'); } function onFormulaBarBlur() { // The timeout is needed because we want 'click' event on 'cancel', // 'accept' button to act before we hide these buttons because // once hidden, click event won't be processed. // TODO: Some better way to do it ? setTimeout(function() { var formulabar = w2ui.formulabar; formulabar.show('sum'); formulabar.show('function'); formulabar.hide('cancelformula'); formulabar.hide('acceptformula'); }, 250); } map.on('hidebusy', function() { // If locked, unlock if (w2ui['toolbar-down'].box.firstChild.className === 'w2ui-lock') { w2utils.unlock(w2ui['toolbar-down'].box); } }); map.on('showbusy', function(e) { w2utils.lock(w2ui['toolbar-down'].box, e.label, true); }); map.on('wopiprops', function(e) { if (e.HideSaveOption) { w2ui['toolbar-up'].hide('save'); } if (e.HideExportOption) { w2ui['presentation-toolbar'].hide('presentation', 'presentationbreak'); } if (e.DisableCopy) { $('input#formulaInput').bind('copy', function(evt) { evt.preventDefault(); }); $('input#addressInput').bind('copy', function(evt) { evt.preventDefault(); }); } if (e.BaseFileName !== null) { // set the document name into the name field $('#document-name-input').val(e.BaseFileName); } if (e.UserCanNotWriteRelative === false) { // Save As allowed $('#document-name-input').prop('disabled', false); $('#document-name-input').addClass('editable'); $('#document-name-input').off('keypress', onDocumentNameKeyPress).on('keypress', onDocumentNameKeyPress); $('#document-name-input').off('focus', onDocumentNameFocus).on('focus', onDocumentNameFocus); $('#document-name-input').off('blur', documentNameCancel).on('blur', documentNameCancel); } else { $('#document-name-input').prop('disabled', true); $('#document-name-input').removeClass('editable'); $('#document-name-input').off('keypress', onDocumentNameKeyPress); } }); map.on('doclayerinit', function () { var toolbarUp = w2ui['toolbar-up']; var statusbar = w2ui['toolbar-down']; var docType = map.getDocType(); switch (docType) { case 'spreadsheet': toolbarUp.remove('inserttable', 'styles', 'justifypara', 'defaultbullet', 'defaultnumbering', 'break-numbering'); statusbar.disable('zoomreset', 'zoomout', 'zoomin', 'zoomlevel'); statusbar.insert('left', [ {type: 'break', id:'break1'}, {type: 'html', id: 'StatusDocPos', html: '
     
' }, {type: 'break', id:'break2'}, {type: 'html', id: 'RowColSelCount', html: '
     
' }, {type: 'break', id:'break3'}, {type: 'html', id: 'InsertMode', mobile: false, html: '
     
' }, {type: 'break', id:'break4'}, {type: 'html', id: 'LanguageStatus', mobile: false, html: '
     
' }, {type: 'break', id:'break5'}, {type: 'html', id: 'StatusSelectionMode', mobile: false, html: '
     
' }, {type: 'break', id:'break8', mobile: false}, {type: 'html', id: 'StateTableCell', mobile:false, html: '
     
' }, {type: 'menu', id: 'StateTableCellMenu', caption: '', current: 5, items: [ { func: '2', text: _('Average'), icon: ''}, { func: '8', text: _('CountA'), icon: ''}, { func: '4', text: _('Count'), icon: ''}, { func: '16', text: _('Maximum'), icon: ''}, { func: '32', text: _('Minimum'), icon: ''}, { func: '512', text: _('Sum'), icon: 'selected'}, { func: '8192', text: _('Selection count'), icon: ''}, { func: '1', text: _('None'), icon: ''} ]} ]); // Remove irrelevant toolbars $('#presentation-toolbar').hide(); break; case 'text': toolbarUp.remove('wraptextseparator', 'wraptext', 'togglemergecells', 'break-toggle', 'numberformatcurrency', 'numberformatpercent', 'numberformatdecimal', 'numberformatdate', 'numberformatincdecimals', 'numberformatdecdecimals', 'break-number', 'sortascending', 'sortdescending'); statusbar.insert('left', [ {type: 'break', id: 'break1'}, {type: 'html', id: 'StatePageNumber', html: '
     
' }, {type: 'break', id:'break2'}, {type: 'html', id: 'StateWordCount', mobile: false, html: '
     
' }, {type: 'break', id:'break5', mobile: false}, {type: 'html', id: 'InsertMode', mobile: false, html: '
     
' }, {type: 'break', id:'break6', mobile:false}, {type: 'html', id: 'StatusSelectionMode', mobile: false, html: '
     
' }, {type: 'break', id:'break7', mobile:false}, {type: 'html', id: 'LanguageStatus', mobile: false, html: '
     
' } ]); // Remove irrelevant toolbars $('#formulabar').hide(); $('#spreadsheet-toolbar').hide(); $('#presentation-toolbar').hide(); break; case 'presentation': var presentationToolbar = w2ui['presentation-toolbar']; presentationToolbar.show('insertpage', 'duplicatepage', 'deletepage'); if (!map['wopi'].HideExportOption) { presentationToolbar.show('presentation', 'presentationbreak'); } toolbarUp.remove('insertannotation', 'wraptextseparator', 'wraptext', 'togglemergecells', 'break-toggle', 'numberformatcurrency', 'numberformatpercent', 'numberformatdecimal', 'numberformatdate', 'numberformatincdecimals', 'numberformatdecdecimals', 'break-number', 'sortascending', 'sortdescending'); statusbar.insert('left', [ {type: 'break', id:'break1'}, {type: 'html', id: 'PageStatus', html: '
     
' }, {type: 'break', id:'break2', mobile:false}, {type: 'html', id: 'LanguageStatus', mobile: false, html: '
     
' } ]); // Remove irrelevant toolbars $('#formulabar').hide(); $('#spreadsheet-toolbar').hide(); break; case 'drawing': toolbarUp.remove('insertannotation', 'wraptextseparator', 'wraptext', 'togglemergecells', 'break-toggle', 'numberformatcurrency', 'numberformatpercent', 'numberformatdecimal', 'numberformatdate', 'numberformatincdecimals', 'numberformatdecdecimals', 'break-number', 'sortascending', 'sortdescending'); // Remove irrelevant toolbars $('#formulabar').hide(); $('#spreadsheet-toolbar').hide(); break; } toolbarUp.refresh(); statusbar.refresh(); resizeToolbar(); }); map.on('commandstatechanged', function (e) { var toolbar = w2ui['toolbar-up']; var statusbar = w2ui['toolbar-down']; var commandName = e.commandName; var state = e.state; var found = false; var value, color, div; if (commandName === '.uno:AssignLayout') { $('.styles-select').val(state).trigger('change'); } else if (commandName === '.uno:StyleApply') { if (!state) { return; } // For impress documents, no styles is supported. if (map.getDocType() === 'presentation') { return; } $('.styles-select option').each(function () { var value = this.value; // For writer we get UI names; ideally we should be getting only programmatic ones // For eg: 'Text body' vs 'Text Body' // (likely to be fixed in core to make the pattern consistent) if (state && value.toLowerCase() === state.toLowerCase()) { state = value; found = true; return; } }); if (!found) { // we need to add the size $('.styles-select') .append($('') .text(state)); } stylesSelectValue = state; $('.styles-select').val(state).trigger('change'); } else if (commandName === '.uno:CharFontName') { $('.fonts-select option').each(function () { value = this.value; if (value.toLowerCase() === state.toLowerCase()) { found = true; updateFontSizeList(value); return; } }); if (!found) { // we need to add the size $('.fonts-select') .append($('') .text(state)); } fontsSelectValue = state; $('.fonts-select').val(state).trigger('change'); } else if (commandName === '.uno:FontHeight') { if (state === '0') { state = ''; } $('.fontsizes-select option').each(function (i, e) { if ($(e).text() === state) { found = true; return; } }); if (!found) { // we need to add the size $('.fontsizes-select') .append($('') .text(state).val(state)); } fontsizesSelectValue = state; $('.fontsizes-select').val(state).trigger('change'); sortFontSizes(); } else if (commandName === '.uno:FontColor' || commandName === '.uno:Color') { // confusingly, the .uno: command is named differently in Writer, Calc and Impress color = parseInt(e.state); if (color === -1) { color = 'transparent'; } else { color = color.toString(16); color = '#' + Array(7 - color.length).join('0') + color; } div = L.DomUtil.get('fontcolorindicator'); if (div) { L.DomUtil.setStyle(div, 'background', color); } } else if (commandName === '.uno:BackColor' || commandName === '.uno:BackgroundColor' || commandName === '.uno:CharBackColor') { // confusingly, the .uno: command is named differently in Writer, Calc and Impress color = parseInt(e.state); if (color === -1) { color = 'transparent'; } else { color = color.toString(16); color = '#' + Array(7 - color.length).join('0') + color; } div = L.DomUtil.get('backcolorindicator'); if (div) { L.DomUtil.setStyle(div, 'background', color); } } else if (commandName === '.uno:LanguageStatus') { updateToolbarItem(statusbar, 'LanguageStatus', $('#LanguageStatus').html(_(state)).parent().html()); } else if (commandName === '.uno:ModifiedStatus') { var modifiedStatus = e.state === 'true'; var html; if (modifiedStatus) { html = $('#modifiedstatuslabel').html('').parent().html(); } else { html = $('#modifiedstatuslabel').html(_('Document saved')).parent().html(); } updateToolbarItem(statusbar, 'modifiedstatuslabel', html); } else if (commandName === '.uno:StatusDocPos') { state = toLocalePattern('Sheet %1 of %2', 'Sheet (\\d+) of (\\d+)', state, '%1', '%2'); updateToolbarItem(statusbar, 'StatusDocPos', $('#StatusDocPos').html(state ? state : '     ').parent().html()); } else if (commandName === '.uno:RowColSelCount') { state = toLocalePattern('$1 rows, $2 columns selected', '(\\d+) rows, (\\d+) columns selected', state, '$1', '$2'); state = toLocalePattern('$1 of $2 records found', '(\\d+) of (\\d+) records found', state, '$1', '$2'); updateToolbarItem(statusbar, 'RowColSelCount', $('#RowColSelCount').html(state ? state : '     ').parent().html()); } else if (commandName === '.uno:InsertMode') { updateToolbarItem(statusbar, 'InsertMode', $('#InsertMode').html(state ? L.Styles.insertMode[state].toLocaleString() : '     ').parent().html()); } else if (commandName === '.uno:StatusSelectionMode' || commandName === '.uno:SelectionMode') { updateToolbarItem(statusbar, 'StatusSelectionMode', $('#StatusSelectionMode').html(state ? L.Styles.selectionMode[state].toLocaleString() : '     ').parent().html()); } else if (commandName == '.uno:StateTableCell') { updateToolbarItem(statusbar, 'StateTableCell', $('#StateTableCell').html(state ? localizeStateTableCell(state) : '     ').parent().html()); } else if (commandName === '.uno:StatusBarFunc') { if (state) { selectItem(statusbar.get('StateTableCellMenu'), state); } } else if (commandName === '.uno:StatePageNumber') { state = toLocalePattern('Page %1 of %2', 'Page (\\d+) of (\\d+)', state, '%1', '%2'); updateToolbarItem(statusbar, 'StatePageNumber', $('#StatePageNumber').html(state ? state : '     ').parent().html()); } else if (commandName === '.uno:StateWordCount') { state = toLocalePattern('%1 words, %2 characters', '([\\d,]+) words, ([\\d,]+) characters', state, '%1', '%2'); updateToolbarItem(statusbar, 'StateWordCount', $('#StateWordCount').html(state ? state : '     ').parent().html()); } else if (commandName === '.uno:PageStatus') { state = toLocalePattern('Slide %1 of %2', 'Slide (\\d+) of (\\d+)', state, '%1', '%2'); updateToolbarItem(statusbar, 'PageStatus', $('#PageStatus').html(state ? state : '     ').parent().html()); } else if (commandName === '.uno:DocumentRepair') { if (state === 'true') { toolbar.enable('repair'); } else { toolbar.disable('repair'); } } var id = unoCmdToToolbarId(commandName); if (state === 'true') { toolbar.enable(id); toolbar.check(id); } else if (state === 'false') { toolbar.enable(id); toolbar.uncheck(id); } // Change the toolbar button states if we are in editmode // If in non-edit mode, will be taken care of when permission is changed to 'edit' else if (map._permission === 'edit' && (state === 'enabled' || state === 'disabled')) { if (state === 'enabled') { toolbar.enable(id); } else { toolbar.uncheck(id); toolbar.disable(id); } } }); map.on('search', function (e) { var searchInput = L.DomUtil.get('search-input'); var toolbar = w2ui['toolbar-down']; if (e.count === 0) { toolbar.disable('searchprev'); toolbar.disable('searchnext'); toolbar.hide('cancelsearch'); L.DomUtil.addClass(searchInput, 'search-not-found'); $('#findthis').addClass('search-not-found'); map.resetSelection(); setTimeout(function () { $('#findthis').removeClass('search-not-found'); L.DomUtil.removeClass(searchInput, 'search-not-found'); }, 500); } }); function updateCommandValues() { var data = []; // 1) For .uno:StyleApply // we need an empty option for the place holder to work if ($('.styles-select option').length === 0) { var styles = []; var topStyles = []; var commandValues = map.getToolbarCommandValues('.uno:StyleApply'); if (typeof commandValues === 'undefined') return; var commands = commandValues.Commands; if (commands && commands.length > 0) { // Inserts a separator element data = data.concat({text: '\u2500\u2500\u2500\u2500\u2500\u2500', disabled: true}); commands.forEach(function (command) { var translated = command.text; if (L.Styles.styleMappings[command.text]) { // if it's in English, translate it translated = L.Styles.styleMappings[command.text].toLocaleString(); } data = data.concat({id: command.id, text: translated }); }, this); } if (map.getDocType() === 'text') { styles = commandValues.ParagraphStyles.slice(7, 19); topStyles = commandValues.ParagraphStyles.slice(0, 7); } else if (map.getDocType() === 'spreadsheet') { styles = commandValues.CellStyles; } else if (map.getDocType() === 'presentation') { // styles are not applied for presentation return; } if (topStyles.length > 0) { // Inserts a separator element data = data.concat({text: '\u2500\u2500\u2500\u2500\u2500\u2500', disabled: true}); topStyles.forEach(function (style) { data = data.concat({id: style, text: L.Styles.styleMappings[style].toLocaleString()}); }, this); } if (styles !== undefined && styles.length > 0) { // Inserts a separator element data = data.concat({text: '\u2500\u2500\u2500\u2500\u2500\u2500', disabled: true}); styles.forEach(function (style) { var localeStyle; if (style.startsWith('outline')) { var outlineLevel = style.split('outline')[1]; localeStyle = 'Outline'.toLocaleString() + ' ' + outlineLevel; } else { localeStyle = L.Styles.styleMappings[style]; localeStyle = localeStyle === undefined ? style : localeStyle.toLocaleString(); } data = data.concat({id: style, text: localeStyle}); }, this); } $('.styles-select').select2({ data: data, placeholder: _('Style') }); $('.styles-select').val(stylesSelectValue).trigger('change'); $('.styles-select').on('select2:select', onStyleSelect); } if ($('.fonts-select option').length === 0) { // 2) For .uno:CharFontName commandValues = map.getToolbarCommandValues('.uno:CharFontName'); if (typeof commandValues === 'undefined') { return; } data = []; // reset data in order to avoid that the font select box is populated with styles, too. // Old browsers like IE11 et al don't like Object.keys with // empty arguments if (typeof commandValues === 'object') { data = data.concat(Object.keys(commandValues)); } $('.fonts-select').select2({ data: data.sort(function (a, b) { // also sort(localely) return a.localeCompare(b); }), placeholder: _('Font') }); $('.fonts-select').on('select2:select', onFontSelect); $('.fonts-select').val(fontsSelectValue).trigger('change'); } if ($('.fontsizes-select option').length === 0) { $('.fontsizes-select').select2({ placeholder: _('Size'), data: [] }); $('.fontsizes-select').on('select2:select', onFontSizeSelect); if (fontsSelectValue) { updateFontSizeList(fontsSelectValue); } $('.fontsizes-select').val(fontsizesSelectValue).trigger('change'); } } map.on('updatetoolbarcommandvalues', function() { w2ui['toolbar-up'].refresh(); }); map.on('updateparts pagenumberchanged', function (e) { if (e.docType === 'text') { var current = e.currentPage; var count = e.pages; } else { current = e.selectedPart; count = e.parts; } var toolbar = w2ui['toolbar-down']; if (e.docType === 'presentation') { toolbar.set('prev', {hint: _('Previous slide')}); toolbar.set('next', {hint: _('Next slide')}); } else { toolbar.hide('presentation'); toolbar.hide('insertpage'); toolbar.hide('duplicatepage'); toolbar.hide('deletepage'); } if (e.docType !== 'spreadsheet') { if (current === 0) { toolbar.disable('prev'); } else { toolbar.enable('prev'); } if (current === count - 1) { toolbar.disable('next'); } else { toolbar.enable('next'); } } toolbar = w2ui['toolbar-up']; if (e.docType !== 'text' && e.docType !== 'spreadsheet') { toolbar.hide('incrementindent'); toolbar.hide('decrementindent'); toolbar.hide('incdecindent'); } toolbar = w2ui['spreadsheet-toolbar']; if (e.docType === 'spreadsheet') { toolbar.show('firstrecord'); toolbar.show('nextrecord'); toolbar.show('prevrecord'); toolbar.show('lastrecord'); toolbar.show('insertsheet'); } }); map.on('commandresult', function (e) { var commandName = e.commandName; if (commandName === '.uno:Save') { if (e.success) { // Saved a new version; the document is modified. map._everModified = true; } var postMessageObj = { success: e.success }; if (!e.success) { // add the result reason string if failed postMessageObj['result'] = e.result && e.result.value; } map.fire('postMessage', {msgId: 'Action_Save_Resp', args: postMessageObj}); } else if ((commandName === '.uno:Undo' || commandName === '.uno:Redo') && e.success === true && e.result.value && !isNaN(e.result.value)) { /*UNDO_CONFLICT*/ $('#tb_toolbar-up_item_repair').w2overlay({ html: '
' + _('Conflict Undo/Redo with multiple users. Please use document repair to resolve') + '
'}); } }); map.on('celladdress', function (e) { if (document.activeElement !== L.DomUtil.get('addressInput')) { // if the user is not editing the address field L.DomUtil.get('addressInput').value = e.address; } }); map.on('cellformula', function (e) { if (document.activeElement !== L.DomUtil.get('formulaInput')) { // if the user is not editing the formula bar L.DomUtil.get('formulaInput').value = e.formula; } }); map.on('zoomend', function () { var zoomRatio = map.getZoomScale(map.getZoom(), map.options.zoom); var zoomPercent = Math.round(zoomRatio * 100); $('#zoomlevel').html(zoomPercent + '%'); }); map.on('hyperlinkclicked', function (e) { window.open(e.url, '_blank'); }); map.on('updatepermission', function (e) { var toolbar = w2ui['toolbar-up']; // copy the first array var items = toolbar.items.slice(); for (var idx in items) { var unoCmd = map.getDocType() === 'spreadsheet' ? items[idx].unosheet : items[idx].uno; var keepDisabled = map['stateChangeHandler'].getItemValue(unoCmd) === 'disabled'; if (e.perm === 'edit') { if (!keepDisabled) { toolbar.enable(items[idx].id); } } else { toolbar.disable(items[idx].id); } } var spreadsheetButtons = ['firstrecord', 'prevrecord', 'nextrecord', 'lastrecord', 'insertsheet']; var formulaBarButtons = ['sum', 'function']; var presentationButtons = ['insertpage', 'duplicatepage', 'deletepage']; var toolbarDownButtons = ['next', 'prev']; if (e.perm === 'edit') { // Enable list boxes $('.styles-select').prop('disabled', false); $('.fonts-select').prop('disabled', false); $('.fontsizes-select').prop('disabled', false); // Enable formula bar $('#addressInput').prop('disabled', false); $('#formulaInput').prop('disabled', false); toolbar = w2ui.formulabar; formulaBarButtons.forEach(function(id) { toolbar.enable(id); }); toolbar = w2ui['spreadsheet-toolbar']; spreadsheetButtons.forEach(function(id) { toolbar.enable(id); }); toolbar = w2ui['presentation-toolbar']; presentationButtons.forEach(function(id) { toolbar.enable(id); }); toolbar = w2ui['toolbar-down']; toolbarDownButtons.forEach(function(id) { toolbar.enable(id); }); $('#search-input').prop('disabled', false); } else { // Disable list boxes $('.styles-select').prop('disabled', true); $('.fonts-select').prop('disabled', true); $('.fontsizes-select').prop('disabled', true); // Disable formula bar $('#addressInput').prop('disabled', true); $('#formulaInput').prop('disabled', true); toolbar = w2ui.formulabar; formulaBarButtons.forEach(function(id) { toolbar.disable(id); }); toolbar = w2ui['spreadsheet-toolbar']; spreadsheetButtons.forEach(function(id) { toolbar.disable(id); }); toolbar = w2ui['presentation-toolbar']; presentationButtons.forEach(function(id) { toolbar.disable(id); }); toolbar = w2ui['toolbar-down']; toolbarDownButtons.forEach(function(id) { toolbar.disable(id); }); $('#search-input').prop('disabled', true); } }); map.on('keydown', function (e) { if (e.originalEvent.ctrlKey && !e.originalEvent.altKey && (e.originalEvent.key === 'f' || e.originalEvent.key === 'F')) { var entry = L.DomUtil.get('search-input'); entry.focus(); entry.select(); e.originalEvent.preventDefault(); } }); function goToViewId(id) { var docLayer = map._docLayer; if (id === -1) return; if (map.getDocType() === 'spreadsheet') { docLayer.goToCellViewCursor(id); } else if (map.getDocType() === 'text' || map.getDocType() === 'presentation') { docLayer.goToViewCursor(id); } } function onUseritemClicked(e) { var docLayer = map._docLayer; var viewId = parseInt(e.currentTarget.id.replace('user-', '')); goToViewId(viewId); if (viewId === map._docLayer._viewId) { $('#tb_toolbar-down_item_userlist').w2overlay(''); return; } else if (docLayer._followThis !== -1) { map.fire('setFollowOff'); } docLayer._followThis = viewId; docLayer._followUser = true; docLayer._followEditor = false; selectUser(viewId); } function editorUpdate(e) { var docLayer = map._docLayer; if (e.target.checked) { var editorId = docLayer._editorId; var userlistItem = w2ui['toolbar-down'].get('userlist'); docLayer._followUser = false; docLayer._followEditor = true; if (editorId !== -1 && editorId !== docLayer.viewId) { goToViewId(editorId); docLayer._followThis = editorId; } $('.selected-user').removeClass('selected-user'); if ($(userlistItem.html).find('.selected-user').length !== 0) userlistItem.html = $(userlistItem.html).find('.selected-user').removeClass('selected-user').parent().parent().parent()[0].outerHTML; } else { docLayer._followEditor = false; docLayer._followThis = -1; } $('#tb_toolbar-down_item_userlist').w2overlay(''); } function selectUser(viewId) { var userlistItem = w2ui['toolbar-down'].get('userlist'); userlistItem.html = $(userlistItem.html).find('#user-' + viewId).addClass('selected-user').parent().parent().parent()[0].outerHTML; $('#tb_toolbar-down_item_userlist').w2overlay(''); } function deselectUser(viewId) { var userlistItem = w2ui['toolbar-down'].get('userlist'); userlistItem.html = $(userlistItem.html).find('#user-' + viewId).removeClass('selected-user').parent().parent().parent()[0].outerHTML; } function getUserItem(viewId, userName, extraInfo, color) { var className = 'useritem'; if (extraInfo !== undefined && extraInfo.avatar !== undefined) { className = 'useritem-avatar'; } var html = '' + ''; if (extraInfo !== undefined && extraInfo.avatar !== undefined) { html += ''; } // TODO: Add mail and other links as sub-menu. html += '' + '' + userName + '' + ''; return html; } function updateUserListCount() { var userlistItem = w2ui['toolbar-down'].get('userlist'); var count = $(userlistItem.html).find('#userlist_table tbody tr').length; if (count > 1) { userlistItem.text = nUsers.replace('%n', count); } else if (count === 1) { userlistItem.text = oneUser; } else { userlistItem.text = noUser; } var zoomlevel = $('#zoomlevel').html(); w2ui['toolbar-down'].refresh(); $('#zoomlevel').html(zoomlevel); } map.on('addview', function(e) { $('#tb_toolbar-down_item_userlist') .w2overlay({ class: 'loleaflet-font', html: userJoinedPopupMessage.replace('%user', e.username), style: 'padding: 5px' }); clearTimeout(userPopupTimeout); userPopupTimeout = setTimeout(function() { $('#tb_toolbar-down_item_userlist').w2overlay(''); clearTimeout(userPopupTimeout); userPopupTimeout = null; }, 3000); var username = e.username; var color = L.LOUtil.rgbToHex(map.getViewColor(e.viewId)); if (e.viewId === map._docLayer._viewId) { username = _('You'); color = '#000'; } // Mention readonly sessions in userlist if (e.readonly) { username += ' (' + _('Readonly') + ')'; } var userlistItem = w2ui['toolbar-down'].get('userlist'); var newhtml = $(userlistItem.html).find('#userlist_table tbody').append(getUserItem(e.viewId, username, e.extraInfo, color)).parent().parent()[0].outerHTML; userlistItem.html = newhtml; updateUserListCount(); }); map.on('removeview', function(e) { $('#tb_toolbar-down_item_userlist') .w2overlay({ class: 'loleaflet-font', html: userLeftPopupMessage.replace('%user', e.username), style: 'padding: 5px' }); clearTimeout(userPopupTimeout); userPopupTimeout = setTimeout(function() { $('#tb_toolbar-down_item_userlist').w2overlay(''); clearTimeout(userPopupTimeout); userPopupTimeout = null; }, 3000); if (e.viewId === map._docLayer._followThis) { map._docLayer._followThis = -1; map._docLayer._followUser = false; } var userlistItem = w2ui['toolbar-down'].get('userlist'); userlistItem.html = $(userlistItem.html).find('#user-' + e.viewId).remove().end()[0].outerHTML; updateUserListCount(); }); map.on('updateEditorName', function(e) { $('#currently-msg').show(); $('#current-editor').text(e.username); }); map.on('setFollowOff', function() { var docLayer = map._docLayer; var viewId = docLayer._followThis; if (viewId !== -1 && map._viewInfo[viewId]) { deselectUser(viewId); } docLayer._followThis = -1; docLayer._followUser = false; docLayer._followEditor = false; }); $(window).resize(function() { resizeToolbar(); }); $(document).ready(function() { if (!closebutton) { $('#closebuttonwrapper').hide(); } else { $('#closebutton').click(function() { map.fire('postMessage', {msgId: 'close', args: {EverModified: map._everModified, Deprecated: true}}); map.fire('postMessage', {msgId: 'UI_Close', args: {EverModified: map._everModified}}); map.remove(); }); } // Attach insert file action $('#insertgraphic').on('change', onInsertFile); });