IMPORTANT

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

Latest topics
» Forumactif Edge - Releases
by Ange Tuteur Fri 08 Jun 2018, 11:02

» 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

» Numbering of messages in the topic
by SLGray Mon 04 Dec 2017, 22:40

Recent Tutorials
Top posting users this month
Who is online?
In total there are 5 users online :: 0 Registered, 0 Hidden and 5 Guests

None

[ 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
Gender : Male
Age : 22
Posts : 4733
Points : 9849
Reputation : 2365
Location : Macungie, PA
Language : EN10, FR5
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
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:
<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.

--------

Ange Tuteur
Tips and TricksContact Me

avatar
Rhino.Freak

Gender : Male
Age : 21
Posts : 275
Points : 2124
Reputation : 86
Location : India!
Language : English, Hindi
Browser : Browser : Google Chrome Forum Version : Forum Version : phpBB3
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
Gender : Male
Age : 22
Posts : 4733
Points : 9849
Reputation : 2365
Location : Macungie, PA
Language : EN10, FR5
Browser : Browser : Brave Forum Version : Forum Version : Forumactif Edge
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

--------

Ange Tuteur
Tips and TricksContact Me

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