Results 1 to 6 of 6

Thread: Code Randomizer

  1. #1
    Join Date
    Sep 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Lightbulb Code Randomizer

    Hi,

    I was hoping someone might be able to help me, I wasn't sure whether to post on php or javascript.

    I've created a toolbar at the bottom of my side that I'd like to use to rotate my Follow, Fan and Subscribe buttons ramdomly. I've seen a few javascripts out there that do this for quotes and images, but when using the arrays of javascript it creates a lot of confusion in having quotes and single quotes that are within the code, with an additional set of array quotes. What script would you recommend?

    I want to randomize these 3 codes:

    Code:
    <div class="fb-like" data-href="https://facebook.com/***" data-send="false" data-width="320" data-show-faces="false" data-colorscheme="dark" data-font="trebuchet ms"></div>
    
    <form id="mc-embedded-subscribe-form" name="mc-embedded-subscribe-form" method="post" class="validate" target="_blank"
    action="http://lonlf.us5.list-manage1.com/subscribe/post?u=8200626871fa13">
    <input style="margin-top: 36px; margin-left: 9px; margin-right: 9px;
    width:140px;" name="EMAIL" id="mce-EMAIL" value="Enter your email..." type="email" class="required email" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;">
    <input type="submit" value="Subscribe" name="subscribe" id="mc-embedded-subscribe" class="button" style="vertical-align:bottom;">
    </form>
    
    <a href="https://twitter.com/Lon" class="twitter-follow-button" data-show-count="false" data-show-screen-name="false">Follow @Lon</a>
    <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
    Last edited by jscheuer1; 11-01-2012 at 03:49 AM. Reason: Format

  2. #2
    Join Date
    May 2012
    Location
    Hitchhiking the Galaxy
    Posts
    1,013
    Thanks
    47
    Thanked 139 Times in 139 Posts
    Blog Entries
    1

    Default

    there's a whole thread on a script similar here:
    http://www.dynamicdrive.com/forums/s...ng-tesimonials
    you can stop any problems you have with multiple quote marks by simply escaping all of them before pasting them in.
    "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program." - Linus Torvalds
    Anime Views Forums
    Bernie

  3. #3
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,998
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    12

    Default

    Maybe you could save each code snippet into its own txt file and save them as 1.txt, 2.txt and 3.txt, in the same folder.

    Then you could use php to randomise the numbers in an include;

    Code:
    <?php
    $snippet = array('1', '2', '3');
    shuffle($snippet);
    include('path/to/snippets/'.$snippet.'.txt');
    ?>
    Same method could be used for randomising images too - just change 'txt' in the code above to 'jpg' or whatever.
    Last edited by Beverleyh; 11-01-2012 at 12:13 PM.
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

  4. #4
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,807
    Thanks
    2
    Thanked 423 Times in 417 Posts

    Default

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <style type="text/css">
    /*<![CDATA[*/
    #tst {
      position:absolute;left:100px;top:100px;width:400px;height:50px;
    }
    
    ,div {
      height:50px;width:100%;
    }
    
    /*]]>*/
    </style></head>
    
    <body>
     <div id="tst" onmouseover="zxcRandomRotate.Pause('tst');"  onmouseout="zxcRandomRotate.Auto('tst');">
      <div class="div" style="background-Color:red;" >Any HTML 1</div>
      <div class="div" style="background-Color:green;" >Any HTML 2</div>
      <div class="div" style="background-Color:blue;" >Any HTML 3</div>
     </div>
    <script> vic=0; </script>
    <form name=Show id=Show style="position:absolute;visibility:visible;top:700px;left:0px;" >
    <input size=100 name=Show0 >
    <input size=10 name=Show1 >
    <input size=10 name=Show2 >
    <input size=10 name=Show3 >
    <input size=10 name=Show4 >
    <input size=10 name=Show5 >
    <input size=10 name=Show6 >
    <input size=10 name=Show7 >
    <input size=10 name=Show8 >
    <input size=10 name=Show9 ><br>
    <textarea name=TA rows=1 cols=100 ></textarea>
    </form>
    
    <script type="text/javascript">
    /*<![CDATA[*/
    
    var zxcRandomRotate={
    
     init:function(o){
      var id=o.ID,hold=o.Hold,obj=document.getElementById(id),clds=obj.childNodes,ary=[],z0=0;
      for (;z0<clds.length;z0++){
       if (clds[z0].nodeType==1){
        clds[z0].style.position='absolute';
        clds[z0].style.zIndex='0';
        clds[z0].style.left='0px';
        clds[z0].style.top='0px';
        ary.push(clds[z0]);
       }
      }
      o=this['zxc'+id]={
       id:id,
       ary:ary,
       hold:typeof(hold)=='number'?hold:5000,
       nu:-1
      }
      this.rotate(o);
     },
    
     Auto:function(id){
      var o=this['zxc'+id],oop=this;
      if (o){
       o.to=setTimeout(function(){ oop.rotate(o); },500);
      }
     },
    
     Pause:function(id){
      var o=this['zxc'+id];
      if (o){
       clearTimeout(o.to);
      }
     },
    
     rotate:function(o){
      var nu=Math.floor(Math.random()*o.ary.length),oop=this;
      while (nu==o.nu){
       nu=Math.floor(Math.random()*o.ary.length);
      }
      if (o.ary[o.nu]){
       o.ary[o.nu].style.zIndex='0';
      }
      o.ary[nu].style.zIndex='1';
      o.nu=nu;
      o.to=setTimeout(function(){ oop.Auto(o.id); },o.hold);
     }
    
    
    }
    
    zxcRandomRotate.init({
     ID:'tst',
     Hold:2000
    });
    
    /*]]>*/
    </script>
    
    </body>
    
    </html>
    Vic
    God Loves You and will never love you less.
    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  5. #5
    Join Date
    Sep 2012
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by Beverleyh View Post
    Maybe you could save each code snippet into its own txt file and save them as 1.txt, 2.txt and 3.txt, in the same folder.

    Then you could use php to randomise the numbers in an include;

    Code:
    <?php
    $snippet = array('1', '2', '3');
    shuffle($snippet);
    include('path/to/snippets/'.$snippet.'.txt');
    ?>
    Same method could be used for randomising images too - just change 'txt' in the code above to 'jpg' or whatever.
    This would be perfect. Unfortunately the place I'm trying to run the randomizing script (wordpress plugin toolbar) doesn't seem to display any php include functions. I would try the other javascript suggestion but it's too long for the "message/code to display" text box. Would there be any other possible way?

  6. #6
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    1,998
    Thanks
    16
    Thanked 315 Times in 313 Posts
    Blog Entries
    12

    Default

    I don't use Wordpress a great deal so I'm not sure of the limitation it poses.

    Maybe this would be a better question for a Wordpress forum?
    Focus on Function Web Design | Latest News RSS | Facebook | Twitter |
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps |
    The only limit to creativity is imagination: JemCon.org

Similar Threads

  1. PHP randomizer show file and filename
    By Feldt in forum Looking for such a script or service
    Replies: 5
    Last Post: 07-24-2008, 11:41 PM
  2. randomizer
    By geebee2008 in forum JavaScript
    Replies: 3
    Last Post: 01-15-2008, 05:03 PM
  3. including randomizer
    By chrigman in forum JavaScript
    Replies: 5
    Last Post: 09-05-2005, 08:27 PM
  4. Randomizer
    By Rayban in forum HTML
    Replies: 5
    Last Post: 07-09-2005, 02:18 PM
  5. Watermark Background Image randomizer script
    By Rayban in forum Dynamic Drive scripts help
    Replies: 1
    Last Post: 02-15-2005, 12:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •