Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Toolbar.js 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  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 msgString = (`
  276. <input name="sipNumber" type="text"
  277. value="${defaultNumber}" autofocus>
  278. `);
  279. APP.UI.messageHandler.openTwoButtonDialog({
  280. titleKey,
  281. msgString,
  282. leftButtonKey: "dialog.Dial",
  283. submitFunction: function (e, v, m, f) {
  284. if (v && f.sipNumber) {
  285. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  286. }
  287. },
  288. focus: ':input:first'
  289. });
  290. }
  291. Toolbar = {
  292. init (eventEmitter) {
  293. emitter = eventEmitter;
  294. // The toolbar is enabled by default.
  295. this.enabled = true;
  296. this.toolbarSelector = $("#mainToolbarContainer");
  297. this.extendedToolbarSelector = $("#extendedToolbar");
  298. // First hide all disabled buttons in the extended toolbar.
  299. // TODO: Make the extended toolbar dynamically created.
  300. UIUtil.hideDisabledButtons(defaultToolbarButtons);
  301. // Initialise the main toolbar. The main toolbar will only take into
  302. // account it's own configuration from interface_config.
  303. this._initMainToolbarButtons();
  304. Object.keys(defaultToolbarButtons).forEach(
  305. id => {
  306. if (UIUtil.isButtonEnabled(id)) {
  307. let button = defaultToolbarButtons[id];
  308. let buttonElement = document.getElementById(button.id);
  309. let tooltipPosition
  310. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  311. .indexOf(id) > -1)
  312. ? "bottom" : "right";
  313. UIUtil.setTooltip( buttonElement,
  314. button.tooltipKey,
  315. tooltipPosition);
  316. if (button.shortcut)
  317. APP.keyboardshortcut.registerShortcut(
  318. button.shortcut,
  319. button.shortcutAttr,
  320. button.shortcutFunc,
  321. button.shortcutDescription
  322. );
  323. }
  324. }
  325. );
  326. Object.keys(buttonHandlers).forEach(
  327. buttonId => $(`#${buttonId}`).click(function(event) {
  328. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  329. })
  330. );
  331. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  332. (containerId, isVisible) => {
  333. Toolbar._handleSideToolbarContainerToggled( containerId,
  334. isVisible);
  335. });
  336. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  337. (isRaisedHand) => {
  338. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  339. });
  340. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  341. (isFullScreen) => {
  342. Toolbar._handleFullScreenToggled(isFullScreen);
  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. let display = show ? 'block' : 'none';
  373. $('#authenticationContainer').css({display});
  374. },
  375. showEtherpadButton () {
  376. if (!$('#toolbar_button_etherpad').is(":visible")) {
  377. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  378. }
  379. },
  380. // Shows or hides the 'shared video' button.
  381. showSharedVideoButton () {
  382. let $element = $('#toolbar_button_sharedvideo');
  383. if (UIUtil.isButtonEnabled('sharedvideo')
  384. && config.disableThirdPartyRequests !== true) {
  385. $element.css({display: "inline-block"});
  386. UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
  387. } else {
  388. $('#toolbar_button_sharedvideo').css({display: "none"});
  389. }
  390. },
  391. // checks whether desktop sharing is enabled and whether
  392. // we have params to start automatically sharing
  393. checkAutoEnableDesktopSharing () {
  394. if (UIUtil.isButtonEnabled('desktop')
  395. && config.autoEnableDesktopSharing) {
  396. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  397. }
  398. },
  399. // Shows or hides SIP calls button
  400. showSipCallButton (show) {
  401. if (APP.conference.sipGatewayEnabled()
  402. && UIUtil.isButtonEnabled('sip') && show) {
  403. $('#toolbar_button_sip').css({display: "inline-block"});
  404. } else {
  405. $('#toolbar_button_sip').css({display: "none"});
  406. }
  407. },
  408. // Shows or hides the dialpad button
  409. showDialPadButton (show) {
  410. if (UIUtil.isButtonEnabled('dialpad') && show) {
  411. $('#toolbar_button_dialpad').css({display: "inline-block"});
  412. } else {
  413. $('#toolbar_button_dialpad').css({display: "none"});
  414. }
  415. },
  416. /**
  417. * Displays user authenticated identity name(login).
  418. * @param authIdentity identity name to be displayed.
  419. */
  420. setAuthenticatedIdentity (authIdentity) {
  421. let selector = $('#toolbar_auth_identity');
  422. if (authIdentity) {
  423. selector.css({display: "list-item"});
  424. selector.text(authIdentity);
  425. } else {
  426. selector.css({display: "none"});
  427. selector.text('');
  428. }
  429. },
  430. /**
  431. * Shows/hides login button.
  432. * @param show <tt>true</tt> to show
  433. */
  434. showLoginButton (show) {
  435. if (show) {
  436. $('#toolbar_button_login').css({display: "list-item"});
  437. } else {
  438. $('#toolbar_button_login').css({display: "none"});
  439. }
  440. },
  441. /**
  442. * Shows/hides logout button.
  443. * @param show <tt>true</tt> to show
  444. */
  445. showLogoutButton (show) {
  446. if (show) {
  447. $('#toolbar_button_logout').css({display: "list-item"});
  448. } else {
  449. $('#toolbar_button_logout').css({display: "none"});
  450. }
  451. },
  452. /**
  453. * Update the state of the button. The button has blue glow if desktop
  454. * streaming is active.
  455. */
  456. updateDesktopSharingButtonState () {
  457. this._setToggledState( "toolbar_button_desktopsharing",
  458. APP.conference.isSharingScreen);
  459. },
  460. /**
  461. * Marks video icon as muted or not.
  462. *
  463. * @param {boolean} muted if icon should look like muted or not
  464. */
  465. toggleVideoIcon (muted) {
  466. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  467. this._setToggledState("toolbar_button_camera", muted);
  468. },
  469. /**
  470. * Enables / disables audio toolbar button.
  471. *
  472. * @param {boolean} enabled indicates if the button should be enabled
  473. * or disabled
  474. */
  475. setVideoIconEnabled (enabled) {
  476. this._setMediaIconEnabled(
  477. '#toolbar_button_camera',
  478. enabled,
  479. /* data-i18n attribute value */
  480. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  481. /* shortcut attribute value */
  482. 'toggleVideoPopover');
  483. enabled || this.toggleVideoIcon(!enabled);
  484. },
  485. /**
  486. * Enables/disables the toolbar button associated with a specific media such
  487. * as audio or video.
  488. *
  489. * @param {string} btn - The jQuery selector <tt>string</tt> which
  490. * identifies the toolbar button to be enabled/disabled.
  491. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  492. * <tt>btn</tt> or <tt>false</tt> to disable it.
  493. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  494. * attribute of the specified <tt>btn</tt>.
  495. * @param {string} shortcut - The value, if any, to assign to the
  496. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  497. * button is enabled.
  498. */
  499. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  500. const $btn = $(btn);
  501. $btn
  502. .prop('disabled', !enabled)
  503. .attr('data-i18n', dataI18n)
  504. .attr('shortcut', enabled && shortcut ? shortcut : '');
  505. enabled
  506. ? $btn.removeAttr('disabled')
  507. : $btn.attr('disabled', 'disabled');
  508. APP.translation.translateElement($btn);
  509. },
  510. /**
  511. * Marks audio icon as muted or not.
  512. *
  513. * @param {boolean} muted if icon should look like muted or not
  514. */
  515. toggleAudioIcon(muted) {
  516. $('#toolbar_button_mute')
  517. .toggleClass("icon-microphone", !muted)
  518. .toggleClass("icon-mic-disabled", muted);
  519. this._setToggledState("toolbar_button_mute", muted);
  520. },
  521. /**
  522. * Enables / disables audio toolbar button.
  523. *
  524. * @param {boolean} enabled indicates if the button should be enabled
  525. * or disabled
  526. */
  527. setAudioIconEnabled (enabled) {
  528. this._setMediaIconEnabled(
  529. '#toolbar_button_mute',
  530. enabled,
  531. /* data-i18n attribute value */
  532. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  533. /* shortcut attribute value */
  534. 'mutePopover');
  535. enabled || this.toggleAudioIcon(!enabled);
  536. },
  537. /**
  538. * Indicates if the toolbar is currently hovered.
  539. * @return {boolean} true if the toolbar is currently hovered,
  540. * false otherwise
  541. */
  542. isHovered() {
  543. var hovered = false;
  544. this.toolbarSelector.find('*').each(function () {
  545. let id = $(this).attr('id');
  546. if ($(`#${id}:hover`).length > 0) {
  547. hovered = true;
  548. // break each
  549. return false;
  550. }
  551. });
  552. if (hovered)
  553. return true;
  554. if ($("#bottomToolbar:hover").length > 0
  555. || $("#extendedToolbar:hover").length > 0
  556. || SideContainerToggler.isHovered()) {
  557. return true;
  558. }
  559. return false;
  560. },
  561. /**
  562. * Returns true if this toolbar is currently visible, or false otherwise.
  563. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  564. */
  565. isVisible() {
  566. return this.toolbarSelector.hasClass("fadeIn");
  567. },
  568. /**
  569. * Hides the toolbar with animation or not depending on the animate
  570. * parameter.
  571. */
  572. hide() {
  573. this.toolbarSelector
  574. .removeClass("fadeIn")
  575. .addClass("fadeOut");
  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("fadeOut")) {
  591. this.toolbarSelector.removeClass("fadeOut");
  592. }
  593. let slideInAnimation = (SideContainerToggler.isVisible)
  594. ? "slideInExtX"
  595. : "slideInX";
  596. let slideOutAnimation = (SideContainerToggler.isVisible)
  597. ? "slideOutExtX"
  598. : "slideOutX";
  599. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  600. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  601. }
  602. this.toolbarSelector.addClass("fadeIn");
  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. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  656. && index
  657. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  658. }
  659. });
  660. },
  661. /**
  662. * Adds the given button to the main (top) toolbar.
  663. *
  664. * @param {Object} the button to add.
  665. * @param {boolean} isFirst indicates if this is the first button in the
  666. * toolbar
  667. * @param {boolean} isLast indicates if this is the last button in the
  668. * toolbar
  669. * @param {boolean} isSplitter if this button is a splitter button for
  670. * the dialog, which means that a special splitter style will be applied
  671. */
  672. _addMainToolbarButton(button, isFirst, isLast, isSplitter) {
  673. let buttonElement = document.createElement("a");
  674. if (button.className)
  675. buttonElement.className = button.className
  676. + ((isFirst) ? " first" : "")
  677. + ((isLast) ? " last" : "")
  678. + ((isSplitter) ? " splitter": "");
  679. buttonElement.id = button.id;
  680. if (button.shortcutAttr)
  681. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  682. if (button.content)
  683. buttonElement.setAttribute("content", button.content);
  684. if (button.i18n)
  685. buttonElement.setAttribute("data-i18n", button.i18n);
  686. buttonElement.setAttribute("data-container", "body");
  687. buttonElement.setAttribute("data-placement", "bottom");
  688. this._addPopups(buttonElement, button.popups);
  689. document.getElementById("mainToolbar")
  690. .appendChild(buttonElement);
  691. },
  692. _addPopups(buttonElement, popups = []) {
  693. popups.forEach((popup) => {
  694. let popupElement = document.createElement("ul");
  695. popupElement.id = popup.id;
  696. popupElement.className = popup.className;
  697. let liElement = document.createElement("li");
  698. liElement.setAttribute("data-i18n", popup.dataAttr);
  699. popupElement.appendChild(liElement);
  700. buttonElement.appendChild(popupElement);
  701. });
  702. },
  703. /**
  704. * Sets the toggled state of the given element depending on the isToggled
  705. * parameter.
  706. *
  707. * @param elementId the element identifier
  708. * @param isToggled indicates if the element should be toggled or untoggled
  709. */
  710. _setToggledState(elementId, isToggled) {
  711. $("#" + elementId).toggleClass("toggled", isToggled);
  712. }
  713. };
  714. export default Toolbar;