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