2015-08-28 21:13:40 +00:00
|
|
|
/* global $, config, interfaceConfig */
|
2015-06-18 16:59:41 +00:00
|
|
|
/**
|
2015-01-07 14:54:03 +00:00
|
|
|
* Created by hristo on 12/22/14.
|
|
|
|
*/
|
2015-08-28 21:13:40 +00:00
|
|
|
var UIUtil = module.exports = {
|
2015-01-07 14:54:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the available video width.
|
|
|
|
*/
|
2015-06-23 08:00:46 +00:00
|
|
|
getAvailableVideoWidth: function (isVisible) {
|
2015-01-07 14:54:03 +00:00
|
|
|
var PanelToggler = require("../side_pannels/SidePanelToggler");
|
2015-06-23 08:00:46 +00:00
|
|
|
if(typeof isVisible === "undefined" || isVisible === null)
|
|
|
|
isVisible = PanelToggler.isVisible();
|
2015-01-07 14:54:03 +00:00
|
|
|
var rightPanelWidth
|
2015-06-23 08:00:46 +00:00
|
|
|
= isVisible ? PanelToggler.getPanelSize()[0] : 0;
|
2015-01-07 14:54:03 +00:00
|
|
|
|
|
|
|
return window.innerWidth - rightPanelWidth;
|
2015-01-19 09:20:00 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Changes the style class of the element given by id.
|
|
|
|
*/
|
|
|
|
buttonClick: function(id, classname) {
|
|
|
|
$(id).toggleClass(classname); // add the class to the clicked element
|
2015-01-23 12:01:44 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns the text width for the given element.
|
|
|
|
*
|
|
|
|
* @param el the element
|
|
|
|
*/
|
|
|
|
getTextWidth: function (el) {
|
|
|
|
return (el.clientWidth + 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the text height for the given element.
|
|
|
|
*
|
|
|
|
* @param el the element
|
|
|
|
*/
|
|
|
|
getTextHeight: function (el) {
|
|
|
|
return (el.clientHeight + 1);
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plays the sound given by id.
|
|
|
|
*
|
|
|
|
* @param id the identifier of the audio element.
|
|
|
|
*/
|
|
|
|
playSoundNotification: function (id) {
|
|
|
|
document.getElementById(id).play();
|
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Escapes the given text.
|
|
|
|
*/
|
|
|
|
escapeHtml: function (unsafeText) {
|
|
|
|
return $('<div/>').text(unsafeText).html();
|
|
|
|
},
|
|
|
|
|
|
|
|
imageToGrayScale: function (canvas) {
|
|
|
|
var context = canvas.getContext('2d');
|
|
|
|
var imgData = context.getImageData(0, 0, canvas.width, canvas.height);
|
|
|
|
var pixels = imgData.data;
|
|
|
|
|
|
|
|
for (var i = 0, n = pixels.length; i < n; i += 4) {
|
|
|
|
var grayscale
|
2015-07-28 21:52:32 +00:00
|
|
|
= pixels[i] * 0.3 + pixels[i+1] * 0.59 + pixels[i+2] * 0.11;
|
2015-01-23 12:01:44 +00:00
|
|
|
pixels[i ] = grayscale; // red
|
|
|
|
pixels[i+1] = grayscale; // green
|
|
|
|
pixels[i+2] = grayscale; // blue
|
|
|
|
// pixels[i+3] is alpha
|
|
|
|
}
|
|
|
|
// redraw the image in black & white
|
|
|
|
context.putImageData(imgData, 0, 0);
|
|
|
|
},
|
|
|
|
|
2015-02-06 15:46:50 +00:00
|
|
|
setTooltip: function (element, key, position) {
|
|
|
|
element.setAttribute("data-i18n", "[data-content]" + key);
|
2015-01-23 12:01:44 +00:00
|
|
|
element.setAttribute("data-toggle", "popover");
|
|
|
|
element.setAttribute("data-placement", position);
|
|
|
|
element.setAttribute("data-html", true);
|
|
|
|
element.setAttribute("data-container", "body");
|
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
|
|
|
|
*/
|
|
|
|
prependChild: function (container, newChild) {
|
|
|
|
var firstChild = container.childNodes[0];
|
|
|
|
if (firstChild) {
|
|
|
|
container.insertBefore(newChild, firstChild);
|
|
|
|
} else {
|
|
|
|
container.appendChild(newChild);
|
|
|
|
}
|
2015-08-28 21:13:40 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
isButtonEnabled: function (name) {
|
|
|
|
var isEnabled = interfaceConfig.TOOLBAR_BUTTONS.indexOf(name) !== -1;
|
|
|
|
if (name === 'prezi') {
|
|
|
|
return isEnabled && !config.disablePrezi;
|
|
|
|
} else if (name === 'recording') {
|
|
|
|
return isEnabled && config.enableRecording;
|
|
|
|
}
|
|
|
|
return isEnabled;
|
|
|
|
},
|
|
|
|
|
|
|
|
hideDisabledButtons: function (mappings) {
|
|
|
|
var selector = Object.keys(mappings)
|
2015-09-14 14:25:43 +00:00
|
|
|
.map(function (buttonName) {
|
|
|
|
return UIUtil.isButtonEnabled(buttonName)
|
|
|
|
? null : mappings[buttonName]; })
|
2015-08-28 21:13:40 +00:00
|
|
|
.filter(function (item) { return item; })
|
|
|
|
.join(',');
|
|
|
|
$(selector).hide();
|
2015-01-07 14:54:03 +00:00
|
|
|
}
|
|
|
|
};
|