mirror of
https://github.com/webodf/WebODF.git
synced 2026-12-01 16:56:05 +01:00
139 lines
4.0 KiB
HTML
139 lines
4.0 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 id='stylesxmlcss' type="text/css" media="screen">
|
|
</style>
|
|
<style id='contentxmlcss' type="text/css" media="screen">
|
|
</style>
|
|
<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"></link>
|
|
<script src="zip.js" type="text/javascript" charset="utf-8"></script>
|
|
<script src="base64.js" type="text/javascript" charset="utf-8"></script>
|
|
<script src="bytearray.js" type="text/javascript" charset="utf-8"></script>
|
|
<script src="rawinflate.js" type="text/javascript" charset="utf-8"></script>
|
|
<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";
|
|
|
|
function init() {
|
|
var location = new String(document.location);
|
|
var pos = location.indexOf('#');
|
|
if (pos != -1) {
|
|
location = location.substr(pos+1);
|
|
}
|
|
document.body.innerHTML = location;
|
|
try {
|
|
loadFile(location);
|
|
} catch(e) {
|
|
document.body.innerHTML = e;
|
|
}
|
|
}
|
|
function clear(element) {
|
|
while (element.firstChild) {
|
|
element.removeChild(element.firstChild);
|
|
}
|
|
}
|
|
|
|
function loadFile(url) {
|
|
clear(document.body);
|
|
|
|
var ziplist = document.body;
|
|
document.body.innerHTML = 'Loading...';
|
|
var zip;
|
|
try {
|
|
zip = new jsodfkit.Zip(url);
|
|
} catch (e) {
|
|
ziplist.innerHTML = e;
|
|
return;
|
|
}
|
|
var xmldata = zip.load('content.xml');
|
|
if (!xmldata || xmldata.length == 0) {
|
|
throw "Cannot read content.xml";
|
|
}
|
|
var parser = new DOMParser();
|
|
var contentxml = parser.parseFromString(xmldata, 'text/xml');
|
|
|
|
clear(document.body);
|
|
handleContentXmlLoaded(contentxml);
|
|
|
|
xmldata = zip.load('styles.xml');
|
|
var stylesxml = parser.parseFromString(xmldata, 'text/xml');
|
|
handleStylesXmlLoaded(stylesxml);
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|
|
/**
|
|
* 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);
|
|
}
|
|
}
|
|
|
|
</script>
|
|
|
|
<title></title>
|
|
</head>
|
|
|
|
<body onload='init()'>
|
|
</body>
|
|
</html>
|