473,420 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

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.
Jul 20 '05 #1
8 1944
On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <jo*****@hotmail.com>
wrote:

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?


IE does a good job:

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

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

Jul 20 '05 #2
On Sun, 15 Feb 2004 22:24:26 GMT, Jim Ley wrote:
On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <jo*****@hotmail.com>
wrote:
[6 quoted line(s) supressed]


IE does a good job:

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


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

J.
Jul 20 '05 #3
On Sun, 15 Feb 2004 20:48:14 -0800, John Dalberg <jo*****@hotmail.com>
wrote:
On Sun, 15 Feb 2004 22:24:26 GMT, Jim Ley wrote:
On Sun, 15 Feb 2004 13:47:44 -0800, John Dalberg <jo*****@hotmail.com>
wrote:
[6 quoted line(s) supressed]


IE does a good job:

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


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


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.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #4
On Mon, 16 Feb 2004 18:31:52 GMT, Jim Ley wrote:
On Sun, 15 Feb 2004 20:48:14 -0800, John Dalberg <jo*****@hotmail.com>
wrote:
[12 quoted line(s) supressed]


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.

Here's one:

var cspbDetectedBrowser='IE5DHTML';var cspbVS='cspbPanelBarLoading';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==' cspbPanelBarLoading'){doc
ument.all.cspbButtons.style.display='inline';docum ent.all[cspbVS].style.dis
play='none';cspbVS='';}var
count=0;for(count=0;count<arguments.length;count++ ){var
id=arguments[count];if(typeof(id)=='string'){id=cspbGetGroupIndex(id) ;}if(d
ocument.all['cspbGroup'+id]){cspbGD=document.all['cspbGroup'+id];if(cspbGD.
style.display=='inline'){document.all['cspbBtnCell'+id].className='cspbBtnC
ell';if(navigator.platform!='MacPPC'){cspbGDH=cspb GD.offsetHeight;cspbEC(0)
;}else{cspbGD.style.display='none';}}else{document .all['cspbBtnCell'+id].cl
assName='cspbBtnCellSlt';cspbGD.style.display='inl ine';if(!cspbFO&&navigato
r.platform!='MacPPC'){cspbGDH=cspbGD.offsetHeight; cspbGD.style.height=1;csp
bEO(cspbGDH);}}}}cspbFO=false;}function cspbGetGroupIndex(caption){var
aCaptions=new
Array();aCaptions[0]='Customers';aCaptions[1]='Orders';aCaptions[2]='Orders
2';aCaptions[3]='About Us';var
count=0;for(count=0;count<aCaptions.length;count++ ){if(aCaptions[count]==ca
ption){return count;}}return 0;}function
cspbHBT(id){document.all['cspbBtnText'+id].className='cspbBtnHvr';}function
cspbDBT(id){document.all['cspbBtnText'+id].className='cspbBtn';}function
cspbEO(l){var
RES=3;cspbEIA=true;cspbTL=l;if(cspbTL==0){cspbGD.s tyle.height=cspbGDH;cspbE
IA=false;}else{if(cspbTL<=RES){cspbTD=1;}else{cspb TD=parseInt(cspbTL/RES);}
if(cspbGDH!=cspbTL){cspbGD.style.height=cspbGDH-cspbTL;}setTimeout('cspbEO(
cspbTL-cspbTD);',25);}}function cspbEC(l){var
RES=6;cspbEIA=true;cspbTL=l;if(cspbGDH==cspbTL){cs pbGD.style.display='none'
;cspbGD.style.height=cspbGDH;cspbEIA=false;}else{i f((cspbGDH-cspbTL)<=RES){
cspbTD=1;}else{cspbTD=parseInt((cspbGDH-cspbTL)/RES);}cspbGD.style.height=c
spbGDH-cspbTL;setTimeout('cspbEC(cspbTL+cspbTD);',10);}}f unction
cspbRefresh(){}function cspbSetHeight(px){}var cspbFSTID;var cspbFSIID;var
cspbFSE=false;function
cspbWSEH(){if(cspbFSE==true){clearTimeout(cspbFSTI D);cspbFSTID=window.setTi
meout('cspbSFSI();',200);}else
if((navigator.userAgent.indexOf('MSIE')>-1)&&(navigator.platform!='MacPPC')
){cspbFSE=true;}}function
cspbSFSI(){clearInterval(cspbFSIID);cspbFSIID=wind ow.setInterval('cspbFS();
',1);}function cspbFS(){var
scrollTop=parseInt(document.body.scrollTop)+0;var
PBTop=parseInt(document.all['cspbPanelBar'].style.top);if(scrollTop==PBTop)
{clearInterval(cspbFSIID);}else
if(PBTop<scrollTop){if((scrollTop-PBTop)<=6){document.all['cspbPanelBar'].s
tyle.top=PBTop+1;}else{document.all['cspbPanelBar'].style.top=parseInt(PBTo
p+((scrollTop-PBTop)/6));}}else{if((PBTop-scrollTop)<=6){document.all['cspb
PanelBar'].style.top=PBTop-1;}else{document.all['cspbPanelBar'].style.top=p
arseInt(PBTop-((PBTop-scrollTop)/6));}}}function cspbASH(){var
e=window.onscroll;if
(typeof(e)=='function'){e=e.toString();e=e.substri ng(e.indexOf('{')+1,e.las
tIndexOf('}'));var
f=cspbWindowScroll.toString();f=f.substring(f.inde xOf('{')+1,f.lastIndexOf(
'}'));var sh=new
Function(f+e);window.onscroll=sh;}else{window.onsc roll=cspbWSEH;}}if(naviga
tor.platform!='MacPPC'){this.attachEvent('onscroll ',cspbWSEH);}
Jul 20 '05 #5
John Dalberg <jo*****@hotmail.com> writes:
Here's one:


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.toString()+"<\/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 cspbDetectedBrowser = "IE5DHTML";
var cspbVS = "cspbPanelBarLoading";
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 == "cspbPanelBarLoading") {
document.all.cspbButtons.style.display = "inline";
document.all[cspbVS].style.display = "none";
cspbVS = "";
}
var count = 0;
for (count = 0; count < arguments.length; count++) {
var id = arguments[count];
if (typeof (id) == "string") {
id = cspbGetGroupIndex(id);
}
if (document.all["cspbGroup" + id]) {
cspbGD = document.all["cspbGroup" + id];
if (cspbGD.style.display == "inline") {
document.all["cspbBtnCell" + id].className = "cspbBtnCell";
if (navigator.platform != "MacPPC") {
cspbGDH = cspbGD.offsetHeight;
cspbEC(0);
} else {
cspbGD.style.display = "none";
}
} else {
document.all["cspbBtnCell" + id].className = "cspbBtnCellSlt";
cspbGD.style.display = "inline";
if (!cspbFO && navigator.platform != "MacPPC") {
cspbGDH = cspbGD.offsetHeight;
cspbGD.style.height = 1;
cspbEO(cspbGDH);
}
}
}
}
cspbFO = false;
}
function cspbGetGroupIndex(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.length; count++) {
if (aCaptions[count] == caption) {
return count;
}
}
return 0;
}
function cspbHBT(id) {
document.all["cspbBtnText" + id].className = "cspbBtnHvr";
}
function cspbDBT(id) {
document.all["cspbBtnText" + id].className = "cspbBtn";
}
function cspbEO(l) {
var RES = 3;
cspbEIA = true;
cspbTL = l;
if (cspbTL == 0) {
cspbGD.style.height = cspbGDH;
cspbEIA = false;
} else {
if (cspbTL <= RES) {
cspbTD = 1;
} else {
cspbTD = parseInt(cspbTL / RES);
}
if (cspbGDH != cspbTL) {
cspbGD.style.height = cspbGDH - cspbTL;
}
setTimeout("cspbEO(cspbTL-cspbTD);", 25);
}
}
function cspbEC(l) {
var RES = 6;
cspbEIA = true;
cspbTL = l;
if (cspbGDH == cspbTL) {
cspbGD.style.display = "none";
cspbGD.style.height = cspbGDH;
cspbEIA = false;
} else {
if ((cspbGDH - cspbTL) <= RES) {
cspbTD = 1;
} else {
cspbTD = parseInt((cspbGDH - cspbTL) / RES);
}
cspbGD.style.height = cspbGDH - cspbTL;
setTimeout("cspbEC(cspbTL+cspbTD);", 10);
}
}
function cspbRefresh() {
}
function cspbSetHeight(px) {
}

var cspbFSTID;
var cspbFSIID;
var cspbFSE = false;

function cspbWSEH() {
if (cspbFSE == true) {
clearTimeout(cspbFSTID);
cspbFSTID = window.setTimeout("cspbSFSI();", 200);
} else {
if ((navigator.userAgent.indexOf("MSIE") > -1) &&
(navigator.platform != "MacPPC")) {
cspbFSE = true;
}
}
}
function cspbSFSI() {
clearInterval(cspbFSIID);
cspbFSIID = window.setInterval("cspbFS();", 1);
}
function cspbFS() {
var scrollTop = parseInt(document.body.scrollTop) + 0;
var PBTop = parseInt(document.all.cspbPanelBar.style.top);
if (scrollTop == PBTop) {
clearInterval(cspbFSIID);
} else {
if (PBTop < scrollTop) {
if ((scrollTop - PBTop) <= 6) {
document.all.cspbPanelBar.style.top = PBTop + 1;
} else {
document.all.cspbPanelBar.style.top = parseInt(PBTop + ((scrollTop - PBTop) / 6));
}
} else {
if ((PBTop - scrollTop) <= 6) {
document.all.cspbPanelBar.style.top = PBTop - 1;
} else {
document.all.cspbPanelBar.style.top = parseInt(PBTop - ((PBTop - scrollTop) / 6));
}
}
}
}
function cspbASH() {
var e = window.onscroll;
if (typeof (e) == "function") {
e = e.toString();
e = e.substring(e.indexOf("{") + 1, e.lastIndexOf("}"));
var f = cspbWindowScroll.toString();
f = f.substring(f.indexOf("{") + 1, f.lastIndexOf("}"));
var sh = new Function(f + e);
window.onscroll = sh;
} else {
window.onscroll = cspbWSEH;
}
}

if (navigator.platform != "MacPPC") {
this.attachEvent("onscroll", cspbWSEH);
}
---

Good luck
/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6

"John Dalberg" <jo*****@hotmail.com> wrote in message
news:zw******************************@40tude.net.. .

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.


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 =---
Jul 20 '05 #7
Ira Baxter wrote:
"John Dalberg" <jo*****@hotmail.com> wrote in message
news:zw******************************@40tude.net.. .
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.

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


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.javascript FAQ - http://jibbering.com/faq/

Jul 20 '05 #8
Randy Webb <hi************@aol.com> writes:
Your answer, of course, is not related to the SEMDesigns purchase of
the #1 hit now would it?
I'd say he was very nice about not pointing to it. :)
But whats the point in paying 50 dollars US for something that can
be done for free? Sheesh.


Like this one:
---
<textarea id="input" style="width:100%;height:10em">Enter code here</textarea>
<input type="button" value="format"
onclick="var inp=document.getElementById('input');
var str=Function(inp.value).toString();
str=str.substring(str.indexOf('{')+1);
str=str.substring(0,str.lastIndexOf('}'));
inp.value=str;">
---
run in (preferably) Mozilla. Unless you like your comments ofcourse :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Alex Fitzpatrick | last post by:
Just by way of introduction, I'm currently the principal developer and maintainer of the a JavaScript editor plug-in for Eclipse. https://sourceforge.net/projects/jseditor/ The plug-in as it...
4
by: Patrick De Ridder | last post by:
Which library should I include for the formatter in formatter.Serialize(output, record); Many thanks. -- Patrick De Ridder ngmail@freeler.nl
4
by: Andreas Huber | last post by:
Hello there I need to serialize/deserialize some pretty simple data structures (no inheritance, few has relationships, ~20 classes) in three formats. One is XML (structure is not important as...
4
by: Carlitos | last post by:
I have researched a lot trying to get this. So as a last resource I will have to ask here. What would be the equivalent to the following javascript excerpt: TheDataManager MyDMgr = new...
2
by: Nadav | last post by:
Hi, I am trying to create a custom formatter ( such as the binary formatter ), I can't figure out where do I bind the input Data Stream with the SerializationInfo object info how should i create...
1
by: Edward Yang | last post by:
When it comes to ViewState in ASP.NET, I have a mixed feeling of both love and hate. For love, it simplifies many aspects of common tasks; for hate, it bloats web pages with large amount of cryptic...
3
by: mistral | last post by:
I there any good javascript formatter tool? (format javascript accurately, etc) Mistral
6
by: Melih Onvural | last post by:
I need to execute some javascript and then read the value as part of a program that I am writing. I am currently doing something like this: import htmllib, urllib, formatter class...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.