Create script.js
Browse files- dir_browser/htdocs/script.js +99 -0
dir_browser/htdocs/script.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// Cached plugin reference (or null. if it could not be instantiated)
|
| 2 |
+
var sharePointPlugin = undefined;
|
| 3 |
+
|
| 4 |
+
function onLoad() {
|
| 5 |
+
// console.log("loaded.");
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
/**
|
| 10 |
+
* Find (and cache) an available ActiveXObject Sharepoint plugin.
|
| 11 |
+
*
|
| 12 |
+
* @returns {ActiveXObject} or null
|
| 13 |
+
*/
|
| 14 |
+
function getSharePointPlugin() {
|
| 15 |
+
if( sharePointPlugin !== undefined ) {
|
| 16 |
+
return sharePointPlugin;
|
| 17 |
+
}
|
| 18 |
+
sharePointPlugin = null;
|
| 19 |
+
|
| 20 |
+
var plugin = document.getElementById("winFirefoxPlugin");
|
| 21 |
+
|
| 22 |
+
if ( plugin && typeof plugin.EditDocument === "function" ) {
|
| 23 |
+
window.console && console.log("Using embedded custom SharePoint plugin.");
|
| 24 |
+
sharePointPlugin = plugin;
|
| 25 |
+
} else if( "ActiveXObject" in window ){
|
| 26 |
+
plugin = null;
|
| 27 |
+
try {
|
| 28 |
+
plugin = new ActiveXObject("SharePoint.OpenDocuments.3"); // Office 2007+
|
| 29 |
+
} catch(e) {
|
| 30 |
+
try {
|
| 31 |
+
plugin = new ActiveXObject("SharePoint.OpenDocuments.2"); // Office 2003
|
| 32 |
+
} catch(e2) {
|
| 33 |
+
try {
|
| 34 |
+
plugin = new ActiveXObject("SharePoint.OpenDocuments.1"); // Office 2000/XP
|
| 35 |
+
} catch(e3) {
|
| 36 |
+
window.console && console.warn("Could not create ActiveXObject('SharePoint.OpenDocuments'): (requires IE <= 11 and matching security settings.");
|
| 37 |
+
}
|
| 38 |
+
}
|
| 39 |
+
}
|
| 40 |
+
if( plugin ){
|
| 41 |
+
window.console && console.log("Using native SharePoint plugin.");
|
| 42 |
+
sharePointPlugin = plugin;
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
return sharePointPlugin;
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
/**
|
| 50 |
+
* Open an MS Office document either with SharePoint plugin or using the 'ms-' URL prefix.
|
| 51 |
+
*
|
| 52 |
+
* @param {object} opts
|
| 53 |
+
* @returns {boolean} true if the URL could be opened
|
| 54 |
+
*/
|
| 55 |
+
function openWebDavDocument(opts) {
|
| 56 |
+
var ofe_link = opts.ofe + opts.href, // (e.g. 'ms-word:ofe|u|http://server/path/file.docx')
|
| 57 |
+
url = opts.href;
|
| 58 |
+
|
| 59 |
+
var plugin = getSharePointPlugin();
|
| 60 |
+
var res = false;
|
| 61 |
+
|
| 62 |
+
if( plugin ) {
|
| 63 |
+
try {
|
| 64 |
+
res = plugin.EditDocument(url);
|
| 65 |
+
if( res === false ) {
|
| 66 |
+
window.console && console.warn("SharePoint plugin.EditDocument(" + url + ") returned false");
|
| 67 |
+
}
|
| 68 |
+
} catch(e) {
|
| 69 |
+
window.console && console.warn("SharePoint plugin.EditDocument(" + url + ") raised an exception", e);
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
if ( res === false ) {
|
| 73 |
+
if( ofe_link ) {
|
| 74 |
+
window.console && console.log("Could not use SharePoint plugin: trying " + ofe_link);
|
| 75 |
+
window.open(ofe_link, "_self");
|
| 76 |
+
res = true;
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
return res;
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
/**
|
| 84 |
+
* Event delegation handler for clicks on a-tags with class 'msoffice'.
|
| 85 |
+
*/
|
| 86 |
+
function onClickTable(event) {
|
| 87 |
+
var target = event.target || event.srcElement,
|
| 88 |
+
opts = {
|
| 89 |
+
href: target.href,
|
| 90 |
+
ofe: target.getAttribute("data-ofe")
|
| 91 |
+
};
|
| 92 |
+
|
| 93 |
+
if( target.className === "msoffice" ){
|
| 94 |
+
if( openWebDavDocument(opts) ){
|
| 95 |
+
// prevent default processing if the document could be opened
|
| 96 |
+
return false;
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
}
|