From: Vincent Vanwaelscappel Date: Wed, 5 Apr 2023 16:39:14 +0000 (+0200) Subject: wait #5844 @6 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=8de0ef3c0b1a99b129253e195b303ed445dc912d;p=fluidbook-html5.git wait #5844 @6 --- diff --git a/js/libs/fluidbook/fluidbook.articles.js b/js/libs/fluidbook/fluidbook.articles.js index c274a40e..e1483253 100644 --- a/js/libs/fluidbook/fluidbook.articles.js +++ b/js/libs/fluidbook/fluidbook.articles.js @@ -165,6 +165,7 @@ FluidbookArticles.prototype = { $('iframe.pdfarticle.view').each(function () { var body = $(this).contents().find('body'); $(body).addClass('article'); + $(body).addClass('seamless'); var $this = this; setTimeout(function () { $($this).closest('.pdfarticle-holder').addClass('visible'); diff --git a/js/libs/fluidbook/fluidbook.links.js b/js/libs/fluidbook/fluidbook.links.js index 1af89aad..cd4c7163 100644 --- a/js/libs/fluidbook/fluidbook.links.js +++ b/js/libs/fluidbook/fluidbook.links.js @@ -11,6 +11,7 @@ __('add to cart') __('click to open the file') __('click to flip') + __('click to open the document') */ function FluidbookLinks(fluidbook) { diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index ed7a72dd..358a044a 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -118,6 +118,8 @@ FluidbookMenu.prototype = { this.openPrint(cb); } else if (view === 'download') { this.openDownload(cb); + } else if (view === 'pdf') { + this.openPDF(param1, cb); } else if (view === 'article') { this.fluidbook.articles.openArticle(param1, cb); } else { @@ -127,12 +129,27 @@ FluidbookMenu.prototype = { if (closeMenu) { this.fluidbook.nav.closeMenu(); } - }, openNotes: function (p1, p2, cb) { + }, + + openNotes: function (p1, p2, cb) { this.fluidbook.notes.openMenu(cb); - }, openSearch: function (q, cb) { + }, + + openSearch: function (q, cb) { this.fluidbook.nav.openSearch(q, cb); }, + openPDF: function (uid, callback) { + var infos = this.fluidbook.settings.pdfLinks[uid]; + let c = this.getCaption('', 'nocaption', 'nocaption'); + c += '
'; + this.viewWrap(c, 'pdf', '', 'pdf'); + if (callback != undefined) { + callback(); + } + this.fluidbook.displayLoader(); + }, + openingView: function (callback, view) { var $this = this; this.fluidbook.resize.resizeView(); @@ -203,7 +220,7 @@ FluidbookMenu.prototype = { var res = '
'; if (close) { - res += this.closeButton(); + res += this.closeButton(close); } if (caption !== '') { res += '

' + caption + '

'; @@ -354,7 +371,7 @@ FluidbookMenu.prototype = { }, closeButton: function (c) { - if (c == undefined) { + if (c == undefined || c === true) { c = ''; } else { c = ' ' + c; @@ -382,7 +399,8 @@ FluidbookMenu.prototype = { if (callback != undefined) { callback(); } - }, openWebVideo: function (service, video, callback) { + }, + openWebVideo: function (service, video, callback) { var hash = '#/webvideo/' + service + '/' + video; var a = $('a[href="' + hash + '"]'); var markup = decodeURIComponent($(a).attr('data-video')); @@ -398,7 +416,8 @@ FluidbookMenu.prototype = { if (callback != undefined) { callback(); } - }, openLocales: function (p1, p2, callback) { + }, + openLocales: function (p1, p2, callback) { var view = this.getCaption('Select language'); view += '
'; view += '
    '; @@ -431,7 +450,9 @@ FluidbookMenu.prototype = { openCart: function (p1, p2, callback) { this.fluidbook.cart.instance.openMenu(p1, p2, callback); - }, openShare: function (p1, p2, callback) { + }, + + openShare: function (p1, p2, callback) { this.fluidbook.share.openShare(p1, p2, callback); }, @@ -494,7 +515,9 @@ FluidbookMenu.prototype = { $('[role="radiogroup"]').AriaRadio(); callback(); } - }, openChapters: function (submenu, callback) { + }, + + openChapters: function (submenu, callback) { if (this.fluidbook.settings.externalChaptersHTML != '') { this.openExternalChapters(callback); return; @@ -532,7 +555,8 @@ FluidbookMenu.prototype = { callback(); } this.fluidbook.stats.track(14); - }, openExternalChapters: function (callback) { + }, + openExternalChapters: function (callback) { var view = this.getCaption(); view += '
    '; view += ''; @@ -544,16 +568,22 @@ FluidbookMenu.prototype = { callback(); } this.fluidbook.stats.track(14); - }, openIndex: function (title, group, closeAll, callback) { + }, + + openIndex: function (title, group, closeAll, callback) { this.index.openIndex(title, group, closeAll, callback); - }, openArchives: function (title, callback) { + }, + + openArchives: function (title, callback) { var archives = this.getCaption(title, true, title === undefined || title === '' ? 'h0' : ''); archives += '
    '; this.viewWrap(archives, 'archives', '', 'archives'); if (callback != undefined) { callback(); } - }, openText: function (text, callback) { + }, + + openText: function (text, callback) { var styleMatches = text.match(/\([^\<]*)<\/style>/); var style = ''; @@ -1044,6 +1074,23 @@ FluidbookMenu.prototype = { w = Math.min(w, this.fluidbook.settings.filesInfos.archives.width / 1.5); } break; + case 'pdf': + this.initPDFViewer(); + iframe = m.find('iframe'); + let seamless = iframe.hasClass('seamless'); + var pw = iframe.data('width') * 2; + var th = iframe.data('total-height') * 2; + + w = Math.min(pw, ww) + fullscreen = (w === ww); + ratio = pw / th; + ih = w / ratio; + h = Math.min(ih, fullscreen ? hh : hh * 0.9); + + let offsetw = seamless ? 40 : 0; + + iframe.css('height', seamless ? ih : h).css('width', w + offsetw); + break; default: if (m.data('max-width') !== null) { maxWidth = parseInt(m.data('max-width')); @@ -1184,5 +1231,30 @@ FluidbookMenu.prototype = { setTimeout(function () { $("#viewOverlay").css('opacity', 1); }, 10); - } + }, + + initPDFViewer: function () { + var menu = this; + $('iframe.pdf.view').each(function () { + var page = $(this).contents().find('div.page'); + if (page.length === 0) { + setTimeout(function () { + menu.initPDFViewer(); + }, 200); + return; + } + menu.fluidbook.hideLoader(); + var body = $(this).contents().find('body'); + if ($(this).hasClass('seamless')) { + $(body).addClass('seamless'); + } + var $this = this; + setTimeout(function () { + $($this).closest('.pdf-holder').addClass('visible'); + $($this).addClass('visible'); + menu.fluidbook.hideLoader(); + }, 500); + + }); + }, }; diff --git a/js/libs/pdfjs/custom.js b/js/libs/pdfjs/custom.js new file mode 100644 index 00000000..006bbcfb --- /dev/null +++ b/js/libs/pdfjs/custom.js @@ -0,0 +1,22 @@ +$(function () { + PDFViewerApplication.preferences.set("externalLinkTarget", 2); + $(document).on('click', 'a', function () { + let url = $(this).attr('href'); + let e = url.split(':', 2); + let protocol = e[0].toLowerCase(); + let content = e[1]; + if (['http', 'https', 'file', 'mailto', 'ftp'].indexOf(protocol) >= 0) { + return true; + } + + openCustomLink(protocol, content, url); + return false; + }); +}); + +function openCustomLink(protocol, content, url) { + var fluidbook = window.parent.fluidbook; + if (protocol === 'cart') { + window.parent.location.hash = '#/cart/add/' + content; + } +} diff --git a/style/fluidbook.less b/style/fluidbook.less index 4c4fbacc..1c7aeae6 100644 --- a/style/fluidbook.less +++ b/style/fluidbook.less @@ -1676,6 +1676,14 @@ html.ios body.portrait #interface { } } + &[data-menu="pdf"] { + iframe { + display: block; + width: 100%; + height: 100%; + } + } + &[data-menu="multimedia"], &[data-menu="webvideo"], &[data-menu="video"], &[data-menu="externalchapters"], &[data-menu="iframe"], &[data-menu="text"], &[data-menu="zoomhd"] { .caption { height: 0; @@ -1709,7 +1717,7 @@ html.ios body.portrait #interface { } // Popup with close button outside - &[data-menu="iframe"], &[data-menu="text"] { + &[data-menu="iframe"], &[data-menu="pdf"], &[data-menu="text"] { overflow: visible; a, div { @@ -3148,6 +3156,7 @@ body > input { @import "tabs.less"; @import "widget.less"; @import "menu-articles.less"; +@import "menu-pdf.less"; @import "nointerface.less"; @import "posad.less"; @import "notes.less"; diff --git a/style/menu-pdf.less b/style/menu-pdf.less new file mode 100644 index 00000000..233077b1 --- /dev/null +++ b/style/menu-pdf.less @@ -0,0 +1,23 @@ +.pdf-holder { + overflow: hidden; + opacity: 0; + transition: opacity 250ms; + + &.visible { + transition: opacity 250ms; + opacity: 1; + } + + iframe { + overflow: hidden; + width: 100%; + height: 100%; + pointer-events: auto; + opacity: 0; + transition: opacity 250ms; + &.visible { + transition: opacity 250ms; + opacity: 1; + } + } +} \ No newline at end of file