2 JUITTER 1.0.0 - 22/07/2009 - http://juitter.com
\r
3 BY RODRIGO FANTE - http://rodrigofante.com
\r
5 ** jQuery 1.2.* or higher required
\r
7 Juitter is distributed under the MIT License
\r
8 Read more about the MIT License --> http://www.opensource.org/licenses/mit-license.php
\r
10 This script is just a beta test version, download and use it at your own risk.
\r
11 The Juitter developer shall have no responsability for data loss or damage of any kind by using this script.
\r
15 // JUITTER DEFAULT CONFIGURATION ========================
\r
16 // YOU CAN CHANGE THE DYNAMIC VARS ON CALLING THE start method, see the system.js for more information about it.
\r
18 numMSG = 20; // set the number of messages to be show
\r
19 containerDiv="tweets", // //Set a place holder DIV which will receive the list of tweets example <div id="juitterContainer"></div>
\r
20 loadMSG="Loading messages...", // Loading message, if you want to show an image, fill it with "image/gif" and go to the next variable to set which image you want to use on
\r
21 imgName="loader.gif", // Loading image, to enable it, go to the loadMSG var above and change it to "image/gif"
\r
22 readMore="Read it on Twitter", // read more message to be show after the tweet content
\r
23 nameUser="image" // insert "image" to show avatar of "text" to show the name of the user that sent the tweet
\r
24 live:"live-20", //optional, disabled by default, the number after "live-" indicates the time in seconds to wait before request the Twitter API for updates, I do not recommend to use less than 60 seconds.
\r
25 // end of configuration
\r
29 var mode,param,time,lang,contDiv,loadMSG,gifName,numMSG,readMore,fromID,ultID,filterWords;
\r
32 apifMultipleUSER = "http://search.twitter.com/search.json?from%3A";
\r
33 apifUSER = "http://search.twitter.com/search.json?q=from%3A";
\r
34 apitMultipleUSER = "http://search.twitter.com/search.json?to%3A";
\r
35 apitUSER = "http://search.twitter.com/search.json?q=to%3A";
\r
36 apiSEARCH = "http://search.twitter.com/search.json?q=";
\r
38 registerVar: function(opt){
\r
39 mode=opt.searchType;
\r
40 param=opt.searchObject;
\r
42 lang=opt.lang?opt.lang:"";
\r
43 contDiv=opt.placeHolder?opt.placeHolder:containerDiv;
\r
44 loadMSG=opt.loadMSG?opt.loadMSG:loadMSG;
\r
45 gifName=opt.imgName?opt.imgName:imgName;
\r
46 numMSG=opt.total?opt.total:numMSG;
\r
47 readMore=opt.readMore?opt.readMore:readMore;
\r
48 fromID=opt.nameUser?opt.nameUser:nameUser;
\r
49 filterWords=opt.filter;
\r
50 openLink=opt.openExternalLinks?"target='_self'":"";
\r
52 start: function(opt) {
\r
54 if($("#"+contDiv)){
\r
55 this.registerVar(opt);
\r
56 // show the load message
\r
58 // create the URL to be request at the Twitter API
\r
59 aURL = this.createURL();
\r
60 // query the twitter API and create the tweets list
\r
61 this.conectaTwitter(1);
\r
62 // if live mode is enabled, schedule the next twitter API query
\r
63 if(timer!=undefined&&!running) this.temporizador();
\r
67 this.conectaTwitter(2);
\r
68 if(timer!=undefined) this.temporizador();
\r
70 loading: function(){
\r
71 if(loadMSG=="image/gif"){
\r
73 .attr('src', gifName)
\r
74 .appendTo("#"+contDiv);
\r
75 } else $("#"+contDiv).html(loadMSG);
\r
77 createURL: function(){
\r
79 jlg=lang.length>0?"&lang="+lang:jlg="";
\r
80 var seachMult = param.search(/,/);
\r
81 if(seachMult>0) param = "&ors="+param.replace(/,/g,"+");
\r
82 if(mode=="fromUser" && seachMult<=0) url=apifUSER+param;
\r
83 else if(mode=="fromUser" && seachMult>=0) url=apifMultipleUSER+param;
\r
84 else if(mode=="toUser" && seachMult<=0) url=apitUSER+param;
\r
85 else if(mode=="toUser" && seachMult>=0) url=apitMultipleUSER+param;
\r
86 else if(mode=="searchWord") url=apiSEARCH+param+jlg;
\r
87 url += "&rpp="+numMSG;
\r
90 delRegister: function(){
\r
91 // remove the oldest entry on the tweets list
\r
95 if(o>=numMSG) $(this).hide("slow");
\r
100 conectaTwitter: function(e){
\r
101 // query the twitter api and create the tweets list
\r
107 error: function(){ $("#"+contDiv).html("fail#"); },
\r
108 success: function(json){
\r
109 if(e==1) $("#"+contDiv).html("");
\r
110 $.each(json.results,function(i,item) {
\r
111 if(e==1 || (i<numMSG && item.id>ultID)){
\r
115 .attr('id', 'twittList'+ultID)
\r
116 .attr('class','twittList rounded')
\r
117 .prependTo("#"+contDiv);
\r
119 if (item.text != "undefined") {
\r
120 var link = "http://twitter.com/"+item.from_user+"/status/"+item.id;
\r
122 var tweet = $.Juitter.filter(item.text);
\r
124 if(fromID=="image") mHTML="<a href='http://www.twitter.com/"+item.from_user+"'><img src='"+item.profile_image_url+"' alt='"+item.from_user+"' class='juitterAvatar' /></a> "+$.Juitter.textFormat(tweet)+" <a href='" + link + "' class='jRM' "+openLink+"><span class='time'>» "+item.created_at+"</span></a>";
\r
125 else mHTML="<a href='http://www.twitter.com/"+item.from_user+"'>@"+item.from_user+":</a> "+$.Juitter.textFormat(tweet)+" <a href='" + link + "' "+openLink+"><span class='time'>» "+item.created_at+"</span></a>";
\r
129 .attr('id', 'twittLI'+msgNb)
\r
130 .attr('class', 'twittLI')
\r
131 .appendTo("#twittList"+ultID);
\r
133 $('#twittLI'+msgNb).hide();
\r
134 $('#twittLI'+msgNb).show("slow");
\r
136 // remove old entries
\r
137 $.Juitter.delRegister();
\r
146 filter: function(s){
\r
148 searchWords = filterWords.split(",");
\r
149 if(searchWords.length>0){
\r
151 $.each(searchWords,function(i,item){
\r
152 sW = item.split("->").length>0 ? item.split("->")[0] : item;
\r
153 rW = item.split("->").length>0 ? item.split("->")[1] : "";
\r
154 regExp=eval('/'+sW+'/gi');
\r
155 cleanHTML = cleanHTML.replace(regExp, rW);
\r
157 } else cleanHTML = s;
\r
161 textFormat: function(texto){
\r
163 var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
\r
164 texto = texto.replace(exp,"<a href='$1' class='extLink' "+openLink+">$1</a>");
\r
165 var exp = /[\@]+([A-Za-z0-9-_]+)/ig;
\r
166 texto = texto.replace(exp,"<a href='http://twitter.com/$1' class='profileLink'>@$1</a>");
\r
167 var exp = /[\#]+([A-Za-z0-9-_]+)/ig;
\r
168 texto = texto.replace(exp,"<a href='http://juitter.com/#$1' onclick='$.Juitter.start({searchType:\"searchWord\",searchObject:\"$1\"});return false;' class='hashLink'>#$1</a>");
\r
170 if(mode=="searchWord"){
\r
171 tempParam = param.replace(/&ors=/,"");
\r
172 arrParam = tempParam.split("+");
\r
173 $.each(arrParam,function(i,item){
\r
174 regExp=eval('/'+item+'/gi');
\r
175 newString = new String(''+item+'');
\r
176 texto = texto.replace(regExp, newString);
\r
181 temporizador: function(){
\r
184 aTim = timer.split("-");
\r
185 if(aTim[0]=="live" && aTim[1].length>0){
\r
186 tempo = aTim[1]*1000;
\r
187 setTimeout("$.Juitter.update()",tempo);
\r