From 4b36e41b098ae805d8a25e1c4ce7f38161418eea Mon Sep 17 00:00:00 2001 From: friendica Date: Mon, 23 Jul 2012 20:49:56 -0700 Subject: implement page update modes --- js/main.js | 156 ++++++++++++++++++++++++++++++++++--------------------------- 1 file changed, 87 insertions(+), 69 deletions(-) (limited to 'js/main.js') diff --git a/js/main.js b/js/main.js index e53373aed..47ce61704 100644 --- a/js/main.js +++ b/js/main.js @@ -210,6 +210,91 @@ timer = setTimeout(NavUpdate,updateInterval); } + +function updateConvItems(mode,data) { + + if(mode === 'update') { + prev = 'threads-begin'; + + $('.thread-wrapper',data).each(function() { + var ident = $(this).attr('id'); + + if($('#' + ident).length == 0 && profile_page == 1) { + $('img',this).each(function() { + $(this).attr('src',$(this).attr('dst')); + }); + $('#' + prev).after($(this)); + $("abbr.wall-item-ago-time").timeago(); + + } + else { + $('img',this).each(function() { + $(this).attr('src',$(this).attr('dst')); + }); + $('#' + ident).replaceWith($(this)); + $("abbr.wall-item-ago-time").timeago(); + } + prev = ident; + }); + } + if(mode === 'append') { + next = 'threads-end'; + $('.thread-wrapper',data).each(function() { + var ident = $(this).attr('id'); + + if($('#' + ident).length == 0) { + $('img',this).each(function() { + $(this).attr('src',$(this).attr('dst')); + }); + $('#threads-end').before($(this)); + $("abbr.wall-item-ago-time").timeago(); + } + else { + $('img',this).each(function() { + $(this).attr('src',$(this).attr('dst')); + }); + $('#' + ident).replaceWith($(this)); + $("abbr.wall-item-ago-time").timeago(); + } + }); + } + if(mode === 'replace') { + // clear existing content + $('.thread-wrapper',data).each(function() { + var ident = $(this).attr('id'); + + if($('#' + ident).length == 0 && profile_page == 1) { + $('img',this).each(function() { + $(this).attr('src',$(this).attr('dst')); + }); + $('#' + prev).after($(this)); + $("abbr.wall-item-ago-time").timeago(); + + } + prev = ident; + }); + } + + $('.like-rotator').hide(); + + if(commentBusy) { + commentBusy = false; + $('body').css('cursor', 'auto'); + } + + /* autocomplete @nicknames */ + $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl"); + + +} + + + + + + + + function liveUpdate() { if((src == null) || (stopped) || (! profile_uid)) { $('.like-rotator').hide(); return; } if(($('.comment-edit-text-full').length) || (in_progress)) { @@ -230,74 +315,7 @@ $.get(update_url,function(data) { in_progress = false; - // $('.collapsed-comments',data).each(function() { - // var ident = $(this).attr('id'); - // var is_hidden = $('#' + ident).is(':hidden'); - // if($('#' + ident).length) { - // $('#' + ident).replaceWith($(this)); - // if(is_hidden) - // $('#' + ident).hide(); - // } - //}); - - // add a new thread - - $('.thread-wrapper',data).each(function() { - var ident = $(this).attr('id'); - - if($('#' + ident).length == 0 && profile_page == 1) { - $('img',this).each(function() { - $(this).attr('src',$(this).attr('dst')); - }); - $('#' + prev).after($(this)); - $("abbr.wall-item-ago-time").timeago(); - - } - else { - $('img',this).each(function() { - $(this).attr('src',$(this).attr('dst')); - }); - $('#' + ident).replaceWith($(this)); - $("abbr.wall-item-ago-time").timeago(); - - } - prev = ident; - }); - - // reset vars for inserting individual items - - /* prev = 'live-' + src; - - $('.wall-item-outside-wrapper',data).each(function() { - var ident = $(this).attr('id'); - - if($('#' + ident).length == 0 && prev != 'live-' + src) { - $('img',this).each(function() { - $(this).attr('src',$(this).attr('dst')); - }); - $('#' + prev).after($(this)); - } - else { - $('#' + ident + ' ' + '.wall-item-ago').replaceWith($(this).find('.wall-item-ago')); - if($('#' + ident + ' ' + '.comment-edit-text-empty').length) - $('#' + ident + ' ' + '.wall-item-comment-wrapper').replaceWith($(this).find('.wall-item-comment-wrapper')); - $('#' + ident + ' ' + '.hide-comments-total').replaceWith($(this).find('.hide-comments-total')); - $('#' + ident + ' ' + '.wall-item-like').replaceWith($(this).find('.wall-item-like')); - $('#' + ident + ' ' + '.wall-item-dislike').replaceWith($(this).find('.wall-item-dislike')); - $('#' + ident + ' ' + '.my-comment-photo').each(function() { - $(this).attr('src',$(this).attr('dst')); - }); - } - prev = ident; - }); - */ - $('.like-rotator').hide(); - if(commentBusy) { - commentBusy = false; - $('body').css('cursor', 'auto'); - } - /* autocomplete @nicknames */ - $(".comment-edit-form textarea").contact_autocomplete(baseurl+"/acl"); + updateConvItems('update',data); }); @@ -654,7 +672,7 @@ Array.prototype.remove = function(item) { function previewTheme(elm) { theme = $(elm).val(); $.getJSON('pretheme?f=&theme=' + theme,function(data) { - $('#theme-preview').html('
' + data.desc + '
' + theme + ''); + $('#theme-preview').html('
' + data.desc + '
' + data.version + '
' + data.credits + '
' + theme + ''); }); } -- cgit v1.2.3