xref: /online/loleaflet/src/control/Control.MobileBottomBar.js (revision 89061cda512e5900280caef656a975364ff73e5d)
1/* -*- js-indent-level: 8 -*- */
2/*
3 * L.Control.MobileBottomBar
4 */
5
6/* global $ w2ui _ _UNO */
7L.Control.MobileBottomBar = L.Control.extend({
8
9	options: {
10		doctype: 'text'
11	},
12
13	initialize: function (docType) {
14		L.setOptions(this, {docType: docType});
15	},
16
17	onAdd: function (map) {
18		this.map = map;
19		this.create();
20
21		map.on('commandstatechanged', window.onCommandStateChanged);
22	},
23
24	getToolItems: function(docType) {
25		if (docType == 'text') {
26			return [
27				{type: 'button',  id: 'showsearchbar',  img: 'search', hint: _('Show the search bar')},
28				{type: 'break'},
29				{type: 'button',  id: 'bold',  img: 'bold', hint: _UNO('.uno:Bold'), uno: 'Bold'},
30				{type: 'button',  id: 'italic', img: 'italic', hint: _UNO('.uno:Italic'), uno: 'Italic'},
31				{type: 'button',  id: 'underline',  img: 'underline', hint: _UNO('.uno:Underline'), uno: 'Underline'},
32				{type: 'button',  id: 'strikeout', img: 'strikeout', hint: _UNO('.uno:Strikeout'), uno: 'Strikeout'},
33				{type: 'break'},
34				{type: 'button',  id: 'fontcolor', img: 'textcolor', hint: _UNO('.uno:FontColor')},
35				{type: 'button',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackgroundColor')},
36				{type: 'button',  id: 'leftpara',  img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true),
37					uno: {textCommand: 'LeftPara', objectCommand: 'ObjectAlignLeft'},
38					unosheet: 'AlignLeft', disabled: true},
39				{type: 'button',  id: 'centerpara',  img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true),
40					uno: {textCommand: 'CenterPara', objectCommand: 'AlignCenter'},
41					unosheet: 'AlignHorizontalCenter', disabled: true},
42				{type: 'button',  id: 'rightpara',  img: 'alignright', hint: _UNO('.uno:RightPara', '', true),
43					uno: {textCommand: 'RightPara', objectCommand: 'ObjectAlignRight'},
44					unosheet: 'AlignRight', disabled: true},
45				{type: 'button',  id: 'justifypara',  img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara', unosheet: '', disabled: true},
46				{type: 'break', id: 'breakspacing'},
47				{type: 'button',  id: 'defaultnumbering',  img: 'numbering', hint: _UNO('.uno:DefaultNumbering', '', true),uno: 'DefaultNumbering', disabled: true},
48				{type: 'button',  id: 'defaultbullet',  img: 'bullet', hint: _UNO('.uno:DefaultBullet', '', true), uno: 'DefaultBullet', disabled: true},
49				{type: 'break', id: 'breakbullet', hidden: true},
50				{type: 'button',  id: 'incrementindent',  img: 'incrementindent', hint: _UNO('.uno:IncrementIndent', '', true), uno: 'IncrementIndent', disabled: true},
51				{type: 'button',  id: 'decrementindent',  img: 'decrementindent', hint: _UNO('.uno:DecrementIndent', '', true), uno: 'DecrementIndent', disabled: true},
52			];
53		} else if (docType == 'spreadsheet') {
54			return [
55				{type: 'button',  id: 'showsearchbar',  img: 'search', hint: _('Show the search bar')},
56				{type: 'break'},
57				{type: 'button',  id: 'bold',  img: 'bold', hint: _UNO('.uno:Bold'), uno: 'Bold'},
58				{type: 'button',  id: 'italic', img: 'italic', hint: _UNO('.uno:Italic'), uno: 'Italic'},
59				{type: 'button',  id: 'underline',  img: 'underline', hint: _UNO('.uno:Underline'), uno: 'Underline'},
60				{type: 'button',  id: 'strikeout', img: 'strikeout', hint: _UNO('.uno:Strikeout'), uno: 'Strikeout'},
61				{type: 'break'},
62				{type: 'button',  id: 'fontcolor', img: 'textcolor', hint: _UNO('.uno:FontColor')},
63				{type: 'button',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackgroundColor')},
64				{type: 'button',  id: 'togglemergecells',  img: 'togglemergecells', hint: _UNO('.uno:ToggleMergeCells', 'spreadsheet', true), uno: 'ToggleMergeCells', disabled: true},
65	//			{type: 'break', id: 'breakmergecells'},
66				{type: 'break'},
67				{type: 'button', id: 'alignleft', img: 'alignleft', hint: _UNO('.uno:AlignLeft', 'spreadsheet', true), uno: 'AlignLeft'},
68				{type: 'button', id: 'alignhorizontalcenter', img: 'alignhorizontal', hint: _UNO('.uno:AlignHorizontalCenter', 'spreadsheet', true), uno: 'AlignHorizontalCenter'},
69				{type: 'button', id: 'alignright', img: 'alignright', hint: _UNO('.uno:AlignRight', 'spreadsheet', true), uno: 'AlignRight'},
70				{type: 'button', id: 'alignblock', img: 'alignblock', hint: _UNO('.uno:AlignBlock', 'spreadsheet', true), uno: 'AlignBlock'},
71				{type: 'break'},
72				{type: 'button',  id: 'wraptext',  img: 'wraptext', hint: _UNO('.uno:WrapText', 'spreadsheet', true), uno: 'WrapText', disabled: true},
73				{type: 'button',  id: 'insertrowsafter',  img: 'insertrowsafter', hint: _UNO('.uno:InsertRowsAfter'), uno: 'InsertRowsAfter'},
74				{type: 'button',  id: 'insertcolumnsafter',  img: 'insertcolumnsafter', hint: _UNO('.uno:InsertColumnsAfter'), uno: 'InsertColumnsAfter'},
75	/*			{type: 'button',  id: 'numberformatcurrency',  img: 'numberformatcurrency', hint: _UNO('.uno:NumberFormatCurrency', 'spreadsheet', true), uno: 'NumberFormatCurrency', disabled: true},
76				{type: 'button',  id: 'numberformatpercent',  img: 'numberformatpercent', hint: _UNO('.uno:NumberFormatPercent', 'spreadsheet', true), uno: 'NumberFormatPercent', disabled: true},
77				{type: 'button',  id: 'numberformatdecdecimals',  img: 'numberformatdecdecimals', hint: _UNO('.uno:NumberFormatDecDecimals', 'spreadsheet', true), hidden: true, uno: 'NumberFormatDecDecimals', disabled: true},
78				{type: 'button',  id: 'numberformatincdecimals',  img: 'numberformatincdecimals', hint: _UNO('.uno:NumberFormatIncDecimals', 'spreadsheet', true), hidden: true, uno: 'NumberFormatIncDecimals', disabled: true},
79				{type: 'button',  id: 'sum',  img: 'autosum', hint: _('Sum')},
80				{type: 'break',   id: 'break-number'}, */
81			];
82		} else if (docType == 'presentation') {
83			return [
84				{type: 'button',  id: 'showsearchbar',  img: 'search', hint: _('Show the search bar')},
85				{type: 'break'},
86				{type: 'button',  id: 'bold',  img: 'bold', hint: _UNO('.uno:Bold'), uno: 'Bold'},
87	//			{type: 'button',  id: 'italic', img: 'italic', hint: _UNO('.uno:Italic'), uno: 'Italic'},
88				{type: 'button',  id: 'underline',  img: 'underline', hint: _UNO('.uno:Underline'), uno: 'Underline'},
89				{type: 'button',  id: 'strikeout', img: 'strikeout', hint: _UNO('.uno:Strikeout'), uno: 'Strikeout'},
90				{type: 'button',  id: 'fontcolor', img: 'textcolor', hint: _UNO('.uno:FontColor')},
91				{type: 'button',  id: 'backcolor', img: 'backcolor', hint: _UNO('.uno:BackgroundColor')},
92				{type: 'break'},
93				{type: 'button', id: 'leftpara', img: 'alignleft', hint: _UNO('.uno:LeftPara', '', true),
94					uno: {textCommand: 'LeftPara', objectCommand: 'ObjectAlignLeft'}},
95				{type: 'button', id: 'centerpara', img: 'alignhorizontal', hint: _UNO('.uno:CenterPara', '', true),
96					uno: {textCommand: 'CenterPara', objectCommand: 'AlignCenter'}},
97				{type: 'button', id: 'rightpara', img: 'alignright', hint: _UNO('.uno:RightPara', '', true),
98					uno: {textCommand: 'RightPara', objectCommand: 'ObjectAlignRight'}},
99				{type: 'button', id: 'justifypara', img: 'alignblock', hint: _UNO('.uno:JustifyPara', '', true), uno: 'JustifyPara'},
100				{type: 'break'},
101				{type: 'button',  id: 'defaultbullet',  img: 'bullet', hint: _UNO('.uno:DefaultBullet', '', true), uno: 'DefaultBullet', disabled: true},
102			];
103		}
104	},
105
106	create: function() {
107		var toolItems = this.getToolItems(this.options.docType);
108
109		var toolbar = $('#toolbar-down');
110		toolbar.w2toolbar({
111			name: 'editbar',
112			items: toolItems,
113			onClick: function (e) {
114				// use global handler
115				window.onClick(e, e.target);
116				window.hideTooltip(this, e.target);
117			},
118			onRefresh: function(edata) {
119				if (edata.target === 'inserttable')
120					window.insertTable();
121
122				if (edata.target === 'insertshapes')
123					window.insertShapes();
124			}
125		});
126
127		toolbar.bind('touchstart', function(e) {
128			w2ui['editbar'].touchStarted = true;
129			var touchEvent = e.originalEvent;
130			if (touchEvent && touchEvent.touches.length > 1) {
131				L.DomEvent.preventDefault(e);
132			}
133		});
134	}
135});
136
137L.control.mobileBottomBar = function (docType) {
138	return new L.Control.MobileBottomBar(docType);
139};
140