]> _ Git - fluidbook-html5.git/commitdiff
Refactoring sharing functionality and fix bug with sharing icon. WIP #807 @1.5
authorStephen Cameron <stephen@cubedesigners.com>
Thu, 21 Sep 2017 15:41:05 +0000 (17:41 +0200)
committerStephen Cameron <stephen@cubedesigners.com>
Thu, 21 Sep 2017 15:41:05 +0000 (17:41 +0200)
js/libs/fluidbook/fluidbook.nav.js
js/libs/fluidbook/fluidbook.share.js
style/mmenu/mmenu.less

index e2f16ce354a7a7945432841ae21ba84165063d16..f04ffffead0e6e49233c56ff347fcbc6236a29df 100644 (file)
@@ -366,67 +366,14 @@ FluidbookNav.prototype = {
 
                     } else if (navType == 'menu') {
 
-                        var shareLinks = {},
-                            shareHTML = '';
-
-                        if (this.fluidbook.datas.friend) {
-                            shareLinks['email'] = 'E-mail';
-                        }
-                        if (this.fluidbook.datas.facebook) {
-                            shareLinks['facebook'] = 'Facebook';
-                        }
-                        if (this.fluidbook.datas.twitter) {
-                            shareLinks['twitter'] = 'Twitter';
-                        }
-                        if (this.fluidbook.datas.googleplus) {
-                            shareLinks['googleplus'] = 'Google Plus';
-                        }
-                        if (this.fluidbook.datas.linkedin) {
-                            shareLinks['linkedin'] = 'LinkedIn';
-                        }
-                        if (this.fluidbook.datas.viadeo) {
-                            shareLinks['viadeo'] = 'Viadeo';
-                        }
-
-                        // Generate links
-                        for (var shareType in shareLinks) {
-                            if (shareLinks.hasOwnProperty(shareType)) { // Ensure we don't get inherited properties
-                                shareHTML += '<a href="#" data-service="' + shareType + '" class="share" title="' + shareLinks[shareType] + '">';
-                                shareHTML += getSpriteIcon('interface-' + shareType);
-                                shareHTML += '</a>';
-                            }
-                        }
-
                         // Save HTML so it can be added to menu once MMenu is initialised
-                        this.shareLinksHTML = '<div id="shareLinks"><div class="share-icons">' + shareHTML + '</div></div>';
-                    }
-
+                        this.shareLinksHTML = '<div id="shareLinks"><div class="share-icons">' + this.fluidbook.share.getShareLinks(true) + '</div></div>';
 
-                    $("#share").click(function () {
-                        if ($this.fluidbook.datas.phonegap != 'android') {
-                            return true;
-                        }
-                        $this.fluidbook.share.intentShare();
-                        return false;
-                    });
+                    }
                 }
 
             } else if (icon == 'bookmark' && this.fluidbook.datas.bookmark) {
-                if (this.fluidbook.datas.bookmark) {
-                    link = this.addLink(navType, 'interface-bookmarks', '#/bookmark', 'bookmarks', 'bookmarks', 'bookmarks');
-                    $("#bookmarks").click(function () {
-                        if (!$this.fluidbook.bookmarks.hasBookmarkedPages()) {
-                            var message = $this.fluidbook.l10n.__("you don't have any bookmarks");
-                            if ($this.fluidbook.datas.phonegap) {
-                                navigator.notification.alert(message, function () {
-                                }, $this.fluidbook.l10n.__('bookmarks'));
-                            } else {
-                                window.alert(message);
-                            }
-                            return false;
-                        }
-                    });
-                }
+                link = this.addLink(navType, 'interface-bookmarks', '#/bookmark', 'bookmarks', 'bookmarks', 'bookmarks');
 
             } else if (icon == 'pdf' && this.fluidbook.datas.pdf) {
                 link = this.addLink(navType, 'interface-download', '#', 'download', 'download', 'download');
@@ -589,7 +536,7 @@ FluidbookNav.prototype = {
             if ($this.fluidbook.datas.phonegap != 'android') {
                 return true;
             }
-            $this.fluidbook.intentShare();
+            $this.fluidbook.share.intentShare();
             return false;
         });
 
index 8c9dfd5be35237ab02f40a82c53f75e24509e276..73c1f3caa365be0e140cabd7a47047f584e142fd 100644 (file)
@@ -29,11 +29,12 @@ FluidbookShare.prototype = {
         }
         return res;
     },
-    openShare: function (p1, p2, callback) {
-        
+
+    getShareLinks: function(hideLabels) {
         var shareLinks = {},
-            shareHTML = '',
-            view;
+            shareHTML = '';
+
+        hideLabels = hideLabels || false;
 
         if (this.fluidbook.datas.friend) {
             shareLinks['email'] = 'E-mail';
@@ -59,16 +60,24 @@ FluidbookShare.prototype = {
             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 += getSpriteIcon('interface-' + shareType);
-                shareHTML += ' ' + shareLinks[shareType]
+                if (!hideLabels) {
+                    shareHTML += ' ' + shareLinks[shareType];
+                }
                 shareHTML += '</a></li>';
             }
         }
 
-        view = '<div class="caption">' + this.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
+        // ToDo: tidy up CSS so we don't have to rely on unrelated class names (less likely to break in the future)
+        return '<ul class="chapters shareList">' + shareHTML + '</ul>';
+    },
+
+    openShare: function (p1, p2, callback) {
+        
+        var view;
+
+        view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + this.fluidbook.l10n.__('share') + '</h2></div>';
         view += '<div class="content">';
-        view += '<ul class="chapters shareList">';
-        view += shareHTML;
-        view += '</ul>';
+        view += this.getShareLinks();
         view += '</div>';
 
         $("#view").append('<div class="mview" data-menu="share">' + view + '</div>');
index bcbef1f69127565d71577341efc181feee67f3df..1c087f29e2b03c1f755cbf5454f224438d573f4e 100644 (file)
@@ -336,13 +336,22 @@ html.mm-opening .mm-menu.mm-opened[class*=mm-pagedim]~#mm-blocker {
     white-space: nowrap;
   }
 
-  a {
+  .shareList {
+    padding: 0;
+  }
+
+  li {
+    display: inline-block;
     padding: 0;
 
     &:not(:last-of-type) {
       margin-right: 33px;
     }
 
+    a {
+      padding: 0;
+    }
+
     img {
       margin: 0;
     }