2020-01-24 16:28:47 +00:00
|
|
|
/* global $ */
|
2016-11-14 12:45:28 +02:00
|
|
|
|
2015-06-18 18:59:41 +02:00
|
|
|
/**
|
2015-01-07 16:54:03 +02:00
|
|
|
* Created by hristo on 12/22/14.
|
|
|
|
|
*/
|
2017-10-12 18:02:29 -05:00
|
|
|
const UIUtil = {
|
2015-12-25 18:55:45 +02:00
|
|
|
|
2015-01-23 14:01:44 +02:00
|
|
|
/**
|
|
|
|
|
* Escapes the given text.
|
|
|
|
|
*/
|
2017-02-04 21:56:25 -06:00
|
|
|
escapeHtml(unsafeText) {
|
2017-10-12 18:02:29 -05:00
|
|
|
return $('<div/>').text(unsafeText)
|
|
|
|
|
.html();
|
2015-01-23 14:01:44 +02:00
|
|
|
},
|
|
|
|
|
|
2015-08-12 12:13:30 +02: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-04 21:56:25 -06:00
|
|
|
prependChild(container, newChild) {
|
2017-10-12 18:02:29 -05:00
|
|
|
const firstChild = container.childNodes[0];
|
2020-04-16 20:15:07 -05:00
|
|
|
let result;
|
2017-10-12 18:02:29 -05:00
|
|
|
|
2015-08-12 12:13:30 +02:00
|
|
|
if (firstChild) {
|
2020-04-16 20:15:07 -05:00
|
|
|
result = container.insertBefore(newChild, firstChild);
|
2015-08-12 12:13:30 +02:00
|
|
|
} else {
|
2020-04-16 20:15:07 -05:00
|
|
|
result = container.appendChild(newChild);
|
2015-08-12 12:13:30 +02:00
|
|
|
}
|
2020-04-16 20:15:07 -05:00
|
|
|
|
|
|
|
|
return result;
|
2015-08-28 16:13:40 -05:00
|
|
|
},
|
|
|
|
|
|
2018-02-26 16:50:27 -06: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-04 21:56:25 -06:00
|
|
|
redirect(url) {
|
2017-10-02 18:08:07 -05:00
|
|
|
window.location.href = url;
|
2016-09-12 23:10:18 -05:00
|
|
|
},
|
2015-12-25 18:55:45 +02:00
|
|
|
|
2016-10-13 17:28:24 -05: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-06 16:28:19 -08:00
|
|
|
return Boolean(document.fullscreenElement
|
2016-10-13 17:28:24 -05:00
|
|
|
|| document.mozFullScreenElement
|
|
|
|
|
|| document.webkitFullscreenElement
|
2018-03-06 16:28:19 -08:00
|
|
|
|| document.msFullscreenElement);
|
2016-10-13 17:28:24 -05:00
|
|
|
},
|
2016-02-09 12:19:43 +02:00
|
|
|
|
2016-04-08 10:55:19 -05: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 18:02:29 -05:00
|
|
|
return el.offsetParent !== null;
|
2016-04-08 10:55:19 -05:00
|
|
|
}
|
2015-12-11 16:48:16 +02:00
|
|
|
};
|
2015-12-14 14:26:50 +02:00
|
|
|
|
|
|
|
|
export default UIUtil;
|