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

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