2013-02-12 13:09:46 +00:00
|
|
|
window.addEventListener('message', function(event) {
|
2013-02-12 13:22:04 +00:00
|
|
|
if (event.origin != 'null' && event.data) {
|
2013-02-12 13:09:46 +00:00
|
|
|
var data = JSON.parse(event.data);
|
2013-02-12 13:22:04 +00:00
|
|
|
if (data.event == 'close') {
|
2013-02-12 13:09:46 +00:00
|
|
|
var e = document.getElementById(data.id);
|
|
|
|
Array.prototype.forEach.call(e.parentElement.getElementsByClassName('button'), function(e) {
|
|
|
|
e.style.display = 'block';
|
|
|
|
});
|
|
|
|
e.parentElement.removeChild(e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-02-12 13:30:58 +00:00
|
|
|
function getEmbedURL(id, videoURL) {
|
|
|
|
var parsed = Ox.parseURL(videoURL),
|
|
|
|
parts = parsed.pathname.split('/'),
|
|
|
|
item = parts[1],
|
|
|
|
points = parts[parts.length - 1].split(','),
|
|
|
|
outPoint = points.pop(),
|
|
|
|
inPoint = points.pop();
|
|
|
|
return parsed.origin + '/' + item + '/embed?view=player&id=' + id
|
2013-02-12 13:33:36 +00:00
|
|
|
+ '&in=' + inPoint + '&out=' + outPoint
|
|
|
|
+ '&paused=false&showCloseButton=true';
|
2013-02-12 13:09:46 +00:00
|
|
|
}
|
|
|
|
|
2013-02-12 07:09:52 +00:00
|
|
|
function getVideoOverlay(page) {
|
2013-02-12 11:20:07 +00:00
|
|
|
return (editable || videoOverlay[page]) ? {
|
2013-02-12 07:09:52 +00:00
|
|
|
beginLayout: function() {
|
2013-02-12 10:38:01 +00:00
|
|
|
this.counter = 0;
|
|
|
|
//console.log('lets beging');
|
2013-02-12 07:09:52 +00:00
|
|
|
},
|
|
|
|
endLayout: function() {
|
2013-02-12 10:38:01 +00:00
|
|
|
//console.log('lets end it here');
|
2013-02-12 07:09:52 +00:00
|
|
|
},
|
|
|
|
appendImage: function(image) {
|
|
|
|
this.counter++;
|
|
|
|
var id = this.counter;
|
2013-02-12 11:20:07 +00:00
|
|
|
if (editable || videoOverlay[page][id]) {
|
2013-02-12 07:09:52 +00:00
|
|
|
var div = document.createElement('div');
|
2013-02-12 10:38:01 +00:00
|
|
|
div.style.left = image.left + 'px';
|
|
|
|
div.style.top = image.top + 'px';
|
|
|
|
div.style.width = image.width + 'px';
|
|
|
|
div.style.height = image.height + 'px';
|
2013-02-12 11:20:07 +00:00
|
|
|
if (videoOverlay[page] && videoOverlay[page][id]) {
|
2013-02-12 11:25:00 +00:00
|
|
|
div.className = 'interface video';
|
2013-02-12 11:28:29 +00:00
|
|
|
div.title = 'Click to play video';
|
2013-02-12 10:38:01 +00:00
|
|
|
div.onclick = function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2013-02-12 13:09:46 +00:00
|
|
|
var iframe = document.createElement('iframe');
|
|
|
|
iframe.width = '100%';
|
|
|
|
iframe.height = '100%';
|
2013-02-12 13:30:50 +00:00
|
|
|
iframe.setAttribute('frameborder', '0');
|
2013-02-12 13:09:46 +00:00
|
|
|
iframe.id = 'video' + page + id;
|
2013-02-12 13:31:21 +00:00
|
|
|
iframe.src = getEmbedURL(iframe.id, videoOverlay[page][id]);
|
2013-02-12 13:09:46 +00:00
|
|
|
div.appendChild(iframe);
|
|
|
|
Array.prototype.forEach.call(div.getElementsByClassName('button'), function(e) {
|
|
|
|
e.style.display = 'none';
|
|
|
|
});
|
2013-02-12 10:38:01 +00:00
|
|
|
return false;
|
|
|
|
};
|
|
|
|
var img = document.createElement('img');
|
|
|
|
img.className = 'button playButton';
|
2013-02-12 10:47:15 +00:00
|
|
|
img.src = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2Ij48cG9seWdvbiBwb2ludHM9IjU2LDMyIDI0OCwxMjggNTYsMjI0IiBmaWxsPSIjRkZGRkZGIi8+PC9zdmc+PCEtLXsiY29sb3IiOiJ2aWRlbyIsIm5hbWUiOiJzeW1ib2xQbGF5IiwidGhlbWUiOiJveGRhcmsifS0tPg==';
|
2013-02-12 10:38:01 +00:00
|
|
|
div.appendChild(img);
|
2013-02-12 11:25:00 +00:00
|
|
|
} else {
|
|
|
|
div.className = 'interface';
|
2013-02-12 11:21:59 +00:00
|
|
|
}
|
|
|
|
if (editable) {
|
2013-02-12 10:38:01 +00:00
|
|
|
var img = document.createElement('img');
|
|
|
|
img.className = 'button editButton';
|
2013-02-12 10:47:15 +00:00
|
|
|
img.src = 'data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyNTYiIGhlaWdodD0iMjU2Ij48cG9seWdvbiBwb2ludHM9IjMyLDIyNCA2NCwxNjAgOTYsMTkyIiBmaWxsPSIjRkZGRkZGIi8+PGxpbmUgeDE9Ijg4IiB5MT0iMTY4IiB4Mj0iMTg0IiB5Mj0iNzIiIHN0cm9rZT0iI0ZGRkZGRiIgc3Ryb2tlLXdpZHRoPSI0OCIvPjxsaW5lIHgxPSIxOTIiIHkxPSI2NCIgeDI9IjIwOCIgeTI9IjQ4IiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iNDgiLz48bGluZSB4MT0iMTEyIiB5MT0iMjIwIiB4Mj0iMjI0IiB5Mj0iMjIwIiBzdHJva2U9IiNGRkZGRkYiIHN0cm9rZS13aWR0aD0iOCIvPjxsaW5lIHgxPSIxMjgiIHkxPSIyMDQiIHgyPSIyMjQiIHkyPSIyMDQiIHN0cm9rZT0iI0ZGRkZGRiIgc3Ryb2tlLXdpZHRoPSI4Ii8+PGxpbmUgeDE9IjE0NCIgeTE9IjE4OCIgeDI9IjIyNCIgeTI9IjE4OCIgc3Ryb2tlPSIjRkZGRkZGIiBzdHJva2Utd2lkdGg9IjgiLz48L3N2Zz4=';
|
2013-02-12 11:28:29 +00:00
|
|
|
img.title = videoOverlay[page] && videoOverlay[page][id]
|
|
|
|
? 'Click to edit or remove video' : 'Click to add video';
|
2013-02-12 10:38:01 +00:00
|
|
|
img.onclick = function(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
event.stopPropagation();
|
2013-02-12 13:22:04 +00:00
|
|
|
if (!videoOverlay[page]) {
|
2013-02-12 13:09:46 +00:00
|
|
|
videoOverlay[page] = {}
|
|
|
|
}
|
2013-02-12 13:22:04 +00:00
|
|
|
if (!videoOverlay[page][id]) {
|
|
|
|
videoOverlay[page][id] = '';
|
2013-02-12 13:09:46 +00:00
|
|
|
}
|
2013-02-12 10:38:01 +00:00
|
|
|
console.log('EDIT');
|
2013-02-12 13:22:04 +00:00
|
|
|
var message = 'Please enter a pan.do/ra video URL, like\n'
|
|
|
|
+ 'http://pad.ma/A/editor/00:00:00,00:01:00,00:02:00'
|
|
|
|
+ (videoOverlay[page][id] ? '\n\nTo remove the video, just remove the URL.' : ''),
|
|
|
|
url = prompt(message, videoOverlay[page][id]);
|
2013-02-12 13:09:46 +00:00
|
|
|
if (url !== null) {
|
|
|
|
videoOverlay[page][id] = url;
|
|
|
|
saveVideoOverlay();
|
|
|
|
}
|
2013-02-12 10:38:01 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
div.appendChild(img);
|
|
|
|
}
|
2013-02-12 07:09:52 +00:00
|
|
|
this.div.appendChild(div);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} : null;
|
|
|
|
}
|
2013-02-12 13:09:46 +00:00
|
|
|
|
|
|
|
function saveVideoOverlay() {
|
|
|
|
var request = new XMLHttpRequest(),
|
|
|
|
id = document.location.pathname.substring(1),
|
|
|
|
formData = new FormData();
|
|
|
|
request.addEventListener('load', function (evt) {
|
|
|
|
console.log(evt);
|
|
|
|
});
|
|
|
|
formData.append('data', JSON.stringify({
|
|
|
|
'id': id,
|
|
|
|
'overlay': videoOverlay
|
|
|
|
}));
|
|
|
|
request.open('POST', '/save');
|
|
|
|
request.setRequestHeader("X-CSRFToken", getCookie('csrftoken'));
|
|
|
|
request.send(formData);
|
|
|
|
|
|
|
|
function getCookie(name) {
|
|
|
|
var cookieValue = null;
|
|
|
|
if (document.cookie && document.cookie != '') {
|
|
|
|
var cookies = document.cookie.split(';');
|
|
|
|
for (var i = 0; i < cookies.length; i++) {
|
|
|
|
var cookie = cookies[i].trim();
|
|
|
|
// Does this cookie string begin with the name we want?
|
|
|
|
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
|
|
|
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cookieValue;
|
|
|
|
}
|
|
|
|
}
|