From 4a280ae879c429fb5a717b6f876fdba609f49edd Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 31 Aug 2017 16:57:52 +0200 Subject: [PATCH] #1621 --- js/libs/fluidbook/fluidbook.js | 72 +-------------- js/libs/fluidbook/fluidbook.menu.js | 32 +------ js/libs/fluidbook/fluidbook.nav.js | 4 +- js/libs/fluidbook/fluidbook.share.js | 123 +++++++++++++++++++++++++ js/libs/fluidbook/fluidbook.support.js | 3 +- js/main.js | 7 -- 6 files changed, 132 insertions(+), 109 deletions(-) create mode 100644 js/libs/fluidbook/fluidbook.share.js diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 6337f542..06ebb9b5 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -39,6 +39,7 @@ Fluidbook.prototype = { this.viewport = new FluidbookViewport(this); this.viewport.updateViewport(); this.desktop = new FluidbookDesktop(this); + this.share = new FluidbookShare(this); if (Modernizr.ftouch && this.support.transitions2d && this.datas.mobileTransitions != 'none') { this.touch = new FluidbookTouch(this); } @@ -626,9 +627,9 @@ Fluidbook.prototype = { this.hideUnnecessaryButtons(page); var animationDuration = d <= 1 ? 0 : parseFloat(this.datas.mobileTransitionDuration); this.updateShadows(page, animationDuration); - try{ + try { this.search.clearHighlights(); - }catch (err){ + } catch (err) { } }, @@ -758,50 +759,6 @@ Fluidbook.prototype = { $("#searchHints").html(''); $("#searchHints").hide(); }, - getLocationToShare: function () { - if (this.datas.phonegap) { - return this.datas.offlineLink; - } else { - var l = window.location.toString(); - var e = l.split("#"); - return e[0]; - } - }, - sendEmail: function () { - window.location = 'mailto:?subject=' + encodeURIComponent(this.datas.title) + '&body=' + encodeURIComponent(this.datas.title + ' : ' + this.getLocationToShare()); - this.stats.track(5); - }, - sendTwitter: function () { - this.service.open('twitterShare', { - url: this.getLocationToShare(), - post: this.datas.twitter_description.replace('%title%', this.datas.title) - }, 'width=650,height=400'); - this.stats.track(13); - }, - sendFacebook: function () { - this.service.open('facebookShare', { - url: this.getLocationToShare() - }, 'width=650,height=400'); - this.stats.track(12); - }, - sendGoogleplus: function () { - this.service.open('googleplusShare', { - url: this.getLocationToShare() - }, 'width=650,height=400'); - this.stats.track(12); - }, - sendLinkedin: function () { - this.service.open('linkedinShare', { - url: this.getLocationToShare() - }, 'width=650,height=400'); - this.stats.track(12); - }, - sendViadeo: function () { - this.service.open('viadeoShare', { - url: this.getLocationToShare() - }, 'width=650,height=400'); - this.stats.track(12); - }, print: function () { var $this = this; var pdf; @@ -986,30 +943,7 @@ Fluidbook.prototype = { } }, - intentShare: function (subject, body) { - if (subject == undefined) { - subject = this.datas.title; - } - if (body == undefined) { - body = this.datas.title + ' : ' + this.getLocationToShare(); - } - if (this.datas.phonegap == 'android') { - var extras = {}; - extras[window.plugins.webintent.EXTRA_SUBJECT] = subject; - extras[window.plugins.webintent.EXTRA_TEXT] = body; - window.plugins.webintent.startActivity({ - action: window.plugins.webintent.ACTION_SEND, - type: 'text/plain', - extras: extras - }, function (args) { - }, function (args) { - }); - } else { - window.location = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body); - } - this.stats.track(5); - }, wopen: function (url, target, options) { if (target == undefined) { target = '_self'; diff --git a/js/libs/fluidbook/fluidbook.menu.js b/js/libs/fluidbook/fluidbook.menu.js index c07362fb..0c981ac4 100644 --- a/js/libs/fluidbook/fluidbook.menu.js +++ b/js/libs/fluidbook/fluidbook.menu.js @@ -329,36 +329,8 @@ FluidbookMenu.prototype = { } , openShare: function (p1, p2, callback) { - var view = '
' + this.closeButton() + '

' + this.fluidbook.l10n.__('share') + '

'; - view += '
'; - view += ''; - view += '
'; - $("#view").append('
' + view + '
'); - if (callback != undefined) { - callback(); - } - } - , + this.fluidbook.share.openShare(p1,p2,callback); + }, openBookmark: function (p1, p2, callback) { var view = this.fluidbook.bookmarks.getView(); if (view !== false) { diff --git a/js/libs/fluidbook/fluidbook.nav.js b/js/libs/fluidbook/fluidbook.nav.js index 1792d367..448621eb 100644 --- a/js/libs/fluidbook/fluidbook.nav.js +++ b/js/libs/fluidbook/fluidbook.nav.js @@ -128,13 +128,13 @@ FluidbookNav.prototype = { } } } else if (icon == 'friend') { - if (this.fluidbook.datas.share) { + if (this.fluidbook.share.isEnabled()) { link = this.addLink('nav-friend', '#/share', 'share', 'share'); $("#share").click(function () { if ($this.fluidbook.datas.phonegap != 'android') { return true; } - $this.fluidbook.intentShare(); + $this.fluidbook.share.intentShare(); return false; }); } diff --git a/js/libs/fluidbook/fluidbook.share.js b/js/libs/fluidbook/fluidbook.share.js new file mode 100644 index 00000000..28d0e222 --- /dev/null +++ b/js/libs/fluidbook/fluidbook.share.js @@ -0,0 +1,123 @@ +function FluidbookShare(fluidbook) { + this.fluidbook = fluidbook; + if(this.isEnabled()){ + var $this=this; + $(document).on('click', '.share', function () { + var f = 'send' + ucfirst($(this).data('service')); + $this[f](); + $(this).closest('.mview').find('.back').click(); + return false; + }); + } +} + +FluidbookShare.prototype = { + isEnabled: function () { + return this.fluidbook.datas.share && this.getShareURL() !== false; + }, + + getShareURL: function () { + var res = false; + if (this.fluidbook.support.offline || this.fluidbook.datas.phonegap) { + if (this.fluidbook.datas.offlineLink != '' && this.fluidbook.datas.offlineLink != 'http://') { + res = this.fluidbook.datas.offlineLink; + } + } else { + var l = window.location.toString(); + var e = l.split("#"); + res = e[0]; + } + return res; + }, + openShare: function (p1, p2, callback) { + var view = '
' + this.fluidbook.menu.closeButton() + '

' + this.fluidbook.l10n.__('share') + '

'; + view += '
'; + view += ''; + view += '
'; + $("#view").append('
' + view + '
'); + if (callback != undefined) { + callback(); + } + }, + intentShare: function (subject, body) { + if (subject == undefined) { + subject = this.fluidbook.datas.title; + } + if (body == undefined) { + body = this.fluidbook.datas.title + ' : ' + this.getShareURL(); + } + + if (this.fluidbook.datas.phonegap == 'android') { + var extras = {}; + extras[window.plugins.webintent.EXTRA_SUBJECT] = subject; + extras[window.plugins.webintent.EXTRA_TEXT] = body; + window.plugins.webintent.startActivity({ + action: window.plugins.webintent.ACTION_SEND, + type: 'text/plain', + extras: extras + }, function (args) { + }, function (args) { + }); + } else { + window.location = 'mailto:?subject=' + encodeURIComponent(subject) + '&body=' + encodeURIComponent(body); + } + this.fluidbook.stats.track(5); + }, + + + sendEmail: function () { + window.location = 'mailto:?subject=' + encodeURIComponent(this.fluidbook.datas.title) + '&body=' + encodeURIComponent(this.fluidbook.datas.title + ' : ' + this.getShareURL()); + this.fluidbook.stats.track(5); + }, + sendTwitter: function () { + this.fluidbook.service.open('twitterShare', { + url: this.getShareURL(), + post: this.fluidbook.datas.twitter_description.replace('%title%', this.fluidbook.datas.title) + }, 'width=650,height=400'); + this.fluidbook.stats.track(13); + }, + sendFacebook: function () { + this.fluidbook.service.open('facebookShare', { + url: this.getShareURL() + }, 'width=650,height=400'); + this.fluidbook.stats.track(12); + }, + sendGoogleplus: function () { + this.fluidbook.service.open('googleplusShare', { + url: this.getShareURL() + }, 'width=650,height=400'); + this.fluidbook.stats.track(12); + }, + sendLinkedin: function () { + this.fluidbook.service.open('linkedinShare', { + url: this.getShareURL() + }, 'width=650,height=400'); + this.fluidbook.stats.track(12); + }, + sendViadeo: function () { + this.fluidbook.service.open('viadeoShare', { + url: this.getShareURL() + }, 'width=650,height=400'); + this.fluidbook.stats.track(12); + }, +}; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.support.js b/js/libs/fluidbook/fluidbook.support.js index cc8bc2eb..9be43a4b 100644 --- a/js/libs/fluidbook/fluidbook.support.js +++ b/js/libs/fluidbook/fluidbook.support.js @@ -4,7 +4,8 @@ function FluidbookSupport(fluidbook) { this.android = this.fitScreenAtZero = this.userAgent.search(/android/i) > -1 || this.userAgent.search(/galaxy/i) > -1; this.android3 = this.android && this.userAgent.search(/android 3/i) > -1; this.iOS = this.userAgent.search(/ipad/i) > -1 || this.userAgent.search(/iphone/i) > -1 || this.userAgent.search(/ipod/i) > -1; - this.offline = typeof process !== "undefined" && process.versions['node-webkit']; + // If in node-webkit or if the index.html fluidbook is locally open in a browser + this.offline = (typeof process !== "undefined" && process.versions['node-webkit']) || window.location.toString().indexOf("file://") == 0; switch (this.fluidbook.datas.mobileVersion) { case 'html5': diff --git a/js/main.js b/js/main.js index 7f5e7d8c..5c8334b8 100644 --- a/js/main.js +++ b/js/main.js @@ -386,13 +386,6 @@ try { return false; }); - $(document).on('click', '.share', function () { - var f = 'send' + ucfirst($(this).data('service')); - fluidbook[f](); - $(this).closest('.mview').find('.back').click(); - return false; - }); - $(document).on('click', 'a', function () { if (!DATAS.phonegap) { return true; -- 2.39.5