mirror of
https://github.com/Yetangitu/owncloud-apps.git
synced 2025-10-02 14:49:17 +02:00
files_reader: experimental PDF support, Work In Progress
This commit is contained in:
parent
9865f94e70
commit
ed0d8ae717
27 changed files with 3649 additions and 2 deletions
115
files_reader/vendor/pdfjs/controllers/toc_controller.js
vendored
Normal file
115
files_reader/vendor/pdfjs/controllers/toc_controller.js
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
PDFJS.reader.TocController = function(toc) {
|
||||
var book = this.book;
|
||||
|
||||
var $list = $("#tocView"),
|
||||
docfrag = document.createDocumentFragment();
|
||||
|
||||
var currentChapter = false;
|
||||
|
||||
var generateTocItems = function(toc, level) {
|
||||
var container = document.createElement("ul");
|
||||
|
||||
if(!level) level = 1;
|
||||
|
||||
toc.forEach(function(chapter) {
|
||||
var listitem = document.createElement("li"),
|
||||
link = document.createElement("a");
|
||||
toggle = document.createElement("a");
|
||||
|
||||
var subitems;
|
||||
|
||||
listitem.id = "toc-"+chapter.id;
|
||||
listitem.classList.add('list_item');
|
||||
|
||||
link.textContent = chapter.label;
|
||||
link.href = chapter.href;
|
||||
|
||||
link.classList.add('toc_link');
|
||||
|
||||
listitem.appendChild(link);
|
||||
|
||||
if(chapter.subitems.length > 0) {
|
||||
level++;
|
||||
subitems = generateTocItems(chapter.subitems, level);
|
||||
toggle.classList.add('toc_toggle');
|
||||
|
||||
listitem.insertBefore(toggle, link);
|
||||
listitem.appendChild(subitems);
|
||||
}
|
||||
|
||||
|
||||
container.appendChild(listitem);
|
||||
|
||||
});
|
||||
|
||||
return container;
|
||||
};
|
||||
|
||||
var onShow = function() {
|
||||
$list.addClass('open');
|
||||
};
|
||||
|
||||
var onHide = function() {
|
||||
$list.removeClass('open');
|
||||
};
|
||||
|
||||
var chapterChange = function(e) {
|
||||
var id = e.id,
|
||||
$item = $list.find("#toc-"+id),
|
||||
$current = $list.find(".currentChapter"),
|
||||
$open = $list.find('.openChapter');
|
||||
|
||||
if($item.length){
|
||||
|
||||
if($item != $current && $item.has(currentChapter).length > 0) {
|
||||
$current.removeClass("currentChapter");
|
||||
}
|
||||
|
||||
$item.addClass("currentChapter");
|
||||
|
||||
// $open.removeClass("openChapter");
|
||||
$item.parents('li').addClass("openChapter");
|
||||
}
|
||||
};
|
||||
|
||||
book.on('renderer:chapterDisplayed', chapterChange);
|
||||
|
||||
var tocitems = generateTocItems(toc);
|
||||
|
||||
docfrag.appendChild(tocitems);
|
||||
|
||||
$list.append(docfrag);
|
||||
$list.find(".toc_link").on("click", function(event){
|
||||
var url = this.getAttribute('href');
|
||||
|
||||
event.preventDefault();
|
||||
|
||||
//-- Provide the Book with the url to show
|
||||
// The Url must be found in the books manifest
|
||||
book.goto(url);
|
||||
|
||||
$list.find(".currentChapter")
|
||||
.addClass("openChapter")
|
||||
.removeClass("currentChapter");
|
||||
|
||||
$(this).parent('li').addClass("currentChapter");
|
||||
|
||||
});
|
||||
|
||||
$list.find(".toc_toggle").on("click", function(event){
|
||||
var $el = $(this).parent('li'),
|
||||
open = $el.hasClass("openChapter");
|
||||
|
||||
event.preventDefault();
|
||||
if(open){
|
||||
$el.removeClass("openChapter");
|
||||
} else {
|
||||
$el.addClass("openChapter");
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
"show" : onShow,
|
||||
"hide" : onHide
|
||||
};
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue