]> _ Git - fluidbook-html5.git/commitdiff
wip #1852 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 31 Jan 2018 13:52:45 +0000 (14:52 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 31 Jan 2018 13:52:45 +0000 (14:52 +0100)
js/libs/fluidbook/fluidbook.landingpage.js
js/libs/fluidbook/fluidbook.nav.js

index 955f94d2fdfabd6144c005846aa7dbee8c87b6f3..388fa08001ec6ab3b5220aa18e197d5d7323c164 100644 (file)
 function FluidbookLandingPage(fluidbook) {
-  this.fluidbook = fluidbook;
-  this.hasLandingPage = false;
-  this.init();
+    this.fluidbook = fluidbook;
+    this.hasLandingPage = false;
+    this.init();
 }
 
 FluidbookLandingPage.prototype = {
 
-  init: function () {
-    var $this = this;
+    init: function () {
+        var $this = this;
+
+        if (this.fluidbook.datas.landingPage != undefined && this.fluidbook.datas.landingPage != '') {
+            this.hasLandingPage = true;
+        }
+
+        setTimeout(function () {
+            $this.setupLandingPage();
+        }, 10);
+
+        // When the splash page hides, we are ready to show the landing page (if one exists)
+        // $(this.fluidbook).on('fluidbook.ready', function() {
+        //   setTimeout($this.show, 500);
+        // });
+
+    },
+
+    setupLandingPage: function () {
+        var $this = this;
+
+        if (this.hasLandingPage) {
+            // window.location.hash = '/landing'; // handled by fluidbook.changeAddress()
+
+            $("#landingPage").html('<iframe id="landingPageIframe" width="100%" height="100%" frameborder="0" src="data/landing-page/index.html"></iframe>');
+
+            // Click handler for all links inside iframe
+            // We must wait for the iframe to load before we can add a listener to the document
+            $('#landingPageIframe').on('load', function () {
+                $(this).contents().on('click', 'a', $this.handleLink);
+            });
+        }
+    },
+
+    handleLink: function (event) {
+
+
+        //## Handle possible link types:
+
+        // 1. Link to a page (data-page attribute)
+        if ($(this).data('page') !== undefined) {
+            fluidbook.landingpage.hide();
+            fluidbook.setCurrentPage(parseInt($(this).data('page')));
+        }
+
+        // 2. Link to a Fluidbook internal link ID (data-link attribute)
+        else if ($(this).data('link') !== undefined) {
+            fluidbook.landingpage.hide();
+            var link = $('[data-id="' + $(this).data('link') + '"] a');
+            if (link.length > 0) {
+                window.location.hash = link.attr('href');
+            }
+        }
+
+        // 3. Other / external link (open new window)
+        else {
+            var href = $(this).attr('href');
+            // Local / internal link
+            if (href.indexOf('#') === 0) {
+                event.preventDefault();
+                window.location.hash = href;
+                fluidbook.landingpage.hide();
+                // External link
+            } else {
+                // ToDo: figure out how to handle this properly with security restrictions
+                window.open(href, '_blank');
+            }
+        }
 
-    if (this.fluidbook.datas.landingPage != undefined && this.fluidbook.datas.landingPage != '') {
-      this.hasLandingPage = true;
-    }
-
-    setTimeout(function(){$this.setupLandingPage();}, 10);
-
-    // When the splash page hides, we are ready to show the landing page (if one exists)
-    // $(this.fluidbook).on('fluidbook.ready', function() {
-    //   setTimeout($this.show, 500);
-    // });
-
-  },
-
-  setupLandingPage: function () {
-    var $this = this;
-
-    if (this.hasLandingPage) {
-      // window.location.hash = '/landing'; // handled by fluidbook.changeAddress()
-
-      $("#landingPage").html('<iframe id="landingPageIframe" src="data/landing-page/index.html">');
-
-      // Click handler for all links inside iframe
-      // We must wait for the iframe to load before we can add a listener to the document
-      $('#landingPageIframe').on('load', function () {
-        $(this).contents().on('click', 'a', $this.handleLink);
-      });
-    }
-  },
-
-  handleLink: function (event) {
-
-
-    //## Handle possible link types:
-
-    // 1. Link to a page (data-page attribute)
-    if ($(this).data('page') !== undefined) {
-      fluidbook.landingpage.hide();
-      fluidbook.setCurrentPage(parseInt($(this).data('page')));
-    }
-
-    // 2. Link to a Fluidbook internal link ID (data-link attribute)
-    else if ($(this).data('link') !== undefined) {
-      fluidbook.landingpage.hide();
-      var link = $('[data-id="' + $(this).data('link') + '"] a');
-      if (link.length > 0) {
-        window.location.hash = link.attr('href');
-      }
-    }
-
-    // 3. Other / external link (open new window)
-    else {
-      var href = $(this).attr('href');
-      // Local / internal link
-      if (href.indexOf('#') === 0) {
         event.preventDefault();
-        window.location.hash = href;
-        fluidbook.landingpage.hide();
-        // External link
-      } else {
-        // ToDo: figure out how to handle this properly with security restrictions
-        window.open(href, '_blank');
-      }
-    }
+        return false;
 
-    event.preventDefault();
-    return false;
+    },
 
-  },
+    hide: function () {
+        $('#landingPage').removeClass('visible');
+    },
 
-  hide: function () {
-    $('#landingPage').removeClass('visible');
-  },
+    show: function () {
+        $('#landingPage').addClass('visible');
+    },
 
-  show: function () {
-    $('#landingPage').addClass('visible');
-  },
+    resize: function (w, h) {
+        if (!this.hasLandingPage) {
+            return;
+        }
 
-  resize: function (w, h) {
-    if (!this.hasLandingPage) {
-      return;
-    }
+        console.log('TODO: landing page resize...');
 
-    console.log('TODO: landing page resize...');
-
-  }
+    }
 };
 
index 16fe13fa4d8706a67dd4503d0f32b25e31f7a660..c9b63f917a1c1a5df55156de0a44a99dfd034169 100644 (file)
@@ -124,7 +124,6 @@ FluidbookNav.prototype = {
     //     return this.fluidbook.loader.getImage(src, this._dimensions[name][0], this._dimensions[name][1]);
     // },
     addLink: function (navType, name, href, id, title, help, before, className, showIcon) {
-
         var $nav = this.getNavFromType(navType),
             elementID = navType + '_' + id;
 
@@ -138,7 +137,7 @@ FluidbookNav.prototype = {
         } else {
             $nav.find("ul #" + before).before(li);
         }
-        return l;
+        return $("#" + elementID).get(0);
     },
     getLink: function (name, href, id, title, help, className, showIcon, navType) {
         if (showIcon == undefined) {
@@ -315,6 +314,8 @@ FluidbookNav.prototype = {
             navOrder.push(navOrder.splice(localeIconIndex, 1)[0]); // Push to end of array
         }
 
+        var $this = this;
+
         for (var i in navOrder) {
             var icon = navOrder[i];
             //var visible = hide.indexOf(icon) == -1;
@@ -324,6 +325,7 @@ FluidbookNav.prototype = {
             if (icon == 'home' && !skipHome) {
 
                 var homeURL = this.fluidbook.datas.home;
+                var homeRequireLoader = true;
                 if (this.fluidbook.datas.home == '%apphome%' || forceHome && DATAS.phonegap) {
                     homeURL = decodeURIComponent(window.localStorage.getItem('apphome'));
                 }
@@ -335,6 +337,9 @@ FluidbookNav.prototype = {
                         $_GET['home'] = decodeURIComponent($_GET['home']);
                     }
                     homeURL = $_GET['home'];
+                } else if (this.fluidbook.landingpage.hasLandingPage) {
+                    homeURL = '#/landing';
+                    homeRequireLoader = false;
                 }
                 try {
                     if (homeURL != '') {
@@ -344,14 +349,20 @@ FluidbookNav.prototype = {
 
                 }
 
-                $('#home').on('click', function () {
-                    var $this = this;
-                    fluidbook.displayLoader();
-                    setTimeout(function () {
-                        window.location = $($this).attr('href');
-                    }, 500);
+                $(link).on('click', function () {
+                    if (homeRequireLoader) {
+                        var $thislink = this;
+                        fluidbook.displayLoader();
+                        setTimeout(function () {
+                            window.location = $($thislink).attr('href');
+                        }, 500);
+                    } else {
+                        $this.menuAPI.close();
+                        window.location = $(this).attr('href');
+                    }
                     return false;
-                })
+                });
+
             } else if (icon == 'index') {
                 link = this.addLink(navType, 'nav-index', '#/index', 'index', 'overview', 'overview');
             } else if (icon == 'chapters') {
@@ -459,7 +470,6 @@ FluidbookNav.prototype = {
                 var extraIcon = DATAS['navExtraIcon' + n];
                 var extraVisibility = DATAS['navExtraVisibility' + n];
                 var extraType = DATAS['navExtraType' + n];
-                console.log(extraURL + ';' + extraIcon + ';' + extraVisibility + ';' + extraType);
                 if (extraURL == '' || extraIcon == '') {
                     continue;
                 }
@@ -515,7 +525,6 @@ FluidbookNav.prototype = {
                     if (foundLink == undefined) {
                         continue;
                     }
-                    console.log(foundLink);
                     link = $(foundLink).find('a').append(linkIcon);
                     if (navType == 'menu' && extraType == 'icon') {
                         var tooltip = $(link).data('tooltip');
@@ -581,7 +590,6 @@ FluidbookNav.prototype = {
         if (this.fluidbook.datas.afterSearch != '' && this.fluidbook.datas.afterSearchDisplayForHTML && this.fluidbook.datas.themeEnableAfterSearch && navType == 'horizontalNav') {
             // Use the "afterSearch" image and links set in the theme and link editor
             var afterSearchContent = '<div id="afterSearch"><div class="c">' + this.fluidbook.loader.getImage('data/images/' + this.fluidbook.datas.afterSearch) + '</div><div class="links">' + this.fluidbook.datas.links.aftersearch + '</div></li>';
-            console.log('insert ' + afterSearchContent);
             $nav.after(afterSearchContent);
         }