From c7a7292e9420216233e2a973fd5365678734a458 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 13 Nov 2017 18:31:26 +0100 Subject: [PATCH] fix #1763 @3 --- js/libs/fluidbook/fluidbook.js | 26 ++++++++++++++++++------ js/libs/fluidbook/fluidbook.links.js | 30 +++++++++++++++++++++++++--- js/main.js | 15 -------------- 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 1e07f9ce..5a029ec3 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -1009,20 +1009,25 @@ Fluidbook.prototype = { options = ''; } + var locationdefault = 'yes'; var mtarget = target; + var replace = true; if (this.datas.phonegap) { - if(target=='_unique' || target=='_new') { + if (target == '_unique' || target == '_new') { mtarget = '_blank'; } } else { if (target == '_new') { - mtarget = 'fb_' + $this.fluidbook.datas.id + '_' + Math.round(Math.random() * 10000000); + mtarget = 'fb_' + this.datas.id + '_' + Math.round(Math.random() * 10000000); + options += ',scrollbars=yes' } else if (target == '_unique') { - mtarget = 'fb_' + $this.fluidbook.datas.id; + mtarget = 'fb_' + this.datas.id; + options += ',scrollbars=yes' + } else { + } } - var locationdefault = 'yes'; if (this.datas.phonegap) { locationdefault = 'yes'; } @@ -1033,9 +1038,18 @@ Fluidbook.prototype = { options += ',location=' + locationdefault; } - if (this.datas.phonegap && mtarget=='_blank') { + if (this.datas.phonegap && mtarget == '_blank') { options += ',zoom=yes,enableViewportScale=yes' } - window.open(url, mtarget, options); + // Open the window + var w = window.open(url, mtarget, options, replace); + try { + // Attempt to focus opened windows (useful for already opened windows) + if (target == '_new' || target == '_unique') { + w.focus(); + } + } catch (e) { + + } } } \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.links.js b/js/libs/fluidbook/fluidbook.links.js index 7448715c..66a006fc 100644 --- a/js/libs/fluidbook/fluidbook.links.js +++ b/js/libs/fluidbook/fluidbook.links.js @@ -37,16 +37,40 @@ FluidbookLinks.prototype = { return false; }); - $(document).on('click', 'a[href^="http"]', function (e) { - if (!navigator.onLine && $this.fluidbook.datas.phonegap) { + $(document).on('click', 'a', function () { + console.log('click link '); + console.log($(this)); + var target = $(this).attr('target'); + if (!target) { + target = '_self'; + } + var href = $(this).attr('href'); + var external = href.substr(0, 4) == 'http'; + if (href == '#') { + return true; + } + + if (!navigator.onLine && external && $this.fluidbook.datas.phonegap) { $this.fluidbook.alertInternetRequired(); e.preventDefault(); e.stopPropagation(); e.stopImmediatePropagation(); + return false; } - return true; + + if ($(this).data('type') == 16 && external) { + target = '_system'; + } + + if (target == '_self') { + return true; + } + fluidbook.wopen($(this).attr('href'), target); + return false; + }); + $(document).on('click touchend', '[data-action]', function () { var map = {'pdf': 'print', 'fullScreen': "fullscreen", 'locales': 'localesContainers'}; var action = $(this).data('action'); diff --git a/js/main.js b/js/main.js index aa8edfab..84e18241 100644 --- a/js/main.js +++ b/js/main.js @@ -380,21 +380,6 @@ try { return false; }); - $(document).on('click', 'a', function () { - if (!DATAS.phonegap) { - return true; - } - var target = $(this).attr('target'); - if ($(this).data('type') == 16 && $(this).attr('href').substr(0, 4) == 'http') { - target = '_system'; - } - if (target == '_blank' || target == '_system' || target=='_unique' || target=='_new') { - fluidbook.wopen($(this).attr('href'), target); - return false; - } - return true; - }); - $(document).trigger('fluidbookready'); $(this).trigger('fluidbook.ready'); -- 2.39.5