You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Toolbar.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. /* global AJS, 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. APP.UI.showCustomToolbarPopup(
  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: '[title]toolbar.micMutedPopup'
  121. },
  122. {
  123. id: 'unableToUnmutePopup',
  124. className: 'loginmenu',
  125. dataAttr: '[title]toolbar.unableToUnmutePopup'
  126. },
  127. {
  128. id: 'talkWhileMutedPopup',
  129. className: 'loginmenu',
  130. dataAttr: '[title]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. hidden: true // will be displayed once
  255. // the recording functionality is detected
  256. },
  257. 'sharedvideo': {
  258. id: 'toolbar_button_sharedvideo',
  259. tooltipKey: 'toolbar.sharedvideo',
  260. className: 'button icon-shared-video',
  261. popups: [
  262. {
  263. id: 'sharedVideoMutedPopup',
  264. className: 'loginmenu extendedToolbarPopup',
  265. dataAttr: '[title]toolbar.sharedVideoMutedPopup',
  266. dataAttrPosition: 'w'
  267. }
  268. ]
  269. },
  270. 'sip': {
  271. id: 'toolbar_button_sip',
  272. tooltipKey: 'toolbar.sip',
  273. className: 'button icon-telephone',
  274. hidden: true // will be displayed once
  275. // the SIP calls functionality is detected
  276. },
  277. 'dialpad': {
  278. id: 'toolbar_button_dialpad',
  279. tooltipKey: 'toolbar.dialpad',
  280. className: 'button icon-dialpad',
  281. //TODO: remove it after UI.updateDTMFSupport fix
  282. hidden: true
  283. }
  284. };
  285. function dialpadButtonClicked() {
  286. //TODO show the dialpad box
  287. }
  288. function showSipNumberInput () {
  289. let defaultNumber = config.defaultSipNumber
  290. ? config.defaultSipNumber
  291. : '';
  292. let titleKey = "dialog.sipMsg";
  293. let msgString = (`
  294. <input class="input-control"
  295. name="sipNumber" type="text"
  296. value="${defaultNumber}" autofocus>`);
  297. APP.UI.messageHandler.openTwoButtonDialog({
  298. titleKey,
  299. msgString,
  300. leftButtonKey: "dialog.Dial",
  301. submitFunction: function (e, v, m, f) {
  302. if (v && f.sipNumber) {
  303. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  304. }
  305. },
  306. focus: ':input:first'
  307. });
  308. }
  309. /**
  310. * Get place for toolbar button.
  311. * Now it can be in main toolbar or in extended (left) toolbar
  312. *
  313. * @param btn {string}
  314. * @returns {string}
  315. */
  316. function getToolbarButtonPlace (btn) {
  317. return interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn) ?
  318. 'main' :
  319. 'extended';
  320. }
  321. Toolbar = {
  322. init (eventEmitter) {
  323. emitter = eventEmitter;
  324. // The toolbar is enabled by default.
  325. this.enabled = true;
  326. this.toolbarSelector = $("#mainToolbarContainer");
  327. this.extendedToolbarSelector = $("#extendedToolbar");
  328. // Initialise the toolbar buttons.
  329. // The main toolbar will only take into account
  330. // it's own configuration from interface_config.
  331. this._initToolbarButtons();
  332. this._setShortcutsAndTooltips();
  333. this._setButtonHandlers();
  334. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  335. (containerId, isVisible) => {
  336. Toolbar._handleSideToolbarContainerToggled( containerId,
  337. isVisible);
  338. });
  339. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  340. (isRaisedHand) => {
  341. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  342. });
  343. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  344. (isFullScreen) => {
  345. Toolbar._handleFullScreenToggled(isFullScreen);
  346. });
  347. APP.UI.addListener(UIEvents.SHOW_CUSTOM_TOOLBAR_BUTTON_POPUP,
  348. (popupID, show, timeout) => {
  349. Toolbar._showCustomToolbarPopup(popupID, show, timeout);
  350. });
  351. if(!APP.tokenData.isGuest) {
  352. $("#toolbar_button_profile").addClass("unclickable");
  353. UIUtil.removeTooltip(
  354. document.getElementById('toolbar_button_profile'));
  355. }
  356. },
  357. /**
  358. * Enables / disables the toolbar.
  359. * @param {e} set to {true} to enable the toolbar or {false}
  360. * to disable it
  361. */
  362. enable (e) {
  363. this.enabled = e;
  364. if (!e && this.isVisible())
  365. this.hide(false);
  366. },
  367. /**
  368. * Indicates if the bottom toolbar is currently enabled.
  369. * @return {this.enabled}
  370. */
  371. isEnabled() {
  372. return this.enabled;
  373. },
  374. showEtherpadButton () {
  375. if (!$('#toolbar_button_etherpad').is(":visible")) {
  376. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  377. }
  378. },
  379. // Shows or hides the 'shared video' button.
  380. showSharedVideoButton () {
  381. let id = 'toolbar_button_sharedvideo';
  382. let shouldShow = UIUtil.isButtonEnabled('sharedvideo')
  383. && !config.disableThirdPartyRequests;
  384. if (shouldShow) {
  385. let el = document.getElementById(id);
  386. UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
  387. }
  388. UIUtil.setVisible(id, shouldShow);
  389. },
  390. // checks whether desktop sharing is enabled and whether
  391. // we have params to start automatically sharing
  392. checkAutoEnableDesktopSharing () {
  393. if (UIUtil.isButtonEnabled('desktop')
  394. && config.autoEnableDesktopSharing) {
  395. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  396. }
  397. },
  398. // Shows or hides SIP calls button
  399. showSipCallButton (show) {
  400. let shouldShow = APP.conference.sipGatewayEnabled()
  401. && UIUtil.isButtonEnabled('sip') && show;
  402. let id = 'toolbar_button_sip';
  403. UIUtil.setVisible(id, shouldShow);
  404. },
  405. // Shows or hides the dialpad button
  406. showDialPadButton (show) {
  407. let shouldShow = UIUtil.isButtonEnabled('dialpad') && show;
  408. let id = 'toolbar_button_dialpad';
  409. UIUtil.setVisible(id, shouldShow);
  410. },
  411. /**
  412. * Update the state of the button. The button has blue glow if desktop
  413. * streaming is active.
  414. */
  415. updateDesktopSharingButtonState () {
  416. this._setToggledState( "toolbar_button_desktopsharing",
  417. APP.conference.isSharingScreen);
  418. },
  419. /**
  420. * Marks video icon as muted or not.
  421. *
  422. * @param {boolean} muted if icon should look like muted or not
  423. */
  424. toggleVideoIcon (muted) {
  425. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  426. this._setToggledState("toolbar_button_camera", muted);
  427. },
  428. /**
  429. * Enables / disables audio toolbar button.
  430. *
  431. * @param {boolean} enabled indicates if the button should be enabled
  432. * or disabled
  433. */
  434. setVideoIconEnabled (enabled) {
  435. this._setMediaIconEnabled(
  436. '#toolbar_button_camera',
  437. enabled,
  438. /* data-i18n attribute value */
  439. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  440. /* shortcut attribute value */
  441. 'toggleVideoPopover');
  442. enabled || this.toggleVideoIcon(!enabled);
  443. },
  444. /**
  445. * Enables/disables the toolbar button associated with a specific media such
  446. * as audio or video.
  447. *
  448. * @param {string} btn - The jQuery selector <tt>string</tt> which
  449. * identifies the toolbar button to be enabled/disabled.
  450. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  451. * <tt>btn</tt> or <tt>false</tt> to disable it.
  452. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  453. * attribute of the specified <tt>btn</tt>.
  454. * @param {string} shortcut - The value, if any, to assign to the
  455. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  456. * button is enabled.
  457. */
  458. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  459. const $btn = $(btn);
  460. $btn
  461. .prop('disabled', !enabled)
  462. .attr('data-i18n', dataI18n)
  463. .attr('shortcut', enabled && shortcut ? shortcut : '');
  464. enabled
  465. ? $btn.removeAttr('disabled')
  466. : $btn.attr('disabled', 'disabled');
  467. APP.translation.translateElement($btn);
  468. },
  469. /**
  470. * Marks audio icon as muted or not.
  471. *
  472. * @param {boolean} muted if icon should look like muted or not
  473. */
  474. toggleAudioIcon(muted) {
  475. $('#toolbar_button_mute')
  476. .toggleClass("icon-microphone", !muted)
  477. .toggleClass("icon-mic-disabled", muted);
  478. this._setToggledState("toolbar_button_mute", muted);
  479. },
  480. /**
  481. * Enables / disables audio toolbar button.
  482. *
  483. * @param {boolean} enabled indicates if the button should be enabled
  484. * or disabled
  485. */
  486. setAudioIconEnabled (enabled) {
  487. this._setMediaIconEnabled(
  488. '#toolbar_button_mute',
  489. enabled,
  490. /* data-i18n attribute value */
  491. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  492. /* shortcut attribute value */
  493. 'mutePopover');
  494. enabled || this.toggleAudioIcon(!enabled);
  495. },
  496. /**
  497. * Indicates if the toolbar is currently hovered.
  498. * @return {boolean} true if the toolbar is currently hovered,
  499. * false otherwise
  500. */
  501. isHovered() {
  502. var hovered = false;
  503. this.toolbarSelector.find('*').each(function () {
  504. let id = $(this).attr('id');
  505. if ($(`#${id}:hover`).length > 0) {
  506. hovered = true;
  507. // break each
  508. return false;
  509. }
  510. });
  511. if (hovered)
  512. return true;
  513. if ($("#bottomToolbar:hover").length > 0
  514. || $("#extendedToolbar:hover").length > 0
  515. || SideContainerToggler.isHovered()) {
  516. return true;
  517. }
  518. return false;
  519. },
  520. /**
  521. * Returns true if this toolbar is currently visible, or false otherwise.
  522. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  523. */
  524. isVisible() {
  525. return this.toolbarSelector.hasClass("fadeIn");
  526. },
  527. /**
  528. * Hides the toolbar with animation or not depending on the animate
  529. * parameter.
  530. */
  531. hide() {
  532. this.toolbarSelector
  533. .removeClass("fadeIn")
  534. .addClass("fadeOut");
  535. let slideInAnimation = (SideContainerToggler.isVisible)
  536. ? "slideInExtX"
  537. : "slideInX";
  538. let slideOutAnimation = (SideContainerToggler.isVisible)
  539. ? "slideOutExtX"
  540. : "slideOutX";
  541. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  542. .toggleClass(slideOutAnimation);
  543. },
  544. /**
  545. * Shows the toolbar with animation or not depending on the animate
  546. * parameter.
  547. */
  548. show() {
  549. if (this.toolbarSelector.hasClass("fadeOut")) {
  550. this.toolbarSelector.removeClass("fadeOut");
  551. }
  552. let slideInAnimation = (SideContainerToggler.isVisible)
  553. ? "slideInExtX"
  554. : "slideInX";
  555. let slideOutAnimation = (SideContainerToggler.isVisible)
  556. ? "slideOutExtX"
  557. : "slideOutX";
  558. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  559. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  560. }
  561. this.toolbarSelector.addClass("fadeIn");
  562. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  563. },
  564. registerClickListeners(listener) {
  565. $('#mainToolbarContainer').click(listener);
  566. $("#extendedToolbar").click(listener);
  567. },
  568. /**
  569. * Handles the side toolbar toggle.
  570. *
  571. * @param {string} containerId the identifier of the container element
  572. */
  573. _handleSideToolbarContainerToggled(containerId) {
  574. Object.keys(defaultToolbarButtons).forEach(
  575. id => {
  576. if (!UIUtil.isButtonEnabled(id))
  577. return;
  578. var button = defaultToolbarButtons[id];
  579. if (button.sideContainerId
  580. && button.sideContainerId === containerId) {
  581. UIUtil.buttonClick(button.id, "selected");
  582. return;
  583. }
  584. }
  585. );
  586. },
  587. /**
  588. * Handles full screen toggled.
  589. *
  590. * @param {boolean} isFullScreen indicates if we're currently in full
  591. * screen mode
  592. */
  593. _handleFullScreenToggled(isFullScreen) {
  594. let element
  595. = document.getElementById("toolbar_button_fullScreen");
  596. element.className = isFullScreen
  597. ? element.className
  598. .replace("icon-full-screen", "icon-exit-full-screen")
  599. : element.className
  600. .replace("icon-exit-full-screen", "icon-full-screen");
  601. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  602. },
  603. /**
  604. * Initialise toolbar buttons.
  605. */
  606. _initToolbarButtons() {
  607. interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
  608. let place = getToolbarButtonPlace(value);
  609. if (value && value in defaultToolbarButtons) {
  610. let button = defaultToolbarButtons[value];
  611. this._addToolbarButton(
  612. button,
  613. place,
  614. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  615. && index
  616. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  617. }
  618. });
  619. },
  620. /**
  621. * Adds the given button to the main (top) or extended (left) toolbar.
  622. *
  623. * @param {Object} the button to add.
  624. * @param {boolean} isFirst indicates if this is the first button in the
  625. * toolbar
  626. * @param {boolean} isLast indicates if this is the last button in the
  627. * toolbar
  628. * @param {boolean} isSplitter if this button is a splitter button for
  629. * the dialog, which means that a special splitter style will be applied
  630. */
  631. _addToolbarButton(button, place, isSplitter) {
  632. const places = {
  633. main: 'mainToolbar',
  634. extended: 'extendedToolbarButtons'
  635. };
  636. let id = places[place];
  637. let buttonElement = document.createElement("a");
  638. if (button.className) {
  639. buttonElement.className = button.className;
  640. }
  641. if (isSplitter) {
  642. let splitter = document.createElement('span');
  643. splitter.className = 'toolbar__splitter';
  644. document.getElementById(id).appendChild(splitter);
  645. }
  646. buttonElement.id = button.id;
  647. if (button.html)
  648. buttonElement.innerHTML = button.html;
  649. //TODO: remove it after UI.updateDTMFSupport fix
  650. if (button.hidden)
  651. buttonElement.style.display = 'none';
  652. if (button.shortcutAttr)
  653. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  654. if (button.content)
  655. buttonElement.setAttribute("content", button.content);
  656. if (button.i18n)
  657. buttonElement.setAttribute("data-i18n", button.i18n);
  658. buttonElement.setAttribute("data-container", "body");
  659. buttonElement.setAttribute("data-placement", "bottom");
  660. this._addPopups(buttonElement, button.popups);
  661. document.getElementById(id)
  662. .appendChild(buttonElement);
  663. },
  664. _addPopups(buttonElement, popups = []) {
  665. popups.forEach((popup) => {
  666. const popupElement = document.createElement('div');
  667. popupElement.id = popup.id;
  668. popupElement.className = popup.className;
  669. popupElement.setAttribute('data-i18n', popup.dataAttr);
  670. let gravity = 'n';
  671. if (popup.dataAttrPosition)
  672. gravity = popup.dataAttrPosition;
  673. // use custom attribute to save gravity option
  674. // we use 'data-tooltip' in UIUtil to activate all tooltips
  675. // but we want these to be manually triggered
  676. popupElement.setAttribute('tooltip-gravity', gravity);
  677. APP.translation.translateElement($(popupElement));
  678. buttonElement.appendChild(popupElement);
  679. });
  680. },
  681. /**
  682. * Show custom popup/tooltip for a specified button.
  683. * @param popupSelectorID the selector id of the popup to show
  684. * @param show true or false/show or hide the popup
  685. * @param timeout the time to show the popup
  686. */
  687. _showCustomToolbarPopup(popupSelectorID, show, timeout) {
  688. const gravity = $(popupSelectorID).attr('tooltip-gravity');
  689. AJS.$(popupSelectorID)
  690. .tooltip({
  691. trigger: 'manual',
  692. html: true,
  693. gravity: gravity,
  694. title: 'title'});
  695. if (show) {
  696. AJS.$(popupSelectorID).tooltip('show');
  697. setTimeout(function () {
  698. // hide the tooltip
  699. AJS.$(popupSelectorID).tooltip('hide');
  700. }, timeout);
  701. } else {
  702. AJS.$(popupSelectorID).tooltip('hide');
  703. }
  704. },
  705. /**
  706. * Sets the toggled state of the given element depending on the isToggled
  707. * parameter.
  708. *
  709. * @param elementId the element identifier
  710. * @param isToggled indicates if the element should be toggled or untoggled
  711. */
  712. _setToggledState(elementId, isToggled) {
  713. $("#" + elementId).toggleClass("toggled", isToggled);
  714. },
  715. /**
  716. * Sets Shortcuts and Tooltips for all toolbar buttons
  717. *
  718. * @private
  719. */
  720. _setShortcutsAndTooltips() {
  721. Object.keys(defaultToolbarButtons).forEach(
  722. id => {
  723. if (UIUtil.isButtonEnabled(id)) {
  724. let button = defaultToolbarButtons[id];
  725. let buttonElement = document.getElementById(button.id);
  726. if (!buttonElement) return false;
  727. let tooltipPosition
  728. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  729. .indexOf(id) > -1)
  730. ? "bottom" : "right";
  731. UIUtil.setTooltip( buttonElement,
  732. button.tooltipKey,
  733. tooltipPosition);
  734. if (button.shortcut)
  735. APP.keyboardshortcut.registerShortcut(
  736. button.shortcut,
  737. button.shortcutAttr,
  738. button.shortcutFunc,
  739. button.shortcutDescription
  740. );
  741. }
  742. }
  743. );
  744. },
  745. /**
  746. * Sets Handlers for all toolbar buttons
  747. *
  748. * @private
  749. */
  750. _setButtonHandlers() {
  751. Object.keys(buttonHandlers).forEach(
  752. buttonId => $(`#${buttonId}`).click(function(event) {
  753. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  754. })
  755. );
  756. }
  757. };
  758. export default Toolbar;