Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 46 additions & 29 deletions PluginLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,39 +53,56 @@ function loadPlugin(pluginName, callback) {
document.getElementsByTagName('head')[0].appendChild(script);
}

function createXMLHttpRequest(){
var xmlhttp;

if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera,Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}

return xmlhttp;
}

function loadDocument(documentUrl) {
"use strict";

if (documentUrl) {
var extension = documentUrl.split('.').pop(),
Plugin;
extension = extension.toLowerCase();
var xmlhttp = createXMLHttpRequest();

switch (extension) {
case 'odt':
case 'fodt':
case 'ott':
case 'odp':
case 'fodp':
case 'otp':
case 'ods':
case 'fods':
case 'ots':
loadPlugin('./ODFViewerPlugin', function () {
Plugin = ODFViewerPlugin;
});
break;
case 'pdf':
loadPlugin('./PDFViewerPlugin', function () {
Plugin = PDFViewerPlugin;
});
break;
}
xmlhttp.onreadystatechange = function() {
//readystate === 2 --> Headers received!
if (xmlhttp.readyState === 2) {
var extension = this.getResponseHeader('content-type');

var Plugin;

switch (extension) {
case 'application/vnd.oasis.opendocument.text':
case 'application/vnd.oasis.opendocument.presentation':
case 'application/vnd.oasis.opendocument.spreadsheet':
loadPlugin('./ODFViewerPlugin', function() {
Plugin = ODFViewerPlugin;
viewer = new Viewer(new Plugin());
});
break;
case 'application/pdf':
loadPlugin('./PDFViewerPlugin', function() {
Plugin = PDFViewerPlugin;
viewer = new Viewer(new Plugin());
});
break;
}

window.onload = function () {
if (Plugin) {
viewer = new Viewer(new Plugin());
}
};
}
//Abort the download of the document, in this phase we only need the content-type
this.abort();
}
};

xmlhttp.open("GET", documentUrl.substring(1), true);
xmlhttp.send();
}
}