Resource icon

Add Random Text to Your Logo 1.0.0

No permission to download

Matthew Hawley

Well-known member
yolulz submitted a new resource:

Add Random Text to your Logo (version 1.0.0) - Have random text next to your logo

Upload the files to your root folder. You change quotes.txt to whatever you want, just make sure @ is after every line.

1. Add this to logo_block. Depending on where your logo is you might have to change the top and left. Or you can move away form your logo. You can also change the css to your liking.
If you dont want the logo to be vertical you can remove the webkit-transform.

Code:
<script type="text/javascript" src="js/jquery/randomtext.js"></script>
<style type="text/css">
.quotes {...

Read more about this resource...
 
Haven't checked it fully, but several times I don't get a display when I go to another page on the forum (mine). I only have 3 lines in the quotes.txt, each terminated with a "@" sign as instructed. I can do a refresh a couple of times and it will finally show up, but only does 2 of the 3.

EDIT: OK, I got to playing around with the .js file and I "think" what my problem is lay in this snippet of code
Code:
var idx = Math.floor(quotes.length * Math.random());

If I change to the following it all works for the 3 I have.
Code:
var idx = Math.floor(3 * Math.random());
It appears (at least on my forum) not to be able to ascertain the exact number of quotes by the quotes.length segment.
I'm no means a coder of any type, so this may not even a problem.
 
I know, sometimes the text does not display. But if you have lots of text it shouldn't be much of a problem.

So far, I've been successful by defining the number of lines using the code:
Code:
var idx = Math.floor ( Math.random ()*3 + 1);
I think what is happening is the code you have uses a 0 and that is where the blank display is coming from since there is no line 0. From my reading (and remember - I'm no coder) by adding a +1 to it you get a number between 1 and 3 for the random (which is how many lines of text I have in my file). As for reading the number of lines from a text file to get the variable... WAY beyond me right now but you got my curiosity up... and I'm like that danged cat.
 
Lol, now I'm the one asking the questions. Doesn't work.

Code:
jQuery(document).ready(function($) {
    $.get('quotes.txt', function(data) {
        var quotes = data.split("\@");
        var idx = Math.floor(quotes.length * Math.random()*3 + 1);
        $('.quotes').html(quotes[idx]);
    });
});
 
Lol, now I'm the one asking the questions. Doesn't work.

Code:
jQuery(document).ready(function($) {
    $.get('quotes.txt', function(data) {
        var quotes = data.split("\@");
        var idx = Math.floor(quotes.length * Math.random()*3 + 1);
        $('.quotes').html(quotes[idx]);
    });
});

:D
Try making it either
Code:
 (quotes.length * Math.random()+1);
or
Code:
(Math.Random() * #quotes in your text file + 1);
You have to use either the quotes.length (which I'm not far enough along to recognize how it pulls the line numbers from a text file) or the actual number of lines in your quotes.txt.
I did read that allowing the .js to read from a text file "could" be a security problem. Have you explored the PHP functions that will allow you to read in text in a secure manner (if it is any more secure - like I said I'm just teaching myself a little of this at a time as I come across it)?
 
Doesn't work. Could you post the code your using?

Code:
jQuery(document).ready(function($) {
    $.get('quotes.txt', function(data) {
        var quotes = data.split("\@");
        var idx = Math.floor ( Math.random()*5+1);
        $('.quotes').html(quotes[idx]);
    });
});
This is the exact code I'm using on my forum for the randomtext.js. I just noticed tho' that I'm still getting a blank one occasionally so it must lay somewhere else. Time for more digging - guess I'm going to learn how to write in javascript eventually!:LOL:
 
I'll try to find it too. I'm not an expert, just something I made from reading on the web. If you find it I'll be sure to give you credit on the update. :)
 
Back
Top Bottom