Javascript Formatter?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John Dalberg

    Javascript Formatter?


    I have spent 1/2 hour looking for a Javascript formatter with no luck.
    I am using a tool that produces Javascript statements in one long string
    and it's hard to read.

    Any recommendations ? I see a .NET tool at codeproject but that site is
    down.
  • Jim Ley

    #2
    Re: Javascript Formatter?

    On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <john_dd@hotmai l.com>
    wrote:
    [color=blue]
    >
    >I have spent 1/2 hour looking for a Javascript formatter with no luck.
    >I am using a tool that produces Javascript statements in one long string
    >and it's hard to read.
    >
    >Any recommendations ?[/color]

    IE does a good job:

    alert(function( ) { /* LongString*/ })

    Jim.
    --
    comp.lang.javas cript FAQ - http://jibbering.com/faq/

    Comment

    • John Dalberg

      #3
      Re: Javascript Formatter?

      On Sun, 15 Feb 2004 22:24:26 GMT, Jim Ley wrote:
      [color=blue]
      > On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <john_dd@hotmai l.com>
      > wrote:
      >[color=green]
      >> [6 quoted line(s) supressed][/color]
      >
      > IE does a good job:
      >
      > alert(function( ) { /* LongString*/ })[/color]

      It doesn't work. Long string as in a few lines in Wordpad.

      J.

      Comment

      • Jim Ley

        #4
        Re: Javascript Formatter?

        On Sun, 15 Feb 2004 20:48:14 -0800, John Dalberg <john_dd@hotmai l.com>
        wrote:
        [color=blue]
        >On Sun, 15 Feb 2004 22:24:26 GMT, Jim Ley wrote:
        >[color=green]
        >> On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <john_dd@hotmai l.com>
        >> wrote:
        >>[color=darkred]
        >>> [6 quoted line(s) supressed][/color]
        >>
        >> IE does a good job:
        >>
        >> alert(function( ) { /* LongString*/ })[/color]
        >
        >It doesn't work. Long string as in a few lines in Wordpad.[/color]

        It does for me....

        Perhaps you should provide an example which demonstrates your problem.

        astyle is of course perhaps a more normal recommendation, but it's a
        little pointless when you already have something that does the job.

        Jim.
        --
        comp.lang.javas cript FAQ - http://jibbering.com/faq/

        Comment

        • John Dalberg

          #5
          Re: Javascript Formatter?

          On Mon, 16 Feb 2004 18:31:52 GMT, Jim Ley wrote:
          [color=blue]
          > On Sun, 15 Feb 2004 20:48:14 -0800, John Dalberg <john_dd@hotmai l.com>
          > wrote:
          >[color=green]
          >> [12 quoted line(s) supressed][/color]
          >
          > It does for me....
          >
          > Perhaps you should provide an example which demonstrates your problem.
          >
          > astyle is of course perhaps a more normal recommendation, but it's a
          > little pointless when you already have something that does the job.
          >[/color]
          Here's one:

          var cspbDetectedBro wser='IE5DHTML' ;var cspbVS='cspbPan elBarLoading';v ar
          cspbGD=new Object();var cspbFO=true;var cspbTL=0;var cspbTD=0;var
          cspbGDH=0;var cspbEIA=false;f unction
          cspbShowSection (){if(cspbEIA){ return;}if(cspb VS=='cspbPanelB arLoading'){doc
          ument.all.cspbB uttons.style.di splay='inline'; document.all[cspbVS].style.dis
          play='none';csp bVS='';}var
          count=0;for(cou nt=0;count<argu ments.length;co unt++){var
          id=arguments[count];if(typeof(id)= ='string'){id=c spbGetGroupInde x(id);}if(d
          ocument.all['cspbGroup'+id]){cspbGD=docume nt.all['cspbGroup'+id];if(cspbGD.
          style.display== 'inline'){docum ent.all['cspbBtnCell'+i d].className='csp bBtnC
          ell';if(navigat or.platform!='M acPPC'){cspbGDH =cspbGD.offsetH eight;cspbEC(0)
          ;}else{cspbGD.s tyle.display='n one';}}else{doc ument.all['cspbBtnCell'+i d].cl
          assName='cspbBt nCellSlt';cspbG D.style.display ='inline';if(!c spbFO&&navigato
          r.platform!='Ma cPPC'){cspbGDH= cspbGD.offsetHe ight;cspbGD.sty le.height=1;csp
          bEO(cspbGDH);}} }}cspbFO=false; }function cspbGetGroupInd ex(caption){var
          aCaptions=new
          Array();aCaptio ns[0]='Customers';aC aptions[1]='Orders';aCapt ions[2]='Orders
          2';aCaptions[3]='About Us';var
          count=0;for(cou nt=0;count<aCap tions.length;co unt++){if(aCapt ions[count]==ca
          ption){return count;}}return 0;}function
          cspbHBT(id){doc ument.all['cspbBtnText'+i d].className='csp bBtnHvr';}funct ion
          cspbDBT(id){doc ument.all['cspbBtnText'+i d].className='csp bBtn';}function
          cspbEO(l){var
          RES=3;cspbEIA=t rue;cspbTL=l;if (cspbTL==0){csp bGD.style.heigh t=cspbGDH;cspbE
          IA=false;}else{ if(cspbTL<=RES) {cspbTD=1;}else {cspbTD=parseIn t(cspbTL/RES);}
          if(cspbGDH!=csp bTL){cspbGD.sty le.height=cspbG DH-cspbTL;}setTime out('cspbEO(
          cspbTL-cspbTD);',25);} }function cspbEC(l){var
          RES=6;cspbEIA=t rue;cspbTL=l;if (cspbGDH==cspbT L){cspbGD.style .display='none'
          ;cspbGD.style.h eight=cspbGDH;c spbEIA=false;}e lse{if((cspbGDH-cspbTL)<=RES){
          cspbTD=1;}else{ cspbTD=parseInt ((cspbGDH-cspbTL)/RES);}cspbGD.st yle.height=c
          spbGDH-cspbTL;setTimeo ut('cspbEC(cspb TL+cspbTD);',10 );}}function
          cspbRefresh(){} function cspbSetHeight(p x){}var cspbFSTID;var cspbFSIID;var
          cspbFSE=false;f unction
          cspbWSEH(){if(c spbFSE==true){c learTimeout(csp bFSTID);cspbFST ID=window.setTi
          meout('cspbSFSI ();',200);}else
          if((navigator.u serAgent.indexO f('MSIE')>-1)&&(navigator. platform!='MacP PC')
          ){cspbFSE=true; }}function
          cspbSFSI(){clea rInterval(cspbF SIID);cspbFSIID =window.setInte rval('cspbFS();
          ',1);}function cspbFS(){var
          scrollTop=parse Int(document.bo dy.scrollTop)+0 ;var
          PBTop=parseInt( document.all['cspbPanelBar'].style.top);if( scrollTop==PBTo p)
          {clearInterval( cspbFSIID);}els e
          if(PBTop<scroll Top){if((scroll Top-PBTop)<=6){docu ment.all['cspbPanelBar'].s
          tyle.top=PBTop+ 1;}else{documen t.all['cspbPanelBar'].style.top=pars eInt(PBTo
          p+((scrollTop-PBTop)/6));}}else{if(( PBTop-scrollTop)<=6){ document.all['cspb
          PanelBar'].style.top=PBTo p-1;}else{documen t.all['cspbPanelBar'].style.top=p
          arseInt(PBTop-((PBTop-scrollTop)/6));}}}function cspbASH(){var
          e=window.onscro ll;if
          (typeof(e)=='fu nction'){e=e.to String();e=e.su bstring(e.index Of('{')+1,e.las
          tIndexOf('}')); var
          f=cspbWindowScr oll.toString(); f=f.substring(f .indexOf('{')+1 ,f.lastIndexOf(
          '}'));var sh=new
          Function(f+e);w indow.onscroll= sh;}else{window .onscroll=cspbW SEH;}}if(naviga
          tor.platform!=' MacPPC'){this.a ttachEvent('ons croll',cspbWSEH );}

          Comment

          • Lasse Reichstein Nielsen

            #6
            Re: Javascript Formatter?

            John Dalberg <john_dd@hotmai l.com> writes:
            [color=blue]
            > Here's one:[/color]

            Not a very good example, because your news client broke the
            lines. That means that the code we see is not even syntactically
            correct Javascript, and we will have to work harder to just make it
            correct again, before we can start solving the problem.

            As for the method:
            Take that code, and put it into another file. Write these lines before
            the code:
            <script type="text/javascript">
            function foo(){
            and this after:
            };
            document.write( "<pre>"+foo.toS tring()+"<\/pre>");
            </script>
            and load it into your browser as an HTML file. Use cut'n'paste to
            pick out the area between
            function foo() {
            and
            }

            In Opera it makes the blocks structure much clearer. In IE it doesn't
            help that much. Mozilla FireFox is by far the prettiest, with
            indentation and everything. Your code, as displayed by FireFox, is
            here (if the lines are broken, check your newsreader):

            ---
            var cspbDetectedBro wser = "IE5DHTML";
            var cspbVS = "cspbPanelBarLo ading";
            var cspbGD = new Object();
            var cspbFO = true;
            var cspbTL = 0;
            var cspbTD = 0;
            var cspbGDH = 0;
            var cspbEIA = false;

            function cspbShowSection () {
            if (cspbEIA) {
            return;
            }
            if (cspbVS == "cspbPanelBarLo ading") {
            document.all.cs pbButtons.style .display = "inline";
            document.all[cspbVS].style.display = "none";
            cspbVS = "";
            }
            var count = 0;
            for (count = 0; count < arguments.lengt h; count++) {
            var id = arguments[count];
            if (typeof (id) == "string") {
            id = cspbGetGroupInd ex(id);
            }
            if (document.all["cspbGroup" + id]) {
            cspbGD = document.all["cspbGroup" + id];
            if (cspbGD.style.d isplay == "inline") {
            document.all["cspbBtnCel l" + id].className = "cspbBtnCel l";
            if (navigator.plat form != "MacPPC") {
            cspbGDH = cspbGD.offsetHe ight;
            cspbEC(0);
            } else {
            cspbGD.style.di splay = "none";
            }
            } else {
            document.all["cspbBtnCel l" + id].className = "cspbBtnCellSlt ";
            cspbGD.style.di splay = "inline";
            if (!cspbFO && navigator.platf orm != "MacPPC") {
            cspbGDH = cspbGD.offsetHe ight;
            cspbGD.style.he ight = 1;
            cspbEO(cspbGDH) ;
            }
            }
            }
            }
            cspbFO = false;
            }


            function cspbGetGroupInd ex(caption) {
            var aCaptions = new Array();
            aCaptions[0] = "Customers" ;
            aCaptions[1] = "Orders";
            aCaptions[2] = "Orders2";
            aCaptions[3] = "About Us";
            var count = 0;
            for (count = 0; count < aCaptions.lengt h; count++) {
            if (aCaptions[count] == caption) {
            return count;
            }
            }
            return 0;
            }


            function cspbHBT(id) {
            document.all["cspbBtnTex t" + id].className = "cspbBtnHvr ";
            }


            function cspbDBT(id) {
            document.all["cspbBtnTex t" + id].className = "cspbBtn";
            }


            function cspbEO(l) {
            var RES = 3;
            cspbEIA = true;
            cspbTL = l;
            if (cspbTL == 0) {
            cspbGD.style.he ight = cspbGDH;
            cspbEIA = false;
            } else {
            if (cspbTL <= RES) {
            cspbTD = 1;
            } else {
            cspbTD = parseInt(cspbTL / RES);
            }
            if (cspbGDH != cspbTL) {
            cspbGD.style.he ight = cspbGDH - cspbTL;
            }
            setTimeout("csp bEO(cspbTL-cspbTD);", 25);
            }
            }


            function cspbEC(l) {
            var RES = 6;
            cspbEIA = true;
            cspbTL = l;
            if (cspbGDH == cspbTL) {
            cspbGD.style.di splay = "none";
            cspbGD.style.he ight = cspbGDH;
            cspbEIA = false;
            } else {
            if ((cspbGDH - cspbTL) <= RES) {
            cspbTD = 1;
            } else {
            cspbTD = parseInt((cspbG DH - cspbTL) / RES);
            }
            cspbGD.style.he ight = cspbGDH - cspbTL;
            setTimeout("csp bEC(cspbTL+cspb TD);", 10);
            }
            }


            function cspbRefresh() {
            }


            function cspbSetHeight(p x) {
            }

            var cspbFSTID;
            var cspbFSIID;
            var cspbFSE = false;

            function cspbWSEH() {
            if (cspbFSE == true) {
            clearTimeout(cs pbFSTID);
            cspbFSTID = window.setTimeo ut("cspbSFSI(); ", 200);
            } else {
            if ((navigator.use rAgent.indexOf( "MSIE") > -1) &&
            (navigator.plat form != "MacPPC")) {
            cspbFSE = true;
            }
            }
            }


            function cspbSFSI() {
            clearInterval(c spbFSIID);
            cspbFSIID = window.setInter val("cspbFS();" , 1);
            }


            function cspbFS() {
            var scrollTop = parseInt(docume nt.body.scrollT op) + 0;
            var PBTop = parseInt(docume nt.all.cspbPane lBar.style.top) ;
            if (scrollTop == PBTop) {
            clearInterval(c spbFSIID);
            } else {
            if (PBTop < scrollTop) {
            if ((scrollTop - PBTop) <= 6) {
            document.all.cs pbPanelBar.styl e.top = PBTop + 1;
            } else {
            document.all.cs pbPanelBar.styl e.top = parseInt(PBTop + ((scrollTop - PBTop) / 6));
            }
            } else {
            if ((PBTop - scrollTop) <= 6) {
            document.all.cs pbPanelBar.styl e.top = PBTop - 1;
            } else {
            document.all.cs pbPanelBar.styl e.top = parseInt(PBTop - ((PBTop - scrollTop) / 6));
            }
            }
            }
            }


            function cspbASH() {
            var e = window.onscroll ;
            if (typeof (e) == "function") {
            e = e.toString();
            e = e.substring(e.i ndexOf("{") + 1, e.lastIndexOf(" }"));
            var f = cspbWindowScrol l.toString();
            f = f.substring(f.i ndexOf("{") + 1, f.lastIndexOf(" }"));
            var sh = new Function(f + e);
            window.onscroll = sh;
            } else {
            window.onscroll = cspbWSEH;
            }
            }

            if (navigator.plat form != "MacPPC") {
            this.attachEven t("onscroll", cspbWSEH);
            }
            ---

            Good luck
            /L
            --
            Lasse Reichstein Nielsen - lrn@hotpop.com
            DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
            'Faith without judgement merely degrades the spirit divine.'

            Comment

            • Ira Baxter

              #7
              Re: Javascript Formatter?


              "John Dalberg" <john_dd@hotmai l.com> wrote in message
              news:zw30p2luas o4$.1hnbuil6c24 rz$.dlg@40tude. net...[color=blue]
              >
              > I have spent 1/2 hour looking for a Javascript formatter with no luck.
              > I am using a tool that produces Javascript statements in one long string
              > and it's hard to read.[/color]

              Did you try Googling for "JavaScript Formatter"?
              The first 20 entries or so like like perfectly good formatters to me.

              -- IDB





              ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
              http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
              ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

              Comment

              • Randy Webb

                #8
                Re: Javascript Formatter?

                Ira Baxter wrote:[color=blue]
                > "John Dalberg" <john_dd@hotmai l.com> wrote in message
                > news:zw30p2luas o4$.1hnbuil6c24 rz$.dlg@40tude. net...
                >[color=green]
                >>I have spent 1/2 hour looking for a Javascript formatter with no luck.
                >>I am using a tool that produces Javascript statements in one long string
                >>and it's hard to read.[/color]
                >
                >
                > Did you try Googling for "JavaScript Formatter"?
                > The first 20 entries or so like like perfectly good formatters to me.[/color]

                Your answer, of course, is not related to the SEMDesigns purchase of the
                #1 hit now would it? But whats the point in paying 50 dollars US for
                something that can be done for free? Sheesh.

                --
                Randy
                Chance Favors The Prepared Mind
                comp.lang.javas cript FAQ - http://jibbering.com/faq/

                Comment

                • Lasse Reichstein Nielsen

                  #9
                  Re: Javascript Formatter?

                  Randy Webb <hikksnotathome @aol.com> writes:
                  [color=blue]
                  > Your answer, of course, is not related to the SEMDesigns purchase of
                  > the #1 hit now would it?[/color]

                  I'd say he was very nice about not pointing to it. :)
                  [color=blue]
                  > But whats the point in paying 50 dollars US for something that can
                  > be done for free? Sheesh.[/color]

                  Like this one:
                  ---
                  <textarea id="input" style="width:10 0%;height:10em" >Enter code here</textarea>
                  <input type="button" value="format"
                  onclick="var inp=document.ge tElementById('i nput');
                  var str=Function(in p.value).toStri ng();
                  str=str.substri ng(str.indexOf( '{')+1);
                  str=str.substri ng(0,str.lastIn dexOf('}'));
                  inp.value=str;" >
                  ---
                  run in (preferably) Mozilla. Unless you like your comments ofcourse :)

                  /L
                  --
                  Lasse Reichstein Nielsen - lrn@hotpop.com
                  DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
                  'Faith without judgement merely degrades the spirit divine.'

                  Comment

                  Working...