選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

Toolbar.js 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. 'bottomtoolbar.filmstrip.toggled');
  165. emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  166. }
  167. };
  168. const defaultToolbarButtons = {
  169. 'microphone': {
  170. id: 'toolbar_button_mute',
  171. className: "button icon-microphone",
  172. shortcut: 'M',
  173. shortcutAttr: 'mutePopover',
  174. shortcutFunc: function() {
  175. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  176. APP.conference.toggleAudioMuted();
  177. },
  178. shortcutDescription: "keyboardShortcuts.mute",
  179. popups: [
  180. {
  181. id: "micMutedPopup",
  182. className: "loginmenu",
  183. dataAttr: "[html]toolbar.micMutedPopup"
  184. },
  185. {
  186. id: "unableToUnmutePopup",
  187. className: "loginmenu",
  188. dataAttr: "[html]toolbar.unableToUnmutePopup"
  189. }
  190. ],
  191. content: "Mute / Unmute",
  192. i18n: "[content]toolbar.mute"
  193. },
  194. 'camera': {
  195. id: 'toolbar_button_camera',
  196. className: "button icon-camera",
  197. shortcut: 'V',
  198. shortcutAttr: 'toggleVideoPopover',
  199. shortcutFunc: function() {
  200. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  201. APP.conference.toggleVideoMuted();
  202. },
  203. shortcutDescription: "keyboardShortcuts.videoMute",
  204. content: "Start / stop camera",
  205. i18n: "[content]toolbar.videomute"
  206. },
  207. 'desktop': {
  208. id: 'toolbar_button_desktopsharing',
  209. className: 'button icon-share-desktop',
  210. shortcut: 'D',
  211. shortcutAttr: 'toggleDesktopSharingPopover',
  212. shortcutFunc: function() {
  213. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  214. APP.conference.toggleScreenSharing();
  215. },
  216. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  217. content: 'Share screen',
  218. i18n: '[content]toolbar.sharescreen'
  219. },
  220. 'security': {
  221. id: 'toolbar_button_security'
  222. },
  223. 'invite': {
  224. id: 'toolbar_button_link',
  225. className: 'button icon-link',
  226. content: 'Invite others',
  227. i18n: '[content]toolbar.invite'
  228. },
  229. 'chat': {
  230. id: 'toolbar_button_chat',
  231. shortcut: 'C',
  232. shortcutAttr: 'toggleChatPopover',
  233. shortcutFunc: function() {
  234. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  235. APP.UI.toggleChat();
  236. },
  237. shortcutDescription: 'keyboardShortcuts.toggleChat',
  238. sideContainerId: 'chat_container'
  239. },
  240. 'contacts': {
  241. id: 'toolbar_contact_list',
  242. sideContainerId: 'contacts_container'
  243. },
  244. 'profile': {
  245. id: 'toolbar_button_profile',
  246. sideContainerId: 'profile_container'
  247. },
  248. 'etherpad': {
  249. id: 'toolbar_button_etherpad'
  250. },
  251. 'fullscreen': {
  252. id: 'toolbar_button_fullScreen',
  253. className: "button icon-full-screen",
  254. shortcut: 'F',
  255. shortcutAttr: 'toggleFullscreenPopover',
  256. shortcutFunc: function() {
  257. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  258. APP.UI.toggleFullScreen();
  259. },
  260. shortcutDescription: "keyboardShortcuts.toggleChat",
  261. content: "Enter / Exit Full Screen",
  262. i18n: "[content]toolbar.fullscreen"
  263. },
  264. 'settings': {
  265. id: 'toolbar_button_settings',
  266. sideContainerId: "settings_container"
  267. },
  268. 'hangup': {
  269. id: 'toolbar_button_hangup',
  270. className: "button icon-hangup",
  271. content: "Hang Up",
  272. i18n: "[content]toolbar.hangup"
  273. },
  274. 'filmstrip': {
  275. id: 'toolbar_film_strip',
  276. shortcut: "F",
  277. shortcutAttr: "filmstripPopover",
  278. shortcutFunc: function() {
  279. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  280. APP.UI.toggleFilmStrip();
  281. },
  282. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  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 sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  293. APP.UI.messageHandler.openTwoButtonDialog(
  294. null, null, null,
  295. `<h2>${sipMsg}</h2>
  296. <input name="sipNumber" type="text" value="${defaultNumber}" autofocus>`,
  297. false, "dialog.Dial",
  298. function (e, v, m, f) {
  299. if (v && f.sipNumber) {
  300. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  301. }
  302. },
  303. null, null, ':input:first'
  304. );
  305. }
  306. const Toolbar = {
  307. init (eventEmitter) {
  308. emitter = eventEmitter;
  309. // The toolbar is enabled by default.
  310. this.enabled = true;
  311. this.toolbarSelector = $("#mainToolbarContainer");
  312. this.extendedToolbarSelector = $("#extendedToolbar");
  313. this._initMainToolbarButtons();
  314. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  315. Object.keys(defaultToolbarButtons).forEach(
  316. id => {
  317. if (UIUtil.isButtonEnabled(id)) {
  318. var button = defaultToolbarButtons[id];
  319. if (button.shortcut)
  320. APP.keyboardshortcut.registerShortcut(
  321. button.shortcut,
  322. button.shortcutAttr,
  323. button.shortcutFunc,
  324. button.shortcutDescription
  325. );
  326. }
  327. }
  328. );
  329. Object.keys(buttonHandlers).forEach(
  330. buttonId => $(`#${buttonId}`).click(function(event) {
  331. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  332. })
  333. );
  334. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  335. function(containerId, isVisible) {
  336. Toolbar._handleSideToolbarContainerToggled( containerId,
  337. isVisible);
  338. });
  339. if(!APP.tokenData.isGuest) {
  340. $("#toolbar_button_profile").addClass("unclickable");
  341. }
  342. },
  343. /**
  344. * Enables / disables the toolbar.
  345. * @param {e} set to {true} to enable the toolbar or {false}
  346. * to disable it
  347. */
  348. enable (e) {
  349. this.enabled = e;
  350. if (!e && this.isVisible())
  351. this.hide(false);
  352. },
  353. /**
  354. * Indicates if the bottom toolbar is currently enabled.
  355. * @return {this.enabled}
  356. */
  357. isEnabled() {
  358. return this.enabled;
  359. },
  360. /**
  361. * Updates the room invite url.
  362. */
  363. updateRoomUrl (newRoomUrl) {
  364. roomUrl = newRoomUrl;
  365. // If the invite dialog has been already opened we update the
  366. // information.
  367. let inviteLink = document.getElementById('inviteLinkRef');
  368. if (inviteLink) {
  369. inviteLink.value = roomUrl;
  370. inviteLink.select();
  371. $('#inviteLinkRef').parent()
  372. .find('button[value=true]').prop('disabled', false);
  373. }
  374. },
  375. /**
  376. * Unlocks the lock button state.
  377. */
  378. unlockLockButton () {
  379. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  380. UIUtil.buttonClick("toolbar_button_security",
  381. "icon-security icon-security-locked");
  382. },
  383. /**
  384. * Updates the lock button state to locked.
  385. */
  386. lockLockButton () {
  387. if ($("#toolbar_button_security").hasClass("icon-security"))
  388. UIUtil.buttonClick("toolbar_button_security",
  389. "icon-security icon-security-locked");
  390. },
  391. /**
  392. * Shows or hides authentication button
  393. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  394. */
  395. showAuthenticateButton (show) {
  396. if (UIUtil.isButtonEnabled('authentication') && show) {
  397. $('#authentication').css({display: "inline"});
  398. } else {
  399. $('#authentication').css({display: "none"});
  400. }
  401. },
  402. showEtherpadButton () {
  403. if (!$('#toolbar_button_etherpad').is(":visible")) {
  404. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  405. }
  406. },
  407. // Shows or hides the 'shared video' button.
  408. showSharedVideoButton () {
  409. if (UIUtil.isButtonEnabled('sharedvideo')
  410. && config.disableThirdPartyRequests !== true) {
  411. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  412. } else {
  413. $('#toolbar_button_sharedvideo').css({display: "none"});
  414. }
  415. },
  416. // checks whether desktop sharing is enabled and whether
  417. // we have params to start automatically sharing
  418. checkAutoEnableDesktopSharing () {
  419. if (UIUtil.isButtonEnabled('desktop')
  420. && config.autoEnableDesktopSharing) {
  421. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  422. }
  423. },
  424. // Shows or hides SIP calls button
  425. showSipCallButton (show) {
  426. if (APP.conference.sipGatewayEnabled()
  427. && UIUtil.isButtonEnabled('sip') && show) {
  428. $('#toolbar_button_sip').css({display: "inline-block"});
  429. } else {
  430. $('#toolbar_button_sip').css({display: "none"});
  431. }
  432. },
  433. // Shows or hides the dialpad button
  434. showDialPadButton (show) {
  435. if (UIUtil.isButtonEnabled('dialpad') && show) {
  436. $('#toolbar_button_dialpad').css({display: "inline-block"});
  437. } else {
  438. $('#toolbar_button_dialpad').css({display: "none"});
  439. }
  440. },
  441. /**
  442. * Displays user authenticated identity name(login).
  443. * @param authIdentity identity name to be displayed.
  444. */
  445. setAuthenticatedIdentity (authIdentity) {
  446. if (authIdentity) {
  447. let selector = $('#toolbar_auth_identity');
  448. selector.css({display: "list-item"});
  449. selector.text(authIdentity);
  450. } else {
  451. $('#toolbar_auth_identity').css({display: "none"});
  452. }
  453. },
  454. /**
  455. * Shows/hides login button.
  456. * @param show <tt>true</tt> to show
  457. */
  458. showLoginButton (show) {
  459. if (UIUtil.isButtonEnabled('authentication') && show) {
  460. $('#toolbar_button_login').css({display: "list-item"});
  461. } else {
  462. $('#toolbar_button_login').css({display: "none"});
  463. }
  464. },
  465. /**
  466. * Shows/hides logout button.
  467. * @param show <tt>true</tt> to show
  468. */
  469. showLogoutButton (show) {
  470. if (UIUtil.isButtonEnabled('authentication') && show) {
  471. $('#toolbar_button_logout').css({display: "list-item"});
  472. } else {
  473. $('#toolbar_button_logout').css({display: "none"});
  474. }
  475. },
  476. /**
  477. * Update the state of the button. The button has blue glow if desktop
  478. * streaming is active.
  479. */
  480. updateDesktopSharingButtonState () {
  481. let button = $("#toolbar_button_desktopsharing");
  482. if (APP.conference.isSharingScreen) {
  483. button.addClass("glow");
  484. } else {
  485. button.removeClass("glow");
  486. }
  487. },
  488. /**
  489. * Marks video icon as muted or not.
  490. * @param {boolean} muted if icon should look like muted or not
  491. */
  492. markVideoIconAsMuted (muted) {
  493. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  494. },
  495. /**
  496. * Marks video icon as disabled or not.
  497. * @param {boolean} disabled if icon should look like disabled or not
  498. */
  499. markVideoIconAsDisabled (disabled) {
  500. var $btn = $('#toolbar_button_camera');
  501. $btn
  502. .prop("disabled", disabled)
  503. .attr("data-i18n", disabled
  504. ? "[content]toolbar.cameraDisabled"
  505. : "[content]toolbar.videomute")
  506. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  507. disabled
  508. ? $btn.attr("disabled", "disabled")
  509. : $btn.removeAttr("disabled");
  510. APP.translation.translateElement($btn);
  511. disabled && this.markVideoIconAsMuted(disabled);
  512. },
  513. /**
  514. * Marks audio icon as muted or not.
  515. * @param {boolean} muted if icon should look like muted or not
  516. */
  517. markAudioIconAsMuted (muted) {
  518. $('#toolbar_button_mute').toggleClass("icon-microphone",
  519. !muted).toggleClass("icon-mic-disabled", muted);
  520. },
  521. /**
  522. * Marks audio icon as disabled or not.
  523. * @param {boolean} disabled if icon should look like disabled or not
  524. */
  525. markAudioIconAsDisabled (disabled) {
  526. var $btn = $('#toolbar_button_mute');
  527. $btn
  528. .prop("disabled", disabled)
  529. .attr("data-i18n", disabled
  530. ? "[content]toolbar.micDisabled"
  531. : "[content]toolbar.mute")
  532. .attr("shortcut", disabled ? "" : "mutePopover");
  533. disabled
  534. ? $btn.attr("disabled", "disabled")
  535. : $btn.removeAttr("disabled");
  536. APP.translation.translateElement($btn);
  537. disabled && this.markAudioIconAsMuted(disabled);
  538. },
  539. /**
  540. * Indicates if the toolbar is currently hovered.
  541. * @return {boolean} true if the toolbar is currently hovered,
  542. * false otherwise
  543. */
  544. isHovered() {
  545. var hovered = false;
  546. this.toolbarSelector.find('*').each(function () {
  547. let id = $(this).attr('id');
  548. if ($(`#${id}:hover`).length > 0) {
  549. hovered = true;
  550. // break each
  551. return false;
  552. }
  553. });
  554. if (hovered)
  555. return true;
  556. if ($("#bottomToolbar:hover").length > 0
  557. || $("#extendedToolbar:hover").length > 0
  558. || SideContainerToggler.isHovered()) {
  559. return true;
  560. }
  561. return false;
  562. },
  563. /**
  564. * Returns true if this toolbar is currently visible, or false otherwise.
  565. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  566. */
  567. isVisible() {
  568. return this.toolbarSelector.hasClass("slideInY");
  569. },
  570. /**
  571. * Hides the toolbar with animation or not depending on the animate
  572. * parameter.
  573. */
  574. hide() {
  575. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  576. let slideInAnimation = (SideContainerToggler.isVisible)
  577. ? "slideInExtX"
  578. : "slideInX";
  579. let slideOutAnimation = (SideContainerToggler.isVisible)
  580. ? "slideOutExtX"
  581. : "slideOutX";
  582. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  583. .toggleClass(slideOutAnimation);
  584. },
  585. /**
  586. * Shows the toolbar with animation or not depending on the animate
  587. * parameter.
  588. */
  589. show() {
  590. if (this.toolbarSelector.hasClass("slideOutY"))
  591. this.toolbarSelector.toggleClass("slideOutY");
  592. let slideInAnimation = (SideContainerToggler.isVisible)
  593. ? "slideInExtX"
  594. : "slideInX";
  595. let slideOutAnimation = (SideContainerToggler.isVisible)
  596. ? "slideOutExtX"
  597. : "slideOutX";
  598. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  599. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  600. this.toolbarSelector.toggleClass("slideInY");
  601. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  602. },
  603. registerClickListeners(listener) {
  604. $('#mainToolbarContainer').click(listener);
  605. $("#extendedToolbar").click(listener);
  606. },
  607. /**
  608. * Handles the side toolbar toggle.
  609. */
  610. _handleSideToolbarContainerToggled(containerId, isVisible) {
  611. Object.keys(defaultToolbarButtons).forEach(
  612. id => {
  613. if (!UIUtil.isButtonEnabled(id))
  614. return;
  615. var button = defaultToolbarButtons[id];
  616. if (button.sideContainerId
  617. && button.sideContainerId === containerId) {
  618. UIUtil.buttonClick(button.id, "selected");
  619. return;
  620. }
  621. }
  622. );
  623. },
  624. /**
  625. * TODO: Fix mic popups
  626. * <a class="button icon-microphone" id="toolbar_button_mute" data-container="body" data-toggle="popover" data-placement="bottom" shortcut="mutePopover" data-i18n="[content]toolbar.mute" content="Mute / Unmute">
  627. * <ul id="micMutedPopup" class="loginmenu">
  628. * <li data-i18n="[html]toolbar.micMutedPopup"></li>
  629. * </ul>
  630. * <ul id="unableToUnmutePopup" class="loginmenu">
  631. * <li data-i18n="[html]toolbar.unableToUnmutePopup"></li>
  632. * </ul>
  633. * </a>
  634. */
  635. _initMainToolbarButtons() {
  636. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  637. if (value && value in defaultToolbarButtons) {
  638. let button = defaultToolbarButtons[value];
  639. this._addMainToolbarButton(
  640. button,
  641. (index === 0),
  642. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  643. }
  644. });
  645. },
  646. /**
  647. * Adds the given button to the main (top) toolbar.
  648. *
  649. * @param {Object} the button to add.
  650. * @param {boolean} isFirst indicates if this is the first button in the
  651. * toolbar
  652. * @param {boolean} isLast indicates if this is the last button in the
  653. * toolbar
  654. */
  655. _addMainToolbarButton(button, isFirst, isLast) {
  656. let buttonElement = document.createElement("a");
  657. if (button.className)
  658. buttonElement.className = button.className
  659. + ((isFirst) ? " first" : "")
  660. + ((isLast) ? " last" : "");
  661. buttonElement.id = button.id;
  662. if (button.shortcutAttr)
  663. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  664. if (button.content)
  665. buttonElement.setAttribute("content", button.content);
  666. if (button.i18n)
  667. buttonElement.setAttribute("data-i18n", button.i18n);
  668. buttonElement.setAttribute("data-container", "body");
  669. buttonElement.setAttribute("data-toggle", "popover");
  670. buttonElement.setAttribute("data-placement", "bottom");
  671. this._addPopups(buttonElement, button.popups);
  672. document.getElementById("mainToolbar")
  673. .appendChild(buttonElement);
  674. },
  675. _addPopups(buttonElement, popups = []) {
  676. popups.forEach((popup) => {
  677. let popupElement = document.createElement("ul");
  678. popupElement.id = popup.id;
  679. popupElement.className = popup.className;
  680. let liElement = document.createElement("li");
  681. liElement.setAttribute("data-i18n", popup.dataAttr);
  682. popupElement.appendChild(liElement);
  683. buttonElement.appendChild(popupElement);
  684. });
  685. }
  686. };
  687. export default Toolbar;