Wednesday, 20 March 2013

Create Your Own Custom Lorem Ipsum Generator using Javascript


Create Your Own Custom Lorem Ipsum Generator using Javascript

Well If Your are a Graphics Designer/HTML Designer you might come up to a situation to write some text in the blank HTML template to fill up the gap. You should have browsed over the net to find an online Lorem Ipsum generator to get the dummy para.

But I dont believe in using others tools when I can create my own...



<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">

    <title>Lorem Ipsum Generator</title>
    
<script type="text/javascript" language="javascript">
    //<![CDATA[

    function objectTag()
    {
     var lorem = new Array();

     switch( document.theForm.loremString.value )
     {
      case "latin":
      {
    lorem[0] = "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.";
    lorem[1] = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.";
    lorem[2] = "Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.";
    lorem[3] = "Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.";
    lorem[4] = "Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.";
    lorem[5] = "At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.";
    lorem[6] = "Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus.";
       break;
      }
      case "silly":
      {
    lorem[0] = "Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum. Defacto lingo est igpay atinlay. Marquee selectus non provisio incongruous feline nolo contendre. Gratuitous octopus niacin, sodium glutimate. Quote meon an estimate et non interruptus stadium.";
    lorem[1] = "Sic tempus fugit esperanto hiccup estrogen. Glorious baklava ex librus hup hey ad infinitum. Non sequitur condominium facile et geranium incognito. Epsum factorial non deposit quid pro quo hic escorol. Marquee selectus non provisio incongruous feline nolo contendre Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum.";
    lorem[2] = "Defacto lingo est igpay atinlay. Marquee selectus non provisio incongruous feline nolo contendre. Gratuitous octopus niacin, sodium glutimate. Quote meon an estimate et non interruptus stadium. Sic tempus fugit esperanto hiccup estrogen. Glorious baklava ex librus hup hey ad infinitum. Non sequitur condominium facile et geranium incognito. Epsum factorial non deposit quid pro quo hic escorol. Olypian quarrels et gorilla congolium sic ad nauseum. Souvlaki ignitus carborundum e pluribus unum. Defacto lingo est igpay atinlay. Gratuitous octopus niacin, sodium glutimate.";
    lorem[3] = "Quote meon an estimate et non interruptus stadium. Sic tempus fugit esperanto hiccup estrogen. Glorious baklava ex librus hup hey ad infinitum. Non sequitur condominium facile et geranium incognito.";
       break;
      }
      case "spanish":
      {
       lorem[0] = "Li Europan lingues es membres del sam familie. Lor separat existentie es un myth. Por scientie, musica, sport etc., li tot Europa usa li sam vocabularium. Li lingues differe solmen in li grammatica, li pronunciation e li plu commun vocabules. Omnicos directe al desirabilit&aacute; de un nov lingua franca: on refusa continuar payar custosi traductores. It solmen va esser necessi far uniform grammatica, pronunciation e plu sommun paroles.";
       break;
      }
      case "italian":
      {
       lorem[0] = "Ma quande lingues coalesce, li grammatica del resultant lingue es plu simplic e regulari quam ti del coalescent lingues. Li nov lingua franca va esser plu simplic e regulari quam li existent Europan lingues. It va esser tam simplic quam Occidental: in fact, it va esser Occidental. A un Angleso it va semblar un simplificat Angles, quam un skeptic Cambridge amico dit me que Occidental es."
       break;
      }
     }

        if( "characters" == document.theForm.type.value )
        {
         var outputString = '';
            var numOfChars = document.theForm.numbers.value;
            numOfChars = parseInt( numOfChars );
            var tempString = lorem.join( "\n\n" );
            while ( outputString.length < numOfChars ) outputString += tempString;
            document.forms[0].output.value = outputString.substring(0, numOfChars );
        }
        else if( "words" == document.theForm.type.value )
        {
            var numOfWords = document.theForm.numbers.value;
            numOfWords = parseInt( numOfWords );

            var list = new Array();
            var wordList = new Array();
            wordList = lorem[ 0 ].split( ' ' );
            var iParagraphCount = 0;
            var iWordCount = 0;

            while( list.length < numOfWords )
            {
             if( iWordCount > wordList.length )
             {
              iWordCount = 0;
              iParagraphCount++;
              if( iParagraphCount + 1 > lorem.length ) iParagraphCount = 0;
              wordList = lorem[ iParagraphCount ].split( ' ' );
              wordList[ 0 ] = "\n\n" + wordList[ 0 ];
             }

             list.push( wordList[ iWordCount ] );

             iWordCount++;
            }
            document.forms[0].output.value = list.join( ' ' );
        }
        else
        {
            var numOfParagraphs = document.theForm.numbers.value;
            numOfParagraphs = parseInt( numOfParagraphs );

            var list = new Array();
   var iParagraphCount = 0;

            while( list.length < numOfParagraphs )
            {
             if( iParagraphCount +1 > lorem.length )
             {
              iParagraphCount = 0;
             }

             list.push( lorem[ iParagraphCount ] );
             iParagraphCount++;
            }
            document.forms[0].output.value = list.join( "\n\n" );
        }
    }

    function copypaste()
    {
        document.forms[0].output.focus();
        document.forms[0].output.select();
        therange=document.forms[0].output.createTextRange();
        therange.execCommand("Copy");
    }
    //]]>
</script>


<style type="text/css">

body {
 background-color : white;
 font-family : Arial, Helvetica, sans-serif;
 font-size   : .9em;
 color       : #424037;
 max-width   : 700px;
 padding     : 15px;
 margin      : auto;
}

td {
 font-family : Arial, Helvetica, sans-serif;
 font-size   : .9em;
 color       : #424037;
}

h1, h2 {
 color : #666;
}

a {
 color : #BC7134;
 text-decoration : none;
}

</style>

</head>

<body>
<h1>Lorem Ipsum Generator</h1>
<form name="theForm" action="javascript:objectTag();" id="theForm"><select name="loremString" style="width: 100%;">
<option value="latin" selected="selected">Lorem ipsum dolor sit amet...</option>
<option value="silly">Epsum factorial non deposit quid pro quo...</option>
<option value="spanish">Li Europan lingues es membres del sam familie...</option>
<option value="italian">Ma quande lingues coalesce, li grammatica...</option>
</select><br>
Number of <select name="type">
<option value="characters">Characters</option>
<option value="words" selected="selected">Words</option>
<option value="paragraphs">Paragraphs</option>
</select> <input type="text" name="numbers" value="8" size="6"> <input type="submit" name="btnOK" value="Generate"><br>
<textarea rows="10" name="output" style="width: 100%;">
</textarea>
<br>
<input type="button" onclick="copypaste()" value="Select All"> to clipboard (IE/Windows only)<br>
</body>
</html>




No comments:

Post a comment

Thank You for Your Comments. We will get back to you soon.

back to top