]> _ Git - fluidbook-html5.git/commitdiff
wait #5844 @6
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Apr 2023 16:39:14 +0000 (18:39 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 5 Apr 2023 16:39:14 +0000 (18:39 +0200)
js/libs/fluidbook/fluidbook.articles.js
js/libs/fluidbook/fluidbook.links.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/pdfjs/custom.js [new file with mode: 0644]
style/fluidbook.less
style/menu-pdf.less [new file with mode: 0644]

index c274a40e660f64c253313be580d8746c018e7fb4..e1483253251ff01fbe7975c639b0bdbd215771bd 100644 (file)
@@ -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');
index 1af89aadf8568efe712e303f4ec89d927f495a89..cd4c7163479a92905c0feed3839014f26663aa12 100644 (file)
@@ -11,6 +11,7 @@
  __('add to cart')
  __('click to open the file')
  __('click to flip')
+ __('click to open the document')
  */
 
 function FluidbookLinks(fluidbook) {
index ed7a72dd0e4aa0d0978febf4f55a27be42bf41b5..358a044ad9f95afe1b8baa5ee16e552c51dc856b 100644 (file)
@@ -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 += '<div class="content"><div class="pdf-holder"><iframe class="pdf view ' + infos.interface + '" data-width="' + infos.width + '" data-height="' + infos.height + '" data-total-height="' + infos.totalHeight + '" frameborder="0" scrolling="no" src="pdfjs/web/viewer.html?&file=../../data/links/' + infos.file + '#zoom=page-width"></iframe></div></div>';
+        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 = '<div class="caption ' + cls + '">';
         if (close) {
-            res += this.closeButton();
+            res += this.closeButton(close);
         }
         if (caption !== '') {
             res += '<h2 id="mview-dialog-title">' + caption + '</h2>';
@@ -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 += '<div class="content">';
         view += '<ul class="chapters localesList">';
@@ -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 += '<div class="content"><div class="multimediaHolder"><div class="multimediaScale">';
         view += '<iframe data-width="' + this.fluidbook.settings.externalChaptersSize.width + '" data-height="' + this.fluidbook.settings.externalChaptersSize.height + '"  width="' + this.fluidbook.settings.externalChaptersSize.width + '" height="' + this.fluidbook.settings.externalChaptersSize.height + '" src="data/chapters/index.html" frameborder="0" marginwidth="0" marginheight="0" scrolling="no" allowfullscreen mozallowfullscreen="true" webkitallowfullscreen="true" onmousewheel=""></iframe>';
@@ -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 += '<div class="content"><div class="image" id="archivesview"><img src="data/images/' + this.fluidbook.settings.externalArchives + '" /><div class="links">' + this.fluidbook.loader.handleExtension(this.fluidbook.settings.links.archives) + '</div></div></div>';
         this.viewWrap(archives, 'archives', '', 'archives');
         if (callback != undefined) {
             callback();
         }
-    }, openText: function (text, callback) {
+    },
+
+    openText: function (text, callback) {
         var styleMatches = text.match(/\<style\>([^\<]*)<\/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 (file)
index 0000000..006bbcf
--- /dev/null
@@ -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;
+    }
+}
index 4c4fbaccb54a4a18513aa006ff71de27cf50daa9..1c7aeae698e5df0df7f68c396932c4616eab5010 100644 (file)
@@ -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 (file)
index 0000000..233077b
--- /dev/null
@@ -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