]> _ Git - fluidbook-html5.git/commitdiff
wip #3385
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 31 Jan 2020 14:44:09 +0000 (15:44 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 31 Jan 2020 14:44:09 +0000 (15:44 +0100)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.secure.js

index 04fdde474f77f5925a5ad108c3624541ac1153ab..fbccc0e2fdcaeb9e24d3622b29c850b0448fa19d 100644 (file)
@@ -1,5 +1,5 @@
-function Fluidbook(datas) {
-    this.init(datas);
+function Fluidbook(settings) {
+    this.init(settings);
 }
 
 // Constantes
@@ -18,21 +18,29 @@ Fluidbook.TOP = 8;
 Fluidbook.BOTTOM = 9;
 
 Fluidbook.prototype = {
-    init: function (datas) {
-
+    init: function (settings) {
         this.flags = {};
         this.canNavigate = false;
 
-        this.initSettings(datas);
-        this.singleMode = (this.datas.mobileNavigationType === 'portrait' || this.datas.mobileNavigationType === 'mobilefirst');
+        this.initSettings(settings);
+        this.secure = new FluidbookSecure(this);
 
-        this.junk = datas.cacheDate;
+        var $this = this;
+        this.secure.checkSecure(function () {
+            $this.secureOK();
+        });
+    },
+
+    secureOK: function () {
+        this.singleMode = (this.settings.mobileNavigationType === 'portrait' || this.settings.mobileNavigationType === 'mobilefirst');
+
+        this.junk = this.settings.cacheDate;
         this.networkControl = new FluidbookNetworkControl(this);
         this.input = new FluidbookInput(this);
-        if (this.datas.landingPage != undefined && this.datas.landingPage != '') {
+        if (this.settings.landingPage != undefined && this.settings.landingPage != '') {
             this.landingpage = new FluidbookLandingPage(this);
         }
-        this.secure = new FluidbookSecure(this);
+
         this.contentlock = new FluidbookContentLock(this);
         this.menu = new FluidbookMenu(this);
         this.support = new FluidbookSupport(this);
@@ -40,8 +48,8 @@ Fluidbook.prototype = {
         this.mobilefirst = new FluidbookMobileFirst(this);
         this.zoom = new FluidbookZoom(this);
         this.zoom.resetZoom();
-        this.cache = new FluidbookCache(datas);
-        this.service = new FluidbookService(this, datas.id);
+        this.cache = new FluidbookCache(this.settings);
+        this.service = new FluidbookService(this, this.settings.id);
         this.loader = new FluidbookLoader(this);
         this.pad = new FluidbookPad(this);
         this.scorm = new FluidbookScorm(this);
@@ -65,14 +73,14 @@ Fluidbook.prototype = {
         this.slideshow = new FluidbookSlideshow(this);
         this.printing = new FluidbookPrint(this);
 
-        if (this.datas.basket) {
+        if (this.settings.basket) {
             this.cart = new FluidbookCart(this);
         }
-        if (this.datas.form == 'bulle') {
+        if (this.settings.form == 'bulle') {
             this.form = new FluidbookBulleForm(this);
-        } else if (this.datas.form == 'bourbon') {
+        } else if (this.settings.form == 'bourbon') {
             this.form = new FluidbookBourbonForm(this);
-        } else if (this.datas.form == 'avery') {
+        } else if (this.settings.form == 'avery') {
             this.form = new FluidbookAveryForm(this);
         } else {
             this.form == false;
@@ -99,7 +107,7 @@ Fluidbook.prototype = {
         if (this.pad.enabled) {
             $("body").addClass('pad');
         }
-        $('html').addClass(this.datas.mobileLVersion);
+        $('html').addClass(this.settings.mobileLVersion);
         this.currentPage = -1;
         this.currentPageURL = -1;
 
@@ -117,11 +125,11 @@ Fluidbook.prototype = {
         this.initLoading();
     },
 
-    initSettings: function (datas) {
-        this.datas = datas;
+    initSettings: function (settings) {
+        this.settings = settings;
         if ($_GET['transition'] != null) {
             var map = {1: 'none', 2: 'slide', 3: 'flip', 4: 'flip3d'};
-            this.datas.mobileTransitions = map[$_GET['transition']];
+            this.settings.mobileTransitions = map[$_GET['transition']];
         }
     },
 
@@ -131,11 +139,11 @@ Fluidbook.prototype = {
 
     initTheme: function () {
         var $this = this;
-        if (this.datas.arrowsTheme) {
+        if (this.settings.arrowsTheme) {
             $('html').addClass('sharp');
         }
 
-        if (this.datas.invertMenuPosition) {
+        if (this.settings.invertMenuPosition) {
             $('html').addClass('menu-inverted');
         } else {
             $('html').addClass('menu-default');
@@ -205,7 +213,7 @@ Fluidbook.prototype = {
         }
         $(this).trigger('fluidbook.splash.beforehide');
         var $this = this;
-        if (this.support.transitions3dacc && this.datas.mobileTransitions === 'flip3d' && !this.mobilefirst.enabled) {
+        if (this.support.transitions3dacc && this.settings.mobileTransitions === 'flip3d' && !this.mobilefirst.enabled) {
             $("#main,#viewOverlay,#view").css('visibility', 'visible');
             resize();
             this.networkControl.pause(4000);
@@ -294,14 +302,14 @@ Fluidbook.prototype = {
     },
 
     loadPlugins: function () {
-        $.each(this.datas.plugins, function (k, plugin) {
+        $.each(this.settings.plugins, function (k, plugin) {
             try {
                 var functionName = plugin.replace(/\./g, '_');
                 eval(functionName + '();');
             } catch (err) {
             }
         });
-        $.each(this.datas.htmlmultimedia, function (k, code) {
+        $.each(this.settings.htmlmultimedia, function (k, code) {
             try {
                 eval(code);
             } catch (err) {
@@ -464,8 +472,8 @@ Fluidbook.prototype = {
         if (args[1] === 'closeview') {
             return this.setCurrentPage(this.currentPage);
         } else if (args[1] === 'page') {
-            if (fluidbook.datas.pageLabels[args[2]] !== undefined) {
-                page = fluidbook.datas.pageLabels[args[2]];
+            if (fluidbook.settings.pageLabels[args[2]] !== undefined) {
+                page = fluidbook.settings.pageLabels[args[2]];
             } else {
                 page = parseInt(args[2]);
             }
@@ -501,7 +509,7 @@ Fluidbook.prototype = {
             if (this.currentPage === -1) {
                 if (view === 'multimedia' || view === 'video' || view === 'iframe') {
                     var searchURL = args.join('/');
-                    $.each(this.datas.links, function (pageNr, links) {
+                    $.each(this.settings.links, function (pageNr, links) {
                         var hl = $('<root>' + links + '</root>');
                         if ($(hl).find('[href="' + searchURL + '"]').length > 0) {
                             $this.currentPage = pageNr;
@@ -547,8 +555,8 @@ Fluidbook.prototype = {
     getButtonsVisibility: function (page) {
         var max = this.contentlock.getMaxPage();
         if (this.contentlock.getMaxPage() % 2 === 1 &&
-            this.datas.mobileNavigationType !== 'portrait' &&
-            this.datas.mobileNavigationType !== 'mobilefirst' &&
+            this.settings.mobileNavigationType !== 'portrait' &&
+            this.settings.mobileNavigationType !== 'mobilefirst' &&
             this.resize.orientation !== 'portrait') {
             max--;
         }
@@ -661,14 +669,14 @@ Fluidbook.prototype = {
         return this.physicalToVirtual(physical);
     },
     clickLogo: function () {
-        if (this.datas.url_link == '' || this.datas.url_link == 'http://') {
+        if (this.settings.url_link == '' || this.settings.url_link == 'http://') {
             return;
         }
 
-        if (this.datas.url_link.indexOf('#') === 0) {
-            window.location.hash = this.datas.url_link;
+        if (this.settings.url_link.indexOf('#') === 0) {
+            window.location.hash = this.settings.url_link;
         } else {
-            this.wopen(this.datas.url_link, '_blank');
+            this.wopen(this.settings.url_link, '_blank');
         }
     },
 
@@ -690,13 +698,13 @@ Fluidbook.prototype = {
         this.waiters = [];
     },
     physicalToVirtual: function (page) {
-        return this.datas.numerotation[page - 1];
+        return this.settings.numerotation[page - 1];
     },
     virtualToPhysical: function (page) {
         if (page === undefined) {
             return false;
         }
-        var i = this.datas.numerotation.indexOf(page.toString());
+        var i = this.settings.numerotation.indexOf(page.toString());
         if (i == -1) {
             return false;
         }
@@ -727,12 +735,12 @@ Fluidbook.prototype = {
         var pdf;
         var pdfName;
 
-        if (this.datas.pages != this.contentlock.getMaxPage()) {
-            pdf = 'https://workshop.fluidbook.com/s/e/' + this.datas.cid + '/1-' + this.contentlock.getMaxPage();
-        } else if (this.datas.pdfName.substr(0, 4) === 'http') {
-            pdf = this.datas.pdfName;
+        if (this.settings.pages != this.contentlock.getMaxPage()) {
+            pdf = 'https://workshop.fluidbook.com/s/e/' + this.settings.cid + '/1-' + this.contentlock.getMaxPage();
+        } else if (this.settings.pdfName.substr(0, 4) === 'http') {
+            pdf = this.settings.pdfName;
         } else {
-            pdf = this.relativeToAbsolute('data/' + this.datas.pdfName);
+            pdf = this.relativeToAbsolute('data/' + this.settings.pdfName);
         }
         var e = pdf.split('/');
         pdfName = e.pop();
@@ -746,7 +754,7 @@ Fluidbook.prototype = {
         }
 
         var $this = this;
-        if (this.datas.phonegap != false) {
+        if (this.settings.phonegap != false) {
             if (type == undefined) {
                 var e = url.split('.');
                 type = e.pop();
@@ -827,7 +835,7 @@ Fluidbook.prototype = {
         var $this = this;
         var types_ios = {pdf: 'com.adobe.pdf'};
         var types_android = {pdf: 'application/pdf'};
-        if (this.datas.phonegap === 'ios') {
+        if (this.settings.phonegap === 'ios') {
             console.log('open download on ios ' + type + ' -> ' + types_ios[type]);
             this.displayLoader();
             if (types_ios[type] !== undefined) {
@@ -869,7 +877,7 @@ Fluidbook.prototype = {
             }
         }
 
-        if (this.datas.phonegap === 'android') {
+        if (this.settings.phonegap === 'android') {
             if (types_android[type] !== undefined) {
 
                 var errorCallback = function (e) {
@@ -988,23 +996,23 @@ Fluidbook.prototype = {
         var locationdefault = 'yes';
         var mtarget = target;
         var replace = true;
-        if (this.datas.phonegap) {
+        if (this.settings.phonegap) {
             if (target == '_unique' || target == '_new') {
                 mtarget = '_blank';
             }
         } else {
             if (target == '_new') {
-                mtarget = 'fb_' + this.datas.id + '_' + Math.round(Math.random() * 10000000);
+                mtarget = 'fb_' + this.settings.id + '_' + Math.round(Math.random() * 10000000);
                 options += ',scrollbars=yes'
             } else if (target == '_unique') {
-                mtarget = 'fb_' + this.datas.id;
+                mtarget = 'fb_' + this.settings.id;
                 options += ',scrollbars=yes'
             } else {
 
             }
         }
 
-        if (this.datas.phonegap) {
+        if (this.settings.phonegap) {
             locationdefault = 'yes';
         }
 
@@ -1014,11 +1022,11 @@ Fluidbook.prototype = {
             options += ',location=' + locationdefault;
         }
 
-        if (this.datas.phonegap && mtarget == '_blank') {
+        if (this.settings.phonegap && mtarget == '_blank') {
             options += ',zoom=yes,enableViewportScale=yes'
         }
 
-        if (!this.datas.phonegap && mtarget == '_blank') {
+        if (!this.settings.phonegap && mtarget == '_blank') {
             options = undefined;
             replace = undefined;
         }
index 4b432b4069c1386502758f8698b6f21b2e09ae27..b88fbef59ab21b0c05721451890d2155e6348d57 100644 (file)
@@ -5,19 +5,37 @@ function FluidbookSecure(fluidbook) {
 
 FluidbookSecure.prototype = {
     init: function () {
-        if (this.fluidbook.datas.restrictPrintDownload !== '') {
-            if (window.location.search.indexOf(this.fluidbook.datas.restrictPrintDownload) === -1) {
-                if (this.fluidbook.datas.restrictPrint) {
-                    this.fluidbook.datas.print = false;
+        if (this.fluidbook.settings.restrictPrintDownload !== '') {
+            if (window.location.search.indexOf(this.fluidbook.settings.restrictPrintDownload) === -1) {
+                if (this.fluidbook.settings.restrictPrint) {
+                    this.fluidbook.settings.print = false;
                 }
-                if (this.fluidbook.datas.restrictDownload) {
-                    this.fluidbook.datas.pdf = false;
+                if (this.fluidbook.settings.restrictDownload) {
+                    this.fluidbook.settings.pdf = false;
                 }
 
-                if (this.fluidbook.datas.restrictSendBookmark) {
-                    this.fluidbook.datas.bookmarkSendEnable = false;
+        var $this = this;
+        $.ajax({
+            url: $this.fluidbook.settings.secureURL,
+            success: function (data) {
+                var res = data.data[0]['logged-in'];
+                if (res !== undefined && res !== null) {
+                    if (res === true) {
+                        callback();
+                    } else if (res === false) {
+                        $this.secureNOK();
+                    }
                 }
+            },
+            error: function (e) {
+                console.log(e);
+                callback();
             }
-        }
+        });
+    },
+
+    secureNOK: function () {
+        console.warn('Auth failed');
+        //window.location = this.fluidbook.settings.secureURLRedirect;
     },
 };
\ No newline at end of file