FM Design
Would you like to react to this message? Create an account in a few clicks or log in to continue.

IMPORTANT

FM Design is in read-only mode, please click here for more information.

Latest topics
» Forumactif Edge - Releases
by Ange Tuteur Tue 03 Sep 2019, 11:49

» GIFActif - Giphy Button for the Editor
by Ange Tuteur Wed 08 May 2019, 17:21

» Forum Closure
by Ange Tuteur Mon 01 Jan 2018, 01:28

» Chit Chat Thread
by Valoish Sun 31 Dec 2017, 19:15

» Font/Text background color.
by Valoish Sun 31 Dec 2017, 19:11

» Forumactif Messenger - Instant Message Application for Forumotion
by Wolfuryo Sun 31 Dec 2017, 18:24

» [GAME] Count to One Million!
by brandon_g Fri 29 Dec 2017, 18:58

» Post Cards
by manikbiradar Wed 20 Dec 2017, 07:50

» [GAME] Countdown from 200,000
by Valoish Wed 13 Dec 2017, 23:22

» GeekPolice Tech Support Forums - GeekPolice.net
by Dr Jay Mon 11 Dec 2017, 19:12

» Asking about some plugin for Forumotion
by Dr Jay Mon 11 Dec 2017, 19:10

» [GAME] What are you thinking right now?
by Van-Helsing Sat 09 Dec 2017, 14:51

» Widget : Similar topics
by ranbac Wed 06 Dec 2017, 18:11

» Change the Background of the Forum and put an image and how to make prefixs?
by Clement Wed 06 Dec 2017, 15:19

» Hello from Western Australia
by SarkZKalie Wed 06 Dec 2017, 05:34

Recent Tutorials
Top posting users this month

Who is online?
In total there are 16 users online :: 0 Registered, 0 Hidden and 16 Guests :: 2 Bots

None

[ View the whole list ]


Most users ever online was 515 on Tue 14 Sep 2021, 15:24

Display the user avatar before mentions

View previous topic View next topic Go down

Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Fri 11 Mar 2016, 10:04

This small plugin will allow you to show the avatar of the user you mentioned on the forum. The avatar will show either before or after the mention depending on your preferences.

Display the user avatar before mentions Captur11

Click to view demo


Installation


To install this plugin go to Modules > JavaScript codes management and create a new script with the following settings.

Tittle : Mention Avatar
Placement : In all the pages ( or "In the topics" if you want it to only work in topics )
Paste the script below and click save :
Code:
(function() {
  window.faMentionAvatar = {
    // position modifies the position of the avatar
    // 0 = before mention
    // 1 = after mention
    position : 0,
    cacheTime : 1*60*60*1000, // amount of time the avatar is cached ( 1 hour )
   
    mentions : null, // mention node list
    index : -1, // current index in the mentions array
   
    // checks if the mention is valid and then gets the avatar
    getter : function() {
      var mention = faMentionAvatar.mentions[++faMentionAvatar.index],
          storage = window.localStorage,
          id;
         
      if (mention) {
        id = mention.href.replace(/.*?\/u/, '');
       
        if (storage && storage['mentionAvatar_' + id] && storage['mentionAvatar_' + id + '_exp'] > +new Date - faMentionAvatar.cacheTime) {
          var avatar = document.createElement('IMG');
          avatar.className += ' mention-ava';
          avatar.src = storage['mentionAvatar_' + id];
          faMentionAvatar.position ? mention.appendChild(avatar) : mention.insertBefore(avatar, mention.firstChild);
          faMentionAvatar.getter();
        } else {
          $.get('/ajax/index.php?f=m&user_id=' + id, function(d) {
            var avatar = $('.tooltip-content > img', d)[0];
               
            if (avatar) {
              faMentionAvatar.position ? mention.appendChild(avatar) : mention.insertBefore(avatar, mention.firstChild);
             
              if (storage) {
                storage['mentionAvatar_' + id] = avatar.src;
                storage['mentionAvatar_' + id + '_exp'] = +new Date;
              }
            }
            faMentionAvatar.getter();
          });
        }
      }
    }
  };
 
  // write the stylesheet into the HEAD section
  document.write('<style type="text/css">.mentiontag img { height:20px; width:20px; vertical-align:middle; border-radius:100px; background:#FFF; box-shadow:0px 1px 1px rgba(0, 0, 0, 0.3), 0px -0px 1px rgba(0, 0, 0, 0.3); margin:1px 3px; padding:1px; }</style>');
 
  // statements that need execution when the document is ready
  $(function() {
    faMentionAvatar.mentions = $('.mentiontag');
    faMentionAvatar.getter();
  });
}());

Once the script is saved go to a topic that someone was mentioned in and you should see their avatar before the mention ! If you'd like to change the position of the avatar please see the modifications section.


Modifications


There are only a few modifications for this plugin which should be easy to understand and edit.

position : At the top of the script you'll see a variable titled "position", this variable modifies the position of the avatar. If you'd like the avatar after the mention change the 0 to a 1 and you'll be set. Change it back to 0 if you want the avatar before the mention. I left a comment in the script as a reminder.

cacheTime : This option influences the amount of time that the avatars are cached. By default the avatars are cache for 1 hour (
Code:
1*60*60*1000
), modify the value of this option if you want to change the cache time. This is primarily meant for performance purposes so that multiple requests don't have to be submitted for the same user. In short ; it makes the script run faster.

style : The style of the avatar is influenced by this line in the script :
Code:
document.write('<style type="text/css">.mentiontag img { height:20px; width:20px; vertical-align:middle; border-radius:100px; background:#FFF; box-shadow:0px 1px 1px rgba(0, 0, 0, 0.3), 0px -0px 1px rgba(0, 0, 0, 0.3); margin:1px 3px; padding:1px; }</style>');

What this line does is write a small stylesheet into the HEAD section of the document. You can modify this CSS to change the size, color, margin, etc.. of the avatar. This is the unminified CSS to make editing easier :
Code:
.mentiontag img {
  height:20px;
  width:20px;
  vertical-align:middle;
  border-radius:100px;
  background:#FFF;
  box-shadow:0px 1px 1px rgba(0, 0, 0, 0.3), 0px -0px 1px rgba(0, 0, 0, 0.3);
  margin:1px 3px;
  padding:1px;
}

If you have any questions or comments please feel free to leave them below. Enjoy ! Thumb left


Notice
Tutorial written by Ange Tuteur.
Reproduction not permitted without consent from the author.


Last edited by Ange Tuteur on Tue 05 Jul 2016, 09:37; edited 5 times in total
Van-Helsing
Van-Helsing

Gender : Male
Age : 50
Posts : 853
Points : 5042
Reputation : 84
Location : Somewhere out there!
Language : English, Greek
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : punBB
http://itexperts.forumgreek.com/

PostVan-Helsing Fri 11 Mar 2016, 11:35

Hello,
Very nice code @Ange Tuteur thank you very mych. Another perfect code by Ange. Smile
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Fri 11 Mar 2016, 11:46

@Dark-Avenger No problem, I'm glad you like it ! Very Happy
SLGray
SLGray
Valued Member
Gender : Male
Age : 51
Posts : 2465
Points : 7345
Reputation : 290
Location : United States
Language : English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : ModernBB
http://www.fmthemes.forumotion.com https://www.facebook.com/FM-Themes-655055824604957 https://twitter.com/FMThemes https://pinterest.com/FMThemes

PostSLGray Fri 11 Mar 2016, 14:31

Thanks for the neat tutorial. I am going to try it on both of my forums now.
mimóza
mimóza
New Member
Gender : Unspecified
Posts : 2
Points : 3185
Reputation : 4
Language : English, Hungarian
Browser : Browser : Google Chrome Forum Version : Forum Version : punBB
http://www.graphicballoon.com/

Postmimóza Sat 12 Mar 2016, 11:37

Wow, this is sooo great! Thank you so much! Display the user avatar before mentions 35815
SLGray
SLGray
Valued Member
Gender : Male
Age : 51
Posts : 2465
Points : 7345
Reputation : 290
Location : United States
Language : English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : ModernBB
http://www.fmthemes.forumotion.com https://www.facebook.com/FM-Themes-655055824604957 https://twitter.com/FMThemes https://pinterest.com/FMThemes

PostSLGray Sat 12 Mar 2016, 14:22

I am using it on both of my forums. They looking great in posts.
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Sat 12 Mar 2016, 17:57

You're welcome guys, I'm happy you like it ! ^^
SarkZKalie
SarkZKalie
Member
Gender : Male
Age : 33
Posts : 24
Points : 3991
Reputation : 11
Language : English
Browser : Browser : Google Chrome Forum Version : Forum Version : punBB

PostSarkZKalie Sat 12 Mar 2016, 21:27

You always surprise us w your best code, Katty Twisted Evil
Thank you @Ange Tuteur !
Display the user avatar before mentions P3ykwi10
Luke Spike
Luke Spike
New Member
Gender : Male
Posts : 9
Points : 3586
Reputation : 0
Location : Paradise
Language : English
Browser : Browser : Google Chrome Forum Version : Forum Version : punBB

PostLuke Spike Fri 25 Mar 2016, 21:06

Does this work for PunBB?
SLGray
SLGray
Valued Member
Gender : Male
Age : 51
Posts : 2465
Points : 7345
Reputation : 290
Location : United States
Language : English
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : ModernBB
http://www.fmthemes.forumotion.com https://www.facebook.com/FM-Themes-655055824604957 https://twitter.com/FMThemes https://pinterest.com/FMThemes

PostSLGray Fri 25 Mar 2016, 22:48

Luke Spike wrote:Does this work for PunBB?
Yes since the tutorial does not specifically state a version.
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Sat 26 Mar 2016, 11:08

@Luke Spike it's as SLGray says ; It'll work on any version, because the class
Code:
.mentiontag
is now present on all mentions after this update.
Wilson
Wilson

Gender : Unspecified
Age : 38
Posts : 868
Points : 4821
Reputation : 124
Language : Filipino and Engrish
Browser : Browser : Google Chrome Forum Version : Forum Version : phpBB3
http://generalaxis.forums.com.bz/

PostWilson Thu 31 Mar 2016, 13:34

A good addition indeed. Thank you for this Ange!
Niko!
Niko!

Gender : Male
Age : 28
Posts : 98
Points : 4234
Reputation : 51
Location : Milan, Italy
Language : Italian, English, French,
Browser : Browser : Google Chrome Forum Version : Forum Version : punBB
https://www.openstudio.one https://www.facebook.com/TranslationsCloud https://twitter.com/TranslaCloud https://pinterest.com/translacloud

PostNiko! Thu 07 Apr 2016, 14:44

Of course I am using this
Ape
Ape

Gender : Male
Age : 49
Posts : 136
Points : 4030
Reputation : 29
Location : UK kent
Language : English i think
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : phpBB3
http://missingpeople.darkbb.com

PostApe Sun 15 May 2016, 14:00

I love this cool system looks so cool just one thing is there away to add a small code to this so when you Tag some one in the post it puts a box around the Avatar and the name like this Display the user avatar before mentions Ape10
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Sun 15 May 2016, 21:27

@Ape of course, you can use the
Code:
.mentiontag
class. Wink

Here's an example CSS rule :
Code:
.mentiontag {
  background:rgba(0, 0, 0, 0.05);
  border:1px solid rgba(0, 0, 0, 0.1);
  border-radius:3px;
  display:inline-block;
  padding:1px 3px;
  margin:1px;
}
Ape
Ape

Gender : Male
Age : 49
Posts : 136
Points : 4030
Reputation : 29
Location : UK kent
Language : English i think
Browser : Browser : Mozilla Firefox Forum Version : Forum Version : phpBB3
http://missingpeople.darkbb.com

PostApe Mon 16 May 2016, 07:54

perfect Smile Thank you Very good
Ange Tuteur
Ange Tuteur
Administrator
Gender : Male
Posts : 4741
Points : 12253
Reputation : 2376
Location : Pennsylvania
Language : EN, JA, FR
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
https://sethclydesdale.github.io/ https://twitter.com/sethc1995

PostAnge Tuteur Mon 16 May 2016, 11:27

Ape wrote:perfect Smile Thank you Very good
Anytime. Doff
Anonymous
Guest
Guest

PostGuest Sat 03 Dec 2016, 07:59

Nice! Installed & works with Edge.
Sponsored content

PostSponsored content

View previous topic View next topic Back to top

Create an account or log in to leave a reply

You need to be a member in order to leave a reply.

Create an account

Join our community by creating a new account. It's easy!


Create a new account

Log in

Already have an account? No problem, log in here.


Log in

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