mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-02 14:49:17 +02:00
files_reader: v1.0.0, see CHANGELOG and appinfo/info.xml for changes and new features
This commit is contained in:
parent
30f758d419
commit
aa85edee22
65 changed files with 13549 additions and 539 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015 Frank de Lange
|
||||
* Copyright (c) 2015-2017 Frank de Lange
|
||||
* Copyright (c) 2013-2014 Lukas Reschke <lukas@owncloud.com>
|
||||
*
|
||||
* This file is licensed under the Affero General Public License version 3
|
||||
|
@ -9,17 +9,33 @@
|
|||
*
|
||||
*/
|
||||
|
||||
|
||||
(function(OCA) {
|
||||
|
||||
OCA.FilesReader = OCA.FilesReader || {};
|
||||
OCA.Files_Reader = OCA.Files_Reader || {};
|
||||
|
||||
var isMobile = navigator.userAgent.match(/Mobi/i);
|
||||
var hasTouch = 'ontouchstart' in document.documentElement;
|
||||
|
||||
function actionHandler(fileName, mime, context) {
|
||||
var downloadUrl = '';
|
||||
if($('#isPublic').val()) {
|
||||
var sharingToken = $('#sharingToken').val();
|
||||
downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
|
||||
token: sharingToken,
|
||||
files: fileName,
|
||||
path: context.dir
|
||||
});
|
||||
} else {
|
||||
downloadUrl = Files.getDownloadUrl(fileName, context.dir);
|
||||
}
|
||||
OCA.Files_Reader.Plugin.show(downloadUrl, mime, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @namespace OCA.FilesReader.Plugin
|
||||
* @namespace OCA.Files_Reader.Plugin
|
||||
*/
|
||||
OCA.FilesReader.Plugin = {
|
||||
OCA.Files_Reader.Plugin = {
|
||||
|
||||
/**
|
||||
* @param fileList
|
||||
|
@ -51,10 +67,10 @@
|
|||
* @param downloadUrl
|
||||
* @param isFileList
|
||||
*/
|
||||
show: function(downloadUrl, isFileList) {
|
||||
show: function(downloadUrl, mimeType, isFileList) {
|
||||
var self = this;
|
||||
var $iframe;
|
||||
var viewer = OC.generateUrl('/apps/files_reader/?file={file}', {file: downloadUrl});
|
||||
var viewer = OC.generateUrl('/apps/files_reader/?file={file}&type={type}', {file: downloadUrl, type: mimeType});
|
||||
// launch in new window on mobile and touch devices...
|
||||
if (isMobile || hasTouch) {
|
||||
window.open(viewer, downloadUrl);
|
||||
|
@ -86,39 +102,41 @@
|
|||
_extendFileActions: function(fileActions) {
|
||||
var self = this;
|
||||
fileActions.registerAction({
|
||||
name: 'view',
|
||||
displayName: 'Favorite',
|
||||
name: 'view-epub',
|
||||
displayName: 'View',
|
||||
mime: 'application/epub+zip',
|
||||
permissions: OC.PERMISSION_READ,
|
||||
actionHandler: function(fileName, context) {
|
||||
var downloadUrl = '';
|
||||
if($('#isPublic').val()) {
|
||||
var sharingToken = $('#sharingToken').val();
|
||||
downloadUrl = OC.generateUrl('/s/{token}/download?files={files}&path={path}', {
|
||||
token: sharingToken,
|
||||
files: fileName,
|
||||
path: context.dir
|
||||
});
|
||||
} else {
|
||||
downloadUrl = Files.getDownloadUrl(fileName, context.dir);
|
||||
}
|
||||
self.show(downloadUrl, true);
|
||||
actionHandler: function(fileName, context){
|
||||
return actionHandler(fileName, 'application/epub+zip', context);
|
||||
}
|
||||
});
|
||||
fileActions.setDefault('application/epub+zip', 'view');
|
||||
fileActions.registerAction({
|
||||
name: 'view-cbr',
|
||||
displayName: 'View',
|
||||
mime: 'application/x-cbr',
|
||||
permissions: OC.PERMISSION_READ,
|
||||
actionHandler: function(fileName, context) {
|
||||
return actionHandler(fileName, 'application/x-cbr', context);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
fileActions.setDefault('application/epub+zip', 'view-epub');
|
||||
fileActions.setDefault('application/x-cbr', 'view-cbr');
|
||||
}
|
||||
};
|
||||
|
||||
})(OCA);
|
||||
|
||||
OC.Plugins.register('OCA.Files.FileList', OCA.FilesReader.Plugin);
|
||||
OC.Plugins.register('OCA.Files.FileList', OCA.Files_Reader.Plugin);
|
||||
|
||||
// FIXME: Hack for single public file view since it is not attached to the fileslist
|
||||
$(document).ready(function(){
|
||||
if ($('#isPublic').val() && $('#mimetype').val() === 'application/epub+zip') {
|
||||
if ($('#isPublic').val() && ($('#mimetype').val() === 'application/epub+zip'|| $('#mimetype').val() === 'application/x-cbr)')) {
|
||||
var sharingToken = $('#sharingToken').val();
|
||||
var downloadUrl = OC.generateUrl('/s/{token}/download', {token: sharingToken});
|
||||
var viewer = OCA.FilesReader.Plugin;
|
||||
viewer.show(downloadUrl, false);
|
||||
var viewer = OCA.Files_Reader.Plugin;
|
||||
var mime = $('#mimetype').val();
|
||||
viewer.show(downloadUrl, mime, false);
|
||||
}
|
||||
});
|
||||
|
|
|
@ -1,169 +1,139 @@
|
|||
function disableStyles(doc, disable) {
|
||||
for ( var i=0; i<doc.styleSheets.length; i++) {
|
||||
void(doc.styleSheets.item(i).disabled=disable);
|
||||
}
|
||||
}
|
||||
|
||||
function addStyleSheet() {
|
||||
var style = document.createElement("style");
|
||||
// WebKit hack :(
|
||||
style.appendChild(document.createTextNode(""));
|
||||
document.head.appendChild(style);
|
||||
return style.sheet;
|
||||
}
|
||||
|
||||
function getCSSRule(sheet, selector, del) {
|
||||
lcSelector = selector.toLowerCase();
|
||||
for ( var i=0; i<sheet.cssRules.length; i++) {
|
||||
if (sheet.cssRules.item(i).selectorText.toLowerCase() == lcSelector) {
|
||||
if (del) {
|
||||
sheet.deleteRule(i);
|
||||
return null;
|
||||
} else {
|
||||
return sheet.cssRules.item(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function addCSSRule(sheet, selector, rules, index) {
|
||||
if("insertRule" in sheet) {
|
||||
sheet.insertRule(selector + "{" + rules + "}", index);
|
||||
}
|
||||
else if("addRule" in sheet) {
|
||||
sheet.addRule(selector, rules, index);
|
||||
}
|
||||
}
|
||||
|
||||
function delCSSRule(sheet, selector) {
|
||||
getCSSRule(sheet, selector, true);
|
||||
}
|
||||
|
||||
document.onreadystatechange = function () {
|
||||
if (document.readyState == "complete") {
|
||||
// only enable close button when launched in an iframe
|
||||
if (parent !== window) {
|
||||
$('#close').show();
|
||||
$('#close').on('click', function() { reader.book.destroy(); parent.OCA.FilesReader.Plugin.hide(); });
|
||||
}
|
||||
|
||||
// some parameters...
|
||||
EPUBJS.filePath = "js/libs/";
|
||||
EPUBJS.cssPath = "css/";
|
||||
if (document.readyState == "complete") {
|
||||
|
||||
// touch-enabled devices...
|
||||
$('#touch_nav').prop('checked', !('ontouchstart' in document.documentElement));
|
||||
if (!($('#touch_nav').prop('checked'))) {
|
||||
$("#next").addClass("touch_nav");
|
||||
$("#prev").addClass("touch_nav");
|
||||
}
|
||||
var type=decodeURIComponent(getUrlParameter('type')),
|
||||
file=decodeURIComponent(getUrlParameter('file')),
|
||||
options = {},
|
||||
$session = $('.session');
|
||||
|
||||
// idevices...
|
||||
if (navigator.userAgent.match(/(iPad|iPhone|iPod)/g)) {
|
||||
$('head').append($('<link rel="stylesheet" type="text/css" />').attr('href', document.getElementsByTagName("base").item(0).href + 'css/idevice.css'));
|
||||
}
|
||||
options.session = {};
|
||||
options.session.filename = decodeURI($session.data('filename'));
|
||||
options.session.format = $session.data('filetype');
|
||||
options.session.fileId = $session.data('fileid');
|
||||
options.session.title = options.session.filename;
|
||||
options.session.nonce = $session.data('nonce') || "";
|
||||
options.session.version = $session.data('version') || "";
|
||||
options.session.metadata = $session.data('metadata') || {};
|
||||
options.session.annotations = $session.data('annotations') || {};
|
||||
options.session.fileId = $session.data('fileid') || "";
|
||||
options.session.scope = $session.data('scope') || "";
|
||||
options.session.cursor = $session.data('cursor') || {};
|
||||
options.session.defaults = $session.data('defaults') || {};
|
||||
options.session.preferences = $session.data('preferences') || {};
|
||||
options.session.defaults = $session.data('defaults') || {};
|
||||
options.session.basePath = $session.data('basepath');
|
||||
options.session.downloadLink = $session.data('downloadlink');
|
||||
|
||||
// IE < 11
|
||||
if (navigator.userAgent.indexOf("MSIE") != -1) {
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").wgxpath = function(callback, renderer){
|
||||
wgxpath.install(renderer.render.window);
|
||||
if(callback)
|
||||
callback();
|
||||
};
|
||||
wgxpath.install(window);
|
||||
}
|
||||
|
||||
function nightModeConfig() {
|
||||
delCSSRule(EPUBJS.nightSheet, EPUBJS.nightSelector);
|
||||
addCSSRule(EPUBJS.nightSheet, EPUBJS.nightSelector, 'color: ' + EPUBJS.nightModeColor + ' !important; background: ' + EPUBJS.nightModeBackground + ' !important;');
|
||||
}
|
||||
/* functions return jquery promises */
|
||||
options.session.getPreference = function(name) {
|
||||
return $.get(options.session.basePath + "preference/" + options.session.fileId + "/" + options.session.scope + "/" + name);
|
||||
};
|
||||
options.session.setPreference = function(name, value) {
|
||||
return $.post(options.session.basePath + "preference",
|
||||
{
|
||||
"fileId": options.session.fileId,
|
||||
"scope": options.session.scope,
|
||||
"name": name,
|
||||
"value": JSON.stringify(value)
|
||||
});
|
||||
};
|
||||
options.session.deletePreference = function(name) {
|
||||
return $.delete(options.session.basePath + "preference/" + options.session.fileId + "/" + options.session.scope + "/" + name);
|
||||
};
|
||||
options.session.getDefault = function(name) {
|
||||
return $.get(options.session.basePath + "preference/default/" + options.session.scope + "/" + name);
|
||||
};
|
||||
options.session.setDefault = function(name, value) {
|
||||
return $.post(options.session.basePath + "preference/default",
|
||||
{
|
||||
"scope": options.session.scope,
|
||||
"name": name,
|
||||
"value": JSON.stringify(value)
|
||||
});
|
||||
};
|
||||
options.session.deleteDefault = function(name) {
|
||||
return $.delete(options.session.basePath + "preference/default/" + options.session.scope + "/" + name);
|
||||
};
|
||||
options.session.getBookmark = function(name, type) {
|
||||
return $.get(options.session.basePath + "bookmark/" + options.session.fileId + "/" + type + "/" + name);
|
||||
};
|
||||
options.session.setBookmark = function(name, value, type, content) {
|
||||
return $.post(options.session.basePath + "bookmark",
|
||||
{
|
||||
"fileId": options.session.fileId,
|
||||
"name": name,
|
||||
"value": JSON.stringify(value),
|
||||
"type": type,
|
||||
"content": JSON.stringify(content)
|
||||
});
|
||||
};
|
||||
options.session.deleteBookmark = function(name) {
|
||||
return $.delete(options.session.basePath + "bookmark/" + options.session.fileId + "/" + name);
|
||||
};
|
||||
options.session.getCursor = function() {
|
||||
return $.get(options.session.basePath + "bookmark/cursor/" + options.session.fileId);
|
||||
};
|
||||
options.session.setCursor = function(value) {
|
||||
return $.post(options.session.basePath + "bookmark/cursor",
|
||||
{
|
||||
"fileId": options.session.fileId,
|
||||
"value": JSON.stringify(value)
|
||||
});
|
||||
};
|
||||
options.session.deleteCursor = function() {
|
||||
return $.delete(options.session.basePath + "bookmark/cursor/" + options.session.fileId);
|
||||
};
|
||||
|
||||
// nightMode
|
||||
EPUBJS.nightMode = false;
|
||||
EPUBJS.nightSheet = addStyleSheet();
|
||||
EPUBJS.nightSelector = '.night *';
|
||||
EPUBJS.nightModeBackground = $('#nightModeBackground').val();
|
||||
EPUBJS.nightModeColor = $('#nightModeColor').val();
|
||||
addCSSRule(EPUBJS.nightSheet, '.nonight', 'background: initial !important;');
|
||||
nightModeConfig();
|
||||
switch (type) {
|
||||
case 'application/epub+zip':
|
||||
options['contained'] = true;
|
||||
renderEpub(file, options);
|
||||
break;
|
||||
case 'application/x-cbr':
|
||||
renderCbr(file, options);
|
||||
break;
|
||||
default:
|
||||
console.log(type + ' is not supported by Reader');
|
||||
}
|
||||
|
||||
// why is there no standard library function for this?
|
||||
function getUrlParameter (param) {
|
||||
var pattern = new RegExp('[?&]'+param+'((=([^&]*))|(?=(&|$)))','i');
|
||||
var m = window.location.search.match(pattern);
|
||||
return m && ( typeof(m[3])==='undefined' ? '' : m[3] );
|
||||
}
|
||||
|
||||
$('#nightModeBackground').on('change', function() {
|
||||
EPUBJS.nightModeBackground = $('#nightModeBackground').val();
|
||||
nightModeConfig();
|
||||
});
|
||||
// start epub.js renderer
|
||||
function renderEpub(file, options) {
|
||||
|
||||
$('#nightModeColor').on('change', function() {
|
||||
EPUBJS.nightModeColor = $('#nightModeColor').val();
|
||||
nightModeConfig();
|
||||
});
|
||||
// some parameters...
|
||||
EPUBJS.filePath = "vendor/epubjs/";
|
||||
EPUBJS.cssPath = "vendor/epubjs/css/";
|
||||
EPUBJS.basePath = $('.session').data('basepath');
|
||||
|
||||
console.log(document.getElementById("dllink").value);
|
||||
var reader = ePubReader(document.getElementById("dllink").value, { contained: true });
|
||||
/* device-specific boilerplate */
|
||||
|
||||
// enable night/day mode switch by clicking on the book title/author
|
||||
// just switching in the "night" class works on some browsers but not on others, hence the trickery with
|
||||
// setStyle/removeStyle...
|
||||
$('#metainfo').on('click', function() {
|
||||
if(EPUBJS.nightMode) {
|
||||
reader.book.removeStyle("background");
|
||||
reader.book.removeStyle("color");
|
||||
$("#outerContainer").removeClass("night");
|
||||
EPUBJS.nightMode = false;
|
||||
} else {
|
||||
reader.book.setStyle("background", EPUBJS.nightModeBackground);
|
||||
reader.book.setStyle("color", EPUBJS.nightModeColor);
|
||||
$("#outerContainer").addClass("night");
|
||||
EPUBJS.nightMode = true;
|
||||
}
|
||||
});
|
||||
// IE < 11
|
||||
if (navigator.userAgent.indexOf("MSIE") != -1) {
|
||||
EPUBJS.Hooks.register("beforeChapterDisplay").wgxpath = function(callback, renderer){
|
||||
wgxpath.install(renderer.render.window);
|
||||
if(callback)
|
||||
callback();
|
||||
};
|
||||
wgxpath.install(window);
|
||||
}
|
||||
|
||||
// extra-wide page turn area?
|
||||
$('#touch_nav').on('click', function() {
|
||||
if ($('#touch_nav').prop('checked')) {
|
||||
$("#prev").removeClass("touch_nav");
|
||||
$("#next").removeClass("touch_nav");
|
||||
} else {
|
||||
$("#prev").addClass("touch_nav");
|
||||
$("#next").addClass("touch_nav");
|
||||
}
|
||||
});
|
||||
|
||||
// user-defined font
|
||||
EPUBJS.ignore_css = false;
|
||||
EPUBJS.bookFrame = null;
|
||||
EPUBJS.user_fontFamily = $('#fontFamily').val();
|
||||
EPUBJS.user_fontSize = $('#fontSize').val() + '%';
|
||||
var reader = ePubReader(file, options);
|
||||
}
|
||||
|
||||
$('#ignore_css').on('click', function() {
|
||||
EPUBJS.bookFrame = document.getElementsByTagName('iframe')[0].contentDocument;
|
||||
if ($('#ignore_css').prop('checked')) {
|
||||
$('#fontFamily').prop('disabled',false);
|
||||
$('#fontSize').prop('disabled',false);
|
||||
EPUBJS.ignore_css = true;
|
||||
reader.book.setStyle('font-size', EPUBJS.user_fontSize);
|
||||
reader.book.setStyle('font-family', EPUBJS.user_fontFamily);
|
||||
} else {
|
||||
$('#fontFamily').prop('disabled',true);
|
||||
$('#fontSize').prop('disabled',true);
|
||||
EPUBJS.ignore_css = false;
|
||||
reader.book.removeStyle('font-size');
|
||||
reader.book.removeStyle('font-family');
|
||||
}
|
||||
disableStyles(EPUBJS.bookFrame, EPUBJS.ignore_css);
|
||||
;
|
||||
});
|
||||
// start cbr.js renderer
|
||||
function renderCbr(file, options) {
|
||||
CBRJS.filePath = "vendor/cbrjs/";
|
||||
|
||||
$('#fontSize').on('change', function() {
|
||||
EPUBJS.user_fontSize = $('#fontSize').val() + '%';
|
||||
$('#font_example').css('font-size', EPUBJS.user_fontSize);
|
||||
reader.book.setStyle('font-size', EPUBJS.user_fontSize);
|
||||
});
|
||||
$('#fontFamily').on('change', function() {
|
||||
EPUBJS.user_fontFamily = $('#fontFamily').val();
|
||||
$('#font_example').css('font-family', EPUBJS.user_fontFamily);
|
||||
reader.book.setStyle('font-family', EPUBJS.user_fontFamily);
|
||||
});
|
||||
}
|
||||
var reader = cbReader(file, options);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue