From: Vincent Vanwaelscappel Date: Wed, 31 Jan 2018 13:52:45 +0000 (+0100) Subject: wip #1852 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=353bd617a194a2644c391083c92781776b19c984;p=fluidbook-html5.git wip #1852 @2 --- diff --git a/js/libs/fluidbook/fluidbook.landingpage.js b/js/libs/fluidbook/fluidbook.landingpage.js index 955f94d2..388fa080 100644 --- a/js/libs/fluidbook/fluidbook.landingpage.js +++ b/js/libs/fluidbook/fluidbook.landingpage.js @@ -1,98 +1,100 @@ 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(''); + + // 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('