Latest topics
» Modify Category Tabs lead to a desired position and auto scroll click
by djblah Yesterday at 20:14

» Recent Topic with Avatar problem
by snows Yesterday at 18:15

» Dark Mode + Another Question
by Haggis Yesterday at 18:11

» IconSkouliki
by skouliki Yesterday at 14:52

» make the topic a color
by mr.blake214 Yesterday at 12:06

» Forum text has changed to bold
by tillytiger99 Yesterday at 05:02

» Request a Username Change
by mr.blake214 Yesterday at 01:30

» Display a preview of the user profile on hover
by HoeGy48 Tue 15 Aug 2017, 16:51

» Hai Guys~
by mr.blake214 Tue 15 Aug 2017, 13:48

» Forumactif Messenger - Instant Message Application for Forumotion
by DDril Tue 15 Aug 2017, 10:25

» Donation Box
by Ange Tuteur Tue 15 Aug 2017, 09:59

» Custom Award Problem (Profile Field)
by Ange Tuteur Tue 15 Aug 2017, 09:39

» Category Tabs
by SLGray Sat 12 Aug 2017, 22:45

» Forum Titles not in line
by Wolfuryo Fri 11 Aug 2017, 12:55

» Notifications not showing
by tillytiger99 Thu 10 Aug 2017, 04:14

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

None

[ View the whole list ]


Most users ever online was 172 on Fri 19 Feb 2016, 05:17

Widget : Groups

View previous topic View next topic Go down

avatar
Ange Tuteur
Administrator
Title :
Coffee Addict
Gender : Male
Age : 21
Posts : 4675
Points : 9684
Reputation : 2331
Location : Macungie, PA
Language : EN10, FR5
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
Awards :
View all awards
View user profile https://github.com/SethClydesdale https://twitter.com/sethc1995

PostAnge Tuteur on Mon 25 Apr 2016, 14:32

The groups widget allows you to see all the groups you belong to, as well as groups that you can join. It's handy if you don't feel like going to the groups page. Wink


Click to view demo

Notes :
1. The widget contains two sections ;
1.1 Group Memberships
- Shows the groups you currently belong to.
- This section is hidden if you don't belong to a group

1.2 Join a Group
- Shows the groups that you can join.
- This section is hidden if there are no groups to join

2. Group data is cached for 1 hour, so you wont see changes immediately unless you clear your cache.


Installation :

To install this widget go to Admin Panel > Modules > Forum widgets management and create a new widget with the following settings.

Titles : Groups
Use a table type : Your choice
Source :
Code:
<!--
DEVELOPED BY ANGE TUTEUR
NO DISTRIBUTION WITHOUT CONSENT OF THE AUTHOR
ORIGIN : http://fmdesign.forumotion.com/t525-widget-groups#7436
-->
<style type="text/css">#fa_group_panel { font-size:12px; font-family:arial, sans-serif; }
#fa_group_panel > div { margin:10px 3px; }
#fa_group_panel select { width:100%; }
#fa_group_memberships a { display:block; }
#fa_group_join dl { text-align:center; }
#fa_group_join dt { display:none; }
#fa_group_join dd { margin:0; }
.fa_group_title { font-weight:bold; color:#369; border-bottom:1px solid #369; padding-bottom:3px; margin:3px 0; }
.fa_group_button { color:#69C; background:transparent; border:1px solid #69C; border-radius:3px; padding:3px 6px; width:100%; }
.fa_group_button:hover { color:#FFF; background:#69C; }</style>

<div id="fa_group_panel">
  <div id="fa_group_status">
    <noscript><span style="color:#F00">Error : Please enable JavaScript to use this widget.</span></noscript>
  </div>
  <div id="fa_group_memberships"></div>
  <div id="fa_group_join"></div>
</div>

<script type="text/javascript">
(function() {
  var cache_time = 1*60*60*1000,

      lang = {
              join : 'Join a Group',
        memberships : 'Group Memberships',
            loading : 'Fetching group data...',
              error : 'There appears to be no groups to join or view.'
      },

      panel = document.getElementById('fa_group_panel'),
      status = document.getElementById('fa_group_status'),
      storage = window.localStorage;

  /* check if group data is already storage */
  if (storage && storage['faGroupData_u' + _userdata.user_id] && storage['faGroupData_exp_u' + _userdata.user_id] > +new Date - cache_time) {
    panel.innerHTML = storage['faGroupData_u' + _userdata.user_id];
  } else {
    status.innerHTML = lang.loading;

    /* get group data via AJAX */
    jQuery.get('/groups?change_version=prosilver', function(d) {
      var node = [
            document.getElementById('fa_group_memberships'),
            document.getElementById('fa_group_join')
          ];

          frag = document.createDocumentFragment(),

          join = jQuery('form:has(select[name="g"])', d)[0],
          membership = jQuery('.noList a[href^="/g"]', d),
          i = 0,
          j = membership.length;

      status.innerHTML = '';

      /* if the member has group memberships */
      if (j) {
        node[0].innerHTML = '<div class="fa_group_title">' + lang.memberships + '</div>';

        for (; i < j; i++) {
          membership[i].href = membership[i].href.replace(/\?change_version=prosilver/, '');
          frag.appendChild(membership[i]);
        }

        node[0].appendChild(frag);
      }

      /* if the member has groups left to join */
      if (join) {
        join.action = '/groups';
        jQuery('input[name="tt"]', join).remove();
        jQuery('input[type="submit"]', join).attr('class', 'fa_group_button');
        node[1].innerHTML = '<div class="fa_group_title">' + lang.join + '</div>';
        node[1].appendChild(join);
      }

      if (!j && !join) {
        status.innerHTML = lang.error;
      }

      if (storage) {
        storage['faGroupData_u' + _userdata.user_id] = panel.innerHTML;
        storage['faGroupData_exp_u' + _userdata.user_id] = +new Date;
      }
    });
  }
}());
</script>

Save the widget when you're finished and you'll be ready to add it to one of the columns on your forum and view your groups ! Cool

See the section below, if you want to make modifications to this widget. Wink


Modifications

Below are the modifications that can be made to this widget.


1. Cache Time
In the widget there should be a variable called cache_time, this controls the time the group data is cached. Edit this value if you want the cache time to be shorter or longer :
Code:
  var cache_time = 1*60*60*1000, // 1 hour


2. Language
If you want to translate or change any of the texts find the lang object in the widget :
Code:
      lang = {
              join : 'Join a Group',
        memberships : 'Group Memberships',
            loading : 'Fetching group data...',
              error : 'There appears to be no groups to join or view.'
      },
Feel free to change the texts to whatever you want. Wink


3. The Theme
You'll notice that the colors of the headers and buttons will be different from your forum. If you want to change these colors feel free to edit the stylesheet at the top of this widget. Smile
Code:
<style type="text/css">#fa_group_panel { font-size:12px; font-family:arial, sans-serif; }
#fa_group_panel > div { margin:10px 3px; }
#fa_group_panel select { width:100%; }
#fa_group_memberships a { display:block; }
#fa_group_join dl { text-align:center; }
#fa_group_join dt { display:none; }
#fa_group_join dd { margin:0; }
.fa_group_title { font-weight:bold; color:#369; border-bottom:1px solid #369; padding-bottom:3px; margin:3px 0; }
.fa_group_button { color:#69C; background:transparent; border:1px solid #69C; border-radius:3px; padding:3px 6px; width:100%; }
.fa_group_button:hover { color:#FFF; background:#69C; }</style>


That's all the modifications ! If you have any questions, comments, or find a bug feel free to leave a reply below. Enjoy ! Super hero


Notice
Tutorial written by Ange Tuteur.
Special thanks to the Beta Testers for testing this plugin.
Reproduction not permitted without consent from the author.
avatar
Guest
Guest
View all awards

PostGuest on Sun 01 May 2016, 05:33

Is it possible not to make hidden usergroups appear in the group memberships?
avatar
Ange Tuteur
Administrator
Title :
Coffee Addict
Gender : Male
Age : 21
Posts : 4675
Points : 9684
Reputation : 2331
Location : Macungie, PA
Language : EN10, FR5
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
Awards :
View all awards
View user profile https://github.com/SethClydesdale https://twitter.com/sethc1995

PostAnge Tuteur on Mon 02 May 2016, 06:47

Not really. If the group appears here it'll appear in the widget.

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