123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645 |
- RealtimeUpdate = {
- _userid: 0,
- _showurl: '',
- _keepaliveurl: '',
- _closeurl: '',
- _updatecounter: 0,
- _maxnotices: 50,
- _windowhasfocus: true,
- _documenttitle: '',
- _paused:false,
- _queuedNotices:[],
-
- init: function(userid, showurl)
- {
- RealtimeUpdate._userid = userid;
- RealtimeUpdate._showurl = showurl;
- RealtimeUpdate._documenttitle = document.title;
- $(window).bind('focus', function() {
- RealtimeUpdate._windowhasfocus = true;
-
- RealtimeUpdate._updatecounter = 0;
- RealtimeUpdate.removeWindowCounter();
- });
- $(window).bind('blur', function() {
- $('#notices_primary .notice').removeClass('mark-top');
- $('#notices_primary .notice:first').addClass('mark-top');
-
-
-
-
- RealtimeUpdate._windowhasfocus = false;
- return false;
- });
- },
-
- receive: function(data)
- {
- if (RealtimeUpdate.isNoticeVisible(data.id)) {
-
-
- return;
- }
- if (RealtimeUpdate._paused === false) {
- RealtimeUpdate.purgeLastNoticeItem();
- RealtimeUpdate.insertNoticeItem(data);
- }
- else {
- RealtimeUpdate._queuedNotices.push(data);
- RealtimeUpdate.updateQueuedCounter();
- }
- RealtimeUpdate.updateWindowCounter();
- },
-
- insertNoticeItem: function(data) {
-
- if (RealtimeUpdate.isNoticeVisible(data.id)) {
- return;
- }
- RealtimeUpdate.makeNoticeItem(data, function(noticeItem) {
-
- if (RealtimeUpdate.isNoticeVisible(data.id)) {
- return;
- }
- var noticeItemID = $(noticeItem).attr('id');
- var list = $("#notices_primary .notices:first")
- var prepend = true;
- var threaded = list.hasClass('threaded-notices');
- if (threaded && data.in_reply_to_status_id) {
-
- var parent = $('#notice-' + data.in_reply_to_status_id);
- if (parent.length == 0) {
-
- } else {
-
-
- var parentList = parent.closest('.notices');
- if (parentList.hasClass('threaded-replies')) {
- parent = parentList.closest('.notice');
- }
- list = parent.find('.threaded-replies');
- if (list.length == 0) {
- list = $('<ul class="notices threaded-replies xoxo"></ul>');
- parent.append(list);
- SN.U.NoticeInlineReplyPlaceholder(parent);
- }
- prepend = false;
- }
- }
- var newNotice = $(noticeItem);
- if (prepend) {
- list.prepend(newNotice);
- } else {
- var placeholder = list.find('li.notice-reply-placeholder')
- if (placeholder.length > 0) {
- newNotice.insertBefore(placeholder)
- } else {
- newNotice.appendTo(list);
- }
- }
- newNotice.css({display:"none"}).fadeIn(1000);
- SN.U.NoticeReplyTo($('#'+noticeItemID));
- SN.U.NoticeWithAttachment($('#'+noticeItemID));
- });
- },
-
- isNoticeVisible: function(id) {
- return ($("#notice-"+id).length > 0);
- },
-
- purgeLastNoticeItem: function() {
- if ($('#notices_primary .notice').length > RealtimeUpdate._maxnotices) {
- $("#notices_primary .notice:last").remove();
- }
- },
-
- updateWindowCounter: function() {
- if (RealtimeUpdate._windowhasfocus === false) {
- RealtimeUpdate._updatecounter += 1;
- document.title = '('+RealtimeUpdate._updatecounter+') ' + RealtimeUpdate._documenttitle;
- }
- },
-
- removeWindowCounter: function() {
- document.title = RealtimeUpdate._documenttitle;
- },
-
- makeNoticeItem: function(data, callback)
- {
- var url = RealtimeUpdate._showurl.replace('0000000000', data.id);
- $.get(url, {ajax: 1}, function(data, textStatus, xhr) {
- var notice = $('li.notice:first', data);
- if (notice.length) {
- var node = document._importNode(notice[0], true);
- callback(node);
- }
- });
- },
-
- makeFavoriteForm: function(id, session_key)
- {
- var ff;
- ff = "<form id=\"favor-"+id+"\" class=\"form_favor\" method=\"post\" action=\""+RealtimeUpdate._favorurl+"\">"+
- "<fieldset>"+
- "<legend>Favor this notice</legend>"+
- "<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
- "<input name=\"notice\" type=\"hidden\" id=\"notice-n"+id+"\" value=\""+id+"\"/>"+
- "<input type=\"submit\" id=\"favor-submit-"+id+"\" name=\"favor-submit-"+id+"\" class=\"submit\" value=\"Favor\" title=\"Favor this notice\"/>"+
- "</fieldset>"+
- "</form>";
- return ff;
- },
-
- makeReplyLink: function(id, nickname)
- {
- var rl;
- rl = "<a class=\"notice_reply\" href=\""+RealtimeUpdate._replyurl+"?replyto="+nickname+"\" title=\"Reply to this notice\">Reply <span class=\"notice_id\">"+id+"</span></a>";
- return rl;
- },
-
- makeRepeatForm: function(id, session_key)
- {
- var rf;
- rf = "<form id=\"repeat-"+id+"\" class=\"form_repeat\" method=\"post\" action=\""+RealtimeUpdate._repeaturl+"\">"+
- "<fieldset>"+
- "<legend>Repeat this notice?</legend>"+
- "<input name=\"token\" type=\"hidden\" id=\"token-"+id+"\" value=\""+session_key+"\"/>"+
- "<input name=\"notice\" type=\"hidden\" id=\"notice-"+id+"\" value=\""+id+"\"/>"+
- "<input type=\"submit\" id=\"repeat-submit-"+id+"\" name=\"repeat-submit-"+id+"\" class=\"submit\" value=\"Yes\" title=\"Repeat this notice\"/>"+
- "</fieldset>"+
- "</form>";
- return rf;
- },
-
- makeDeleteLink: function(id)
- {
- var dl, delurl;
- delurl = RealtimeUpdate._deleteurl.replace("0000000000", id);
- dl = "<a class=\"notice_delete\" href=\""+delurl+"\" title=\"Delete this notice\">Delete</a>";
- return dl;
- },
-
- initActions: function(url, timeline, path, keepaliveurl, closeurl)
- {
- $('#notices_primary').prepend('<ul id="realtime_actions"><li id="realtime_playpause"></li><li id="realtime_timeline"></li></ul>');
- RealtimeUpdate._pluginPath = path;
- RealtimeUpdate._keepaliveurl = keepaliveurl;
- RealtimeUpdate._closeurl = closeurl;
-
- $(window).unload(function() {
- $.ajax({
- type: 'POST',
- url: RealtimeUpdate._closeurl});
- });
- setInterval(function() {
- $.ajax({
- type: 'POST',
- url: RealtimeUpdate._keepaliveurl});
- }, 15 * 60 * 1000 );
- RealtimeUpdate.initPlayPause();
- RealtimeUpdate.initAddPopup(url, timeline, RealtimeUpdate._pluginPath);
- },
-
- initPlayPause: function()
- {
- if (typeof(localStorage) == 'undefined') {
- RealtimeUpdate.showPause();
- }
- else {
- if (localStorage.getItem('RealtimeUpdate_paused') === 'true') {
- RealtimeUpdate.showPlay();
- }
- else {
- RealtimeUpdate.showPause();
- }
- }
- },
-
- showPause: function()
- {
- RealtimeUpdate.setPause(false);
- RealtimeUpdate.showQueuedNotices();
- RealtimeUpdate.addNoticesHover();
- $('#realtime_playpause').remove();
- $('#realtime_actions').prepend('<li id="realtime_playpause"><button id="realtime_pause" class="pause"></button></li>');
- $('#realtime_pause').text(SN.msg('realtime_pause'))
- .attr('title', SN.msg('realtime_pause_tooltip'))
- .bind('click', function() {
- RealtimeUpdate.removeNoticesHover();
- RealtimeUpdate.showPlay();
- return false;
- });
- },
-
- showPlay: function()
- {
- RealtimeUpdate.setPause(true);
- $('#realtime_playpause').remove();
- $('#realtime_actions').prepend('<li id="realtime_playpause"><span id="queued_counter"></span> <button id="realtime_play" class="play"></button></li>');
- $('#realtime_play').text(SN.msg('realtime_play'))
- .attr('title', SN.msg('realtime_play_tooltip'))
- .bind('click', function() {
- RealtimeUpdate.showPause();
- return false;
- });
- },
-
- setPause: function(state)
- {
- RealtimeUpdate._paused = state;
- if (typeof(localStorage) != 'undefined') {
- localStorage.setItem('RealtimeUpdate_paused', RealtimeUpdate._paused);
- }
- },
-
- showQueuedNotices: function()
- {
- $.each(RealtimeUpdate._queuedNotices, function(i, n) {
- RealtimeUpdate.insertNoticeItem(n);
- });
- RealtimeUpdate._queuedNotices = [];
- RealtimeUpdate.removeQueuedCounter();
- },
-
- updateQueuedCounter: function()
- {
- $('#realtime_playpause #queued_counter').html('('+RealtimeUpdate._queuedNotices.length+')');
- },
-
- removeQueuedCounter: function()
- {
- $('#realtime_playpause #queued_counter').empty();
- },
-
- addNoticesHover: function()
- {
- $('#notices_primary .notices').hover(
- function() {
- if (RealtimeUpdate._paused === false) {
- RealtimeUpdate.showPlay();
- }
- },
- function() {
- if (RealtimeUpdate._paused === true) {
- RealtimeUpdate.showPause();
- }
- }
- );
- },
-
- removeNoticesHover: function()
- {
- $('#notices_primary .notices').unbind();
- },
-
- initAddPopup: function(url, timeline, path)
- {
- $('#realtime_timeline').append('<button id="realtime_popup"></button>');
- $('#realtime_popup').text(SN.msg('realtime_popup'))
- .attr('title', SN.msg('realtime_popup_tooltip'))
- .bind('click', function() {
- window.open(url,
- '',
- 'toolbar=no,resizable=yes,scrollbars=yes,status=no,menubar=no,personalbar=no,location=no,width=500,height=550');
- return false;
- });
- },
-
- initPopupWindow: function()
- {
- $('.notices .entry-title a, .notices .e-content a').bind('click', function() {
- window.open(this.href, '');
- return false;
- });
- $('#showstream .entity_profile').css({'width':'69%'});
- }
- }
|