您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbar.js 26KB

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