/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

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