jiti-meet/modules/UI/toolbars/Toolbar.js

784 lines
26 KiB
JavaScript
Raw Normal View History

/* global APP, $, config, interfaceConfig, JitsiMeetJS */
2015-12-10 16:36:03 +00:00
import UIUtil from '../util/UIUtil';
import UIEvents from '../../../service/UI/UIEvents';
import SideContainerToggler from "../side_pannels/SideContainerToggler";
2015-01-07 14:54:03 +00:00
2015-12-10 16:36:03 +00:00
let emitter = null;
let Toolbar;
2015-12-10 13:30:25 +00:00
const buttonHandlers = {
2016-09-11 21:54:32 +00:00
"toolbar_button_profile": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.profile.toggled');
emitter.emit(UIEvents.TOGGLE_PROFILE);
},
2015-01-07 14:54:03 +00:00
"toolbar_button_mute": function () {
let sharedVideoManager = APP.UI.getSharedVideoManager();
if (APP.conference.audioMuted) {
// If there's a shared video with the volume "on" and we aren't
// the video owner, we warn the user
// that currently it's not possible to unmute.
if (sharedVideoManager
&& sharedVideoManager.isSharedVideoVolumeOn()
&& !sharedVideoManager.isSharedVideoOwner()) {
UIUtil.animateShowElement(
$("#unableToUnmutePopup"), true, 5000);
}
else {
JitsiMeetJS.analytics.sendEvent('toolbar.audio.unmuted');
emitter.emit(UIEvents.AUDIO_MUTED, false, true);
}
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.audio.muted');
emitter.emit(UIEvents.AUDIO_MUTED, true, true);
2015-09-02 17:08:48 +00:00
}
2015-01-07 14:54:03 +00:00
},
"toolbar_button_camera": function () {
if (APP.conference.videoMuted) {
JitsiMeetJS.analytics.sendEvent('toolbar.video.enabled');
2015-12-03 13:11:01 +00:00
emitter.emit(UIEvents.VIDEO_MUTED, false);
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.video.disabled');
2015-12-03 13:11:01 +00:00
emitter.emit(UIEvents.VIDEO_MUTED, true);
2015-09-02 17:08:48 +00:00
}
2015-01-07 14:54:03 +00:00
},
"toolbar_button_link": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.invite.clicked');
emitter.emit(UIEvents.INVITE_CLICKED);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_chat": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.chat.toggled');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.TOGGLE_CHAT);
2015-01-07 14:54:03 +00:00
},
"toolbar_contact_list": function () {
JitsiMeetJS.analytics.sendEvent(
'toolbar.contacts.toggled');
emitter.emit(UIEvents.TOGGLE_CONTACT_LIST);
},
2015-01-07 14:54:03 +00:00
"toolbar_button_etherpad": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.etherpad.clicked');
emitter.emit(UIEvents.ETHERPAD_CLICKED);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_sharedvideo": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sharedvideo.clicked');
emitter.emit(UIEvents.SHARED_VIDEO_CLICKED);
},
2015-01-07 14:54:03 +00:00
"toolbar_button_desktopsharing": function () {
if (APP.conference.isSharingScreen) {
JitsiMeetJS.analytics.sendEvent('toolbar.screen.disabled');
2015-09-02 17:08:48 +00:00
} else {
JitsiMeetJS.analytics.sendEvent('toolbar.screen.enabled');
2015-09-02 17:08:48 +00:00
}
2015-12-30 13:28:56 +00:00
emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_fullScreen": function() {
JitsiMeetJS.analytics.sendEvent('toolbar.fullscreen.enabled');
2016-10-13 20:09:18 +00:00
emitter.emit(UIEvents.TOGGLE_FULLSCREEN);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_sip": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sip.clicked');
2015-12-10 15:48:56 +00:00
showSipNumberInput();
2015-01-07 14:54:03 +00:00
},
"toolbar_button_dialpad": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.sip.dialpad.clicked');
2015-12-10 13:30:25 +00:00
dialpadButtonClicked();
},
2015-01-07 14:54:03 +00:00
"toolbar_button_settings": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.settings.toggled');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.TOGGLE_SETTINGS);
2015-01-07 14:54:03 +00:00
},
"toolbar_button_hangup": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.hangup');
2015-12-10 15:48:56 +00:00
emitter.emit(UIEvents.HANGUP);
},
"toolbar_button_login": function () {
JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.login.clicked');
2015-12-10 13:30:25 +00:00
emitter.emit(UIEvents.AUTH_CLICKED);
},
"toolbar_button_logout": function () {
let titleKey = "dialog.logoutTitle";
let msgKey = "dialog.logoutQuestion";
JitsiMeetJS.analytics.sendEvent('toolbar.authenticate.logout.clicked');
// Ask for confirmation
APP.UI.messageHandler.openTwoButtonDialog({
titleKey,
msgKey,
leftButtonKey: "dialog.Yes",
submitFunction: function (evt, yes) {
if (yes) {
2015-12-10 15:48:56 +00:00
emitter.emit(UIEvents.LOGOUT);
}
2015-12-10 15:48:56 +00:00
}
});
},
"toolbar_film_strip": function () {
JitsiMeetJS.analytics.sendEvent(
'toolbar.filmstrip.toggled');
emitter.emit(UIEvents.TOGGLE_FILM_STRIP);
},
"toolbar_button_raisehand": function () {
JitsiMeetJS.analytics.sendEvent(
'toolbar.raiseHand.clicked');
APP.conference.maybeToggleRaisedHand();
2015-01-07 14:54:03 +00:00
}
};
2016-09-11 21:54:32 +00:00
2015-12-10 16:36:03 +00:00
const defaultToolbarButtons = {
2016-08-29 03:59:09 +00:00
'microphone': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_mute',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.mute',
2016-09-11 21:54:32 +00:00
className: "button icon-microphone",
2016-08-29 03:59:09 +00:00
shortcut: 'M',
shortcutAttr: 'mutePopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.audiomute.toggled');
APP.conference.toggleAudioMuted();
},
2016-09-11 21:54:32 +00:00
shortcutDescription: "keyboardShortcuts.mute",
2016-09-12 19:43:34 +00:00
popups: [
{
id: "micMutedPopup",
className: "loginmenu",
dataAttr: "[html]toolbar.micMutedPopup"
},
{
id: "unableToUnmutePopup",
className: "loginmenu",
dataAttr: "[html]toolbar.unableToUnmutePopup"
},
{
id: "talkWhileMutedPopup",
className: "loginmenu",
dataAttr: "[html]toolbar.talkWhileMutedPopup"
2016-09-12 19:43:34 +00:00
}
],
2016-09-11 21:54:32 +00:00
content: "Mute / Unmute",
i18n: "[content]toolbar.mute"
2016-08-29 03:59:09 +00:00
},
'camera': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_camera',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.videomute',
2016-09-11 21:54:32 +00:00
className: "button icon-camera",
2016-08-29 03:59:09 +00:00
shortcut: 'V',
shortcutAttr: 'toggleVideoPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.videomute.toggled');
APP.conference.toggleVideoMuted();
},
2016-09-11 21:54:32 +00:00
shortcutDescription: "keyboardShortcuts.videoMute",
content: "Start / stop camera",
i18n: "[content]toolbar.videomute"
2016-08-29 03:59:09 +00:00
},
'desktop': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_desktopsharing',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.sharescreen',
className: 'button icon-share-desktop',
2016-08-29 03:59:09 +00:00
shortcut: 'D',
shortcutAttr: 'toggleDesktopSharingPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.screen.toggled');
APP.conference.toggleScreenSharing();
},
shortcutDescription: 'keyboardShortcuts.toggleScreensharing',
content: 'Share screen',
i18n: '[content]toolbar.sharescreen'
2016-08-29 03:59:09 +00:00
},
'invite': {
id: 'toolbar_button_link',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.invite',
className: 'button icon-link',
content: 'Invite others',
i18n: '[content]toolbar.invite'
2016-08-29 03:59:09 +00:00
},
'chat': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_chat',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.chat',
2016-08-29 03:59:09 +00:00
shortcut: 'C',
shortcutAttr: 'toggleChatPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.chat.toggled');
APP.UI.toggleChat();
},
shortcutDescription: 'keyboardShortcuts.toggleChat',
sideContainerId: 'chat_container'
2016-08-29 03:59:09 +00:00
},
'contacts': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_contact_list',
2016-09-16 03:22:56 +00:00
tooltipKey: 'bottomtoolbar.contactlist',
sideContainerId: 'contacts_container'
},
2016-09-11 21:54:32 +00:00
'profile': {
id: 'toolbar_button_profile',
2016-09-16 03:22:56 +00:00
tooltipKey: 'profile.setDisplayNameLabel',
sideContainerId: 'profile_container'
2016-09-11 21:54:32 +00:00
},
2016-08-29 03:59:09 +00:00
'etherpad': {
2016-09-16 03:22:56 +00:00
id: 'toolbar_button_etherpad',
tooltipKey: 'toolbar.etherpad',
2016-08-29 03:59:09 +00:00
},
'fullscreen': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_fullScreen',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.fullscreen',
2016-09-11 21:54:32 +00:00
className: "button icon-full-screen",
shortcut: 'S',
2016-09-11 21:54:32 +00:00
shortcutAttr: 'toggleFullscreenPopover',
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent('shortcut.fullscreen.toggled');
APP.UI.toggleFullScreen();
},
shortcutDescription: "keyboardShortcuts.fullScreen",
2016-09-11 21:54:32 +00:00
content: "Enter / Exit Full Screen",
i18n: "[content]toolbar.fullscreen"
2016-08-29 03:59:09 +00:00
},
'settings': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_settings',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.Settings',
sideContainerId: "settings_container"
2016-08-29 03:59:09 +00:00
},
'hangup': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_button_hangup',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.hangup',
2016-09-11 21:54:32 +00:00
className: "button icon-hangup",
content: "Hang Up",
i18n: "[content]toolbar.hangup"
},
'filmstrip': {
2016-09-11 21:54:32 +00:00
id: 'toolbar_film_strip',
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.filmstrip',
shortcut: "F",
shortcutAttr: "filmstripPopover",
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent("shortcut.film.toggled");
APP.UI.toggleFilmStrip();
},
shortcutDescription: "keyboardShortcuts.toggleFilmstrip"
},
'raisehand': {
id: "toolbar_button_raisehand",
2016-09-16 03:22:56 +00:00
tooltipKey: 'toolbar.raiseHand',
className: "button icon-raised-hand",
shortcut: "R",
shortcutAttr: "raiseHandPopover",
shortcutFunc: function() {
JitsiMeetJS.analytics.sendEvent("shortcut.raisehand.clicked");
APP.conference.maybeToggleRaisedHand();
},
shortcutDescription: "keyboardShortcuts.raiseHand",
content: "Raise Hand",
i18n: "[content]toolbar.raiseHand"
2016-08-29 03:59:09 +00:00
}
};
2015-01-07 14:54:03 +00:00
function dialpadButtonClicked() {
//TODO show the dialpad box
}
2015-12-10 15:48:56 +00:00
function showSipNumberInput () {
2015-12-10 13:30:25 +00:00
let defaultNumber = config.defaultSipNumber
? config.defaultSipNumber
: '';
let titleKey = "dialog.sipMsg";
2015-12-10 13:30:25 +00:00
let sipMsg = APP.translation.generateTranslationHTML("dialog.sipMsg");
let msgString = (`
<input name="sipNumber" type="text"
value="${defaultNumber}" autofocus>
`);
APP.UI.messageHandler.openTwoButtonDialog({
titleKey,
titleString: sipMsg,
msgString,
leftButtonKey: "dialog.Dial",
submitFunction: function (e, v, m, f) {
2015-12-10 15:48:56 +00:00
if (v && f.sipNumber) {
emitter.emit(UIEvents.SIP_DIAL, f.sipNumber);
}
},
focus: ':input:first'
});
}
Toolbar = {
2015-12-09 17:10:49 +00:00
init (eventEmitter) {
2015-12-03 13:11:01 +00:00
emitter = eventEmitter;
// The toolbar is enabled by default.
this.enabled = true;
this.toolbarSelector = $("#mainToolbarContainer");
this.extendedToolbarSelector = $("#extendedToolbar");
2015-12-10 16:36:03 +00:00
// First hide all disabled buttons in the extended toolbar.
// TODO: Make the extended toolbar dynamically created.
UIUtil.hideDisabledButtons(defaultToolbarButtons);
// Initialise the main toolbar. The main toolbar will only take into
// account it's own configuration from interface_config.
this._initMainToolbarButtons();
2016-08-29 03:59:09 +00:00
Object.keys(defaultToolbarButtons).forEach(
id => {
if (UIUtil.isButtonEnabled(id)) {
2016-09-16 03:22:56 +00:00
let button = defaultToolbarButtons[id];
let buttonElement = document.getElementById(button.id);
let tooltipPosition
= (interfaceConfig.MAIN_TOOLBAR_BUTTONS
.indexOf(id) > -1)
? "bottom" : "right";
UIUtil.setTooltip( buttonElement,
button.tooltipKey,
tooltipPosition);
2016-08-29 03:59:09 +00:00
if (button.shortcut)
APP.keyboardshortcut.registerShortcut(
2016-08-29 03:59:09 +00:00
button.shortcut,
button.shortcutAttr,
button.shortcutFunc,
button.shortcutDescription
);
}
}
);
2015-12-10 16:36:03 +00:00
Object.keys(buttonHandlers).forEach(
buttonId => $(`#${buttonId}`).click(function(event) {
!$(this).prop('disabled') && buttonHandlers[buttonId](event);
})
2015-12-10 16:36:03 +00:00
);
APP.UI.addListener(UIEvents.SIDE_TOOLBAR_CONTAINER_TOGGLED,
(containerId, isVisible) => {
2016-09-11 21:54:32 +00:00
Toolbar._handleSideToolbarContainerToggled( containerId,
isVisible);
});
APP.UI.addListener(UIEvents.LOCAL_RAISE_HAND_CHANGED,
(isRaisedHand) => {
this._setToggledState("toolbar_button_raisehand", isRaisedHand);
2016-09-16 05:09:26 +00:00
});
2016-10-13 20:09:18 +00:00
APP.UI.addListener(UIEvents.FULLSCREEN_TOGGLED,
(isFullScreen) => {
Toolbar._handleFullScreenToggled(isFullScreen);
});
if(!APP.tokenData.isGuest) {
$("#toolbar_button_profile").addClass("unclickable");
UIUtil.removeTooltip(
document.getElementById('toolbar_button_profile'));
}
2015-12-09 17:10:49 +00:00
},
/**
* Enables / disables the toolbar.
* @param {e} set to {true} to enable the toolbar or {false}
* to disable it
*/
enable (e) {
this.enabled = e;
if (!e && this.isVisible())
this.hide(false);
},
/**
* Indicates if the bottom toolbar is currently enabled.
* @return {this.enabled}
*/
isEnabled() {
return this.enabled;
},
/**
* Shows or hides authentication button
* @param show <tt>true</tt> to show or <tt>false</tt> to hide
*/
2015-12-09 17:10:49 +00:00
showAuthenticateButton (show) {
let display = show ? 'block' : 'none';
$('#authenticationContainer').css({display});
2015-12-09 17:10:49 +00:00
},
2015-12-25 16:55:45 +00:00
showEtherpadButton () {
if (!$('#toolbar_button_etherpad').is(":visible")) {
$('#toolbar_button_etherpad').css({display: 'inline-block'});
}
},
// Shows or hides the 'shared video' button.
showSharedVideoButton () {
2016-09-16 03:22:56 +00:00
let $element = $('#toolbar_button_sharedvideo');
if (UIUtil.isButtonEnabled('sharedvideo')
&& config.disableThirdPartyRequests !== true) {
2016-09-16 03:22:56 +00:00
$element.css({display: "inline-block"});
UIUtil.setTooltip($element.get(0), 'toolbar.sharedvideo', 'right');
} else {
$('#toolbar_button_sharedvideo').css({display: "none"});
}
},
// checks whether desktop sharing is enabled and whether
// we have params to start automatically sharing
2015-12-09 17:10:49 +00:00
checkAutoEnableDesktopSharing () {
if (UIUtil.isButtonEnabled('desktop')
&& config.autoEnableDesktopSharing) {
2015-12-30 13:28:56 +00:00
emitter.emit(UIEvents.TOGGLE_SCREENSHARING);
}
2015-12-09 17:10:49 +00:00
},
2014-08-08 13:25:24 +00:00
// Shows or hides SIP calls button
2015-12-09 17:10:49 +00:00
showSipCallButton (show) {
if (APP.conference.sipGatewayEnabled()
&& UIUtil.isButtonEnabled('sip') && show) {
$('#toolbar_button_sip').css({display: "inline-block"});
} else {
$('#toolbar_button_sip').css({display: "none"});
2014-08-08 13:25:24 +00:00
}
2015-12-09 17:10:49 +00:00
},
2014-08-08 13:25:24 +00:00
// Shows or hides the dialpad button
2015-12-09 17:10:49 +00:00
showDialPadButton (show) {
if (UIUtil.isButtonEnabled('dialpad') && show) {
$('#toolbar_button_dialpad').css({display: "inline-block"});
} else {
$('#toolbar_button_dialpad').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Displays user authenticated identity name(login).
* @param authIdentity identity name to be displayed.
*/
2015-12-09 17:10:49 +00:00
setAuthenticatedIdentity (authIdentity) {
let selector = $('#toolbar_auth_identity');
if (authIdentity) {
2015-04-08 10:49:49 +00:00
selector.css({display: "list-item"});
selector.text(authIdentity);
} else {
selector.css({display: "none"});
selector.text('');
}
2015-12-09 17:10:49 +00:00
},
/**
* Shows/hides login button.
* @param show <tt>true</tt> to show
*/
2015-12-09 17:10:49 +00:00
showLoginButton (show) {
if (show) {
$('#toolbar_button_login').css({display: "list-item"});
} else {
$('#toolbar_button_login').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Shows/hides logout button.
* @param show <tt>true</tt> to show
*/
2015-12-09 17:10:49 +00:00
showLogoutButton (show) {
if (show) {
$('#toolbar_button_logout').css({display: "list-item"});
} else {
$('#toolbar_button_logout').css({display: "none"});
}
2015-12-09 17:10:49 +00:00
},
/**
* Update the state of the button. The button has blue glow if desktop
* streaming is active.
*/
updateDesktopSharingButtonState () {
this._setToggledState( "toolbar_button_desktopsharing",
APP.conference.isSharingScreen);
2016-09-16 05:09:26 +00:00
},
/**
* Marks video icon as muted or not.
*
* @param {boolean} muted if icon should look like muted or not
*/
toggleVideoIcon (muted) {
$('#toolbar_button_camera').toggleClass("icon-camera-disabled", muted);
this._setToggledState("toolbar_button_camera", muted);
},
/**
* Enables / disables audio toolbar button.
*
* @param {boolean} enabled indicates if the button should be enabled
* or disabled
*/
setVideoIconEnabled (enabled) {
2016-10-07 20:31:00 +00:00
this._setMediaIconEnabled(
'#toolbar_button_camera',
enabled,
/* data-i18n attribute value */
`[content]toolbar.${enabled ? 'videomute' : 'cameraDisabled'}`,
/* shortcut attribute value */
'toggleVideoPopover');
enabled || this.toggleVideoIcon(!enabled);
},
/**
* Enables/disables the toolbar button associated with a specific media such
* as audio or video.
*
* @param {string} btn - The jQuery selector <tt>string</tt> which
* identifies the toolbar button to be enabled/disabled.
* @param {boolean} enabled - <tt>true</tt> to enable the specified
* <tt>btn</tt> or <tt>false</tt> to disable it.
* @param {string} dataI18n - The value to assign to the <tt>data-i18n</tt>
* attribute of the specified <tt>btn</tt>.
* @param {string} shortcut - The value, if any, to assign to the
* <tt>shortcut</tt> attribute of the specified <tt>btn</tt> if the toolbar
* button is enabled.
*/
_setMediaIconEnabled(btn, enabled, dataI18n, shortcut) {
const $btn = $(btn);
$btn
2016-10-07 20:31:00 +00:00
.prop('disabled', !enabled)
.attr('data-i18n', dataI18n)
.attr('shortcut', enabled && shortcut ? shortcut : '');
enabled
2016-10-07 20:31:00 +00:00
? $btn.removeAttr('disabled')
: $btn.attr('disabled', 'disabled');
APP.translation.translateElement($btn);
},
/**
* Marks audio icon as muted or not.
*
* @param {boolean} muted if icon should look like muted or not
*/
toggleAudioIcon(muted) {
2016-10-07 20:31:00 +00:00
$('#toolbar_button_mute')
.toggleClass("icon-microphone", !muted)
.toggleClass("icon-mic-disabled", muted);
this._setToggledState("toolbar_button_mute", muted);
},
/**
* Enables / disables audio toolbar button.
*
* @param {boolean} enabled indicates if the button should be enabled
* or disabled
*/
setAudioIconEnabled (enabled) {
2016-10-07 20:31:00 +00:00
this._setMediaIconEnabled(
'#toolbar_button_mute',
enabled,
/* data-i18n attribute value */
`[content]toolbar.${enabled ? 'mute' : 'micDisabled'}`,
/* shortcut attribute value */
'mutePopover');
enabled || this.toggleAudioIcon(!enabled);
},
/**
* Indicates if the toolbar is currently hovered.
* @return {boolean} true if the toolbar is currently hovered,
* false otherwise
*/
isHovered() {
var hovered = false;
this.toolbarSelector.find('*').each(function () {
let id = $(this).attr('id');
if ($(`#${id}:hover`).length > 0) {
hovered = true;
// break each
return false;
}
});
if (hovered)
return true;
if ($("#bottomToolbar:hover").length > 0
|| $("#extendedToolbar:hover").length > 0
2016-09-10 02:26:29 +00:00
|| SideContainerToggler.isHovered()) {
return true;
}
return false;
},
/**
* Returns true if this toolbar is currently visible, or false otherwise.
* @return <tt>true</tt> if currently visible, <tt>false</tt> - otherwise
*/
isVisible() {
return this.toolbarSelector.hasClass("slideInY");
},
/**
* Hides the toolbar with animation or not depending on the animate
* parameter.
*/
hide() {
this.toolbarSelector.toggleClass("slideInY").toggleClass("slideOutY");
2016-09-10 02:26:29 +00:00
let slideInAnimation = (SideContainerToggler.isVisible)
? "slideInExtX"
: "slideInX";
let slideOutAnimation = (SideContainerToggler.isVisible)
? "slideOutExtX"
: "slideOutX";
this.extendedToolbarSelector.toggleClass(slideInAnimation)
.toggleClass(slideOutAnimation);
},
/**
* Shows the toolbar with animation or not depending on the animate
* parameter.
*/
show() {
if (this.toolbarSelector.hasClass("slideOutY"))
this.toolbarSelector.toggleClass("slideOutY");
2016-09-10 02:26:29 +00:00
let slideInAnimation = (SideContainerToggler.isVisible)
? "slideInExtX"
: "slideInX";
let slideOutAnimation = (SideContainerToggler.isVisible)
? "slideOutExtX"
: "slideOutX";
if (this.extendedToolbarSelector.hasClass(slideOutAnimation))
this.extendedToolbarSelector.toggleClass(slideOutAnimation);
this.toolbarSelector.toggleClass("slideInY");
2016-09-10 02:26:29 +00:00
this.extendedToolbarSelector.toggleClass(slideInAnimation);
},
registerClickListeners(listener) {
$('#mainToolbarContainer').click(listener);
$("#extendedToolbar").click(listener);
},
/**
2016-09-10 02:26:29 +00:00
* Handles the side toolbar toggle.
2016-10-13 20:09:18 +00:00
*
* @param {string} containerId the identifier of the container element
*/
_handleSideToolbarContainerToggled(containerId) {
Object.keys(defaultToolbarButtons).forEach(
id => {
if (!UIUtil.isButtonEnabled(id))
return;
var button = defaultToolbarButtons[id];
if (button.sideContainerId
&& button.sideContainerId === containerId) {
UIUtil.buttonClick(button.id, "selected");
2016-09-11 21:54:32 +00:00
return;
}
}
);
2016-09-11 21:54:32 +00:00
},
2016-10-13 20:09:18 +00:00
/**
* Handles full screen toggled.
*
* @param {boolean} isFullScreen indicates if we're currently in full
* screen mode
*/
_handleFullScreenToggled(isFullScreen) {
let element
= document.getElementById("toolbar_button_fullScreen");
element.className = isFullScreen
? element.className
.replace("icon-full-screen", "icon-exit-full-screen")
: element.className
.replace("icon-exit-full-screen", "icon-full-screen");
Toolbar._setToggledState("toolbar_button_fullScreen", isFullScreen);
},
2016-09-11 21:54:32 +00:00
/**
* Initialise main toolbar buttons.
2016-09-11 21:54:32 +00:00
*/
_initMainToolbarButtons() {
interfaceConfig.MAIN_TOOLBAR_BUTTONS.forEach((value, index) => {
if (value && value in defaultToolbarButtons) {
let button = defaultToolbarButtons[value];
this._addMainToolbarButton(
button,
(index === 0),
2016-10-14 20:27:08 +00:00
(index === interfaceConfig.MAIN_TOOLBAR_BUTTONS.length -1),
2016-10-17 20:59:35 +00:00
(interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX !== undefined
2016-10-14 20:27:08 +00:00
&& index
=== interfaceConfig.MAIN_TOOLBAR_SPLITTER_INDEX));
2016-09-11 21:54:32 +00:00
}
});
},
/**
* Adds the given button to the main (top) toolbar.
*
* @param {Object} the button to add.
* @param {boolean} isFirst indicates if this is the first button in the
* toolbar
* @param {boolean} isLast indicates if this is the last button in the
* toolbar
2016-10-14 20:27:08 +00:00
* @param {boolean} isSplitter if this button is a splitter button for
* the dialog, which means that a special splitter style will be applied
*/
2016-10-14 20:27:08 +00:00
_addMainToolbarButton(button, isFirst, isLast, isSplitter) {
2016-09-11 21:54:32 +00:00
let buttonElement = document.createElement("a");
if (button.className)
buttonElement.className = button.className
+ ((isFirst) ? " first" : "")
2016-10-14 20:27:08 +00:00
+ ((isLast) ? " last" : "")
+ ((isSplitter) ? " splitter": "");
2016-09-11 21:54:32 +00:00
buttonElement.id = button.id;
if (button.shortcutAttr)
buttonElement.setAttribute("shortcut", button.shortcutAttr);
if (button.content)
buttonElement.setAttribute("content", button.content);
if (button.i18n)
buttonElement.setAttribute("data-i18n", button.i18n);
buttonElement.setAttribute("data-container", "body");
buttonElement.setAttribute("data-placement", "bottom");
2016-09-12 19:43:34 +00:00
this._addPopups(buttonElement, button.popups);
2016-09-11 21:54:32 +00:00
document.getElementById("mainToolbar")
.appendChild(buttonElement);
2016-09-12 19:43:34 +00:00
},
_addPopups(buttonElement, popups = []) {
popups.forEach((popup) => {
let popupElement = document.createElement("ul");
popupElement.id = popup.id;
popupElement.className = popup.className;
let liElement = document.createElement("li");
liElement.setAttribute("data-i18n", popup.dataAttr);
popupElement.appendChild(liElement);
buttonElement.appendChild(popupElement);
});
},
/**
* Sets the toggled state of the given element depending on the isToggled
* parameter.
*
* @param elementId the element identifier
* @param isToggled indicates if the element should be toggled or untoggled
*/
_setToggledState(elementId, isToggled) {
$("#" + elementId).toggleClass("toggled", isToggled);
2015-12-09 17:10:49 +00:00
}
};
2015-01-07 14:54:03 +00:00
export default Toolbar;