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

Toolbar.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834
  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. Toolbar = {
  322. init (eventEmitter) {
  323. emitter = eventEmitter;
  324. // The toolbar is enabled by default.
  325. this.enabled = true;
  326. this.toolbarSelector = $("#mainToolbarContainer");
  327. this.extendedToolbarSelector = $("#extendedToolbar");
  328. // Initialise the toolbar buttons.
  329. // The main toolbar will only take into account
  330. // it's own configuration from interface_config.
  331. this._initToolbarButtons();
  332. this._setShortcutsAndTooltips();
  333. this._setButtonHandlers();
  334. APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
  335. (containerId, isVisible) => {
  336. Toolbar._handleSideToolbarContainerToggled( containerId,
  337. isVisible);
  338. });
  339. APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
  340. (isRaisedHand) => {
  341. this._setToggledState("toolbar_button_raisehand", isRaisedHand);
  342. });
  343. APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
  344. (isFullScreen) => {
  345. Toolbar._handleFullScreenToggled(isFullScreen);
  346. });
  347. APP.UI.addListener(UIEvents.SHOW_CUSTOM_TOOLBAR_BUTTON_POPUP,
  348. (toolbarButtonID, popupID, show, timeout) => {
  349. Toolbar._showCustomToolbarPopup(
  350. toolbarButtonID, popupID, show, timeout);
  351. });
  352. if(!APP.tokenData.isGuest) {
  353. $("#toolbar_button_profile").addClass("unclickable");
  354. UIUtil.removeTooltip(
  355. document.getElementById('toolbar_button_profile'));
  356. }
  357. },
  358. /**
  359. * Enables / disables the toolbar.
  360. * @param {e} set to {true} to enable the toolbar or {false}
  361. * to disable it
  362. */
  363. enable (e) {
  364. this.enabled = e;
  365. if (!e && this.isVisible())
  366. this.hide(false);
  367. },
  368. /**
  369. * Indicates if the bottom toolbar is currently enabled.
  370. * @return {this.enabled}
  371. */
  372. isEnabled() {
  373. return this.enabled;
  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 id = 'toolbar_button_sharedvideo';
  383. let shouldShow = UIUtil.isButtonEnabled('sharedvideo')
  384. && !config.disableThirdPartyRequests;
  385. if (shouldShow) {
  386. let el = document.getElementById(id);
  387. UIUtil.setTooltip(el, 'toolbar.sharedvideo', 'right');
  388. }
  389. UIUtil.setVisible(id, shouldShow);
  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. let shouldShow = APP.conference.sipGatewayEnabled()
  402. && UIUtil.isButtonEnabled('sip') && show;
  403. let id = 'toolbar_button_sip';
  404. UIUtil.setVisible(id, shouldShow);
  405. },
  406. // Shows or hides the dialpad button
  407. showDialPadButton (show) {
  408. let shouldShow = UIUtil.isButtonEnabled('dialpad') && show;
  409. let id = 'toolbar_button_dialpad';
  410. UIUtil.setVisible(id, shouldShow);
  411. },
  412. /**
  413. * Update the state of the button. The button has blue glow if desktop
  414. * streaming is active.
  415. */
  416. updateDesktopSharingButtonState () {
  417. this._setToggledState( "toolbar_button_desktopsharing",
  418. APP.conference.isSharingScreen);
  419. },
  420. /**
  421. * Marks video icon as muted or not.
  422. *
  423. * @param {boolean} muted if icon should look like muted or not
  424. */
  425. toggleVideoIcon (muted) {
  426. $('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
  427. this._setToggledState("toolbar_button_camera", muted);
  428. },
  429. /**
  430. * Enables / disables audio toolbar button.
  431. *
  432. * @param {boolean} enabled indicates if the button should be enabled
  433. * or disabled
  434. */
  435. setVideoIconEnabled (enabled) {
  436. this._setMediaIconEnabled(
  437. '#toolbar_button_camera',
  438. enabled,
  439. /* data-i18n attribute value */
  440. `[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
  441. /* shortcut attribute value */
  442. 'toggleVideoPopover');
  443. enabled || this.toggleVideoIcon(!enabled);
  444. },
  445. /**
  446. * Enables/disables the toolbar button associated with a specific media such
  447. * as audio or video.
  448. *
  449. * @param {string} btn - The jQuery selector <tt>string</tt> which
  450. * identifies the toolbar button to be enabled/disabled.
  451. * @param {boolean} enabled - <tt>true</tt> to enable the specified
  452. * <tt>btn</tt> or <tt>false</tt> to disable it.
  453. * @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
  454. * attribute of the specified <tt>btn</tt>.
  455. * @param {string} shortcut - The value, if any, to assign to the
  456. * <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
  457. * button is enabled.
  458. */
  459. _setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
  460. const $btn = $(btn);
  461. $btn
  462. .prop('disabled', !enabled)
  463. .attr('data-i18n', dataI18n)
  464. .attr('shortcut', enabled && shortcut ? shortcut : '');
  465. enabled
  466. ? $btn.removeAttr('disabled')
  467. : $btn.attr('disabled', 'disabled');
  468. APP.translation.translateElement($btn);
  469. },
  470. /**
  471. * Marks audio icon as muted or not.
  472. *
  473. * @param {boolean} muted if icon should look like muted or not
  474. */
  475. toggleAudioIcon(muted) {
  476. $('#toolbar_button_mute')
  477. .toggleClass("icon-microphone", !muted)
  478. .toggleClass("icon-mic-disabled", muted);
  479. this._setToggledState("toolbar_button_mute", muted);
  480. },
  481. /**
  482. * Enables / disables audio toolbar button.
  483. *
  484. * @param {boolean} enabled indicates if the button should be enabled
  485. * or disabled
  486. */
  487. setAudioIconEnabled (enabled) {
  488. this._setMediaIconEnabled(
  489. '#toolbar_button_mute',
  490. enabled,
  491. /* data-i18n attribute value */
  492. `[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
  493. /* shortcut attribute value */
  494. 'mutePopover');
  495. enabled || this.toggleAudioIcon(!enabled);
  496. },
  497. /**
  498. * Indicates if the toolbar is currently hovered.
  499. * @return {boolean} true if the toolbar is currently hovered,
  500. * false otherwise
  501. */
  502. isHovered() {
  503. var hovered = false;
  504. this.toolbarSelector.find('*').each(function () {
  505. let id = $(this).attr('id');
  506. if ($(`#${id}:hover`).length > 0) {
  507. hovered = true;
  508. // break each
  509. return false;
  510. }
  511. });
  512. if (hovered)
  513. return true;
  514. if ($("#bottomToolbar:hover").length > 0
  515. || $("#extendedToolbar:hover").length > 0
  516. || SideContainerToggler.isHovered()) {
  517. return true;
  518. }
  519. return false;
  520. },
  521. /**
  522. * Returns true if this toolbar is currently visible, or false otherwise.
  523. * @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
  524. */
  525. isVisible() {
  526. return this.toolbarSelector.hasClass("fadeIn");
  527. },
  528. /**
  529. * Hides the toolbar with animation or not depending on the animate
  530. * parameter.
  531. */
  532. hide() {
  533. this.toolbarSelector
  534. .removeClass("fadeIn")
  535. .addClass("fadeOut");
  536. let slideInAnimation = (SideContainerToggler.isVisible)
  537. ? "slideInExtX"
  538. : "slideInX";
  539. let slideOutAnimation = (SideContainerToggler.isVisible)
  540. ? "slideOutExtX"
  541. : "slideOutX";
  542. this.extendedToolbarSelector.toggleClass(slideInAnimation)
  543. .toggleClass(slideOutAnimation);
  544. },
  545. /**
  546. * Shows the toolbar with animation or not depending on the animate
  547. * parameter.
  548. */
  549. show() {
  550. if (this.toolbarSelector.hasClass("fadeOut")) {
  551. this.toolbarSelector.removeClass("fadeOut");
  552. }
  553. let slideInAnimation = (SideContainerToggler.isVisible)
  554. ? "slideInExtX"
  555. : "slideInX";
  556. let slideOutAnimation = (SideContainerToggler.isVisible)
  557. ? "slideOutExtX"
  558. : "slideOutX";
  559. if (this.extendedToolbarSelector.hasClass(slideOutAnimation)) {
  560. this.extendedToolbarSelector.toggleClass(slideOutAnimation);
  561. }
  562. this.toolbarSelector.addClass("fadeIn");
  563. this.extendedToolbarSelector.toggleClass(slideInAnimation);
  564. },
  565. registerClickListeners(listener) {
  566. $('#mainToolbarContainer').click(listener);
  567. $("#extendedToolbar").click(listener);
  568. },
  569. /**
  570. * Handles the side toolbar toggle.
  571. *
  572. * @param {string} containerId the identifier of the container element
  573. */
  574. _handleSideToolbarContainerToggled(containerId) {
  575. Object.keys(defaultToolbarButtons).forEach(
  576. id => {
  577. if (!UIUtil.isButtonEnabled(id))
  578. return;
  579. var button = defaultToolbarButtons[id];
  580. if (button.sideContainerId
  581. && button.sideContainerId === containerId) {
  582. UIUtil.buttonClick(button.id, "selected");
  583. return;
  584. }
  585. }
  586. );
  587. },
  588. /**
  589. * Handles full screen toggled.
  590. *
  591. * @param {boolean} isFullScreen indicates if we're currently in full
  592. * screen mode
  593. */
  594. _handleFullScreenToggled(isFullScreen) {
  595. let element
  596. = document.getElementById("toolbar_button_fullScreen");
  597. element.className = isFullScreen
  598. ? element.className
  599. .replace("icon-full-screen", "icon-exit-full-screen")
  600. : element.className
  601. .replace("icon-exit-full-screen", "icon-full-screen");
  602. Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
  603. },
  604. /**
  605. * Initialise toolbar buttons.
  606. */
  607. _initToolbarButtons() {
  608. interfaceConfig.TOOLBAR_BUTTONS.forEach((value, index) => {
  609. let place = getToolbarButtonPlace(value);
  610. if (value && value in defaultToolbarButtons) {
  611. let button = defaultToolbarButtons[value];
  612. this._addToolbarButton(
  613. button,
  614. place,
  615. (interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
  616. && index
  617. === interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
  618. }
  619. });
  620. },
  621. /**
  622. * Adds the given button to the main (top) or extended (left) toolbar.
  623. *
  624. * @param {Object} the button to add.
  625. * @param {boolean} isFirst indicates if this is the first button in the
  626. * toolbar
  627. * @param {boolean} isLast indicates if this is the last button in the
  628. * toolbar
  629. * @param {boolean} isSplitter if this button is a splitter button for
  630. * the dialog, which means that a special splitter style will be applied
  631. */
  632. _addToolbarButton(button, place, isSplitter) {
  633. const places = {
  634. main: 'mainToolbar',
  635. extended: 'extendedToolbarButtons'
  636. };
  637. let id = places[place];
  638. let buttonElement = document.createElement("a");
  639. if (button.className) {
  640. buttonElement.className = button.className;
  641. }
  642. if (isSplitter) {
  643. let splitter = document.createElement('span');
  644. splitter.className = 'toolbar__splitter';
  645. document.getElementById(id).appendChild(splitter);
  646. }
  647. buttonElement.id = button.id;
  648. if (button.html)
  649. buttonElement.innerHTML = button.html;
  650. //TODO: remove it after UI.updateDTMFSupport fix
  651. if (button.hidden)
  652. buttonElement.style.display = 'none';
  653. if (button.shortcutAttr)
  654. buttonElement.setAttribute("shortcut", button.shortcutAttr);
  655. if (button.content)
  656. buttonElement.setAttribute("content", button.content);
  657. if (button.i18n)
  658. buttonElement.setAttribute("data-i18n", button.i18n);
  659. buttonElement.setAttribute("data-container", "body");
  660. buttonElement.setAttribute("data-placement", "bottom");
  661. this._addPopups(buttonElement, button.popups);
  662. document.getElementById(id)
  663. .appendChild(buttonElement);
  664. },
  665. _addPopups(buttonElement, popups = []) {
  666. popups.forEach((popup) => {
  667. const popupElement = document.createElement('div');
  668. popupElement.id = popup.id;
  669. popupElement.className = popup.className;
  670. popupElement.setAttribute('data-i18n', popup.dataAttr);
  671. let gravity = 'n';
  672. if (popup.dataAttrPosition)
  673. gravity = popup.dataAttrPosition;
  674. popupElement.setAttribute('data-tooltip', gravity);
  675. buttonElement.appendChild(popupElement);
  676. });
  677. },
  678. /**
  679. * Show custom popup/tooltip for a specified button.
  680. * @param popupSelectorID the selector id of the popup to show
  681. * @param show true or false/show or hide the popup
  682. * @param timeout the time to show the popup
  683. */
  684. _showCustomToolbarPopup(popupSelectorID, show, timeout) {
  685. const gravity = $(popupSelectorID).attr('data-tooltip');
  686. AJS.$(popupSelectorID)
  687. .tooltip({
  688. trigger: 'manual',
  689. html: true,
  690. gravity: gravity,
  691. title: 'title'});
  692. if (show) {
  693. AJS.$(popupSelectorID).tooltip('show');
  694. setTimeout(function () {
  695. // hide the tooltip
  696. AJS.$(popupSelectorID).tooltip('hide');
  697. }, timeout);
  698. } else {
  699. AJS.$(popupSelectorID).tooltip('hide');
  700. }
  701. },
  702. /**
  703. * Sets the toggled state of the given element depending on the isToggled
  704. * parameter.
  705. *
  706. * @param elementId the element identifier
  707. * @param isToggled indicates if the element should be toggled or untoggled
  708. */
  709. _setToggledState(elementId, isToggled) {
  710. $("#" + elementId).toggleClass("toggled", isToggled);
  711. },
  712. /**
  713. * Sets Shortcuts and Tooltips for all toolbar buttons
  714. *
  715. * @private
  716. */
  717. _setShortcutsAndTooltips() {
  718. Object.keys(defaultToolbarButtons).forEach(
  719. id => {
  720. if (UIUtil.isButtonEnabled(id)) {
  721. let button = defaultToolbarButtons[id];
  722. let buttonElement = document.getElementById(button.id);
  723. if (!buttonElement) return false;
  724. let tooltipPosition
  725. = (interfaceConfig.MAIN_TOOLBAR_BUTTONS
  726. .indexOf(id) > -1)
  727. ? "bottom" : "right";
  728. UIUtil.setTooltip( buttonElement,
  729. button.tooltipKey,
  730. tooltipPosition);
  731. if (button.shortcut)
  732. APP.keyboardshortcut.registerShortcut(
  733. button.shortcut,
  734. button.shortcutAttr,
  735. button.shortcutFunc,
  736. button.shortcutDescription
  737. );
  738. }
  739. }
  740. );
  741. },
  742. /**
  743. * Sets Handlers for all toolbar buttons
  744. *
  745. * @private
  746. */
  747. _setButtonHandlers() {
  748. Object.keys(buttonHandlers).forEach(
  749. buttonId => $(`#${buttonId}`).click(function(event) {
  750. !$(this).prop('disabled') && buttonHandlers[buttonId](event);
  751. })
  752. );
  753. }
  754. };
  755. export default Toolbar;