Commit 4386cfa6 authored by Romain Courteaud's avatar Romain Courteaud

erp5_run_my_doc: xxx viewer

parent 78317e1c
/*global window, rJS, RSVP, domsugar, Reveal*/
/*global window, rJS, RSVP, domsugar, Reveal, URL*/
/*jslint nomen: true, maxlen:80, indent:2*/
(function (window, rJS, RSVP, domsugar, Reveal) {
(function (window, rJS, RSVP, domsugar, Reveal, URL) {
"use strict";
function fixupERP5UrlCompatibility(jio_key, url) {
console.log(jio_key);
if (!jio_key) {
return url;
}
return new URL(
url,
new URL(jio_key + '/', window.location.href).href
).href;
}
function getSlideElementList(presentation_html) {
// Convert to an Array so that array methods can be used to reorder slides
return Array.prototype.slice.call(domsugar('div', {
......@@ -23,7 +34,7 @@
return fragment;
}
function cleanupSlide(slide_element) {
function cleanupSlide(slide_element, jio_key) {
var detail_list = Array.prototype.slice.call(
slide_element.querySelectorAll(':scope > details')
),
......@@ -50,15 +61,30 @@
}
}
}
// Rewrite img url to support sub document ID
detail_list = Array.prototype.slice.call(
slide_element.querySelectorAll('img')
);
len = detail_list.length;
for (i = 0; i < len; i += 1) {
console.log('img', detail_list[i]);
detail_list[i].src = fixupERP5UrlCompatibility(
jio_key,
detail_list[i].src
)
}
return slide_element;
}
function cleanupPresentationFormat(presentation_html) {
function cleanupPresentationFormat(presentation_html, jio_key) {
var slide_list = getSlideElementList(presentation_html),
i,
len = slide_list.length;
for (i = 0; i < len; i += 1) {
cleanupSlide(slide_list[i]);
cleanupSlide(slide_list[i], jio_key);
}
return domsugar('div', {class: 'reveal'}, [
domsugar('div', {class: 'slides'}, slide_list)
......@@ -73,7 +99,8 @@
.declareMethod('render', function (options) {
return this.changeState({
value: options.value || ""
value: options.value || "",
jio_key: options.jio_key
});
})
......@@ -82,7 +109,7 @@
return new RSVP.Queue()
.push(function () {
domsugar(gadget.element, [
cleanupPresentationFormat(gadget.state.value)
cleanupPresentationFormat(gadget.state.value, gadget.state.jio_key)
]);
return Reveal.initialize(gadget.element, {
......@@ -112,4 +139,4 @@
});
}(window, rJS, RSVP, domsugar, Reveal));
\ No newline at end of file
}(window, rJS, RSVP, domsugar, Reveal, URL));
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment