Blame view
sources/apps/reader/js/.goutputstream-7F73MW
6.86 KB
|
42e4f8d60
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
$(document).ready(function() {
$('#fileList tr').each(function(){
// data-file attribute to contain unescaped filenames.
$(this).attr('data-file',decodeURIComponent($(this).attr('data-file')));
});
$('#file_action_panel').attr('activeAction', false);
/*$('table').ready(function(){
$('a.name').each(function(){
*/
/*});
});*/
});
$(function() {
// See if url conatins the index 'reader'
if(location.href.indexOf("reader")!=-1) {
'use strict';
// create thumbnails for pdfs inside current directory.
create_thumbnails();
// Render pdf view on every click of a thumbnail, now and in future.
$('td.filename a').live('click',function(event) {
event.preventDefault();
var filename=$(this).parent().parent().attr('data-file');
var tr=$('tr').filterAttr('data-file',filename);
var mime=$(this).parent().parent().data('mime');
var type=$(this).parent().parent().data('type');
// Check if clicked link is a pdf file or a directory, perform suitable function.
var action=getAction(mime,type);
if(action){
action(filename);
}
});
// Generate thumbnails for folders.
create_folder_thumbnails();
// On close of the pdf viewer, reload the page.
$('#close').live('click',function(event) {
location.reload();
});
// On hover over pdf thumbnails, their title should show.
$('a.name').hover(function(){
if($(this).children().hasClass('title'))
$(this).children().addClass('visible');
});
$('a.name').mouseleave(function(){
if($(this).children().hasClass('title'))
$(this).children().removeClass('visible');
});
/*$('#thumbnail').live('hover',function(event){
var canvas1 = document.getElementById("thumbnail");
if (canvas1.getContext) {
var ctx = canvas1.getContext("2d"); // Get the context for the canvas.
var myImage = canvas1.toDataURL("image/png"); // Get the data as an image.
}
var imageElement = document.getElementById("theimage"); // Get the img object.
imageElement.src = myImage; // Set the src to data from the canvas.
});*/
}
});
/* Function that returns suitable function definition to be executed on
* click of the file whose mime and type are passed. */
function getAction(mime,type) {
var name;
if(mime == 'application/pdf') {
name = function (filename){
showPDFviewer($('#dir').val(),filename);
}
}
else {
name = function (filename){
window.location=OC.linkTo('reader', 'index.php') + '&dir='+
encodeURIComponent($('#dir').val()).replace(/%2F/g, '/')+'/'+
encodeURIComponent(filename) + '/';
}
}
return name;
}
function create_thumbnails() {
PDFJS.disableWorker = true;
$('td.filename a').each(function() {
// Get url and title of each pdf file from anchor tags.
var url = $(this).attr('href');
var title = $(this).parent().parent().attr('data-file');
if (url.indexOf('pdf') != -1) {
PDFJS.getDocument(url).then(function(pdf) {
// Using promise to fetch the page
pdf.getPage(1).then(function(page) {
var scale = 0.2;
var viewport = page.getViewport(scale);
/*var div = document.createElement('div');
div.id = 'thumbnailContainer';
div.className = 'thumbnail';
var anchor = document.getElementById(url);*/
// Create canvas elements for each pdf's first page.
var canvas = document.createElement("canvas");
canvas.id = 'thumbnail';
// Canvas elements should be of proper size, not too big, not too small.
if (viewport.height > 170 || viewport.width > 130) {
scale = 0.1;
}
else if (viewport.height < 129 || viewport.width < 86) {
scale = 0.3;
}
viewport = page.getViewport(scale);
canvas.height = viewport.height;
canvas.width = viewport.width;
/*div.style.height = canvas.height + 'px';
div.style.width = canvas.width + 'px';
div.appendChild(canvas);
anchor.appendChild(div);
var title_div = document.createElement('div');
title_div.className = 'title';
title_div.innerHTML = title;
anchor.appendChild(title_div);*/
var ctx = canvas.getContext('2d');
ctx.save();
ctx.fillStyle = 'rgb(255, 255, 255)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
var view = page.view;
var scaleX = (canvas.width / page.width);
var scaleY = (canvas.height / page.height);
ctx.translate(-view.x * scaleX, -view.y * scaleY);
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
page.render(renderContext);
alert('yoto');
});
});
}
});
}
// Function to create thumbnails for folders.
function create_folder_thumbnails() {
$('a.dirs input').each(function() {
// fetch margin, url and and directory name values for each pdf, stored in input tags.
var margin = $(this).attr('name');
var pdf_dir = $(this).attr('value');
var url = $(this).attr('id');
PDFJS.getDocument(url).then(function(pdf) {
// Using promise to fetch the page
pdf.getPage(1).then(function(page) {
var scale = 0.3;
var viewport = page.getViewport(scale);
// Prepare canvas using PDF page dimensions
var anchor = document.getElementById(pdf_dir);
var canvas = document.createElement("canvas");
canvas.id = "dirsCanvas";
// Each thumbnail in the 3-thumbnail set should be of same dimensions.
canvas.height = '168';
canvas.width = '120';
// Canvases should be on top of each other
$(canvas).css('z-index',100 - margin);
$(canvas).css('margin-left', margin + 'px');
$(canvas).css('-webkit-backface-visibility', 'visible');
$(canvas).css('-webkit-transform-origin', '0% 51%');
$(canvas).css('-webkit-transform',' perspective(' + margin*35 + 'px) rotateY(23deg)');
anchor.appendChild(canvas);
var ctx = canvas.getContext('2d');
ctx.save();
ctx.fillStyle = 'rgb(255, 255, 255)';
ctx.fillRect(0, 0, canvas.width, canvas.height);
ctx.restore();
var view = page.view;
var scaleX = (canvas.width / page.width);
var scaleY = (canvas.height / page.height);
ctx.translate(-view.x * scaleX, -view.y * scaleY);
// Render PDF page into canvas context
var renderContext = {
canvasContext: ctx,
viewport: viewport
};
page.render(renderContext);
});
});
});
}
window.onload = function(){
var canvas = document.getElementById("thumbnail");
//alert(canvas);
if (canvas.getContext) {
var ctx = canvas.getContext("2d");
var myImage = canvas.toDataURL("image/png"); // Get the data as an image.
}
var imageElement = document.getElementById("theimage"); // Get the img object.
imageElement.src = myImage;
}
|