[Tutorial] Online staff widget

Page 2 of 2 Previous  1, 2

Go down

[Tutorial] Online staff widget

Post by Daemon on March 1st 2017, 3:28 pm

First topic message reminder :

This code serves to create a widget with online team members.

Image:


Create a custom widget with the following content:
Code:
<ul id="staff_widget"></ul>
<script type="text/javascript">
/*
 *  Application: Staff Online Widget
 *  Date: 14/06/2018
 *  Version: 2.014062018
 *  Copyright (c) 2018 Daemon <help.forumotion.com>
 *  This work is free. You can redistribute it and/or modify it
 */
jQuery(function() {

    function staffOnline() {

        var staff = [
            {group: "Administrator", color: "FF0000"},
            {group: "Moderator", color: "008C09"},
            {group: "Helper", color: "D69A45"}
        ];

        jQuery.get("/viewonline", function(data) {
            staffWidget.html("");
            // variables
            var table = jQuery(".table, .table1, .ipbtable, .three-col .forumline", data);
            // List each item in the array
            jQuery.each(staff, function(i, val) {
                var staffColor = table.find("span[style*='" + val.color + "']");
                // Check span elements that contain array colors
                if (typeof(staffColor) != "undefined" && staffColor != null) {
                    // For each existing color
                    jQuery.each(staffColor, function(i, el) {
                        var stafferHref = jQuery(el).closest("a").attr("href");
                        jQuery.get(stafferHref, function(data2) {
                            var stafferName = jQuery(el).closest("a").parent().html(),
                                stafferId = stafferHref.split("/u")[1],
                                avatarSrc = jQuery(".module", data2).find("img").attr("src");
                            staffWidget.append(
                                '<li class="online_staff clearfix">' +
                                '  <div class="div-icon-staff">' +
                                '    <div class="staff-avatar"><img src="' + avatarSrc + '" alt="avatar"></div>' +
                                '  </div>' +
                                '  <div class="div-main-staff">' +
                                '    <div class="staff-mp"><a href="/privmsg?mode=post&u=' + stafferId + '"><img src="https://hitsk.in/t/18/09/33/i_icon_pm.png" title="Send PM"></a></div>' +
                                '    <div class="staff-name">' + stafferName + '</div>' +
                                '    <p class="staff-rank">' + val.group + '</p>' +
                                '  </div>' +
                                '</li>'
                            );
                            sessionStorage.setItem("online_staff", staffWidget.html());
                        }); // end request 2
                    }); // end each staffColor
                }// end if
            });// end each staff
        });// end request 1
    }
 
    var staffWidget = jQuery("#staff_widget");
    storedValue = sessionStorage.getItem("online_staff");
    staffWidget.html((storedValue !== null) ? storedValue : staffOnline());

    setInterval(function() {
        sessionStorage.removeItem("online_staff");
        staffOnline();
    }, 180000); // staffOnline function, reload every 3 minutes

});
</script>
<style type="text/css">
#staff_widget {padding: 0;}
#staff_widget:empty:before {
    content: "Não há staff online!";
}
#staff_widget .online_staff {
  display: block;
  font-size: 14px;
  padding: 1px 0;
  zoom: 1;
}
#staff_widget .div-icon-staff {
  width: 25px;
  min-width: 25px;
  padding-top: 12px;
}
#staff_widget .div-icon-staff, #staff_widget .div-main-staff {
  display: table-cell;
  padding: 8px;
  vertical-align: top;
}
#staff_widget .staff-avatar {
  background: #fff;
  vertical-align: middle;
  display: inline-block;
  line-height: 1px;
  position: relative;
  margin: 2px;
}
#staff_widget .staff-avatar img {
  width: 34px;
  height: 34px;
  border: 1px solid #ddd;
}
#staff_widget .staff-mp {
  display: inline-block;
  float: right;
  margin-right: -25px;
}
#staff_widget .staff-rank {
  color: rgb(150, 150, 150);
  margin-top: 5px;
}
</style>

To add groups and their colors, edit in the following lines of code:
Code:
var staff = [
    {group: "Administrator", color: "FF0000"},
    {group: "Moderator", color: "008C09"},
    {group: "Helper", color: "D69A45"}
];

Smile


Last edited by Daemon on June 25th 2018, 3:39 pm; edited 15 times in total
avatar
Daemon
Forumember

Posts : 101
Reputation : 80
Language : Português

Back to top Go down


Re: [Tutorial] Online staff widget

Post by Van-Helsing on October 3rd 2017, 10:55 pm

Hello @Daemon,
I 've just tested on my new forum and its not working.

Forum Link:

avatar
Van-Helsing
Hyperactive

Male Posts : 2413
Reputation : 113
Language : English, Greek

http://helpgr.forumgreek.com/

Back to top Go down

Re: [Tutorial] Online staff widget

Post by ShinyFirefly on January 8th 2018, 11:57 pm

I just tried it on mine (phpbb3) as well and the output was all the lines of code where the widget should be.
avatar
ShinyFirefly
New Member

Female Posts : 21
Reputation : 1
Language : English
Location : The Ether

http://www.spoilerthings.forumotion.com

Back to top Go down

Page 2 of 2 Previous  1, 2

Back to top


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