Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  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. if (UIUtil.isButtonEnabled('authentication') && show) {
  375. $('#authentication').css({display: "inline"});
  376. } else {
  377. $('#authentication').css({display: "none"});
  378. }
  379. },
  380. showEtherpadButton () {
  381. if (!$('#toolbar_button_etherpad').is(":visible")) {
  382. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  383. }
  384. },
  385. // Shows or hides the 'shared video' button.
  386. showSharedVideoButton () {
  387. let $element = $('#toolbar_button_sharedvideo');
  388. if (UIUtil.isButtonEnabled('sharedvideo')
  389. && config.disableThirdPartyRequests !== true) {
  390. $element.css({display: "inline-block"});
  391. UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
  392. } else {
  393. $('#toolbar_button_sharedvideo').css({display: "none"});
  394. }
  395. },
  396. // checks whether desktop sharing is enabled and whether
  397. // we have params to start automatically sharing
  398. checkAutoEnableDesktopSharing () {
  399. if (UIUtil.isButtonEnabled('desktop')
  400. && config.autoEnableDesktopSharing) {
  401. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  402. }
  403. },
  404. // Shows or hides SIP calls button
  405. showSipCallButton (show) {
  406. if (APP.conference.sipGatewayEnabled()
  407. && UIUtil.isButtonEnabled('sip') && show) {
  408. $('#toolbar_button_sip').css({display: "inline-block"});
  409. } else {
  410. $('#toolbar_button_sip').css({display: "none"});
  411. }
  412. },
  413. // Shows or hides the dialpad button
  414. showDialPadButton (show) {
  415. if (UIUtil.isButtonEnabled('dialpad') && show) {
  416. $('#toolbar_button_dialpad').css({display: "inline-block"});
  417. } else {
  418. $('#toolbar_button_dialpad').css({display: "none"});
  419. }
  420. },
  421. /**
  422. * Displays user authenticated identity name(login).
  423. * @param authIdentity identity name to be displayed.
  424. */
  425. setAuthenticatedIdentity (authIdentity) {
  426. if (authIdentity) {
  427. let selector = $('#toolbar_auth_identity');
  428. selector.css({display: "list-item"});
  429. selector.text(authIdentity);
  430. } else {
  431. $('#toolbar_auth_identity').css({display: "none"});
  432. }
  433. },
  434. /**
  435. * Shows/hides login button.
  436. * @param show <tt>true</tt> to show
  437. */
  438. showLoginButton (show) {
  439. if (UIUtil.isButtonEnabled('authentication') && show) {
  440. $('#toolbar_button_login').css({display: "list-item"});
  441. } else {
  442. $('#toolbar_button_login').css({display: "none"});
  443. }
  444. },
  445. /**
  446. * Shows/hides logout button.
  447. * @param show <tt>true</tt> to show
  448. */
  449. showLogoutButton (show) {
  450. if (UIUtil.isButtonEnabled('authentication') && show) {
  451. $('#toolbar_button_logout').css({display: "list-item"});
  452. } else {
  453. $('#toolbar_button_logout').css({display: "none"});
  454. }
  455. },
  456. /**
  457. * Update the state of the button. The button has blue glow if desktop
  458. * streaming is active.
  459. */
  460. updateDesktopSharingButtonState () {
  461. this._setToggledState( "toolbar_button_desktopsharing",
  462. APP.conference.isSharingScreen);
  463. },
  464. /**
  465. * Marks video icon as muted or not.
  466. *
  467. * @param {boolean} muted if icon should look like muted or not
  468. */
  469. toggleVideoIcon (muted) {
  470. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  471. this._setToggledState("toolbar_button_camera", muted);
  472. },
  473. /**
  474. * Enables / disables audio toolbar button.
  475. *
  476. * @param {boolean} enabled indicates if the button should be enabled
  477. * or disabled
  478. */
  479. setVideoIconEnabled (enabled) {
  480. this._setMediaIconEnabled(
  481. '#toolbar_button_camera',
  482. enabled,
  483. /* data-i18n attribute value */
  484. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  485. /* shortcut attribute value */
  486. 'toggleVideoPopover');
  487. enabled || this.toggleVideoIcon(!enabled);
  488. },
  489. /**
  490. * Enables/disables the toolbar button associated with a specific media such
  491. * as audio or video.
  492. *
  493. * @param {string} btn - The jQuery selector <tt>string</tt> which
  494. * identifies the toolbar button to be enabled/disabled.
  495. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  496. * <tt>btn</tt> or <tt>false</tt> to disable it.
  497. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  498. * attribute of the specified <tt>btn</tt>.
  499. * @param {string} shortcut - The value, if any, to assign to the
  500. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  501. * button is enabled.
  502. */
  503. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  504. const $btn = $(btn);
  505. $btn
  506. .prop('disabled', !enabled)
  507. .attr('data-i18n', dataI18n)
  508. .attr('shortcut', enabled && shortcut ? shortcut : '');
  509. enabled
  510. ? $btn.removeAttr('disabled')
  511. : $btn.attr('disabled', 'disabled');
  512. APP.translation.translateElement($btn);
  513. },
  514. /**
  515. * Marks audio icon as muted or not.
  516. *
  517. * @param {boolean} muted if icon should look like muted or not
  518. */
  519. toggleAudioIcon(muted) {
  520. $('#toolbar_button_mute')
  521. .toggleClass("icon-microphone", !muted)
  522. .toggleClass("icon-mic-disabled", muted);
  523. this._setToggledState("toolbar_button_mute", muted);
  524. },
  525. /**
  526. * Enables / disables audio toolbar button.
  527. *
  528. * @param {boolean} enabled indicates if the button should be enabled
  529. * or disabled
  530. */
  531. setAudioIconEnabled (enabled) {
  532. this._setMediaIconEnabled(
  533. '#toolbar_button_mute',
  534. enabled,
  535. /* data-i18n attribute value */
  536. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  537. /* shortcut attribute value */
  538. 'mutePopover');
  539. enabled || this.toggleAudioIcon(!enabled);
  540. },
  541. /**
  542. * Indicates if the toolbar is currently hovered.
  543. * @return {boolean} true if the toolbar is currently hovered,
  544. * false otherwise
  545. */
  546. isHovered() {
  547. var hovered = false;
  548. this.toolbarSelector.find('*').each(function () {
  549. let id = $(this).attr('id');
  550. if ($(`#${id}:hover`).length > 0) {
  551. hovered = true;
  552. // break each
  553. return false;
  554. }
  555. });
  556. if (hovered)
  557. return true;
  558. if ($("#bottomToolbar:hover").length > 0
  559. || $("#extendedToolbar:hover").length > 0
  560. || SideContainerToggler.isHovered()) {
  561. return true;
  562. }
  563. return false;
  564. },
  565. /**
  566. * Returns true if this toolbar is currently visible, or false otherwise.
  567. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  568. */
  569. isVisible() {
  570. return this.toolbarSelector.hasClass("slideInY");
  571. },
  572. /**
  573. * Hides the toolbar with animation or not depending on the animate
  574. * parameter.
  575. */
  576. hide() {
  577. this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
  578. let slideInAnimation = (SideContainerToggler.isVisible)
  579. ? "slideInExtX"
  580. : "slideInX";
  581. let slideOutAnimation = (SideContainerToggler.isVisible)
  582. ? "slideOutExtX"
  583. : "slideOutX";
  584. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  585. .toggleClass(slideOutAnimation);
  586. },
  587. /**
  588. * Shows the toolbar with animation or not depending on the animate
  589. * parameter.
  590. */
  591. show() {
  592. if (this.toolbarSelector.hasClass("slideOutY"))
  593. this.toolbarSelector.toggleClass("slideOutY");
  594. let slideInAnimation = (SideContainerToggler.isVisible)
  595. ? "slideInExtX"
  596. : "slideInX";
  597. let slideOutAnimation = (SideContainerToggler.isVisible)
  598. ? "slideOutExtX"
  599. : "slideOutX";
  600. if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
  601. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  602. this.toolbarSelector.toggleClass("slideInY");
  603. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  604. },
  605. registerClickListeners(listener) {
  606. $('#mainToolbarContainer').click(listener);
  607. $("#extendedToolbar").click(listener);
  608. },
  609. /**
  610. * Handles the side toolbar toggle.
  611. *
  612. * @param {string} containerId the identifier of the container element
  613. */
  614. _handleSideToolbarContainerToggled(containerId) {
  615. Object.keys(defaultToolbarButtons).forEach(
  616. id => {
  617. if (!UIUtil.isButtonEnabled(id))
  618. return;
  619. var button = defaultToolbarButtons[id];
  620. if (button.sideContainerId
  621. && button.sideContainerId === containerId) {
  622. UIUtil.buttonClick(button.id, "selected");
  623. return;
  624. }
  625. }
  626. );
  627. },
  628. /**
  629. * Handles full screen toggled.
  630. *
  631. * @param {boolean} isFullScreen indicates if we're currently in full
  632. * screen mode
  633. */
  634. _handleFullScreenToggled(isFullScreen) {
  635. let element
  636. = document.getElementById("toolbar_button_fullScreen");
  637. element.className = isFullScreen
  638. ? element.className
  639. .replace("icon-full-screen", "icon-exit-full-screen")
  640. : element.className
  641. .replace("icon-exit-full-screen", "icon-full-screen");
  642. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  643. },
  644. /**
  645. * Initialise main toolbar buttons.
  646. */
  647. _initMainToolbarButtons() {
  648. interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
  649. if (value && value in defaultToolbarButtons) {
  650. let button = defaultToolbarButtons[value];
  651. this._addMainToolbarButton(
  652. button,
  653. (index === 0),
  654. (index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1));
  655. }
  656. });
  657. },
  658. /**
  659. * Adds the given button to the main (top) toolbar.
  660. *
  661. * @param {Object} the button to add.
  662. * @param {boolean} isFirst indicates if this is the first button in the
  663. * toolbar
  664. * @param {boolean} isLast indicates if this is the last button in the
  665. * toolbar
  666. */
  667. _addMainToolbarButton(button, isFirst, isLast) {
  668. let buttonElement = document.createElement("a");
  669. if (button.className)
  670. buttonElement.className = button.className
  671. + ((isFirst) ? " first" : "")
  672. + ((isLast) ? " last" : "");
  673. buttonElement.id = button.id;
  674. if (button.shortcutAttr)
  675. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  676. if (button.content)
  677. buttonElement.setAttribute("content", button.content);
  678. if (button.i18n)
  679. buttonElement.setAttribute("data-i18n", button.i18n);
  680. buttonElement.setAttribute("data-container", "body");
  681. buttonElement.setAttribute("data-placement", "bottom");
  682. this._addPopups(buttonElement, button.popups);
  683. document.getElementById("mainToolbar")
  684. .appendChild(buttonElement);
  685. },
  686. _addPopups(buttonElement, popups = []) {
  687. popups.forEach((popup) => {
  688. let popupElement = document.createElement("ul");
  689. popupElement.id = popup.id;
  690. popupElement.className = popup.className;
  691. let liElement = document.createElement("li");
  692. liElement.setAttribute("data-i18n", popup.dataAttr);
  693. popupElement.appendChild(liElement);
  694. buttonElement.appendChild(popupElement);
  695. });
  696. },
  697. /**
  698. * Sets the toggled state of the given element depending on the isToggled
  699. * parameter.
  700. *
  701. * @param elementId the element identifier
  702. * @param isToggled indicates if the element should be toggled or untoggled
  703. */
  704. _setToggledState(elementId, isToggled) {
  705. $("#" + elementId).toggleClass("toggled", isToggled);
  706. }
  707. };
  708. export default Toolbar;