2017-07-26 21:00:10 +00:00
|
|
|
/* global $, interfaceConfig */
|
2016-09-28 14:22:03 +00:00
|
|
|
|
2016-11-04 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Associates the default display type with corresponding CSS class
|
|
|
|
*/
|
|
|
|
const SHOW_CLASSES = {
|
|
|
|
'block': 'show',
|
|
|
|
'inline': 'show-inline',
|
|
|
|
'list-item': 'show-list-item'
|
|
|
|
};
|
|
|
|
|
2016-11-14 10:45:28 +00:00
|
|
|
/**
|
|
|
|
* Contains sizes of thumbnails
|
|
|
|
* @type {{SMALL: number, MEDIUM: number}}
|
|
|
|
*/
|
|
|
|
const ThumbnailSizes = {
|
|
|
|
SMALL: 60,
|
|
|
|
MEDIUM: 80
|
|
|
|
};
|
|
|
|
|
2015-06-18 16:59:41 +00:00
|
|
|
/**
|
2015-01-07 14:54:03 +00:00
|
|
|
* Created by hristo on 12/22/14.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
const UIUtil = {
|
2015-12-25 16:55:45 +00:00
|
|
|
|
2015-01-07 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the available video width.
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
getAvailableVideoWidth() {
|
2016-11-04 16:13:57 +00:00
|
|
|
return window.innerWidth;
|
2015-01-19 09:20:00 +00:00
|
|
|
},
|
2016-02-24 21:05:24 +00:00
|
|
|
|
2015-01-19 09:20:00 +00:00
|
|
|
/**
|
|
|
|
* Changes the style class of the element given by id.
|
|
|
|
*/
|
2017-10-12 23:02:29 +00:00
|
|
|
buttonClick(id, classname) {
|
2016-09-11 21:54:32 +00:00
|
|
|
// add the class to the clicked element
|
2017-10-12 23:02:29 +00:00
|
|
|
$(`#${id}`).toggleClass(classname);
|
2015-01-23 12:01:44 +00:00
|
|
|
},
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2015-01-23 12:01:44 +00:00
|
|
|
/**
|
|
|
|
* Returns the text width for the given element.
|
|
|
|
*
|
|
|
|
* @param el the element
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
getTextWidth(el) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return el.clientWidth + 1;
|
2015-01-23 12:01:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the text height for the given element.
|
|
|
|
*
|
|
|
|
* @param el the element
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
getTextHeight(el) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return el.clientHeight + 1;
|
2015-01-23 12:01:44 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes the given text.
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
escapeHtml(unsafeText) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return $('<div/>').text(unsafeText)
|
|
|
|
.html();
|
2015-01-23 12:01:44 +00:00
|
|
|
},
|
|
|
|
|
2017-02-05 03:56:25 +00:00
|
|
|
imageToGrayScale(canvas) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
const imgData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
|
|
const pixels = imgData.data;
|
|
|
|
|
|
|
|
for (let i = 0, n = pixels.length; i < n; i += 4) {
|
|
|
|
const grayscale
|
|
|
|
= (pixels[i] * 0.3)
|
|
|
|
+ (pixels[i + 1] * 0.59)
|
|
|
|
+ (pixels[i + 2] * 0.11);
|
|
|
|
|
|
|
|
pixels[i] = grayscale; // red
|
|
|
|
pixels[i + 1] = grayscale; // green
|
|
|
|
pixels[i + 2] = grayscale; // blue
|
2015-01-23 12:01:44 +00:00
|
|
|
// pixels[i+3] is alpha
|
|
|
|
}
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2015-01-23 12:01:44 +00:00
|
|
|
// redraw the image in black & white
|
|
|
|
context.putImageData(imgData, 0, 0);
|
|
|
|
},
|
|
|
|
|
2015-08-12 10:13:30 +00:00
|
|
|
/**
|
|
|
|
* Inserts given child element as the first one into the container.
|
|
|
|
* @param container the container to which new child element will be added
|
|
|
|
* @param newChild the new element that will be inserted into the container
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
prependChild(container, newChild) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const firstChild = container.childNodes[0];
|
|
|
|
|
2015-08-12 10:13:30 +00:00
|
|
|
if (firstChild) {
|
|
|
|
container.insertBefore(newChild, firstChild);
|
|
|
|
} else {
|
|
|
|
container.appendChild(newChild);
|
|
|
|
}
|
2015-08-28 21:13:40 +00:00
|
|
|
},
|
|
|
|
|
2016-10-12 12:33:07 +00:00
|
|
|
/**
|
|
|
|
* Indicates if Authentication Section should be shown
|
|
|
|
*
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
isAuthenticationEnabled() {
|
2016-10-12 12:33:07 +00:00
|
|
|
return interfaceConfig.AUTHENTICATION_ENABLE;
|
|
|
|
},
|
|
|
|
|
2016-09-13 22:37:09 +00:00
|
|
|
/**
|
2016-11-29 21:07:18 +00:00
|
|
|
* Shows / hides the element given by id.
|
2016-09-13 22:37:09 +00:00
|
|
|
*
|
2016-11-29 21:07:18 +00:00
|
|
|
* @param {string|HTMLElement} idOrElement the identifier or the element
|
|
|
|
* to show/hide
|
|
|
|
* @param {boolean} show <tt>true</tt> to show or <tt>false</tt> to hide
|
2016-09-13 22:37:09 +00:00
|
|
|
*/
|
2016-11-29 21:07:18 +00:00
|
|
|
setVisible(id, visible) {
|
2016-11-04 14:48:52 +00:00
|
|
|
let element;
|
2017-10-12 23:02:29 +00:00
|
|
|
|
2016-11-04 14:48:52 +00:00
|
|
|
if (id instanceof HTMLElement) {
|
|
|
|
element = id;
|
|
|
|
} else {
|
|
|
|
element = document.getElementById(id);
|
|
|
|
}
|
2016-09-14 00:44:47 +00:00
|
|
|
|
2016-11-04 10:40:21 +00:00
|
|
|
if (!element) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (!visible) {
|
2016-11-29 21:07:18 +00:00
|
|
|
element.classList.add('hide');
|
2017-10-12 23:02:29 +00:00
|
|
|
} else if (element.classList.contains('hide')) {
|
2016-11-04 10:40:21 +00:00
|
|
|
element.classList.remove('hide');
|
|
|
|
}
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
const type = this._getElementDefaultDisplay(element.tagName);
|
|
|
|
const className = SHOW_CLASSES[type];
|
2016-11-04 10:40:21 +00:00
|
|
|
|
2016-11-29 21:07:18 +00:00
|
|
|
if (visible) {
|
|
|
|
element.classList.add(className);
|
2017-10-12 23:02:29 +00:00
|
|
|
} else if (element.classList.contains(className)) {
|
2016-11-04 13:58:43 +00:00
|
|
|
element.classList.remove(className);
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
2016-09-13 22:37:09 +00:00
|
|
|
},
|
2015-08-28 21:13:40 +00:00
|
|
|
|
2016-11-04 13:58:43 +00:00
|
|
|
/**
|
|
|
|
* Returns default display style for the tag
|
|
|
|
* @param tag
|
|
|
|
* @returns {*}
|
2016-11-11 10:27:29 +00:00
|
|
|
* @private
|
2016-11-04 13:58:43 +00:00
|
|
|
*/
|
2016-11-11 10:27:29 +00:00
|
|
|
_getElementDefaultDisplay(tag) {
|
2017-10-12 23:02:29 +00:00
|
|
|
const tempElement = document.createElement(tag);
|
2016-11-04 13:58:43 +00:00
|
|
|
|
|
|
|
document.body.appendChild(tempElement);
|
2017-10-12 23:02:29 +00:00
|
|
|
const style = window.getComputedStyle(tempElement).display;
|
|
|
|
|
2016-11-04 13:58:43 +00:00
|
|
|
document.body.removeChild(tempElement);
|
2016-09-14 00:44:47 +00:00
|
|
|
|
2016-11-04 13:58:43 +00:00
|
|
|
return style;
|
2016-09-13 22:37:09 +00:00
|
|
|
},
|
2015-08-28 21:13:40 +00:00
|
|
|
|
2016-10-20 19:28:10 +00:00
|
|
|
/**
|
|
|
|
* Shows / hides the element with the given jQuery selector.
|
|
|
|
*
|
2016-11-29 21:07:18 +00:00
|
|
|
* @param {jQuery} jquerySelector the jQuery selector of the element to
|
|
|
|
* show / shide
|
2016-10-20 19:28:10 +00:00
|
|
|
* @param {boolean} isVisible
|
|
|
|
*/
|
2016-11-29 21:07:18 +00:00
|
|
|
setVisibleBySelector(jquerySelector, isVisible) {
|
|
|
|
if (jquerySelector && jquerySelector.length > 0) {
|
2017-10-12 23:02:29 +00:00
|
|
|
jquerySelector.css('visibility', isVisible ? 'visible' : 'hidden');
|
2016-10-20 19:28:10 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-02-26 22:50:27 +00:00
|
|
|
/**
|
|
|
|
* Redirects to a given URL.
|
|
|
|
*
|
|
|
|
* @param {string} url - The redirect URL.
|
|
|
|
* NOTE: Currently used to redirect to 3rd party location for
|
|
|
|
* authentication. In most cases redirectWithStoredParams action must be
|
|
|
|
* used instead of this method in order to preserve curent URL params.
|
|
|
|
*/
|
2017-02-05 03:56:25 +00:00
|
|
|
redirect(url) {
|
2017-10-02 23:08:07 +00:00
|
|
|
window.location.href = url;
|
2016-09-13 04:10:18 +00:00
|
|
|
},
|
2015-12-25 16:55:45 +00:00
|
|
|
|
2016-10-13 22:28:24 +00:00
|
|
|
/**
|
|
|
|
* Indicates if we're currently in full screen mode.
|
|
|
|
*
|
|
|
|
* @return {boolean} {true} to indicate that we're currently in full screen
|
|
|
|
* mode, {false} otherwise
|
|
|
|
*/
|
|
|
|
isFullScreen() {
|
2018-03-07 00:28:19 +00:00
|
|
|
return Boolean(document.fullscreenElement
|
2016-10-13 22:28:24 +00:00
|
|
|
|| document.mozFullScreenElement
|
|
|
|
|| document.webkitFullscreenElement
|
2018-03-07 00:28:19 +00:00
|
|
|
|| document.msFullscreenElement);
|
2016-10-13 22:28:24 +00:00
|
|
|
},
|
2016-02-09 10:19:43 +00:00
|
|
|
|
2016-10-13 22:28:24 +00:00
|
|
|
/**
|
2016-02-09 10:19:43 +00:00
|
|
|
* Create html attributes string out of object properties.
|
|
|
|
* @param {Object} attrs object with properties
|
|
|
|
* @returns {String} string of html element attributes
|
|
|
|
*/
|
2017-10-02 23:08:07 +00:00
|
|
|
attrsToString(attrs) {
|
|
|
|
return (
|
2017-10-12 23:02:29 +00:00
|
|
|
Object.keys(attrs).map(key => ` ${key}="${attrs[key]}"`)
|
|
|
|
.join(' '));
|
2017-10-02 23:08:07 +00:00
|
|
|
},
|
2016-04-08 15:55:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if the given DOM element is currently visible. The offsetParent
|
|
|
|
* will be null if the "display" property of the element or any of its
|
|
|
|
* parent containers is set to "none". This method will NOT check the
|
|
|
|
* visibility property though.
|
|
|
|
* @param {el} The DOM element we'd like to check for visibility
|
|
|
|
*/
|
|
|
|
isVisible(el) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return el.offsetParent !== null;
|
2016-04-19 18:07:04 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Shows / hides the element given by {selector} and sets a timeout if the
|
|
|
|
* {hideDelay} is set to a value > 0.
|
|
|
|
* @param selector the jquery selector of the element to show/hide.
|
|
|
|
* @param show a {boolean} that indicates if the element should be shown or
|
|
|
|
* hidden
|
|
|
|
* @param hideDelay the value in milliseconds to wait before hiding the
|
|
|
|
* element
|
|
|
|
*/
|
|
|
|
animateShowElement(selector, show, hideDelay) {
|
2017-10-12 23:02:29 +00:00
|
|
|
if (show) {
|
|
|
|
if (!selector.is(':visible')) {
|
|
|
|
selector.css('display', 'inline-block');
|
|
|
|
}
|
2016-04-19 18:07:04 +00:00
|
|
|
|
|
|
|
selector.fadeIn(300,
|
2017-10-12 23:02:29 +00:00
|
|
|
() => {
|
|
|
|
selector.css({ opacity: 1 });
|
|
|
|
}
|
2016-04-19 18:07:04 +00:00
|
|
|
);
|
|
|
|
|
2017-10-12 23:02:29 +00:00
|
|
|
if (hideDelay && hideDelay > 0) {
|
2016-04-19 18:07:04 +00:00
|
|
|
setTimeout(
|
2017-10-02 23:08:07 +00:00
|
|
|
() => {
|
|
|
|
selector.fadeOut(
|
|
|
|
300,
|
2017-10-12 23:02:29 +00:00
|
|
|
() => {
|
|
|
|
selector.css({ opacity: 0 });
|
|
|
|
});
|
2017-10-02 23:08:07 +00:00
|
|
|
},
|
|
|
|
hideDelay);
|
2017-10-12 23:02:29 +00:00
|
|
|
}
|
|
|
|
} else {
|
2016-04-19 18:07:04 +00:00
|
|
|
selector.fadeOut(300,
|
2017-10-12 23:02:29 +00:00
|
|
|
() => {
|
|
|
|
selector.css({ opacity: 0 });
|
|
|
|
}
|
2016-04-19 18:07:04 +00:00
|
|
|
);
|
|
|
|
}
|
2016-05-01 18:35:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Parses the given cssValue as an Integer. If the value is not a number
|
|
|
|
* we return 0 instead of NaN.
|
|
|
|
* @param cssValue the string value we obtain when querying css properties
|
|
|
|
*/
|
|
|
|
parseCssInt(cssValue) {
|
2017-10-12 23:02:29 +00:00
|
|
|
return parseInt(cssValue, 10) || 0;
|
2016-09-16 19:05:39 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds href value to 'a' link jquery object. If link value is null,
|
|
|
|
* undefined or empty string, disables the link.
|
|
|
|
* @param {object} aLinkElement the jquery object
|
|
|
|
* @param {string} link the link value
|
|
|
|
*/
|
|
|
|
setLinkHref(aLinkElement, link) {
|
|
|
|
if (link) {
|
|
|
|
aLinkElement.attr('href', link);
|
|
|
|
} else {
|
|
|
|
aLinkElement.css({
|
2017-10-12 23:02:29 +00:00
|
|
|
'pointer-events': 'none',
|
|
|
|
'cursor': 'default'
|
2016-09-16 19:05:39 +00:00
|
|
|
});
|
|
|
|
}
|
2016-10-26 03:05:32 +00:00
|
|
|
},
|
|
|
|
|
2016-11-14 10:45:28 +00:00
|
|
|
/**
|
|
|
|
* Returns font size for indicators according to current
|
|
|
|
* height of thumbnail
|
2017-07-10 22:29:44 +00:00
|
|
|
* @param {Number} [thumbnailHeight] - current height of thumbnail
|
2016-11-14 10:45:28 +00:00
|
|
|
* @returns {Number} - font size for current height
|
|
|
|
*/
|
2017-07-10 22:29:44 +00:00
|
|
|
getIndicatorFontSize(thumbnailHeight) {
|
|
|
|
const height = typeof thumbnailHeight === 'undefined'
|
|
|
|
? $('#localVideoContainer').height() : thumbnailHeight;
|
|
|
|
|
2016-11-14 10:45:28 +00:00
|
|
|
const { SMALL, MEDIUM } = ThumbnailSizes;
|
2019-02-21 17:10:22 +00:00
|
|
|
const IndicatorFontSizes = interfaceConfig.INDICATOR_FONT_SIZES || {
|
|
|
|
SMALL: 5,
|
|
|
|
MEDIUM: 6,
|
|
|
|
NORMAL: 8
|
|
|
|
};
|
2016-11-14 10:45:28 +00:00
|
|
|
let fontSize = IndicatorFontSizes.NORMAL;
|
|
|
|
|
|
|
|
if (height <= SMALL) {
|
|
|
|
fontSize = IndicatorFontSizes.SMALL;
|
|
|
|
} else if (height > SMALL && height <= MEDIUM) {
|
|
|
|
fontSize = IndicatorFontSizes.MEDIUM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return fontSize;
|
2016-04-08 15:55:19 +00:00
|
|
|
}
|
2015-12-11 14:48:16 +00:00
|
|
|
};
|
2015-12-14 12:26:50 +00:00
|
|
|
|
|
|
|
export default UIUtil;
|