OpenSlides/openslides/projector/static/javascript/projector.js

96 lines
2.8 KiB
JavaScript
Raw Normal View History

/**
* OpenSlides projector functions
*
* :copyright: 20112013 by OpenSlides team, see AUTHORS.
* :license: GNU GPL, see LICENSE for more details.
*/
$(document).ready(function() {
if ($('#content.reload').length > 0) {
updater.start();
}
});
var projector = {
_loaded_files: {},
load_file: function(src) {
if (projector._loaded_files[src] === undefined) {
projector._loaded_files[src] = document.createElement('script');
projector._loaded_files[src].setAttribute("type","text/javascript");
projector._loaded_files[src].setAttribute("src", src);
$('head').append(projector._loaded_files[src]);
}
},
scroll: function(value) {
$('#content').css('margin-top', -10 * value + 'em');
},
scale: function(value) {
$('#content').css('font-size', 100 + 20 * value + '%');
},
get_server_time: function () {
var date = new Date();
date.setTime(date.getTime() + projector.server_time_offset);
return date;
},
update_data: function(data) {
$.each(data, function (key, value) {
if (key === 'load_file')
projector.load_file(value);
else if (key === 'server_time') {
var local_time = Date.parse(new Date().toUTCString());
projector.server_time_offset = local_time - value * 1000;
} else
projector[key] = value;
2011-07-31 10:46:29 +02:00
});
}
};
2011-07-31 10:46:29 +02:00
var updater = {
socket: null,
2011-07-31 10:46:29 +02:00
start: function() {
2013-10-26 10:42:48 +02:00
var url = "http://" + location.host + "/projector/socket";
updater.socket = new SockJS(url);
updater.socket.onmessage = function(event) {
2013-10-26 10:42:48 +02:00
updater.updateProjector(event.data);
}
updater.socket.onclose = function() {
setTimeout('updater.start()', 5000);
}
},
updateProjector: function(data) {
if (data.content) {
$('#content').removeClass('fullscreen');
$('#footer').removeClass('black');
$('body').removeClass('black');
$('#content').html(data.content);
}
if (data.overlays) {
$.each(data.overlays, function (key, value) {
var overlay = $('#overlays #overlay_' + key)
if (!value)
overlay.remove();
else {
if (overlay.length) {
overlay.html(value.html)
} else {
$('#overlays').append(value.html);
}
projector.update_data(value.javascript);
}
});
}
if (data.calls) {
$.each(data.calls, function (call, argument) {
projector[call](argument);
});
}
}
};