mirror of
https://github.com/webodf/WebODF.git
synced 2026-11-30 16:47:58 +01:00
228 lines
7.8 KiB
HTML
228 lines
7.8 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
<style type="text/css" media="screen">
|
|
body, html, div {
|
|
padding: 0px;
|
|
margin: 0px;
|
|
border: 0px;
|
|
background: #888888;
|
|
}
|
|
</style>
|
|
<link rel="stylesheet" type="text/css" href="defaultodfstyle.css"/>
|
|
<style id='stylesxmlcss' type="text/css">
|
|
/* define namespaces here, because in WebKit they cannot be added dynamically */
|
|
@namespace draw url(urn:oasis:names:tc:opendocument:xmlns:drawing:1.0);
|
|
@namespace fo url(urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0);
|
|
@namespace office url(urn:oasis:names:tc:opendocument:xmlns:office:1.0);
|
|
@namespace style url(urn:oasis:names:tc:opendocument:xmlns:style:1.0);
|
|
@namespace table url(urn:oasis:names:tc:opendocument:xmlns:table:1.0);
|
|
@namespace text url(urn:oasis:names:tc:opendocument:xmlns:text:1.0);
|
|
</style>
|
|
<style id='autostylesxmlcss' type="text/css">
|
|
/* define namespaces here, because in WebKit they cannot be added dynamically */
|
|
@namespace draw url(urn:oasis:names:tc:opendocument:xmlns:drawing:1.0);
|
|
@namespace fo url(urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0);
|
|
@namespace office url(urn:oasis:names:tc:opendocument:xmlns:office:1.0);
|
|
@namespace style url(urn:oasis:names:tc:opendocument:xmlns:style:1.0);
|
|
@namespace table url(urn:oasis:names:tc:opendocument:xmlns:table:1.0);
|
|
@namespace text url(urn:oasis:names:tc:opendocument:xmlns:text:1.0);
|
|
</style>
|
|
<style id='contentxmlcss' type="text/css">
|
|
/* define namespaces here, because in WebKit they cannot be added dynamically */
|
|
@namespace draw url(urn:oasis:names:tc:opendocument:xmlns:drawing:1.0);
|
|
@namespace fo url(urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0);
|
|
@namespace office url(urn:oasis:names:tc:opendocument:xmlns:office:1.0);
|
|
@namespace style url(urn:oasis:names:tc:opendocument:xmlns:style:1.0);
|
|
@namespace table url(urn:oasis:names:tc:opendocument:xmlns:table:1.0);
|
|
@namespace text url(urn:oasis:names:tc:opendocument:xmlns:text:1.0);
|
|
</style>
|
|
<style id='positioncss' type="text/css">
|
|
/* define namespaces here, because in WebKit they cannot be added dynamically */
|
|
@namespace draw url(urn:oasis:names:tc:opendocument:xmlns:drawing:1.0);
|
|
@namespace svg url(urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0);
|
|
</style>
|
|
<script src="style2css.js" type="text/javascript" charset="utf-8"></script>
|
|
<script type="text/javascript" charset="utf-8">
|
|
|
|
var xhtmlns = "http://www.w3.org/1999/xhtml";
|
|
|
|
var dynamicOdfJavascript = null;
|
|
|
|
function loadJavascript(jsfiles) {
|
|
if (dynamicOdfJavascript) return;
|
|
var req = new XMLHttpRequest();
|
|
var js = "";
|
|
for (var i in jsfiles) {
|
|
req.open('GET', jsfiles[i], null);
|
|
req.send(null);
|
|
js += req.responseText;
|
|
}
|
|
if (js.length ) {
|
|
dynamicOdfJavascript = js;
|
|
}
|
|
}
|
|
|
|
function init() {
|
|
// if there is no native 'window.odf' object, create one
|
|
if (!window.odf) {
|
|
// try to load the javascript required when no native ODF support is
|
|
// available
|
|
// if there is no native window.odf, there still might be a window.qtodf
|
|
var jsfiles;
|
|
if (window.qtodf) {
|
|
jsfiles = ['qtodf.js'];
|
|
} else {
|
|
jsfiles = ['base64.js','bytearray.js','rawinflate.js','zip.js','odf.js'];
|
|
}
|
|
loadJavascript(jsfiles);
|
|
window.odf = eval(dynamicOdfJavascript);
|
|
}
|
|
|
|
// if the url has a fragment (#...), try to load the file it represents
|
|
var location = new String(document.location);
|
|
var pos = location.indexOf('#');
|
|
if (pos == -1) {
|
|
return;
|
|
}
|
|
location = location.substr(pos+1);
|
|
// open the odf container
|
|
window.odfcontainer = new window.odf.OdfContainer(location);
|
|
refreshOdf();
|
|
}
|
|
|
|
function clear(element) {
|
|
while (element.firstChild) {
|
|
element.removeChild(element.firstChild);
|
|
}
|
|
}
|
|
|
|
function refreshOdf() {
|
|
// synchronize the object a window.odfcontainer with the view
|
|
var container = window.odfcontainer;
|
|
|
|
clear(document.body);
|
|
|
|
var documentcontent = container.getXmlNode('content.xml');
|
|
|
|
clear(document.body);
|
|
handleContentXmlLoaded(documentcontent);
|
|
|
|
var documentstyles = container.getXmlNode('styles.xml');
|
|
handleStylesXmlLoaded(documentstyles);
|
|
}
|
|
|
|
var officens = "urn:oasis:names:tc:opendocument:xmlns:office:1.0";
|
|
|
|
/**
|
|
* A new content.xml has been loaded. Update the live document with it.
|
|
**/
|
|
function handleContentXmlLoaded(contentxml) {
|
|
// replace content.xml in the live document
|
|
var contentcontainer = document.getElementById('contentxml');
|
|
if (!contentcontainer) {
|
|
contentcontainer = document.createElementNS(xhtmlns, "div");
|
|
document.body.appendChild(contentcontainer);
|
|
}
|
|
clear(contentcontainer);
|
|
if (contentxml && contentxml.firstChild) {
|
|
contentxml = document.importNode(contentxml.firstChild, true);
|
|
contentcontainer.appendChild(contentxml);
|
|
}
|
|
var contentxmlcss = document.getElementById('contentxmlcss');
|
|
var automaticstyles = contentxml.getElementsByTagNameNS(officens, 'automatic-styles');
|
|
if (automaticstyles.length > 0) {
|
|
automaticstyles = automaticstyles.item(0);
|
|
try {
|
|
style2css(contentxmlcss.sheet, automaticstyles);
|
|
} catch (e) {
|
|
alert(e);
|
|
}
|
|
}
|
|
|
|
// experiment
|
|
var positioncss = document.getElementById('positioncss');
|
|
modifyImages(contentxml, positioncss.sheet);
|
|
}
|
|
/**
|
|
* A new styles.xml has been loaded. Update the live document with it.
|
|
**/
|
|
function handleStylesXmlLoaded(stylesxml) {
|
|
// replace styles.xml in the live document
|
|
var stylescontainer = document.getElementById('stylesxml');
|
|
if (!stylescontainer) {
|
|
stylescontainer = document.createElementNS(xhtmlns, "div");
|
|
document.body.appendChild(stylescontainer);
|
|
}
|
|
clear(stylescontainer);
|
|
if (stylesxml && stylesxml.firstChild) {
|
|
stylesxml = document.importNode(stylesxml.firstChild, true);
|
|
stylescontainer.appendChild(stylesxml);
|
|
}
|
|
|
|
// update the css translation of the styles
|
|
stylesxml = stylesxml.getElementsByTagNameNS(officens, 'styles');
|
|
if (stylesxml.length < 1) {
|
|
return;
|
|
}
|
|
stylesxml = stylesxml.item(0);
|
|
var stylesxmlcss = document.getElementById('stylesxmlcss');
|
|
try {
|
|
style2css(stylesxmlcss.sheet, stylesxml);
|
|
} catch (e) {
|
|
alert(e);
|
|
}
|
|
}
|
|
var drawns="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0";
|
|
var svgns="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0";
|
|
|
|
function modifyImages(contentxml, stylesheet) {
|
|
var namespaces = {
|
|
draw: drawns,
|
|
svg: svgns
|
|
};
|
|
var namespaceResolver = function(prefix) {
|
|
return namespaces[prefix];
|
|
}
|
|
var doc = contentxml.ownerDocument;
|
|
var frames = contentxml.getElementsByTagNameNS(drawns, 'frame');
|
|
for (var i=0; i<frames.length; ++i) {
|
|
setFramePosition(i, frames.item(i), stylesheet);
|
|
}
|
|
}
|
|
function setFramePosition(id, frame, stylesheet) {
|
|
frame.setAttribute('styleid', id);
|
|
var rule = 'position: relative;';
|
|
var x = frame.getAttributeNS(svgns, 'x');
|
|
if (x) { rule += 'top: ' + x + ';'; }
|
|
var y = frame.getAttributeNS(svgns, 'x');
|
|
if (y) { rule += 'left: ' + y + ';'; }
|
|
var width = frame.getAttributeNS(svgns, 'width');
|
|
if (width) { rule += 'width: ' + width + ';'; }
|
|
var height = frame.getAttributeNS(svgns, 'height');
|
|
if (height) { rule += 'height: ' + height + ';' }
|
|
rule = 'draw|frame[styleid="' + id + '"] {' + rule + '}';
|
|
stylesheet.insertRule(rule, stylesheet.cssRules.length);
|
|
}
|
|
/*
|
|
function refreshOdf() {
|
|
var odfcontainer = new window.odf.OdfContainer('hi');
|
|
alert(odfcontainer);
|
|
|
|
var parser = new DOMParser();
|
|
var contentxml = odfcontainer.getContentXml();
|
|
var doc = parser.parseFromString(contentxml, "text/xml");
|
|
var root = doc.documentElement;
|
|
root = document.importNode(root, true);
|
|
document.body.appendChild(root);
|
|
}
|
|
*/
|
|
</script>
|
|
<title></title>
|
|
</head>
|
|
|
|
<body onload='init()'>
|
|
</body>
|
|
</html>
|