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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768
  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. // First hide all disabled buttons in the extended toolbar.
  332. // TODO: Make the extended toolbar dynamically created.
  333. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  334. // Initialise the main toolbar. The main toolbar will only take into
  335. // account it's own configuration from interface_config.
  336. this._initMainToolbarButtons();
  337. Object.keys(defaultToolbarButtons).forEach(
  338. id => {
  339. if (UIUtil.isButtonEnabled(id)) {
  340. var button = defaultToolbarButtons[id];
  341. if (button.shortcut)
  342. APP.keyboardshortcut.registerShortcut(
  343. button.shortcut,
  344. button.shortcutAttr,
  345. button.shortcutFunc,
  346. button.shortcutDescription
  347. );
  348. }
  349. }
  350. );
  351. Object.keys(buttonHandlers).forEach(
  352. buttonId => $(`#${buttonId}`).click(function(event) {
  353. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  354. })
  355. );
  356. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  357. function(containerId, isVisible) {
  358. Toolbar._handleSideToolbarContainerToggled( containerId,
  359. isVisible);
  360. });
  361. if(!APP.tokenData.isGuest) {
  362. $("#toolbar_button_profile").addClass("unclickable");
  363. }
  364. },
  365. /**
  366. * Enables / disables the toolbar.
  367. * @param {e} set to {true} to enable the toolbar or {false}
  368. * to disable it
  369. */
  370. enable (e) {
  371. this.enabled = e;
  372. if (!e && this.isVisible())
  373. this.hide(false);
  374. },
  375. /**
  376. * Indicates if the bottom toolbar is currently enabled.
  377. * @return {this.enabled}
  378. */
  379. isEnabled() {
  380. return this.enabled;
  381. },
  382. /**
  383. * Updates the room invite url.
  384. */
  385. updateRoomUrl (newRoomUrl) {
  386. roomUrl = newRoomUrl;
  387. // If the invite dialog has been already opened we update the
  388. // information.
  389. let inviteLink = document.getElementById('inviteLinkRef');
  390. if (inviteLink) {
  391. inviteLink.value = roomUrl;
  392. inviteLink.select();
  393. $('#inviteLinkRef').parent()
  394. .find('button[value=true]').prop('disabled', false);
  395. }
  396. },
  397. /**
  398. * Unlocks the lock button state.
  399. */
  400. unlockLockButton () {
  401. if ($("#toolbar_button_security").hasClass("icon-security-locked"))
  402. UIUtil.buttonClick("toolbar_button_security",
  403. "icon-security icon-security-locked");
  404. },
  405. /**
  406. * Updates the lock button state to locked.
  407. */
  408. lockLockButton () {
  409. if ($("#toolbar_button_security").hasClass("icon-security"))
  410. UIUtil.buttonClick("toolbar_button_security",
  411. "icon-security icon-security-locked");
  412. },
  413. /**
  414. * Shows or hides authentication button
  415. * @param show <tt>true</tt> to show or <tt>false</tt> to hide
  416. */
  417. showAuthenticateButton (show) {
  418. if (UIUtil.isButtonEnabled('authentication') && show) {
  419. $('#authentication').css({display: "inline"});
  420. } else {
  421. $('#authentication').css({display: "none"});
  422. }
  423. },
  424. showEtherpadButton () {
  425. if (!$('#toolbar_button_etherpad').is(":visible")) {
  426. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  427. }
  428. },
  429. // Shows or hides the 'shared video' button.
  430. showSharedVideoButton () {
  431. if (UIUtil.isButtonEnabled('sharedvideo')
  432. && config.disableThirdPartyRequests !== true) {
  433. $('#toolbar_button_sharedvideo').css({display: "inline-block"});
  434. } else {
  435. $('#toolbar_button_sharedvideo').css({display: "none"});
  436. }
  437. },
  438. // checks whether desktop sharing is enabled and whether
  439. // we have params to start automatically sharing
  440. checkAutoEnableDesktopSharing () {
  441. if (UIUtil.isButtonEnabled('desktop')
  442. && config.autoEnableDesktopSharing) {
  443. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  444. }
  445. },
  446. // Shows or hides SIP calls button
  447. showSipCallButton (show) {
  448. if (APP.conference.sipGatewayEnabled()
  449. && UIUtil.isButtonEnabled('sip') && show) {
  450. $('#toolbar_button_sip').css({display: "inline-block"});
  451. } else {
  452. $('#toolbar_button_sip').css({display: "none"});
  453. }
  454. },
  455. // Shows or hides the dialpad button
  456. showDialPadButton (show) {
  457. if (UIUtil.isButtonEnabled('dialpad') && show) {
  458. $('#toolbar_button_dialpad').css({display: "inline-block"});
  459. } else {
  460. $('#toolbar_button_dialpad').css({display: "none"});
  461. }
  462. },
  463. /**
  464. * Displays user authenticated identity name(login).
  465. * @param authIdentity identity name to be displayed.
  466. */
  467. setAuthenticatedIdentity (authIdentity) {
  468. if (authIdentity) {
  469. let selector = $('#toolbar_auth_identity');
  470. selector.css({display: "list-item"});
  471. selector.text(authIdentity);
  472. } else {
  473. $('#toolbar_auth_identity').css({display: "none"});
  474. }
  475. },
  476. /**
  477. * Shows/hides login button.
  478. * @param show <tt>true</tt> to show
  479. */
  480. showLoginButton (show) {
  481. if (UIUtil.isButtonEnabled('authentication') && show) {
  482. $('#toolbar_button_login').css({display: "list-item"});
  483. } else {
  484. $('#toolbar_button_login').css({display: "none"});
  485. }
  486. },
  487. /**
  488. * Shows/hides logout button.
  489. * @param show <tt>true</tt> to show
  490. */
  491. showLogoutButton (show) {
  492. if (UIUtil.isButtonEnabled('authentication') && show) {
  493. $('#toolbar_button_logout').css({display: "list-item"});
  494. } else {
  495. $('#toolbar_button_logout').css({display: "none"});
  496. }
  497. },
  498. /**
  499. * Update the state of the button. The button has blue glow if desktop
  500. * streaming is active.
  501. */
  502. updateDesktopSharingButtonState () {
  503. let button = $("#toolbar_button_desktopsharing");
  504. if (APP.conference.isSharingScreen) {
  505. button.addClass("glow");
  506. } else {
  507. button.removeClass("glow");
  508. }
  509. },
  510. /**
  511. * Marks video icon as muted or not.
  512. * @param {boolean} muted if icon should look like muted or not
  513. */
  514. markVideoIconAsMuted (muted) {
  515. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  516. },
  517. /**
  518. * Marks video icon as disabled or not.
  519. * @param {boolean} disabled if icon should look like disabled or not
  520. */
  521. markVideoIconAsDisabled (disabled) {
  522. var $btn = $('#toolbar_button_camera');
  523. $btn
  524. .prop("disabled", disabled)
  525. .attr("data-i18n", disabled
  526. ? "[content]toolbar.cameraDisabled"
  527. : "[content]toolbar.videomute")
  528. .attr("shortcut", disabled ? "" : "toggleVideoPopover");
  529. disabled
  530. ? $btn.attr("disabled", "disabled")
  531. : $btn.removeAttr("disabled");
  532. APP.translation.translateElement($btn);
  533. disabled && this.markVideoIconAsMuted(disabled);
  534. },
  535. /**
  536. * Marks audio icon as muted or not.
  537. * @param {boolean} muted if icon should look like muted or not
  538. */
  539. markAudioIconAsMuted (muted) {
  540. $('#toolbar_button_mute').toggleClass("icon-microphone",
  541. !muted).toggleClass("icon-mic-disabled", muted);
  542. },
  543. /**
  544. * Marks audio icon as disabled or not.
  545. * @param {boolean} disabled if icon should look like disabled or not
  546. */
  547. markAudioIconAsDisabled (disabled) {
  548. var $btn = $('#toolbar_button_mute');
  549. $btn
  550. .prop("disabled", disabled)
  551. .attr("data-i18n", disabled
  552. ? "[content]toolbar.micDisabled"
  553. : "[content]toolbar.mute")
  554. .attr("shortcut", disabled ? "" : "mutePopover");
  555. disabled
  556. ? $btn.attr("disabled", "disabled")
  557. : $btn.removeAttr("disabled");
  558. APP.translation.translateElement($btn);
  559. disabled && this.markAudioIconAsMuted(disabled);
  560. },
  561. /**
  562. * Indicates if the toolbar is currently hovered.
  563. * @return {boolean} true if the toolbar is currently hovered,
  564. * false otherwise
  565. */
  566. isHovered() {
  567. var hovered = false;
  568. this.toolbarSelector.find('*').each(function () {
  569. let id = $(this).attr('id');
  570. if ($(`#${id}:hover`).length > 0) {
  571. hovered = true;
  572. // break each
  573. return false;
  574. }
  575. });
  576. if (hovered)
  577. return true;
  578. if ($("#bottomToolbar:hover").length > 0
  579. || $("#extendedToolbar:hover").length > 0
  580. || SideContainerToggler.isHovered()) {
  581. return true;
  582. }
  583. return false;
  584. },
  585. /**
  586. * Returns true if this toolbar is currently visible, or false otherwise.
  587. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  588. */
  589. isVisible() {
  590. return this.toolbarSelector.hasClass("slideInY");
  591. },
  592. /**
  593. * Hides the toolbar with animation or not depending on the animate
  594. * parameter.
  595. */
  596. hide() {
  597. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  598. let slideInAnimation = (SideContainerToggler.isVisible)
  599. ? "slideInExtX"
  600. : "slideInX";
  601. let slideOutAnimation = (SideContainerToggler.isVisible)
  602. ? "slideOutExtX"
  603. : "slideOutX";
  604. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  605. .toggleClass(slideOutAnimation);
  606. },
  607. /**
  608. * Shows the toolbar with animation or not depending on the animate
  609. * parameter.
  610. */
  611. show() {
  612. if (this.toolbarSelector.hasClass("slideOutY"))
  613. this.toolbarSelector.toggleClass("slideOutY");
  614. let slideInAnimation = (SideContainerToggler.isVisible)
  615. ? "slideInExtX"
  616. : "slideInX";
  617. let slideOutAnimation = (SideContainerToggler.isVisible)
  618. ? "slideOutExtX"
  619. : "slideOutX";
  620. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  621. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  622. this.toolbarSelector.toggleClass("slideInY");
  623. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  624. },
  625. registerClickListeners(listener) {
  626. $('#mainToolbarContainer').click(listener);
  627. $("#extendedToolbar").click(listener);
  628. },
  629. /**
  630. * Handles the side toolbar toggle.
  631. */
  632. _handleSideToolbarContainerToggled(containerId, isVisible) {
  633. Object.keys(defaultToolbarButtons).forEach(
  634. id => {
  635. if (!UIUtil.isButtonEnabled(id))
  636. return;
  637. var button = defaultToolbarButtons[id];
  638. if (button.sideContainerId
  639. && button.sideContainerId === containerId) {
  640. UIUtil.buttonClick(button.id, "selected");
  641. return;
  642. }
  643. }
  644. );
  645. },
  646. /**
  647. * Initialise main toolbar buttons.
  648. */
  649. _initMainToolbarButtons() {
  650. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  651. if (value && value in defaultToolbarButtons) {
  652. let button = defaultToolbarButtons[value];
  653. this._addMainToolbarButton(
  654. button,
  655. (index === 0),
  656. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  657. }
  658. });
  659. },
  660. /**
  661. * Adds the given button to the main (top) toolbar.
  662. *
  663. * @param {Object} the button to add.
  664. * @param {boolean} isFirst indicates if this is the first button in the
  665. * toolbar
  666. * @param {boolean} isLast indicates if this is the last button in the
  667. * toolbar
  668. */
  669. _addMainToolbarButton(button, isFirst, isLast) {
  670. let buttonElement = document.createElement("a");
  671. if (button.className)
  672. buttonElement.className = button.className
  673. + ((isFirst) ? " first" : "")
  674. + ((isLast) ? " last" : "");
  675. buttonElement.id = button.id;
  676. if (button.shortcutAttr)
  677. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  678. if (button.content)
  679. buttonElement.setAttribute("content", button.content);
  680. if (button.i18n)
  681. buttonElement.setAttribute("data-i18n", button.i18n);
  682. buttonElement.setAttribute("data-container", "body");
  683. buttonElement.setAttribute("data-toggle", "popover");
  684. buttonElement.setAttribute("data-placement", "bottom");
  685. this._addPopups(buttonElement, button.popups);
  686. document.getElementById("mainToolbar")
  687. .appendChild(buttonElement);
  688. },
  689. _addPopups(buttonElement, popups = []) {
  690. popups.forEach((popup) => {
  691. let popupElement = document.createElement("ul");
  692. popupElement.id = popup.id;
  693. popupElement.className = popup.className;
  694. let liElement = document.createElement("li");
  695. liElement.setAttribute("data-i18n", popup.dataAttr);
  696. popupElement.appendChild(liElement);
  697. buttonElement.appendChild(popupElement);
  698. });
  699. }
  700. };
  701. export default Toolbar;