Latest topics
» [GAME] What are you thinking right now?
by universecat Yesterday at 21:46

» [GAME] Animal Game
by universecat Yesterday at 21:43

» [GAME] Count to 1000 using even numbers Van-Helsing Edition
by universecat Yesterday at 21:40

» [GAME] Count to One Million!
by universecat Yesterday at 21:40

» [GAME] Last Letter Game
by universecat Yesterday at 21:39

» [GAME] Post a random picture
by SLGray Yesterday at 16:28

» Dark Mode + Another Question
by Ace 1 Yesterday at 13:31

» Hi everyone!
by skouliki Yesterday at 02:01

» Hai Guys~
by skouliki Yesterday at 01:59

» Add a login popup for the toolbar
by Ape Sun 15 Oct 2017, 13:51

» Mobile Usability Test
by Ange Tuteur Sat 14 Oct 2017, 11:20

» Chit Chat Thread
by Ange Tuteur Sat 14 Oct 2017, 11:20

» [GAME] World Snake
by SLGray Thu 12 Oct 2017, 16:12

» [GAME] Never have I ever..
by Valoish Thu 12 Oct 2017, 13:01

» Browsers & Updates
by SLGray Mon 09 Oct 2017, 12:11

Recent Tutorials
Who is online?
In total there are 8 users online :: 1 Registered, 0 Hidden and 7 Guests :: 1 Bot

jlmic

[ View the whole list ]


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

Widget : Random

View previous topic View next topic Go down

avatar
Ange Tuteur
Administrator
Title :
Coffee Addict
Gender : Male
Age : 21
Posts : 4698
Points : 9534
Reputation : 2337
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 Thu 07 Apr 2016, 10:51

What's so "Random" about this Random Widget ? The Random widget provides you with three buttons ; Random Topic, Random Forum, and Random User. Clicking any of these buttons will take you to a random topic, forum, or user on your forum.


Click to view demo

Feeling adventurous ? Want to discover long forgotten content that you never knew existed ? Then this widget is for you !


Installation

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

Titles : Random
Use a table type : Your Choice
Paste the code below and save :
Code:
<!--
DEVELOPED BY ANGE TUTEUR
NO DISTRIBUTION WITHOUT CONSENT OF THE AUTHOR
ORIGIN : http://fmdesign.forumotion.com/t447-widget-random#4027
-->
<style type="text/css">#fa_random_widget a { color:#69C; border:1px solid #69C; font-family:arial, sans-serif; font-size:12px; text-align:center; border-radius:3px; padding:3px 6px; margin:6px 3px; display:block; transition:250ms; }
#fa_random_widget a:hover { color:#FFF; background:#69C; }</style>

<div id="fa_random_widget">
<script type="text/javascript">//<![CDATA[
window.FARandomTries = 0;
window.FA.Random = function(type) {
  var perform_check = false,
      sel = { topic : '.post', forum : '.forumbg' }, link;
 
  type = typeof type != 'string' ? 'topic' : type.toLowerCase();
 
  switch (type) {
    case 'topic' :
      link = '/t'+ ( Math.floor(Math.random() * '{FORUMCOUNTOPIC}') + 1 ) + '-';
      break;

    case 'forum' :
      link = '/f' + ( Math.floor(Math.random() * '{FORUMCOUNTFORUM}') + 1 ) + '-';
      break;
     
    case 'user' :
      link = '/u' + ( Math.floor(Math.random() * '{FORUMLASTUSERLINK}'.replace(/.*?u=(\d+).*/, function(M, S1) { return S1 })) + 1 );
      break;

    default :
      alert(type + ' is not supported for randomization.');
      return;
  }
 
  if (perform_check) {
    if (++FARandomTries < 5) {
      if (FARandomTries == 1) {
        for (var a = document.getElementById('fa_random_widget').getElementsByTagName('A'), i = 0, j = a.length; i < j; i++) {
          a[i].href = '#';
          a[i].innerHTML = 'Please wait...';
          a[i].style.opacity = '0.5';
        }
      }
   
      jQuery.get(link + '?change_version=prosilver', function(d) {
        if ((type == 'user' && !/<title>.*? - .*?<\/title>/.test(d)) || (type != 'user' && !jQuery(sel[type], d)[0]) || new RegExp(link).test(window.location.href)) FA.Random(type);
        else window.location.href = link;
      });
    } else {
      document.getElementById('fa_random_widget').innerHTML = window.FARandomButtons + '<p style="color:red;">The request timed out. Please try again.</p>';
      window.FARandomTries = 0;
    }
  } else {
    new RegExp(link).test(window.location.href) ? FA.Random(type) : window.location.href = link;
  }
};

// Random Buttons
document.write('<a href="javascript:FA.Random(\'topic\');">Random Topic</a>');
document.write('<a href="javascript:FA.Random(\'forum\');">Random Forum</a>');
document.write('<a href="javascript:FA.Random(\'user\');">Random User</a>');

window.FARandomButtons = document.getElementById('fa_random_widget').innerHTML;
//]]></script>
</div>

Once you save the widget, go back to forum widgets management and drag the widget into the column of your choice. After this you'll be able to find all kinds of random content ! Popcorn


Modifications

There are a few modifications which can be made to this widget. Please read below for information on each one.

1. The Style
The style of the buttons is influenced by the CSS at the very top of the widget. Modify the CSS to change the color, size, etc.. of the buttons.
Code:
<style type="text/css">#fa_random_widget a { color:#69C; border:1px solid #69C; font-family:arial, sans-serif; font-size:12px; text-align:center; border-radius:3px; padding:3px 6px; margin:6px 3px; display:block; transition:250ms; }
#fa_random_widget a:hover { color:#FFF; background:#69C; }</style>


2. Existence / Permission Check
Sometimes you may get an error like "The topic you are trying to view does not exist" because a topic or user has been deleted. If you're getting this many times and you find it annoying, then find the perform_check variable in the widget and set its value to true. This will perform a check to make sure that the page you're trying to view exists.
Code:
  var perform_check = true,
Note : This method sends a request to the page before migrating you. If it performs 5 checks without finding a page it will timeout and ask you to try again.


3. Editing / Removing Buttons
If you want to edit or remove buttons, you can find them at the bottom of the widget.
Code:
// Random Buttons
document.write('<a href="javascript:FA.Random(\'topic\');">Random Topic</a>');
document.write('<a href="javascript:FA.Random(\'forum\');">Random Forum</a>');
document.write('<a href="javascript:FA.Random(\'user\');">Random User</a>');
Feel free to edit the text or remove the buttons that you don't want.

Those are all the notable modifications that you can make. Wink

If you have any questions, comments, or find a bug feel free to leave a reply below. Now go on a random adventure and have fun ! Victory


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
Rhino.Freak

Title :
Lord of the 7 kingdoms and protector of the realm
Gender : Male
Age : 21
Posts : 275
Points : 1874
Reputation : 86
Location : India!
Language : English, Hindi
Browser : Browser : Google Chrome Forum Version : Forum Version : phpBB3
Awards :
View all awards
View user profile http://tokyoghoular.foruns.com.pt/

PostRhino.Freak on Sun 12 Jun 2016, 15:37

Is it possible to show random topics from a specific subforum?
avatar
Ange Tuteur
Administrator
Title :
Coffee Addict
Gender : Male
Age : 21
Posts : 4698
Points : 9534
Reputation : 2337
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 13 Jun 2016, 10:31

@Rhino.Freak yeah it's possible, but you'd need to create a script which will crawl that specific sub-forum so it can put all topics within that forum into an array. I don't think there's any simple way to go about it like using variables, unfortunately. Think

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