]> git.wh0rd.org - tt-rss.git/commitdiff
tweak display of tweet button
authorAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 09:05:48 +0000 (12:05 +0300)
committerAndrew Dolgov <fox@madoka.volgo-balt.ru>
Thu, 25 Nov 2010 09:06:09 +0000 (12:06 +0300)
functions.php
images/art-tweet.png [new file with mode: 0644]
viewfeed.js

index 6b76cea3052cda72205bcab9b52c189eb91c41b1..888af56672ea5d67dd8c23f4a8efc7f07123c14f 100644 (file)
                }
        }
 
-       function truncate_string($str, $max_len) {
+       function truncate_string($str, $max_len, $suffix = '&hellip;') {
                if (mb_strlen($str, "utf-8") > $max_len - 3) {
-                       return mb_substr($str, 0, $max_len, "utf-8") . "&hellip;";
+                       return mb_substr($str, 0, $max_len, "utf-8") . $suffix;
                } else {
                        return $str;
                }
                        print "<div id=\"PTITLE-$id\" style=\"display : none\">" . 
                                truncate_string(strip_tags($line['title']), 15) . "</div>";
 
+                       $tweet_title = htmlspecialchars(
+                               truncate_string(strip_tags($line['title']), 100, '...'));
+
+                       $tweet_link = htmlspecialchars($line['link']);
+
+                       print "<span id=\"TWEETINFO-$id\" style=\"display : none\">";
+                       print json_encode(array("title" => $tweet_title, "link" => $tweet_link));
+                       print "</span>";
+
                        print "<div class=\"postReply\" id=\"POST-$id\">";
 
                        /* print "<div dojoType=\"dijit.Menu\" style=\"display: none;\" 
                                                alt='Zoom' title='".__('Forward by email')."'>";
                                }
 
+                               if (ENABLE_TWEET_BUTTON) {
+                                       print "<img src=\"".theme_image($link, 'images/art-tweet.png')."\" 
+                                                       class='tagsPic' style=\"cursor : pointer\"
+                                                       onclick=\"tweetArticle($id)\"
+                                                       alt='Zoom' title='".__('Share on Twitter')."'>";
+                               }
+
                                print "<img src=\"".theme_image($link, 'images/digest_checkbox.png')."\" 
                                                class='tagsPic' style=\"cursor : pointer\"
                                                onclick=\"closeArticlePanel($id)\"
                        print_article_enclosures($link, $id, $always_display_enclosures, 
                                $article_content);
 
-                       $short_title = truncate_string(strip_tags($line['title']), 90);
-
-                       print "<br/><a href=\"http://twitter.com/share\" 
-                               class=\"twitter-share-button\" 
-                               data-text=\"$short_title\"
-                               data-url=\"".htmlspecialchars($line["link"])."\" 
-                               data-count=\"horizontal\">Tweet</a>";
-
                        print "</div>";
 
                        print "</div>";
                                        $short_title = truncate_string(
                                                strip_tags($line['title']), 90);
 
-                                       print "<br/><a href=\"http://twitter.com/share\" 
-                                               class=\"twitter-share-button\" 
-                                               data-text=\"$short_title\"
-                                               data-url=\"".htmlspecialchars($line["link"])."\" 
-                                               data-count=\"horizontal\">Tweet</a>";
+                                       $tweet_title = htmlspecialchars(
+                                               truncate_string(strip_tags($line['title']), 100, '...'));
+
+                                       $tweet_link = htmlspecialchars($line['link']);
+
+                                       print "<span id=\"TWEETINFO-$id\" style=\"display : none\">";
+                                       print json_encode(array("title" => $tweet_title, "link" => $tweet_link));
+                                       print "</span>";
 
                                        print "</div>";
 
                                                alt='Zoom' 
                                                title='".__('Open article in new tab')."'>";
 
+                                       $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
+
+                                       print "<img src=\"images/art-pub-note.png\"
+                                               style=\"cursor : pointer\" style=\"cursor : pointer\"
+                                               onclick=\"publishWithNote($id, '$note_escaped')\"
+                                               alt='PubNote' title='".__('Publish article with a note')."'>";
+
                                        if (DIGEST_ENABLE) {
                                                print "<img src=\"".theme_image($link, 'images/art-email.png')."\" 
                                                        style=\"cursor : pointer\"
                                                        alt='Zoom' title='".__('Forward by email')."'>";
                                        }
 
-                                       $note_escaped = htmlspecialchars($line['note'], ENT_QUOTES);
-
-                                       print "<img src=\"images/art-pub-note.png\"
-                                               style=\"cursor : pointer\" style=\"cursor : pointer\"
-                                               onclick=\"publishWithNote($id, '$note_escaped')\"
-                                               alt='PubNote' title='".__('Publish article with a note')."'>";
+                                       if (ENABLE_TWEET_BUTTON) {
+                                               print "<img src=\"".theme_image($link, 'images/art-tweet.png')."\" 
+                                                       class='tagsPic' style=\"cursor : pointer\"
+                                                       onclick=\"tweetArticle($id)\"
+                                                       alt='Zoom' title='".__('Share on Twitter')."'>";
+                                       }
 
                                        print "<img src=\"images/digest_checkbox.png\"
                                                style=\"cursor : pointer\" style=\"cursor : pointer\"
diff --git a/images/art-tweet.png b/images/art-tweet.png
new file mode 100644 (file)
index 0000000..071dfb6
Binary files /dev/null and b/images/art-tweet.png differ
index b276a3ef3e4f1db109f38d926a050f90367e0f45..602dc7724744954b7bb53c279c30b329fa646d21 100644 (file)
@@ -104,10 +104,6 @@ function headlines_callback2(transport, feed_cur_page) {
                                        dijit.byId("headlines-toolbar").attr('content',
                                                headlines_toolbar.firstChild.nodeValue);
 
-                                       $$("#headlines-frame a.twitter-share-button").each(
-                                               function(btn) { var tbtn = new twttr.TweetButton(btn); 
-                                                       tbtn.render(); });
-
                                        initHeadlinesMenu();
 
                                        var cache_prefix = "";
@@ -143,10 +139,6 @@ function headlines_callback2(transport, feed_cur_page) {
                                                c.attr('content', c.attr('content') + 
                                                        headlines_content.firstChild.nodeValue);
 
-                                               $$("#headlines-frame a.twitter-share-button").each(
-                                                       function(btn) { var tbtn = new twttr.TweetButton(btn); 
-                                                               tbtn.render(); });
-
                                                console.log("restore selected ids: " + ids);
 
                                                for (var i = 0; i < ids.length; i++) {
@@ -228,9 +220,6 @@ function render_article(article) {
 
                correctHeadlinesOffset(getActiveArticleId());           
 
-               $$("#content-insert a.twitter-share-button").each(
-                               function(btn) { var tbtn = new twttr.TweetButton(btn); tbtn.render(); });
-               
        } catch (e) {
                exception_error("render_article", e);
        }
@@ -1724,9 +1713,6 @@ function zoomToArticle(event, id) {
        
                        dijit.byId("content-tabs").addChild(article_pane);
 
-                       $$("#ATAB-"+id+" a.twitter-share-button").each(
-                                       function(btn) { var tbtn = new twttr.TweetButton(btn); tbtn.render(); });
-
                        if (!event || !event.shiftKey)
                                dijit.byId("content-tabs").selectChild(article_pane);
 
@@ -1758,10 +1744,6 @@ function zoomToArticle(event, id) {
        
                                                dijit.byId("content-tabs").addChild(article_pane);
 
-                                               $$("#ATAB-"+id+" a.twitter-share-button").each(
-                                                       function(btn) { var tbtn = new twttr.TweetButton(btn); 
-                                                               tbtn.render(); });
-
                                                if (!event || !event.shiftKey)
                                                        dijit.byId("content-tabs").selectChild(article_pane);
 
@@ -2320,3 +2302,23 @@ function initHeadlinesMenu() {
                exception_error("initHeadlinesMenu", e);
        }
 }
+
+function tweetArticle(id) {
+       try {
+               var d = new Date();
+      var ts = d.getTime();
+
+               var ti = JSON.parse($("TWEETINFO-" + id).innerHTML);
+
+               var share_url = "http://twitter.com/share?_=" + ts +
+                       "&text=" + param_escape(ti.title) + 
+                       "&url=" + param_escape(ti.link);
+
+               window.open(share_url, 'ttrss_tweet',
+                       "status=0,toolbar=0,location=0,width=500,height=400,scrollbars=1,menubar=0");
+
+
+       } catch (e) {
+               exception_error("tweetArticle", e);
+       }
+}