The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

script for avatar in topics... some notes

2 posters

Go down

script for avatar in topics... some notes Empty script for avatar in topics... some notes

Post by Ahmed.K March 29th 2014, 12:41 am

about this topic: https://help.forumotion.com/t131344-script-for-avatar-in-topics-and-recent-topics-widget#880505

Code:
          $(function(){
           
              if(!window.localStorage) return;
           
              // Avatar by default
                var default_avatar= 'http://2img.net/i/fa/invision/pp-blank-thumb.png';
           
              // Time of cache, here : 24hrs * 60m * 60s * 1000ms so one day
                var caching_time= 24*60*60*1000;
           
              // Time of cache in case of error, here : 60s * 1000ms so one minute
                var caching_error= 60*1000;
           
              var set_avatar= function(id) {
                    $('.mini_ava.member'+id).html('<img src="'+get_avatar(id)+'" />');
                };
           
              var get_avatar= function(id) {
                    if(localStorage.getItem('t_ava'+id) < +new Date - caching_time || (localStorage.getItem('d_ava'+id)==default_avatar && localStorage.getItem('t_ava'+id) < +new Date - caching_error))
                    {
                        localStorage.setItem('d_ava'+id, default_avatar);
                        $.get('/u'+id, function (d){
                            localStorage.setItem('t_ava'+id,+new Date);
                            localStorage.setItem('d_ava'+id, $('#profile-advanced-right .module:first div img:first,.forumline td.row1.gensmall:first > img, .frm-set.profile-view.left dd img,dl.left-box.details:first dd img, .row1 b .gen:first img, .real_avatar img',d).first().attr('src')||default_avatar);
                            set_avatar(id);
                        });
                    }
                    return localStorage.getItem('d_ava'+id);
                };
           
              var to_replace= {};
           
              $('dd.lastpost strong a.gensmall, .ipbtable tr td:last-child span strong a.gensmall, .table td.tcr strong a.gensmall, .forumline .row3.over strong a.gensmall').each(function(){
                    to_replace[$(this).attr('href').substr(2)]= 1;
                    $(this).closest('td,dd').prepend('<div class="mini_ava member'+$(this).attr('href').substr(2)+'"></div>');
                });
           
              for(i in to_replace)
                {
                    set_avatar(i);
                };
           
          });

This code uses link to the profile page, and the Guests can not see the profile page, so, this code doesn't work with me.

Can we get the avatar-link from the last post in the topics? I think this will be much better.

Something like this:
$(this).parentsUntil('.topictitle').find('a').attr('href')

But some times there are many pages in the pagination.

Any ideas?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

script for avatar in topics... some notes Empty Re: script for avatar in topics... some notes

Post by Ange Tuteur March 29th 2014, 1:06 pm

Hello Ahmed.K,

What forum version are you using ?

Thanks Smile
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

script for avatar in topics... some notes Empty Re: script for avatar in topics... some notes

Post by Ahmed.K March 29th 2014, 10:49 pm

Hi Ange, PunBB version.
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

script for avatar in topics... some notes Empty Re: script for avatar in topics... some notes

Post by Ahmed.K March 31st 2014, 4:36 pm

No ideas?
avatar
Ahmed.K
Forumember

Posts : 349
Reputation : 4
Language : English

Back to top Go down

script for avatar in topics... some notes Empty Re: script for avatar in topics... some notes

Post by Ange Tuteur March 31st 2014, 5:26 pm

The most I have so far is :
Code:
         $(function(){
          
             if(!window.localStorage) return;
          
             // Avatar by default
                var default_avatar= 'http://2img.net/i/fa/invision/pp-blank-thumb.png';
          
             // Time of cache, here : 24hrs * 60m * 60s * 1000ms so one day
                var caching_time= 24*60*60*1000;
          
             // Time of cache in case of error, here : 60s * 1000ms so one minute
                var caching_error= 60*1000;
          
             var set_avatar= function(id) {
                    $('.mini_ava.member'+id).html('<img src="'+get_avatar(id)+'" />');
                };
          
             var get_avatar= function(id) {
                    if(localStorage.getItem('t_ava'+id) < +new Date - caching_time || (localStorage.getItem('d_ava'+id)==default_avatar && localStorage.getItem('t_ava'+id) < +new Date - caching_error))
                    {
                        localStorage.setItem('d_ava'+id, default_avatar);
                        $.get('/t'+id, function (d){
                            localStorage.setItem('t_ava'+id,+new Date);
                            localStorage.setItem('d_ava'+id, $('.post:last .user-basic-info a img',d).first().attr('src')||default_avatar);
                            set_avatar(id);
                        });
                    }
                    return localStorage.getItem('d_ava'+id);
                };
          
             var to_replace= {};
          
             $('.table td.tcr a.last-post-icon').each(function(){
                    to_replace[$(this).attr('href').substr(2)]= 1;
                    $(this).closest('td,dd').prepend('<div class="mini_ava member'+$(this).attr('href').substr(2)+'"></div>');
                });
          
             for(i in to_replace)
                {
                    set_avatar(i);
                };
          
         });

However, I've not got it working, yet.
Ange Tuteur
Ange Tuteur
Forumaster

Male Posts : 13246
Reputation : 3000
Language : English & 日本語
Location : Pennsylvania

https://fmdesign.forumotion.com

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum