]> _ Git - fluidbook-html5.git/commitdiff
wip #1799 @3.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Nov 2017 16:31:55 +0000 (17:31 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 20 Nov 2017 16:31:55 +0000 (17:31 +0100)
_seo.html
js/libs/fluidbook/fluidbook.links.js
js/libs/fluidbook/fluidbook.share.js
js/libs/fluidbook/fluidbook.utils.js

index b98e2fd1156114c677162be2f6280ce80d8c954c..f7fc9e889baf3c2d371ac63dc290c11c76652bb9 100644 (file)
--- a/_seo.html
+++ b/_seo.html
@@ -11,6 +11,7 @@
        <meta name="twitter:title" content="$title">
        <meta name="twitter:description" content="$description">
        <meta name="twitter:image" content="$imageurl">
+       <meta name="twitter:site" content="@Fluidbook">
        <meta name="twitter:card" content="summary_large_image">
 </head>
 <body>
index f452db1344a4b47b18b6206bcd2c9d0e8d2c9e5c..a19ac4403096386cc9b8acdaaa8bdc199eb613c7 100644 (file)
@@ -74,6 +74,11 @@ FluidbookLinks.prototype = {
         $(document).on('click touchend', '[data-action]', function () {
             var map = {'pdf': 'print', 'fullScreen': "fullscreen", 'locales': 'localesContainers'};
             var action = $(this).data('action');
+            if(action=='share'){
+                // Let share class handle this
+                return true;
+            }
+
             if (map[action]) {
                 action = map[action];
             }
index 6f8f76aa1bb7f12b91b29865a6407768097eca24..4b7477a41c709ef89081a1a4e9976d15250b0065 100644 (file)
@@ -4,36 +4,88 @@ function FluidbookShare(fluidbook) {
         var $this = this;
         $(document).on('click', '.share', function () {
             var f = 'send' + ucfirst($(this).data('service'));
-            $this[f]();
+            var url = $(this).data("url");
+            if (url == undefined || url == null || url == 'undefined') {
+                url = '';
+            }
+            $this[f](url);
             $(this).closest('.mview').find('.back').click();
             return false;
         });
+
+        $(document).on('click touchend', '[data-action="share"]', function () {
+            $this.fluidbook.menu.openView("share", $(this).data('extra'));
+            return false;
+        });
     }
 }
 
 FluidbookShare.prototype = {
     isEnabled: function () {
-        return this.fluidbook.datas.share && this.getShareURL() !== false;
+        return this.fluidbook.datas.share && this.getShareURL('') !== false;
+    },
+
+    getFluidbookURL: function () {
+        var l = window.location.toString();
+        var e = l.split("#");
+        return e[0];
     },
 
-    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;
+    getShareURL: function (url) {
+
+        if (url == undefined || url == 'undefined' || url == null || url == false) {
+            url = '';
+        }
+        if (url == '') {
+            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 {
+                res = this.getFluidbookURL();
+            }
+            return res;
+        }
+
+        var e = url.split(':');
+        console.log(e);
+        if (e.length == 1) {
+            return relativeToAbsoluteURL(url);
+        } else {
+            if (e[0] == 'http' || e[0] == 'https') {
+                return url
+            } else if (e[0] == 'article') {
+                console.log(e[1]);
+                return relativeToAbsoluteURL('./p/' + this.getSEOArticle(e[1]).url);
             }
+        }
+    },
+
+    getShareTitle: function (url) {
+        if (url == '') {
+            return this.fluidbook.datas.title;
         } else {
-            var l = window.location.toString();
-            var e = l.split("#");
-            res = e[0];
+            var e = url.split(':');
+            if (e[0] == 'article') {
+                return this.getSEOArticle(e[1]).title;
+            }
         }
-        return res;
+        return this.fluidbook.datas.title;
+    },
+
+    getSEOArticle: function (title) {
+        return this.fluidbook.datas.seoArticles[title];
     },
 
-    getShareLinks: function (hideLabels) {
+    getShareLinks: function (hideLabels, url) {
         var shareLinks = {},
             shareHTML = '';
 
+        if (url == undefined || url == 'undefined') {
+            url == '';
+        }
+
         hideLabels = hideLabels || false;
 
         if (this.fluidbook.datas.friend) {
@@ -58,7 +110,7 @@ FluidbookShare.prototype = {
         // Generate links
         for (var shareType in shareLinks) {
             if (shareLinks.hasOwnProperty(shareType)) { // Ensure we don't get inherited properties
-                shareHTML += '<li data-level="0"><a href="#" data-service="' + shareType + '" class="share level0">';
+                shareHTML += '<li data-level="0"><a href="#" data-service="' + shareType + '" data-url="' + url + '" class="share level0">';
                 shareHTML += getSpriteIcon('share-' + shareType);
                 if (!hideLabels) {
                     shareHTML += ' ' + shareLinks[shareType];
@@ -71,13 +123,16 @@ FluidbookShare.prototype = {
         return '<ul class="chapters shareList">' + shareHTML + '</ul>';
     },
 
-    openShare: function (p1, p2, callback) {
-
+    openShare: function (url, p2, callback) {
+        console.log('open share');
         var view;
+        if (url == undefined || url == null || url == 'undefined' || !url) {
+            url = '';
+        }
 
         view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
         view += '<div class="content">';
-        view += this.getShareLinks();
+        view += this.getShareLinks(false, url);
         view += '</div>';
         ;
 
@@ -117,39 +172,32 @@ FluidbookShare.prototype = {
     },
 
 
-    sendEmail: function () {
-        window.location = 'mailto:?subject=' + encodeURIComponent(this.fluidbook.datas.title) + '&body=' + encodeURIComponent(this.fluidbook.datas.title + ' : ' + this.getShareURL());
+    sendEmail: function (url) {
+        window.location = 'mailto:?subject=' + encodeURIComponent(this.getShareTitle(url)) + '&body=' + encodeURIComponent(this.getShareTitle(url) + ' : ' + this.getShareURL(url));
         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');
+    sendTwitter: function (url) {
+        var tweet = this.fluidbook.datas.twitter_description.replace('%title%', this.getShareTitle(url))
+        tweet = tweet.replace('%short%', '');
+        tweet = tweet.replace('%url%', '');
+
+        this.fluidbook.wopen('http://twitter.com/intent/tweet?source=webclient&url=' + encodeURIComponent(this.getShareURL(url)) + '&text=' + encodeURIComponent(tweet), 'share_twitter', 'width=650,height=400');
         this.fluidbook.stats.track(13);
     },
-    sendFacebook: function () {
-        this.fluidbook.service.open('facebookShare', {
-            url: this.getShareURL()
-        }, 'width=650,height=400');
+    sendFacebook: function (url) {
+        this.fluidbook.wopen('https://www.facebook.com/sharer/sharer.php?u=' + encodeURIComponent(this.getShareURL(url)), 'share_facebook', 'width=650,height=400');
         this.fluidbook.stats.track(12);
     },
-    sendGoogleplus: function () {
-        this.fluidbook.service.open('googleplusShare', {
-            url: this.getShareURL()
-        }, 'width=650,height=400');
+    sendGoogleplus: function (url) {
+        this.fluidbook.wopen('https://plus.google.com/share?url=' + encodeURIComponent(this.getShareURL(url)), 'share_googleplus', 'width=600,height=600');
         this.fluidbook.stats.track(12);
     },
-    sendLinkedin: function () {
-        this.fluidbook.service.open('linkedinShare', {
-            url: this.getShareURL()
-        }, 'width=650,height=400');
+    sendLinkedin: function (url) {
+        this.fluidbook.wopen('https://www.linkedin.com/cws/share?url=' + encodeURIComponent(this.getShareURL(url)) + '&isFramed=true&_ts=' + Date.now(), 'share_linkedin', 'width=650,height=400');
         this.fluidbook.stats.track(12);
     },
-    sendViadeo: function () {
-        this.fluidbook.service.open('viadeoShare', {
-            url: this.getShareURL()
-        }, 'width=650,height=400');
+    sendViadeo: function (url) {
+        this.fluidbook.wopen('http://www.viadeo.com/shareit/share/?url=' + encodeURIComponent(this.getShareURL(url)), 'share_viadeo', 'width=650,height=400');
         this.fluidbook.stats.track(12);
     },
 };
\ No newline at end of file
index 5defdfd4a4d1f89c7aaa5788a87e95e5a46cc0c0..0c52a7a2317d6aea68daf9a1513c69e8e2544275 100644 (file)
@@ -1,6 +1,6 @@
 function isMobile(returnTrueIfTouch) {
-    if(returnTrueIfTouch==undefined){
-        returnTrueIfTouch=true;
+    if (returnTrueIfTouch == undefined) {
+        returnTrueIfTouch = true;
     }
     var ua = navigator.userAgent;
     var devices = ['iphone', 'ipad', 'ipod', 'droid', 'blackberry', 'mobile', 'htc', 'samsung', 'nokia', 'archos', 'galaxy', 'motorola', 'pad', 'tab', 'slate', 'motorola', 'symbian', 'phone', 'nintendo', 'playstation', 'touch', 'webos', 'ericsson'];
@@ -80,6 +80,13 @@ function getSpriteIcon(icon, attrs) {
     return '<svg ' + a.join(' ') + '><use xlink:href="#' + icon + '" /></svg>';
 }
 
+function relativeToAbsoluteURL(relative) {
+    console.log(relative);
+    var link = document.createElement("a");
+    link.href = relative;
+    return link.href;
+}
+
 function blur() {
     if ($(":focus").length > 0) {
         var tmp = document.createElement("input");
@@ -89,7 +96,7 @@ function blur() {
     }
 }
 
-function array_diff(a,b){
+function array_diff(a, b) {
     return a.filter(function (i) {
         return b.indexOf(i) < 0;
     });