1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Unmaintained Add Random Text to Your Logo 1.0.0

Have random text next to your logo

  1. Matthew Hawley

    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

    Read more about this resource...
     
  2. Tracy Perry

    Tracy Perry Well-Known Member

    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.
     
  3. Matthew Hawley

    Matthew Hawley Well-Known Member

    I know, sometimes the text does not display. But if you have lots of text it shouldn't be much of a problem.
     
  4. Tracy Perry

    Tracy Perry Well-Known Member

    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.
     
  5. Matthew Hawley

    Matthew Hawley Well-Known Member

    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]);
        });
    });
     
  6. Tracy Perry

    Tracy Perry Well-Known Member

    :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)?
     
  7. Matthew Hawley

    Matthew Hawley Well-Known Member

    Doesn't work. Could you post the code your using?
     
  8. Tracy Perry

    Tracy Perry Well-Known Member

    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:
     
  9. Matthew Hawley

    Matthew Hawley Well-Known Member

    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. :)
     

Share This Page