The forum of the forums
Welcome to the Official Support Forum of Forumotion!

To take full advantage of everything offered by our forum, please log in if you are already a member, or join our community if you've not yet.



Create a free forum like this one.

[Tutorial] Hovercard

Go down

[Tutorial] Hovercard

Post by Daemon on February 22nd 2017, 10:21 pm

This code allows a hovercard to appear with user information by hovering over the nickname.

Image:


All you have to do is create a new JavaScript with investment on every page.
Code:
/*
 *  Application: Hovercard
 *  Date: 22/04/2018
 *  Version: 1.222042018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
*/
$(document).ready(function(e) {

var lang = {
    sendPm: "Send PM",
    profile: "Profile",
    posts: "Posts",
    reputation: "Reputation",
    join: "Join Date"
};

var images = {
    loading: "http://imgur.com/qgD1gdO.gif",
    pm: "https://hitsk.in/t/18/09/33/i_icon_pm.png",
    profile: "http://hitsk.in/t/18/09/33/i_icon_profile.png"
};

var config = {
    hovercard: $("<div>",{
        class: "hovercard"
    }),
    myCSS: '<style type="text/css">' +
        '.hovercard {' +
        '  display: none;' +
        '  position: absolute;' +
        '  font-family:"Open Sans","Helvetica Neue",Helvetica,Arial,sans-serif;' +
        '  margin-top: 8px;' +
        '  word-wrap: break-word;' +
        '  color: #555;' +
        '  font-size: 13px;' +
        '  padding: 4px;' +
        '  border-radius: 4px;' +
        '  -webkit-border-radius: 4px;' +
        '  -moz-border-radius: 4px;' +
        '  text-decoration: none' +
        '  z-index: 50;' +
        '  background-color: #fff;' +
        '  -webkit-box-shadow:  rgba(0, 0, 0, 0.4) 0px 3px 4px;' +
        '  -moz-box-shadow:  rgba(0, 0, 0, 0.4) 0px 3px 4px;' +
        '  box-shadow:  rgba(0, 0, 0, 0.4) 0px 3px 4px;' +
        '}' +
        '.hovercard-inner {' +
        '  height: 145px;' +
        '  width: 230px;' +
        '}' +
        '.hovercard ul {' +
        '  margin-right: 5px;' +
        '  list-style: none;' +
        '  float: right;' +
        '}' +
        '.hovercard li {padding: 5px 2px;border-bottom: 1px solid #ccc;}' +
        '.hovercard li:last-child {border-bottom: 0;}' +
        '.hovercard li a {margin-left: 5px;}' +
        '.hovercard:before {' +
        '  content: "";' +
        '  position: absolute;' +
        '  pointer-events: none !important;' +
        '  bottom: 100%;' +
        '  border-width: 10px;' +
        '  border-style: solid;' +
        '  border-color: transparent transparent #fff transparent;' +
        '}' +
        '.hovercard h3 {' +
        '  background-color: #353c41;' +
        '  border-radius: 4px 4px 0 0;' +
        '  -webkit-border-radius: 4px 4px 0 0;' +
        '  -moz-border-radius: 4px 4px 0 0;' +
        '  margin: 0;' +
        '  margin-bottom: 5px;' +
        '  padding: 13px;' +
        '  text-align: center;' +
        '}' +
        '.hovercard h3 a {' +
        '  font-size: 17px;' +
        '  text-decoration: none;' +
        '  color:#fff;' +
        '}' +
        '.hovercard h3 a:hover {color: #479fcf;}' +
        '.hover-photo {' +
        '  width: 55px;' +
        '  height: 55px;' +
        '  background-color: #FFFFFF;' +
        '  border: 1px solid #aaa;' +
        '  border-radius: 150px;' +
        '  -webkit-border-radius: 150px;' +
        '  -moz-border-radius: 150px;' +
        '  -webkit-box-shadow:  rgba(0, 0, 0, 0.4) 0px 2px 3px;' +
        '  -moz-box-shadow:  rgba(0, 0, 0, 0.4) 0px 2px 3px;' +
        '  box-shadow:  rgba(0, 0, 0, 0.4) 0px 2px 3px;' +
        '  float: left;' +
        '  padding: 2px;' +
        '}' +
        '.hovercard-button {' +
        '  -moz-border-bottom-colors: none;' +
        '  -moz-border-left-colors: none;' +
        '  -moz-border-right-colors: none;' +
        '  -moz-border-top-colors: none;' +
        '  background-color: #EEEEEE;' +
        '  background-image: linear-gradient(#F5F6F6, #E4E4E3);' +
        '  border-color: #999999 #999999 #888888;' +
        '  border-image: none;' +
        '  border-style: solid;' +
        '  border-width: 1px;' +
        '  box-shadow: 0 1px 0 rgba(0, 0, 0, 0.1), 0 1px 0 #FFFFFF inset;' +
        '  font: bold 11px tahoma,verdana,arial,sans-serif;' +
        '  padding: 7px 6px 3px;' +
        '  text-align: center;' +
        '}' +
        '</style>',
        openingInterval: 400, // 0.4 seconds to open the hovercard
        closingInterval: 400, // 0.4 seconds to close the hovercard
};

// Inserting CSS before page body
$(config.myCSS).insertBefore("body");
// Inserting element hovercard append to page body
$(config.hovercard).appendTo("body");
     
function content(user, url, id, photo, msg, rep, reg) {
    config.hovercard.html(
    '<div class="hovercard-inner">' +
    '    <h3>' +
    '        <img src="' + photo + '" class="hover-photo" alt>' +
    '        <a href="/profile?mode=viewprofile&u=' + user + '">' + user + '</a>' +
    '    </h3>' +
    '    <ul>' +
    '        <li><strong>' + lang.posts + '</strong> ' + msg + '</li>' +
    '        <li><strong>' + lang.reputation + '</strong> ' + rep + '</li>' +
    '        <li><strong>' + lang.join + '</strong> ' + reg + '</li>' +
    '        <li>' +
    '            <a href="/privmsg?mode=post&u=' + id + '" class="hovercard-button">' +
    '                <img src="' + images.pm + '" title="' + lang.sendPm + '">' +
    '            </a>' +
    '            <a href="/profile?mode=viewprofile&u=' + user + '" class="hovercard-button">' +
    '                <img src="' + images.profile + '" title="' + lang.profile + '">' +
    '            </a>' +
    '        </li>' +
    '    </ul>' +
    '</div>'
    );
}

var timeout,
    pos = {},
    urlUser = null,
    idUser = null,
    stored = null,
    user = null,
    photoUser = null,
    msg = null,
    rep = null,
    reg = null,
    JSONuser = [],
    dataAsJsonString = null;

function fadeOutHovercard() {
    timeout = setTimeout(function() {
        config.hovercard.fadeOut(config.closingInterval, function() {
            $(this).html("<img src='" + images.loading + "' alt>");
        });
    }, 1500);
}

$(document).on("mouseenter", "a[href^='/u']", function(e) {
    if($(this).attr("href").split(/[\d,]+/)[1]) return; // If it is user profile
    if(timeout) clearTimeout(timeout); // Clear time out
    // Hovercard position
    pos = {
        "top": e.pageY+ "px",
        "left": e.pageX + "px"
    };
    // Positioning and displaying hovercard
    config.hovercard.html("<img src='" + images.loading + "' alt>").css(pos).fadeIn(config.openingInterval);

    urlUser = $(this).attr("href"),
    idUser = urlUser.match(/\d+/).toString(),
    stored = sessionStorage.getItem("hovercard-" + idUser);

    if(!stored) {
        $.get(urlUser + "?change_version=punbb", function(data) {
            user = $(data).filter("title").text().split("- ")[1],
            photoUser = $("#profile-advanced-right .module:first .main-content img", data).attr("src"),
            msg = $("#field_id-6 dd", data).text(),
            rep = $("#field_id-14 dd", data).text(),
            reg = $("#field_id-4 dd", data).text(),
            JSONuser = [{name: user, url: urlUser, photo: photoUser, id: idUser, message: msg, reputation: rep, register: reg}],
            dataAsJsonString = JSON.stringify(JSONuser);
            sessionStorage.setItem("hovercard-" + idUser, dataAsJsonString);                   
            content(user, urlUser, idUser, photoUser, msg, rep, reg);
        });
        return;
    }

    JSONuser = $.parseJSON(stored);
    $.each(JSONuser, function(i, val) {
        if(val.id == idUser) content(val.name, val.url, val.id, val.photo, val.message, val.reputation, val.register);
    });
}).on("mouseleave", function(e) {
    fadeOutHovercard();
});
 
config.hovercard.on("mouseenter", function(e) {
    if(timeout) clearTimeout(timeout); // Clear time out
}).on("mouseleave", function(e) {
    fadeOutHovercard();
});
 
});

Wink


Last edited by Daemon on April 22nd 2018, 11:42 am; edited 7 times in total
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Re: [Tutorial] Hovercard

Post by tylercole on February 22nd 2017, 10:50 pm

Cool, but what do u mean by, "With an investment on every page?"
avatar
tylercole
Forumember

Posts : 304
Reputation : 17
Language : english

http://insectsandentomolgy.forumotion.com/

Back to top Go down

Re: [Tutorial] Hovercard

Post by SarkZKalie on February 22nd 2017, 11:43 pm

^in all the pages Very Happy
avatar
SarkZKalie
Forumember

Male Posts : 686
Reputation : 104
Language : English

http://rotavn.forumotion.com

Back to top Go down

Re: [Tutorial] Hovercard

Post by tylercole on February 23rd 2017, 12:33 am

That's cool, any idea how to make the headers of these hover cards a certain color?
avatar
tylercole
Forumember

Posts : 304
Reputation : 17
Language : english

http://insectsandentomolgy.forumotion.com/

Back to top Go down

Re: [Tutorial] Hovercard

Post by Daemon on February 23rd 2017, 8:23 am

You can change the header color in the following part (#eee).
Code:
'.hovercard h3 {' +
'  background-color: #eee;' +
'  border-bottom: 1px dashed #aaa;' +
'  margin: 0;' +
'  margin-bottom: 5px;' +
'  padding: 3px;' +
'  text-align: center;' +
'}' +
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Re: [Tutorial] Hovercard

Post by SLGray on February 23rd 2017, 12:18 pm

Is this a modified version of the pop up feature that we already have?


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 42731
Reputation : 3010
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: [Tutorial] Hovercard

Post by Daemon on February 23rd 2017, 1:13 pm

The default popup applies to the marked names, with the @, correct?
This code I made, applies to any nickname that has a user link. Just mouse over.
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Re: [Tutorial] Hovercard

Post by SLGray on February 23rd 2017, 1:20 pm

Ok.  Thanks for sharing it.


When your topic has been solved, ensure you mark the topic solved.
Never post your email in public.

avatar
SLGray
Administrator
Administrator

Male Posts : 42731
Reputation : 3010
Language : English
Location : United States

https://fmthemes.forumotion.com/

Back to top Go down

Re: [Tutorial] Hovercard

Post by tylercole on February 23rd 2017, 1:22 pm

Yeah, super cool. Just added it to my forum. Appreciate it.
avatar
tylercole
Forumember

Posts : 304
Reputation : 17
Language : english

http://insectsandentomolgy.forumotion.com/

Back to top Go down

Re: [Tutorial] Hovercard

Post by YoshiGM on February 23rd 2017, 10:18 pm

Well done dude! Wink
avatar
YoshiGM
Forumember

Male Posts : 712
Reputation : 97
Language : Spanish, English & Italian (16%)
Location : Mexico

http://asistencia.foroactivo.com/u21373

Back to top Go down

Re: [Tutorial] Hovercard

Post by Daemon on February 26th 2017, 8:58 pm

Updated to 1.1 Wink
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Re: [Tutorial] Hovercard

Post by Str0ng on March 1st 2017, 3:06 am

Awesome! But if you change the value on the profile of the user.. it does not update in the pop up until you have closed (entirely) and have reset the browser. Is possible to change it? And do it update after x amount of minutes or something?

TY!

Str0ng
Forumember

Posts : 55
Reputation : 7
Language : Spanish

http://www.seasonal-trackers.com

Back to top Go down

Re: [Tutorial] Hovercard

Post by Daemon on March 1st 2017, 9:15 am

I did this in order to avoid having a large number of requests, saving the content with sessionStorage to avoid loading multiple times.
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Re: [Tutorial] Hovercard

Post by Str0ng on March 1st 2017, 2:13 pm

I see.. and why not, store them in the forum cookies? Instead on the browser? So to see the updated content only will be needed to clean the forum cookies (and not need to close all the tabs of the browser etc..)

Str0ng
Forumember

Posts : 55
Reputation : 7
Language : Spanish

http://www.seasonal-trackers.com

Back to top Go down

Re: [Tutorial] Hovercard

Post by jackauk on October 30th 2017, 1:04 pm

Hello,
I get trouble that when I move cursor over nickname in near right bound of window, the panel dont show full detail.
avatar
jackauk
New Member

Posts : 2
Reputation : 2
Language : English, Vietnamese

http://openlab.forumvi.com

Back to top Go down

Re: [Tutorial] Hovercard

Post by Daemon on April 13th 2018, 1:08 am

Updated!
avatar
Daemon
Forumember

Posts : 74
Reputation : 63
Language : Português

Back to top Go down

Back to top


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