您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Toolbar.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. /* global AJS, 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. /**
  8. * Handlers for toolbar buttons.
  9. *
  10. * buttonId {string}: handler {function}
  11. */
  12. const buttonHandlers = {
  13. "toolbar_button_profile": function () {
  14. JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
  15. emitter.emit(UIEvents.TOGGLE_PROFILE);
  16. },
  17. "toolbar_button_mute": function () {
  18. let sharedVideoManager = APP.UI.getSharedVideoManager();
  19. if (APP.conference.audioMuted) {
  20. // If there's a shared video with the volume "on" and we aren't
  21. // the video owner, we warn the user
  22. // that currently it's not possible to unmute.
  23. if (sharedVideoManager
  24. && sharedVideoManager.isSharedVideoVolumeOn()
  25. && !sharedVideoManager.isSharedVideoOwner()) {
  26. APP.UI.showCustomToolbarPopup(
  27. '#unableToUnmutePopup', true, 5000);
  28. }
  29. else {
  30. JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
  31. emitter.emit(UIEvents.AUDIO_MUTED, false, true);
  32. }
  33. } else {
  34. JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
  35. emitter.emit(UIEvents.AUDIO_MUTED, true, true);
  36. }
  37. },
  38. "toolbar_button_camera": function () {
  39. if (APP.conference.videoMuted) {
  40. JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
  41. emitter.emit(UIEvents.VIDEO_MUTED, false);
  42. } else {
  43. JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
  44. emitter.emit(UIEvents.VIDEO_MUTED, true);
  45. }
  46. },
  47. "toolbar_button_link": function () {
  48. JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
  49. emitter.emit(UIEvents.INVITE_CLICKED);
  50. },
  51. "toolbar_button_chat": function () {
  52. JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
  53. emitter.emit(UIEvents.TOGGLE_CHAT);
  54. },
  55. "toolbar_contact_list": function () {
  56. JitsiMeetJS.analytics.sendEvent(
  57. 'toolbar.contacts.toggled');
  58. emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
  59. },
  60. "toolbar_button_etherpad": function () {
  61. JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
  62. emitter.emit(UIEvents.ETHERPAD_CLICKED);
  63. },
  64. "toolbar_button_sharedvideo": function () {
  65. JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
  66. emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
  67. },
  68. "toolbar_button_desktopsharing": function () {
  69. if (APP.conference.isSharingScreen) {
  70. JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
  71. } else {
  72. JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
  73. }
  74. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  75. },
  76. "toolbar_button_fullScreen": function() {
  77. JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
  78. emitter.emit(UIEvents.TOGGLE_FULLSCREEN);
  79. },
  80. "toolbar_button_sip": function () {
  81. JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
  82. showSipNumberInput();
  83. },
  84. "toolbar_button_dialpad": function () {
  85. JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
  86. dialpadButtonClicked();
  87. },
  88. "toolbar_button_settings": function () {
  89. JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
  90. emitter.emit(UIEvents.TOGGLE_SETTINGS);
  91. },
  92. "toolbar_button_hangup": function () {
  93. JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
  94. emitter.emit(UIEvents.HANGUP);
  95. },
  96. "toolbar_button_raisehand": function () {
  97. JitsiMeetJS.analytics.sendEvent('toolbar.raiseHand.clicked');
  98. APP.conference.maybeToggleRaisedHand();
  99. }
  100. };
  101. /**
  102. * All toolbars buttons description
  103. */
  104. const defaultToolbarButtons = {
  105. 'microphone': {
  106. id: 'toolbar_button_mute',
  107. tooltipKey: 'toolbar.mute',
  108. className: "button icon-microphone",
  109. shortcut: 'M',
  110. shortcutAttr: 'mutePopover',
  111. shortcutFunc: function() {
  112. JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
  113. APP.conference.toggleAudioMuted();
  114. },
  115. shortcutDescription: "keyboardShortcuts.mute",
  116. popups: [
  117. {
  118. id: 'micMutedPopup',
  119. className: 'loginmenu',
  120. dataAttr: '[title]toolbar.micMutedPopup'
  121. },
  122. {
  123. id: 'unableToUnmutePopup',
  124. className: 'loginmenu',
  125. dataAttr: '[title]toolbar.unableToUnmutePopup'
  126. },
  127. {
  128. id: 'talkWhileMutedPopup',
  129. className: 'loginmenu',
  130. dataAttr: '[title]toolbar.talkWhileMutedPopup'
  131. }
  132. ],
  133. content: "Mute / Unmute",
  134. i18n: "[content]toolbar.mute"
  135. },
  136. 'camera': {
  137. id: 'toolbar_button_camera',
  138. tooltipKey: 'toolbar.videomute',
  139. className: "button icon-camera",
  140. shortcut: 'V',
  141. shortcutAttr: 'toggleVideoPopover',
  142. shortcutFunc: function() {
  143. JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
  144. APP.conference.toggleVideoMuted();
  145. },
  146. shortcutDescription: "keyboardShortcuts.videoMute",
  147. content: "Start / stop camera",
  148. i18n: "[content]toolbar.videomute"
  149. },
  150. 'desktop': {
  151. id: 'toolbar_button_desktopsharing',
  152. tooltipKey: 'toolbar.sharescreen',
  153. className: 'button icon-share-desktop',
  154. shortcut: 'D',
  155. shortcutAttr: 'toggleDesktopSharingPopover',
  156. shortcutFunc: function() {
  157. JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
  158. APP.conference.toggleScreenSharing();
  159. },
  160. shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
  161. content: 'Share screen',
  162. i18n: '[content]toolbar.sharescreen'
  163. },
  164. 'invite': {
  165. id: 'toolbar_button_link',
  166. tooltipKey: 'toolbar.invite',
  167. className: 'button icon-link',
  168. content: 'Invite others',
  169. i18n: '[content]toolbar.invite'
  170. },
  171. 'chat': {
  172. id: 'toolbar_button_chat',
  173. tooltipKey: 'toolbar.chat',
  174. className: 'button icon-chat',
  175. shortcut: 'C',
  176. shortcutAttr: 'toggleChatPopover',
  177. shortcutFunc: function() {
  178. JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
  179. APP.UI.toggleChat();
  180. },
  181. shortcutDescription: 'keyboardShortcuts.toggleChat',
  182. sideContainerId: 'chat_container',
  183. html: `<span class="badge-round">
  184. <span id="unreadMessages"></span>
  185. </span>`
  186. },
  187. 'contacts': {
  188. id: 'toolbar_contact_list',
  189. tooltipKey: 'bottomtoolbar.contactlist',
  190. className: 'button icon-contactList',
  191. sideContainerId: 'contacts_container',
  192. html: `<span class="badge-round">
  193. <span id="numberOfParticipants"></span>
  194. </span>`
  195. },
  196. 'profile': {
  197. id: 'toolbar_button_profile',
  198. tooltipKey: 'profile.setDisplayNameLabel',
  199. className: 'button',
  200. sideContainerId: 'profile_container',
  201. html: `<img id="avatar" src="images/avatar2.png"/>`
  202. },
  203. 'etherpad': {
  204. id: 'toolbar_button_etherpad',
  205. tooltipKey: 'toolbar.etherpad',
  206. className: 'button icon-share-doc'
  207. },
  208. 'fullscreen': {
  209. id: 'toolbar_button_fullScreen',
  210. tooltipKey: 'toolbar.fullscreen',
  211. className: "button icon-full-screen",
  212. shortcut: 'S',
  213. shortcutAttr: 'toggleFullscreenPopover',
  214. shortcutFunc: function() {
  215. JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
  216. APP.UI.toggleFullScreen();
  217. },
  218. shortcutDescription: "keyboardShortcuts.fullScreen",
  219. content: "Enter / Exit Full Screen",
  220. i18n: "[content]toolbar.fullscreen"
  221. },
  222. 'settings': {
  223. id: 'toolbar_button_settings',
  224. tooltipKey: 'toolbar.Settings',
  225. className: 'button icon-settings',
  226. sideContainerId: "settings_container"
  227. },
  228. 'hangup': {
  229. id: 'toolbar_button_hangup',
  230. tooltipKey: 'toolbar.hangup',
  231. className: "button icon-hangup",
  232. content: "Hang Up",
  233. i18n: "[content]toolbar.hangup"
  234. },
  235. 'raisehand': {
  236. id: "toolbar_button_raisehand",
  237. tooltipKey: 'toolbar.raiseHand',
  238. className: "button icon-raised-hand",
  239. shortcut: "R",
  240. shortcutAttr: "raiseHandPopover",
  241. shortcutFunc: function() {
  242. JitsiMeetJS.analytics.sendEvent("shortcut.raisehand.clicked");
  243. APP.conference.maybeToggleRaisedHand();
  244. },
  245. shortcutDescription: "keyboardShortcuts.raiseHand",
  246. content: "Raise Hand",
  247. i18n: "[content]toolbar.raiseHand"
  248. },
  249. //init and btn handler: Recording.initRecordingButton (Recording.js)
  250. 'recording': {
  251. id: 'toolbar_button_record',
  252. tooltipKey: 'liveStreaming.buttonTooltip',
  253. className: 'button',
  254. hidden: true // will be displayed once
  255. // the recording functionality is detected
  256. },
  257. 'sharedvideo': {
  258. id: 'toolbar_button_sharedvideo',
  259. tooltipKey: 'toolbar.sharedvideo',
  260. className: 'button icon-shared-video',
  261. popups: [
  262. {
  263. id: 'sharedVideoMutedPopup',
  264. className: 'loginmenu extendedToolbarPopup',
  265. dataAttr: '[title]toolbar.sharedVideoMutedPopup',
  266. dataAttrPosition: 'w'
  267. }
  268. ]
  269. },
  270. 'sip': {
  271. id: 'toolbar_button_sip',
  272. tooltipKey: 'toolbar.sip',
  273. className: 'button icon-telephone',
  274. hidden: true // will be displayed once
  275. // the SIP calls functionality is detected
  276. },
  277. 'dialpad': {
  278. id: 'toolbar_button_dialpad',
  279. tooltipKey: 'toolbar.dialpad',
  280. className: 'button icon-dialpad',
  281. //TODO: remove it after UI.updateDTMFSupport fix
  282. hidden: true
  283. }
  284. };
  285. function dialpadButtonClicked() {
  286. //TODO show the dialpad box
  287. }
  288. function showSipNumberInput () {
  289. let defaultNumber = config.defaultSipNumber
  290. ? config.defaultSipNumber
  291. : '';
  292. let titleKey = "dialog.sipMsg";
  293. let msgString = (`
  294. <input class="input-control"
  295. name="sipNumber" type="text"
  296. value="${defaultNumber}" autofocus>`);
  297. APP.UI.messageHandler.openTwoButtonDialog({
  298. titleKey,
  299. msgString,
  300. leftButtonKey: "dialog.Dial",
  301. submitFunction: function (e, v, m, f) {
  302. if (v && f.sipNumber) {
  303. emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
  304. }
  305. },
  306. focus: ':input:first'
  307. });
  308. }
  309. /**
  310. * Get place for toolbar button.
  311. * Now it can be in main toolbar or in extended (left) toolbar
  312. *
  313. * @param btn {string}
  314. * @returns {string}
  315. */
  316. function getToolbarButtonPlace (btn) {
  317. return interfaceConfig.MAIN_TOOLBAR_BUTTONS.includes(btn) ?
  318. 'main' :
  319. 'extended';
  320. }
  321. /**
  322. * Event handler for side toolbar container toggled event.
  323. *
  324. * @param {string} containerId - ID of the container.
  325. * @param {boolean} isVisible - Flag showing whether container
  326. * is visible.
  327. * @returns {void}
  328. */
  329. function onSideToolbarContainerToggled(containerId, isVisible) {
  330. Toolbar._handleSideToolbarContainerToggled(containerId, isVisible);
  331. }
  332. /**
  333. * Event handler for local raise hand changed event.
  334. *
  335. * @param {boolean} isRaisedHand - Flag showing whether hand is raised.
  336. * @returns {void}
  337. */
  338. function onLocalRaiseHandChanged(isRaisedHand) {
  339. Toolbar._setToggledState("toolbar_button_raisehand", isRaisedHand);
  340. }
  341. /**
  342. * Event handler for full screen toggled event.
  343. *
  344. * @param {boolean} isFullScreen - Flag showing whether app in full
  345. * screen mode.
  346. * @returns {void}
  347. */
  348. function onFullScreenToggled(isFullScreen) {
  349. Toolbar._handleFullScreenToggled(isFullScreen);
  350. }
  351. Toolbar = {
  352. init (eventEmitter) {
  353. emitter = eventEmitter;
  354. // The toolbar is enabled by default.
  355. this.enabled = true;
  356. this.toolbarSelector = $("#mainToolbarContainer");
  357. this.extendedToolbarSelector = $("#extendedToolbar");
  358. // Unregister listeners in case of reinitialization.
  359. this.unregisterListeners();
  360. // Initialise the toolbar buttons.
  361. // The main toolbar will only take into account
  362. // it's own configuration from interface_config.
  363. this._initToolbarButtons();
  364. this._setShortcutsAndTooltips();
  365. this._setButtonHandlers();
  366. this.registerListeners();
  367. APP.UI.addListener(UIEvents.SHOW_CUSTOM_TOOLBAR_BUTTON_POPUP,
  368. (popupID, show, timeout) => {
  369. Toolbar._showCustomToolbarPopup(popupID, show, timeout);
  370. });
  371. if(!APP.tokenData.isGuest) {
  372. $("#toolbar_button_profile").addClass("unclickable");
  373. UIUtil.removeTooltip(
  374. document.getElementById('toolbar_button_profile'));
  375. }
  376. },
  377. /**
  378. * Register listeners for UI events of toolbar component.
  379. *
  380. * @returns {void}
  381. */
  382. registerListeners() {
  383. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  384. onSideToolbarContainerToggled);
  385. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  386. onLocalRaiseHandChanged);
  387. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED, onFullScreenToggled);
  388. },
  389. /**
  390. * Unregisters handlers for UI events of Toolbar component.
  391. *
  392. * @returns {void}
  393. */
  394. unregisterListeners() {
  395. APP.UI.removeListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  396. onSideToolbarContainerToggled);
  397. APP.UI.removeListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  398. onLocalRaiseHandChanged);
  399. APP.UI.removeListener(UIEvents.FULLSCREEN_TOGGLED,
  400. onFullScreenToggled);
  401. },
  402. /**
  403. * Enables / disables the toolbar.
  404. * @param {e} set to {true} to enable the toolbar or {false}
  405. * to disable it
  406. */
  407. enable (e) {
  408. this.enabled = e;
  409. if (!e && this.isVisible())
  410. this.hide(false);
  411. },
  412. /**
  413. * Indicates if the bottom toolbar is currently enabled.
  414. * @return {this.enabled}
  415. */
  416. isEnabled() {
  417. return this.enabled;
  418. },
  419. showEtherpadButton () {
  420. if (!$('#toolbar_button_etherpad').is(":visible")) {
  421. $('#toolbar_button_etherpad').css({display: 'inline-block'});
  422. }
  423. },
  424. // Shows or hides the 'shared video' button.
  425. showSharedVideoButton () {
  426. let id = 'toolbar_button_sharedvideo';
  427. let shouldShow = UIUtil.isButtonEnabled('sharedvideo')
  428. && !config.disableThirdPartyRequests;
  429. if (shouldShow) {
  430. let el = document.getElementById(id);
  431. UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
  432. }
  433. UIUtil.setVisible(id, shouldShow);
  434. },
  435. // checks whether desktop sharing is enabled and whether
  436. // we have params to start automatically sharing
  437. checkAutoEnableDesktopSharing () {
  438. if (UIUtil.isButtonEnabled('desktop')
  439. && config.autoEnableDesktopSharing) {
  440. emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
  441. }
  442. },
  443. // Shows or hides SIP calls button
  444. showSipCallButton (show) {
  445. let shouldShow = APP.conference.sipGatewayEnabled()
  446. && UIUtil.isButtonEnabled('sip') && show;
  447. let id = 'toolbar_button_sip';
  448. UIUtil.setVisible(id, shouldShow);
  449. },
  450. // Shows or hides the dialpad button
  451. showDialPadButton (show) {
  452. let shouldShow = UIUtil.isButtonEnabled('dialpad') && show;
  453. let id = 'toolbar_button_dialpad';
  454. UIUtil.setVisible(id, shouldShow);
  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("fadeIn");
  571. },
  572. /**
  573. * Hides the toolbar with animation or not depending on the animate
  574. * parameter.
  575. */
  576. hide() {
  577. this.toolbarSelector
  578. .removeClass("fadeIn")
  579. .addClass("fadeOut");
  580. let slideInAnimation = (SideContainerToggler.isVisible)
  581. ? "slideInExtX"
  582. : "slideInX";
  583. let slideOutAnimation = (SideContainerToggler.isVisible)
  584. ? "slideOutExtX"
  585. : "slideOutX";
  586. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  587. .toggleClass(slideOutAnimation);
  588. },
  589. /**
  590. * Shows the toolbar with animation or not depending on the animate
  591. * parameter.
  592. */
  593. show() {
  594. if (this.toolbarSelector.hasClass("fadeOut")) {
  595. this.toolbarSelector.removeClass("fadeOut");
  596. }
  597. let slideInAnimation = (SideContainerToggler.isVisible)
  598. ? "slideInExtX"
  599. : "slideInX";
  600. let slideOutAnimation = (SideContainerToggler.isVisible)
  601. ? "slideOutExtX"
  602. : "slideOutX";
  603. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  604. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  605. }
  606. this.toolbarSelector.addClass("fadeIn");
  607. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  608. },
  609. registerClickListeners(listener) {
  610. $('#mainToolbarContainer').click(listener);
  611. $("#extendedToolbar").click(listener);
  612. },
  613. /**
  614. * Handles the side toolbar toggle.
  615. *
  616. * @param {string} containerId the identifier of the container element
  617. */
  618. _handleSideToolbarContainerToggled(containerId) {
  619. Object.keys(defaultToolbarButtons).forEach(
  620. id => {
  621. if (!UIUtil.isButtonEnabled(id))
  622. return;
  623. var button = defaultToolbarButtons[id];
  624. if (button.sideContainerId
  625. && button.sideContainerId === containerId) {
  626. UIUtil.buttonClick(button.id, "selected");
  627. return;
  628. }
  629. }
  630. );
  631. },
  632. /**
  633. * Handles full screen toggled.
  634. *
  635. * @param {boolean} isFullScreen indicates if we're currently in full
  636. * screen mode
  637. */
  638. _handleFullScreenToggled(isFullScreen) {
  639. let element
  640. = document.getElementById("toolbar_button_fullScreen");
  641. element.className = isFullScreen
  642. ? element.className
  643. .replace("icon-full-screen", "icon-exit-full-screen")
  644. : element.className
  645. .replace("icon-exit-full-screen", "icon-full-screen");
  646. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  647. },
  648. /**
  649. * Initialise toolbar buttons.
  650. */
  651. _initToolbarButtons() {
  652. interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
  653. let place = getToolbarButtonPlace(value);
  654. if (value && value in defaultToolbarButtons) {
  655. let button = defaultToolbarButtons[value];
  656. this._addToolbarButton(
  657. button,
  658. place,
  659. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  660. && index
  661. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  662. }
  663. });
  664. },
  665. /**
  666. * Adds the given button to the main (top) or extended (left) toolbar.
  667. *
  668. * @param {Object} the button to add.
  669. * @param {boolean} isFirst indicates if this is the first button in the
  670. * toolbar
  671. * @param {boolean} isLast indicates if this is the last button in the
  672. * toolbar
  673. * @param {boolean} isSplitter if this button is a splitter button for
  674. * the dialog, which means that a special splitter style will be applied
  675. */
  676. _addToolbarButton(button, place, isSplitter) {
  677. const places = {
  678. main: 'mainToolbar',
  679. extended: 'extendedToolbarButtons'
  680. };
  681. let id = places[place];
  682. let buttonElement = document.createElement("a");
  683. if (button.className) {
  684. buttonElement.className = button.className;
  685. }
  686. if (isSplitter) {
  687. let splitter = document.createElement('span');
  688. splitter.className = 'toolbar__splitter';
  689. document.getElementById(id).appendChild(splitter);
  690. }
  691. buttonElement.id = button.id;
  692. if (button.html)
  693. buttonElement.innerHTML = button.html;
  694. //TODO: remove it after UI.updateDTMFSupport fix
  695. if (button.hidden)
  696. buttonElement.style.display = 'none';
  697. if (button.shortcutAttr)
  698. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  699. if (button.content)
  700. buttonElement.setAttribute("content", button.content);
  701. if (button.i18n)
  702. buttonElement.setAttribute("data-i18n", button.i18n);
  703. buttonElement.setAttribute("data-container", "body");
  704. buttonElement.setAttribute("data-placement", "bottom");
  705. this._addPopups(buttonElement, button.popups);
  706. document.getElementById(id)
  707. .appendChild(buttonElement);
  708. },
  709. _addPopups(buttonElement, popups = []) {
  710. popups.forEach((popup) => {
  711. const popupElement = document.createElement('div');
  712. popupElement.id = popup.id;
  713. popupElement.className = popup.className;
  714. popupElement.setAttribute('data-i18n', popup.dataAttr);
  715. let gravity = 'n';
  716. if (popup.dataAttrPosition)
  717. gravity = popup.dataAttrPosition;
  718. // use custom attribute to save gravity option
  719. // we use 'data-tooltip' in UIUtil to activate all tooltips
  720. // but we want these to be manually triggered
  721. popupElement.setAttribute('tooltip-gravity', gravity);
  722. APP.translation.translateElement($(popupElement));
  723. buttonElement.appendChild(popupElement);
  724. });
  725. },
  726. /**
  727. * Show custom popup/tooltip for a specified button.
  728. * @param popupSelectorID the selector id of the popup to show
  729. * @param show true or false/show or hide the popup
  730. * @param timeout the time to show the popup
  731. */
  732. _showCustomToolbarPopup(popupSelectorID, show, timeout) {
  733. const gravity = $(popupSelectorID).attr('tooltip-gravity');
  734. AJS.$(popupSelectorID)
  735. .tooltip({
  736. trigger: 'manual',
  737. html: true,
  738. gravity: gravity,
  739. title: 'title'});
  740. if (show) {
  741. AJS.$(popupSelectorID).tooltip('show');
  742. setTimeout(function () {
  743. // hide the tooltip
  744. AJS.$(popupSelectorID).tooltip('hide');
  745. }, timeout);
  746. } else {
  747. AJS.$(popupSelectorID).tooltip('hide');
  748. }
  749. },
  750. /**
  751. * Sets the toggled state of the given element depending on the isToggled
  752. * parameter.
  753. *
  754. * @param elementId the element identifier
  755. * @param isToggled indicates if the element should be toggled or untoggled
  756. */
  757. _setToggledState(elementId, isToggled) {
  758. $("#" + elementId).toggleClass("toggled", isToggled);
  759. },
  760. /**
  761. * Sets Shortcuts and Tooltips for all toolbar buttons
  762. *
  763. * @private
  764. */
  765. _setShortcutsAndTooltips() {
  766. Object.keys(defaultToolbarButtons).forEach(
  767. id => {
  768. if (UIUtil.isButtonEnabled(id)) {
  769. let button = defaultToolbarButtons[id];
  770. let buttonElement = document.getElementById(button.id);
  771. if (!buttonElement) return false;
  772. let tooltipPosition
  773. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  774. .indexOf(id) > -1)
  775. ? "bottom" : "right";
  776. UIUtil.setTooltip( buttonElement,
  777. button.tooltipKey,
  778. tooltipPosition);
  779. if (button.shortcut)
  780. APP.keyboardshortcut.registerShortcut(
  781. button.shortcut,
  782. button.shortcutAttr,
  783. button.shortcutFunc,
  784. button.shortcutDescription
  785. );
  786. }
  787. }
  788. );
  789. },
  790. /**
  791. * Sets Handlers for all toolbar buttons
  792. *
  793. * @private
  794. */
  795. _setButtonHandlers() {
  796. Object.keys(buttonHandlers).forEach(
  797. buttonId => $(`#${buttonId}`).click(function(event) {
  798. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  799. })
  800. );
  801. }
  802. };
  803. export default Toolbar;