Permalink
Browse files

Moving over to Github.

  • Loading branch information...
0 parents commit 80dcb4c969392ccdf6fa4567118201ae05006f6e @jeresig committed Jul 9, 2009
Showing with 224 additions and 0 deletions.
  1. +19 −0 LICENSE
  2. +7 −0 README
  3. +30 −0 demos.html
  4. +168 −0 retweet.js
19 LICENSE
@@ -0,0 +1,19 @@
+Copyright (c) 2009 John Resig
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
7 README
@@ -0,0 +1,7 @@
+Easy Retweet Button
+
+More information:
+http://ejohn.org/blog/retweet/
+
+License:
+http://www.opensource.org/licenses/mit-license.php
@@ -0,0 +1,30 @@
+<html>
+<head>
+<title>Easy Retweet Button Examples</title>
+<script src="http://ejohn.org/files/retweet.js"></script>
+<style>td, th { background: #fff; color: black; font: 12px Helveitca, Arial; }
+td.r { text-align: right; }
+td { padding: 5px; }
+tr:nth-of-type(even) { background: #F5F5F5; }</style>
+</head>
+<body>
+ <p>Examples of the <a href="http://ejohn.org/blog/retweet/">Easy Retweet Button</a>.</p>
+ <h3>Simple Style</h3>
+ <table>
+ <tr><td></td><th>Sample Code</th></tr>
+ <tr><td class="r"><a class="retweet" href="http://ejohn.org/">John Resig's Blog</a></td><td><pre>&lt;a class="retweet" href="http://ejohn.org/">John Resig's Blog&lt;/a></pre><p><strong>Tweet Text:</strong> "John Resig's Blog http://bit.ly/vqYAg"</p></td></tr>
+ <tr><td class="r"><a class="retweet" href="http://jquery.com/">jQuery JavaScript Library</a></td><td><pre>&lt;a class="retweet" href="http://jquery.com/">jQuery JavaScript Library&lt;/a></pre><p><strong>Tweet Text:</strong> "jQuery JavaScript Library http://bit.ly/FGybD"</p></td></tr>
+ <tr><td class="r"><a class="retweet" href="http://google.com/" title="Google Search Engine">Google</a></td><td><pre>&lt;a class="retweet" href="http://google.com/" title="Google Search Engine">Google&lt;/a></pre><p><strong>Tweet Text:</strong> "Google Search Engine http://bit.ly/ScCbV"</p></td></tr>
+ <tr><td class="r"><a class="retweet self" href=""></a></td><td><pre>&lt;a class="retweet self" href="">&lt;/a></pre><p><strong>Tweet Text:</strong> "Easy Retweet Button Examples http://bit.ly/LrsqA"</p></td></tr>
+ </table>
+ <br style="clear:both;"/>
+ <h3>Vertical Style</h3>
+ <table>
+ <tr><td></td><th>Sample Code</th></tr>
+ <tr><td><a class="retweet vert" href="http://ejohn.org/">John Resig's Blog</a></td><td><pre>&lt;a class="retweet vert" href="http://ejohn.org/">John Resig's Blog&lt;/a></pre><p><strong>Tweet Text:</strong> "John Resig's Blog http://bit.ly/vqYAg"</p></td></tr>
+ <tr><td><a class="retweet vert" href="http://jquery.com/">jQuery JavaScript Library</a></td><td><pre>&lt;a class="retweet vert" href="http://jquery.com/">jQuery JavaScript Library&lt;/a></pre><p><strong>Tweet Text:</strong> "jQuery JavaScript Library http://bit.ly/FGybD"</p></td></tr>
+ <tr><td><a class="retweet vert" href="http://google.com/" title="Google Search Engine">Google</a></td><td><pre>&lt;a class="retweet vert" href="http://google.com/" title="Google Search Engine">Google&lt;/a></pre><p><strong>Tweet Text:</strong> "Google Search Engine http://bit.ly/ScCbV"</p></td></tr>
+ <tr><td><a class="retweet vert self" href=""></a></td><td><pre>&lt;a class="retweet vert self" href="">&lt;/a></pre><p><strong>Tweet Text:</strong> "Easy Retweet Button Examples http://bit.ly/LrsqA"</p></td></tr>
+ </table>
+</body>
+</html>
@@ -0,0 +1,168 @@
+/*
+ * Easy Retweet Button
+ * http://ejohn.org/blog/retweet/
+ * by John Resig (ejohn.org)
+ *
+ * Licensed under the MIT License:
+ * http://www.opensource.org/licenses/mit-license.php
+ */
+
+(function(){
+
+window.RetweetJS = {
+ // Your Bit.ly Username
+ bitly_user: "retweetjs",
+
+ // Your Bit.ly API Key
+ // Found here: http://bit.ly/account
+ bitly_key: "R_6287c92ecaf9efc6f39e4f33bdbf80b1",
+
+ // The text to replace the links with
+ link_text: (/windows/i.test( navigator.userAgent) ? "&#9658;" : "&#9851;") +
+ " Retweet",
+
+ // What # to show (Use "clicks" for # of clicks or "none" for nothing)
+ count_type: "clicks",
+
+ // Tweet Prefix text
+ // "RT @jeresig " would result in: "RT @jeresig Link Title http://bit.ly/asdf"
+ prefix: "",
+
+ // Style information
+ styling: "a.retweet { font: 12px Helvetica,Arial; color: #000; text-decoration: none; }" +
+ "a.retweet span { color: #FFF; background: #94CC3D; margin-left: 2px; border: 1px solid #43A52A; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 3px; }" +
+ "a.vert { display: block; text-align: center; font-size: 16px; float: left; margin: 4px; }" +
+ "a.retweet strong.vert { display: block; margin-bottom: 4px; background: #F5F5F5; border: 1px solid #EEE; -moz-border-radius: 3px; -webkit-border-radius: 3px; border-radius: 3px; padding: 3px; }" +
+ "a.retweet span.vert { display: block; font-size: 12px; margin-left: 0px; }"
+};
+
+//////////////// No Need to Configure Below Here ////////////////
+
+var loadCount = 1;
+
+// Asynchronously load the Bit.ly JavaScript API
+// If it hasn't been loaded already
+if ( typeof BitlyClient === "undefined" ) {
+ var head = document.getElementsByTagName("head")[0] ||
+ document.documentElement;
+ var script = document.createElement("script");
+ script.src = "http://bit.ly/javascript-api.js?version=latest&login=" +
+ RetweetJS.bitly_user + "&apiKey=" + RetweetJS.bitly_key;
+ script.charSet = "utf-8";
+ head.appendChild( script );
+
+ var check = setInterval(function(){
+ if ( typeof BitlyCB !== "undefined" ) {
+ clearInterval( check );
+ head.removeChild( script );
+ loaded();
+ }
+ }, 10);
+
+ loadCount = 0;
+}
+
+if ( document.addEventListener ) {
+ document.addEventListener("DOMContentLoaded", loaded, false);
+
+} else if ( window.attachEvent ) {
+ window.attachEvent("onload", loaded);
+}
+
+function loaded(){
+ // Need to wait for doc ready and js ready
+ if ( ++loadCount < 2 ) {
+ return;
+ }
+
+ var elems = [], urlElem = {}, hashURL = {};
+
+ BitlyCB.shortenResponse = function(data) {
+ for ( var url in data.results ) {
+ var hash = data.results[url].userHash;
+ hashURL[hash] = url;
+
+ var elems = urlElem[ url ];
+
+ for ( var i = 0; i < elems.length; i++ ) {
+ elems[i].href += hash;
+ }
+
+ if ( RetweetJS.count_type === "clicks" ) {
+ BitlyClient.stats(hash, 'BitlyCB.statsResponse');
+ }
+ }
+ };
+
+ BitlyCB.statsResponse = function(data) {
+ var clicks = data.results.clicks, hash = data.results.userHash;
+ var url = hashURL[ hash ], elems = urlElem[ url ];
+
+ if ( clicks > 0 ) {
+ for ( var i = 0; i < elems.length; i++ ) {
+ var strong = document.createElement("strong");
+ strong.appendChild( document.createTextNode( clicks + " " ) );
+ elems[i].insertBefore(strong, elems[i].firstChild);
+
+ if ( /(^|\s)vert(\s|$)/.test( elems[i].className ) ) {
+ elems[i].firstChild.className = elems[i].lastChild.className = "vert";
+ }
+ }
+ }
+
+ hashURL[ hash ] = urlElem[ url ] = null;
+ };
+
+ if ( document.getElementsByClassName ) {
+ elems = document.getElementsByClassName("retweet");
+ } else {
+ var tmp = document.getElementsByTagName("a");
+ for ( var i = 0; i < tmp.length; i++ ) {
+ if ( /(^|\s)retweet(\s|$)/.test( tmp[i].className ) ) {
+ elems.push( tmp[i] );
+ }
+ }
+ }
+
+ if ( elems.length && RetweetJS.styling ) {
+ var style = document.createElement("style");
+ style.type = "text/css";
+
+ try {
+ style.appendChild( document.createTextNode( RetweetJS.styling ) );
+ } catch (e) {
+ if ( style.styleSheet ) {
+ style.styleSheet.cssText = RetweetJS.styling;
+ }
+ }
+
+ document.body.appendChild( style );
+ }
+
+ for ( var i = 0; i < elems.length; i++ ) {
+ var elem = elems[i];
+
+ if ( /(^|\s)self(\s|$)/.test( elem.className ) ) {
+ elem.href = window.location;
+ elem.title = document.title;
+ }
+
+ var origText = elem.title || elem.textContent || elem.innerText,
+ href = elem.href;
+
+ elem.innerHTML = "<span>" + RetweetJS.link_text + "</span>";
+ elem.title = "";
+ elem.href = "http://twitter.com/home?status=" +
+ encodeURIComponent(RetweetJS.prefix + origText + " http://bit.ly/");
+
+ if ( urlElem[ href ] ) {
+ urlElem[ href ].push( elem );
+ } else {
+ urlElem[ href ] = [ elem ];
+ BitlyClient.shorten(href, 'BitlyCB.shortenResponse');
+ }
+ }
+
+}
+
+})();

0 comments on commit 80dcb4c

Please sign in to comment.