成功/失败在Google+,Pinterest,Linkedin,Twitter上分享后回拨

时间:2014-12-30 07:12:22

标签: javascript jquery angularjs twitter google-plus

我有Google+,Pinterest,LinkedIn,Twitter的自定义共享按钮。我想在各自的网站上“共享”之后需要一个回调函数,即点击弹出窗口中的分享按钮。 (不是在点击自定义按钮后)

代码如下 -

查看

     <a class="c-hand" ng-click="GooglePlusSharing(Story.Id)" title={{$root.tooltip.detailPage.shareWithGoogle}}>
                                                <i class="fa fa-google-plus"></i>
                                            </a>

        <a class="c-hand" class="pin-it-button" count-layout="horizontal" ng-click="PinterestSharing(Story.Id);" title={{$root.tooltip.detailPage.shareWithPinterest}}>
                                            <i class="fa fa-pinterest"></i>
                                        </a>
    <a class="c-hand" rel="nofollow" ng-click="LinkedInSharing(Story.Id)" onfocus="this.blur()" title={{$root.tooltip.detailPage.shareWithLkdIn}}>
                                        <i class="fa fa-linkedin"></i>
                                    </a>
 <a class="c-hand" title={{$root.tooltip.detailPage.shareWithTwitter}}>
                                    <i class="fa fa-twitter" ng-click="TwitterSharing(Story.Id)"></i>
                                </a>

控制器

           //Google+
             $scope.GooglePlusSharing = function (Id) {

                    var openwindow = window.open('https://plus.google.com/share?url=' + $scope.SiteUrl, '', 'menubar=no,toolbar=no,resizable=yes,scrollbars=yes,height=600,width=600');

                 var returnObj = StoryService.UpdateStoryGoogleSharedCount(Id);
                  returnObj.then(function (data) {

                      $scope.Story.TotalSharedCount = parseInt($scope.Story.TotalSharedCount) + 1;
                      Message.showSuccessMessage("Story shared successfully.");
                      console.log("google+ Success");

                    }, function (error) {

                       Message.showFailureMessage("There is an error while sharing story.");
                       console.log("google+ failed");
                    })

                }

        //Pinterest Sharing
        $scope.PinterestSharing = function (Id) {

            window.pinterest = window.open('http://pinterest.com/pin/create/button/?url=' + $scope.HomePageUrl + '&media=' + $scope.DetailPageImage, 'template_window', '550', '400', 'yes', 'center');

            var returnObj = StoryService.UpdateStoryPinterestSharedCount(Id);
            returnObj.then(function (data) {

                $scope.Story.TotalSharedCount = parseInt($scope.Story.TotalSharedCount) + 1;
                Message.showSuccessMessage("Story shared successfully.");
                console.log("pinterest Success");

            }, function (error) {

                Message.showFailureMessage("There is an error while sharing story.");
                console.log("pinterest failed");
            })

        }

//LinkedIn
         $scope.LinkedInSharing = function (Id) {

                var openwindow = window.open('http://www.linkedin.com/shareArticle?mini=true&url=' + $scope.SiteUrl + '&title=' + $scope.SiteTitle + '&summary=' + $scope.SiteSummary + '&source=' + $scope.SiteSource, 'template_window', '550', '400', 'yes', 'center');

                var returnObj = StoryService.UpdateStoryLinkdinSharedCount(Id);
                returnObj.then(function (data) {

                    $scope.Story.TotalSharedCount = parseInt($scope.Story.TotalSharedCount) + 1;
                    console.log("linkedIn Success");
                    Message.showSuccessMessage("Story shared successfully.");

                }, function (error) {

                    Message.showFailureMessage("There is an error while sharing story.");
                    console.log("linkedIn failed");

                })
            }
                }, function (error) {

                    Message.showFailureMessage("There is an error while sharing story.");
                    console.log("pinterest failed");
                })

            }

    //Twitter
     $scope.TwitterSharing = function (Id) {

            window.twttr = window.twttr || {}; var D = 550, A = 450, C = screen.height, B = screen.width, H = Math.round((B / 2) - (D / 2)), G = 0, F = document, E; if (C > A) { G = Math.round((C / 2) - (A / 2)) } window.twttr.shareWin = window.open('http://twitter.com/share', '', 'left=' + H + ',top=' + G + ',width=' + D + ',height=' + A + ',personalbar=0,toolbar=0,scrollbars=1,resizable=1'); E = F.createElement('script'); E.src = 'http://platform.twitter.com/bookmarklets/share.js?v=1'; F.getElementsByTagName('head')[0].appendChild(E);

            var returnObj = StoryService.UpdateStoryTwitterSharedCount(Id);
            returnObj.then(function (data) {

                $scope.Story.TotalSharedCount = parseInt($scope.Story.TotalSharedCount) + 1;
                Message.showSuccessMessage("Story shared successfully.");
                console.log("twitter Success");

            }, function (error) {

                Message.showFailureMessage("There is an error while sharing story.");
                console.log("twitter failed");
            })
        }

0 个答案:

没有答案