Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. /* global APP, $, config, interfaceConfig, JitsiMeetJS */
  2. import UIUtil from '../util/UIUtil';
  3. import UIEvents from '../../../service/UI/UIEvents';
  4. import SideContainerToggler from "../side_pannels/SideContainerToggler";
  5. let emitter = null;
  6. let Toolbar;
  7. /**
  8. * Handlers for toolbar buttons.
  9. *
  10. * buttonId {string}: handler {function}
  11. */
  12. const buttonHandlers = {
  13. "toolbar_button_profile": function () {
  14. JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
  15. emitter.emit(UIEvents.TOGGLE_PROFILE);
  16. },
  17. "toolbar_button_mute": function () {
  18. let sharedVideoManager = APP.UI.getSharedVideoManager();
  19. if (APP.conference.audioMuted) {
  20. // If there's a shared video with the volume "on" and we aren't
  21. // the video owner, we warn the user
  22. // that currently it's not possible to unmute.
  23. if (sharedVideoManager
  24. && sharedVideoManager.isSharedVideoVolumeOn()
  25. && !sharedVideoManager.isSharedVideoOwner()) {
  26. UIUtil.animateShowElement(
  27. $("#unableToUnmutePopup"), true, 5000);
  28. }
  29. else {
  30. JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
  31. emitter.emit(UIEvents.AUDIO_MUTED, false, true);
  32. }
  33. } else {
  34. JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
  35. emitter.emit(UIEvents.AUDIO_MUTED, true, true);
  36. }
  37. },
  38. "toolbar_button_camera": function () {
  39. if (APP.conference.videoMuted) {
  40. JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
  41. emitter.emit(UIEvents.VIDEO_MUTED, false);
  42. } else {
  43. JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
  44. emitter.emit(UIEvents.VIDEO_MUTED, true);
  45. }
  46. },
  47. "toolbar_button_link": function () {
  48. JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
  49. emitter.emit(UIEvents.INVITE_CLICKED);
  50. },
  51. "toolbar_button_chat": function () {
  52. JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
  53. emitter.emit(UIEvents.TOGGLE_CHAT);
  54. },
  55. "toolbar_contact_list": function () {
  56. JitsiMeetJS.analytics.sendEvent(
  57. 'toolbar.contacts.toggled');
  58. emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
  59. },
  60. "toolbar_button_etherpad": function () {
  61. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  62. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  63. },
  64. "toolbar_button_sharedvideo": function () {
  65. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  66. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  67. },
  68. "toolbar_button_desktopsharing": function () {
  69. if (APP.conference.isSharingScreen) {
  70. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  71. } else {
  72. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  73. }
  74. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  75. },
  76. "toolbar_button_fullScreen": function() {
  77. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  78. emitter.emit(UIEvents.TOGGLE_FULLSCREEN);
  79. },
  80. "toolbar_button_sip": function () {
  81. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  82. showSipNumberInput();
  83. },
  84. "toolbar_button_dialpad": function () {
  85. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  86. dialpadButtonClicked();
  87. },
  88. "toolbar_button_settings": function () {
  89. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  90. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  91. },
  92. "toolbar_button_hangup": function () {
  93. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  94. emitter.emit(UIEvents.HANGUP);
  95. },
  96. "toolbar_button_raisehand": function () {
  97. JitsiMeetJS.analytics.sendEvent('toolbar.raiseHand.clicked');
  98. APP.conference.maybeToggleRaisedHand();
  99. }
  100. };
  101. /**
  102. * All toolbars buttons description
  103. */
  104. const defaultToolbarButtons = {
  105. 'microphone': {
  106. id: 'toolbar_button_mute',
  107. tooltipKey: 'toolbar.mute',
  108. className: "button icon-microphone",
  109. shortcut: 'M',
  110. shortcutAttr: 'mutePopover',
  111. shortcutFunc: function() {
  112. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  113. APP.conference.toggleAudioMuted();
  114. },
  115. shortcutDescription: "keyboardShortcuts.mute",
  116. popups: [
  117. {
  118. id: "micMutedPopup",
  119. className: "loginmenu",
  120. dataAttr: "[html]toolbar.micMutedPopup"
  121. },
  122. {
  123. id: "unableToUnmutePopup",
  124. className: "loginmenu",
  125. dataAttr: "[html]toolbar.unableToUnmutePopup"
  126. },
  127. {
  128. id: "talkWhileMutedPopup",
  129. className: "loginmenu",
  130. dataAttr: "[html]toolbar.talkWhileMutedPopup"
  131. }
  132. ],
  133. content: "Mute / Unmute",
  134. i18n: "[content]toolbar.mute"
  135. },
  136. 'camera': {
  137. id: 'toolbar_button_camera',
  138. tooltipKey: 'toolbar.videomute',
  139. className: "button icon-camera",
  140. shortcut: 'V',
  141. shortcutAttr: 'toggleVideoPopover',
  142. shortcutFunc: function() {
  143. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  144. APP.conference.toggleVideoMuted();
  145. },
  146. shortcutDescription: "keyboardShortcuts.videoMute",
  147. content: "Start / stop camera",
  148. i18n: "[content]toolbar.videomute"
  149. },
  150. 'desktop': {
  151. id: 'toolbar_button_desktopsharing',
  152. tooltipKey: 'toolbar.sharescreen',
  153. className: 'button icon-share-desktop',
  154. shortcut: 'D',
  155. shortcutAttr: 'toggleDesktopSharingPopover',
  156. shortcutFunc: function() {
  157. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  158. APP.conference.toggleScreenSharing();
  159. },
  160. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  161. content: 'Share screen',
  162. i18n: '[content]toolbar.sharescreen'
  163. },
  164. 'invite': {
  165. id: 'toolbar_button_link',
  166. tooltipKey: 'toolbar.invite',
  167. className: 'button icon-link',
  168. content: 'Invite others',
  169. i18n: '[content]toolbar.invite'
  170. },
  171. 'chat': {
  172. id: 'toolbar_button_chat',
  173. tooltipKey: 'toolbar.chat',
  174. className: 'button icon-chat',
  175. shortcut: 'C',
  176. shortcutAttr: 'toggleChatPopover',
  177. shortcutFunc: function() {
  178. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  179. APP.UI.toggleChat();
  180. },
  181. shortcutDescription: 'keyboardShortcuts.toggleChat',
  182. sideContainerId: 'chat_container',
  183. html: `<span class="badge-round">
  184. <span id="unreadMessages"></span>
  185. </span>`
  186. },
  187. 'contacts': {
  188. id: 'toolbar_contact_list',
  189. tooltipKey: 'bottomtoolbar.contactlist',
  190. className: 'button icon-contactList',
  191. sideContainerId: 'contacts_container',
  192. html: `<span class="badge-round">
  193. <span id="numberOfParticipants"></span>
  194. </span>`
  195. },
  196. 'profile': {
  197. id: 'toolbar_button_profile',
  198. tooltipKey: 'profile.setDisplayNameLabel',
  199. className: 'button',
  200. sideContainerId: 'profile_container',
  201. html: `<img id="avatar" src="images/avatar2.png"/>`
  202. },
  203. 'etherpad': {
  204. id: 'toolbar_button_etherpad',
  205. tooltipKey: 'toolbar.etherpad',
  206. className: 'button icon-share-doc'
  207. },
  208. 'fullscreen': {
  209. id: 'toolbar_button_fullScreen',
  210. tooltipKey: 'toolbar.fullscreen',
  211. className: "button icon-full-screen",
  212. shortcut: 'S',
  213. shortcutAttr: 'toggleFullscreenPopover',
  214. shortcutFunc: function() {
  215. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  216. APP.UI.toggleFullScreen();
  217. },
  218. shortcutDescription: "keyboardShortcuts.fullScreen",
  219. content: "Enter / Exit Full Screen",
  220. i18n: "[content]toolbar.fullscreen"
  221. },
  222. 'settings': {
  223. id: 'toolbar_button_settings',
  224. tooltipKey: 'toolbar.Settings',
  225. className: 'button icon-settings',
  226. sideContainerId: "settings_container"
  227. },
  228. 'hangup': {
  229. id: 'toolbar_button_hangup',
  230. tooltipKey: 'toolbar.hangup',
  231. className: "button icon-hangup",
  232. content: "Hang Up",
  233. i18n: "[content]toolbar.hangup"
  234. },
  235. 'raisehand': {
  236. id: "toolbar_button_raisehand",
  237. tooltipKey: 'toolbar.raiseHand',
  238. className: "button icon-raised-hand",
  239. shortcut: "R",
  240. shortcutAttr: "raiseHandPopover",
  241. shortcutFunc: function() {
  242. JitsiMeetJS.analytics.sendEvent("shortcut.raisehand.clicked");
  243. APP.conference.maybeToggleRaisedHand();
  244. },
  245. shortcutDescription: "keyboardShortcuts.raiseHand",
  246. content: "Raise Hand",
  247. i18n: "[content]toolbar.raiseHand"
  248. },
  249. //init and btn handler: Recording.initRecordingButton (Recording.js)
  250. 'recording': {
  251. id: 'toolbar_button_record',
  252. tooltipKey: 'liveStreaming.buttonTooltip',
  253. className: 'button'
  254. },
  255. 'sharedvideo': {
  256. id: 'toolbar_button_sharedvideo',
  257. tooltipKey: 'toolbar.sharedvideo',
  258. className: 'button icon-shared-video',
  259. html: `<ul id="sharedVideoMutedPopup"
  260. class="loginmenu extendedToolbarPopup">
  261. <li data-i18n="[html]toolbar.sharedVideoMutedPopup"></li>
  262. </ul>
  263. `
  264. },
  265. 'sip': {
  266. id: 'toolbar_button_sip',
  267. tooltipKey: 'toolbar.sip',
  268. className: 'button icon-telephone'
  269. },
  270. 'dialpad': {
  271. id: 'toolbar_button_dialpad',
  272. tooltipKey: 'toolbar.dialpad',
  273. className: 'button icon-dialpad',
  274. //TODO: remove it after UI.updateDTMFSupport fix
  275. hidden: true
  276. }
  277. };
  278. function dialpadButtonClicked() {
  279. //TODO show the dialpad box
  280. }
  281. function showSipNumberInput () {
  282. let defaultNumber = config.defaultSipNumber
  283. ? config.defaultSipNumber
  284. : '';
  285. let titleKey = "dialog.sipMsg";
  286. let msgString = (`
  287. <input class="input-control"
  288. name="sipNumber" type="text"
  289. value="${defaultNumber}" autofocus>`);
  290. APP.UI.messageHandler.openTwoButtonDialog({
  291. titleKey,
  292. msgString,
  293. leftButtonKey: "dialog.Dial",
  294. submitFunction: function (e, v, m, f) {
  295. if (v && f.sipNumber) {
  296. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  297. }
  298. },
  299. focus: ':input:first'
  300. });
  301. }
  302. /**
  303. * Get place for toolbar button.
  304. * Now it can be in main toolbar or in extended (left) toolbar
  305. *
  306. * @param btn {string}
  307. * @returns {string}
  308. */
  309. function getToolbarButtonPlace (btn) {
  310. return interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn) ?
  311. 'main' :
  312. 'extended';
  313. }
  314. Toolbar = {
  315. init (eventEmitter) {
  316. emitter = eventEmitter;
  317. // The toolbar is enabled by default.
  318. this.enabled = true;
  319. this.toolbarSelector = $("#mainToolbarContainer");
  320. this.extendedToolbarSelector = $("#extendedToolbar");
  321. // Initialise the toolbar buttons.
  322. // The main toolbar will only take into account
  323. // it's own configuration from interface_config.
  324. this._initToolbarButtons();
  325. this._setShortcutsAndTooltips();
  326. this._setButtonHandlers();
  327. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  328. (containerId, isVisible) => {
  329. Toolbar._handleSideToolbarContainerToggled( containerId,
  330. isVisible);
  331. });
  332. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  333. (isRaisedHand) => {
  334. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  335. });
  336. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  337. (isFullScreen) => {
  338. Toolbar._handleFullScreenToggled(isFullScreen);
  339. });
  340. if(!APP.tokenData.isGuest) {
  341. $("#toolbar_button_profile").addClass("unclickable");
  342. UIUtil.removeTooltip(
  343. document.getElementById('toolbar_button_profile'));
  344. }
  345. },
  346. /**
  347. * Enables / disables the toolbar.
  348. * @param {e} set to {true} to enable the toolbar or {false}
  349. * to disable it
  350. */
  351. enable (e) {
  352. this.enabled = e;
  353. if (!e && this.isVisible())
  354. this.hide(false);
  355. },
  356. /**
  357. * Indicates if the bottom toolbar is currently enabled.
  358. * @return {this.enabled}
  359. */
  360. isEnabled() {
  361. return this.enabled;
  362. },
  363. showEtherpadButton () {
  364. if (!$('#toolbar_button_etherpad').is(":visible")) {
  365. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  366. }
  367. },
  368. // Shows or hides the 'shared video' button.
  369. showSharedVideoButton () {
  370. let id = 'toolbar_button_sharedvideo';
  371. let shouldShow = UIUtil.isButtonEnabled('sharedvideo')
  372. && !config.disableThirdPartyRequests;
  373. if (shouldShow) {
  374. let el = document.getElementById(id);
  375. UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
  376. }
  377. UIUtil.showOrHideElement(id, shouldShow);
  378. },
  379. // checks whether desktop sharing is enabled and whether
  380. // we have params to start automatically sharing
  381. checkAutoEnableDesktopSharing () {
  382. if (UIUtil.isButtonEnabled('desktop')
  383. && config.autoEnableDesktopSharing) {
  384. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  385. }
  386. },
  387. // Shows or hides SIP calls button
  388. showSipCallButton (show) {
  389. let shouldShow = APP.conference.sipGatewayEnabled()
  390. && UIUtil.isButtonEnabled('sip') && show;
  391. let id = 'toolbar_button_sip';
  392. UIUtil.showOrHideElement(id, shouldShow);
  393. },
  394. // Shows or hides the dialpad button
  395. showDialPadButton (show) {
  396. let shouldShow = UIUtil.isButtonEnabled('dialpad') && show;
  397. let id = 'toolbar_button_dialpad';
  398. UIUtil.showOrHideElement(id, shouldShow);
  399. },
  400. /**
  401. * Update the state of the button. The button has blue glow if desktop
  402. * streaming is active.
  403. */
  404. updateDesktopSharingButtonState () {
  405. this._setToggledState( "toolbar_button_desktopsharing",
  406. APP.conference.isSharingScreen);
  407. },
  408. /**
  409. * Marks video icon as muted or not.
  410. *
  411. * @param {boolean} muted if icon should look like muted or not
  412. */
  413. toggleVideoIcon (muted) {
  414. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  415. this._setToggledState("toolbar_button_camera", muted);
  416. },
  417. /**
  418. * Enables / disables audio toolbar button.
  419. *
  420. * @param {boolean} enabled indicates if the button should be enabled
  421. * or disabled
  422. */
  423. setVideoIconEnabled (enabled) {
  424. this._setMediaIconEnabled(
  425. '#toolbar_button_camera',
  426. enabled,
  427. /* data-i18n attribute value */
  428. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  429. /* shortcut attribute value */
  430. 'toggleVideoPopover');
  431. enabled || this.toggleVideoIcon(!enabled);
  432. },
  433. /**
  434. * Enables/disables the toolbar button associated with a specific media such
  435. * as audio or video.
  436. *
  437. * @param {string} btn - The jQuery selector <tt>string</tt> which
  438. * identifies the toolbar button to be enabled/disabled.
  439. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  440. * <tt>btn</tt> or <tt>false</tt> to disable it.
  441. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  442. * attribute of the specified <tt>btn</tt>.
  443. * @param {string} shortcut - The value, if any, to assign to the
  444. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  445. * button is enabled.
  446. */
  447. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  448. const $btn = $(btn);
  449. $btn
  450. .prop('disabled', !enabled)
  451. .attr('data-i18n', dataI18n)
  452. .attr('shortcut', enabled && shortcut ? shortcut : '');
  453. enabled
  454. ? $btn.removeAttr('disabled')
  455. : $btn.attr('disabled', 'disabled');
  456. APP.translation.translateElement($btn);
  457. },
  458. /**
  459. * Marks audio icon as muted or not.
  460. *
  461. * @param {boolean} muted if icon should look like muted or not
  462. */
  463. toggleAudioIcon(muted) {
  464. $('#toolbar_button_mute')
  465. .toggleClass("icon-microphone", !muted)
  466. .toggleClass("icon-mic-disabled", muted);
  467. this._setToggledState("toolbar_button_mute", muted);
  468. },
  469. /**
  470. * Enables / disables audio toolbar button.
  471. *
  472. * @param {boolean} enabled indicates if the button should be enabled
  473. * or disabled
  474. */
  475. setAudioIconEnabled (enabled) {
  476. this._setMediaIconEnabled(
  477. '#toolbar_button_mute',
  478. enabled,
  479. /* data-i18n attribute value */
  480. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  481. /* shortcut attribute value */
  482. 'mutePopover');
  483. enabled || this.toggleAudioIcon(!enabled);
  484. },
  485. /**
  486. * Indicates if the toolbar is currently hovered.
  487. * @return {boolean} true if the toolbar is currently hovered,
  488. * false otherwise
  489. */
  490. isHovered() {
  491. var hovered = false;
  492. this.toolbarSelector.find('*').each(function () {
  493. let id = $(this).attr('id');
  494. if ($(`#${id}:hover`).length > 0) {
  495. hovered = true;
  496. // break each
  497. return false;
  498. }
  499. });
  500. if (hovered)
  501. return true;
  502. if ($("#bottomToolbar:hover").length > 0
  503. || $("#extendedToolbar:hover").length > 0
  504. || SideContainerToggler.isHovered()) {
  505. return true;
  506. }
  507. return false;
  508. },
  509. /**
  510. * Returns true if this toolbar is currently visible, or false otherwise.
  511. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  512. */
  513. isVisible() {
  514. return this.toolbarSelector.hasClass("fadeIn");
  515. },
  516. /**
  517. * Hides the toolbar with animation or not depending on the animate
  518. * parameter.
  519. */
  520. hide() {
  521. this.toolbarSelector
  522. .removeClass("fadeIn")
  523. .addClass("fadeOut");
  524. let slideInAnimation = (SideContainerToggler.isVisible)
  525. ? "slideInExtX"
  526. : "slideInX";
  527. let slideOutAnimation = (SideContainerToggler.isVisible)
  528. ? "slideOutExtX"
  529. : "slideOutX";
  530. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  531. .toggleClass(slideOutAnimation);
  532. },
  533. /**
  534. * Shows the toolbar with animation or not depending on the animate
  535. * parameter.
  536. */
  537. show() {
  538. if (this.toolbarSelector.hasClass("fadeOut")) {
  539. this.toolbarSelector.removeClass("fadeOut");
  540. }
  541. let slideInAnimation = (SideContainerToggler.isVisible)
  542. ? "slideInExtX"
  543. : "slideInX";
  544. let slideOutAnimation = (SideContainerToggler.isVisible)
  545. ? "slideOutExtX"
  546. : "slideOutX";
  547. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  548. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  549. }
  550. this.toolbarSelector.addClass("fadeIn");
  551. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  552. },
  553. registerClickListeners(listener) {
  554. $('#mainToolbarContainer').click(listener);
  555. $("#extendedToolbar").click(listener);
  556. },
  557. /**
  558. * Handles the side toolbar toggle.
  559. *
  560. * @param {string} containerId the identifier of the container element
  561. */
  562. _handleSideToolbarContainerToggled(containerId) {
  563. Object.keys(defaultToolbarButtons).forEach(
  564. id => {
  565. if (!UIUtil.isButtonEnabled(id))
  566. return;
  567. var button = defaultToolbarButtons[id];
  568. if (button.sideContainerId
  569. && button.sideContainerId === containerId) {
  570. UIUtil.buttonClick(button.id, "selected");
  571. return;
  572. }
  573. }
  574. );
  575. },
  576. /**
  577. * Handles full screen toggled.
  578. *
  579. * @param {boolean} isFullScreen indicates if we're currently in full
  580. * screen mode
  581. */
  582. _handleFullScreenToggled(isFullScreen) {
  583. let element
  584. = document.getElementById("toolbar_button_fullScreen");
  585. element.className = isFullScreen
  586. ? element.className
  587. .replace("icon-full-screen", "icon-exit-full-screen")
  588. : element.className
  589. .replace("icon-exit-full-screen", "icon-full-screen");
  590. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  591. },
  592. /**
  593. * Initialise toolbar buttons.
  594. */
  595. _initToolbarButtons() {
  596. interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
  597. let place = getToolbarButtonPlace(value);
  598. if (value && value in defaultToolbarButtons) {
  599. let button = defaultToolbarButtons[value];
  600. this._addToolbarButton(
  601. button,
  602. place,
  603. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  604. && index
  605. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  606. }
  607. });
  608. },
  609. /**
  610. * Adds the given button to the main (top) or extended (left) toolbar.
  611. *
  612. * @param {Object} the button to add.
  613. * @param {boolean} isFirst indicates if this is the first button in the
  614. * toolbar
  615. * @param {boolean} isLast indicates if this is the last button in the
  616. * toolbar
  617. * @param {boolean} isSplitter if this button is a splitter button for
  618. * the dialog, which means that a special splitter style will be applied
  619. */
  620. _addToolbarButton(button, place, isSplitter) {
  621. const places = {
  622. main: 'mainToolbar',
  623. extended: 'extendedToolbarButtons'
  624. };
  625. let id = places[place];
  626. let buttonElement = document.createElement("a");
  627. if (button.className) {
  628. buttonElement.className = button.className;
  629. }
  630. if (isSplitter) {
  631. let splitter = document.createElement('span');
  632. splitter.className = 'toolbar__splitter';
  633. document.getElementById(id).appendChild(splitter);
  634. }
  635. buttonElement.id = button.id;
  636. if (button.html)
  637. buttonElement.innerHTML = button.html;
  638. //TODO: remove it after UI.updateDTMFSupport fix
  639. if (button.hidden)
  640. buttonElement.style.display = 'none';
  641. if (button.shortcutAttr)
  642. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  643. if (button.content)
  644. buttonElement.setAttribute("content", button.content);
  645. if (button.i18n)
  646. buttonElement.setAttribute("data-i18n", button.i18n);
  647. buttonElement.setAttribute("data-container", "body");
  648. buttonElement.setAttribute("data-placement", "bottom");
  649. this._addPopups(buttonElement, button.popups);
  650. document.getElementById(id)
  651. .appendChild(buttonElement);
  652. },
  653. _addPopups(buttonElement, popups = []) {
  654. popups.forEach((popup) => {
  655. let popupElement = document.createElement("ul");
  656. popupElement.id = popup.id;
  657. popupElement.className = popup.className;
  658. let liElement = document.createElement("li");
  659. liElement.setAttribute("data-i18n", popup.dataAttr);
  660. popupElement.appendChild(liElement);
  661. buttonElement.appendChild(popupElement);
  662. });
  663. },
  664. /**
  665. * Sets the toggled state of the given element depending on the isToggled
  666. * parameter.
  667. *
  668. * @param elementId the element identifier
  669. * @param isToggled indicates if the element should be toggled or untoggled
  670. */
  671. _setToggledState(elementId, isToggled) {
  672. $("#" + elementId).toggleClass("toggled", isToggled);
  673. },
  674. /**
  675. * Sets Shortcuts and Tooltips for all toolbar buttons
  676. *
  677. * @private
  678. */
  679. _setShortcutsAndTooltips() {
  680. Object.keys(defaultToolbarButtons).forEach(
  681. id => {
  682. if (UIUtil.isButtonEnabled(id)) {
  683. let button = defaultToolbarButtons[id];
  684. let buttonElement = document.getElementById(button.id);
  685. if (!buttonElement) return false;
  686. let tooltipPosition
  687. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  688. .indexOf(id) > -1)
  689. ? "bottom" : "right";
  690. UIUtil.setTooltip( buttonElement,
  691. button.tooltipKey,
  692. tooltipPosition);
  693. if (button.shortcut)
  694. APP.keyboardshortcut.registerShortcut(
  695. button.shortcut,
  696. button.shortcutAttr,
  697. button.shortcutFunc,
  698. button.shortcutDescription
  699. );
  700. }
  701. }
  702. );
  703. },
  704. /**
  705. * Sets Handlers for all toolbar buttons
  706. *
  707. * @private
  708. */
  709. _setButtonHandlers() {
  710. Object.keys(buttonHandlers).forEach(
  711. buttonId => $(`#${buttonId}`).click(function(event) {
  712. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  713. })
  714. );
  715. }
  716. };
  717. export default Toolbar;