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 25KB

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