| 1 | |
package net.sf.statcvs.pages; |
| 2 | |
|
| 3 | 0 | |
| 4 | 0 | public abstract class AbstractMarkup { |
| 5 | 0 | protected void addTwitterScript(final StringBuffer b) { |
| 6 | 0 | |
| 7 | 0 | |
| 8 | 0 | |
| 9 | 0 | b.append("<script type=\"text/javascript\" charset=\"utf-8\" src=\""); |
| 10 | 0 | b.append("http://bit.ly/javascript-api.js?version=latest&login=statsvn&apiKey=R_2c362b417d0517c27876cbaca1bb68cc"); |
| 11 | 0 | b.append("\"></script>\n"); |
| 12 | 0 | |
| 13 | 0 | |
| 14 | 0 | |
| 15 | 0 | b.append("<script type=\"text/javascript\" charset=\"utf-8\">").append("\n"); |
| 16 | 0 | b.append(" // wait until page is loaded to call API").append("\n"); |
| 17 | 0 | b.append(" var redir_url;").append("\n"); |
| 18 | 0 | b.append(" var short_url;").append("\n"); |
| 19 | 0 | b.append(" BitlyCB.myShortenCallback = function(data) {").append("\n"); |
| 20 | 0 | b.append(" // this is how to get a result of shortening a single url").append("\n"); |
| 21 | 0 | b.append(" var result;").append("\n"); |
| 22 | 0 | b.append(" short_url=null;").append("\n"); |
| 23 | 0 | b.append(" for (var r in data.results) {").append("\n"); |
| 24 | 0 | b.append(" result = data.results[r];").append("\n"); |
| 25 | 0 | b.append(" result['longUrl'] = r;").append("\n"); |
| 26 | 0 | b.append(" short_url = result['shortUrl'];").append("\n"); |
| 27 | 0 | b.append(" break;").append("\n"); |
| 28 | 0 | b.append(" }").append("\n"); |
| 29 | 0 | b.append(" if (short_url==null) // bit.ly failed").append("\n"); |
| 30 | 0 | b.append(" document.location=redir_url;").append("\n"); |
| 31 | 0 | b.append(" else").append("\n"); |
| 32 | 0 | b.append(" redirToTwitter();").append("\n"); |
| 33 | 0 | b.append(" };").append("\n"); |
| 34 | 0 | b.append(" function shortenTweet(url) {").append("\n"); |
| 35 | 0 | b.append(" if (short_url == null || redir_url!=url) {").append("\n"); |
| 36 | 0 | b.append(" redir_url = url;").append("\n"); |
| 37 | 0 | b.append(" BitlyClient.shorten(document.location, 'BitlyCB.myShortenCallback');").append("\n"); |
| 38 | 0 | b.append(" }").append("\n"); |
| 39 | 0 | b.append(" else").append("\n"); |
| 40 | 0 | b.append(" redirToTwitter();").append("\n"); |
| 41 | 0 | b.append(" return false;").append("\n"); |
| 42 | 0 | b.append(" }").append("\n"); |
| 43 | 0 | b.append(" function redirToTwitter() { ").append("\n"); |
| 44 | 0 | b.append(" // replace {0} which is visible as %7B0} in the link").append("\n"); |
| 45 | 0 | b.append(" document.location = redir_url.replace('%7B0}', short_url);").append("\n"); |
| 46 | 0 | b.append(" }").append("\n"); |
| 47 | 0 | b.append("</script>").append("\n"); |
| 48 | 0 | |
| 49 | |
|
| 50 | |
|
| 51 | |
|
| 52 | |
|
| 53 | |
|
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | 0 | |
| 62 | |
|
| 63 | |
|
| 64 | |
|
| 65 | |
|
| 66 | |
|
| 67 | 0 | } |
| 68 | 0 | } |