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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  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. emitter.emit(UIEvents.TOGGLE_FULLSCREEN);
  74. },
  75. "toolbar_button_sip": function () {
  76. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  77. showSipNumberInput();
  78. },
  79. "toolbar_button_dialpad": function () {
  80. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  81. dialpadButtonClicked();
  82. },
  83. "toolbar_button_settings": function () {
  84. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  85. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  86. },
  87. "toolbar_button_hangup": function () {
  88. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  89. emitter.emit(UIEvents.HANGUP);
  90. },
  91. "toolbar_button_login": function () {
  92. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
  93. emitter.emit(UIEvents.AUTH_CLICKED);
  94. },
  95. "toolbar_button_logout": function () {
  96. let titleKey = "dialog.logoutTitle";
  97. let msgKey = "dialog.logoutQuestion";
  98. JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
  99. // Ask for confirmation
  100. APP.UI.messageHandler.openTwoButtonDialog({
  101. titleKey,
  102. msgKey,
  103. leftButtonKey: "dialog.Yes",
  104. submitFunction: function (evt, yes) {
  105. if (yes) {
  106. emitter.emit(UIEvents.LOGOUT);
  107. }
  108. }
  109. });
  110. },
  111. "toolbar_film_strip": function () {
  112. JitsiMeetJS.analytics.sendEvent(
  113. 'toolbar.filmstrip.toggled');
  114. emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
  115. },
  116. "toolbar_button_raisehand": function () {
  117. JitsiMeetJS.analytics.sendEvent(
  118. 'toolbar.raiseHand.clicked');
  119. APP.conference.maybeToggleRaisedHand();
  120. }
  121. };
  122. const defaultToolbarButtons = {
  123. 'microphone': {
  124. id: 'toolbar_button_mute',
  125. tooltipKey: 'toolbar.mute',
  126. className: "button icon-microphone",
  127. shortcut: 'M',
  128. shortcutAttr: 'mutePopover',
  129. shortcutFunc: function() {
  130. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  131. APP.conference.toggleAudioMuted();
  132. },
  133. shortcutDescription: "keyboardShortcuts.mute",
  134. popups: [
  135. {
  136. id: "micMutedPopup",
  137. className: "loginmenu",
  138. dataAttr: "[html]toolbar.micMutedPopup"
  139. },
  140. {
  141. id: "unableToUnmutePopup",
  142. className: "loginmenu",
  143. dataAttr: "[html]toolbar.unableToUnmutePopup"
  144. },
  145. {
  146. id: "talkWhileMutedPopup",
  147. className: "loginmenu",
  148. dataAttr: "[html]toolbar.talkWhileMutedPopup"
  149. }
  150. ],
  151. content: "Mute / Unmute",
  152. i18n: "[content]toolbar.mute"
  153. },
  154. 'camera': {
  155. id: 'toolbar_button_camera',
  156. tooltipKey: 'toolbar.videomute',
  157. className: "button icon-camera",
  158. shortcut: 'V',
  159. shortcutAttr: 'toggleVideoPopover',
  160. shortcutFunc: function() {
  161. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  162. APP.conference.toggleVideoMuted();
  163. },
  164. shortcutDescription: "keyboardShortcuts.videoMute",
  165. content: "Start / stop camera",
  166. i18n: "[content]toolbar.videomute"
  167. },
  168. 'desktop': {
  169. id: 'toolbar_button_desktopsharing',
  170. tooltipKey: 'toolbar.sharescreen',
  171. className: 'button icon-share-desktop',
  172. shortcut: 'D',
  173. shortcutAttr: 'toggleDesktopSharingPopover',
  174. shortcutFunc: function() {
  175. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  176. APP.conference.toggleScreenSharing();
  177. },
  178. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  179. content: 'Share screen',
  180. i18n: '[content]toolbar.sharescreen'
  181. },
  182. 'invite': {
  183. id: 'toolbar_button_link',
  184. tooltipKey: 'toolbar.invite',
  185. className: 'button icon-link',
  186. content: 'Invite others',
  187. i18n: '[content]toolbar.invite'
  188. },
  189. 'chat': {
  190. id: 'toolbar_button_chat',
  191. tooltipKey: 'toolbar.chat',
  192. shortcut: 'C',
  193. shortcutAttr: 'toggleChatPopover',
  194. shortcutFunc: function() {
  195. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  196. APP.UI.toggleChat();
  197. },
  198. shortcutDescription: 'keyboardShortcuts.toggleChat',
  199. sideContainerId: 'chat_container'
  200. },
  201. 'contacts': {
  202. id: 'toolbar_contact_list',
  203. tooltipKey: 'bottomtoolbar.contactlist',
  204. sideContainerId: 'contacts_container'
  205. },
  206. 'profile': {
  207. id: 'toolbar_button_profile',
  208. tooltipKey: 'profile.setDisplayNameLabel',
  209. sideContainerId: 'profile_container'
  210. },
  211. 'etherpad': {
  212. id: 'toolbar_button_etherpad',
  213. tooltipKey: 'toolbar.etherpad',
  214. },
  215. 'fullscreen': {
  216. id: 'toolbar_button_fullScreen',
  217. tooltipKey: 'toolbar.fullscreen',
  218. className: "button icon-full-screen",
  219. shortcut: 'S',
  220. shortcutAttr: 'toggleFullscreenPopover',
  221. shortcutFunc: function() {
  222. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  223. APP.UI.toggleFullScreen();
  224. },
  225. shortcutDescription: "keyboardShortcuts.fullScreen",
  226. content: "Enter / Exit Full Screen",
  227. i18n: "[content]toolbar.fullscreen"
  228. },
  229. 'settings': {
  230. id: 'toolbar_button_settings',
  231. tooltipKey: 'toolbar.Settings',
  232. sideContainerId: "settings_container"
  233. },
  234. 'hangup': {
  235. id: 'toolbar_button_hangup',
  236. tooltipKey: 'toolbar.hangup',
  237. className: "button icon-hangup",
  238. content: "Hang Up",
  239. i18n: "[content]toolbar.hangup"
  240. },
  241. 'filmstrip': {
  242. id: 'toolbar_film_strip',
  243. tooltipKey: 'toolbar.filmstrip',
  244. shortcut: "F",
  245. shortcutAttr: "filmstripPopover",
  246. shortcutFunc: function() {
  247. JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
  248. APP.UI.toggleFilmStrip();
  249. },
  250. shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
  251. },
  252. 'raisehand': {
  253. id: "toolbar_button_raisehand",
  254. tooltipKey: 'toolbar.raiseHand',
  255. className: "button icon-raised-hand",
  256. shortcut: "R",
  257. shortcutAttr: "raiseHandPopover",
  258. shortcutFunc: function() {
  259. JitsiMeetJS.analytics.sendEvent("shortcut.raisehand.clicked");
  260. APP.conference.maybeToggleRaisedHand();
  261. },
  262. shortcutDescription: "keyboardShortcuts.raiseHand",
  263. content: "Raise Hand",
  264. i18n: "[content]toolbar.raiseHand"
  265. }
  266. };
  267. function dialpadButtonClicked() {
  268. //TODO show the dialpad box
  269. }
  270. function showSipNumberInput () {
  271. let defaultNumber = config.defaultSipNumber
  272. ? config.defaultSipNumber
  273. : '';
  274. let titleKey = "dialog.sipMsg";
  275. let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
  276. let msgString = (`
  277. <input name="sipNumber" type="text"
  278. value="${defaultNumber}" autofocus>
  279. `);
  280. APP.UI.messageHandler.openTwoButtonDialog({
  281. titleKey,
  282. titleString: sipMsg,
  283. msgString,
  284. leftButtonKey: "dialog.Dial",
  285. submitFunction: function (e, v, m, f) {
  286. if (v && f.sipNumber) {
  287. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  288. }
  289. },
  290. focus: ':input:first'
  291. });
  292. }
  293. Toolbar = {
  294. init (eventEmitter) {
  295. emitter = eventEmitter;
  296. // The toolbar is enabled by default.
  297. this.enabled = true;
  298. this.toolbarSelector = $("#mainToolbarContainer");
  299. this.extendedToolbarSelector = $("#extendedToolbar");
  300. // First hide all disabled buttons in the extended toolbar.
  301. // TODO: Make the extended toolbar dynamically created.
  302. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  303. // Initialise the main toolbar. The main toolbar will only take into
  304. // account it's own configuration from interface_config.
  305. this._initMainToolbarButtons();
  306. Object.keys(defaultToolbarButtons).forEach(
  307. id => {
  308. if (UIUtil.isButtonEnabled(id)) {
  309. let button = defaultToolbarButtons[id];
  310. let buttonElement = document.getElementById(button.id);
  311. let tooltipPosition
  312. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  313. .indexOf(id) > -1)
  314. ? "bottom" : "right";
  315. UIUtil.setTooltip( buttonElement,
  316. button.tooltipKey,
  317. tooltipPosition);
  318. if (button.shortcut)
  319. APP.keyboardshortcut.registerShortcut(
  320. button.shortcut,
  321. button.shortcutAttr,
  322. button.shortcutFunc,
  323. button.shortcutDescription
  324. );
  325. }
  326. }
  327. );
  328. Object.keys(buttonHandlers).forEach(
  329. buttonId => $(`#${buttonId}`).click(function(event) {
  330. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  331. })
  332. );
  333. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  334. (containerId, isVisible) => {
  335. Toolbar._handleSideToolbarContainerToggled( containerId,
  336. isVisible);
  337. });
  338. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  339. (isRaisedHand) => {
  340. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  341. });
  342. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  343. (isFullScreen) => {
  344. Toolbar._handleFullScreenToggled(isFullScreen);
  345. });
  346. if(!APP.tokenData.isGuest) {
  347. $("#toolbar_button_profile").addClass("unclickable");
  348. UIUtil.removeTooltip(
  349. document.getElementById('toolbar_button_profile'));
  350. }
  351. },
  352. /**
  353. * Enables / disables the toolbar.
  354. * @param {e} set to {true} to enable the toolbar or {false}
  355. * to disable it
  356. */
  357. enable (e) {
  358. this.enabled = e;
  359. if (!e && this.isVisible())
  360. this.hide(false);
  361. },
  362. /**
  363. * Indicates if the bottom toolbar is currently enabled.
  364. * @return {this.enabled}
  365. */
  366. isEnabled() {
  367. return this.enabled;
  368. },
  369. /**
  370. * Shows or hides authentication button
  371. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  372. */
  373. showAuthenticateButton (show) {
  374. let display = show ? 'block' : 'none';
  375. $('#authenticationContainer').css({display});
  376. },
  377. showEtherpadButton () {
  378. if (!$('#toolbar_button_etherpad').is(":visible")) {
  379. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  380. }
  381. },
  382. // Shows or hides the 'shared video' button.
  383. showSharedVideoButton () {
  384. let $element = $('#toolbar_button_sharedvideo');
  385. if (UIUtil.isButtonEnabled('sharedvideo')
  386. && config.disableThirdPartyRequests !== true) {
  387. $element.css({display: "inline-block"});
  388. UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
  389. } else {
  390. $('#toolbar_button_sharedvideo').css({display: "none"});
  391. }
  392. },
  393. // checks whether desktop sharing is enabled and whether
  394. // we have params to start automatically sharing
  395. checkAutoEnableDesktopSharing () {
  396. if (UIUtil.isButtonEnabled('desktop')
  397. && config.autoEnableDesktopSharing) {
  398. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  399. }
  400. },
  401. // Shows or hides SIP calls button
  402. showSipCallButton (show) {
  403. if (APP.conference.sipGatewayEnabled()
  404. && UIUtil.isButtonEnabled('sip') && show) {
  405. $('#toolbar_button_sip').css({display: "inline-block"});
  406. } else {
  407. $('#toolbar_button_sip').css({display: "none"});
  408. }
  409. },
  410. // Shows or hides the dialpad button
  411. showDialPadButton (show) {
  412. if (UIUtil.isButtonEnabled('dialpad') && show) {
  413. $('#toolbar_button_dialpad').css({display: "inline-block"});
  414. } else {
  415. $('#toolbar_button_dialpad').css({display: "none"});
  416. }
  417. },
  418. /**
  419. * Displays user authenticated identity name(login).
  420. * @param authIdentity identity name to be displayed.
  421. */
  422. setAuthenticatedIdentity (authIdentity) {
  423. let selector = $('#toolbar_auth_identity');
  424. if (authIdentity) {
  425. selector.css({display: "list-item"});
  426. selector.text(authIdentity);
  427. } else {
  428. selector.css({display: "none"});
  429. selector.text('');
  430. }
  431. },
  432. /**
  433. * Shows/hides login button.
  434. * @param show <tt>true</tt> to show
  435. */
  436. showLoginButton (show) {
  437. if (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 (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. * @param {string} containerId the identifier of the container element
  611. */
  612. _handleSideToolbarContainerToggled(containerId) {
  613. Object.keys(defaultToolbarButtons).forEach(
  614. id => {
  615. if (!UIUtil.isButtonEnabled(id))
  616. return;
  617. var button = defaultToolbarButtons[id];
  618. if (button.sideContainerId
  619. && button.sideContainerId === containerId) {
  620. UIUtil.buttonClick(button.id, "selected");
  621. return;
  622. }
  623. }
  624. );
  625. },
  626. /**
  627. * Handles full screen toggled.
  628. *
  629. * @param {boolean} isFullScreen indicates if we're currently in full
  630. * screen mode
  631. */
  632. _handleFullScreenToggled(isFullScreen) {
  633. let element
  634. = document.getElementById("toolbar_button_fullScreen");
  635. element.className = isFullScreen
  636. ? element.className
  637. .replace("icon-full-screen", "icon-exit-full-screen")
  638. : element.className
  639. .replace("icon-exit-full-screen", "icon-full-screen");
  640. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  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. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  654. && index
  655. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  656. }
  657. });
  658. },
  659. /**
  660. * Adds the given button to the main (top) toolbar.
  661. *
  662. * @param {Object} the button to add.
  663. * @param {boolean} isFirst indicates if this is the first button in the
  664. * toolbar
  665. * @param {boolean} isLast indicates if this is the last button in the
  666. * toolbar
  667. * @param {boolean} isSplitter if this button is a splitter button for
  668. * the dialog, which means that a special splitter style will be applied
  669. */
  670. _addMainToolbarButton(button, isFirst, isLast, isSplitter) {
  671. let buttonElement = document.createElement("a");
  672. if (button.className)
  673. buttonElement.className = button.className
  674. + ((isFirst) ? " first" : "")
  675. + ((isLast) ? " last" : "")
  676. + ((isSplitter) ? " splitter": "");
  677. buttonElement.id = button.id;
  678. if (button.shortcutAttr)
  679. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  680. if (button.content)
  681. buttonElement.setAttribute("content", button.content);
  682. if (button.i18n)
  683. buttonElement.setAttribute("data-i18n", button.i18n);
  684. buttonElement.setAttribute("data-container", "body");
  685. buttonElement.setAttribute("data-placement", "bottom");
  686. this._addPopups(buttonElement, button.popups);
  687. document.getElementById("mainToolbar")
  688. .appendChild(buttonElement);
  689. },
  690. _addPopups(buttonElement, popups = []) {
  691. popups.forEach((popup) => {
  692. let popupElement = document.createElement("ul");
  693. popupElement.id = popup.id;
  694. popupElement.className = popup.className;
  695. let liElement = document.createElement("li");
  696. liElement.setAttribute("data-i18n", popup.dataAttr);
  697. popupElement.appendChild(liElement);
  698. buttonElement.appendChild(popupElement);
  699. });
  700. },
  701. /**
  702. * Sets the toggled state of the given element depending on the isToggled
  703. * parameter.
  704. *
  705. * @param elementId the element identifier
  706. * @param isToggled indicates if the element should be toggled or untoggled
  707. */
  708. _setToggledState(elementId, isToggled) {
  709. $("#" + elementId).toggleClass("toggled", isToggled);
  710. }
  711. };
  712. export default Toolbar;