]> _ Git - fluidbook-html5.git/commitdiff
#1621
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 31 Aug 2017 14:57:52 +0000 (16:57 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 31 Aug 2017 14:57:52 +0000 (16:57 +0200)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.menu.js
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.share.js [new file with mode: 0644]
js/libs/fluidbook/fluidbook.support.js
js/main.js

index 6337f5428c278ef2e9689f8138c96dc396d58ac7..06ebb9b58fd04054835a76c4d6138b4759382dc6 100644 (file)
@@ -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';
index c07362fba96e02b7689924d94b890be600ee9c9e..0c981ac428ace59b19eb81c0c3a8814ab7869067 100644 (file)
@@ -329,36 +329,8 @@ FluidbookMenu.prototype = {
     }
     ,
     openShare: function (p1, p2, callback) {
-        var view = '<div class="caption">' + this.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
-        view += '<div class="content">';
-        view += '<ul class="chapters shareList">';
-        var $this = this;
-        if (this.fluidbook.datas.friend) {
-            view += '<li data-level="0"><a href="#" data-service="email" class="share level0"><img height="25" src="data/images/share-email.svg" /> E-mail</a></li>';
-        }
-        if (this.fluidbook.datas.facebook) {
-            view += '<li data-level="0"><a href="#" data-service="facebook" class="share level0"><img height="25" src="data/images/share-facebook.svg" /> Facebook</a></li>';
-        }
-        if (this.fluidbook.datas.twitter) {
-            view += '<li data-level="0"><a href="#" data-service="twitter" class="share level0"><img height="25" src="data/images/share-twitter.svg" /> Twitter</a></li>';
-        }
-        if (this.fluidbook.datas.googleplus) {
-            view += '<li data-level="0"><a href="#" data-service="googleplus" class="share level0"><img height="25" src="data/images/share-googleplus.svg" /> Google+</a></li>';
-        }
-        if (this.fluidbook.datas.linkedin) {
-            view += '<li data-level="0"><a href="#" data-service="linkedin" class="share level0"><img height="25" src="data/images/share-linkedin.svg" /> LinkedIn</a></li>';
-        }
-        if (this.fluidbook.datas.viadeo) {
-            view += '<li data-level="0"><a href="#" data-service="viadeo" class="share level0"><img height="25" src="data/images/share-viadeo.svg" /> Viadeo</a></li>';
-        }
-        view += '</ul>';
-        view += '</div>';
-        $("#view").append('<div class="mview" data-menu="share">' + view + '</div>');
-        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) {
index 1792d367daab8bb96c3fcb2504bc2ef27cc3214c..448621eb58924e561c84906b8fbc06a357f7ae69 100644 (file)
@@ -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 (file)
index 0000000..28d0e22
--- /dev/null
@@ -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 = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
+        view += '<div class="content">';
+        view += '<ul class="chapters ' +
+            'shareList">';
+        if (this.fluidbook.datas.friend) {
+            view += '<li data-level="0"><a href="#" data-service="email" class="share level0"><img height="25" src="data/images/share-email.svg" /> E-mail</a></li>';
+        }
+        if (this.fluidbook.datas.facebook) {
+            view += '<li data-level="0"><a href="#" data-service="facebook" class="share level0"><img height="25" src="data/images/share-facebook.svg" /> Facebook</a></li>';
+        }
+        if (this.fluidbook.datas.twitter) {
+            view += '<li data-level="0"><a href="#" data-service="twitter" class="share level0"><img height="25" src="data/images/share-twitter.svg" /> Twitter</a></li>';
+        }
+        if (this.fluidbook.datas.googleplus) {
+            view += '<li data-level="0"><a href="#" data-service="googleplus" class="share level0"><img height="25" src="data/images/share-googleplus.svg" /> Google+</a></li>';
+        }
+        if (this.fluidbook.datas.linkedin) {
+            view += '<li data-level="0"><a href="#" data-service="linkedin" class="share level0"><img height="25" src="data/images/share-linkedin.svg" /> LinkedIn</a></li>';
+        }
+        if (this.fluidbook.datas.viadeo) {
+            view += '<li data-level="0"><a href="#" data-service="viadeo" class="share level0"><img height="25" src="data/images/share-viadeo.svg" /> Viadeo</a></li>';
+        }
+        view += '</ul>';
+        view += '</div>';
+        $("#view").append('<div class="mview" data-menu="share">' + view + '</div>');
+        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
index cc8bc2ebc0873a47672ac6d394d47bf173300d54..9be43a4be9b7b7fb9380892376a696f6713bc464 100644 (file)
@@ -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':
index 7f5e7d8c123d16a9ea8aee5af173badc42c6e1cd..5c8334b8f4e81417a8daa7ba9684425035d82677 100644 (file)
@@ -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;