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.

Posting Reactions

View previous topic View next topic Go down

Solved Posting Reactions

Post by MasterofChaos on July 4th 2014, 2:01 pm

My forum is trying to use something that can post random images from my selection after a certain post. Though the dice generator is too limited for what I need it for. Is there any code that can make a randomization program work with the posting system?

MasterofChaos
Forumember

Posts : 55
Reputation : 1
Language : english

Back to top Go down

Solved Re: Posting Reactions

Post by Ange Tuteur on July 4th 2014, 4:27 pm

Hello MasterofChaos,

You could probably do something through JavaScript to enter a random object into the editor. It would probably take a bit of editing on your part, though. If that's not a problem with you, I can write a small draft.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Posting Reactions

Post by MasterofChaos on July 4th 2014, 4:49 pm

editing wont really be a problem i just no idea how to start the code lol

MasterofChaos
Forumember

Posts : 55
Reputation : 1
Language : english

Back to top Go down

Solved Re: Posting Reactions

Post by Ange Tuteur on July 4th 2014, 5:26 pm

Okay give this a try ^^
Administration panel > Modules > JavaScript codes management > Create a new script

Title : Your choice
Placement : in all the pages
Paste the code below :
Code:
$(function(){$(function() {
 var buttonImage = 'http://illiweb.com/rs3/58/frm/SCEditor/src/themes/icons/src/famfamfam/faspoiler.png';
 var n = 5;
 
 $('.sceditor-button-source').before('<a class="sceditor-button sceditor-button-randomI"><div style="background-image:url('+buttonImage+');"></div></a>');
 $('.sceditor-button-randomI').click(function() {
  var rand = Math.floor( Math.random() * n + 1 );
 
  if (rand === 1) var content = '1';
  if (rand === 2) var content = '2';
  if (rand === 3) var content = '3';
  if (rand === 4) var content = '4';
  if (rand === 5) var content = '5';
 
  $('#text_editor_textarea').sceditor('instance').insertText('',content);
 
 });
})});

At the beginning we have the variable buttonImage here you can change the icon that is displayed on the button by replacing the current URL with another. Next is n, n holds a number value which will be the amount of random results we want. Currently it is set to 5. Using Math.random() we'll add n + 1 = 0-6; our result is the occurrence of 0, 1, 2, 3, 4, or 5, but we exclude 0 to less confuse things.

Now the last thing you need to modify is the conditions. A condition is simple : If a certain condition is met, let's say n is exactly equal to 5, then we'll display a popup saying "You win !". In this case we'll be using strings(text), see below our current conditions :
Code:
if (rand === 1) var content = '1'; // if rand contains the value 1, then this will be the resulting text
if (rand === 2) var content = '2'; // read the comment above but replace 1 w/ 2
if (rand === 3) var content = '3'; // I'll be entered into the editor if rand loves m-- I mean is 3
if (rand === 4) var content = '4';
if (rand === 5) var content = '5';

Simply put, all you need to do is replace the values between the single quotes with your own, and if you increase the value of n add another condition. So if n is equal to 20 we'll have 20 conditions, make sure to change the number in the condition too ! ex : if (rand === 20)

In your case you're adding images correct ? This is how it would look :
Code:
$(function(){$(function() {
 var buttonImage = 'http://illiweb.com/rs3/58/frm/SCEditor/src/themes/icons/src/famfamfam/faspoiler.png';
 var n = 5;
 
 $('.sceditor-button-source').before('<a class="sceditor-button sceditor-button-randomI"><div style="background-image:url('+buttonImage+');"></div></a>');
 $('.sceditor-button-randomI').click(function() {
  var rand = Math.floor( Math.random() * n + 1 );
 
  if (rand === 1) var content = '[img]/myimage.gif[/img]';
  if (rand === 2) var content = '[img]/myimage.gif[/img]';
  if (rand === 3) var content = '[img]/myimage.gif[/img]';
  if (rand === 4) var content = '[img]/myimage.gif[/img]';
  if (rand === 5) var content = '[img]/myimage.gif[/img]';
 
  $('#text_editor_textarea').sceditor('instance').insertText('',content);
 
 });
})});

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Posting Reactions

Post by MasterofChaos on July 4th 2014, 6:05 pm

thanks ill let you know how it goes

MasterofChaos
Forumember

Posts : 55
Reputation : 1
Language : english

Back to top Go down

Solved Re: Posting Reactions

Post by Ange Tuteur on July 5th 2014, 1:04 am

Okay, let me know. Smile

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

Solved Re: Posting Reactions

Post by MasterofChaos on July 17th 2014, 5:02 pm

so far it seems to be working thanks

MasterofChaos
Forumember

Posts : 55
Reputation : 1
Language : english

Back to top Go down

Solved Re: Posting Reactions

Post by Ange Tuteur on July 17th 2014, 7:37 pm

Very good, you're welcome. Smile

Topic archived

If you encounter any bugs you can let me know, or create a new topic.

Ange Tuteur
Forumaster

Male Posts : 13028
Reputation : 2704
Language : EN10, FR5
Location : Pennsylvania

http://fmdesign.forumotion.com

Back to top Go down

View previous topic View next topic Back to top


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