PageRenderTime 25ms CodeModel.GetById 19ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/source/app/NOS.Wiki/Themes/NOS/includes/a2 - monitter.js

http://github.com/agross/netopenspace
JavaScript | 104 lines | 90 code | 14 blank | 0 comment | 6 complexity | fd0774730a645d86712641e984b5cb3d MD5 | raw file
  1var monitter =
  2{
  3	init: function()
  4	{
  5		jQuery.fn.reverse = Array.prototype.reverse;
  6
  7		String.prototype.linkify = function () {
  8			return this.replace(/[a-z]+:\/\/[a-z0-9-_]+\.[a-z0-9-_:%&\?\/.=]+/gi, function (m) {
  9				return m.link(m);
 10			});
 11		};
 12
 13		String.prototype.linkuser = function () {
 14			return this.replace(/@[\w-äöüß]+/gi, function (u) {
 15				var username = u.replace("@", "")
 16				return u.link("http://twitter.com/" + username);
 17			});
 18		};
 19
 20		String.prototype.linktag = function () {
 21			return this.replace(/#[\w-äöüß]+/gi, function (t) {
 22				var tag = t.replace("#", "%23")
 23				return t.link("http://search.twitter.com/search?q=" + tag);
 24			});
 25		};
 26	},
 27	
 28	fetchTweets: function(element, params) {
 29		element = $(element);
 30		query = params.query.replace(/#/g, '%23');
 31		
 32		if (!params.lastId)
 33		{
 34			params.lastId = 0;
 35		}
 36		
 37		var url = "http://search.twitter.com/search.json?include_entities=1&q=" + query + "&rpp=" + params.limit + "&since_id=" +  params.lastId + "&callback=?";
 38	
 39		$.jsonp({
 40			url: url,
 41			timeout: params.timeout,
 42			success: function(json, textStatus)
 43			{
 44				$(json.results).reverse().each(function() {
 45					if ($('#tw' + this.id, element).length != 0)
 46					{
 47						return;
 48					}
 49					
 50					var tweet = $('<div>')
 51							.attr('id', 'tw' + this.id)
 52							.data('id', this.id)
 53							.addClass('tweet')
 54							.append(params.buildTweet.call(this))
 55							.hide();
 56						
 57					params.lastId = this.id;
 58					element.prepend(tweet);
 59				});
 60				
 61				$('div.tweet:gt(' + (params.limit - 1) + ')', element).each(function() {
 62					if (params.hideTweet)
 63					{
 64						params.hideTweet.call($(this));
 65					}
 66					else
 67					{
 68						$(this).remove();
 69					}
 70				});
 71				
 72				$('div.tweet', element).each(function(index) {
 73					if (params.showTweet)
 74					{
 75						params.showTweet.call($(this), index, params.limit);
 76					}
 77					else
 78					{
 79						$(this).show();
 80					}
 81				});
 82			},
 83			complete: function(xOptions, textStatus)
 84			{
 85				if (params.updated)
 86				{
 87					params.updated(params, textStatus);
 88				}
 89				
 90				setTimeout(function() {
 91					monitter.fetchTweets(element, params)
 92				}, params.timeout);  
 93			}});
 94	}
 95}
 96
 97$(document).ready(function () {
 98	monitter.init();
 99	
100	jQuery.fn.monitter = function(params) {
101		monitter.fetchTweets(this, params);
102		return this;
103	}; 
104});