xref: /online/loleaflet/src/control/Control.Menubar.js (revision f7f4464b3c835ccaacf5519ad7ef9ef0bc98d668)
1/* -*- js-indent-level: 8 -*- */
2/*
3* Control.Menubar
4*/
5
6/* global $ _ _UNO vex L */
7L.Control.Menubar = L.Control.extend({
8	// TODO: Some mechanism to stop the need to copy duplicate menus (eg. Help)
9	options: {
10		initial: [
11			{name: _UNO('.uno:PickList')},
12			{name: _UNO('.uno:EditMenu')},
13			{name: _UNO('.uno:ViewMenu')},
14			{name: _UNO('.uno:InsertMenu')},
15			{name: _UNO('.uno:ToolsMenu')}
16		],
17		text:  [
18			{name: _UNO('.uno:PickList', 'text'), id: 'file', type: 'menu', menu: [
19				{name: _UNO('.uno:Save', 'text'), id: 'save', type: 'action'},
20				{name: _UNO('.uno:SaveAs', 'text'), id: 'saveas', type: 'action'},
21				{name: _('Share...'), id:'shareas', type: 'action'},
22				{name: _UNO('.uno:Print', 'text'), id: 'print', type: 'action'},
23				{name: _('See revision history'), id: 'rev-history', type: 'action'},
24				{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id: 'downloadas', type: 'menu', menu: [
25					{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
26					{name: _('ODF text document (.odt)'), id: 'downloadas-odt', type: 'action'},
27					{name: _('Word 2003 Document (.doc)'), id: 'downloadas-doc', type: 'action'},
28					{name: _('Word Document (.docx)'), id: 'downloadas-docx', type: 'action'},
29					{name: _('Rich Text (.rtf)'), id: 'downloadas-rtf', type: 'action'},
30					{name: _('EPUB (.epub)'), id: 'downloadas-epub', type: 'action'}]},
31				{name: _('Sign document'), id: 'signdocument', type: 'action'},
32				{type: 'separator'},
33				{name: _('Close document'), id: 'closedocument', type: 'action'}
34			]},
35			{name: _UNO('.uno:EditMenu', 'text'), id: 'editmenu', type: 'menu', menu: [
36				{uno: '.uno:Undo'},
37				{uno: '.uno:Redo'},
38				{name: _('Repair'), id: 'repair',  type: 'action'},
39				{type: 'separator'},
40				{uno: '.uno:Cut'},
41				{uno: '.uno:Copy'},
42				{uno: '.uno:Paste'},
43				{uno: '.uno:SelectAll'},
44				{type: 'separator'},
45				{uno: '.uno:SearchDialog'},
46				{type: 'separator'},
47				{name: _UNO('.uno:ChangesMenu', 'text'), id: 'changesmenu', type: 'menu', menu: [
48					{uno: '.uno:TrackChanges'},
49					{uno: '.uno:ShowTrackedChanges'},
50					{type: 'separator'},
51					{uno: '.uno:AcceptTrackedChanges'},
52					{uno: '.uno:AcceptAllTrackedChanges'},
53					{uno: '.uno:RejectAllTrackedChanges'},
54					{uno: '.uno:PreviousTrackedChange'},
55					{uno: '.uno:NextTrackedChange'}
56				]},
57				{uno: '.uno:EditStyle'}
58			]},
59			{name: _UNO('.uno:ViewMenu', 'text'), id: 'view', type: 'menu',
60			 menu: (window.mode.isTablet() ? [] : [
61				{name: _UNO('.uno:FullScreen', 'text'), id: 'fullscreen', type: 'action'},
62				{type: 'separator'},
63				{name: _UNO('.uno:ZoomPlus', 'text'), id: 'zoomin', type: 'action'},
64				{name: _UNO('.uno:ZoomMinus', 'text'), id: 'zoomout', type: 'action',},
65				{name: _('Reset zoom'), id: 'zoomreset', type: 'action'},
66				{name: _('Show Ruler'), id: 'showruler', type: 'action'},
67				{name: _('Show Status Bar'), id: 'showstatusbar', type: 'action'},
68				{type: 'separator'},
69			]).concat([
70				{uno: '.uno:ControlCodes'},
71				{type: 'separator'},
72				{name: _UNO('.uno:ShowResolvedAnnotations', 'text'), id: 'showresolved', type: 'action'},
73				{type: 'separator'},
74				{uno: '.uno:Sidebar'},
75			])},
76			{name: _UNO('.uno:InsertMenu', 'text'), id: 'insert', type: 'menu', menu: [
77				{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
78				{name: _UNO('.uno:InsertGraphic', 'text'), id: 'insertgraphicremote', type: 'action'},
79				{name: _UNO('.uno:InsertAnnotation', 'text'), id: 'insertcomment', type: 'action'},
80				{uno: '.uno:InsertObjectChart'},
81				{type: 'separator'},
82				{uno: '.uno:InsertSection', id: 'insertsection'},
83				{name: _UNO('.uno:InsertField', 'text'), type: 'menu', menu: [
84					{uno: '.uno:InsertPageNumberField'},
85					{uno: '.uno:InsertPageCountField'},
86					{uno: '.uno:InsertDateField'},
87					{uno: '.uno:InsertTimeField'},
88					{uno: '.uno:InsertTitleField'},
89					{uno: '.uno:InsertAuthorField'},
90					{uno: '.uno:InsertTopicField'}
91				]},
92				{name: _UNO('.uno:InsertHeaderFooterMenu', 'text'), type: 'menu', menu: [
93					{name: _UNO('.uno:InsertPageHeader', 'text'), type: 'menu', menu: [
94						{name: _('All'), disabled: true, id: 'insertheader', tag: '_ALL_', uno: '.uno:InsertPageHeader?'}]},
95					{name: _UNO('.uno:InsertPageFooter', 'text'), type: 'menu', menu: [
96						{name: _('All'), disabled: true, id: 'insertfooter', tag: '_ALL_', uno: '.uno:InsertPageFooter?'}]}
97				]},
98				{uno: '.uno:InsertFootnote'},
99				{uno: '.uno:InsertEndnote'},
100				{type: 'separator'},
101				{uno: '.uno:InsertPagebreak'},
102				{name: _UNO('.uno:InsertColumnBreak', 'spreadsheet'), uno: '.uno:InsertColumnBreak'},
103				{type: 'separator'},
104				{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
105				{uno: '.uno:InsertSymbol'},
106				{name: _UNO('.uno:FormattingMarkMenu', 'text'), type: 'menu', menu: [
107					{uno: '.uno:InsertNonBreakingSpace'},
108					{uno: '.uno:InsertHardHyphen'},
109					{uno: '.uno:InsertSoftHyphen'},
110					{uno: '.uno:InsertZWSP'},
111					{uno: '.uno:InsertZWNBSP'},
112					{uno: '.uno:InsertLRM'},
113					{uno: '.uno:InsertRLM'}]},
114				{name: _UNO('.uno:IndexesMenu', 'text'), type: 'menu', menu: [
115					{uno: '.uno:InsertIndexesEntry'},
116					{uno: '.uno:InsertAuthoritiesEntry'},
117					{uno: '.uno:InsertMultiIndex'}]},
118			]},
119			{name: _UNO('.uno:FormatMenu', 'text'), id: 'format', type: 'menu', menu: [
120				{name: _UNO('.uno:FormatTextMenu', 'text'), type: 'menu', menu: [
121					{uno: '.uno:Bold'},
122					{uno: '.uno:Italic'},
123					{uno: '.uno:Underline'},
124					{uno: '.uno:UnderlineDouble'},
125					{uno: '.uno:Strikeout'},
126					{uno: '.uno:Overline'},
127					{type: 'separator'},
128					{uno: '.uno:SuperScript'},
129					{uno: '.uno:SubScript'},
130					{uno: '.uno:SmallCaps'},
131					{type: 'separator'},
132					{uno: '.uno:Shadowed'},
133					{uno: '.uno:OutlineFont'},
134					{type: 'separator'},
135					{uno: '.uno:Grow'},
136					{uno: '.uno:Shrink'},
137					{type: 'separator'},
138					{uno: '.uno:ChangeCaseToUpper'},
139					{uno: '.uno:ChangeCaseToLower'},
140					{uno: '.uno:ChangeCaseRotateCase'},
141					{type: 'separator'},
142					{uno: '.uno:ChangeCaseToSentenceCase'},
143					{uno: '.uno:ChangeCaseToTitleCase'},
144					{uno: '.uno:ChangeCaseToToggleCase'}]},
145				{name: _('Text orientation'), type: 'menu', menu: [
146					{uno: '.uno:ParaLeftToRight'},
147					{uno: '.uno:ParaRightToLeft'}]},
148				{name: _UNO('.uno:FormatSpacingMenu', 'text'), type: 'menu', menu: [
149					{uno: '.uno:SpacePara1'},
150					{uno: '.uno:SpacePara15'},
151					{uno: '.uno:SpacePara2'},
152					{type: 'separator'},
153					{uno: '.uno:ParaspaceIncrease'},
154					{uno: '.uno:ParaspaceDecrease'},
155					{type: 'separator'},
156					{uno: '.uno:IncrementIndent'},
157					{uno: '.uno:DecrementIndent'}]},
158				{name: _UNO('.uno:TextAlign', 'text'), type: 'menu', menu: [
159					{uno: '.uno:CommonAlignLeft'},
160					{uno: '.uno:CommonAlignHorizontalCenter'},
161					{uno: '.uno:CommonAlignRight'},
162					{uno: '.uno:CommonAlignJustified'},
163					{type: 'separator'},
164					{uno: '.uno:CommonAlignTop'},
165					{uno: '.uno:CommonAlignVerticalCenter'},
166					{uno: '.uno:CommonAlignBottom'}]},
167				{name: _UNO('.uno:FormatBulletsMenu', 'text'), type: 'menu', menu: [
168					{uno: '.uno:DefaultBullet'},
169					{uno: '.uno:DefaultNumbering'},
170					{type: 'separator'},
171					{uno: '.uno:DecrementLevel'},
172					{uno: '.uno:IncrementLevel'},
173					{uno: '.uno:DecrementSubLevels'},
174					{uno: '.uno:IncrementSubLevels'},
175					{type: 'separator'},
176					{uno: '.uno:MoveDown'},
177					{uno: '.uno:MoveUp'},
178					{uno: '.uno:MoveDownSubItems'},
179					{uno: '.uno:MoveUpSubItems'},
180					{type: 'separator'},
181					{uno: '.uno:InsertNeutralParagraph'},
182					{uno: '.uno:NumberingStart'},
183					{type: 'separator'},
184					{uno: '.uno:JumpDownThisLevel'},
185					{uno: '.uno:JumpUpThisLevel'},
186					{uno: '.uno:ContinueNumbering'}]},
187				{type: 'separator'},
188				{uno: '.uno:FontDialog'},
189				{uno: '.uno:ParagraphDialog'},
190				{uno: '.uno:OutlineBullet'},
191				{uno: '.uno:PageDialog'},
192				{uno: '.uno:EditRegion'},
193				{uno: '.uno:TitlePageDialog'},
194				{type: 'separator'},
195				{uno: '.uno:TransformDialog'},
196				{uno: '.uno:FormatLine'},
197				{uno: '.uno:FormatArea'},
198				{type: 'separator'},
199				{uno: '.uno:Watermark'},
200				{type: 'separator'},
201				{uno: '.uno:FormatColumns'},
202				{type: 'separator'},
203				{uno: '.uno:ResetAttributes'}
204			]},
205			{name: _UNO('.uno:TableMenu', 'text'), type: 'menu', menu: [
206				{uno: '.uno:InsertTable'},
207				{name: _UNO('.uno:TableInsertMenu', 'text'), type: 'menu', menu: [
208					{uno: '.uno:InsertRowsBefore'},
209					{uno: '.uno:InsertRowsAfter'},
210					{type: 'separator'},
211					{uno: '.uno:InsertColumnsBefore'},
212					{uno: '.uno:InsertColumnsAfter'}]},
213				{name: _UNO('.uno:TableDeleteMenu', 'text'), type: 'menu', menu: [
214					{uno: '.uno:DeleteRows'},
215					{uno: '.uno:DeleteColumns'},
216					{uno: '.uno:DeleteTable'}]},
217				{name: _UNO('.uno:TableSelectMenu', 'text'), type: 'menu', menu: [
218					{uno: '.uno:SelectTable'},
219					{uno: '.uno:EntireRow'},
220					{uno: '.uno:EntireColumn'},
221					{uno: '.uno:EntireCell'}]},
222				{uno: '.uno:MergeCells'},
223				{type: 'separator'},
224				{uno: '.uno:TableDialog'}
225			]},
226			{name: _UNO('.uno:ToolsMenu', 'text'), id: 'tools', type: 'menu', menu: [
227				{uno: '.uno:SpellingAndGrammarDialog'},
228				{uno: '.uno:SpellOnline'},
229				{uno: '.uno:ThesaurusDialog'},
230				{name: _UNO('.uno:LanguageMenu'), type: 'menu', menu: [
231					{name: _UNO('.uno:SetLanguageSelectionMenu', 'text'), type: 'menu', menu: [
232						{name: _('None (Do not check spelling)'), id: 'noneselection', uno: '.uno:LanguageStatus?Language:string=Current_LANGUAGE_NONE'}]},
233					{name: _UNO('.uno:SetLanguageParagraphMenu', 'text'), type: 'menu', menu: [
234						{name: _('None (Do not check spelling)'), id: 'noneparagraph', uno: '.uno:LanguageStatus?Language:string=Paragraph_LANGUAGE_NONE'}]},
235					{name: _UNO('.uno:SetLanguageAllTextMenu', 'text'), type: 'menu', menu: [
236						{name: _('None (Do not check spelling)'), id: 'nonelanguage', uno: '.uno:LanguageStatus?Language:string=Default_LANGUAGE_NONE'}]}
237				]},
238				{uno: '.uno:WordCountDialog'},
239				{uno: '.uno:LineNumberingDialog'},
240				{type: 'separator'},
241				{name: _UNO('.uno:AutoFormatMenu', 'text'), type: 'menu', menu: [
242					{uno: '.uno:OnlineAutoFormat'}]}
243			]},
244			{name: _UNO('.uno:HelpMenu', 'text'), id: 'help', type: 'menu', menu: [
245				{name: _('Online Help'), id: 'online-help', type: 'action', iosapp: false},
246				{name: _('Keyboard shortcuts'), id: 'keyboard-shortcuts', type: 'action', iosapp: false},
247				{name: _('Report an issue'), id: 'report-an-issue', type: 'action', iosapp: false},
248				{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
249				{name: _('About'), id: 'about', type: 'action'}]
250			},
251			{name: _('Last modification'), id: 'last-mod', type: 'action', tablet: false}
252		],
253
254		presentation: [
255			{name: _UNO('.uno:PickList', 'presentation'), id: 'file', type: 'menu', menu: [
256				{name: _UNO('.uno:Save', 'presentation'), id: 'save', type: 'action'},
257				{name: _UNO('.uno:SaveAs', 'presentation'), id: 'saveas', type: 'action'},
258				{name: _('Save Comments'), id: 'savecomments', type: 'action'},
259				{name: _('Share...'), id:'shareas', type: 'action'},
260				{name: _UNO('.uno:Print', 'presentation'), id: 'print', type: 'action'},
261				{name: _('See revision history'), id: 'rev-history', type: 'action'},
262				{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id: 'downloadas', type: 'menu', menu: [
263					{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
264					{name: _('ODF presentation (.odp)'), id: 'downloadas-odp', type: 'action', drawing: false},
265					{name: _('PowerPoint 2003 Presentation (.ppt)'), id: 'downloadas-ppt', type: 'action', drawing: false},
266					{name: _('PowerPoint Presentation (.pptx)'), id: 'downloadas-pptx', type: 'action', drawing: false},
267					{name: _('ODF Drawing (.odg)'), id: 'downloadas-odg', type: 'action'}
268				]},
269				{type: 'separator'},
270				{name: _('Close document'), id: 'closedocument', type: 'action'}
271			]},
272			{name: _UNO('.uno:EditMenu', 'presentation'), id: 'editmenu', type: 'menu', menu: [
273				{uno: '.uno:Undo'},
274				{uno: '.uno:Redo'},
275				{name: _('Repair'), id: 'repair',  type: 'action'},
276				{type: 'separator'},
277				{uno: '.uno:Cut'},
278				{uno: '.uno:Copy'},
279				{uno: '.uno:Paste'},
280				{uno: '.uno:SelectAll'},
281				{type: 'separator'},
282				{uno: '.uno:SearchDialog'}
283			]},
284			{name: _UNO('.uno:ViewMenu', 'presentation'), id: 'view', type: 'menu', menu: [
285				{name: _UNO('.uno:FullScreen', 'presentation'), id: 'fullscreen', type: 'action'},
286				{type: 'separator'},
287				{name: _UNO('.uno:ZoomPlus', 'presentation'), id: 'zoomin', type: 'action'},
288				{name: _UNO('.uno:ZoomMinus', 'presentation'), id: 'zoomout', type: 'action'},
289				{name: _('Reset zoom'), id: 'zoomreset', type: 'action'},
290				{type: 'separator', drawing: false},
291				{uno: '.uno:SlideMasterPage', drawing: false},
292				{type: 'separator', drawing: false},
293				{uno: '.uno:ModifyPage', drawing: false},
294				{uno: '.uno:SlideChangeWindow', drawing: false},
295				{uno: '.uno:CustomAnimation', drawing: false},
296				{uno: '.uno:MasterSlidesPanel', drawing: false},
297				{type: 'separator', drawing: false},
298				{uno: '.uno:Sidebar', drawing: false},
299				{name: _('Show Status Bar'), id: 'showstatusbar', type: 'action'}]
300			},
301			{name: _UNO('.uno:InsertMenu', 'presentation'), id: 'insert', type: 'menu', menu: [
302				{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
303				{name: _UNO('.uno:InsertGraphic', 'presentation'), id: 'insertgraphicremote', type: 'action'},
304				{name: _UNO('.uno:SelectBackground', 'presentation'), id: 'selectbackground', type: 'action'},
305				{name: _UNO('.uno:InsertAnnotation', 'presentation'), id: 'insertcomment', type: 'action'},
306				{uno: '.uno:InsertObjectChart'},
307				{type: 'separator'},
308				{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
309				{type: 'separator'},
310				{uno: '.uno:InsertSymbol'},
311				{type: 'separator'},
312				{uno: '.uno:HeaderAndFooter'},
313				{type: 'separator'},
314				{name: _UNO('.uno:InsertField', 'text'), id: 'insertfield', type: 'menu', menu: [
315					{uno: '.uno:InsertDateFieldFix'},
316					{uno: '.uno:InsertDateFieldVar'},
317					{uno: '.uno:InsertTimeFieldFix'},
318					{uno: '.uno:InsertTimeFieldVar'},
319					{type: 'separator'},
320					{name: _UNO('.uno:InsertSlideField', 'presentation'), id: 'insertslidefield', type: 'action'},
321					{name: _UNO('.uno:InsertSlideTitleField', 'presentation'), id: 'insertslidetitlefield', type: 'action'},
322					{name: _UNO('.uno:InsertSlidesField', 'presentation'), id: 'insertslidesfield', type: 'action'},
323				]},
324			]},
325			{name: _UNO('.uno:FormatMenu', 'presentation'), id: 'format', type: 'menu', menu: [
326				{uno: '.uno:FontDialog'},
327				{uno: '.uno:ParagraphDialog'},
328				{uno: '.uno:PageSetup'},
329				{type: 'separator'},
330				{uno: '.uno:TransformDialog'},
331				{uno: '.uno:FormatLine'},
332				{uno: '.uno:FormatArea'},
333				{type: 'separator'},
334				{uno: '.uno:OutlineBullet'}]
335			},
336			{name: _UNO('.uno:TableMenu', 'text'/*HACK should be 'presentation', but not in xcu*/), type: 'menu', menu: [
337				{name: _UNO('.uno:InsertTable', 'text'), uno: '.uno:InsertTable'},
338				{name: _UNO('.uno:TableInsertMenu', 'text'/*HACK should be 'presentation', but not in xcu*/), type: 'menu', menu: [
339					{uno: '.uno:InsertRowsBefore'},
340					{uno: '.uno:InsertRowsAfter'},
341					{type: 'separator'},
342					{uno: '.uno:InsertColumnsBefore'},
343					{uno: '.uno:InsertColumnsAfter'}]},
344				{name: _UNO('.uno:TableDeleteMenu', 'text'/*HACK should be 'presentation', but not in xcu*/), type: 'menu', menu: [
345					{uno: '.uno:DeleteRows'},
346					{uno: '.uno:DeleteColumns'},
347					{uno: '.uno:DeleteTable'}]},
348				{name: _UNO('.uno:TableSelectMenu', 'text'), type: 'menu', menu: [
349					{uno: '.uno:SelectTable'},
350					{uno: '.uno:EntireRow'},
351					{uno: '.uno:EntireColumn'}]},
352				{uno: '.uno:MergeCells'},
353				{uno: '.uno:TableDialog'}]
354			},
355			{name: _UNO('.uno:SlideMenu', 'presentation'), type: 'menu', menu: [
356				{name: _UNO('.uno:InsertSlide', 'presentation'), id: 'insertpage', type: 'action'},
357				{name: _UNO('.uno:DuplicateSlide', 'presentation'), id: 'duplicatepage', type: 'action'},
358				{name: _UNO('.uno:DeleteSlide', 'presentation'), id: 'deletepage', type: 'action'},
359				{type: 'separator', id: 'fullscreen-presentation-separator'},
360				{name: _('Fullscreen presentation'), id: 'fullscreen-presentation', type: 'action'},
361				{name: _('Present current slide'), id: 'presentation-currentslide', type: 'action'}]
362			},
363			{name: _UNO('.uno:ToolsMenu', 'presentation'), id: 'tools', type: 'menu', menu: [
364				{uno: '.uno:SpellDialog'},
365				{uno: '.uno:SpellOnline'},
366				{name: _UNO('.uno:LanguageMenu'), type: 'menu', menu: [
367					{name: _('None (Do not check spelling)'), id: 'nonelanguage', uno: '.uno:LanguageStatus?Language:string=Default_LANGUAGE_NONE'}]}
368			]},
369			{name: _UNO('.uno:HelpMenu', 'presentation'), id: 'help', type: 'menu', menu: [
370				{name: _('Online Help'), id: 'online-help', type: 'action', iosapp: false},
371				{name: _('Keyboard shortcuts'), id: 'keyboard-shortcuts', type: 'action', iosapp: false},
372				{name: _('Report an issue'), id: 'report-an-issue', type: 'action', iosapp: false},
373				{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
374				{name: _('About'), id: 'about', type: 'action'}]
375			},
376			{name: _('Last modification'), id: 'last-mod', type: 'action', tablet: false}
377		],
378
379		spreadsheet: [
380			{name: _UNO('.uno:PickList', 'spreadsheet'), id: 'file', type: 'menu', menu: [
381				{name: _UNO('.uno:Save', 'spreadsheet'), id: 'save', type: 'action'},
382				{name: _UNO('.uno:SaveAs', 'spreadsheet'), id: 'saveas', type: 'action'},
383				{name: _('Share...'), id:'shareas', type: 'action'},
384				{name: _UNO('.uno:Print', 'spreadsheet'), id: 'print', type: 'action'},
385				{name: _('See revision history'), id: 'rev-history', type: 'action'},
386				{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id:'downloadas', type: 'menu', menu: [
387					{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
388					{name: _('ODF spreadsheet (.ods)'), id: 'downloadas-ods', type: 'action'},
389					{name: _('Excel 2003 Spreadsheet (.xls)'), id: 'downloadas-xls', type: 'action'},
390					{name: _('Excel Spreadsheet (.xlsx)'), id: 'downloadas-xlsx', type: 'action'}]},
391				{type: 'separator'},
392				{name: _('Close document'), id: 'closedocument', type: 'action'}
393			]},
394			{name: _UNO('.uno:EditMenu', 'spreadsheet'), id: 'editmenu', type: 'menu', menu: [
395				{uno: '.uno:Undo'},
396				{uno: '.uno:Redo'},
397				{name: _('Repair'), id: 'repair',  type: 'action'},
398				{type: 'separator'},
399				{uno: '.uno:Cut'},
400				{uno: '.uno:Copy'},
401				{uno: '.uno:Paste'},
402				{uno: '.uno:SelectAll'},
403				{type: 'separator'},
404				{uno: '.uno:SearchDialog'}
405			]},
406			{name: _UNO('.uno:ViewMenu', 'spreadsheet'), id: 'view', type: 'menu', menu: [
407				{name: _UNO('.uno:FullScreen', 'spreadsheet'), id: 'fullscreen', type: 'action'},
408				{type: 'separator'},
409				{name: _UNO('.uno:FreezePanes', 'spreadsheet', true), id: 'FreezePanes', type: 'action', uno: '.uno:FreezePanes'},
410				{name: _UNO('.uno:FreezeCellsMenu', 'spreadsheet', true), id: 'FreezeCellsMenu', type: 'menu', uno: '.uno:FreezeCellsMenu', menu: [
411					{name: _UNO('.uno:FreezePanesColumn', 'spreadsheet', true), id: 'FreezePanesColumn', type: 'action', uno: '.uno:FreezePanesColumn'},
412					{name: _UNO('.uno:FreezePanesRow', 'spreadsheet', true), id: 'FreezePanesRow', type: 'action', uno: '.uno:FreezePanesRow'}
413				]},
414				{type: 'separator'},
415				{uno: '.uno:Sidebar'},
416			]},
417			{name: _UNO('.uno:InsertMenu', 'spreadsheet'), id: 'insert', type: 'menu', menu: [
418				{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
419				{name: _UNO('.uno:InsertGraphic', 'spreadsheet'), id: 'insertgraphicremote', type: 'action'},
420				{uno: '.uno:InsertObjectChart'},
421				{name: _UNO('.uno:InsertAnnotation', 'spreadsheet'), id: 'insertcomment', type: 'action'},
422				{type: 'separator'},
423				{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
424				{uno: '.uno:InsertSymbol'},
425				{uno: '.uno:EditHeaderAndFooter'} /*todo: add to Control.Notebookbar.Calc.js (as Insert tab)*/
426			]},
427			{name: _UNO('.uno:FormatMenu', 'spreadsheet'), id: 'format', type: 'menu', menu: [
428				{uno: '.uno:ResetAttributes'},
429				{uno: '.uno:FormatCellDialog'},
430				{uno: '.uno:PageFormatDialog'},
431				{type: 'separator'},
432				{uno: '.uno:TransformDialog'},
433				{uno: '.uno:FormatLine'},
434				{uno: '.uno:FormatArea'},
435				{type: 'separator'},
436				{name: _UNO('.uno:ConditionalFormatMenu', 'spreadsheet'), type: 'menu', menu: [
437					{uno: '.uno:ConditionalFormatDialog'},
438					{uno: '.uno:ColorScaleFormatDialog'},
439					{uno: '.uno:DataBarFormatDialog'},
440					{uno: '.uno:IconSetFormatDialog'},
441					{uno: '.uno:CondDateFormatDialog'},
442					{type: 'separator'},
443					{uno: '.uno:ConditionalFormatManagerDialog'}]},
444			]},
445			{name: _UNO('.uno:SheetMenu', 'spreadsheet'), type: 'menu', menu: [
446				{name: _UNO('.uno:InsertRowsMenu', 'spreadsheet'), type: 'menu', menu: [
447					{uno: '.uno:InsertRowsBefore'},
448					{uno: '.uno:InsertRowsAfter'}]},
449				{name: _UNO('.uno:InsertColumnsMenu', 'spreadsheet'), type: 'menu', menu: [
450					{uno: '.uno:InsertColumnsBefore'},
451					{uno: '.uno:InsertColumnsAfter'}]},
452				{name: _UNO('.uno:InsertBreakMenu', 'spreadsheet'), type: 'menu', menu: [
453					{uno: '.uno:InsertRowBreak'},
454					{uno: '.uno:InsertColumnBreak'}]},
455				{type: 'separator'},
456				{uno: '.uno:DeleteRows'},
457				{uno: '.uno:DeleteColumns'},
458				{name: _UNO('.uno:DelBreakMenu', 'spreadsheet'), type: 'menu', menu: [
459					{uno: '.uno:DeleteRowbreak'},
460					{uno: '.uno:DeleteColumnbreak'}]}
461			]},
462			{name: _UNO('.uno:DataMenu', 'spreadsheet'), type: 'menu', menu: [
463				{uno: '.uno:DataSort'},
464				{uno: '.uno:SortAscending'},
465				{uno: '.uno:SortDescending'},
466				{uno: '.uno:Validation'},
467				{type: 'separator'},
468				{uno: '.uno:DataFilterAutoFilter'},
469				{name: _UNO('.uno:FilterMenu', 'spreadsheet'), type: 'menu', menu: [
470					{uno: '.uno:DataFilterStandardFilter'},
471					{uno: '.uno:DataFilterSpecialFilter'},
472					{type: 'separator'},
473					{uno: '.uno:DataFilterRemoveFilter'},
474					{uno: '.uno:DataFilterHideAutoFilter'}]},
475				{type: 'separator'},
476				{name: _UNO('.uno:GroupOutlineMenu', 'spreadsheet'), type: 'menu', menu: [
477					{uno: '.uno:Group'},
478					{uno: '.uno:Ungroup'},
479					{type: 'separator'},
480					{uno: '.uno:ClearOutline'},
481					{type: 'separator'},
482					{uno: '.uno:HideDetail'},
483					{uno: '.uno:ShowDetail'}]}
484			]},
485			{name: _UNO('.uno:ToolsMenu', 'spreadsheet'), id: 'tools', type: 'menu', menu: [
486				{uno: '.uno:SpellDialog'},
487				{uno: '.uno:SpellOnline'},
488				{name: _UNO('.uno:LanguageMenu'), type: 'menu', menu: [
489					{name: _('None (Do not check spelling)'), id: 'nonelanguage', uno: '.uno:LanguageStatus?Language:string=Default_LANGUAGE_NONE'}]},
490				{uno: '.uno:GoalSeekDialog'}
491			]},
492			{name: _UNO('.uno:HelpMenu', 'spreadsheet'), id: 'help', type: 'menu', menu: [
493				{name: _('Online Help'), id: 'online-help', type: 'action', iosapp: false},
494				{name: _('Keyboard shortcuts'), id: 'keyboard-shortcuts', type: 'action', iosapp: false},
495				{name: _('Report an issue'), id: 'report-an-issue', type: 'action', iosapp: false},
496				{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
497				{name: _('About'), id: 'about', type: 'action'}]
498			},
499			{name: _('Last modification'), id: 'last-mod', type: 'action', tablet: false}
500		],
501
502		mobiletext:  [
503			{name: _UNO('.uno:PickList', 'text'), id: 'file', type: 'menu', menu: [
504				{name: _UNO('.uno:Save', 'text'), id: 'save', type: 'action'},
505				{name: _UNO('.uno:SaveAs', 'text'), id: 'saveas', type: 'action'},
506				{name: _('Share...'), id:'shareas', type: 'action'},
507				{name: _UNO('.uno:Print', 'text'), id: 'print', type: 'action'},
508				{name: _('See revision history'), id: 'rev-history', type: 'action'},
509				{name: _('Sign document'), id: 'signdocument', type: 'action'}
510			]},
511			{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id: 'downloadas', type: 'menu', menu: [
512				{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
513				{name: _('ODF text document (.odt)'), id: 'downloadas-odt', type: 'action'},
514				{name: _('Word 2003 Document (.doc)'), id: 'downloadas-doc', type: 'action'},
515				{name: _('Word Document (.docx)'), id: 'downloadas-docx', type: 'action'},
516				{name: _('Rich Text (.rtf)'), id: 'downloadas-rtf', type: 'action'},
517				{name: _('EPUB (.epub)'), id: 'downloadas-epub', type: 'action'}
518			]},
519			{name: _UNO('.uno:EditMenu', 'text'), id: 'editmenu', type: 'menu', menu: [
520				{uno: '.uno:Undo'},
521				{uno: '.uno:Redo'},
522				{name: _('Repair'), id: 'repair',  type: 'action'},
523				{type: 'separator'},
524				{uno: '.uno:Cut'},
525				{uno: '.uno:Copy'},
526				{uno: '.uno:Paste'},
527				{uno: '.uno:SelectAll'}
528			]},
529			{name: _('Search'), id: 'searchdialog', type: 'action'},
530			{uno: '.uno:WordCountDialog'},
531			{name: _UNO('.uno:ChangesMenu', 'text'), id: 'changesmenu', type: 'menu', menu: [
532				{uno: '.uno:TrackChanges'},
533				{uno: '.uno:ShowTrackedChanges'},
534				{type: 'separator'},
535				{uno: '.uno:AcceptAllTrackedChanges'},
536				{uno: '.uno:RejectAllTrackedChanges'},
537				{uno: '.uno:PreviousTrackedChange'},
538				{uno: '.uno:NextTrackedChange'}
539			]},
540			{name: _('Page Setup'), id: 'pagesetup', type: 'action'},
541			{id: 'watermark', uno: '.uno:Watermark'},
542			{name: _UNO('.uno:ViewMenu', 'text'), id: 'view', type: 'menu', menu: [
543				{uno: '.uno:ControlCodes'},
544				{uno: '.uno:SpellOnline'},
545				{name: _UNO('.uno:ShowResolvedAnnotations', 'text'), id: 'showresolved', type: 'action', uno: '.uno:ShowResolvedAnnotations'},
546			]
547			},
548			{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
549			{name: _('About'), id: 'about', type: 'action'},
550		],
551
552		mobilepresentation: [
553			{name: _UNO('.uno:PickList', 'presentation'), id: 'file', type: 'menu', menu: [
554				{name: _UNO('.uno:Save', 'presentation'), id: 'save', type: 'action'},
555				{name: _UNO('.uno:SaveAs', 'presentation'), id: 'saveas', type: 'action'},
556				{name: _('Share...'), id:'shareas', type: 'action'},
557				{name: _UNO('.uno:Print', 'presentation'), id: 'print', type: 'action'},
558				{name: _('See revision history'), id: 'rev-history', type: 'action'},
559			]},
560			{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id:'downloadas', type: 'menu', menu: [
561				{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
562				{name: _('ODF presentation (.odp)'), id: 'downloadas-odp', type: 'action', drawing: false},
563				{name: _('PowerPoint 2003 Presentation (.ppt)'), id: 'downloadas-ppt', type: 'action', drawing: false},
564				{name: _('PowerPoint Presentation (.pptx)'), id: 'downloadas-pptx', type: 'action', drawing: false},
565				{name: _('ODF Drawing (.odg)'), id: 'downloadas-odg', type: 'action'}
566			]},
567			{name: _UNO('.uno:EditMenu', 'presentation'), id: 'editmenu', type: 'menu', menu: [
568				{uno: '.uno:Undo'},
569				{uno: '.uno:Redo'},
570				{name: _('Repair'), id: 'repair',  type: 'action'},
571				{type: 'separator'},
572				{uno: '.uno:Cut'},
573				{uno: '.uno:Copy'},
574				{uno: '.uno:Paste'},
575				{uno: '.uno:SelectAll'}
576			]},
577			{name: _('Search'), id: 'searchdialog', type: 'action'},
578			{name: _UNO('.uno:TableMenu', 'text'/*HACK should be 'presentation', but not in xcu*/), id: 'tablemenu', type: 'menu', menu: [
579				{uno: '.uno:InsertRowsBefore'},
580				{uno: '.uno:InsertRowsAfter'},
581				{type: 'separator'},
582				{uno: '.uno:InsertColumnsBefore'},
583				{uno: '.uno:InsertColumnsAfter'},
584				{uno: '.uno:DeleteRows'},
585				{uno: '.uno:DeleteColumns'},
586				{uno: '.uno:MergeCells'}]
587			},
588			{name: _UNO('.uno:SlideMenu', 'presentation'), id: 'slidemenu', type: 'menu', menu: [
589				{name: _UNO('.uno:InsertSlide', 'presentation'), id: 'insertpage', type: 'action'},
590				{name: _UNO('.uno:DuplicateSlide', 'presentation'), id: 'duplicatepage', type: 'action'},
591				{name: _UNO('.uno:DeleteSlide', 'presentation'), id: 'deletepage', type: 'action'}]
592			},
593			{name: _UNO('.uno:FullScreen', 'presentation'), id: 'fullscreen', type: 'action', mobileapp: false},
594			{uno: '.uno:SpellOnline'},
595			{name: _('Fullscreen presentation'), id: 'fullscreen-presentation', type: 'action'},
596			{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
597			{name: _('About'), id: 'about', type: 'action'},
598		],
599
600		mobilespreadsheet: [
601			{name: _UNO('.uno:PickList', 'spreadsheet'), id: 'file', type: 'menu', menu: [
602				{name: _UNO('.uno:Save', 'spreadsheet'), id: 'save', type: 'action'},
603				{name: _UNO('.uno:SaveAs', 'spreadsheet'), id: 'saveas', type: 'action'},
604				{name: _('Share...'), id:'shareas', type: 'action'},
605				{name: _UNO('.uno:Print', 'spreadsheet'), id: 'print', type: 'action'},
606				{name: _('See revision history'), id: 'rev-history', type: 'action'},
607			]},
608			{name: !window.ThisIsAMobileApp ? _('Download as') : _('Export as'), id:'downloadas', type: 'menu', menu: [
609				{name: _('PDF Document (.pdf)'), id: 'downloadas-pdf', type: 'action'},
610				{name: _('ODF spreadsheet (.ods)'), id: 'downloadas-ods', type: 'action'},
611				{name: _('Excel 2003 Spreadsheet (.xls)'), id: 'downloadas-xls', type: 'action'},
612				{name: _('Excel Spreadsheet (.xlsx)'), id: 'downloadas-xlsx', type: 'action'}
613			]},
614			{name: _UNO('.uno:EditMenu', 'spreadsheet'), id: 'editmenu', type: 'menu', menu: [
615				{uno: '.uno:Undo'},
616				{uno: '.uno:Redo'},
617				{name: _('Repair'), id: 'repair',  type: 'action'},
618				{type: 'separator'},
619				{uno: '.uno:Cut'},
620				{uno: '.uno:Copy'},
621				{uno: '.uno:Paste'},
622				{uno: '.uno:SelectAll'}
623			]},
624			{name: _('Search'), id: 'searchdialog', type: 'action'},
625			{name: _UNO('.uno:SheetMenu', 'spreadsheet'), id: 'sheetmenu', type: 'menu', menu: [
626				{name: _UNO('.uno:InsertRowsMenu', 'spreadsheet'), id: 'insertrowsmenu', type: 'menu', menu: [
627					{uno: '.uno:InsertRowsBefore'},
628					{uno: '.uno:InsertRowsAfter'}]},
629				{name: _UNO('.uno:InsertColumnsMenu', 'spreadsheet'), id: 'insertcolumnsmenu', type: 'menu', menu: [
630					{uno: '.uno:InsertColumnsBefore'},
631					{uno: '.uno:InsertColumnsAfter'}]},
632				{name: _UNO('.uno:InsertBreakMenu', 'spreadsheet'), id: 'insertbreakmenu', type: 'menu', menu: [
633					{uno: '.uno:InsertRowBreak'},
634					{uno: '.uno:InsertColumnBreak'}]},
635				{type: 'separator'},
636				{uno: '.uno:DeleteRows'},
637				{uno: '.uno:DeleteColumns'},
638				{name: _UNO('.uno:DelBreakMenu', 'spreadsheet'), id: 'delbreakmenu', type: 'menu', menu: [
639					{uno: '.uno:DeleteRowbreak'},
640					{uno: '.uno:DeleteColumnbreak'}]}
641			]},
642			{name: _UNO('.uno:DataMenu', 'spreadsheet'), id: 'datamenu', type: 'menu', menu: [
643				{uno: '.uno:Validation'},
644				{type: 'separator'},
645				{uno: '.uno:SortAscending'},
646				{uno: '.uno:SortDescending'},
647				{type: 'separator'},
648				{name: _UNO('.uno:GroupOutlineMenu', 'spreadsheet'), id: 'groupoutlinemenu', type: 'menu', menu: [
649					{uno: '.uno:Group'},
650					{uno: '.uno:Ungroup'},
651					{type: 'separator'},
652					{uno: '.uno:ClearOutline'},
653					{type: 'separator'},
654					{uno: '.uno:HideDetail'},
655					{uno: '.uno:ShowDetail'}]}
656			]},
657			{uno: '.uno:SpellOnline'},
658			{name: _UNO('.uno:FullScreen', 'spreadsheet'), id: 'fullscreen', type: 'action', mobileapp: false},
659			{name: _('Latest Updates'), id: 'latest-updates', type: 'action', iosapp: false},
660			{name: _('About'), id: 'about', type: 'action'},
661		],
662
663		mobileInsertMenu : {
664			text : {
665				name: _UNO('.uno:InsertMenu', 'text'), id: 'insert', type: 'menu', menu: [
666					{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
667					{name: _UNO('.uno:InsertGraphic', 'text'), id: 'insertgraphicremote', type: 'action'},
668					{name: _UNO('.uno:InsertAnnotation', 'text'), id: 'insertcomment', type: 'action'},
669					{name: _UNO('.uno:TableMenu'), id: 'inserttable', type: 'action'},
670					{type: 'separator'},
671					{name: _UNO('.uno:InsertField', 'text'), id: 'insertfield', type: 'menu', menu: [
672						{uno: '.uno:InsertPageNumberField'},
673						{uno: '.uno:InsertPageCountField'},
674						{uno: '.uno:InsertDateField'},
675						{uno: '.uno:InsertTimeField'},
676						{uno: '.uno:InsertTitleField'},
677						{uno: '.uno:InsertAuthorField'},
678						{uno: '.uno:InsertTopicField'}
679					]},
680					{name: _UNO('.uno:InsertHeaderFooterMenu', 'text'), id: 'insertheaderfooter', type: 'menu', menu: [
681						{name: _UNO('.uno:InsertPageHeader', 'text'), id: 'insertpageheader', type: 'menu', menu: [
682							{name: _('All'), disabled: true, id: 'insertheader', tag: '_ALL_', uno: '.uno:InsertPageHeader?On:bool=true'}]},
683						{name: _UNO('.uno:InsertPageFooter', 'text'), id: 'insertpagefooter', type: 'menu', menu: [
684							{name: _('All'), disabled: true, id: 'insertfooter', tag: '_ALL_', uno: '.uno:InsertPageFooter?On:bool=true'}]}
685					]},
686					{uno: '.uno:InsertFootnote'},
687					{uno: '.uno:InsertEndnote'},
688					{type: 'separator'},
689					{uno: '.uno:InsertPagebreak'},
690					{name: _UNO('.uno:InsertColumnBreak', 'spreadsheet'), uno: '.uno:InsertColumnBreak'},
691					{type: 'separator'},
692					{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
693					{name: _UNO('.uno:ShapesMenu'), id: 'insertshape', type: 'action'},
694					{name: _UNO('.uno:FormattingMarkMenu', 'text'), id: 'formattingmark', type: 'menu', menu: [
695						{uno: '.uno:InsertNonBreakingSpace'},
696						{uno: '.uno:InsertHardHyphen'},
697						{uno: '.uno:InsertSoftHyphen'},
698						{uno: '.uno:InsertZWSP'},
699						{uno: '.uno:InsertZWNBSP'},
700						{uno: '.uno:InsertLRM'},
701						{uno: '.uno:InsertRLM'}]},
702				]
703			},
704			spreadsheet : {
705				name: _UNO('.uno:InsertMenu', 'spreadsheet'), id: 'insert', type: 'menu', menu: [
706					{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
707					{name: _UNO('.uno:InsertGraphic', 'spreadsheet'), id: 'insertgraphicremote', type: 'action'},
708					{uno: '.uno:InsertObjectChart'},
709					{name: _UNO('.uno:InsertAnnotation', 'spreadsheet'), id: 'insertcomment', type: 'action'},
710					{type: 'separator'},
711					{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
712					{name: _UNO('.uno:ShapesMenu'), id: 'insertshape', type: 'action'},
713					{uno: '.uno:InsertCurrentDate'},
714					{uno: '.uno:InsertCurrentTime'},
715					// other fields need EditEngine context & can't be disabled in the menu.
716				]
717			},
718			presentation : {
719				name: _UNO('.uno:InsertMenu', 'presentation'), id: 'insert', type: 'menu', menu: [
720					{name: _('Local Image...'), id: 'insertgraphic', type: 'action'},
721					{name: _UNO('.uno:InsertGraphic', 'presentation'), id: 'insertgraphicremote', type: 'action'},
722					{name: _UNO('.uno:InsertAnnotation', 'presentation'), id: 'insertcomment', type: 'action'},
723					{name: _UNO('.uno:TableMenu'), id: 'inserttable', type: 'action'},
724					{name: _UNO('.uno:HyperlinkDialog'), id: 'inserthyperlink', type: 'action'},
725					{name: _UNO('.uno:ShapesMenu'), id: 'insertshape', type: 'action'},
726					{name: _UNO('.uno:Text', 'presentation'), id: 'inserttextbox', type: 'action'},
727					{name: _UNO('.uno:InsertField', 'text'), id: 'insertfield', type: 'menu', menu: [
728						{uno: '.uno:InsertDateFieldFix'},
729						{uno: '.uno:InsertDateFieldVar'},
730						{uno: '.uno:InsertTimeFieldFix'},
731						{uno: '.uno:InsertTimeFieldVar'},
732						{type: 'separator'},
733						{name: _UNO('.uno:InsertSlideField', 'presentation'), id: 'insertslidefield', type: 'action'},
734						{name: _UNO('.uno:InsertSlideTitleField', 'presentation'), id: 'insertslidetitlefield', type: 'action'},
735						{name: _UNO('.uno:InsertSlidesField', 'presentation'), id: 'insertslidesfield', type: 'action'},
736					]},
737				]
738			}
739		},
740
741		commandStates: {},
742
743		// Only these menu options will be visible in readonly mode
744		allowedReadonlyMenus: ['file', 'downloadas', 'view', 'insert', 'help'],
745
746		allowedViewModeActions: [
747			'savecomments', 'shareas', 'print', // file menu
748			'downloadas-pdf', 'downloadas-odt', 'downloadas-doc', 'downloadas-docx', 'downloadas-rtf', 'downloadas-epub', // file menu
749			'downloadas-odp', 'downloadas-ppt', 'downloadas-pptx', 'downloadas-odg', 'print', // file menu
750			'downloadas-ods', 'downloadas-xls', 'downloadas-xlsx', 'closedocument', // file menu
751			'fullscreen', 'zoomin', 'zoomout', 'zoomreset', 'showresolved', // view menu
752			'about', 'keyboard-shortcuts', 'latest-updates', 'online-help', 'report-an-issue', // help menu
753			'insertcomment'
754		]
755	},
756
757	onAdd: function (map) {
758		this._initialized = false;
759		this._hiddenItems = [];
760		this._menubarCont = L.DomUtil.get('main-menu');
761		this._initializeMenu(this.options.initial);
762
763		map.on('doclayerinit', this._onDocLayerInit, this);
764		map.on('updatepermission', this._onRefresh, this);
765		map.on('addmenu', this._addMenu, this);
766		map.on('commandvalues', this._onInitLanguagesMenu, this);
767		map.on('updatetoolbarcommandvalues', this._onStyleMenu, this);
768	},
769
770	_addMenu: function (e) {
771		var alreadyExists = L.DomUtil.get('menu-' + e.id);
772		if (alreadyExists)
773			return;
774
775		var liItem = L.DomUtil.create('li', '');
776		liItem.id = 'menu-' + e.id;
777		if (this._map.isPermissionReadOnly()) {
778			L.DomUtil.addClass(liItem, 'readonly');
779		}
780		var aItem = L.DomUtil.create('a', '', liItem);
781		$(aItem).text(e.label);
782		$(aItem).data('id', e.id);
783		$(aItem).data('type', 'action');
784		$(aItem).data('postmessage', 'true');
785		this._menubarCont.insertBefore(liItem, this._menubarCont.firstChild);
786	},
787
788	_createUnoMenuItem: function (caption, command, tag) {
789		var liItem, aItem;
790		liItem = L.DomUtil.create('li', '');
791		aItem = L.DomUtil.create('a', '', liItem);
792		$(aItem).text(caption);
793		$(aItem).data('type', 'unocommand');
794		$(aItem).data('uno', command);
795		$(aItem).data('tag', tag);
796		return liItem;
797	},
798
799
800	_onInitLanguagesMenu: function (e) {
801		if (e.commandName === '.uno:LanguageStatus' && L.Util.isArray(e.commandValues)) {
802			var translated, neutral;
803			var constDefa = 'Default_RESET_LANGUAGES';
804			var constCurr = 'Current_RESET_LANGUAGES';
805			var constPara = 'Paragraph_RESET_LANGUAGES';
806			var constLang = '.uno:LanguageStatus?Language:string=';
807			var resetLang = _('Reset to Default Language');
808			var languages  = [];
809
810			e.commandValues.forEach(function(language) {
811				var split = language.split(';');
812				language = split[0];
813				var isoCode = '';
814				if (split.length > 1)
815					isoCode = split[1];
816				languages.push({translated: _(language), neutral: language, iso: isoCode});
817			});
818			languages.sort(function(a, b) {
819				return a.translated < b.translated ? -1 : a.translated > b.translated ? 1 : 0;
820			});
821
822			var $menuSelection = $('#menu-noneselection').parent();
823			var $menuParagraph = $('#menu-noneparagraph').parent();
824			var $menuDefault = $('#menu-nonelanguage').parent();
825
826			var noneselection = $('#menu-noneselection').detach();
827			var noneparagraph = $('#menu-noneparagraph').detach();
828			var nonelanguage = $('#menu-nonelanguage').detach();
829
830			// clear old entries
831
832			$menuSelection.empty();
833			$menuParagraph.empty();
834			$menuDefault.empty();
835
836			$menuSelection.append(noneselection);
837			$menuParagraph.append(noneparagraph);
838			$menuDefault.append(nonelanguage);
839
840			for (var lang in languages) {
841				translated = languages[lang].translated;
842				neutral = languages[lang].neutral;
843
844				$menuSelection.append(this._createUnoMenuItem(translated, constLang + encodeURIComponent('Current_' + neutral)));
845				$menuParagraph.append(this._createUnoMenuItem(translated, constLang + encodeURIComponent('Paragraph_' + neutral)));
846				$menuDefault.append(this._createUnoMenuItem(translated, constLang + encodeURIComponent('Default_' + neutral)));
847			}
848
849			$menuSelection.append(this._createMenu([{type: 'separator'}]));
850			$menuParagraph.append(this._createMenu([{type: 'separator'}]));
851			$menuDefault.append(this._createMenu([{type: 'separator'}]));
852
853			$menuSelection.append(this._createUnoMenuItem(resetLang, constLang + constCurr));
854			$menuParagraph.append(this._createUnoMenuItem(resetLang, constLang + constPara));
855			$menuDefault.append(this._createUnoMenuItem(resetLang, constLang + constDefa));
856		}
857	},
858
859	_onRefresh: function() {
860		// clear initial menu
861		L.DomUtil.removeChildNodes(this._menubarCont);
862
863		// Add document specific menu
864		var docType = this._map.getDocType();
865		if (docType === 'text') {
866			this._initializeMenu(this.options.text);
867		} else if (docType === 'spreadsheet') {
868			this._initializeMenu(this.options.spreadsheet);
869		} else if (docType === 'presentation' || docType === 'drawing') {
870			this._initializeMenu(this.options.presentation);
871		}
872
873		// initialize menubar plugin
874		$('#main-menu').smartmenus({
875			hideOnClick: true,
876			showOnClick: true,
877			hideTimeout: 0,
878			hideDuration: 0,
879			showDuration: 0,
880			showTimeout: 0,
881			collapsibleHideDuration: 0,
882			subIndicatorsPos: 'append',
883			subIndicatorsText: '&#8250;'
884		});
885		$('#main-menu').attr('tabindex', 0);
886
887
888		this._createFileIcon();
889	},
890
891	_onStyleMenu: function (e) {
892		if (e.commandName === '.uno:StyleApply') {
893			var style;
894			var constArg = '&';
895			var constHeader = '.uno:InsertPageHeader?PageStyle:string=';
896			var constFooter = '.uno:InsertPageFooter?PageStyle:string=';
897			var $menuHeader = $('#menu-insertheader').parent();
898			var $menuFooter = $('#menu-insertfooter').parent();
899			var pageStyles = e.commandValues['HeaderFooter'];
900			for (var iterator in pageStyles) {
901				style = pageStyles[iterator];
902				if (!window.mode.isMobile()) {
903					$menuHeader.append(this._createUnoMenuItem(_(style), constHeader + encodeURIComponent(style) + constArg, style));
904					$menuFooter.append(this._createUnoMenuItem(_(style), constFooter + encodeURIComponent(style) + constArg, style));
905				} else {
906					var docType = this._map.getDocType();
907					var target = this.options['mobileInsertMenu'][docType];
908
909					var findFunction = function(item) {
910						return item.name === _(style);
911					};
912
913					var foundMenu = this._findSubMenuByName(target, _UNO('.uno:InsertPageHeader', 'text'));
914					if (foundMenu && foundMenu.menu.find(findFunction) === undefined)
915						foundMenu.menu.push({name: _(style), tag: style, uno: constHeader + encodeURIComponent(style) + constArg});
916
917					foundMenu = this._findSubMenuByName(target, _UNO('.uno:InsertPageFooter', 'text'));
918					if (foundMenu && foundMenu.menu.find(findFunction) === undefined)
919						foundMenu.menu.push({name: _(style), tag: style, uno: constFooter + encodeURIComponent(style) + constArg});
920				}
921			}
922		}
923	},
924
925	_createDocument: function(e) {
926		var self = e.data.self;
927		var docType = self._map.getDocType();
928		self._map.fire('postMessage', {msgId: 'UI_CreateFile', args: {DocumentType: docType}});
929	},
930
931	_onDocLayerInit: function() {
932		this._onRefresh();
933
934		$('#main-menu').bind('select.smapi', {self: this}, this._onItemSelected);
935		$('#main-menu').bind('mouseenter.smapi', {self: this}, this._onMouseEnter);
936		$('#main-menu').bind('mouseleave.smapi', {self: this}, this._onMouseLeave);
937
938		$('#main-menu').bind('beforeshow.smapi', {self: this}, this._beforeShow);
939		$('#main-menu').bind('click.smapi', {self: this}, this._onClicked);
940
941		$('#main-menu').bind('keydown', {self: this}, this._onKeyDown);
942
943		if (window.mode.isMobile())
944			$('#main-menu').parent().css('height', '0');
945
946		var self = this;
947		// Also the vertical menu displayed when tapping the hamburger button is produced by SmartMenus
948		$(function() {
949			var $mainMenuState = $('#main-menu-state');
950			if ($mainMenuState.length) {
951				// animate mobile menu
952				$mainMenuState.change(function() {
953					// This code is invoked when the hamburger menu is opened or closed
954					var $menu = $('#main-menu');
955					var $nav = $menu.parent();
956					if (this.checked) {
957						self._map.fire('closesidebar');
958						if (!window.mode.isMobile()) {
959							// Surely this code, if it really is related only to the hamburger menu,
960							// will never be invoked on non-mobile browsers? I might be wrong though.
961							// If you notice this logging, please modify this comment to indicate what is
962							// going on.
963							console.log('======> Assertion failed!? Not window.mode.isMobile()? Control.Menubar.js #1');
964							$nav.css({height: 'initial', bottom: '38px'});
965							$menu.hide().slideDown(250, function() { $menu.css('display', ''); });
966							$('#mobile-wizard-header').show();
967						} else {
968							window.mobileMenuWizard = true;
969							var menuData = self._map.menubar.generateFullMenuStructure();
970							self._map.fire('mobilewizard', menuData);
971							$('#toolbar-hamburger').removeClass('menuwizard-closed').addClass('menuwizard-opened');
972							$('#mobile-wizard-header').hide();
973						}
974					} else if (!window.mode.isMobile()) {
975						// Ditto.
976						console.log('======> Assertion failed!? Not window.mode.isMobile()? Control.Menubar.js #2');
977						$menu.show().slideUp(250, function() { $menu.css('display', ''); });
978						$nav.css({height:'', bottom: ''});
979					} else {
980						window.mobileMenuWizard = false;
981						self._map.fire('closemobilewizard');
982						$('#toolbar-hamburger').removeClass('menuwizard-opened').addClass('menuwizard-closed');
983					}
984				});
985				// hide mobile menu beforeunload
986				$(window).bind('beforeunload unload', function() {
987					if ($mainMenuState[0].checked) {
988						$mainMenuState[0].click();
989					}
990				});
991			}
992		});
993
994		this._initialized = true;
995	},
996
997	_onClicked: function(e, menu) {
998		if ($(menu).hasClass('highlighted')) {
999			$('#main-menu').smartmenus('menuHideAll');
1000		}
1001
1002		var $mainMenuState = $('#main-menu-state');
1003		if (!$(menu).hasClass('has-submenu') && $mainMenuState[0].checked) {
1004			$mainMenuState[0].click();
1005		}
1006	},
1007
1008	_checkedMenu: function(uno, item) {
1009		var constChecked = 'lo-menu-item-checked';
1010		var state = this._map['stateChangeHandler'].getItemValue(uno);
1011		var data = $(item).data('tag');
1012		state = state[data] || false;
1013		if (state) {
1014			$(item).addClass(constChecked);
1015		} else {
1016			$(item).removeClass(constChecked);
1017		}
1018	},
1019
1020	_beforeShow: function(e, menu) {
1021		var self = e.data.self;
1022		var items = $(menu).children().children('a').not('.has-submenu');
1023		$(items).each(function() {
1024			var aItem = this;
1025			var type = $(aItem).data('type');
1026			var id = $(aItem).data('id');
1027			var constChecked = 'lo-menu-item-checked';
1028			if (self._map.isPermissionEdit()) {
1029				if (type === 'unocommand') { // enable all depending on stored commandStates
1030					var data, lang, languageAndCode;
1031					var constUno = 'uno';
1032					var constState = 'stateChangeHandler';
1033					var constLanguage = '.uno:LanguageStatus';
1034					var constPageHeader = '.uno:InsertPageHeader';
1035					var constPageFooter = '.uno:InsertPageFooter';
1036					var unoCommand = $(aItem).data(constUno);
1037					var itemState = self._map[constState].getItemValue(unoCommand);
1038					if (itemState === 'disabled') {
1039						if (unoCommand.startsWith('.uno:Paste')) {
1040							console.log('do not disable paste based on server side data');
1041						} else {
1042							$(aItem).addClass('disabled');
1043						}
1044					} else {
1045						$(aItem).removeClass('disabled');
1046					}
1047					if (unoCommand.startsWith(constLanguage)) {
1048						unoCommand = constLanguage;
1049						languageAndCode = self._map[constState].getItemValue(unoCommand);
1050						lang = languageAndCode.split(';')[0];
1051						data = decodeURIComponent($(aItem).data(constUno));
1052						if (data.indexOf(lang) !== -1) {
1053							$(aItem).addClass(constChecked);
1054						} else if (data.indexOf('LANGUAGE_NONE') !== -1 && lang === '[None]') {
1055							$(aItem).addClass(constChecked);
1056						} else {
1057							$(aItem).removeClass(constChecked);
1058						}
1059					}
1060					else if (unoCommand.startsWith(constPageHeader)) {
1061						unoCommand = constPageHeader;
1062						self._checkedMenu(unoCommand, this);
1063					}
1064					else if (unoCommand.startsWith(constPageFooter)) {
1065						unoCommand = constPageFooter;
1066						self._checkedMenu(unoCommand, this);
1067					}
1068					else if (itemState === 'true') {
1069						$(aItem).addClass(constChecked);
1070					} else {
1071						$(aItem).removeClass(constChecked);
1072					}
1073				} else if (type === 'action') { // enable all except fullscreen on windows
1074					if (id === 'fullscreen' && (L.Browser.ie || L.Browser.edge)) { // Full screen works weirdly on IE 11 and on Edge
1075						$(aItem).addClass('disabled');
1076						var index = self.options.allowedViewModeActions.indexOf('fullscreen');
1077						if (index > 0) {
1078							self.options.allowedViewModeActions.splice(index, 1);
1079						}
1080					} else if (id === 'showruler') {
1081						if (self._map.uiManager.isRulerVisible()) {
1082							$(aItem).addClass(constChecked);
1083						} else {
1084							$(aItem).removeClass(constChecked);
1085						}
1086
1087					} else if (id === 'showstatusbar') {
1088						if (self._map.uiManager.isStatusBarVisible()) {
1089							$(aItem).addClass(constChecked);
1090						} else {
1091							$(aItem).removeClass(constChecked);
1092						}
1093
1094					} else if (self._map.getDocType() === 'presentation' && (id === 'deletepage' || id === 'insertpage' || id === 'duplicatepage')) {
1095						if (id === 'deletepage') {
1096							itemState = self._map['stateChangeHandler'].getItemValue('.uno:DeletePage');
1097						} else if (id === 'insertpage') {
1098							itemState = self._map['stateChangeHandler'].getItemValue('.uno:InsertPage');
1099						} else {
1100							itemState = self._map['stateChangeHandler'].getItemValue('.uno:DuplicatePage');
1101						}
1102						if (itemState === 'disabled') {
1103							$(aItem).addClass('disabled');
1104						} else {
1105							$(aItem).removeClass('disabled');
1106						}
1107					} else if (id === 'showresolved') {
1108						if (self._map._docLayer._annotations._items.length === 0) {
1109							$(aItem).addClass('disabled');
1110						} else if (self._map._docLayer._annotations._showResolved) {
1111							$(aItem).removeClass('disabled');
1112							$(aItem).addClass(constChecked);
1113						} else {
1114							$(aItem).removeClass('disabled');
1115							$(aItem).removeClass(constChecked);
1116						}
1117					} else {
1118						$(aItem).removeClass('disabled');
1119					}
1120				}
1121			} else { // eslint-disable-next-line no-lonely-if
1122				if (type === 'unocommand') { // disable all uno commands
1123					$(aItem).addClass('disabled');
1124				} else if (type === 'action') { // disable all except allowedViewModeActions
1125					var found = false;
1126					for (var i in self.options.allowedViewModeActions) {
1127						if (self.options.allowedViewModeActions[i] === id) {
1128							found = true;
1129							break;
1130						}
1131					}
1132					if (id === 'insertcomment' && self._map.getDocType() !== 'drawing')
1133						found = false;
1134					if (!found) {
1135						$(aItem).addClass('disabled');
1136					} else {
1137						$(aItem).removeClass('disabled');
1138					}
1139				}
1140			}
1141		});
1142	},
1143
1144	_openInsertShapesWizard: function() {
1145		var content = window.createShapesPanel();
1146		var data = {
1147			id: 'insertshape',
1148			type: '',
1149			text: _('Insert Shape'),
1150			enabled: true,
1151			children: []
1152		};
1153
1154		var container = {
1155			id: '',
1156			type: 'htmlcontrol',
1157			content: content,
1158			enabled: true
1159		};
1160
1161		data.children.push(container);
1162		this._map._docLayer._openMobileWizard(data);
1163	},
1164
1165	_executeAction: function(itNode, itWizard) {
1166		var id, postmessage;
1167		if (itNode === undefined)
1168		{ // called from JSDialogBuilder
1169			id = itWizard.id;
1170			postmessage = false;
1171		}
1172		else
1173		{ // called from
1174			id = $(itNode).data('id');
1175			postmessage = ($(itNode).data('postmessage') === 'true');
1176		}
1177
1178		if (id === 'save') {
1179			// Save only when not read-only.
1180			if (!this._map.isPermissionReadOnly()) {
1181				this._map.fire('postMessage', {msgId: 'UI_Save'});
1182				if (!this._map._disableDefaultAction['UI_Save']) {
1183					this._map.save(false, false);
1184				}
1185			}
1186		} else if (id === 'saveas') {
1187			this._map.fire('postMessage', {msgId: 'UI_SaveAs'});
1188		} else if (id === 'savecomments') {
1189			if (this._map.isPermissionEditForComments()) {
1190				this._map.fire('postMessage', {msgId: 'UI_Save'});
1191				if (!this._map._disableDefaultAction['UI_Save']) {
1192					this._map.save(false, false);
1193				}
1194			}
1195		} else if (id === 'shareas') {
1196			this._map.fire('postMessage', {msgId: 'UI_Share'});
1197		} else if (id === 'print') {
1198			this._map.print();
1199		} else if (id.startsWith('downloadas-')) {
1200			var format = id.substring('downloadas-'.length);
1201			var fileName = this._map['wopi'].BaseFileName;
1202			fileName = fileName.substr(0, fileName.lastIndexOf('.'));
1203			fileName = fileName === '' ? 'document' : fileName;
1204			this._map.downloadAs(fileName + '.' + format, format);
1205		} else if (id === 'signdocument') {
1206			this._map.showSignDocument();
1207		} else if (id === 'insertcomment') {
1208			this._map.insertComment();
1209		} else if (id === 'insertgraphic') {
1210			L.DomUtil.get('insertgraphic').click();
1211		} else if (id === 'insertgraphicremote') {
1212			this._map.fire('postMessage', {msgId: 'UI_InsertGraphic'});
1213		} else if (id === 'selectbackground') {
1214			L.DomUtil.get('selectbackground').click();
1215		} else if (id === 'zoomin' && this._map.getZoom() < this._map.getMaxZoom()) {
1216			this._map.zoomIn(1);
1217		} else if (id === 'showresolved') {
1218			this._map.showResolvedComments(!$(itNode).hasClass('lo-menu-item-checked'));
1219		} else if (id === 'zoomout' && this._map.getZoom() > this._map.getMinZoom()) {
1220			this._map.zoomOut(1);
1221		} else if (id === 'zoomreset') {
1222			this._map.setZoom(this._map.options.zoom);
1223		} else if (id === 'fullscreen') {
1224			L.toggleFullScreen();
1225		} else if (id === 'showruler') {
1226			this._map.uiManager.toggleRuler();
1227		} else if (id === 'showstatusbar') {
1228			this._map.uiManager.toggleStatusBar();
1229		} else if (id === 'fullscreen-presentation' && this._map.getDocType() === 'presentation') {
1230			this._map.fire('fullscreen');
1231		} else if (id === 'presentation-currentslide' && this._map.getDocType() === 'presentation') {
1232			this._map.fire('fullscreen', {startSlideNumber: this._map.getCurrentPartNumber()});
1233		} else if (id === 'insertpage') {
1234			this._map.insertPage();
1235		} else if (id === 'insertshape') {
1236			this._openInsertShapesWizard();
1237		} else if (id === 'duplicatepage') {
1238			this._map.duplicatePage();
1239		} else if (id === 'deletepage') {
1240			var map = this._map;
1241			vex.dialog.open({
1242				message: _('Are you sure you want to delete this slide?'),
1243				buttons: [
1244					$.extend({}, vex.dialog.buttons.YES, { text: _('OK') }),
1245					$.extend({}, vex.dialog.buttons.NO, { text: _('Cancel') })
1246				],
1247				callback: function(e) {
1248					if (e === true) {
1249						map.deletePage();
1250					}
1251				}
1252			});
1253		} else if (id === 'about') {
1254			this._map.showLOAboutDialog();
1255		} else if (id === 'latest-updates') {
1256			this._map.showWelcomeDialog(/*calledFromMenu=*/true);
1257		} else if (id === 'report-an-issue') {
1258			window.open('https://bugs.documentfoundation.org/enter_bug.cgi?product=LibreOffice%20Online', '_blank');
1259		} else if (id === 'inserthyperlink') {
1260			this._map.showHyperlinkDialog();
1261		} else if (id === 'keyboard-shortcuts' || id === 'online-help') {
1262			this._map.showHelp(id);
1263		} else if (L.Params.revHistoryEnabled && (id === 'rev-history' || id === 'last-mod')) {
1264			// if we are being loaded inside an iframe, ask
1265			// our host to show revision history mode
1266			this._map.fire('postMessage', {msgId: 'rev-history', args: {Deprecated: true}});
1267			this._map.fire('postMessage', {msgId: 'UI_FileVersions'});
1268		} else if (id === 'closedocument') {
1269			window.onClose();
1270		} else if (id === 'repair') {
1271			this._map._socket.sendMessage('commandvalues command=.uno:DocumentRepair');
1272		} else if (id === 'searchdialog') {
1273			if (this._map.isPermissionReadOnly()) {
1274				$('#toolbar-down').hide();
1275				$('#toolbar-search').show();
1276				$('#mobile-edit-button').hide();
1277				L.DomUtil.get('search-input').focus();
1278			} else {
1279				this._map.sendUnoCommand('.uno:SearchDialog');
1280			}
1281		} else if (id === 'inserttextbox') {
1282			this._map.sendUnoCommand('.uno:Text?CreateDirectly:bool=true');
1283		} else if (id === 'insertslidefield') {
1284			this._map.sendUnoCommand('.uno:InsertPageField');
1285		} else if (id === 'insertslidetitlefield') {
1286			this._map.sendUnoCommand('.uno:InsertPageTitleField');
1287		} else if (id === 'insertslidesfield') {
1288			this._map.sendUnoCommand('.uno:InsertPagesField');
1289		} else if (id === 'pagesetup') {
1290			this._map.sendUnoCommand('.uno:LOKSidebarWriterPage');
1291			this._map.fire('showwizardsidebar');
1292			window.pageMobileWizard = true;
1293		}
1294		// Inform the host if asked
1295		if (postmessage)
1296			this._map.fire('postMessage', {msgId: 'Clicked_Button', args: {Id: id} });
1297	},
1298
1299	_sendCommand: function (item) {
1300		var unoCommand = $(item).data('uno');
1301		if (unoCommand.startsWith('.uno:InsertPageHeader') || unoCommand.startsWith('.uno:InsertPageFooter')) {
1302			unoCommand = unoCommand + ($(item).hasClass('lo-menu-item-checked') ? 'On:bool=false' : 'On:bool=true');
1303		}
1304		else if (unoCommand.startsWith('.uno:SlideMasterPage')) {
1305			// Toggle between showing master page and closing it.
1306			unoCommand = ($(item).hasClass('lo-menu-item-checked') ? '.uno:CloseMasterView' : '.uno:SlideMasterPage');
1307		}
1308		else if (this._map._clip && this._map._clip.filterExecCopyPaste(unoCommand)) {
1309			return;
1310		}
1311
1312		if (unoCommand.startsWith('.uno:Sidebar') || unoCommand.startsWith('.uno:SlideMasterPage') ||
1313			unoCommand.startsWith('.uno:ModifyPage') || unoCommand.startsWith('.uno:SlideChangeWindow') ||
1314			unoCommand.startsWith('.uno:CustomAnimation') || unoCommand.startsWith('.uno:MasterSlidesPanel')) {
1315			window.initSidebarState = true;
1316		}
1317
1318		this._map.sendUnoCommand(unoCommand);
1319	},
1320
1321	_onItemSelected: function(e, item) {
1322		var self = e.data.self;
1323		var type = $(item).data('type');
1324		if (type === 'unocommand') {
1325			self._sendCommand(item);
1326		} else if (type === 'action') {
1327			self._executeAction(item);
1328		}
1329
1330		if (!window.mode.isMobile() && $(item).data('id') !== 'insertcomment')
1331			self._map.focus();
1332	},
1333
1334	_onMouseEnter: function(e, item) {
1335		var self = e.data.self;
1336		var type = $(item).data('type');
1337		if (type === 'unocommand') {
1338			var unoCommand = $(item).data('uno');
1339			self._map.setHelpTarget(unoCommand);
1340		} else if (type === 'action') {
1341			var id = $(item).data('id');
1342			self._map.setHelpTarget('modules/online/menu/' + id);
1343		}
1344	},
1345
1346	_onMouseLeave: function(e) {
1347		var self = e.data.self;
1348		self._map.setHelpTarget(null);
1349	},
1350
1351	_onKeyDown: function(e) {
1352		var self = e.data.self;
1353
1354		// handle help - F1
1355		if (e.type === 'keydown' && !e.shiftKey && !e.ctrlKey && !e.altKey && e.keyCode == 112) {
1356			self._map.showHelp('online-help');
1357		}
1358	},
1359
1360	_createFileIcon: function() {
1361		var iconClass = 'document-logo';
1362		var docType = this._map.getDocType();
1363		if (docType === 'text') {
1364			iconClass += ' writer-icon-img';
1365		} else if (docType === 'spreadsheet') {
1366			iconClass += ' calc-icon-img';
1367		} else if (docType === 'presentation' || docType === 'drawing') {
1368			iconClass += ' impress-icon-img';
1369		}
1370		$('.main-nav').addClass(docType + '-color-indicator');
1371
1372		var liItem = L.DomUtil.create('li', '');
1373		liItem.id = 'document-header';
1374		var aItem = L.DomUtil.create('div', iconClass, liItem);
1375		$(aItem).data('id', 'document-logo');
1376		$(aItem).data('type', 'action');
1377
1378		this._menubarCont.insertBefore(liItem, this._menubarCont.firstChild);
1379
1380		var $docLogo = $(aItem);
1381		$docLogo.bind('click', {self: this}, this._createDocument);
1382
1383	},
1384
1385	_checkItemVisibility: function(menuItem) {
1386		if (window.ThisIsTheiOSApp && menuItem.iosapp === false) {
1387			return false;
1388		}
1389		if (menuItem.id === 'about' && (L.DomUtil.get('about-dialog') === null)) {
1390			return false;
1391		}
1392		if (menuItem.id === 'signdocument' && (L.DomUtil.get('document-signing-bar') === null)) {
1393			return false;
1394		}
1395		if (this._map.isPermissionReadOnly() && menuItem.type === 'menu') {
1396			var found = false;
1397			for (var j in this.options.allowedReadonlyMenus) {
1398				if (this.options.allowedReadonlyMenus[j] === menuItem.id) {
1399					found = true;
1400					break;
1401				}
1402			}
1403			if (!found)
1404				return false;
1405		}
1406		if (this._map.isPermissionReadOnly()) {
1407			switch (menuItem.id) {
1408			case 'last-mod':
1409			case 'save':
1410			case 'pagesetup':
1411			case 'watermark':
1412				return false;
1413			}
1414		}
1415
1416		if (this._map.isPermissionEdit()) {
1417			switch (menuItem.id) {
1418			case 'savecomments':
1419				return false;
1420			}
1421		}
1422
1423		if (menuItem.type === 'action') {
1424			if ((menuItem.id === 'rev-history' && !L.Params.revHistoryEnabled) ||
1425				(menuItem.id === 'closedocument' && !L.Params.closeButtonEnabled) ||
1426				(menuItem.id === 'latest-updates' && !window.enableWelcomeMessage)) {
1427				return false;
1428			}
1429		}
1430
1431		if (menuItem.id === 'print' && this._map['wopi'].HidePrintOption)
1432			return false;
1433
1434		if (menuItem.id === 'save' && this._map['wopi'].HideSaveOption)
1435			return false;
1436
1437		if (menuItem.id === 'saveas' && this._map['wopi'].UserCanNotWriteRelative)
1438			return false;
1439
1440		if (menuItem.id === 'shareas' && !this._map['wopi'].EnableShare)
1441			return false;
1442
1443		if (menuItem.id === 'insertgraphicremote' && !this._map['wopi'].EnableInsertRemoteImage)
1444			return false;
1445
1446		if (menuItem.id && menuItem.id.startsWith('fullscreen-presentation') && this._map['wopi'].HideExportOption)
1447			return false;
1448
1449		if (menuItem.id === 'changesmenu' && this._map['wopi'].HideChangeTrackingControls)
1450			return false;
1451
1452		if (menuItem.drawing === false && this._map.getDocType() === 'drawing')
1453			return false;
1454
1455		// polyfill endsWidth for IE11
1456		if (!String.prototype.endsWith) {
1457			String.prototype.endsWith = function(search, thisLen) {
1458				if (thisLen === undefined || thisLen > this.length) {
1459					thisLen = this.length;
1460				}
1461				return this.substring(thisLen - search.length, thisLen) === search;
1462			};
1463		}
1464
1465		if (menuItem.id === 'downloadas-odg' && !this._map['wopi'].BaseFileName.endsWith('.odg'))
1466			return false;
1467
1468		// Keep track of all 'downloadas-' options and register them as
1469		// export formats with docLayer which can then be publicly accessed unlike
1470		// this Menubar control for which there doesn't seem to be any easy way
1471		// to get access to.
1472		if (menuItem.id && menuItem.id.startsWith('downloadas-')) {
1473			var format = menuItem.id.substring('downloadas-'.length);
1474			this._map._docLayer.registerExportFormat(menuItem.name, format);
1475
1476			if (this._map['wopi'].HideExportOption)
1477				return false;
1478		}
1479
1480		if (this._hiddenItems &&
1481		    $.inArray(menuItem.id, this._hiddenItems) !== -1)
1482			return false;
1483
1484		return true;
1485	},
1486
1487	_createMenu: function(menu) {
1488		var itemList = [];
1489		var docType = this._map.getDocType();
1490		for (var i in menu) {
1491			if (this._checkItemVisibility(menu[i]) === false)
1492				continue;
1493
1494			var liItem = L.DomUtil.create('li', '');
1495			if (menu[i].id) {
1496				liItem.id = 'menu-' + menu[i].id;
1497				if (menu[i].id === 'closedocument' && this._map.isPermissionReadOnly()) {
1498					// see corresponding css rule for readonly class usage
1499					L.DomUtil.addClass(liItem, 'readonly');
1500				}
1501			}
1502			var aItem = L.DomUtil.create('a', menu[i].disabled ? 'disabled' : '', liItem);
1503			if (menu[i].name !== undefined) {
1504				aItem.innerHTML = menu[i].name;
1505			} else if (menu[i].uno !== undefined) {
1506				aItem.innerHTML = _UNO(menu[i].uno, docType);
1507			} else {
1508				aItem.innerHTML = '';
1509			}
1510
1511			if (menu[i].type === 'menu') {
1512				var ulItem = L.DomUtil.create('ul', '', liItem);
1513				var subitemList = this._createMenu(menu[i].menu);
1514				if (!subitemList.length) {
1515					continue;
1516				}
1517				for (var idx in subitemList) {
1518					ulItem.appendChild(subitemList[idx]);
1519				}
1520			} else if (menu[i].type === 'unocommand' || menu[i].uno !== undefined) {
1521				$(aItem).data('type', 'unocommand');
1522				$(aItem).data('uno', menu[i].uno);
1523				$(aItem).data('tag', menu[i].tag);
1524			} else if (menu[i].type === 'separator') {
1525				$(aItem).addClass('separator');
1526			} else if (menu[i].type === 'action') {
1527				$(aItem).data('type', 'action');
1528				$(aItem).data('id', menu[i].id);
1529			}
1530
1531			if (menu[i].tablet == false && window.mode.isTablet()) {
1532				$(aItem).css('display', 'none');
1533			}
1534
1535			if (this._hiddenItems && $.inArray(menu[i].id, this._hiddenItems) !== -1) {
1536				$(aItem).css('display', 'none');
1537			}
1538
1539			itemList.push(liItem);
1540		}
1541
1542		return itemList;
1543	},
1544
1545	_getItems: function() {
1546		return $(this._menubarCont).children().children('ul').children('li').add($(this._menubarCont).children('li'));
1547	},
1548
1549	_getItem: function(targetId) {
1550		var items = this._getItems();
1551		var found = $(items).filter(function() {
1552			var item = this;
1553			var id = $(item).attr('id');
1554			if (id && id == 'menu-' + targetId) {
1555				return true;
1556			}
1557			return false;
1558		});
1559		return found.length ? found : null;
1560	},
1561
1562	hasItem: function(targetId) {
1563		return this._getItem(targetId) != null;
1564	},
1565
1566	hideItem: function(targetId) {
1567		var item = this._getItem(targetId);
1568		if (item) {
1569			if ($.inArray(targetId, this._hiddenItems) == -1)
1570				this._hiddenItems.push(targetId);
1571			$(item).css('display', 'none');
1572		}
1573	},
1574
1575	showItem: function(targetId) {
1576		var item = this._getItem(targetId);
1577		if (item) {
1578			if ($.inArray(targetId, this._hiddenItems) !== -1)
1579				this._hiddenItems.splice(this._hiddenItems.indexOf(targetId), 1);
1580			$(item).css('display', '');
1581		}
1582	},
1583
1584	_initializeMenu: function(menu) {
1585		var menuHtml = this._createMenu(menu);
1586		for (var i in menuHtml) {
1587			this._menubarCont.appendChild(menuHtml[i]);
1588		}
1589	},
1590
1591	generateFullMenuStructure: function() {
1592		var topMenu = {
1593			type : 'menubar',
1594			enabled : true,
1595			id : 'menubar',
1596			children : []
1597		};
1598		var docType = this._map.getDocType();
1599		var items = this.options['mobile' + docType];
1600
1601		for (var i = 0; i < items.length; i++) {
1602			if (this._checkItemVisibility(items[i]) === true) {
1603				var item = this._generateMenuStructure(items[i], docType, false);
1604				if (item)
1605					topMenu.children.push(item);
1606			}
1607		}
1608		return topMenu;
1609	},
1610
1611	generateInsertMenuStructure: function() {
1612		var docType = this._map.getDocType();
1613		var target = this.options['mobileInsertMenu'][docType];
1614
1615		var menuStructure = this._generateMenuStructure(target, docType, true);
1616		return menuStructure;
1617	},
1618
1619	_generateMenuStructure: function(item, docType, mainMenu) {
1620		var itemType;
1621		if (mainMenu) {
1622			itemType = 'mainmenu';
1623		} else {
1624			if (item.mobileapp == true && !window.ThisIsAMobileApp)
1625				return undefined;
1626			if (item.mobileapp === false && window.ThisIsAMobileApp)
1627				return undefined;
1628			if (!item.menu) {
1629				itemType = 'menuitem';
1630			} else {
1631				itemType = 'submenu';
1632			}
1633		}
1634
1635		var itemName;
1636		if (item.name)
1637			itemName = item.name;
1638		else if (item.uno)
1639			itemName = _UNO(item.uno, docType);
1640		else
1641			return undefined; // separator
1642
1643		var menuStructure = {
1644			id : item.id,
1645			type : itemType,
1646			enabled : !item.disabled,
1647			text : itemName,
1648			command : item.uno,
1649			executionType : item.type,
1650			data : item,
1651			children : []
1652		};
1653
1654		// Checked state for insert header / footer
1655		var insertHeaderString = '.uno:InsertPageHeader?PageStyle:string=';
1656		var insertFooterString = '.uno:InsertPageFooter?PageStyle:string=';
1657		if (item.uno && (item.uno.startsWith(insertHeaderString) || item.uno.startsWith(insertFooterString))) {
1658			var style = decodeURIComponent(item.uno.slice(item.uno.search('=') + 1));
1659			style = style.slice(0, style.length - 1);
1660			var shortUno = item.uno.slice(0, item.uno.search('\\?'));
1661			var state = this._map['stateChangeHandler'].getItemValue(shortUno);
1662			if (state && state[style]) {
1663				menuStructure['checked'] = true;
1664			}
1665		} else if (item.uno === '.uno:TrackChanges' ||
1666			item.uno === '.uno:ShowTrackedChanges' ||
1667			item.uno === '.uno:ControlCodes' ||
1668			item.uno === '.uno:SpellOnline' ||
1669			item.uno === '.uno:ShowResolvedAnnotations') {
1670			if (this._map['stateChangeHandler'].getItemValue(item.uno) === 'true') {
1671				menuStructure['checked'] = true;
1672			}
1673		}
1674
1675		if (item.menu)
1676		{
1677			for (var i = 0; i < item.menu.length; i++) {
1678				if (this._checkItemVisibility(item.menu[i]) === true) {
1679					var element = this._generateMenuStructure(item.menu[i], docType, false);
1680					if (element)
1681						menuStructure['children'].push(element);
1682				}
1683			}
1684		}
1685		return menuStructure;
1686	},
1687
1688	_findSubMenuByName: function(menuTarget, nameString) {
1689		if (menuTarget.name === nameString)
1690			return menuTarget;
1691
1692		if (menuTarget.menu)
1693		{
1694			for (var i = 0; i < menuTarget.menu.length; i++) {
1695				var foundItem = this._findSubMenuByName(menuTarget.menu[i], nameString);
1696				if (foundItem)
1697					return foundItem;
1698			}
1699		}
1700		return null;
1701	},
1702});
1703
1704L.control.menubar = function (options) {
1705	return new L.Control.Menubar(options);
1706};
1707